@btc-vision/bitcoin 7.0.0-alpha.1 → 7.0.0-alpha.3

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.
Files changed (180) hide show
  1. package/README.md +334 -161
  2. package/browser/address.d.ts +5 -1
  3. package/browser/address.d.ts.map +1 -1
  4. package/browser/branded.d.ts +3 -14
  5. package/browser/branded.d.ts.map +1 -1
  6. package/browser/ecc/context.d.ts +22 -21
  7. package/browser/ecc/context.d.ts.map +1 -1
  8. package/browser/ecc/index.d.ts +1 -1
  9. package/browser/ecc/index.d.ts.map +1 -1
  10. package/browser/ecc/types.d.ts +10 -123
  11. package/browser/ecc/types.d.ts.map +1 -1
  12. package/browser/index.d.ts +3 -2
  13. package/browser/index.d.ts.map +1 -1
  14. package/browser/index.js +6465 -4692
  15. package/browser/opcodes.d.ts +11 -0
  16. package/browser/opcodes.d.ts.map +1 -1
  17. package/browser/payments/p2tr.d.ts.map +1 -1
  18. package/browser/psbt/PsbtCache.d.ts +54 -0
  19. package/browser/psbt/PsbtCache.d.ts.map +1 -0
  20. package/browser/psbt/PsbtFinalizer.d.ts +21 -0
  21. package/browser/psbt/PsbtFinalizer.d.ts.map +1 -0
  22. package/browser/psbt/PsbtSigner.d.ts +32 -0
  23. package/browser/psbt/PsbtSigner.d.ts.map +1 -0
  24. package/browser/psbt/PsbtTransaction.d.ts +25 -0
  25. package/browser/psbt/PsbtTransaction.d.ts.map +1 -0
  26. package/browser/psbt/types.d.ts +4 -70
  27. package/browser/psbt/types.d.ts.map +1 -1
  28. package/browser/psbt/validation.d.ts +1 -1
  29. package/browser/psbt/validation.d.ts.map +1 -1
  30. package/browser/psbt.d.ts +26 -40
  31. package/browser/psbt.d.ts.map +1 -1
  32. package/browser/script.d.ts.map +1 -1
  33. package/browser/transaction.d.ts +4 -4
  34. package/browser/transaction.d.ts.map +1 -1
  35. package/browser/types.d.ts +5 -3
  36. package/browser/types.d.ts.map +1 -1
  37. package/browser/workers/index.d.ts +3 -50
  38. package/browser/workers/index.d.ts.map +1 -1
  39. package/browser/workers/index.node.d.ts +24 -0
  40. package/browser/workers/index.node.d.ts.map +1 -0
  41. package/build/address.d.ts +5 -1
  42. package/build/address.d.ts.map +1 -1
  43. package/build/address.js +29 -17
  44. package/build/address.js.map +1 -1
  45. package/build/branded.d.ts +3 -14
  46. package/build/branded.d.ts.map +1 -1
  47. package/build/branded.js +0 -5
  48. package/build/branded.js.map +1 -1
  49. package/build/ecc/context.d.ts +22 -21
  50. package/build/ecc/context.d.ts.map +1 -1
  51. package/build/ecc/context.js +23 -95
  52. package/build/ecc/context.js.map +1 -1
  53. package/build/ecc/index.d.ts +1 -1
  54. package/build/ecc/index.d.ts.map +1 -1
  55. package/build/ecc/types.d.ts +7 -126
  56. package/build/ecc/types.d.ts.map +1 -1
  57. package/build/ecc/types.js +4 -1
  58. package/build/ecc/types.js.map +1 -1
  59. package/build/index.d.ts +3 -2
  60. package/build/index.d.ts.map +1 -1
  61. package/build/index.js +1 -1
  62. package/build/index.js.map +1 -1
  63. package/build/opcodes.d.ts +11 -0
  64. package/build/opcodes.d.ts.map +1 -1
  65. package/build/opcodes.js +19 -4
  66. package/build/opcodes.js.map +1 -1
  67. package/build/payments/p2tr.d.ts.map +1 -1
  68. package/build/payments/p2tr.js +2 -3
  69. package/build/payments/p2tr.js.map +1 -1
  70. package/build/psbt/PsbtCache.d.ts +54 -0
  71. package/build/psbt/PsbtCache.d.ts.map +1 -0
  72. package/build/psbt/PsbtCache.js +249 -0
  73. package/build/psbt/PsbtCache.js.map +1 -0
  74. package/build/psbt/PsbtFinalizer.d.ts +21 -0
  75. package/build/psbt/PsbtFinalizer.d.ts.map +1 -0
  76. package/build/psbt/PsbtFinalizer.js +157 -0
  77. package/build/psbt/PsbtFinalizer.js.map +1 -0
  78. package/build/psbt/PsbtSigner.d.ts +32 -0
  79. package/build/psbt/PsbtSigner.d.ts.map +1 -0
  80. package/build/psbt/PsbtSigner.js +192 -0
  81. package/build/psbt/PsbtSigner.js.map +1 -0
  82. package/build/psbt/PsbtTransaction.d.ts +25 -0
  83. package/build/psbt/PsbtTransaction.d.ts.map +1 -0
  84. package/build/psbt/PsbtTransaction.js +61 -0
  85. package/build/psbt/PsbtTransaction.js.map +1 -0
  86. package/build/psbt/types.d.ts +4 -70
  87. package/build/psbt/types.d.ts.map +1 -1
  88. package/build/psbt/validation.d.ts +1 -1
  89. package/build/psbt/validation.d.ts.map +1 -1
  90. package/build/psbt.d.ts +26 -40
  91. package/build/psbt.d.ts.map +1 -1
  92. package/build/psbt.js +177 -799
  93. package/build/psbt.js.map +1 -1
  94. package/build/script.d.ts.map +1 -1
  95. package/build/script.js +2 -2
  96. package/build/script.js.map +1 -1
  97. package/build/transaction.d.ts +4 -4
  98. package/build/transaction.d.ts.map +1 -1
  99. package/build/transaction.js +5 -4
  100. package/build/transaction.js.map +1 -1
  101. package/build/tsconfig.build.tsbuildinfo +1 -1
  102. package/build/types.d.ts +5 -3
  103. package/build/types.d.ts.map +1 -1
  104. package/build/types.js +9 -0
  105. package/build/types.js.map +1 -1
  106. package/build/workers/WorkerSigningPool.js +1 -1
  107. package/build/workers/WorkerSigningPool.js.map +1 -1
  108. package/build/workers/index.d.ts +3 -3
  109. package/build/workers/index.d.ts.map +1 -1
  110. package/build/workers/index.js +0 -3
  111. package/build/workers/index.js.map +1 -1
  112. package/build/workers/index.node.d.ts +24 -0
  113. package/build/workers/index.node.d.ts.map +1 -0
  114. package/build/workers/index.node.js +26 -0
  115. package/build/workers/index.node.js.map +1 -0
  116. package/package.json +27 -8
  117. package/src/address.ts +41 -18
  118. package/src/branded.ts +15 -13
  119. package/src/ecc/context.ts +30 -133
  120. package/src/ecc/index.ts +2 -2
  121. package/src/ecc/types.ts +7 -138
  122. package/src/index.ts +36 -2
  123. package/src/opcodes.ts +21 -4
  124. package/src/payments/p2tr.ts +2 -2
  125. package/src/psbt/PsbtCache.ts +325 -0
  126. package/src/psbt/PsbtFinalizer.ts +213 -0
  127. package/src/psbt/PsbtSigner.ts +302 -0
  128. package/src/psbt/PsbtTransaction.ts +82 -0
  129. package/src/psbt/types.ts +4 -86
  130. package/src/psbt/validation.ts +1 -1
  131. package/src/psbt.ts +348 -1197
  132. package/src/script.ts +2 -2
  133. package/src/transaction.ts +9 -8
  134. package/src/types.ts +14 -1
  135. package/src/workers/WorkerSigningPool.ts +1 -1
  136. package/src/workers/index.node.ts +27 -0
  137. package/src/workers/index.ts +7 -9
  138. package/test/address.spec.ts +2 -2
  139. package/test/bitcoin.core.spec.ts +5 -2
  140. package/test/browser/payments.spec.ts +151 -0
  141. package/test/browser/psbt.spec.ts +1510 -0
  142. package/test/browser/script.spec.ts +223 -0
  143. package/test/browser/setup.ts +13 -0
  144. package/test/browser/workers-signing.spec.ts +537 -0
  145. package/test/crypto.spec.ts +2 -2
  146. package/test/fixtures/core/base58_encode_decode.json +12 -48
  147. package/test/fixtures/core/base58_keys_invalid.json +50 -150
  148. package/test/fixtures/core/sighash.json +1 -3
  149. package/test/fixtures/core/tx_valid.json +133 -501
  150. package/test/fixtures/embed.json +3 -11
  151. package/test/fixtures/p2ms.json +21 -91
  152. package/test/fixtures/p2pk.json +5 -24
  153. package/test/fixtures/p2pkh.json +7 -36
  154. package/test/fixtures/p2sh.json +8 -54
  155. package/test/fixtures/p2tr.json +2 -6
  156. package/test/fixtures/p2wpkh.json +7 -36
  157. package/test/fixtures/p2wsh.json +14 -59
  158. package/test/fixtures/psbt.json +2 -6
  159. package/test/fixtures/script.json +12 -48
  160. package/test/integration/addresses.spec.ts +11 -5
  161. package/test/integration/bip32.spec.ts +1 -1
  162. package/test/integration/cltv.spec.ts +10 -6
  163. package/test/integration/csv.spec.ts +10 -9
  164. package/test/integration/payments.spec.ts +8 -4
  165. package/test/integration/taproot.spec.ts +26 -6
  166. package/test/integration/transactions.spec.ts +22 -8
  167. package/test/payments.spec.ts +1 -1
  168. package/test/payments.utils.ts +1 -1
  169. package/test/psbt.spec.ts +250 -64
  170. package/test/script_signature.spec.ts +1 -1
  171. package/test/transaction.spec.ts +18 -5
  172. package/test/tsconfig.json +6 -20
  173. package/test/workers-pool.spec.ts +22 -23
  174. package/test/workers-signing.spec.ts +7 -3
  175. package/test/workers.spec.ts +6 -7
  176. package/typedoc.json +11 -1
  177. package/vitest.config.browser.ts +68 -0
  178. package/browser/ecpair.d.ts +0 -99
  179. package/src/ecpair.d.ts +0 -99
  180. package/test/taproot-cache.spec.ts +0 -694
@@ -3,9 +3,7 @@
3
3
  {
4
4
  "asm": "OP_1NEGATE",
5
5
  "script": "4f",
6
- "stack": [
7
- "81"
8
- ]
6
+ "stack": ["81"]
9
7
  },
10
8
  {
11
9
  "asm": "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801",
@@ -74,18 +72,12 @@
74
72
  {
75
73
  "asm": "OP_0 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5",
76
74
  "script": "0014aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5",
77
- "stack": [
78
- "",
79
- "aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5"
80
- ]
75
+ "stack": ["", "aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5"]
81
76
  },
82
77
  {
83
78
  "asm": "OP_0 32447752937d355ca2defddcd1f6b4fc53d182f8901cebbcff42f5e381bf0b80",
84
79
  "script": "002032447752937d355ca2defddcd1f6b4fc53d182f8901cebbcff42f5e381bf0b80",
85
- "stack": [
86
- "",
87
- "32447752937d355ca2defddcd1f6b4fc53d182f8901cebbcff42f5e381bf0b80"
88
- ]
80
+ "stack": ["", "32447752937d355ca2defddcd1f6b4fc53d182f8901cebbcff42f5e381bf0b80"]
89
81
  },
90
82
  {
91
83
  "asm": "OP_RETURN 06deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474",
@@ -112,12 +104,7 @@
112
104
  {
113
105
  "asm": "OP_0 OP_0 OP_0 OP_0",
114
106
  "script": "00000000",
115
- "stack": [
116
- "",
117
- "",
118
- "",
119
- ""
120
- ]
107
+ "stack": ["", "", "", ""]
121
108
  },
122
109
  {
123
110
  "asm": "OP_0 OP_0 30450221009c92c1ae1767ac04e424da7f6db045d979b08cde86b1ddba48621d59a109d818022004f5bb21ad72255177270abaeb2d7940ac18f1e5ca1f53db4f3fd1045647a8a801 52410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b84104c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a52ae",
@@ -140,24 +127,17 @@
140
127
  {
141
128
  "asm": "OP_0",
142
129
  "script": "00",
143
- "stack": [
144
- ""
145
- ]
130
+ "stack": [""]
146
131
  },
147
132
  {
148
133
  "asm": "OP_0 00",
149
134
  "script": "000100",
150
- "stack": [
151
- "",
152
- "00"
153
- ]
135
+ "stack": ["", "00"]
154
136
  },
155
137
  {
156
138
  "asm": "OP_6",
157
139
  "script": "56",
158
- "stack": [
159
- "06"
160
- ],
140
+ "stack": ["06"],
161
141
  "nonstandard": {
162
142
  "scriptSig": "OP_6",
163
143
  "scriptSigHex": "0106"
@@ -306,9 +286,7 @@
306
286
  },
307
287
  {
308
288
  "type": "nulldata",
309
- "data": [
310
- "deadffffffffffffffffffffffffffffffffbeef"
311
- ],
289
+ "data": ["deadffffffffffffffffffffffffffffffffbeef"],
312
290
  "output": "OP_RETURN deadffffffffffffffffffffffffffffffffbeef",
313
291
  "outputHex": "6a14deadffffffffffffffffffffffffffffffffbeef"
314
292
  },
@@ -342,19 +320,10 @@
342
320
  "02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340",
343
321
  "024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34"
344
322
  ],
345
- "signatures": [
346
- null,
347
- null,
348
- null
349
- ],
323
+ "signatures": [null, null, null],
350
324
  "input": "OP_0 OP_0 OP_0 OP_0",
351
325
  "inputHex": "00000000",
352
- "inputStack": [
353
- "",
354
- "",
355
- "",
356
- ""
357
- ]
326
+ "inputStack": ["", "", "", ""]
358
327
  },
359
328
  {
360
329
  "type": "scripthash",
@@ -406,10 +375,7 @@
406
375
  "type": "nonstandard",
407
376
  "input": "OP_0 00",
408
377
  "inputHex": "000100",
409
- "inputStack": [
410
- "",
411
- "00"
412
- ]
378
+ "inputStack": ["", "00"]
413
379
  },
414
380
  {
415
381
  "type": "nonstandard",
@@ -419,9 +385,7 @@
419
385
  "input": "06",
420
386
  "inputHex": "0106"
421
387
  },
422
- "inputStack": [
423
- "06"
424
- ]
388
+ "inputStack": ["06"]
425
389
  },
426
390
  {
427
391
  "type": "nonstandard",
@@ -1,12 +1,18 @@
1
1
  import assert from 'assert';
2
- import { ECPairFactory } from 'ecpair';
3
- import * as ecc from 'tiny-secp256k1';
4
2
  import { describe, it } from 'vitest';
5
- import * as bitcoin from '../../src/index.js';
6
3
  import type { PublicKey } from '../../src/index.js';
4
+ import * as bitcoin from '../../src/index.js';
7
5
  import { regtestUtils } from './_regtest.js';
8
-
9
- const ECPair = ECPairFactory(ecc);
6
+ import { ECPairSigner, createNobleBackend } from '@btc-vision/ecpair';
7
+ import type { Network } from '../../src/networks.js';
8
+
9
+ const backend = createNobleBackend();
10
+ const ECPair = {
11
+ makeRandom: (opts?: { network?: Network }) =>
12
+ ECPairSigner.makeRandom(backend, opts?.network ?? bitcoin.networks.bitcoin),
13
+ fromWIF: (wif: string, network?: Network | Network[]) =>
14
+ ECPairSigner.fromWIF(backend, wif, network ?? bitcoin.networks.bitcoin),
15
+ };
10
16
  const dhttp = regtestUtils.dhttp;
11
17
  const TESTNET = bitcoin.networks.testnet;
12
18
 
@@ -3,8 +3,8 @@ import { BIP32Factory } from '@btc-vision/bip32';
3
3
  import * as ecc from 'tiny-secp256k1';
4
4
  import * as bip39 from 'bip39';
5
5
  import { describe, it } from 'vitest';
6
- import * as bitcoin from '../../src/index.js';
7
6
  import type { PublicKey } from '../../src/index.js';
7
+ import * as bitcoin from '../../src/index.js';
8
8
 
9
9
  const bip32 = BIP32Factory(ecc);
10
10
 
@@ -1,16 +1,20 @@
1
1
  import assert from 'assert';
2
- import { ECPairFactory } from 'ecpair';
3
- import * as ecc from 'tiny-secp256k1';
4
2
  import { beforeAll, describe, it } from 'vitest';
3
+ import type { Bytes32, Satoshi, Script } from '../../src/index.js';
5
4
  import * as bitcoin from '../../src/index.js';
6
- import { toHex, fromHex, reverseCopy } from '../../src/index.js';
7
- import type { Script, Bytes32, Satoshi } from '../../src/index.js';
5
+ import { fromHex, reverseCopy, toHex } from '../../src/index.js';
8
6
  import { regtestUtils } from './_regtest.js';
9
7
 
10
8
  // @ts-ignore
11
9
  import bip65 from 'bip65';
12
-
13
- const ECPair = ECPairFactory(ecc);
10
+ import { ECPairSigner, createNobleBackend } from '@btc-vision/ecpair';
11
+ import type { Network } from '../../src/networks.js';
12
+
13
+ const backend = createNobleBackend();
14
+ const ECPair = {
15
+ fromWIF: (wif: string, network?: Network | Network[]) =>
16
+ ECPairSigner.fromWIF(backend, wif, network ?? bitcoin.networks.bitcoin),
17
+ };
14
18
  const regtest = regtestUtils.network;
15
19
 
16
20
  function toOutputScript(address: string): Script {
@@ -1,19 +1,20 @@
1
1
  import assert from 'assert';
2
- import { ECPairFactory } from 'ecpair';
3
- import * as ecc from 'tiny-secp256k1';
4
2
  import { beforeAll, describe, it } from 'vitest';
3
+ import type { Bytes32, PsbtInput, Satoshi, Script } from '../../src/index.js';
5
4
  import * as bitcoin from '../../src/index.js';
6
- import type { PsbtInput } from '../../src/index.js';
7
- import { toHex, fromHex, reverseCopy } from '../../src/index.js';
8
- import type { Script, Bytes32, Satoshi } from '../../src/index.js';
5
+ import { fromHex, reverseCopy, toHex } from '../../src/index.js';
9
6
  import { regtestUtils } from './_regtest.js';
10
7
 
11
8
  // @ts-ignore
12
9
  import bip68 from 'bip68';
13
-
14
-
15
-
16
- const ECPair = ECPairFactory(ecc);
10
+ import { ECPairSigner, createNobleBackend } from '@btc-vision/ecpair';
11
+ import type { Network } from '../../src/networks.js';
12
+
13
+ const backend = createNobleBackend();
14
+ const ECPair = {
15
+ fromWIF: (wif: string, network?: Network | Network[]) =>
16
+ ECPairSigner.fromWIF(backend, wif, network ?? bitcoin.networks.bitcoin),
17
+ };
17
18
  const regtest = regtestUtils.network;
18
19
 
19
20
  function toOutputScript(address: string): Script {
@@ -1,13 +1,17 @@
1
- import { ECPairFactory } from 'ecpair';
2
- import * as ecc from 'tiny-secp256k1';
1
+ import { ECPairSigner, createNobleBackend } from '@btc-vision/ecpair';
3
2
  import { describe, it } from 'vitest';
3
+ import type { Satoshi } from '../../src/index.js';
4
4
  import * as bitcoin from '../../src/index.js';
5
5
  import { fromHex } from '../../src/index.js';
6
- import type { Satoshi } from '../../src/index.js';
7
6
  import { regtestUtils } from './_regtest.js';
8
7
  import * as fs from 'node:fs';
8
+ import type { Network } from '../../src/networks.js';
9
9
 
10
- const ECPair = ECPairFactory(ecc);
10
+ const backend = createNobleBackend();
11
+ const ECPair = {
12
+ makeRandom: (opts?: { network?: Network }) =>
13
+ ECPairSigner.makeRandom(backend, opts?.network ?? bitcoin.networks.bitcoin),
14
+ };
11
15
  const NETWORK = regtestUtils.network;
12
16
  const keyPairs = [ECPair.makeRandom({ network: NETWORK }), ECPair.makeRandom({ network: NETWORK })];
13
17
 
@@ -3,10 +3,19 @@ import { BIP32Factory } from '@btc-vision/bip32';
3
3
  import * as bip39 from 'bip39';
4
4
  import * as ecc from 'tiny-secp256k1';
5
5
  import { describe, it } from 'vitest';
6
- import { regtestUtils, broadcastAndVerify } from './_regtest.js';
6
+ import { broadcastAndVerify, regtestUtils } from './_regtest.js';
7
+ import type {
8
+ EccLib,
9
+ PsbtInput,
10
+ PublicKey,
11
+ Satoshi,
12
+ TapLeaf,
13
+ TapLeafScript,
14
+ Taptree,
15
+ XOnlyPublicKey,
16
+ } from '../../src/index.js';
7
17
  import * as bitcoin from '../../src/index.js';
8
- import { toHex, fromHex, concat } from '../../src/index.js';
9
- import type { PsbtInput, TapLeaf, TapLeafScript, Taptree, XOnlyPublicKey, PublicKey, Satoshi, Bytes32, EccLib } from '../../src/index.js';
18
+ import { concat, fromHex, toHex } from '../../src/index.js';
10
19
  import { LEAF_VERSION_TAPSCRIPT } from '../../src/payments/bip341.js';
11
20
  import { tapTreeFromList, tapTreeToList } from '../../src/psbt/bip371.js';
12
21
  import { witnessStackToScriptWitness } from '../../src/psbt/psbtutils.js';
@@ -59,7 +68,10 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
59
68
  // amount to send
60
69
  const sendAmount = amount - 1e4;
61
70
  // Send some sats to the address via faucet. Get the hash and index. (txid/vout)
62
- const { txId: hash, vout: index } = await regtestUtils.faucetComplex(Buffer.from(output), amount);
71
+ const { txId: hash, vout: index } = await regtestUtils.faucetComplex(
72
+ Buffer.from(output),
73
+ amount,
74
+ );
63
75
  // Sent 420000 sats to taproot address
64
76
 
65
77
  const psbt = new bitcoin.Psbt({ network: regtest })
@@ -583,7 +595,11 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
583
595
  });
584
596
 
585
597
  it('should fail validating invalid signatures for taproot (See issue #1931)', () => {
586
- const schnorrValidator = (pubkey: Uint8Array, msghash: Uint8Array, signature: Uint8Array) => {
598
+ const schnorrValidator = (
599
+ pubkey: Uint8Array,
600
+ msghash: Uint8Array,
601
+ signature: Uint8Array,
602
+ ) => {
587
603
  return ecc.verifySchnorr(msghash, pubkey, signature);
588
604
  };
589
605
 
@@ -607,7 +623,11 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
607
623
  });
608
624
 
609
625
  it('should succeed validating valid signatures for taproot (See issue #1934)', () => {
610
- const schnorrValidator = (pubkey: Uint8Array, msghash: Uint8Array, signature: Uint8Array) => {
626
+ const schnorrValidator = (
627
+ pubkey: Uint8Array,
628
+ msghash: Uint8Array,
629
+ signature: Uint8Array,
630
+ ) => {
611
631
  return ecc.verifySchnorr(msghash, pubkey, signature);
612
632
  };
613
633
 
@@ -1,22 +1,33 @@
1
1
  import assert from 'assert';
2
2
  import { BIP32Factory } from '@btc-vision/bip32';
3
3
  import * as ecc from 'tiny-secp256k1';
4
- import { ECPairFactory } from 'ecpair';
5
4
  import { describe, it } from 'vitest';
5
+ import type { MessageHash, PrivateKey, PublicKey, Satoshi, Signature } from '../../src/index.js';
6
6
  import * as bitcoin from '../../src/index.js';
7
- import { fromHex, compare } from '../../src/index.js';
8
- import type { Satoshi, PublicKey } from '../../src/index.js';
7
+ import { compare, fromHex } from '../../src/index.js';
9
8
  import type { HDSigner } from '../../src/psbt/types.js';
10
- import { regtestUtils, broadcastAndVerify } from './_regtest.js';
9
+ import { broadcastAndVerify, regtestUtils } from './_regtest.js';
11
10
 
12
11
  import rng from 'randombytes';
13
-
14
- const ECPair = ECPairFactory(ecc);
12
+ import { ECPairSigner, createNobleBackend } from '@btc-vision/ecpair';
13
+ import type { Network } from '../../src/networks.js';
14
+
15
+ const backend = createNobleBackend();
16
+ const ECPair = {
17
+ makeRandom: (opts?: { network?: Network }) =>
18
+ ECPairSigner.makeRandom(backend, opts?.network ?? bitcoin.networks.bitcoin),
19
+ fromWIF: (wif: string, network?: Network | Network[]) =>
20
+ ECPairSigner.fromWIF(backend, wif, network ?? bitcoin.networks.bitcoin),
21
+ fromPublicKey: (pubkey: Uint8Array, opts?: { network?: Network }) =>
22
+ ECPairSigner.fromPublicKey(backend, pubkey as PublicKey, opts?.network ?? bitcoin.networks.bitcoin),
23
+ fromPrivateKey: (key: Uint8Array, opts?: { network?: Network }) =>
24
+ ECPairSigner.fromPrivateKey(backend, key as PrivateKey, opts?.network ?? bitcoin.networks.bitcoin),
25
+ };
15
26
  const regtest = { ...regtestUtils.network, bech32Opnet: 'opreg' };
16
27
  const bip32 = BIP32Factory(ecc);
17
28
 
18
29
  const validator = (pubkey: Uint8Array, msghash: Uint8Array, signature: Uint8Array): boolean =>
19
- ECPair.fromPublicKey(pubkey).verify(msghash, signature);
30
+ ECPair.fromPublicKey(pubkey).verify(msghash as MessageHash, signature as Signature);
20
31
 
21
32
  // See bottom of file for some helper functions used to make the payment objects needed.
22
33
 
@@ -566,7 +577,10 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
566
577
  .signInputHD(0, hdRoot as unknown as HDSigner); // must sign with root!!!
567
578
 
568
579
  assert.strictEqual(psbt.validateSignaturesOfInput(0, validator), true);
569
- assert.strictEqual(psbt.validateSignaturesOfInput(0, validator, childNode.publicKey as PublicKey), true);
580
+ assert.strictEqual(
581
+ psbt.validateSignaturesOfInput(0, validator, childNode.publicKey as PublicKey),
582
+ true,
583
+ );
570
584
  psbt.finalizeAllInputs();
571
585
 
572
586
  const tx = psbt.extractTransaction();
@@ -1,8 +1,8 @@
1
1
  import assert from 'assert';
2
2
  import * as ecc from 'tiny-secp256k1';
3
3
  import { beforeEach, describe, it } from 'vitest';
4
- import { initEccLib } from '../src/index.js';
5
4
  import type { EccLib } from '../src/index.js';
5
+ import { initEccLib } from '../src/index.js';
6
6
  import type { P2SHPayment, PaymentCreator } from '../src/payments/index.js';
7
7
  import { p2pk, p2wsh } from '../src/payments/index.js';
8
8
  import * as u from './payments.utils.js';
@@ -1,7 +1,7 @@
1
1
  import * as t from 'assert';
2
2
  import * as BNETWORKS from '../src/networks.js';
3
3
  import * as bscript from '../src/script.js';
4
- import { toHex, fromHex as ioFromHex } from '../src/io/index.js';
4
+ import { fromHex as ioFromHex, toHex } from '../src/io/index.js';
5
5
 
6
6
  function tryHex(x: Uint8Array | Uint8Array[]): string | string[] {
7
7
  if (x instanceof Uint8Array) return toHex(x);