bitcoinjs / bitcoinjs-lib

A javascript Bitcoin library for node.js and browsers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Offline signing for Psbt class

raphaels10 opened this issue · comments

Hi!

I'm developing a crypto application that leverages Hardware Security Modules (HSMs) to store BIP32 keys and also sign bitcoin transactions.

In the older versions of the lib, i could do it just fine by using the TransactionBuilder class to add the transaction inputs and outputs and then by calling the hashForSignature or hashForWitnessV0 (in the case that the input is Segwit) to generate the hashes to be signed by the private key within the HSM. At the end, i just had to call the setInputScript or setWitness method to append the signatures and generate the fully signed transaction.

With the Psbt class, i can't seem to find a way to do that. There are no methods to generate the hashes to be signed, and no methods to append the signatures to the transaction object. Trying to convert the Psbt to a Transaction object also fails if the transaction hasn't been signed yet. Is there any way to do this offline signing process with the new Psbt class?

Implement an AsyncSigner interface and pass that into signInputAsync (and any of the other Async signing methods).

If you absolutely must smuggle the hash, you could implement a smuggler signer that just exfiltrates the hash, and then an injector signer that compares the hash given to the hash you signed, and if they're equal, inject the signature.

@junderw Just tested it and it's working! Thanks for the help