@bitgo/wasm-utxo 1.44.0 → 2.1.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.
Files changed (30) hide show
  1. package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +34 -50
  2. package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +71 -32
  3. package/dist/cjs/js/fixedScriptWallet/RootWalletKeys.d.ts +5 -0
  4. package/dist/cjs/js/fixedScriptWallet/RootWalletKeys.js +7 -0
  5. package/dist/cjs/js/fixedScriptWallet/index.d.ts +1 -1
  6. package/dist/cjs/js/fixedScriptWallet/index.js +2 -1
  7. package/dist/cjs/js/index.d.ts +6 -1
  8. package/dist/cjs/js/psbt.d.ts +15 -6
  9. package/dist/cjs/js/transaction.d.ts +2 -6
  10. package/dist/cjs/js/transaction.js +6 -6
  11. package/dist/cjs/js/wasm/wasm_utxo.d.ts +32 -86
  12. package/dist/cjs/js/wasm/wasm_utxo.js +463 -81
  13. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
  14. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +71 -54
  15. package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +34 -50
  16. package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +71 -33
  17. package/dist/esm/js/fixedScriptWallet/RootWalletKeys.d.ts +5 -0
  18. package/dist/esm/js/fixedScriptWallet/RootWalletKeys.js +7 -0
  19. package/dist/esm/js/fixedScriptWallet/index.d.ts +1 -1
  20. package/dist/esm/js/fixedScriptWallet/index.js +1 -1
  21. package/dist/esm/js/index.d.ts +6 -1
  22. package/dist/esm/js/index.js +1 -1
  23. package/dist/esm/js/psbt.d.ts +15 -6
  24. package/dist/esm/js/transaction.d.ts +2 -6
  25. package/dist/esm/js/transaction.js +6 -6
  26. package/dist/esm/js/wasm/wasm_utxo.d.ts +32 -86
  27. package/dist/esm/js/wasm/wasm_utxo_bg.js +463 -81
  28. package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
  29. package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +71 -54
  30. package/package.json +11 -4
@@ -1,13 +1,22 @@
1
1
  import type { PsbtInputData, PsbtOutputData, PsbtOutputDataWithAddress } from "./wasm/wasm_utxo.js";
2
- /** Common interface for PSBT introspection methods */
3
- export interface IPsbtIntrospection {
4
- readonly inputCount: number;
5
- readonly outputCount: number;
2
+ import type { BIP32 } from "./bip32.js";
3
+ /** Common interface for PSBT types */
4
+ export interface IPsbt {
5
+ inputCount(): number;
6
+ outputCount(): number;
6
7
  getInputs(): PsbtInputData[];
7
8
  getOutputs(): PsbtOutputData[];
9
+ getGlobalXpubs(): BIP32[];
10
+ version(): number;
11
+ lockTime(): number;
12
+ unsignedTxId(): string;
13
+ addInputAtIndex(index: number, txid: string, vout: number, value: bigint, script: Uint8Array, sequence?: number): number;
14
+ addOutputAtIndex(index: number, script: Uint8Array, value: bigint): number;
15
+ removeInput(index: number): void;
16
+ removeOutput(index: number): void;
8
17
  }
9
- /** Extended introspection with address resolution (no coin parameter needed) */
10
- export interface IPsbtIntrospectionWithAddress extends IPsbtIntrospection {
18
+ /** Extended PSBT with address resolution (no coin parameter needed) */
19
+ export interface IPsbtWithAddress extends IPsbt {
11
20
  getOutputsWithAddress(): PsbtOutputDataWithAddress[];
12
21
  }
13
22
  /**
@@ -30,13 +30,9 @@ export declare class Transaction implements ITransaction {
30
30
  * @param sequence - Optional sequence number (default: 0xFFFFFFFF)
31
31
  * @returns The index of the newly added input
32
32
  */
33
+ addInputAtIndex(index: number, txid: string, vout: number, sequence?: number): number;
33
34
  addInput(txid: string, vout: number, sequence?: number): number;
34
- /**
35
- * Add an output to the transaction
36
- * @param script - Output script (scriptPubKey)
37
- * @param value - Value in satoshis
38
- * @returns The index of the newly added output
39
- */
35
+ addOutputAtIndex(index: number, script: Uint8Array, value: bigint): number;
40
36
  addOutput(script: Uint8Array, value: bigint): number;
41
37
  toBytes(): Uint8Array;
42
38
  /**
@@ -31,15 +31,15 @@ export class Transaction {
31
31
  * @param sequence - Optional sequence number (default: 0xFFFFFFFF)
32
32
  * @returns The index of the newly added input
33
33
  */
34
+ addInputAtIndex(index, txid, vout, sequence) {
35
+ return this._wasm.add_input_at_index(index, txid, vout, sequence);
36
+ }
34
37
  addInput(txid, vout, sequence) {
35
38
  return this._wasm.add_input(txid, vout, sequence);
36
39
  }
37
- /**
38
- * Add an output to the transaction
39
- * @param script - Output script (scriptPubKey)
40
- * @param value - Value in satoshis
41
- * @returns The index of the newly added output
42
- */
40
+ addOutputAtIndex(index, script, value) {
41
+ return this._wasm.add_output_at_index(index, script, value);
42
+ }
43
43
  addOutput(script, value) {
44
44
  return this._wasm.add_output(script, value);
45
45
  }
@@ -116,6 +116,7 @@ export class BitGoPsbt {
116
116
  private constructor();
117
117
  free(): void;
118
118
  [Symbol.dispose](): void;
119
+ add_input(txid: string, vout: number, value: bigint, script: Uint8Array, sequence?: number | null, prev_tx?: Uint8Array | null): number;
119
120
  /**
120
121
  * Add an input to the PSBT
121
122
  *
@@ -129,29 +130,11 @@ export class BitGoPsbt {
129
130
  * # Returns
130
131
  * The index of the newly added input
131
132
  */
132
- add_input(txid: string, vout: number, value: bigint, script: Uint8Array, sequence?: number | null, prev_tx?: Uint8Array | null): number;
133
- /**
134
- * Add an output to the PSBT
135
- *
136
- * # Arguments
137
- * * `script` - The output script (scriptPubKey)
138
- * * `value` - The value in satoshis
139
- *
140
- * # Returns
141
- * The index of the newly added output
142
- */
133
+ add_input_at_index(index: number, txid: string, vout: number, value: bigint, script: Uint8Array, sequence?: number | null, prev_tx?: Uint8Array | null): number;
143
134
  add_output(script: Uint8Array, value: bigint): number;
144
- /**
145
- * Add an output to the PSBT by address
146
- *
147
- * # Arguments
148
- * * `address` - The destination address
149
- * * `value` - The value in satoshis
150
- *
151
- * # Returns
152
- * The index of the newly added output
153
- */
135
+ add_output_at_index(index: number, script: Uint8Array, value: bigint): number;
154
136
  add_output_with_address(address: string, value: bigint): number;
137
+ add_output_with_address_at_index(index: number, address: string, value: bigint): number;
155
138
  /**
156
139
  * Add a PayGo attestation to a PSBT output
157
140
  *
@@ -165,61 +148,12 @@ export class BitGoPsbt {
165
148
  * - `Err(WasmUtxoError)` if the output index is out of bounds or entropy is invalid
166
149
  */
167
150
  add_paygo_attestation(output_index: number, entropy: Uint8Array, signature: Uint8Array): void;
168
- /**
169
- * Add a replay protection input to the PSBT
170
- *
171
- * Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
172
- * transaction replay attacks. They use a simple pubkey script without wallet derivation.
173
- *
174
- * # Arguments
175
- * * `ecpair` - The ECPair containing the public key for the replay protection input
176
- * * `txid` - The transaction ID (hex string) of the output being spent
177
- * * `vout` - The output index being spent
178
- * * `value` - The value in satoshis
179
- * * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
180
- *
181
- * # Returns
182
- * The index of the newly added input
183
- */
184
151
  add_replay_protection_input(ecpair: WasmECPair, txid: string, vout: number, value: bigint, sequence?: number | null, prev_tx?: Uint8Array | null): number;
185
- /**
186
- * Add a wallet input with full PSBT metadata
187
- *
188
- * This is a higher-level method that adds an input and populates all required
189
- * PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
190
- *
191
- * # Arguments
192
- * * `txid` - The transaction ID (hex string)
193
- * * `vout` - The output index being spent
194
- * * `value` - The value in satoshis
195
- * * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
196
- * * `index` - The derivation index
197
- * * `wallet_keys` - The root wallet keys
198
- * * `signer` - The key that will sign ("user", "backup", or "bitgo") - required for p2tr/p2trMusig2
199
- * * `cosigner` - The key that will co-sign - required for p2tr/p2trMusig2
200
- * * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
201
- * * `prev_tx` - Optional full previous transaction bytes (for non-segwit)
202
- *
203
- * # Returns
204
- * The index of the newly added input
205
- */
152
+ add_replay_protection_input_at_index(index: number, ecpair: WasmECPair, txid: string, vout: number, value: bigint, sequence?: number | null, prev_tx?: Uint8Array | null): number;
206
153
  add_wallet_input(txid: string, vout: number, value: bigint, wallet_keys: WasmRootWalletKeys, chain: number, index: number, signer?: string | null, cosigner?: string | null, sequence?: number | null, prev_tx?: Uint8Array | null): number;
207
- /**
208
- * Add a wallet output with full PSBT metadata
209
- *
210
- * This creates a verifiable wallet output (typically for change) with all required
211
- * PSBT fields (scripts, derivation info) based on the wallet's chain type.
212
- *
213
- * # Arguments
214
- * * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
215
- * * `index` - The derivation index
216
- * * `value` - The value in satoshis
217
- * * `wallet_keys` - The root wallet keys
218
- *
219
- * # Returns
220
- * The index of the newly added output
221
- */
154
+ add_wallet_input_at_index(index: number, txid: string, vout: number, value: bigint, wallet_keys: WasmRootWalletKeys, chain: number, derivation_index: number, signer?: string | null, cosigner?: string | null, sequence?: number | null, prev_tx?: Uint8Array | null): number;
222
155
  add_wallet_output(chain: number, index: number, value: bigint, wallet_keys: WasmRootWalletKeys): number;
156
+ add_wallet_output_at_index(index: number, chain: number, derivation_index: number, value: bigint, wallet_keys: WasmRootWalletKeys): number;
223
157
  /**
224
158
  * Combine/merge data from another PSBT into this one
225
159
  *
@@ -384,6 +318,10 @@ export class BitGoPsbt {
384
318
  * generated for security. Custom session_id is only allowed on testnets for testing purposes.
385
319
  */
386
320
  generate_musig2_nonces(xpriv: WasmBIP32, session_id_bytes?: Uint8Array | null): void;
321
+ /**
322
+ * Returns the global xpubs from the PSBT as an array of WasmBIP32 instances.
323
+ */
324
+ get_global_xpubs(): any;
387
325
  /**
388
326
  * Get all PSBT inputs as an array of PsbtInputData
389
327
  *
@@ -452,6 +390,8 @@ export class BitGoPsbt {
452
390
  * Parse transaction with wallet keys to identify wallet inputs/outputs
453
391
  */
454
392
  parse_transaction_with_wallet_keys(wallet_keys: WasmRootWalletKeys, replay_protection: WasmReplayProtection, paygo_pubkeys?: WasmECPair[] | null): any;
393
+ remove_input(index: number): void;
394
+ remove_output(index: number): void;
455
395
  /**
456
396
  * Serialize the PSBT to bytes
457
397
  *
@@ -782,6 +722,12 @@ export class FixedScriptWalletNamespace {
782
722
  * - Dogecoin only supports legacy scripts (p2sh)
783
723
  */
784
724
  static supports_script_type(coin: string, script_type: string): boolean;
725
+ /**
726
+ * Sort an xpub triple into [user, backup, bitgo] order by validating
727
+ * against the PSBT's wallet inputs. Returns a RootWalletKeys with the
728
+ * correct ordering.
729
+ */
730
+ static to_wallet_keys(psbt: BitGoPsbt, user_or_a: WasmBIP32, backup_or_b: WasmBIP32, bitgo_or_c: WasmBIP32): WasmRootWalletKeys;
785
731
  }
786
732
 
787
733
  /**
@@ -1230,6 +1176,7 @@ export class WasmTransaction {
1230
1176
  private constructor();
1231
1177
  free(): void;
1232
1178
  [Symbol.dispose](): void;
1179
+ add_input(txid: string, vout: number, sequence?: number | null): number;
1233
1180
  /**
1234
1181
  * Add an input to the transaction
1235
1182
  *
@@ -1241,18 +1188,9 @@ export class WasmTransaction {
1241
1188
  * # Returns
1242
1189
  * The index of the newly added input
1243
1190
  */
1244
- add_input(txid: string, vout: number, sequence?: number | null): number;
1245
- /**
1246
- * Add an output to the transaction
1247
- *
1248
- * # Arguments
1249
- * * `script` - The output script (scriptPubKey)
1250
- * * `value` - The value in satoshis
1251
- *
1252
- * # Returns
1253
- * The index of the newly added output
1254
- */
1191
+ add_input_at_index(index: number, txid: string, vout: number, sequence?: number | null): number;
1255
1192
  add_output(script: Uint8Array, value: bigint): number;
1193
+ add_output_at_index(index: number, script: Uint8Array, value: bigint): number;
1256
1194
  /**
1257
1195
  * Create an empty transaction (version 1, locktime 0)
1258
1196
  */
@@ -1373,6 +1311,7 @@ export class WrapMiniscript {
1373
1311
  export class WrapPsbt {
1374
1312
  free(): void;
1375
1313
  [Symbol.dispose](): void;
1314
+ addInput(txid: string, vout: number, value: bigint, script: Uint8Array, sequence?: number | null): number;
1376
1315
  /**
1377
1316
  * Add an input to the PSBT
1378
1317
  *
@@ -1386,7 +1325,8 @@ export class WrapPsbt {
1386
1325
  * # Returns
1387
1326
  * The index of the newly added input
1388
1327
  */
1389
- addInput(txid: string, vout: number, value: bigint, script: Uint8Array, sequence?: number | null): number;
1328
+ addInputAtIndex(index: number, txid: string, vout: number, value: bigint, script: Uint8Array, sequence?: number | null): number;
1329
+ addOutput(script: Uint8Array, value: bigint): number;
1390
1330
  /**
1391
1331
  * Add an output to the PSBT
1392
1332
  *
@@ -1397,7 +1337,7 @@ export class WrapPsbt {
1397
1337
  * # Returns
1398
1338
  * The index of the newly added output
1399
1339
  */
1400
- addOutput(script: Uint8Array, value: bigint): number;
1340
+ addOutputAtIndex(index: number, script: Uint8Array, value: bigint): number;
1401
1341
  clone(): WrapPsbt;
1402
1342
  static deserialize(psbt: Uint8Array): WrapPsbt;
1403
1343
  /**
@@ -1412,6 +1352,10 @@ export class WrapPsbt {
1412
1352
  */
1413
1353
  extractTransaction(): WasmTransaction;
1414
1354
  finalize(): void;
1355
+ /**
1356
+ * Get global xpubs from the PSBT as an array of WasmBIP32 instances.
1357
+ */
1358
+ getGlobalXpubs(): any;
1415
1359
  /**
1416
1360
  * Get all PSBT inputs as an array of PsbtInputData
1417
1361
  *
@@ -1469,6 +1413,8 @@ export class WrapPsbt {
1469
1413
  * Get the number of outputs in the PSBT
1470
1414
  */
1471
1415
  outputCount(): number;
1416
+ removeInput(index: number): void;
1417
+ removeOutput(index: number): void;
1472
1418
  serialize(): Uint8Array;
1473
1419
  /**
1474
1420
  * Sign all inputs with a WasmBIP32 key