@scure/btc-signer 2.0.1 → 2.2.0

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/README.md CHANGED
@@ -107,6 +107,10 @@ import { deepStrictEqual, throws } from 'assert';
107
107
  Legacy script, doesn't have an address. Must be wrapped in P2SH / P2WSH / P2SH-P2WSH. Not recommended.
108
108
 
109
109
  ```ts
110
+ import * as btc from '@scure/btc-signer';
111
+ import { hex } from '@scure/base';
112
+ import { deepStrictEqual } from 'node:assert';
113
+
110
114
  const uncompressed = hex.decode(
111
115
  '04ad90e5b6bc86b3ec7fac2c5fbda7423fc8ef0d58df594c773fa05e2c281b2bfe877677c668bd13603944e34f4818ee03cadd81a88542b8b4d5431264180e2c28'
112
116
  );
@@ -124,11 +128,16 @@ deepStrictEqual(btc.p2pk(uncompressed), {
124
128
  Classic (pre-SegWit) address.
125
129
 
126
130
  ```ts
131
+ import * as btc from '@scure/btc-signer';
132
+ import { hex } from '@scure/base';
133
+ import { deepStrictEqual } from 'node:assert';
134
+
127
135
  const PubKey = hex.decode('030000000000000000000000000000000000000000000000000000000000000001');
128
136
  deepStrictEqual(btc.p2pkh(PubKey), {
129
137
  type: 'pkh',
130
138
  address: '134D6gYy8DsR5m4416BnmgASuMBqKvogQh',
131
139
  script: hex.decode('76a914168b992bcfc44050310b3a94bd0771136d0b28d188ac'),
140
+ hash: hex.decode('168b992bcfc44050310b3a94bd0771136d0b28d1'),
132
141
  });
133
142
  // P2SH-P2PKH
134
143
  deepStrictEqual(btc.p2sh(btc.p2pkh(PubKey)), {
@@ -136,6 +145,7 @@ deepStrictEqual(btc.p2sh(btc.p2pkh(PubKey)), {
136
145
  address: '3EPhLJ1FuR2noj6qrTs4YvepCvB6sbShoV',
137
146
  script: hex.decode('a9148b530b962725af3bb7c818f197c619db3f71495087'),
138
147
  redeemScript: hex.decode('76a914168b992bcfc44050310b3a94bd0771136d0b28d188ac'),
148
+ hash: hex.decode('8b530b962725af3bb7c818f197c619db3f714950'),
139
149
  });
140
150
  // P2WSH-P2PKH
141
151
  deepStrictEqual(btc.p2wsh(btc.p2pkh(PubKey)), {
@@ -143,6 +153,7 @@ deepStrictEqual(btc.p2wsh(btc.p2pkh(PubKey)), {
143
153
  address: 'bc1qhxtthndg70cthfasy8y4qlk9h7r3006azn9md0fad5dg9hh76nkqaufnuz',
144
154
  script: hex.decode('0020b996bbcda8f3f0bba7b021c9507ec5bf8717bf5d14cbb6bd3d6d1a82defed4ec'),
145
155
  witnessScript: hex.decode('76a914168b992bcfc44050310b3a94bd0771136d0b28d188ac'),
156
+ hash: hex.decode('b996bbcda8f3f0bba7b021c9507ec5bf8717bf5d14cbb6bd3d6d1a82defed4ec'),
146
157
  });
147
158
  // P2SH-P2WSH-P2PKH
148
159
  deepStrictEqual(btc.p2sh(btc.p2wsh(btc.p2pkh(PubKey))), {
@@ -151,6 +162,7 @@ deepStrictEqual(btc.p2sh(btc.p2wsh(btc.p2pkh(PubKey))), {
151
162
  script: hex.decode('a9148a3d36fb710a9c7cae06cfcdf39792ff5773e8f187'),
152
163
  redeemScript: hex.decode('0020b996bbcda8f3f0bba7b021c9507ec5bf8717bf5d14cbb6bd3d6d1a82defed4ec'),
153
164
  witnessScript: hex.decode('76a914168b992bcfc44050310b3a94bd0771136d0b28d188ac'),
165
+ hash: hex.decode('8a3d36fb710a9c7cae06cfcdf39792ff5773e8f1'),
154
166
  });
155
167
  ```
156
168
 
@@ -163,11 +175,16 @@ Uses bech32 address.
163
175
  Can't be wrapped in [P2WSH](#p2wsh-witness-script-hash).
164
176
 
165
177
  ```ts
178
+ import * as btc from '@scure/btc-signer';
179
+ import { hex } from '@scure/base';
180
+ import { deepStrictEqual } from 'node:assert';
181
+
166
182
  const PubKey = hex.decode('030000000000000000000000000000000000000000000000000000000000000001');
167
183
  deepStrictEqual(btc.p2wpkh(PubKey), {
168
184
  type: 'wpkh',
169
185
  address: 'bc1qz69ej270c3q9qvgt822t6pm3zdksk2x35j2jlm',
170
186
  script: hex.decode('0014168b992bcfc44050310b3a94bd0771136d0b28d1'),
187
+ hash: hex.decode('168b992bcfc44050310b3a94bd0771136d0b28d1'),
171
188
  });
172
189
  // P2SH-P2WPKH
173
190
  deepStrictEqual(btc.p2sh(btc.p2wpkh(PubKey)), {
@@ -175,6 +192,7 @@ deepStrictEqual(btc.p2sh(btc.p2wpkh(PubKey)), {
175
192
  address: '3BCuRViGCTXmQjyJ9zjeRUYrdZTUa38zjC',
176
193
  script: hex.decode('a91468602f2db7b7d7cdcd2639ab6bf7f5bfe828e53f87'),
177
194
  redeemScript: hex.decode('0014168b992bcfc44050310b3a94bd0771136d0b28d1'),
195
+ hash: hex.decode('68602f2db7b7d7cdcd2639ab6bf7f5bfe828e53f'),
178
196
  });
179
197
  ```
180
198
 
@@ -185,6 +203,10 @@ Classic (pre-SegWit) script address. Useful for multisig and other advanced use-
185
203
  Required tx input fields to make it spendable: `redeemScript`
186
204
 
187
205
  ```ts
206
+ import * as btc from '@scure/btc-signer';
207
+ import { hex } from '@scure/base';
208
+ import { deepStrictEqual } from 'node:assert';
209
+
188
210
  const PubKey = hex.decode('030000000000000000000000000000000000000000000000000000000000000001');
189
211
  // Wrap P2PKH in P2SH
190
212
  deepStrictEqual(btc.p2sh(btc.p2pkh(PubKey)), {
@@ -192,6 +214,7 @@ deepStrictEqual(btc.p2sh(btc.p2pkh(PubKey)), {
192
214
  address: '3EPhLJ1FuR2noj6qrTs4YvepCvB6sbShoV',
193
215
  script: hex.decode('a9148b530b962725af3bb7c818f197c619db3f71495087'),
194
216
  redeemScript: hex.decode('76a914168b992bcfc44050310b3a94bd0771136d0b28d188ac'),
217
+ hash: hex.decode('8b530b962725af3bb7c818f197c619db3f714950'),
195
218
  });
196
219
  ```
197
220
 
@@ -203,12 +226,17 @@ In SegWit, signature is removed from tx hash calculation.
203
226
  Required tx input fields to make it spendable: `witnessScript`
204
227
 
205
228
  ```ts
229
+ import * as btc from '@scure/btc-signer';
230
+ import { hex } from '@scure/base';
231
+ import { deepStrictEqual } from 'node:assert';
232
+
206
233
  const PubKey = hex.decode('030000000000000000000000000000000000000000000000000000000000000001');
207
234
  deepStrictEqual(btc.p2wsh(btc.p2pkh(PubKey)), {
208
235
  type: 'wsh',
209
236
  address: 'bc1qhxtthndg70cthfasy8y4qlk9h7r3006azn9md0fad5dg9hh76nkqaufnuz',
210
237
  script: hex.decode('0020b996bbcda8f3f0bba7b021c9507ec5bf8717bf5d14cbb6bd3d6d1a82defed4ec'),
211
238
  witnessScript: hex.decode('76a914168b992bcfc44050310b3a94bd0771136d0b28d188ac'),
239
+ hash: hex.decode('b996bbcda8f3f0bba7b021c9507ec5bf8717bf5d14cbb6bd3d6d1a82defed4ec'),
212
240
  });
213
241
  ```
214
242
 
@@ -219,6 +247,10 @@ Not really script type, but construction of P2WSH inside P2SH.
219
247
  Required tx input fields to make it spendable: `redeemScript`, `witnessScript`
220
248
 
221
249
  ```ts
250
+ import * as btc from '@scure/btc-signer';
251
+ import { hex } from '@scure/base';
252
+ import { deepStrictEqual } from 'node:assert';
253
+
222
254
  const PubKey = hex.decode('030000000000000000000000000000000000000000000000000000000000000001');
223
255
  deepStrictEqual(btc.p2sh(btc.p2wsh(btc.p2pkh(PubKey))), {
224
256
  type: 'sh',
@@ -226,6 +258,7 @@ deepStrictEqual(btc.p2sh(btc.p2wsh(btc.p2pkh(PubKey))), {
226
258
  script: hex.decode('a9148a3d36fb710a9c7cae06cfcdf39792ff5773e8f187'),
227
259
  redeemScript: hex.decode('0020b996bbcda8f3f0bba7b021c9507ec5bf8717bf5d14cbb6bd3d6d1a82defed4ec'),
228
260
  witnessScript: hex.decode('76a914168b992bcfc44050310b3a94bd0771136d0b28d188ac'),
261
+ hash: hex.decode('8a3d36fb710a9c7cae06cfcdf39792ff5773e8f1'),
229
262
  });
230
263
  ```
231
264
 
@@ -236,6 +269,10 @@ Classic / segwit (pre-taproot) M-of-N Multisig. Doesn't have an address, must be
236
269
  Duplicate public keys are not accepted to reduce mistakes. Use flag `allowSamePubkeys` to override the behavior, for cases like `2-of-[A,A,B,C]`, which can be signed by `A or (B and C)`.
237
270
 
238
271
  ```ts
272
+ import * as btc from '@scure/btc-signer';
273
+ import { hex } from '@scure/base';
274
+ import { deepStrictEqual } from 'node:assert';
275
+
239
276
  const PubKeys = [
240
277
  hex.decode('030000000000000000000000000000000000000000000000000000000000000001'),
241
278
  hex.decode('030000000000000000000000000000000000000000000000000000000000000002'),
@@ -249,6 +286,7 @@ deepStrictEqual(btc.p2sh(btc.p2ms(2, PubKeys)), {
249
286
  redeemScript: hex.decode(
250
287
  '5221030000000000000000000000000000000000000000000000000000000000000001210300000000000000000000000000000000000000000000000000000000000000022103000000000000000000000000000000000000000000000000000000000000000353ae'
251
288
  ),
289
+ hash: hex.decode('9d91c6de4eacde72a7cc86bff98d1915b3c7818f'),
252
290
  });
253
291
  // Multisig 2-of-3 wrapped in P2WSH
254
292
  deepStrictEqual(btc.p2wsh(btc.p2ms(2, PubKeys)), {
@@ -258,6 +296,7 @@ deepStrictEqual(btc.p2wsh(btc.p2ms(2, PubKeys)), {
258
296
  witnessScript: hex.decode(
259
297
  '5221030000000000000000000000000000000000000000000000000000000000000001210300000000000000000000000000000000000000000000000000000000000000022103000000000000000000000000000000000000000000000000000000000000000353ae'
260
298
  ),
299
+ hash: hex.decode('74ee2b4ceec10839a489c07d4a538384394681e3dcd88f3ee87a85199908aa5e'),
261
300
  });
262
301
  // Multisig 2-of-3 wrapped in P2SH-P2WSH
263
302
  deepStrictEqual(btc.p2sh(btc.p2wsh(btc.p2ms(2, PubKeys))), {
@@ -268,6 +307,7 @@ deepStrictEqual(btc.p2sh(btc.p2wsh(btc.p2ms(2, PubKeys))), {
268
307
  witnessScript: hex.decode(
269
308
  '5221030000000000000000000000000000000000000000000000000000000000000001210300000000000000000000000000000000000000000000000000000000000000022103000000000000000000000000000000000000000000000000000000000000000353ae'
270
309
  ),
310
+ hash: hex.decode('ab70ab84b12b891364b4b2a14ca813cac308b242'),
271
311
  });
272
312
  // Useful util: wraps P2MS in P2SH or P2WSH
273
313
  deepStrictEqual(btc.p2sh(btc.p2ms(2, PubKeys)), btc.multisig(2, PubKeys));
@@ -289,6 +329,10 @@ to sign multi-sig wallets, and there is no BIP/PSBT fields for that yet.
289
329
  Required tx input fields to make it spendable: `tapInternalKey`, `tapMerkleRoot`, `tapLeafScript`
290
330
 
291
331
  ```ts
332
+ import * as btc from '@scure/btc-signer';
333
+ import { hex } from '@scure/base';
334
+ import { deepStrictEqual } from 'node:assert';
335
+
292
336
  const PubKey = hex.decode('0101010101010101010101010101010101010101010101010101010101010101');
293
337
  // Key Path Spend (owned of private key for PubKey can spend)
294
338
  deepStrictEqual(btc.p2tr(PubKey), {
@@ -338,6 +382,10 @@ This is fast for cases like 15-of-20, but extremely slow for cases like 5-of-20.
338
382
  Duplicate public keys are not accepted to reduce mistakes. Use flag `allowSamePubkeys` to override the behavior, for cases like `2-of-[A,A,B,C]`, which can be signed by `A or (B and C)`.
339
383
 
340
384
  ```ts
385
+ import * as btc from '@scure/btc-signer';
386
+ import { hex } from '@scure/base';
387
+ import { deepStrictEqual } from 'node:assert';
388
+
341
389
  const PubKey = hex.decode('0101010101010101010101010101010101010101010101010101010101010101');
342
390
  const PubKey2 = hex.decode('0202020202020202020202020202020202020202020202020202020202020202');
343
391
  const PubKey3 = hex.decode('1212121212121212121212121212121212121212121212121212121212121212');
@@ -371,6 +419,10 @@ Duplicate public keys are not accepted to reduce mistakes. Use flag `allowSamePu
371
419
  **Experimental**, use at your own risk.
372
420
 
373
421
  ```ts
422
+ import * as btc from '@scure/btc-signer';
423
+ import { hex } from '@scure/base';
424
+ import { deepStrictEqual } from 'node:assert';
425
+
374
426
  const PubKey = hex.decode('0101010101010101010101010101010101010101010101010101010101010101');
375
427
  const PubKey2 = hex.decode('0202020202020202020202020202020202020202020202020202020202020202');
376
428
  const PubKey3 = hex.decode('1212121212121212121212121212121212121212121212121212121212121212');
@@ -395,6 +447,10 @@ deepStrictEqual(clean(btc.p2tr(undefined, btc.p2tr_ms(2, [PubKey, PubKey2, PubKe
395
447
  Specific case of `p2tr_ns(1, [pubkey])`, which is the same as the BTC descriptor: `tr($H,pk(PUBKEY))`
396
448
 
397
449
  ```ts
450
+ import * as btc from '@scure/btc-signer';
451
+ import { hex } from '@scure/base';
452
+ import { deepStrictEqual } from 'node:assert';
453
+
398
454
  const PubKey = hex.decode('0101010101010101010101010101010101010101010101010101010101010101');
399
455
  // P2PK for taproot
400
456
  const clean = (x) => ({ type: x.type, address: x.address, script: hex.encode(x.script) });
@@ -410,6 +466,10 @@ deepStrictEqual(clean(btc.p2tr(undefined, [btc.p2tr_pk(PubKey)])), {
410
466
  Ephemeral anchors are supported. [Check out docs](https://bitcoinops.org/en/topics/ephemeral-anchors/).
411
467
 
412
468
  ```ts
469
+ import * as btc from '@scure/btc-signer';
470
+ import { hex } from '@scure/base';
471
+ import { deepStrictEqual } from 'node:assert';
472
+
413
473
  const p2aScript = hex.decode('51024e73');
414
474
  const decoded = btc.OutScript.decode(p2aScript);
415
475
  deepStrictEqual(decoded, { type: 'p2a', script: p2aScript });
@@ -428,7 +488,7 @@ If you have use-case where they are needed, create a github issue.
428
488
 
429
489
  PSBTv2 features tx_modifiable and taproot+bip32 are not supported yet.
430
490
 
431
- ```ts
491
+ ```text
432
492
  // Decode
433
493
  Transaction.fromRaw(raw: Bytes, opts: TxOpts = {}); // Raw tx
434
494
  Transaction.fromPSBT(psbt: Bytes, opts: TxOpts = {}); // PSBT tx
@@ -448,16 +508,26 @@ Use `getInput` and `inputsLength` to read information about inputs: they return
448
508
  This is necessary to avoid accidental modification of internal structures without calling methods (addInput/updateInput) that will verify correctness.
449
509
 
450
510
  ```ts
511
+ import * as btc from '@scure/btc-signer';
512
+ import { hex } from '@scure/base';
513
+ import { deepStrictEqual, throws } from 'node:assert';
514
+
515
+ const tx = new btc.Transaction();
516
+ type Bytes = Uint8Array | string;
517
+ type RawTransactionBytesOrHex = Uint8Array | string;
518
+ type DerivationPath = { fingerprint: number; path: number[] };
519
+ type TapScriptSigKey = { pubKey: Bytes; leafHash: Bytes };
520
+ type TapLeafScriptKey = { version: number; internalKey: Bytes; merklePath: Bytes[] };
451
521
  type TransactionInput = {
452
522
  txid?: Bytes,
453
523
  index?: number,
454
- nonWitnessUtxo?: <RawTransactionBytesOrHex>,
455
- witnessUtxo?: {script?: Bytes; amount: bigint},
524
+ nonWitnessUtxo?: RawTransactionBytesOrHex,
525
+ witnessUtxo?: { script?: Bytes; amount: bigint },
456
526
  partialSig?: [Bytes, Bytes][]; // [PubKey, Signature]
457
- sighashType?: P.U32LE,
527
+ sighashType?: number,
458
528
  redeemScript?: Bytes,
459
529
  witnessScript?: Bytes,
460
- bip32Derivation?: [Bytes, {fingerprint: number; path: number[]}]; // [PubKey, DeriviationPath]
530
+ bip32Derivation?: [Bytes, DerivationPath | undefined][]; // [PubKey, DeriviationPath]
461
531
  finalScriptSig?: Bytes,
462
532
  finalScriptWitness?: Bytes[],
463
533
  porCommitment?: Bytes,
@@ -465,15 +535,15 @@ type TransactionInput = {
465
535
  requiredTimeLocktime?: number,
466
536
  requiredHeightLocktime?: number,
467
537
  tapKeySig?: Bytes,
468
- tapScriptSig?: [Bytes, Bytes][]; // [PubKeySchnorr, LeafHash]
538
+ tapScriptSig?: [TapScriptSigKey, Bytes][]; // [PubKeySchnorr, LeafHash]
469
539
  // [ControlBlock, ScriptWithVersion]
470
- tapLeafScript?: [{version: number; internalKey: Bytes; merklePath: Bytes[]}, Bytes];
540
+ tapLeafScript?: [TapLeafScriptKey, Bytes][];
471
541
  tapInternalKey?: Bytes,
472
542
  tapMerkleRoot?: Bytes,
473
543
  };
474
544
 
475
- tx.addInput(input: TransactionInput): number;
476
- tx.updateInput(idx: number, input: TransactionInput);
545
+ // tx.addInput(input: TransactionInput): number;
546
+ // tx.updateInput(idx: number, input: TransactionInput);
477
547
 
478
548
  // Input
479
549
  tx.addInput({ txid: new Uint8Array(32), index: 0 });
@@ -494,7 +564,7 @@ tx.addInput({
494
564
  txid: '0000000000000000000000000000000000000000000000000000000000000000',
495
565
  index: 0,
496
566
  });
497
- deepStrictEqual(tx.inputs[2], {
567
+ deepStrictEqual(tx.inputs[1], {
498
568
  txid: new Uint8Array(32),
499
569
  index: 0,
500
570
  sequence: btc.DEFAULT_SEQUENCE,
@@ -542,9 +612,11 @@ for (let i = 0; i < tx.inputsLength; i++) {
542
612
 
543
613
  ### Outputs
544
614
 
545
- `addOutputAddress` uses bigint amounts, which means satoshis - NOT btc. If you need btc representation, use Decimal:
615
+ `addOutputAddress` uses bigint amounts, which means satoshis, not BTC. If you need BTC representation, use `Decimal`:
546
616
 
547
617
  ```ts
618
+ import * as btc from '@scure/btc-signer';
619
+
548
620
  const amountSatoshi = btc.Decimal.decode('1.5'); // 1.5 btc in satoshi
549
621
  ```
550
622
 
@@ -552,23 +624,33 @@ Use `getOutput` and `outputsLength` to read outputs information. This methods re
552
624
  This is necessary to avoid accidental modification of internal structures without calling methods (addOutput/updateOutput) that will verify correctness.
553
625
 
554
626
  ```ts
627
+ import * as btc from '@scure/btc-signer';
628
+ import { hex } from '@scure/base';
629
+ import { deepStrictEqual, throws } from 'node:assert';
630
+
631
+ const tx = new btc.Transaction();
632
+ type Bytes = Uint8Array | string;
633
+ type DerivationPath = { fingerprint: number; path: number[] };
555
634
  type TransactionOutput = {
556
635
  script?: Bytes,
557
636
  amount?: bigint,
558
637
  redeemScript?: Bytes,
559
638
  witnessScript?: Bytes,
560
- bip32Derivation?: [Bytes, {fingerprint: number; path: number[]}]; // [PubKey, DeriviationPath]
639
+ bip32Derivation?: [Bytes, DerivationPath | undefined][]; // [PubKey, DeriviationPath]
561
640
  tapInternalKey?: Bytes,
562
641
  };
563
642
 
564
- tx.addOutput(o: TransactionOutput): number;
565
- tx.updateOutput(idx: number, output: TransactionOutput);
566
- tx.addOutputAddress(address: string, amount: bigint, network = NETWORK): number;
643
+ // tx.addOutput(o: TransactionOutput): number;
644
+ // tx.updateOutput(idx: number, output: TransactionOutput);
645
+ // tx.addOutputAddress(address: string, amount: bigint, network = NETWORK): number;
567
646
 
568
- const compressed = hex.decode(
569
- '030000000000000000000000000000000000000000000000000000000000000001'
570
- );
571
- const script = btc.p2pkh(compressed).script;
647
+ const pubKey = hex.decode('030000000000000000000000000000000000000000000000000000000000000001');
648
+ const bip1 = [pubKey, { fingerprint: 5, path: [1, 2, 3] }];
649
+ const pubKey2 = hex.decode('030000000000000000000000000000000000000000000000000000000000000002');
650
+ const bip2 = [pubKey2, { fingerprint: 6, path: [4, 5, 6] }];
651
+ const pubKey3 = hex.decode('030000000000000000000000000000000000000000000000000000000000000003');
652
+ const bip3 = [pubKey3, { fingerprint: 7, path: [7, 8, 9] }];
653
+ const script = btc.p2pkh(pubKey).script;
572
654
  tx.addOutput({ script, amount: 100n });
573
655
  deepStrictEqual(tx.outputs[0], {
574
656
  script,
@@ -616,15 +698,45 @@ for (let i = 0; i < tx.outputsLength; i++) {
616
698
  ### Basic transaction sign
617
699
 
618
700
  ```ts
701
+ import * as btc from '@scure/btc-signer';
702
+ import { hex } from '@scure/base';
703
+ import { pubECDSA } from '@scure/btc-signer/utils.js';
704
+ import { deepStrictEqual } from 'node:assert';
705
+
619
706
  const privKey = hex.decode('0101010101010101010101010101010101010101010101010101010101010101');
620
- const txP2WPKH = new btc.Transaction();
707
+ const pubKey = pubECDSA(privKey);
708
+ const TX_TEST_OUTPUTS = [
709
+ ['1cMh228HTCiwS8ZsaakH8A8wze1JR5ZsP', 10n],
710
+ ['3H3Kc7aSPP4THLX68k4mQMyf1gvL6AtmDm', 50n],
711
+ ['bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', 93n],
712
+ ] as const;
713
+ const TX_TEST_INPUTS = [
714
+ {
715
+ txid: hex.decode('c061c23190ed3370ad5206769651eaf6fac6d87d85b5db34e30a74e0c4a6da3e'),
716
+ index: 0,
717
+ amount: 550n,
718
+ },
719
+ {
720
+ txid: hex.decode('a21965903c938af35e7280ae5779b9fea4f7f01ac256b8a2a53b1b19a4e89a0d'),
721
+ index: 0,
722
+ amount: 600n,
723
+ },
724
+ {
725
+ txid: hex.decode('fae21e319ca827df32462afc3225c17719338a8e8d3e3b3ddeb0c2387da3a4c7'),
726
+ index: 0,
727
+ amount: 600n,
728
+ },
729
+ ];
730
+ const RAW_TX_HEX =
731
+ '01000000033edaa6c4e0740ae334dbb5857dd8c6faf6ea5196760652ad7033ed9031c261c00000000000ffffffff0d9ae8a4191b3ba5a2b856c21af0f7a4feb97957ae80725ef38a933c906519a20000000000ffffffffc7a4a37d38c2b0de3d3b3e8d8e8a331977c12532fc2a4632df27a89c311ee2fa0000000000ffffffff030a000000000000001976a91406afd46bcdfd22ef94ac122aa11f241244a37ecc88ac320000000000000017a914a860f76561c85551594c18eecceffaee8c4822d7875d00000000000000160014e8df018c7e326cc253faac7e46cdc51e68542c4200000000';
732
+ const txP2WPKH = new btc.Transaction({ version: 1 });
621
733
  for (const inp of TX_TEST_INPUTS) {
622
734
  txP2WPKH.addInput({
623
735
  txid: inp.txid,
624
736
  index: inp.index,
625
737
  witnessUtxo: {
626
738
  amount: inp.amount,
627
- script: btc.p2wpkh(secp256k1.getPublicKey(privKey, true)).script,
739
+ script: btc.p2wpkh(pubKey).script,
628
740
  },
629
741
  });
630
742
  }
@@ -632,16 +744,23 @@ for (const [address, amount] of TX_TEST_OUTPUTS) txP2WPKH.addOutputAddress(addre
632
744
  deepStrictEqual(hex.encode(txP2WPKH.unsignedTx), RAW_TX_HEX);
633
745
  txP2WPKH.sign(privKey);
634
746
  txP2WPKH.finalize();
635
- deepStrictEqual(txP2WPKH.id, 'cbb94443b19861df0824914fa654212facc071854e0df6f7388b482a6394526d');
747
+ deepStrictEqual(txP2WPKH.id, 'e4db0a196f378a6648deb221a2771fde577892479a2d52abbe8cf3d31d2f140f');
636
748
  deepStrictEqual(
637
749
  txP2WPKH.hex,
638
- '010000000001033edaa6c4e0740ae334dbb5857dd8c6faf6ea5196760652ad7033ed9031c261c00000000000ffffffff0d9ae8a4191b3ba5a2b856c21af0f7a4feb97957ae80725ef38a933c906519a20000000000ffffffffc7a4a37d38c2b0de3d3b3e8d8e8a331977c12532fc2a4632df27a89c311ee2fa0000000000ffffffff03e8030000000000001976a91406afd46bcdfd22ef94ac122aa11f241244a37ecc88ac881300000000000017a914a860f76561c85551594c18eecceffaee8c4822d7876b24000000000000160014e8df018c7e326cc253faac7e46cdc51e68542c4202473044022024e7b1a6ae19a95c69c192745db09cc54385a80cc7684570cfbf2da84cbbfa0802205ad55efb2019a1aa6edc03cf243989ea428c4d216699cbae2cfaf3c26ddef5650121031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f0247304402204415ef16f341e888ca2483b767b47fcf22977b6d673c3f7c6cae2f6b4bc2ac08022055be98747345b02a6f40edcc2f80390dcef4efe57b38c1bb7d16bdbca710abfd0121031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f02473044022069769fb5c97a7dd9401dbd3f6d32a38fe82bc8934c49c7c4cd3b39c6d120080c02202c181604203dc45c10e5290ded103195fae117d7fb0db19cdc411e73a76da6cb0121031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f00000000'
750
+ '010000000001033edaa6c4e0740ae334dbb5857dd8c6faf6ea5196760652ad7033ed9031c261c00000000000ffffffff0d9ae8a4191b3ba5a2b856c21af0f7a4feb97957ae80725ef38a933c906519a20000000000ffffffffc7a4a37d38c2b0de3d3b3e8d8e8a331977c12532fc2a4632df27a89c311ee2fa0000000000ffffffff030a000000000000001976a91406afd46bcdfd22ef94ac122aa11f241244a37ecc88ac320000000000000017a914a860f76561c85551594c18eecceffaee8c4822d7875d00000000000000160014e8df018c7e326cc253faac7e46cdc51e68542c4202483045022100d04801283249fc9a80f71d8fe8d9f6dc0e84afc0e59df2733f04ff659e095a8802206ce71c598d8f75b7cb2102b252b7bd04c6228c0826da0ed27104f8cca829869d0121031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f02473044022026ef492099b86572a965b28d11a40bf9b1e9fe5a2aeab22cbca1b354988910e30220416508f564e67932cb1c38bef7a3c3f0a95470fc81c6cb359a9268a49f6449850121031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f0247304402202cf37bbcf2c098e48ffc204d0ab688465b43642546d2e0414f5b8e4bdfae9420022006ccfb2415c7a941b6d5c07651fd80b9656bdea5fe793530cf2c604920c72d100121031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f00000000'
639
751
  );
640
752
  ```
641
753
 
642
754
  ### BIP174 PSBT multi-sig example
643
755
 
756
+ > `npm install @scure/base @scure/bip32`
757
+
644
758
  ```ts
759
+ import * as btc from '@scure/btc-signer';
760
+ import { hex } from '@scure/base';
761
+ import * as bip32 from '@scure/bip32';
762
+ import { deepStrictEqual } from 'node:assert';
763
+
645
764
  const testnet = {
646
765
  wif: 0xef,
647
766
  bip32: {
@@ -828,8 +947,14 @@ a lot of outputs close to dust.
828
947
  #### Example
829
948
 
830
949
  ```ts
950
+ import * as btc from '@scure/btc-signer';
951
+ import { hex } from '@scure/base';
952
+ import { pubECDSA } from '@scure/btc-signer/utils.js';
953
+ import { deepStrictEqual } from 'node:assert';
954
+
831
955
  const privKey = hex.decode('0101010101010101010101010101010101010101010101010101010101010101');
832
- const pubKey = secp256k1.getPublicKey(privKey, true);
956
+ const pubKey = pubECDSA(privKey);
957
+ const regtest = { bech32: 'bcrt', pubKeyHash: 0x6f, scriptHash: 0xc4 };
833
958
  const spend = btc.p2wpkh(pubKey, regtest);
834
959
  const utxo = [
835
960
  {
@@ -874,7 +999,8 @@ const selected = btc.selectUTXO(utxo, outputs, 'default', {
874
999
  createTx: true, // create tx with selected inputs/outputs
875
1000
  network: regtest,
876
1001
  });
877
- // NOTE: 'selected' will 'undefined' if there is not enough funds
1002
+ // selectUTXO returns undefined if there is not enough funds.
1003
+ if (!selected) throw new Error('expected enough funds');
878
1004
  deepStrictEqual(selected.fee, 394n); // estimated fee
879
1005
  deepStrictEqual(selected.change, true); // change address used
880
1006
  deepStrictEqual(selected.outputs, [
@@ -902,20 +1028,25 @@ deepStrictEqual(tx.fee, 394n);
902
1028
  ## MuSig2
903
1029
 
904
1030
  MuSig2 implementation conforming to [BIP-327](https://github.com/bitcoin/bips/blob/master/bip-0327.mediawiki)
905
- is available in `@scure/btc-signer/musig2.js`. Check out [bip327-musig2.test.js](./test/bip327-musig2.test.js) as well:
1031
+ is available in `@scure/btc-signer/musig2.js`. Check out [bip327-musig2.test.ts](./test/bip327-musig2.test.ts) as well:
1032
+
1033
+ > `npm install @noble/curves`
906
1034
 
907
1035
  ```ts
1036
+ import * as btc from '@scure/btc-signer';
908
1037
  import * as musig2 from '@scure/btc-signer/musig2.js';
1038
+ import { schnorr } from '@noble/curves/secp256k1.js';
1039
+ import { deepStrictEqual } from 'node:assert';
909
1040
  // MuSig2 Multi-signature for Alice, Bob, and Carol
910
1041
  // 1. Key Generation (for each signer: Alice, Bob, Carol)
911
1042
  // - Alice's key generation
912
- const aliceSecretKey = randomBytes(32); // Alice generates a random 32-byte secret key
1043
+ const aliceSecretKey = btc.utils.randomPrivateKeyBytes(); // Alice generates a random 32-byte secret key
913
1044
  const alicePublicKey = musig2.IndividualPubkey(aliceSecretKey); // Alice derives her individual public key from her secret key
914
1045
  // - Bob's key generation
915
- const bobSecretKey = randomBytes(32); // Bob generates a random 32-byte secret key
1046
+ const bobSecretKey = btc.utils.randomPrivateKeyBytes(); // Bob generates a random 32-byte secret key
916
1047
  const bobPublicKey = musig2.IndividualPubkey(bobSecretKey); // Bob derives his individual public key from his secret key
917
1048
  // - Carol's key generation
918
- const carolSecretKey = randomBytes(32); // Carol generates a random 32-byte secret key
1049
+ const carolSecretKey = btc.utils.randomPrivateKeyBytes(); // Carol generates a random 32-byte secret key
919
1050
  const carolPublicKey = musig2.IndividualPubkey(carolSecretKey); // Carol derives her individual public key from her secret key
920
1051
 
921
1052
  // 2. Key Aggregation (All signers participate by sharing public keys)
@@ -953,9 +1084,7 @@ const partialSignatures = [alicePartialSignature, bobPartialSignature, carolPart
953
1084
  const finalSignature = session.partialSigAgg(partialSignatures); // Aggregate partial signatures to create the final signature
954
1085
 
955
1086
  // 7. Signature Verification (Anyone can verify the final signature)
956
- // Verify the final signature
957
- import { schnorr } from '@noble/curves/secp256k1';
958
- schnorr.verify(finalSignature, msg, aggregatePublicKey);
1087
+ deepStrictEqual(schnorr.verify(finalSignature, msg, aggregatePublicKey), true);
959
1088
  ```
960
1089
 
961
1090
  ## Ordinals and custom scripts
@@ -1011,6 +1140,8 @@ for (const k of [alice, bob]) {
1011
1140
 
1012
1141
  ## Utils
1013
1142
 
1143
+ > `npm install @scure/base`
1144
+
1014
1145
  ### secp256k1 keys
1015
1146
 
1016
1147
  ```ts
@@ -1027,11 +1158,15 @@ const pub = pubSchnorr(priv);
1027
1158
  Returns common addresses from privateKey
1028
1159
 
1029
1160
  ```ts
1161
+ import * as btc from '@scure/btc-signer';
1162
+ import { hex } from '@scure/base';
1163
+ import { deepStrictEqual } from 'node:assert';
1164
+
1030
1165
  const privKey = hex.decode('0101010101010101010101010101010101010101010101010101010101010101');
1031
1166
  deepStrictEqual(btc.getAddress('pkh', privKey), '1C6Rc3w25VHud3dLDamutaqfKWqhrLRTaD'); // P2PKH (legacy address)
1032
1167
  deepStrictEqual(btc.getAddress('wpkh', privKey), 'bc1q0xcqpzrky6eff2g52qdye53xkk9jxkvrh6yhyw'); // SegWit V0 address
1033
1168
  deepStrictEqual(
1034
- btc.getAddress('tr', priv),
1169
+ btc.getAddress('tr', privKey),
1035
1170
  'bc1p33wm0auhr9kkahzd6l0kqj85af4cswn276hsxg6zpz85xe2r0y8syx4e5t'
1036
1171
  ); // TapRoot KeyPathSpend
1037
1172
  ```
@@ -1041,6 +1176,10 @@ deepStrictEqual(
1041
1176
  Encoding/decoding of WIF privateKeys. Only compressed keys are supported for now.
1042
1177
 
1043
1178
  ```ts
1179
+ import * as btc from '@scure/btc-signer';
1180
+ import { hex } from '@scure/base';
1181
+ import { deepStrictEqual } from 'node:assert';
1182
+
1044
1183
  const privKey = hex.decode('0101010101010101010101010101010101010101010101010101010101010101');
1045
1184
  deepStrictEqual(btc.WIF().encode(privKey), 'KwFfNUhSDaASSAwtG7ssQM1uVX8RgX5GHWnnLfhfiQDigjioWXHH');
1046
1185
  deepStrictEqual(
@@ -1054,29 +1193,33 @@ deepStrictEqual(
1054
1193
  Encoding/decoding bitcoin scripts
1055
1194
 
1056
1195
  ```ts
1196
+ import * as btc from '@scure/btc-signer';
1197
+ import { hex } from '@scure/base';
1198
+ import { deepStrictEqual } from 'node:assert';
1199
+
1057
1200
  deepStrictEqual(
1058
1201
  btc.Script.decode(
1059
1202
  hex.decode(
1060
1203
  '5221030000000000000000000000000000000000000000000000000000000000000001210300000000000000000000000000000000000000000000000000000000000000022103000000000000000000000000000000000000000000000000000000000000000353ae'
1061
1204
  )
1062
- ).map((i) => (P.isBytes(i) ? hex.encode(i) : i)),
1205
+ ).map((i) => (btc.utils.isBytes(i) ? hex.encode(i) : i)),
1063
1206
  [
1064
- 'OP_2',
1207
+ 2,
1065
1208
  '030000000000000000000000000000000000000000000000000000000000000001',
1066
1209
  '030000000000000000000000000000000000000000000000000000000000000002',
1067
1210
  '030000000000000000000000000000000000000000000000000000000000000003',
1068
- 'OP_3',
1211
+ 3,
1069
1212
  'CHECKMULTISIG',
1070
1213
  ]
1071
1214
  );
1072
1215
  deepStrictEqual(
1073
1216
  hex.encode(
1074
1217
  btc.Script.encode([
1075
- 'OP_2',
1218
+ 2,
1076
1219
  hex.decode('030000000000000000000000000000000000000000000000000000000000000001'),
1077
1220
  hex.decode('030000000000000000000000000000000000000000000000000000000000000002'),
1078
1221
  hex.decode('030000000000000000000000000000000000000000000000000000000000000003'),
1079
- 'OP_3',
1222
+ 3,
1080
1223
  'CHECKMULTISIG',
1081
1224
  ])
1082
1225
  ),
@@ -1089,6 +1232,10 @@ deepStrictEqual(
1089
1232
  Encoding / decoding of output scripts
1090
1233
 
1091
1234
  ```ts
1235
+ import * as btc from '@scure/btc-signer';
1236
+ import { hex } from '@scure/base';
1237
+ import { deepStrictEqual } from 'node:assert';
1238
+
1092
1239
  deepStrictEqual(
1093
1240
  btc.OutScript.decode(
1094
1241
  hex.decode(
@@ -1166,6 +1313,9 @@ Bitcoin is more complex than ETH / SOL despite having less features:
1166
1313
 
1167
1314
  The library has been independently audited:
1168
1315
 
1316
+ - at version 2.2.0, in Apr 2026, by ourselves (self-audited)
1317
+ - Scope: everything
1318
+ - [Changes since audit](https://github.com/paulmillr/scure-btc-signer/compare/2.2.0..main)
1169
1319
  - at version 0.3.0, in Feb 2023, by [cure53](https://cure53.de)
1170
1320
  - PDFs: [online](https://cure53.de/audit-report_micro-btc-signer.pdf), [offline](./audit/2023-02-21-cure53-audit-report.pdf)
1171
1321
  - [Changes since audit](https://github.com/paulmillr/scure-btc-signer/compare/0.3.0..main).
@@ -1195,7 +1345,7 @@ For this package, there are 4 dependencies; and a few dev dependencies:
1195
1345
  - [noble-curves](https://github.com/paulmillr/noble-curves) provides secp256k1 elliptic curve
1196
1346
  - [scure-base](https://github.com/paulmillr/scure-base) provides base58 and bech32
1197
1347
  - [micro-packed](https://github.com/paulmillr/micro-packed) is responsible for binary encoding
1198
- - micro-bmark, micro-should and jsbt are used for benchmarking / testing / build tooling and developed by the same author
1348
+ - jsbt is used for benchmarking / testing / build tooling and developed by the same author
1199
1349
  - prettier, fast-check and typescript are used for code quality / test generation / ts compilation. It's hard to audit their source code thoroughly and fully because of their size
1200
1350
 
1201
1351
  ## Contributing & testing
package/index.d.ts CHANGED
@@ -1,19 +1,29 @@
1
1
  /*! scure-btc-signer - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
+ import type { TArg, TRet } from './utils.ts';
2
3
  import { compareBytes, taprootTweakPubkey } from './utils.ts';
3
4
  export { multisig, p2ms, p2pk, p2pkh, p2sh, p2tr, p2tr_ms, p2tr_ns, p2tr_pk, p2wpkh, p2wsh } from './payment.ts';
4
5
  export { CompactSize, MAX_SCRIPT_BYTE_LENGTH, OP, RawTx, RawWitness, Script, ScriptNum, } from './script.ts';
5
6
  export type { ScriptType } from './script.ts';
6
7
  export { getInputType, Transaction } from './transaction.ts';
7
8
  export { NETWORK, TAPROOT_UNSPENDABLE_KEY, TEST_NETWORK } from './utils.ts';
9
+ export type { TArg, TRet } from './utils.ts';
8
10
  export { selectUTXO } from './utxo.ts';
9
- export declare const utils: {
11
+ /**
12
+ * Small collection of commonly used utility exports.
13
+ * @example
14
+ * Reach for the grouped helpers when you want the common byte and Taproot utilities.
15
+ * ```ts
16
+ * utils.compareBytes(new Uint8Array([1]), new Uint8Array([2]));
17
+ * ```
18
+ */
19
+ export declare const utils: TRet<Readonly<{
10
20
  isBytes: (a: unknown) => a is Uint8Array;
11
- concatBytes: (...arrays: Uint8Array[]) => Uint8Array;
21
+ concatBytes: (...arrays: TArg<Uint8Array[]>) => TRet<Uint8Array>;
12
22
  compareBytes: typeof compareBytes;
13
- pubSchnorr: (priv: string | Uint8Array) => Uint8Array;
14
- randomPrivateKeyBytes: () => Uint8Array;
23
+ pubSchnorr: (priv: TArg<Uint8Array>) => TRet<Uint8Array>;
24
+ randomPrivateKeyBytes: () => TRet<Uint8Array>;
15
25
  taprootTweakPubkey: typeof taprootTweakPubkey;
16
- };
26
+ }>>;
17
27
  export { _sortPubkeys, Address, combinations, getAddress, OutScript, sortedMultisig, taprootListToTree, WIF, } from './payment.ts';
18
28
  export type { CustomScript, OptScript } from './payment.ts';
19
29
  export { _DebugPSBT, TaprootControlBlock } from './psbt.ts';
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,OAAO,EACL,YAAY,EAKZ,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,QAAQ,EACR,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EACxE,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,EAAE,EACF,KAAK,EACL,UAAU,EACV,MAAM,EACN,SAAS,GACV,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,eAAO,MAAM,KAAK;;;;;;;CAOjB,CAAC;AAEF,OAAO,EACL,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,UAAU,EACV,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,GAAG,GACJ,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,YAAY,EAKZ,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,QAAQ,EACR,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EACxE,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,EAAE,EACF,KAAK,EACL,UAAU,EACV,MAAM,EACN,SAAS,GACV,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5E,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;;;;;;;GAOG;AAEH,eAAO,MAAM,KAAK,EAAE,IAAI,CACtB,QAAQ,CAAC;IACP,OAAO,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,IAAI,UAAU,CAAC;IACzC,WAAW,EAAE,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC;IACjE,YAAY,EAAE,OAAO,YAAY,CAAC;IAClC,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC;IACzD,qBAAqB,EAAE,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9C,kBAAkB,EAAE,OAAO,kBAAkB,CAAC;CAC/C,CAAC,CASG,CAAC;AAER,OAAO,EACL,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,UAAU,EACV,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,GAAG,GACJ,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAE5D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC"}
package/index.js CHANGED
@@ -1,4 +1,3 @@
1
- /*! scure-btc-signer - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
1
  import { compareBytes, concatBytes, isBytes, pubSchnorr, randomPrivateKeyBytes, taprootTweakPubkey, } from "./utils.js";
3
2
  // should multisig be exported as classicMultisig?
4
3
  // prettier-ignore
@@ -7,16 +6,27 @@ export { CompactSize, MAX_SCRIPT_BYTE_LENGTH, OP, RawTx, RawWitness, Script, Scr
7
6
  export { getInputType, Transaction } from "./transaction.js";
8
7
  export { NETWORK, TAPROOT_UNSPENDABLE_KEY, TEST_NETWORK } from "./utils.js";
9
8
  export { selectUTXO } from "./utxo.js";
10
- export const utils = {
9
+ /**
10
+ * Small collection of commonly used utility exports.
11
+ * @example
12
+ * Reach for the grouped helpers when you want the common byte and Taproot utilities.
13
+ * ```ts
14
+ * utils.compareBytes(new Uint8Array([1]), new Uint8Array([2]));
15
+ * ```
16
+ */
17
+ // Convenience subset; import from `./utils.ts` when you need the full helper surface.
18
+ export const utils = /* @__PURE__ */ (() => Object.freeze({
11
19
  isBytes,
12
20
  concatBytes,
13
21
  compareBytes,
14
22
  pubSchnorr,
15
23
  randomPrivateKeyBytes,
16
24
  taprootTweakPubkey,
17
- };
18
- export { _sortPubkeys, Address, combinations, getAddress, OutScript, sortedMultisig, taprootListToTree, WIF, } from "./payment.js"; // remove
19
- export { _DebugPSBT, TaprootControlBlock } from "./psbt.js"; // remove
20
- export { bip32Path, Decimal, DEFAULT_SEQUENCE, PSBTCombine, SigHash } from "./transaction.js"; // remove
25
+ }))();
26
+ export { _sortPubkeys, Address, combinations, getAddress, OutScript, sortedMultisig, taprootListToTree, WIF, } from "./payment.js";
27
+ // remove
28
+ export { _DebugPSBT, TaprootControlBlock } from "./psbt.js";
29
+ // remove
30
+ export { bip32Path, Decimal, DEFAULT_SEQUENCE, PSBTCombine, SigHash } from "./transaction.js";
21
31
  export { _cmpBig, _Estimator } from "./utxo.js";
22
32
  //# sourceMappingURL=index.js.map