import { Buffer32, RawAnchor, RawTxId, Buffer28, RawCredential, } from "../types"; import { RawValue } from "./value"; export interface TypedMap extends Omit, 'get' | 'set'> { get(key: K): T[K] | undefined; set(key: K, value: T[K]): this; // Re-add standard Map methods you might need so they don't break has(key: keyof T): boolean; forEach(callbackfn: (value: T[keyof T], key: keyof T, map: Map) => void): void; readonly size: number; } // --- Primitives & Common Types --- export type RawCoin = bigint | number; export type RawSlot = bigint | number; export type RawEpoch = number; export type RawNetworkId = 0 | 1; // --- Plutus Data (Recursive) --- export type RawPlutusData = | [tag: 0, constr: [tag: bigint, fields: RawPlutusData[]]] // #6.121 - #6.127 & #6.102 | [tag: 1, map: Map] // {* plutus_data => plutus_data} | [tag: 2, list: RawPlutusData[]] // [* plutus_data] | [tag: 3, int: bigint] // big_int (int / big_uint / big_nint) | [tag: 4, bytes: Buffer]; // bounded_bytes // --- Native Scripts (Corrected Sum Type) --- export type RawNativeScript = | [tag: 0, key_hash: Buffer28] | [tag: 1, all_scripts: RawNativeScript[]] | [tag: 2, any_scripts: RawNativeScript[]] | [tag: 3, n: number, scripts: RawNativeScript[]] | [tag: 4, invalid_before: RawSlot] | [tag: 5, invalid_hereafter: RawSlot]; // --- Scripts (Labeled Sum Type) --- export type RawScript = | [tag: 0, native_script: RawNativeScript] | [tag: 1, plutus_v1_script: Buffer] | [tag: 2, plutus_v2_script: Buffer] | [tag: 3, plutus_v3_script: Buffer]; // --- Governance (Labeled Rational & ID) --- /** * A unit interval is represented as a rational number [#6.30([uint, uint])] * where numerator <= denominator. */ export type RawUnitInterval = [numerator: bigint, denominator: bigint]; /** * Unique identifier for a governance action. */ export type RawGovActionId = [transaction_id: Buffer32, gov_action_index: number]; // --- Voters (Labeled Sum Type) --- export type RawVoter = | [tag: 0, committee_key_hash: Buffer28] | [tag: 1, committee_script_hash: Buffer28] | [tag: 2, drep_key_hash: Buffer28] | [tag: 3, drep_script_hash: Buffer28] | [tag: 4, stake_pool_key_hash: Buffer28]; export type RawVote = 0 | 1 | 2; // No, Yes, Abstain export type RawVotingProcedure = [vote: RawVote, anchor: RawAnchor | null]; export type RawVotingProcedures = Map>; export interface RawProtocolParamUpdateMap { 0?: RawCoin; 1?: RawCoin; 2?: number; 3?: number; 4?: number; 5?: RawCoin; 6?: RawCoin; 7?: number; 8?: number; 9?: RawUnitInterval; 10?: RawUnitInterval; 11?: RawUnitInterval; 16?: RawCoin; 17?: RawCoin; 18?: Map; // cost_models 19?: [RawUnitInterval, RawUnitInterval]; // ex_unit_prices 20?: RawExUnits; 21?: RawExUnits; 22?: number; 23?: number; 24?: number; 25?: RawUnitInterval[]; // pool_voting_thresholds 26?: RawUnitInterval[]; // drep_voting_thresholds 27?: number; 28?: number; 29?: number; 30?: RawCoin; 31?: RawCoin; 32?: number; 33?: RawUnitInterval; } export type RawProtocolParamUpdate = TypedMap; export type RawGovAction = | [tag: 0, action_id: RawTxId | null, params: RawProtocolParamUpdate, guardrail: Buffer28 | null] // ParameterChange | [tag: 1, action_id: RawTxId | null, protocol_version: [major: number, minor: number]] // HardFork | [tag: 2, withdrawals: Map, guardrail: Buffer28 | null] // TreasuryWithdrawals | [tag: 3, action_id: RawTxId | null] // NoConfidence | [tag: 4, action_id: RawTxId | null, members_to_remove: Buffer28[], members_to_add: Map, threshold: RawUnitInterval] // UpdateCommittee | [tag: 5, action_id: RawTxId | null, constitution: [anchor: RawAnchor, guardrail: Buffer28 | null]] // NewConstitution | [tag: 6]; // InfoAction export type RawProposalProcedure = [deposit: RawCoin, reward_account: Buffer, gov_action: RawGovAction, anchor: RawAnchor]; // --- Certificates --- export type RawDRep = [0, Buffer28] | [1, Buffer28] | [2] | [3]; // --- Relays (Corrected Sum Type) --- export type RawRelay = | [tag: 0, port: number | null, ipv4: Buffer | null, ipv6: Buffer | null] | [tag: 1, port: number | null, dns_name: string] | [tag: 2, dns_name: string]; /** * Supporting types specifically for PoolParams */ export type RawPoolMetadata = [ url: string, metadata_hash: Buffer32 ]; export type RawPoolParams = [ operator: Buffer28, // pool_keyhash vrf_keyhash: Buffer32, // vrf_keyhash pledge: RawCoin, // coin cost: RawCoin, // coin margin: RawUnitInterval, // unit_interval (#6.30 tagged rational) reward_account: Buffer, // reward_account (bytes) pool_owners: Set, // set (#6.258 tagged set) relays: RawRelay[], // [* relay] pool_metadata: RawPoolMetadata | null // pool_metadata / nil ]; export type RawCertificate = | [tag: 0, credential: RawCredential] // Reg | [tag: 1, credential: RawCredential] // Unreg | [tag: 2, credential: RawCredential, pool_keyhash: Buffer28] // Delegate Stake | [tag: 3, pool_params: RawPoolParams] // Pool Reg (Simplified PoolParams) | [tag: 4, pool_keyhash: Buffer28, epoch: RawEpoch] // Pool Retire | [tag: 7, credential: RawCredential, deposit: RawCoin] // Reg Deposit | [tag: 8, credential: RawCredential, deposit: RawCoin] // Unreg Deposit | [tag: 9, credential: RawCredential, drep: RawDRep] // Delegate DRep | [tag: 10, credential: RawCredential, pool_keyhash: Buffer28, drep: RawDRep] // Delegate Stake + DRep | [tag: 11, credential: RawCredential, pool_keyhash: Buffer28, deposit: RawCoin] // Reg + Delegate Stake | [tag: 12, credential: RawCredential, drep: RawDRep, deposit: RawCoin] // Reg + Delegate DRep | [tag: 13, credential: RawCredential, pool_keyhash: Buffer28, drep: RawDRep, deposit: RawCoin] // Reg + Stake + DRep | [tag: 14, cold_credential: RawCredential, hot_credential: RawCredential] // Committee Auth | [tag: 15, cold_credential: RawCredential, anchor: RawAnchor | null] // Committee Resign | [tag: 16, drep_credential: RawCredential, deposit: RawCoin, anchor: RawAnchor | null] // DRep Reg | [tag: 17, drep_credential: RawCredential, deposit: RawCoin] // DRep Unreg | [tag: 18, drep_credential: RawCredential, anchor: RawAnchor | null]; // DRep Update // --- Transaction Body --- export interface RawTxBodyMap { 0: RawTxId[]; // inputs 1: RawTransactionOutput[]; // outputs 2: RawCoin; // fee 3?: RawSlot; // ttl 4?: RawCertificate[]; // certificates 5?: Map; // withdrawals 7?: Buffer32; // auxiliary_data_hash 8?: RawSlot; // validity_interval_start 9?: Map>; // mint 11?: Buffer32; // script_data_hash 13?: RawTxId[]; // collateral 14?: Buffer28[]; // required_signers 15?: RawNetworkId; // network_id 16?: RawTransactionOutput; // collateral_return 17?: RawCoin; // total_collateral 18?: RawTxId[]; // reference_inputs 19?: RawVotingProcedures; // voting_procedures 20?: RawProposalProcedure[]; // proposal_procedures 21?: RawCoin; // current_treasury_value 22?: RawCoin; // donation } export type RawTxBody = TypedMap; // --- Transaction Output --- export interface RawBabbageTransactionOutputMap { 0: Buffer; // address 1: RawValue; // value 2?: [0, Buffer32] | [1, RawPlutusData]; // datum_option 3?: Buffer; // script_ref } export type RawBabbageTransactionOutput = TypedMap; export type RawTransactionOutput = [Buffer, RawValue, Buffer32?] | RawBabbageTransactionOutput; // --- Witness Set --- export interface RawExUnits { mem: bigint; steps: bigint; } export type RawRedeemerTag = 0 | 1 | 2 | 3 | 4 | 5; export type RawRedeemer = [RawRedeemerTag, number, RawPlutusData, RawExUnits]; export interface RawTxWitnessSetMap { 0?: [Buffer, Buffer][]; // vkey witnesses 1?: RawNativeScript[]; 2?: [Buffer, Buffer, Buffer, Buffer][]; // bootstrap witnesses 3?: Buffer[]; // plutus v1 4?: RawPlutusData[]; 5?: RawRedeemer[] | Map<[RawRedeemerTag, number], [RawPlutusData, RawExUnits]>; 6?: Buffer[]; // plutus v2 7?: Buffer[]; // plutus v3 } export type RawTxWitnessSet = TypedMap; export type TxMetadataLabel = number | bigint; export type TransactionDatum = number | bigint | Buffer | string; export type RawMetadata = Map | TransactionDatum[] | TransactionDatum; export type LabeledMetadata = Map; // --- Auxiliary Data --- export interface RawAuxiliaryDataMap { /** field 0: transaction_metadata */ 0?: LabeledMetadata; /** field 1: auxiliary_scripts (Native/Timelock) */ 1?: RawNativeScript[]; /** field 2: plutus_v1_scripts */ 2?: Buffer[]; /** field 3: plutus_v2_scripts */ 3?: Buffer[]; /** field 4: plutus_v3_scripts (Conway Era) */ 4?: Buffer[]; } /** * Represents the Alonzo/Conway Auxiliary Data Map (#6.259) */ export type RawAuxiliaryData = TypedMap; // --- Top Level Transaction --- // Raw trabsaction is a List of [body, witness_set, is_valid, auxiliary_data] export type RawTransaction = [ body: RawTxBody, witness_set: RawTxWitnessSet, isValid: boolean, auxiliary_data: RawAuxiliaryData | null, ]; export type RawBlock = [ header: RawBlockHeader, transaction_bodies: RawTxBody[], transaction_witness_sets: RawTxWitnessSet[], auxiliary_data_set: TypedMap>, invalid_transactions: number[] ]; export type RawBlockHeader = [ header_body: RawHeaderBody, body_signature: Buffer ]; export type RawHeaderBody = [ block_number: number, slot: RawSlot, prev_hash: Buffer | null, issuer_vkey: Buffer, vrf_vkey: Buffer, vrf_result: RawVrfCert, block_body_size: number, block_body_hash: Buffer, operational_cert: RawOperationalCert, protocol_version: [number, number] ]; export type RawVrfCert = [ output: Buffer, proof: Buffer ]; export type RawOperationalCert = [ hot_vkey: Buffer, sequence_number: number, kes_period: number, sigma: Buffer ];