UNPKG

@bsv/sdk

Version:

BSV Blockchain Software Development Kit

119 lines 5.67 kB
import LockingScript from './LockingScript.js'; import UnlockingScript from './UnlockingScript.js'; import TransactionInput from '../transaction/TransactionInput.js'; import TransactionOutput from '../transaction/TransactionOutput.js'; /** * The Spend class represents a spend action within a Bitcoin SV transaction. * It encapsulates all the necessary data required for spending a UTXO (Unspent Transaction Output) * and includes details about the source transaction, output, and the spending transaction itself. * * @property {string} sourceTXID - The transaction ID of the source UTXO. * @property {number} sourceOutputIndex - The index of the output in the source transaction. * @property {BigNumber} sourceSatoshis - The amount of satoshis in the source UTXO. * @property {LockingScript} lockingScript - The locking script associated with the UTXO. * @property {number} transactionVersion - The version of the current transaction. * @property {Array<{ sourceTXID: string, sourceOutputIndex: number, sequence: number }>} otherInputs - * An array of other inputs in the transaction, each with a txid, outputIndex, and sequence number. * @property {Array<{ satoshis: BigNumber, lockingScript: LockingScript }>} outputs - * An array of outputs of the current transaction, including the satoshi value and locking script for each. * @property {number} inputIndex - The index of this input in the current transaction. * @property {UnlockingScript} unlockingScript - The unlocking script that unlocks the UTXO for spending. * @property {number} inputSequence - The sequence number of this input. * @property {number} lockTime - The lock time of the transaction. */ export default class Spend { sourceTXID: string; sourceOutputIndex: number; sourceSatoshis: number; lockingScript: LockingScript; transactionVersion: number; otherInputs: TransactionInput[]; outputs: TransactionOutput[]; inputIndex: number; unlockingScript: UnlockingScript; inputSequence: number; lockTime: number; context: 'UnlockingScript' | 'LockingScript'; programCounter: number; lastCodeSeparator: number | null; stack: number[][]; altStack: number[][]; ifStack: boolean[]; memoryLimit: number; stackMem: number; altStackMem: number; /** * @constructor * Constructs the Spend object with necessary transaction details. * @param {string} params.sourceTXID - The transaction ID of the source UTXO. * @param {number} params.sourceOutputIndex - The index of the output in the source transaction. * @param {BigNumber} params.sourceSatoshis - The amount of satoshis in the source UTXO. * @param {LockingScript} params.lockingScript - The locking script associated with the UTXO. * @param {number} params.transactionVersion - The version of the current transaction. * @param {Array<{ sourceTXID: string, sourceOutputIndex: number, sequence: number }>} params.otherInputs - * An array of other inputs in the transaction. * @param {Array<{ satoshis: BigNumber, lockingScript: LockingScript }>} params.outputs - * The outputs of the current transaction. * @param {number} params.inputIndex - The index of this input in the current transaction. * @param {UnlockingScript} params.unlockingScript - The unlocking script for this spend. * @param {number} params.inputSequence - The sequence number of this input. * @param {number} params.lockTime - The lock time of the transaction. * * @example * const spend = new Spend({ * sourceTXID: "abcd1234", // sourceTXID * sourceOutputIndex: 0, // sourceOutputIndex * sourceSatoshis: new BigNumber(1000), // sourceSatoshis * lockingScript: LockingScript.fromASM("OP_DUP OP_HASH160 abcd1234... OP_EQUALVERIFY OP_CHECKSIG"), * transactionVersion: 1, // transactionVersion * otherInputs: [{ sourceTXID: "abcd1234", sourceOutputIndex: 1, sequence: 0xffffffff }], // otherInputs * outputs: [{ satoshis: new BigNumber(500), lockingScript: LockingScript.fromASM("OP_DUP...") }], // outputs * inputIndex: 0, // inputIndex * unlockingScript: UnlockingScript.fromASM("3045... 02ab..."), * inputSequence: 0xffffffff // inputSequence * memoryLimit: 100000 // memoryLimit * }); */ constructor(params: { sourceTXID: string; sourceOutputIndex: number; sourceSatoshis: number; lockingScript: LockingScript; transactionVersion: number; otherInputs: TransactionInput[]; outputs: TransactionOutput[]; unlockingScript: UnlockingScript; inputSequence: number; inputIndex: number; lockTime: number; memoryLimit?: number; }); reset(): void; private ensureStackMem; private ensureAltStackMem; private pushStack; private pushStackCopy; private popStack; private stackTop; private pushAltStack; private popAltStack; private checkSignatureEncoding; private checkPublicKeyEncoding; private verifySignature; step(): boolean; /** * @method validate * Validates the spend action by interpreting the locking and unlocking scripts. * @returns {boolean} Returns true if the scripts are valid and the spend is legitimate, otherwise false. * @example * if (spend.validate()) { * console.log("Spend is valid!"); * } else { * console.log("Invalid spend!"); * } */ validate(): boolean; private castToBool; private scriptEvaluationError; } //# sourceMappingURL=Spend.d.ts.map