cloud-cryptographic-wallet icon indicating copy to clipboard operation
cloud-cryptographic-wallet copied to clipboard

support signTypedMessage

Open ansoncsh opened this issue 2 years ago • 2 comments

Add the method signTypedMessage to support EIP-712

ansoncsh avatar Aug 30 '22 03:08 ansoncsh

@ansoncsh Sorry for the late reply.

I am currently implementing a test for signTypedMessage

It would be easier to implement the tests if you have sample code using signTypedMessage. Do you have sample code?

odanado avatar Sep 08 '22 12:09 odanado

@odanado

Sorry for my late response. Please find the sample code below:

const provider = new KmsProvider(rpcUrl, { region, keyIds: [keyId] });
const accounts = await provider.getAccounts();
const digest = "0xbe609aee343fb3c4b28e1df9e632fca64fcfaede20f02e86244efddf30957bd2"
const signature = await provider.signTypedMessage({
    from: accounts[0],
    data: digest
})

The parameter digest refers to this EIP-712 example

ansoncsh avatar Sep 17 '22 09:09 ansoncsh

@ansoncsh According to EIP-712, the second argument of eth_signTypedData should be the data before hashing https://eips.ethereum.org/EIPS/eip-712#specification-of-the-eth_signtypeddata-json-rpc

Have you tried implementing passing hashed data to data in other wallets such as MetaMask?

odanado avatar Sep 20 '22 17:09 odanado

@ansoncsh According to EIP-712, the second argument of eth_signTypedData should be the data before hashing https://eips.ethereum.org/EIPS/eip-712#specification-of-the-eth_signtypeddata-json-rpc

Have you tried implementing passing hashed data to data in other wallets such as MetaMask?

@odanado I didn't try it

From my case,

  • use KMS wallet to sign a meta transaction for Contract A
  • pass signature to Contract B
  • execute meta transaction from Contract B

Just notice that it works on my case but not work on MetaMask.

ansoncsh avatar Sep 26 '22 02:09 ansoncsh

OK.

I tried signTypedMessage with ethers. https://github.com/odan-sandbox/sign-typed-data-sandbox/blob/34add5f0f8411daf673ea360be1ca3ffcfd2f373/hooks/useSignTypedData.ts#L42-L47

This resulted in the following error.

Error: Cannot convert string to buffer. toBuffer only supports 0x-prefixed hex strings and this string was given: {"types":{"Person":[{"name":"name","type":"string"},{"name":"wallet","type":"address"}],"Mail":[{"name":"from","type":"Person"},{"name":"to","type":"Person"},{"name":"contents","type":"string"}],"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}]},"domain":{"name":"Ether Mail","version":"1","chainId":"1","verifyingContract":"0xcccccccccccccccccccccccccccccccccccccccc"},"primaryType":"Mail","message":{"from":{"name":"Cow","wallet":"0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826"},"to":{"name":"Bob","wallet":"0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"},"contents":"Hello, Bob!"}}

I am implementing a fix to prevent this error from occurring.

odanado avatar Sep 28 '22 03:09 odanado

Pull Request Test Coverage Report for Build 3156097120

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 88.0%

Totals Coverage Status
Change from base Build 3046947450: 0.0%
Covered Lines: 118
Relevant Lines: 131

💛 - Coveralls

coveralls avatar Sep 28 '22 14:09 coveralls

@ansoncsh Changed eth_signTypedData to pass raw data as the second argument Can you confirm that this is available for your use case?

odanado avatar Sep 28 '22 16:09 odanado

@ansoncsh Changed eth_signTypedData to pass raw data as the second argument Can you confirm that this is available for your use case?

Yes, it works for my case too. Thanks!

ansoncsh avatar Oct 03 '22 04:10 ansoncsh

@ansoncsh LGTM Thank you!

odanado avatar Oct 15 '22 06:10 odanado

This change was released at [email protected].

odanado avatar Oct 15 '22 06:10 odanado