0

I am attempting to get consistent signatures / recovery for text containing special characters.

For example, the bitcoin symbol U+20BF, ₿

Junk address and private key:

0xd60595Bef7F106a42792D5075Fb5f8eA819D4446
0x6f88aa12e42d2973e0e71cacb9212608231d438018bdd72335df404c87247188

Sign in .js file with node:

const Web3 = require('web3');
let web3 =  new Web3(myprovider);
web3.version; //1.2.4
...

sig = await web3.eth.accounts.sign(`₿`,"0x6f88aa12e42d2973e0e71cacb9212608231d438018bdd72335df404c87247188")
console.log(sig.signature)
//0x3b7bf2e1be49aef293d2838fc90d0b39dc677df18197e598ed6aa0e6f60276c44e79c055ba9a0033b41c2ac629acf8cd15dfe0f8c14e89c829f9f932f15c568d1c

Recover in browser:

// expect to recover address 0xf509D7437cA9A804331478187c5AE5dCC81e2e77, but doesn't :-(
web3.version; //1.2.9
await web3.eth.accounts.recover('₿','0x3b7bf2e1be49aef293d2838fc90d0b39dc677df18197e598ed6aa0e6f60276c44e79c055ba9a0033b41c2ac629acf8cd15dfe0f8c14e89c829f9f932f15c568d1c',false);
//0xd60595Bef7F106a42792D5075Fb5f8eA819D4446
await web3.eth.accounts.recover('₿','0x3b7bf2e1be49aef293d2838fc90d0b39dc677df18197e598ed6aa0e6f60276c44e79c055ba9a0033b41c2ac629acf8cd15dfe0f8c14e89c829f9f932f15c568d1c',true);
//0x3B37B414621766b255d62898a2aEb2Fd0893B8ea

Test signature in browser:

  // not a good idea to handle private keys in browser js code imho. This is just for illustration of error
   await web3.eth.accounts.sign('₿','0x6f88aa12e42d2973e0e71cacb9212608231d438018bdd72335df404c87247188')
   // gives different signature:
   // 0xb0144eacbb08217276945e98127e1fe7230cb843604d5ac4feb5a0e45e1da85b21e1e19bb40c872a037c2c83e38e882db67eb01c3d05171fc5ef8302d8ea3bc11b

Note the above approach works with plain ascii.

What is the best way to encode special characters to ensure consistent signatures?

Is there something obvious I'm doing wrong here?

EDIT - Updated browser web3 to v1.2.11 and it produce consistent, but incorrect, recover outputs.

web3.version //1.2.11
await web3.eth.accounts.recover('₿','0x3b7bf2e1be49aef293d2838fc90d0b39dc677df18197e598ed6aa0e6f60276c44e79c055ba9a0033b41c2ac629acf8cd15dfe0f8c14e89c829f9f932f15c568d1c',false)
"0xd60595Bef7F106a42792D5075Fb5f8eA819D4446"

EDIT 2 - Post update doesn't work for some characters (e.g. §, utf8 hex 0xC2 0xA7)

*EDIT 3 - Updating both web3 versions to 1.2.11 works (for all the chars I checked) , again I would accept an answer that states what the issue was with web3js... *

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.