import { Writer } from './io/writer.js'; import { Op } from './op.js'; import { Bytes } from './io/bytes.js'; /** A Bitcoin Script locking/unlocking a UTXO */ export declare class Script { bytecode: Uint8Array; /** Create a new Script with the given bytecode or empty */ constructor(bytecode?: Uint8Array); /** * Write the script to the writer with the script size as VARINT * prepended. **/ writeWithSize(writer: Writer): void; static readWithSize(bytes: Bytes): Script; /** Build a Script from the given Script Ops */ static fromOps(ops: Op[]): Script; static fromAddress(address: string): Script; /** Iterate over the Ops of this Script */ ops(): ScriptOpIter; /** Create a deep copy of this Script */ copy(): Script; /** * Find the n-th OP_CODESEPARATOR (0-based) and cut out the bytecode * following it. Required for signing BIP143 scripts that have an * OP_CODESEPARATOR. * * Throw an error if the n-th OP_CODESEPARATOR doesn't exist. * * Historically this opcode has been seen as obscure and useless, but in * BIP143 sighash-based covenants, basically every covenant benefits from * its usage, by trimming down the sighash preimage size and thus tx size. * * Really long Scripts will have a big BIP143 preimage, which costs precious * bytes (and the preimage might even go over the 520 pushdata limit). * This can be trimmed down to just one single byte by ending the covenant * in `... OP_CODESEPARATOR OP_CHECKSIG`, in which case the BIP143 signature * algo will cut out everything after the OP_CODESEPARATOR, so only the * OP_CHECKSIG remains. * If the covenant bytecode is 520 or so, this would save 519 bytes. */ cutOutCodesep(nCodesep: number): Script; /** * Whether the Script is a P2SH Script. * Matches CScript::IsPayToScriptHash in /src/script/script.h. **/ isP2sh(): boolean; /** * Return hex string of this Script's bytecode */ toHex(): string; /** Build a P2SH script for the given script hash */ static p2sh(scriptHash: Uint8Array): Script; /** Build a P2PKH script for the given public key hash */ static p2pkh(pkh: Uint8Array): Script; /** Build a scriptSig for spending a P2PKH output */ static p2pkhSpend(pk: Uint8Array, sig: Uint8Array): Script; /** * Build m-of-n multisig script: OP_m pubkey1 pubkey2 ... pubkey_n OP_n OP_CHECKMULTISIG. * Works for P2SH-wrapped or bare multisig. * Pubkeys are used in the order given; callers who want canonical (sorted) multisig * must sort pubkeys before calling. */ static multisig(minNumPks: number, pubkeys: Uint8Array[]): Script; /** * Return true iff this script has the shape of a standard multisig output script * `OP_m pubkey_1 ... pubkey_N OP_N OP_CHECKMULTISIG` (fixed size: `N + 3` ops). */ isMultisig(): boolean; /** * Build scriptSig for multisig: sig1 sig2 ... sig_m [redeemScript]. * Omit redeemScript for bare multisig; include for P2SH-wrapped. * Use undefined for missing signatures (replaced with 0x01 placeholder). * For Schnorr sigs, pass pubkeyIndices (set of signer indices) to build the * checkbits dummy; signatures must be ordered by sorted pubkeyIndices. * The full set of signer indices must be known when building Schnorr format. * For partially signed inputs where the final signers are not yet known, * use ECDSA format (omit pubkeyIndices) until the full signer set is determined. * Ref spec https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/2019-11-15-schnorrmultisig.md */ static multisigSpend(params: { signatures: (Uint8Array | undefined)[]; redeemScript?: Script; pubkeyIndices?: Set; /** For bare Schnorr multisig: total pubkey count when redeemScript omitted */ numPubkeys?: number; }): Script; /** * Parse P2SH multisig spend script to extract signatures and redeem script. * Returns signatures (undefined for placeholder) and parsed numSignatures, numPubkeys from redeem script. * Supports both ECDSA (OP_0 + sigs) and Schnorr (checkbits + sigs) formats. * Schnorr format accepts partial scriptSigs (checkbits may have fewer bits set than * numSignatures when earlier signers may not yet know who else will sign). * Not for bare multisig (where the locking script is in output, not input). */ parseP2shMultisigSpend(): { signatures: (Uint8Array | undefined)[]; redeemScript: Script; numSignatures: number; numPubkeys: number; pubkeys: Uint8Array[]; isSchnorr: boolean; /** Indices of signers (0..numPubkeys-1) for Schnorr; undefined for ECDSA */ pubkeyIndices?: Set; }; /** * Parse bare multisig spend scriptSig to extract signatures. * For bare multisig the output script is the multisig script; the scriptSig * is [dummy] sig1 sig2 ... sig_m with no redeem script. * Assumes a fully-formed scriptSig (see parseP2shMultisigSpend for details). * @param outputScript - The multisig output script (OP_m pubkey1 ... pubkey_n OP_n OP_CHECKMULTISIG) */ parseBareMultisigSpend(outputScript: Script): { signatures: (Uint8Array | undefined)[]; numSignatures: number; numPubkeys: number; pubkeys: Uint8Array[]; isSchnorr: boolean; pubkeyIndices?: Set; }; /** Parse an OP_m ... OP_CHECKMULTISIG redeem script (used by multisig PSBT flows). */ parseMultisigRedeemScript(): { numSignatures: number; numPubkeys: number; pubkeys: Uint8Array[]; }; private static parseMultisigScriptSig; } /** Iterator over the Ops of a Script. */ export declare class ScriptOpIter { bytes: Bytes; constructor(bytes: Bytes); /** * Read the next Op and return it, or `undefined` if there are no more Ops. * Throws an error if reading the next op failed. */ next(): Op | undefined; } //# sourceMappingURL=script.d.ts.map