@bitgo/wasm-utxo 1.42.0 → 1.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Inspect - TypeScript bindings for PSBT and Transaction parsing
3
+ *
4
+ * Provides typed wrappers around the WASM inspect functions that return
5
+ * hierarchical node structures suitable for display as collapsible trees.
6
+ *
7
+ * Import via: `import { ... } from "@bitgo/wasm-utxo/inspect"`
8
+ */
9
+ import { parsePsbtToJson as wasmParsePsbtToJson, parseTxToJson as wasmParseTxToJson, parsePsbtRawToJson as wasmParsePsbtRawToJson, isInspectEnabled as wasmIsInspectEnabled, } from "../wasm/wasm_utxo.js";
10
+ /** All supported networks in order of parsing priority */
11
+ export const allNetworks = [
12
+ "btc",
13
+ "tbtc",
14
+ "tbtc4",
15
+ "tbtcsig",
16
+ "tbtcbgsig",
17
+ "ltc",
18
+ "tltc",
19
+ "bch",
20
+ "tbch",
21
+ "bcha",
22
+ "tbcha",
23
+ "btg",
24
+ "tbtg",
25
+ "bsv",
26
+ "tbsv",
27
+ "dash",
28
+ "tdash",
29
+ "doge",
30
+ "tdoge",
31
+ "zec",
32
+ "tzec",
33
+ ];
34
+ /**
35
+ * Parse a PSBT and return a typed node tree.
36
+ *
37
+ * @param psbtBytes - The raw PSBT bytes
38
+ * @param network - The network coin name (e.g., "btc", "ltc", "bch")
39
+ * @returns A Node tree representing the parsed PSBT structure
40
+ * @throws If the PSBT bytes are invalid or network is unknown
41
+ */
42
+ export function parsePsbtToNode(psbtBytes, network) {
43
+ const json = wasmParsePsbtToJson(psbtBytes, network);
44
+ return JSON.parse(json);
45
+ }
46
+ /**
47
+ * Parse a transaction and return a typed node tree.
48
+ *
49
+ * @param txBytes - The raw transaction bytes
50
+ * @param network - The network coin name (e.g., "btc", "ltc", "bch")
51
+ * @returns A Node tree representing the parsed transaction structure
52
+ * @throws If the transaction bytes are invalid or network is unknown
53
+ */
54
+ export function parseTxToNode(txBytes, network) {
55
+ const json = wasmParseTxToJson(txBytes, network);
56
+ return JSON.parse(json);
57
+ }
58
+ /**
59
+ * Try to parse a PSBT with all networks and return the first one that succeeds.
60
+ *
61
+ * @param psbtBytes - The raw PSBT bytes
62
+ * @param networks - Optional list of networks to try (defaults to all networks)
63
+ * @returns An object with the parsed Node and detected network, or null if all fail
64
+ */
65
+ export function tryParsePsbt(psbtBytes, networks = allNetworks) {
66
+ for (const network of networks) {
67
+ try {
68
+ const node = parsePsbtToNode(psbtBytes, network);
69
+ return { node, network };
70
+ }
71
+ catch {
72
+ // Try next network
73
+ }
74
+ }
75
+ return null;
76
+ }
77
+ /**
78
+ * Try to parse a transaction with all networks and return the first one that succeeds.
79
+ *
80
+ * @param txBytes - The raw transaction bytes
81
+ * @param networks - Optional list of networks to try (defaults to all networks)
82
+ * @returns An object with the parsed Node and detected network, or null if all fail
83
+ */
84
+ export function tryParseTx(txBytes, networks = allNetworks) {
85
+ for (const network of networks) {
86
+ try {
87
+ const node = parseTxToNode(txBytes, network);
88
+ return { node, network };
89
+ }
90
+ catch {
91
+ // Try next network
92
+ }
93
+ }
94
+ return null;
95
+ }
96
+ /**
97
+ * Parse a PSBT at the raw byte level and return a typed node tree.
98
+ *
99
+ * Unlike `parsePsbtToNode`, this function exposes the raw key-value pair
100
+ * structure as defined in BIP-174, showing:
101
+ * - Raw key type IDs and their human-readable names
102
+ * - Proprietary keys with their structured format
103
+ * - Unknown/unrecognized keys that standard parsers might skip
104
+ *
105
+ * @param psbtBytes - The raw PSBT bytes
106
+ * @param network - The network coin name (e.g., "btc", "ltc", "zec")
107
+ * @returns A Node tree representing the raw PSBT key-value structure
108
+ * @throws If the PSBT bytes are invalid or network is unknown
109
+ */
110
+ export function parsePsbtRawToNode(psbtBytes, network) {
111
+ const json = wasmParsePsbtRawToJson(psbtBytes, network);
112
+ return JSON.parse(json);
113
+ }
114
+ /**
115
+ * Try to parse a raw PSBT with all networks and return the first one that succeeds.
116
+ *
117
+ * @param psbtBytes - The raw PSBT bytes
118
+ * @param networks - Optional list of networks to try (defaults to all networks)
119
+ * @returns An object with the parsed Node and detected network, or null if all fail
120
+ */
121
+ export function tryParsePsbtRaw(psbtBytes, networks = allNetworks) {
122
+ for (const network of networks) {
123
+ try {
124
+ const node = parsePsbtRawToNode(psbtBytes, network);
125
+ return { node, network };
126
+ }
127
+ catch {
128
+ // Try next network
129
+ }
130
+ }
131
+ return null;
132
+ }
133
+ /**
134
+ * Check if the inspect feature is enabled in the WASM build.
135
+ *
136
+ * @returns true if the feature is enabled, false otherwise
137
+ */
138
+ export function isInspectEnabled() {
139
+ return wasmIsInspectEnabled();
140
+ }
@@ -14,11 +14,30 @@ export interface ITransaction {
14
14
  export declare class Transaction implements ITransaction {
15
15
  private _wasm;
16
16
  private constructor();
17
+ /**
18
+ * Create an empty transaction (version 1, locktime 0)
19
+ */
20
+ static create(): Transaction;
17
21
  static fromBytes(bytes: Uint8Array): Transaction;
18
22
  /**
19
23
  * @internal Create from WASM instance directly (avoids re-parsing bytes)
20
24
  */
21
25
  static fromWasm(wasm: WasmTransaction): Transaction;
26
+ /**
27
+ * Add an input to the transaction
28
+ * @param txid - Previous transaction ID (hex string)
29
+ * @param vout - Output index being spent
30
+ * @param sequence - Optional sequence number (default: 0xFFFFFFFF)
31
+ * @returns The index of the newly added input
32
+ */
33
+ addInput(txid: string, vout: number, sequence?: number): number;
34
+ /**
35
+ * Add an output to the transaction
36
+ * @param script - Output script (scriptPubKey)
37
+ * @param value - Value in satoshis
38
+ * @returns The index of the newly added output
39
+ */
40
+ addOutput(script: Uint8Array, value: bigint): number;
22
41
  toBytes(): Uint8Array;
23
42
  /**
24
43
  * Get the transaction ID (txid)
@@ -9,6 +9,12 @@ export class Transaction {
9
9
  constructor(_wasm) {
10
10
  this._wasm = _wasm;
11
11
  }
12
+ /**
13
+ * Create an empty transaction (version 1, locktime 0)
14
+ */
15
+ static create() {
16
+ return new Transaction(WasmTransaction.create());
17
+ }
12
18
  static fromBytes(bytes) {
13
19
  return new Transaction(WasmTransaction.from_bytes(bytes));
14
20
  }
@@ -18,6 +24,25 @@ export class Transaction {
18
24
  static fromWasm(wasm) {
19
25
  return new Transaction(wasm);
20
26
  }
27
+ /**
28
+ * Add an input to the transaction
29
+ * @param txid - Previous transaction ID (hex string)
30
+ * @param vout - Output index being spent
31
+ * @param sequence - Optional sequence number (default: 0xFFFFFFFF)
32
+ * @returns The index of the newly added input
33
+ */
34
+ addInput(txid, vout, sequence) {
35
+ return this._wasm.add_input(txid, vout, sequence);
36
+ }
37
+ /**
38
+ * Add an output to the transaction
39
+ * @param script - Output script (scriptPubKey)
40
+ * @param value - Value in satoshis
41
+ * @returns The index of the newly added output
42
+ */
43
+ addOutput(script, value) {
44
+ return this._wasm.add_output(script, value);
45
+ }
21
46
  toBytes() {
22
47
  return this._wasm.to_bytes();
23
48
  }
@@ -181,7 +181,7 @@ export class BitGoPsbt {
181
181
  * # Returns
182
182
  * The index of the newly added input
183
183
  */
184
- add_replay_protection_input(ecpair: WasmECPair, txid: string, vout: number, value: bigint, sequence?: number | null): number;
184
+ add_replay_protection_input(ecpair: WasmECPair, txid: string, vout: number, value: bigint, sequence?: number | null, prev_tx?: Uint8Array | null): number;
185
185
  /**
186
186
  * Add a wallet input with full PSBT metadata
187
187
  *
@@ -756,6 +756,16 @@ export class FixedScriptWalletNamespace {
756
756
  static create_op_return_script(data?: Uint8Array | null): Uint8Array;
757
757
  static output_script(keys: WasmRootWalletKeys, chain: number, index: number, network: any): Uint8Array;
758
758
  static output_script_with_network_str(keys: WasmRootWalletKeys, chain: number, index: number, network: string): Uint8Array;
759
+ /**
760
+ * Get the P2SH-P2PK output script for a compressed public key
761
+ *
762
+ * # Arguments
763
+ * * `pubkey` - The compressed public key bytes (33 bytes)
764
+ *
765
+ * # Returns
766
+ * The P2SH-P2PK output script as bytes
767
+ */
768
+ static p2sh_p2pk_output_script(pubkey: Uint8Array): Uint8Array;
759
769
  /**
760
770
  * Check if a network supports a given fixed-script wallet script type
761
771
  *
@@ -1220,6 +1230,33 @@ export class WasmTransaction {
1220
1230
  private constructor();
1221
1231
  free(): void;
1222
1232
  [Symbol.dispose](): void;
1233
+ /**
1234
+ * Add an input to the transaction
1235
+ *
1236
+ * # Arguments
1237
+ * * `txid` - The transaction ID (hex string) of the output being spent
1238
+ * * `vout` - The output index being spent
1239
+ * * `sequence` - Optional sequence number (default: 0xFFFFFFFF)
1240
+ *
1241
+ * # Returns
1242
+ * The index of the newly added input
1243
+ */
1244
+ add_input(txid: string, vout: number, sequence?: number | null): number;
1245
+ /**
1246
+ * Add an output to the transaction
1247
+ *
1248
+ * # Arguments
1249
+ * * `script` - The output script (scriptPubKey)
1250
+ * * `value` - The value in satoshis
1251
+ *
1252
+ * # Returns
1253
+ * The index of the newly added output
1254
+ */
1255
+ add_output(script: Uint8Array, value: bigint): number;
1256
+ /**
1257
+ * Create an empty transaction (version 1, locktime 0)
1258
+ */
1259
+ static create(): WasmTransaction;
1223
1260
  /**
1224
1261
  * Deserialize a transaction from bytes
1225
1262
  *
@@ -1497,3 +1534,74 @@ export class WrapPsbt {
1497
1534
  */
1498
1535
  version(): number;
1499
1536
  }
1537
+
1538
+ /**
1539
+ * Check if the inspect feature is enabled.
1540
+ *
1541
+ * # Returns
1542
+ * `true` if the feature is enabled, `false` otherwise
1543
+ */
1544
+ export function isInspectEnabled(): boolean;
1545
+
1546
+ /**
1547
+ * Parse a PSBT at the raw byte level and return a JSON representation.
1548
+ *
1549
+ * Unlike `parsePsbtToJson`, this function exposes the raw key-value pair
1550
+ * structure as defined in BIP-174, showing:
1551
+ * - Raw key type IDs and their human-readable names
1552
+ * - Proprietary keys with their structured format
1553
+ * - Unknown/unrecognized keys that standard parsers might skip
1554
+ *
1555
+ * # Arguments
1556
+ * * `psbt_bytes` - The raw PSBT bytes
1557
+ * * `coin_name` - The network coin name (e.g., "btc", "ltc", "zec")
1558
+ *
1559
+ * # Returns
1560
+ * A JSON string representing the raw PSBT key-value structure
1561
+ *
1562
+ * # Errors
1563
+ * Returns an error if:
1564
+ * - The `inspect` feature is not enabled
1565
+ * - The PSBT bytes are invalid
1566
+ * - The network name is unknown
1567
+ */
1568
+ export function parsePsbtRawToJson(psbt_bytes: Uint8Array, coin_name: string): string;
1569
+
1570
+ /**
1571
+ * Parse a PSBT and return a JSON representation of its structure.
1572
+ *
1573
+ * This function parses the PSBT using the standard bitcoin crate parser
1574
+ * and returns a hierarchical node structure suitable for display.
1575
+ *
1576
+ * # Arguments
1577
+ * * `psbt_bytes` - The raw PSBT bytes
1578
+ * * `coin_name` - The network coin name (e.g., "btc", "ltc", "bch")
1579
+ *
1580
+ * # Returns
1581
+ * A JSON string representing the parsed PSBT structure
1582
+ *
1583
+ * # Errors
1584
+ * Returns an error if:
1585
+ * - The `inspect` feature is not enabled
1586
+ * - The PSBT bytes are invalid
1587
+ * - The network name is unknown
1588
+ */
1589
+ export function parsePsbtToJson(psbt_bytes: Uint8Array, coin_name: string): string;
1590
+
1591
+ /**
1592
+ * Parse a transaction and return a JSON representation of its structure.
1593
+ *
1594
+ * # Arguments
1595
+ * * `tx_bytes` - The raw transaction bytes
1596
+ * * `coin_name` - The network coin name (e.g., "btc", "ltc", "bch")
1597
+ *
1598
+ * # Returns
1599
+ * A JSON string representing the parsed transaction structure
1600
+ *
1601
+ * # Errors
1602
+ * Returns an error if:
1603
+ * - The `inspect` feature is not enabled
1604
+ * - The transaction bytes are invalid
1605
+ * - The network name is unknown
1606
+ */
1607
+ export function parseTxToJson(tx_bytes: Uint8Array, coin_name: string): string;
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./wasm_utxo_bg.js";
5
5
  __wbg_set_wasm(wasm);
6
6
 
7
7
  export {
8
- AddressNamespace, Bip322Namespace, BitGoPsbt, FixedScriptWalletNamespace, InscriptionsNamespace, MessageNamespace, UtxolibCompatNamespace, WasmBIP32, WasmDashTransaction, WasmDimensions, WasmECPair, WasmReplayProtection, WasmRootWalletKeys, WasmTransaction, WasmZcashTransaction, WrapDescriptor, WrapMiniscript, WrapPsbt
8
+ AddressNamespace, Bip322Namespace, BitGoPsbt, FixedScriptWalletNamespace, InscriptionsNamespace, MessageNamespace, UtxolibCompatNamespace, WasmBIP32, WasmDashTransaction, WasmDimensions, WasmECPair, WasmReplayProtection, WasmRootWalletKeys, WasmTransaction, WasmZcashTransaction, WrapDescriptor, WrapMiniscript, WrapPsbt, isInspectEnabled, parsePsbtRawToJson, parsePsbtToJson, parseTxToJson
9
9
  } from "./wasm_utxo_bg.js";
@@ -517,15 +517,18 @@ export class BitGoPsbt {
517
517
  * @param {number} vout
518
518
  * @param {bigint} value
519
519
  * @param {number | null} [sequence]
520
+ * @param {Uint8Array | null} [prev_tx]
520
521
  * @returns {number}
521
522
  */
522
- add_replay_protection_input(ecpair, txid, vout, value, sequence) {
523
+ add_replay_protection_input(ecpair, txid, vout, value, sequence, prev_tx) {
523
524
  try {
524
525
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
525
526
  _assertClass(ecpair, WasmECPair);
526
527
  const ptr0 = passStringToWasm0(txid, wasm.__wbindgen_export, wasm.__wbindgen_export2);
527
528
  const len0 = WASM_VECTOR_LEN;
528
- wasm.bitgopsbt_add_replay_protection_input(retptr, this.__wbg_ptr, ecpair.__wbg_ptr, ptr0, len0, vout, value, isLikeNone(sequence) ? 0x100000001 : (sequence) >>> 0);
529
+ var ptr1 = isLikeNone(prev_tx) ? 0 : passArray8ToWasm0(prev_tx, wasm.__wbindgen_export);
530
+ var len1 = WASM_VECTOR_LEN;
531
+ wasm.bitgopsbt_add_replay_protection_input(retptr, this.__wbg_ptr, ecpair.__wbg_ptr, ptr0, len0, vout, value, isLikeNone(sequence) ? 0x100000001 : (sequence) >>> 0, ptr1, len1);
529
532
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
530
533
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
531
534
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -1945,6 +1948,37 @@ export class FixedScriptWalletNamespace {
1945
1948
  wasm.__wbindgen_add_to_stack_pointer(16);
1946
1949
  }
1947
1950
  }
1951
+ /**
1952
+ * Get the P2SH-P2PK output script for a compressed public key
1953
+ *
1954
+ * # Arguments
1955
+ * * `pubkey` - The compressed public key bytes (33 bytes)
1956
+ *
1957
+ * # Returns
1958
+ * The P2SH-P2PK output script as bytes
1959
+ * @param {Uint8Array} pubkey
1960
+ * @returns {Uint8Array}
1961
+ */
1962
+ static p2sh_p2pk_output_script(pubkey) {
1963
+ try {
1964
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1965
+ const ptr0 = passArray8ToWasm0(pubkey, wasm.__wbindgen_export);
1966
+ const len0 = WASM_VECTOR_LEN;
1967
+ wasm.fixedscriptwalletnamespace_p2sh_p2pk_output_script(retptr, ptr0, len0);
1968
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1969
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1970
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1971
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1972
+ if (r3) {
1973
+ throw takeObject(r2);
1974
+ }
1975
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
1976
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
1977
+ return v2;
1978
+ } finally {
1979
+ wasm.__wbindgen_add_to_stack_pointer(16);
1980
+ }
1981
+ }
1948
1982
  /**
1949
1983
  * Check if a network supports a given fixed-script wallet script type
1950
1984
  *
@@ -3463,6 +3497,65 @@ export class WasmTransaction {
3463
3497
  const ptr = this.__destroy_into_raw();
3464
3498
  wasm.__wbg_wasmtransaction_free(ptr, 0);
3465
3499
  }
3500
+ /**
3501
+ * Add an input to the transaction
3502
+ *
3503
+ * # Arguments
3504
+ * * `txid` - The transaction ID (hex string) of the output being spent
3505
+ * * `vout` - The output index being spent
3506
+ * * `sequence` - Optional sequence number (default: 0xFFFFFFFF)
3507
+ *
3508
+ * # Returns
3509
+ * The index of the newly added input
3510
+ * @param {string} txid
3511
+ * @param {number} vout
3512
+ * @param {number | null} [sequence]
3513
+ * @returns {number}
3514
+ */
3515
+ add_input(txid, vout, sequence) {
3516
+ try {
3517
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
3518
+ const ptr0 = passStringToWasm0(txid, wasm.__wbindgen_export, wasm.__wbindgen_export2);
3519
+ const len0 = WASM_VECTOR_LEN;
3520
+ wasm.wasmtransaction_add_input(retptr, this.__wbg_ptr, ptr0, len0, vout, isLikeNone(sequence) ? 0x100000001 : (sequence) >>> 0);
3521
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
3522
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
3523
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
3524
+ if (r2) {
3525
+ throw takeObject(r1);
3526
+ }
3527
+ return r0 >>> 0;
3528
+ } finally {
3529
+ wasm.__wbindgen_add_to_stack_pointer(16);
3530
+ }
3531
+ }
3532
+ /**
3533
+ * Add an output to the transaction
3534
+ *
3535
+ * # Arguments
3536
+ * * `script` - The output script (scriptPubKey)
3537
+ * * `value` - The value in satoshis
3538
+ *
3539
+ * # Returns
3540
+ * The index of the newly added output
3541
+ * @param {Uint8Array} script
3542
+ * @param {bigint} value
3543
+ * @returns {number}
3544
+ */
3545
+ add_output(script, value) {
3546
+ const ptr0 = passArray8ToWasm0(script, wasm.__wbindgen_export);
3547
+ const len0 = WASM_VECTOR_LEN;
3548
+ const ret = wasm.wasmtransaction_add_output(this.__wbg_ptr, ptr0, len0, value);
3549
+ return ret >>> 0;
3550
+ }
3551
+ /**
3552
+ * Create an empty transaction (version 1, locktime 0)
3553
+ * @returns {WasmTransaction}
3554
+ */
3555
+ static create() {
3556
+ const ret = wasm.wasmtransaction_create();
3557
+ return WasmTransaction.__wrap(ret);
3558
+ }
3466
3559
  /**
3467
3560
  * Deserialize a transaction from bytes
3468
3561
  *
@@ -4664,6 +4757,171 @@ export class WrapPsbt {
4664
4757
  }
4665
4758
  }
4666
4759
  if (Symbol.dispose) WrapPsbt.prototype[Symbol.dispose] = WrapPsbt.prototype.free;
4760
+
4761
+ /**
4762
+ * Check if the inspect feature is enabled.
4763
+ *
4764
+ * # Returns
4765
+ * `true` if the feature is enabled, `false` otherwise
4766
+ * @returns {boolean}
4767
+ */
4768
+ export function isInspectEnabled() {
4769
+ const ret = wasm.isInspectEnabled();
4770
+ return ret !== 0;
4771
+ }
4772
+
4773
+ /**
4774
+ * Parse a PSBT at the raw byte level and return a JSON representation.
4775
+ *
4776
+ * Unlike `parsePsbtToJson`, this function exposes the raw key-value pair
4777
+ * structure as defined in BIP-174, showing:
4778
+ * - Raw key type IDs and their human-readable names
4779
+ * - Proprietary keys with their structured format
4780
+ * - Unknown/unrecognized keys that standard parsers might skip
4781
+ *
4782
+ * # Arguments
4783
+ * * `psbt_bytes` - The raw PSBT bytes
4784
+ * * `coin_name` - The network coin name (e.g., "btc", "ltc", "zec")
4785
+ *
4786
+ * # Returns
4787
+ * A JSON string representing the raw PSBT key-value structure
4788
+ *
4789
+ * # Errors
4790
+ * Returns an error if:
4791
+ * - The `inspect` feature is not enabled
4792
+ * - The PSBT bytes are invalid
4793
+ * - The network name is unknown
4794
+ * @param {Uint8Array} psbt_bytes
4795
+ * @param {string} coin_name
4796
+ * @returns {string}
4797
+ */
4798
+ export function parsePsbtRawToJson(psbt_bytes, coin_name) {
4799
+ let deferred4_0;
4800
+ let deferred4_1;
4801
+ try {
4802
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
4803
+ const ptr0 = passArray8ToWasm0(psbt_bytes, wasm.__wbindgen_export);
4804
+ const len0 = WASM_VECTOR_LEN;
4805
+ const ptr1 = passStringToWasm0(coin_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
4806
+ const len1 = WASM_VECTOR_LEN;
4807
+ wasm.parsePsbtRawToJson(retptr, ptr0, len0, ptr1, len1);
4808
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
4809
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
4810
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
4811
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
4812
+ var ptr3 = r0;
4813
+ var len3 = r1;
4814
+ if (r3) {
4815
+ ptr3 = 0; len3 = 0;
4816
+ throw takeObject(r2);
4817
+ }
4818
+ deferred4_0 = ptr3;
4819
+ deferred4_1 = len3;
4820
+ return getStringFromWasm0(ptr3, len3);
4821
+ } finally {
4822
+ wasm.__wbindgen_add_to_stack_pointer(16);
4823
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
4824
+ }
4825
+ }
4826
+
4827
+ /**
4828
+ * Parse a PSBT and return a JSON representation of its structure.
4829
+ *
4830
+ * This function parses the PSBT using the standard bitcoin crate parser
4831
+ * and returns a hierarchical node structure suitable for display.
4832
+ *
4833
+ * # Arguments
4834
+ * * `psbt_bytes` - The raw PSBT bytes
4835
+ * * `coin_name` - The network coin name (e.g., "btc", "ltc", "bch")
4836
+ *
4837
+ * # Returns
4838
+ * A JSON string representing the parsed PSBT structure
4839
+ *
4840
+ * # Errors
4841
+ * Returns an error if:
4842
+ * - The `inspect` feature is not enabled
4843
+ * - The PSBT bytes are invalid
4844
+ * - The network name is unknown
4845
+ * @param {Uint8Array} psbt_bytes
4846
+ * @param {string} coin_name
4847
+ * @returns {string}
4848
+ */
4849
+ export function parsePsbtToJson(psbt_bytes, coin_name) {
4850
+ let deferred4_0;
4851
+ let deferred4_1;
4852
+ try {
4853
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
4854
+ const ptr0 = passArray8ToWasm0(psbt_bytes, wasm.__wbindgen_export);
4855
+ const len0 = WASM_VECTOR_LEN;
4856
+ const ptr1 = passStringToWasm0(coin_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
4857
+ const len1 = WASM_VECTOR_LEN;
4858
+ wasm.parsePsbtRawToJson(retptr, ptr0, len0, ptr1, len1);
4859
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
4860
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
4861
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
4862
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
4863
+ var ptr3 = r0;
4864
+ var len3 = r1;
4865
+ if (r3) {
4866
+ ptr3 = 0; len3 = 0;
4867
+ throw takeObject(r2);
4868
+ }
4869
+ deferred4_0 = ptr3;
4870
+ deferred4_1 = len3;
4871
+ return getStringFromWasm0(ptr3, len3);
4872
+ } finally {
4873
+ wasm.__wbindgen_add_to_stack_pointer(16);
4874
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
4875
+ }
4876
+ }
4877
+
4878
+ /**
4879
+ * Parse a transaction and return a JSON representation of its structure.
4880
+ *
4881
+ * # Arguments
4882
+ * * `tx_bytes` - The raw transaction bytes
4883
+ * * `coin_name` - The network coin name (e.g., "btc", "ltc", "bch")
4884
+ *
4885
+ * # Returns
4886
+ * A JSON string representing the parsed transaction structure
4887
+ *
4888
+ * # Errors
4889
+ * Returns an error if:
4890
+ * - The `inspect` feature is not enabled
4891
+ * - The transaction bytes are invalid
4892
+ * - The network name is unknown
4893
+ * @param {Uint8Array} tx_bytes
4894
+ * @param {string} coin_name
4895
+ * @returns {string}
4896
+ */
4897
+ export function parseTxToJson(tx_bytes, coin_name) {
4898
+ let deferred4_0;
4899
+ let deferred4_1;
4900
+ try {
4901
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
4902
+ const ptr0 = passArray8ToWasm0(tx_bytes, wasm.__wbindgen_export);
4903
+ const len0 = WASM_VECTOR_LEN;
4904
+ const ptr1 = passStringToWasm0(coin_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
4905
+ const len1 = WASM_VECTOR_LEN;
4906
+ wasm.parsePsbtRawToJson(retptr, ptr0, len0, ptr1, len1);
4907
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
4908
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
4909
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
4910
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
4911
+ var ptr3 = r0;
4912
+ var len3 = r1;
4913
+ if (r3) {
4914
+ ptr3 = 0; len3 = 0;
4915
+ throw takeObject(r2);
4916
+ }
4917
+ deferred4_0 = ptr3;
4918
+ deferred4_1 = len3;
4919
+ return getStringFromWasm0(ptr3, len3);
4920
+ } finally {
4921
+ wasm.__wbindgen_add_to_stack_pointer(16);
4922
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
4923
+ }
4924
+ }
4667
4925
  export function __wbg_Error_8c4e43fe74559d73(arg0, arg1) {
4668
4926
  const ret = Error(getStringFromWasm0(arg0, arg1));
4669
4927
  return addHeapObject(ret);
Binary file