import { IContext } from './types/context.js'; import { ByteString, SHPreimage } from './types/index.js'; import { Int32, PubKey, Sig, OpcatState } from './types/primitives.js'; import { BacktraceInfo } from './types/structs.js'; /** * The abstract class for a smart contract. * All of the abstract methods of it can be used directly inside a smart contract \@method. * @category SmartContract */ export declare abstract class AbstractContract { /** * Injected preimage signature for checkPreimage verification. * Set during _autoInject and used by checkSHPreimageImpl. * @internal */ _injectedPreimageSig?: Sig; /** * Using the [OP_PUSH_TX]{@link https://scryptplatform.medium.com/trustless-ordinal-sales-using-op-cat-enabled-covenants-on-bitcoin-0318052f02b2} technique, check if `shPreimage` is the preimage of the current transaction. * @onchain * @param shPreimage The format of the preimage * @returns true if `shPreimage` is the preimage of the current transaction. Otherwise false. */ abstract checkSHPreimage(shPreimage: SHPreimage): boolean; /** * A built-in function to create an change output. * @onchain * @returns the serialized change output byte string or empty byte string if there is no change. */ abstract buildChangeOutput(): ByteString; /** * A built-in function verifies an ECDSA signature. It takes two inputs from the stack, a public key (on top of the stack) and an ECDSA signature in its DER_CANONISED format concatenated with sighash flags. It outputs true or false on the stack based on whether the signature check passes or fails. * @onchain * @category Signature Verification * @see https://en.bitcoin.it/wiki/OP_CHECKSIG */ abstract checkSig(signature: Sig, publickey: PubKey, errorMsg?: string): boolean; /** * Verifies an ECDSA signature with an explicit sighash flag check. * This method validates that the signature's trailing sighash flag byte matches * the explicitly provided flag parameter before performing the signature verification. * * @param signature - The signature to verify (DER encoded with sighash flag appended) * @param publickey - The public key to verify the signature against * @param sigHashFlag - The expected sighash flag value (e.g., 1 for ALL, 2 for NONE, 129 for ANYONECANPAY_ALL) * @returns true if the flag matches AND the signature is valid, false otherwise * @onchain * @category Signature Verification */ abstract checkSigWithFlag(signature: Sig, publickey: PubKey, sigHashFlag: bigint): boolean; /** * Verifies an ECDSA signature against an explicit message and public key. * Unlike checkSig which uses the transaction preimage as the implicit message, * checkDataSig allows verifying signatures on arbitrary data. * * Uses OP_CHECKSIGFROMSTACK (0xba) under the hood. * Stack order: (bottom to top) * * @param signature - The signature to verify (DER encoded with sighash type) * @param message - The message that was signed (will be SHA256 hashed once) * @param publickey - The public key to verify the signature against * @returns true if the signature is valid, false otherwise * @onchain * @category Signature Verification */ abstract checkDataSig(signature: Sig, message: ByteString, publickey: PubKey): boolean; /** * Implements an absolute time-based lock on a transaction until a specified `locktime` has been reached. * The lock can be based on either block height or a UNIX timestamp. * * If the `locktime` is below 500,000,000, it's interpreted as a block height. Otherwise, * it's interpreted as a UNIX timestamp. This function checks and ensures that the transaction's * nSequence is less than `UINT_MAX`, and that the provided `locktime` has been reached or passed. * * @param {bigint} locktime - The block height or timestamp until which the transaction should be locked. * @returns If `true` is returned, nlockTime and sequence in `this.ctx` are valid, otherwise they are invalid. * @onchain * @category Time Lock * @see https://docs.opcatlabs.io/tutorials/timeLock */ abstract timeLock(locktime: bigint): boolean; /** * Build the state related outputs. * @returns the serialized outputs (state hash root output + other state outputs) * @onchain * @category State * */ /** * Check the outputs with the context of current transaction. * @param outputs the expected serialized outputs of the current transaction * @returns true if the outputs are not consistent with the transaction context, otherwise false. * @onchain */ abstract checkOutputs(outputs: ByteString): boolean; /** * The context of the current spending contract input. * It contains the preimage of the current transaction and other context information for the contract input. * @onchain */ abstract ctx: IContext; /** * Calculate the hash of the contract state. * @param state the state of the contract * @returns the hash byte string of the contract state * @onchain * @category State */ static serializeState(_state: ST): ByteString; static stateHash(_state: ST): ByteString; /** * Check the validity of an input state by verifying its committed state hash. * @param inputIndex the index of the input * @param rawState the raw/serialized state of the input * @returns true if the input state is correct. Otherwise false. * @onchain * @category State */ abstract checkInputState(inputIndex: Int32, rawState: ByteString): boolean; /** * Check whether the contract can be traced back to the genesis outpoint. * @param backtraceInfo the backtrace info to verify, including prevTx and prevPrevTx informations * @param genesisOutpoint expected genesis outpoint to be traced back to * @returns true if the contract can be backtraced to the genesis outpoint. Otherwise false. * @onchain * @category Backtrace */ abstract backtraceToOutpoint(backtraceInfo: BacktraceInfo, genesisOutpoint: ByteString): boolean; /** * Check whether the contract can be traced back to the genesis script. * @param backtraceInfo the backtrace info to verify, including prevTx and prevPrevTx informations * @param genesisScript expected genesis script to be traced back to * @returns true if the contract can be backtraced to the genesis script. Otherwise false. * @onchain * @category Backtrace */ abstract backtraceToScript(backtraceInfo: BacktraceInfo, genesisScript: ByteString): boolean; } //# sourceMappingURL=abstractContract.d.ts.map