@argonprotocol/bitcoin 1.4.12-dev.4d726964 → 1.4.12-dev.9deec2d7

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-P6N66RIB.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_359c1a2982fe9d47(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_d8b43d7217475933(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_fcbf9a76c2d9b520(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_d8b43d7217475933,
339
+ __wbg_vout_fcbf9a76c2d9b520,
340
+ __wbg_satoshis_359c1a2982fe9d47,
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
@@ -471,7 +505,7 @@ var CosignScript = class {
471
505
  });
472
506
  return tx.toPSBT(0);
473
507
  }
474
- calculateFee(feeRatePerSatVb, toScriptPubkey) {
508
+ calculateFee(feeRatePerSatVb, inputCount, toScriptPubkey, hasChange) {
475
509
  toScriptPubkey = addressBytesHex(toScriptPubkey, this.network);
476
510
  const { lock, network } = this;
477
511
  return calculateFee(
@@ -483,7 +517,9 @@ var CosignScript = class {
483
517
  BigInt(lock.createdAtHeight),
484
518
  network,
485
519
  feeRatePerSatVb,
486
- toScriptPubkey
520
+ inputCount,
521
+ toScriptPubkey,
522
+ hasChange
487
523
  );
488
524
  }
489
525
  calculateScriptPubkey() {
@@ -500,12 +536,14 @@ var CosignScript = class {
500
536
  }
501
537
  getCosignPsbt(args) {
502
538
  const { lock, network } = this;
503
- const { releaseRequest, utxoRef, utxoSatoshis } = args;
539
+ const { releaseRequest, utxos } = args;
504
540
  const toScriptPubkey = addressBytesHex(releaseRequest.toScriptPubkey, network);
505
541
  const psbtStr = getCosignPsbt(
506
- utxoRef.txid,
507
- utxoRef.vout,
508
- utxoSatoshis,
542
+ utxos.map((x) => ({
543
+ txid: x.utxoRef.txid,
544
+ vout: x.utxoRef.vout,
545
+ satoshis: x.satoshis
546
+ })),
509
547
  lock.vaultPubkey,
510
548
  lock.vaultClaimPubkey,
511
549
  lock.ownerPubkey,
@@ -514,6 +552,8 @@ var CosignScript = class {
514
552
  BigInt(lock.createdAtHeight),
515
553
  network,
516
554
  toScriptPubkey,
555
+ releaseRequest.destinationSatoshis,
556
+ releaseRequest.changeSatoshis,
517
557
  releaseRequest.bitcoinNetworkFee
518
558
  );
519
559
  return this.psbtFromHex(psbtStr);
@@ -572,10 +612,15 @@ var CosignScript = class {
572
612
  cosignAndGenerateTx(args) {
573
613
  const { lock } = this;
574
614
  const psbt = this.getCosignPsbt(args);
575
- const { addTx, vaultCosignature, ownerXpriv, ownerXprivChildHdPath } = args;
576
- psbt.updateInput(0, {
577
- partialSig: [[keyToU8a(lock.vaultPubkey), vaultCosignature]]
578
- });
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
+ }
579
624
  const derivePubkey = ownerXprivChildHdPath ? ownerXpriv.derive(ownerXprivChildHdPath).publicKey : ownerXpriv.publicKey;
580
625
  if (!derivePubkey) {
581
626
  throw new Error("Failed to derive owner public key");
@@ -586,30 +631,6 @@ var CosignScript = class {
586
631
  `Owner pubkey ${u8aToHex2(ownerPubkey)} does not match the derived pubkey ${u8aToHex2(derivePubkey)}`
587
632
  );
588
633
  }
589
- if (addTx) {
590
- const addTxBytes = hexToU8a2(addTx);
591
- const tx = Transaction.fromPSBT(addTxBytes);
592
- for (let i = 0; i < tx.outputsLength; i++) {
593
- const output = tx.getOutput(i);
594
- const network = getScureNetwork(this.network);
595
- const scripts = [
596
- p2wpkh(ownerPubkey, network).script,
597
- p2wsh(p2wpkh(ownerPubkey, network), network).script,
598
- p2sh(p2pkh(ownerPubkey, network), network).script,
599
- p2pkh(ownerPubkey, network).script
600
- ];
601
- if (scripts.some((x) => x && output.script && u8aEq(output.script, x))) {
602
- psbt.addInput({
603
- txid: tx.id,
604
- index: i,
605
- witnessUtxo: {
606
- script: output.script,
607
- amount: output.amount
608
- }
609
- });
610
- }
611
- }
612
- }
613
634
  const psbtBytes = u8aToHex2(psbt.toPSBT());
614
635
  const signedPsbt = ownerXprivChildHdPath ? signPsbtDerived(psbtBytes, ownerXpriv.privateExtendedKey, ownerXprivChildHdPath, true) : signPsbt(psbtBytes, this.network, u8aToHex2(ownerXpriv.privateKey, void 0, false), true);
615
636
  return this.psbtFromHex(signedPsbt);
@@ -648,9 +669,9 @@ export {
648
669
  getXpubFromXpriv,
649
670
  keyToU8a,
650
671
  p2pk,
651
- p2pkh2 as p2pkh,
652
- p2sh2 as p2sh,
653
- p2wpkh2 as p2wpkh,
654
- p2wsh2 as p2wsh,
672
+ p2pkh,
673
+ p2sh,
674
+ p2wpkh,
675
+ p2wsh,
655
676
  p2wshScriptHexToAddress
656
677
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argonprotocol/bitcoin",
3
- "version": "1.4.12-dev.4d726964",
3
+ "version": "1.4.12-dev.9deec2d7",
4
4
  "description": "A client for interop with bitcoin in nodejs.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -51,7 +51,7 @@
51
51
  "./browser/index.js"
52
52
  ],
53
53
  "dependencies": {
54
- "@argonprotocol/mainchain": "1.4.12-dev.4d726964",
54
+ "@argonprotocol/mainchain": "1.4.12-dev.9deec2d7",
55
55
  "@noble/secp256k1": "^2.3.0",
56
56
  "@scure/bip32": "^1.7.0",
57
57
  "@scure/bip39": "^1.6.0",
@@ -60,7 +60,7 @@
60
60
  "bs58check": "^4.0.0"
61
61
  },
62
62
  "devDependencies": {
63
- "@argonprotocol/testing": "1.4.12-dev.4d726964",
63
+ "@argonprotocol/testing": "1.4.12-dev.9deec2d7",
64
64
  "@types/node": "22.17.1",
65
65
  "esbuild-plugin-wasm": "^1.1.0",
66
66
  "tsup": "^8.5.0",