@bitgo/wasm-utxo 1.14.0 → 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.
- package/README.md +12 -2
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +205 -0
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +178 -0
- package/dist/cjs/js/fixedScriptWallet/index.d.ts +1 -1
- package/dist/cjs/js/wasm/wasm_utxo.d.ts +98 -0
- package/dist/cjs/js/wasm/wasm_utxo.js +251 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +58 -50
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +205 -0
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +178 -0
- package/dist/esm/js/fixedScriptWallet/index.d.ts +1 -1
- package/dist/esm/js/wasm/wasm_utxo.d.ts +98 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.js +251 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +58 -50
- package/package.json +4 -4
|
@@ -297,6 +297,36 @@ class BitGoPsbt {
|
|
|
297
297
|
const ptr = this.__destroy_into_raw();
|
|
298
298
|
wasm.__wbg_bitgopsbt_free(ptr, 0);
|
|
299
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* Add an output to the PSBT
|
|
302
|
+
*
|
|
303
|
+
* # Arguments
|
|
304
|
+
* * `script` - The output script (scriptPubKey)
|
|
305
|
+
* * `value` - The value in satoshis
|
|
306
|
+
*
|
|
307
|
+
* # Returns
|
|
308
|
+
* The index of the newly added output
|
|
309
|
+
* @param {Uint8Array} script
|
|
310
|
+
* @param {bigint} value
|
|
311
|
+
* @returns {number}
|
|
312
|
+
*/
|
|
313
|
+
add_output(script, value) {
|
|
314
|
+
try {
|
|
315
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
316
|
+
const ptr0 = passArray8ToWasm0(script, wasm.__wbindgen_export);
|
|
317
|
+
const len0 = WASM_VECTOR_LEN;
|
|
318
|
+
wasm.bitgopsbt_add_output(retptr, this.__wbg_ptr, ptr0, len0, value);
|
|
319
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
320
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
321
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
322
|
+
if (r2) {
|
|
323
|
+
throw takeObject(r1);
|
|
324
|
+
}
|
|
325
|
+
return r0 >>> 0;
|
|
326
|
+
} finally {
|
|
327
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
300
330
|
/**
|
|
301
331
|
* Deserialize a PSBT from bytes with network-specific logic
|
|
302
332
|
* @param {Uint8Array} bytes
|
|
@@ -322,6 +352,38 @@ class BitGoPsbt {
|
|
|
322
352
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
323
353
|
}
|
|
324
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* Create an empty PSBT for the given network with wallet keys
|
|
357
|
+
*
|
|
358
|
+
* # Arguments
|
|
359
|
+
* * `network` - Network name (utxolib or coin name)
|
|
360
|
+
* * `wallet_keys` - The wallet's root keys (used to set global xpubs)
|
|
361
|
+
* * `version` - Optional transaction version (default: 2)
|
|
362
|
+
* * `lock_time` - Optional lock time (default: 0)
|
|
363
|
+
* @param {string} network
|
|
364
|
+
* @param {WasmRootWalletKeys} wallet_keys
|
|
365
|
+
* @param {number | null} [version]
|
|
366
|
+
* @param {number | null} [lock_time]
|
|
367
|
+
* @returns {BitGoPsbt}
|
|
368
|
+
*/
|
|
369
|
+
static create_empty(network, wallet_keys, version, lock_time) {
|
|
370
|
+
try {
|
|
371
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
372
|
+
const ptr0 = passStringToWasm0(network, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
373
|
+
const len0 = WASM_VECTOR_LEN;
|
|
374
|
+
_assertClass(wallet_keys, WasmRootWalletKeys);
|
|
375
|
+
wasm.bitgopsbt_create_empty(retptr, ptr0, len0, wallet_keys.__wbg_ptr, isLikeNone(version) ? 0x100000001 : (version) >> 0, isLikeNone(lock_time) ? 0x100000001 : (lock_time) >>> 0);
|
|
376
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
377
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
378
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
379
|
+
if (r2) {
|
|
380
|
+
throw takeObject(r1);
|
|
381
|
+
}
|
|
382
|
+
return BitGoPsbt.__wrap(r0);
|
|
383
|
+
} finally {
|
|
384
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
325
387
|
/**
|
|
326
388
|
* Get the unsigned transaction ID
|
|
327
389
|
* @returns {string}
|
|
@@ -377,6 +439,98 @@ class BitGoPsbt {
|
|
|
377
439
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
378
440
|
}
|
|
379
441
|
}
|
|
442
|
+
/**
|
|
443
|
+
* Add a wallet input with full PSBT metadata
|
|
444
|
+
*
|
|
445
|
+
* This is a higher-level method that adds an input and populates all required
|
|
446
|
+
* PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
|
|
447
|
+
*
|
|
448
|
+
* # Arguments
|
|
449
|
+
* * `txid` - The transaction ID (hex string)
|
|
450
|
+
* * `vout` - The output index being spent
|
|
451
|
+
* * `value` - The value in satoshis
|
|
452
|
+
* * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
|
|
453
|
+
* * `index` - The derivation index
|
|
454
|
+
* * `wallet_keys` - The root wallet keys
|
|
455
|
+
* * `signer` - The key that will sign ("user", "backup", or "bitgo") - required for p2tr/p2trMusig2
|
|
456
|
+
* * `cosigner` - The key that will co-sign - required for p2tr/p2trMusig2
|
|
457
|
+
* * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
|
|
458
|
+
* * `prev_tx` - Optional full previous transaction bytes (for non-segwit)
|
|
459
|
+
*
|
|
460
|
+
* # Returns
|
|
461
|
+
* The index of the newly added input
|
|
462
|
+
* @param {string} txid
|
|
463
|
+
* @param {number} vout
|
|
464
|
+
* @param {bigint} value
|
|
465
|
+
* @param {WasmRootWalletKeys} wallet_keys
|
|
466
|
+
* @param {number} chain
|
|
467
|
+
* @param {number} index
|
|
468
|
+
* @param {string | null} [signer]
|
|
469
|
+
* @param {string | null} [cosigner]
|
|
470
|
+
* @param {number | null} [sequence]
|
|
471
|
+
* @param {Uint8Array | null} [prev_tx]
|
|
472
|
+
* @returns {number}
|
|
473
|
+
*/
|
|
474
|
+
add_wallet_input(txid, vout, value, wallet_keys, chain, index, signer, cosigner, sequence, prev_tx) {
|
|
475
|
+
try {
|
|
476
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
477
|
+
const ptr0 = passStringToWasm0(txid, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
478
|
+
const len0 = WASM_VECTOR_LEN;
|
|
479
|
+
_assertClass(wallet_keys, WasmRootWalletKeys);
|
|
480
|
+
var ptr1 = isLikeNone(signer) ? 0 : passStringToWasm0(signer, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
481
|
+
var len1 = WASM_VECTOR_LEN;
|
|
482
|
+
var ptr2 = isLikeNone(cosigner) ? 0 : passStringToWasm0(cosigner, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
483
|
+
var len2 = WASM_VECTOR_LEN;
|
|
484
|
+
var ptr3 = isLikeNone(prev_tx) ? 0 : passArray8ToWasm0(prev_tx, wasm.__wbindgen_export);
|
|
485
|
+
var len3 = WASM_VECTOR_LEN;
|
|
486
|
+
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);
|
|
487
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
488
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
489
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
490
|
+
if (r2) {
|
|
491
|
+
throw takeObject(r1);
|
|
492
|
+
}
|
|
493
|
+
return r0 >>> 0;
|
|
494
|
+
} finally {
|
|
495
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Add a wallet output with full PSBT metadata
|
|
500
|
+
*
|
|
501
|
+
* This creates a verifiable wallet output (typically for change) with all required
|
|
502
|
+
* PSBT fields (scripts, derivation info) based on the wallet's chain type.
|
|
503
|
+
*
|
|
504
|
+
* # Arguments
|
|
505
|
+
* * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
|
|
506
|
+
* * `index` - The derivation index
|
|
507
|
+
* * `value` - The value in satoshis
|
|
508
|
+
* * `wallet_keys` - The root wallet keys
|
|
509
|
+
*
|
|
510
|
+
* # Returns
|
|
511
|
+
* The index of the newly added output
|
|
512
|
+
* @param {number} chain
|
|
513
|
+
* @param {number} index
|
|
514
|
+
* @param {bigint} value
|
|
515
|
+
* @param {WasmRootWalletKeys} wallet_keys
|
|
516
|
+
* @returns {number}
|
|
517
|
+
*/
|
|
518
|
+
add_wallet_output(chain, index, value, wallet_keys) {
|
|
519
|
+
try {
|
|
520
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
521
|
+
_assertClass(wallet_keys, WasmRootWalletKeys);
|
|
522
|
+
wasm.bitgopsbt_add_wallet_output(retptr, this.__wbg_ptr, chain, index, value, wallet_keys.__wbg_ptr);
|
|
523
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
524
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
525
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
526
|
+
if (r2) {
|
|
527
|
+
throw takeObject(r1);
|
|
528
|
+
}
|
|
529
|
+
return r0 >>> 0;
|
|
530
|
+
} finally {
|
|
531
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
380
534
|
/**
|
|
381
535
|
* Sign a single input with a raw private key
|
|
382
536
|
*
|
|
@@ -648,6 +802,46 @@ class BitGoPsbt {
|
|
|
648
802
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
649
803
|
}
|
|
650
804
|
}
|
|
805
|
+
/**
|
|
806
|
+
* Add a replay protection input to the PSBT
|
|
807
|
+
*
|
|
808
|
+
* Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
|
|
809
|
+
* transaction replay attacks. They use a simple pubkey script without wallet derivation.
|
|
810
|
+
*
|
|
811
|
+
* # Arguments
|
|
812
|
+
* * `ecpair` - The ECPair containing the public key for the replay protection input
|
|
813
|
+
* * `txid` - The transaction ID (hex string) of the output being spent
|
|
814
|
+
* * `vout` - The output index being spent
|
|
815
|
+
* * `value` - The value in satoshis
|
|
816
|
+
* * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
|
|
817
|
+
*
|
|
818
|
+
* # Returns
|
|
819
|
+
* The index of the newly added input
|
|
820
|
+
* @param {WasmECPair} ecpair
|
|
821
|
+
* @param {string} txid
|
|
822
|
+
* @param {number} vout
|
|
823
|
+
* @param {bigint} value
|
|
824
|
+
* @param {number | null} [sequence]
|
|
825
|
+
* @returns {number}
|
|
826
|
+
*/
|
|
827
|
+
add_replay_protection_input(ecpair, txid, vout, value, sequence) {
|
|
828
|
+
try {
|
|
829
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
830
|
+
_assertClass(ecpair, WasmECPair);
|
|
831
|
+
const ptr0 = passStringToWasm0(txid, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
832
|
+
const len0 = WASM_VECTOR_LEN;
|
|
833
|
+
wasm.bitgopsbt_add_replay_protection_input(retptr, this.__wbg_ptr, ecpair.__wbg_ptr, ptr0, len0, vout, value, isLikeNone(sequence) ? 0x100000001 : (sequence) >>> 0);
|
|
834
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
835
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
836
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
837
|
+
if (r2) {
|
|
838
|
+
throw takeObject(r1);
|
|
839
|
+
}
|
|
840
|
+
return r0 >>> 0;
|
|
841
|
+
} finally {
|
|
842
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
651
845
|
/**
|
|
652
846
|
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
653
847
|
*
|
|
@@ -756,6 +950,63 @@ class BitGoPsbt {
|
|
|
756
950
|
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
757
951
|
}
|
|
758
952
|
}
|
|
953
|
+
/**
|
|
954
|
+
* Get the transaction version
|
|
955
|
+
* @returns {number}
|
|
956
|
+
*/
|
|
957
|
+
version() {
|
|
958
|
+
const ret = wasm.bitgopsbt_version(this.__wbg_ptr);
|
|
959
|
+
return ret;
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Add an input to the PSBT
|
|
963
|
+
*
|
|
964
|
+
* # Arguments
|
|
965
|
+
* * `txid` - The transaction ID (hex string) of the output being spent
|
|
966
|
+
* * `vout` - The output index being spent
|
|
967
|
+
* * `value` - The value in satoshis of the output being spent
|
|
968
|
+
* * `script` - The output script (scriptPubKey) of the output being spent
|
|
969
|
+
* * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
|
|
970
|
+
*
|
|
971
|
+
* # Returns
|
|
972
|
+
* The index of the newly added input
|
|
973
|
+
* @param {string} txid
|
|
974
|
+
* @param {number} vout
|
|
975
|
+
* @param {bigint} value
|
|
976
|
+
* @param {Uint8Array} script
|
|
977
|
+
* @param {number | null} [sequence]
|
|
978
|
+
* @param {Uint8Array | null} [prev_tx]
|
|
979
|
+
* @returns {number}
|
|
980
|
+
*/
|
|
981
|
+
add_input(txid, vout, value, script, sequence, prev_tx) {
|
|
982
|
+
try {
|
|
983
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
984
|
+
const ptr0 = passStringToWasm0(txid, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
985
|
+
const len0 = WASM_VECTOR_LEN;
|
|
986
|
+
const ptr1 = passArray8ToWasm0(script, wasm.__wbindgen_export);
|
|
987
|
+
const len1 = WASM_VECTOR_LEN;
|
|
988
|
+
var ptr2 = isLikeNone(prev_tx) ? 0 : passArray8ToWasm0(prev_tx, wasm.__wbindgen_export);
|
|
989
|
+
var len2 = WASM_VECTOR_LEN;
|
|
990
|
+
wasm.bitgopsbt_add_input(retptr, this.__wbg_ptr, ptr0, len0, vout, value, ptr1, len1, isLikeNone(sequence) ? 0x100000001 : (sequence) >>> 0, ptr2, len2);
|
|
991
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
992
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
993
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
994
|
+
if (r2) {
|
|
995
|
+
throw takeObject(r1);
|
|
996
|
+
}
|
|
997
|
+
return r0 >>> 0;
|
|
998
|
+
} finally {
|
|
999
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Get the transaction lock time
|
|
1004
|
+
* @returns {number}
|
|
1005
|
+
*/
|
|
1006
|
+
lock_time() {
|
|
1007
|
+
const ret = wasm.bitgopsbt_lock_time(this.__wbg_ptr);
|
|
1008
|
+
return ret >>> 0;
|
|
1009
|
+
}
|
|
759
1010
|
/**
|
|
760
1011
|
* Serialize the PSBT to bytes
|
|
761
1012
|
*
|
|
Binary file
|
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_wasmbip32_free: (a: number, b: number) => void;
|
|
5
|
+
export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
|
|
6
|
+
export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
|
|
7
|
+
export const __wbg_wrappsbt_free: (a: number, b: number) => void;
|
|
8
|
+
export const wasmbip32_chain_code: (a: number) => number;
|
|
9
|
+
export const wasmbip32_depth: (a: number) => number;
|
|
10
|
+
export const wasmbip32_derive: (a: number, b: number, c: number) => void;
|
|
11
|
+
export const wasmbip32_derive_hardened: (a: number, b: number, c: number) => void;
|
|
12
|
+
export const wasmbip32_derive_path: (a: number, b: number, c: number, d: number) => void;
|
|
13
|
+
export const wasmbip32_fingerprint: (a: number) => number;
|
|
14
|
+
export const wasmbip32_from_base58: (a: number, b: number, c: number) => void;
|
|
15
|
+
export const wasmbip32_from_bip32_interface: (a: number, b: number) => void;
|
|
16
|
+
export const wasmbip32_from_seed: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
17
|
+
export const wasmbip32_from_xprv: (a: number, b: number, c: number) => void;
|
|
18
|
+
export const wasmbip32_from_xpub: (a: number, b: number, c: number) => void;
|
|
19
|
+
export const wasmbip32_identifier: (a: number) => number;
|
|
20
|
+
export const wasmbip32_index: (a: number) => number;
|
|
21
|
+
export const wasmbip32_is_neutered: (a: number) => number;
|
|
22
|
+
export const wasmbip32_neutered: (a: number) => number;
|
|
23
|
+
export const wasmbip32_parent_fingerprint: (a: number) => number;
|
|
24
|
+
export const wasmbip32_private_key: (a: number) => number;
|
|
25
|
+
export const wasmbip32_public_key: (a: number) => number;
|
|
26
|
+
export const wasmbip32_to_base58: (a: number, b: number) => void;
|
|
27
|
+
export const wasmbip32_to_wif: (a: number, b: number) => void;
|
|
28
|
+
export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
|
|
29
|
+
export const wrapdescriptor_descType: (a: number, b: number) => void;
|
|
30
|
+
export const wrapdescriptor_encode: (a: number, b: number) => void;
|
|
31
|
+
export const wrapdescriptor_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
32
|
+
export const wrapdescriptor_fromStringDetectType: (a: number, b: number, c: number) => void;
|
|
33
|
+
export const wrapdescriptor_hasWildcard: (a: number) => number;
|
|
34
|
+
export const wrapdescriptor_maxWeightToSatisfy: (a: number, b: number) => void;
|
|
35
|
+
export const wrapdescriptor_node: (a: number, b: number) => void;
|
|
36
|
+
export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
|
|
37
|
+
export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
|
|
38
|
+
export const wrapdescriptor_toString: (a: number, b: number) => void;
|
|
39
|
+
export const wrapminiscript_encode: (a: number, b: number) => void;
|
|
40
|
+
export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
41
|
+
export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
42
|
+
export const wrapminiscript_node: (a: number, b: number) => void;
|
|
43
|
+
export const wrapminiscript_toAsmString: (a: number, b: number) => void;
|
|
44
|
+
export const wrapminiscript_toString: (a: number, b: number) => void;
|
|
45
|
+
export const wrappsbt_clone: (a: number) => number;
|
|
46
|
+
export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
|
|
47
|
+
export const wrappsbt_finalize: (a: number, b: number) => void;
|
|
48
|
+
export const wrappsbt_serialize: (a: number, b: number) => void;
|
|
49
|
+
export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number) => void;
|
|
50
|
+
export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
|
|
51
|
+
export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
52
|
+
export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
53
|
+
export const wasmbip32_from_bip32_properties: (a: number, b: number) => void;
|
|
4
54
|
export const __wbg_addressnamespace_free: (a: number, b: number) => void;
|
|
5
55
|
export const __wbg_bitgopsbt_free: (a: number, b: number) => void;
|
|
6
56
|
export const __wbg_fixedscriptwalletnamespace_free: (a: number, b: number) => void;
|
|
@@ -8,15 +58,21 @@ export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
|
|
|
8
58
|
export const __wbg_wasmecpair_free: (a: number, b: number) => void;
|
|
9
59
|
export const __wbg_wasmreplayprotection_free: (a: number, b: number) => void;
|
|
10
60
|
export const __wbg_wasmrootwalletkeys_free: (a: number, b: number) => void;
|
|
11
|
-
export const __wbg_wrappsbt_free: (a: number, b: number) => void;
|
|
12
61
|
export const addressnamespace_from_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
13
62
|
export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
63
|
+
export const bitgopsbt_add_input: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number, h: number, i: number, j: number, k: number) => void;
|
|
64
|
+
export const bitgopsbt_add_output: (a: number, b: number, c: number, d: number, e: bigint) => void;
|
|
14
65
|
export const bitgopsbt_add_paygo_attestation: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
66
|
+
export const bitgopsbt_add_replay_protection_input: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint, h: number) => void;
|
|
67
|
+
export const bitgopsbt_add_wallet_input: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number) => void;
|
|
68
|
+
export const bitgopsbt_add_wallet_output: (a: number, b: number, c: number, d: number, e: bigint, f: number) => void;
|
|
15
69
|
export const bitgopsbt_combine_musig2_nonces: (a: number, b: number, c: number) => void;
|
|
70
|
+
export const bitgopsbt_create_empty: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
16
71
|
export const bitgopsbt_extract_transaction: (a: number, b: number) => void;
|
|
17
72
|
export const bitgopsbt_finalize_all_inputs: (a: number, b: number) => void;
|
|
18
73
|
export const bitgopsbt_from_bytes: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
19
74
|
export const bitgopsbt_generate_musig2_nonces: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
75
|
+
export const bitgopsbt_lock_time: (a: number) => number;
|
|
20
76
|
export const bitgopsbt_network: (a: number, b: number) => void;
|
|
21
77
|
export const bitgopsbt_parse_outputs_with_wallet_keys: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
22
78
|
export const bitgopsbt_parse_transaction_with_wallet_keys: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
@@ -27,6 +83,7 @@ export const bitgopsbt_unsigned_txid: (a: number, b: number) => void;
|
|
|
27
83
|
export const bitgopsbt_verify_replay_protection_signature: (a: number, b: number, c: number, d: number) => void;
|
|
28
84
|
export const bitgopsbt_verify_signature_with_pub: (a: number, b: number, c: number, d: number) => void;
|
|
29
85
|
export const bitgopsbt_verify_signature_with_xpub: (a: number, b: number, c: number, d: number) => void;
|
|
86
|
+
export const bitgopsbt_version: (a: number) => number;
|
|
30
87
|
export const fixedscriptwalletnamespace_address: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
31
88
|
export const fixedscriptwalletnamespace_output_script: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
32
89
|
export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
@@ -49,55 +106,6 @@ export const wasmrootwalletkeys_bitgo_key: (a: number) => number;
|
|
|
49
106
|
export const wasmrootwalletkeys_new: (a: number, b: number, c: number, d: number) => void;
|
|
50
107
|
export const wasmrootwalletkeys_user_key: (a: number) => number;
|
|
51
108
|
export const wasmrootwalletkeys_with_derivation_prefixes: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
|
|
52
|
-
export const wrappsbt_clone: (a: number) => number;
|
|
53
|
-
export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
|
|
54
|
-
export const wrappsbt_finalize: (a: number, b: number) => void;
|
|
55
|
-
export const wrappsbt_serialize: (a: number, b: number) => void;
|
|
56
|
-
export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number) => void;
|
|
57
|
-
export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
|
|
58
|
-
export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
59
|
-
export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
60
|
-
export const __wbg_wasmbip32_free: (a: number, b: number) => void;
|
|
61
|
-
export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
|
|
62
|
-
export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
|
|
63
|
-
export const wasmbip32_chain_code: (a: number) => number;
|
|
64
|
-
export const wasmbip32_depth: (a: number) => number;
|
|
65
|
-
export const wasmbip32_derive: (a: number, b: number, c: number) => void;
|
|
66
|
-
export const wasmbip32_derive_hardened: (a: number, b: number, c: number) => void;
|
|
67
|
-
export const wasmbip32_derive_path: (a: number, b: number, c: number, d: number) => void;
|
|
68
|
-
export const wasmbip32_fingerprint: (a: number) => number;
|
|
69
|
-
export const wasmbip32_from_base58: (a: number, b: number, c: number) => void;
|
|
70
|
-
export const wasmbip32_from_bip32_interface: (a: number, b: number) => void;
|
|
71
|
-
export const wasmbip32_from_seed: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
72
|
-
export const wasmbip32_from_xprv: (a: number, b: number, c: number) => void;
|
|
73
|
-
export const wasmbip32_from_xpub: (a: number, b: number, c: number) => void;
|
|
74
|
-
export const wasmbip32_identifier: (a: number) => number;
|
|
75
|
-
export const wasmbip32_index: (a: number) => number;
|
|
76
|
-
export const wasmbip32_is_neutered: (a: number) => number;
|
|
77
|
-
export const wasmbip32_neutered: (a: number) => number;
|
|
78
|
-
export const wasmbip32_parent_fingerprint: (a: number) => number;
|
|
79
|
-
export const wasmbip32_private_key: (a: number) => number;
|
|
80
|
-
export const wasmbip32_public_key: (a: number) => number;
|
|
81
|
-
export const wasmbip32_to_base58: (a: number, b: number) => void;
|
|
82
|
-
export const wasmbip32_to_wif: (a: number, b: number) => void;
|
|
83
|
-
export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
|
|
84
|
-
export const wrapdescriptor_descType: (a: number, b: number) => void;
|
|
85
|
-
export const wrapdescriptor_encode: (a: number, b: number) => void;
|
|
86
|
-
export const wrapdescriptor_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
87
|
-
export const wrapdescriptor_fromStringDetectType: (a: number, b: number, c: number) => void;
|
|
88
|
-
export const wrapdescriptor_hasWildcard: (a: number) => number;
|
|
89
|
-
export const wrapdescriptor_maxWeightToSatisfy: (a: number, b: number) => void;
|
|
90
|
-
export const wrapdescriptor_node: (a: number, b: number) => void;
|
|
91
|
-
export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
|
|
92
|
-
export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
|
|
93
|
-
export const wrapdescriptor_toString: (a: number, b: number) => void;
|
|
94
|
-
export const wrapminiscript_encode: (a: number, b: number) => void;
|
|
95
|
-
export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
96
|
-
export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
97
|
-
export const wrapminiscript_node: (a: number, b: number) => void;
|
|
98
|
-
export const wrapminiscript_toAsmString: (a: number, b: number) => void;
|
|
99
|
-
export const wrapminiscript_toString: (a: number, b: number) => void;
|
|
100
|
-
export const wasmbip32_from_bip32_properties: (a: number, b: number) => void;
|
|
101
109
|
export const rustsecp256k1_v0_10_0_context_create: (a: number) => number;
|
|
102
110
|
export const rustsecp256k1_v0_10_0_context_destroy: (a: number) => void;
|
|
103
111
|
export const rustsecp256k1_v0_10_0_default_error_callback_fn: (a: number, b: number) => void;
|
|
@@ -21,6 +21,7 @@ export type ParsedInput = {
|
|
|
21
21
|
value: bigint;
|
|
22
22
|
scriptId: ScriptId | null;
|
|
23
23
|
scriptType: InputScriptType;
|
|
24
|
+
sequence: number;
|
|
24
25
|
};
|
|
25
26
|
export type ParsedOutput = {
|
|
26
27
|
address: string | null;
|
|
@@ -36,9 +37,77 @@ export type ParsedTransaction = {
|
|
|
36
37
|
minerFee: bigint;
|
|
37
38
|
virtualSize: number;
|
|
38
39
|
};
|
|
40
|
+
export type CreateEmptyOptions = {
|
|
41
|
+
/** Transaction version (default: 2) */
|
|
42
|
+
version?: number;
|
|
43
|
+
/** Lock time (default: 0) */
|
|
44
|
+
lockTime?: number;
|
|
45
|
+
};
|
|
46
|
+
export type AddInputOptions = {
|
|
47
|
+
/** Previous transaction ID (hex string) */
|
|
48
|
+
txid: string;
|
|
49
|
+
/** Output index being spent */
|
|
50
|
+
vout: number;
|
|
51
|
+
/** Value in satoshis (for witness_utxo) */
|
|
52
|
+
value: bigint;
|
|
53
|
+
/** Sequence number (default: 0xFFFFFFFE for RBF) */
|
|
54
|
+
sequence?: number;
|
|
55
|
+
/** Full previous transaction (for non-segwit strict compliance) */
|
|
56
|
+
prevTx?: Uint8Array;
|
|
57
|
+
};
|
|
58
|
+
export type AddOutputOptions = {
|
|
59
|
+
/** Output script (scriptPubKey) */
|
|
60
|
+
script: Uint8Array;
|
|
61
|
+
/** Value in satoshis */
|
|
62
|
+
value: bigint;
|
|
63
|
+
};
|
|
64
|
+
/** Key identifier for signing ("user", "backup", or "bitgo") */
|
|
65
|
+
export type SignerKey = "user" | "backup" | "bitgo";
|
|
66
|
+
/** Specifies signer and cosigner for Taproot inputs */
|
|
67
|
+
export type SignPath = {
|
|
68
|
+
/** Key that will sign */
|
|
69
|
+
signer: SignerKey;
|
|
70
|
+
/** Key that will co-sign */
|
|
71
|
+
cosigner: SignerKey;
|
|
72
|
+
};
|
|
73
|
+
export type AddWalletInputOptions = {
|
|
74
|
+
/** Script location in wallet (chain + index) */
|
|
75
|
+
scriptId: ScriptId;
|
|
76
|
+
/** Sign path - required for p2tr/p2trMusig2 (chains 30-41) */
|
|
77
|
+
signPath?: SignPath;
|
|
78
|
+
};
|
|
79
|
+
export type AddWalletOutputOptions = {
|
|
80
|
+
/** Chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2) */
|
|
81
|
+
chain: number;
|
|
82
|
+
/** Derivation index */
|
|
83
|
+
index: number;
|
|
84
|
+
/** Value in satoshis */
|
|
85
|
+
value: bigint;
|
|
86
|
+
};
|
|
39
87
|
export declare class BitGoPsbt {
|
|
40
88
|
private wasm;
|
|
41
89
|
private constructor();
|
|
90
|
+
/**
|
|
91
|
+
* Create an empty PSBT for the given network with wallet keys
|
|
92
|
+
*
|
|
93
|
+
* The wallet keys are used to set global xpubs in the PSBT, which identifies
|
|
94
|
+
* the keys that will be used for signing.
|
|
95
|
+
*
|
|
96
|
+
* @param network - Network name (utxolib name like "bitcoin" or coin name like "btc")
|
|
97
|
+
* @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
|
|
98
|
+
* @param options - Optional transaction parameters (version, lockTime)
|
|
99
|
+
* @returns A new empty BitGoPsbt instance
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* // Create empty PSBT with wallet keys
|
|
104
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys);
|
|
105
|
+
*
|
|
106
|
+
* // Create with custom version and lockTime
|
|
107
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys, { version: 1, lockTime: 500000 });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
static createEmpty(network: NetworkName, walletKeys: WalletKeysArg, options?: CreateEmptyOptions): BitGoPsbt;
|
|
42
111
|
/**
|
|
43
112
|
* Deserialize a PSBT from bytes
|
|
44
113
|
* @param bytes - The PSBT bytes
|
|
@@ -46,11 +115,147 @@ export declare class BitGoPsbt {
|
|
|
46
115
|
* @returns A BitGoPsbt instance
|
|
47
116
|
*/
|
|
48
117
|
static fromBytes(bytes: Uint8Array, network: NetworkName): BitGoPsbt;
|
|
118
|
+
/**
|
|
119
|
+
* Add an input to the PSBT
|
|
120
|
+
*
|
|
121
|
+
* This adds a transaction input and corresponding PSBT input metadata.
|
|
122
|
+
* The witness_utxo is automatically populated for modern signing compatibility.
|
|
123
|
+
*
|
|
124
|
+
* @param options - Input options (txid, vout, value, sequence)
|
|
125
|
+
* @param script - Output script of the UTXO being spent
|
|
126
|
+
* @returns The index of the newly added input
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const inputIndex = psbt.addInput({
|
|
131
|
+
* txid: "abc123...",
|
|
132
|
+
* vout: 0,
|
|
133
|
+
* value: 100000n,
|
|
134
|
+
* }, outputScript);
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
addInput(options: AddInputOptions, script: Uint8Array): number;
|
|
138
|
+
/**
|
|
139
|
+
* Add an output to the PSBT
|
|
140
|
+
*
|
|
141
|
+
* @param options - Output options (script, value)
|
|
142
|
+
* @returns The index of the newly added output
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const outputIndex = psbt.addOutput({
|
|
147
|
+
* script: outputScript,
|
|
148
|
+
* value: 50000n,
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
addOutput(options: AddOutputOptions): number;
|
|
153
|
+
/**
|
|
154
|
+
* Add a wallet input with full PSBT metadata
|
|
155
|
+
*
|
|
156
|
+
* This is a higher-level method that adds an input and populates all required
|
|
157
|
+
* PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
|
|
158
|
+
*
|
|
159
|
+
* For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript (signPath not needed)
|
|
160
|
+
* For p2tr/p2trMusig2 script path: Sets tapLeafScript, tapBip32Derivation (signPath required)
|
|
161
|
+
* For p2trMusig2 key path: Sets tapInternalKey, tapMerkleRoot, tapBip32Derivation, musig2 participants (signPath required)
|
|
162
|
+
*
|
|
163
|
+
* @param inputOptions - Common input options (txid, vout, value, sequence)
|
|
164
|
+
* @param walletKeys - The wallet's root keys
|
|
165
|
+
* @param walletOptions - Wallet-specific options (scriptId, signPath, prevTx)
|
|
166
|
+
* @returns The index of the newly added input
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* // Add a p2shP2wsh input (signPath not needed)
|
|
171
|
+
* const inputIndex = psbt.addWalletInput(
|
|
172
|
+
* { txid: "abc123...", vout: 0, value: 100000n },
|
|
173
|
+
* walletKeys,
|
|
174
|
+
* { scriptId: { chain: 10, index: 0 } }, // p2shP2wsh external
|
|
175
|
+
* );
|
|
176
|
+
*
|
|
177
|
+
* // Add a p2trMusig2 key path input (signPath required)
|
|
178
|
+
* const inputIndex = psbt.addWalletInput(
|
|
179
|
+
* { txid: "def456...", vout: 1, value: 50000n },
|
|
180
|
+
* walletKeys,
|
|
181
|
+
* { scriptId: { chain: 40, index: 5 }, signPath: { signer: "user", cosigner: "bitgo" } },
|
|
182
|
+
* );
|
|
183
|
+
*
|
|
184
|
+
* // Add p2trMusig2 with backup key (script path spend)
|
|
185
|
+
* const inputIndex = psbt.addWalletInput(
|
|
186
|
+
* { txid: "ghi789...", vout: 0, value: 75000n },
|
|
187
|
+
* walletKeys,
|
|
188
|
+
* { scriptId: { chain: 40, index: 3 }, signPath: { signer: "user", cosigner: "backup" } },
|
|
189
|
+
* );
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
addWalletInput(inputOptions: AddInputOptions, walletKeys: WalletKeysArg, walletOptions: AddWalletInputOptions): number;
|
|
193
|
+
/**
|
|
194
|
+
* Add a wallet output with full PSBT metadata
|
|
195
|
+
*
|
|
196
|
+
* This creates a verifiable wallet output (typically for change) with all required
|
|
197
|
+
* PSBT fields (scripts, derivation info) based on the wallet's chain type.
|
|
198
|
+
*
|
|
199
|
+
* For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript
|
|
200
|
+
* For p2tr/p2trMusig2: Sets tapInternalKey, tapBip32Derivation
|
|
201
|
+
*
|
|
202
|
+
* @param walletKeys - The wallet's root keys
|
|
203
|
+
* @param options - Output options including chain, index, and value
|
|
204
|
+
* @returns The index of the newly added output
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* // Add a p2shP2wsh change output
|
|
209
|
+
* const outputIndex = psbt.addWalletOutput(walletKeys, {
|
|
210
|
+
* chain: 11, // p2shP2wsh internal (change)
|
|
211
|
+
* index: 0,
|
|
212
|
+
* value: 50000n,
|
|
213
|
+
* });
|
|
214
|
+
*
|
|
215
|
+
* // Add a p2trMusig2 change output
|
|
216
|
+
* const outputIndex = psbt.addWalletOutput(walletKeys, {
|
|
217
|
+
* chain: 41, // p2trMusig2 internal (change)
|
|
218
|
+
* index: 5,
|
|
219
|
+
* value: 25000n,
|
|
220
|
+
* });
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
addWalletOutput(walletKeys: WalletKeysArg, options: AddWalletOutputOptions): number;
|
|
224
|
+
/**
|
|
225
|
+
* Add a replay protection input to the PSBT
|
|
226
|
+
*
|
|
227
|
+
* Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
|
|
228
|
+
* transaction replay attacks. They use a simple pubkey script without wallet derivation.
|
|
229
|
+
*
|
|
230
|
+
* @param inputOptions - Common input options (txid, vout, value, sequence)
|
|
231
|
+
* @param key - ECPair containing the public key for the replay protection input
|
|
232
|
+
* @returns The index of the newly added input
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* // Add a replay protection input using ECPair
|
|
237
|
+
* const inputIndex = psbt.addReplayProtectionInput(
|
|
238
|
+
* { txid: "abc123...", vout: 0, value: 1000n },
|
|
239
|
+
* replayProtectionKey,
|
|
240
|
+
* );
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
addReplayProtectionInput(inputOptions: AddInputOptions, key: ECPairArg): number;
|
|
49
244
|
/**
|
|
50
245
|
* Get the unsigned transaction ID
|
|
51
246
|
* @returns The unsigned transaction ID
|
|
52
247
|
*/
|
|
53
248
|
unsignedTxid(): string;
|
|
249
|
+
/**
|
|
250
|
+
* Get the transaction version
|
|
251
|
+
* @returns The transaction version number
|
|
252
|
+
*/
|
|
253
|
+
get version(): number;
|
|
254
|
+
/**
|
|
255
|
+
* Get the transaction lock time
|
|
256
|
+
* @returns The transaction lock time
|
|
257
|
+
*/
|
|
258
|
+
get lockTime(): number;
|
|
54
259
|
/**
|
|
55
260
|
* Parse transaction with wallet keys to identify wallet inputs/outputs
|
|
56
261
|
* @param walletKeys - The wallet keys to use for identification
|