cloud-cryptographic-wallet
cloud-cryptographic-wallet copied to clipboard
support signTypedMessage
Add the method signTypedMessage to support EIP-712
@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
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 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?
@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.
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.
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 | |
---|---|
Change from base Build 3046947450: | 0.0% |
Covered Lines: | 118 |
Relevant Lines: | 131 |
💛 - Coveralls
@ansoncsh Changed eth_signTypedData to pass raw data as the second argument Can you confirm that this is available for your use case?
@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 LGTM Thank you!
This change was released at [email protected]
.