WalletConnect / WalletConnectSwiftV2

WalletConnect Swift SDK v2
https://docs.walletconnect.com
Apache License 2.0
368 stars 180 forks source link

Need to sign Eip712 Typed data from the json string #1176

Open awaiskhan1304 opened 1 year ago

awaiskhan1304 commented 1 year ago

In the wallet connect request I am receiving eth_signTypedData_v4 with the json string needed to be signed. I want to sign this message. In the example project under Signer->EthSigner.swift their is one method signTypedData but it is returning dummy sigature.

muratogat commented 1 year ago

Yes, it seems that WC devs are not bothered with implementing signTypedData properly, so they simply return a dummy signature instead. Maybe this helps https://stackoverflow.com/questions/71215667/how-to-implement-eth-signtypeddata-in-swift

awaiskhan1304 commented 1 year ago

I have tried this and able to create the signature but there is something wrong with the signature. When I verify the signature on web using web3.eth.accounts.recover(message,sig) method it verifies the message and gives me correct result while when I use the method which wallet connect test dapp uses it fails to verify the signature.

function recoverAddress(sig, hash) { const params = ethUtil.fromRpcSig(sig); const result = ethUtil.ecrecover( ethUtil.toBuffer(hash), params.v, params.r, params.s ); const signer = ethUtil.bufferToHex(ethUtil.publicToAddress(result)); return signer; }

Not getting why this is happening

muratogat commented 1 year ago

The signature sent back over wallet connect to the dapp needs to start with 0x.

awaiskhan1304 commented 1 year ago

yes sending it back with 0x.