Bitcoin: How do you finalize a PSBT when the last signature is provided by a HWW?

Here is an article on how to complete a PSBT (Proof of Stake Bulletproofs) when the final signature is provided by a hardware wallet (HWW):

Complete PSBT with HWW Signature

Bitcoin: How do you finalize a PSBT when the last signature is provided by a HWW?

When using the device API for hardware wallets such as Ledger or Trezor, there may be situations where the final signature has not yet been provided. However, it is important to note that these devices usually provide the required signature after successful initialization.

To complete a PSBT (Proof of Stake Bulletproofs) after receiving the HWW signature, follow these steps:

Step 1: Get the HWW Signature

The first step is to retrieve the HWW signature from your hardware wallet. This can be done using the “sign_tx” method provided by the device API, as mentioned in the question.

use psbt::prelude::*;

// Let's say you have a Ledger device and a Trezor device with the same API.

let hww = LedgerDevice::new("path/to/ledger").unwrap();

hww.sign_tx(psbt::Tx::NewTransaction(

psbt::Amount::Null(),

psbt::Target,

psbt::Hash,

psbt::ProofOfStake::Unconfirmed,

));

Step 2. Create the final PSBT

Once you have the HWW signature, you can create the final PSBT using the ‘finalize’ method provided by the device API.

// Let's assume you have a Ledger device and a Trezor device with the same API.

let psbt = finalize (

hww.hww_signature,

psbt::Amount::Null(),

psbt::Target,

psbt::Hash,

);

Step 3: Sign the completed PSBT (optional)

If you want to sign the completed PSBT with another HWW, use the “sign_tx” method again.

// Suppose you have another Ledger device and a Trezor device with the same API.

let hww_sign = LedgerDevice::new("path/to/other_ledger").unwrap();

let psbt_sign = finalize(

hww.sign_tx(psbt::Amount::Zero(), psbt::Target, psbt::Hash),

psbt::Amount::Zero(),

psbt::Target,

psbt::Hash,

);

Step 4: Review the completed PSBT

To make sure that the completed PSBT is correct, verify it by checking its hash and signature.

// Let's say you have a Ledger device and a Trezor device with the same API.

let hww = LedgerDevice::new("path/to/ledger").unwrap();

hww.verify_finalized_psbt(&psbt::Hash, &psbt::Signature);

Example Use Case

Here is an example use case that shows how to finalize a PSBT with HWW signatures:

use psbt::prelude::*;

fn main() {

// Create a new Trezor device using the same API.

let trezor = TrezorDevice::new("path/to/trezor").unwrap();

// Generate the public and private keys for your wallet.

let pk = generate_keys().unwrap();

let sk = generate_keys().unwrap();

// Create a new Proof of Stake Bulletproof (PSBT) transaction.

let mut psbt = create_psbt(&pk, &sk);

// Sign the PSBT with a Ledger device and another Trezor device.

let hww_sign = LedgerDevice::new("path/to/ledger").unwrap();

let trezor_sign = TrezorDevice::new("path/to/trezor").unwrap();

psbt.sign_tx(hww_sign.hww_signature, &psbt);

psbt.sign_tx(trezor_sign.hww_signature, &psbt);

// Get the finalized PSBT.

let finalized_psbt = finalize(&hww_sign.hww_signature, &psbt).unwrap();

println!("Finalized PSBT hash: {}", finalized_psbt.hash());

}

Please note that this is a simplified example. For specific instructions on completing PSBT with HWW signatures, please refer to the device API documentation. Also, keep in mind that the Bitcoin community does not recommend using HWW for key storage and transaction signing due to security reasons.

Leave a Comment

Your email address will not be published. Required fields are marked *