@bitgo/wasm-utxo 1.20.0 → 1.22.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/bip322/index.d.ts +236 -0
- package/dist/cjs/js/bip322/index.js +193 -0
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +2 -1
- package/dist/cjs/js/fixedScriptWallet/index.d.ts +30 -1
- package/dist/cjs/js/fixedScriptWallet/index.js +30 -0
- package/dist/cjs/js/fixedScriptWallet/scriptType.d.ts +17 -0
- package/dist/cjs/js/fixedScriptWallet/scriptType.js +2 -0
- package/dist/cjs/js/index.d.ts +1 -0
- package/dist/cjs/js/index.js +2 -1
- package/dist/cjs/js/wasm/wasm_utxo.d.ts +116 -0
- package/dist/cjs/js/wasm/wasm_utxo.js +336 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +17 -10
- package/dist/esm/js/bip322/index.d.ts +236 -0
- package/dist/esm/js/bip322/index.js +186 -0
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +2 -1
- package/dist/esm/js/fixedScriptWallet/index.d.ts +30 -1
- package/dist/esm/js/fixedScriptWallet/index.js +29 -0
- package/dist/esm/js/fixedScriptWallet/scriptType.d.ts +17 -0
- package/dist/esm/js/fixedScriptWallet/scriptType.js +1 -0
- package/dist/esm/js/index.d.ts +1 -0
- package/dist/esm/js/index.js +1 -0
- package/dist/esm/js/wasm/wasm_utxo.d.ts +116 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.js +335 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +17 -10
- package/package.json +1 -1
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BIP-0322 Generic Signed Message Format
|
|
3
|
+
*
|
|
4
|
+
* This module implements BIP-0322 for BitGo fixed-script wallets.
|
|
5
|
+
* It allows proving control of wallet addresses by signing arbitrary messages.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { bip322, fixedScriptWallet } from '@bitgo/wasm-utxo';
|
|
10
|
+
*
|
|
11
|
+
* // Create wallet keys
|
|
12
|
+
* const walletKeys = fixedScriptWallet.RootWalletKeys.from([userXpub, backupXpub, bitgoXpub]);
|
|
13
|
+
*
|
|
14
|
+
* // Create an empty PSBT for BIP-0322 (version 0 required)
|
|
15
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys, { version: 0 });
|
|
16
|
+
*
|
|
17
|
+
* // Add BIP-0322 inputs
|
|
18
|
+
* const idx0 = bip322.addBip322Input(psbt, {
|
|
19
|
+
* message: "Hello, World!",
|
|
20
|
+
* scriptId: { chain: 10, index: 0 },
|
|
21
|
+
* rootWalletKeys: walletKeys,
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Sign the input
|
|
25
|
+
* psbt.sign(idx0, userXpriv);
|
|
26
|
+
* psbt.sign(idx0, bitgoXpriv);
|
|
27
|
+
*
|
|
28
|
+
* // Verify the input
|
|
29
|
+
* bip322.verifyBip322PsbtInput(psbt, idx0, {
|
|
30
|
+
* message: "Hello, World!",
|
|
31
|
+
* scriptId: { chain: 10, index: 0 },
|
|
32
|
+
* rootWalletKeys: walletKeys,
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
import { BitGoPsbt, type NetworkName, type ScriptId, type SignPath } from "../fixedScriptWallet/BitGoPsbt.js";
|
|
37
|
+
import { type WalletKeysArg } from "../fixedScriptWallet/RootWalletKeys.js";
|
|
38
|
+
import { type OutputScriptType } from "../fixedScriptWallet/scriptType.js";
|
|
39
|
+
import { Transaction } from "../transaction.js";
|
|
40
|
+
export type { OutputScriptType };
|
|
41
|
+
/**
|
|
42
|
+
* Parameters for adding a BIP-0322 input to a PSBT
|
|
43
|
+
*/
|
|
44
|
+
export type AddBip322InputParams = {
|
|
45
|
+
/** The message to sign (UTF-8 string) */
|
|
46
|
+
message: string;
|
|
47
|
+
/** The wallet script location (chain and index) */
|
|
48
|
+
scriptId: ScriptId;
|
|
49
|
+
/** The wallet's root keys */
|
|
50
|
+
rootWalletKeys: WalletKeysArg;
|
|
51
|
+
/**
|
|
52
|
+
* Sign path for taproot inputs (required for p2tr/p2trMusig2).
|
|
53
|
+
* Specifies which two keys will sign the message.
|
|
54
|
+
*/
|
|
55
|
+
signPath?: SignPath;
|
|
56
|
+
/** Custom tag for message hashing (default: "BIP0322-signed-message") */
|
|
57
|
+
tag?: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Parameters for verifying a BIP-0322 input
|
|
61
|
+
*/
|
|
62
|
+
export type VerifyBip322InputParams = {
|
|
63
|
+
/** The message that was signed */
|
|
64
|
+
message: string;
|
|
65
|
+
/** The wallet script location (chain and index) */
|
|
66
|
+
scriptId: ScriptId;
|
|
67
|
+
/** The wallet's root keys */
|
|
68
|
+
rootWalletKeys: WalletKeysArg;
|
|
69
|
+
/** Custom tag if one was used during signing */
|
|
70
|
+
tag?: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Parameters for verifying a BIP-0322 transaction input
|
|
74
|
+
*/
|
|
75
|
+
export type VerifyBip322TxInputParams = VerifyBip322InputParams & {
|
|
76
|
+
/** Network name (default: "bitcoin") */
|
|
77
|
+
network?: NetworkName;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Add a BIP-0322 message input to an existing BitGoPsbt
|
|
81
|
+
*
|
|
82
|
+
* The PSBT must have version 0 per BIP-0322 specification. Use
|
|
83
|
+
* `BitGoPsbt.createEmpty(network, walletKeys, { version: 0 })` to create one.
|
|
84
|
+
*
|
|
85
|
+
* On the first input added, this also adds the required OP_RETURN output.
|
|
86
|
+
*
|
|
87
|
+
* @param psbt - The BitGoPsbt to add the input to (must have version 0)
|
|
88
|
+
* @param params - Input parameters including message, scriptId, and wallet keys
|
|
89
|
+
* @returns The index of the added input
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // Create a BIP-0322 PSBT
|
|
94
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys, { version: 0 });
|
|
95
|
+
*
|
|
96
|
+
* // Add inputs
|
|
97
|
+
* const idx0 = bip322.addBip322Input(psbt, {
|
|
98
|
+
* message: "I control this address",
|
|
99
|
+
* scriptId: { chain: 10, index: 5 },
|
|
100
|
+
* rootWalletKeys: walletKeys,
|
|
101
|
+
* });
|
|
102
|
+
*
|
|
103
|
+
* // Sign with user and bitgo keys
|
|
104
|
+
* psbt.sign(idx0, userXpriv);
|
|
105
|
+
* psbt.sign(idx0, bitgoXpriv);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare function addBip322Input(psbt: BitGoPsbt, params: AddBip322InputParams): number;
|
|
109
|
+
/**
|
|
110
|
+
* Verify a single input of a BIP-0322 transaction proof
|
|
111
|
+
*
|
|
112
|
+
* This verifies that the specified input correctly proves control of the
|
|
113
|
+
* wallet address corresponding to the given message.
|
|
114
|
+
*
|
|
115
|
+
* @param tx - The signed transaction
|
|
116
|
+
* @param inputIndex - The index of the input to verify
|
|
117
|
+
* @param params - Verification parameters including message, scriptId, and wallet keys
|
|
118
|
+
* @throws Error if verification fails
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* // Extract and verify the transaction
|
|
123
|
+
* psbt.finalizeAllInputs();
|
|
124
|
+
* const txBytes = psbt.extractTransaction();
|
|
125
|
+
* const tx = Transaction.fromBytes(txBytes, "bitcoin");
|
|
126
|
+
*
|
|
127
|
+
* bip322.verifyBip322TxInput(tx, 0, {
|
|
128
|
+
* message: "Hello, World!",
|
|
129
|
+
* scriptId: { chain: 10, index: 0 },
|
|
130
|
+
* rootWalletKeys: walletKeys,
|
|
131
|
+
* network: "bitcoin",
|
|
132
|
+
* });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare function verifyBip322TxInput(tx: Transaction, inputIndex: number, params: VerifyBip322TxInputParams): void;
|
|
136
|
+
/** Signer key name */
|
|
137
|
+
export type SignerName = "user" | "backup" | "bitgo";
|
|
138
|
+
/** Triple of hex-encoded pubkeys [user, backup, bitgo] */
|
|
139
|
+
export type PubkeyTriple = [string, string, string];
|
|
140
|
+
/**
|
|
141
|
+
* Parameters for verifying a BIP-0322 input with pubkeys
|
|
142
|
+
*/
|
|
143
|
+
export type VerifyBip322WithPubkeysParams = {
|
|
144
|
+
/** The message that was signed */
|
|
145
|
+
message: string;
|
|
146
|
+
/** Hex-encoded pubkeys [user, backup, bitgo] */
|
|
147
|
+
pubkeys: PubkeyTriple;
|
|
148
|
+
/** Script type */
|
|
149
|
+
scriptType: OutputScriptType;
|
|
150
|
+
/** For taproot types, whether script path was used */
|
|
151
|
+
isScriptPath?: boolean;
|
|
152
|
+
/** Custom tag if one was used during signing */
|
|
153
|
+
tag?: string;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Parameters for verifying a BIP-0322 transaction input with pubkeys
|
|
157
|
+
*/
|
|
158
|
+
export type VerifyBip322TxWithPubkeysParams = VerifyBip322WithPubkeysParams;
|
|
159
|
+
/**
|
|
160
|
+
* Verify a single input of a BIP-0322 PSBT proof
|
|
161
|
+
*
|
|
162
|
+
* This verifies that the specified input correctly proves control of the
|
|
163
|
+
* wallet address by checking:
|
|
164
|
+
* - The PSBT structure follows BIP-0322 (version 0, OP_RETURN output)
|
|
165
|
+
* - The input references the correct virtual to_spend transaction
|
|
166
|
+
* - At least one valid signature exists from the wallet keys
|
|
167
|
+
*
|
|
168
|
+
* @param psbt - The signed PSBT
|
|
169
|
+
* @param inputIndex - The index of the input to verify
|
|
170
|
+
* @param params - Verification parameters including message, scriptId, and wallet keys
|
|
171
|
+
* @returns An array of signer names ("user", "backup", "bitgo") that have valid signatures
|
|
172
|
+
* @throws Error if verification fails or no valid signatures found
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* // Verify the signed PSBT input
|
|
177
|
+
* const signers = bip322.verifyBip322PsbtInput(psbt, 0, {
|
|
178
|
+
* message: "Hello, World!",
|
|
179
|
+
* scriptId: { chain: 10, index: 0 },
|
|
180
|
+
* rootWalletKeys: walletKeys,
|
|
181
|
+
* });
|
|
182
|
+
* console.log(signers); // ["user", "bitgo"]
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
export declare function verifyBip322PsbtInput(psbt: BitGoPsbt, inputIndex: number, params: VerifyBip322InputParams): SignerName[];
|
|
186
|
+
/**
|
|
187
|
+
* Verify a single input of a BIP-0322 PSBT proof using pubkeys directly
|
|
188
|
+
*
|
|
189
|
+
* This verifies that the specified input correctly proves control of the
|
|
190
|
+
* wallet address by checking:
|
|
191
|
+
* - The PSBT structure follows BIP-0322 (version 0, OP_RETURN output)
|
|
192
|
+
* - The input references the correct virtual to_spend transaction
|
|
193
|
+
* - At least one valid signature exists from the provided pubkeys
|
|
194
|
+
*
|
|
195
|
+
* @param psbt - The signed PSBT
|
|
196
|
+
* @param inputIndex - The index of the input to verify
|
|
197
|
+
* @param params - Verification parameters including message, pubkeys, and script type
|
|
198
|
+
* @returns An array of pubkey indices (0, 1, 2) that have valid signatures
|
|
199
|
+
* @throws Error if verification fails or no valid signatures found
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* // Verify the signed PSBT input with pubkeys
|
|
204
|
+
* const signerIndices = bip322.verifyBip322PsbtInputWithPubkeys(psbt, 0, {
|
|
205
|
+
* message: "Hello, World!",
|
|
206
|
+
* pubkeys: [userPubkey, backupPubkey, bitgoPubkey],
|
|
207
|
+
* scriptType: "p2shP2wsh",
|
|
208
|
+
* });
|
|
209
|
+
* console.log(signerIndices); // [0, 2] for user+bitgo
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export declare function verifyBip322PsbtInputWithPubkeys(psbt: BitGoPsbt, inputIndex: number, params: VerifyBip322WithPubkeysParams): number[];
|
|
213
|
+
/**
|
|
214
|
+
* Verify a single input of a BIP-0322 transaction proof using pubkeys directly
|
|
215
|
+
*
|
|
216
|
+
* This verifies that the specified input correctly proves control of the
|
|
217
|
+
* wallet address corresponding to the given message.
|
|
218
|
+
*
|
|
219
|
+
* @param tx - The signed transaction
|
|
220
|
+
* @param inputIndex - The index of the input to verify
|
|
221
|
+
* @param params - Verification parameters including message, pubkeys, and script type
|
|
222
|
+
* @returns An array of pubkey indices (0, 1, 2) that have valid signatures
|
|
223
|
+
* @throws Error if verification fails
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* // Verify the signed transaction input with pubkeys
|
|
228
|
+
* const signerIndices = bip322.verifyBip322TxInputWithPubkeys(tx, 0, {
|
|
229
|
+
* message: "Hello, World!",
|
|
230
|
+
* pubkeys: [userPubkey, backupPubkey, bitgoPubkey],
|
|
231
|
+
* scriptType: "p2wsh",
|
|
232
|
+
* });
|
|
233
|
+
* console.log(signerIndices); // [0, 2] for user+bitgo
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
export declare function verifyBip322TxInputWithPubkeys(tx: Transaction, inputIndex: number, params: VerifyBip322TxWithPubkeysParams): number[];
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BIP-0322 Generic Signed Message Format
|
|
4
|
+
*
|
|
5
|
+
* This module implements BIP-0322 for BitGo fixed-script wallets.
|
|
6
|
+
* It allows proving control of wallet addresses by signing arbitrary messages.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { bip322, fixedScriptWallet } from '@bitgo/wasm-utxo';
|
|
11
|
+
*
|
|
12
|
+
* // Create wallet keys
|
|
13
|
+
* const walletKeys = fixedScriptWallet.RootWalletKeys.from([userXpub, backupXpub, bitgoXpub]);
|
|
14
|
+
*
|
|
15
|
+
* // Create an empty PSBT for BIP-0322 (version 0 required)
|
|
16
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys, { version: 0 });
|
|
17
|
+
*
|
|
18
|
+
* // Add BIP-0322 inputs
|
|
19
|
+
* const idx0 = bip322.addBip322Input(psbt, {
|
|
20
|
+
* message: "Hello, World!",
|
|
21
|
+
* scriptId: { chain: 10, index: 0 },
|
|
22
|
+
* rootWalletKeys: walletKeys,
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Sign the input
|
|
26
|
+
* psbt.sign(idx0, userXpriv);
|
|
27
|
+
* psbt.sign(idx0, bitgoXpriv);
|
|
28
|
+
*
|
|
29
|
+
* // Verify the input
|
|
30
|
+
* bip322.verifyBip322PsbtInput(psbt, idx0, {
|
|
31
|
+
* message: "Hello, World!",
|
|
32
|
+
* scriptId: { chain: 10, index: 0 },
|
|
33
|
+
* rootWalletKeys: walletKeys,
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.addBip322Input = addBip322Input;
|
|
39
|
+
exports.verifyBip322TxInput = verifyBip322TxInput;
|
|
40
|
+
exports.verifyBip322PsbtInput = verifyBip322PsbtInput;
|
|
41
|
+
exports.verifyBip322PsbtInputWithPubkeys = verifyBip322PsbtInputWithPubkeys;
|
|
42
|
+
exports.verifyBip322TxInputWithPubkeys = verifyBip322TxInputWithPubkeys;
|
|
43
|
+
const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
|
|
44
|
+
const RootWalletKeys_js_1 = require("../fixedScriptWallet/RootWalletKeys.js");
|
|
45
|
+
/**
|
|
46
|
+
* Add a BIP-0322 message input to an existing BitGoPsbt
|
|
47
|
+
*
|
|
48
|
+
* The PSBT must have version 0 per BIP-0322 specification. Use
|
|
49
|
+
* `BitGoPsbt.createEmpty(network, walletKeys, { version: 0 })` to create one.
|
|
50
|
+
*
|
|
51
|
+
* On the first input added, this also adds the required OP_RETURN output.
|
|
52
|
+
*
|
|
53
|
+
* @param psbt - The BitGoPsbt to add the input to (must have version 0)
|
|
54
|
+
* @param params - Input parameters including message, scriptId, and wallet keys
|
|
55
|
+
* @returns The index of the added input
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* // Create a BIP-0322 PSBT
|
|
60
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys, { version: 0 });
|
|
61
|
+
*
|
|
62
|
+
* // Add inputs
|
|
63
|
+
* const idx0 = bip322.addBip322Input(psbt, {
|
|
64
|
+
* message: "I control this address",
|
|
65
|
+
* scriptId: { chain: 10, index: 5 },
|
|
66
|
+
* rootWalletKeys: walletKeys,
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // Sign with user and bitgo keys
|
|
70
|
+
* psbt.sign(idx0, userXpriv);
|
|
71
|
+
* psbt.sign(idx0, bitgoXpriv);
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
function addBip322Input(psbt, params) {
|
|
75
|
+
const keys = RootWalletKeys_js_1.RootWalletKeys.from(params.rootWalletKeys);
|
|
76
|
+
return wasm_utxo_js_1.Bip322Namespace.add_bip322_input(psbt.wasm, params.message, params.scriptId.chain, params.scriptId.index, keys.wasm, params.signPath?.signer, params.signPath?.cosigner, params.tag);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Verify a single input of a BIP-0322 transaction proof
|
|
80
|
+
*
|
|
81
|
+
* This verifies that the specified input correctly proves control of the
|
|
82
|
+
* wallet address corresponding to the given message.
|
|
83
|
+
*
|
|
84
|
+
* @param tx - The signed transaction
|
|
85
|
+
* @param inputIndex - The index of the input to verify
|
|
86
|
+
* @param params - Verification parameters including message, scriptId, and wallet keys
|
|
87
|
+
* @throws Error if verification fails
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* // Extract and verify the transaction
|
|
92
|
+
* psbt.finalizeAllInputs();
|
|
93
|
+
* const txBytes = psbt.extractTransaction();
|
|
94
|
+
* const tx = Transaction.fromBytes(txBytes, "bitcoin");
|
|
95
|
+
*
|
|
96
|
+
* bip322.verifyBip322TxInput(tx, 0, {
|
|
97
|
+
* message: "Hello, World!",
|
|
98
|
+
* scriptId: { chain: 10, index: 0 },
|
|
99
|
+
* rootWalletKeys: walletKeys,
|
|
100
|
+
* network: "bitcoin",
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
function verifyBip322TxInput(tx, inputIndex, params) {
|
|
105
|
+
const keys = RootWalletKeys_js_1.RootWalletKeys.from(params.rootWalletKeys);
|
|
106
|
+
const network = params.network ?? "bitcoin";
|
|
107
|
+
wasm_utxo_js_1.Bip322Namespace.verify_bip322_tx_input(tx.wasm, inputIndex, params.message, params.scriptId.chain, params.scriptId.index, keys.wasm, network, params.tag);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Verify a single input of a BIP-0322 PSBT proof
|
|
111
|
+
*
|
|
112
|
+
* This verifies that the specified input correctly proves control of the
|
|
113
|
+
* wallet address by checking:
|
|
114
|
+
* - The PSBT structure follows BIP-0322 (version 0, OP_RETURN output)
|
|
115
|
+
* - The input references the correct virtual to_spend transaction
|
|
116
|
+
* - At least one valid signature exists from the wallet keys
|
|
117
|
+
*
|
|
118
|
+
* @param psbt - The signed PSBT
|
|
119
|
+
* @param inputIndex - The index of the input to verify
|
|
120
|
+
* @param params - Verification parameters including message, scriptId, and wallet keys
|
|
121
|
+
* @returns An array of signer names ("user", "backup", "bitgo") that have valid signatures
|
|
122
|
+
* @throws Error if verification fails or no valid signatures found
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* // Verify the signed PSBT input
|
|
127
|
+
* const signers = bip322.verifyBip322PsbtInput(psbt, 0, {
|
|
128
|
+
* message: "Hello, World!",
|
|
129
|
+
* scriptId: { chain: 10, index: 0 },
|
|
130
|
+
* rootWalletKeys: walletKeys,
|
|
131
|
+
* });
|
|
132
|
+
* console.log(signers); // ["user", "bitgo"]
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
function verifyBip322PsbtInput(psbt, inputIndex, params) {
|
|
136
|
+
const keys = RootWalletKeys_js_1.RootWalletKeys.from(params.rootWalletKeys);
|
|
137
|
+
return wasm_utxo_js_1.Bip322Namespace.verify_bip322_psbt_input(psbt.wasm, inputIndex, params.message, params.scriptId.chain, params.scriptId.index, keys.wasm, params.tag);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Verify a single input of a BIP-0322 PSBT proof using pubkeys directly
|
|
141
|
+
*
|
|
142
|
+
* This verifies that the specified input correctly proves control of the
|
|
143
|
+
* wallet address by checking:
|
|
144
|
+
* - The PSBT structure follows BIP-0322 (version 0, OP_RETURN output)
|
|
145
|
+
* - The input references the correct virtual to_spend transaction
|
|
146
|
+
* - At least one valid signature exists from the provided pubkeys
|
|
147
|
+
*
|
|
148
|
+
* @param psbt - The signed PSBT
|
|
149
|
+
* @param inputIndex - The index of the input to verify
|
|
150
|
+
* @param params - Verification parameters including message, pubkeys, and script type
|
|
151
|
+
* @returns An array of pubkey indices (0, 1, 2) that have valid signatures
|
|
152
|
+
* @throws Error if verification fails or no valid signatures found
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* // Verify the signed PSBT input with pubkeys
|
|
157
|
+
* const signerIndices = bip322.verifyBip322PsbtInputWithPubkeys(psbt, 0, {
|
|
158
|
+
* message: "Hello, World!",
|
|
159
|
+
* pubkeys: [userPubkey, backupPubkey, bitgoPubkey],
|
|
160
|
+
* scriptType: "p2shP2wsh",
|
|
161
|
+
* });
|
|
162
|
+
* console.log(signerIndices); // [0, 2] for user+bitgo
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
function verifyBip322PsbtInputWithPubkeys(psbt, inputIndex, params) {
|
|
166
|
+
return Array.from(wasm_utxo_js_1.Bip322Namespace.verify_bip322_psbt_input_with_pubkeys(psbt.wasm, inputIndex, params.message, params.pubkeys, params.scriptType, params.isScriptPath, params.tag));
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Verify a single input of a BIP-0322 transaction proof using pubkeys directly
|
|
170
|
+
*
|
|
171
|
+
* This verifies that the specified input correctly proves control of the
|
|
172
|
+
* wallet address corresponding to the given message.
|
|
173
|
+
*
|
|
174
|
+
* @param tx - The signed transaction
|
|
175
|
+
* @param inputIndex - The index of the input to verify
|
|
176
|
+
* @param params - Verification parameters including message, pubkeys, and script type
|
|
177
|
+
* @returns An array of pubkey indices (0, 1, 2) that have valid signatures
|
|
178
|
+
* @throws Error if verification fails
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* // Verify the signed transaction input with pubkeys
|
|
183
|
+
* const signerIndices = bip322.verifyBip322TxInputWithPubkeys(tx, 0, {
|
|
184
|
+
* message: "Hello, World!",
|
|
185
|
+
* pubkeys: [userPubkey, backupPubkey, bitgoPubkey],
|
|
186
|
+
* scriptType: "p2wsh",
|
|
187
|
+
* });
|
|
188
|
+
* console.log(signerIndices); // [0, 2] for user+bitgo
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
function verifyBip322TxInputWithPubkeys(tx, inputIndex, params) {
|
|
192
|
+
return Array.from(wasm_utxo_js_1.Bip322Namespace.verify_bip322_tx_input_with_pubkeys(tx.wasm, inputIndex, params.message, params.pubkeys, params.scriptType, params.isScriptPath, params.tag));
|
|
193
|
+
}
|
|
@@ -5,12 +5,13 @@ import { type BIP32Arg } from "../bip32.js";
|
|
|
5
5
|
import { type ECPairArg } from "../ecpair.js";
|
|
6
6
|
import type { UtxolibName } from "../utxolibCompat.js";
|
|
7
7
|
import type { CoinName } from "../coinName.js";
|
|
8
|
+
import type { InputScriptType } from "./scriptType.js";
|
|
9
|
+
export type { InputScriptType };
|
|
8
10
|
export type NetworkName = UtxolibName | CoinName;
|
|
9
11
|
export type ScriptId = {
|
|
10
12
|
chain: number;
|
|
11
13
|
index: number;
|
|
12
14
|
};
|
|
13
|
-
export type InputScriptType = "p2shP2pk" | "p2sh" | "p2shP2wsh" | "p2wsh" | "p2trLegacy" | "p2trMusig2ScriptPath" | "p2trMusig2KeyPath";
|
|
14
15
|
export type OutPoint = {
|
|
15
16
|
txid: string;
|
|
16
17
|
vout: number;
|
|
@@ -1,6 +1,35 @@
|
|
|
1
|
+
import type { CoinName } from "../coinName.js";
|
|
1
2
|
export { RootWalletKeys, type WalletKeysArg, type IWalletKeys } from "./RootWalletKeys.js";
|
|
2
3
|
export { ReplayProtection, type ReplayProtectionArg } from "./ReplayProtection.js";
|
|
3
4
|
export { outputScript, address } from "./address.js";
|
|
4
5
|
export { Dimensions } from "./Dimensions.js";
|
|
5
|
-
export {
|
|
6
|
+
export { type OutputScriptType, type InputScriptType, type ScriptType } from "./scriptType.js";
|
|
7
|
+
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";
|
|
6
8
|
export { ZcashBitGoPsbt, type ZcashNetworkName, type CreateEmptyZcashOptions, } from "./ZcashBitGoPsbt.js";
|
|
9
|
+
import type { ScriptType } from "./scriptType.js";
|
|
10
|
+
/**
|
|
11
|
+
* Check if a network supports a given fixed-script wallet script type
|
|
12
|
+
*
|
|
13
|
+
* @param coin - Coin name (e.g., "btc", "ltc", "doge")
|
|
14
|
+
* @param scriptType - Output script type or input script type to check
|
|
15
|
+
* @returns `true` if the network supports the script type, `false` otherwise
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Bitcoin supports all script types
|
|
20
|
+
* supportsScriptType("btc", "p2tr"); // true
|
|
21
|
+
*
|
|
22
|
+
* // Litecoin supports segwit but not taproot
|
|
23
|
+
* supportsScriptType("ltc", "p2wsh"); // true
|
|
24
|
+
* supportsScriptType("ltc", "p2tr"); // false
|
|
25
|
+
*
|
|
26
|
+
* // Dogecoin only supports legacy scripts
|
|
27
|
+
* supportsScriptType("doge", "p2sh"); // true
|
|
28
|
+
* supportsScriptType("doge", "p2wsh"); // false
|
|
29
|
+
*
|
|
30
|
+
* // Also works with input script types
|
|
31
|
+
* supportsScriptType("btc", "p2trMusig2KeyPath"); // true
|
|
32
|
+
* supportsScriptType("doge", "p2trLegacy"); // false
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function supportsScriptType(coin: CoinName, scriptType: ScriptType): boolean;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ZcashBitGoPsbt = exports.BitGoPsbt = exports.Dimensions = exports.address = exports.outputScript = exports.ReplayProtection = exports.RootWalletKeys = void 0;
|
|
4
|
+
exports.supportsScriptType = supportsScriptType;
|
|
5
|
+
const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
|
|
4
6
|
var RootWalletKeys_js_1 = require("./RootWalletKeys.js");
|
|
5
7
|
Object.defineProperty(exports, "RootWalletKeys", { enumerable: true, get: function () { return RootWalletKeys_js_1.RootWalletKeys; } });
|
|
6
8
|
var ReplayProtection_js_1 = require("./ReplayProtection.js");
|
|
@@ -16,3 +18,31 @@ Object.defineProperty(exports, "BitGoPsbt", { enumerable: true, get: function ()
|
|
|
16
18
|
// Zcash-specific PSBT subclass
|
|
17
19
|
var ZcashBitGoPsbt_js_1 = require("./ZcashBitGoPsbt.js");
|
|
18
20
|
Object.defineProperty(exports, "ZcashBitGoPsbt", { enumerable: true, get: function () { return ZcashBitGoPsbt_js_1.ZcashBitGoPsbt; } });
|
|
21
|
+
/**
|
|
22
|
+
* Check if a network supports a given fixed-script wallet script type
|
|
23
|
+
*
|
|
24
|
+
* @param coin - Coin name (e.g., "btc", "ltc", "doge")
|
|
25
|
+
* @param scriptType - Output script type or input script type to check
|
|
26
|
+
* @returns `true` if the network supports the script type, `false` otherwise
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // Bitcoin supports all script types
|
|
31
|
+
* supportsScriptType("btc", "p2tr"); // true
|
|
32
|
+
*
|
|
33
|
+
* // Litecoin supports segwit but not taproot
|
|
34
|
+
* supportsScriptType("ltc", "p2wsh"); // true
|
|
35
|
+
* supportsScriptType("ltc", "p2tr"); // false
|
|
36
|
+
*
|
|
37
|
+
* // Dogecoin only supports legacy scripts
|
|
38
|
+
* supportsScriptType("doge", "p2sh"); // true
|
|
39
|
+
* supportsScriptType("doge", "p2wsh"); // false
|
|
40
|
+
*
|
|
41
|
+
* // Also works with input script types
|
|
42
|
+
* supportsScriptType("btc", "p2trMusig2KeyPath"); // true
|
|
43
|
+
* supportsScriptType("doge", "p2trLegacy"); // false
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
function supportsScriptType(coin, scriptType) {
|
|
47
|
+
return wasm_utxo_js_1.FixedScriptWalletNamespace.supports_script_type(coin, scriptType);
|
|
48
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed-script wallet output script types (2-of-3 multisig)
|
|
3
|
+
*
|
|
4
|
+
* This type represents the abstract script type, independent of chain (external/internal).
|
|
5
|
+
* Use this for checking network support or when you need the script type without derivation info.
|
|
6
|
+
*/
|
|
7
|
+
export type OutputScriptType = "p2sh" | "p2shP2wsh" | "p2wsh" | "p2tr" | "p2trLegacy" | "p2trMusig2";
|
|
8
|
+
/**
|
|
9
|
+
* Input script types for fixed-script wallets
|
|
10
|
+
*
|
|
11
|
+
* These are more specific than output types and include single-sig and taproot variants.
|
|
12
|
+
*/
|
|
13
|
+
export type InputScriptType = "p2shP2pk" | "p2sh" | "p2shP2wsh" | "p2wsh" | "p2trLegacy" | "p2trMusig2ScriptPath" | "p2trMusig2KeyPath";
|
|
14
|
+
/**
|
|
15
|
+
* Union of all script types that can be checked for network support
|
|
16
|
+
*/
|
|
17
|
+
export type ScriptType = OutputScriptType | InputScriptType;
|
package/dist/cjs/js/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * as address from "./address.js";
|
|
2
2
|
export * as ast from "./ast/index.js";
|
|
3
|
+
export * as bip322 from "./bip322/index.js";
|
|
3
4
|
export * as utxolibCompat from "./utxolibCompat.js";
|
|
4
5
|
export * as fixedScriptWallet from "./fixedScriptWallet/index.js";
|
|
5
6
|
export * as bip32 from "./bip32.js";
|
package/dist/cjs/js/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ZcashTransaction = exports.Transaction = exports.DashTransaction = exports.Psbt = exports.Miniscript = exports.Descriptor = exports.Dimensions = exports.BIP32 = exports.ECPair = exports.ecpair = exports.bip32 = exports.fixedScriptWallet = exports.utxolibCompat = exports.ast = exports.address = void 0;
|
|
36
|
+
exports.ZcashTransaction = exports.Transaction = exports.DashTransaction = exports.Psbt = exports.Miniscript = exports.Descriptor = exports.Dimensions = exports.BIP32 = exports.ECPair = exports.ecpair = exports.bip32 = exports.fixedScriptWallet = exports.utxolibCompat = exports.bip322 = exports.ast = exports.address = void 0;
|
|
37
37
|
const wasm = __importStar(require("./wasm/wasm_utxo.js"));
|
|
38
38
|
// we need to access the wasm module here, otherwise webpack gets all weird
|
|
39
39
|
// and forgets to include it in the bundle
|
|
@@ -42,6 +42,7 @@ void wasm;
|
|
|
42
42
|
// and to make imports more explicit (e.g., `import { address } from '@bitgo/wasm-utxo'`)
|
|
43
43
|
exports.address = __importStar(require("./address.js"));
|
|
44
44
|
exports.ast = __importStar(require("./ast/index.js"));
|
|
45
|
+
exports.bip322 = __importStar(require("./bip322/index.js"));
|
|
45
46
|
exports.utxolibCompat = __importStar(require("./utxolibCompat.js"));
|
|
46
47
|
exports.fixedScriptWallet = __importStar(require("./fixedScriptWallet/index.js"));
|
|
47
48
|
exports.bip32 = __importStar(require("./bip32.js"));
|