-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Allow binary message for wallet.signMessage. #80
Comments
Just saw this issue was opened #78 . It is a bit related and I've tried both way (with wallet instance and signing key) and I can't find the right output. Also, should signing the same piece of data through the wallet instance or through the signing key output the same data? |
Hey Jenna! Can you provide an example of a privateKey (obviously newly created for this sample) as well as data and the output you expect? Also keep in mind that Web3 treats strings inconsistently. So the string "0x12". is 1 byte long, but the string "12" is two bytes long. And as a result there is no easy way to represent the 4 byte string "0x12", except to expand it to "0x30793132". |
by the way, have you checked out: var w = new ethers.Wallet('0x123456789012345678901234567890123456789012345678901234567890123');
var sig = w.signMessage("Hello World");
//'0xe0ed34fbbe927a58267ce2e8067a611c69869e20e731bc99187a8bc97058664c16de07f7660f06ce0985d1d8e063726783033fda59b307897f26a21392d62b3a1c'
var address = ethers.Wallet.verifyMessage("Hello World", sig);
// address === w.address |
Thanks @ricmoo for your answer! I tried this indeed, and verifyMessage does return my account address. Still, its not the same output as the one I have when signing with |
Hey @ricmoo , here is some code to reproduce. I used ethereumjs-util (think its easier to reproduce than with parity.js). As you can see, signing with ethers.js and signing with ethereumjs-util doesn't give the same output.
|
Ok, I've found the problem. I have updated the signMessage API to allow binary data to be passed in. Before it only allowed UTF-8 strings. You will have to make a small change to the above code, since "0x1234" is a valid string (of 6 bytes); the eth-sig-util is using the message as a binary payload. var hash = "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"
// To use the 66 byte string (not what you want)
wallet.signMessage(hash);
// To use the 32 byte binary data (matches the above eth-sig-util)
var hashData = ethers.utils.arrayify(hash);
wallet.signMessage(hashData); I've also added your example to the test-cases. Once Travis-CI has completed, I'll publish to npm and close this issue. You'll have to delete your package-lock.json and node_modules and redo an |
Awesome thanks @ricmoo |
Just published to npm. Thanks @jennazenk! |
Thank you @jennazenk and @ricmoo ! This saved me (after spending whole Sunday trying to make it work). I would love for this to be included in the cookbook part of the docs as the most common case would be off-chain |
Excellent Point! I will add it to my todo list for the Cookbook. |
Here is my playground: https://gitlab.com/limelabs/ecrecover-test/tree/master I feel that in order for this to be a fully comprehensive example the Smart Contract part might be needed too. The meaty part is in |
hello @ricmoo , what is the equivalent of
web.eth.sign()
(https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethsign) in ethers.js ?I am trying to sign a piece of data in order to retrieve s, r and v from the signature. I tried with
Wallet.sign()
and alsoSigningKey.signDigest
, but I don't get the same output as when I callweb3.eth.sign()
.The purpose of that is that I need to call the solidity
ecrecover
function to verify that my address has signed the data.Thanks a lot!
The text was updated successfully, but these errors were encountered: