@bitgo/wasm-utxo 1.5.0 → 1.7.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/ast/formatNode.js +2 -2
- package/dist/cjs/js/ast/fromWasmNode.js +2 -1
- package/dist/cjs/js/bip32.d.ts +140 -0
- package/dist/cjs/js/bip32.js +177 -0
- package/dist/cjs/js/ecpair.d.ts +96 -0
- package/dist/cjs/js/ecpair.js +134 -0
- package/dist/cjs/js/{fixedScriptWallet.d.ts → fixedScriptWallet/BitGoPsbt.d.ts} +40 -41
- package/dist/cjs/js/{fixedScriptWallet.js → fixedScriptWallet/BitGoPsbt.js} +50 -36
- package/dist/cjs/js/fixedScriptWallet/ReplayProtection.d.ts +58 -0
- package/dist/cjs/js/fixedScriptWallet/ReplayProtection.js +89 -0
- package/dist/cjs/js/fixedScriptWallet/RootWalletKeys.d.ts +66 -0
- package/dist/cjs/js/fixedScriptWallet/RootWalletKeys.js +108 -0
- package/dist/cjs/js/fixedScriptWallet/address.d.ts +20 -0
- package/dist/cjs/js/fixedScriptWallet/address.js +29 -0
- package/dist/cjs/js/fixedScriptWallet/index.d.ts +4 -0
- package/dist/cjs/js/fixedScriptWallet/index.js +12 -0
- package/dist/cjs/js/index.d.ts +5 -1
- package/dist/cjs/js/index.js +11 -2
- package/dist/cjs/js/utxolibCompat.d.ts +0 -18
- package/dist/cjs/js/wasm/wasm_utxo.d.ts +254 -22
- package/dist/cjs/js/wasm/wasm_utxo.js +1081 -223
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +53 -8
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/js/ast/formatNode.js +2 -2
- package/dist/esm/js/ast/fromWasmNode.js +2 -1
- package/dist/esm/js/bip32.d.ts +140 -0
- package/dist/esm/js/bip32.js +173 -0
- package/dist/esm/js/ecpair.d.ts +96 -0
- package/dist/esm/js/ecpair.js +130 -0
- package/dist/esm/js/{fixedScriptWallet.d.ts → fixedScriptWallet/BitGoPsbt.d.ts} +40 -41
- package/dist/esm/js/{fixedScriptWallet.js → fixedScriptWallet/BitGoPsbt.js} +49 -33
- package/dist/esm/js/fixedScriptWallet/ReplayProtection.d.ts +58 -0
- package/dist/esm/js/fixedScriptWallet/ReplayProtection.js +85 -0
- package/dist/esm/js/fixedScriptWallet/RootWalletKeys.d.ts +66 -0
- package/dist/esm/js/fixedScriptWallet/RootWalletKeys.js +104 -0
- package/dist/esm/js/fixedScriptWallet/address.d.ts +20 -0
- package/dist/esm/js/fixedScriptWallet/address.js +25 -0
- package/dist/esm/js/fixedScriptWallet/index.d.ts +4 -0
- package/dist/esm/js/fixedScriptWallet/index.js +4 -0
- package/dist/esm/js/index.d.ts +5 -1
- package/dist/esm/js/index.js +8 -1
- package/dist/esm/js/utxolibCompat.d.ts +0 -18
- package/dist/esm/js/wasm/wasm_utxo.d.ts +254 -22
- package/dist/esm/js/wasm/wasm_utxo_bg.js +1070 -220
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +53 -8
- package/dist/esm/test/address/utxolibCompat.js +12 -10
- package/dist/esm/test/bip32.d.ts +1 -0
- package/dist/esm/test/bip32.js +242 -0
- package/dist/esm/test/descriptorUtil.js +1 -1
- package/dist/esm/test/ecpair.d.ts +1 -0
- package/dist/esm/test/ecpair.js +137 -0
- package/dist/esm/test/fixedScript/address.js +9 -7
- package/dist/esm/test/fixedScript/fixtureUtil.d.ts +5 -3
- package/dist/esm/test/fixedScript/fixtureUtil.js +18 -7
- package/dist/esm/test/fixedScript/parseTransactionWithWalletKeys.js +39 -11
- package/dist/esm/test/fixedScript/verifySignature.js +73 -27
- package/dist/esm/test/fixedScriptToDescriptor.js +6 -4
- package/dist/esm/test/fixtures.js +5 -1
- package/dist/esm/test/psbt.util.js +1 -4
- package/dist/esm/test/psbtFixedScriptCompat.js +19 -17
- package/dist/esm/test/psbtFixedScriptCompatFixtures.js +1 -1
- package/dist/esm/test/psbtFromDescriptor.js +5 -8
- package/dist/esm/test/psbtFromDescriptor.util.js +3 -3
- package/dist/esm/test/test.js +5 -4
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -3
|
@@ -1,44 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { type WalletKeysArg } from "./RootWalletKeys.js";
|
|
2
|
+
import { type ReplayProtectionArg } from "./ReplayProtection.js";
|
|
3
|
+
import { type BIP32Arg } from "../bip32.js";
|
|
4
|
+
import { type ECPairArg } from "../ecpair.js";
|
|
5
|
+
import type { UtxolibName } from "../utxolibCompat.js";
|
|
6
|
+
import type { CoinName } from "../coinName.js";
|
|
5
7
|
export type NetworkName = UtxolibName | CoinName;
|
|
6
|
-
export type WalletKeys =
|
|
7
|
-
/** Just an xpub triple, will assume default derivation prefixes */
|
|
8
|
-
Triple<string>
|
|
9
|
-
/** Compatible with utxolib RootWalletKeys */
|
|
10
|
-
| UtxolibRootWalletKeys;
|
|
11
|
-
/**
|
|
12
|
-
* Create the output script for a given wallet keys and chain and index
|
|
13
|
-
*/
|
|
14
|
-
export declare function outputScript(keys: WalletKeys, chain: number, index: number, network: UtxolibNetwork): Uint8Array;
|
|
15
|
-
/**
|
|
16
|
-
* Create the address for a given wallet keys and chain and index and network.
|
|
17
|
-
* Wrapper for outputScript that also encodes the script to an address.
|
|
18
|
-
* @param keys - The wallet keys to use.
|
|
19
|
-
* @param chain - The chain to use.
|
|
20
|
-
* @param index - The index to use.
|
|
21
|
-
* @param network - The network to use.
|
|
22
|
-
* @param addressFormat - The address format to use.
|
|
23
|
-
* Only relevant for Bitcoin Cash and eCash networks, where:
|
|
24
|
-
* - "default" means base58check,
|
|
25
|
-
* - "cashaddr" means cashaddr.
|
|
26
|
-
*/
|
|
27
|
-
export declare function address(keys: WalletKeys, chain: number, index: number, network: UtxolibNetwork, addressFormat?: AddressFormat): string;
|
|
28
|
-
type ReplayProtection = {
|
|
29
|
-
outputScripts: Uint8Array[];
|
|
30
|
-
} | {
|
|
31
|
-
addresses: string[];
|
|
32
|
-
};
|
|
33
8
|
export type ScriptId = {
|
|
34
9
|
chain: number;
|
|
35
10
|
index: number;
|
|
36
11
|
};
|
|
12
|
+
export type InputScriptType = "p2shP2pk" | "p2sh" | "p2shP2wsh" | "p2wsh" | "p2trLegacy" | "p2trMusig2ScriptPath" | "p2trMusig2KeyPath";
|
|
37
13
|
export type ParsedInput = {
|
|
38
14
|
address: string;
|
|
39
15
|
script: Uint8Array;
|
|
40
16
|
value: bigint;
|
|
41
17
|
scriptId: ScriptId | null;
|
|
18
|
+
scriptType: InputScriptType;
|
|
42
19
|
};
|
|
43
20
|
export type ParsedOutput = {
|
|
44
21
|
address: string | null;
|
|
@@ -74,7 +51,7 @@ export declare class BitGoPsbt {
|
|
|
74
51
|
* @param replayProtection - Scripts that are allowed as inputs without wallet validation
|
|
75
52
|
* @returns Parsed transaction information
|
|
76
53
|
*/
|
|
77
|
-
parseTransactionWithWalletKeys(walletKeys:
|
|
54
|
+
parseTransactionWithWalletKeys(walletKeys: WalletKeysArg, replayProtection: ReplayProtectionArg): ParsedTransaction;
|
|
78
55
|
/**
|
|
79
56
|
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
80
57
|
* with the given wallet keys.
|
|
@@ -86,23 +63,46 @@ export declare class BitGoPsbt {
|
|
|
86
63
|
* @returns Array of parsed outputs
|
|
87
64
|
* @note This method does NOT validate wallet inputs. It only parses outputs.
|
|
88
65
|
*/
|
|
89
|
-
parseOutputsWithWalletKeys(walletKeys:
|
|
66
|
+
parseOutputsWithWalletKeys(walletKeys: WalletKeysArg): ParsedOutput[];
|
|
90
67
|
/**
|
|
91
|
-
* Verify if a valid signature exists for a given
|
|
68
|
+
* Verify if a valid signature exists for a given key at the specified input index.
|
|
69
|
+
*
|
|
70
|
+
* This method can verify signatures using either:
|
|
71
|
+
* - Extended public key (xpub): Derives the public key using the derivation path from PSBT
|
|
72
|
+
* - ECPair (private key): Extracts the public key and verifies directly
|
|
92
73
|
*
|
|
93
|
-
*
|
|
94
|
-
* PSBT input, then verifies the signature. It supports:
|
|
74
|
+
* When using xpub, it supports:
|
|
95
75
|
* - ECDSA signatures (for legacy/SegWit inputs)
|
|
96
76
|
* - Schnorr signatures (for Taproot script path inputs)
|
|
97
77
|
* - MuSig2 partial signatures (for Taproot keypath MuSig2 inputs)
|
|
98
78
|
*
|
|
79
|
+
* When using ECPair, it supports:
|
|
80
|
+
* - ECDSA signatures (for legacy/SegWit inputs)
|
|
81
|
+
* - Schnorr signatures (for Taproot script path inputs)
|
|
82
|
+
* Note: MuSig2 inputs require xpubs for derivation
|
|
83
|
+
*
|
|
99
84
|
* @param inputIndex - The index of the input to check (0-based)
|
|
100
|
-
* @param
|
|
85
|
+
* @param key - Either an extended public key (base58 string, BIP32 instance, or WasmBIP32) or an ECPair (private key Buffer, ECPair instance, or WasmECPair)
|
|
101
86
|
* @returns true if a valid signature exists, false if no signature exists
|
|
102
|
-
* @throws Error if input index is out of bounds,
|
|
87
|
+
* @throws Error if input index is out of bounds, key is invalid, or verification fails
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* // Verify wallet input signature with xpub
|
|
92
|
+
* const hasUserSig = psbt.verifySignature(0, userXpub);
|
|
93
|
+
*
|
|
94
|
+
* // Verify signature with ECPair (private key)
|
|
95
|
+
* const ecpair = ECPair.fromPrivateKey(privateKeyBuffer);
|
|
96
|
+
* const hasReplaySig = psbt.verifySignature(1, ecpair);
|
|
97
|
+
*
|
|
98
|
+
* // Or pass private key directly
|
|
99
|
+
* const hasReplaySig2 = psbt.verifySignature(1, privateKeyBuffer);
|
|
100
|
+
* ```
|
|
103
101
|
*/
|
|
104
|
-
verifySignature(inputIndex: number,
|
|
102
|
+
verifySignature(inputIndex: number, key: BIP32Arg | ECPairArg): boolean;
|
|
105
103
|
/**
|
|
104
|
+
* @deprecated - use verifySignature with the replay protection key instead
|
|
105
|
+
*
|
|
106
106
|
* Verify if a replay protection input has a valid signature.
|
|
107
107
|
*
|
|
108
108
|
* This method checks if a given input is a replay protection input (like P2shP2pk) and verifies
|
|
@@ -120,7 +120,7 @@ export declare class BitGoPsbt {
|
|
|
120
120
|
* @returns true if the input is a replay protection input and has a valid signature, false if no valid signature
|
|
121
121
|
* @throws Error if the input is not a replay protection input, index is out of bounds, or scripts are invalid
|
|
122
122
|
*/
|
|
123
|
-
verifyReplayProtectionSignature(inputIndex: number, replayProtection:
|
|
123
|
+
verifyReplayProtectionSignature(inputIndex: number, replayProtection: ReplayProtectionArg): boolean;
|
|
124
124
|
/**
|
|
125
125
|
* Serialize the PSBT to bytes
|
|
126
126
|
*
|
|
@@ -141,4 +141,3 @@ export declare class BitGoPsbt {
|
|
|
141
141
|
*/
|
|
142
142
|
extractTransaction(): Uint8Array;
|
|
143
143
|
}
|
|
144
|
-
export {};
|
|
@@ -1,31 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BitGoPsbt = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
function outputScript(keys, chain, index, network) {
|
|
11
|
-
return wasm_utxo_js_1.FixedScriptWalletNamespace.output_script(keys, chain, index, network);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Create the address for a given wallet keys and chain and index and network.
|
|
15
|
-
* Wrapper for outputScript that also encodes the script to an address.
|
|
16
|
-
* @param keys - The wallet keys to use.
|
|
17
|
-
* @param chain - The chain to use.
|
|
18
|
-
* @param index - The index to use.
|
|
19
|
-
* @param network - The network to use.
|
|
20
|
-
* @param addressFormat - The address format to use.
|
|
21
|
-
* Only relevant for Bitcoin Cash and eCash networks, where:
|
|
22
|
-
* - "default" means base58check,
|
|
23
|
-
* - "cashaddr" means cashaddr.
|
|
24
|
-
*/
|
|
25
|
-
function address(keys, chain, index, network, addressFormat) {
|
|
26
|
-
return wasm_utxo_js_1.FixedScriptWalletNamespace.address(keys, chain, index, network, addressFormat);
|
|
27
|
-
}
|
|
28
|
-
const wasm_utxo_js_2 = require("./wasm/wasm_utxo.js");
|
|
4
|
+
const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
|
|
5
|
+
const RootWalletKeys_js_1 = require("./RootWalletKeys.js");
|
|
6
|
+
const ReplayProtection_js_1 = require("./ReplayProtection.js");
|
|
7
|
+
const bip32_js_1 = require("../bip32.js");
|
|
8
|
+
const ecpair_js_1 = require("../ecpair.js");
|
|
29
9
|
class BitGoPsbt {
|
|
30
10
|
wasm;
|
|
31
11
|
constructor(wasm) {
|
|
@@ -38,7 +18,7 @@ class BitGoPsbt {
|
|
|
38
18
|
* @returns A BitGoPsbt instance
|
|
39
19
|
*/
|
|
40
20
|
static fromBytes(bytes, network) {
|
|
41
|
-
const wasm =
|
|
21
|
+
const wasm = wasm_utxo_js_1.BitGoPsbt.from_bytes(bytes, network);
|
|
42
22
|
return new BitGoPsbt(wasm);
|
|
43
23
|
}
|
|
44
24
|
/**
|
|
@@ -55,7 +35,9 @@ class BitGoPsbt {
|
|
|
55
35
|
* @returns Parsed transaction information
|
|
56
36
|
*/
|
|
57
37
|
parseTransactionWithWalletKeys(walletKeys, replayProtection) {
|
|
58
|
-
|
|
38
|
+
const keys = RootWalletKeys_js_1.RootWalletKeys.from(walletKeys);
|
|
39
|
+
const rp = ReplayProtection_js_1.ReplayProtection.from(replayProtection, this.wasm.network());
|
|
40
|
+
return this.wasm.parse_transaction_with_wallet_keys(keys.wasm, rp.wasm);
|
|
59
41
|
}
|
|
60
42
|
/**
|
|
61
43
|
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
@@ -69,26 +51,57 @@ class BitGoPsbt {
|
|
|
69
51
|
* @note This method does NOT validate wallet inputs. It only parses outputs.
|
|
70
52
|
*/
|
|
71
53
|
parseOutputsWithWalletKeys(walletKeys) {
|
|
72
|
-
|
|
54
|
+
const keys = RootWalletKeys_js_1.RootWalletKeys.from(walletKeys);
|
|
55
|
+
return this.wasm.parse_outputs_with_wallet_keys(keys.wasm);
|
|
73
56
|
}
|
|
74
57
|
/**
|
|
75
|
-
* Verify if a valid signature exists for a given
|
|
58
|
+
* Verify if a valid signature exists for a given key at the specified input index.
|
|
59
|
+
*
|
|
60
|
+
* This method can verify signatures using either:
|
|
61
|
+
* - Extended public key (xpub): Derives the public key using the derivation path from PSBT
|
|
62
|
+
* - ECPair (private key): Extracts the public key and verifies directly
|
|
76
63
|
*
|
|
77
|
-
*
|
|
78
|
-
* PSBT input, then verifies the signature. It supports:
|
|
64
|
+
* When using xpub, it supports:
|
|
79
65
|
* - ECDSA signatures (for legacy/SegWit inputs)
|
|
80
66
|
* - Schnorr signatures (for Taproot script path inputs)
|
|
81
67
|
* - MuSig2 partial signatures (for Taproot keypath MuSig2 inputs)
|
|
82
68
|
*
|
|
69
|
+
* When using ECPair, it supports:
|
|
70
|
+
* - ECDSA signatures (for legacy/SegWit inputs)
|
|
71
|
+
* - Schnorr signatures (for Taproot script path inputs)
|
|
72
|
+
* Note: MuSig2 inputs require xpubs for derivation
|
|
73
|
+
*
|
|
83
74
|
* @param inputIndex - The index of the input to check (0-based)
|
|
84
|
-
* @param
|
|
75
|
+
* @param key - Either an extended public key (base58 string, BIP32 instance, or WasmBIP32) or an ECPair (private key Buffer, ECPair instance, or WasmECPair)
|
|
85
76
|
* @returns true if a valid signature exists, false if no signature exists
|
|
86
|
-
* @throws Error if input index is out of bounds,
|
|
77
|
+
* @throws Error if input index is out of bounds, key is invalid, or verification fails
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* // Verify wallet input signature with xpub
|
|
82
|
+
* const hasUserSig = psbt.verifySignature(0, userXpub);
|
|
83
|
+
*
|
|
84
|
+
* // Verify signature with ECPair (private key)
|
|
85
|
+
* const ecpair = ECPair.fromPrivateKey(privateKeyBuffer);
|
|
86
|
+
* const hasReplaySig = psbt.verifySignature(1, ecpair);
|
|
87
|
+
*
|
|
88
|
+
* // Or pass private key directly
|
|
89
|
+
* const hasReplaySig2 = psbt.verifySignature(1, privateKeyBuffer);
|
|
90
|
+
* ```
|
|
87
91
|
*/
|
|
88
|
-
verifySignature(inputIndex,
|
|
89
|
-
|
|
92
|
+
verifySignature(inputIndex, key) {
|
|
93
|
+
// Try to parse as BIP32Arg first (string or BIP32 instance)
|
|
94
|
+
if (typeof key === "string" || ("derive" in key && typeof key.derive === "function")) {
|
|
95
|
+
const wasmKey = bip32_js_1.BIP32.from(key).wasm;
|
|
96
|
+
return this.wasm.verify_signature_with_xpub(inputIndex, wasmKey);
|
|
97
|
+
}
|
|
98
|
+
// Otherwise it's an ECPairArg (Uint8Array, ECPair, or WasmECPair)
|
|
99
|
+
const wasmECPair = ecpair_js_1.ECPair.from(key).wasm;
|
|
100
|
+
return this.wasm.verify_signature_with_pub(inputIndex, wasmECPair);
|
|
90
101
|
}
|
|
91
102
|
/**
|
|
103
|
+
* @deprecated - use verifySignature with the replay protection key instead
|
|
104
|
+
*
|
|
92
105
|
* Verify if a replay protection input has a valid signature.
|
|
93
106
|
*
|
|
94
107
|
* This method checks if a given input is a replay protection input (like P2shP2pk) and verifies
|
|
@@ -107,7 +120,8 @@ class BitGoPsbt {
|
|
|
107
120
|
* @throws Error if the input is not a replay protection input, index is out of bounds, or scripts are invalid
|
|
108
121
|
*/
|
|
109
122
|
verifyReplayProtectionSignature(inputIndex, replayProtection) {
|
|
110
|
-
|
|
123
|
+
const rp = ReplayProtection_js_1.ReplayProtection.from(replayProtection, this.wasm.network());
|
|
124
|
+
return this.wasm.verify_replay_protection_signature(inputIndex, rp.wasm);
|
|
111
125
|
}
|
|
112
126
|
/**
|
|
113
127
|
* Serialize the PSBT to bytes
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { WasmReplayProtection } from "../wasm/wasm_utxo.js";
|
|
2
|
+
import { type ECPairArg } from "../ecpair.js";
|
|
3
|
+
/**
|
|
4
|
+
* ReplayProtectionArg represents the various forms that replay protection can take
|
|
5
|
+
* before being converted to a WasmReplayProtection instance
|
|
6
|
+
*/
|
|
7
|
+
export type ReplayProtectionArg = ReplayProtection | WasmReplayProtection | {
|
|
8
|
+
publicKeys: ECPairArg[];
|
|
9
|
+
} | {
|
|
10
|
+
/** @deprecated - use publicKeys instead */
|
|
11
|
+
outputScripts: Uint8Array[];
|
|
12
|
+
} | {
|
|
13
|
+
/** @deprecated - use publicKeys instead */
|
|
14
|
+
addresses: string[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* ReplayProtection wrapper class for PSBT replay protection inputs
|
|
18
|
+
*/
|
|
19
|
+
export declare class ReplayProtection {
|
|
20
|
+
private _wasm;
|
|
21
|
+
private constructor();
|
|
22
|
+
/**
|
|
23
|
+
* Create a ReplayProtection instance from a WasmReplayProtection instance (internal use)
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
static fromWasm(wasm: WasmReplayProtection): ReplayProtection;
|
|
27
|
+
/**
|
|
28
|
+
* Convert ReplayProtectionArg to ReplayProtection instance
|
|
29
|
+
* @param arg - The replay protection in various formats
|
|
30
|
+
* @param network - Optional network string (required for addresses variant)
|
|
31
|
+
* @returns ReplayProtection instance
|
|
32
|
+
*/
|
|
33
|
+
static from(arg: ReplayProtectionArg, network?: string): ReplayProtection;
|
|
34
|
+
/**
|
|
35
|
+
* Create from public keys (derives P2SH-P2PK output scripts)
|
|
36
|
+
* @param publicKeys - Array of ECPair instances or arguments
|
|
37
|
+
* @returns ReplayProtection instance
|
|
38
|
+
*/
|
|
39
|
+
static fromPublicKeys(publicKeys: ECPairArg[]): ReplayProtection;
|
|
40
|
+
/**
|
|
41
|
+
* Create from output scripts
|
|
42
|
+
* @param outputScripts - Array of output script buffers
|
|
43
|
+
* @returns ReplayProtection instance
|
|
44
|
+
*/
|
|
45
|
+
static fromOutputScripts(outputScripts: Uint8Array[]): ReplayProtection;
|
|
46
|
+
/**
|
|
47
|
+
* Create from addresses
|
|
48
|
+
* @param addresses - Array of address strings
|
|
49
|
+
* @param network - Network string (e.g., "bitcoin", "testnet", "btc", "tbtc")
|
|
50
|
+
* @returns ReplayProtection instance
|
|
51
|
+
*/
|
|
52
|
+
static fromAddresses(addresses: string[], network: string): ReplayProtection;
|
|
53
|
+
/**
|
|
54
|
+
* Get the underlying WASM instance (internal use only)
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
get wasm(): WasmReplayProtection;
|
|
58
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReplayProtection = void 0;
|
|
4
|
+
const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
|
|
5
|
+
const ecpair_js_1 = require("../ecpair.js");
|
|
6
|
+
/**
|
|
7
|
+
* ReplayProtection wrapper class for PSBT replay protection inputs
|
|
8
|
+
*/
|
|
9
|
+
class ReplayProtection {
|
|
10
|
+
_wasm;
|
|
11
|
+
constructor(_wasm) {
|
|
12
|
+
this._wasm = _wasm;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a ReplayProtection instance from a WasmReplayProtection instance (internal use)
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
static fromWasm(wasm) {
|
|
19
|
+
return new ReplayProtection(wasm);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Convert ReplayProtectionArg to ReplayProtection instance
|
|
23
|
+
* @param arg - The replay protection in various formats
|
|
24
|
+
* @param network - Optional network string (required for addresses variant)
|
|
25
|
+
* @returns ReplayProtection instance
|
|
26
|
+
*/
|
|
27
|
+
static from(arg, network) {
|
|
28
|
+
// Short-circuit if already a ReplayProtection instance
|
|
29
|
+
if (arg instanceof ReplayProtection) {
|
|
30
|
+
return arg;
|
|
31
|
+
}
|
|
32
|
+
// If it's a WasmReplayProtection instance, wrap it
|
|
33
|
+
if (arg instanceof wasm_utxo_js_1.WasmReplayProtection) {
|
|
34
|
+
return new ReplayProtection(arg);
|
|
35
|
+
}
|
|
36
|
+
// Handle object variants
|
|
37
|
+
if ("publicKeys" in arg) {
|
|
38
|
+
// Convert ECPairArg to public key bytes
|
|
39
|
+
const publicKeyBytes = arg.publicKeys.map((key) => ecpair_js_1.ECPair.from(key).publicKey);
|
|
40
|
+
const wasm = wasm_utxo_js_1.WasmReplayProtection.from_public_keys(publicKeyBytes);
|
|
41
|
+
return new ReplayProtection(wasm);
|
|
42
|
+
}
|
|
43
|
+
if ("outputScripts" in arg) {
|
|
44
|
+
const wasm = wasm_utxo_js_1.WasmReplayProtection.from_output_scripts(arg.outputScripts);
|
|
45
|
+
return new ReplayProtection(wasm);
|
|
46
|
+
}
|
|
47
|
+
if ("addresses" in arg) {
|
|
48
|
+
if (!network) {
|
|
49
|
+
throw new Error("Network is required when using addresses variant");
|
|
50
|
+
}
|
|
51
|
+
const wasm = wasm_utxo_js_1.WasmReplayProtection.from_addresses(arg.addresses, network);
|
|
52
|
+
return new ReplayProtection(wasm);
|
|
53
|
+
}
|
|
54
|
+
throw new Error("Invalid ReplayProtectionArg type");
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create from public keys (derives P2SH-P2PK output scripts)
|
|
58
|
+
* @param publicKeys - Array of ECPair instances or arguments
|
|
59
|
+
* @returns ReplayProtection instance
|
|
60
|
+
*/
|
|
61
|
+
static fromPublicKeys(publicKeys) {
|
|
62
|
+
return ReplayProtection.from({ publicKeys });
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Create from output scripts
|
|
66
|
+
* @param outputScripts - Array of output script buffers
|
|
67
|
+
* @returns ReplayProtection instance
|
|
68
|
+
*/
|
|
69
|
+
static fromOutputScripts(outputScripts) {
|
|
70
|
+
return ReplayProtection.from({ outputScripts });
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create from addresses
|
|
74
|
+
* @param addresses - Array of address strings
|
|
75
|
+
* @param network - Network string (e.g., "bitcoin", "testnet", "btc", "tbtc")
|
|
76
|
+
* @returns ReplayProtection instance
|
|
77
|
+
*/
|
|
78
|
+
static fromAddresses(addresses, network) {
|
|
79
|
+
return ReplayProtection.from({ addresses }, network);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the underlying WASM instance (internal use only)
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
get wasm() {
|
|
86
|
+
return this._wasm;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.ReplayProtection = ReplayProtection;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { BIP32Interface } from "../bip32.js";
|
|
2
|
+
import { BIP32 } from "../bip32.js";
|
|
3
|
+
import { Triple } from "../triple.js";
|
|
4
|
+
import { WasmRootWalletKeys } from "../wasm/wasm_utxo.js";
|
|
5
|
+
/**
|
|
6
|
+
* IWalletKeys represents the various forms that wallet keys can take
|
|
7
|
+
* before being converted to a RootWalletKeys instance
|
|
8
|
+
*/
|
|
9
|
+
export type IWalletKeys = {
|
|
10
|
+
triple: Triple<BIP32Interface>;
|
|
11
|
+
derivationPrefixes: Triple<string>;
|
|
12
|
+
};
|
|
13
|
+
export type WalletKeysArg =
|
|
14
|
+
/** Just an xpub triple, will assume default derivation prefixes */
|
|
15
|
+
Triple<string>
|
|
16
|
+
/** Compatible with utxolib RootWalletKeys */
|
|
17
|
+
| IWalletKeys
|
|
18
|
+
/** RootWalletKeys instance */
|
|
19
|
+
| RootWalletKeys;
|
|
20
|
+
/**
|
|
21
|
+
* RootWalletKeys represents a set of three extended public keys with their derivation prefixes
|
|
22
|
+
*/
|
|
23
|
+
export declare class RootWalletKeys {
|
|
24
|
+
private _wasm;
|
|
25
|
+
private constructor();
|
|
26
|
+
/**
|
|
27
|
+
* Create a RootWalletKeys from various input formats
|
|
28
|
+
* @param keys - Can be a triple of xpub strings, an IWalletKeys object, or another RootWalletKeys instance
|
|
29
|
+
* @returns A RootWalletKeys instance
|
|
30
|
+
*/
|
|
31
|
+
static from(keys: WalletKeysArg): RootWalletKeys;
|
|
32
|
+
/**
|
|
33
|
+
* Create a RootWalletKeys from three xpub strings
|
|
34
|
+
* Uses default derivation prefix of m/0/0 for all three keys
|
|
35
|
+
* @param xpubs - Triple of xpub strings
|
|
36
|
+
* @returns A RootWalletKeys instance
|
|
37
|
+
*/
|
|
38
|
+
static fromXpubs(xpubs: Triple<string>): RootWalletKeys;
|
|
39
|
+
/**
|
|
40
|
+
* Create a RootWalletKeys from three xpub strings with custom derivation prefixes
|
|
41
|
+
* @param xpubs - Triple of xpub strings
|
|
42
|
+
* @param derivationPrefixes - Triple of derivation path strings (e.g., ["0/0", "0/0", "0/0"])
|
|
43
|
+
* @returns A RootWalletKeys instance
|
|
44
|
+
*/
|
|
45
|
+
static withDerivationPrefixes(xpubs: Triple<string>, derivationPrefixes: Triple<string>): RootWalletKeys;
|
|
46
|
+
/**
|
|
47
|
+
* Get the user key (first xpub)
|
|
48
|
+
* @returns The user key as a BIP32 instance
|
|
49
|
+
*/
|
|
50
|
+
userKey(): BIP32;
|
|
51
|
+
/**
|
|
52
|
+
* Get the backup key (second xpub)
|
|
53
|
+
* @returns The backup key as a BIP32 instance
|
|
54
|
+
*/
|
|
55
|
+
backupKey(): BIP32;
|
|
56
|
+
/**
|
|
57
|
+
* Get the BitGo key (third xpub)
|
|
58
|
+
* @returns The BitGo key as a BIP32 instance
|
|
59
|
+
*/
|
|
60
|
+
bitgoKey(): BIP32;
|
|
61
|
+
/**
|
|
62
|
+
* Get the underlying WASM instance (internal use only)
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
get wasm(): WasmRootWalletKeys;
|
|
66
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RootWalletKeys = void 0;
|
|
4
|
+
const bip32_js_1 = require("../bip32.js");
|
|
5
|
+
const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
|
|
6
|
+
/**
|
|
7
|
+
* Convert WalletKeysArg to a triple of BIP32 instances
|
|
8
|
+
*/
|
|
9
|
+
function toBIP32Triple(keys) {
|
|
10
|
+
if (keys instanceof RootWalletKeys) {
|
|
11
|
+
return [keys.userKey(), keys.backupKey(), keys.bitgoKey()];
|
|
12
|
+
}
|
|
13
|
+
// Check if it's an IWalletKeys object
|
|
14
|
+
if (typeof keys === "object" && "triple" in keys) {
|
|
15
|
+
// Extract BIP32 keys from the triple
|
|
16
|
+
return keys.triple.map((key) => bip32_js_1.BIP32.from(key));
|
|
17
|
+
}
|
|
18
|
+
// Otherwise it's a triple of strings (xpubs)
|
|
19
|
+
return keys.map((xpub) => bip32_js_1.BIP32.fromWasm(wasm_utxo_js_1.WasmBIP32.from_xpub(xpub)));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Extract derivation prefixes from WalletKeysArg, if present
|
|
23
|
+
*/
|
|
24
|
+
function extractDerivationPrefixes(keys) {
|
|
25
|
+
if (typeof keys === "object" && "derivationPrefixes" in keys) {
|
|
26
|
+
return keys.derivationPrefixes;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* RootWalletKeys represents a set of three extended public keys with their derivation prefixes
|
|
32
|
+
*/
|
|
33
|
+
class RootWalletKeys {
|
|
34
|
+
_wasm;
|
|
35
|
+
constructor(_wasm) {
|
|
36
|
+
this._wasm = _wasm;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a RootWalletKeys from various input formats
|
|
40
|
+
* @param keys - Can be a triple of xpub strings, an IWalletKeys object, or another RootWalletKeys instance
|
|
41
|
+
* @returns A RootWalletKeys instance
|
|
42
|
+
*/
|
|
43
|
+
static from(keys) {
|
|
44
|
+
if (keys instanceof RootWalletKeys) {
|
|
45
|
+
return keys;
|
|
46
|
+
}
|
|
47
|
+
const [user, backup, bitgo] = toBIP32Triple(keys);
|
|
48
|
+
const derivationPrefixes = extractDerivationPrefixes(keys);
|
|
49
|
+
const wasm = derivationPrefixes
|
|
50
|
+
? wasm_utxo_js_1.WasmRootWalletKeys.with_derivation_prefixes(user.wasm, backup.wasm, bitgo.wasm, derivationPrefixes[0], derivationPrefixes[1], derivationPrefixes[2])
|
|
51
|
+
: new wasm_utxo_js_1.WasmRootWalletKeys(user.wasm, backup.wasm, bitgo.wasm);
|
|
52
|
+
return new RootWalletKeys(wasm);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a RootWalletKeys from three xpub strings
|
|
56
|
+
* Uses default derivation prefix of m/0/0 for all three keys
|
|
57
|
+
* @param xpubs - Triple of xpub strings
|
|
58
|
+
* @returns A RootWalletKeys instance
|
|
59
|
+
*/
|
|
60
|
+
static fromXpubs(xpubs) {
|
|
61
|
+
const [user, backup, bitgo] = xpubs.map((xpub) => wasm_utxo_js_1.WasmBIP32.from_xpub(xpub));
|
|
62
|
+
const wasm = new wasm_utxo_js_1.WasmRootWalletKeys(user, backup, bitgo);
|
|
63
|
+
return new RootWalletKeys(wasm);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a RootWalletKeys from three xpub strings with custom derivation prefixes
|
|
67
|
+
* @param xpubs - Triple of xpub strings
|
|
68
|
+
* @param derivationPrefixes - Triple of derivation path strings (e.g., ["0/0", "0/0", "0/0"])
|
|
69
|
+
* @returns A RootWalletKeys instance
|
|
70
|
+
*/
|
|
71
|
+
static withDerivationPrefixes(xpubs, derivationPrefixes) {
|
|
72
|
+
const [user, backup, bitgo] = xpubs.map((xpub) => wasm_utxo_js_1.WasmBIP32.from_xpub(xpub));
|
|
73
|
+
const wasm = wasm_utxo_js_1.WasmRootWalletKeys.with_derivation_prefixes(user, backup, bitgo, derivationPrefixes[0], derivationPrefixes[1], derivationPrefixes[2]);
|
|
74
|
+
return new RootWalletKeys(wasm);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the user key (first xpub)
|
|
78
|
+
* @returns The user key as a BIP32 instance
|
|
79
|
+
*/
|
|
80
|
+
userKey() {
|
|
81
|
+
const wasm = this._wasm.user_key();
|
|
82
|
+
return bip32_js_1.BIP32.fromWasm(wasm);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the backup key (second xpub)
|
|
86
|
+
* @returns The backup key as a BIP32 instance
|
|
87
|
+
*/
|
|
88
|
+
backupKey() {
|
|
89
|
+
const wasm = this._wasm.backup_key();
|
|
90
|
+
return bip32_js_1.BIP32.fromWasm(wasm);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get the BitGo key (third xpub)
|
|
94
|
+
* @returns The BitGo key as a BIP32 instance
|
|
95
|
+
*/
|
|
96
|
+
bitgoKey() {
|
|
97
|
+
const wasm = this._wasm.bitgo_key();
|
|
98
|
+
return bip32_js_1.BIP32.fromWasm(wasm);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get the underlying WASM instance (internal use only)
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
104
|
+
get wasm() {
|
|
105
|
+
return this._wasm;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.RootWalletKeys = RootWalletKeys;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type WalletKeysArg } from "./RootWalletKeys.js";
|
|
2
|
+
import type { UtxolibNetwork } from "../utxolibCompat.js";
|
|
3
|
+
import { AddressFormat } from "../address.js";
|
|
4
|
+
/**
|
|
5
|
+
* Create the output script for a given wallet keys and chain and index
|
|
6
|
+
*/
|
|
7
|
+
export declare function outputScript(keys: WalletKeysArg, chain: number, index: number, network: UtxolibNetwork): Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* Create the address for a given wallet keys and chain and index and network.
|
|
10
|
+
* Wrapper for outputScript that also encodes the script to an address.
|
|
11
|
+
* @param keys - The wallet keys to use.
|
|
12
|
+
* @param chain - The chain to use.
|
|
13
|
+
* @param index - The index to use.
|
|
14
|
+
* @param network - The network to use.
|
|
15
|
+
* @param addressFormat - The address format to use.
|
|
16
|
+
* Only relevant for Bitcoin Cash and eCash networks, where:
|
|
17
|
+
* - "default" means base58check,
|
|
18
|
+
* - "cashaddr" means cashaddr.
|
|
19
|
+
*/
|
|
20
|
+
export declare function address(keys: WalletKeysArg, chain: number, index: number, network: UtxolibNetwork, addressFormat?: AddressFormat): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.outputScript = outputScript;
|
|
4
|
+
exports.address = address;
|
|
5
|
+
const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
|
|
6
|
+
const RootWalletKeys_js_1 = require("./RootWalletKeys.js");
|
|
7
|
+
/**
|
|
8
|
+
* Create the output script for a given wallet keys and chain and index
|
|
9
|
+
*/
|
|
10
|
+
function outputScript(keys, chain, index, network) {
|
|
11
|
+
const walletKeys = RootWalletKeys_js_1.RootWalletKeys.from(keys);
|
|
12
|
+
return wasm_utxo_js_1.FixedScriptWalletNamespace.output_script(walletKeys.wasm, chain, index, network);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create the address for a given wallet keys and chain and index and network.
|
|
16
|
+
* Wrapper for outputScript that also encodes the script to an address.
|
|
17
|
+
* @param keys - The wallet keys to use.
|
|
18
|
+
* @param chain - The chain to use.
|
|
19
|
+
* @param index - The index to use.
|
|
20
|
+
* @param network - The network to use.
|
|
21
|
+
* @param addressFormat - The address format to use.
|
|
22
|
+
* Only relevant for Bitcoin Cash and eCash networks, where:
|
|
23
|
+
* - "default" means base58check,
|
|
24
|
+
* - "cashaddr" means cashaddr.
|
|
25
|
+
*/
|
|
26
|
+
function address(keys, chain, index, network, addressFormat) {
|
|
27
|
+
const walletKeys = RootWalletKeys_js_1.RootWalletKeys.from(keys);
|
|
28
|
+
return wasm_utxo_js_1.FixedScriptWalletNamespace.address(walletKeys.wasm, chain, index, network, addressFormat);
|
|
29
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { RootWalletKeys, type WalletKeysArg, type IWalletKeys } from "./RootWalletKeys.js";
|
|
2
|
+
export { ReplayProtection, type ReplayProtectionArg } from "./ReplayProtection.js";
|
|
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";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BitGoPsbt = exports.address = exports.outputScript = exports.ReplayProtection = exports.RootWalletKeys = void 0;
|
|
4
|
+
var RootWalletKeys_js_1 = require("./RootWalletKeys.js");
|
|
5
|
+
Object.defineProperty(exports, "RootWalletKeys", { enumerable: true, get: function () { return RootWalletKeys_js_1.RootWalletKeys; } });
|
|
6
|
+
var ReplayProtection_js_1 = require("./ReplayProtection.js");
|
|
7
|
+
Object.defineProperty(exports, "ReplayProtection", { enumerable: true, get: function () { return ReplayProtection_js_1.ReplayProtection; } });
|
|
8
|
+
var address_js_1 = require("./address.js");
|
|
9
|
+
Object.defineProperty(exports, "outputScript", { enumerable: true, get: function () { return address_js_1.outputScript; } });
|
|
10
|
+
Object.defineProperty(exports, "address", { enumerable: true, get: function () { return address_js_1.address; } });
|
|
11
|
+
var BitGoPsbt_js_1 = require("./BitGoPsbt.js");
|
|
12
|
+
Object.defineProperty(exports, "BitGoPsbt", { enumerable: true, get: function () { return BitGoPsbt_js_1.BitGoPsbt; } });
|
package/dist/cjs/js/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export * as address from "./address.js";
|
|
2
2
|
export * as ast from "./ast/index.js";
|
|
3
3
|
export * as utxolibCompat from "./utxolibCompat.js";
|
|
4
|
-
export * as fixedScriptWallet from "./fixedScriptWallet.js";
|
|
4
|
+
export * as fixedScriptWallet from "./fixedScriptWallet/index.js";
|
|
5
|
+
export * as bip32 from "./bip32.js";
|
|
6
|
+
export * as ecpair from "./ecpair.js";
|
|
7
|
+
export { ECPair } from "./ecpair.js";
|
|
8
|
+
export { BIP32 } from "./bip32.js";
|
|
5
9
|
export type { CoinName } from "./coinName.js";
|
|
6
10
|
export type { Triple } from "./triple.js";
|
|
7
11
|
export type { AddressFormat } from "./address.js";
|