import type { AuthenticationInstruction, AuthenticationInstructionMalformed, AuthenticationInstructionMaybeMalformed, AuthenticationInstructionPush, AuthenticationInstructions, AuthenticationInstructionsMalformed, AuthenticationInstructionsMaybeMalformed, Output, ReadPosition } from '../../../lib.js'; /** * A type-guard that checks if the provided instruction is malformed. * @param instruction - the instruction to check */ export declare const authenticationInstructionIsMalformed: (instruction: AuthenticationInstructionMaybeMalformed) => instruction is AuthenticationInstructionMalformed; /** * A type-guard that checks if the final instruction in the provided array of * instructions is malformed. (Only the final instruction can be malformed.) * @param instructions - the array of instructions to check */ export declare const authenticationInstructionsAreMalformed: (instructions: AuthenticationInstructionsMaybeMalformed) => instructions is AuthenticationInstructionsMalformed; export declare const authenticationInstructionsArePushInstructions: (instructions: AuthenticationInstructions) => instructions is AuthenticationInstructionPush[]; declare const uint8Bytes = 1; declare const uint16Bytes = 2; declare const uint32Bytes = 4; /** * Read a little endian number of `length` from the provided * {@link ReadPosition}. * * @param position - the {@link ReadPosition} at which to start reading * @param length - the length of the little endian number to read */ export declare const readLittleEndianNumber: (position: ReadPosition, length: typeof uint8Bytes | typeof uint16Bytes | typeof uint32Bytes) => number; /** * Returns the number of bytes used to indicate the length of the push in this * operation. * @param opcode - an opcode between 0x00 and 0xff */ export declare const opcodeToPushLength: (opcode: number) => typeof uint8Bytes | typeof uint16Bytes | typeof uint32Bytes | 0; /** * Decode one virtual machine bytecode instruction from the * provided {@link ReadPosition}. * * Returns an object with an `instruction` referencing a * {@link AuthenticationInstructionMaybeMalformed} and the next position. * * If the next index is greater than or equal to the length of the bytecode, the * bytecode has been fully decoded. * * The final {@link AuthenticationInstructionMaybeMalformed} in the bytecode may * be malformed if 1) the final operation is a push and 2) too few bytes remain * for the push operation to complete. * * @param position - the {@link ReadPosition} at which to start reading */ export declare const readAuthenticationInstruction: (position: ReadPosition) => { instruction: AuthenticationInstructionMaybeMalformed; position: ReadPosition; }; /** * @param instruction - the {@link AuthenticationInstruction} to clone. * @returns A copy of the provided {@link AuthenticationInstruction}. * * @deprecated use `structuredClone` instead */ export declare const cloneAuthenticationInstruction: (instruction: AuthenticationInstruction) => AuthenticationInstruction; /** * Decode authentication virtual machine bytecode (`lockingBytecode` or * `unlockingBytecode`) into {@link AuthenticationInstructionsMaybeMalformed}. * The method {@link authenticationInstructionsAreMalformed} can be used to * check if these instructions include a malformed instruction. If not, they are * valid {@link AuthenticationInstructions}. * * @param bytecode - the authentication virtual machine bytecode to decode */ export declare const decodeAuthenticationInstructions: (bytecode: Uint8Array) => AuthenticationInstructionsMaybeMalformed; /** * Disassemble a malformed authentication instruction into a string description. * @param opcodes - a mapping of possible opcodes to their string representation * @param instruction - the {@link AuthenticationInstructionMalformed} to * disassemble */ export declare const disassembleAuthenticationInstructionMalformed: (opcodes: { [opcode: number]: string; }, instruction: AuthenticationInstructionMalformed) => string; /** * Disassemble a properly-formed authentication instruction into a string * description. * @param opcodes - a mapping of possible opcodes to their string representation * @param instruction - the instruction to disassemble */ export declare const disassembleAuthenticationInstruction: (opcodes: { [opcode: number]: string; }, instruction: AuthenticationInstruction) => string; /** * Disassemble a single {@link AuthenticationInstructionMaybeMalformed} into its * ASM representation. * * @param opcodes - a mapping of possible opcodes to their string representation * @param instruction - the instruction to disassemble */ export declare const disassembleAuthenticationInstructionMaybeMalformed: (opcodes: { [opcode: number]: string; }, instruction: AuthenticationInstructionMaybeMalformed) => string; /** * Disassemble an array of {@link AuthenticationInstructionMaybeMalformed} * (including potentially malformed instructions) into its ASM representation. * * This method supports disassembling an array including multiple * {@link AuthenticationInstructionMaybeMalformed}s, rather than the more * constrained {@link AuthenticationInstructionsMaybeMalformed} (may only * include one malformed instruction as the last item in the array). * * @param opcodes - a mapping of possible opcodes to their string representation * @param instructions - the array of instructions to disassemble */ export declare const disassembleAuthenticationInstructionsMaybeMalformed: (opcodes: { [opcode: number]: string; }, instructions: AuthenticationInstructionMaybeMalformed[]) => string; /** * Disassemble authentication bytecode into a lossless ASM representation. (All * push operations are represented with the same opcodes used in the bytecode, * even when non-minimally encoded.) * * For the reverse, see {@link assembleBytecode}. * * @param opcodes - a mapping of possible opcodes to their string representation * @param bytecode - the authentication bytecode to disassemble */ export declare const disassembleBytecode: (opcodes: { [opcode: number]: string; }, bytecode: Uint8Array) => string; /** * Disassemble BCH authentication bytecode into its ASM representation. * * Note, this method automatically uses the latest BCH instruction set. To * manually select an instruction set, use {@link disassembleBytecode}. * * For the reverse, see {@link assembleBytecodeBCH}. * * @param bytecode - the virtual machine bytecode to disassemble */ export declare const disassembleBytecodeBCH: (bytecode: Uint8Array) => string; /** * Disassemble BTC authentication bytecode into its ASM representation. * * Note, this method automatically uses the latest BTC instruction set. To * manually select an instruction set, use {@link disassembleBytecode}. * * For the reverse, see {@link assembleBytecodeBTC}. * * @param bytecode - the virtual machine bytecode to disassemble */ export declare const disassembleBytecodeBTC: (bytecode: Uint8Array) => string; /** * Create an object where each key is an opcode identifier and each value is * the bytecode value (`Uint8Array`) it represents. * @param opcodes - An opcode enum, e.g. {@link OpcodesBCH} */ export declare const generateBytecodeMap: (opcodes: { [opcode: string]: unknown; }) => { [opcode: string]: Uint8Array; }; /** * Re-encode a valid authentication instruction. * @param instruction - the instruction to encode */ export declare const encodeAuthenticationInstruction: (instruction: AuthenticationInstruction) => Uint8Array; /** * Re-encode a malformed authentication instruction. * @param instruction - the {@link AuthenticationInstructionMalformed} to encode */ export declare const encodeAuthenticationInstructionMalformed: (instruction: AuthenticationInstructionMalformed) => Uint8Array; /** * Re-encode a potentially-malformed authentication instruction. * @param instruction - the {@link AuthenticationInstructionMaybeMalformed} * to encode */ export declare const encodeAuthenticationInstructionMaybeMalformed: (instruction: AuthenticationInstructionMaybeMalformed) => Uint8Array; /** * Re-encode an array of valid authentication instructions. * @param instructions - the array of valid instructions to encode */ export declare const encodeAuthenticationInstructions: (instructions: AuthenticationInstruction[]) => Uint8Array; /** * Re-encode an array of potentially-malformed authentication instructions. * @param instructions - the array of * {@link AuthenticationInstructionMaybeMalformed}s to encode */ export declare const encodeAuthenticationInstructionsMaybeMalformed: (instructions: AuthenticationInstructionMaybeMalformed[]) => Uint8Array; export declare enum VmNumberError { outOfRange = "Failed to decode VM Number: overflows VM Number range.", requiresMinimal = "Failed to decode VM Number: the number is not minimally-encoded." } export declare const isVmNumberError: (value: VmNumberError | bigint) => value is VmNumberError; /** * This method attempts to decode a VM Number, a format in which numeric values * are represented on the stack. (The Satoshi implementation calls this * `CScriptNum`.) * * If `bytes` is a valid VM Number, this method returns the represented number * in BigInt format. If `bytes` is not valid, a {@link VmNumberError} * is returned. * * All common operations accepting numeric parameters or pushing numeric values * to the stack currently use the VM Number format. The binary format of numbers * wouldn't be important if they could only be operated on by arithmetic * operators, but since the results of these operations may become input to * other operations (e.g. hashing), the specific representation is consensus- * critical. * * For the reverse, see {@link bigIntToVmNumber}. * * @param bytes - a Uint8Array from the stack */ export declare const vmNumberToBigInt: (bytes: Uint8Array, { maximumVmNumberByteLength, requireMinimalEncoding, }?: { /** * The maximum valid number of bytes in a VM Number. */ maximumVmNumberByteLength?: number | undefined; /** * If `true`, this method returns an error when parsing non-minimally * encoded VM Numbers. */ requireMinimalEncoding?: boolean | undefined; }) => VmNumberError | bigint; /** * Convert a BigInt into the VM Number format. See {@link vmNumberToBigInt} for * more information. * * For the reverse, use {@link vmNumberToBigInt}. * * @param integer - the BigInt to encode as a VM Number */ export declare const bigIntToVmNumber: (integer: bigint) => Uint8Array; /** * Returns true if the provided stack item is "truthy" in the sense required * by several operations (anything but zero and "negative zero"). * * The Satoshi implementation calls this method `CastToBool`. * * To cast a boolean value to a stack item (VM number), * use {@link booleanToVmNumber}. * * @param item - the stack item to check for truthiness */ export declare const stackItemIsTruthy: (item: Uint8Array) => boolean; /** * Convert a boolean into VM Number format (the type used to express * boolean values emitted by several operations). * * For the less-strict inverse used by the VM, see {@link stackItemIsTruthy}. * * @param value - the boolean value to convert */ export declare const booleanToVmNumber: (value: boolean) => Uint8Array; /** * From C++ implementation: * Note that IsPushOnly() *does* consider OP_RESERVED to be a push-type * opcode, however execution of OP_RESERVED fails, so it's not relevant to * P2SH/BIP62 as the scriptSig would fail prior to the P2SH special * validation code being executed. */ export declare const isPushOperation: (opcode: number) => boolean; export declare const isPushOnly: (bytecode: Uint8Array) => boolean; export declare const isPushOnlyAccurate: (bytecode: Uint8Array) => boolean; /** * Test if the provided locking bytecode is an arbitrary data output (A.K.A. * `TX_NULL_DATA`, "data carrier", or OP_RETURN output). * @param lockingBytecode - the locking bytecode to test */ export declare const isArbitraryDataOutput: (lockingBytecode: Uint8Array) => boolean; /** * Given a number of bytes and a fee rate in satoshis-per-kilobyte, return the * minimum required fee. This calculation is important for standardness in dust * threshold calculation. * * @param length - the number of bytes for which the fee is to be paid * @param feeRateSatsPerKb - the fee rate in satoshis per 1000 bytes */ export declare const getMinimumFee: (length: bigint, feeRateSatsPerKb: bigint) => bigint; /** * Given an encoded output length, return the minimum output value in satoshis * required to exceed the dust threshold. See {@link getDustThreshold} * for details. * * Most applications should instead use {@link getDustThreshold} to ensure * proper encoding and proper treatment of arbitrary data outputs * ({@link isArbitraryDataOutput}). * * @param outputLength - the length of the serialized output * @param dustRelayFeeSatPerKb - the "dust relay fee", defaults to `1000n` */ export declare const getDustThresholdForLength: (outputLength: number, dustRelayFeeSatPerKb?: bigint) => bigint; /** * Given an {@link Output} and (optionally) a dust relay fee in * satoshis-per-kilobyte, return the minimum satoshi value for this output to * not be considered a "dust output". **For nodes to relay or mine a transaction * with this output, the output must have a satoshi value greater than or equal * to this threshold.** * * By standardness, if an output is expected to cost more than 1/3 of it's value * in fees to spend, it is considered dust. When calculating the expected fee, * the input size is assumed to be (at least) the size of a typical P2PKH input * spent using a 72-byte ECDSA signature, 148 bytes: * - Outpoint transaction hash: 32 bytes * - Outpoint index: 4 bytes * - Unlocking bytecode length: 1 byte * - Push of 72-byte ECDSA signature: 72 + 1 byte * - Push of public key: 33 + 1 byte * - Sequence number: 4 bytes * * The encoded length of the serialized output is added to 148 bytes, and the * dust threshold for the output is 3 times the minimum fee for the total bytes. * For a P2PKH output (34 bytes) and the standard 1000 sat/Kb dust relay fee, * this results in a dust limit of `546` satoshis (`(34+148)*3*1000/1000`). * * Note, arbitrary data outputs are not required to meet the dust limit as * they are provably unspendable and can be pruned from the UTXO set. * * @param output - the output to test * @param dustRelayFeeSatPerKb - the "dust relay fee", defaults to `1000n` */ export declare const getDustThreshold: (output: Output, dustRelayFeeSatPerKb?: bigint) => bigint; /** * Given an {@link Output} and (optionally) a dust relay fee in * satoshis-per-kilobyte, return `true` if the provided output is considered * a "dust output", or `false` otherwise. * * @param output - the output to test * @param dustRelayFeeSatPerKb - the "dust relay fee", defaults to `1000n` */ export declare const isDustOutput: (output: Output, dustRelayFeeSatPerKb?: bigint) => boolean; export declare const isValidUncompressedPublicKeyEncoding: (publicKey: Uint8Array) => boolean; export declare const isValidCompressedPublicKeyEncoding: (publicKey: Uint8Array) => boolean; export declare const isValidPublicKeyEncoding: (publicKey: Uint8Array) => boolean; export declare const pushNumberOpcodeToNumber: (opcode: number) => number | false; export declare const isSimpleMultisig: (lockingBytecode: Uint8Array) => false | { m: number; n: number; publicKeys: Uint8Array[]; }; export declare const isStandardMultisig: (lockingBytecode: Uint8Array) => boolean; export declare const isStandardOutputBytecode: (lockingBytecode: Uint8Array) => boolean; export declare const isStandardOutputBytecode2023: (lockingBytecode: Uint8Array) => boolean; /** * Test a stack item for the SegWit Recovery Rules activated in `BCH_2019_05`. * * @param bytecode - the stack item to test */ export declare const isWitnessProgram: (bytecode: Uint8Array) => boolean; export {}; //# sourceMappingURL=instruction-sets-utils.d.ts.map