question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow binary message for wallet.signMessage.

See original GitHub issue

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 also SigningKey.signDigest, but I don’t get the same output as when I call web3.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!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
ricmoocommented, Dec 2, 2017

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 npm install, but then you should be off to the races. 😃

1reaction
ricmoocommented, Mar 25, 2018

Excellent Point! I will add it to my todo list for the Cookbook.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Signing Messages — ethers.js 4.0.0 documentation
By allowing a user to sign a string, which can be verified on-chain, interesting forms of ... Create a wallet to sign the...
Read more >
Signing Messages - Solflare Wallet
The signMessage function expects an Uint8Array and a data display type parameter (either utf8 for readable text or hex for binary data) and...
Read more >
Unable to verify message signed by sol-wallet-adapter
Use solana.signMessage and base58 encode the signature. var _signature = ''; try { signedMessage = await window.solana.request({ method: " ...
Read more >
eth_account — eth-account 0.8.0 documentation
Creates a new private key, and returns it as a LocalAccount , alongside the mnemonic that can used to regenerate it using any...
Read more >
Create a Signed Transaction | Aptos Docs
The Aptos node will generate the signing message, the transaction ... In Aptos blockchain, all the data is encoded as BCS (Binary Canonical...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found