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

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 (379) hide show
  1. package/README.md +477 -155
  2. package/benchmark-compare/BENCHMARK.md +144 -0
  3. package/benchmark-compare/compare.bench.ts +1024 -0
  4. package/benchmark-compare/harness.ts +220 -0
  5. package/benchmark-compare/package.json +18 -0
  6. package/browser/address.d.ts +5 -1
  7. package/browser/address.d.ts.map +1 -1
  8. package/browser/block.d.ts.map +1 -1
  9. package/browser/branded.d.ts +3 -14
  10. package/browser/branded.d.ts.map +1 -1
  11. package/browser/chunks/psbt-parallel-B-dfm5GZ.js +10624 -0
  12. package/browser/crypto-hashes.d.ts +4 -0
  13. package/browser/crypto-hashes.d.ts.map +1 -0
  14. package/browser/crypto-hashes.native.d.ts +4 -0
  15. package/browser/crypto-hashes.native.d.ts.map +1 -0
  16. package/browser/crypto.d.ts.map +1 -1
  17. package/browser/ecc/context.d.ts +22 -21
  18. package/browser/ecc/context.d.ts.map +1 -1
  19. package/browser/ecc/index.d.ts +1 -1
  20. package/browser/ecc/index.d.ts.map +1 -1
  21. package/browser/ecc/types.d.ts +10 -123
  22. package/browser/ecc/types.d.ts.map +1 -1
  23. package/browser/env.d.ts +13 -0
  24. package/browser/env.d.ts.map +1 -0
  25. package/browser/index.d.ts +6 -6
  26. package/browser/index.d.ts.map +1 -1
  27. package/browser/index.js +2622 -11782
  28. package/browser/io/base58check.d.ts +26 -0
  29. package/browser/io/base58check.d.ts.map +1 -0
  30. package/browser/io/base64.d.ts +8 -0
  31. package/browser/io/base64.d.ts.map +1 -1
  32. package/browser/io/hex.d.ts.map +1 -1
  33. package/browser/io/index.d.ts +2 -2
  34. package/browser/io/index.d.ts.map +1 -1
  35. package/browser/io/utils.d.ts.map +1 -1
  36. package/browser/opcodes.d.ts +11 -0
  37. package/browser/opcodes.d.ts.map +1 -1
  38. package/browser/payments/bip341.d.ts.map +1 -1
  39. package/browser/payments/p2op.d.ts.map +1 -1
  40. package/browser/payments/p2pkh.d.ts.map +1 -1
  41. package/browser/payments/p2sh.d.ts.map +1 -1
  42. package/browser/payments/p2tr.d.ts.map +1 -1
  43. package/browser/payments/p2wpkh.d.ts.map +1 -1
  44. package/browser/psbt/PsbtCache.d.ts +54 -0
  45. package/browser/psbt/PsbtCache.d.ts.map +1 -0
  46. package/browser/psbt/PsbtFinalizer.d.ts +21 -0
  47. package/browser/psbt/PsbtFinalizer.d.ts.map +1 -0
  48. package/browser/psbt/PsbtSigner.d.ts +32 -0
  49. package/browser/psbt/PsbtSigner.d.ts.map +1 -0
  50. package/browser/psbt/PsbtTransaction.d.ts +25 -0
  51. package/browser/psbt/PsbtTransaction.d.ts.map +1 -0
  52. package/browser/psbt/bip371.d.ts.map +1 -1
  53. package/browser/psbt/types.d.ts +4 -70
  54. package/browser/psbt/types.d.ts.map +1 -1
  55. package/browser/psbt/validation.d.ts +1 -1
  56. package/browser/psbt/validation.d.ts.map +1 -1
  57. package/browser/psbt.d.ts +26 -40
  58. package/browser/psbt.d.ts.map +1 -1
  59. package/browser/react-native-quick-crypto.d.ts +11 -0
  60. package/browser/script.d.ts.map +1 -1
  61. package/browser/transaction.d.ts +4 -4
  62. package/browser/transaction.d.ts.map +1 -1
  63. package/browser/types.d.ts +5 -3
  64. package/browser/types.d.ts.map +1 -1
  65. package/browser/workers/WorkerSigningPool.d.ts +7 -0
  66. package/browser/workers/WorkerSigningPool.d.ts.map +1 -1
  67. package/browser/workers/WorkerSigningPool.node.d.ts +7 -0
  68. package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -1
  69. package/browser/workers/WorkerSigningPool.sequential.d.ts +67 -0
  70. package/browser/workers/WorkerSigningPool.sequential.d.ts.map +1 -0
  71. package/browser/workers/WorkerSigningPool.worklet.d.ts +64 -0
  72. package/browser/workers/WorkerSigningPool.worklet.d.ts.map +1 -0
  73. package/browser/workers/index.browser.d.ts +16 -0
  74. package/browser/workers/index.browser.d.ts.map +1 -0
  75. package/browser/workers/index.d.ts +4 -64
  76. package/browser/workers/index.d.ts.map +1 -1
  77. package/browser/workers/index.js +28 -0
  78. package/browser/workers/index.node.d.ts +17 -0
  79. package/browser/workers/index.node.d.ts.map +1 -0
  80. package/browser/workers/index.react-native.d.ts +28 -0
  81. package/browser/workers/index.react-native.d.ts.map +1 -0
  82. package/browser/workers/index.shared.d.ts +15 -0
  83. package/browser/workers/index.shared.d.ts.map +1 -0
  84. package/browser/workers/psbt-parallel.d.ts +2 -3
  85. package/browser/workers/psbt-parallel.d.ts.map +1 -1
  86. package/browser/workers/types.d.ts +17 -0
  87. package/browser/workers/types.d.ts.map +1 -1
  88. package/build/address.d.ts +5 -1
  89. package/build/address.d.ts.map +1 -1
  90. package/build/address.js +48 -29
  91. package/build/address.js.map +1 -1
  92. package/build/bech32utils.js.map +1 -1
  93. package/build/bip66.js +4 -4
  94. package/build/bip66.js.map +1 -1
  95. package/build/block.d.ts.map +1 -1
  96. package/build/block.js +9 -2
  97. package/build/block.js.map +1 -1
  98. package/build/branded.d.ts +3 -14
  99. package/build/branded.d.ts.map +1 -1
  100. package/build/branded.js +0 -5
  101. package/build/branded.js.map +1 -1
  102. package/build/crypto-hashes.d.ts +4 -0
  103. package/build/crypto-hashes.d.ts.map +1 -0
  104. package/build/crypto-hashes.js +4 -0
  105. package/build/crypto-hashes.js.map +1 -0
  106. package/build/crypto-hashes.native.d.ts +4 -0
  107. package/build/crypto-hashes.native.d.ts.map +1 -0
  108. package/build/crypto-hashes.native.js +15 -0
  109. package/build/crypto-hashes.native.js.map +1 -0
  110. package/build/crypto.d.ts.map +1 -1
  111. package/build/crypto.js +1 -2
  112. package/build/crypto.js.map +1 -1
  113. package/build/ecc/context.d.ts +22 -21
  114. package/build/ecc/context.d.ts.map +1 -1
  115. package/build/ecc/context.js +23 -95
  116. package/build/ecc/context.js.map +1 -1
  117. package/build/ecc/index.d.ts +1 -1
  118. package/build/ecc/index.d.ts.map +1 -1
  119. package/build/ecc/types.d.ts +7 -126
  120. package/build/ecc/types.d.ts.map +1 -1
  121. package/build/ecc/types.js +4 -1
  122. package/build/ecc/types.js.map +1 -1
  123. package/build/env.d.ts +13 -0
  124. package/build/env.d.ts.map +1 -0
  125. package/build/env.js +198 -0
  126. package/build/env.js.map +1 -0
  127. package/build/index.d.ts +7 -6
  128. package/build/index.d.ts.map +1 -1
  129. package/build/index.js +7 -5
  130. package/build/index.js.map +1 -1
  131. package/build/io/BinaryReader.js +1 -1
  132. package/build/io/BinaryReader.js.map +1 -1
  133. package/build/io/base58check.d.ts +26 -0
  134. package/build/io/base58check.d.ts.map +1 -0
  135. package/build/io/base58check.js +32 -0
  136. package/build/io/base58check.js.map +1 -0
  137. package/build/io/base64.d.ts +8 -0
  138. package/build/io/base64.d.ts.map +1 -1
  139. package/build/io/base64.js +14 -0
  140. package/build/io/base64.js.map +1 -1
  141. package/build/io/hex.d.ts.map +1 -1
  142. package/build/io/hex.js +3 -2
  143. package/build/io/hex.js.map +1 -1
  144. package/build/io/index.d.ts +2 -2
  145. package/build/io/index.d.ts.map +1 -1
  146. package/build/io/index.js +4 -4
  147. package/build/io/index.js.map +1 -1
  148. package/build/io/utils.d.ts.map +1 -1
  149. package/build/io/utils.js +3 -4
  150. package/build/io/utils.js.map +1 -1
  151. package/build/merkle.js.map +1 -1
  152. package/build/opcodes.d.ts +11 -0
  153. package/build/opcodes.d.ts.map +1 -1
  154. package/build/opcodes.js +19 -4
  155. package/build/opcodes.js.map +1 -1
  156. package/build/payments/bip341.d.ts.map +1 -1
  157. package/build/payments/bip341.js +4 -3
  158. package/build/payments/bip341.js.map +1 -1
  159. package/build/payments/embed.js.map +1 -1
  160. package/build/payments/p2ms.js.map +1 -1
  161. package/build/payments/p2op.d.ts.map +1 -1
  162. package/build/payments/p2op.js +6 -4
  163. package/build/payments/p2op.js.map +1 -1
  164. package/build/payments/p2pk.js.map +1 -1
  165. package/build/payments/p2pkh.d.ts.map +1 -1
  166. package/build/payments/p2pkh.js +3 -4
  167. package/build/payments/p2pkh.js.map +1 -1
  168. package/build/payments/p2sh.d.ts.map +1 -1
  169. package/build/payments/p2sh.js +3 -4
  170. package/build/payments/p2sh.js.map +1 -1
  171. package/build/payments/p2tr.d.ts.map +1 -1
  172. package/build/payments/p2tr.js +15 -9
  173. package/build/payments/p2tr.js.map +1 -1
  174. package/build/payments/p2wpkh.d.ts.map +1 -1
  175. package/build/payments/p2wpkh.js +7 -5
  176. package/build/payments/p2wpkh.js.map +1 -1
  177. package/build/payments/p2wsh.js.map +1 -1
  178. package/build/psbt/PsbtCache.d.ts +54 -0
  179. package/build/psbt/PsbtCache.d.ts.map +1 -0
  180. package/build/psbt/PsbtCache.js +253 -0
  181. package/build/psbt/PsbtCache.js.map +1 -0
  182. package/build/psbt/PsbtFinalizer.d.ts +21 -0
  183. package/build/psbt/PsbtFinalizer.d.ts.map +1 -0
  184. package/build/psbt/PsbtFinalizer.js +163 -0
  185. package/build/psbt/PsbtFinalizer.js.map +1 -0
  186. package/build/psbt/PsbtSigner.d.ts +32 -0
  187. package/build/psbt/PsbtSigner.d.ts.map +1 -0
  188. package/build/psbt/PsbtSigner.js +193 -0
  189. package/build/psbt/PsbtSigner.js.map +1 -0
  190. package/build/psbt/PsbtTransaction.d.ts +25 -0
  191. package/build/psbt/PsbtTransaction.d.ts.map +1 -0
  192. package/build/psbt/PsbtTransaction.js +61 -0
  193. package/build/psbt/PsbtTransaction.js.map +1 -0
  194. package/build/psbt/bip371.d.ts.map +1 -1
  195. package/build/psbt/bip371.js +4 -3
  196. package/build/psbt/bip371.js.map +1 -1
  197. package/build/psbt/types.d.ts +4 -70
  198. package/build/psbt/types.d.ts.map +1 -1
  199. package/build/psbt/utils.js.map +1 -1
  200. package/build/psbt/validation.d.ts +1 -1
  201. package/build/psbt/validation.d.ts.map +1 -1
  202. package/build/psbt.d.ts +26 -40
  203. package/build/psbt.d.ts.map +1 -1
  204. package/build/psbt.js +177 -799
  205. package/build/psbt.js.map +1 -1
  206. package/build/push_data.js +1 -1
  207. package/build/push_data.js.map +1 -1
  208. package/build/script.d.ts.map +1 -1
  209. package/build/script.js +6 -5
  210. package/build/script.js.map +1 -1
  211. package/build/script_number.js +1 -1
  212. package/build/script_number.js.map +1 -1
  213. package/build/script_signature.js.map +1 -1
  214. package/build/transaction.d.ts +4 -4
  215. package/build/transaction.d.ts.map +1 -1
  216. package/build/transaction.js +7 -5
  217. package/build/transaction.js.map +1 -1
  218. package/build/tsconfig.build.tsbuildinfo +1 -1
  219. package/build/types.d.ts +5 -3
  220. package/build/types.d.ts.map +1 -1
  221. package/build/types.js +11 -16
  222. package/build/types.js.map +1 -1
  223. package/build/workers/WorkerSigningPool.d.ts +7 -0
  224. package/build/workers/WorkerSigningPool.d.ts.map +1 -1
  225. package/build/workers/WorkerSigningPool.js +12 -1
  226. package/build/workers/WorkerSigningPool.js.map +1 -1
  227. package/build/workers/WorkerSigningPool.node.d.ts +7 -0
  228. package/build/workers/WorkerSigningPool.node.d.ts.map +1 -1
  229. package/build/workers/WorkerSigningPool.node.js +37 -5
  230. package/build/workers/WorkerSigningPool.node.js.map +1 -1
  231. package/build/workers/WorkerSigningPool.sequential.d.ts +76 -0
  232. package/build/workers/WorkerSigningPool.sequential.d.ts.map +1 -0
  233. package/build/workers/WorkerSigningPool.sequential.js +162 -0
  234. package/build/workers/WorkerSigningPool.sequential.js.map +1 -0
  235. package/build/workers/WorkerSigningPool.worklet.d.ts +79 -0
  236. package/build/workers/WorkerSigningPool.worklet.d.ts.map +1 -0
  237. package/build/workers/WorkerSigningPool.worklet.js +390 -0
  238. package/build/workers/WorkerSigningPool.worklet.js.map +1 -0
  239. package/build/workers/index.browser.d.ts +24 -0
  240. package/build/workers/index.browser.d.ts.map +1 -0
  241. package/build/workers/index.browser.js +30 -0
  242. package/build/workers/index.browser.js.map +1 -0
  243. package/build/workers/index.d.ts +6 -18
  244. package/build/workers/index.d.ts.map +1 -1
  245. package/build/workers/index.js +12 -14
  246. package/build/workers/index.js.map +1 -1
  247. package/build/workers/index.node.d.ts +38 -0
  248. package/build/workers/index.node.d.ts.map +1 -0
  249. package/build/workers/index.node.js +45 -0
  250. package/build/workers/index.node.js.map +1 -0
  251. package/build/workers/index.react-native.d.ts +28 -0
  252. package/build/workers/index.react-native.d.ts.map +1 -0
  253. package/build/workers/index.react-native.js +67 -0
  254. package/build/workers/index.react-native.js.map +1 -0
  255. package/build/workers/index.shared.d.ts +15 -0
  256. package/build/workers/index.shared.d.ts.map +1 -0
  257. package/build/workers/index.shared.js +20 -0
  258. package/build/workers/index.shared.js.map +1 -0
  259. package/build/workers/psbt-parallel.d.ts +2 -3
  260. package/build/workers/psbt-parallel.d.ts.map +1 -1
  261. package/build/workers/psbt-parallel.js +4 -4
  262. package/build/workers/psbt-parallel.js.map +1 -1
  263. package/build/workers/types.d.ts +17 -0
  264. package/build/workers/types.d.ts.map +1 -1
  265. package/package.json +51 -11
  266. package/src/address.ts +59 -31
  267. package/src/bech32utils.ts +3 -3
  268. package/src/bip66.ts +18 -18
  269. package/src/block.ts +8 -3
  270. package/src/branded.ts +15 -13
  271. package/src/crypto-hashes.native.ts +18 -0
  272. package/src/crypto-hashes.ts +3 -0
  273. package/src/crypto.ts +1 -2
  274. package/src/ecc/context.ts +30 -133
  275. package/src/ecc/index.ts +2 -2
  276. package/src/ecc/types.ts +7 -138
  277. package/src/env.ts +239 -0
  278. package/src/index.ts +48 -9
  279. package/src/io/BinaryReader.ts +1 -1
  280. package/src/io/base58check.ts +35 -0
  281. package/src/io/base64.ts +15 -0
  282. package/src/io/hex.ts +3 -2
  283. package/src/io/index.ts +5 -5
  284. package/src/io/utils.ts +6 -7
  285. package/src/merkle.ts +3 -3
  286. package/src/opcodes.ts +21 -4
  287. package/src/payments/bip341.ts +8 -7
  288. package/src/payments/embed.ts +1 -1
  289. package/src/payments/p2ms.ts +2 -2
  290. package/src/payments/p2op.ts +6 -4
  291. package/src/payments/p2pk.ts +2 -2
  292. package/src/payments/p2pkh.ts +7 -8
  293. package/src/payments/p2sh.ts +8 -9
  294. package/src/payments/p2tr.ts +26 -19
  295. package/src/payments/p2wpkh.ts +9 -7
  296. package/src/payments/p2wsh.ts +3 -3
  297. package/src/psbt/PsbtCache.ts +328 -0
  298. package/src/psbt/PsbtFinalizer.ts +219 -0
  299. package/src/psbt/PsbtSigner.ts +303 -0
  300. package/src/psbt/PsbtTransaction.ts +82 -0
  301. package/src/psbt/bip371.ts +4 -3
  302. package/src/psbt/types.ts +4 -86
  303. package/src/psbt/utils.ts +1 -1
  304. package/src/psbt/validation.ts +1 -1
  305. package/src/psbt.ts +355 -1202
  306. package/src/push_data.ts +5 -5
  307. package/src/react-native-quick-crypto.d.ts +11 -0
  308. package/src/script.ts +7 -6
  309. package/src/script_number.ts +6 -6
  310. package/src/script_signature.ts +2 -2
  311. package/src/transaction.ts +24 -22
  312. package/src/types.ts +19 -29
  313. package/src/workers/WorkerSigningPool.node.ts +42 -6
  314. package/src/workers/WorkerSigningPool.sequential.ts +192 -0
  315. package/src/workers/WorkerSigningPool.ts +17 -4
  316. package/src/workers/WorkerSigningPool.worklet.ts +522 -0
  317. package/src/workers/index.browser.ts +34 -0
  318. package/src/workers/index.node.ts +50 -0
  319. package/src/workers/index.react-native.ts +110 -0
  320. package/src/workers/index.shared.ts +58 -0
  321. package/src/workers/index.ts +14 -65
  322. package/src/workers/psbt-parallel.ts +9 -9
  323. package/src/workers/types.ts +21 -0
  324. package/test/address.spec.ts +3 -2
  325. package/test/bitcoin.core.spec.ts +14 -4
  326. package/test/browser/payments.spec.ts +151 -0
  327. package/test/browser/psbt.spec.ts +1535 -0
  328. package/test/browser/script.spec.ts +223 -0
  329. package/test/browser/setup.ts +13 -0
  330. package/test/browser/workers-signing.spec.ts +537 -0
  331. package/test/crypto.spec.ts +3 -3
  332. package/test/env.spec.ts +418 -0
  333. package/test/fixtures/core/base58_encode_decode.json +12 -48
  334. package/test/fixtures/core/base58_keys_invalid.json +50 -150
  335. package/test/fixtures/core/sighash.json +1 -3
  336. package/test/fixtures/core/tx_valid.json +133 -501
  337. package/test/fixtures/embed.json +3 -11
  338. package/test/fixtures/p2ms.json +21 -91
  339. package/test/fixtures/p2pk.json +5 -24
  340. package/test/fixtures/p2pkh.json +7 -36
  341. package/test/fixtures/p2sh.json +8 -54
  342. package/test/fixtures/p2tr.json +2 -6
  343. package/test/fixtures/p2wpkh.json +7 -36
  344. package/test/fixtures/p2wsh.json +14 -59
  345. package/test/fixtures/psbt.json +2 -6
  346. package/test/fixtures/script.json +12 -48
  347. package/test/integration/_regtest.ts +2 -2
  348. package/test/integration/addresses.spec.ts +11 -5
  349. package/test/integration/bip32.spec.ts +1 -1
  350. package/test/integration/blocks.spec.ts +1 -1
  351. package/test/integration/cltv.spec.ts +10 -6
  352. package/test/integration/csv.spec.ts +11 -10
  353. package/test/integration/payments.spec.ts +10 -6
  354. package/test/integration/taproot.spec.ts +29 -9
  355. package/test/integration/transactions.spec.ts +27 -12
  356. package/test/payments.spec.ts +1 -1
  357. package/test/payments.utils.ts +1 -1
  358. package/test/psbt.spec.ts +293 -83
  359. package/test/script_signature.spec.ts +1 -1
  360. package/test/transaction.spec.ts +24 -8
  361. package/test/tsconfig.json +6 -20
  362. package/test/workers-pool.spec.ts +69 -27
  363. package/test/workers-sequential.spec.ts +669 -0
  364. package/test/workers-signing.spec.ts +15 -11
  365. package/test/workers-worklet.spec.ts +500 -0
  366. package/test/workers.spec.ts +9 -10
  367. package/typedoc.json +11 -1
  368. package/vite.config.browser.ts +31 -6
  369. package/vitest.config.browser.ts +68 -0
  370. package/browser/ecpair.d.ts +0 -99
  371. package/browser/io/MemoryPool.d.ts +0 -220
  372. package/browser/io/MemoryPool.d.ts.map +0 -1
  373. package/build/io/MemoryPool.d.ts +0 -220
  374. package/build/io/MemoryPool.d.ts.map +0 -1
  375. package/build/io/MemoryPool.js +0 -309
  376. package/build/io/MemoryPool.js.map +0 -1
  377. package/src/ecpair.d.ts +0 -99
  378. package/src/io/MemoryPool.ts +0 -343
  379. package/test/taproot-cache.spec.ts +0 -694
package/README.md CHANGED
@@ -1,201 +1,523 @@
1
- # BitcoinJS (bitcoinjs-lib)
2
- [![Github CI](https://github.com/bitcoinjs/bitcoinjs-lib/actions/workflows/main_ci.yml/badge.svg)](https://github.com/bitcoinjs/bitcoinjs-lib/actions/workflows/main_ci.yml) [![NPM](https://img.shields.io/npm/v/bitcoinjs-lib.svg)](https://www.npmjs.org/package/bitcoinjs-lib) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
1
+ # @btc-vision/bitcoin
3
2
 
4
- A javascript Bitcoin library for node.js and browsers. Written in TypeScript, but committing the JS files to verify.
3
+ ![Bitcoin](https://img.shields.io/badge/Bitcoin-000?style=for-the-badge&logo=bitcoin&logoColor=white)
4
+ ![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)
5
+ ![NodeJS](https://img.shields.io/badge/Node%20js-339933?style=for-the-badge&logo=nodedotjs&logoColor=white)
6
+ ![NPM](https://img.shields.io/badge/npm-CB3837?style=for-the-badge&logo=npm&logoColor=white)
5
7
 
6
- Released under the terms of the [MIT LICENSE](LICENSE).
8
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
7
9
 
8
- ## Should I use this in production?
9
- If you are thinking of using the *master* branch of this library in production, **stop**.
10
- Master is not stable; it is our development branch, and [only tagged releases may be classified as stable](https://github.com/bitcoinjs/bitcoinjs-lib/tags).
10
+ ## Overview
11
11
 
12
- ## Can I trust this code?
13
- > Don't trust. Verify.
12
+ A client-side Bitcoin library for Node.js and browsers, written in TypeScript. Provides low-level transaction handling, PSBT (Partially Signed Bitcoin Transactions), address encoding/decoding, payment script creation, and cryptographic operations across multiple networks.
14
13
 
15
- We recommend every user of this library and the [bitcoinjs](https://github.com/bitcoinjs) ecosystem audit and verify any underlying code for its validity and suitability, including reviewing any and all of your project's dependencies.
14
+ This is a modernized fork of [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib) with significant API changes:
16
15
 
17
- Mistakes and bugs happen, but with your help in resolving and reporting [issues](https://github.com/bitcoinjs/bitcoinjs-lib/issues), together we can produce open source software that is:
16
+ - **Branded types** (`Bytes32`, `PrivateKey`, `PublicKey`, `Satoshi`, etc.) for compile-time safety
17
+ - **Modular PSBT architecture** split into composable classes (`PsbtCache`, `PsbtSigner`, `PsbtFinalizer`, `PsbtTransaction`)
18
+ - **Worker-based parallel signing** for both Node.js (`worker_threads`) and browsers (Web Workers)
19
+ - **Native `Uint8Array`** throughout (no Node.js `Buffer` dependency)
20
+ - **`bigint` for satoshi values** instead of `number` to prevent precision loss
21
+ - **Structured error hierarchy** with typed error classes
22
+ - **Granular sub-path exports** for tree-shaking
23
+ - **Multi-chain support** including Bitcoin, Litecoin, Dogecoin, Bitcoin Cash, and Dash
18
24
 
19
- - Easy to audit and verify,
20
- - Tested, with test coverage >95%,
21
- - Advanced and feature rich,
22
- - Standardized, using [prettier](https://github.com/prettier/prettier) and Node `Buffer`'s throughout, and
23
- - Friendly, with a strong and helpful community, ready to answer questions.
25
+ > **Breaking Changes from bitcoinjs-lib**
26
+ >
27
+ > This library has undergone massive API-breaking changes. Transaction values use `bigint` (as `Satoshi`), all byte buffers are `Uint8Array` with branded type wrappers, the ECC library must be explicitly initialized, and key management has been moved to [`@btc-vision/ecpair`](https://github.com/btc-vision/ecpair) and [`@btc-vision/bip32`](https://github.com/btc-vision/bip32).
24
28
 
25
- ## Documentation
26
- Visit our [documentation](https://bitcoinjs.github.io/bitcoinjs-lib/) to explore the available resources. We're continually enhancing our documentation with additional features for an enriched experience. If you need further guidance beyond what our [examples](#examples) offer, don't hesitate to [ask for help](https://github.com/bitcoinjs/bitcoinjs-lib/issues/new). We're here to assist you.
29
+ ## Installation
30
+
31
+ ```bash
32
+ npm install @btc-vision/bitcoin
33
+ # Key management libraries (separate packages)
34
+ npm install @btc-vision/ecpair @btc-vision/bip32
35
+ # ECC backend
36
+ npm install tiny-secp256k1
37
+ ```
27
38
 
28
- You can find a [Web UI](https://bitcoincore.tech/apps/bitcoinjs-ui/index.html) that covers most of the `psbt.ts`, `transaction.ts` and `p2*.ts` APIs [here](https://bitcoincore.tech/apps/bitcoinjs-ui/index.html).
39
+ Requires Node.js >= 24.0.0.
29
40
 
30
- ## How can I contact the developers outside of Github?
31
- **Most of the time, this is not appropriate. Creating issues and pull requests in the open will help others with similar issues, so please try to use public issues and pull requests for communication.**
41
+ ## Performance
32
42
 
33
- That said, sometimes developers might be open to taking things off the record (ie. You want to share code that you don't want public to get help with it). In that case, please negotiate on the public issues as to where you will contact.
43
+ Benchmarked against `bitcoinjs-lib` v7.0.1 on Node.js v25.3.0 (Linux x64). The fork column uses the fastest backend for each scenario.
34
44
 
35
- We have created public rooms on IRC (`#bitcoinjs` on `libera.chat`) and Matrix (`#bitcoinjs-dev:matrix.org`). These two channels have been joined together in a Matrix "Space" which has the Matrix room AND an IRC bridge room that can converse with the IRC room. The "Space" is `#bitcoinjs-space:matrix.org`.
45
+ | Operation | Inputs | @btc-vision/bitcoin | bitcoinjs-lib | Improvement |
46
+ |-----------|-------:|--------------------:|-------------:|:-----------:|
47
+ | PSBT Creation | 100 | 2.13ms | 305ms | **143x** |
48
+ | PSBT Creation | 500 | 9.90ms | 7,020ms | **709x** |
49
+ | P2WPKH Sign | 100 | 40ms | 349ms | **8.6x** |
50
+ | P2WPKH Sign | 500 | 258ms | 7,710ms | **29.9x** |
51
+ | P2TR Sign | 100 | 22ms | 45ms | **2.1x** |
52
+ | P2TR Sign | 500 | 106ms | 575ms | **5.4x** |
53
+ | E2E P2WPKH | 100 | 44ms | 333ms | **7.6x** |
54
+ | E2E P2TR | 100 | 22ms | 56ms | **2.5x** |
55
+ | Parallel Sign (4 workers) | 500 | 106ms | 6,770ms | **63.6x** |
36
56
 
37
- Matrix and IRC both have functions for direct messaging, but IRC is not end to end encrypted, so Matrix is recommended for most communication. The official Matrix client maintained by the Matrix core team is called "Element" and can be downloaded here: https://element.io/download (Account creation is free on the matrix.org server, which is the default setting for Element.)
57
+ Parallel signing via `worker_threads` / Web Workers is exclusive to this fork. See [benchmark-compare/BENCHMARK.md](benchmark-compare/BENCHMARK.md) for detailed methodology and analysis.
38
58
 
39
- We used to have a Slack. It is dead. If you find it, no one will answer you most likely.
59
+ ```bash
60
+ cd benchmark-compare && npm install && npm run bench
61
+ ```
40
62
 
41
- No we will not make a Discord.
63
+ ## Quick Start
42
64
 
43
- ## Installation
44
- ``` bash
45
- npm install bitcoinjs-lib
46
- # optionally, install a key derivation library as well
47
- npm install ecpair bip32
48
- # ecpair is the ECPair class for single keys
49
- # bip32 is for generating HD keys
65
+ ### Initialize the ECC Library
66
+
67
+ The ECC library must be initialized before using Taproot, signing, or any elliptic curve operations.
68
+ Two backends are available:
69
+
70
+ **Noble (recommended for browsers)** -- pure JS, no WASM dependency:
71
+
72
+ ```typescript
73
+ import { initEccLib } from '@btc-vision/bitcoin';
74
+ import { createNobleBackend } from '@btc-vision/ecpair';
75
+
76
+ initEccLib(createNobleBackend());
77
+ ```
78
+
79
+ **tiny-secp256k1** -- WASM-based, faster in Node.js:
80
+
81
+ ```typescript
82
+ import { initEccLib } from '@btc-vision/bitcoin';
83
+ import { createLegacyBackend } from '@btc-vision/ecpair';
84
+ import * as tinysecp from 'tiny-secp256k1';
85
+
86
+ initEccLib(createLegacyBackend(tinysecp));
87
+ ```
88
+
89
+ ### Create a Key Pair
90
+
91
+ ```typescript
92
+ import { ECPairSigner, createNobleBackend } from '@btc-vision/ecpair';
93
+ import { networks } from '@btc-vision/bitcoin';
94
+
95
+ const backend = createNobleBackend();
96
+
97
+ // Random key pair
98
+ const keyPair = ECPairSigner.makeRandom(backend, networks.bitcoin);
99
+
100
+ // From WIF
101
+ const imported = ECPairSigner.fromWIF(
102
+ backend,
103
+ 'L2uPYXe17xSTqbCjZvL2DsyXPCbXspvcu5mHLDYUgzdUbZGSKrSr',
104
+ networks.bitcoin,
105
+ );
106
+ ```
107
+
108
+ ### Generate Addresses
109
+
110
+ ```typescript
111
+ import { payments, networks } from '@btc-vision/bitcoin';
112
+
113
+ // P2PKH (Legacy)
114
+ const { address: legacy } = payments.p2pkh({ pubkey: keyPair.publicKey });
115
+
116
+ // P2WPKH (Native SegWit)
117
+ const { address: segwit } = payments.p2wpkh({ pubkey: keyPair.publicKey });
118
+
119
+ // P2TR (Taproot) - requires ECC initialization
120
+ import { toXOnly } from '@btc-vision/bitcoin';
121
+ const { address: taproot } = payments.p2tr({
122
+ internalPubkey: toXOnly(keyPair.publicKey),
123
+ });
124
+
125
+ // P2SH-P2WPKH (Wrapped SegWit)
126
+ const { address: wrapped } = payments.p2sh({
127
+ redeem: payments.p2wpkh({ pubkey: keyPair.publicKey }),
128
+ });
129
+
130
+ // P2SH Multisig (2-of-3)
131
+ const { address: multisig } = payments.p2sh({
132
+ redeem: payments.p2ms({ m: 2, pubkeys: [pubkey1, pubkey2, pubkey3] }),
133
+ });
134
+ ```
135
+
136
+ ### Create and Sign a Transaction (PSBT)
137
+
138
+ ```typescript
139
+ import { Psbt, networks } from '@btc-vision/bitcoin';
140
+ import { fromHex } from '@btc-vision/bitcoin';
141
+ import type { Satoshi } from '@btc-vision/bitcoin';
142
+
143
+ const psbt = new Psbt({ network: networks.bitcoin });
144
+
145
+ // Add input
146
+ psbt.addInput({
147
+ hash: '7d067b4a697a09d2c3cff7d4d9506c9955e93bff41bf82d439da7d030382bc3e',
148
+ index: 0,
149
+ nonWitnessUtxo: fromHex('0200000001...'),
150
+ sighashType: 1,
151
+ });
152
+
153
+ // Add output (values are bigint)
154
+ psbt.addOutput({
155
+ address: '1KRMKfeZcmosxALVYESdPNez1AP1mEtywp',
156
+ value: 80_000n as Satoshi,
157
+ });
158
+
159
+ // Sign, finalize, and extract
160
+ psbt.signInput(0, keyPair);
161
+ psbt.finalizeAllInputs();
162
+ const txHex = psbt.extractTransaction().toHex();
163
+ ```
164
+
165
+ ### Async Signing
166
+
167
+ ```typescript
168
+ await psbt.signInputAsync(0, keyPair);
169
+ await psbt.signAllInputsAsync(keyPair);
170
+ ```
171
+
172
+ ### Parse a Transaction
173
+
174
+ ```typescript
175
+ import { Transaction } from '@btc-vision/bitcoin';
176
+
177
+ const tx = Transaction.fromHex('0200000001...');
178
+ console.log(tx.version); // 2
179
+ console.log(tx.ins.length); // number of inputs
180
+ console.log(tx.outs.length); // number of outputs
181
+ console.log(tx.toHex()); // round-trip back to hex
50
182
  ```
51
183
 
52
- Previous versions of the library included classes for key management (ECPair, HDNode(->"bip32")) but now these have been separated into different libraries. This lowers the bundle size significantly if you don't need to perform any crypto functions (converting private to public keys and deriving HD keys).
184
+ ### Decode and Encode Addresses
53
185
 
54
- Typically we support the [Node Maintenance LTS version](https://github.com/nodejs/Release). TypeScript target will be set
55
- to the ECMAScript version in which all features are fully supported by current Active Node LTS.
56
- However, depending on adoption among other environments (browsers etc.) we may keep the target back a year or two.
57
- If in doubt, see the [main_ci.yml](.github/workflows/main_ci.yml) for what versions are used by our continuous integration tests.
186
+ ```typescript
187
+ import { address, networks } from '@btc-vision/bitcoin';
58
188
 
59
- **WARNING**: We presently don't provide any tooling to verify that the release on `npm` matches GitHub. As such, you should verify anything downloaded by `npm` against your own verified copy.
189
+ // Decode any address to its output script
190
+ const outputScript = address.toOutputScript(
191
+ 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
192
+ networks.bitcoin,
193
+ );
60
194
 
195
+ // Convert output script back to address
196
+ const addr = address.fromOutputScript(outputScript, networks.bitcoin);
197
+
198
+ // Low-level Base58Check
199
+ const { hash, version } = address.fromBase58Check('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH');
200
+ const encoded = address.toBase58Check(hash, version);
201
+
202
+ // Low-level Bech32
203
+ const decoded = address.fromBech32('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4');
204
+ const bech32Addr = address.toBech32(decoded.data, decoded.version, 'bc');
205
+ ```
61
206
 
62
- ## Usage
63
- Crypto is hard.
207
+ ### Parallel Signing with Workers
64
208
 
65
- When working with private keys, the random number generator is fundamentally one of the most important parts of any software you write.
66
- For random number generation, we *default* to the [`randombytes`](https://github.com/crypto-browserify/randombytes) module, which uses [`window.crypto.getRandomValues`](https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues) in the browser, or Node js' [`crypto.randomBytes`](https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback), depending on your build system.
67
- Although this default is ~OK, there is no simple way to detect if the underlying RNG provided is good enough, or if it is **catastrophically bad**.
68
- You should always verify this yourself to your own standards.
209
+ For high-throughput signing across many inputs, use the worker pool.
69
210
 
70
- This library uses [tiny-secp256k1](https://github.com/bitcoinjs/tiny-secp256k1), which uses [RFC6979](https://tools.ietf.org/html/rfc6979) to help prevent `k` re-use and exploitation.
71
- Unfortunately, this isn't a silver bullet.
72
- Often, Javascript itself is working against us by bypassing these counter-measures.
211
+ #### Sign a PSBT in parallel
73
212
 
74
- Problems in [`Buffer (UInt8Array)`](https://github.com/feross/buffer), for example, can trivially result in **catastrophic fund loss** without any warning.
75
- It can do this through undermining your random number generation, accidentally producing a [duplicate `k` value](https://www.nilsschneider.net/2013/01/28/recovering-bitcoin-private-keys.html), sending Bitcoin to a malformed output script, or any of a million different ways.
76
- Running tests in your target environment is important and a recommended step to verify continuously.
213
+ `signPsbtParallel` analyzes inputs, distributes signing across workers, and applies signatures back to the PSBT:
77
214
 
78
- Finally, **adhere to best practice**.
79
- We are not an authoritative source of best practice, but, at the very least:
215
+ ```typescript
216
+ import { Psbt, networks } from '@btc-vision/bitcoin';
217
+ import { signPsbtParallel, createSigningPool } from '@btc-vision/bitcoin/workers';
80
218
 
81
- * [Don't reuse addresses](https://en.bitcoin.it/wiki/Address_reuse).
82
- * Don't share BIP32 extended public keys ('xpubs'). [They are a liability](https://bitcoin.stackexchange.com/questions/56916/derivation-of-parent-private-key-from-non-hardened-child), and it only takes 1 misplaced private key (or a buggy implementation!) and you are vulnerable to **catastrophic fund loss**.
83
- * [Don't use `Math.random`](https://security.stackexchange.com/questions/181580/why-is-math-random-not-designed-to-be-cryptographically-secure) - in any way - don't.
84
- * Enforce that users always verify (manually) a freshly-decoded human-readable version of their intended transaction before broadcast.
85
- * [Don't *ask* users to generate mnemonics](https://en.bitcoin.it/wiki/Brainwallet#cite_note-1), or 'brain wallets', humans are terrible random number generators.
86
- * Lastly, if you can, use [Typescript](https://www.typescriptlang.org/) or similar.
219
+ // Create a platform-appropriate pool (Node.js worker_threads or Web Workers)
220
+ const pool = await createSigningPool({ workerCount: 4 });
221
+ pool.preserveWorkers();
87
222
 
223
+ // Build your PSBT as usual
224
+ const psbt = new Psbt({ network: networks.bitcoin });
225
+ psbt.addInput({ /* ... */ });
226
+ psbt.addInput({ /* ... */ });
227
+ psbt.addOutput({ /* ... */ });
88
228
 
89
- ### Browser
90
- The recommended method of using `bitcoinjs-lib` in your browser is through [browserify](http://browserify.org/).
229
+ // Sign all signable inputs in parallel — replaces signAllInputs / signAllInputsAsync
230
+ const result = await signPsbtParallel(psbt, keyPair, pool);
91
231
 
92
- If you'd like to use a different (more modern) build tool than `browserify`, you can compile just this library and its dependencies into a single JavaScript file:
232
+ if (result.success) {
233
+ console.log(`Signed ${result.signatures.size} inputs in ${result.durationMs}ms`);
234
+ psbt.finalizeAllInputs();
235
+ const tx = psbt.extractTransaction();
236
+ }
93
237
 
94
- ```sh
95
- $ npm install bitcoinjs-lib browserify
96
- $ npx browserify --standalone bitcoin - -o bitcoinjs-lib.js <<<"module.exports = require('bitcoinjs-lib');"
238
+ // Shut down when done (or keep the pool alive for future PSBTs)
239
+ await pool.shutdown();
97
240
  ```
98
241
 
99
- Which you can then import as an ESM module:
242
+ You can also pass a config object instead of a pool instance. A temporary pool will be created and
243
+ destroyed automatically:
244
+
245
+ ```typescript
246
+ const result = await signPsbtParallel(psbt, keyPair, { workerCount: 4 });
247
+ ```
248
+
249
+ #### Low-level batch signing
250
+
251
+ For manual control over sighash computation and task construction:
252
+
253
+ ```typescript
254
+ import { createSigningPool, SignatureType } from '@btc-vision/bitcoin/workers';
255
+
256
+ const pool = await createSigningPool({ workerCount: 4 });
257
+ pool.preserveWorkers();
258
+
259
+ const tasks = [
260
+ {
261
+ taskId: 'input-0',
262
+ inputIndex: 0,
263
+ hash: sighash0,
264
+ signatureType: SignatureType.ECDSA,
265
+ sighashType: 0x01,
266
+ },
267
+ {
268
+ taskId: 'input-1',
269
+ inputIndex: 1,
270
+ hash: sighash1,
271
+ signatureType: SignatureType.Schnorr,
272
+ sighashType: 0x00,
273
+ },
274
+ ];
275
+
276
+ const result = await pool.signBatch(tasks, keyPair);
277
+ if (result.success) {
278
+ console.log(`Signed ${result.signatures.size} inputs in ${result.durationMs}ms`);
279
+ }
280
+
281
+ await pool.shutdown();
282
+ ```
283
+
284
+ ## API Reference
285
+
286
+ ### Exports
287
+
288
+ The library provides granular sub-path exports for tree-shaking:
289
+
290
+ ```typescript
291
+ import { ... } from '@btc-vision/bitcoin'; // Full API
292
+ import { ... } from '@btc-vision/bitcoin/address'; // Address encoding/decoding
293
+ import { ... } from '@btc-vision/bitcoin/script'; // Script compile/decompile
294
+ import { ... } from '@btc-vision/bitcoin/crypto'; // Hash functions
295
+ import { ... } from '@btc-vision/bitcoin/transaction';// Transaction class
296
+ import { ... } from '@btc-vision/bitcoin/psbt'; // PSBT classes
297
+ import { ... } from '@btc-vision/bitcoin/networks'; // Network definitions
298
+ import { ... } from '@btc-vision/bitcoin/payments'; // Payment creators
299
+ import { ... } from '@btc-vision/bitcoin/io'; // Binary I/O utilities
300
+ import { ... } from '@btc-vision/bitcoin/ecc'; // ECC context
301
+ import { ... } from '@btc-vision/bitcoin/types'; // Type definitions & guards
302
+ import { ... } from '@btc-vision/bitcoin/errors'; // Error classes
303
+ import { ... } from '@btc-vision/bitcoin/workers'; // Parallel signing
304
+ ```
305
+
306
+ ### Branded Types
307
+
308
+ Values use branded types to prevent accidental misuse:
309
+
310
+ ```typescript
311
+ import type {
312
+ Bytes32, // 32-byte Uint8Array (tx hashes, witness programs)
313
+ Bytes20, // 20-byte Uint8Array (pubkey hashes)
314
+ PublicKey, // Compressed/uncompressed public key
315
+ XOnlyPublicKey, // 32-byte x-only pubkey (Taproot)
316
+ PrivateKey, // 32-byte private key
317
+ Satoshi, // bigint value (0 to 21e14)
318
+ Signature, // DER-encoded ECDSA signature
319
+ SchnorrSignature, // 64-byte Schnorr signature
320
+ Script, // Compiled script bytes
321
+ } from '@btc-vision/bitcoin';
322
+
323
+ // Type guards
324
+ import {
325
+ isBytes32, isBytes20, isPoint, isSatoshi,
326
+ isPrivateKey, isSignature, isSchnorrSignature,
327
+ isXOnlyPublicKey, isScript,
328
+ } from '@btc-vision/bitcoin';
329
+
330
+ // Conversion helpers (throw on invalid input)
331
+ import { toBytes32, toBytes20, toSatoshi } from '@btc-vision/bitcoin';
332
+ ```
333
+
334
+ ### Payment Types
335
+
336
+ | Type | Function | Class | Description |
337
+ |------|----------|-------|-------------|
338
+ | P2PK | `p2pk()` | `P2PK` | Pay-to-Public-Key |
339
+ | P2PKH | `p2pkh()` | `P2PKH` | Pay-to-Public-Key-Hash (Legacy) |
340
+ | P2SH | `p2sh()` | `P2SH` | Pay-to-Script-Hash |
341
+ | P2MS | `p2ms()` | `P2MS` | Pay-to-Multisig |
342
+ | P2WPKH | `p2wpkh()` | `P2WPKH` | SegWit v0 Public Key Hash |
343
+ | P2WSH | `p2wsh()` | `P2WSH` | SegWit v0 Script Hash |
344
+ | P2TR | `p2tr()` | `P2TR` | Taproot (SegWit v1) |
345
+ | P2OP | `p2op()` | `P2OP` | OPNet (SegWit v16) |
346
+ | Embed | `p2data()` | `Embed` | OP_RETURN data |
347
+
348
+ ### Network Support
349
+
350
+ | Network | Constant | Bech32 Prefix |
351
+ |---------|----------|---------------|
352
+ | Bitcoin Mainnet | `networks.bitcoin` | `bc` |
353
+ | Bitcoin Testnet | `networks.testnet` | `tb` |
354
+ | Bitcoin Regtest | `networks.regtest` | `bcrt` |
355
+ | Dogecoin | `networks.dogecoin` | - |
356
+ | Litecoin | `networks.litecoin` | `ltc` |
357
+ | Bitcoin Cash | `networks.bitcoinCash` | `bitcoincash` |
358
+ | Dash | `networks.dash` | - |
359
+
360
+ ### Error Handling
361
+
362
+ All errors extend `BitcoinError`:
363
+
364
+ ```typescript
365
+ import {
366
+ BitcoinError, // Base class
367
+ ValidationError, // Input validation failures
368
+ InvalidInputError, // Invalid transaction input
369
+ InvalidOutputError,// Invalid transaction output
370
+ ScriptError, // Script operation failures
371
+ PsbtError, // PSBT operation failures
372
+ EccError, // ECC library not initialized
373
+ AddressError, // Address encoding/decoding failures
374
+ SignatureError, // Signature operation failures
375
+ } from '@btc-vision/bitcoin';
376
+
377
+ try {
378
+ psbt.signInput(0, signer);
379
+ } catch (err) {
380
+ if (err instanceof PsbtError) {
381
+ // Handle PSBT-specific error
382
+ }
383
+ }
384
+ ```
385
+
386
+ ### Utility Functions
387
+
388
+ ```typescript
389
+ import {
390
+ toHex, fromHex, isHex, // Hex encoding
391
+ concat, equals, compare, // Buffer operations
392
+ clone, reverse, reverseCopy, // Buffer manipulation
393
+ alloc, xor, isZero, // Buffer utilities
394
+ fromUtf8, toUtf8, // UTF-8 conversion
395
+ toXOnly, // Compress pubkey to x-only (32 bytes)
396
+ decompressPublicKey, // Decompress compressed pubkey
397
+ } from '@btc-vision/bitcoin';
398
+ ```
399
+
400
+ ### Crypto Functions
401
+
402
+ ```typescript
403
+ import { sha256, sha1, ripemd160, hash160, hash256, taggedHash } from '@btc-vision/bitcoin';
404
+
405
+ const h = hash160(publicKey); // RIPEMD160(SHA256(data))
406
+ const d = hash256(data); // SHA256(SHA256(data))
407
+ const t = taggedHash('TapLeaf', data); // BIP340 tagged hash
408
+ ```
409
+
410
+ ## Browser Usage
411
+
412
+ The library ships with a browser-optimized build via the `browser` conditional export. Bundlers that support the `exports` field in `package.json` (Vite, Webpack 5+, esbuild) will automatically resolve to the browser build.
413
+
414
+ For browser environments, use `createNobleBackend()` -- it is pure JavaScript with no WASM dependency. The `tiny-secp256k1` backend requires WebAssembly support and is better suited for Node.js.
415
+
416
+ ## React Native
417
+
418
+ The library works in React Native with Hermes 0.76+ (BigInt and `crypto.getRandomValues()` required). The core library (PSBT, transactions, addresses, crypto) is pure JS and runs on the main thread. Parallel signing uses `react-native-worklets` when available, otherwise falls back to sequential execution automatically.
419
+
420
+ ### Metro Configuration
421
+
422
+ Add `react-native` to the condition names in your `metro.config.js`:
100
423
 
101
424
  ```javascript
102
- <script type="module">import "/scripts/bitcoinjs-lib.js"</script>
103
- ````
104
-
105
- #### Using Taproot:
106
- When utilizing Taproot features with bitcoinjs-lib, you may need to include an additional ECC (Elliptic Curve Cryptography) library. The commonly used `tiny-secp256k1` library, however, might lead to compatibility issues due to its reliance on WASM (WebAssembly). The following alternatives may be used instead, though they may be significantly slower for high volume of signing and pubkey deriving operations.
107
-
108
- #### Alternatives for ECC Library:
109
- 1. `@bitcoinjs-lib/tiny-secp256k1-asmjs`
110
- A version of `tiny-secp256k1` compiled to ASM.js directly from the WASM version, potentially better supported in browsers. This is the slowest option.
111
- 2. `@bitcoinerlab/secp256k1`
112
- Another alternative library for ECC functionality. This requires access to the global `BigInt` primitive.
113
- For advantages and detailed comparison of these libraries, visit: [tiny-secp256k1 GitHub page](https://github.com/bitcoinjs/tiny-secp256k1).
114
-
115
- **NOTE**: We use Node Maintenance LTS features, if you need strict ES5, use [`--transform babelify`](https://github.com/babel/babelify) in conjunction with your `browserify` step (using an [`es2015`](https://babeljs.io/docs/plugins/preset-es2015/) preset).
116
-
117
- **WARNING**: iOS devices have [problems](https://github.com/feross/buffer/issues/136), use at least [buffer@5.0.5](https://github.com/feross/buffer/pull/155) or greater, and enforce the test suites (for `Buffer`, and any other dependency) pass before use.
118
-
119
- ### Typescript or VSCode users
120
- Type declarations for Typescript are included in this library. Normal installation should include all the needed type information.
121
-
122
- ## Examples
123
- The below examples are implemented as integration tests, they should be very easy to understand.
124
- Otherwise, pull requests are appreciated.
125
- Some examples interact (via HTTPS) with a 3rd Party Blockchain Provider (3PBP).
126
-
127
-
128
- - [Taproot Key Spend](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/taproot.spec.ts)
129
- - [Generate a random address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
130
- - [Import an address via WIF](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
131
- - [Generate a 2-of-3 P2SH multisig address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
132
- - [Generate a SegWit address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
133
- - [Generate a SegWit P2SH address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
134
- - [Generate a SegWit 3-of-4 multisig address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
135
- - [Generate a SegWit 2-of-2 P2SH multisig address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
136
- - [Support the retrieval of transactions for an address (3rd party blockchain)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
137
- - [Generate a Testnet address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
138
- - [Generate a Litecoin address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
139
- - [Create a 1-to-1 Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
140
- - [Create (and broadcast via 3PBP) a typical Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
141
- - [Create (and broadcast via 3PBP) a Transaction with an OP\_RETURN output](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
142
- - [Create (and broadcast via 3PBP) a Transaction with a 2-of-4 P2SH(multisig) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
143
- - [Create (and broadcast via 3PBP) a Transaction with a SegWit P2SH(P2WPKH) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
144
- - [Create (and broadcast via 3PBP) a Transaction with a SegWit P2WPKH input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
145
- - [Create (and broadcast via 3PBP) a Transaction with a SegWit P2PK input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
146
- - [Create (and broadcast via 3PBP) a Transaction with a SegWit 3-of-4 P2SH(P2WSH(multisig)) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
147
- - [Create (and broadcast via 3PBP) a Transaction and sign with an HDSigner interface (bip32)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
148
- - [Import a BIP32 testnet xpriv and export to WIF](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
149
- - [Export a BIP32 xpriv, then import it](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
150
- - [Export a BIP32 xpub](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
151
- - [Create a BIP32, bitcoin, account 0, external address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
152
- - [Create a BIP44, bitcoin, account 0, external address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
153
- - [Create a BIP49, bitcoin testnet, account 0, external address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
154
- - [Use BIP39 to generate BIP32 addresses](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
155
- - [Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the past)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.spec.ts)
156
- - [Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.spec.ts)
157
- - [Create (and broadcast via 3PBP) a Transaction where Alice and Bob can redeem the output at any time](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.spec.ts)
158
- - [Create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.spec.ts)
159
- - [Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future) (simple CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.spec.ts)
160
- - [Create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry (simple CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.spec.ts)
161
- - [Create (and broadcast via 3PBP) a Transaction where Bob and Charles can send (complex CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.spec.ts)
162
- - [Create (and broadcast via 3PBP) a Transaction where Alice (mediator) and Bob can send after 2 blocks (complex CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.spec.ts)
163
- - [Create (and broadcast via 3PBP) a Transaction where Alice (mediator) can send after 5 blocks (complex CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.spec.ts)
164
-
165
- If you have a use case that you feel could be listed here, please [ask for it](https://github.com/bitcoinjs/bitcoinjs-lib/issues/new)!
425
+ const config = {
426
+ resolver: {
427
+ unstable_conditionNames: ['react-native', 'import', 'default'],
428
+ },
429
+ };
430
+ ```
166
431
 
432
+ ### Usage
167
433
 
168
- ## Contributing
169
- See [CONTRIBUTING.md](CONTRIBUTING.md).
434
+ Usage is identical to Node.js and browsers:
170
435
 
436
+ ```typescript
437
+ import { initEccLib, Psbt, networks } from '@btc-vision/bitcoin';
438
+ import { createNobleBackend, ECPairSigner } from '@btc-vision/ecpair';
171
439
 
172
- ### Running the test suite
440
+ // Initialize ECC (pure JS Noble backend — no WASM needed)
441
+ const backend = createNobleBackend();
442
+ initEccLib(backend);
173
443
 
174
- ``` bash
175
- npm test
176
- npm run-script coverage
444
+ // Create key pair, build PSBT, sign — same API as Node.js/browser
445
+ const keyPair = ECPairSigner.fromWIF(backend, wif, networks.bitcoin);
446
+ const psbt = new Psbt({ network: networks.bitcoin });
447
+ // ... add inputs/outputs ...
448
+ psbt.signAllInputs(keyPair);
177
449
  ```
178
450
 
179
- ## Complementing Libraries
180
- - [BIP21](https://github.com/bitcoinjs/bip21) - A BIP21 compatible URL encoding library
181
- - [BIP38](https://github.com/bitcoinjs/bip38) - Passphrase-protected private keys
182
- - [BIP39](https://github.com/bitcoinjs/bip39) - Mnemonic generation for deterministic keys
183
- - [BIP32-Utils](https://github.com/bitcoinjs/bip32-utils) - A set of utilities for working with BIP32
184
- - [BIP66](https://github.com/bitcoinjs/bip66) - Strict DER signature decoding
185
- - [BIP68](https://github.com/bitcoinjs/bip68) - Relative lock-time encoding library
186
- - [BIP69](https://github.com/bitcoinjs/bip69) - Lexicographical Indexing of Transaction Inputs and Outputs
187
- - [Base58](https://github.com/cryptocoinjs/bs58) - Base58 encoding/decoding
188
- - [Base58 Check](https://github.com/bitcoinjs/bs58check) - Base58 check encoding/decoding
189
- - [Bech32](https://github.com/bitcoinjs/bech32) - A BIP173/BIP350 compliant Bech32/Bech32m encoding library
190
- - [coinselect](https://github.com/bitcoinjs/coinselect) - A fee-optimizing, transaction input selection module for bitcoinjs-lib.
191
- - [merkle-lib](https://github.com/bitcoinjs/merkle-lib) - A performance conscious library for merkle root and tree calculations.
192
- - [minimaldata](https://github.com/bitcoinjs/minimaldata) - A module to check bitcoin policy: SCRIPT_VERIFY_MINIMALDATA
451
+ ### Parallel Signing
452
+
453
+ `signPsbtParallel()` and `createSigningPool()` support true parallel signing in React Native via [`react-native-worklets`](https://github.com/margelo/react-native-worklets) (Software Mansion, v0.7+). Each worklet runtime gets its own ECC module instance and signing tasks are distributed round-robin across runtimes.
454
+
455
+ Install the optional peer dependency to enable parallel signing:
456
+
457
+ ```bash
458
+ npm install react-native-worklets
459
+ ```
460
+
461
+ Usage is identical to Node.js/browser `createSigningPool()` detects worklets automatically:
462
+
463
+ ```typescript
464
+ import { signPsbtParallel, createSigningPool } from '@btc-vision/bitcoin/workers';
465
+
466
+ // Automatically uses WorkletSigningPool if react-native-worklets is installed,
467
+ // otherwise falls back to SequentialSigningPool (main-thread, one-by-one)
468
+ const pool = await createSigningPool({ workerCount: 4 });
469
+ pool.preserveWorkers();
470
+
471
+ const result = await signPsbtParallel(psbt, keyPair, pool);
472
+ await pool.shutdown();
473
+ ```
474
+
475
+ You can also import `WorkletSigningPool` directly for explicit control:
476
+
477
+ ```typescript
478
+ import { WorkletSigningPool } from '@btc-vision/bitcoin/workers';
479
+
480
+ const pool = WorkletSigningPool.getInstance({ workerCount: 4 });
481
+ pool.preserveWorkers();
482
+ await pool.initialize();
483
+
484
+ const result = await pool.signBatch(tasks, keyPair);
485
+ await pool.shutdown();
486
+ ```
487
+
488
+ If `react-native-worklets` is not installed, `createSigningPool()` returns a `SequentialSigningPool` that signs inputs one-by-one on the main thread using the same API.
489
+
490
+ ### Requirements
491
+
492
+ - **Hermes 0.76+** (React Native 0.76+) for BigInt and `crypto.getRandomValues()` support
493
+ - **`react-native-worklets` >= 0.7.0** (optional) for parallel signing across worklet runtimes
494
+ - `react-native-quick-crypto` is **not** required — the core library uses `@noble/hashes` and `@noble/curves` (pure JS)
495
+ - A future `@btc-vision/react-native-secp256k1` Nitro Module would provide native C++ performance via `initEccLib(createNativeBackend())`
496
+
497
+ ## Running Tests
498
+
499
+ ```bash
500
+ npm test # Full suite (lint + build + test)
501
+ npm run unit # Unit tests only
502
+ npm run integration # Integration tests
503
+ npm run test:browser # Browser tests (Playwright)
504
+ npm run bench # Benchmarks
505
+ ```
506
+
507
+ ## Contributing
508
+
509
+ 1. Fork the repository
510
+ 2. Create a feature branch
511
+ 3. Make your changes
512
+ 4. Run tests: `npm test`
513
+ 5. Submit a pull request
193
514
 
515
+ ## License
194
516
 
195
- ## Alternatives
196
- - [BCoin](https://github.com/indutny/bcoin)
197
- - [Bitcore](https://github.com/bitpay/bitcore)
198
- - [Cryptocoin](https://github.com/cryptocoinjs/cryptocoin)
517
+ [MIT](LICENSE)
199
518
 
519
+ ## Links
200
520
 
201
- ## LICENSE [MIT](LICENSE)
521
+ - [GitHub](https://github.com/btc-vision/bitcoin)
522
+ - [npm](https://www.npmjs.com/package/@btc-vision/bitcoin)
523
+ - [API Documentation](https://bitcoinjs.github.io/bitcoinjs-lib/)