Transaction.ts
Transaction overview
Table of contents
encoding
addVKeyWitnesses
Add VKey witnesses to a transaction at the domain level.
This creates a new Transaction with the additional witnesses merged in. All encoding metadata (body bytes, redeemers format, witness map structure) is preserved so that txId and scriptDataHash remain stable.
Signature
export declare const addVKeyWitnesses: (
tx: Transaction,
witnesses: ReadonlyArray<TransactionWitnessSet.VKeyWitness>
) => TransactionAdded in v2.0.0
addVKeyWitnessesBytes
Merge wallet vkey witnesses into a transaction, preserving CBOR encoding.
Uses the WithFormat round-trip: decode with format capture, mutate at the domain level, re-encode with the original format tree. Body encoding, redeemer bytes, map key ordering, and all non-witness data are preserved through the format tree reconciliation.
A witness set without vkey witnesses gains the vkey witnesses key at its ascending position when its keys ascend, so a canonical transaction stays canonical; otherwise the key follows the decoded keys.
options applies only to parsing the wallet witness set bytes. Transaction
decoding and re-encoding are governed by the captured format tree, making
codec options irrelevant for the transaction round-trip path.
Signature
export declare const addVKeyWitnessesBytes: (
txBytes: Uint8Array,
walletWitnessSetBytes: Uint8Array,
options?: CBOR.CodecOptions
) => Uint8ArrayAdded in v2.0.0
addVKeyWitnessesHex
Hex variant of addVKeyWitnessesBytes.
Signature
export declare const addVKeyWitnessesHex: (
txHex: string,
walletWitnessSetHex: string,
options?: CBOR.CodecOptions
) => stringAdded in v2.0.0
extractBodyBytes
Extract the original body bytes from a raw transaction CBOR byte array.
A Cardano transaction is a 4-element CBOR array: [body, witnessSet, isValid, auxiliaryData].
This returns the raw body bytes without decoding/re-encoding, preserving the exact CBOR encoding.
Signature
export declare const extractBodyBytes: (txBytes: Uint8Array) => Uint8ArrayAdded in v2.0.0
toCBORBytesWithFormat
Convert a Transaction to CBOR bytes using an explicit root format tree.
The witness set is written as TransactionWitnessSet.toCBORBytesWithFormat
writes it.
Signature
export declare const toCBORBytesWithFormat: (data: Transaction, format: CBOR.CBORFormat) => Uint8ArrayAdded in v2.0.0
toCBORHexWithFormat
Convert a Transaction to CBOR hex string using an explicit root format tree,
as in toCBORBytesWithFormat.
Signature
export declare const toCBORHexWithFormat: (data: Transaction, format: CBOR.CBORFormat) => stringAdded in v2.0.0
withCodecOptions
Record the codec options for a transaction and return it. The transaction
is then encoded with these options when the caller passes none, so code
that writes it with the default options, such as a provider, writes the
bytes these options give. Options passed explicitly, other than
CBOR.TX_DEFAULT_OPTIONS and CBOR.CML_DEFAULT_OPTIONS, and the encoding
captured when the transaction was decoded take precedence.
Signature
export declare const withCodecOptions: (
tx: Transaction,
options: CBOR.TxCodecOptions | CBOR.CodecOptions
) => TransactionExample
import * as CBOR from "@evolution-sdk/evolution/CBOR"
import * as Transaction from "@evolution-sdk/evolution/Transaction"
import * as TransactionBody from "@evolution-sdk/evolution/TransactionBody"
import * as TransactionWitnessSet from "@evolution-sdk/evolution/TransactionWitnessSet"
const tx = new Transaction.Transaction({
body: new TransactionBody.TransactionBody({ inputs: [], outputs: [], fee: 0n }),
witnessSet: new TransactionWitnessSet.TransactionWitnessSet({}),
isValid: true,
auxiliaryData: null
})
const recorded = Transaction.withCodecOptions(tx, CBOR.TX_CANONICAL_OPTIONS)
// Same bytes as Transaction.toCBORHex(tx, CBOR.TX_CANONICAL_OPTIONS)
const hex = Transaction.toCBORHex(recorded)Added in v2.0.0
model
Transaction (class)
Transaction based on Conway CDDL specification
CDDL: transaction = [transaction_body, transaction_witness_set, bool, auxiliary_data / nil]
Signature
export declare class TransactionAdded in v2.0.0
toJSON (method)
Signature
toJSON()toString (method)
Signature
toString(): string[Inspectable.NodeInspectSymbol] (method)
Signature
[Inspectable.NodeInspectSymbol](): unknown[Equal.symbol] (method)
Signature
[Equal.symbol](that: unknown): boolean[Hash.symbol] (method)
Signature
[Hash.symbol](): numberparsing
fromCBORBytesWithFormat
Parse a Transaction from CBOR bytes and return the root format tree.
Signature
export declare const fromCBORBytesWithFormat: (bytes: Uint8Array) => CBOR.DecodedWithFormat<Transaction>Added in v2.0.0
fromCBORHexWithFormat
Parse a Transaction from CBOR hex string and return the root format tree.
Signature
export declare const fromCBORHexWithFormat: (hex: string) => CBOR.DecodedWithFormat<Transaction>Added in v2.0.0
utils
CDDLSchema
Conway CDDL schema for Transaction tuple structure.
CDDL: transaction = [transaction_body, transaction_witness_set, bool, auxiliary_data / nil]
Signature
export declare const CDDLSchema: Schema.declare<
readonly [Map<bigint, CBOR.CBOR>, Map<bigint, CBOR.CBOR>, boolean, CBOR.CBOR],
readonly [Map<bigint, CBOR.CBOR>, Map<bigint, CBOR.CBOR>, boolean, CBOR.CBOR],
readonly [],
never
>FromCBORBytes
CBOR bytes transformation schema for Transaction. The body and the witness
set are written as TransactionBody.FromCBORBytes(options) and
TransactionWitnessSet.FromCBORBytes(options) write them, the rest with
the ledger options. Plain options are read as CBOR.toTxCodecOptions
reads them.
Signature
export declare const FromCBORBytes: (
options?: CBOR.TxCodecOptions | CBOR.CodecOptions
) => Schema.transformOrFail<
typeof Schema.Uint8ArrayFromSelf,
Schema.SchemaClass<Transaction, Transaction, never>,
never
>FromCBORHex
CBOR hex transformation schema for Transaction, as in FromCBORBytes.
Signature
export declare const FromCBORHex: (
options?: CBOR.TxCodecOptions | CBOR.CodecOptions
) => Schema.transform<
Schema.Schema<Uint8Array, string, never>,
Schema.transformOrFail<typeof Schema.Uint8ArrayFromSelf, Schema.SchemaClass<Transaction, Transaction, never>, never>
>FromCDDL
Transform between CDDL tuple and Transaction class.
Signature
export declare const FromCDDL: Schema.transformOrFail<
Schema.declare<
readonly [Map<bigint, CBOR.CBOR>, Map<bigint, CBOR.CBOR>, boolean, CBOR.CBOR],
readonly [Map<bigint, CBOR.CBOR>, Map<bigint, CBOR.CBOR>, boolean, CBOR.CBOR],
readonly [],
never
>,
Schema.SchemaClass<Transaction, Transaction, never>,
never
>arbitrary
Signature
export declare const arbitrary: FastCheck.Arbitrary<Transaction>fromCBORBytes
Signature
export declare const fromCBORBytes: (bytes: Uint8Array, options?: CBOR.CodecOptions) => TransactionfromCBORHex
Signature
export declare const fromCBORHex: (hex: string, options?: CBOR.CodecOptions) => TransactiontoCBORBytes
Signature
export declare const toCBORBytes: (data: Transaction, options?: CBOR.TxCodecOptions | CBOR.CodecOptions) => Uint8ArraytoCBORHex
Signature
export declare const toCBORHex: (data: Transaction, options?: CBOR.TxCodecOptions | CBOR.CodecOptions) => string