@bitgo/wasm-utxo 1.21.0 → 1.23.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.
@@ -1,9 +1,59 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
+ export const __wbg_wasmtransaction_free: (a: number, b: number) => void;
5
+ export const __wbg_wasmzcashtransaction_free: (a: number, b: number) => void;
6
+ export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
7
+ export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
8
+ export const __wbg_wrappsbt_free: (a: number, b: number) => void;
9
+ export const wasmtransaction_from_bytes: (a: number, b: number, c: number) => void;
10
+ export const wasmtransaction_get_vsize: (a: number) => number;
11
+ export const wasmtransaction_to_bytes: (a: number, b: number) => void;
12
+ export const wasmzcashtransaction_from_bytes: (a: number, b: number, c: number) => void;
13
+ export const wasmzcashtransaction_to_bytes: (a: number, b: number) => void;
14
+ export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
15
+ export const wrapdescriptor_descType: (a: number, b: number) => void;
16
+ export const wrapdescriptor_encode: (a: number, b: number) => void;
17
+ export const wrapdescriptor_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
18
+ export const wrapdescriptor_fromStringDetectType: (a: number, b: number, c: number) => void;
19
+ export const wrapdescriptor_hasWildcard: (a: number) => number;
20
+ export const wrapdescriptor_maxWeightToSatisfy: (a: number, b: number) => void;
21
+ export const wrapdescriptor_node: (a: number, b: number) => void;
22
+ export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
23
+ export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
24
+ export const wrapdescriptor_toString: (a: number, b: number) => void;
25
+ export const wrapminiscript_encode: (a: number, b: number) => void;
26
+ export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
27
+ export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
28
+ export const wrapminiscript_node: (a: number, b: number) => void;
29
+ export const wrapminiscript_toAsmString: (a: number, b: number) => void;
30
+ export const wrapminiscript_toString: (a: number, b: number) => void;
31
+ export const wrappsbt_clone: (a: number) => number;
32
+ export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
33
+ export const wrappsbt_finalize: (a: number, b: number) => void;
34
+ export const wrappsbt_serialize: (a: number, b: number) => void;
35
+ export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number) => void;
36
+ export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
37
+ export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
38
+ export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
39
+ export const __wbg_addressnamespace_free: (a: number, b: number) => void;
40
+ export const __wbg_bip322namespace_free: (a: number, b: number) => void;
4
41
  export const __wbg_bitgopsbt_free: (a: number, b: number) => void;
5
42
  export const __wbg_fixedscriptwalletnamespace_free: (a: number, b: number) => void;
43
+ export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
6
44
  export const __wbg_wasmbip32_free: (a: number, b: number) => void;
45
+ export const __wbg_wasmdashtransaction_free: (a: number, b: number) => void;
46
+ export const __wbg_wasmdimensions_free: (a: number, b: number) => void;
47
+ export const __wbg_wasmecpair_free: (a: number, b: number) => void;
48
+ export const __wbg_wasmreplayprotection_free: (a: number, b: number) => void;
49
+ export const __wbg_wasmrootwalletkeys_free: (a: number, b: number) => void;
50
+ export const addressnamespace_from_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
51
+ export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
52
+ export const bip322namespace_add_bip322_input: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number) => void;
53
+ export const bip322namespace_verify_bip322_psbt_input: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
54
+ export const bip322namespace_verify_bip322_psbt_input_with_pubkeys: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
55
+ export const bip322namespace_verify_bip322_tx_input: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
56
+ export const bip322namespace_verify_bip322_tx_input_with_pubkeys: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
7
57
  export const bitgopsbt_add_input: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number, h: number, i: number, j: number, k: number) => void;
8
58
  export const bitgopsbt_add_output: (a: number, b: number, c: number, d: number, e: bigint) => void;
9
59
  export const bitgopsbt_add_output_with_address: (a: number, b: number, c: number, d: number, e: bigint) => void;
@@ -34,8 +84,11 @@ export const bitgopsbt_verify_signature_with_xpub: (a: number, b: number, c: num
34
84
  export const bitgopsbt_version: (a: number) => number;
35
85
  export const bitgopsbt_version_group_id: (a: number) => number;
36
86
  export const fixedscriptwalletnamespace_address: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
87
+ export const fixedscriptwalletnamespace_chain_code_table: () => number;
37
88
  export const fixedscriptwalletnamespace_output_script: (a: number, b: number, c: number, d: number, e: number) => void;
38
89
  export const fixedscriptwalletnamespace_supports_script_type: (a: number, b: number, c: number, d: number, e: number) => void;
90
+ export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
91
+ export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
39
92
  export const wasmbip32_chain_code: (a: number) => number;
40
93
  export const wasmbip32_depth: (a: number) => number;
41
94
  export const wasmbip32_derive: (a: number, b: number, c: number) => void;
@@ -56,9 +109,22 @@ export const wasmbip32_private_key: (a: number) => number;
56
109
  export const wasmbip32_public_key: (a: number) => number;
57
110
  export const wasmbip32_to_base58: (a: number, b: number) => void;
58
111
  export const wasmbip32_to_wif: (a: number, b: number) => void;
59
- export const wasmbip32_from_bip32_properties: (a: number, b: number) => void;
60
- export const __wbg_wasmecpair_free: (a: number, b: number) => void;
61
- export const __wbg_wasmreplayprotection_free: (a: number, b: number) => void;
112
+ export const wasmdashtransaction_from_bytes: (a: number, b: number, c: number) => void;
113
+ export const wasmdashtransaction_to_bytes: (a: number, b: number) => void;
114
+ export const wasmdimensions_empty: () => number;
115
+ export const wasmdimensions_from_input: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
116
+ export const wasmdimensions_from_input_script_type: (a: number, b: number, c: number) => void;
117
+ export const wasmdimensions_from_output_script: (a: number, b: number) => number;
118
+ export const wasmdimensions_from_psbt: (a: number, b: number) => void;
119
+ export const wasmdimensions_get_input_vsize: (a: number, b: number, c: number) => number;
120
+ export const wasmdimensions_get_input_weight: (a: number, b: number, c: number) => number;
121
+ export const wasmdimensions_get_output_vsize: (a: number) => number;
122
+ export const wasmdimensions_get_output_weight: (a: number) => number;
123
+ export const wasmdimensions_get_vsize: (a: number, b: number, c: number) => number;
124
+ export const wasmdimensions_get_weight: (a: number, b: number, c: number) => number;
125
+ export const wasmdimensions_has_segwit: (a: number) => number;
126
+ export const wasmdimensions_plus: (a: number, b: number) => number;
127
+ export const wasmdimensions_times: (a: number, b: number) => number;
62
128
  export const wasmecpair_from_private_key: (a: number, b: number, c: number) => void;
63
129
  export const wasmecpair_from_public_key: (a: number, b: number, c: number) => void;
64
130
  export const wasmecpair_from_wif: (a: number, b: number, c: number) => void;
@@ -72,66 +138,12 @@ export const wasmecpair_to_wif_testnet: (a: number, b: number) => void;
72
138
  export const wasmreplayprotection_from_addresses: (a: number, b: number, c: number, d: number, e: number) => void;
73
139
  export const wasmreplayprotection_from_output_scripts: (a: number, b: number) => number;
74
140
  export const wasmreplayprotection_from_public_keys: (a: number, b: number, c: number) => void;
75
- export const __wbg_addressnamespace_free: (a: number, b: number) => void;
76
- export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
77
- export const __wbg_wasmdimensions_free: (a: number, b: number) => void;
78
- export const __wbg_wasmtransaction_free: (a: number, b: number) => void;
79
- export const __wbg_wasmzcashtransaction_free: (a: number, b: number) => void;
80
- export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
81
- export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
82
- export const __wbg_wrappsbt_free: (a: number, b: number) => void;
83
- export const addressnamespace_from_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
84
- export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
85
- export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
86
- export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
87
- export const wasmdimensions_empty: () => number;
88
- export const wasmdimensions_from_input: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
89
- export const wasmdimensions_from_input_script_type: (a: number, b: number, c: number) => void;
90
- export const wasmdimensions_from_output_script: (a: number, b: number) => number;
91
- export const wasmdimensions_from_psbt: (a: number, b: number) => void;
92
- export const wasmdimensions_get_vsize: (a: number, b: number, c: number) => number;
93
- export const wasmdimensions_get_weight: (a: number, b: number, c: number) => number;
94
- export const wasmdimensions_has_segwit: (a: number) => number;
95
- export const wasmdimensions_plus: (a: number, b: number) => number;
96
- export const wasmtransaction_from_bytes: (a: number, b: number, c: number) => void;
97
- export const wasmtransaction_get_vsize: (a: number) => number;
98
- export const wasmtransaction_to_bytes: (a: number, b: number) => void;
99
- export const wasmzcashtransaction_from_bytes: (a: number, b: number, c: number) => void;
100
- export const wasmzcashtransaction_to_bytes: (a: number, b: number) => void;
101
- export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
102
- export const wrapdescriptor_descType: (a: number, b: number) => void;
103
- export const wrapdescriptor_encode: (a: number, b: number) => void;
104
- export const wrapdescriptor_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
105
- export const wrapdescriptor_fromStringDetectType: (a: number, b: number, c: number) => void;
106
- export const wrapdescriptor_hasWildcard: (a: number) => number;
107
- export const wrapdescriptor_maxWeightToSatisfy: (a: number, b: number) => void;
108
- export const wrapdescriptor_node: (a: number, b: number) => void;
109
- export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
110
- export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
111
- export const wrapdescriptor_toString: (a: number, b: number) => void;
112
- export const wrapminiscript_encode: (a: number, b: number) => void;
113
- export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
114
- export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
115
- export const wrapminiscript_node: (a: number, b: number) => void;
116
- export const wrapminiscript_toAsmString: (a: number, b: number) => void;
117
- export const wrapminiscript_toString: (a: number, b: number) => void;
118
- export const wrappsbt_clone: (a: number) => number;
119
- export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
120
- export const wrappsbt_finalize: (a: number, b: number) => void;
121
- export const wrappsbt_serialize: (a: number, b: number) => void;
122
- export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number) => void;
123
- export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
124
- export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
125
- export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
126
- export const __wbg_wasmrootwalletkeys_free: (a: number, b: number) => void;
127
141
  export const wasmrootwalletkeys_backup_key: (a: number) => number;
128
142
  export const wasmrootwalletkeys_bitgo_key: (a: number) => number;
129
143
  export const wasmrootwalletkeys_new: (a: number, b: number, c: number, d: number) => void;
130
144
  export const wasmrootwalletkeys_user_key: (a: number) => number;
131
145
  export const wasmrootwalletkeys_with_derivation_prefixes: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
132
- export const __wbg_wasmdashtransaction_free: (a: number, b: number) => void;
133
- export const wasmdashtransaction_from_bytes: (a: number, b: number, c: number) => void;
134
- export const wasmdashtransaction_to_bytes: (a: number, b: number) => void;
146
+ export const wasmbip32_from_bip32_properties: (a: number, b: number) => void;
135
147
  export const rustsecp256k1_v0_10_0_context_create: (a: number) => number;
136
148
  export const rustsecp256k1_v0_10_0_context_destroy: (a: number) => void;
137
149
  export const rustsecp256k1_v0_10_0_default_error_callback_fn: (a: number, b: number) => void;
@@ -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
+ }
@@ -47,6 +47,10 @@ export declare class Dimensions {
47
47
  * Combine with another Dimensions instance
48
48
  */
49
49
  plus(other: Dimensions): Dimensions;
50
+ /**
51
+ * Multiply dimensions by a scalar
52
+ */
53
+ times(n: number): Dimensions;
50
54
  /**
51
55
  * Whether any inputs are segwit (affects overhead calculation)
52
56
  */
@@ -61,5 +65,23 @@ export declare class Dimensions {
61
65
  * @param size - "min" or "max", defaults to "max"
62
66
  */
63
67
  getVSize(size?: "min" | "max"): number;
68
+ /**
69
+ * Get input weight only (min or max)
70
+ * @param size - "min" or "max", defaults to "max"
71
+ */
72
+ getInputWeight(size?: "min" | "max"): number;
73
+ /**
74
+ * Get input virtual size (min or max)
75
+ * @param size - "min" or "max", defaults to "max"
76
+ */
77
+ getInputVSize(size?: "min" | "max"): number;
78
+ /**
79
+ * Get output weight
80
+ */
81
+ getOutputWeight(): number;
82
+ /**
83
+ * Get output virtual size
84
+ */
85
+ getOutputVSize(): number;
64
86
  }
65
87
  export {};
@@ -56,6 +56,12 @@ export class Dimensions {
56
56
  plus(other) {
57
57
  return new Dimensions(this._wasm.plus(other._wasm));
58
58
  }
59
+ /**
60
+ * Multiply dimensions by a scalar
61
+ */
62
+ times(n) {
63
+ return new Dimensions(this._wasm.times(n));
64
+ }
59
65
  /**
60
66
  * Whether any inputs are segwit (affects overhead calculation)
61
67
  */
@@ -76,4 +82,30 @@ export class Dimensions {
76
82
  getVSize(size = "max") {
77
83
  return this._wasm.get_vsize(size);
78
84
  }
85
+ /**
86
+ * Get input weight only (min or max)
87
+ * @param size - "min" or "max", defaults to "max"
88
+ */
89
+ getInputWeight(size = "max") {
90
+ return this._wasm.get_input_weight(size);
91
+ }
92
+ /**
93
+ * Get input virtual size (min or max)
94
+ * @param size - "min" or "max", defaults to "max"
95
+ */
96
+ getInputVSize(size = "max") {
97
+ return this._wasm.get_input_vsize(size);
98
+ }
99
+ /**
100
+ * Get output weight
101
+ */
102
+ getOutputWeight() {
103
+ return this._wasm.get_output_weight();
104
+ }
105
+ /**
106
+ * Get output virtual size
107
+ */
108
+ getOutputVSize() {
109
+ return this._wasm.get_output_vsize();
110
+ }
79
111
  }