@dynamic-labs-wallet/btc-utils 0.0.263 → 0.0.265

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.js CHANGED
@@ -117,7 +117,8 @@ var currentEcc = null;
117
117
  var network = getBitcoinNetwork(networkName);
118
118
  var compressedPubKey = normalizeForCompressed(pubKey);
119
119
  var address = bitcoin.payments.p2wpkh({
120
- pubkey: compressedPubKey,
120
+ // Safe: creates a Uint8Array view over Buffer's underlying memory without copying
121
+ pubkey: new Uint8Array(compressedPubKey),
121
122
  network: network
122
123
  }).address;
123
124
  return address || '';
@@ -138,7 +139,8 @@ var currentEcc = null;
138
139
  var xOnlyPubKey = pubKey.subarray(-32);
139
140
  var xOnlyPubKeyArray = Uint8Array.from(xOnlyPubKey);
140
141
  var address = bitcoin.payments.p2tr({
141
- internalPubkey: toBuffer(xOnlyPubKeyArray),
142
+ // Safe: creates a Uint8Array view over Buffer's underlying memory without copying
143
+ internalPubkey: new Uint8Array(toBuffer(xOnlyPubKeyArray)),
142
144
  network: network
143
145
  }).address;
144
146
  if (!address) {
@@ -322,12 +324,15 @@ var convertObjectToBuffer = function(actualPubkey) {
322
324
  txToSignSegwit.locktime = 0;
323
325
  var prevTxId = toSpendTx.getId();
324
326
  var prevHash = Buffer.from(prevTxId, 'hex').reverse();
325
- txToSignSegwit.addInput(prevHash, 0, 0);
326
- txToSignSegwit.addOutput(Buffer.from([
327
+ // Safe: creates a Uint8Array view over Buffer's underlying memory without copying
328
+ txToSignSegwit.addInput(new Uint8Array(prevHash), 0, 0);
329
+ // Safe: creates a Uint8Array view over Buffer's underlying memory without copying
330
+ txToSignSegwit.addOutput(new Uint8Array(Buffer.from([
327
331
  0x6a
328
- ]), BigInt(0));
332
+ ])), BigInt(0));
329
333
  var p2pkh = bitcoin__namespace.payments.p2pkh({
330
- pubkey: normalizedKey,
334
+ // Safe: creates a Uint8Array view over Buffer's underlying memory without copying
335
+ pubkey: new Uint8Array(normalizedKey),
331
336
  network: network === core.BitcoinNetwork.TESTNET ? bitcoin__namespace.networks.testnet : bitcoin__namespace.networks.bitcoin
332
337
  });
333
338
  var scriptCode = p2pkh.output;
@@ -366,9 +371,10 @@ function _instanceof$7(left, right) {
366
371
  var s = signature.s;
367
372
  var rBuf = Buffer.isBuffer(r) ? r : Buffer.from(r);
368
373
  var sBuf = Buffer.isBuffer(s) ? s : Buffer.from(s);
374
+ // Safe: creates Uint8Array views over Buffer's underlying memory without copying
369
375
  sigBuffer = Buffer.concat([
370
- rBuf,
371
- sBuf
376
+ new Uint8Array(rBuf),
377
+ new Uint8Array(sBuf)
372
378
  ]);
373
379
  }
374
380
  toSignPsbt.updateInput(0, {
@@ -377,9 +383,10 @@ function _instanceof$7(left, right) {
377
383
  } else {
378
384
  var r1 = signature.r;
379
385
  var s1 = signature.s;
386
+ // Safe: creates Uint8Array views over Buffer's underlying memory without copying
380
387
  var compactSignature = Buffer.concat([
381
- Buffer.from(r1),
382
- Buffer.from(s1)
388
+ new Uint8Array(Buffer.from(r1)),
389
+ new Uint8Array(Buffer.from(s1))
383
390
  ]);
384
391
  var mpcSignerForPsbt = {
385
392
  publicKey: normalizedKey,
@@ -1212,9 +1219,10 @@ function _instanceof$2(left, right) {
1212
1219
  var s = signature.s;
1213
1220
  var rBuf = Buffer.isBuffer(r) ? r : Buffer.from(r);
1214
1221
  var sBuf = Buffer.isBuffer(s) ? s : Buffer.from(s);
1222
+ // Safe: creates Uint8Array views over Buffer's underlying memory without copying
1215
1223
  return Buffer.concat([
1216
- rBuf,
1217
- sBuf
1224
+ new Uint8Array(rBuf),
1225
+ new Uint8Array(sBuf)
1218
1226
  ]);
1219
1227
  };
1220
1228
 
@@ -1329,7 +1337,7 @@ function _type_of(obj) {
1329
1337
  var network = getBitcoinNetwork(networkName);
1330
1338
  var compressedPubKey = normalizeForCompressed(pubKey);
1331
1339
  var address = bitcoin.payments.p2pkh({
1332
- pubkey: compressedPubKey,
1340
+ pubkey: new Uint8Array(compressedPubKey),
1333
1341
  network: network
1334
1342
  }).address;
1335
1343
  return address || '';
@@ -1346,7 +1354,7 @@ function _type_of(obj) {
1346
1354
  var compressedPubKey = normalizeForCompressed(pubKey);
1347
1355
  var address = bitcoin.payments.p2sh({
1348
1356
  redeem: bitcoin.payments.p2wpkh({
1349
- pubkey: compressedPubKey,
1357
+ pubkey: new Uint8Array(compressedPubKey),
1350
1358
  network: network
1351
1359
  }),
1352
1360
  network: network
@@ -1403,7 +1411,7 @@ function _type_of(obj) {
1403
1411
  var _input_witnessUtxo = input.witnessUtxo, script = _input_witnessUtxo.script, value = _input_witnessUtxo.value;
1404
1412
  // Build P2PKH script code from the pubkey hash in the witness program
1405
1413
  var p2pkh = bitcoin__namespace.payments.p2pkh({
1406
- hash: toBuffer(script).subarray(2),
1414
+ hash: new Uint8Array(toBuffer(script).subarray(2)),
1407
1415
  network: bitcoinNetwork
1408
1416
  });
1409
1417
  var scriptCode = p2pkh.output;
@@ -1496,13 +1504,13 @@ function _type_of(obj) {
1496
1504
  txToSignSegwit.locktime = 0;
1497
1505
  var prevTxId = toSpendTx.getId();
1498
1506
  var prevHash = Buffer.from(prevTxId, 'hex').reverse();
1499
- txToSignSegwit.addInput(prevHash, 0, 0);
1500
- txToSignSegwit.addOutput(Buffer.from([
1507
+ txToSignSegwit.addInput(new Uint8Array(prevHash), 0, 0);
1508
+ txToSignSegwit.addOutput(new Uint8Array(Buffer.from([
1501
1509
  0x6a
1502
- ]), BigInt(0));
1510
+ ])), BigInt(0));
1503
1511
  // Build P2PKH script code from pubkey
1504
1512
  var p2pkh = bitcoin__namespace.payments.p2pkh({
1505
- pubkey: pubKeyBuffer,
1513
+ pubkey: new Uint8Array(pubKeyBuffer),
1506
1514
  network: bitcoinNetwork
1507
1515
  });
1508
1516
  var scriptCode = p2pkh.output;
package/index.esm.js CHANGED
@@ -97,7 +97,8 @@ var currentEcc = null;
97
97
  var network = getBitcoinNetwork(networkName);
98
98
  var compressedPubKey = normalizeForCompressed(pubKey);
99
99
  var address = payments.p2wpkh({
100
- pubkey: compressedPubKey,
100
+ // Safe: creates a Uint8Array view over Buffer's underlying memory without copying
101
+ pubkey: new Uint8Array(compressedPubKey),
101
102
  network: network
102
103
  }).address;
103
104
  return address || '';
@@ -118,7 +119,8 @@ var currentEcc = null;
118
119
  var xOnlyPubKey = pubKey.subarray(-32);
119
120
  var xOnlyPubKeyArray = Uint8Array.from(xOnlyPubKey);
120
121
  var address = payments.p2tr({
121
- internalPubkey: toBuffer(xOnlyPubKeyArray),
122
+ // Safe: creates a Uint8Array view over Buffer's underlying memory without copying
123
+ internalPubkey: new Uint8Array(toBuffer(xOnlyPubKeyArray)),
122
124
  network: network
123
125
  }).address;
124
126
  if (!address) {
@@ -302,12 +304,15 @@ var convertObjectToBuffer = function(actualPubkey) {
302
304
  txToSignSegwit.locktime = 0;
303
305
  var prevTxId = toSpendTx.getId();
304
306
  var prevHash = Buffer.from(prevTxId, 'hex').reverse();
305
- txToSignSegwit.addInput(prevHash, 0, 0);
306
- txToSignSegwit.addOutput(Buffer.from([
307
+ // Safe: creates a Uint8Array view over Buffer's underlying memory without copying
308
+ txToSignSegwit.addInput(new Uint8Array(prevHash), 0, 0);
309
+ // Safe: creates a Uint8Array view over Buffer's underlying memory without copying
310
+ txToSignSegwit.addOutput(new Uint8Array(Buffer.from([
307
311
  0x6a
308
- ]), BigInt(0));
312
+ ])), BigInt(0));
309
313
  var p2pkh = bitcoin.payments.p2pkh({
310
- pubkey: normalizedKey,
314
+ // Safe: creates a Uint8Array view over Buffer's underlying memory without copying
315
+ pubkey: new Uint8Array(normalizedKey),
311
316
  network: network === BitcoinNetwork.TESTNET ? bitcoin.networks.testnet : bitcoin.networks.bitcoin
312
317
  });
313
318
  var scriptCode = p2pkh.output;
@@ -346,9 +351,10 @@ function _instanceof$7(left, right) {
346
351
  var s = signature.s;
347
352
  var rBuf = Buffer.isBuffer(r) ? r : Buffer.from(r);
348
353
  var sBuf = Buffer.isBuffer(s) ? s : Buffer.from(s);
354
+ // Safe: creates Uint8Array views over Buffer's underlying memory without copying
349
355
  sigBuffer = Buffer.concat([
350
- rBuf,
351
- sBuf
356
+ new Uint8Array(rBuf),
357
+ new Uint8Array(sBuf)
352
358
  ]);
353
359
  }
354
360
  toSignPsbt.updateInput(0, {
@@ -357,9 +363,10 @@ function _instanceof$7(left, right) {
357
363
  } else {
358
364
  var r1 = signature.r;
359
365
  var s1 = signature.s;
366
+ // Safe: creates Uint8Array views over Buffer's underlying memory without copying
360
367
  var compactSignature = Buffer.concat([
361
- Buffer.from(r1),
362
- Buffer.from(s1)
368
+ new Uint8Array(Buffer.from(r1)),
369
+ new Uint8Array(Buffer.from(s1))
363
370
  ]);
364
371
  var mpcSignerForPsbt = {
365
372
  publicKey: normalizedKey,
@@ -1192,9 +1199,10 @@ function _instanceof$2(left, right) {
1192
1199
  var s = signature.s;
1193
1200
  var rBuf = Buffer.isBuffer(r) ? r : Buffer.from(r);
1194
1201
  var sBuf = Buffer.isBuffer(s) ? s : Buffer.from(s);
1202
+ // Safe: creates Uint8Array views over Buffer's underlying memory without copying
1195
1203
  return Buffer.concat([
1196
- rBuf,
1197
- sBuf
1204
+ new Uint8Array(rBuf),
1205
+ new Uint8Array(sBuf)
1198
1206
  ]);
1199
1207
  };
1200
1208
 
@@ -1309,7 +1317,7 @@ function _type_of(obj) {
1309
1317
  var network = getBitcoinNetwork(networkName);
1310
1318
  var compressedPubKey = normalizeForCompressed(pubKey);
1311
1319
  var address = payments.p2pkh({
1312
- pubkey: compressedPubKey,
1320
+ pubkey: new Uint8Array(compressedPubKey),
1313
1321
  network: network
1314
1322
  }).address;
1315
1323
  return address || '';
@@ -1326,7 +1334,7 @@ function _type_of(obj) {
1326
1334
  var compressedPubKey = normalizeForCompressed(pubKey);
1327
1335
  var address = payments.p2sh({
1328
1336
  redeem: payments.p2wpkh({
1329
- pubkey: compressedPubKey,
1337
+ pubkey: new Uint8Array(compressedPubKey),
1330
1338
  network: network
1331
1339
  }),
1332
1340
  network: network
@@ -1383,7 +1391,7 @@ function _type_of(obj) {
1383
1391
  var _input_witnessUtxo = input.witnessUtxo, script = _input_witnessUtxo.script, value = _input_witnessUtxo.value;
1384
1392
  // Build P2PKH script code from the pubkey hash in the witness program
1385
1393
  var p2pkh = bitcoin.payments.p2pkh({
1386
- hash: toBuffer(script).subarray(2),
1394
+ hash: new Uint8Array(toBuffer(script).subarray(2)),
1387
1395
  network: bitcoinNetwork
1388
1396
  });
1389
1397
  var scriptCode = p2pkh.output;
@@ -1476,13 +1484,13 @@ function _type_of(obj) {
1476
1484
  txToSignSegwit.locktime = 0;
1477
1485
  var prevTxId = toSpendTx.getId();
1478
1486
  var prevHash = Buffer.from(prevTxId, 'hex').reverse();
1479
- txToSignSegwit.addInput(prevHash, 0, 0);
1480
- txToSignSegwit.addOutput(Buffer.from([
1487
+ txToSignSegwit.addInput(new Uint8Array(prevHash), 0, 0);
1488
+ txToSignSegwit.addOutput(new Uint8Array(Buffer.from([
1481
1489
  0x6a
1482
- ]), BigInt(0));
1490
+ ])), BigInt(0));
1483
1491
  // Build P2PKH script code from pubkey
1484
1492
  var p2pkh = bitcoin.payments.p2pkh({
1485
- pubkey: pubKeyBuffer,
1493
+ pubkey: new Uint8Array(pubKeyBuffer),
1486
1494
  network: bitcoinNetwork
1487
1495
  });
1488
1496
  var scriptCode = p2pkh.output;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/btc-utils",
3
- "version": "0.0.263",
3
+ "version": "0.0.265",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "dependencies": {
8
- "@dynamic-labs-wallet/core": "0.0.263",
8
+ "@dynamic-labs-wallet/core": "0.0.265",
9
9
  "bitcoinjs-lib": "^7.0.0",
10
10
  "bip322-js": "^3.0.0",
11
11
  "@noble/hashes": "1.7.1",
@@ -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;CAgEjD,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;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;CAmEjD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"convertSignatureToTaprootBuffer.d.ts","sourceRoot":"","sources":["../../src/convertSignatureToTaprootBuffer/convertSignatureToTaprootBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,cAC/B,cAAc,GAAG,UAAU,GAAG,MAAM,KAC9C,MAUF,CAAC"}
1
+ {"version":3,"file":"convertSignatureToTaprootBuffer.d.ts","sourceRoot":"","sources":["../../src/convertSignatureToTaprootBuffer/convertSignatureToTaprootBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,cAC/B,cAAc,GAAG,UAAU,GAAG,MAAM,KAC9C,MAWF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createNativeSegWitAddress.d.ts","sourceRoot":"","sources":["../../src/createNativeSegWitAddress/createNativeSegWitAddress.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAKhE;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,WAC5B,MAAM,eACD,cAAc,QACrB,GAAG,KACR,MAaF,CAAC"}
1
+ {"version":3,"file":"createNativeSegWitAddress.d.ts","sourceRoot":"","sources":["../../src/createNativeSegWitAddress/createNativeSegWitAddress.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAKhE;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,WAC5B,MAAM,eACD,cAAc,QACrB,GAAG,KACR,MAcF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createTaprootAddress.d.ts","sourceRoot":"","sources":["../../src/createTaprootAddress/createTaprootAddress.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAKhE;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,WACvB,MAAM,eACD,cAAc,QACrB,GAAG,KACR,MAmBF,CAAC"}
1
+ {"version":3,"file":"createTaprootAddress.d.ts","sourceRoot":"","sources":["../../src/createTaprootAddress/createTaprootAddress.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAKhE;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,WACvB,MAAM,eACD,cAAc,QACrB,GAAG,KACR,MAoBF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"encodeBip322Signature.d.ts","sourceRoot":"","sources":["../../src/encodeBip322Signature/encodeBip322Signature.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,eACpB,GAAG,UACP,GAAG,aACA,cAAc,GAAG,UAAU,eACzB,kBAAkB,KAC9B,MAuCF,CAAC"}
1
+ {"version":3,"file":"encodeBip322Signature.d.ts","sourceRoot":"","sources":["../../src/encodeBip322Signature/encodeBip322Signature.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,eACpB,GAAG,UACP,GAAG,aACA,cAAc,GAAG,UAAU,eACzB,kBAAkB,KAC9B,MAyCF,CAAC"}