@bitgo/wasm-utxo 1.27.0 → 1.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/js/bip32.d.ts +7 -0
- package/dist/cjs/js/bip32.js +16 -0
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +60 -26
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +56 -36
- package/dist/cjs/js/fixedScriptWallet/chains.d.ts +5 -0
- package/dist/cjs/js/fixedScriptWallet/chains.js +6 -2
- package/dist/cjs/js/fixedScriptWallet/index.d.ts +19 -2
- package/dist/cjs/js/fixedScriptWallet/index.js +25 -1
- package/dist/cjs/js/fixedScriptWallet/scriptType.d.ts +15 -5
- package/dist/cjs/js/fixedScriptWallet/scriptType.js +28 -0
- package/dist/cjs/js/testutils/AcidTest.d.ts +132 -0
- package/dist/cjs/js/testutils/AcidTest.js +306 -0
- package/dist/cjs/js/testutils/index.d.ts +2 -0
- package/dist/cjs/js/testutils/index.js +18 -0
- package/dist/cjs/js/testutils/keys.d.ts +76 -0
- package/dist/cjs/js/testutils/keys.js +154 -0
- package/dist/cjs/js/wasm/wasm_utxo.d.ts +183 -0
- package/dist/cjs/js/wasm/wasm_utxo.js +354 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +67 -56
- package/dist/esm/js/bip32.d.ts +7 -0
- package/dist/esm/js/bip32.js +15 -0
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +60 -26
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +57 -37
- package/dist/esm/js/fixedScriptWallet/chains.d.ts +5 -0
- package/dist/esm/js/fixedScriptWallet/chains.js +6 -3
- package/dist/esm/js/fixedScriptWallet/index.d.ts +19 -2
- package/dist/esm/js/fixedScriptWallet/index.js +21 -1
- package/dist/esm/js/fixedScriptWallet/scriptType.d.ts +15 -5
- package/dist/esm/js/fixedScriptWallet/scriptType.js +27 -1
- package/dist/esm/js/testutils/AcidTest.d.ts +132 -0
- package/dist/esm/js/testutils/AcidTest.js +302 -0
- package/dist/esm/js/testutils/index.d.ts +2 -0
- package/dist/esm/js/testutils/index.js +2 -0
- package/dist/esm/js/testutils/keys.d.ts +76 -0
- package/dist/esm/js/testutils/keys.js +113 -0
- package/dist/esm/js/wasm/wasm_utxo.d.ts +183 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.js +354 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +67 -56
- package/package.json +2 -1
package/dist/cjs/js/bip32.d.ts
CHANGED
|
@@ -138,3 +138,10 @@ export declare class BIP32 implements BIP32Interface {
|
|
|
138
138
|
*/
|
|
139
139
|
get wasm(): WasmBIP32;
|
|
140
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Type guard to check if a value is a BIP32Arg
|
|
143
|
+
*
|
|
144
|
+
* @param key - The value to check
|
|
145
|
+
* @returns true if the value is a BIP32Arg (string, BIP32, WasmBIP32, or BIP32Interface)
|
|
146
|
+
*/
|
|
147
|
+
export declare function isBIP32Arg(key: unknown): key is BIP32Arg;
|
package/dist/cjs/js/bip32.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BIP32 = void 0;
|
|
4
|
+
exports.isBIP32Arg = isBIP32Arg;
|
|
4
5
|
const wasm_utxo_js_1 = require("./wasm/wasm_utxo.js");
|
|
5
6
|
/**
|
|
6
7
|
* BIP32 wrapper class for extended key operations
|
|
@@ -175,3 +176,18 @@ class BIP32 {
|
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
exports.BIP32 = BIP32;
|
|
179
|
+
/**
|
|
180
|
+
* Type guard to check if a value is a BIP32Arg
|
|
181
|
+
*
|
|
182
|
+
* @param key - The value to check
|
|
183
|
+
* @returns true if the value is a BIP32Arg (string, BIP32, WasmBIP32, or BIP32Interface)
|
|
184
|
+
*/
|
|
185
|
+
function isBIP32Arg(key) {
|
|
186
|
+
return (typeof key === "string" ||
|
|
187
|
+
key instanceof BIP32 ||
|
|
188
|
+
key instanceof wasm_utxo_js_1.WasmBIP32 ||
|
|
189
|
+
(typeof key === "object" &&
|
|
190
|
+
key !== null &&
|
|
191
|
+
"derive" in key &&
|
|
192
|
+
typeof key.derive === "function"));
|
|
193
|
+
}
|
|
@@ -371,16 +371,63 @@ export declare class BitGoPsbt {
|
|
|
371
371
|
*/
|
|
372
372
|
verifySignature(inputIndex: number, key: BIP32Arg | ECPairArg): boolean;
|
|
373
373
|
/**
|
|
374
|
-
* Sign
|
|
374
|
+
* Sign all matching inputs with a private key.
|
|
375
|
+
*
|
|
376
|
+
* This method signs all inputs that match the provided key in a single efficient pass.
|
|
377
|
+
* It accepts either:
|
|
378
|
+
* - An xpriv (BIP32Arg: base58 string, BIP32 instance, or WasmBIP32) for wallet inputs
|
|
379
|
+
* - A raw privkey (ECPairArg: Buffer, ECPair instance, or WasmECPair) for replay protection inputs
|
|
380
|
+
*
|
|
381
|
+
* **Note:** MuSig2 inputs are skipped by this method when using xpriv because they require
|
|
382
|
+
* FirstRound state. After calling this method, sign MuSig2 inputs individually using
|
|
383
|
+
* `signInput()` after calling `generateMusig2Nonces()`.
|
|
384
|
+
*
|
|
385
|
+
* @param key - Either an xpriv (BIP32Arg) or a raw privkey (ECPairArg)
|
|
386
|
+
* @returns Array of input indices that were signed
|
|
387
|
+
* @throws Error if signing fails
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```typescript
|
|
391
|
+
* // Sign all wallet inputs with user's xpriv
|
|
392
|
+
* const signedIndices = psbt.sign(userXpriv);
|
|
393
|
+
* console.log(`Signed inputs: ${signedIndices.join(", ")}`);
|
|
394
|
+
*
|
|
395
|
+
* // Sign all replay protection inputs with raw privkey
|
|
396
|
+
* const rpSignedIndices = psbt.sign(replayProtectionPrivkey);
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
sign(key: BIP32Arg | ECPairArg): number[];
|
|
400
|
+
/**
|
|
401
|
+
* Sign a single input with a private key.
|
|
402
|
+
*
|
|
403
|
+
* @deprecated Use `sign(key)` to sign all matching inputs (more efficient), or use
|
|
404
|
+
* `signInput(inputIndex, key)` for explicit single-input signing.
|
|
405
|
+
*
|
|
406
|
+
* **Note:** This method is NOT more efficient than `sign(key)` for non-MuSig2 inputs.
|
|
407
|
+
* The underlying miniscript library signs all inputs regardless. This overload exists
|
|
408
|
+
* for backward compatibility only.
|
|
409
|
+
*
|
|
410
|
+
* @param inputIndex - The index of the input to sign (0-based)
|
|
411
|
+
* @param key - Either an xpriv (BIP32Arg) or a raw privkey (ECPairArg)
|
|
412
|
+
* @throws Error if signing fails, or if generateMusig2Nonces() was not called first for MuSig2 inputs
|
|
413
|
+
*/
|
|
414
|
+
sign(inputIndex: number, key: BIP32Arg | ECPairArg): void;
|
|
415
|
+
/**
|
|
416
|
+
* Sign a single input with a private key.
|
|
375
417
|
*
|
|
376
418
|
* This method signs a specific input using the provided key. It accepts either:
|
|
377
|
-
* - An xpriv (BIP32Arg: base58 string, BIP32 instance, or WasmBIP32) for wallet inputs
|
|
378
|
-
* - A raw privkey (ECPairArg: Buffer, ECPair instance, or WasmECPair) for replay protection inputs
|
|
419
|
+
* - An xpriv (BIP32Arg: base58 string, BIP32 instance, or WasmBIP32) for wallet inputs
|
|
420
|
+
* - A raw privkey (ECPairArg: Buffer, ECPair instance, or WasmECPair) for replay protection inputs
|
|
379
421
|
*
|
|
380
|
-
* This method
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
422
|
+
* **Important:** This method is NOT faster than `sign(key)` for non-MuSig2 inputs.
|
|
423
|
+
* The underlying miniscript library signs all inputs regardless. This method uses a
|
|
424
|
+
* save/restore pattern to ensure only the target input receives the signature.
|
|
425
|
+
*
|
|
426
|
+
* Use this method only when you need precise control over which inputs are signed,
|
|
427
|
+
* for example:
|
|
428
|
+
* - Signing MuSig2 inputs (after calling generateMusig2Nonces())
|
|
429
|
+
* - Mixed transactions where different inputs need different keys
|
|
430
|
+
* - Testing or debugging signing behavior
|
|
384
431
|
*
|
|
385
432
|
* @param inputIndex - The index of the input to sign (0-based)
|
|
386
433
|
* @param key - Either an xpriv (BIP32Arg) or a raw privkey (ECPairArg)
|
|
@@ -388,28 +435,15 @@ export declare class BitGoPsbt {
|
|
|
388
435
|
*
|
|
389
436
|
* @example
|
|
390
437
|
* ```typescript
|
|
391
|
-
* //
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
* // Sign regular wallet inputs with xpriv
|
|
395
|
-
* for (let i = 0; i < parsed.inputs.length; i++) {
|
|
396
|
-
* const input = parsed.inputs[i];
|
|
397
|
-
* if (input.scriptId !== null && input.scriptType !== "p2shP2pk") {
|
|
398
|
-
* psbt.sign(i, userXpriv);
|
|
399
|
-
* }
|
|
400
|
-
* }
|
|
438
|
+
* // Sign a specific MuSig2 input after nonce generation
|
|
439
|
+
* psbt.generateMusig2Nonces(userXpriv);
|
|
440
|
+
* psbt.signInput(musig2InputIndex, userXpriv);
|
|
401
441
|
*
|
|
402
|
-
* // Sign replay protection
|
|
403
|
-
*
|
|
404
|
-
* for (let i = 0; i < parsed.inputs.length; i++) {
|
|
405
|
-
* const input = parsed.inputs[i];
|
|
406
|
-
* if (input.scriptType === "p2shP2pk") {
|
|
407
|
-
* psbt.sign(i, userPrivkey);
|
|
408
|
-
* }
|
|
409
|
-
* }
|
|
442
|
+
* // Sign a specific replay protection input
|
|
443
|
+
* psbt.signInput(rpInputIndex, replayProtectionPrivkey);
|
|
410
444
|
* ```
|
|
411
445
|
*/
|
|
412
|
-
|
|
446
|
+
signInput(inputIndex: number, key: BIP32Arg | ECPairArg): void;
|
|
413
447
|
/**
|
|
414
448
|
* @deprecated - use verifySignature with the replay protection key instead
|
|
415
449
|
*
|
|
@@ -306,17 +306,49 @@ class BitGoPsbt {
|
|
|
306
306
|
const wasmECPair = ecpair_js_1.ECPair.from(key).wasm;
|
|
307
307
|
return this._wasm.verify_signature_with_pub(inputIndex, wasmECPair);
|
|
308
308
|
}
|
|
309
|
+
sign(inputIndexOrKey, key) {
|
|
310
|
+
// Detect which overload was called
|
|
311
|
+
if (typeof inputIndexOrKey === "number") {
|
|
312
|
+
// Called as sign(inputIndex, key) - deprecated single-input signing
|
|
313
|
+
if (key === undefined) {
|
|
314
|
+
throw new Error("Key is required when signing a single input");
|
|
315
|
+
}
|
|
316
|
+
this.signInput(inputIndexOrKey, key);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
// Called as sign(key) - sign all matching inputs
|
|
320
|
+
const keyArg = inputIndexOrKey;
|
|
321
|
+
if ((0, bip32_js_1.isBIP32Arg)(keyArg)) {
|
|
322
|
+
// It's a BIP32Arg - sign all wallet inputs (ECDSA + MuSig2)
|
|
323
|
+
const wasmKey = bip32_js_1.BIP32.from(keyArg);
|
|
324
|
+
// Sign all non-MuSig2 wallet inputs
|
|
325
|
+
const walletSigned = this._wasm.sign_all_wallet_inputs(wasmKey.wasm);
|
|
326
|
+
// Sign all MuSig2 keypath inputs (more efficient - reuses SighashCache)
|
|
327
|
+
const musig2Signed = this._wasm.sign_all_musig2_inputs(wasmKey.wasm);
|
|
328
|
+
return [...walletSigned, ...musig2Signed];
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
// It's an ECPairArg - sign all replay protection inputs
|
|
332
|
+
const wasmKey = ecpair_js_1.ECPair.from(keyArg);
|
|
333
|
+
return this._wasm.sign_replay_protection_inputs(wasmKey.wasm);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
309
336
|
/**
|
|
310
|
-
* Sign a single input with a private key
|
|
337
|
+
* Sign a single input with a private key.
|
|
311
338
|
*
|
|
312
339
|
* This method signs a specific input using the provided key. It accepts either:
|
|
313
|
-
* - An xpriv (BIP32Arg: base58 string, BIP32 instance, or WasmBIP32) for wallet inputs
|
|
314
|
-
* - A raw privkey (ECPairArg: Buffer, ECPair instance, or WasmECPair) for replay protection inputs
|
|
340
|
+
* - An xpriv (BIP32Arg: base58 string, BIP32 instance, or WasmBIP32) for wallet inputs
|
|
341
|
+
* - A raw privkey (ECPairArg: Buffer, ECPair instance, or WasmECPair) for replay protection inputs
|
|
342
|
+
*
|
|
343
|
+
* **Important:** This method is NOT faster than `sign(key)` for non-MuSig2 inputs.
|
|
344
|
+
* The underlying miniscript library signs all inputs regardless. This method uses a
|
|
345
|
+
* save/restore pattern to ensure only the target input receives the signature.
|
|
315
346
|
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
* -
|
|
319
|
-
* -
|
|
347
|
+
* Use this method only when you need precise control over which inputs are signed,
|
|
348
|
+
* for example:
|
|
349
|
+
* - Signing MuSig2 inputs (after calling generateMusig2Nonces())
|
|
350
|
+
* - Mixed transactions where different inputs need different keys
|
|
351
|
+
* - Testing or debugging signing behavior
|
|
320
352
|
*
|
|
321
353
|
* @param inputIndex - The index of the input to sign (0-based)
|
|
322
354
|
* @param key - Either an xpriv (BIP32Arg) or a raw privkey (ECPairArg)
|
|
@@ -324,42 +356,30 @@ class BitGoPsbt {
|
|
|
324
356
|
*
|
|
325
357
|
* @example
|
|
326
358
|
* ```typescript
|
|
327
|
-
* //
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
* // Sign regular wallet inputs with xpriv
|
|
331
|
-
* for (let i = 0; i < parsed.inputs.length; i++) {
|
|
332
|
-
* const input = parsed.inputs[i];
|
|
333
|
-
* if (input.scriptId !== null && input.scriptType !== "p2shP2pk") {
|
|
334
|
-
* psbt.sign(i, userXpriv);
|
|
335
|
-
* }
|
|
336
|
-
* }
|
|
359
|
+
* // Sign a specific MuSig2 input after nonce generation
|
|
360
|
+
* psbt.generateMusig2Nonces(userXpriv);
|
|
361
|
+
* psbt.signInput(musig2InputIndex, userXpriv);
|
|
337
362
|
*
|
|
338
|
-
* // Sign replay protection
|
|
339
|
-
*
|
|
340
|
-
* for (let i = 0; i < parsed.inputs.length; i++) {
|
|
341
|
-
* const input = parsed.inputs[i];
|
|
342
|
-
* if (input.scriptType === "p2shP2pk") {
|
|
343
|
-
* psbt.sign(i, userPrivkey);
|
|
344
|
-
* }
|
|
345
|
-
* }
|
|
363
|
+
* // Sign a specific replay protection input
|
|
364
|
+
* psbt.signInput(rpInputIndex, replayProtectionPrivkey);
|
|
346
365
|
* ```
|
|
347
366
|
*/
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
// If string or has 'derive' method → BIP32Arg
|
|
351
|
-
// Otherwise → ECPairArg
|
|
352
|
-
if (typeof key === "string" ||
|
|
353
|
-
(typeof key === "object" &&
|
|
354
|
-
key !== null &&
|
|
355
|
-
"derive" in key &&
|
|
356
|
-
typeof key.derive === "function")) {
|
|
367
|
+
signInput(inputIndex, key) {
|
|
368
|
+
if ((0, bip32_js_1.isBIP32Arg)(key)) {
|
|
357
369
|
// It's a BIP32Arg
|
|
358
370
|
const wasmKey = bip32_js_1.BIP32.from(key);
|
|
359
|
-
|
|
371
|
+
// Route to the appropriate method based on input type
|
|
372
|
+
if (this._wasm.is_musig2_input(inputIndex)) {
|
|
373
|
+
// MuSig2 keypath: true single-input signing (efficient)
|
|
374
|
+
this._wasm.sign_musig2_input(inputIndex, wasmKey.wasm);
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
// ECDSA/Schnorr script path: save/restore pattern (not faster than bulk)
|
|
378
|
+
this._wasm.sign_wallet_input(inputIndex, wasmKey.wasm);
|
|
379
|
+
}
|
|
360
380
|
}
|
|
361
381
|
else {
|
|
362
|
-
// It's an ECPairArg
|
|
382
|
+
// It's an ECPairArg - for replay protection inputs
|
|
363
383
|
const wasmKey = ecpair_js_1.ECPair.from(key);
|
|
364
384
|
this._wasm.sign_with_privkey(inputIndex, wasmKey.wasm);
|
|
365
385
|
}
|
|
@@ -5,6 +5,11 @@ export declare const chainCodes: readonly [0, 1, 10, 11, 20, 21, 30, 31, 40, 41]
|
|
|
5
5
|
export type ChainCode = (typeof chainCodes)[number];
|
|
6
6
|
/** Whether a chain is for receiving (external) or change (internal) addresses */
|
|
7
7
|
export type Scope = "internal" | "external";
|
|
8
|
+
/**
|
|
9
|
+
* Assert that a number is a valid chain code.
|
|
10
|
+
* @throws Error if the number is not a valid chain code
|
|
11
|
+
*/
|
|
12
|
+
export declare function assertChainCode(n: number): ChainCode;
|
|
8
13
|
/**
|
|
9
14
|
* ChainCode namespace with utility functions for working with chain codes.
|
|
10
15
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ChainCode = exports.chainCodes = void 0;
|
|
4
|
+
exports.assertChainCode = assertChainCode;
|
|
4
5
|
/**
|
|
5
6
|
* Chain code utilities for BitGo fixed-script wallets.
|
|
6
7
|
*
|
|
@@ -14,10 +15,13 @@ exports.chainCodes = [0, 1, 10, 11, 20, 21, 30, 31, 40, 41];
|
|
|
14
15
|
const chainCodeSet = new Set(exports.chainCodes);
|
|
15
16
|
const chainToMeta = new Map();
|
|
16
17
|
const scriptTypeToChain = new Map();
|
|
17
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Assert that a number is a valid chain code.
|
|
20
|
+
* @throws Error if the number is not a valid chain code
|
|
21
|
+
*/
|
|
18
22
|
function assertChainCode(n) {
|
|
19
23
|
if (!chainCodeSet.has(n)) {
|
|
20
|
-
throw new Error(`Invalid chain code
|
|
24
|
+
throw new Error(`Invalid chain code: ${n}`);
|
|
21
25
|
}
|
|
22
26
|
return n;
|
|
23
27
|
}
|
|
@@ -3,8 +3,8 @@ export { RootWalletKeys, type WalletKeysArg, type IWalletKeys } from "./RootWall
|
|
|
3
3
|
export { ReplayProtection, type ReplayProtectionArg } from "./ReplayProtection.js";
|
|
4
4
|
export { outputScript, address } from "./address.js";
|
|
5
5
|
export { Dimensions } from "./Dimensions.js";
|
|
6
|
-
export { type OutputScriptType, type InputScriptType, type ScriptType } from "./scriptType.js";
|
|
7
|
-
export { ChainCode, chainCodes, type Scope } from "./chains.js";
|
|
6
|
+
export { outputScriptTypes, inputScriptTypes, type OutputScriptType, type InputScriptType, type ScriptType, } from "./scriptType.js";
|
|
7
|
+
export { ChainCode, chainCodes, assertChainCode, type Scope } from "./chains.js";
|
|
8
8
|
export { BitGoPsbt, type NetworkName, type ScriptId, type ParsedInput, type ParsedOutput, type ParsedTransaction, type SignPath, type CreateEmptyOptions, type AddInputOptions, type AddOutputOptions, type AddWalletInputOptions, type AddWalletOutputOptions, } from "./BitGoPsbt.js";
|
|
9
9
|
export { ZcashBitGoPsbt, type ZcashNetworkName, type CreateEmptyZcashOptions, } from "./ZcashBitGoPsbt.js";
|
|
10
10
|
import type { ScriptType } from "./scriptType.js";
|
|
@@ -34,3 +34,20 @@ import type { ScriptType } from "./scriptType.js";
|
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
36
|
export declare function supportsScriptType(coin: CoinName, scriptType: ScriptType): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Create an OP_RETURN output script with optional data
|
|
39
|
+
*
|
|
40
|
+
* @param data - Optional data bytes to include in the OP_RETURN script
|
|
41
|
+
* @returns The OP_RETURN script as a Uint8Array
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // Empty OP_RETURN
|
|
46
|
+
* const script = createOpReturnScript();
|
|
47
|
+
*
|
|
48
|
+
* // OP_RETURN with data
|
|
49
|
+
* const data = new Uint8Array([1, 2, 3, 4]);
|
|
50
|
+
* const script = createOpReturnScript(data);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function createOpReturnScript(data?: Uint8Array): Uint8Array;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ZcashBitGoPsbt = exports.BitGoPsbt = exports.chainCodes = exports.ChainCode = exports.Dimensions = exports.address = exports.outputScript = exports.ReplayProtection = exports.RootWalletKeys = void 0;
|
|
3
|
+
exports.ZcashBitGoPsbt = exports.BitGoPsbt = exports.assertChainCode = exports.chainCodes = exports.ChainCode = exports.inputScriptTypes = exports.outputScriptTypes = exports.Dimensions = exports.address = exports.outputScript = exports.ReplayProtection = exports.RootWalletKeys = void 0;
|
|
4
4
|
exports.supportsScriptType = supportsScriptType;
|
|
5
|
+
exports.createOpReturnScript = createOpReturnScript;
|
|
5
6
|
const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
|
|
6
7
|
var RootWalletKeys_js_1 = require("./RootWalletKeys.js");
|
|
7
8
|
Object.defineProperty(exports, "RootWalletKeys", { enumerable: true, get: function () { return RootWalletKeys_js_1.RootWalletKeys; } });
|
|
@@ -12,9 +13,13 @@ Object.defineProperty(exports, "outputScript", { enumerable: true, get: function
|
|
|
12
13
|
Object.defineProperty(exports, "address", { enumerable: true, get: function () { return address_js_1.address; } });
|
|
13
14
|
var Dimensions_js_1 = require("./Dimensions.js");
|
|
14
15
|
Object.defineProperty(exports, "Dimensions", { enumerable: true, get: function () { return Dimensions_js_1.Dimensions; } });
|
|
16
|
+
var scriptType_js_1 = require("./scriptType.js");
|
|
17
|
+
Object.defineProperty(exports, "outputScriptTypes", { enumerable: true, get: function () { return scriptType_js_1.outputScriptTypes; } });
|
|
18
|
+
Object.defineProperty(exports, "inputScriptTypes", { enumerable: true, get: function () { return scriptType_js_1.inputScriptTypes; } });
|
|
15
19
|
var chains_js_1 = require("./chains.js");
|
|
16
20
|
Object.defineProperty(exports, "ChainCode", { enumerable: true, get: function () { return chains_js_1.ChainCode; } });
|
|
17
21
|
Object.defineProperty(exports, "chainCodes", { enumerable: true, get: function () { return chains_js_1.chainCodes; } });
|
|
22
|
+
Object.defineProperty(exports, "assertChainCode", { enumerable: true, get: function () { return chains_js_1.assertChainCode; } });
|
|
18
23
|
// Bitcoin-like PSBT (for all non-Zcash networks)
|
|
19
24
|
var BitGoPsbt_js_1 = require("./BitGoPsbt.js");
|
|
20
25
|
Object.defineProperty(exports, "BitGoPsbt", { enumerable: true, get: function () { return BitGoPsbt_js_1.BitGoPsbt; } });
|
|
@@ -49,3 +54,22 @@ Object.defineProperty(exports, "ZcashBitGoPsbt", { enumerable: true, get: functi
|
|
|
49
54
|
function supportsScriptType(coin, scriptType) {
|
|
50
55
|
return wasm_utxo_js_1.FixedScriptWalletNamespace.supports_script_type(coin, scriptType);
|
|
51
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Create an OP_RETURN output script with optional data
|
|
59
|
+
*
|
|
60
|
+
* @param data - Optional data bytes to include in the OP_RETURN script
|
|
61
|
+
* @returns The OP_RETURN script as a Uint8Array
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // Empty OP_RETURN
|
|
66
|
+
* const script = createOpReturnScript();
|
|
67
|
+
*
|
|
68
|
+
* // OP_RETURN with data
|
|
69
|
+
* const data = new Uint8Array([1, 2, 3, 4]);
|
|
70
|
+
* const script = createOpReturnScript(data);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
function createOpReturnScript(data) {
|
|
74
|
+
return wasm_utxo_js_1.FixedScriptWalletNamespace.create_op_return_script(data);
|
|
75
|
+
}
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* All output script types for fixed-script wallets (2-of-3 multisig)
|
|
3
3
|
*
|
|
4
|
-
* This
|
|
4
|
+
* This represents the abstract script type, independent of chain (external/internal).
|
|
5
5
|
* Use this for checking network support or when you need the script type without derivation info.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export declare const outputScriptTypes: readonly ["p2sh", "p2shP2wsh", "p2wsh", "p2trLegacy", "p2trMusig2"];
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Output script type for fixed-script wallets
|
|
10
|
+
*
|
|
11
|
+
* Note: "p2tr" is an alias for "p2trLegacy" for backward compatibility.
|
|
12
|
+
*/
|
|
13
|
+
export type OutputScriptType = (typeof outputScriptTypes)[number] | "p2tr";
|
|
14
|
+
/**
|
|
15
|
+
* All input script types for fixed-script wallets
|
|
10
16
|
*
|
|
11
17
|
* These are more specific than output types and include single-sig and taproot variants.
|
|
12
18
|
*/
|
|
13
|
-
export
|
|
19
|
+
export declare const inputScriptTypes: readonly ["p2shP2pk", "p2sh", "p2shP2wsh", "p2wsh", "p2trLegacy", "p2trMusig2ScriptPath", "p2trMusig2KeyPath"];
|
|
20
|
+
/**
|
|
21
|
+
* Input script type for fixed-script wallets
|
|
22
|
+
*/
|
|
23
|
+
export type InputScriptType = (typeof inputScriptTypes)[number];
|
|
14
24
|
/**
|
|
15
25
|
* Union of all script types that can be checked for network support
|
|
16
26
|
*/
|
|
@@ -1,2 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inputScriptTypes = exports.outputScriptTypes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* All output script types for fixed-script wallets (2-of-3 multisig)
|
|
6
|
+
*
|
|
7
|
+
* This represents the abstract script type, independent of chain (external/internal).
|
|
8
|
+
* Use this for checking network support or when you need the script type without derivation info.
|
|
9
|
+
*/
|
|
10
|
+
exports.outputScriptTypes = [
|
|
11
|
+
"p2sh",
|
|
12
|
+
"p2shP2wsh",
|
|
13
|
+
"p2wsh",
|
|
14
|
+
"p2trLegacy",
|
|
15
|
+
"p2trMusig2",
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* All input script types for fixed-script wallets
|
|
19
|
+
*
|
|
20
|
+
* These are more specific than output types and include single-sig and taproot variants.
|
|
21
|
+
*/
|
|
22
|
+
exports.inputScriptTypes = [
|
|
23
|
+
"p2shP2pk",
|
|
24
|
+
"p2sh",
|
|
25
|
+
"p2shP2wsh",
|
|
26
|
+
"p2wsh",
|
|
27
|
+
"p2trLegacy",
|
|
28
|
+
"p2trMusig2ScriptPath",
|
|
29
|
+
"p2trMusig2KeyPath",
|
|
30
|
+
];
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { BitGoPsbt } from "../fixedScriptWallet/BitGoPsbt.js";
|
|
2
|
+
import { RootWalletKeys } from "../fixedScriptWallet/RootWalletKeys.js";
|
|
3
|
+
import { BIP32 } from "../bip32.js";
|
|
4
|
+
import { inputScriptTypes, outputScriptTypes, type InputScriptType, type OutputScriptType, type ScriptId } from "../fixedScriptWallet/index.js";
|
|
5
|
+
import type { CoinName } from "../coinName.js";
|
|
6
|
+
import type { Triple } from "../triple.js";
|
|
7
|
+
export declare const signStages: readonly ["unsigned", "halfsigned", "fullsigned"];
|
|
8
|
+
export type SignStage = (typeof signStages)[number];
|
|
9
|
+
export declare const txFormats: readonly ["psbt", "psbt-lite"];
|
|
10
|
+
export type TxFormat = (typeof txFormats)[number];
|
|
11
|
+
/**
|
|
12
|
+
* Utility type to make union variants mutually exclusive.
|
|
13
|
+
* For each variant T in the union, adds `?: never` for all keys from other variants.
|
|
14
|
+
*/
|
|
15
|
+
type Exclusive<T, U = T> = T extends unknown ? T & Partial<Record<Exclude<U extends unknown ? keyof U : never, keyof T>, never>> : never;
|
|
16
|
+
/** Base input fields */
|
|
17
|
+
type InputBase = {
|
|
18
|
+
value: bigint;
|
|
19
|
+
/** Wallet keys to use. Defaults to root wallet keys */
|
|
20
|
+
walletKeys?: RootWalletKeys;
|
|
21
|
+
};
|
|
22
|
+
/** Input variant types */
|
|
23
|
+
type InputVariant = {
|
|
24
|
+
scriptType: InputScriptType;
|
|
25
|
+
index?: number;
|
|
26
|
+
} | {
|
|
27
|
+
scriptId: ScriptId;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Input configuration for AcidTest PSBT
|
|
31
|
+
*
|
|
32
|
+
* Either specify `scriptType` (chain derived from type, index defaults to position)
|
|
33
|
+
* or specify `scriptId` (explicit chain + index).
|
|
34
|
+
*/
|
|
35
|
+
export type Input = InputBase & Exclusive<InputVariant>;
|
|
36
|
+
/** Base output fields */
|
|
37
|
+
type OutputBase = {
|
|
38
|
+
value: bigint;
|
|
39
|
+
/** Wallet keys to use. Defaults to root wallet keys. null = external output (no bip32 derivation) */
|
|
40
|
+
walletKeys?: RootWalletKeys | null;
|
|
41
|
+
};
|
|
42
|
+
/** Output variant types */
|
|
43
|
+
type OutputVariant = {
|
|
44
|
+
scriptType: OutputScriptType;
|
|
45
|
+
index?: number;
|
|
46
|
+
} | {
|
|
47
|
+
scriptId: ScriptId;
|
|
48
|
+
} | {
|
|
49
|
+
opReturn: string;
|
|
50
|
+
} | {
|
|
51
|
+
address: string;
|
|
52
|
+
} | {
|
|
53
|
+
script: Uint8Array;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Output configuration for AcidTest PSBT
|
|
57
|
+
*
|
|
58
|
+
* Specify one of:
|
|
59
|
+
* - `scriptType` (chain derived from type, index defaults to position)
|
|
60
|
+
* - `scriptId` (explicit chain + index)
|
|
61
|
+
* - `opReturn` for OP_RETURN data output
|
|
62
|
+
* - `address` for address-based output
|
|
63
|
+
* - `script` for raw script output
|
|
64
|
+
*/
|
|
65
|
+
export type Output = OutputBase & Exclusive<OutputVariant>;
|
|
66
|
+
type SuiteConfig = {
|
|
67
|
+
/**
|
|
68
|
+
* By default, we exclude p2trMusig2ScriptPath from the inputs since
|
|
69
|
+
* it uses user + backup keys (not typical 2-of-3 with user + bitgo).
|
|
70
|
+
* Set to true to include this input type.
|
|
71
|
+
*/
|
|
72
|
+
includeP2trMusig2ScriptPath?: boolean;
|
|
73
|
+
};
|
|
74
|
+
export { inputScriptTypes, outputScriptTypes };
|
|
75
|
+
/**
|
|
76
|
+
* Creates a valid PSBT with as many features as possible (kitchen sink).
|
|
77
|
+
*
|
|
78
|
+
* - Inputs:
|
|
79
|
+
* - All wallet script types supported by the network
|
|
80
|
+
* - A p2shP2pk input (for replay protection)
|
|
81
|
+
* - Outputs:
|
|
82
|
+
* - All wallet script types supported by the network
|
|
83
|
+
* - A p2sh output with derivation info of a different wallet
|
|
84
|
+
* - A p2sh output with no derivation info (external output)
|
|
85
|
+
* - An OP_RETURN output
|
|
86
|
+
*
|
|
87
|
+
* Signature stages:
|
|
88
|
+
* - unsigned: No signatures
|
|
89
|
+
* - halfsigned: One signature per input (user key)
|
|
90
|
+
* - fullsigned: Two signatures per input (user + bitgo)
|
|
91
|
+
*
|
|
92
|
+
* Transaction formats:
|
|
93
|
+
* - psbt: Full PSBT with non_witness_utxo
|
|
94
|
+
* - psbt-lite: Only witness_utxo (no non_witness_utxo)
|
|
95
|
+
*/
|
|
96
|
+
export declare class AcidTest {
|
|
97
|
+
readonly network: CoinName;
|
|
98
|
+
readonly signStage: SignStage;
|
|
99
|
+
readonly txFormat: TxFormat;
|
|
100
|
+
readonly rootWalletKeys: RootWalletKeys;
|
|
101
|
+
readonly otherWalletKeys: RootWalletKeys;
|
|
102
|
+
readonly inputs: Input[];
|
|
103
|
+
readonly outputs: Output[];
|
|
104
|
+
private readonly userXprv;
|
|
105
|
+
private readonly backupXprv;
|
|
106
|
+
private readonly bitgoXprv;
|
|
107
|
+
constructor(network: CoinName, signStage: SignStage, txFormat: TxFormat, rootWalletKeys: RootWalletKeys, otherWalletKeys: RootWalletKeys, inputs: Input[], outputs: Output[], xprvTriple: Triple<BIP32>);
|
|
108
|
+
/**
|
|
109
|
+
* Create an AcidTest with specific configuration
|
|
110
|
+
*/
|
|
111
|
+
static withConfig(network: CoinName, signStage: SignStage, txFormat: TxFormat, suiteConfig?: SuiteConfig): AcidTest;
|
|
112
|
+
/**
|
|
113
|
+
* Get a human-readable name for this test configuration
|
|
114
|
+
*/
|
|
115
|
+
get name(): string;
|
|
116
|
+
/**
|
|
117
|
+
* Get the BIP32 user key for replay protection (p2shP2pk)
|
|
118
|
+
*/
|
|
119
|
+
getReplayProtectionKey(): BIP32;
|
|
120
|
+
/**
|
|
121
|
+
* Create the actual PSBT with all inputs and outputs
|
|
122
|
+
*/
|
|
123
|
+
createPsbt(): BitGoPsbt;
|
|
124
|
+
/**
|
|
125
|
+
* Sign the PSBT according to the sign stage
|
|
126
|
+
*/
|
|
127
|
+
private signPsbt;
|
|
128
|
+
/**
|
|
129
|
+
* Generate test suite for all networks, sign stages, and tx formats
|
|
130
|
+
*/
|
|
131
|
+
static forAllNetworksSignStagesTxFormats(suiteConfig?: SuiteConfig): AcidTest[];
|
|
132
|
+
}
|