@bitgo/wasm-utxo 1.14.1 → 1.16.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 +10 -1
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +210 -2
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +180 -0
- package/dist/cjs/js/fixedScriptWallet/ZcashBitGoPsbt.d.ts +113 -0
- package/dist/cjs/js/fixedScriptWallet/ZcashBitGoPsbt.js +114 -0
- package/dist/cjs/js/fixedScriptWallet/index.d.ts +2 -1
- package/dist/cjs/js/fixedScriptWallet/index.js +5 -1
- package/dist/cjs/js/wasm/wasm_utxo.d.ts +141 -0
- package/dist/cjs/js/wasm/wasm_utxo.js +352 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +53 -41
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +210 -2
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +180 -0
- package/dist/esm/js/fixedScriptWallet/ZcashBitGoPsbt.d.ts +113 -0
- package/dist/esm/js/fixedScriptWallet/ZcashBitGoPsbt.js +110 -0
- package/dist/esm/js/fixedScriptWallet/index.d.ts +2 -1
- package/dist/esm/js/fixedScriptWallet/index.js +3 -0
- package/dist/esm/js/wasm/wasm_utxo.d.ts +141 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.js +352 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +53 -41
- package/package.json +1 -1
|
@@ -1,22 +1,43 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
|
|
5
|
+
export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
|
|
6
|
+
export const wrapdescriptor_descType: (a: number, b: number) => void;
|
|
7
|
+
export const wrapdescriptor_encode: (a: number, b: number) => void;
|
|
8
|
+
export const wrapdescriptor_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
9
|
+
export const wrapdescriptor_fromStringDetectType: (a: number, b: number, c: number) => void;
|
|
10
|
+
export const wrapdescriptor_hasWildcard: (a: number) => number;
|
|
11
|
+
export const wrapdescriptor_maxWeightToSatisfy: (a: number, b: number) => void;
|
|
12
|
+
export const wrapdescriptor_node: (a: number, b: number) => void;
|
|
13
|
+
export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
|
|
14
|
+
export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
|
|
15
|
+
export const wrapdescriptor_toString: (a: number, b: number) => void;
|
|
4
16
|
export const __wbg_addressnamespace_free: (a: number, b: number) => void;
|
|
5
17
|
export const __wbg_bitgopsbt_free: (a: number, b: number) => void;
|
|
6
18
|
export const __wbg_fixedscriptwalletnamespace_free: (a: number, b: number) => void;
|
|
7
|
-
export const
|
|
19
|
+
export const __wbg_wasmbip32_free: (a: number, b: number) => void;
|
|
8
20
|
export const __wbg_wasmecpair_free: (a: number, b: number) => void;
|
|
9
|
-
export const __wbg_wasmreplayprotection_free: (a: number, b: number) => void;
|
|
10
21
|
export const __wbg_wasmrootwalletkeys_free: (a: number, b: number) => void;
|
|
11
22
|
export const __wbg_wrappsbt_free: (a: number, b: number) => void;
|
|
12
23
|
export const addressnamespace_from_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
13
24
|
export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
25
|
+
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;
|
|
26
|
+
export const bitgopsbt_add_output: (a: number, b: number, c: number, d: number, e: bigint) => void;
|
|
14
27
|
export const bitgopsbt_add_paygo_attestation: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
28
|
+
export const bitgopsbt_add_replay_protection_input: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint, h: number) => void;
|
|
29
|
+
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;
|
|
30
|
+
export const bitgopsbt_add_wallet_output: (a: number, b: number, c: number, d: number, e: bigint, f: number) => void;
|
|
15
31
|
export const bitgopsbt_combine_musig2_nonces: (a: number, b: number, c: number) => void;
|
|
32
|
+
export const bitgopsbt_create_empty: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
33
|
+
export const bitgopsbt_create_empty_zcash: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
34
|
+
export const bitgopsbt_create_empty_zcash_at_height: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
35
|
+
export const bitgopsbt_expiry_height: (a: number) => number;
|
|
16
36
|
export const bitgopsbt_extract_transaction: (a: number, b: number) => void;
|
|
17
37
|
export const bitgopsbt_finalize_all_inputs: (a: number, b: number) => void;
|
|
18
38
|
export const bitgopsbt_from_bytes: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
19
39
|
export const bitgopsbt_generate_musig2_nonces: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
40
|
+
export const bitgopsbt_lock_time: (a: number) => number;
|
|
20
41
|
export const bitgopsbt_network: (a: number, b: number) => void;
|
|
21
42
|
export const bitgopsbt_parse_outputs_with_wallet_keys: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
22
43
|
export const bitgopsbt_parse_transaction_with_wallet_keys: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
@@ -27,10 +48,30 @@ export const bitgopsbt_unsigned_txid: (a: number, b: number) => void;
|
|
|
27
48
|
export const bitgopsbt_verify_replay_protection_signature: (a: number, b: number, c: number, d: number) => void;
|
|
28
49
|
export const bitgopsbt_verify_signature_with_pub: (a: number, b: number, c: number, d: number) => void;
|
|
29
50
|
export const bitgopsbt_verify_signature_with_xpub: (a: number, b: number, c: number, d: number) => void;
|
|
51
|
+
export const bitgopsbt_version: (a: number) => number;
|
|
52
|
+
export const bitgopsbt_version_group_id: (a: number) => number;
|
|
30
53
|
export const fixedscriptwalletnamespace_address: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
31
54
|
export const fixedscriptwalletnamespace_output_script: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
32
|
-
export const
|
|
33
|
-
export const
|
|
55
|
+
export const wasmbip32_chain_code: (a: number) => number;
|
|
56
|
+
export const wasmbip32_depth: (a: number) => number;
|
|
57
|
+
export const wasmbip32_derive: (a: number, b: number, c: number) => void;
|
|
58
|
+
export const wasmbip32_derive_hardened: (a: number, b: number, c: number) => void;
|
|
59
|
+
export const wasmbip32_derive_path: (a: number, b: number, c: number, d: number) => void;
|
|
60
|
+
export const wasmbip32_fingerprint: (a: number) => number;
|
|
61
|
+
export const wasmbip32_from_base58: (a: number, b: number, c: number) => void;
|
|
62
|
+
export const wasmbip32_from_bip32_interface: (a: number, b: number) => void;
|
|
63
|
+
export const wasmbip32_from_seed: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
64
|
+
export const wasmbip32_from_xprv: (a: number, b: number, c: number) => void;
|
|
65
|
+
export const wasmbip32_from_xpub: (a: number, b: number, c: number) => void;
|
|
66
|
+
export const wasmbip32_identifier: (a: number) => number;
|
|
67
|
+
export const wasmbip32_index: (a: number) => number;
|
|
68
|
+
export const wasmbip32_is_neutered: (a: number) => number;
|
|
69
|
+
export const wasmbip32_neutered: (a: number) => number;
|
|
70
|
+
export const wasmbip32_parent_fingerprint: (a: number) => number;
|
|
71
|
+
export const wasmbip32_private_key: (a: number) => number;
|
|
72
|
+
export const wasmbip32_public_key: (a: number) => number;
|
|
73
|
+
export const wasmbip32_to_base58: (a: number, b: number) => void;
|
|
74
|
+
export const wasmbip32_to_wif: (a: number, b: number) => void;
|
|
34
75
|
export const wasmecpair_from_private_key: (a: number, b: number, c: number) => void;
|
|
35
76
|
export const wasmecpair_from_public_key: (a: number, b: number, c: number) => void;
|
|
36
77
|
export const wasmecpair_from_wif: (a: number, b: number, c: number) => void;
|
|
@@ -41,9 +82,6 @@ export const wasmecpair_public_key: (a: number) => number;
|
|
|
41
82
|
export const wasmecpair_to_wif: (a: number, b: number) => void;
|
|
42
83
|
export const wasmecpair_to_wif_mainnet: (a: number, b: number) => void;
|
|
43
84
|
export const wasmecpair_to_wif_testnet: (a: number, b: number) => void;
|
|
44
|
-
export const wasmreplayprotection_from_addresses: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
45
|
-
export const wasmreplayprotection_from_output_scripts: (a: number, b: number) => number;
|
|
46
|
-
export const wasmreplayprotection_from_public_keys: (a: number, b: number, c: number) => void;
|
|
47
85
|
export const wasmrootwalletkeys_backup_key: (a: number) => number;
|
|
48
86
|
export const wasmrootwalletkeys_bitgo_key: (a: number) => number;
|
|
49
87
|
export const wasmrootwalletkeys_new: (a: number, b: number, c: number, d: number) => void;
|
|
@@ -57,47 +95,21 @@ export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number)
|
|
|
57
95
|
export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
|
|
58
96
|
export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
59
97
|
export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
60
|
-
export const
|
|
61
|
-
export const
|
|
98
|
+
export const wasmbip32_from_bip32_properties: (a: number, b: number) => void;
|
|
99
|
+
export const __wbg_wasmreplayprotection_free: (a: number, b: number) => void;
|
|
100
|
+
export const wasmreplayprotection_from_addresses: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
101
|
+
export const wasmreplayprotection_from_output_scripts: (a: number, b: number) => number;
|
|
102
|
+
export const wasmreplayprotection_from_public_keys: (a: number, b: number, c: number) => void;
|
|
103
|
+
export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
|
|
62
104
|
export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
|
|
63
|
-
export const
|
|
64
|
-
export const
|
|
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;
|
|
105
|
+
export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
106
|
+
export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
94
107
|
export const wrapminiscript_encode: (a: number, b: number) => void;
|
|
95
108
|
export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
96
109
|
export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
97
110
|
export const wrapminiscript_node: (a: number, b: number) => void;
|
|
98
111
|
export const wrapminiscript_toAsmString: (a: number, b: number) => void;
|
|
99
112
|
export const wrapminiscript_toString: (a: number, b: number) => void;
|
|
100
|
-
export const wasmbip32_from_bip32_properties: (a: number, b: number) => void;
|
|
101
113
|
export const rustsecp256k1_v0_10_0_context_create: (a: number) => number;
|
|
102
114
|
export const rustsecp256k1_v0_10_0_context_destroy: (a: number) => void;
|
|
103
115
|
export const rustsecp256k1_v0_10_0_default_error_callback_fn: (a: number, b: number) => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BitGoPsbt as WasmBitGoPsbt } from "../wasm/wasm_utxo.js";
|
|
1
2
|
import { type WalletKeysArg } from "./RootWalletKeys.js";
|
|
2
3
|
import { type ReplayProtectionArg } from "./ReplayProtection.js";
|
|
3
4
|
import { type BIP32Arg } from "../bip32.js";
|
|
@@ -21,6 +22,7 @@ export type ParsedInput = {
|
|
|
21
22
|
value: bigint;
|
|
22
23
|
scriptId: ScriptId | null;
|
|
23
24
|
scriptType: InputScriptType;
|
|
25
|
+
sequence: number;
|
|
24
26
|
};
|
|
25
27
|
export type ParsedOutput = {
|
|
26
28
|
address: string | null;
|
|
@@ -36,9 +38,79 @@ export type ParsedTransaction = {
|
|
|
36
38
|
minerFee: bigint;
|
|
37
39
|
virtualSize: number;
|
|
38
40
|
};
|
|
41
|
+
export type CreateEmptyOptions = {
|
|
42
|
+
/** Transaction version (default: 2) */
|
|
43
|
+
version?: number;
|
|
44
|
+
/** Lock time (default: 0) */
|
|
45
|
+
lockTime?: number;
|
|
46
|
+
};
|
|
47
|
+
export type AddInputOptions = {
|
|
48
|
+
/** Previous transaction ID (hex string) */
|
|
49
|
+
txid: string;
|
|
50
|
+
/** Output index being spent */
|
|
51
|
+
vout: number;
|
|
52
|
+
/** Value in satoshis (for witness_utxo) */
|
|
53
|
+
value: bigint;
|
|
54
|
+
/** Sequence number (default: 0xFFFFFFFE for RBF) */
|
|
55
|
+
sequence?: number;
|
|
56
|
+
/** Full previous transaction (for non-segwit strict compliance) */
|
|
57
|
+
prevTx?: Uint8Array;
|
|
58
|
+
};
|
|
59
|
+
export type AddOutputOptions = {
|
|
60
|
+
/** Output script (scriptPubKey) */
|
|
61
|
+
script: Uint8Array;
|
|
62
|
+
/** Value in satoshis */
|
|
63
|
+
value: bigint;
|
|
64
|
+
};
|
|
65
|
+
/** Key identifier for signing ("user", "backup", or "bitgo") */
|
|
66
|
+
export type SignerKey = "user" | "backup" | "bitgo";
|
|
67
|
+
/** Specifies signer and cosigner for Taproot inputs */
|
|
68
|
+
export type SignPath = {
|
|
69
|
+
/** Key that will sign */
|
|
70
|
+
signer: SignerKey;
|
|
71
|
+
/** Key that will co-sign */
|
|
72
|
+
cosigner: SignerKey;
|
|
73
|
+
};
|
|
74
|
+
export type AddWalletInputOptions = {
|
|
75
|
+
/** Script location in wallet (chain + index) */
|
|
76
|
+
scriptId: ScriptId;
|
|
77
|
+
/** Sign path - required for p2tr/p2trMusig2 (chains 30-41) */
|
|
78
|
+
signPath?: SignPath;
|
|
79
|
+
};
|
|
80
|
+
export type AddWalletOutputOptions = {
|
|
81
|
+
/** Chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2) */
|
|
82
|
+
chain: number;
|
|
83
|
+
/** Derivation index */
|
|
84
|
+
index: number;
|
|
85
|
+
/** Value in satoshis */
|
|
86
|
+
value: bigint;
|
|
87
|
+
};
|
|
39
88
|
export declare class BitGoPsbt {
|
|
40
|
-
|
|
41
|
-
|
|
89
|
+
protected wasm: WasmBitGoPsbt;
|
|
90
|
+
protected constructor(wasm: WasmBitGoPsbt);
|
|
91
|
+
/**
|
|
92
|
+
* Create an empty PSBT for the given network with wallet keys
|
|
93
|
+
*
|
|
94
|
+
* The wallet keys are used to set global xpubs in the PSBT, which identifies
|
|
95
|
+
* the keys that will be used for signing.
|
|
96
|
+
*
|
|
97
|
+
* For Zcash networks, use ZcashBitGoPsbt.createEmpty() instead.
|
|
98
|
+
*
|
|
99
|
+
* @param network - Network name (utxolib name like "bitcoin" or coin name like "btc")
|
|
100
|
+
* @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
|
|
101
|
+
* @param options - Optional transaction parameters (version, lockTime)
|
|
102
|
+
* @returns A new empty BitGoPsbt instance
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* // Create empty PSBT with wallet keys
|
|
107
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys);
|
|
108
|
+
*
|
|
109
|
+
* // Create with custom version and lockTime
|
|
110
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys, { version: 1, lockTime: 500000 });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
static createEmpty(network: NetworkName, walletKeys: WalletKeysArg, options?: CreateEmptyOptions): BitGoPsbt;
|
|
42
114
|
/**
|
|
43
115
|
* Deserialize a PSBT from bytes
|
|
44
116
|
* @param bytes - The PSBT bytes
|
|
@@ -46,11 +118,147 @@ export declare class BitGoPsbt {
|
|
|
46
118
|
* @returns A BitGoPsbt instance
|
|
47
119
|
*/
|
|
48
120
|
static fromBytes(bytes: Uint8Array, network: NetworkName): BitGoPsbt;
|
|
121
|
+
/**
|
|
122
|
+
* Add an input to the PSBT
|
|
123
|
+
*
|
|
124
|
+
* This adds a transaction input and corresponding PSBT input metadata.
|
|
125
|
+
* The witness_utxo is automatically populated for modern signing compatibility.
|
|
126
|
+
*
|
|
127
|
+
* @param options - Input options (txid, vout, value, sequence)
|
|
128
|
+
* @param script - Output script of the UTXO being spent
|
|
129
|
+
* @returns The index of the newly added input
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const inputIndex = psbt.addInput({
|
|
134
|
+
* txid: "abc123...",
|
|
135
|
+
* vout: 0,
|
|
136
|
+
* value: 100000n,
|
|
137
|
+
* }, outputScript);
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
addInput(options: AddInputOptions, script: Uint8Array): number;
|
|
141
|
+
/**
|
|
142
|
+
* Add an output to the PSBT
|
|
143
|
+
*
|
|
144
|
+
* @param options - Output options (script, value)
|
|
145
|
+
* @returns The index of the newly added output
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const outputIndex = psbt.addOutput({
|
|
150
|
+
* script: outputScript,
|
|
151
|
+
* value: 50000n,
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
addOutput(options: AddOutputOptions): number;
|
|
156
|
+
/**
|
|
157
|
+
* Add a wallet input with full PSBT metadata
|
|
158
|
+
*
|
|
159
|
+
* This is a higher-level method that adds an input and populates all required
|
|
160
|
+
* PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
|
|
161
|
+
*
|
|
162
|
+
* For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript (signPath not needed)
|
|
163
|
+
* For p2tr/p2trMusig2 script path: Sets tapLeafScript, tapBip32Derivation (signPath required)
|
|
164
|
+
* For p2trMusig2 key path: Sets tapInternalKey, tapMerkleRoot, tapBip32Derivation, musig2 participants (signPath required)
|
|
165
|
+
*
|
|
166
|
+
* @param inputOptions - Common input options (txid, vout, value, sequence)
|
|
167
|
+
* @param walletKeys - The wallet's root keys
|
|
168
|
+
* @param walletOptions - Wallet-specific options (scriptId, signPath, prevTx)
|
|
169
|
+
* @returns The index of the newly added input
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* // Add a p2shP2wsh input (signPath not needed)
|
|
174
|
+
* const inputIndex = psbt.addWalletInput(
|
|
175
|
+
* { txid: "abc123...", vout: 0, value: 100000n },
|
|
176
|
+
* walletKeys,
|
|
177
|
+
* { scriptId: { chain: 10, index: 0 } }, // p2shP2wsh external
|
|
178
|
+
* );
|
|
179
|
+
*
|
|
180
|
+
* // Add a p2trMusig2 key path input (signPath required)
|
|
181
|
+
* const inputIndex = psbt.addWalletInput(
|
|
182
|
+
* { txid: "def456...", vout: 1, value: 50000n },
|
|
183
|
+
* walletKeys,
|
|
184
|
+
* { scriptId: { chain: 40, index: 5 }, signPath: { signer: "user", cosigner: "bitgo" } },
|
|
185
|
+
* );
|
|
186
|
+
*
|
|
187
|
+
* // Add p2trMusig2 with backup key (script path spend)
|
|
188
|
+
* const inputIndex = psbt.addWalletInput(
|
|
189
|
+
* { txid: "ghi789...", vout: 0, value: 75000n },
|
|
190
|
+
* walletKeys,
|
|
191
|
+
* { scriptId: { chain: 40, index: 3 }, signPath: { signer: "user", cosigner: "backup" } },
|
|
192
|
+
* );
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
addWalletInput(inputOptions: AddInputOptions, walletKeys: WalletKeysArg, walletOptions: AddWalletInputOptions): number;
|
|
196
|
+
/**
|
|
197
|
+
* Add a wallet output with full PSBT metadata
|
|
198
|
+
*
|
|
199
|
+
* This creates a verifiable wallet output (typically for change) with all required
|
|
200
|
+
* PSBT fields (scripts, derivation info) based on the wallet's chain type.
|
|
201
|
+
*
|
|
202
|
+
* For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript
|
|
203
|
+
* For p2tr/p2trMusig2: Sets tapInternalKey, tapBip32Derivation
|
|
204
|
+
*
|
|
205
|
+
* @param walletKeys - The wallet's root keys
|
|
206
|
+
* @param options - Output options including chain, index, and value
|
|
207
|
+
* @returns The index of the newly added output
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* // Add a p2shP2wsh change output
|
|
212
|
+
* const outputIndex = psbt.addWalletOutput(walletKeys, {
|
|
213
|
+
* chain: 11, // p2shP2wsh internal (change)
|
|
214
|
+
* index: 0,
|
|
215
|
+
* value: 50000n,
|
|
216
|
+
* });
|
|
217
|
+
*
|
|
218
|
+
* // Add a p2trMusig2 change output
|
|
219
|
+
* const outputIndex = psbt.addWalletOutput(walletKeys, {
|
|
220
|
+
* chain: 41, // p2trMusig2 internal (change)
|
|
221
|
+
* index: 5,
|
|
222
|
+
* value: 25000n,
|
|
223
|
+
* });
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
addWalletOutput(walletKeys: WalletKeysArg, options: AddWalletOutputOptions): number;
|
|
227
|
+
/**
|
|
228
|
+
* Add a replay protection input to the PSBT
|
|
229
|
+
*
|
|
230
|
+
* Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
|
|
231
|
+
* transaction replay attacks. They use a simple pubkey script without wallet derivation.
|
|
232
|
+
*
|
|
233
|
+
* @param inputOptions - Common input options (txid, vout, value, sequence)
|
|
234
|
+
* @param key - ECPair containing the public key for the replay protection input
|
|
235
|
+
* @returns The index of the newly added input
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* // Add a replay protection input using ECPair
|
|
240
|
+
* const inputIndex = psbt.addReplayProtectionInput(
|
|
241
|
+
* { txid: "abc123...", vout: 0, value: 1000n },
|
|
242
|
+
* replayProtectionKey,
|
|
243
|
+
* );
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
addReplayProtectionInput(inputOptions: AddInputOptions, key: ECPairArg): number;
|
|
49
247
|
/**
|
|
50
248
|
* Get the unsigned transaction ID
|
|
51
249
|
* @returns The unsigned transaction ID
|
|
52
250
|
*/
|
|
53
251
|
unsignedTxid(): string;
|
|
252
|
+
/**
|
|
253
|
+
* Get the transaction version
|
|
254
|
+
* @returns The transaction version number
|
|
255
|
+
*/
|
|
256
|
+
get version(): number;
|
|
257
|
+
/**
|
|
258
|
+
* Get the transaction lock time
|
|
259
|
+
* @returns The transaction lock time
|
|
260
|
+
*/
|
|
261
|
+
get lockTime(): number;
|
|
54
262
|
/**
|
|
55
263
|
* Parse transaction with wallet keys to identify wallet inputs/outputs
|
|
56
264
|
* @param walletKeys - The wallet keys to use for identification
|
|
@@ -8,6 +8,33 @@ 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
|
+
* For Zcash networks, use ZcashBitGoPsbt.createEmpty() instead.
|
|
18
|
+
*
|
|
19
|
+
* @param network - Network name (utxolib name like "bitcoin" or coin name like "btc")
|
|
20
|
+
* @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
|
|
21
|
+
* @param options - Optional transaction parameters (version, lockTime)
|
|
22
|
+
* @returns A new empty BitGoPsbt instance
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Create empty PSBT with wallet keys
|
|
27
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys);
|
|
28
|
+
*
|
|
29
|
+
* // Create with custom version and lockTime
|
|
30
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys, { version: 1, lockTime: 500000 });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
static createEmpty(network, walletKeys, options) {
|
|
34
|
+
const keys = RootWalletKeys.from(walletKeys);
|
|
35
|
+
const wasm = WasmBitGoPsbt.create_empty(network, keys.wasm, options?.version, options?.lockTime);
|
|
36
|
+
return new BitGoPsbt(wasm);
|
|
37
|
+
}
|
|
11
38
|
/**
|
|
12
39
|
* Deserialize a PSBT from bytes
|
|
13
40
|
* @param bytes - The PSBT bytes
|
|
@@ -18,6 +45,145 @@ export class BitGoPsbt {
|
|
|
18
45
|
const wasm = WasmBitGoPsbt.from_bytes(bytes, network);
|
|
19
46
|
return new BitGoPsbt(wasm);
|
|
20
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Add an input to the PSBT
|
|
50
|
+
*
|
|
51
|
+
* This adds a transaction input and corresponding PSBT input metadata.
|
|
52
|
+
* The witness_utxo is automatically populated for modern signing compatibility.
|
|
53
|
+
*
|
|
54
|
+
* @param options - Input options (txid, vout, value, sequence)
|
|
55
|
+
* @param script - Output script of the UTXO being spent
|
|
56
|
+
* @returns The index of the newly added input
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const inputIndex = psbt.addInput({
|
|
61
|
+
* txid: "abc123...",
|
|
62
|
+
* vout: 0,
|
|
63
|
+
* value: 100000n,
|
|
64
|
+
* }, outputScript);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
addInput(options, script) {
|
|
68
|
+
return this.wasm.add_input(options.txid, options.vout, options.value, script, options.sequence, options.prevTx);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Add an output to the PSBT
|
|
72
|
+
*
|
|
73
|
+
* @param options - Output options (script, value)
|
|
74
|
+
* @returns The index of the newly added output
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const outputIndex = psbt.addOutput({
|
|
79
|
+
* script: outputScript,
|
|
80
|
+
* value: 50000n,
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
addOutput(options) {
|
|
85
|
+
return this.wasm.add_output(options.script, options.value);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Add a wallet input with full PSBT metadata
|
|
89
|
+
*
|
|
90
|
+
* This is a higher-level method that adds an input and populates all required
|
|
91
|
+
* PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
|
|
92
|
+
*
|
|
93
|
+
* For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript (signPath not needed)
|
|
94
|
+
* For p2tr/p2trMusig2 script path: Sets tapLeafScript, tapBip32Derivation (signPath required)
|
|
95
|
+
* For p2trMusig2 key path: Sets tapInternalKey, tapMerkleRoot, tapBip32Derivation, musig2 participants (signPath required)
|
|
96
|
+
*
|
|
97
|
+
* @param inputOptions - Common input options (txid, vout, value, sequence)
|
|
98
|
+
* @param walletKeys - The wallet's root keys
|
|
99
|
+
* @param walletOptions - Wallet-specific options (scriptId, signPath, prevTx)
|
|
100
|
+
* @returns The index of the newly added input
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* // Add a p2shP2wsh input (signPath not needed)
|
|
105
|
+
* const inputIndex = psbt.addWalletInput(
|
|
106
|
+
* { txid: "abc123...", vout: 0, value: 100000n },
|
|
107
|
+
* walletKeys,
|
|
108
|
+
* { scriptId: { chain: 10, index: 0 } }, // p2shP2wsh external
|
|
109
|
+
* );
|
|
110
|
+
*
|
|
111
|
+
* // Add a p2trMusig2 key path input (signPath required)
|
|
112
|
+
* const inputIndex = psbt.addWalletInput(
|
|
113
|
+
* { txid: "def456...", vout: 1, value: 50000n },
|
|
114
|
+
* walletKeys,
|
|
115
|
+
* { scriptId: { chain: 40, index: 5 }, signPath: { signer: "user", cosigner: "bitgo" } },
|
|
116
|
+
* );
|
|
117
|
+
*
|
|
118
|
+
* // Add p2trMusig2 with backup key (script path spend)
|
|
119
|
+
* const inputIndex = psbt.addWalletInput(
|
|
120
|
+
* { txid: "ghi789...", vout: 0, value: 75000n },
|
|
121
|
+
* walletKeys,
|
|
122
|
+
* { scriptId: { chain: 40, index: 3 }, signPath: { signer: "user", cosigner: "backup" } },
|
|
123
|
+
* );
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
addWalletInput(inputOptions, walletKeys, walletOptions) {
|
|
127
|
+
const keys = RootWalletKeys.from(walletKeys);
|
|
128
|
+
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);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Add a wallet output with full PSBT metadata
|
|
132
|
+
*
|
|
133
|
+
* This creates a verifiable wallet output (typically for change) with all required
|
|
134
|
+
* PSBT fields (scripts, derivation info) based on the wallet's chain type.
|
|
135
|
+
*
|
|
136
|
+
* For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript
|
|
137
|
+
* For p2tr/p2trMusig2: Sets tapInternalKey, tapBip32Derivation
|
|
138
|
+
*
|
|
139
|
+
* @param walletKeys - The wallet's root keys
|
|
140
|
+
* @param options - Output options including chain, index, and value
|
|
141
|
+
* @returns The index of the newly added output
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // Add a p2shP2wsh change output
|
|
146
|
+
* const outputIndex = psbt.addWalletOutput(walletKeys, {
|
|
147
|
+
* chain: 11, // p2shP2wsh internal (change)
|
|
148
|
+
* index: 0,
|
|
149
|
+
* value: 50000n,
|
|
150
|
+
* });
|
|
151
|
+
*
|
|
152
|
+
* // Add a p2trMusig2 change output
|
|
153
|
+
* const outputIndex = psbt.addWalletOutput(walletKeys, {
|
|
154
|
+
* chain: 41, // p2trMusig2 internal (change)
|
|
155
|
+
* index: 5,
|
|
156
|
+
* value: 25000n,
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
addWalletOutput(walletKeys, options) {
|
|
161
|
+
const keys = RootWalletKeys.from(walletKeys);
|
|
162
|
+
return this.wasm.add_wallet_output(options.chain, options.index, options.value, keys.wasm);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Add a replay protection input to the PSBT
|
|
166
|
+
*
|
|
167
|
+
* Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
|
|
168
|
+
* transaction replay attacks. They use a simple pubkey script without wallet derivation.
|
|
169
|
+
*
|
|
170
|
+
* @param inputOptions - Common input options (txid, vout, value, sequence)
|
|
171
|
+
* @param key - ECPair containing the public key for the replay protection input
|
|
172
|
+
* @returns The index of the newly added input
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* // Add a replay protection input using ECPair
|
|
177
|
+
* const inputIndex = psbt.addReplayProtectionInput(
|
|
178
|
+
* { txid: "abc123...", vout: 0, value: 1000n },
|
|
179
|
+
* replayProtectionKey,
|
|
180
|
+
* );
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
addReplayProtectionInput(inputOptions, key) {
|
|
184
|
+
const ecpair = ECPair.from(key);
|
|
185
|
+
return this.wasm.add_replay_protection_input(ecpair.wasm, inputOptions.txid, inputOptions.vout, inputOptions.value, inputOptions.sequence);
|
|
186
|
+
}
|
|
21
187
|
/**
|
|
22
188
|
* Get the unsigned transaction ID
|
|
23
189
|
* @returns The unsigned transaction ID
|
|
@@ -25,6 +191,20 @@ export class BitGoPsbt {
|
|
|
25
191
|
unsignedTxid() {
|
|
26
192
|
return this.wasm.unsigned_txid();
|
|
27
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Get the transaction version
|
|
196
|
+
* @returns The transaction version number
|
|
197
|
+
*/
|
|
198
|
+
get version() {
|
|
199
|
+
return this.wasm.version();
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get the transaction lock time
|
|
203
|
+
* @returns The transaction lock time
|
|
204
|
+
*/
|
|
205
|
+
get lockTime() {
|
|
206
|
+
return this.wasm.lock_time();
|
|
207
|
+
}
|
|
28
208
|
/**
|
|
29
209
|
* Parse transaction with wallet keys to identify wallet inputs/outputs
|
|
30
210
|
* @param walletKeys - The wallet keys to use for identification
|