Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth_sign won't resolve promise #10961

Closed
joelamouche opened this issue Apr 30, 2021 · 12 comments
Closed

eth_sign won't resolve promise #10961

joelamouche opened this issue Apr 30, 2021 · 12 comments

Comments

@joelamouche
Copy link

Describe the bug
const signedMsg = await provider.request({ method: 'eth_sign',params:[accountsRead[0],"test"] }); won't resolve and stays pending even if the call does trigger a signature in MetaMask and does show the appropriate warning.

Steps to reproduce (REQUIRED)
Steps to reproduce the behavior, libraries used with version number, and/or any setup information to easily reproduce:

  1. Go to https://github.com/joelamouche/test-dapp/tree/testEthSign
  2. Run yarn start
  3. Open http://localhost:3000/ on browser and display console
  4. Click on the Button
  5. Call never resolves

You should be able to see "SIGNED" in the console, as per https://github.com/joelamouche/test-dapp/blob/b40dda41246a44f07087852fcfef6e4b480bdfbb/src/connect.ts#L71

Expected behavior
You should be able to see "SIGNED" in the console, as per https://github.com/joelamouche/test-dapp/blob/b40dda41246a44f07087852fcfef6e4b480bdfbb/src/connect.ts#L71
And see the signed message
Also I do want to specify that @danfinlay said that eth_sign should be implemented in MetaMask/metamask-docs#239

Browser details (please complete the following information):

  • OS: Mac OS Big Sur
  • Browser: Chrome
  • MetaMask Version: 9.4.0
@tmashuang
Copy link
Contributor

Are there any errors in the dapp console that can reference an implementation issue? I ask because simply running the eth_sign snippet below in the dev console on a connected site works as intended.

ethereum.request({method: 'eth_sign', params: [ethereum.selectedAddress, 'hello world']})

@joelamouche
Copy link
Author

Strange because it doesn't work as intended on my browser:
Screen Shot 2021-05-03 at 3 41 44 PM

The promise never resolves...
Does it resolve for you in your browser?

My version of Chrome is Version 90.0.4430.93 (Official Build) (arm64)

@tmashuang
Copy link
Contributor

I was mistaken, the eth_sign currently does not work all arbitrary data as it stands. The trace starts at
metamask-controller.js#L1534
eth-simple-keyring/index.js#L63
ethereumjs-util/src/signature.ts#L25
finally to
secp256k1-node/lib/index#L253
where it fails the assert for a 32byte message.

So this should work.

ethereum.request({method: 'eth_sign', params: [ethereum.selectedAddress, 'hello world but a lil bit longer']})

eth.wiki/#eth_sign says it can take N bytes, but the docs can be old. But from what I can see our implementation is not currently in spec with secp256k1.

@joelamouche
Copy link
Author

Thanks for the help @tmashuang

It does resolve now but the signature verification fails: https://github.com/joelamouche/test-dapp/blob/95ac0a4cd3d12d5934812b23653aec991d5133e8/src/connect.ts#L79

Is there a signature verification test I could take inspiration from? Thanks in advance

@joelamouche
Copy link
Author

I was actually able to verify using ethUtil.bufferToHex(Buffer.from(testMsg)) from ethereumjs-util (see permalink above)
The verification still fails with signatureVerify from '@polkadot/util-crypto' ...

@joelamouche
Copy link
Author

@tmashuang what is the authorized length? I'm trying to sign a 216 long byte msg and it never resolves, much like it used to for short messages

@joelamouche
Copy link
Author

@tmashuang Is there a way we can change that limit please ?

@joelamouche
Copy link
Author

@tmashuang nevermind I hashed it and it works

@wjmelements
Copy link
Contributor

I am also seeing the same issue.

@vanvantsyan
Copy link

@wjmelements @joelamouche , so what was your solution ? how are u hashing it ?

@joelamouche
Copy link
Author

@vanvantsyan See https://github.com/polkadot-js/extension/blob/51a4eabed8293ea92b456f0f493c7c5ea55b81d5/packages/extension-compat-metamask/src/index.ts#L77

I used Web3.utils.sha3(raw.data) to make sure the data is the accurate length

@danjm danjm added the area-api label Sep 24, 2021
@sinsinpurin
Copy link

I used web3.utils.sha3 then it's solved.
May be its was Caused by not having 32bytes message.

If you want to see sample See https://github.com/sinsinpurin/metamask-sign-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants
@wjmelements @danjm @tmashuang @joelamouche @vanvantsyan @sinsinpurin and others