@argonprotocol/bitcoin 1.4.12-dev.8cae3588 → 1.4.12-dev.a0735a19

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
@@ -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-CMIKLQTW.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) {
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);
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, 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, 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
@@ -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) {
467
509
  toScriptPubkey = addressBytesHex(toScriptPubkey, this.network);
468
510
  const { lock, network } = this;
469
511
  return calculateFee(
@@ -475,6 +517,7 @@ var CosignScript = class {
475
517
  BigInt(lock.createdAtHeight),
476
518
  network,
477
519
  feeRatePerSatVb,
520
+ inputCount,
478
521
  toScriptPubkey
479
522
  );
480
523
  }
@@ -492,12 +535,14 @@ var CosignScript = class {
492
535
  }
493
536
  getCosignPsbt(args) {
494
537
  const { lock, network } = this;
495
- const { releaseRequest, utxoRef, utxoSatoshis } = args;
496
- releaseRequest.toScriptPubkey = addressBytesHex(releaseRequest.toScriptPubkey, network);
538
+ const { releaseRequest, utxos } = args;
539
+ const toScriptPubkey = addressBytesHex(releaseRequest.toScriptPubkey, network);
497
540
  const psbtStr = getCosignPsbt(
498
- utxoRef.txid,
499
- utxoRef.vout,
500
- utxoSatoshis ?? lock.utxoSatoshis ?? lock.satoshis,
541
+ utxos.map((x) => ({
542
+ txid: x.utxoRef.txid,
543
+ vout: x.utxoRef.vout,
544
+ satoshis: x.satoshis
545
+ })),
501
546
  lock.vaultPubkey,
502
547
  lock.vaultClaimPubkey,
503
548
  lock.ownerPubkey,
@@ -505,7 +550,7 @@ var CosignScript = class {
505
550
  BigInt(lock.openClaimHeight),
506
551
  BigInt(lock.createdAtHeight),
507
552
  network,
508
- releaseRequest.toScriptPubkey,
553
+ toScriptPubkey,
509
554
  releaseRequest.bitcoinNetworkFee
510
555
  );
511
556
  return this.psbtFromHex(psbtStr);
@@ -564,10 +609,15 @@ var CosignScript = class {
564
609
  cosignAndGenerateTx(args) {
565
610
  const { lock } = this;
566
611
  const psbt = this.getCosignPsbt(args);
567
- const { addTx, vaultCosignature, ownerXpriv, ownerXprivChildHdPath } = args;
568
- psbt.updateInput(0, {
569
- partialSig: [[keyToU8a(lock.vaultPubkey), vaultCosignature]]
570
- });
612
+ const { addTx, vaultCosignatures, ownerXpriv, ownerXprivChildHdPath } = args;
613
+ if (vaultCosignatures.length !== psbt.inputsLength) {
614
+ throw new Error("Vault signature count does not match the Bitcoin lock input count");
615
+ }
616
+ for (let i = 0; i < vaultCosignatures.length; i++) {
617
+ psbt.updateInput(i, {
618
+ partialSig: [[keyToU8a(lock.vaultPubkey), vaultCosignatures[i]]]
619
+ });
620
+ }
571
621
  const derivePubkey = ownerXprivChildHdPath ? ownerXpriv.derive(ownerXprivChildHdPath).publicKey : ownerXpriv.publicKey;
572
622
  if (!derivePubkey) {
573
623
  throw new Error("Failed to derive owner public key");
@@ -636,6 +686,7 @@ export {
636
686
  getChildXpriv,
637
687
  getCompressedPubkey,
638
688
  getScureNetwork,
689
+ getXpubBytes,
639
690
  getXpubFromXpriv,
640
691
  keyToU8a,
641
692
  p2pk,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argonprotocol/bitcoin",
3
- "version": "1.4.12-dev.8cae3588",
3
+ "version": "1.4.12-dev.a0735a19",
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-dev.8cae3588",
54
+ "@argonprotocol/mainchain": "1.4.12-dev.a0735a19",
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-dev.8cae3588",
63
+ "@argonprotocol/testing": "1.4.12-dev.a0735a19",
63
64
  "@types/node": "22.17.1",
64
65
  "esbuild-plugin-wasm": "^1.1.0",
65
66
  "tsup": "^8.5.0",