kaspa_consensus_client/serializable/
mod.rs

1//!
2//! # Standardized JSON serialization and deserialization of Kaspa transactions.
3//!
4//! This module provides standardized JSON serialization and deserialization of
5//! Kaspa transactions. There are two sub-modules: `numeric` and `string`.
6//!
7//! The `numeric` module provides serialization and deserialization of transactions
8//! with all large integer values as `bigint` types in WASM or numerical values that
9//! exceed the largest integer that can be represented by the JavaScript `number` type.
10//!
11//! The `string` module provides serialization and deserialization of transactions
12//! with all large integer values as `string` types. This allows deserialization
13//! via JSON in JavaScript environments and later conversion to `bigint` types.
14//!
15//! These data structures can be used for manual transport of transactions using JSON.
16//! For more advanced use cases, please refer to `PSKT` in the [`kaspa_wallet_pskt`](https://docs.rs/kaspa_wallet_pskt)
17//! crate.
18//!
19
20#![allow(non_snake_case)]
21
22pub mod numeric;
23pub mod string;
24
25use wasm_bindgen::prelude::*;
26#[wasm_bindgen(typescript_custom_section)]
27const TS_TYPES: &'static str = r#"
28
29/**
30 * Interface defines the structure of a serializable UTXO entry.
31 * 
32 * @see {@link ISerializableTransactionInput}, {@link ISerializableTransaction}
33 * @category Wallet SDK
34 */
35export interface ISerializableUtxoEntry {
36    address?: Address;
37    amount: bigint;
38    scriptPublicKey: ScriptPublicKey;
39    blockDaaScore: bigint;
40    isCoinbase: boolean;
41}
42
43/**
44 * Interface defines the structure of a serializable transaction input.
45 * 
46 * @see {@link ISerializableTransaction}
47 * @category Wallet SDK
48 */
49export interface ISerializableTransactionInput {
50    transactionId : HexString;
51    index: number;
52    sequence: bigint;
53    sigOpCount: number;
54    signatureScript?: HexString;
55    utxo: ISerializableUtxoEntry;
56}
57
58/**
59 * Interface defines the structure of a serializable transaction output.
60 * 
61 * @see {@link ISerializableTransaction}
62 * @category Wallet SDK
63 */
64export interface ISerializableTransactionOutput {
65    value: bigint;
66    scriptPublicKey: IScriptPublicKey;
67}
68
69/**
70 * Interface defines the structure of a serializable transaction.
71 * 
72 * Serializable transactions can be produced using 
73 * {@link Transaction.serializeToJSON},
74 * {@link Transaction.serializeToSafeJSON} and 
75 * {@link Transaction.serializeToObject} 
76 * functions for processing (signing) in external systems.
77 * 
78 * Once the transaction is signed, it can be deserialized
79 * into {@link Transaction} using {@link Transaction.deserializeFromJSON}
80 * and {@link Transaction.deserializeFromSafeJSON} functions. 
81 * 
82 * @see {@link Transaction},
83 * {@link ISerializableTransactionInput},
84 * {@link ISerializableTransactionOutput},
85 * {@link ISerializableUtxoEntry}
86 * 
87 * @category Wallet SDK
88 */
89export interface ISerializableTransaction {
90    id? : HexString;
91    version: number;
92    inputs: ISerializableTransactionInput[];
93    outputs: ISerializableTransactionOutput[];
94    lockTime: bigint;
95    subnetworkId: HexString;
96    gas: bigint;
97    payload: HexString;
98}
99
100"#;
101
102#[wasm_bindgen]
103extern "C" {
104    /// WASM (TypeScript) representation of the `ISerializableTransaction` interface.
105    #[wasm_bindgen(extends = js_sys::Array, typescript_type = "ISerializableTransaction")]
106    pub type SerializableTransactionT;
107}