I'm using the Web3 library. I want to extract a signature hash from a Web3 transaction to send to an external hardware device, sign it there, then use the signature I get from there to broadcast my transaction on Ropsten.
On their GitHub page I found a test example:
On lines 26-37 I checked how it's signed:
const tx = {
chainId: '0x11',
data: '0x',
gas: '0x7530',
gasPrice: '0x3b9aca00',
nonce: '0x3',
to: '0xb414031Aa4838A69e27Cb2AE31E709Bcd674F0Cb',
value: '0x64'
};
await expect(
transactionSigner.sign(tx, '3a0ce9a362c73439adb38c595e739539be1e34d19c5e9f04962c101c86bd7616')
Apparently transactionSigner does the signing:
In that class, at lines 62-63:
const ethTx = new EthereumTx(transaction);
ethTx.sign(Buffer.from(privateKey, 'hex'));
So they're actually using another library, ehtereumjs-tx:
https://github.com/ethereumjs/ethereumjs-tx/blob/master/src/transaction.ts
At lines 269-270 we find:
const msgHash = this.hash(false)
const sig = ecsign(msgHash, privateKey)
This is what I want, the "msgHash" variable. How can I get to it without needing to butcher half the library and rewrite it manually? Or is there a simple way for me to construct it myself, and if so, how exactly?
For example, in bitcoinlib-js, there is a SignerAsync object, which you can construct yourself and simply assign its "sign(hash: Buffer)" property your own custom signing function. Bitcoinlib automatically throws in this "hash" thing that I need into the sign(hash: Buffer) and I simply pass it to my external Hardware device. Is there anything similar in Web3?