UNPKG

@bsv/sdk

Version:

BSV Blockchain Software Development Kit

148 lines 5.08 kB
import ScriptChunk from './ScriptChunk.js'; import BigNumber from '../primitives/BigNumber.js'; /** * The Script class represents a script in a Bitcoin SV transaction, * encapsulating the functionality to construct, parse, and serialize * scripts used in both locking (output) and unlocking (input) scripts. * * @property {ScriptChunk[]} chunks - An array of script chunks that make up the script. */ export default class Script { chunks: ScriptChunk[]; /** * @method fromASM * Static method to construct a Script instance from an ASM (Assembly) formatted string. * @param asm - The script in ASM string format. * @returns A new Script instance. * @example * const script = Script.fromASM("OP_DUP OP_HASH160 abcd... OP_EQUALVERIFY OP_CHECKSIG") */ static fromASM(asm: string): Script; /** * @method fromHex * Static method to construct a Script instance from a hexadecimal string. * @param hex - The script in hexadecimal format. * @returns A new Script instance. * @example * const script = Script.fromHex("76a9..."); */ static fromHex(hex: string): Script; /** * @method fromBinary * Static method to construct a Script instance from a binary array. * @param bin - The script in binary array format. * @returns A new Script instance. * @example * const script = Script.fromBinary([0x76, 0xa9, ...]) */ static fromBinary(bin: number[]): Script; /** * @constructor * Constructs a new Script object. * @param chunks=[] - An array of script chunks to directly initialize the script. */ constructor(chunks?: ScriptChunk[]); /** * @method toASM * Serializes the script to an ASM formatted string. * @returns The script in ASM string format. */ toASM(): string; /** * @method toHex * Serializes the script to a hexadecimal string. * @returns The script in hexadecimal format. */ toHex(): string; /** * @method toBinary * Serializes the script to a binary array. * @returns The script in binary array format. */ toBinary(): number[]; /** * @method writeScript * Appends another script to this script. * @param script - The script to append. * @returns This script instance for chaining. */ writeScript(script: Script): Script; /** * @method writeOpCode * Appends an opcode to the script. * @param op - The opcode to append. * @returns This script instance for chaining. */ writeOpCode(op: number): Script; /** * @method setChunkOpCode * Sets the opcode of a specific chunk in the script. * @param i - The index of the chunk. * @param op - The opcode to set. * @returns This script instance for chaining. */ setChunkOpCode(i: number, op: number): Script; /** * @method writeBn * Appends a BigNumber to the script as an opcode. * @param bn - The BigNumber to append. * @returns This script instance for chaining. */ writeBn(bn: BigNumber): Script; /** * @method writeBin * Appends binary data to the script, determining the appropriate opcode based on length. * @param bin - The binary data to append. * @returns This script instance for chaining. * @throws {Error} Throws an error if the data is too large to be pushed. */ writeBin(bin: number[]): Script; /** * @method writeNumber * Appends a number to the script. * @param num - The number to append. * @returns This script instance for chaining. */ writeNumber(num: number): Script; /** * @method removeCodeseparators * Removes all OP_CODESEPARATOR opcodes from the script. * @returns This script instance for chaining. */ removeCodeseparators(): Script; /** * Deletes the given item wherever it appears in the current script. * * @param script - The script containing the item to delete from the current script. * * @returns This script instance for chaining. */ findAndDelete(script: Script): Script; /** * @method isPushOnly * Checks if the script contains only push data operations. * @returns True if the script is push-only, otherwise false. */ isPushOnly(): boolean; /** * @method isLockingScript * Determines if the script is a locking script. * @returns True if the script is a locking script, otherwise false. */ isLockingScript(): boolean; /** * @method isUnlockingScript * Determines if the script is an unlocking script. * @returns True if the script is an unlocking script, otherwise false. */ isUnlockingScript(): boolean; /** * @private * @method _chunkToString * Converts a script chunk to its string representation. * @param chunk - The script chunk. * @returns The string representation of the chunk. */ private _chunkToString; } //# sourceMappingURL=Script.d.ts.map