Methods for working with BIP 174 PSBTs
npm install psbtPSBTs are a format for communicating and collaboratively working with
transactions.
The format is defined in BIP-0174:
https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki
An ECPair object is required for some methods:
``node
const tinysecp = require('tiny-secp256k1');
const ECPair = await import('ecpair')
const ecp = ECPair.ECPairFactory(tinysecp);
``
Combine multiple PSBTs
{
ecp:
psbts: [
}
@throws
@returns
{
psbt:
}
Create a PSBT
{
outputs: [{
script:
@returns
{
psbt:
}
Decode a BIP 174 encoded PSBT
{
ecp:
psbt:
}
@throws
@returns
{
inputs: [{
[bip32_derivations]: [{
fingerprint:
[leaf_hashes]:
path:
public_key:
}]
[final_scriptsig]:
[final_scriptwitness]:
[non_witness_utxo]:
[partial_sig]: [{
hash_type:
public_key:
signature:
}]
[redeem_script]:
[sighash_type]:
[taproot_control_block]:
[taproot_leaf_hash]:
[taproot_leaf_public_key]:
[taproot_leaf_script]:
[taproot_leaf_version]:
[taproot_internal_key]:
[taproot_key_spend_sig]:
[taproot_root_hash]:
[taproot_script_signature]:
[unrecognized_attributes]: [{
type:
value:
}]
[witness_script]:
[witness_utxo]: {
script_pub:
tokens:
}
}]
outputs: [{
[bip32_derivation]: {
fingerprint:
[leaf_hashes]:
path:
public_key:
}
[redeem_script]:
[taproot_internal_key]:
[taproot_script_tree]: [{
depth:
script:
version:
}]
[unrecognized_attributes]: [{
type:
value:
}]
[witness_script]:
}]
pairs: [{
type:
value:
}]
[unrecognized_attributes]: [{
type:
value:
}]
unsigned_transaction:
}
Encode a Partially Signed Bitcoin Transaction
{
pairs: [{
[separator]:
[type]:
[value]:
}]
}
@throws
@returns
{
psbt:
}
Extract a transaction from a finalized PSBT
{
ecp:
psbt:
}
@throws
@returns
{
transaction:
}
Finalize the inputs of a PSBT
{
ecp:
psbt:
}
@throws
@returns
{
psbt:
}
Update a PSBT with signatures
{
ecp:
network:
psbt:
signing_keys: [
}
@throws
@returns
{
psbt:
}
Convert a signed transaction to a signed PSBT
Note: not all signed transactions can be converted to a signed PSBT. For
example, a preimage cannot be represented in a standard PSBT.
{
ecp:
spending: [
transaction:
}
@throws
@returns
{
psbt:
}
Update a PSBT
{
[additional_attributes]: [{
type:
value:
vin:
vout:
}]
[bip32_derivations]: [{
fingerprint:
path:
public_key:
}]
ecp:
psbt:
[redeem_scripts]: [
[sighashes]: [{
id:
sighash:
vout:
}]
[signatures]: [{
vin:
hash_type:
public_key:
signature:
}]
[taproot_inputs]: [{
vin:
[key_spend_sig]:
}]
[transactions]: [
[witness_scripts]: [
}
@throws
@returns
{
psbt:
}