validateEarlyUnlockBytes
Checks a bond's early-unlock-bytes subscript before it is spliced into a lockup script, and returns it as bytes. Pure computation: no network call.
Usage
import { fetchBond, validateEarlyUnlockBytes } from '@stacks/bitcoin-staking';
const bond = await fetchBond({ bondIndex: 2, network: 'mainnet' });
if (!bond) throw new Error('bond 2 is not set up');
const earlyUnlockBytes = validateEarlyUnlockBytes(bond.earlyUnlockBytes);Notes
The structural check always runs. It throws if the bytes are empty, since the early-exit branch would then carry no spend condition, or if they do not decode as Bitcoin script, since a truncated push corrupts the assembled lockup script.
The shape check runs unless
opts.shapeisfalse. It throws unless the subscript has exactly one 33-byte public-key push, ends inOP_CHECKSIG, and contains noOP_IF,OP_NOTIF,OP_ELSEorOP_ENDIF.pox-5 treats these bytes as opaque, so an M-of-N template is valid on chain but fails the shape check. Pass
{ shape: false }for such a bond. finalizeReclaim still cannot assemble an early-exit witness for more than one cosigner key.buildLockScript runs this check on its
earlyUnlockBytes.
Signature
Returns
Uint8Array
The subscript as bytes, unchanged.
Parameters
earlyUnlockBytes (required)
Type:
Uint8Array | string
The bond's early-unlock subscript, as bytes or hex.
opts.shape (optional)
Type:
boolean
Whether to run the shape check. Defaults to true.
Was this helpful?