finalizeReclaim
Assembles the lockup witness for the chosen branch from the signatures already on a reclaim transaction, and returns the transaction ready to broadcast. No network call: broadcasting is left to the caller.
Usage
import { buildReclaim, finalizeReclaim } from '@stacks/bitcoin-staking';
import type { BuildReclaimOpts } from '@stacks/bitcoin-staking';
declare const opts: BuildReclaimOpts; // path: 'locktime'
declare const stakerBtcPrivateKey: Uint8Array; // key behind the lockup's unlockBytes
const tx = buildReclaim(opts);
tx.signIdx(stakerBtcPrivateKey, 0);
const { txHex, txid } = finalizeReclaim({ path: 'locktime', tx });
// broadcast txHex through your Bitcoin node or indexerNotes
Reads the
partialSigentries on input 0, left bytx.signIdxor bytx.updateInput(0, { partialSig }), and matches each public key against the lockup script to tell the staker's signature from the cosigner's.The witness stack is
[stakerSig, 0x01, witnessScript]for'locktime'and[stakerSig, cosignerSig, preimage, <empty>, witnessScript]for'early-exit'.Throws an
Errorif input 0 has no witness script, if the script does not have the pox-5 lockup layout, if the staker subscript has other than one public key, or if the staker's signature is missing. On'early-exit'it also throws if the early-unlock subscript has other than one public key or the cosigner's signature is missing. Multi-key subscripts are valid in pox-5 but this function cannot assemble their witness.stxAddressis not checked against the script. A wrong address produces a witness that Bitcoin rejects at theOP_EQUALVERIFYafterOP_SHA256.Mutates
tx: the witness is written to input 0.txidis computed locally. It identifies the transaction you broadcast and says nothing about whether it was accepted or confirmed.
Signature
opts is a FinalizeReclaimOpts.
Returns
{ txHex: string; txid: string }
txHex
string
The finalized transaction, hex-encoded, ready to broadcast
txid
string
The transaction ID
Parameters
opts.path (required)
Type:
'locktime' | 'early-exit'
The branch to spend. Use the path the transaction was built with in buildReclaim, which sets the locktime and sequence for that branch.
opts.tx (required)
Type:
btc.Transaction
The signed reclaim transaction from buildReclaim. btc is @scure/btc-signer.
opts.stxAddress (required for 'early-exit')
Type:
string
The staker principal the lockup script commits to. Used to compute the preimage with computeRegisterPreimage.
Was this helpful?