Skip to content

Commit

Permalink
check the chain id
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Oct 19, 2024
1 parent b03101f commit 263bf64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public final class Client {
}
}

private static func initializeClient(
static func initializeClient(
accountAddress: String,
options: ClientOptions,
signingKey: SigningKey?,
Expand Down Expand Up @@ -210,8 +210,8 @@ public final class Client {
)
}

public static func buildV3(address: String, scwChainId: Int64? = nil, options: ClientOptions) async throws -> Client {
let accountAddress = if(scwChainId != nil) { "eip155:\(String(describing: scwChainId)):\(address.lowercased())" } else { address }
public static func buildV3(address: String, chainId: Int64? = nil, options: ClientOptions) async throws -> Client {
let accountAddress = if(chainId != nil) { "eip155:\(String(describing: chainId)):\(address.lowercased())" } else { address }
let inboxId = try await getOrCreateInboxId(options: options, address: accountAddress)

return try await initializeClient(
Expand Down Expand Up @@ -275,10 +275,13 @@ public final class Client {
if let signingKey = signingKey {
do {
if signingKey.isSmartContractWallet {
guard let chainId = signingKey.chainId else {
throw ClientError.creationError("Chain id must be present to sign Smart Contract Wallet")
}
let signedData = try await signingKey.signSCW(message: signatureRequest.signatureText())
try await signatureRequest.addScwSignature(signatureBytes: signedData,
address: signingKey.address,
chainId: UInt64(signingKey.chainId),
chainId: UInt64(chainId),
blockNumber: signingKey.blockNumber.flatMap { $0 >= 0 ? UInt64($0) : nil })

} else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/XMTPiOS/SigningKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ extension SigningKey {
return false
}

public var chainId: Int64 {
return 1
public var chainId: Int64? {
return nil
}

public var blockNumber: Int64? {
Expand Down

0 comments on commit 263bf64

Please sign in to comment.