import { Bytes } from './io/bytes.js'; import { Writer } from './io/writer.js'; import { Ecc } from './ecc.js'; import { Script } from './script.js'; import { SigHashType } from './sigHashType.js'; /** * Default value for nSequence of inputs if left undefined; this opts out of * BIP68 relative lock-time, and if all inputs have this value, nLockTime is * disabled, too. * * This is chosen as the default as it's the default in the node too, * see CTxIn in /src/primitives/transaction.h. **/ export declare const DEFAULT_SEQUENCE = 4294967295; /** Current tx version, see CTransaction in /stc/primitives/transaction.h */ export declare const DEFAULT_TX_VERSION = 2; /** COutPoint, pointing to a coin being spent. */ export interface OutPoint { /** * TxId of the output of the coin, either a big-endian hex encoded TxId * or a little-endian bytearray. **/ txid: string | Uint8Array; /** Index in the outputs of the tx of the coin. */ outIdx: number; } /** CTxIn, spending an unspent output. */ export interface TxInput { /** Points to an output being spent. */ prevOut: OutPoint; /** scriptSig unlocking the output, defaults to the empty Script. */ script?: Script; /** nSequence, defaults to 0xffffffff if unspecified. */ sequence?: number; /** Sign data required to sign an input */ signData?: SignData; } /** CTxOut, creating a new output. */ export interface TxOutput { /** Value in satoshis of the output (1 XEC = 100 satoshis) */ sats: bigint; /** Script locking the output */ script: Script; } /** All the data required to sign an input (using BIP143). */ export interface SignData { /** Value of the output being spent */ sats: bigint; /** Script of the output being spent (not for P2SH) */ outputScript?: Script; /** * For P2SH inputs, the preimage of the script hash locking the output being * spent. **/ redeemScript?: Script; } /** CTransaction, a Bitcoin transaction. */ export declare class Tx { /** nVersion of the tx */ version: number; /** vin, tx inputs spending outputs of other txs */ inputs: TxInput[]; /** vout, tx outputs created in this tx */ outputs: TxOutput[]; /** nLockTime of the tx, specifies when the tx can be mined earliest */ locktime: number; constructor(params?: { version?: number; inputs?: TxInput[]; outputs?: TxOutput[]; locktime?: number; }); /** Serialize the tx to a byte array */ ser(): Uint8Array; /** Serialize the tx to a hex string */ toHex(): string; /** Calculate the serialized size of the tx */ serSize(): number; /** Write the tx to the given writer */ write(writer: Writer): void; /** Deserialize a Tx from a Uint8Array */ static deser(data: Uint8Array): Tx; /** Deserialize a Tx from a hex string */ static fromHex(hex: string): Tx; /** * Compute the transaction ID (TxId) as a hex string (little-endian). * This follows the eCash convention: the TxId is the double SHA256 of the * serialized transaction, returned as a hex string in little-endian (reversed) order. * See the node src/primitives/txid.h for more details. */ txid(): string; /** * Attempt to parse a **non-SegWit** serialized transaction from `data` — the same * encoding as {@link Tx.deser} / `Tx.ser()` (version, inputs, outputs, locktime; * no witness marker or witness stacks). eCash does not use SegWit transactions, * so this is the full-transaction wire format on-chain here. Returns a `Tx` only * when `data` is **exactly** one such transaction: the parse must consume the * **entire** buffer (no trailing bytes). Returns `undefined` on malformed input * or if any bytes remain after `locktime`. * * **PSBT-only motivation:** Bitcoin ABC’s PSBT input key `0x00` (`PSBT_IN_UTXO`) * stores **either** a full previous transaction (BIP 174 “non-witness UTXO”) **or** * a compact `CTxOut` (amount + `scriptPubKey`). Callers must disambiguate. Plain * {@link Tx.deser} reads a tx from the start of `data` but **does not** require * `data.length` to match the serialized length — leftover bytes are ignored, so * you cannot use it to prove “this blob is solely a full tx.” This helper is * used from PSBT (`resolveWitnessFromKey00` in `psbt.ts`): if `tryDeserExact` * succeeds (and the txid matches), treat as non-witness UTXO; otherwise decode as * `CTxOut`-shaped bytes. */ static tryDeserExact(data: Uint8Array): Tx | undefined; /** * Add a signature to a partially-signed multisig input. * Verifies the signature against the sighash for each pubkey in the * redeem/output script and merges with existing signatures (which pubkey * signed is inferred from verification). */ addMultisigSignature(params: { inputIdx: number; signature: Uint8Array; signData: SignData; ecc?: Ecc; }): Tx; /** * Like {@link addMultisigSignature}, but computes the signature from a * secret key: BIP143 preimage (or legacy if `sigHashType` is legacy), * Schnorr for Schnorr-format multisig spends and ECDSA otherwise. */ addMultisigSignatureFromKey(params: { inputIdx: number; sk: Uint8Array; signData: SignData; /** Defaults to {@link ALL_BIP143}. */ sigHashType?: SigHashType; ecc?: Ecc; }): Tx; /** * Whether every **multisig** input (identified from `signData`) has enough * signatures in its scriptSig. Non-multisig inputs are ignored. * * If the transaction has **no** multisig inputs, this returns `true` (there * is nothing multisig-specific left to satisfy). That can look surprising on * a non-multisig or otherwise incomplete tx; this helper is **not** a * broadcast-readiness check. Call sites are expected to use it only in * multisig / PSBT flows where the question is specifically whether multisig * inputs still need more signatures (including mixed txs: non-multisig * inputs are finalized elsewhere). */ isFullySignedMultisig(): boolean; } export declare function readTxOutput(bytes: Bytes): TxOutput; /** Write an outpoint to a Writer */ export declare function writeOutPoint(outpoint: OutPoint, writer: Writer): void; /** Write a TxInput to a Writer */ export declare function writeTxInput(input: TxInput, writer: Writer): void; /** Write a TxOutput to a Writer */ export declare function writeTxOutput(output: TxOutput, writer: Writer): void; /** Create a deep copy of the TxInput */ export declare function copyTxInput(input: TxInput): TxInput; /** Create a deep copy of the TxOutput */ export declare function copyTxOutput(output: TxOutput): TxOutput; //# sourceMappingURL=tx.d.ts.map