@bitgo/wasm-utxo 1.7.0 → 1.8.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/fixedScriptWallet/BitGoPsbt.d.ts +99 -0
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +122 -0
- package/dist/cjs/js/wasm/wasm_utxo.d.ts +86 -0
- package/dist/cjs/js/wasm/wasm_utxo.js +277 -25
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +21 -17
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +99 -0
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +122 -0
- package/dist/esm/js/wasm/wasm_utxo.d.ts +86 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.js +277 -25
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +21 -17
- package/dist/esm/test/fixedScript/fixtureUtil.d.ts +8 -0
- package/dist/esm/test/fixedScript/fixtureUtil.js +10 -0
- package/dist/esm/test/fixedScript/musig2Nonces.js +77 -0
- package/dist/esm/test/fixedScript/signAndVerifySignature.d.ts +1 -0
- package/dist/esm/test/fixedScript/{verifySignature.js → signAndVerifySignature.js} +105 -24
- package/dist/esm/test/fixedScript/walletKeys.util.d.ts +12 -0
- package/dist/esm/test/fixedScript/walletKeys.util.js +17 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- /package/dist/esm/test/fixedScript/{verifySignature.d.ts → musig2Nonces.d.ts} +0 -0
|
@@ -64,6 +64,18 @@ function getArrayU8FromWasm0(ptr, len) {
|
|
|
64
64
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
function dropObject(idx) {
|
|
68
|
+
if (idx < 132) return;
|
|
69
|
+
heap[idx] = heap_next;
|
|
70
|
+
heap_next = idx;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function takeObject(idx) {
|
|
74
|
+
const ret = getObject(idx);
|
|
75
|
+
dropObject(idx);
|
|
76
|
+
return ret;
|
|
77
|
+
}
|
|
78
|
+
|
|
67
79
|
function isLikeNone(x) {
|
|
68
80
|
return x === undefined || x === null;
|
|
69
81
|
}
|
|
@@ -131,16 +143,21 @@ function passStringToWasm0(arg, malloc, realloc) {
|
|
|
131
143
|
return ptr;
|
|
132
144
|
}
|
|
133
145
|
|
|
134
|
-
function
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
146
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
147
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
148
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
149
|
+
WASM_VECTOR_LEN = arg.length;
|
|
150
|
+
return ptr;
|
|
138
151
|
}
|
|
139
152
|
|
|
140
|
-
function
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
153
|
+
function passArrayJsValueToWasm0(array, malloc) {
|
|
154
|
+
const ptr = malloc(array.length * 4, 4) >>> 0;
|
|
155
|
+
const mem = getDataViewMemory0();
|
|
156
|
+
for (let i = 0; i < array.length; i++) {
|
|
157
|
+
mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
|
|
158
|
+
}
|
|
159
|
+
WASM_VECTOR_LEN = array.length;
|
|
160
|
+
return ptr;
|
|
144
161
|
}
|
|
145
162
|
|
|
146
163
|
function _assertClass(instance, klass) {
|
|
@@ -149,13 +166,6 @@ function _assertClass(instance, klass) {
|
|
|
149
166
|
}
|
|
150
167
|
}
|
|
151
168
|
|
|
152
|
-
function passArray8ToWasm0(arg, malloc) {
|
|
153
|
-
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
154
|
-
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
155
|
-
WASM_VECTOR_LEN = arg.length;
|
|
156
|
-
return ptr;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
169
|
let stack_pointer = 128;
|
|
160
170
|
|
|
161
171
|
function addBorrowedObject(obj) {
|
|
@@ -164,16 +174,6 @@ function addBorrowedObject(obj) {
|
|
|
164
174
|
return stack_pointer;
|
|
165
175
|
}
|
|
166
176
|
|
|
167
|
-
function passArrayJsValueToWasm0(array, malloc) {
|
|
168
|
-
const ptr = malloc(array.length * 4, 4) >>> 0;
|
|
169
|
-
const mem = getDataViewMemory0();
|
|
170
|
-
for (let i = 0; i < array.length; i++) {
|
|
171
|
-
mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
|
|
172
|
-
}
|
|
173
|
-
WASM_VECTOR_LEN = array.length;
|
|
174
|
-
return ptr;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
177
|
const AddressNamespaceFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
178
178
|
? { register: () => {}, unregister: () => {} }
|
|
179
179
|
: new FinalizationRegistry(ptr => wasm.__wbg_addressnamespace_free(ptr >>> 0, 1));
|
|
@@ -327,6 +327,76 @@ export class BitGoPsbt {
|
|
|
327
327
|
wasm.__wbindgen_export_3(deferred1_0, deferred1_1, 1);
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Sign a single input with an extended private key (xpriv)
|
|
332
|
+
*
|
|
333
|
+
* This method signs a specific input using the provided xpriv. It accepts:
|
|
334
|
+
* - An xpriv (WasmBIP32) for wallet inputs - derives the key and signs
|
|
335
|
+
*
|
|
336
|
+
* This method automatically detects and handles different input types:
|
|
337
|
+
* - For regular inputs: uses standard PSBT signing
|
|
338
|
+
* - For MuSig2 inputs: uses the FirstRound state stored by generate_musig2_nonces()
|
|
339
|
+
* - For replay protection inputs: returns error (use sign_with_privkey instead)
|
|
340
|
+
*
|
|
341
|
+
* # Arguments
|
|
342
|
+
* - `input_index`: The index of the input to sign (0-based)
|
|
343
|
+
* - `xpriv`: The extended private key as a WasmBIP32 instance
|
|
344
|
+
*
|
|
345
|
+
* # Returns
|
|
346
|
+
* - `Ok(())` if signing was successful
|
|
347
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
348
|
+
* @param {number} input_index
|
|
349
|
+
* @param {WasmBIP32} xpriv
|
|
350
|
+
*/
|
|
351
|
+
sign_with_xpriv(input_index, xpriv) {
|
|
352
|
+
try {
|
|
353
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
354
|
+
_assertClass(xpriv, WasmBIP32);
|
|
355
|
+
wasm.bitgopsbt_sign_with_xpriv(retptr, this.__wbg_ptr, input_index, xpriv.__wbg_ptr);
|
|
356
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
357
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
358
|
+
if (r1) {
|
|
359
|
+
throw takeObject(r0);
|
|
360
|
+
}
|
|
361
|
+
} finally {
|
|
362
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Sign a single input with a raw private key
|
|
367
|
+
*
|
|
368
|
+
* This method signs a specific input using the provided ECPair. It accepts:
|
|
369
|
+
* - A raw privkey (WasmECPair) for replay protection inputs - signs directly
|
|
370
|
+
*
|
|
371
|
+
* This method automatically detects and handles different input types:
|
|
372
|
+
* - For replay protection inputs: signs with legacy P2SH sighash
|
|
373
|
+
* - For regular inputs: uses standard PSBT signing
|
|
374
|
+
* - For MuSig2 inputs: returns error (requires FirstRound, use sign_with_xpriv instead)
|
|
375
|
+
*
|
|
376
|
+
* # Arguments
|
|
377
|
+
* - `input_index`: The index of the input to sign (0-based)
|
|
378
|
+
* - `ecpair`: The ECPair containing the private key
|
|
379
|
+
*
|
|
380
|
+
* # Returns
|
|
381
|
+
* - `Ok(())` if signing was successful
|
|
382
|
+
* - `Err(WasmUtxoError)` if signing fails
|
|
383
|
+
* @param {number} input_index
|
|
384
|
+
* @param {WasmECPair} ecpair
|
|
385
|
+
*/
|
|
386
|
+
sign_with_privkey(input_index, ecpair) {
|
|
387
|
+
try {
|
|
388
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
389
|
+
_assertClass(ecpair, WasmECPair);
|
|
390
|
+
wasm.bitgopsbt_sign_with_privkey(retptr, this.__wbg_ptr, input_index, ecpair.__wbg_ptr);
|
|
391
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
392
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
393
|
+
if (r1) {
|
|
394
|
+
throw takeObject(r0);
|
|
395
|
+
}
|
|
396
|
+
} finally {
|
|
397
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
330
400
|
/**
|
|
331
401
|
* Extract the final transaction from a finalized PSBT
|
|
332
402
|
*
|
|
@@ -379,6 +449,83 @@ export class BitGoPsbt {
|
|
|
379
449
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
380
450
|
}
|
|
381
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* Combine/merge data from another PSBT into this one
|
|
454
|
+
*
|
|
455
|
+
* This method copies MuSig2 nonces and signatures (proprietary key-value pairs) from the
|
|
456
|
+
* source PSBT to this PSBT. This is useful for merging PSBTs during the nonce exchange
|
|
457
|
+
* and signature collection phases.
|
|
458
|
+
*
|
|
459
|
+
* # Arguments
|
|
460
|
+
* * `source_psbt` - The source PSBT containing data to merge
|
|
461
|
+
*
|
|
462
|
+
* # Returns
|
|
463
|
+
* Ok(()) if data was successfully merged
|
|
464
|
+
*
|
|
465
|
+
* # Errors
|
|
466
|
+
* Returns error if networks don't match
|
|
467
|
+
* @param {BitGoPsbt} source_psbt
|
|
468
|
+
*/
|
|
469
|
+
combine_musig2_nonces(source_psbt) {
|
|
470
|
+
try {
|
|
471
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
472
|
+
_assertClass(source_psbt, BitGoPsbt);
|
|
473
|
+
wasm.bitgopsbt_combine_musig2_nonces(retptr, this.__wbg_ptr, source_psbt.__wbg_ptr);
|
|
474
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
475
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
476
|
+
if (r1) {
|
|
477
|
+
throw takeObject(r0);
|
|
478
|
+
}
|
|
479
|
+
} finally {
|
|
480
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Generate and store MuSig2 nonces for all MuSig2 inputs
|
|
485
|
+
*
|
|
486
|
+
* This method generates nonces using the State-Machine API and stores them in the PSBT.
|
|
487
|
+
* The nonces are stored as proprietary fields in the PSBT and will be included when serialized.
|
|
488
|
+
* After ALL participants have generated their nonces, they can sign MuSig2 inputs using
|
|
489
|
+
* sign_with_xpriv().
|
|
490
|
+
*
|
|
491
|
+
* # Arguments
|
|
492
|
+
* * `xpriv` - The extended private key (xpriv) for signing
|
|
493
|
+
* * `session_id_bytes` - Optional 32-byte session ID for nonce generation. **Only allowed on testnets**.
|
|
494
|
+
* On mainnets, a secure random session ID is always generated automatically.
|
|
495
|
+
* Must be unique per signing session.
|
|
496
|
+
*
|
|
497
|
+
* # Returns
|
|
498
|
+
* Ok(()) if nonces were successfully generated and stored
|
|
499
|
+
*
|
|
500
|
+
* # Errors
|
|
501
|
+
* Returns error if:
|
|
502
|
+
* - Nonce generation fails
|
|
503
|
+
* - session_id length is invalid
|
|
504
|
+
* - Custom session_id is provided on a mainnet (security restriction)
|
|
505
|
+
*
|
|
506
|
+
* # Security
|
|
507
|
+
* The session_id MUST be cryptographically random and unique for each signing session.
|
|
508
|
+
* Never reuse a session_id with the same key! On mainnets, session_id is always randomly
|
|
509
|
+
* generated for security. Custom session_id is only allowed on testnets for testing purposes.
|
|
510
|
+
* @param {WasmBIP32} xpriv
|
|
511
|
+
* @param {Uint8Array | null} [session_id_bytes]
|
|
512
|
+
*/
|
|
513
|
+
generate_musig2_nonces(xpriv, session_id_bytes) {
|
|
514
|
+
try {
|
|
515
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
516
|
+
_assertClass(xpriv, WasmBIP32);
|
|
517
|
+
var ptr0 = isLikeNone(session_id_bytes) ? 0 : passArray8ToWasm0(session_id_bytes, wasm.__wbindgen_export_1);
|
|
518
|
+
var len0 = WASM_VECTOR_LEN;
|
|
519
|
+
wasm.bitgopsbt_generate_musig2_nonces(retptr, this.__wbg_ptr, xpriv.__wbg_ptr, ptr0, len0);
|
|
520
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
521
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
522
|
+
if (r1) {
|
|
523
|
+
throw takeObject(r0);
|
|
524
|
+
}
|
|
525
|
+
} finally {
|
|
526
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
382
529
|
/**
|
|
383
530
|
* Verify if a valid signature exists for a given ECPair key at the specified input index
|
|
384
531
|
*
|
|
@@ -2184,6 +2331,25 @@ export function __wbg_Error_e17e777aac105295(arg0, arg1) {
|
|
|
2184
2331
|
return addHeapObject(ret);
|
|
2185
2332
|
};
|
|
2186
2333
|
|
|
2334
|
+
export function __wbg_call_13410aac570ffff7() { return handleError(function (arg0, arg1) {
|
|
2335
|
+
const ret = getObject(arg0).call(getObject(arg1));
|
|
2336
|
+
return addHeapObject(ret);
|
|
2337
|
+
}, arguments) };
|
|
2338
|
+
|
|
2339
|
+
export function __wbg_call_a5400b25a865cfd8() { return handleError(function (arg0, arg1, arg2) {
|
|
2340
|
+
const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
|
|
2341
|
+
return addHeapObject(ret);
|
|
2342
|
+
}, arguments) };
|
|
2343
|
+
|
|
2344
|
+
export function __wbg_crypto_574e78ad8b13b65f(arg0) {
|
|
2345
|
+
const ret = getObject(arg0).crypto;
|
|
2346
|
+
return addHeapObject(ret);
|
|
2347
|
+
};
|
|
2348
|
+
|
|
2349
|
+
export function __wbg_getRandomValues_b8f5dbd5f3995a9e() { return handleError(function (arg0, arg1) {
|
|
2350
|
+
getObject(arg0).getRandomValues(getObject(arg1));
|
|
2351
|
+
}, arguments) };
|
|
2352
|
+
|
|
2187
2353
|
export function __wbg_get_458e874b43b18b25() { return handleError(function (arg0, arg1) {
|
|
2188
2354
|
const ret = Reflect.get(getObject(arg0), getObject(arg1));
|
|
2189
2355
|
return addHeapObject(ret);
|
|
@@ -2194,6 +2360,11 @@ export function __wbg_length_6bb7e81f9d7713e4(arg0) {
|
|
|
2194
2360
|
return ret;
|
|
2195
2361
|
};
|
|
2196
2362
|
|
|
2363
|
+
export function __wbg_msCrypto_a61aeb35a24c1329(arg0) {
|
|
2364
|
+
const ret = getObject(arg0).msCrypto;
|
|
2365
|
+
return addHeapObject(ret);
|
|
2366
|
+
};
|
|
2367
|
+
|
|
2197
2368
|
export function __wbg_new_19c25a3f2fa63a02() {
|
|
2198
2369
|
const ret = new Object();
|
|
2199
2370
|
return addHeapObject(ret);
|
|
@@ -2219,6 +2390,26 @@ export function __wbg_newfromslice_074c56947bd43469(arg0, arg1) {
|
|
|
2219
2390
|
return addHeapObject(ret);
|
|
2220
2391
|
};
|
|
2221
2392
|
|
|
2393
|
+
export function __wbg_newnoargs_254190557c45b4ec(arg0, arg1) {
|
|
2394
|
+
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
2395
|
+
return addHeapObject(ret);
|
|
2396
|
+
};
|
|
2397
|
+
|
|
2398
|
+
export function __wbg_newwithlength_a167dcc7aaa3ba77(arg0) {
|
|
2399
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
2400
|
+
return addHeapObject(ret);
|
|
2401
|
+
};
|
|
2402
|
+
|
|
2403
|
+
export function __wbg_node_905d3e251edff8a2(arg0) {
|
|
2404
|
+
const ret = getObject(arg0).node;
|
|
2405
|
+
return addHeapObject(ret);
|
|
2406
|
+
};
|
|
2407
|
+
|
|
2408
|
+
export function __wbg_process_dc0fbacc7c1c06f7(arg0) {
|
|
2409
|
+
const ret = getObject(arg0).process;
|
|
2410
|
+
return addHeapObject(ret);
|
|
2411
|
+
};
|
|
2412
|
+
|
|
2222
2413
|
export function __wbg_prototypesetcall_3d4a26c1ed734349(arg0, arg1, arg2) {
|
|
2223
2414
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
|
|
2224
2415
|
};
|
|
@@ -2228,16 +2419,71 @@ export function __wbg_push_330b2eb93e4e1212(arg0, arg1) {
|
|
|
2228
2419
|
return ret;
|
|
2229
2420
|
};
|
|
2230
2421
|
|
|
2422
|
+
export function __wbg_randomFillSync_ac0988aba3254290() { return handleError(function (arg0, arg1) {
|
|
2423
|
+
getObject(arg0).randomFillSync(takeObject(arg1));
|
|
2424
|
+
}, arguments) };
|
|
2425
|
+
|
|
2426
|
+
export function __wbg_require_60cc747a6bc5215a() { return handleError(function () {
|
|
2427
|
+
const ret = module.require;
|
|
2428
|
+
return addHeapObject(ret);
|
|
2429
|
+
}, arguments) };
|
|
2430
|
+
|
|
2231
2431
|
export function __wbg_set_453345bcda80b89a() { return handleError(function (arg0, arg1, arg2) {
|
|
2232
2432
|
const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
|
|
2233
2433
|
return ret;
|
|
2234
2434
|
}, arguments) };
|
|
2235
2435
|
|
|
2436
|
+
export function __wbg_static_accessor_GLOBAL_8921f820c2ce3f12() {
|
|
2437
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
2438
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
2439
|
+
};
|
|
2440
|
+
|
|
2441
|
+
export function __wbg_static_accessor_GLOBAL_THIS_f0a4409105898184() {
|
|
2442
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
2443
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
2444
|
+
};
|
|
2445
|
+
|
|
2446
|
+
export function __wbg_static_accessor_SELF_995b214ae681ff99() {
|
|
2447
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
2448
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
2449
|
+
};
|
|
2450
|
+
|
|
2451
|
+
export function __wbg_static_accessor_WINDOW_cde3890479c675ea() {
|
|
2452
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
2453
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
2454
|
+
};
|
|
2455
|
+
|
|
2456
|
+
export function __wbg_subarray_70fd07feefe14294(arg0, arg1, arg2) {
|
|
2457
|
+
const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
|
|
2458
|
+
return addHeapObject(ret);
|
|
2459
|
+
};
|
|
2460
|
+
|
|
2461
|
+
export function __wbg_versions_c01dfd4722a88165(arg0) {
|
|
2462
|
+
const ret = getObject(arg0).versions;
|
|
2463
|
+
return addHeapObject(ret);
|
|
2464
|
+
};
|
|
2465
|
+
|
|
2466
|
+
export function __wbg_wbindgenisfunction_8cee7dce3725ae74(arg0) {
|
|
2467
|
+
const ret = typeof(getObject(arg0)) === 'function';
|
|
2468
|
+
return ret;
|
|
2469
|
+
};
|
|
2470
|
+
|
|
2236
2471
|
export function __wbg_wbindgenisnull_f3037694abe4d97a(arg0) {
|
|
2237
2472
|
const ret = getObject(arg0) === null;
|
|
2238
2473
|
return ret;
|
|
2239
2474
|
};
|
|
2240
2475
|
|
|
2476
|
+
export function __wbg_wbindgenisobject_307a53c6bd97fbf8(arg0) {
|
|
2477
|
+
const val = getObject(arg0);
|
|
2478
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
2479
|
+
return ret;
|
|
2480
|
+
};
|
|
2481
|
+
|
|
2482
|
+
export function __wbg_wbindgenisstring_d4fa939789f003b0(arg0) {
|
|
2483
|
+
const ret = typeof(getObject(arg0)) === 'string';
|
|
2484
|
+
return ret;
|
|
2485
|
+
};
|
|
2486
|
+
|
|
2241
2487
|
export function __wbg_wbindgenisundefined_c4b71d073b92f3c5(arg0) {
|
|
2242
2488
|
const ret = getObject(arg0) === undefined;
|
|
2243
2489
|
return ret;
|
|
@@ -2275,6 +2521,12 @@ export function __wbindgen_cast_4625c577ab2ec9ee(arg0) {
|
|
|
2275
2521
|
return addHeapObject(ret);
|
|
2276
2522
|
};
|
|
2277
2523
|
|
|
2524
|
+
export function __wbindgen_cast_cb9088102bce6b30(arg0, arg1) {
|
|
2525
|
+
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
2526
|
+
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
2527
|
+
return addHeapObject(ret);
|
|
2528
|
+
};
|
|
2529
|
+
|
|
2278
2530
|
export function __wbindgen_cast_d6cd19b81560fd6e(arg0) {
|
|
2279
2531
|
// Cast intrinsic for `F64 -> Externref`.
|
|
2280
2532
|
const ret = arg0;
|
|
Binary file
|
|
@@ -2,11 +2,25 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
|
|
5
|
+
export const __wbg_wasmreplayprotection_free: (a: number, b: number) => void;
|
|
6
|
+
export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
|
|
7
|
+
export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
8
|
+
export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
9
|
+
export const wasmreplayprotection_from_addresses: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
10
|
+
export const wasmreplayprotection_from_output_scripts: (a: number, b: number) => number;
|
|
11
|
+
export const wasmreplayprotection_from_public_keys: (a: number, b: number, c: number) => void;
|
|
12
|
+
export const wrapminiscript_encode: (a: number, b: number) => void;
|
|
13
|
+
export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
14
|
+
export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
15
|
+
export const wrapminiscript_node: (a: number, b: number) => void;
|
|
16
|
+
export const wrapminiscript_toAsmString: (a: number, b: number) => void;
|
|
17
|
+
export const wrapminiscript_toString: (a: number, b: number) => void;
|
|
18
|
+
export const __wbg_addressnamespace_free: (a: number, b: number) => void;
|
|
5
19
|
export const __wbg_wasmbip32_free: (a: number, b: number) => void;
|
|
6
20
|
export const __wbg_wasmecpair_free: (a: number, b: number) => void;
|
|
7
21
|
export const __wbg_wasmrootwalletkeys_free: (a: number, b: number) => void;
|
|
8
|
-
export const
|
|
9
|
-
export const
|
|
22
|
+
export const addressnamespace_from_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
23
|
+
export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
10
24
|
export const wasmbip32_chain_code: (a: number) => number;
|
|
11
25
|
export const wasmbip32_depth: (a: number) => number;
|
|
12
26
|
export const wasmbip32_derive: (a: number, b: number, c: number) => void;
|
|
@@ -43,20 +57,21 @@ export const wasmrootwalletkeys_new: (a: number, b: number, c: number, d: number
|
|
|
43
57
|
export const wasmrootwalletkeys_user_key: (a: number) => number;
|
|
44
58
|
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;
|
|
45
59
|
export const wasmbip32_from_bip32_properties: (a: number, b: number) => void;
|
|
46
|
-
export const __wbg_addressnamespace_free: (a: number, b: number) => void;
|
|
47
60
|
export const __wbg_bitgopsbt_free: (a: number, b: number) => void;
|
|
61
|
+
export const __wbg_fixedscriptwalletnamespace_free: (a: number, b: number) => void;
|
|
48
62
|
export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
|
|
49
|
-
export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
|
|
50
63
|
export const __wbg_wrappsbt_free: (a: number, b: number) => void;
|
|
51
|
-
export const
|
|
52
|
-
export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
64
|
+
export const bitgopsbt_combine_musig2_nonces: (a: number, b: number, c: number) => void;
|
|
53
65
|
export const bitgopsbt_extract_transaction: (a: number, b: number) => void;
|
|
54
66
|
export const bitgopsbt_finalize_all_inputs: (a: number, b: number) => void;
|
|
55
67
|
export const bitgopsbt_from_bytes: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
68
|
+
export const bitgopsbt_generate_musig2_nonces: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
56
69
|
export const bitgopsbt_network: (a: number, b: number) => void;
|
|
57
70
|
export const bitgopsbt_parse_outputs_with_wallet_keys: (a: number, b: number, c: number) => void;
|
|
58
71
|
export const bitgopsbt_parse_transaction_with_wallet_keys: (a: number, b: number, c: number, d: number) => void;
|
|
59
72
|
export const bitgopsbt_serialize: (a: number, b: number) => void;
|
|
73
|
+
export const bitgopsbt_sign_with_privkey: (a: number, b: number, c: number, d: number) => void;
|
|
74
|
+
export const bitgopsbt_sign_with_xpriv: (a: number, b: number, c: number, d: number) => void;
|
|
60
75
|
export const bitgopsbt_unsigned_txid: (a: number, b: number) => void;
|
|
61
76
|
export const bitgopsbt_verify_replay_protection_signature: (a: number, b: number, c: number, d: number) => void;
|
|
62
77
|
export const bitgopsbt_verify_signature_with_pub: (a: number, b: number, c: number, d: number) => void;
|
|
@@ -74,12 +89,6 @@ export const wrapdescriptor_node: (a: number, b: number) => void;
|
|
|
74
89
|
export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
|
|
75
90
|
export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
|
|
76
91
|
export const wrapdescriptor_toString: (a: number, b: number) => void;
|
|
77
|
-
export const wrapminiscript_encode: (a: number, b: number) => void;
|
|
78
|
-
export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
79
|
-
export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
80
|
-
export const wrapminiscript_node: (a: number, b: number) => void;
|
|
81
|
-
export const wrapminiscript_toAsmString: (a: number, b: number) => void;
|
|
82
|
-
export const wrapminiscript_toString: (a: number, b: number) => void;
|
|
83
92
|
export const wrappsbt_clone: (a: number) => number;
|
|
84
93
|
export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
|
|
85
94
|
export const wrappsbt_finalize: (a: number, b: number) => void;
|
|
@@ -88,11 +97,6 @@ export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number)
|
|
|
88
97
|
export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
|
|
89
98
|
export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
90
99
|
export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
91
|
-
export const __wbg_fixedscriptwalletnamespace_free: (a: number, b: number) => void;
|
|
92
|
-
export const __wbg_wasmreplayprotection_free: (a: number, b: number) => void;
|
|
93
|
-
export const wasmreplayprotection_from_addresses: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
94
|
-
export const wasmreplayprotection_from_output_scripts: (a: number, b: number) => number;
|
|
95
|
-
export const wasmreplayprotection_from_public_keys: (a: number, b: number, c: number) => void;
|
|
96
100
|
export const rustsecp256k1_v0_10_0_context_create: (a: number) => number;
|
|
97
101
|
export const rustsecp256k1_v0_10_0_context_destroy: (a: number) => void;
|
|
98
102
|
export const rustsecp256k1_v0_10_0_default_error_callback_fn: (a: number, b: number) => void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RootWalletKeys } from "../../js/fixedScriptWallet/RootWalletKeys.js";
|
|
2
2
|
import { ECPair } from "../../js/ecpair.js";
|
|
3
|
+
import type { BitGoPsbt, NetworkName } from "../../js/fixedScriptWallet/index.js";
|
|
3
4
|
export type SignatureState = "unsigned" | "halfsigned" | "fullsigned";
|
|
4
5
|
export type Triple<T> = [T, T, T];
|
|
5
6
|
export type Bip32Derivation = {
|
|
@@ -80,6 +81,13 @@ export type Fixture = {
|
|
|
80
81
|
* Get PSBT buffer from a fixture
|
|
81
82
|
*/
|
|
82
83
|
export declare function getPsbtBuffer(fixture: Fixture): Buffer;
|
|
84
|
+
/**
|
|
85
|
+
* Get BitGoPsbt from a fixture
|
|
86
|
+
* @param fixture - The test fixture
|
|
87
|
+
* @param networkName - The network name for deserializing the PSBT
|
|
88
|
+
* @returns A BitGoPsbt instance
|
|
89
|
+
*/
|
|
90
|
+
export declare function getBitGoPsbt(fixture: Fixture, networkName: NetworkName): BitGoPsbt;
|
|
83
91
|
/**
|
|
84
92
|
* Load a PSBT fixture from JSON file
|
|
85
93
|
*/
|
|
@@ -6,6 +6,7 @@ import { dirname } from "node:path";
|
|
|
6
6
|
import { BIP32 } from "../../js/bip32.js";
|
|
7
7
|
import { RootWalletKeys } from "../../js/fixedScriptWallet/RootWalletKeys.js";
|
|
8
8
|
import { ECPair } from "../../js/ecpair.js";
|
|
9
|
+
import { fixedScriptWallet } from "../../js/index.js";
|
|
9
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
11
|
const __dirname = dirname(__filename);
|
|
11
12
|
/**
|
|
@@ -14,6 +15,15 @@ const __dirname = dirname(__filename);
|
|
|
14
15
|
export function getPsbtBuffer(fixture) {
|
|
15
16
|
return Buffer.from(fixture.psbtBase64, "base64");
|
|
16
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Get BitGoPsbt from a fixture
|
|
20
|
+
* @param fixture - The test fixture
|
|
21
|
+
* @param networkName - The network name for deserializing the PSBT
|
|
22
|
+
* @returns A BitGoPsbt instance
|
|
23
|
+
*/
|
|
24
|
+
export function getBitGoPsbt(fixture, networkName) {
|
|
25
|
+
return fixedScriptWallet.BitGoPsbt.fromBytes(getPsbtBuffer(fixture), networkName);
|
|
26
|
+
}
|
|
17
27
|
/**
|
|
18
28
|
* Load a PSBT fixture from JSON file
|
|
19
29
|
*/
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { BIP32 } from "../../js/bip32.js";
|
|
3
|
+
import { loadPsbtFixture, getBitGoPsbt } from "./fixtureUtil.js";
|
|
4
|
+
describe("MuSig2 nonce management", function () {
|
|
5
|
+
describe("Bitcoin mainnet", function () {
|
|
6
|
+
const networkName = "bitcoin";
|
|
7
|
+
let fixture;
|
|
8
|
+
let userKey;
|
|
9
|
+
let backupKey;
|
|
10
|
+
let bitgoKey;
|
|
11
|
+
before(function () {
|
|
12
|
+
fixture = loadPsbtFixture(networkName, "unsigned");
|
|
13
|
+
userKey = BIP32.fromBase58(fixture.walletKeys[0]);
|
|
14
|
+
backupKey = BIP32.fromBase58(fixture.walletKeys[1]);
|
|
15
|
+
bitgoKey = BIP32.fromBase58(fixture.walletKeys[2]);
|
|
16
|
+
});
|
|
17
|
+
it("should generate nonces for MuSig2 inputs with auto-generated session ID", function () {
|
|
18
|
+
const unsignedBitgoPsbt = getBitGoPsbt(fixture, networkName);
|
|
19
|
+
// Generate nonces with auto-generated session ID (no second parameter)
|
|
20
|
+
assert.doesNotThrow(() => {
|
|
21
|
+
unsignedBitgoPsbt.generateMusig2Nonces(userKey);
|
|
22
|
+
});
|
|
23
|
+
// Verify nonces were stored by serializing and deserializing
|
|
24
|
+
const serializedWithUserNonces = unsignedBitgoPsbt.serialize();
|
|
25
|
+
assert.ok(serializedWithUserNonces.length > getBitGoPsbt(fixture, networkName).serialize().length);
|
|
26
|
+
assert.doesNotThrow(() => {
|
|
27
|
+
unsignedBitgoPsbt.generateMusig2Nonces(bitgoKey);
|
|
28
|
+
});
|
|
29
|
+
const serializedWithBitgoNonces = unsignedBitgoPsbt.serialize();
|
|
30
|
+
assert.ok(serializedWithBitgoNonces.length > serializedWithUserNonces.length);
|
|
31
|
+
assert.throws(() => {
|
|
32
|
+
unsignedBitgoPsbt.generateMusig2Nonces(backupKey);
|
|
33
|
+
}, "Should throw error when generating nonces for backup key");
|
|
34
|
+
});
|
|
35
|
+
it("implements combineMusig2Nonces", function () {
|
|
36
|
+
const unsignedBitgoPsbtWithUserNonces = getBitGoPsbt(fixture, networkName);
|
|
37
|
+
unsignedBitgoPsbtWithUserNonces.generateMusig2Nonces(userKey);
|
|
38
|
+
const unsignedBitgoPsbtWithBitgoNonces = getBitGoPsbt(fixture, networkName);
|
|
39
|
+
unsignedBitgoPsbtWithBitgoNonces.generateMusig2Nonces(bitgoKey);
|
|
40
|
+
const unsignedBitgoPsbtWithBothNonces = getBitGoPsbt(fixture, networkName);
|
|
41
|
+
unsignedBitgoPsbtWithBothNonces.combineMusig2Nonces(unsignedBitgoPsbtWithUserNonces);
|
|
42
|
+
unsignedBitgoPsbtWithBothNonces.combineMusig2Nonces(unsignedBitgoPsbtWithBitgoNonces);
|
|
43
|
+
{
|
|
44
|
+
const psbt = getBitGoPsbt(fixture, networkName);
|
|
45
|
+
psbt.combineMusig2Nonces(unsignedBitgoPsbtWithUserNonces);
|
|
46
|
+
assert.strictEqual(psbt.serialize().length, unsignedBitgoPsbtWithUserNonces.serialize().length);
|
|
47
|
+
}
|
|
48
|
+
{
|
|
49
|
+
const psbt = getBitGoPsbt(fixture, networkName);
|
|
50
|
+
psbt.combineMusig2Nonces(unsignedBitgoPsbtWithBitgoNonces);
|
|
51
|
+
assert.strictEqual(psbt.serialize().length, unsignedBitgoPsbtWithBitgoNonces.serialize().length);
|
|
52
|
+
}
|
|
53
|
+
{
|
|
54
|
+
const psbt = getBitGoPsbt(fixture, networkName);
|
|
55
|
+
psbt.combineMusig2Nonces(unsignedBitgoPsbtWithUserNonces);
|
|
56
|
+
psbt.combineMusig2Nonces(unsignedBitgoPsbtWithBitgoNonces);
|
|
57
|
+
assert.strictEqual(psbt.serialize().length, unsignedBitgoPsbtWithBothNonces.serialize().length);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
it("should reject invalid session ID length", function () {
|
|
61
|
+
const unsignedBitgoPsbt = getBitGoPsbt(fixture, networkName);
|
|
62
|
+
// Invalid session ID (wrong length)
|
|
63
|
+
const invalidSessionId = new Uint8Array(16); // Should be 32 bytes
|
|
64
|
+
assert.throws(() => {
|
|
65
|
+
unsignedBitgoPsbt.generateMusig2Nonces(userKey, invalidSessionId);
|
|
66
|
+
}, "Should throw error for invalid session ID length");
|
|
67
|
+
});
|
|
68
|
+
it("should reject custom session ID on mainnet (security)", function () {
|
|
69
|
+
const unsignedBitgoPsbt = getBitGoPsbt(fixture, "bitcoin");
|
|
70
|
+
// Custom session ID should be rejected on mainnet for security
|
|
71
|
+
const customSessionId = new Uint8Array(32).fill(1);
|
|
72
|
+
assert.throws(() => {
|
|
73
|
+
unsignedBitgoPsbt.generateMusig2Nonces(userKey, customSessionId);
|
|
74
|
+
}, /Custom session_id is only allowed on testnets/, "Should throw error when providing custom session_id on mainnet");
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|