@bitgo/wasm-utxo 1.14.1 → 1.15.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.
@@ -8,6 +8,31 @@ export class BitGoPsbt {
8
8
  constructor(wasm) {
9
9
  this.wasm = wasm;
10
10
  }
11
+ /**
12
+ * Create an empty PSBT for the given network with wallet keys
13
+ *
14
+ * The wallet keys are used to set global xpubs in the PSBT, which identifies
15
+ * the keys that will be used for signing.
16
+ *
17
+ * @param network - Network name (utxolib name like "bitcoin" or coin name like "btc")
18
+ * @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
19
+ * @param options - Optional transaction parameters (version, lockTime)
20
+ * @returns A new empty BitGoPsbt instance
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * // Create empty PSBT with wallet keys
25
+ * const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys);
26
+ *
27
+ * // Create with custom version and lockTime
28
+ * const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys, { version: 1, lockTime: 500000 });
29
+ * ```
30
+ */
31
+ static createEmpty(network, walletKeys, options) {
32
+ const keys = RootWalletKeys.from(walletKeys);
33
+ const wasm = WasmBitGoPsbt.create_empty(network, keys.wasm, options?.version, options?.lockTime);
34
+ return new BitGoPsbt(wasm);
35
+ }
11
36
  /**
12
37
  * Deserialize a PSBT from bytes
13
38
  * @param bytes - The PSBT bytes
@@ -18,6 +43,145 @@ export class BitGoPsbt {
18
43
  const wasm = WasmBitGoPsbt.from_bytes(bytes, network);
19
44
  return new BitGoPsbt(wasm);
20
45
  }
46
+ /**
47
+ * Add an input to the PSBT
48
+ *
49
+ * This adds a transaction input and corresponding PSBT input metadata.
50
+ * The witness_utxo is automatically populated for modern signing compatibility.
51
+ *
52
+ * @param options - Input options (txid, vout, value, sequence)
53
+ * @param script - Output script of the UTXO being spent
54
+ * @returns The index of the newly added input
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const inputIndex = psbt.addInput({
59
+ * txid: "abc123...",
60
+ * vout: 0,
61
+ * value: 100000n,
62
+ * }, outputScript);
63
+ * ```
64
+ */
65
+ addInput(options, script) {
66
+ return this.wasm.add_input(options.txid, options.vout, options.value, script, options.sequence, options.prevTx);
67
+ }
68
+ /**
69
+ * Add an output to the PSBT
70
+ *
71
+ * @param options - Output options (script, value)
72
+ * @returns The index of the newly added output
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * const outputIndex = psbt.addOutput({
77
+ * script: outputScript,
78
+ * value: 50000n,
79
+ * });
80
+ * ```
81
+ */
82
+ addOutput(options) {
83
+ return this.wasm.add_output(options.script, options.value);
84
+ }
85
+ /**
86
+ * Add a wallet input with full PSBT metadata
87
+ *
88
+ * This is a higher-level method that adds an input and populates all required
89
+ * PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
90
+ *
91
+ * For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript (signPath not needed)
92
+ * For p2tr/p2trMusig2 script path: Sets tapLeafScript, tapBip32Derivation (signPath required)
93
+ * For p2trMusig2 key path: Sets tapInternalKey, tapMerkleRoot, tapBip32Derivation, musig2 participants (signPath required)
94
+ *
95
+ * @param inputOptions - Common input options (txid, vout, value, sequence)
96
+ * @param walletKeys - The wallet's root keys
97
+ * @param walletOptions - Wallet-specific options (scriptId, signPath, prevTx)
98
+ * @returns The index of the newly added input
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * // Add a p2shP2wsh input (signPath not needed)
103
+ * const inputIndex = psbt.addWalletInput(
104
+ * { txid: "abc123...", vout: 0, value: 100000n },
105
+ * walletKeys,
106
+ * { scriptId: { chain: 10, index: 0 } }, // p2shP2wsh external
107
+ * );
108
+ *
109
+ * // Add a p2trMusig2 key path input (signPath required)
110
+ * const inputIndex = psbt.addWalletInput(
111
+ * { txid: "def456...", vout: 1, value: 50000n },
112
+ * walletKeys,
113
+ * { scriptId: { chain: 40, index: 5 }, signPath: { signer: "user", cosigner: "bitgo" } },
114
+ * );
115
+ *
116
+ * // Add p2trMusig2 with backup key (script path spend)
117
+ * const inputIndex = psbt.addWalletInput(
118
+ * { txid: "ghi789...", vout: 0, value: 75000n },
119
+ * walletKeys,
120
+ * { scriptId: { chain: 40, index: 3 }, signPath: { signer: "user", cosigner: "backup" } },
121
+ * );
122
+ * ```
123
+ */
124
+ addWalletInput(inputOptions, walletKeys, walletOptions) {
125
+ const keys = RootWalletKeys.from(walletKeys);
126
+ return this.wasm.add_wallet_input(inputOptions.txid, inputOptions.vout, inputOptions.value, keys.wasm, walletOptions.scriptId.chain, walletOptions.scriptId.index, walletOptions.signPath?.signer, walletOptions.signPath?.cosigner, inputOptions.sequence, inputOptions.prevTx);
127
+ }
128
+ /**
129
+ * Add a wallet output with full PSBT metadata
130
+ *
131
+ * This creates a verifiable wallet output (typically for change) with all required
132
+ * PSBT fields (scripts, derivation info) based on the wallet's chain type.
133
+ *
134
+ * For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript
135
+ * For p2tr/p2trMusig2: Sets tapInternalKey, tapBip32Derivation
136
+ *
137
+ * @param walletKeys - The wallet's root keys
138
+ * @param options - Output options including chain, index, and value
139
+ * @returns The index of the newly added output
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * // Add a p2shP2wsh change output
144
+ * const outputIndex = psbt.addWalletOutput(walletKeys, {
145
+ * chain: 11, // p2shP2wsh internal (change)
146
+ * index: 0,
147
+ * value: 50000n,
148
+ * });
149
+ *
150
+ * // Add a p2trMusig2 change output
151
+ * const outputIndex = psbt.addWalletOutput(walletKeys, {
152
+ * chain: 41, // p2trMusig2 internal (change)
153
+ * index: 5,
154
+ * value: 25000n,
155
+ * });
156
+ * ```
157
+ */
158
+ addWalletOutput(walletKeys, options) {
159
+ const keys = RootWalletKeys.from(walletKeys);
160
+ return this.wasm.add_wallet_output(options.chain, options.index, options.value, keys.wasm);
161
+ }
162
+ /**
163
+ * Add a replay protection input to the PSBT
164
+ *
165
+ * Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
166
+ * transaction replay attacks. They use a simple pubkey script without wallet derivation.
167
+ *
168
+ * @param inputOptions - Common input options (txid, vout, value, sequence)
169
+ * @param key - ECPair containing the public key for the replay protection input
170
+ * @returns The index of the newly added input
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * // Add a replay protection input using ECPair
175
+ * const inputIndex = psbt.addReplayProtectionInput(
176
+ * { txid: "abc123...", vout: 0, value: 1000n },
177
+ * replayProtectionKey,
178
+ * );
179
+ * ```
180
+ */
181
+ addReplayProtectionInput(inputOptions, key) {
182
+ const ecpair = ECPair.from(key);
183
+ return this.wasm.add_replay_protection_input(ecpair.wasm, inputOptions.txid, inputOptions.vout, inputOptions.value, inputOptions.sequence);
184
+ }
21
185
  /**
22
186
  * Get the unsigned transaction ID
23
187
  * @returns The unsigned transaction ID
@@ -25,6 +189,20 @@ export class BitGoPsbt {
25
189
  unsignedTxid() {
26
190
  return this.wasm.unsigned_txid();
27
191
  }
192
+ /**
193
+ * Get the transaction version
194
+ * @returns The transaction version number
195
+ */
196
+ get version() {
197
+ return this.wasm.version();
198
+ }
199
+ /**
200
+ * Get the transaction lock time
201
+ * @returns The transaction lock time
202
+ */
203
+ get lockTime() {
204
+ return this.wasm.lock_time();
205
+ }
28
206
  /**
29
207
  * Parse transaction with wallet keys to identify wallet inputs/outputs
30
208
  * @param walletKeys - The wallet keys to use for identification
@@ -1,4 +1,4 @@
1
1
  export { RootWalletKeys, type WalletKeysArg, type IWalletKeys } from "./RootWalletKeys.js";
2
2
  export { ReplayProtection, type ReplayProtectionArg } from "./ReplayProtection.js";
3
3
  export { outputScript, address } from "./address.js";
4
- export { BitGoPsbt, type NetworkName, type ScriptId, type InputScriptType, type ParsedInput, type ParsedOutput, type ParsedTransaction, } from "./BitGoPsbt.js";
4
+ export { BitGoPsbt, type NetworkName, type ScriptId, type InputScriptType, type ParsedInput, type ParsedOutput, type ParsedTransaction, type SignPath, } from "./BitGoPsbt.js";
@@ -13,10 +13,31 @@ export class BitGoPsbt {
13
13
  private constructor();
14
14
  free(): void;
15
15
  [Symbol.dispose](): void;
16
+ /**
17
+ * Add an output to the PSBT
18
+ *
19
+ * # Arguments
20
+ * * `script` - The output script (scriptPubKey)
21
+ * * `value` - The value in satoshis
22
+ *
23
+ * # Returns
24
+ * The index of the newly added output
25
+ */
26
+ add_output(script: Uint8Array, value: bigint): number;
16
27
  /**
17
28
  * Deserialize a PSBT from bytes with network-specific logic
18
29
  */
19
30
  static from_bytes(bytes: Uint8Array, network: string): BitGoPsbt;
31
+ /**
32
+ * Create an empty PSBT for the given network with wallet keys
33
+ *
34
+ * # Arguments
35
+ * * `network` - Network name (utxolib or coin name)
36
+ * * `wallet_keys` - The wallet's root keys (used to set global xpubs)
37
+ * * `version` - Optional transaction version (default: 2)
38
+ * * `lock_time` - Optional lock time (default: 0)
39
+ */
40
+ static create_empty(network: string, wallet_keys: WasmRootWalletKeys, version?: number | null, lock_time?: number | null): BitGoPsbt;
20
41
  /**
21
42
  * Get the unsigned transaction ID
22
43
  */
@@ -41,6 +62,44 @@ export class BitGoPsbt {
41
62
  * - `Err(WasmUtxoError)` if signing fails
42
63
  */
43
64
  sign_with_xpriv(input_index: number, xpriv: WasmBIP32): void;
65
+ /**
66
+ * Add a wallet input with full PSBT metadata
67
+ *
68
+ * This is a higher-level method that adds an input and populates all required
69
+ * PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
70
+ *
71
+ * # Arguments
72
+ * * `txid` - The transaction ID (hex string)
73
+ * * `vout` - The output index being spent
74
+ * * `value` - The value in satoshis
75
+ * * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
76
+ * * `index` - The derivation index
77
+ * * `wallet_keys` - The root wallet keys
78
+ * * `signer` - The key that will sign ("user", "backup", or "bitgo") - required for p2tr/p2trMusig2
79
+ * * `cosigner` - The key that will co-sign - required for p2tr/p2trMusig2
80
+ * * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
81
+ * * `prev_tx` - Optional full previous transaction bytes (for non-segwit)
82
+ *
83
+ * # Returns
84
+ * The index of the newly added input
85
+ */
86
+ add_wallet_input(txid: string, vout: number, value: bigint, wallet_keys: WasmRootWalletKeys, chain: number, index: number, signer?: string | null, cosigner?: string | null, sequence?: number | null, prev_tx?: Uint8Array | null): number;
87
+ /**
88
+ * Add a wallet output with full PSBT metadata
89
+ *
90
+ * This creates a verifiable wallet output (typically for change) with all required
91
+ * PSBT fields (scripts, derivation info) based on the wallet's chain type.
92
+ *
93
+ * # Arguments
94
+ * * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
95
+ * * `index` - The derivation index
96
+ * * `value` - The value in satoshis
97
+ * * `wallet_keys` - The root wallet keys
98
+ *
99
+ * # Returns
100
+ * The index of the newly added output
101
+ */
102
+ add_wallet_output(chain: number, index: number, value: bigint, wallet_keys: WasmRootWalletKeys): number;
44
103
  /**
45
104
  * Sign a single input with a raw private key
46
105
  *
@@ -181,6 +240,23 @@ export class BitGoPsbt {
181
240
  * - `Err(WasmUtxoError)` if the input index is out of bounds, derivation fails, or verification fails
182
241
  */
183
242
  verify_signature_with_xpub(input_index: number, xpub: WasmBIP32): boolean;
243
+ /**
244
+ * Add a replay protection input to the PSBT
245
+ *
246
+ * Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
247
+ * transaction replay attacks. They use a simple pubkey script without wallet derivation.
248
+ *
249
+ * # Arguments
250
+ * * `ecpair` - The ECPair containing the public key for the replay protection input
251
+ * * `txid` - The transaction ID (hex string) of the output being spent
252
+ * * `vout` - The output index being spent
253
+ * * `value` - The value in satoshis
254
+ * * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
255
+ *
256
+ * # Returns
257
+ * The index of the newly added input
258
+ */
259
+ add_replay_protection_input(ecpair: WasmECPair, txid: string, vout: number, value: bigint, sequence?: number | null): number;
184
260
  /**
185
261
  * Parse outputs with wallet keys to identify which outputs belong to a wallet
186
262
  *
@@ -213,6 +289,28 @@ export class BitGoPsbt {
213
289
  * Get the network of the PSBT
214
290
  */
215
291
  network(): string;
292
+ /**
293
+ * Get the transaction version
294
+ */
295
+ version(): number;
296
+ /**
297
+ * Add an input to the PSBT
298
+ *
299
+ * # Arguments
300
+ * * `txid` - The transaction ID (hex string) of the output being spent
301
+ * * `vout` - The output index being spent
302
+ * * `value` - The value in satoshis of the output being spent
303
+ * * `script` - The output script (scriptPubKey) of the output being spent
304
+ * * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
305
+ *
306
+ * # Returns
307
+ * The index of the newly added input
308
+ */
309
+ add_input(txid: string, vout: number, value: bigint, script: Uint8Array, sequence?: number | null, prev_tx?: Uint8Array | null): number;
310
+ /**
311
+ * Get the transaction lock time
312
+ */
313
+ lock_time(): number;
216
314
  /**
217
315
  * Serialize the PSBT to bytes
218
316
  *
@@ -305,6 +305,36 @@ export class BitGoPsbt {
305
305
  const ptr = this.__destroy_into_raw();
306
306
  wasm.__wbg_bitgopsbt_free(ptr, 0);
307
307
  }
308
+ /**
309
+ * Add an output to the PSBT
310
+ *
311
+ * # Arguments
312
+ * * `script` - The output script (scriptPubKey)
313
+ * * `value` - The value in satoshis
314
+ *
315
+ * # Returns
316
+ * The index of the newly added output
317
+ * @param {Uint8Array} script
318
+ * @param {bigint} value
319
+ * @returns {number}
320
+ */
321
+ add_output(script, value) {
322
+ try {
323
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
324
+ const ptr0 = passArray8ToWasm0(script, wasm.__wbindgen_export);
325
+ const len0 = WASM_VECTOR_LEN;
326
+ wasm.bitgopsbt_add_output(retptr, this.__wbg_ptr, ptr0, len0, value);
327
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
328
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
329
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
330
+ if (r2) {
331
+ throw takeObject(r1);
332
+ }
333
+ return r0 >>> 0;
334
+ } finally {
335
+ wasm.__wbindgen_add_to_stack_pointer(16);
336
+ }
337
+ }
308
338
  /**
309
339
  * Deserialize a PSBT from bytes with network-specific logic
310
340
  * @param {Uint8Array} bytes
@@ -330,6 +360,38 @@ export class BitGoPsbt {
330
360
  wasm.__wbindgen_add_to_stack_pointer(16);
331
361
  }
332
362
  }
363
+ /**
364
+ * Create an empty PSBT for the given network with wallet keys
365
+ *
366
+ * # Arguments
367
+ * * `network` - Network name (utxolib or coin name)
368
+ * * `wallet_keys` - The wallet's root keys (used to set global xpubs)
369
+ * * `version` - Optional transaction version (default: 2)
370
+ * * `lock_time` - Optional lock time (default: 0)
371
+ * @param {string} network
372
+ * @param {WasmRootWalletKeys} wallet_keys
373
+ * @param {number | null} [version]
374
+ * @param {number | null} [lock_time]
375
+ * @returns {BitGoPsbt}
376
+ */
377
+ static create_empty(network, wallet_keys, version, lock_time) {
378
+ try {
379
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
380
+ const ptr0 = passStringToWasm0(network, wasm.__wbindgen_export, wasm.__wbindgen_export2);
381
+ const len0 = WASM_VECTOR_LEN;
382
+ _assertClass(wallet_keys, WasmRootWalletKeys);
383
+ wasm.bitgopsbt_create_empty(retptr, ptr0, len0, wallet_keys.__wbg_ptr, isLikeNone(version) ? 0x100000001 : (version) >> 0, isLikeNone(lock_time) ? 0x100000001 : (lock_time) >>> 0);
384
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
385
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
386
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
387
+ if (r2) {
388
+ throw takeObject(r1);
389
+ }
390
+ return BitGoPsbt.__wrap(r0);
391
+ } finally {
392
+ wasm.__wbindgen_add_to_stack_pointer(16);
393
+ }
394
+ }
333
395
  /**
334
396
  * Get the unsigned transaction ID
335
397
  * @returns {string}
@@ -385,6 +447,98 @@ export class BitGoPsbt {
385
447
  wasm.__wbindgen_add_to_stack_pointer(16);
386
448
  }
387
449
  }
450
+ /**
451
+ * Add a wallet input with full PSBT metadata
452
+ *
453
+ * This is a higher-level method that adds an input and populates all required
454
+ * PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
455
+ *
456
+ * # Arguments
457
+ * * `txid` - The transaction ID (hex string)
458
+ * * `vout` - The output index being spent
459
+ * * `value` - The value in satoshis
460
+ * * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
461
+ * * `index` - The derivation index
462
+ * * `wallet_keys` - The root wallet keys
463
+ * * `signer` - The key that will sign ("user", "backup", or "bitgo") - required for p2tr/p2trMusig2
464
+ * * `cosigner` - The key that will co-sign - required for p2tr/p2trMusig2
465
+ * * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
466
+ * * `prev_tx` - Optional full previous transaction bytes (for non-segwit)
467
+ *
468
+ * # Returns
469
+ * The index of the newly added input
470
+ * @param {string} txid
471
+ * @param {number} vout
472
+ * @param {bigint} value
473
+ * @param {WasmRootWalletKeys} wallet_keys
474
+ * @param {number} chain
475
+ * @param {number} index
476
+ * @param {string | null} [signer]
477
+ * @param {string | null} [cosigner]
478
+ * @param {number | null} [sequence]
479
+ * @param {Uint8Array | null} [prev_tx]
480
+ * @returns {number}
481
+ */
482
+ add_wallet_input(txid, vout, value, wallet_keys, chain, index, signer, cosigner, sequence, prev_tx) {
483
+ try {
484
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
485
+ const ptr0 = passStringToWasm0(txid, wasm.__wbindgen_export, wasm.__wbindgen_export2);
486
+ const len0 = WASM_VECTOR_LEN;
487
+ _assertClass(wallet_keys, WasmRootWalletKeys);
488
+ var ptr1 = isLikeNone(signer) ? 0 : passStringToWasm0(signer, wasm.__wbindgen_export, wasm.__wbindgen_export2);
489
+ var len1 = WASM_VECTOR_LEN;
490
+ var ptr2 = isLikeNone(cosigner) ? 0 : passStringToWasm0(cosigner, wasm.__wbindgen_export, wasm.__wbindgen_export2);
491
+ var len2 = WASM_VECTOR_LEN;
492
+ var ptr3 = isLikeNone(prev_tx) ? 0 : passArray8ToWasm0(prev_tx, wasm.__wbindgen_export);
493
+ var len3 = WASM_VECTOR_LEN;
494
+ wasm.bitgopsbt_add_wallet_input(retptr, this.__wbg_ptr, ptr0, len0, vout, value, wallet_keys.__wbg_ptr, chain, index, ptr1, len1, ptr2, len2, isLikeNone(sequence) ? 0x100000001 : (sequence) >>> 0, ptr3, len3);
495
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
496
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
497
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
498
+ if (r2) {
499
+ throw takeObject(r1);
500
+ }
501
+ return r0 >>> 0;
502
+ } finally {
503
+ wasm.__wbindgen_add_to_stack_pointer(16);
504
+ }
505
+ }
506
+ /**
507
+ * Add a wallet output with full PSBT metadata
508
+ *
509
+ * This creates a verifiable wallet output (typically for change) with all required
510
+ * PSBT fields (scripts, derivation info) based on the wallet's chain type.
511
+ *
512
+ * # Arguments
513
+ * * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
514
+ * * `index` - The derivation index
515
+ * * `value` - The value in satoshis
516
+ * * `wallet_keys` - The root wallet keys
517
+ *
518
+ * # Returns
519
+ * The index of the newly added output
520
+ * @param {number} chain
521
+ * @param {number} index
522
+ * @param {bigint} value
523
+ * @param {WasmRootWalletKeys} wallet_keys
524
+ * @returns {number}
525
+ */
526
+ add_wallet_output(chain, index, value, wallet_keys) {
527
+ try {
528
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
529
+ _assertClass(wallet_keys, WasmRootWalletKeys);
530
+ wasm.bitgopsbt_add_wallet_output(retptr, this.__wbg_ptr, chain, index, value, wallet_keys.__wbg_ptr);
531
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
532
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
533
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
534
+ if (r2) {
535
+ throw takeObject(r1);
536
+ }
537
+ return r0 >>> 0;
538
+ } finally {
539
+ wasm.__wbindgen_add_to_stack_pointer(16);
540
+ }
541
+ }
388
542
  /**
389
543
  * Sign a single input with a raw private key
390
544
  *
@@ -656,6 +810,46 @@ export class BitGoPsbt {
656
810
  wasm.__wbindgen_add_to_stack_pointer(16);
657
811
  }
658
812
  }
813
+ /**
814
+ * Add a replay protection input to the PSBT
815
+ *
816
+ * Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
817
+ * transaction replay attacks. They use a simple pubkey script without wallet derivation.
818
+ *
819
+ * # Arguments
820
+ * * `ecpair` - The ECPair containing the public key for the replay protection input
821
+ * * `txid` - The transaction ID (hex string) of the output being spent
822
+ * * `vout` - The output index being spent
823
+ * * `value` - The value in satoshis
824
+ * * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
825
+ *
826
+ * # Returns
827
+ * The index of the newly added input
828
+ * @param {WasmECPair} ecpair
829
+ * @param {string} txid
830
+ * @param {number} vout
831
+ * @param {bigint} value
832
+ * @param {number | null} [sequence]
833
+ * @returns {number}
834
+ */
835
+ add_replay_protection_input(ecpair, txid, vout, value, sequence) {
836
+ try {
837
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
838
+ _assertClass(ecpair, WasmECPair);
839
+ const ptr0 = passStringToWasm0(txid, wasm.__wbindgen_export, wasm.__wbindgen_export2);
840
+ const len0 = WASM_VECTOR_LEN;
841
+ wasm.bitgopsbt_add_replay_protection_input(retptr, this.__wbg_ptr, ecpair.__wbg_ptr, ptr0, len0, vout, value, isLikeNone(sequence) ? 0x100000001 : (sequence) >>> 0);
842
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
843
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
844
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
845
+ if (r2) {
846
+ throw takeObject(r1);
847
+ }
848
+ return r0 >>> 0;
849
+ } finally {
850
+ wasm.__wbindgen_add_to_stack_pointer(16);
851
+ }
852
+ }
659
853
  /**
660
854
  * Parse outputs with wallet keys to identify which outputs belong to a wallet
661
855
  *
@@ -764,6 +958,63 @@ export class BitGoPsbt {
764
958
  wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
765
959
  }
766
960
  }
961
+ /**
962
+ * Get the transaction version
963
+ * @returns {number}
964
+ */
965
+ version() {
966
+ const ret = wasm.bitgopsbt_version(this.__wbg_ptr);
967
+ return ret;
968
+ }
969
+ /**
970
+ * Add an input to the PSBT
971
+ *
972
+ * # Arguments
973
+ * * `txid` - The transaction ID (hex string) of the output being spent
974
+ * * `vout` - The output index being spent
975
+ * * `value` - The value in satoshis of the output being spent
976
+ * * `script` - The output script (scriptPubKey) of the output being spent
977
+ * * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
978
+ *
979
+ * # Returns
980
+ * The index of the newly added input
981
+ * @param {string} txid
982
+ * @param {number} vout
983
+ * @param {bigint} value
984
+ * @param {Uint8Array} script
985
+ * @param {number | null} [sequence]
986
+ * @param {Uint8Array | null} [prev_tx]
987
+ * @returns {number}
988
+ */
989
+ add_input(txid, vout, value, script, sequence, prev_tx) {
990
+ try {
991
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
992
+ const ptr0 = passStringToWasm0(txid, wasm.__wbindgen_export, wasm.__wbindgen_export2);
993
+ const len0 = WASM_VECTOR_LEN;
994
+ const ptr1 = passArray8ToWasm0(script, wasm.__wbindgen_export);
995
+ const len1 = WASM_VECTOR_LEN;
996
+ var ptr2 = isLikeNone(prev_tx) ? 0 : passArray8ToWasm0(prev_tx, wasm.__wbindgen_export);
997
+ var len2 = WASM_VECTOR_LEN;
998
+ wasm.bitgopsbt_add_input(retptr, this.__wbg_ptr, ptr0, len0, vout, value, ptr1, len1, isLikeNone(sequence) ? 0x100000001 : (sequence) >>> 0, ptr2, len2);
999
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1000
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1001
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1002
+ if (r2) {
1003
+ throw takeObject(r1);
1004
+ }
1005
+ return r0 >>> 0;
1006
+ } finally {
1007
+ wasm.__wbindgen_add_to_stack_pointer(16);
1008
+ }
1009
+ }
1010
+ /**
1011
+ * Get the transaction lock time
1012
+ * @returns {number}
1013
+ */
1014
+ lock_time() {
1015
+ const ret = wasm.bitgopsbt_lock_time(this.__wbg_ptr);
1016
+ return ret >>> 0;
1017
+ }
767
1018
  /**
768
1019
  * Serialize the PSBT to bytes
769
1020
  *
Binary file