@argonprotocol/bitcoin 1.4.12 → 1.4.13-dev.d9b3437c

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,10 +5,10 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // ts/index.ts
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";
8
+ import { Transaction as Transaction2, Address as Address2, p2wsh, p2wpkh, p2sh, p2pk, p2pkh } from "@scure/btc-signer";
9
9
 
10
10
  // ts/CosignScript.ts
11
- import { p2pkh, p2sh, p2wpkh, p2wsh, Transaction } from "@scure/btc-signer";
11
+ import { Transaction } from "@scure/btc-signer";
12
12
  import {
13
13
  hexToU8a as hexToU8a2,
14
14
  u8aEq,
@@ -18,6 +18,7 @@ import {
18
18
  // wasm-module:/home/runner/work/mainchain/mainchain/bitcoin/nodejs/ts/wasm/bitcoin_bindings_bg.wasm
19
19
  var bitcoin_bindings_bg_exports = {};
20
20
  __export(bitcoin_bindings_bg_exports, {
21
+ __externref_table_alloc: () => __externref_table_alloc,
21
22
  __externref_table_dealloc: () => __externref_table_dealloc,
22
23
  __wbindgen_externrefs: () => __wbindgen_externrefs,
23
24
  __wbindgen_free: () => __wbindgen_free,
@@ -39,7 +40,7 @@ __export(bitcoin_bindings_bg_exports, {
39
40
  });
40
41
 
41
42
  // wasm-deferred:/home/runner/work/mainchain/mainchain/bitcoin/nodejs/ts/wasm/bitcoin_bindings_bg.wasm
42
- var bitcoin_bindings_bg_default = "./bitcoin_bindings_bg-G57R5LDM.wasm";
43
+ var bitcoin_bindings_bg_default = "./bitcoin_bindings_bg-RU6TWQ7W.wasm";
43
44
 
44
45
  // ts/wasm/bitcoin_bindings_bg.js
45
46
  var BitcoinNetwork = Object.freeze({
@@ -64,7 +65,7 @@ var BitcoinNetwork = Object.freeze({
64
65
  Regtest: 3,
65
66
  "3": "Regtest"
66
67
  });
67
- function calculateFee(vault_pubkey_hex, vault_claim_pubkey_hex, owner_pubkey_hex, vault_claim_height, open_claim_height, created_at_height, bitcoin_network, fee_rate_sats_per_vb, to_script_pubkey) {
68
+ function calculateFee(vault_pubkey_hex, vault_claim_pubkey_hex, owner_pubkey_hex, vault_claim_height, open_claim_height, created_at_height, bitcoin_network, fee_rate_sats_per_vb, input_count, to_script_pubkey, has_change) {
68
69
  const ptr0 = passStringToWasm0(vault_pubkey_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
69
70
  const len0 = WASM_VECTOR_LEN;
70
71
  const ptr1 = passStringToWasm0(vault_claim_pubkey_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -73,7 +74,7 @@ function calculateFee(vault_pubkey_hex, vault_claim_pubkey_hex, owner_pubkey_hex
73
74
  const len2 = WASM_VECTOR_LEN;
74
75
  const ptr3 = passStringToWasm0(to_script_pubkey, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
75
76
  const len3 = WASM_VECTOR_LEN;
76
- const ret = wasm.calculateFee(ptr0, len0, ptr1, len1, ptr2, len2, vault_claim_height, open_claim_height, created_at_height, bitcoin_network, fee_rate_sats_per_vb, ptr3, len3);
77
+ const ret = wasm.calculateFee(ptr0, len0, ptr1, len1, ptr2, len2, vault_claim_height, open_claim_height, created_at_height, bitcoin_network, fee_rate_sats_per_vb, input_count, ptr3, len3, has_change);
77
78
  if (ret[2]) {
78
79
  throw takeFromExternrefTable0(ret[1]);
79
80
  }
@@ -104,11 +105,11 @@ function createCosignPubkey(vault_pubkey_hex, vault_claim_pubkey_hex, owner_pubk
104
105
  wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
105
106
  }
106
107
  }
107
- function getCosignPsbt(txid, vout, satoshis, vault_pubkey_hex, vault_claim_pubkey_hex, owner_pubkey_hex, vault_claim_height, open_claim_height, created_at_height, bitcoin_network, to_script_pubkey_hex, bitcoin_network_fee) {
108
+ function getCosignPsbt(utxos, vault_pubkey_hex, vault_claim_pubkey_hex, owner_pubkey_hex, vault_claim_height, open_claim_height, created_at_height, bitcoin_network, to_script_pubkey_hex, destination_satoshis, change_satoshis, bitcoin_network_fee) {
108
109
  let deferred7_0;
109
110
  let deferred7_1;
110
111
  try {
111
- const ptr0 = passStringToWasm0(txid, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
112
+ const ptr0 = passArrayJsValueToWasm0(utxos, wasm.__wbindgen_malloc);
112
113
  const len0 = WASM_VECTOR_LEN;
113
114
  const ptr1 = passStringToWasm0(vault_pubkey_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
114
115
  const len1 = WASM_VECTOR_LEN;
@@ -118,7 +119,7 @@ function getCosignPsbt(txid, vout, satoshis, vault_pubkey_hex, vault_claim_pubke
118
119
  const len3 = WASM_VECTOR_LEN;
119
120
  const ptr4 = passStringToWasm0(to_script_pubkey_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
120
121
  const len4 = WASM_VECTOR_LEN;
121
- const ret = wasm.getCosignPsbt(ptr0, len0, vout, satoshis, ptr1, len1, ptr2, len2, ptr3, len3, vault_claim_height, open_claim_height, created_at_height, bitcoin_network, ptr4, len4, bitcoin_network_fee);
122
+ const ret = wasm.getCosignPsbt(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, vault_claim_height, open_claim_height, created_at_height, bitcoin_network, ptr4, len4, destination_satoshis, change_satoshis, bitcoin_network_fee);
122
123
  var ptr6 = ret[0];
123
124
  var len6 = ret[1];
124
125
  if (ret[3]) {
@@ -199,6 +200,10 @@ function __wbg_new_8a6f238a6ece86ea() {
199
200
  const ret = new Error();
200
201
  return ret;
201
202
  }
203
+ function __wbg_satoshis_653e28e5089976d5(arg0) {
204
+ const ret = arg0.satoshis;
205
+ return ret;
206
+ }
202
207
  function __wbg_stack_0ed75d68575b0f3c(arg0, arg1) {
203
208
  const ret = arg1.stack;
204
209
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -206,6 +211,17 @@ function __wbg_stack_0ed75d68575b0f3c(arg0, arg1) {
206
211
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
207
212
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
208
213
  }
214
+ function __wbg_txid_0d4259ca3791e85a(arg0, arg1) {
215
+ const ret = arg1.txid;
216
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
217
+ const len1 = WASM_VECTOR_LEN;
218
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
219
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
220
+ }
221
+ function __wbg_vout_467ff75deafa6784(arg0) {
222
+ const ret = arg0.vout;
223
+ return ret;
224
+ }
209
225
  function __wbindgen_cast_0000000000000001(arg0, arg1) {
210
226
  const ret = getStringFromWasm0(arg0, arg1);
211
227
  return ret;
@@ -219,6 +235,11 @@ function __wbindgen_init_externref_table() {
219
235
  table.set(offset + 2, true);
220
236
  table.set(offset + 3, false);
221
237
  }
238
+ function addToExternrefTable0(obj) {
239
+ const idx = wasm.__externref_table_alloc();
240
+ wasm.__wbindgen_externrefs.set(idx, obj);
241
+ return idx;
242
+ }
222
243
  var cachedDataViewMemory0 = null;
223
244
  function getDataViewMemory0() {
224
245
  if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
@@ -237,6 +258,15 @@ function getUint8ArrayMemory0() {
237
258
  }
238
259
  return cachedUint8ArrayMemory0;
239
260
  }
261
+ function passArrayJsValueToWasm0(array, malloc) {
262
+ const ptr = malloc(array.length * 4, 4) >>> 0;
263
+ for (let i = 0; i < array.length; i++) {
264
+ const add = addToExternrefTable0(array[i]);
265
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
266
+ }
267
+ WASM_VECTOR_LEN = array.length;
268
+ return ptr;
269
+ }
240
270
  function passStringToWasm0(arg, malloc, realloc) {
241
271
  if (realloc === void 0) {
242
272
  const buf = cachedTextEncoder.encode(arg);
@@ -305,6 +335,9 @@ function __wbg_set_wasm(val) {
305
335
  // wasm-module:/home/runner/work/mainchain/mainchain/bitcoin/nodejs/ts/wasm/bitcoin_bindings_bg.wasm
306
336
  var imports = {
307
337
  ["./bitcoin_bindings_bg.js"]: {
338
+ __wbg_txid_0d4259ca3791e85a,
339
+ __wbg_vout_467ff75deafa6784,
340
+ __wbg_satoshis_653e28e5089976d5,
308
341
  __wbg_new_8a6f238a6ece86ea,
309
342
  __wbg_stack_0ed75d68575b0f3c,
310
343
  __wbg_error_7534b8e9a36f1ab4,
@@ -355,6 +388,7 @@ var __wbindgen_malloc = instance.exports.__wbindgen_malloc;
355
388
  var __wbindgen_realloc = instance.exports.__wbindgen_realloc;
356
389
  var __wbindgen_externrefs = instance.exports.__wbindgen_externrefs;
357
390
  var __externref_table_dealloc = instance.exports.__externref_table_dealloc;
391
+ var __externref_table_alloc = instance.exports.__externref_table_alloc;
358
392
  var __wbindgen_start = instance.exports.__wbindgen_start;
359
393
 
360
394
  // ts/wasm/bitcoin_bindings.js
@@ -367,6 +401,7 @@ import { bech32 } from "@scure/base";
367
401
  import { HDKey } from "@scure/bip32";
368
402
  import { hexToU8a, u8aToHex } from "@argonprotocol/mainchain";
369
403
  import * as secp256k1 from "@noble/secp256k1";
404
+ import bs58check from "bs58check";
370
405
  function getBip32Version(network) {
371
406
  if (!network) {
372
407
  return void 0;
@@ -396,6 +431,13 @@ function getChildXpriv(bip39Seed, hdPath, network) {
396
431
  function getXpubFromXpriv(xpriv) {
397
432
  return xpriv.publicExtendedKey;
398
433
  }
434
+ function getXpubBytes(xpub) {
435
+ const bytes = bs58check.decode(xpub);
436
+ if (bytes.length !== 78) {
437
+ throw new Error("Invalid Bitcoin xpub key length, must be 78 bytes");
438
+ }
439
+ return bytes;
440
+ }
399
441
  function getCompressedPubkey(pubkey) {
400
442
  const pubkeyUint8Array = keyToU8a(pubkey);
401
443
  if (pubkeyUint8Array.length === 33) {
@@ -455,15 +497,15 @@ var CosignScript = class {
455
497
  this.network = network;
456
498
  }
457
499
  getFundingPsbt() {
458
- const { lock, network } = this;
500
+ const { lock } = this;
459
501
  const tx = new Transaction();
460
502
  tx.addOutput({
461
503
  script: keyToU8a(lock.p2wshScriptHashHex),
462
- amount: lock.utxoSatoshis ?? lock.satoshis
504
+ amount: lock.securitizedSatoshis
463
505
  });
464
506
  return tx.toPSBT(0);
465
507
  }
466
- calculateFee(feeRatePerSatVb, toScriptPubkey) {
508
+ calculateFee(feeRatePerSatVb, inputCount, toScriptPubkey, hasChange) {
467
509
  toScriptPubkey = addressBytesHex(toScriptPubkey, this.network);
468
510
  const { lock, network } = this;
469
511
  return calculateFee(
@@ -475,7 +517,9 @@ var CosignScript = class {
475
517
  BigInt(lock.createdAtHeight),
476
518
  network,
477
519
  feeRatePerSatVb,
478
- toScriptPubkey
520
+ inputCount,
521
+ toScriptPubkey,
522
+ hasChange
479
523
  );
480
524
  }
481
525
  calculateScriptPubkey() {
@@ -492,12 +536,14 @@ var CosignScript = class {
492
536
  }
493
537
  getCosignPsbt(args) {
494
538
  const { lock, network } = this;
495
- const { releaseRequest, utxoRef, utxoSatoshis } = args;
496
- releaseRequest.toScriptPubkey = addressBytesHex(releaseRequest.toScriptPubkey, network);
539
+ const { releaseRequest, utxos } = args;
540
+ const toScriptPubkey = addressBytesHex(releaseRequest.toScriptPubkey, network);
497
541
  const psbtStr = getCosignPsbt(
498
- utxoRef.txid,
499
- utxoRef.vout,
500
- utxoSatoshis ?? lock.utxoSatoshis ?? lock.satoshis,
542
+ utxos.map((x) => ({
543
+ txid: x.utxoRef.txid,
544
+ vout: x.utxoRef.vout,
545
+ satoshis: x.satoshis
546
+ })),
501
547
  lock.vaultPubkey,
502
548
  lock.vaultClaimPubkey,
503
549
  lock.ownerPubkey,
@@ -505,7 +551,9 @@ var CosignScript = class {
505
551
  BigInt(lock.openClaimHeight),
506
552
  BigInt(lock.createdAtHeight),
507
553
  network,
508
- releaseRequest.toScriptPubkey,
554
+ toScriptPubkey,
555
+ releaseRequest.destinationSatoshis,
556
+ releaseRequest.changeSatoshis,
509
557
  releaseRequest.bitcoinNetworkFee
510
558
  );
511
559
  return this.psbtFromHex(psbtStr);
@@ -564,10 +612,15 @@ var CosignScript = class {
564
612
  cosignAndGenerateTx(args) {
565
613
  const { lock } = this;
566
614
  const psbt = this.getCosignPsbt(args);
567
- const { addTx, vaultCosignature, ownerXpriv, ownerXprivChildHdPath } = args;
568
- psbt.updateInput(0, {
569
- partialSig: [[keyToU8a(lock.vaultPubkey), vaultCosignature]]
570
- });
615
+ const { vaultCosignatures, ownerXpriv, ownerXprivChildHdPath } = args;
616
+ if (vaultCosignatures.length !== psbt.inputsLength) {
617
+ throw new Error("Vault signature count does not match the Bitcoin lock input count");
618
+ }
619
+ for (let i = 0; i < vaultCosignatures.length; i++) {
620
+ psbt.updateInput(i, {
621
+ partialSig: [[keyToU8a(lock.vaultPubkey), vaultCosignatures[i]]]
622
+ });
623
+ }
571
624
  const derivePubkey = ownerXprivChildHdPath ? ownerXpriv.derive(ownerXprivChildHdPath).publicKey : ownerXpriv.publicKey;
572
625
  if (!derivePubkey) {
573
626
  throw new Error("Failed to derive owner public key");
@@ -578,30 +631,6 @@ var CosignScript = class {
578
631
  `Owner pubkey ${u8aToHex2(ownerPubkey)} does not match the derived pubkey ${u8aToHex2(derivePubkey)}`
579
632
  );
580
633
  }
581
- if (addTx) {
582
- const addTxBytes = hexToU8a2(addTx);
583
- const tx = Transaction.fromPSBT(addTxBytes);
584
- for (let i = 0; i < tx.outputsLength; i++) {
585
- const output = tx.getOutput(i);
586
- const network = getScureNetwork(this.network);
587
- const scripts = [
588
- p2wpkh(ownerPubkey, network).script,
589
- p2wsh(p2wpkh(ownerPubkey, network), network).script,
590
- p2sh(p2pkh(ownerPubkey, network), network).script,
591
- p2pkh(ownerPubkey, network).script
592
- ];
593
- if (scripts.some((x) => x && output.script && u8aEq(output.script, x))) {
594
- psbt.addInput({
595
- txid: tx.id,
596
- index: i,
597
- witnessUtxo: {
598
- script: output.script,
599
- amount: output.amount
600
- }
601
- });
602
- }
603
- }
604
- }
605
634
  const psbtBytes = u8aToHex2(psbt.toPSBT());
606
635
  const signedPsbt = ownerXprivChildHdPath ? signPsbtDerived(psbtBytes, ownerXpriv.privateExtendedKey, ownerXprivChildHdPath, true) : signPsbt(psbtBytes, this.network, u8aToHex2(ownerXpriv.privateKey, void 0, false), true);
607
636
  return this.psbtFromHex(signedPsbt);
@@ -636,12 +665,13 @@ export {
636
665
  getChildXpriv,
637
666
  getCompressedPubkey,
638
667
  getScureNetwork,
668
+ getXpubBytes,
639
669
  getXpubFromXpriv,
640
670
  keyToU8a,
641
671
  p2pk,
642
- p2pkh2 as p2pkh,
643
- p2sh2 as p2sh,
644
- p2wpkh2 as p2wpkh,
645
- p2wsh2 as p2wsh,
672
+ p2pkh,
673
+ p2sh,
674
+ p2wpkh,
675
+ p2wsh,
646
676
  p2wshScriptHexToAddress
647
677
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argonprotocol/bitcoin",
3
- "version": "1.4.12",
3
+ "version": "1.4.13-dev.d9b3437c",
4
4
  "description": "A client for interop with bitcoin in nodejs.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -51,15 +51,16 @@
51
51
  "./browser/index.js"
52
52
  ],
53
53
  "dependencies": {
54
- "@argonprotocol/mainchain": "1.4.12",
54
+ "@argonprotocol/mainchain": "1.4.13-dev.d9b3437c",
55
55
  "@noble/secp256k1": "^2.3.0",
56
56
  "@scure/bip32": "^1.7.0",
57
57
  "@scure/bip39": "^1.6.0",
58
58
  "@scure/btc-signer": "^1.8.1",
59
- "bignumber.js": "^9.3.1"
59
+ "bignumber.js": "^9.3.1",
60
+ "bs58check": "^4.0.0"
60
61
  },
61
62
  "devDependencies": {
62
- "@argonprotocol/testing": "1.4.12",
63
+ "@argonprotocol/testing": "1.4.13-dev.d9b3437c",
63
64
  "@types/node": "22.17.1",
64
65
  "esbuild-plugin-wasm": "^1.1.0",
65
66
  "tsup": "^8.5.0",