Skip to content

Commit

Permalink
fix a little formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Sep 21, 2024
1 parent 4e43786 commit ede8c29
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
21 changes: 0 additions & 21 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,6 @@ public final class Client {
do {
let signedData = try await signingKey.sign(message: signatureRequest.signatureText())
if signingKey.isSmartContractWallet {
guard isValidAccountID(signingKey.address) else {
throw ClientError.creationError("Account address must conform to CAIP format")
}
try await signatureRequest.addScwSignature(signatureBytes: signedData.rawData, address: signingKey.address, chainId: signingKey.chainId, blockNumber: signingKey.blockNumber)
} else {
try await signatureRequest.addEcdsaSignature(signatureBytes: signedData.rawData)
Expand Down Expand Up @@ -703,22 +700,4 @@ public final class Client {
}
return InboxState(ffiInboxState: try await client.inboxState(refreshFromNetwork: refreshFromNetwork))
}

// See for more details https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md
public func isValidAccountID(_ accountAddress: String) -> Bool {
// Define the regular expressions for chain_id and account_address
let chainIDPattern = "[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}"
let accountAddressPattern = "[-.%a-zA-Z0-9]{1,128}"

// Combine them to match the entire account_id format
let accountIDPattern = "^\(chainIDPattern):\(accountAddressPattern)$"

let regex = try? NSRegularExpression(pattern: accountIDPattern)

if let match = regex?.firstMatch(in: accountAddress, options: [], range: NSRange(location: 0, length: accountAddress.utf16.count)) {
return match.range.location != NSNotFound
} else {
return false
}
}
}
6 changes: 3 additions & 3 deletions Sources/XMTPiOS/SigningKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public protocol SigningKey {
/// If this signing key is a smart contract wallet
var isSmartContractWallet: Bool { get }

/// The name of the chainId for example "eip155:1"
/// The name of the chainId for example "8453" is the chainId for base
var chainId: UInt64 { get }

/// The blockNumber of the chain for example "1"
Expand All @@ -43,11 +43,11 @@ extension SigningKey {
}

public var chainId: UInt64 {
return "eip155:1"
return 8453
}

public var blockNumber: UInt64 {
return "eip155:1"
return 0
}

func createIdentity(_ identity: PrivateKey, preCreateIdentityCallback: PreEventCallback? = nil) async throws -> AuthorizedIdentity {
Expand Down

0 comments on commit ede8c29

Please sign in to comment.