@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,4 +1,5 @@
|
|
|
1
1
|
export { RootWalletKeys, type WalletKeysArg, type IWalletKeys } from "./RootWalletKeys.js";
|
|
2
2
|
export { ReplayProtection, type ReplayProtectionArg } from "./ReplayProtection.js";
|
|
3
3
|
export { outputScript, address } from "./address.js";
|
|
4
|
-
export { BitGoPsbt, type NetworkName, type ScriptId, type InputScriptType, type ParsedInput, type ParsedOutput, type ParsedTransaction, } from "./BitGoPsbt.js";
|
|
4
|
+
export { BitGoPsbt, type NetworkName, type ScriptId, type InputScriptType, type ParsedInput, type ParsedOutput, type ParsedTransaction, type SignPath, type CreateEmptyOptions, type AddInputOptions, type AddOutputOptions, type AddWalletInputOptions, type AddWalletOutputOptions, } from "./BitGoPsbt.js";
|
|
5
|
+
export { ZcashBitGoPsbt, type ZcashNetworkName, type CreateEmptyZcashOptions, } from "./ZcashBitGoPsbt.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BitGoPsbt = exports.address = exports.outputScript = exports.ReplayProtection = exports.RootWalletKeys = void 0;
|
|
3
|
+
exports.ZcashBitGoPsbt = exports.BitGoPsbt = exports.address = exports.outputScript = exports.ReplayProtection = exports.RootWalletKeys = void 0;
|
|
4
4
|
var RootWalletKeys_js_1 = require("./RootWalletKeys.js");
|
|
5
5
|
Object.defineProperty(exports, "RootWalletKeys", { enumerable: true, get: function () { return RootWalletKeys_js_1.RootWalletKeys; } });
|
|
6
6
|
var ReplayProtection_js_1 = require("./ReplayProtection.js");
|
|
@@ -8,5 +8,9 @@ Object.defineProperty(exports, "ReplayProtection", { enumerable: true, get: func
|
|
|
8
8
|
var address_js_1 = require("./address.js");
|
|
9
9
|
Object.defineProperty(exports, "outputScript", { enumerable: true, get: function () { return address_js_1.outputScript; } });
|
|
10
10
|
Object.defineProperty(exports, "address", { enumerable: true, get: function () { return address_js_1.address; } });
|
|
11
|
+
// Bitcoin-like PSBT (for all non-Zcash networks)
|
|
11
12
|
var BitGoPsbt_js_1 = require("./BitGoPsbt.js");
|
|
12
13
|
Object.defineProperty(exports, "BitGoPsbt", { enumerable: true, get: function () { return BitGoPsbt_js_1.BitGoPsbt; } });
|
|
14
|
+
// Zcash-specific PSBT subclass
|
|
15
|
+
var ZcashBitGoPsbt_js_1 = require("./ZcashBitGoPsbt.js");
|
|
16
|
+
Object.defineProperty(exports, "ZcashBitGoPsbt", { enumerable: true, get: function () { return ZcashBitGoPsbt_js_1.ZcashBitGoPsbt; } });
|
|
@@ -13,10 +13,35 @@ export class BitGoPsbt {
|
|
|
13
13
|
private constructor();
|
|
14
14
|
free(): void;
|
|
15
15
|
[Symbol.dispose](): void;
|
|
16
|
+
/**
|
|
17
|
+
* Add an output to the PSBT
|
|
18
|
+
*
|
|
19
|
+
* # Arguments
|
|
20
|
+
* * `script` - The output script (scriptPubKey)
|
|
21
|
+
* * `value` - The value in satoshis
|
|
22
|
+
*
|
|
23
|
+
* # Returns
|
|
24
|
+
* The index of the newly added output
|
|
25
|
+
*/
|
|
26
|
+
add_output(script: Uint8Array, value: bigint): number;
|
|
16
27
|
/**
|
|
17
28
|
* Deserialize a PSBT from bytes with network-specific logic
|
|
18
29
|
*/
|
|
19
30
|
static from_bytes(bytes: Uint8Array, network: string): BitGoPsbt;
|
|
31
|
+
/**
|
|
32
|
+
* Create an empty PSBT for the given network with wallet keys
|
|
33
|
+
*
|
|
34
|
+
* # Arguments
|
|
35
|
+
* * `network` - Network name (utxolib or coin name)
|
|
36
|
+
* * `wallet_keys` - The wallet's root keys (used to set global xpubs)
|
|
37
|
+
* * `version` - Optional transaction version (default: 2)
|
|
38
|
+
* * `lock_time` - Optional lock time (default: 0)
|
|
39
|
+
*/
|
|
40
|
+
static create_empty(network: string, wallet_keys: WasmRootWalletKeys, version?: number | null, lock_time?: number | null): BitGoPsbt;
|
|
41
|
+
/**
|
|
42
|
+
* Get the Zcash expiry height (returns None for non-Zcash PSBTs)
|
|
43
|
+
*/
|
|
44
|
+
expiry_height(): number | undefined;
|
|
20
45
|
/**
|
|
21
46
|
* Get the unsigned transaction ID
|
|
22
47
|
*/
|
|
@@ -41,6 +66,48 @@ export class BitGoPsbt {
|
|
|
41
66
|
* - `Err(WasmUtxoError)` if signing fails
|
|
42
67
|
*/
|
|
43
68
|
sign_with_xpriv(input_index: number, xpriv: WasmBIP32): void;
|
|
69
|
+
/**
|
|
70
|
+
* Add a wallet input with full PSBT metadata
|
|
71
|
+
*
|
|
72
|
+
* This is a higher-level method that adds an input and populates all required
|
|
73
|
+
* PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
|
|
74
|
+
*
|
|
75
|
+
* # Arguments
|
|
76
|
+
* * `txid` - The transaction ID (hex string)
|
|
77
|
+
* * `vout` - The output index being spent
|
|
78
|
+
* * `value` - The value in satoshis
|
|
79
|
+
* * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
|
|
80
|
+
* * `index` - The derivation index
|
|
81
|
+
* * `wallet_keys` - The root wallet keys
|
|
82
|
+
* * `signer` - The key that will sign ("user", "backup", or "bitgo") - required for p2tr/p2trMusig2
|
|
83
|
+
* * `cosigner` - The key that will co-sign - required for p2tr/p2trMusig2
|
|
84
|
+
* * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
|
|
85
|
+
* * `prev_tx` - Optional full previous transaction bytes (for non-segwit)
|
|
86
|
+
*
|
|
87
|
+
* # Returns
|
|
88
|
+
* The index of the newly added input
|
|
89
|
+
*/
|
|
90
|
+
add_wallet_input(txid: string, vout: number, value: bigint, wallet_keys: WasmRootWalletKeys, chain: number, index: number, signer?: string | null, cosigner?: string | null, sequence?: number | null, prev_tx?: Uint8Array | null): number;
|
|
91
|
+
/**
|
|
92
|
+
* Get the Zcash version group ID (returns None for non-Zcash PSBTs)
|
|
93
|
+
*/
|
|
94
|
+
version_group_id(): number | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Add a wallet output with full PSBT metadata
|
|
97
|
+
*
|
|
98
|
+
* This creates a verifiable wallet output (typically for change) with all required
|
|
99
|
+
* PSBT fields (scripts, derivation info) based on the wallet's chain type.
|
|
100
|
+
*
|
|
101
|
+
* # Arguments
|
|
102
|
+
* * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
|
|
103
|
+
* * `index` - The derivation index
|
|
104
|
+
* * `value` - The value in satoshis
|
|
105
|
+
* * `wallet_keys` - The root wallet keys
|
|
106
|
+
*
|
|
107
|
+
* # Returns
|
|
108
|
+
* The index of the newly added output
|
|
109
|
+
*/
|
|
110
|
+
add_wallet_output(chain: number, index: number, value: bigint, wallet_keys: WasmRootWalletKeys): number;
|
|
44
111
|
/**
|
|
45
112
|
* Sign a single input with a raw private key
|
|
46
113
|
*
|
|
@@ -61,6 +128,22 @@ export class BitGoPsbt {
|
|
|
61
128
|
* - `Err(WasmUtxoError)` if signing fails
|
|
62
129
|
*/
|
|
63
130
|
sign_with_privkey(input_index: number, ecpair: WasmECPair): void;
|
|
131
|
+
/**
|
|
132
|
+
* Create an empty Zcash PSBT with the required consensus branch ID
|
|
133
|
+
*
|
|
134
|
+
* This method is specifically for Zcash networks which require additional
|
|
135
|
+
* parameters for sighash computation.
|
|
136
|
+
*
|
|
137
|
+
* # Arguments
|
|
138
|
+
* * `network` - Network name (must be "zcash" or "zcashTest")
|
|
139
|
+
* * `wallet_keys` - The wallet's root keys (used to set global xpubs)
|
|
140
|
+
* * `consensus_branch_id` - Zcash consensus branch ID (e.g., 0xC2D6D0B4 for NU5)
|
|
141
|
+
* * `version` - Optional transaction version (default: 4 for Zcash Sapling+)
|
|
142
|
+
* * `lock_time` - Optional lock time (default: 0)
|
|
143
|
+
* * `version_group_id` - Optional version group ID (defaults to Sapling: 0x892F2085)
|
|
144
|
+
* * `expiry_height` - Optional expiry height
|
|
145
|
+
*/
|
|
146
|
+
static create_empty_zcash(network: string, wallet_keys: WasmRootWalletKeys, consensus_branch_id: number, version?: number | null, lock_time?: number | null, version_group_id?: number | null, expiry_height?: number | null): BitGoPsbt;
|
|
64
147
|
/**
|
|
65
148
|
* Extract the final transaction from a finalized PSBT
|
|
66
149
|
*
|
|
@@ -181,6 +264,42 @@ export class BitGoPsbt {
|
|
|
181
264
|
* - `Err(WasmUtxoError)` if the input index is out of bounds, derivation fails, or verification fails
|
|
182
265
|
*/
|
|
183
266
|
verify_signature_with_xpub(input_index: number, xpub: WasmBIP32): boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Add a replay protection input to the PSBT
|
|
269
|
+
*
|
|
270
|
+
* Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
|
|
271
|
+
* transaction replay attacks. They use a simple pubkey script without wallet derivation.
|
|
272
|
+
*
|
|
273
|
+
* # Arguments
|
|
274
|
+
* * `ecpair` - The ECPair containing the public key for the replay protection input
|
|
275
|
+
* * `txid` - The transaction ID (hex string) of the output being spent
|
|
276
|
+
* * `vout` - The output index being spent
|
|
277
|
+
* * `value` - The value in satoshis
|
|
278
|
+
* * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
|
|
279
|
+
*
|
|
280
|
+
* # Returns
|
|
281
|
+
* The index of the newly added input
|
|
282
|
+
*/
|
|
283
|
+
add_replay_protection_input(ecpair: WasmECPair, txid: string, vout: number, value: bigint, sequence?: number | null): number;
|
|
284
|
+
/**
|
|
285
|
+
* Create an empty Zcash PSBT with consensus branch ID determined from block height
|
|
286
|
+
*
|
|
287
|
+
* This method automatically determines the correct consensus branch ID based on
|
|
288
|
+
* the network and block height using the network upgrade activation heights.
|
|
289
|
+
*
|
|
290
|
+
* # Arguments
|
|
291
|
+
* * `network` - Network name (must be "zcash" or "zcashTest")
|
|
292
|
+
* * `wallet_keys` - The wallet's root keys (used to set global xpubs)
|
|
293
|
+
* * `block_height` - Block height to determine consensus rules
|
|
294
|
+
* * `version` - Optional transaction version (default: 4 for Zcash Sapling+)
|
|
295
|
+
* * `lock_time` - Optional lock time (default: 0)
|
|
296
|
+
* * `version_group_id` - Optional version group ID (defaults to Sapling: 0x892F2085)
|
|
297
|
+
* * `expiry_height` - Optional expiry height
|
|
298
|
+
*
|
|
299
|
+
* # Errors
|
|
300
|
+
* Returns error if block height is before Overwinter activation
|
|
301
|
+
*/
|
|
302
|
+
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;
|
|
184
303
|
/**
|
|
185
304
|
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
186
305
|
*
|
|
@@ -213,6 +332,28 @@ export class BitGoPsbt {
|
|
|
213
332
|
* Get the network of the PSBT
|
|
214
333
|
*/
|
|
215
334
|
network(): string;
|
|
335
|
+
/**
|
|
336
|
+
* Get the transaction version
|
|
337
|
+
*/
|
|
338
|
+
version(): number;
|
|
339
|
+
/**
|
|
340
|
+
* Add an input to the PSBT
|
|
341
|
+
*
|
|
342
|
+
* # Arguments
|
|
343
|
+
* * `txid` - The transaction ID (hex string) of the output being spent
|
|
344
|
+
* * `vout` - The output index being spent
|
|
345
|
+
* * `value` - The value in satoshis of the output being spent
|
|
346
|
+
* * `script` - The output script (scriptPubKey) of the output being spent
|
|
347
|
+
* * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
|
|
348
|
+
*
|
|
349
|
+
* # Returns
|
|
350
|
+
* The index of the newly added input
|
|
351
|
+
*/
|
|
352
|
+
add_input(txid: string, vout: number, value: bigint, script: Uint8Array, sequence?: number | null, prev_tx?: Uint8Array | null): number;
|
|
353
|
+
/**
|
|
354
|
+
* Get the transaction lock time
|
|
355
|
+
*/
|
|
356
|
+
lock_time(): number;
|
|
216
357
|
/**
|
|
217
358
|
* Serialize the PSBT to bytes
|
|
218
359
|
*
|
|
@@ -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,46 @@ 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
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Get the Zcash expiry height (returns None for non-Zcash PSBTs)
|
|
389
|
+
* @returns {number | undefined}
|
|
390
|
+
*/
|
|
391
|
+
expiry_height() {
|
|
392
|
+
const ret = wasm.bitgopsbt_expiry_height(this.__wbg_ptr);
|
|
393
|
+
return ret === 0x100000001 ? undefined : ret;
|
|
394
|
+
}
|
|
325
395
|
/**
|
|
326
396
|
* Get the unsigned transaction ID
|
|
327
397
|
* @returns {string}
|
|
@@ -377,6 +447,106 @@ class BitGoPsbt {
|
|
|
377
447
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
378
448
|
}
|
|
379
449
|
}
|
|
450
|
+
/**
|
|
451
|
+
* Add a wallet input with full PSBT metadata
|
|
452
|
+
*
|
|
453
|
+
* This is a higher-level method that adds an input and populates all required
|
|
454
|
+
* PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
|
|
455
|
+
*
|
|
456
|
+
* # Arguments
|
|
457
|
+
* * `txid` - The transaction ID (hex string)
|
|
458
|
+
* * `vout` - The output index being spent
|
|
459
|
+
* * `value` - The value in satoshis
|
|
460
|
+
* * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
|
|
461
|
+
* * `index` - The derivation index
|
|
462
|
+
* * `wallet_keys` - The root wallet keys
|
|
463
|
+
* * `signer` - The key that will sign ("user", "backup", or "bitgo") - required for p2tr/p2trMusig2
|
|
464
|
+
* * `cosigner` - The key that will co-sign - required for p2tr/p2trMusig2
|
|
465
|
+
* * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
|
|
466
|
+
* * `prev_tx` - Optional full previous transaction bytes (for non-segwit)
|
|
467
|
+
*
|
|
468
|
+
* # Returns
|
|
469
|
+
* The index of the newly added input
|
|
470
|
+
* @param {string} txid
|
|
471
|
+
* @param {number} vout
|
|
472
|
+
* @param {bigint} value
|
|
473
|
+
* @param {WasmRootWalletKeys} wallet_keys
|
|
474
|
+
* @param {number} chain
|
|
475
|
+
* @param {number} index
|
|
476
|
+
* @param {string | null} [signer]
|
|
477
|
+
* @param {string | null} [cosigner]
|
|
478
|
+
* @param {number | null} [sequence]
|
|
479
|
+
* @param {Uint8Array | null} [prev_tx]
|
|
480
|
+
* @returns {number}
|
|
481
|
+
*/
|
|
482
|
+
add_wallet_input(txid, vout, value, wallet_keys, chain, index, signer, cosigner, sequence, prev_tx) {
|
|
483
|
+
try {
|
|
484
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
485
|
+
const ptr0 = passStringToWasm0(txid, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
486
|
+
const len0 = WASM_VECTOR_LEN;
|
|
487
|
+
_assertClass(wallet_keys, WasmRootWalletKeys);
|
|
488
|
+
var ptr1 = isLikeNone(signer) ? 0 : passStringToWasm0(signer, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
489
|
+
var len1 = WASM_VECTOR_LEN;
|
|
490
|
+
var ptr2 = isLikeNone(cosigner) ? 0 : passStringToWasm0(cosigner, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
491
|
+
var len2 = WASM_VECTOR_LEN;
|
|
492
|
+
var ptr3 = isLikeNone(prev_tx) ? 0 : passArray8ToWasm0(prev_tx, wasm.__wbindgen_export);
|
|
493
|
+
var len3 = WASM_VECTOR_LEN;
|
|
494
|
+
wasm.bitgopsbt_add_wallet_input(retptr, this.__wbg_ptr, ptr0, len0, vout, value, wallet_keys.__wbg_ptr, chain, index, ptr1, len1, ptr2, len2, isLikeNone(sequence) ? 0x100000001 : (sequence) >>> 0, ptr3, len3);
|
|
495
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
496
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
497
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
498
|
+
if (r2) {
|
|
499
|
+
throw takeObject(r1);
|
|
500
|
+
}
|
|
501
|
+
return r0 >>> 0;
|
|
502
|
+
} finally {
|
|
503
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Get the Zcash version group ID (returns None for non-Zcash PSBTs)
|
|
508
|
+
* @returns {number | undefined}
|
|
509
|
+
*/
|
|
510
|
+
version_group_id() {
|
|
511
|
+
const ret = wasm.bitgopsbt_version_group_id(this.__wbg_ptr);
|
|
512
|
+
return ret === 0x100000001 ? undefined : ret;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Add a wallet output with full PSBT metadata
|
|
516
|
+
*
|
|
517
|
+
* This creates a verifiable wallet output (typically for change) with all required
|
|
518
|
+
* PSBT fields (scripts, derivation info) based on the wallet's chain type.
|
|
519
|
+
*
|
|
520
|
+
* # Arguments
|
|
521
|
+
* * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
|
|
522
|
+
* * `index` - The derivation index
|
|
523
|
+
* * `value` - The value in satoshis
|
|
524
|
+
* * `wallet_keys` - The root wallet keys
|
|
525
|
+
*
|
|
526
|
+
* # Returns
|
|
527
|
+
* The index of the newly added output
|
|
528
|
+
* @param {number} chain
|
|
529
|
+
* @param {number} index
|
|
530
|
+
* @param {bigint} value
|
|
531
|
+
* @param {WasmRootWalletKeys} wallet_keys
|
|
532
|
+
* @returns {number}
|
|
533
|
+
*/
|
|
534
|
+
add_wallet_output(chain, index, value, wallet_keys) {
|
|
535
|
+
try {
|
|
536
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
537
|
+
_assertClass(wallet_keys, WasmRootWalletKeys);
|
|
538
|
+
wasm.bitgopsbt_add_wallet_output(retptr, this.__wbg_ptr, chain, index, value, wallet_keys.__wbg_ptr);
|
|
539
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
540
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
541
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
542
|
+
if (r2) {
|
|
543
|
+
throw takeObject(r1);
|
|
544
|
+
}
|
|
545
|
+
return r0 >>> 0;
|
|
546
|
+
} finally {
|
|
547
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
380
550
|
/**
|
|
381
551
|
* Sign a single input with a raw private key
|
|
382
552
|
*
|
|
@@ -412,6 +582,47 @@ class BitGoPsbt {
|
|
|
412
582
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
413
583
|
}
|
|
414
584
|
}
|
|
585
|
+
/**
|
|
586
|
+
* Create an empty Zcash PSBT with the required consensus branch ID
|
|
587
|
+
*
|
|
588
|
+
* This method is specifically for Zcash networks which require additional
|
|
589
|
+
* parameters for sighash computation.
|
|
590
|
+
*
|
|
591
|
+
* # Arguments
|
|
592
|
+
* * `network` - Network name (must be "zcash" or "zcashTest")
|
|
593
|
+
* * `wallet_keys` - The wallet's root keys (used to set global xpubs)
|
|
594
|
+
* * `consensus_branch_id` - Zcash consensus branch ID (e.g., 0xC2D6D0B4 for NU5)
|
|
595
|
+
* * `version` - Optional transaction version (default: 4 for Zcash Sapling+)
|
|
596
|
+
* * `lock_time` - Optional lock time (default: 0)
|
|
597
|
+
* * `version_group_id` - Optional version group ID (defaults to Sapling: 0x892F2085)
|
|
598
|
+
* * `expiry_height` - Optional expiry height
|
|
599
|
+
* @param {string} network
|
|
600
|
+
* @param {WasmRootWalletKeys} wallet_keys
|
|
601
|
+
* @param {number} consensus_branch_id
|
|
602
|
+
* @param {number | null} [version]
|
|
603
|
+
* @param {number | null} [lock_time]
|
|
604
|
+
* @param {number | null} [version_group_id]
|
|
605
|
+
* @param {number | null} [expiry_height]
|
|
606
|
+
* @returns {BitGoPsbt}
|
|
607
|
+
*/
|
|
608
|
+
static create_empty_zcash(network, wallet_keys, consensus_branch_id, version, lock_time, version_group_id, expiry_height) {
|
|
609
|
+
try {
|
|
610
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
611
|
+
const ptr0 = passStringToWasm0(network, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
612
|
+
const len0 = WASM_VECTOR_LEN;
|
|
613
|
+
_assertClass(wallet_keys, WasmRootWalletKeys);
|
|
614
|
+
wasm.bitgopsbt_create_empty_zcash(retptr, ptr0, len0, wallet_keys.__wbg_ptr, consensus_branch_id, isLikeNone(version) ? 0x100000001 : (version) >> 0, isLikeNone(lock_time) ? 0x100000001 : (lock_time) >>> 0, isLikeNone(version_group_id) ? 0x100000001 : (version_group_id) >>> 0, isLikeNone(expiry_height) ? 0x100000001 : (expiry_height) >>> 0);
|
|
615
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
616
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
617
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
618
|
+
if (r2) {
|
|
619
|
+
throw takeObject(r1);
|
|
620
|
+
}
|
|
621
|
+
return BitGoPsbt.__wrap(r0);
|
|
622
|
+
} finally {
|
|
623
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
415
626
|
/**
|
|
416
627
|
* Extract the final transaction from a finalized PSBT
|
|
417
628
|
*
|
|
@@ -648,6 +859,90 @@ class BitGoPsbt {
|
|
|
648
859
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
649
860
|
}
|
|
650
861
|
}
|
|
862
|
+
/**
|
|
863
|
+
* Add a replay protection input to the PSBT
|
|
864
|
+
*
|
|
865
|
+
* Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
|
|
866
|
+
* transaction replay attacks. They use a simple pubkey script without wallet derivation.
|
|
867
|
+
*
|
|
868
|
+
* # Arguments
|
|
869
|
+
* * `ecpair` - The ECPair containing the public key for the replay protection input
|
|
870
|
+
* * `txid` - The transaction ID (hex string) of the output being spent
|
|
871
|
+
* * `vout` - The output index being spent
|
|
872
|
+
* * `value` - The value in satoshis
|
|
873
|
+
* * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
|
|
874
|
+
*
|
|
875
|
+
* # Returns
|
|
876
|
+
* The index of the newly added input
|
|
877
|
+
* @param {WasmECPair} ecpair
|
|
878
|
+
* @param {string} txid
|
|
879
|
+
* @param {number} vout
|
|
880
|
+
* @param {bigint} value
|
|
881
|
+
* @param {number | null} [sequence]
|
|
882
|
+
* @returns {number}
|
|
883
|
+
*/
|
|
884
|
+
add_replay_protection_input(ecpair, txid, vout, value, sequence) {
|
|
885
|
+
try {
|
|
886
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
887
|
+
_assertClass(ecpair, WasmECPair);
|
|
888
|
+
const ptr0 = passStringToWasm0(txid, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
889
|
+
const len0 = WASM_VECTOR_LEN;
|
|
890
|
+
wasm.bitgopsbt_add_replay_protection_input(retptr, this.__wbg_ptr, ecpair.__wbg_ptr, ptr0, len0, vout, value, isLikeNone(sequence) ? 0x100000001 : (sequence) >>> 0);
|
|
891
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
892
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
893
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
894
|
+
if (r2) {
|
|
895
|
+
throw takeObject(r1);
|
|
896
|
+
}
|
|
897
|
+
return r0 >>> 0;
|
|
898
|
+
} finally {
|
|
899
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Create an empty Zcash PSBT with consensus branch ID determined from block height
|
|
904
|
+
*
|
|
905
|
+
* This method automatically determines the correct consensus branch ID based on
|
|
906
|
+
* the network and block height using the network upgrade activation heights.
|
|
907
|
+
*
|
|
908
|
+
* # Arguments
|
|
909
|
+
* * `network` - Network name (must be "zcash" or "zcashTest")
|
|
910
|
+
* * `wallet_keys` - The wallet's root keys (used to set global xpubs)
|
|
911
|
+
* * `block_height` - Block height to determine consensus rules
|
|
912
|
+
* * `version` - Optional transaction version (default: 4 for Zcash Sapling+)
|
|
913
|
+
* * `lock_time` - Optional lock time (default: 0)
|
|
914
|
+
* * `version_group_id` - Optional version group ID (defaults to Sapling: 0x892F2085)
|
|
915
|
+
* * `expiry_height` - Optional expiry height
|
|
916
|
+
*
|
|
917
|
+
* # Errors
|
|
918
|
+
* Returns error if block height is before Overwinter activation
|
|
919
|
+
* @param {string} network
|
|
920
|
+
* @param {WasmRootWalletKeys} wallet_keys
|
|
921
|
+
* @param {number} block_height
|
|
922
|
+
* @param {number | null} [version]
|
|
923
|
+
* @param {number | null} [lock_time]
|
|
924
|
+
* @param {number | null} [version_group_id]
|
|
925
|
+
* @param {number | null} [expiry_height]
|
|
926
|
+
* @returns {BitGoPsbt}
|
|
927
|
+
*/
|
|
928
|
+
static create_empty_zcash_at_height(network, wallet_keys, block_height, version, lock_time, version_group_id, expiry_height) {
|
|
929
|
+
try {
|
|
930
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
931
|
+
const ptr0 = passStringToWasm0(network, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
932
|
+
const len0 = WASM_VECTOR_LEN;
|
|
933
|
+
_assertClass(wallet_keys, WasmRootWalletKeys);
|
|
934
|
+
wasm.bitgopsbt_create_empty_zcash_at_height(retptr, ptr0, len0, wallet_keys.__wbg_ptr, block_height, isLikeNone(version) ? 0x100000001 : (version) >> 0, isLikeNone(lock_time) ? 0x100000001 : (lock_time) >>> 0, isLikeNone(version_group_id) ? 0x100000001 : (version_group_id) >>> 0, isLikeNone(expiry_height) ? 0x100000001 : (expiry_height) >>> 0);
|
|
935
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
936
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
937
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
938
|
+
if (r2) {
|
|
939
|
+
throw takeObject(r1);
|
|
940
|
+
}
|
|
941
|
+
return BitGoPsbt.__wrap(r0);
|
|
942
|
+
} finally {
|
|
943
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
651
946
|
/**
|
|
652
947
|
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
653
948
|
*
|
|
@@ -756,6 +1051,63 @@ class BitGoPsbt {
|
|
|
756
1051
|
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
757
1052
|
}
|
|
758
1053
|
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Get the transaction version
|
|
1056
|
+
* @returns {number}
|
|
1057
|
+
*/
|
|
1058
|
+
version() {
|
|
1059
|
+
const ret = wasm.bitgopsbt_version(this.__wbg_ptr);
|
|
1060
|
+
return ret;
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Add an input to the PSBT
|
|
1064
|
+
*
|
|
1065
|
+
* # Arguments
|
|
1066
|
+
* * `txid` - The transaction ID (hex string) of the output being spent
|
|
1067
|
+
* * `vout` - The output index being spent
|
|
1068
|
+
* * `value` - The value in satoshis of the output being spent
|
|
1069
|
+
* * `script` - The output script (scriptPubKey) of the output being spent
|
|
1070
|
+
* * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
|
|
1071
|
+
*
|
|
1072
|
+
* # Returns
|
|
1073
|
+
* The index of the newly added input
|
|
1074
|
+
* @param {string} txid
|
|
1075
|
+
* @param {number} vout
|
|
1076
|
+
* @param {bigint} value
|
|
1077
|
+
* @param {Uint8Array} script
|
|
1078
|
+
* @param {number | null} [sequence]
|
|
1079
|
+
* @param {Uint8Array | null} [prev_tx]
|
|
1080
|
+
* @returns {number}
|
|
1081
|
+
*/
|
|
1082
|
+
add_input(txid, vout, value, script, sequence, prev_tx) {
|
|
1083
|
+
try {
|
|
1084
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1085
|
+
const ptr0 = passStringToWasm0(txid, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1086
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1087
|
+
const ptr1 = passArray8ToWasm0(script, wasm.__wbindgen_export);
|
|
1088
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1089
|
+
var ptr2 = isLikeNone(prev_tx) ? 0 : passArray8ToWasm0(prev_tx, wasm.__wbindgen_export);
|
|
1090
|
+
var len2 = WASM_VECTOR_LEN;
|
|
1091
|
+
wasm.bitgopsbt_add_input(retptr, this.__wbg_ptr, ptr0, len0, vout, value, ptr1, len1, isLikeNone(sequence) ? 0x100000001 : (sequence) >>> 0, ptr2, len2);
|
|
1092
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1093
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1094
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1095
|
+
if (r2) {
|
|
1096
|
+
throw takeObject(r1);
|
|
1097
|
+
}
|
|
1098
|
+
return r0 >>> 0;
|
|
1099
|
+
} finally {
|
|
1100
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* Get the transaction lock time
|
|
1105
|
+
* @returns {number}
|
|
1106
|
+
*/
|
|
1107
|
+
lock_time() {
|
|
1108
|
+
const ret = wasm.bitgopsbt_lock_time(this.__wbg_ptr);
|
|
1109
|
+
return ret >>> 0;
|
|
1110
|
+
}
|
|
759
1111
|
/**
|
|
760
1112
|
* Serialize the PSBT to bytes
|
|
761
1113
|
*
|
|
Binary file
|