@bitgo/wasm-utxo 4.1.0 → 4.3.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.
@@ -1,14 +1,9 @@
1
1
  import { WrapPsbt as WasmPsbt, } from "../wasm/wasm_utxo.js";
2
2
  import { Transaction } from "../transaction.js";
3
- export class Psbt {
4
- _wasm;
3
+ import { PsbtBase } from "../psbtBase.js";
4
+ export class Psbt extends PsbtBase {
5
5
  constructor(versionOrWasm, lockTime) {
6
- if (versionOrWasm instanceof WasmPsbt) {
7
- this._wasm = versionOrWasm;
8
- }
9
- else {
10
- this._wasm = new WasmPsbt(versionOrWasm, lockTime);
11
- }
6
+ super(versionOrWasm instanceof WasmPsbt ? versionOrWasm : new WasmPsbt(versionOrWasm, lockTime));
12
7
  }
13
8
  /** @internal Access the underlying WASM instance */
14
9
  get wasm() {
@@ -22,37 +17,10 @@ export class Psbt {
22
17
  return new Psbt(WasmPsbt.deserialize(bytes));
23
18
  }
24
19
  // -- Serialization --
25
- serialize() {
26
- return this._wasm.serialize();
27
- }
28
20
  clone() {
29
21
  return new Psbt(this._wasm.clone());
30
22
  }
31
23
  // -- IPsbt: introspection --
32
- inputCount() {
33
- return this._wasm.input_count();
34
- }
35
- outputCount() {
36
- return this._wasm.output_count();
37
- }
38
- version() {
39
- return this._wasm.version();
40
- }
41
- lockTime() {
42
- return this._wasm.lock_time();
43
- }
44
- unsignedTxId() {
45
- return this._wasm.unsigned_tx_id();
46
- }
47
- getInputs() {
48
- return this._wasm.get_inputs();
49
- }
50
- getOutputs() {
51
- return this._wasm.get_outputs();
52
- }
53
- getGlobalXpubs() {
54
- return this._wasm.get_global_xpubs();
55
- }
56
24
  getOutputsWithAddress(coin) {
57
25
  return this._wasm.get_outputs_with_address(coin);
58
26
  }
@@ -69,30 +37,6 @@ export class Psbt {
69
37
  addOutput(script, value) {
70
38
  return this._wasm.add_output(script, value);
71
39
  }
72
- removeInput(index) {
73
- this._wasm.remove_input(index);
74
- }
75
- removeOutput(index) {
76
- this._wasm.remove_output(index);
77
- }
78
- setKV(key, value) {
79
- this._wasm.set_kv(key, value);
80
- }
81
- getKV(key) {
82
- return this._wasm.get_kv(key) ?? undefined;
83
- }
84
- setInputKV(index, key, value) {
85
- this._wasm.set_input_kv(index, key, value);
86
- }
87
- getInputKV(index, key) {
88
- return this._wasm.get_input_kv(index, key) ?? undefined;
89
- }
90
- setOutputKV(index, key, value) {
91
- this._wasm.set_output_kv(index, key, value);
92
- }
93
- getOutputKV(index, key) {
94
- return this._wasm.get_output_kv(index, key) ?? undefined;
95
- }
96
40
  // -- Descriptor updates --
97
41
  updateInputWithDescriptor(inputIndex, descriptor) {
98
42
  this._wasm.update_input_with_descriptor(inputIndex, descriptor);
@@ -1,5 +1,6 @@
1
- import { BitGoPsbt as WasmBitGoPsbt, type PsbtInputData, type PsbtOutputData, type PsbtOutputDataWithAddress } from "../wasm/wasm_utxo.js";
1
+ import { BitGoPsbt as WasmBitGoPsbt, type PsbtOutputDataWithAddress } from "../wasm/wasm_utxo.js";
2
2
  import type { IPsbtWithAddress } from "../psbt.js";
3
+ import { PsbtBase } from "../psbtBase.js";
3
4
  import { type WalletKeysArg, RootWalletKeys } from "./RootWalletKeys.js";
4
5
  import { type ReplayProtectionArg } from "./ReplayProtection.js";
5
6
  import { type BIP32Arg, BIP32 } from "../bip32.js";
@@ -7,7 +8,6 @@ import { type ECPairArg } from "../ecpair.js";
7
8
  import type { UtxolibName } from "../utxolibCompat.js";
8
9
  import type { CoinName } from "../coinName.js";
9
10
  import type { InputScriptType } from "./scriptType.js";
10
- import type { PsbtKvKey } from "./BitGoKeySubtype.js";
11
11
  import { type ITransaction } from "../transaction.js";
12
12
  export type { InputScriptType };
13
13
  export type NetworkName = UtxolibName | CoinName;
@@ -103,10 +103,12 @@ export type HydrationUnspent = {
103
103
  chain: number;
104
104
  index: number;
105
105
  value: bigint;
106
+ } | {
107
+ pubkey: Uint8Array;
108
+ value: bigint;
106
109
  };
107
- export declare class BitGoPsbt implements IPsbtWithAddress {
108
- protected _wasm: WasmBitGoPsbt;
109
- protected constructor(_wasm: WasmBitGoPsbt);
110
+ export declare class BitGoPsbt extends PsbtBase<WasmBitGoPsbt> implements IPsbtWithAddress {
111
+ protected constructor(wasm: WasmBitGoPsbt);
110
112
  /**
111
113
  * Get the underlying WASM instance
112
114
  * @internal - for use by other wasm-utxo modules
@@ -289,31 +291,6 @@ export declare class BitGoPsbt implements IPsbtWithAddress {
289
291
  */
290
292
  addReplayProtectionInputAtIndex(index: number, inputOptions: AddInputOptions, key: ECPairArg): number;
291
293
  addReplayProtectionInput(inputOptions: AddInputOptions, key: ECPairArg): number;
292
- removeInput(index: number): void;
293
- removeOutput(index: number): void;
294
- /**
295
- * Get the unsigned transaction ID
296
- * @returns The unsigned transaction ID
297
- */
298
- unsignedTxId(): string;
299
- /**
300
- * Get the transaction version
301
- * @returns The transaction version number
302
- */
303
- version(): number;
304
- lockTime(): number;
305
- /** Set an arbitrary KV pair on the PSBT global map. */
306
- setKV(key: PsbtKvKey, value: Uint8Array): void;
307
- /** Get a KV value from the PSBT global map. Returns `undefined` if not present. */
308
- getKV(key: PsbtKvKey): Uint8Array | undefined;
309
- /** Set an arbitrary KV pair on a specific PSBT input. */
310
- setInputKV(index: number, key: PsbtKvKey, value: Uint8Array): void;
311
- /** Get a KV value from a specific PSBT input. Returns `undefined` if not present. */
312
- getInputKV(index: number, key: PsbtKvKey): Uint8Array | undefined;
313
- /** Set an arbitrary KV pair on a specific PSBT output. */
314
- setOutputKV(index: number, key: PsbtKvKey, value: Uint8Array): void;
315
- /** Get a KV value from a specific PSBT output. Returns `undefined` if not present. */
316
- getOutputKV(index: number, key: PsbtKvKey): Uint8Array | undefined;
317
294
  /**
318
295
  * Parse transaction with wallet keys to identify wallet inputs/outputs
319
296
  * @param walletKeys - The wallet keys to use for identification
@@ -480,12 +457,6 @@ export declare class BitGoPsbt implements IPsbtWithAddress {
480
457
  * @throws Error if the input is not a replay protection input, index is out of bounds, or scripts are invalid
481
458
  */
482
459
  verifyReplayProtectionSignature(inputIndex: number, replayProtection: ReplayProtectionArg): boolean;
483
- /**
484
- * Serialize the PSBT to bytes
485
- *
486
- * @returns The serialized PSBT as a byte array
487
- */
488
- serialize(): Uint8Array;
489
460
  /**
490
461
  * Generate and store MuSig2 nonces for all MuSig2 inputs
491
462
  *
@@ -584,31 +555,6 @@ export declare class BitGoPsbt implements IPsbtWithAddress {
584
555
  * ```
585
556
  */
586
557
  getHalfSignedLegacyFormat(): Uint8Array;
587
- /**
588
- * Get the number of inputs in the PSBT
589
- * @returns The number of inputs
590
- */
591
- inputCount(): number;
592
- outputCount(): number;
593
- /**
594
- * Get all PSBT inputs as an array
595
- *
596
- * Returns raw PSBT input data including witness_utxo and derivation info.
597
- * For parsed transaction data with address identification, use
598
- * parseTransactionWithWalletKeys() instead.
599
- *
600
- * @returns Array of PsbtInputData objects
601
- */
602
- getInputs(): PsbtInputData[];
603
- /**
604
- * Get all PSBT outputs as an array
605
- *
606
- * Returns raw PSBT output data without address resolution.
607
- * For output data with addresses, use getOutputsWithAddress().
608
- *
609
- * @returns Array of PsbtOutputData objects
610
- */
611
- getOutputs(): PsbtOutputData[];
612
558
  /**
613
559
  * Get all PSBT outputs with resolved address strings
614
560
  *
@@ -626,10 +572,6 @@ export declare class BitGoPsbt implements IPsbtWithAddress {
626
572
  * ```
627
573
  */
628
574
  getOutputsWithAddress(): PsbtOutputDataWithAddress[];
629
- /**
630
- * Returns the unordered global xpubs from this PSBT as BIP32 instances.
631
- */
632
- getGlobalXpubs(): BIP32[];
633
575
  }
634
576
  /**
635
577
  * Extract sorted wallet keys from a PSBT's global xpub fields.
@@ -1,13 +1,13 @@
1
1
  import { BitGoPsbt as WasmBitGoPsbt, FixedScriptWalletNamespace, } from "../wasm/wasm_utxo.js";
2
+ import { PsbtBase } from "../psbtBase.js";
2
3
  import { RootWalletKeys } from "./RootWalletKeys.js";
3
4
  import { ReplayProtection } from "./ReplayProtection.js";
4
5
  import { BIP32, isBIP32Arg } from "../bip32.js";
5
6
  import { ECPair } from "../ecpair.js";
6
7
  import { Transaction, DashTransaction, ZcashTransaction, } from "../transaction.js";
7
- export class BitGoPsbt {
8
- _wasm;
9
- constructor(_wasm) {
10
- this._wasm = _wasm;
8
+ export class BitGoPsbt extends PsbtBase {
9
+ constructor(wasm) {
10
+ super(wasm);
11
11
  }
12
12
  /**
13
13
  * Get the underlying WASM instance
@@ -230,53 +230,6 @@ export class BitGoPsbt {
230
230
  const ecpair = ECPair.from(key);
231
231
  return this._wasm.add_replay_protection_input(ecpair.wasm, inputOptions.txid, inputOptions.vout, inputOptions.value, inputOptions.sequence, inputOptions.prevTx);
232
232
  }
233
- removeInput(index) {
234
- this._wasm.remove_input(index);
235
- }
236
- removeOutput(index) {
237
- this._wasm.remove_output(index);
238
- }
239
- /**
240
- * Get the unsigned transaction ID
241
- * @returns The unsigned transaction ID
242
- */
243
- unsignedTxId() {
244
- return this._wasm.unsigned_txid();
245
- }
246
- /**
247
- * Get the transaction version
248
- * @returns The transaction version number
249
- */
250
- version() {
251
- return this._wasm.version();
252
- }
253
- lockTime() {
254
- return this._wasm.lock_time();
255
- }
256
- /** Set an arbitrary KV pair on the PSBT global map. */
257
- setKV(key, value) {
258
- this._wasm.set_kv(key, value);
259
- }
260
- /** Get a KV value from the PSBT global map. Returns `undefined` if not present. */
261
- getKV(key) {
262
- return this._wasm.get_kv(key) ?? undefined;
263
- }
264
- /** Set an arbitrary KV pair on a specific PSBT input. */
265
- setInputKV(index, key, value) {
266
- this._wasm.set_input_kv(index, key, value);
267
- }
268
- /** Get a KV value from a specific PSBT input. Returns `undefined` if not present. */
269
- getInputKV(index, key) {
270
- return this._wasm.get_input_kv(index, key) ?? undefined;
271
- }
272
- /** Set an arbitrary KV pair on a specific PSBT output. */
273
- setOutputKV(index, key, value) {
274
- this._wasm.set_output_kv(index, key, value);
275
- }
276
- /** Get a KV value from a specific PSBT output. Returns `undefined` if not present. */
277
- getOutputKV(index, key) {
278
- return this._wasm.get_output_kv(index, key) ?? undefined;
279
- }
280
233
  /**
281
234
  * Parse transaction with wallet keys to identify wallet inputs/outputs
282
235
  * @param walletKeys - The wallet keys to use for identification
@@ -470,14 +423,6 @@ export class BitGoPsbt {
470
423
  const rp = ReplayProtection.from(replayProtection, this._wasm.network());
471
424
  return this._wasm.verify_replay_protection_signature(inputIndex, rp.wasm);
472
425
  }
473
- /**
474
- * Serialize the PSBT to bytes
475
- *
476
- * @returns The serialized PSBT as a byte array
477
- */
478
- serialize() {
479
- return this._wasm.serialize();
480
- }
481
426
  /**
482
427
  * Generate and store MuSig2 nonces for all MuSig2 inputs
483
428
  *
@@ -596,39 +541,6 @@ export class BitGoPsbt {
596
541
  getHalfSignedLegacyFormat() {
597
542
  return this._wasm.extract_half_signed_legacy_tx();
598
543
  }
599
- /**
600
- * Get the number of inputs in the PSBT
601
- * @returns The number of inputs
602
- */
603
- inputCount() {
604
- return this._wasm.input_count();
605
- }
606
- outputCount() {
607
- return this._wasm.output_count();
608
- }
609
- /**
610
- * Get all PSBT inputs as an array
611
- *
612
- * Returns raw PSBT input data including witness_utxo and derivation info.
613
- * For parsed transaction data with address identification, use
614
- * parseTransactionWithWalletKeys() instead.
615
- *
616
- * @returns Array of PsbtInputData objects
617
- */
618
- getInputs() {
619
- return this._wasm.get_inputs();
620
- }
621
- /**
622
- * Get all PSBT outputs as an array
623
- *
624
- * Returns raw PSBT output data without address resolution.
625
- * For output data with addresses, use getOutputsWithAddress().
626
- *
627
- * @returns Array of PsbtOutputData objects
628
- */
629
- getOutputs() {
630
- return this._wasm.get_outputs();
631
- }
632
544
  /**
633
545
  * Get all PSBT outputs with resolved address strings
634
546
  *
@@ -648,13 +560,6 @@ export class BitGoPsbt {
648
560
  getOutputsWithAddress() {
649
561
  return this._wasm.get_outputs_with_address();
650
562
  }
651
- /**
652
- * Returns the unordered global xpubs from this PSBT as BIP32 instances.
653
- */
654
- getGlobalXpubs() {
655
- const result = this._wasm.get_global_xpubs();
656
- return result.map((w) => BIP32.fromWasm(w));
657
- }
658
563
  }
659
564
  /**
660
565
  * Extract sorted wallet keys from a PSBT's global xpub fields.
@@ -0,0 +1,44 @@
1
+ import type { PsbtInputData, PsbtOutputData } from "./wasm/wasm_utxo.js";
2
+ import { BIP32 } from "./bip32.js";
3
+ import type { PsbtKvKey } from "./fixedScriptWallet/BitGoKeySubtype.js";
4
+ interface WasmPsbtBase {
5
+ input_count(): number;
6
+ output_count(): number;
7
+ version(): number;
8
+ lock_time(): number;
9
+ unsigned_tx_id(): string;
10
+ serialize(): Uint8Array;
11
+ get_inputs(): unknown;
12
+ get_outputs(): unknown;
13
+ get_global_xpubs(): unknown;
14
+ remove_input(index: number): void;
15
+ remove_output(index: number): void;
16
+ set_kv(key: unknown, value: Uint8Array): void;
17
+ get_kv(key: unknown): Uint8Array | null | undefined;
18
+ set_input_kv(index: number, key: unknown, value: Uint8Array): void;
19
+ get_input_kv(index: number, key: unknown): Uint8Array | null | undefined;
20
+ set_output_kv(index: number, key: unknown, value: Uint8Array): void;
21
+ get_output_kv(index: number, key: unknown): Uint8Array | null | undefined;
22
+ }
23
+ export declare abstract class PsbtBase<W extends WasmPsbtBase> {
24
+ protected _wasm: W;
25
+ constructor(wasm: W);
26
+ inputCount(): number;
27
+ outputCount(): number;
28
+ version(): number;
29
+ lockTime(): number;
30
+ unsignedTxId(): string;
31
+ serialize(): Uint8Array;
32
+ getInputs(): PsbtInputData[];
33
+ getOutputs(): PsbtOutputData[];
34
+ getGlobalXpubs(): BIP32[];
35
+ removeInput(index: number): void;
36
+ removeOutput(index: number): void;
37
+ setKV(key: PsbtKvKey, value: Uint8Array): void;
38
+ getKV(key: PsbtKvKey): Uint8Array | undefined;
39
+ setInputKV(index: number, key: PsbtKvKey, value: Uint8Array): void;
40
+ getInputKV(index: number, key: PsbtKvKey): Uint8Array | undefined;
41
+ setOutputKV(index: number, key: PsbtKvKey, value: Uint8Array): void;
42
+ getOutputKV(index: number, key: PsbtKvKey): Uint8Array | undefined;
43
+ }
44
+ export {};
@@ -0,0 +1,58 @@
1
+ import { BIP32 } from "./bip32.js";
2
+ export class PsbtBase {
3
+ _wasm;
4
+ constructor(wasm) {
5
+ this._wasm = wasm;
6
+ }
7
+ inputCount() {
8
+ return this._wasm.input_count();
9
+ }
10
+ outputCount() {
11
+ return this._wasm.output_count();
12
+ }
13
+ version() {
14
+ return this._wasm.version();
15
+ }
16
+ lockTime() {
17
+ return this._wasm.lock_time();
18
+ }
19
+ unsignedTxId() {
20
+ return this._wasm.unsigned_tx_id();
21
+ }
22
+ serialize() {
23
+ return this._wasm.serialize();
24
+ }
25
+ getInputs() {
26
+ return this._wasm.get_inputs();
27
+ }
28
+ getOutputs() {
29
+ return this._wasm.get_outputs();
30
+ }
31
+ getGlobalXpubs() {
32
+ return this._wasm.get_global_xpubs().map((w) => BIP32.fromWasm(w));
33
+ }
34
+ removeInput(index) {
35
+ this._wasm.remove_input(index);
36
+ }
37
+ removeOutput(index) {
38
+ this._wasm.remove_output(index);
39
+ }
40
+ setKV(key, value) {
41
+ this._wasm.set_kv(key, value);
42
+ }
43
+ getKV(key) {
44
+ return this._wasm.get_kv(key) ?? undefined;
45
+ }
46
+ setInputKV(index, key, value) {
47
+ this._wasm.set_input_kv(index, key, value);
48
+ }
49
+ getInputKV(index, key) {
50
+ return this._wasm.get_input_kv(index, key) ?? undefined;
51
+ }
52
+ setOutputKV(index, key, value) {
53
+ this._wasm.set_output_kv(index, key, value);
54
+ }
55
+ getOutputKV(index, key) {
56
+ return this._wasm.get_output_kv(index, key) ?? undefined;
57
+ }
58
+ }
@@ -1,5 +1,7 @@
1
- import { WasmDashTransaction, WasmTransaction, WasmZcashTransaction, type TxInputData, type TxOutputData, type TxOutputDataWithAddress } from "./wasm/wasm_utxo.js";
1
+ import { WasmDashTransaction, WasmTransaction, WasmZcashTransaction } from "./wasm/wasm_utxo.js";
2
+ import type { TxInputData, TxOutputData, TxOutputDataWithAddress } from "./wasm/wasm_utxo.js";
2
3
  import type { CoinName } from "./coinName.js";
4
+ import { TransactionBase } from "./transactionBase.js";
3
5
  /** Common read-only interface shared by transactions and PSBTs */
4
6
  export interface ITransactionCommon<TInput, TOutput> {
5
7
  inputCount(): number;
@@ -20,8 +22,7 @@ export interface ITransaction extends ITransactionCommon<TxInputData, TxOutputDa
20
22
  *
21
23
  * Provides a camelCase, strongly-typed API over the snake_case WASM bindings.
22
24
  */
23
- export declare class Transaction implements ITransaction {
24
- private _wasm;
25
+ export declare class Transaction extends TransactionBase<WasmTransaction> {
25
26
  private constructor();
26
27
  /**
27
28
  * Create an empty transaction (version 1, locktime 0)
@@ -41,16 +42,6 @@ export declare class Transaction implements ITransaction {
41
42
  addInput(txid: string, vout: number, sequence?: number): number;
42
43
  addOutputAtIndex(index: number, script: Uint8Array, value: bigint): number;
43
44
  addOutput(script: Uint8Array, value: bigint): number;
44
- toBytes(): Uint8Array;
45
- /**
46
- * Get the transaction ID (txid)
47
- *
48
- * The txid is the double SHA256 of the transaction bytes (excluding witness
49
- * data for segwit transactions), displayed in reverse byte order as is standard.
50
- *
51
- * @returns The transaction ID as a hex string
52
- */
53
- getId(): string;
54
45
  /**
55
46
  * Get the virtual size of the transaction
56
47
  *
@@ -59,13 +50,6 @@ export declare class Transaction implements ITransaction {
59
50
  * @returns The virtual size in virtual bytes (vbytes)
60
51
  */
61
52
  getVSize(): number;
62
- inputCount(): number;
63
- outputCount(): number;
64
- version(): number;
65
- lockTime(): number;
66
- getInputs(): TxInputData[];
67
- getOutputs(): TxOutputData[];
68
- getOutputsWithAddress(coin: CoinName): TxOutputDataWithAddress[];
69
53
  /** @internal */
70
54
  get wasm(): WasmTransaction;
71
55
  }
@@ -74,29 +58,11 @@ export declare class Transaction implements ITransaction {
74
58
  *
75
59
  * Provides a camelCase, strongly-typed API over the snake_case WASM bindings.
76
60
  */
77
- export declare class ZcashTransaction implements ITransaction {
78
- private _wasm;
61
+ export declare class ZcashTransaction extends TransactionBase<WasmZcashTransaction> {
79
62
  private constructor();
80
63
  static fromBytes(bytes: Uint8Array): ZcashTransaction;
81
64
  /** @internal Create from WASM instance directly (avoids re-parsing bytes) */
82
65
  static fromWasm(wasm: WasmZcashTransaction): ZcashTransaction;
83
- toBytes(): Uint8Array;
84
- /**
85
- * Get the transaction ID (txid)
86
- *
87
- * The txid is the double SHA256 of the full Zcash transaction bytes,
88
- * displayed in reverse byte order as is standard.
89
- *
90
- * @returns The transaction ID as a hex string
91
- */
92
- getId(): string;
93
- inputCount(): number;
94
- outputCount(): number;
95
- version(): number;
96
- lockTime(): number;
97
- getInputs(): TxInputData[];
98
- getOutputs(): TxOutputData[];
99
- getOutputsWithAddress(coin: CoinName): TxOutputDataWithAddress[];
100
66
  /** @internal */
101
67
  get wasm(): WasmZcashTransaction;
102
68
  }
@@ -105,29 +71,11 @@ export declare class ZcashTransaction implements ITransaction {
105
71
  *
106
72
  * Round-trip only: bytes -> parse -> bytes.
107
73
  */
108
- export declare class DashTransaction implements ITransaction {
109
- private _wasm;
74
+ export declare class DashTransaction extends TransactionBase<WasmDashTransaction> {
110
75
  private constructor();
111
76
  static fromBytes(bytes: Uint8Array): DashTransaction;
112
77
  /** @internal Create from WASM instance directly (avoids re-parsing bytes) */
113
78
  static fromWasm(wasm: WasmDashTransaction): DashTransaction;
114
- toBytes(): Uint8Array;
115
- /**
116
- * Get the transaction ID (txid)
117
- *
118
- * The txid is the double SHA256 of the full Dash transaction bytes,
119
- * displayed in reverse byte order as is standard.
120
- *
121
- * @returns The transaction ID as a hex string
122
- */
123
- getId(): string;
124
- inputCount(): number;
125
- outputCount(): number;
126
- version(): number;
127
- lockTime(): number;
128
- getInputs(): TxInputData[];
129
- getOutputs(): TxOutputData[];
130
- getOutputsWithAddress(coin: CoinName): TxOutputDataWithAddress[];
131
79
  /** @internal */
132
80
  get wasm(): WasmDashTransaction;
133
81
  }