1

I use digital bitbox to sign some data and would like to use web3.js to recover the account address. Following https://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#recover I couldn't successfully recover the address so far. I think the main issue is whether I have to prefix the data with web3.eth.accounts.hashMessage(message); and if yes, when exactly. This is what I currently do:

let data = ...

let data_hash = web3.utils.sha3(data, {encoding: 'hex'});
signature = sig.signData(data_hash.substring(2)) //signing by digital bitbox
let v;
if (signature.recid === "00") {
     v = "0x1b";
} else {
     v = "0x1c";
}
const r = "0x" + signature.sig.slice(0, 64);
const s = "0x" + signature.sig.slice(64, 128);

const signatureObject = {
messageHash: data,
   v: v,
   r: r,
   s: s
};

const recover = web3.eth.accounts.recover(signatureObject);
//recover should equal the address used by bitbox

I tried many combinations of web3.eth.accounts.hashMessage(data); and when to call web3.utils.sha3 on data but nothing seemed to work.

What did I miss?

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.