Skip to content

Commit

Permalink
complate 3step signing
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Nov 15, 2024
1 parent c69e782 commit ecbfe26
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
27 changes: 21 additions & 6 deletions Example/Shared/Signer/Signer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ final class Signer {
let messageHash = messageToSign.sha3(.keccak256).toHexString()

// Step 1
let prepareSignMessage = try await WalletKit.instance.prepareSignMessage(messageHash, ownerAccount: ownerAccount)
let prepareSignMessage: PreparedSignMessage
do {
prepareSignMessage = try await WalletKit.instance.prepareSignMessage(messageHash, ownerAccount: ownerAccount)
} catch {
print(error)
throw error
}

// Sign prepared message
let dataToSign = prepareSignMessage.hash.data(using: .utf8)!
Expand All @@ -112,25 +118,34 @@ final class Signer {
let result: String = "0x" + r.toHexString() + s.toHexString() + String(v + 27, radix: 16)

// Step 2
let prepareSign = try await WalletKit.instance.doSignMessage([result], ownerAccount: ownerAccount)
let prepareSign: PreparedSign
do {
prepareSign = try await WalletKit.instance.doSignMessage([result], ownerAccount: ownerAccount)
} catch {
print(error)
throw error
}

switch prepareSign {
case .signature(let signature):
return AnyCodable(signature)
case .signStep3(let preparedSignStep3):
// Step 3

let dataToSign = preparedSignStep3.hash.data(using: .utf8)!
let privateKey = try! EthereumPrivateKey(hexPrivateKey: importAccount.privateKey)
let (v, r, s) = try! privateKey.sign(message: .init(Data(dataToSign)))
let result: String = "0x" + r.toHexString() + s.toHexString() + String(v + 27, radix: 16)

let signature = try await WalletKit.instance.finalizeSignMessage([result], signStep3Params: preparedSignStep3.signStep3Params, ownerAccount: ownerAccount)

let signature: String
do {
signature = try await WalletKit.instance.finalizeSignMessage([result], signStep3Params: preparedSignStep3.signStep3Params, ownerAccount: ownerAccount)
} catch {
print(error)
throw error
}
return AnyCodable(signature)
}


case "eth_signTypedData":
let params = try request.params.get([String].self)
let message = params[0]
Expand Down
1 change: 1 addition & 0 deletions Sources/ReownWalletKit/SmartAccount/SafesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SafesManager {
safe: true
)
// TODO remove registration

x.register(privateKey: "ff89825a799afce0d5deaa079cdde227072ec3f62973951683ac8cc033092156")
return x
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/WalletConnectSigner/Verifier/MessageVerifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public struct MessageVerifier {
message: prefixedMessage,
address: address
)
return // If 6492 verification succeeds, we’re done
return // If 191 verification succeeds, we’re done
} catch {
// If eip191 verification fails, we’ll attempt 6492 verification
}
Expand Down

0 comments on commit ecbfe26

Please sign in to comment.