@argonprotocol/bitcoin 1.3.2 → 1.3.4

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/lib/index.js CHANGED
@@ -5,17 +5,41 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // ts/index.ts
8
- import { Transaction as Transaction2, Psbt as Psbt2, networks as networks3, Network, address as address2 } from "bitcoinjs-lib";
8
+ import { Transaction as Transaction2, Address as Address2, p2wsh as p2wsh2, p2wpkh as p2wpkh2, p2sh as p2sh2, p2pk, p2pkh as p2pkh2 } from "@scure/btc-signer";
9
9
 
10
10
  // ts/CosignScript.ts
11
- import { networks as networks2, payments, Psbt, Transaction } from "bitcoinjs-lib";
11
+ import { p2pkh, p2sh, p2wpkh, p2wsh, Transaction } from "@scure/btc-signer";
12
+ import {
13
+ hexToU8a as hexToU8a2,
14
+ u8aEq,
15
+ u8aToHex as u8aToHex2
16
+ } from "@argonprotocol/mainchain";
12
17
 
13
- // ts/wasm/bitcoin_bindings_bg.wasm
18
+ // wasm-module:/home/runner/work/mainchain/mainchain/bitcoin/nodejs/ts/wasm/bitcoin_bindings_bg.wasm
14
19
  var bitcoin_bindings_bg_exports = {};
15
20
  __export(bitcoin_bindings_bg_exports, {
16
- default: () => bitcoin_bindings_bg_default
21
+ __externref_table_dealloc: () => __externref_table_dealloc,
22
+ __wbindgen_export_3: () => __wbindgen_export_3,
23
+ __wbindgen_free: () => __wbindgen_free,
24
+ __wbindgen_malloc: () => __wbindgen_malloc,
25
+ __wbindgen_realloc: () => __wbindgen_realloc,
26
+ __wbindgen_start: () => __wbindgen_start,
27
+ calculateFee: () => calculateFee2,
28
+ createCosignPubkey: () => createCosignPubkey2,
29
+ getCosignPsbt: () => getCosignPsbt2,
30
+ instance: () => instance,
31
+ memory: () => memory,
32
+ module: () => module2,
33
+ rustsecp256k1_v0_10_0_context_create: () => rustsecp256k1_v0_10_0_context_create,
34
+ rustsecp256k1_v0_10_0_context_destroy: () => rustsecp256k1_v0_10_0_context_destroy,
35
+ rustsecp256k1_v0_10_0_default_error_callback_fn: () => rustsecp256k1_v0_10_0_default_error_callback_fn,
36
+ rustsecp256k1_v0_10_0_default_illegal_callback_fn: () => rustsecp256k1_v0_10_0_default_illegal_callback_fn,
37
+ signPsbt: () => signPsbt2,
38
+ signPsbtDerived: () => signPsbtDerived2
17
39
  });
18
- var bitcoin_bindings_bg_default = "./bitcoin_bindings_bg-NTNPUTAE.wasm";
40
+
41
+ // wasm-deferred:/home/runner/work/mainchain/mainchain/bitcoin/nodejs/ts/wasm/bitcoin_bindings_bg.wasm
42
+ var bitcoin_bindings_bg_default = "./bitcoin_bindings_bg-67GA3ENS.wasm";
19
43
 
20
44
  // ts/wasm/bitcoin_bindings_bg.js
21
45
  var wasm;
@@ -79,6 +103,13 @@ function passStringToWasm0(arg, malloc, realloc) {
79
103
  WASM_VECTOR_LEN = offset;
80
104
  return ptr;
81
105
  }
106
+ var cachedDataViewMemory0 = null;
107
+ function getDataViewMemory0() {
108
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
109
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
110
+ }
111
+ return cachedDataViewMemory0;
112
+ }
82
113
  function takeFromExternrefTable0(idx) {
83
114
  const value = wasm.__wbindgen_export_3.get(idx);
84
115
  wasm.__externref_table_dealloc(idx);
@@ -223,80 +254,206 @@ var BitcoinNetwork = Object.freeze({
223
254
  Regtest: 3,
224
255
  "3": "Regtest"
225
256
  });
257
+ function __wbg_error_7534b8e9a36f1ab4(arg0, arg1) {
258
+ let deferred0_0;
259
+ let deferred0_1;
260
+ try {
261
+ deferred0_0 = arg0;
262
+ deferred0_1 = arg1;
263
+ console.error(getStringFromWasm0(arg0, arg1));
264
+ } finally {
265
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
266
+ }
267
+ }
268
+ function __wbg_new_8a6f238a6ece86ea() {
269
+ const ret = new Error();
270
+ return ret;
271
+ }
272
+ function __wbg_stack_0ed75d68575b0f3c(arg0, arg1) {
273
+ const ret = arg1.stack;
274
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
275
+ const len1 = WASM_VECTOR_LEN;
276
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
277
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
278
+ }
279
+ function __wbindgen_init_externref_table() {
280
+ const table = wasm.__wbindgen_export_3;
281
+ const offset = table.grow(4);
282
+ table.set(0, void 0);
283
+ table.set(offset + 0, void 0);
284
+ table.set(offset + 1, null);
285
+ table.set(offset + 2, true);
286
+ table.set(offset + 3, false);
287
+ ;
288
+ }
289
+ function __wbindgen_string_new(arg0, arg1) {
290
+ const ret = getStringFromWasm0(arg0, arg1);
291
+ return ret;
292
+ }
293
+ function __wbindgen_throw(arg0, arg1) {
294
+ throw new Error(getStringFromWasm0(arg0, arg1));
295
+ }
296
+
297
+ // wasm-module:/home/runner/work/mainchain/mainchain/bitcoin/nodejs/ts/wasm/bitcoin_bindings_bg.wasm
298
+ var imports = {
299
+ ["./bitcoin_bindings_bg.js"]: {
300
+ __wbindgen_string_new,
301
+ __wbg_new_8a6f238a6ece86ea,
302
+ __wbg_stack_0ed75d68575b0f3c,
303
+ __wbg_error_7534b8e9a36f1ab4,
304
+ __wbindgen_throw,
305
+ __wbindgen_init_externref_table
306
+ }
307
+ };
308
+ async function loadWasm(module3, imports2) {
309
+ if (typeof module3 === "string") {
310
+ if (module3.startsWith("./")) {
311
+ module3 = new URL(module3, import.meta.url).href;
312
+ }
313
+ if (module3.startsWith("file://")) {
314
+ const fs = await import("fs");
315
+ module3 = await fs.promises.readFile(new URL(module3));
316
+ } else {
317
+ const moduleRequest = await fetch(module3);
318
+ if (typeof WebAssembly.instantiateStreaming === "function") {
319
+ try {
320
+ return await WebAssembly.instantiateStreaming(moduleRequest, imports2);
321
+ } catch (e) {
322
+ if (moduleRequest.headers.get("Content-Type") != "application/wasm") {
323
+ console.warn(e);
324
+ } else {
325
+ throw e;
326
+ }
327
+ }
328
+ }
329
+ module3 = await moduleRequest.arrayBuffer();
330
+ }
331
+ }
332
+ return await WebAssembly.instantiate(module3, imports2);
333
+ }
334
+ var { instance, module: module2 } = await loadWasm(bitcoin_bindings_bg_default, imports);
335
+ var memory = instance.exports.memory;
336
+ var createCosignPubkey2 = instance.exports.createCosignPubkey;
337
+ var calculateFee2 = instance.exports.calculateFee;
338
+ var signPsbtDerived2 = instance.exports.signPsbtDerived;
339
+ var signPsbt2 = instance.exports.signPsbt;
340
+ var getCosignPsbt2 = instance.exports.getCosignPsbt;
341
+ var rustsecp256k1_v0_10_0_context_create = instance.exports.rustsecp256k1_v0_10_0_context_create;
342
+ var rustsecp256k1_v0_10_0_context_destroy = instance.exports.rustsecp256k1_v0_10_0_context_destroy;
343
+ var rustsecp256k1_v0_10_0_default_illegal_callback_fn = instance.exports.rustsecp256k1_v0_10_0_default_illegal_callback_fn;
344
+ var rustsecp256k1_v0_10_0_default_error_callback_fn = instance.exports.rustsecp256k1_v0_10_0_default_error_callback_fn;
345
+ var __wbindgen_free = instance.exports.__wbindgen_free;
346
+ var __wbindgen_malloc = instance.exports.__wbindgen_malloc;
347
+ var __wbindgen_realloc = instance.exports.__wbindgen_realloc;
348
+ var __wbindgen_export_3 = instance.exports.__wbindgen_export_3;
349
+ var __externref_table_dealloc = instance.exports.__externref_table_dealloc;
350
+ var __wbindgen_start = instance.exports.__wbindgen_start;
226
351
 
227
352
  // ts/wasm/bitcoin_bindings.js
228
353
  __wbg_set_wasm(bitcoin_bindings_bg_exports);
229
- (void 0)();
354
+ __wbindgen_start();
230
355
 
231
356
  // ts/KeysHelper.ts
232
- import { address } from "bitcoinjs-lib";
233
- import BIP32Factory from "bip32";
234
- import * as ecc from "tiny-secp256k1";
235
- import * as bip39 from "bip39";
236
- function getBip32Factory() {
237
- return BIP32Factory(ecc);
357
+ import { Address, NETWORK, OutScript, TEST_NETWORK } from "@scure/btc-signer";
358
+ import { bech32 } from "@scure/base";
359
+ import { HDKey } from "@scure/bip32";
360
+ import { hexToU8a, u8aToHex } from "@argonprotocol/mainchain";
361
+ import * as secp256k1 from "@noble/secp256k1";
362
+ function getBip32Version(network) {
363
+ if (!network) {
364
+ return void 0;
365
+ }
366
+ if (network === BitcoinNetwork.Testnet || network === BitcoinNetwork.Signet) {
367
+ return {
368
+ private: 70615956,
369
+ // tprv
370
+ public: 70617039
371
+ // tpub
372
+ };
373
+ }
374
+ if (network === BitcoinNetwork.Regtest) {
375
+ return {
376
+ private: 70615956,
377
+ // rprv
378
+ public: 70617039
379
+ // rpub
380
+ };
381
+ }
382
+ return void 0;
238
383
  }
239
384
  function getChildXpriv(bip39Seed, hdPath, network) {
240
- const root = BIP32Factory(ecc).fromSeed(bip39Seed, network);
241
- return root.derivePath(hdPath);
242
- }
243
- function getBip39Seed(mnemonic, passphrase) {
244
- return bip39.mnemonicToSeedSync(mnemonic, passphrase);
385
+ const root = HDKey.fromMasterSeed(bip39Seed, getBip32Version(network));
386
+ return root.derive(hdPath);
245
387
  }
246
388
  function getXpubFromXpriv(xpriv) {
247
- return xpriv.neutered().toBase58();
389
+ return xpriv.publicExtendedKey;
248
390
  }
249
391
  function getCompressedPubkey(pubkey) {
250
- const pubkeyBuffer = keyToBuffer(pubkey);
251
- if (ecc.isPointCompressed(pubkeyBuffer)) {
252
- return pubkeyBuffer;
392
+ const pubkeyUint8Array = keyToU8a(pubkey);
393
+ if (pubkeyUint8Array.length === 33) {
394
+ return pubkeyUint8Array;
253
395
  }
254
- return Buffer.from(ecc.pointCompress(pubkeyBuffer, true));
396
+ const point = secp256k1.Point.fromHex(pubkeyUint8Array);
397
+ return point.toRawBytes(true);
398
+ }
399
+ function getBech32Prefix(network) {
400
+ return getScureNetwork(network).bech32;
255
401
  }
256
- function stripLeadingHexPrefix(hex) {
257
- if (hex.startsWith("0x")) {
258
- return hex.slice(2);
402
+ function p2wshScriptHexToAddress(scriptPubKeyHex, network) {
403
+ const script = hexToU8a(scriptPubKeyHex);
404
+ if (script.byteLength !== 34 || script[0] !== 0 || script[1] !== 32) {
405
+ throw new Error("Invalid P2WSH scriptPubKey");
259
406
  }
260
- return hex;
407
+ const witnessProgram = script.slice(2);
408
+ const version = 0;
409
+ const prefix = getBech32Prefix(network);
410
+ return bech32.encode(prefix, [version, ...bech32.toWords(witnessProgram)]);
261
411
  }
262
- function addressBytesHex(addressString, network) {
263
- if (addressString.startsWith("0x")) {
264
- return addressString;
412
+ function addressBytesHex(address, network) {
413
+ if (address.startsWith("0x")) {
414
+ return address;
265
415
  }
266
- console.log("Converting address to bytes:", addressString, network);
267
- if (/^[0-9a-fA-F]+$/.test(addressString) && !addressString.startsWith("bc")) {
268
- return `0x${addressString}`;
416
+ const bech32Prefix = getBech32Prefix(network);
417
+ if (/^[0-9a-fA-F]+$/.test(address) && !address.startsWith("bc") && !address.startsWith(bech32Prefix)) {
418
+ return `0x${address}`;
269
419
  }
270
- const scriptbuf = address.toOutputScript(addressString, network);
271
- return `0x${scriptbuf.toString("hex")}`;
420
+ const btcNetwork = getScureNetwork(network);
421
+ const decoded = Address(btcNetwork).decode(address);
422
+ const out = OutScript.encode(decoded);
423
+ return u8aToHex(out);
272
424
  }
273
- function keyToBuffer(key) {
274
- if (typeof key === "string") {
275
- key = stripLeadingHexPrefix(key);
276
- return Buffer.from(key, "hex");
425
+ function keyToU8a(pubkey) {
426
+ return typeof pubkey === "string" ? hexToU8a(pubkey) : pubkey;
427
+ }
428
+ function getScureNetwork(network) {
429
+ if (network === BitcoinNetwork.Bitcoin) {
430
+ return NETWORK;
431
+ } else if (network === BitcoinNetwork.Testnet || network === BitcoinNetwork.Signet) {
432
+ return TEST_NETWORK;
433
+ } else {
434
+ return {
435
+ bech32: "bcrt",
436
+ pubKeyHash: 111,
437
+ scriptHash: 196,
438
+ wif: 239
439
+ };
277
440
  }
278
- return Buffer.from(key);
279
441
  }
280
442
 
281
443
  // ts/CosignScript.ts
282
- var CosignScript = class _CosignScript {
444
+ var CosignScript = class {
283
445
  constructor(lock, network) {
284
446
  this.lock = lock;
285
- if (network === networks2.bitcoin || network === networks2.testnet || network === networks2.regtest) {
286
- this.network = network;
287
- } else {
288
- this.network = _CosignScript.getBitcoinJsNetwork(
289
- network
290
- );
291
- }
447
+ this.network = network;
292
448
  }
293
- network;
294
449
  getFundingPsbt() {
295
450
  const { lock, network } = this;
296
- return new Psbt({ network }).addOutput({
297
- script: keyToBuffer(lock.p2wshScriptHashHex),
298
- value: Number(lock.satoshis)
451
+ const tx = new Transaction();
452
+ tx.addOutput({
453
+ script: keyToU8a(lock.p2wshScriptHashHex),
454
+ amount: lock.satoshis
299
455
  });
456
+ return tx.toPSBT(0);
300
457
  }
301
458
  calculateFee(feeRatePerSatVb, toScriptPubkey) {
302
459
  toScriptPubkey = addressBytesHex(toScriptPubkey, this.network);
@@ -308,7 +465,7 @@ var CosignScript = class _CosignScript {
308
465
  BigInt(lock.vaultClaimHeight),
309
466
  BigInt(lock.openClaimHeight),
310
467
  BigInt(lock.createdAtHeight),
311
- toBitcoinNetwork(network),
468
+ network,
312
469
  feeRatePerSatVb,
313
470
  toScriptPubkey
314
471
  );
@@ -322,7 +479,7 @@ var CosignScript = class _CosignScript {
322
479
  BigInt(lock.vaultClaimHeight),
323
480
  BigInt(lock.openClaimHeight),
324
481
  BigInt(lock.createdAtHeight),
325
- toBitcoinNetwork(network)
482
+ network
326
483
  );
327
484
  }
328
485
  getCosignPsbt(args) {
@@ -339,21 +496,22 @@ var CosignScript = class _CosignScript {
339
496
  BigInt(lock.vaultClaimHeight),
340
497
  BigInt(lock.openClaimHeight),
341
498
  BigInt(lock.createdAtHeight),
342
- toBitcoinNetwork(network),
499
+ network,
343
500
  releaseRequest.toScriptPubkey,
344
501
  releaseRequest.bitcoinNetworkFee
345
502
  );
346
503
  return this.psbtFromHex(psbtStr);
347
504
  }
348
505
  psbtFromHex(psbtHex) {
349
- const psbt = Psbt.fromHex(psbtHex.replace(/^0x(.+)/, "$1"), { network: this.network });
350
- if (psbt.data.inputs.length === 0) {
506
+ const psbtBytes = hexToU8a2(psbtHex);
507
+ const tx = Transaction.fromPSBT(psbtBytes);
508
+ if (tx.inputsLength === 0) {
351
509
  throw new Error("PSBT has no inputs");
352
510
  }
353
- if (psbt.data.outputs.length === 0) {
511
+ if (tx.outputsLength === 0) {
354
512
  throw new Error("PSBT has no outputs");
355
513
  }
356
- return psbt;
514
+ return tx;
357
515
  }
358
516
  /**
359
517
  * Cosigns the PSBT with the vault xpub.
@@ -362,21 +520,33 @@ var CosignScript = class _CosignScript {
362
520
  * @param vaultXpriv - The vault's extended private key of which the xpub was used to create the vault.
363
521
  */
364
522
  vaultCosignPsbt(psbt, lock, vaultXpriv) {
365
- const parentFingerprint = Buffer.from(lock.vaultXpubSources.parentFingerprint);
366
- if (!parentFingerprint.equals(vaultXpriv.fingerprint)) {
523
+ const parentFingerprint = lock.vaultXpubSources.parentFingerprint;
524
+ const vaultFingerprint = vaultXpriv.identifier?.slice(0, 4);
525
+ if (!vaultFingerprint) {
526
+ throw new Error("Could not get vault fingerprint from HDKey");
527
+ }
528
+ if (!u8aEq(parentFingerprint, vaultFingerprint)) {
367
529
  throw new Error(
368
- `Vault xpub fingerprint ${parentFingerprint.toString("hex")} does not match the vault xpriv fingerprint ${vaultXpriv.fingerprint.toString("hex")}`
530
+ `Vault xpub fingerprint ${u8aToHex2(parentFingerprint)} does not match the vault xpriv fingerprint ${u8aToHex2(vaultFingerprint)}`
369
531
  );
370
532
  }
371
533
  const childPath = `${lock.vaultXpubSources.cosignHdIndex}`;
372
- const pubkey = vaultXpriv.derivePath(childPath).publicKey;
373
- const vaultPubkey = keyToBuffer(lock.vaultPubkey);
374
- if (!vaultPubkey.equals(pubkey)) {
534
+ const pubkey = vaultXpriv.deriveChild(lock.vaultXpubSources.cosignHdIndex).publicKey;
535
+ if (!pubkey) {
536
+ throw new Error(`Failed to derive public key for path ${childPath}`);
537
+ }
538
+ const vaultPubkey = keyToU8a(lock.vaultPubkey);
539
+ if (!u8aEq(vaultPubkey, pubkey)) {
375
540
  throw new Error(
376
- `Vault pubkey ${vaultPubkey.toString("hex")} does not match the derived pubkey ${pubkey.toString("hex")} using path ${childPath}`
541
+ `Vault pubkey ${u8aToHex2(vaultPubkey)} does not match the derived pubkey ${u8aToHex2(pubkey)} using path ${childPath}`
377
542
  );
378
543
  }
379
- const signedPsbt = signPsbtDerived(psbt.toHex(), vaultXpriv.toBase58(), childPath, false);
544
+ const signedPsbt = signPsbtDerived(
545
+ u8aToHex2(psbt.toPSBT()),
546
+ vaultXpriv.privateExtendedKey,
547
+ childPath,
548
+ false
549
+ );
380
550
  psbt = this.psbtFromHex(signedPsbt);
381
551
  return psbt;
382
552
  }
@@ -388,84 +558,80 @@ var CosignScript = class _CosignScript {
388
558
  const psbt = this.getCosignPsbt(args);
389
559
  const { addTx, vaultCosignature, ownerXpriv, ownerXprivChildHdPath } = args;
390
560
  psbt.updateInput(0, {
391
- partialSig: [
392
- {
393
- pubkey: keyToBuffer(lock.vaultPubkey),
394
- signature: Buffer.from(vaultCosignature)
395
- }
396
- ]
561
+ partialSig: [[keyToU8a(lock.vaultPubkey), vaultCosignature]]
397
562
  });
398
- const derivePubkey = ownerXpriv.publicKey;
399
- const ownerPubkey = keyToBuffer(lock.ownerPubkey);
400
- if (!ownerPubkey.equals(derivePubkey)) {
563
+ const derivePubkey = ownerXprivChildHdPath ? ownerXpriv.derive(ownerXprivChildHdPath).publicKey : ownerXpriv.publicKey;
564
+ if (!derivePubkey) {
565
+ throw new Error("Failed to derive owner public key");
566
+ }
567
+ const ownerPubkey = keyToU8a(lock.ownerPubkey);
568
+ if (!u8aEq(ownerPubkey, derivePubkey)) {
401
569
  throw new Error(
402
- `Owner pubkey ${ownerPubkey.toString("hex")} does not match the derived pubkey ${derivePubkey.toString("hex")}`
570
+ `Owner pubkey ${u8aToHex2(ownerPubkey)} does not match the derived pubkey ${u8aToHex2(derivePubkey)}`
403
571
  );
404
572
  }
405
573
  if (addTx) {
406
- const tx = Transaction.fromHex(addTx.replace(/^0x(.+)/, "$1"));
407
- for (let i = 0; i < tx.outs.length; i++) {
408
- const output = tx.outs[i];
574
+ const addTxBytes = hexToU8a2(addTx);
575
+ const tx = Transaction.fromPSBT(addTxBytes);
576
+ for (let i = 0; i < tx.outputsLength; i++) {
577
+ const output = tx.getOutput(i);
578
+ const network = getScureNetwork(this.network);
409
579
  const scripts = [
410
- payments.p2wpkh({ pubkey: ownerPubkey }).output,
411
- payments.p2sh({ redeem: payments.p2wpkh({ pubkey: ownerPubkey }) }).output,
412
- payments.p2pkh({ pubkey: ownerPubkey }).output
580
+ p2wpkh(ownerPubkey, network).script,
581
+ p2wsh(p2wpkh(ownerPubkey, network), network).script,
582
+ p2sh(p2pkh(ownerPubkey, network), network).script,
583
+ p2pkh(ownerPubkey, network).script
413
584
  ];
414
- if (scripts.some((x) => x && output.script.equals(x))) {
585
+ if (scripts.some((x) => x && output.script && u8aEq(output.script, x))) {
415
586
  psbt.addInput({
416
- hash: tx.getId(),
587
+ txid: tx.id,
417
588
  index: i,
418
589
  witnessUtxo: {
419
590
  script: output.script,
420
- value: output.value
591
+ amount: output.amount
421
592
  }
422
593
  });
423
594
  }
424
595
  }
425
596
  }
426
- const signedPsbt = ownerXprivChildHdPath ? signPsbtDerived(psbt.toHex(), ownerXpriv.toBase58(), ownerXprivChildHdPath, true) : signPsbt(
427
- psbt.toHex(),
428
- toBitcoinNetwork(this.network),
429
- ownerXpriv.privateKey.toString("hex"),
430
- true
431
- );
432
- const finalPsbt = this.psbtFromHex(signedPsbt);
433
- return finalPsbt.extractTransaction();
434
- }
435
- static getBitcoinJsNetwork(network) {
436
- if (network.isBitcoin) return networks2.bitcoin;
437
- if (network.isTestnet || network.isSignet) return networks2.testnet;
438
- if (network.isRegtest) return networks2.regtest;
439
- throw new Error("Unsupported network: " + network);
597
+ const psbtBytes = u8aToHex2(psbt.toPSBT());
598
+ const signedPsbt = ownerXprivChildHdPath ? signPsbtDerived(psbtBytes, ownerXpriv.privateExtendedKey, ownerXprivChildHdPath, true) : signPsbt(psbtBytes, this.network, u8aToHex2(ownerXpriv.privateKey, void 0, false), true);
599
+ return this.psbtFromHex(signedPsbt);
440
600
  }
441
601
  };
442
- function toBitcoinNetwork(network) {
443
- if (network === networks2.bitcoin) {
602
+ function getBitcoinNetworkFromApi(network) {
603
+ if (network.isBitcoin) {
444
604
  return BitcoinNetwork.Bitcoin;
445
- } else if (network === networks2.testnet) {
605
+ } else if (network.isTestnet) {
446
606
  return BitcoinNetwork.Testnet;
447
- } else if (network === networks2.regtest) {
607
+ } else if (network.isRegtest) {
448
608
  return BitcoinNetwork.Regtest;
449
609
  }
450
610
  throw new Error("Unsupported network: " + network);
451
611
  }
452
612
 
453
613
  // ts/index.ts
454
- import * as bip392 from "bip39";
614
+ import * as bip39 from "@scure/bip39";
455
615
  export {
616
+ Address2 as Address,
617
+ BitcoinNetwork,
456
618
  CosignScript,
457
- Network,
458
- Psbt2 as Psbt,
619
+ HDKey,
459
620
  Transaction2 as Transaction,
460
- address2 as address,
461
621
  addressBytesHex,
462
- bip392 as bip39,
463
- getBip32Factory,
464
- getBip39Seed,
622
+ bip39,
623
+ getBech32Prefix,
624
+ getBip32Version,
625
+ getBitcoinNetworkFromApi,
465
626
  getChildXpriv,
466
627
  getCompressedPubkey,
628
+ getScureNetwork,
467
629
  getXpubFromXpriv,
468
- keyToBuffer,
469
- networks3 as networks,
470
- stripLeadingHexPrefix
630
+ keyToU8a,
631
+ p2pk,
632
+ p2pkh2 as p2pkh,
633
+ p2sh2 as p2sh,
634
+ p2wpkh2 as p2wpkh,
635
+ p2wsh2 as p2wsh,
636
+ p2wshScriptHexToAddress
471
637
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argonprotocol/bitcoin",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "A client for interop with bitcoin in nodejs.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,32 +13,54 @@
13
13
  },
14
14
  "homepage": "https://github.com/argonprotocol/mainchain#readme",
15
15
  "scripts": {
16
- "wasm-pack": "wasm-pack build --target bundler --release --out-dir ts/wasm --out-name bitcoin_bindings --no-pack --no-opt",
16
+ "wasm-pack": "wasm-pack build --target bundler --release --out-dir ts/wasm --out-name bitcoin_bindings --no-pack",
17
17
  "prebuild": "yarn workspace @argonprotocol/mainchain run build",
18
18
  "build": "yarn wasm-pack && yarn tsc",
19
19
  "pretsc": "yarn workspace @argonprotocol/mainchain run tsc",
20
20
  "tsc": "yarn pretsc && tsup",
21
21
  "test": "yarn build && vitest --run --typecheck --disableConsoleIntercept",
22
22
  "test:ci": "yarn tsc && vitest --run --disableConsoleIntercept",
23
- "tsup": "yarn tsc"
23
+ "tsup": "yarn tsc",
24
+ "watch": "yarn pretsc && tsup --watch"
24
25
  },
25
26
  "files": [
26
- "lib/"
27
+ "lib/",
28
+ "browser/"
27
29
  ],
28
30
  "type": "module",
29
- "bin": "./lib/cli.js",
30
31
  "module": "./lib/index.js",
31
32
  "types": "./lib/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./lib/index.d.ts",
36
+ "import": "./lib/index.js",
37
+ "browser": {
38
+ "types": "./browser/index.d.ts",
39
+ "default": "./browser/index.js"
40
+ }
41
+ },
42
+ "./browser": {
43
+ "types": "./browser/index.d.ts",
44
+ "default": "./browser/index.js"
45
+ }
46
+ },
47
+ "sideEffects": [
48
+ "./ts/wasm/bitcoin_bindings.js",
49
+ "./lib/index.js",
50
+ "./browser/index.js"
51
+ ],
32
52
  "dependencies": {
33
- "@argonprotocol/mainchain": "1.3.2",
34
- "bignumber.js": "^9.1.2",
35
- "bip32": "^4.0.0",
36
- "bip39": "^3.1.0",
37
- "bitcoinjs-lib": "^6.1.7",
38
- "tiny-secp256k1": "^2.2.3"
53
+ "@argonprotocol/mainchain": "1.3.4",
54
+ "@noble/secp256k1": "^2.3.0",
55
+ "@scure/bip32": "^1.7.0",
56
+ "@scure/bip39": "^1.6.0",
57
+ "@scure/btc-signer": "^1.8.1",
58
+ "bignumber.js": "^9.1.2"
39
59
  },
40
60
  "devDependencies": {
41
- "@argonprotocol/testing": "1.3.2",
61
+ "@argonprotocol/testing": "1.3.4",
62
+ "@types/node": "22.16.3",
63
+ "esbuild-plugin-wasm": "^1.1.0",
42
64
  "tsup": "^8.4.0",
43
65
  "tsx": "^4.19.2",
44
66
  "typescript": "^5.8.3",