11import { WasmDashTransaction , WasmTransaction , WasmZcashTransaction } from "./wasm/wasm_utxo.js" ;
22
3+ /**
4+ * Common interface for all transaction types
5+ */
6+ export interface ITransaction {
7+ toBytes ( ) : Uint8Array ;
8+ getId ( ) : string ;
9+ }
10+
311/**
412 * Transaction wrapper (Bitcoin-like networks)
513 *
614 * Provides a camelCase, strongly-typed API over the snake_case WASM bindings.
715 */
8- export class Transaction {
16+ export class Transaction implements ITransaction {
917 private constructor ( private _wasm : WasmTransaction ) { }
1018
1119 static fromBytes ( bytes : Uint8Array ) : Transaction {
1220 return new Transaction ( WasmTransaction . from_bytes ( bytes ) ) ;
1321 }
1422
23+ /**
24+ * @internal Create from WASM instance directly (avoids re-parsing bytes)
25+ */
26+ static fromWasm ( wasm : WasmTransaction ) : Transaction {
27+ return new Transaction ( wasm ) ;
28+ }
29+
1530 toBytes ( ) : Uint8Array {
1631 return this . _wasm . to_bytes ( ) ;
1732 }
1833
34+ /**
35+ * Get the transaction ID (txid)
36+ *
37+ * The txid is the double SHA256 of the transaction bytes (excluding witness
38+ * data for segwit transactions), displayed in reverse byte order as is standard.
39+ *
40+ * @returns The transaction ID as a hex string
41+ */
42+ getId ( ) : string {
43+ return this . _wasm . get_txid ( ) ;
44+ }
45+
1946 /**
2047 * Get the virtual size of the transaction
2148 *
@@ -40,17 +67,36 @@ export class Transaction {
4067 *
4168 * Provides a camelCase, strongly-typed API over the snake_case WASM bindings.
4269 */
43- export class ZcashTransaction {
70+ export class ZcashTransaction implements ITransaction {
4471 private constructor ( private _wasm : WasmZcashTransaction ) { }
4572
4673 static fromBytes ( bytes : Uint8Array ) : ZcashTransaction {
4774 return new ZcashTransaction ( WasmZcashTransaction . from_bytes ( bytes ) ) ;
4875 }
4976
77+ /**
78+ * @internal Create from WASM instance directly (avoids re-parsing bytes)
79+ */
80+ static fromWasm ( wasm : WasmZcashTransaction ) : ZcashTransaction {
81+ return new ZcashTransaction ( wasm ) ;
82+ }
83+
5084 toBytes ( ) : Uint8Array {
5185 return this . _wasm . to_bytes ( ) ;
5286 }
5387
88+ /**
89+ * Get the transaction ID (txid)
90+ *
91+ * The txid is the double SHA256 of the full Zcash transaction bytes,
92+ * displayed in reverse byte order as is standard.
93+ *
94+ * @returns The transaction ID as a hex string
95+ */
96+ getId ( ) : string {
97+ return this . _wasm . get_txid ( ) ;
98+ }
99+
54100 /**
55101 * @internal
56102 */
@@ -64,17 +110,36 @@ export class ZcashTransaction {
64110 *
65111 * Round-trip only: bytes -> parse -> bytes.
66112 */
67- export class DashTransaction {
113+ export class DashTransaction implements ITransaction {
68114 private constructor ( private _wasm : WasmDashTransaction ) { }
69115
70116 static fromBytes ( bytes : Uint8Array ) : DashTransaction {
71117 return new DashTransaction ( WasmDashTransaction . from_bytes ( bytes ) ) ;
72118 }
73119
120+ /**
121+ * @internal Create from WASM instance directly (avoids re-parsing bytes)
122+ */
123+ static fromWasm ( wasm : WasmDashTransaction ) : DashTransaction {
124+ return new DashTransaction ( wasm ) ;
125+ }
126+
74127 toBytes ( ) : Uint8Array {
75128 return this . _wasm . to_bytes ( ) ;
76129 }
77130
131+ /**
132+ * Get the transaction ID (txid)
133+ *
134+ * The txid is the double SHA256 of the full Dash transaction bytes,
135+ * displayed in reverse byte order as is standard.
136+ *
137+ * @returns The transaction ID as a hex string
138+ */
139+ getId ( ) : string {
140+ return this . _wasm . get_txid ( ) ;
141+ }
142+
78143 /**
79144 * @internal
80145 */
0 commit comments