@btc-vision/bitcoin 6.3.1 → 6.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (374) hide show
  1. package/.babelrc +4 -0
  2. package/.gitattributes +2 -0
  3. package/.nyc_output/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +1 -0
  4. package/.nyc_output/processinfo/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +1 -0
  5. package/.nyc_output/processinfo/index.json +1 -0
  6. package/.prettierrc.json +12 -0
  7. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.ready +0 -0
  8. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.release-please-manifest.json +3 -0
  9. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CHANGELOG.md +962 -0
  10. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CONTRIBUTING.md +34 -0
  11. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/LICENSE +24 -0
  12. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/README.md +273 -0
  13. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/SECURITY.md +2 -0
  14. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/addon.gypi +204 -0
  15. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/bin/node-gyp.js +138 -0
  16. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/.release-please-manifest.json +3 -0
  17. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/LICENSE +28 -0
  18. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/ninja/build.ninja +4 -0
  19. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/win/large-pdb-shim.cc +12 -0
  20. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/GypVsCMake.md +116 -0
  21. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Hacking.md +46 -0
  22. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/InputFormatReference.md +1080 -0
  23. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/LanguageSpecification.md +430 -0
  24. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/README.md +27 -0
  25. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Testing.md +450 -0
  26. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/UserDocumentation.md +965 -0
  27. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp +8 -0
  28. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp.bat +5 -0
  29. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  30. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +365 -0
  31. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  32. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1272 -0
  33. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  34. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  35. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  36. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  37. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  38. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +692 -0
  39. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common.py +711 -0
  40. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +171 -0
  41. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +169 -0
  42. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +113 -0
  43. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  44. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  45. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +804 -0
  46. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  47. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1318 -0
  48. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +127 -0
  49. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  50. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +461 -0
  51. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  52. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +57 -0
  53. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2745 -0
  54. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3976 -0
  55. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  56. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2964 -0
  57. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +67 -0
  58. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1391 -0
  59. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  60. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input.py +3115 -0
  61. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  62. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  63. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1260 -0
  64. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  65. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  66. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +373 -0
  67. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1938 -0
  68. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +53 -0
  69. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  70. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3198 -0
  71. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  72. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE +3 -0
  73. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.APACHE +177 -0
  74. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.BSD +23 -0
  75. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/__init__.py +15 -0
  76. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py +108 -0
  77. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py +252 -0
  78. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py +83 -0
  79. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_parser.py +359 -0
  80. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_structures.py +61 -0
  81. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py +192 -0
  82. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/markers.py +252 -0
  83. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +825 -0
  84. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/py.typed +0 -0
  85. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/requirements.py +90 -0
  86. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py +1030 -0
  87. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/tags.py +553 -0
  88. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/utils.py +172 -0
  89. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/version.py +563 -0
  90. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pyproject.toml +120 -0
  91. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/release-please-config.json +11 -0
  92. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/test_gyp.py +261 -0
  93. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/Find-VisualStudio.cs +250 -0
  94. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/build.js +227 -0
  95. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/clean.js +15 -0
  96. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/configure.js +328 -0
  97. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/create-config-gypi.js +150 -0
  98. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/download.js +39 -0
  99. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-node-directory.js +63 -0
  100. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-python.js +310 -0
  101. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-visualstudio.js +590 -0
  102. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/install.js +415 -0
  103. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/list.js +26 -0
  104. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/log.js +168 -0
  105. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/node-gyp.js +188 -0
  106. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/process-release.js +146 -0
  107. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/rebuild.js +12 -0
  108. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/remove.js +43 -0
  109. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/util.js +81 -0
  110. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/macOS_Catalina_acid_test.sh +21 -0
  111. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/package.json +51 -0
  112. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/release-please-config.json +40 -0
  113. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/src/win_delay_load_hook.cc +39 -0
  114. package/CHANGELOG.md +403 -0
  115. package/CONTRIBUTING.md +83 -0
  116. package/browser/address.d.ts +16 -0
  117. package/{src → browser}/bip66.d.ts +6 -7
  118. package/{src → browser}/block.d.ts +29 -30
  119. package/{src → browser}/bufferutils.d.ts +34 -54
  120. package/browser/crypto/crypto.d.ts +1 -0
  121. package/{src → browser}/crypto.d.ts +13 -18
  122. package/browser/ecc_lib.d.ts +3 -0
  123. package/browser/hooks/AdvancedSignatureManager.d.ts +16 -0
  124. package/{src → browser}/hooks/HookedSigner.d.ts +4 -4
  125. package/browser/hooks/SignatureManager.d.ts +13 -0
  126. package/browser/index.d.ts +58 -0
  127. package/browser/index.js +2 -0
  128. package/browser/index.js.LICENSE.txt +14 -0
  129. package/browser/merkle.d.ts +1 -0
  130. package/browser/networks.d.ts +23 -0
  131. package/{src → browser}/ops.d.ts +126 -126
  132. package/browser/payments/bip341.d.ts +23 -0
  133. package/browser/payments/embed.d.ts +2 -0
  134. package/browser/payments/index.d.ts +43 -0
  135. package/{src → browser}/payments/lazy.d.ts +2 -2
  136. package/browser/payments/p2ms.d.ts +2 -0
  137. package/browser/payments/p2pk.d.ts +2 -0
  138. package/browser/payments/p2pkh.d.ts +2 -0
  139. package/browser/payments/p2sh.d.ts +2 -0
  140. package/browser/payments/p2tr.d.ts +2 -0
  141. package/browser/payments/p2wpkh.d.ts +2 -0
  142. package/browser/payments/p2wsh.d.ts +2 -0
  143. package/browser/psbt/bip371.d.ts +16 -0
  144. package/browser/psbt/psbtutils.d.ts +26 -0
  145. package/{src → browser}/psbt.d.ts +167 -238
  146. package/browser/push_data.d.ts +7 -0
  147. package/browser/script.d.ts +17 -0
  148. package/browser/script_number.d.ts +2 -0
  149. package/browser/script_signature.d.ts +7 -0
  150. package/{src → browser}/transaction.d.ts +48 -60
  151. package/{src → browser}/types.d.ts +37 -54
  152. package/build/address.d.ts +16 -0
  153. package/build/address.js +148 -0
  154. package/build/bip66.d.ts +6 -0
  155. package/build/bip66.js +99 -0
  156. package/build/block.d.ts +29 -0
  157. package/build/block.js +181 -0
  158. package/build/bufferutils.d.ts +34 -0
  159. package/build/bufferutils.js +141 -0
  160. package/build/crypto/crypto.d.ts +1 -0
  161. package/build/crypto/crypto.js +1 -0
  162. package/build/crypto.d.ts +13 -0
  163. package/build/crypto.js +87 -0
  164. package/build/ecc_lib.d.ts +3 -0
  165. package/build/ecc_lib.js +61 -0
  166. package/build/hooks/AdvancedSignatureManager.d.ts +16 -0
  167. package/build/hooks/AdvancedSignatureManager.js +52 -0
  168. package/build/hooks/HookedSigner.d.ts +4 -0
  169. package/build/hooks/HookedSigner.js +64 -0
  170. package/build/hooks/SignatureManager.d.ts +13 -0
  171. package/build/hooks/SignatureManager.js +45 -0
  172. package/build/index.d.ts +58 -0
  173. package/build/index.js +32 -0
  174. package/build/merkle.d.ts +1 -0
  175. package/build/merkle.js +19 -0
  176. package/build/networks.d.ts +23 -0
  177. package/build/networks.js +121 -0
  178. package/build/ops.d.ts +126 -0
  179. package/{src → build}/ops.js +127 -131
  180. package/build/payments/bip341.d.ts +23 -0
  181. package/build/payments/bip341.js +82 -0
  182. package/build/payments/embed.d.ts +2 -0
  183. package/build/payments/embed.js +39 -0
  184. package/build/payments/index.d.ts +43 -0
  185. package/build/payments/index.js +10 -0
  186. package/build/payments/lazy.d.ts +2 -0
  187. package/{src → build}/payments/lazy.js +28 -32
  188. package/build/payments/p2ms.d.ts +2 -0
  189. package/{src → build}/payments/p2ms.js +128 -158
  190. package/build/payments/p2pk.d.ts +2 -0
  191. package/build/payments/p2pk.js +68 -0
  192. package/build/payments/p2pkh.d.ts +2 -0
  193. package/build/payments/p2pkh.js +173 -0
  194. package/build/payments/p2sh.d.ts +2 -0
  195. package/build/payments/p2sh.js +176 -0
  196. package/build/payments/p2tr.d.ts +2 -0
  197. package/build/payments/p2tr.js +254 -0
  198. package/build/payments/p2wpkh.d.ts +2 -0
  199. package/build/payments/p2wpkh.js +130 -0
  200. package/build/payments/p2wsh.d.ts +2 -0
  201. package/build/payments/p2wsh.js +180 -0
  202. package/build/psbt/bip371.d.ts +16 -0
  203. package/build/psbt/bip371.js +246 -0
  204. package/build/psbt/psbtutils.d.ts +26 -0
  205. package/build/psbt/psbtutils.js +177 -0
  206. package/build/psbt.d.ts +167 -0
  207. package/build/psbt.js +1307 -0
  208. package/build/push_data.d.ts +7 -0
  209. package/build/push_data.js +57 -0
  210. package/build/script.d.ts +17 -0
  211. package/build/script.js +167 -0
  212. package/build/script_number.d.ts +2 -0
  213. package/build/script_number.js +49 -0
  214. package/build/script_signature.d.ts +7 -0
  215. package/build/script_signature.js +49 -0
  216. package/build/transaction.d.ts +48 -0
  217. package/build/transaction.js +445 -0
  218. package/build/types.d.ts +37 -0
  219. package/build/types.js +73 -0
  220. package/cjs/package.json +3 -0
  221. package/coverage/tmp/coverage-31752-1735543485354-0.json +1 -0
  222. package/coverage/tmp/coverage-59920-1735543484555-0.json +1 -0
  223. package/coverage/tmp/coverage-66252-1735543483919-0.json +1 -0
  224. package/coverage/tmp/coverage-68440-1735543485236-0.json +1 -0
  225. package/coverage/tmp/coverage-70588-1735543484426-0.json +1 -0
  226. package/coverage/tmp/coverage-79292-1735543485296-0.json +1 -0
  227. package/coverage/tmp/coverage-80212-1735543483980-0.json +1 -0
  228. package/eslint.config.js +56 -0
  229. package/gulpfile.js +42 -0
  230. package/package.json +105 -50
  231. package/src/{address.js → address.ts} +211 -191
  232. package/src/{bip66.js → bip66.ts} +23 -19
  233. package/src/{block.js → block.ts} +114 -105
  234. package/src/{bufferutils.js → bufferutils.ts} +65 -67
  235. package/src/crypto/crypto-browser.js +75 -0
  236. package/src/crypto/crypto.ts +1 -0
  237. package/src/crypto.ts +108 -0
  238. package/src/{ecc_lib.js → ecc_lib.ts} +25 -53
  239. package/src/hooks/{AdvancedSignatureManager.js → AdvancedSignatureManager.ts} +34 -18
  240. package/src/hooks/HookedSigner.ts +108 -0
  241. package/src/hooks/{SignatureManager.js → SignatureManager.ts} +26 -14
  242. package/src/index.ts +86 -0
  243. package/src/{merkle.js → merkle.ts} +8 -7
  244. package/src/{networks.js → networks.ts} +235 -220
  245. package/src/ops.ts +282 -0
  246. package/src/payments/bip341.ts +140 -0
  247. package/src/payments/embed.ts +55 -0
  248. package/src/payments/{index.d.ts → index.ts} +24 -10
  249. package/src/payments/lazy.ts +28 -0
  250. package/src/payments/p2ms.ts +150 -0
  251. package/src/payments/{p2pk.js → p2pk.ts} +85 -82
  252. package/src/payments/p2pkh.ts +206 -0
  253. package/src/payments/{p2sh.js → p2sh.ts} +206 -204
  254. package/src/payments/{p2tr.js → p2tr.ts} +114 -125
  255. package/src/payments/{p2wpkh.js → p2wpkh.ts} +51 -56
  256. package/src/payments/{p2wsh.js → p2wsh.ts} +69 -81
  257. package/src/psbt/{bip371.js → bip371.ts} +441 -424
  258. package/src/psbt/psbtutils.ts +301 -0
  259. package/src/{psbt.js → psbt.ts} +2187 -1828
  260. package/src/{push_data.js → push_data.ts} +35 -21
  261. package/src/{script.js → script.ts} +93 -77
  262. package/src/{script_number.js → script_number.ts} +15 -21
  263. package/src/{script_signature.js → script_signature.ts} +26 -14
  264. package/src/{transaction.js → transaction.ts} +247 -167
  265. package/src/types.ts +122 -0
  266. package/test/address.spec.js +124 -0
  267. package/test/address.spec.ts +177 -0
  268. package/test/bitcoin.core.spec.js +170 -0
  269. package/test/bitcoin.core.spec.ts +234 -0
  270. package/test/block.spec.js +141 -0
  271. package/test/block.spec.ts +194 -0
  272. package/test/bufferutils.spec.js +427 -0
  273. package/test/bufferutils.spec.ts +513 -0
  274. package/test/crypto.spec.js +41 -0
  275. package/test/crypto.spec.ts +55 -0
  276. package/test/fixtures/address.json +329 -0
  277. package/test/fixtures/block.json +148 -0
  278. package/test/fixtures/bufferutils.json +102 -0
  279. package/test/fixtures/core/README.md +26 -0
  280. package/test/fixtures/core/base58_encode_decode.json +50 -0
  281. package/test/fixtures/core/base58_keys_invalid.json +152 -0
  282. package/test/fixtures/core/base58_keys_valid.json +452 -0
  283. package/test/fixtures/core/blocks.json +27 -0
  284. package/test/fixtures/core/sig_canonical.json +7 -0
  285. package/test/fixtures/core/sig_noncanonical.json +33 -0
  286. package/test/fixtures/core/sighash.json +3505 -0
  287. package/test/fixtures/core/tx_valid.json +2023 -0
  288. package/test/fixtures/crypto.json +43 -0
  289. package/test/fixtures/ecdsa.json +217 -0
  290. package/test/fixtures/ecpair.json +141 -0
  291. package/test/fixtures/embed.json +108 -0
  292. package/test/fixtures/p2ms.json +434 -0
  293. package/test/fixtures/p2pk.json +179 -0
  294. package/test/fixtures/p2pkh.json +276 -0
  295. package/test/fixtures/p2sh.json +508 -0
  296. package/test/fixtures/p2tr.json +1198 -0
  297. package/test/fixtures/p2wpkh.json +290 -0
  298. package/test/fixtures/p2wsh.json +489 -0
  299. package/test/fixtures/psbt.json +924 -0
  300. package/test/fixtures/script.json +465 -0
  301. package/test/fixtures/script_number.json +225 -0
  302. package/test/fixtures/signature.json +140 -0
  303. package/test/fixtures/transaction.json +916 -0
  304. package/test/integration/_regtest.js +7 -0
  305. package/test/integration/_regtest.ts +6 -0
  306. package/test/integration/addresses.spec.js +116 -0
  307. package/test/integration/addresses.spec.ts +154 -0
  308. package/test/integration/bip32.spec.js +85 -0
  309. package/test/integration/bip32.spec.ts +151 -0
  310. package/test/integration/blocks.spec.js +26 -0
  311. package/test/integration/blocks.spec.ts +28 -0
  312. package/test/integration/cltv.spec.js +199 -0
  313. package/test/integration/cltv.spec.ts +283 -0
  314. package/test/integration/csv.spec.js +362 -0
  315. package/test/integration/csv.spec.ts +527 -0
  316. package/test/integration/payments.spec.js +98 -0
  317. package/test/integration/payments.spec.ts +135 -0
  318. package/test/integration/taproot.spec.js +532 -0
  319. package/test/integration/taproot.spec.ts +707 -0
  320. package/test/integration/transactions.spec.js +561 -0
  321. package/test/integration/transactions.spec.ts +769 -0
  322. package/test/payments.spec.js +97 -0
  323. package/test/payments.spec.ts +125 -0
  324. package/test/payments.utils.js +190 -0
  325. package/test/payments.utils.ts +208 -0
  326. package/test/psbt.spec.js +1044 -0
  327. package/test/psbt.spec.ts +1414 -0
  328. package/test/script.spec.js +151 -0
  329. package/test/script.spec.ts +210 -0
  330. package/test/script_number.spec.js +24 -0
  331. package/test/script_number.spec.ts +29 -0
  332. package/test/script_signature.spec.js +52 -0
  333. package/test/script_signature.spec.ts +66 -0
  334. package/test/transaction.spec.js +269 -0
  335. package/test/transaction.spec.ts +387 -0
  336. package/test/ts-node-register.js +5 -0
  337. package/test/tsconfig.json +45 -0
  338. package/test/types.spec.js +46 -0
  339. package/test/types.spec.ts +58 -0
  340. package/tsconfig.base.json +27 -0
  341. package/tsconfig.json +19 -0
  342. package/tsconfig.webpack.json +18 -0
  343. package/webpack.config.js +79 -0
  344. package/src/address.d.ts +0 -42
  345. package/src/crypto.js +0 -128
  346. package/src/ecc_lib.d.ts +0 -17
  347. package/src/hooks/AdvancedSignatureManager.d.ts +0 -44
  348. package/src/hooks/HookedSigner.js +0 -90
  349. package/src/hooks/SignatureManager.d.ts +0 -35
  350. package/src/index.d.ts +0 -42
  351. package/src/index.js +0 -87
  352. package/src/merkle.d.ts +0 -10
  353. package/src/networks.d.ts +0 -83
  354. package/src/payments/bip341.d.ts +0 -49
  355. package/src/payments/bip341.js +0 -124
  356. package/src/payments/embed.d.ts +0 -9
  357. package/src/payments/embed.js +0 -54
  358. package/src/payments/index.js +0 -69
  359. package/src/payments/p2ms.d.ts +0 -9
  360. package/src/payments/p2pk.d.ts +0 -10
  361. package/src/payments/p2pkh.d.ts +0 -10
  362. package/src/payments/p2pkh.js +0 -143
  363. package/src/payments/p2sh.d.ts +0 -10
  364. package/src/payments/p2tr.d.ts +0 -10
  365. package/src/payments/p2wpkh.d.ts +0 -10
  366. package/src/payments/p2wsh.d.ts +0 -10
  367. package/src/psbt/bip371.d.ts +0 -42
  368. package/src/psbt/psbtutils.d.ts +0 -64
  369. package/src/psbt/psbtutils.js +0 -191
  370. package/src/push_data.d.ts +0 -29
  371. package/src/script.d.ts +0 -42
  372. package/src/script_number.d.ts +0 -19
  373. package/src/script_signature.d.ts +0 -21
  374. package/src/types.js +0 -106
@@ -1,143 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.p2pkh = void 0;
4
- const bcrypto = require('../crypto');
5
- const networks_1 = require('../networks');
6
- const bscript = require('../script');
7
- const types_1 = require('../types');
8
- const lazy = require('./lazy');
9
- const bs58check = require('bs58check');
10
- const OPS = bscript.OPS;
11
- // input: {signature} {pubkey}
12
- // output: OP_DUP OP_HASH160 {hash160(pubkey)} OP_EQUALVERIFY OP_CHECKSIG
13
- /**
14
- * Creates a Pay-to-Public-Key-Hash (P2PKH) payment object.
15
- *
16
- * @param a - The payment object containing the necessary data.
17
- * @param opts - Optional payment options.
18
- * @returns The P2PKH payment object.
19
- * @throws {TypeError} If the required data is not provided or if the data is invalid.
20
- */
21
- function p2pkh(a, opts) {
22
- if (!a.address && !a.hash && !a.output && !a.pubkey && !a.input)
23
- throw new TypeError('Not enough data');
24
- opts = Object.assign({ validate: true }, opts || {});
25
- (0, types_1.typeforce)(
26
- {
27
- network: types_1.typeforce.maybe(types_1.typeforce.Object),
28
- address: types_1.typeforce.maybe(types_1.typeforce.String),
29
- hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)),
30
- output: types_1.typeforce.maybe(types_1.typeforce.BufferN(25)),
31
- pubkey: types_1.typeforce.maybe(types_1.isPoint),
32
- signature: types_1.typeforce.maybe(
33
- bscript.isCanonicalScriptSignature,
34
- ),
35
- input: types_1.typeforce.maybe(types_1.typeforce.Buffer),
36
- },
37
- a,
38
- );
39
- const _address = lazy.value(() => {
40
- const payload = Buffer.from(bs58check.decode(a.address));
41
- const version = payload.readUInt8(0);
42
- const hash = payload.slice(1);
43
- return { version, hash };
44
- });
45
- const _chunks = lazy.value(() => {
46
- return bscript.decompile(a.input);
47
- });
48
- const network = a.network || networks_1.bitcoin;
49
- const o = { name: 'p2pkh', network };
50
- lazy.prop(o, 'address', () => {
51
- if (!o.hash) return;
52
- const payload = Buffer.allocUnsafe(21);
53
- payload.writeUInt8(network.pubKeyHash, 0);
54
- o.hash.copy(payload, 1);
55
- return bs58check.encode(payload);
56
- });
57
- lazy.prop(o, 'hash', () => {
58
- if (a.output) return a.output.slice(3, 23);
59
- if (a.address) return _address().hash;
60
- if (a.pubkey || o.pubkey) return bcrypto.hash160(a.pubkey || o.pubkey);
61
- });
62
- lazy.prop(o, 'output', () => {
63
- if (!o.hash) return;
64
- return bscript.compile([
65
- OPS.OP_DUP,
66
- OPS.OP_HASH160,
67
- o.hash,
68
- OPS.OP_EQUALVERIFY,
69
- OPS.OP_CHECKSIG,
70
- ]);
71
- });
72
- lazy.prop(o, 'pubkey', () => {
73
- if (!a.input) return;
74
- return _chunks()[1];
75
- });
76
- lazy.prop(o, 'signature', () => {
77
- if (!a.input) return;
78
- return _chunks()[0];
79
- });
80
- lazy.prop(o, 'input', () => {
81
- if (!a.pubkey) return;
82
- if (!a.signature) return;
83
- return bscript.compile([a.signature, a.pubkey]);
84
- });
85
- lazy.prop(o, 'witness', () => {
86
- if (!o.input) return;
87
- return [];
88
- });
89
- // extended validation
90
- if (opts.validate) {
91
- let hash = Buffer.from([]);
92
- if (a.address) {
93
- if (_address().version !== network.pubKeyHash)
94
- throw new TypeError('Invalid version or Network mismatch');
95
- if (_address().hash.length !== 20)
96
- throw new TypeError('Invalid address');
97
- hash = _address().hash;
98
- }
99
- if (a.hash) {
100
- if (hash.length > 0 && !hash.equals(a.hash))
101
- throw new TypeError('Hash mismatch');
102
- else hash = a.hash;
103
- }
104
- if (a.output) {
105
- if (
106
- a.output.length !== 25 ||
107
- a.output[0] !== OPS.OP_DUP ||
108
- a.output[1] !== OPS.OP_HASH160 ||
109
- a.output[2] !== 0x14 ||
110
- a.output[23] !== OPS.OP_EQUALVERIFY ||
111
- a.output[24] !== OPS.OP_CHECKSIG
112
- )
113
- throw new TypeError('Output is invalid');
114
- const hash2 = a.output.slice(3, 23);
115
- if (hash.length > 0 && !hash.equals(hash2))
116
- throw new TypeError('Hash mismatch');
117
- else hash = hash2;
118
- }
119
- if (a.pubkey) {
120
- const pkh = bcrypto.hash160(a.pubkey);
121
- if (hash.length > 0 && !hash.equals(pkh))
122
- throw new TypeError('Hash mismatch');
123
- else hash = pkh;
124
- }
125
- if (a.input) {
126
- const chunks = _chunks();
127
- if (chunks.length !== 2) throw new TypeError('Input is invalid');
128
- if (!bscript.isCanonicalScriptSignature(chunks[0]))
129
- throw new TypeError('Input has invalid signature');
130
- if (!(0, types_1.isPoint)(chunks[1]))
131
- throw new TypeError('Input has invalid pubkey');
132
- if (a.signature && !a.signature.equals(chunks[0]))
133
- throw new TypeError('Signature mismatch');
134
- if (a.pubkey && !a.pubkey.equals(chunks[1]))
135
- throw new TypeError('Pubkey mismatch');
136
- const pkh = bcrypto.hash160(chunks[1]);
137
- if (hash.length > 0 && !hash.equals(pkh))
138
- throw new TypeError('Hash mismatch');
139
- }
140
- }
141
- return Object.assign(o, a);
142
- }
143
- exports.p2pkh = p2pkh;
@@ -1,10 +0,0 @@
1
- import { Payment, PaymentOpts } from './index';
2
- /**
3
- * Creates a Pay-to-Script-Hash (P2SH) payment object.
4
- *
5
- * @param a - The payment object containing the necessary data.
6
- * @param opts - Optional payment options.
7
- * @returns The P2SH payment object.
8
- * @throws {TypeError} If the required data is not provided or if the data is invalid.
9
- */
10
- export declare function p2sh(a: Payment, opts?: PaymentOpts): Payment;
@@ -1,10 +0,0 @@
1
- import { Payment, PaymentOpts } from './index';
2
- /**
3
- * Creates a Pay-to-Taproot (P2TR) payment object.
4
- *
5
- * @param a - The payment object containing the necessary data for P2TR.
6
- * @param opts - Optional payment options.
7
- * @returns The P2TR payment object.
8
- * @throws {TypeError} If the provided data is invalid or insufficient.
9
- */
10
- export declare function p2tr(a: Payment, opts?: PaymentOpts): Payment;
@@ -1,10 +0,0 @@
1
- import { Payment, PaymentOpts } from './index';
2
- /**
3
- * Creates a pay-to-witness-public-key-hash (p2wpkh) payment object.
4
- *
5
- * @param a - The payment object containing the necessary data.
6
- * @param opts - Optional payment options.
7
- * @returns The p2wpkh payment object.
8
- * @throws {TypeError} If the required data is missing or invalid.
9
- */
10
- export declare function p2wpkh(a: Payment, opts?: PaymentOpts): Payment;
@@ -1,10 +0,0 @@
1
- import { Payment, PaymentOpts } from './index';
2
- /**
3
- * Creates a Pay-to-Witness-Script-Hash (P2WSH) payment object.
4
- *
5
- * @param a - The payment object containing the necessary data.
6
- * @param opts - Optional payment options.
7
- * @returns The P2WSH payment object.
8
- * @throws {TypeError} If the required data is missing or invalid.
9
- */
10
- export declare function p2wsh(a: Payment, opts?: PaymentOpts): Payment;
@@ -1,42 +0,0 @@
1
- /// <reference types="node" />
2
- import { Taptree } from '../types';
3
- import { PsbtInput, PsbtOutput, TapLeaf } from 'bip174/src/lib/interfaces';
4
- export declare const toXOnly: (pubKey: Buffer) => Buffer;
5
- /**
6
- * Default tapscript finalizer. It searches for the `tapLeafHashToFinalize` if provided.
7
- * Otherwise it will search for the tapleaf that has at least one signature and has the shortest path.
8
- * @param inputIndex the position of the PSBT input.
9
- * @param input the PSBT input.
10
- * @param tapLeafHashToFinalize optional, if provided the finalizer will search for a tapleaf that has this hash
11
- * and will try to build the finalScriptWitness.
12
- * @returns the finalScriptWitness or throws an exception if no tapleaf found.
13
- */
14
- export declare function tapScriptFinalizer(inputIndex: number, input: PsbtInput, tapLeafHashToFinalize?: Buffer): {
15
- finalScriptWitness: Buffer | undefined;
16
- };
17
- export declare function serializeTaprootSignature(sig: Buffer, sighashType?: number): Buffer;
18
- export declare function isTaprootInput(input: PsbtInput): boolean;
19
- export declare function isTaprootOutput(output: PsbtOutput, script?: Buffer): boolean;
20
- export declare function checkTaprootInputFields(inputData: PsbtInput, newInputData: PsbtInput, action: string): void;
21
- export declare function checkTaprootOutputFields(outputData: PsbtOutput, newOutputData: PsbtOutput, action: string): void;
22
- export declare function tweakInternalPubKey(inputIndex: number, input: PsbtInput): Buffer;
23
- /**
24
- * Convert a binary tree to a BIP371 type list. Each element of the list is (according to BIP371):
25
- * One or more tuples representing the depth, leaf version, and script for a leaf in the Taproot tree,
26
- * allowing the entire tree to be reconstructed. The tuples must be in depth first search order so that
27
- * the tree is correctly reconstructed.
28
- * @param tree the binary tap tree
29
- * @returns a list of BIP 371 tapleaves
30
- */
31
- export declare function tapTreeToList(tree: Taptree): TapLeaf[];
32
- /**
33
- * Convert a BIP371 TapLeaf list to a TapTree (binary).
34
- * @param leaves a list of tapleaves where each element of the list is (according to BIP371):
35
- * One or more tuples representing the depth, leaf version, and script for a leaf in the Taproot tree,
36
- * allowing the entire tree to be reconstructed. The tuples must be in depth first search order so that
37
- * the tree is correctly reconstructed.
38
- * @returns the corresponding taptree, or throws an exception if the tree cannot be reconstructed
39
- */
40
- export declare function tapTreeFromList(leaves?: TapLeaf[]): Taptree;
41
- export declare function checkTaprootInputForSigs(input: PsbtInput, action: string): boolean;
42
- export declare function getTapKeySigFromWitness(finalScriptWitness?: Buffer): Buffer | undefined;
@@ -1,64 +0,0 @@
1
- /// <reference types="node" />
2
- import { PartialSig, PsbtInput } from 'bip174/src/lib/interfaces';
3
- export declare const isP2MS: (script: Buffer) => boolean;
4
- export declare const isP2PK: (script: Buffer) => boolean;
5
- export declare const isP2PKH: (script: Buffer) => boolean;
6
- export declare const isP2WPKH: (script: Buffer) => boolean;
7
- export declare const isP2WSHScript: (script: Buffer) => boolean;
8
- export declare const isP2SHScript: (script: Buffer) => boolean;
9
- export declare const isP2TR: (script: Buffer) => boolean;
10
- /**
11
- * Converts a witness stack to a script witness.
12
- * @param witness The witness stack to convert.
13
- * @returns The script witness as a Buffer.
14
- */
15
- /**
16
- * Converts a witness stack to a script witness.
17
- * @param witness The witness stack to convert.
18
- * @returns The converted script witness.
19
- */
20
- export declare function witnessStackToScriptWitness(witness: Buffer[]): Buffer;
21
- /**
22
- * Finds the position of a public key in a script.
23
- * @param pubkey The public key to search for.
24
- * @param script The script to search in.
25
- * @returns The index of the public key in the script, or -1 if not found.
26
- * @throws {Error} If there is an unknown script error.
27
- */
28
- export declare function pubkeyPositionInScript(pubkey: Buffer, script: Buffer): number;
29
- /**
30
- * Checks if a public key is present in a script.
31
- * @param pubkey The public key to check.
32
- * @param script The script to search in.
33
- * @returns A boolean indicating whether the public key is present in the script.
34
- */
35
- export declare function pubkeyInScript(pubkey: Buffer, script: Buffer): boolean;
36
- /**
37
- * Checks if an input contains a signature for a specific action.
38
- * @param input - The input to check.
39
- * @param action - The action to check for.
40
- * @returns A boolean indicating whether the input contains a signature for the specified action.
41
- */
42
- export declare function checkInputForSig(input: PsbtInput, action: string): boolean;
43
- type SignatureDecodeFunc = (buffer: Buffer) => {
44
- signature: Buffer;
45
- hashType: number;
46
- };
47
- /**
48
- * Determines if a given action is allowed for a signature block.
49
- * @param signature - The signature block.
50
- * @param signatureDecodeFn - The function used to decode the signature.
51
- * @param action - The action to be checked.
52
- * @returns True if the action is allowed, false otherwise.
53
- */
54
- export declare function signatureBlocksAction(signature: Buffer, signatureDecodeFn: SignatureDecodeFunc, action: string): boolean;
55
- /**
56
- * Retrieves the partial signatures (Psigs) from the input's final scripts.
57
- * Psigs are extracted from both the final scriptSig and final scriptWitness of the input.
58
- * Only canonical script signatures are considered.
59
- *
60
- * @param input - The PsbtInput object representing the input.
61
- * @returns An array of PartialSig objects containing the extracted Psigs.
62
- */
63
- export declare function getPsigsFromInputFinalScripts(input: PsbtInput): PartialSig[];
64
- export {};
@@ -1,191 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.getPsigsFromInputFinalScripts =
4
- exports.signatureBlocksAction =
5
- exports.checkInputForSig =
6
- exports.pubkeyInScript =
7
- exports.pubkeyPositionInScript =
8
- exports.witnessStackToScriptWitness =
9
- exports.isP2TR =
10
- exports.isP2SHScript =
11
- exports.isP2WSHScript =
12
- exports.isP2WPKH =
13
- exports.isP2PKH =
14
- exports.isP2PK =
15
- exports.isP2MS =
16
- void 0;
17
- const varuint = require('bip174/src/lib/converter/varint');
18
- const bscript = require('../script');
19
- const transaction_1 = require('../transaction');
20
- const crypto_1 = require('../crypto');
21
- const payments = require('../payments');
22
- function isPaymentFactory(payment) {
23
- return script => {
24
- try {
25
- payment({ output: script });
26
- return true;
27
- } catch (err) {
28
- return false;
29
- }
30
- };
31
- }
32
- exports.isP2MS = isPaymentFactory(payments.p2ms);
33
- exports.isP2PK = isPaymentFactory(payments.p2pk);
34
- exports.isP2PKH = isPaymentFactory(payments.p2pkh);
35
- exports.isP2WPKH = isPaymentFactory(payments.p2wpkh);
36
- exports.isP2WSHScript = isPaymentFactory(payments.p2wsh);
37
- exports.isP2SHScript = isPaymentFactory(payments.p2sh);
38
- exports.isP2TR = isPaymentFactory(payments.p2tr);
39
- /**
40
- * Converts a witness stack to a script witness.
41
- * @param witness The witness stack to convert.
42
- * @returns The script witness as a Buffer.
43
- */
44
- /**
45
- * Converts a witness stack to a script witness.
46
- * @param witness The witness stack to convert.
47
- * @returns The converted script witness.
48
- */
49
- function witnessStackToScriptWitness(witness) {
50
- let buffer = Buffer.allocUnsafe(0);
51
- function writeSlice(slice) {
52
- buffer = Buffer.concat([buffer, Buffer.from(slice)]);
53
- }
54
- function writeVarInt(i) {
55
- const currentLen = buffer.length;
56
- const varintLen = varuint.encodingLength(i);
57
- buffer = Buffer.concat([buffer, Buffer.allocUnsafe(varintLen)]);
58
- varuint.encode(i, buffer, currentLen);
59
- }
60
- function writeVarSlice(slice) {
61
- writeVarInt(slice.length);
62
- writeSlice(slice);
63
- }
64
- function writeVector(vector) {
65
- writeVarInt(vector.length);
66
- vector.forEach(writeVarSlice);
67
- }
68
- writeVector(witness);
69
- return buffer;
70
- }
71
- exports.witnessStackToScriptWitness = witnessStackToScriptWitness;
72
- /**
73
- * Finds the position of a public key in a script.
74
- * @param pubkey The public key to search for.
75
- * @param script The script to search in.
76
- * @returns The index of the public key in the script, or -1 if not found.
77
- * @throws {Error} If there is an unknown script error.
78
- */
79
- function pubkeyPositionInScript(pubkey, script) {
80
- const pubkeyHash = (0, crypto_1.hash160)(pubkey);
81
- const pubkeyXOnly = pubkey.slice(1, 33); // slice before calling?
82
- const decompiled = bscript.decompile(script);
83
- if (decompiled === null) throw new Error('Unknown script error');
84
- return decompiled.findIndex(element => {
85
- if (typeof element === 'number') return false;
86
- return (
87
- element.equals(pubkey) ||
88
- element.equals(pubkeyHash) ||
89
- element.equals(pubkeyXOnly)
90
- );
91
- });
92
- }
93
- exports.pubkeyPositionInScript = pubkeyPositionInScript;
94
- /**
95
- * Checks if a public key is present in a script.
96
- * @param pubkey The public key to check.
97
- * @param script The script to search in.
98
- * @returns A boolean indicating whether the public key is present in the script.
99
- */
100
- function pubkeyInScript(pubkey, script) {
101
- return pubkeyPositionInScript(pubkey, script) !== -1;
102
- }
103
- exports.pubkeyInScript = pubkeyInScript;
104
- /**
105
- * Checks if an input contains a signature for a specific action.
106
- * @param input - The input to check.
107
- * @param action - The action to check for.
108
- * @returns A boolean indicating whether the input contains a signature for the specified action.
109
- */
110
- function checkInputForSig(input, action) {
111
- const pSigs = extractPartialSigs(input);
112
- return pSigs.some(pSig =>
113
- signatureBlocksAction(pSig, bscript.signature.decode, action),
114
- );
115
- }
116
- exports.checkInputForSig = checkInputForSig;
117
- /**
118
- * Determines if a given action is allowed for a signature block.
119
- * @param signature - The signature block.
120
- * @param signatureDecodeFn - The function used to decode the signature.
121
- * @param action - The action to be checked.
122
- * @returns True if the action is allowed, false otherwise.
123
- */
124
- function signatureBlocksAction(signature, signatureDecodeFn, action) {
125
- const { hashType } = signatureDecodeFn(signature);
126
- const whitelist = [];
127
- const isAnyoneCanPay =
128
- hashType & transaction_1.Transaction.SIGHASH_ANYONECANPAY;
129
- if (isAnyoneCanPay) whitelist.push('addInput');
130
- const hashMod = hashType & 0x1f;
131
- switch (hashMod) {
132
- case transaction_1.Transaction.SIGHASH_ALL:
133
- break;
134
- case transaction_1.Transaction.SIGHASH_SINGLE:
135
- case transaction_1.Transaction.SIGHASH_NONE:
136
- whitelist.push('addOutput');
137
- whitelist.push('setInputSequence');
138
- break;
139
- }
140
- if (whitelist.indexOf(action) === -1) {
141
- return true;
142
- }
143
- return false;
144
- }
145
- exports.signatureBlocksAction = signatureBlocksAction;
146
- /**
147
- * Extracts the signatures from a PsbtInput object.
148
- * If the input has partial signatures, it returns an array of the signatures.
149
- * If the input does not have partial signatures, it checks if it has a finalScriptSig or finalScriptWitness.
150
- * If it does, it extracts the signatures from the final scripts and returns them.
151
- * If none of the above conditions are met, it returns an empty array.
152
- *
153
- * @param input - The PsbtInput object from which to extract the signatures.
154
- * @returns An array of signatures extracted from the PsbtInput object.
155
- */
156
- function extractPartialSigs(input) {
157
- let pSigs = [];
158
- if ((input.partialSig || []).length === 0) {
159
- if (!input.finalScriptSig && !input.finalScriptWitness) return [];
160
- pSigs = getPsigsFromInputFinalScripts(input);
161
- } else {
162
- pSigs = input.partialSig;
163
- }
164
- return pSigs.map(p => p.signature);
165
- }
166
- /**
167
- * Retrieves the partial signatures (Psigs) from the input's final scripts.
168
- * Psigs are extracted from both the final scriptSig and final scriptWitness of the input.
169
- * Only canonical script signatures are considered.
170
- *
171
- * @param input - The PsbtInput object representing the input.
172
- * @returns An array of PartialSig objects containing the extracted Psigs.
173
- */
174
- function getPsigsFromInputFinalScripts(input) {
175
- const scriptItems = !input.finalScriptSig
176
- ? []
177
- : bscript.decompile(input.finalScriptSig) || [];
178
- const witnessItems = !input.finalScriptWitness
179
- ? []
180
- : bscript.decompile(input.finalScriptWitness) || [];
181
- return scriptItems
182
- .concat(witnessItems)
183
- .filter(item => {
184
- return (
185
- Buffer.isBuffer(item) &&
186
- bscript.isCanonicalScriptSignature(item)
187
- );
188
- })
189
- .map(sig => ({ signature: sig }));
190
- }
191
- exports.getPsigsFromInputFinalScripts = getPsigsFromInputFinalScripts;
@@ -1,29 +0,0 @@
1
- /// <reference types="node" />
2
- /**
3
- * Calculates the encoding length of a number used for push data in Bitcoin transactions.
4
- * @param i The number to calculate the encoding length for.
5
- * @returns The encoding length of the number.
6
- */
7
- export declare function encodingLength(i: number): number;
8
- /**
9
- * Encodes a number into a buffer using a variable-length encoding scheme.
10
- * The encoded buffer is written starting at the specified offset.
11
- * Returns the size of the encoded buffer.
12
- *
13
- * @param buffer - The buffer to write the encoded data into.
14
- * @param num - The number to encode.
15
- * @param offset - The offset at which to start writing the encoded buffer.
16
- * @returns The size of the encoded buffer.
17
- */
18
- export declare function encode(buffer: Buffer, num: number, offset: number): number;
19
- /**
20
- * Decodes a buffer and returns information about the opcode, number, and size.
21
- * @param buffer - The buffer to decode.
22
- * @param offset - The offset within the buffer to start decoding.
23
- * @returns An object containing the opcode, number, and size, or null if decoding fails.
24
- */
25
- export declare function decode(buffer: Buffer, offset: number): {
26
- opcode: number;
27
- number: number;
28
- size: number;
29
- } | null;
package/src/script.d.ts DELETED
@@ -1,42 +0,0 @@
1
- /// <reference types="node" />
2
- import { OPS } from './ops';
3
- import { Stack } from './payments';
4
- import * as scriptNumber from './script_number';
5
- import * as scriptSignature from './script_signature';
6
- export { OPS };
7
- export declare function isPushOnly(value: Stack): boolean;
8
- export declare function countNonPushOnlyOPs(value: Stack): number;
9
- /**
10
- * Compiles an array of chunks into a Buffer.
11
- *
12
- * @param chunks - The array of chunks to compile.
13
- * @returns The compiled Buffer.
14
- * @throws Error if the compilation fails.
15
- */
16
- export declare function compile(chunks: Buffer | Stack): Buffer;
17
- export declare function decompile(buffer: Buffer | Array<number | Buffer>): Array<number | Buffer> | null;
18
- /**
19
- * Converts the given chunks into an ASM (Assembly) string representation.
20
- * If the chunks parameter is a Buffer, it will be decompiled into a Stack before conversion.
21
- * @param chunks - The chunks to convert into ASM.
22
- * @returns The ASM string representation of the chunks.
23
- */
24
- export declare function toASM(chunks: Buffer | Array<number | Buffer>): string;
25
- /**
26
- * Converts an ASM string to a Buffer.
27
- * @param asm The ASM string to convert.
28
- * @returns The converted Buffer.
29
- */
30
- export declare function fromASM(asm: string): Buffer;
31
- /**
32
- * Converts the given chunks into a stack of buffers.
33
- *
34
- * @param chunks - The chunks to convert.
35
- * @returns The stack of buffers.
36
- */
37
- export declare function toStack(chunks: Buffer | Array<number | Buffer>): Buffer[];
38
- export declare function isCanonicalPubKey(buffer: Buffer): boolean;
39
- export declare function isDefinedHashType(hashType: number): boolean;
40
- export declare function isCanonicalScriptSignature(buffer: Buffer): boolean;
41
- export declare const number: typeof scriptNumber;
42
- export declare const signature: typeof scriptSignature;
@@ -1,19 +0,0 @@
1
- /// <reference types="node" />
2
- /**
3
- * Decodes a script number from a buffer.
4
- *
5
- * @param buffer - The buffer containing the script number.
6
- * @param maxLength - The maximum length of the script number. Defaults to 4.
7
- * @param minimal - Whether the script number should be minimal. Defaults to true.
8
- * @returns The decoded script number.
9
- * @throws {TypeError} If the script number overflows the maximum length.
10
- * @throws {Error} If the script number is not minimally encoded when minimal is true.
11
- */
12
- export declare function decode(buffer: Buffer, maxLength?: number, minimal?: boolean): number;
13
- /**
14
- * Encodes a number into a Buffer using a specific format.
15
- *
16
- * @param _number - The number to encode.
17
- * @returns The encoded number as a Buffer.
18
- */
19
- export declare function encode(_number: number): Buffer;
@@ -1,21 +0,0 @@
1
- /// <reference types="node" />
2
- interface ScriptSignature {
3
- signature: Buffer;
4
- hashType: number;
5
- }
6
- /**
7
- * Decodes a buffer into a ScriptSignature object.
8
- * @param buffer - The buffer to decode.
9
- * @returns The decoded ScriptSignature object.
10
- * @throws Error if the hashType is invalid.
11
- */
12
- export declare function decode(buffer: Buffer): ScriptSignature;
13
- /**
14
- * Encodes a signature and hash type into a buffer.
15
- * @param signature - The signature to encode.
16
- * @param hashType - The hash type to encode.
17
- * @returns The encoded buffer.
18
- * @throws Error if the hashType is invalid.
19
- */
20
- export declare function encode(signature: Buffer, hashType: number): Buffer;
21
- export {};