buildUnlockScript
Builds the default staker unlock subscript, <pubkey> OP_CHECKSIG, from a compressed public key. Pure computation: no network call.
Usage
import { buildUnlockScript } from '@stacks/bitcoin-staking';
const unlockBytes = buildUnlockScript(
'0316e35d38b52d4886e40065e4952a49535ce914e02294be58e252d1998f129b19'
);
// 35 bytes: 0x21 (push 33 bytes), the key, 0xac (OP_CHECKSIG)Notes
Throws an
Errorif the key is not 33 bytes, does not start with0x02or0x03, or is not a point on secp256k1. The on-curve check matters because an off-curve key still yields a fundable lockup address whoseOP_CHECKSIGcan never pass.Pass the result as
unlockBytesto buildLockScript, buildLockOutputScript or buildLockAddress, and aslockup.unlockBytesto buildRegisterForBond. buildRegisterMetadata calls it for you.pox-5 splices these bytes raw at the end of the lockup script, so they run in both spend branches (construct-lockup-script).
register-for-bondtakes them asstaker-unlock-bytes, capped at 683 bytes (L664).finalizeReclaim expects exactly one staker public key in this subscript, which this format provides.
Signature
Returns
Uint8Array
The encoded subscript: a 33-byte push of the key followed by OP_CHECKSIG.
Parameters
publicKey (required)
Type:
Uint8Array | string
The staker's 33-byte compressed secp256k1 public key, as bytes or hex. This is the key that signs the lockup reclaim.
Was this helpful?