@dynamic-labs-wallet/btc-utils 1.1.36 → 1.1.38

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/index.cjs CHANGED
@@ -350,6 +350,54 @@ var convertObjectToBuffer = function(actualPubkey) {
350
350
  throw new Error('Unable to determine Bitcoin address type');
351
351
  };
352
352
 
353
+ function _array_like_to_array$2(arr, len) {
354
+ if (len == null || len > arr.length) len = arr.length;
355
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
356
+ return arr2;
357
+ }
358
+ function _array_without_holes$2(arr) {
359
+ if (Array.isArray(arr)) return _array_like_to_array$2(arr);
360
+ }
361
+ function _iterable_to_array$2(iter) {
362
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
363
+ }
364
+ function _non_iterable_spread$2() {
365
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
366
+ }
367
+ function _to_consumable_array$2(arr) {
368
+ return _array_without_holes$2(arr) || _iterable_to_array$2(arr) || _unsupported_iterable_to_array$2(arr) || _non_iterable_spread$2();
369
+ }
370
+ function _unsupported_iterable_to_array$2(o, minLen) {
371
+ if (!o) return;
372
+ if (typeof o === "string") return _array_like_to_array$2(o, minLen);
373
+ var n = Object.prototype.toString.call(o).slice(8, -1);
374
+ if (n === "Object" && o.constructor) n = o.constructor.name;
375
+ if (n === "Map" || n === "Set") return Array.from(n);
376
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
377
+ }
378
+ var NULL_PREVOUT_HASH = new Uint8Array(32);
379
+ var NULL_PREVOUT_INDEX = 0xffffffff;
380
+ var OP_0_PUSH32 = [
381
+ 0x00,
382
+ 0x20
383
+ ];
384
+ /**
385
+ * Builds the BIP-322 `to_spend` transaction as a plain Transaction.
386
+ *
387
+ * `BIP322.buildToSpendTx` goes through `Psbt.extractTransaction()`, which bitcoinjs-lib >= 7.0.4 rejects
388
+ * because the virtual input has no UTXO ("Need a Utxo input item for input #0"). A Transaction has no such check.
389
+ *
390
+ * @param message - The message to sign
391
+ * @param scriptPubKey - The message challenge (the signer's script public key)
392
+ */ var buildToSpendTx = function(message, scriptPubKey) {
393
+ var tx = new bitcoin__namespace.Transaction();
394
+ tx.version = 0;
395
+ tx.locktime = 0;
396
+ tx.addInput(NULL_PREVOUT_HASH, NULL_PREVOUT_INDEX, 0, new Uint8Array(_to_consumable_array$2(OP_0_PUSH32).concat(_to_consumable_array$2(bip322Js.BIP322.hashMessage(message)))));
397
+ tx.addOutput(scriptPubKey, BigInt(0));
398
+ return tx;
399
+ };
400
+
353
401
  /**
354
402
  * Calculates the hash to be signed for a BIP-322 message verification
355
403
  *
@@ -366,7 +414,7 @@ var convertObjectToBuffer = function(actualPubkey) {
366
414
  throw new Error('Failed to generate address for BIP-322');
367
415
  }
368
416
  var scriptPubKey = bip322Js.Address.convertAdressToScriptPubkey(address);
369
- var toSpendTx = bip322Js.BIP322.buildToSpendTx(message, scriptPubKey);
417
+ var toSpendTx = buildToSpendTx(message, scriptPubKey);
370
418
  var toSignPsbt = bip322Js.BIP322.buildToSignTx(toSpendTx.getId(), scriptPubKey);
371
419
  var txToSign = toSignPsbt.__CACHE.__TX;
372
420
  var hashToSign;
package/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BitcoinNetwork, BitcoinAddressType } from '@dynamic-labs-wallet/core';
2
2
  import * as bitcoin from 'bitcoinjs-lib';
3
3
  import { initEccLib as initEccLib$1, payments } from 'bitcoinjs-lib';
4
- import { Address, BIP322 } from 'bip322-js';
4
+ import { BIP322, Address } from 'bip322-js';
5
5
  import bs58 from 'bs58';
6
6
  import { sha256 } from '@noble/hashes/sha256';
7
7
 
@@ -330,6 +330,54 @@ var convertObjectToBuffer = function(actualPubkey) {
330
330
  throw new Error('Unable to determine Bitcoin address type');
331
331
  };
332
332
 
333
+ function _array_like_to_array$2(arr, len) {
334
+ if (len == null || len > arr.length) len = arr.length;
335
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
336
+ return arr2;
337
+ }
338
+ function _array_without_holes$2(arr) {
339
+ if (Array.isArray(arr)) return _array_like_to_array$2(arr);
340
+ }
341
+ function _iterable_to_array$2(iter) {
342
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
343
+ }
344
+ function _non_iterable_spread$2() {
345
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
346
+ }
347
+ function _to_consumable_array$2(arr) {
348
+ return _array_without_holes$2(arr) || _iterable_to_array$2(arr) || _unsupported_iterable_to_array$2(arr) || _non_iterable_spread$2();
349
+ }
350
+ function _unsupported_iterable_to_array$2(o, minLen) {
351
+ if (!o) return;
352
+ if (typeof o === "string") return _array_like_to_array$2(o, minLen);
353
+ var n = Object.prototype.toString.call(o).slice(8, -1);
354
+ if (n === "Object" && o.constructor) n = o.constructor.name;
355
+ if (n === "Map" || n === "Set") return Array.from(n);
356
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
357
+ }
358
+ var NULL_PREVOUT_HASH = new Uint8Array(32);
359
+ var NULL_PREVOUT_INDEX = 0xffffffff;
360
+ var OP_0_PUSH32 = [
361
+ 0x00,
362
+ 0x20
363
+ ];
364
+ /**
365
+ * Builds the BIP-322 `to_spend` transaction as a plain Transaction.
366
+ *
367
+ * `BIP322.buildToSpendTx` goes through `Psbt.extractTransaction()`, which bitcoinjs-lib >= 7.0.4 rejects
368
+ * because the virtual input has no UTXO ("Need a Utxo input item for input #0"). A Transaction has no such check.
369
+ *
370
+ * @param message - The message to sign
371
+ * @param scriptPubKey - The message challenge (the signer's script public key)
372
+ */ var buildToSpendTx = function(message, scriptPubKey) {
373
+ var tx = new bitcoin.Transaction();
374
+ tx.version = 0;
375
+ tx.locktime = 0;
376
+ tx.addInput(NULL_PREVOUT_HASH, NULL_PREVOUT_INDEX, 0, new Uint8Array(_to_consumable_array$2(OP_0_PUSH32).concat(_to_consumable_array$2(BIP322.hashMessage(message)))));
377
+ tx.addOutput(scriptPubKey, BigInt(0));
378
+ return tx;
379
+ };
380
+
333
381
  /**
334
382
  * Calculates the hash to be signed for a BIP-322 message verification
335
383
  *
@@ -346,7 +394,7 @@ var convertObjectToBuffer = function(actualPubkey) {
346
394
  throw new Error('Failed to generate address for BIP-322');
347
395
  }
348
396
  var scriptPubKey = Address.convertAdressToScriptPubkey(address);
349
- var toSpendTx = BIP322.buildToSpendTx(message, scriptPubKey);
397
+ var toSpendTx = buildToSpendTx(message, scriptPubKey);
350
398
  var toSignPsbt = BIP322.buildToSignTx(toSpendTx.getId(), scriptPubKey);
351
399
  var txToSign = toSignPsbt.__CACHE.__TX;
352
400
  var hashToSign;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/btc-utils",
3
- "version": "1.1.36",
3
+ "version": "1.1.38",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "dependencies": {
8
- "@dynamic-labs-wallet/core": "1.1.36",
8
+ "@dynamic-labs-wallet/core": "1.1.38",
9
9
  "bitcoinjs-lib": "^7.0.0",
10
- "bip322-js": "^3.0.0",
10
+ "bip322-js": "4.0.0",
11
11
  "@noble/hashes": "1.7.1",
12
12
  "bs58": "^6.0.0"
13
13
  },
@@ -0,0 +1,12 @@
1
+ import * as bitcoin from 'bitcoinjs-lib';
2
+ /**
3
+ * Builds the BIP-322 `to_spend` transaction as a plain Transaction.
4
+ *
5
+ * `BIP322.buildToSpendTx` goes through `Psbt.extractTransaction()`, which bitcoinjs-lib >= 7.0.4 rejects
6
+ * because the virtual input has no UTXO ("Need a Utxo input item for input #0"). A Transaction has no such check.
7
+ *
8
+ * @param message - The message to sign
9
+ * @param scriptPubKey - The message challenge (the signer's script public key)
10
+ */
11
+ export declare const buildToSpendTx: (message: string, scriptPubKey: Uint8Array) => bitcoin.Transaction;
12
+ //# sourceMappingURL=buildToSpendTx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildToSpendTx.d.ts","sourceRoot":"","sources":["../../src/buildToSpendTx/buildToSpendTx.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AAMzC;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,YAAa,MAAM,gBAAgB,UAAU,KAAG,OAAO,CAAC,WAalF,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { buildToSpendTx } from './buildToSpendTx.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildToSpendTx/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"calculateBip322Hash.d.ts","sourceRoot":"","sources":["../../src/calculateBip322Hash/calculateBip322Hash.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAI/E;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,YACrB,MAAM,UACP,GAAG,eACE,kBAAkB,WACtB,cAAc,QACjB,GAAG,KACR;IAAE,gBAAgB,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,GAAG,CAAA;CAiDjD,CAAC"}
1
+ {"version":3,"file":"calculateBip322Hash.d.ts","sourceRoot":"","sources":["../../src/calculateBip322Hash/calculateBip322Hash.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAK/E;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,YACrB,MAAM,UACP,GAAG,eACE,kBAAkB,WACtB,cAAc,QACjB,GAAG,KACR;IAAE,gBAAgB,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,GAAG,CAAA;CAiDjD,CAAC"}