computeRegisterPreimage
Computes the 32-byte preimage that an early-exit spend of a lockup must reveal: sha256 of the staker's Clarity consensus serialization. Pure computation: no network call.
Usage
import { computeRegisterPreimage } from '@stacks/bitcoin-staking';
const preimage = computeRegisterPreimage('SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7');
// 32 bytes: sha256(to-consensus-buff? staker)Notes
The lockup script commits to the staker by the double hash
sha256(sha256(to-consensus-buff? staker))(construct-lockup-script). TheOP_ELSE(early-exit) branch checks that the revealed witness item is 32 bytes and hashes to that commitment, so it needs this single-hash value. TheOP_IF(locktime) branch does not use it.finalizeReclaim calls this for the early-exit path. You need it directly only to assemble the witness yourself.
Standard and contract principals are both accepted, serialized the same way pox-5 serializes them. Throws if
stxAddressdoes not decode as a Stacks address.
Signature
function computeRegisterPreimage(stxAddress: string): Uint8Array;Returns
Uint8Array
The 32-byte preimage.
Parameters
stxAddress (required)
Type:
string
The staker's Stacks principal, standard or contract. It must be the principal the lockup script was built for.
Was this helpful?