@bitgo/wasm-utxo 1.27.0 → 1.29.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.
- package/dist/cjs/js/bip32.d.ts +7 -0
- package/dist/cjs/js/bip32.js +16 -0
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +60 -26
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +56 -36
- package/dist/cjs/js/fixedScriptWallet/chains.d.ts +5 -0
- package/dist/cjs/js/fixedScriptWallet/chains.js +6 -2
- package/dist/cjs/js/fixedScriptWallet/index.d.ts +19 -2
- package/dist/cjs/js/fixedScriptWallet/index.js +25 -1
- package/dist/cjs/js/fixedScriptWallet/scriptType.d.ts +15 -5
- package/dist/cjs/js/fixedScriptWallet/scriptType.js +28 -0
- package/dist/cjs/js/testutils/AcidTest.d.ts +132 -0
- package/dist/cjs/js/testutils/AcidTest.js +306 -0
- package/dist/cjs/js/testutils/index.d.ts +2 -0
- package/dist/cjs/js/testutils/index.js +18 -0
- package/dist/cjs/js/testutils/keys.d.ts +76 -0
- package/dist/cjs/js/testutils/keys.js +154 -0
- package/dist/cjs/js/wasm/wasm_utxo.d.ts +183 -0
- package/dist/cjs/js/wasm/wasm_utxo.js +354 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +67 -56
- package/dist/esm/js/bip32.d.ts +7 -0
- package/dist/esm/js/bip32.js +15 -0
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +60 -26
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +57 -37
- package/dist/esm/js/fixedScriptWallet/chains.d.ts +5 -0
- package/dist/esm/js/fixedScriptWallet/chains.js +6 -3
- package/dist/esm/js/fixedScriptWallet/index.d.ts +19 -2
- package/dist/esm/js/fixedScriptWallet/index.js +21 -1
- package/dist/esm/js/fixedScriptWallet/scriptType.d.ts +15 -5
- package/dist/esm/js/fixedScriptWallet/scriptType.js +27 -1
- package/dist/esm/js/testutils/AcidTest.d.ts +132 -0
- package/dist/esm/js/testutils/AcidTest.js +302 -0
- package/dist/esm/js/testutils/index.d.ts +2 -0
- package/dist/esm/js/testutils/index.js +2 -0
- package/dist/esm/js/testutils/keys.d.ts +76 -0
- package/dist/esm/js/testutils/keys.js +113 -0
- package/dist/esm/js/wasm/wasm_utxo.d.ts +183 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.js +354 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +67 -56
- package/package.json +2 -1
|
@@ -146,6 +146,20 @@ export class BitGoPsbt {
|
|
|
146
146
|
* Get the unsigned transaction ID
|
|
147
147
|
*/
|
|
148
148
|
unsigned_txid(): string;
|
|
149
|
+
/**
|
|
150
|
+
* Check if an input is a MuSig2 keypath input.
|
|
151
|
+
*
|
|
152
|
+
* MuSig2 inputs require special handling: nonces must be generated first with
|
|
153
|
+
* `generate_musig2_nonces()`, then signed with `sign_musig2_input()`.
|
|
154
|
+
*
|
|
155
|
+
* # Arguments
|
|
156
|
+
* - `input_index`: The index of the input to check (0-based)
|
|
157
|
+
*
|
|
158
|
+
* # Returns
|
|
159
|
+
* - `true` if the input is a MuSig2 keypath input
|
|
160
|
+
* - `false` otherwise (or if input_index is out of bounds)
|
|
161
|
+
*/
|
|
162
|
+
is_musig2_input(input_index: number): boolean;
|
|
149
163
|
/**
|
|
150
164
|
* Sign a single input with an extended private key (xpriv)
|
|
151
165
|
*
|
|
@@ -208,6 +222,45 @@ export class BitGoPsbt {
|
|
|
208
222
|
* The index of the newly added output
|
|
209
223
|
*/
|
|
210
224
|
add_wallet_output(chain: number, index: number, value: bigint, wallet_keys: WasmRootWalletKeys): number;
|
|
225
|
+
/**
|
|
226
|
+
* Sign a single MuSig2 keypath input.
|
|
227
|
+
*
|
|
228
|
+
* This uses the FirstRound state generated by `generate_musig2_nonces()`.
|
|
229
|
+
* Each FirstRound can only be used once (nonce reuse is a security risk).
|
|
230
|
+
*
|
|
231
|
+
* For non-MuSig2 inputs, returns an error (use `sign_wallet_input` instead).
|
|
232
|
+
*
|
|
233
|
+
* # Arguments
|
|
234
|
+
* - `input_index`: The index of the input to sign (0-based)
|
|
235
|
+
* - `xpriv`: The extended private key as a WasmBIP32 instance
|
|
236
|
+
*
|
|
237
|
+
* # Returns
|
|
238
|
+
* - `Ok(())` if signing was successful
|
|
239
|
+
* - `Err(WasmUtxoError)` if signing fails, no FirstRound exists, or not a MuSig2 input
|
|
240
|
+
*/
|
|
241
|
+
sign_musig2_input(input_index: number, xpriv: WasmBIP32): void;
|
|
242
|
+
/**
|
|
243
|
+
* Sign a single non-MuSig2 wallet input using save/restore pattern.
|
|
244
|
+
*
|
|
245
|
+
* For MuSig2 inputs, returns an error (use `sign_musig2_input` instead).
|
|
246
|
+
* For ECDSA inputs, this uses a save/restore pattern: clones the PSBT,
|
|
247
|
+
* signs all inputs on the clone, then copies only the target input's
|
|
248
|
+
* signatures back.
|
|
249
|
+
*
|
|
250
|
+
* **Important:** This is NOT faster than `sign_all_wallet_inputs()` for ECDSA inputs.
|
|
251
|
+
* The underlying library signs all inputs regardless. This method just ensures
|
|
252
|
+
* that only the specified input gets signatures added to the PSBT.
|
|
253
|
+
* Use `sign_all_wallet_inputs()` when signing multiple inputs with the same key.
|
|
254
|
+
*
|
|
255
|
+
* # Arguments
|
|
256
|
+
* - `input_index`: The index of the input to sign (0-based)
|
|
257
|
+
* - `xpriv`: The extended private key as a WasmBIP32 instance
|
|
258
|
+
*
|
|
259
|
+
* # Returns
|
|
260
|
+
* - `Ok(())` if the input was signed
|
|
261
|
+
* - `Err(WasmUtxoError)` if signing fails or input is MuSig2
|
|
262
|
+
*/
|
|
263
|
+
sign_wallet_input(input_index: number, xpriv: WasmBIP32): void;
|
|
211
264
|
/**
|
|
212
265
|
* Sign a single input with a raw private key
|
|
213
266
|
*
|
|
@@ -266,6 +319,24 @@ export class BitGoPsbt {
|
|
|
266
319
|
* - `Err(WasmUtxoError)` if any input failed to finalize
|
|
267
320
|
*/
|
|
268
321
|
finalize_all_inputs(): void;
|
|
322
|
+
/**
|
|
323
|
+
* Sign all non-MuSig2 inputs with an extended private key (xpriv) in a single pass.
|
|
324
|
+
*
|
|
325
|
+
* This is more efficient than calling `sign_with_xpriv` for each input individually.
|
|
326
|
+
* The underlying miniscript library's `sign` method signs all matching inputs at once.
|
|
327
|
+
*
|
|
328
|
+
* **Note:** MuSig2 inputs are skipped by this method because they require FirstRound
|
|
329
|
+
* state from nonce generation. After calling this method, sign MuSig2 inputs
|
|
330
|
+
* individually using `sign_with_xpriv`.
|
|
331
|
+
*
|
|
332
|
+
* # Arguments
|
|
333
|
+
* - `xpriv`: The extended private key as a WasmBIP32 instance
|
|
334
|
+
*
|
|
335
|
+
* # Returns
|
|
336
|
+
* - `Ok(JsValue)` with an array of input indices that were signed
|
|
337
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
338
|
+
*/
|
|
339
|
+
sign_all_with_xpriv(xpriv: WasmBIP32): any;
|
|
269
340
|
/**
|
|
270
341
|
* Add a PayGo attestation to a PSBT output
|
|
271
342
|
*
|
|
@@ -325,6 +396,41 @@ export class BitGoPsbt {
|
|
|
325
396
|
* generated for security. Custom session_id is only allowed on testnets for testing purposes.
|
|
326
397
|
*/
|
|
327
398
|
generate_musig2_nonces(xpriv: WasmBIP32, session_id_bytes?: Uint8Array | null): void;
|
|
399
|
+
/**
|
|
400
|
+
* Sign all MuSig2 keypath inputs in a single pass with optimized sighash computation.
|
|
401
|
+
*
|
|
402
|
+
* This is more efficient than calling `sign_musig2_input()` for each input because
|
|
403
|
+
* it reuses the SighashCache across all inputs, avoiding redundant computation of
|
|
404
|
+
* sha_prevouts, sha_amounts, sha_scriptpubkeys, sha_sequences, and sha_outputs.
|
|
405
|
+
*
|
|
406
|
+
* Each MuSig2 input requires a FirstRound from `generate_musig2_nonces()`.
|
|
407
|
+
* FirstRounds that have already been consumed (signed) are skipped.
|
|
408
|
+
*
|
|
409
|
+
* # Arguments
|
|
410
|
+
* - `xpriv`: The extended private key as a WasmBIP32 instance
|
|
411
|
+
*
|
|
412
|
+
* # Returns
|
|
413
|
+
* - `Ok(JsValue)` with an array of input indices that were signed
|
|
414
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
415
|
+
*/
|
|
416
|
+
sign_all_musig2_inputs(xpriv: WasmBIP32): any;
|
|
417
|
+
/**
|
|
418
|
+
* Sign all non-MuSig2 wallet inputs in a single efficient pass.
|
|
419
|
+
*
|
|
420
|
+
* This signs all ECDSA (P2SH, P2SH-P2WSH, P2WSH) and Taproot script path (P2TR)
|
|
421
|
+
* inputs that match the provided xpriv. MuSig2 keypath inputs are skipped.
|
|
422
|
+
*
|
|
423
|
+
* This is the most efficient way to sign wallet inputs. After calling this,
|
|
424
|
+
* sign any MuSig2 inputs using `sign_all_musig2_inputs()` or `sign_musig2_input()`.
|
|
425
|
+
*
|
|
426
|
+
* # Arguments
|
|
427
|
+
* - `xpriv`: The extended private key as a WasmBIP32 instance
|
|
428
|
+
*
|
|
429
|
+
* # Returns
|
|
430
|
+
* - `Ok(JsValue)` with an array of input indices that were signed
|
|
431
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
432
|
+
*/
|
|
433
|
+
sign_all_wallet_inputs(xpriv: WasmBIP32): any;
|
|
328
434
|
/**
|
|
329
435
|
* Add an output to the PSBT by address
|
|
330
436
|
*
|
|
@@ -411,12 +517,79 @@ export class BitGoPsbt {
|
|
|
411
517
|
* Returns error if block height is before Overwinter activation
|
|
412
518
|
*/
|
|
413
519
|
static create_empty_zcash_at_height(network: string, wallet_keys: WasmRootWalletKeys, block_height: number, version?: number | null, lock_time?: number | null, version_group_id?: number | null, expiry_height?: number | null): BitGoPsbt;
|
|
520
|
+
/**
|
|
521
|
+
* Sign a single input with an extended private key, using save/restore for ECDSA inputs.
|
|
522
|
+
*
|
|
523
|
+
* For MuSig2 inputs, this returns an error (use sign_with_xpriv which handles FirstRound).
|
|
524
|
+
* For ECDSA inputs, this clones the PSBT, signs all, then copies only the target
|
|
525
|
+
* input's signatures back.
|
|
526
|
+
*
|
|
527
|
+
* **Important:** This is NOT faster than `sign_all_with_xpriv` for ECDSA inputs.
|
|
528
|
+
* The underlying miniscript library signs all inputs regardless. This method
|
|
529
|
+
* just prevents signatures from being added to other inputs.
|
|
530
|
+
*
|
|
531
|
+
* # Arguments
|
|
532
|
+
* - `input_index`: The index of the input to sign (0-based)
|
|
533
|
+
* - `xpriv`: The extended private key as a WasmBIP32 instance
|
|
534
|
+
*
|
|
535
|
+
* # Returns
|
|
536
|
+
* - `Ok(())` if the input was signed
|
|
537
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
538
|
+
*/
|
|
539
|
+
sign_single_input_with_xpriv(input_index: number, xpriv: WasmBIP32): void;
|
|
540
|
+
/**
|
|
541
|
+
* Sign all replay protection inputs with a raw private key.
|
|
542
|
+
*
|
|
543
|
+
* This iterates through all inputs looking for P2SH-P2PK (replay protection) inputs
|
|
544
|
+
* that match the provided public key and signs them.
|
|
545
|
+
*
|
|
546
|
+
* # Arguments
|
|
547
|
+
* - `ecpair`: The ECPair containing the private key
|
|
548
|
+
*
|
|
549
|
+
* # Returns
|
|
550
|
+
* - `Ok(JsValue)` with an array of input indices that were signed
|
|
551
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
552
|
+
*/
|
|
553
|
+
sign_replay_protection_inputs(ecpair: WasmECPair): any;
|
|
414
554
|
/**
|
|
415
555
|
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
416
556
|
*
|
|
417
557
|
* Note: This method does NOT validate wallet inputs. It only parses outputs.
|
|
418
558
|
*/
|
|
419
559
|
parse_outputs_with_wallet_keys(wallet_keys: WasmRootWalletKeys, paygo_pubkeys?: WasmECPair[] | null): any;
|
|
560
|
+
/**
|
|
561
|
+
* Sign a single input with a raw private key, using save/restore for regular inputs.
|
|
562
|
+
*
|
|
563
|
+
* For replay protection inputs (P2SH-P2PK), this uses direct signing which is
|
|
564
|
+
* already single-input. For regular inputs, this clones the PSBT, signs all,
|
|
565
|
+
* then copies only the target input's signatures back.
|
|
566
|
+
*
|
|
567
|
+
* **Important:** This is NOT faster than signing all inputs for regular (non-RP) inputs.
|
|
568
|
+
* The underlying miniscript library signs all inputs regardless.
|
|
569
|
+
*
|
|
570
|
+
* # Arguments
|
|
571
|
+
* - `input_index`: The index of the input to sign (0-based)
|
|
572
|
+
* - `ecpair`: The ECPair containing the private key
|
|
573
|
+
*
|
|
574
|
+
* # Returns
|
|
575
|
+
* - `Ok(())` if the input was signed
|
|
576
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
577
|
+
*/
|
|
578
|
+
sign_single_input_with_privkey(input_index: number, ecpair: WasmECPair): void;
|
|
579
|
+
/**
|
|
580
|
+
* Sign all replay protection inputs with a raw private key.
|
|
581
|
+
*
|
|
582
|
+
* This iterates through all inputs looking for P2SH-P2PK (replay protection) inputs
|
|
583
|
+
* that match the provided public key and signs them.
|
|
584
|
+
*
|
|
585
|
+
* # Arguments
|
|
586
|
+
* - `ecpair`: The ECPair containing the private key
|
|
587
|
+
*
|
|
588
|
+
* # Returns
|
|
589
|
+
* - `Ok(JsValue)` with an array of input indices that were signed
|
|
590
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
591
|
+
*/
|
|
592
|
+
sign_all_replay_protection_inputs(ecpair: WasmECPair): any;
|
|
420
593
|
/**
|
|
421
594
|
* Parse transaction with wallet keys to identify wallet inputs/outputs
|
|
422
595
|
*/
|
|
@@ -504,6 +677,16 @@ export class FixedScriptWalletNamespace {
|
|
|
504
677
|
* - Dogecoin only supports legacy scripts (p2sh)
|
|
505
678
|
*/
|
|
506
679
|
static supports_script_type(coin: string, script_type: string): boolean;
|
|
680
|
+
/**
|
|
681
|
+
* Create an OP_RETURN output script with optional data
|
|
682
|
+
*
|
|
683
|
+
* # Arguments
|
|
684
|
+
* * `data` - Optional data bytes to include in the OP_RETURN script
|
|
685
|
+
*
|
|
686
|
+
* # Returns
|
|
687
|
+
* The OP_RETURN script as bytes
|
|
688
|
+
*/
|
|
689
|
+
static create_op_return_script(data?: Uint8Array | null): Uint8Array;
|
|
507
690
|
static address_with_network_str(keys: WasmRootWalletKeys, chain: number, index: number, network: string, address_format?: string | null): string;
|
|
508
691
|
static output_script_with_network_str(keys: WasmRootWalletKeys, chain: number, index: number, network: string): Uint8Array;
|
|
509
692
|
static address(keys: WasmRootWalletKeys, chain: number, index: number, network: any, address_format?: string | null): string;
|
|
@@ -731,6 +731,25 @@ class BitGoPsbt {
|
|
|
731
731
|
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
732
732
|
}
|
|
733
733
|
}
|
|
734
|
+
/**
|
|
735
|
+
* Check if an input is a MuSig2 keypath input.
|
|
736
|
+
*
|
|
737
|
+
* MuSig2 inputs require special handling: nonces must be generated first with
|
|
738
|
+
* `generate_musig2_nonces()`, then signed with `sign_musig2_input()`.
|
|
739
|
+
*
|
|
740
|
+
* # Arguments
|
|
741
|
+
* - `input_index`: The index of the input to check (0-based)
|
|
742
|
+
*
|
|
743
|
+
* # Returns
|
|
744
|
+
* - `true` if the input is a MuSig2 keypath input
|
|
745
|
+
* - `false` otherwise (or if input_index is out of bounds)
|
|
746
|
+
* @param {number} input_index
|
|
747
|
+
* @returns {boolean}
|
|
748
|
+
*/
|
|
749
|
+
is_musig2_input(input_index) {
|
|
750
|
+
const ret = wasm.bitgopsbt_is_musig2_input(this.__wbg_ptr, input_index);
|
|
751
|
+
return ret !== 0;
|
|
752
|
+
}
|
|
734
753
|
/**
|
|
735
754
|
* Sign a single input with an extended private key (xpriv)
|
|
736
755
|
*
|
|
@@ -866,6 +885,75 @@ class BitGoPsbt {
|
|
|
866
885
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
867
886
|
}
|
|
868
887
|
}
|
|
888
|
+
/**
|
|
889
|
+
* Sign a single MuSig2 keypath input.
|
|
890
|
+
*
|
|
891
|
+
* This uses the FirstRound state generated by `generate_musig2_nonces()`.
|
|
892
|
+
* Each FirstRound can only be used once (nonce reuse is a security risk).
|
|
893
|
+
*
|
|
894
|
+
* For non-MuSig2 inputs, returns an error (use `sign_wallet_input` instead).
|
|
895
|
+
*
|
|
896
|
+
* # Arguments
|
|
897
|
+
* - `input_index`: The index of the input to sign (0-based)
|
|
898
|
+
* - `xpriv`: The extended private key as a WasmBIP32 instance
|
|
899
|
+
*
|
|
900
|
+
* # Returns
|
|
901
|
+
* - `Ok(())` if signing was successful
|
|
902
|
+
* - `Err(WasmUtxoError)` if signing fails, no FirstRound exists, or not a MuSig2 input
|
|
903
|
+
* @param {number} input_index
|
|
904
|
+
* @param {WasmBIP32} xpriv
|
|
905
|
+
*/
|
|
906
|
+
sign_musig2_input(input_index, xpriv) {
|
|
907
|
+
try {
|
|
908
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
909
|
+
_assertClass(xpriv, WasmBIP32);
|
|
910
|
+
wasm.bitgopsbt_sign_musig2_input(retptr, this.__wbg_ptr, input_index, xpriv.__wbg_ptr);
|
|
911
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
912
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
913
|
+
if (r1) {
|
|
914
|
+
throw takeObject(r0);
|
|
915
|
+
}
|
|
916
|
+
} finally {
|
|
917
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Sign a single non-MuSig2 wallet input using save/restore pattern.
|
|
922
|
+
*
|
|
923
|
+
* For MuSig2 inputs, returns an error (use `sign_musig2_input` instead).
|
|
924
|
+
* For ECDSA inputs, this uses a save/restore pattern: clones the PSBT,
|
|
925
|
+
* signs all inputs on the clone, then copies only the target input's
|
|
926
|
+
* signatures back.
|
|
927
|
+
*
|
|
928
|
+
* **Important:** This is NOT faster than `sign_all_wallet_inputs()` for ECDSA inputs.
|
|
929
|
+
* The underlying library signs all inputs regardless. This method just ensures
|
|
930
|
+
* that only the specified input gets signatures added to the PSBT.
|
|
931
|
+
* Use `sign_all_wallet_inputs()` when signing multiple inputs with the same key.
|
|
932
|
+
*
|
|
933
|
+
* # Arguments
|
|
934
|
+
* - `input_index`: The index of the input to sign (0-based)
|
|
935
|
+
* - `xpriv`: The extended private key as a WasmBIP32 instance
|
|
936
|
+
*
|
|
937
|
+
* # Returns
|
|
938
|
+
* - `Ok(())` if the input was signed
|
|
939
|
+
* - `Err(WasmUtxoError)` if signing fails or input is MuSig2
|
|
940
|
+
* @param {number} input_index
|
|
941
|
+
* @param {WasmBIP32} xpriv
|
|
942
|
+
*/
|
|
943
|
+
sign_wallet_input(input_index, xpriv) {
|
|
944
|
+
try {
|
|
945
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
946
|
+
_assertClass(xpriv, WasmBIP32);
|
|
947
|
+
wasm.bitgopsbt_sign_single_input_with_xpriv(retptr, this.__wbg_ptr, input_index, xpriv.__wbg_ptr);
|
|
948
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
949
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
950
|
+
if (r1) {
|
|
951
|
+
throw takeObject(r0);
|
|
952
|
+
}
|
|
953
|
+
} finally {
|
|
954
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
869
957
|
/**
|
|
870
958
|
* Sign a single input with a raw private key
|
|
871
959
|
*
|
|
@@ -994,6 +1082,41 @@ class BitGoPsbt {
|
|
|
994
1082
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
995
1083
|
}
|
|
996
1084
|
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Sign all non-MuSig2 inputs with an extended private key (xpriv) in a single pass.
|
|
1087
|
+
*
|
|
1088
|
+
* This is more efficient than calling `sign_with_xpriv` for each input individually.
|
|
1089
|
+
* The underlying miniscript library's `sign` method signs all matching inputs at once.
|
|
1090
|
+
*
|
|
1091
|
+
* **Note:** MuSig2 inputs are skipped by this method because they require FirstRound
|
|
1092
|
+
* state from nonce generation. After calling this method, sign MuSig2 inputs
|
|
1093
|
+
* individually using `sign_with_xpriv`.
|
|
1094
|
+
*
|
|
1095
|
+
* # Arguments
|
|
1096
|
+
* - `xpriv`: The extended private key as a WasmBIP32 instance
|
|
1097
|
+
*
|
|
1098
|
+
* # Returns
|
|
1099
|
+
* - `Ok(JsValue)` with an array of input indices that were signed
|
|
1100
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
1101
|
+
* @param {WasmBIP32} xpriv
|
|
1102
|
+
* @returns {any}
|
|
1103
|
+
*/
|
|
1104
|
+
sign_all_with_xpriv(xpriv) {
|
|
1105
|
+
try {
|
|
1106
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1107
|
+
_assertClass(xpriv, WasmBIP32);
|
|
1108
|
+
wasm.bitgopsbt_sign_all_wallet_inputs(retptr, this.__wbg_ptr, xpriv.__wbg_ptr);
|
|
1109
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1110
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1111
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1112
|
+
if (r2) {
|
|
1113
|
+
throw takeObject(r1);
|
|
1114
|
+
}
|
|
1115
|
+
return takeObject(r0);
|
|
1116
|
+
} finally {
|
|
1117
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
997
1120
|
/**
|
|
998
1121
|
* Add a PayGo attestation to a PSBT output
|
|
999
1122
|
*
|
|
@@ -1103,6 +1226,75 @@ class BitGoPsbt {
|
|
|
1103
1226
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1104
1227
|
}
|
|
1105
1228
|
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Sign all MuSig2 keypath inputs in a single pass with optimized sighash computation.
|
|
1231
|
+
*
|
|
1232
|
+
* This is more efficient than calling `sign_musig2_input()` for each input because
|
|
1233
|
+
* it reuses the SighashCache across all inputs, avoiding redundant computation of
|
|
1234
|
+
* sha_prevouts, sha_amounts, sha_scriptpubkeys, sha_sequences, and sha_outputs.
|
|
1235
|
+
*
|
|
1236
|
+
* Each MuSig2 input requires a FirstRound from `generate_musig2_nonces()`.
|
|
1237
|
+
* FirstRounds that have already been consumed (signed) are skipped.
|
|
1238
|
+
*
|
|
1239
|
+
* # Arguments
|
|
1240
|
+
* - `xpriv`: The extended private key as a WasmBIP32 instance
|
|
1241
|
+
*
|
|
1242
|
+
* # Returns
|
|
1243
|
+
* - `Ok(JsValue)` with an array of input indices that were signed
|
|
1244
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
1245
|
+
* @param {WasmBIP32} xpriv
|
|
1246
|
+
* @returns {any}
|
|
1247
|
+
*/
|
|
1248
|
+
sign_all_musig2_inputs(xpriv) {
|
|
1249
|
+
try {
|
|
1250
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1251
|
+
_assertClass(xpriv, WasmBIP32);
|
|
1252
|
+
wasm.bitgopsbt_sign_all_musig2_inputs(retptr, this.__wbg_ptr, xpriv.__wbg_ptr);
|
|
1253
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1254
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1255
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1256
|
+
if (r2) {
|
|
1257
|
+
throw takeObject(r1);
|
|
1258
|
+
}
|
|
1259
|
+
return takeObject(r0);
|
|
1260
|
+
} finally {
|
|
1261
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* Sign all non-MuSig2 wallet inputs in a single efficient pass.
|
|
1266
|
+
*
|
|
1267
|
+
* This signs all ECDSA (P2SH, P2SH-P2WSH, P2WSH) and Taproot script path (P2TR)
|
|
1268
|
+
* inputs that match the provided xpriv. MuSig2 keypath inputs are skipped.
|
|
1269
|
+
*
|
|
1270
|
+
* This is the most efficient way to sign wallet inputs. After calling this,
|
|
1271
|
+
* sign any MuSig2 inputs using `sign_all_musig2_inputs()` or `sign_musig2_input()`.
|
|
1272
|
+
*
|
|
1273
|
+
* # Arguments
|
|
1274
|
+
* - `xpriv`: The extended private key as a WasmBIP32 instance
|
|
1275
|
+
*
|
|
1276
|
+
* # Returns
|
|
1277
|
+
* - `Ok(JsValue)` with an array of input indices that were signed
|
|
1278
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
1279
|
+
* @param {WasmBIP32} xpriv
|
|
1280
|
+
* @returns {any}
|
|
1281
|
+
*/
|
|
1282
|
+
sign_all_wallet_inputs(xpriv) {
|
|
1283
|
+
try {
|
|
1284
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1285
|
+
_assertClass(xpriv, WasmBIP32);
|
|
1286
|
+
wasm.bitgopsbt_sign_all_wallet_inputs(retptr, this.__wbg_ptr, xpriv.__wbg_ptr);
|
|
1287
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1288
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1289
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1290
|
+
if (r2) {
|
|
1291
|
+
throw takeObject(r1);
|
|
1292
|
+
}
|
|
1293
|
+
return takeObject(r0);
|
|
1294
|
+
} finally {
|
|
1295
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1106
1298
|
/**
|
|
1107
1299
|
* Add an output to the PSBT by address
|
|
1108
1300
|
*
|
|
@@ -1292,6 +1484,72 @@ class BitGoPsbt {
|
|
|
1292
1484
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1293
1485
|
}
|
|
1294
1486
|
}
|
|
1487
|
+
/**
|
|
1488
|
+
* Sign a single input with an extended private key, using save/restore for ECDSA inputs.
|
|
1489
|
+
*
|
|
1490
|
+
* For MuSig2 inputs, this returns an error (use sign_with_xpriv which handles FirstRound).
|
|
1491
|
+
* For ECDSA inputs, this clones the PSBT, signs all, then copies only the target
|
|
1492
|
+
* input's signatures back.
|
|
1493
|
+
*
|
|
1494
|
+
* **Important:** This is NOT faster than `sign_all_with_xpriv` for ECDSA inputs.
|
|
1495
|
+
* The underlying miniscript library signs all inputs regardless. This method
|
|
1496
|
+
* just prevents signatures from being added to other inputs.
|
|
1497
|
+
*
|
|
1498
|
+
* # Arguments
|
|
1499
|
+
* - `input_index`: The index of the input to sign (0-based)
|
|
1500
|
+
* - `xpriv`: The extended private key as a WasmBIP32 instance
|
|
1501
|
+
*
|
|
1502
|
+
* # Returns
|
|
1503
|
+
* - `Ok(())` if the input was signed
|
|
1504
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
1505
|
+
* @param {number} input_index
|
|
1506
|
+
* @param {WasmBIP32} xpriv
|
|
1507
|
+
*/
|
|
1508
|
+
sign_single_input_with_xpriv(input_index, xpriv) {
|
|
1509
|
+
try {
|
|
1510
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1511
|
+
_assertClass(xpriv, WasmBIP32);
|
|
1512
|
+
wasm.bitgopsbt_sign_single_input_with_xpriv(retptr, this.__wbg_ptr, input_index, xpriv.__wbg_ptr);
|
|
1513
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1514
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1515
|
+
if (r1) {
|
|
1516
|
+
throw takeObject(r0);
|
|
1517
|
+
}
|
|
1518
|
+
} finally {
|
|
1519
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
/**
|
|
1523
|
+
* Sign all replay protection inputs with a raw private key.
|
|
1524
|
+
*
|
|
1525
|
+
* This iterates through all inputs looking for P2SH-P2PK (replay protection) inputs
|
|
1526
|
+
* that match the provided public key and signs them.
|
|
1527
|
+
*
|
|
1528
|
+
* # Arguments
|
|
1529
|
+
* - `ecpair`: The ECPair containing the private key
|
|
1530
|
+
*
|
|
1531
|
+
* # Returns
|
|
1532
|
+
* - `Ok(JsValue)` with an array of input indices that were signed
|
|
1533
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
1534
|
+
* @param {WasmECPair} ecpair
|
|
1535
|
+
* @returns {any}
|
|
1536
|
+
*/
|
|
1537
|
+
sign_replay_protection_inputs(ecpair) {
|
|
1538
|
+
try {
|
|
1539
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1540
|
+
_assertClass(ecpair, WasmECPair);
|
|
1541
|
+
wasm.bitgopsbt_sign_all_replay_protection_inputs(retptr, this.__wbg_ptr, ecpair.__wbg_ptr);
|
|
1542
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1543
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1544
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1545
|
+
if (r2) {
|
|
1546
|
+
throw takeObject(r1);
|
|
1547
|
+
}
|
|
1548
|
+
return takeObject(r0);
|
|
1549
|
+
} finally {
|
|
1550
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1295
1553
|
/**
|
|
1296
1554
|
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
1297
1555
|
*
|
|
@@ -1318,6 +1576,71 @@ class BitGoPsbt {
|
|
|
1318
1576
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1319
1577
|
}
|
|
1320
1578
|
}
|
|
1579
|
+
/**
|
|
1580
|
+
* Sign a single input with a raw private key, using save/restore for regular inputs.
|
|
1581
|
+
*
|
|
1582
|
+
* For replay protection inputs (P2SH-P2PK), this uses direct signing which is
|
|
1583
|
+
* already single-input. For regular inputs, this clones the PSBT, signs all,
|
|
1584
|
+
* then copies only the target input's signatures back.
|
|
1585
|
+
*
|
|
1586
|
+
* **Important:** This is NOT faster than signing all inputs for regular (non-RP) inputs.
|
|
1587
|
+
* The underlying miniscript library signs all inputs regardless.
|
|
1588
|
+
*
|
|
1589
|
+
* # Arguments
|
|
1590
|
+
* - `input_index`: The index of the input to sign (0-based)
|
|
1591
|
+
* - `ecpair`: The ECPair containing the private key
|
|
1592
|
+
*
|
|
1593
|
+
* # Returns
|
|
1594
|
+
* - `Ok(())` if the input was signed
|
|
1595
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
1596
|
+
* @param {number} input_index
|
|
1597
|
+
* @param {WasmECPair} ecpair
|
|
1598
|
+
*/
|
|
1599
|
+
sign_single_input_with_privkey(input_index, ecpair) {
|
|
1600
|
+
try {
|
|
1601
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1602
|
+
_assertClass(ecpair, WasmECPair);
|
|
1603
|
+
wasm.bitgopsbt_sign_single_input_with_privkey(retptr, this.__wbg_ptr, input_index, ecpair.__wbg_ptr);
|
|
1604
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1605
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1606
|
+
if (r1) {
|
|
1607
|
+
throw takeObject(r0);
|
|
1608
|
+
}
|
|
1609
|
+
} finally {
|
|
1610
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
/**
|
|
1614
|
+
* Sign all replay protection inputs with a raw private key.
|
|
1615
|
+
*
|
|
1616
|
+
* This iterates through all inputs looking for P2SH-P2PK (replay protection) inputs
|
|
1617
|
+
* that match the provided public key and signs them.
|
|
1618
|
+
*
|
|
1619
|
+
* # Arguments
|
|
1620
|
+
* - `ecpair`: The ECPair containing the private key
|
|
1621
|
+
*
|
|
1622
|
+
* # Returns
|
|
1623
|
+
* - `Ok(JsValue)` with an array of input indices that were signed
|
|
1624
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
1625
|
+
* @param {WasmECPair} ecpair
|
|
1626
|
+
* @returns {any}
|
|
1627
|
+
*/
|
|
1628
|
+
sign_all_replay_protection_inputs(ecpair) {
|
|
1629
|
+
try {
|
|
1630
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1631
|
+
_assertClass(ecpair, WasmECPair);
|
|
1632
|
+
wasm.bitgopsbt_sign_all_replay_protection_inputs(retptr, this.__wbg_ptr, ecpair.__wbg_ptr);
|
|
1633
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1634
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1635
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1636
|
+
if (r2) {
|
|
1637
|
+
throw takeObject(r1);
|
|
1638
|
+
}
|
|
1639
|
+
return takeObject(r0);
|
|
1640
|
+
} finally {
|
|
1641
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1321
1644
|
/**
|
|
1322
1645
|
* Parse transaction with wallet keys to identify wallet inputs/outputs
|
|
1323
1646
|
* @param {WasmRootWalletKeys} wallet_keys
|
|
@@ -1573,6 +1896,37 @@ class FixedScriptWalletNamespace {
|
|
|
1573
1896
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1574
1897
|
}
|
|
1575
1898
|
}
|
|
1899
|
+
/**
|
|
1900
|
+
* Create an OP_RETURN output script with optional data
|
|
1901
|
+
*
|
|
1902
|
+
* # Arguments
|
|
1903
|
+
* * `data` - Optional data bytes to include in the OP_RETURN script
|
|
1904
|
+
*
|
|
1905
|
+
* # Returns
|
|
1906
|
+
* The OP_RETURN script as bytes
|
|
1907
|
+
* @param {Uint8Array | null} [data]
|
|
1908
|
+
* @returns {Uint8Array}
|
|
1909
|
+
*/
|
|
1910
|
+
static create_op_return_script(data) {
|
|
1911
|
+
try {
|
|
1912
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1913
|
+
var ptr0 = isLikeNone(data) ? 0 : passArray8ToWasm0(data, wasm.__wbindgen_export);
|
|
1914
|
+
var len0 = WASM_VECTOR_LEN;
|
|
1915
|
+
wasm.fixedscriptwalletnamespace_create_op_return_script(retptr, ptr0, len0);
|
|
1916
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1917
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1918
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1919
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1920
|
+
if (r3) {
|
|
1921
|
+
throw takeObject(r2);
|
|
1922
|
+
}
|
|
1923
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
1924
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
1925
|
+
return v2;
|
|
1926
|
+
} finally {
|
|
1927
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1576
1930
|
/**
|
|
1577
1931
|
* @param {WasmRootWalletKeys} keys
|
|
1578
1932
|
* @param {number} chain
|
|
Binary file
|