@bitgo/wasm-utxo 1.21.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/index.d.ts +1 -0
- package/dist/cjs/js/index.js +2 -1
- package/dist/cjs/js/wasm/wasm_utxo.d.ts +100 -0
- package/dist/cjs/js/wasm/wasm_utxo.js +299 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +64 -58
- package/dist/esm/js/bip322/index.d.ts +236 -0
- package/dist/esm/js/bip322/index.js +186 -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 +100 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.js +298 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +64 -58
- 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,186 @@
|
|
|
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 { Bip322Namespace } from "../wasm/wasm_utxo.js";
|
|
37
|
+
import { RootWalletKeys } from "../fixedScriptWallet/RootWalletKeys.js";
|
|
38
|
+
/**
|
|
39
|
+
* Add a BIP-0322 message input to an existing BitGoPsbt
|
|
40
|
+
*
|
|
41
|
+
* The PSBT must have version 0 per BIP-0322 specification. Use
|
|
42
|
+
* `BitGoPsbt.createEmpty(network, walletKeys, { version: 0 })` to create one.
|
|
43
|
+
*
|
|
44
|
+
* On the first input added, this also adds the required OP_RETURN output.
|
|
45
|
+
*
|
|
46
|
+
* @param psbt - The BitGoPsbt to add the input to (must have version 0)
|
|
47
|
+
* @param params - Input parameters including message, scriptId, and wallet keys
|
|
48
|
+
* @returns The index of the added input
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // Create a BIP-0322 PSBT
|
|
53
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys, { version: 0 });
|
|
54
|
+
*
|
|
55
|
+
* // Add inputs
|
|
56
|
+
* const idx0 = bip322.addBip322Input(psbt, {
|
|
57
|
+
* message: "I control this address",
|
|
58
|
+
* scriptId: { chain: 10, index: 5 },
|
|
59
|
+
* rootWalletKeys: walletKeys,
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // Sign with user and bitgo keys
|
|
63
|
+
* psbt.sign(idx0, userXpriv);
|
|
64
|
+
* psbt.sign(idx0, bitgoXpriv);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export function addBip322Input(psbt, params) {
|
|
68
|
+
const keys = RootWalletKeys.from(params.rootWalletKeys);
|
|
69
|
+
return Bip322Namespace.add_bip322_input(psbt.wasm, params.message, params.scriptId.chain, params.scriptId.index, keys.wasm, params.signPath?.signer, params.signPath?.cosigner, params.tag);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Verify a single input of a BIP-0322 transaction proof
|
|
73
|
+
*
|
|
74
|
+
* This verifies that the specified input correctly proves control of the
|
|
75
|
+
* wallet address corresponding to the given message.
|
|
76
|
+
*
|
|
77
|
+
* @param tx - The signed transaction
|
|
78
|
+
* @param inputIndex - The index of the input to verify
|
|
79
|
+
* @param params - Verification parameters including message, scriptId, and wallet keys
|
|
80
|
+
* @throws Error if verification fails
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // Extract and verify the transaction
|
|
85
|
+
* psbt.finalizeAllInputs();
|
|
86
|
+
* const txBytes = psbt.extractTransaction();
|
|
87
|
+
* const tx = Transaction.fromBytes(txBytes, "bitcoin");
|
|
88
|
+
*
|
|
89
|
+
* bip322.verifyBip322TxInput(tx, 0, {
|
|
90
|
+
* message: "Hello, World!",
|
|
91
|
+
* scriptId: { chain: 10, index: 0 },
|
|
92
|
+
* rootWalletKeys: walletKeys,
|
|
93
|
+
* network: "bitcoin",
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export function verifyBip322TxInput(tx, inputIndex, params) {
|
|
98
|
+
const keys = RootWalletKeys.from(params.rootWalletKeys);
|
|
99
|
+
const network = params.network ?? "bitcoin";
|
|
100
|
+
Bip322Namespace.verify_bip322_tx_input(tx.wasm, inputIndex, params.message, params.scriptId.chain, params.scriptId.index, keys.wasm, network, params.tag);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Verify a single input of a BIP-0322 PSBT proof
|
|
104
|
+
*
|
|
105
|
+
* This verifies that the specified input correctly proves control of the
|
|
106
|
+
* wallet address by checking:
|
|
107
|
+
* - The PSBT structure follows BIP-0322 (version 0, OP_RETURN output)
|
|
108
|
+
* - The input references the correct virtual to_spend transaction
|
|
109
|
+
* - At least one valid signature exists from the wallet keys
|
|
110
|
+
*
|
|
111
|
+
* @param psbt - The signed PSBT
|
|
112
|
+
* @param inputIndex - The index of the input to verify
|
|
113
|
+
* @param params - Verification parameters including message, scriptId, and wallet keys
|
|
114
|
+
* @returns An array of signer names ("user", "backup", "bitgo") that have valid signatures
|
|
115
|
+
* @throws Error if verification fails or no valid signatures found
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* // Verify the signed PSBT input
|
|
120
|
+
* const signers = bip322.verifyBip322PsbtInput(psbt, 0, {
|
|
121
|
+
* message: "Hello, World!",
|
|
122
|
+
* scriptId: { chain: 10, index: 0 },
|
|
123
|
+
* rootWalletKeys: walletKeys,
|
|
124
|
+
* });
|
|
125
|
+
* console.log(signers); // ["user", "bitgo"]
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export function verifyBip322PsbtInput(psbt, inputIndex, params) {
|
|
129
|
+
const keys = RootWalletKeys.from(params.rootWalletKeys);
|
|
130
|
+
return Bip322Namespace.verify_bip322_psbt_input(psbt.wasm, inputIndex, params.message, params.scriptId.chain, params.scriptId.index, keys.wasm, params.tag);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Verify a single input of a BIP-0322 PSBT proof using pubkeys directly
|
|
134
|
+
*
|
|
135
|
+
* This verifies that the specified input correctly proves control of the
|
|
136
|
+
* wallet address by checking:
|
|
137
|
+
* - The PSBT structure follows BIP-0322 (version 0, OP_RETURN output)
|
|
138
|
+
* - The input references the correct virtual to_spend transaction
|
|
139
|
+
* - At least one valid signature exists from the provided pubkeys
|
|
140
|
+
*
|
|
141
|
+
* @param psbt - The signed PSBT
|
|
142
|
+
* @param inputIndex - The index of the input to verify
|
|
143
|
+
* @param params - Verification parameters including message, pubkeys, and script type
|
|
144
|
+
* @returns An array of pubkey indices (0, 1, 2) that have valid signatures
|
|
145
|
+
* @throws Error if verification fails or no valid signatures found
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* // Verify the signed PSBT input with pubkeys
|
|
150
|
+
* const signerIndices = bip322.verifyBip322PsbtInputWithPubkeys(psbt, 0, {
|
|
151
|
+
* message: "Hello, World!",
|
|
152
|
+
* pubkeys: [userPubkey, backupPubkey, bitgoPubkey],
|
|
153
|
+
* scriptType: "p2shP2wsh",
|
|
154
|
+
* });
|
|
155
|
+
* console.log(signerIndices); // [0, 2] for user+bitgo
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export function verifyBip322PsbtInputWithPubkeys(psbt, inputIndex, params) {
|
|
159
|
+
return Array.from(Bip322Namespace.verify_bip322_psbt_input_with_pubkeys(psbt.wasm, inputIndex, params.message, params.pubkeys, params.scriptType, params.isScriptPath, params.tag));
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Verify a single input of a BIP-0322 transaction proof using pubkeys directly
|
|
163
|
+
*
|
|
164
|
+
* This verifies that the specified input correctly proves control of the
|
|
165
|
+
* wallet address corresponding to the given message.
|
|
166
|
+
*
|
|
167
|
+
* @param tx - The signed transaction
|
|
168
|
+
* @param inputIndex - The index of the input to verify
|
|
169
|
+
* @param params - Verification parameters including message, pubkeys, and script type
|
|
170
|
+
* @returns An array of pubkey indices (0, 1, 2) that have valid signatures
|
|
171
|
+
* @throws Error if verification fails
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* // Verify the signed transaction input with pubkeys
|
|
176
|
+
* const signerIndices = bip322.verifyBip322TxInputWithPubkeys(tx, 0, {
|
|
177
|
+
* message: "Hello, World!",
|
|
178
|
+
* pubkeys: [userPubkey, backupPubkey, bitgoPubkey],
|
|
179
|
+
* scriptType: "p2wsh",
|
|
180
|
+
* });
|
|
181
|
+
* console.log(signerIndices); // [0, 2] for user+bitgo
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
export function verifyBip322TxInputWithPubkeys(tx, inputIndex, params) {
|
|
185
|
+
return Array.from(Bip322Namespace.verify_bip322_tx_input_with_pubkeys(tx.wasm, inputIndex, params.message, params.pubkeys, params.scriptType, params.isScriptPath, params.tag));
|
|
186
|
+
}
|
package/dist/esm/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/esm/js/index.js
CHANGED
|
@@ -6,6 +6,7 @@ void wasm;
|
|
|
6
6
|
// and to make imports more explicit (e.g., `import { address } from '@bitgo/wasm-utxo'`)
|
|
7
7
|
export * as address from "./address.js";
|
|
8
8
|
export * as ast from "./ast/index.js";
|
|
9
|
+
export * as bip322 from "./bip322/index.js";
|
|
9
10
|
export * as utxolibCompat from "./utxolibCompat.js";
|
|
10
11
|
export * as fixedScriptWallet from "./fixedScriptWallet/index.js";
|
|
11
12
|
export * as bip32 from "./bip32.js";
|
|
@@ -9,6 +9,106 @@ export class AddressNamespace {
|
|
|
9
9
|
static from_output_script_with_coin(script: Uint8Array, coin: string, format?: string | null): string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
export class Bip322Namespace {
|
|
13
|
+
private constructor();
|
|
14
|
+
free(): void;
|
|
15
|
+
[Symbol.dispose](): void;
|
|
16
|
+
/**
|
|
17
|
+
* Add a BIP-0322 message input to an existing BitGoPsbt
|
|
18
|
+
*
|
|
19
|
+
* If this is the first input, also adds the OP_RETURN output.
|
|
20
|
+
* The PSBT must have version 0 per BIP-0322 specification.
|
|
21
|
+
*
|
|
22
|
+
* # Arguments
|
|
23
|
+
* * `psbt` - The BitGoPsbt to add the input to
|
|
24
|
+
* * `message` - The message to sign
|
|
25
|
+
* * `chain` - The wallet chain (e.g., 10 for external, 20 for internal)
|
|
26
|
+
* * `index` - The address index
|
|
27
|
+
* * `wallet_keys` - The wallet's root keys
|
|
28
|
+
* * `signer` - Optional signer key name for taproot (e.g., "user", "backup", "bitgo")
|
|
29
|
+
* * `cosigner` - Optional cosigner key name for taproot
|
|
30
|
+
* * `tag` - Optional custom tag for message hashing
|
|
31
|
+
*
|
|
32
|
+
* # Returns
|
|
33
|
+
* The index of the added input
|
|
34
|
+
*/
|
|
35
|
+
static add_bip322_input(psbt: BitGoPsbt, message: string, chain: number, index: number, wallet_keys: WasmRootWalletKeys, signer?: string | null, cosigner?: string | null, tag?: string | null): number;
|
|
36
|
+
/**
|
|
37
|
+
* Verify a single input of a BIP-0322 transaction proof
|
|
38
|
+
*
|
|
39
|
+
* # Arguments
|
|
40
|
+
* * `tx` - The signed transaction
|
|
41
|
+
* * `input_index` - The index of the input to verify
|
|
42
|
+
* * `message` - The message that was signed
|
|
43
|
+
* * `chain` - The wallet chain
|
|
44
|
+
* * `index` - The address index
|
|
45
|
+
* * `wallet_keys` - The wallet's root keys
|
|
46
|
+
* * `network` - Network name
|
|
47
|
+
* * `tag` - Optional custom tag for message hashing
|
|
48
|
+
*
|
|
49
|
+
* # Throws
|
|
50
|
+
* Throws an error if verification fails
|
|
51
|
+
*/
|
|
52
|
+
static verify_bip322_tx_input(tx: WasmTransaction, input_index: number, message: string, chain: number, index: number, wallet_keys: WasmRootWalletKeys, network: string, tag?: string | null): void;
|
|
53
|
+
/**
|
|
54
|
+
* Verify a single input of a BIP-0322 PSBT proof
|
|
55
|
+
*
|
|
56
|
+
* # Arguments
|
|
57
|
+
* * `psbt` - The signed BitGoPsbt
|
|
58
|
+
* * `input_index` - The index of the input to verify
|
|
59
|
+
* * `message` - The message that was signed
|
|
60
|
+
* * `chain` - The wallet chain
|
|
61
|
+
* * `index` - The address index
|
|
62
|
+
* * `wallet_keys` - The wallet's root keys
|
|
63
|
+
* * `tag` - Optional custom tag for message hashing
|
|
64
|
+
*
|
|
65
|
+
* # Returns
|
|
66
|
+
* An array of signer names ("user", "backup", "bitgo") that have valid signatures
|
|
67
|
+
*
|
|
68
|
+
* # Throws
|
|
69
|
+
* Throws an error if verification fails or no valid signatures found
|
|
70
|
+
*/
|
|
71
|
+
static verify_bip322_psbt_input(psbt: BitGoPsbt, input_index: number, message: string, chain: number, index: number, wallet_keys: WasmRootWalletKeys, tag?: string | null): string[];
|
|
72
|
+
/**
|
|
73
|
+
* Verify a single input of a BIP-0322 transaction proof using pubkeys directly
|
|
74
|
+
*
|
|
75
|
+
* # Arguments
|
|
76
|
+
* * `tx` - The signed transaction
|
|
77
|
+
* * `input_index` - The index of the input to verify
|
|
78
|
+
* * `message` - The message that was signed
|
|
79
|
+
* * `pubkeys` - Array of 3 hex-encoded pubkeys [user, backup, bitgo]
|
|
80
|
+
* * `script_type` - One of: "p2sh", "p2shP2wsh", "p2wsh", "p2tr", "p2trMusig2"
|
|
81
|
+
* * `is_script_path` - For taproot types, whether script path was used
|
|
82
|
+
* * `tag` - Optional custom tag for message hashing
|
|
83
|
+
*
|
|
84
|
+
* # Returns
|
|
85
|
+
* An array of pubkey indices (0, 1, 2) that have valid signatures
|
|
86
|
+
*
|
|
87
|
+
* # Throws
|
|
88
|
+
* Throws an error if verification fails
|
|
89
|
+
*/
|
|
90
|
+
static verify_bip322_tx_input_with_pubkeys(tx: WasmTransaction, input_index: number, message: string, pubkeys: string[], script_type: string, is_script_path?: boolean | null, tag?: string | null): Uint32Array;
|
|
91
|
+
/**
|
|
92
|
+
* Verify a single input of a BIP-0322 PSBT proof using pubkeys directly
|
|
93
|
+
*
|
|
94
|
+
* # Arguments
|
|
95
|
+
* * `psbt` - The signed BitGoPsbt
|
|
96
|
+
* * `input_index` - The index of the input to verify
|
|
97
|
+
* * `message` - The message that was signed
|
|
98
|
+
* * `pubkeys` - Array of 3 hex-encoded pubkeys [user, backup, bitgo]
|
|
99
|
+
* * `script_type` - One of: "p2sh", "p2shP2wsh", "p2wsh", "p2tr", "p2trMusig2"
|
|
100
|
+
* * `is_script_path` - For taproot types, whether script path was used
|
|
101
|
+
* * `tag` - Optional custom tag for message hashing
|
|
102
|
+
*
|
|
103
|
+
* # Returns
|
|
104
|
+
* An array of pubkey indices (0, 1, 2) that have valid signatures
|
|
105
|
+
*
|
|
106
|
+
* # Throws
|
|
107
|
+
* Throws an error if verification fails or no valid signatures found
|
|
108
|
+
*/
|
|
109
|
+
static verify_bip322_psbt_input_with_pubkeys(psbt: BitGoPsbt, input_index: number, message: string, pubkeys: string[], script_type: string, is_script_path?: boolean | null, tag?: string | null): Uint32Array;
|
|
110
|
+
}
|
|
111
|
+
|
|
12
112
|
export class BitGoPsbt {
|
|
13
113
|
private constructor();
|
|
14
114
|
free(): void;
|