@btc-vision/bitcoin 7.0.0-alpha.0 → 7.0.0-alpha.10

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 (369) hide show
  1. package/README.md +455 -155
  2. package/browser/address.d.ts +6 -2
  3. package/browser/address.d.ts.map +1 -1
  4. package/browser/block.d.ts.map +1 -1
  5. package/browser/branded.d.ts +3 -14
  6. package/browser/branded.d.ts.map +1 -1
  7. package/browser/chunks/psbt-parallel-BBFlkmiv.js +10717 -0
  8. package/browser/crypto.d.ts +1 -1
  9. package/browser/ecc/context.d.ts +25 -24
  10. package/browser/ecc/context.d.ts.map +1 -1
  11. package/browser/ecc/index.d.ts +1 -1
  12. package/browser/ecc/index.d.ts.map +1 -1
  13. package/browser/ecc/types.d.ts +10 -123
  14. package/browser/ecc/types.d.ts.map +1 -1
  15. package/browser/env.d.ts +13 -0
  16. package/browser/env.d.ts.map +1 -0
  17. package/browser/index.d.ts +7 -7
  18. package/browser/index.d.ts.map +1 -1
  19. package/browser/index.js +2497 -11686
  20. package/browser/io/BinaryReader.d.ts +15 -15
  21. package/browser/io/BinaryReader.d.ts.map +1 -1
  22. package/browser/io/BinaryWriter.d.ts +17 -17
  23. package/browser/io/BinaryWriter.d.ts.map +1 -1
  24. package/browser/io/hex.d.ts.map +1 -1
  25. package/browser/io/index.d.ts +0 -1
  26. package/browser/io/index.d.ts.map +1 -1
  27. package/browser/opcodes.d.ts +11 -0
  28. package/browser/opcodes.d.ts.map +1 -1
  29. package/browser/payments/bip341.d.ts +1 -1
  30. package/browser/payments/bip341.d.ts.map +1 -1
  31. package/browser/payments/embed.d.ts +1 -1
  32. package/browser/payments/embed.d.ts.map +1 -1
  33. package/browser/payments/p2ms.d.ts.map +1 -1
  34. package/browser/payments/p2op.d.ts +1 -1
  35. package/browser/payments/p2op.d.ts.map +1 -1
  36. package/browser/payments/p2pk.d.ts +1 -1
  37. package/browser/payments/p2pk.d.ts.map +1 -1
  38. package/browser/payments/p2pkh.d.ts +1 -1
  39. package/browser/payments/p2pkh.d.ts.map +1 -1
  40. package/browser/payments/p2sh.d.ts.map +1 -1
  41. package/browser/payments/p2tr.d.ts +2 -2
  42. package/browser/payments/p2tr.d.ts.map +1 -1
  43. package/browser/payments/p2wpkh.d.ts +1 -1
  44. package/browser/payments/p2wpkh.d.ts.map +1 -1
  45. package/browser/payments/p2wsh.d.ts.map +1 -1
  46. package/browser/payments/types.d.ts +1 -1
  47. package/browser/payments/types.d.ts.map +1 -1
  48. package/browser/psbt/PsbtCache.d.ts +54 -0
  49. package/browser/psbt/PsbtCache.d.ts.map +1 -0
  50. package/browser/psbt/PsbtFinalizer.d.ts +21 -0
  51. package/browser/psbt/PsbtFinalizer.d.ts.map +1 -0
  52. package/browser/psbt/PsbtSigner.d.ts +32 -0
  53. package/browser/psbt/PsbtSigner.d.ts.map +1 -0
  54. package/browser/psbt/PsbtTransaction.d.ts +25 -0
  55. package/browser/psbt/PsbtTransaction.d.ts.map +1 -0
  56. package/browser/psbt/bip371.d.ts.map +1 -1
  57. package/browser/psbt/types.d.ts +5 -71
  58. package/browser/psbt/types.d.ts.map +1 -1
  59. package/browser/psbt/validation.d.ts +1 -1
  60. package/browser/psbt/validation.d.ts.map +1 -1
  61. package/browser/psbt.d.ts +26 -40
  62. package/browser/psbt.d.ts.map +1 -1
  63. package/browser/script.d.ts.map +1 -1
  64. package/browser/transaction.d.ts +4 -4
  65. package/browser/transaction.d.ts.map +1 -1
  66. package/browser/types.d.ts +5 -3
  67. package/browser/types.d.ts.map +1 -1
  68. package/browser/workers/WorkerSigningPool.d.ts +24 -17
  69. package/browser/workers/WorkerSigningPool.d.ts.map +1 -1
  70. package/browser/workers/WorkerSigningPool.node.d.ts +19 -12
  71. package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -1
  72. package/browser/workers/WorkerSigningPool.sequential.d.ts +67 -0
  73. package/browser/workers/WorkerSigningPool.sequential.d.ts.map +1 -0
  74. package/browser/workers/WorkerSigningPool.worklet.d.ts +64 -0
  75. package/browser/workers/WorkerSigningPool.worklet.d.ts.map +1 -0
  76. package/browser/workers/index.browser.d.ts +16 -0
  77. package/browser/workers/index.browser.d.ts.map +1 -0
  78. package/browser/workers/index.d.ts +4 -64
  79. package/browser/workers/index.d.ts.map +1 -1
  80. package/browser/workers/index.js +28 -0
  81. package/browser/workers/index.node.d.ts +17 -0
  82. package/browser/workers/index.node.d.ts.map +1 -0
  83. package/browser/workers/index.react-native.d.ts +28 -0
  84. package/browser/workers/index.react-native.d.ts.map +1 -0
  85. package/browser/workers/index.shared.d.ts +15 -0
  86. package/browser/workers/index.shared.d.ts.map +1 -0
  87. package/browser/workers/psbt-parallel.d.ts +2 -3
  88. package/browser/workers/psbt-parallel.d.ts.map +1 -1
  89. package/browser/workers/types.d.ts +17 -0
  90. package/browser/workers/types.d.ts.map +1 -1
  91. package/build/address.d.ts +6 -2
  92. package/build/address.d.ts.map +1 -1
  93. package/build/address.js +32 -19
  94. package/build/address.js.map +1 -1
  95. package/build/bech32utils.js.map +1 -1
  96. package/build/block.d.ts.map +1 -1
  97. package/build/block.js +2 -4
  98. package/build/block.js.map +1 -1
  99. package/build/branded.d.ts +3 -14
  100. package/build/branded.d.ts.map +1 -1
  101. package/build/branded.js +0 -5
  102. package/build/branded.js.map +1 -1
  103. package/build/crypto.d.ts +1 -1
  104. package/build/ecc/context.d.ts +25 -24
  105. package/build/ecc/context.d.ts.map +1 -1
  106. package/build/ecc/context.js +29 -101
  107. package/build/ecc/context.js.map +1 -1
  108. package/build/ecc/index.d.ts +1 -1
  109. package/build/ecc/index.d.ts.map +1 -1
  110. package/build/ecc/types.d.ts +7 -126
  111. package/build/ecc/types.d.ts.map +1 -1
  112. package/build/ecc/types.js +4 -1
  113. package/build/ecc/types.js.map +1 -1
  114. package/build/env.d.ts +13 -0
  115. package/build/env.d.ts.map +1 -0
  116. package/build/env.js +198 -0
  117. package/build/env.js.map +1 -0
  118. package/build/index.d.ts +8 -7
  119. package/build/index.d.ts.map +1 -1
  120. package/build/index.js +9 -7
  121. package/build/index.js.map +1 -1
  122. package/build/io/BinaryReader.d.ts +15 -15
  123. package/build/io/BinaryReader.d.ts.map +1 -1
  124. package/build/io/BinaryReader.js +17 -17
  125. package/build/io/BinaryReader.js.map +1 -1
  126. package/build/io/BinaryWriter.d.ts +17 -17
  127. package/build/io/BinaryWriter.d.ts.map +1 -1
  128. package/build/io/BinaryWriter.js +39 -39
  129. package/build/io/BinaryWriter.js.map +1 -1
  130. package/build/io/hex.d.ts.map +1 -1
  131. package/build/io/hex.js +2 -1
  132. package/build/io/hex.js.map +1 -1
  133. package/build/io/index.d.ts +0 -1
  134. package/build/io/index.d.ts.map +1 -1
  135. package/build/io/index.js +0 -2
  136. package/build/io/index.js.map +1 -1
  137. package/build/opcodes.d.ts +11 -0
  138. package/build/opcodes.d.ts.map +1 -1
  139. package/build/opcodes.js +19 -4
  140. package/build/opcodes.js.map +1 -1
  141. package/build/payments/bip341.d.ts +1 -2
  142. package/build/payments/bip341.d.ts.map +1 -1
  143. package/build/payments/bip341.js +1 -2
  144. package/build/payments/bip341.js.map +1 -1
  145. package/build/payments/embed.d.ts +1 -1
  146. package/build/payments/embed.d.ts.map +1 -1
  147. package/build/payments/embed.js +14 -14
  148. package/build/payments/embed.js.map +1 -1
  149. package/build/payments/p2ms.d.ts.map +1 -1
  150. package/build/payments/p2ms.js +21 -21
  151. package/build/payments/p2ms.js.map +1 -1
  152. package/build/payments/p2op.d.ts +1 -1
  153. package/build/payments/p2op.d.ts.map +1 -1
  154. package/build/payments/p2op.js +18 -18
  155. package/build/payments/p2op.js.map +1 -1
  156. package/build/payments/p2pk.d.ts +1 -1
  157. package/build/payments/p2pk.d.ts.map +1 -1
  158. package/build/payments/p2pk.js +17 -17
  159. package/build/payments/p2pk.js.map +1 -1
  160. package/build/payments/p2pkh.d.ts +1 -1
  161. package/build/payments/p2pkh.d.ts.map +1 -1
  162. package/build/payments/p2pkh.js +20 -20
  163. package/build/payments/p2pkh.js.map +1 -1
  164. package/build/payments/p2sh.d.ts.map +1 -1
  165. package/build/payments/p2sh.js +22 -20
  166. package/build/payments/p2sh.js.map +1 -1
  167. package/build/payments/p2tr.d.ts +2 -2
  168. package/build/payments/p2tr.d.ts.map +1 -1
  169. package/build/payments/p2tr.js +25 -26
  170. package/build/payments/p2tr.js.map +1 -1
  171. package/build/payments/p2wpkh.d.ts +1 -1
  172. package/build/payments/p2wpkh.d.ts.map +1 -1
  173. package/build/payments/p2wpkh.js +20 -20
  174. package/build/payments/p2wpkh.js.map +1 -1
  175. package/build/payments/p2wsh.d.ts.map +1 -1
  176. package/build/payments/p2wsh.js +22 -22
  177. package/build/payments/p2wsh.js.map +1 -1
  178. package/build/payments/types.d.ts +1 -1
  179. package/build/payments/types.d.ts.map +1 -1
  180. package/build/psbt/PsbtCache.d.ts +54 -0
  181. package/build/psbt/PsbtCache.d.ts.map +1 -0
  182. package/build/psbt/PsbtCache.js +249 -0
  183. package/build/psbt/PsbtCache.js.map +1 -0
  184. package/build/psbt/PsbtFinalizer.d.ts +21 -0
  185. package/build/psbt/PsbtFinalizer.d.ts.map +1 -0
  186. package/build/psbt/PsbtFinalizer.js +157 -0
  187. package/build/psbt/PsbtFinalizer.js.map +1 -0
  188. package/build/psbt/PsbtSigner.d.ts +32 -0
  189. package/build/psbt/PsbtSigner.d.ts.map +1 -0
  190. package/build/psbt/PsbtSigner.js +192 -0
  191. package/build/psbt/PsbtSigner.js.map +1 -0
  192. package/build/psbt/PsbtTransaction.d.ts +25 -0
  193. package/build/psbt/PsbtTransaction.d.ts.map +1 -0
  194. package/build/psbt/PsbtTransaction.js +61 -0
  195. package/build/psbt/PsbtTransaction.js.map +1 -0
  196. package/build/psbt/bip371.d.ts.map +1 -1
  197. package/build/psbt/bip371.js +6 -2
  198. package/build/psbt/bip371.js.map +1 -1
  199. package/build/psbt/psbtutils.js +1 -1
  200. package/build/psbt/psbtutils.js.map +1 -1
  201. package/build/psbt/types.d.ts +5 -71
  202. package/build/psbt/types.d.ts.map +1 -1
  203. package/build/psbt/validation.d.ts +1 -1
  204. package/build/psbt/validation.d.ts.map +1 -1
  205. package/build/psbt/validation.js +1 -1
  206. package/build/psbt/validation.js.map +1 -1
  207. package/build/psbt.d.ts +26 -40
  208. package/build/psbt.d.ts.map +1 -1
  209. package/build/psbt.js +180 -808
  210. package/build/psbt.js.map +1 -1
  211. package/build/script.d.ts.map +1 -1
  212. package/build/script.js +4 -4
  213. package/build/script.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 +6 -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 +14 -25
  222. package/build/types.js.map +1 -1
  223. package/build/workers/WorkerSigningPool.d.ts +24 -17
  224. package/build/workers/WorkerSigningPool.d.ts.map +1 -1
  225. package/build/workers/WorkerSigningPool.js +36 -25
  226. package/build/workers/WorkerSigningPool.js.map +1 -1
  227. package/build/workers/WorkerSigningPool.node.d.ts +19 -12
  228. package/build/workers/WorkerSigningPool.node.d.ts.map +1 -1
  229. package/build/workers/WorkerSigningPool.node.js +60 -28
  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 +160 -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/build/workers/types.js.map +1 -1
  266. package/package.json +48 -9
  267. package/src/address.ts +53 -21
  268. package/src/bech32utils.ts +3 -3
  269. package/src/block.ts +17 -10
  270. package/src/branded.ts +15 -13
  271. package/src/crypto.ts +1 -1
  272. package/src/ecc/context.ts +36 -136
  273. package/src/ecc/index.ts +2 -2
  274. package/src/ecc/types.ts +7 -145
  275. package/src/env.ts +239 -0
  276. package/src/index.ts +57 -22
  277. package/src/io/BinaryReader.ts +18 -18
  278. package/src/io/BinaryWriter.ts +43 -43
  279. package/src/io/hex.ts +2 -1
  280. package/src/io/index.ts +0 -3
  281. package/src/opcodes.ts +21 -4
  282. package/src/payments/bip341.ts +5 -7
  283. package/src/payments/embed.ts +19 -19
  284. package/src/payments/p2ms.ts +34 -27
  285. package/src/payments/p2op.ts +22 -22
  286. package/src/payments/p2pk.ts +22 -22
  287. package/src/payments/p2pkh.ts +28 -28
  288. package/src/payments/p2sh.ts +33 -30
  289. package/src/payments/p2tr.ts +40 -40
  290. package/src/payments/p2wpkh.ts +30 -30
  291. package/src/payments/p2wsh.ts +29 -29
  292. package/src/payments/types.ts +1 -1
  293. package/src/psbt/PsbtCache.ts +325 -0
  294. package/src/psbt/PsbtFinalizer.ts +213 -0
  295. package/src/psbt/PsbtSigner.ts +302 -0
  296. package/src/psbt/PsbtTransaction.ts +82 -0
  297. package/src/psbt/bip371.ts +7 -3
  298. package/src/psbt/psbtutils.ts +1 -1
  299. package/src/psbt/types.ts +5 -94
  300. package/src/psbt/validation.ts +5 -12
  301. package/src/psbt.ts +376 -1201
  302. package/src/script.ts +6 -9
  303. package/src/transaction.ts +19 -15
  304. package/src/types.ts +33 -45
  305. package/src/workers/WorkerSigningPool.node.ts +72 -36
  306. package/src/workers/WorkerSigningPool.sequential.ts +191 -0
  307. package/src/workers/WorkerSigningPool.ts +48 -39
  308. package/src/workers/WorkerSigningPool.worklet.ts +522 -0
  309. package/src/workers/index.browser.ts +34 -0
  310. package/src/workers/index.node.ts +50 -0
  311. package/src/workers/index.react-native.ts +110 -0
  312. package/src/workers/index.shared.ts +58 -0
  313. package/src/workers/index.ts +14 -65
  314. package/src/workers/psbt-parallel.ts +8 -13
  315. package/src/workers/types.ts +26 -1
  316. package/test/address.spec.ts +2 -2
  317. package/test/bitcoin.core.spec.ts +5 -2
  318. package/test/browser/payments.spec.ts +151 -0
  319. package/test/browser/psbt.spec.ts +1510 -0
  320. package/test/browser/script.spec.ts +223 -0
  321. package/test/browser/setup.ts +13 -0
  322. package/test/browser/workers-signing.spec.ts +537 -0
  323. package/test/crypto.spec.ts +2 -2
  324. package/test/env.spec.ts +418 -0
  325. package/test/fixtures/core/base58_encode_decode.json +12 -48
  326. package/test/fixtures/core/base58_keys_invalid.json +50 -150
  327. package/test/fixtures/core/sighash.json +1 -3
  328. package/test/fixtures/core/tx_valid.json +133 -501
  329. package/test/fixtures/embed.json +3 -11
  330. package/test/fixtures/p2ms.json +21 -91
  331. package/test/fixtures/p2pk.json +5 -24
  332. package/test/fixtures/p2pkh.json +7 -36
  333. package/test/fixtures/p2sh.json +8 -54
  334. package/test/fixtures/p2tr.json +2 -6
  335. package/test/fixtures/p2wpkh.json +7 -36
  336. package/test/fixtures/p2wsh.json +14 -59
  337. package/test/fixtures/psbt.json +2 -6
  338. package/test/fixtures/script.json +12 -48
  339. package/test/integration/addresses.spec.ts +11 -5
  340. package/test/integration/bip32.spec.ts +1 -1
  341. package/test/integration/cltv.spec.ts +10 -6
  342. package/test/integration/csv.spec.ts +10 -9
  343. package/test/integration/payments.spec.ts +8 -4
  344. package/test/integration/taproot.spec.ts +26 -6
  345. package/test/integration/transactions.spec.ts +22 -8
  346. package/test/payments.spec.ts +1 -1
  347. package/test/payments.utils.ts +1 -1
  348. package/test/psbt.spec.ts +250 -64
  349. package/test/script_signature.spec.ts +1 -1
  350. package/test/transaction.spec.ts +18 -5
  351. package/test/tsconfig.json +6 -20
  352. package/test/workers-pool.spec.ts +65 -23
  353. package/test/workers-sequential.spec.ts +669 -0
  354. package/test/workers-signing.spec.ts +7 -3
  355. package/test/workers-worklet.spec.ts +500 -0
  356. package/test/workers.spec.ts +6 -7
  357. package/typedoc.json +39 -0
  358. package/vite.config.browser.ts +31 -6
  359. package/vitest.config.browser.ts +68 -0
  360. package/browser/ecpair.d.ts +0 -99
  361. package/browser/io/MemoryPool.d.ts +0 -220
  362. package/browser/io/MemoryPool.d.ts.map +0 -1
  363. package/build/io/MemoryPool.d.ts +0 -220
  364. package/build/io/MemoryPool.d.ts.map +0 -1
  365. package/build/io/MemoryPool.js +0 -309
  366. package/build/io/MemoryPool.js.map +0 -1
  367. package/src/ecpair.d.ts +0 -99
  368. package/src/io/MemoryPool.ts +0 -343
  369. package/test/taproot-cache.spec.ts +0 -694
package/README.md CHANGED
@@ -1,201 +1,501 @@
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
27
30
 
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).
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
+ ```
29
38
 
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.**
39
+ Requires Node.js >= 24.0.0.
32
40
 
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.
41
+ ## Quick Start
34
42
 
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`.
43
+ ### Initialize the ECC Library
36
44
 
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.)
45
+ The ECC library must be initialized before using Taproot, signing, or any elliptic curve operations.
46
+ Two backends are available:
38
47
 
39
- We used to have a Slack. It is dead. If you find it, no one will answer you most likely.
48
+ **Noble (recommended for browsers)** -- pure JS, no WASM dependency:
40
49
 
41
- No we will not make a Discord.
50
+ ```typescript
51
+ import { initEccLib } from '@btc-vision/bitcoin';
52
+ import { createNobleBackend } from '@btc-vision/ecpair';
42
53
 
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
54
+ initEccLib(createNobleBackend());
50
55
  ```
51
56
 
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).
57
+ **tiny-secp256k1** -- WASM-based, faster in Node.js:
53
58
 
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.
59
+ ```typescript
60
+ import { initEccLib } from '@btc-vision/bitcoin';
61
+ import { createLegacyBackend } from '@btc-vision/ecpair';
62
+ import * as tinysecp from 'tiny-secp256k1';
58
63
 
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.
64
+ initEccLib(createLegacyBackend(tinysecp));
65
+ ```
66
+
67
+ ### Create a Key Pair
60
68
 
69
+ ```typescript
70
+ import { ECPairSigner, createNobleBackend } from '@btc-vision/ecpair';
71
+ import { networks } from '@btc-vision/bitcoin';
61
72
 
62
- ## Usage
63
- Crypto is hard.
73
+ const backend = createNobleBackend();
64
74
 
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.
75
+ // Random key pair
76
+ const keyPair = ECPairSigner.makeRandom(backend, networks.bitcoin);
69
77
 
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.
78
+ // From WIF
79
+ const imported = ECPairSigner.fromWIF(
80
+ backend,
81
+ 'L2uPYXe17xSTqbCjZvL2DsyXPCbXspvcu5mHLDYUgzdUbZGSKrSr',
82
+ networks.bitcoin,
83
+ );
84
+ ```
73
85
 
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.
86
+ ### Generate Addresses
77
87
 
78
- Finally, **adhere to best practice**.
79
- We are not an authoritative source of best practice, but, at the very least:
88
+ ```typescript
89
+ import { payments, networks } from '@btc-vision/bitcoin';
80
90
 
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.
91
+ // P2PKH (Legacy)
92
+ const { address: legacy } = payments.p2pkh({ pubkey: keyPair.publicKey });
87
93
 
94
+ // P2WPKH (Native SegWit)
95
+ const { address: segwit } = payments.p2wpkh({ pubkey: keyPair.publicKey });
88
96
 
89
- ### Browser
90
- The recommended method of using `bitcoinjs-lib` in your browser is through [browserify](http://browserify.org/).
97
+ // P2TR (Taproot) - requires ECC initialization
98
+ import { toXOnly } from '@btc-vision/bitcoin';
99
+ const { address: taproot } = payments.p2tr({
100
+ internalPubkey: toXOnly(keyPair.publicKey),
101
+ });
102
+
103
+ // P2SH-P2WPKH (Wrapped SegWit)
104
+ const { address: wrapped } = payments.p2sh({
105
+ redeem: payments.p2wpkh({ pubkey: keyPair.publicKey }),
106
+ });
107
+
108
+ // P2SH Multisig (2-of-3)
109
+ const { address: multisig } = payments.p2sh({
110
+ redeem: payments.p2ms({ m: 2, pubkeys: [pubkey1, pubkey2, pubkey3] }),
111
+ });
112
+ ```
113
+
114
+ ### Create and Sign a Transaction (PSBT)
115
+
116
+ ```typescript
117
+ import { Psbt, networks } from '@btc-vision/bitcoin';
118
+ import { fromHex } from '@btc-vision/bitcoin';
119
+ import type { Satoshi } from '@btc-vision/bitcoin';
120
+
121
+ const psbt = new Psbt({ network: networks.bitcoin });
122
+
123
+ // Add input
124
+ psbt.addInput({
125
+ hash: '7d067b4a697a09d2c3cff7d4d9506c9955e93bff41bf82d439da7d030382bc3e',
126
+ index: 0,
127
+ nonWitnessUtxo: fromHex('0200000001...'),
128
+ sighashType: 1,
129
+ });
130
+
131
+ // Add output (values are bigint)
132
+ psbt.addOutput({
133
+ address: '1KRMKfeZcmosxALVYESdPNez1AP1mEtywp',
134
+ value: 80_000n as Satoshi,
135
+ });
136
+
137
+ // Sign, finalize, and extract
138
+ psbt.signInput(0, keyPair);
139
+ psbt.finalizeAllInputs();
140
+ const txHex = psbt.extractTransaction().toHex();
141
+ ```
91
142
 
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:
143
+ ### Async Signing
93
144
 
94
- ```sh
95
- $ npm install bitcoinjs-lib browserify
96
- $ npx browserify --standalone bitcoin - -o bitcoinjs-lib.js <<<"module.exports = require('bitcoinjs-lib');"
145
+ ```typescript
146
+ await psbt.signInputAsync(0, keyPair);
147
+ await psbt.signAllInputsAsync(keyPair);
97
148
  ```
98
149
 
99
- Which you can then import as an ESM module:
150
+ ### Parse a Transaction
151
+
152
+ ```typescript
153
+ import { Transaction } from '@btc-vision/bitcoin';
154
+
155
+ const tx = Transaction.fromHex('0200000001...');
156
+ console.log(tx.version); // 2
157
+ console.log(tx.ins.length); // number of inputs
158
+ console.log(tx.outs.length); // number of outputs
159
+ console.log(tx.toHex()); // round-trip back to hex
160
+ ```
161
+
162
+ ### Decode and Encode Addresses
163
+
164
+ ```typescript
165
+ import { address, networks } from '@btc-vision/bitcoin';
166
+
167
+ // Decode any address to its output script
168
+ const outputScript = address.toOutputScript(
169
+ 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
170
+ networks.bitcoin,
171
+ );
172
+
173
+ // Convert output script back to address
174
+ const addr = address.fromOutputScript(outputScript, networks.bitcoin);
175
+
176
+ // Low-level Base58Check
177
+ const { hash, version } = address.fromBase58Check('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH');
178
+ const encoded = address.toBase58Check(hash, version);
179
+
180
+ // Low-level Bech32
181
+ const decoded = address.fromBech32('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4');
182
+ const bech32Addr = address.toBech32(decoded.data, decoded.version, 'bc');
183
+ ```
184
+
185
+ ### Parallel Signing with Workers
186
+
187
+ For high-throughput signing across many inputs, use the worker pool.
188
+
189
+ #### Sign a PSBT in parallel
190
+
191
+ `signPsbtParallel` analyzes inputs, distributes signing across workers, and applies signatures back to the PSBT:
192
+
193
+ ```typescript
194
+ import { Psbt, networks } from '@btc-vision/bitcoin';
195
+ import { signPsbtParallel, createSigningPool } from '@btc-vision/bitcoin/workers';
196
+
197
+ // Create a platform-appropriate pool (Node.js worker_threads or Web Workers)
198
+ const pool = await createSigningPool({ workerCount: 4 });
199
+ pool.preserveWorkers();
200
+
201
+ // Build your PSBT as usual
202
+ const psbt = new Psbt({ network: networks.bitcoin });
203
+ psbt.addInput({ /* ... */ });
204
+ psbt.addInput({ /* ... */ });
205
+ psbt.addOutput({ /* ... */ });
206
+
207
+ // Sign all signable inputs in parallel — replaces signAllInputs / signAllInputsAsync
208
+ const result = await signPsbtParallel(psbt, keyPair, pool);
209
+
210
+ if (result.success) {
211
+ console.log(`Signed ${result.signatures.size} inputs in ${result.durationMs}ms`);
212
+ psbt.finalizeAllInputs();
213
+ const tx = psbt.extractTransaction();
214
+ }
215
+
216
+ // Shut down when done (or keep the pool alive for future PSBTs)
217
+ await pool.shutdown();
218
+ ```
219
+
220
+ You can also pass a config object instead of a pool instance. A temporary pool will be created and
221
+ destroyed automatically:
222
+
223
+ ```typescript
224
+ const result = await signPsbtParallel(psbt, keyPair, { workerCount: 4 });
225
+ ```
226
+
227
+ #### Low-level batch signing
228
+
229
+ For manual control over sighash computation and task construction:
230
+
231
+ ```typescript
232
+ import { createSigningPool, SignatureType } from '@btc-vision/bitcoin/workers';
233
+
234
+ const pool = await createSigningPool({ workerCount: 4 });
235
+ pool.preserveWorkers();
236
+
237
+ const tasks = [
238
+ {
239
+ taskId: 'input-0',
240
+ inputIndex: 0,
241
+ hash: sighash0,
242
+ signatureType: SignatureType.ECDSA,
243
+ sighashType: 0x01,
244
+ },
245
+ {
246
+ taskId: 'input-1',
247
+ inputIndex: 1,
248
+ hash: sighash1,
249
+ signatureType: SignatureType.Schnorr,
250
+ sighashType: 0x00,
251
+ },
252
+ ];
253
+
254
+ const result = await pool.signBatch(tasks, keyPair);
255
+ if (result.success) {
256
+ console.log(`Signed ${result.signatures.size} inputs in ${result.durationMs}ms`);
257
+ }
258
+
259
+ await pool.shutdown();
260
+ ```
261
+
262
+ ## API Reference
263
+
264
+ ### Exports
265
+
266
+ The library provides granular sub-path exports for tree-shaking:
267
+
268
+ ```typescript
269
+ import { ... } from '@btc-vision/bitcoin'; // Full API
270
+ import { ... } from '@btc-vision/bitcoin/address'; // Address encoding/decoding
271
+ import { ... } from '@btc-vision/bitcoin/script'; // Script compile/decompile
272
+ import { ... } from '@btc-vision/bitcoin/crypto'; // Hash functions
273
+ import { ... } from '@btc-vision/bitcoin/transaction';// Transaction class
274
+ import { ... } from '@btc-vision/bitcoin/psbt'; // PSBT classes
275
+ import { ... } from '@btc-vision/bitcoin/networks'; // Network definitions
276
+ import { ... } from '@btc-vision/bitcoin/payments'; // Payment creators
277
+ import { ... } from '@btc-vision/bitcoin/io'; // Binary I/O utilities
278
+ import { ... } from '@btc-vision/bitcoin/ecc'; // ECC context
279
+ import { ... } from '@btc-vision/bitcoin/types'; // Type definitions & guards
280
+ import { ... } from '@btc-vision/bitcoin/errors'; // Error classes
281
+ import { ... } from '@btc-vision/bitcoin/workers'; // Parallel signing
282
+ ```
283
+
284
+ ### Branded Types
285
+
286
+ Values use branded types to prevent accidental misuse:
287
+
288
+ ```typescript
289
+ import type {
290
+ Bytes32, // 32-byte Uint8Array (tx hashes, witness programs)
291
+ Bytes20, // 20-byte Uint8Array (pubkey hashes)
292
+ PublicKey, // Compressed/uncompressed public key
293
+ XOnlyPublicKey, // 32-byte x-only pubkey (Taproot)
294
+ PrivateKey, // 32-byte private key
295
+ Satoshi, // bigint value (0 to 21e14)
296
+ Signature, // DER-encoded ECDSA signature
297
+ SchnorrSignature, // 64-byte Schnorr signature
298
+ Script, // Compiled script bytes
299
+ } from '@btc-vision/bitcoin';
300
+
301
+ // Type guards
302
+ import {
303
+ isBytes32, isBytes20, isPoint, isSatoshi,
304
+ isPrivateKey, isSignature, isSchnorrSignature,
305
+ isXOnlyPublicKey, isScript,
306
+ } from '@btc-vision/bitcoin';
307
+
308
+ // Conversion helpers (throw on invalid input)
309
+ import { toBytes32, toBytes20, toSatoshi } from '@btc-vision/bitcoin';
310
+ ```
311
+
312
+ ### Payment Types
313
+
314
+ | Type | Function | Class | Description |
315
+ |------|----------|-------|-------------|
316
+ | P2PK | `p2pk()` | `P2PK` | Pay-to-Public-Key |
317
+ | P2PKH | `p2pkh()` | `P2PKH` | Pay-to-Public-Key-Hash (Legacy) |
318
+ | P2SH | `p2sh()` | `P2SH` | Pay-to-Script-Hash |
319
+ | P2MS | `p2ms()` | `P2MS` | Pay-to-Multisig |
320
+ | P2WPKH | `p2wpkh()` | `P2WPKH` | SegWit v0 Public Key Hash |
321
+ | P2WSH | `p2wsh()` | `P2WSH` | SegWit v0 Script Hash |
322
+ | P2TR | `p2tr()` | `P2TR` | Taproot (SegWit v1) |
323
+ | P2OP | `p2op()` | `P2OP` | OPNet (SegWit v16) |
324
+ | Embed | `p2data()` | `Embed` | OP_RETURN data |
325
+
326
+ ### Network Support
327
+
328
+ | Network | Constant | Bech32 Prefix |
329
+ |---------|----------|---------------|
330
+ | Bitcoin Mainnet | `networks.bitcoin` | `bc` |
331
+ | Bitcoin Testnet | `networks.testnet` | `tb` |
332
+ | Bitcoin Regtest | `networks.regtest` | `bcrt` |
333
+ | Dogecoin | `networks.dogecoin` | - |
334
+ | Litecoin | `networks.litecoin` | `ltc` |
335
+ | Bitcoin Cash | `networks.bitcoinCash` | `bitcoincash` |
336
+ | Dash | `networks.dash` | - |
337
+
338
+ ### Error Handling
339
+
340
+ All errors extend `BitcoinError`:
341
+
342
+ ```typescript
343
+ import {
344
+ BitcoinError, // Base class
345
+ ValidationError, // Input validation failures
346
+ InvalidInputError, // Invalid transaction input
347
+ InvalidOutputError,// Invalid transaction output
348
+ ScriptError, // Script operation failures
349
+ PsbtError, // PSBT operation failures
350
+ EccError, // ECC library not initialized
351
+ AddressError, // Address encoding/decoding failures
352
+ SignatureError, // Signature operation failures
353
+ } from '@btc-vision/bitcoin';
354
+
355
+ try {
356
+ psbt.signInput(0, signer);
357
+ } catch (err) {
358
+ if (err instanceof PsbtError) {
359
+ // Handle PSBT-specific error
360
+ }
361
+ }
362
+ ```
363
+
364
+ ### Utility Functions
365
+
366
+ ```typescript
367
+ import {
368
+ toHex, fromHex, isHex, // Hex encoding
369
+ concat, equals, compare, // Buffer operations
370
+ clone, reverse, reverseCopy, // Buffer manipulation
371
+ alloc, xor, isZero, // Buffer utilities
372
+ fromUtf8, toUtf8, // UTF-8 conversion
373
+ toXOnly, // Compress pubkey to x-only (32 bytes)
374
+ decompressPublicKey, // Decompress compressed pubkey
375
+ } from '@btc-vision/bitcoin';
376
+ ```
377
+
378
+ ### Crypto Functions
379
+
380
+ ```typescript
381
+ import { sha256, sha1, ripemd160, hash160, hash256, taggedHash } from '@btc-vision/bitcoin';
382
+
383
+ const h = hash160(publicKey); // RIPEMD160(SHA256(data))
384
+ const d = hash256(data); // SHA256(SHA256(data))
385
+ const t = taggedHash('TapLeaf', data); // BIP340 tagged hash
386
+ ```
387
+
388
+ ## Browser Usage
389
+
390
+ 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.
391
+
392
+ 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.
393
+
394
+ ## React Native
395
+
396
+ 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.
397
+
398
+ ### Metro Configuration
399
+
400
+ Add `react-native` to the condition names in your `metro.config.js`:
100
401
 
101
402
  ```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)!
403
+ const config = {
404
+ resolver: {
405
+ unstable_conditionNames: ['react-native', 'import', 'default'],
406
+ },
407
+ };
408
+ ```
166
409
 
410
+ ### Usage
167
411
 
168
- ## Contributing
169
- See [CONTRIBUTING.md](CONTRIBUTING.md).
412
+ Usage is identical to Node.js and browsers:
413
+
414
+ ```typescript
415
+ import { initEccLib, Psbt, networks } from '@btc-vision/bitcoin';
416
+ import { createNobleBackend, ECPairSigner } from '@btc-vision/ecpair';
417
+
418
+ // Initialize ECC (pure JS Noble backend — no WASM needed)
419
+ const backend = createNobleBackend();
420
+ initEccLib(backend);
421
+
422
+ // Create key pair, build PSBT, sign — same API as Node.js/browser
423
+ const keyPair = ECPairSigner.fromWIF(backend, wif, networks.bitcoin);
424
+ const psbt = new Psbt({ network: networks.bitcoin });
425
+ // ... add inputs/outputs ...
426
+ psbt.signAllInputs(keyPair);
427
+ ```
428
+
429
+ ### Parallel Signing
430
+
431
+ `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.
432
+
433
+ Install the optional peer dependency to enable parallel signing:
434
+
435
+ ```bash
436
+ npm install react-native-worklets
437
+ ```
438
+
439
+ Usage is identical to Node.js/browser — `createSigningPool()` detects worklets automatically:
440
+
441
+ ```typescript
442
+ import { signPsbtParallel, createSigningPool } from '@btc-vision/bitcoin/workers';
443
+
444
+ // Automatically uses WorkletSigningPool if react-native-worklets is installed,
445
+ // otherwise falls back to SequentialSigningPool (main-thread, one-by-one)
446
+ const pool = await createSigningPool({ workerCount: 4 });
447
+ pool.preserveWorkers();
448
+
449
+ const result = await signPsbtParallel(psbt, keyPair, pool);
450
+ await pool.shutdown();
451
+ ```
452
+
453
+ You can also import `WorkletSigningPool` directly for explicit control:
454
+
455
+ ```typescript
456
+ import { WorkletSigningPool } from '@btc-vision/bitcoin/workers';
457
+
458
+ const pool = WorkletSigningPool.getInstance({ workerCount: 4 });
459
+ pool.preserveWorkers();
460
+ await pool.initialize();
461
+
462
+ const result = await pool.signBatch(tasks, keyPair);
463
+ await pool.shutdown();
464
+ ```
465
+
466
+ 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.
467
+
468
+ ### Requirements
170
469
 
470
+ - **Hermes 0.76+** (React Native 0.76+) for BigInt and `crypto.getRandomValues()` support
471
+ - **`react-native-worklets` >= 0.7.0** (optional) for parallel signing across worklet runtimes
472
+ - `react-native-quick-crypto` is **not** required — the core library uses `@noble/hashes` and `@noble/curves` (pure JS)
473
+ - A future `@btc-vision/react-native-secp256k1` Nitro Module would provide native C++ performance via `initEccLib(createNativeBackend())`
171
474
 
172
- ### Running the test suite
475
+ ## Running Tests
173
476
 
174
- ``` bash
175
- npm test
176
- npm run-script coverage
477
+ ```bash
478
+ npm test # Full suite (lint + build + test)
479
+ npm run unit # Unit tests only
480
+ npm run integration # Integration tests
481
+ npm run test:browser # Browser tests (Playwright)
482
+ npm run bench # Benchmarks
177
483
  ```
178
484
 
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
485
+ ## Contributing
486
+
487
+ 1. Fork the repository
488
+ 2. Create a feature branch
489
+ 3. Make your changes
490
+ 4. Run tests: `npm test`
491
+ 5. Submit a pull request
193
492
 
493
+ ## License
194
494
 
195
- ## Alternatives
196
- - [BCoin](https://github.com/indutny/bcoin)
197
- - [Bitcore](https://github.com/bitpay/bitcore)
198
- - [Cryptocoin](https://github.com/cryptocoinjs/cryptocoin)
495
+ [MIT](LICENSE)
199
496
 
497
+ ## Links
200
498
 
201
- ## LICENSE [MIT](LICENSE)
499
+ - [GitHub](https://github.com/btc-vision/bitcoin)
500
+ - [npm](https://www.npmjs.com/package/@btc-vision/bitcoin)
501
+ - [API Documentation](https://bitcoinjs.github.io/bitcoinjs-lib/)