@bsv/sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (464) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +40 -0
  2. package/.github/ISSUE_TEMPLATE/discussion.md +24 -0
  3. package/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +23 -0
  4. package/CHANGELOG.md +72 -0
  5. package/CONTRIBUTING.md +85 -0
  6. package/LICENSE.txt +28 -0
  7. package/README.md +87 -0
  8. package/ROADMAP.md +3 -0
  9. package/dist/cjs/mod.js +25 -0
  10. package/dist/cjs/mod.js.map +1 -0
  11. package/dist/cjs/package.json +42 -0
  12. package/dist/cjs/src/compat/BIP39.js +272 -0
  13. package/dist/cjs/src/compat/BIP39.js.map +1 -0
  14. package/dist/cjs/src/compat/BSM.js +77 -0
  15. package/dist/cjs/src/compat/BSM.js.map +1 -0
  16. package/dist/cjs/src/compat/ECIES.js +483 -0
  17. package/dist/cjs/src/compat/ECIES.js.map +1 -0
  18. package/dist/cjs/src/compat/HD.js +326 -0
  19. package/dist/cjs/src/compat/HD.js.map +1 -0
  20. package/dist/cjs/src/compat/Mnemonic.js +298 -0
  21. package/dist/cjs/src/compat/Mnemonic.js.map +1 -0
  22. package/dist/cjs/src/compat/bip-39-wordlist-en.js +2057 -0
  23. package/dist/cjs/src/compat/bip-39-wordlist-en.js.map +1 -0
  24. package/dist/cjs/src/compat/index.js +37 -0
  25. package/dist/cjs/src/compat/index.js.map +1 -0
  26. package/dist/cjs/src/messages/EncryptedMessage.js +69 -0
  27. package/dist/cjs/src/messages/EncryptedMessage.js.map +1 -0
  28. package/dist/cjs/src/messages/SignedMessage.js +85 -0
  29. package/dist/cjs/src/messages/SignedMessage.js.map +1 -0
  30. package/dist/cjs/src/messages/index.js +29 -0
  31. package/dist/cjs/src/messages/index.js.map +1 -0
  32. package/dist/cjs/src/primitives/AESGCM.js +384 -0
  33. package/dist/cjs/src/primitives/AESGCM.js.map +1 -0
  34. package/dist/cjs/src/primitives/BasePoint.js +19 -0
  35. package/dist/cjs/src/primitives/BasePoint.js.map +1 -0
  36. package/dist/cjs/src/primitives/BigNumber.js +4269 -0
  37. package/dist/cjs/src/primitives/BigNumber.js.map +1 -0
  38. package/dist/cjs/src/primitives/Curve.js +1126 -0
  39. package/dist/cjs/src/primitives/Curve.js.map +1 -0
  40. package/dist/cjs/src/primitives/DRBG.js +99 -0
  41. package/dist/cjs/src/primitives/DRBG.js.map +1 -0
  42. package/dist/cjs/src/primitives/ECDSA.js +169 -0
  43. package/dist/cjs/src/primitives/ECDSA.js.map +1 -0
  44. package/dist/cjs/src/primitives/Hash.js +1332 -0
  45. package/dist/cjs/src/primitives/Hash.js.map +1 -0
  46. package/dist/cjs/src/primitives/JacobianPoint.js +400 -0
  47. package/dist/cjs/src/primitives/JacobianPoint.js.map +1 -0
  48. package/dist/cjs/src/primitives/K256.js +111 -0
  49. package/dist/cjs/src/primitives/K256.js.map +1 -0
  50. package/dist/cjs/src/primitives/Mersenne.js +118 -0
  51. package/dist/cjs/src/primitives/Mersenne.js.map +1 -0
  52. package/dist/cjs/src/primitives/MontgomoryMethod.js +150 -0
  53. package/dist/cjs/src/primitives/MontgomoryMethod.js.map +1 -0
  54. package/dist/cjs/src/primitives/Point.js +819 -0
  55. package/dist/cjs/src/primitives/Point.js.map +1 -0
  56. package/dist/cjs/src/primitives/PrivateKey.js +190 -0
  57. package/dist/cjs/src/primitives/PrivateKey.js.map +1 -0
  58. package/dist/cjs/src/primitives/PublicKey.js +151 -0
  59. package/dist/cjs/src/primitives/PublicKey.js.map +1 -0
  60. package/dist/cjs/src/primitives/Random.js +57 -0
  61. package/dist/cjs/src/primitives/Random.js.map +1 -0
  62. package/dist/cjs/src/primitives/ReductionContext.js +490 -0
  63. package/dist/cjs/src/primitives/ReductionContext.js.map +1 -0
  64. package/dist/cjs/src/primitives/Signature.js +220 -0
  65. package/dist/cjs/src/primitives/Signature.js.map +1 -0
  66. package/dist/cjs/src/primitives/SymmetricKey.js +69 -0
  67. package/dist/cjs/src/primitives/SymmetricKey.js.map +1 -0
  68. package/dist/cjs/src/primitives/TransactionSignature.js +172 -0
  69. package/dist/cjs/src/primitives/TransactionSignature.js.map +1 -0
  70. package/dist/cjs/src/primitives/index.js +45 -0
  71. package/dist/cjs/src/primitives/index.js.map +1 -0
  72. package/dist/cjs/src/primitives/utils.js +615 -0
  73. package/dist/cjs/src/primitives/utils.js.map +1 -0
  74. package/dist/cjs/src/script/LockingScript.js +35 -0
  75. package/dist/cjs/src/script/LockingScript.js.map +1 -0
  76. package/dist/cjs/src/script/OP.js +208 -0
  77. package/dist/cjs/src/script/OP.js.map +1 -0
  78. package/dist/cjs/src/script/Script.js +429 -0
  79. package/dist/cjs/src/script/Script.js.map +1 -0
  80. package/dist/cjs/src/script/ScriptChunk.js +3 -0
  81. package/dist/cjs/src/script/ScriptChunk.js.map +1 -0
  82. package/dist/cjs/src/script/ScriptTemplate.js +3 -0
  83. package/dist/cjs/src/script/ScriptTemplate.js.map +1 -0
  84. package/dist/cjs/src/script/Spend.js +1252 -0
  85. package/dist/cjs/src/script/Spend.js.map +1 -0
  86. package/dist/cjs/src/script/UnlockingScript.js +35 -0
  87. package/dist/cjs/src/script/UnlockingScript.js.map +1 -0
  88. package/dist/cjs/src/script/index.js +32 -0
  89. package/dist/cjs/src/script/index.js.map +1 -0
  90. package/dist/cjs/src/script/templates/P2PKH.js +98 -0
  91. package/dist/cjs/src/script/templates/P2PKH.js.map +1 -0
  92. package/dist/cjs/src/script/templates/RPuzzle.js +125 -0
  93. package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -0
  94. package/dist/cjs/src/script/templates/index.js +11 -0
  95. package/dist/cjs/src/script/templates/index.js.map +1 -0
  96. package/dist/cjs/src/transaction/Broadcaster.js +3 -0
  97. package/dist/cjs/src/transaction/Broadcaster.js.map +1 -0
  98. package/dist/cjs/src/transaction/ChainTracker.js +3 -0
  99. package/dist/cjs/src/transaction/ChainTracker.js.map +1 -0
  100. package/dist/cjs/src/transaction/FeeModel.js +3 -0
  101. package/dist/cjs/src/transaction/FeeModel.js.map +1 -0
  102. package/dist/cjs/src/transaction/MerklePath.js +239 -0
  103. package/dist/cjs/src/transaction/MerklePath.js.map +1 -0
  104. package/dist/cjs/src/transaction/Transaction.js +557 -0
  105. package/dist/cjs/src/transaction/Transaction.js.map +1 -0
  106. package/dist/cjs/src/transaction/TransactionInput.js +3 -0
  107. package/dist/cjs/src/transaction/TransactionInput.js.map +1 -0
  108. package/dist/cjs/src/transaction/TransactionOutput.js +3 -0
  109. package/dist/cjs/src/transaction/TransactionOutput.js.map +1 -0
  110. package/dist/cjs/src/transaction/broadcasters/ARC.js +101 -0
  111. package/dist/cjs/src/transaction/broadcasters/ARC.js.map +1 -0
  112. package/dist/cjs/src/transaction/broadcasters/index.js +9 -0
  113. package/dist/cjs/src/transaction/broadcasters/index.js.map +1 -0
  114. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js +69 -0
  115. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -0
  116. package/dist/cjs/src/transaction/fee-models/index.js +9 -0
  117. package/dist/cjs/src/transaction/fee-models/index.js.map +1 -0
  118. package/dist/cjs/src/transaction/index.js +11 -0
  119. package/dist/cjs/src/transaction/index.js.map +1 -0
  120. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
  121. package/dist/esm/mod.js +9 -0
  122. package/dist/esm/mod.js.map +1 -0
  123. package/dist/esm/src/compat/BIP39.js +272 -0
  124. package/dist/esm/src/compat/BIP39.js.map +1 -0
  125. package/dist/esm/src/compat/BSM.js +45 -0
  126. package/dist/esm/src/compat/BSM.js.map +1 -0
  127. package/dist/esm/src/compat/ECIES.js +454 -0
  128. package/dist/esm/src/compat/ECIES.js.map +1 -0
  129. package/dist/esm/src/compat/HD.js +304 -0
  130. package/dist/esm/src/compat/HD.js.map +1 -0
  131. package/dist/esm/src/compat/Mnemonic.js +272 -0
  132. package/dist/esm/src/compat/Mnemonic.js.map +1 -0
  133. package/dist/esm/src/compat/bip-39-wordlist-en.js +2054 -0
  134. package/dist/esm/src/compat/bip-39-wordlist-en.js.map +1 -0
  135. package/dist/esm/src/compat/index.js +5 -0
  136. package/dist/esm/src/compat/index.js.map +1 -0
  137. package/dist/esm/src/messages/EncryptedMessage.js +61 -0
  138. package/dist/esm/src/messages/EncryptedMessage.js.map +1 -0
  139. package/dist/esm/src/messages/SignedMessage.js +77 -0
  140. package/dist/esm/src/messages/SignedMessage.js.map +1 -0
  141. package/dist/esm/src/messages/index.js +3 -0
  142. package/dist/esm/src/messages/index.js.map +1 -0
  143. package/dist/esm/src/primitives/AESGCM.js +371 -0
  144. package/dist/esm/src/primitives/AESGCM.js.map +1 -0
  145. package/dist/esm/src/primitives/BasePoint.js +16 -0
  146. package/dist/esm/src/primitives/BasePoint.js.map +1 -0
  147. package/dist/esm/src/primitives/BigNumber.js +4304 -0
  148. package/dist/esm/src/primitives/BigNumber.js.map +1 -0
  149. package/dist/esm/src/primitives/Curve.js +1141 -0
  150. package/dist/esm/src/primitives/Curve.js.map +1 -0
  151. package/dist/esm/src/primitives/DRBG.js +98 -0
  152. package/dist/esm/src/primitives/DRBG.js.map +1 -0
  153. package/dist/esm/src/primitives/ECDSA.js +161 -0
  154. package/dist/esm/src/primitives/ECDSA.js.map +1 -0
  155. package/dist/esm/src/primitives/Hash.js +1336 -0
  156. package/dist/esm/src/primitives/Hash.js.map +1 -0
  157. package/dist/esm/src/primitives/JacobianPoint.js +398 -0
  158. package/dist/esm/src/primitives/JacobianPoint.js.map +1 -0
  159. package/dist/esm/src/primitives/K256.js +105 -0
  160. package/dist/esm/src/primitives/K256.js.map +1 -0
  161. package/dist/esm/src/primitives/Mersenne.js +117 -0
  162. package/dist/esm/src/primitives/Mersenne.js.map +1 -0
  163. package/dist/esm/src/primitives/MontgomoryMethod.js +149 -0
  164. package/dist/esm/src/primitives/MontgomoryMethod.js.map +1 -0
  165. package/dist/esm/src/primitives/Point.js +816 -0
  166. package/dist/esm/src/primitives/Point.js.map +1 -0
  167. package/dist/esm/src/primitives/PrivateKey.js +184 -0
  168. package/dist/esm/src/primitives/PrivateKey.js.map +1 -0
  169. package/dist/esm/src/primitives/PublicKey.js +145 -0
  170. package/dist/esm/src/primitives/PublicKey.js.map +1 -0
  171. package/dist/esm/src/primitives/Random.js +56 -0
  172. package/dist/esm/src/primitives/Random.js.map +1 -0
  173. package/dist/esm/src/primitives/ReductionContext.js +486 -0
  174. package/dist/esm/src/primitives/ReductionContext.js.map +1 -0
  175. package/dist/esm/src/primitives/Signature.js +223 -0
  176. package/dist/esm/src/primitives/Signature.js.map +1 -0
  177. package/dist/esm/src/primitives/SymmetricKey.js +63 -0
  178. package/dist/esm/src/primitives/SymmetricKey.js.map +1 -0
  179. package/dist/esm/src/primitives/TransactionSignature.js +144 -0
  180. package/dist/esm/src/primitives/TransactionSignature.js.map +1 -0
  181. package/dist/esm/src/primitives/index.js +9 -0
  182. package/dist/esm/src/primitives/index.js.map +1 -0
  183. package/dist/esm/src/primitives/utils.js +601 -0
  184. package/dist/esm/src/primitives/utils.js.map +1 -0
  185. package/dist/esm/src/script/LockingScript.js +29 -0
  186. package/dist/esm/src/script/LockingScript.js.map +1 -0
  187. package/dist/esm/src/script/OP.js +206 -0
  188. package/dist/esm/src/script/OP.js.map +1 -0
  189. package/dist/esm/src/script/Script.js +424 -0
  190. package/dist/esm/src/script/Script.js.map +1 -0
  191. package/dist/esm/src/script/ScriptChunk.js +2 -0
  192. package/dist/esm/src/script/ScriptChunk.js.map +1 -0
  193. package/dist/esm/src/script/ScriptTemplate.js +2 -0
  194. package/dist/esm/src/script/ScriptTemplate.js.map +1 -0
  195. package/dist/esm/src/script/Spend.js +1240 -0
  196. package/dist/esm/src/script/Spend.js.map +1 -0
  197. package/dist/esm/src/script/UnlockingScript.js +29 -0
  198. package/dist/esm/src/script/UnlockingScript.js.map +1 -0
  199. package/dist/esm/src/script/index.js +7 -0
  200. package/dist/esm/src/script/index.js.map +1 -0
  201. package/dist/esm/src/script/templates/P2PKH.js +92 -0
  202. package/dist/esm/src/script/templates/P2PKH.js.map +1 -0
  203. package/dist/esm/src/script/templates/RPuzzle.js +119 -0
  204. package/dist/esm/src/script/templates/RPuzzle.js.map +1 -0
  205. package/dist/esm/src/script/templates/index.js +3 -0
  206. package/dist/esm/src/script/templates/index.js.map +1 -0
  207. package/dist/esm/src/transaction/Broadcaster.js +2 -0
  208. package/dist/esm/src/transaction/Broadcaster.js.map +1 -0
  209. package/dist/esm/src/transaction/ChainTracker.js +2 -0
  210. package/dist/esm/src/transaction/ChainTracker.js.map +1 -0
  211. package/dist/esm/src/transaction/FeeModel.js +2 -0
  212. package/dist/esm/src/transaction/FeeModel.js.map +1 -0
  213. package/dist/esm/src/transaction/MerklePath.js +237 -0
  214. package/dist/esm/src/transaction/MerklePath.js.map +1 -0
  215. package/dist/esm/src/transaction/Transaction.js +557 -0
  216. package/dist/esm/src/transaction/Transaction.js.map +1 -0
  217. package/dist/esm/src/transaction/TransactionInput.js +2 -0
  218. package/dist/esm/src/transaction/TransactionInput.js.map +1 -0
  219. package/dist/esm/src/transaction/TransactionOutput.js +2 -0
  220. package/dist/esm/src/transaction/TransactionOutput.js.map +1 -0
  221. package/dist/esm/src/transaction/broadcasters/ARC.js +100 -0
  222. package/dist/esm/src/transaction/broadcasters/ARC.js.map +1 -0
  223. package/dist/esm/src/transaction/broadcasters/index.js +2 -0
  224. package/dist/esm/src/transaction/broadcasters/index.js.map +1 -0
  225. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js +71 -0
  226. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -0
  227. package/dist/esm/src/transaction/fee-models/index.js +2 -0
  228. package/dist/esm/src/transaction/fee-models/index.js.map +1 -0
  229. package/dist/esm/src/transaction/index.js +3 -0
  230. package/dist/esm/src/transaction/index.js.map +1 -0
  231. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
  232. package/dist/types/mod.d.ts +9 -0
  233. package/dist/types/mod.d.ts.map +1 -0
  234. package/dist/types/src/compat/BIP39.d.ts +132 -0
  235. package/dist/types/src/compat/BIP39.d.ts.map +1 -0
  236. package/dist/types/src/compat/BSM.d.ts +28 -0
  237. package/dist/types/src/compat/BSM.d.ts.map +1 -0
  238. package/dist/types/src/compat/ECIES.d.ts +62 -0
  239. package/dist/types/src/compat/ECIES.d.ts.map +1 -0
  240. package/dist/types/src/compat/HD.d.ts +117 -0
  241. package/dist/types/src/compat/HD.d.ts.map +1 -0
  242. package/dist/types/src/compat/Mnemonic.d.ts +132 -0
  243. package/dist/types/src/compat/Mnemonic.d.ts.map +1 -0
  244. package/dist/types/src/compat/bip-39-wordlist-en.d.ts +5 -0
  245. package/dist/types/src/compat/bip-39-wordlist-en.d.ts.map +1 -0
  246. package/dist/types/src/compat/index.d.ts +5 -0
  247. package/dist/types/src/compat/index.d.ts.map +1 -0
  248. package/dist/types/src/messages/EncryptedMessage.d.ts +20 -0
  249. package/dist/types/src/messages/EncryptedMessage.d.ts.map +1 -0
  250. package/dist/types/src/messages/SignedMessage.d.ts +21 -0
  251. package/dist/types/src/messages/SignedMessage.d.ts.map +1 -0
  252. package/dist/types/src/messages/index.d.ts +3 -0
  253. package/dist/types/src/messages/index.d.ts.map +1 -0
  254. package/dist/types/src/primitives/AESGCM.d.ts +14 -0
  255. package/dist/types/src/primitives/AESGCM.d.ts.map +1 -0
  256. package/dist/types/src/primitives/BasePoint.d.ts +22 -0
  257. package/dist/types/src/primitives/BasePoint.d.ts.map +1 -0
  258. package/dist/types/src/primitives/BigNumber.d.ts +1895 -0
  259. package/dist/types/src/primitives/BigNumber.d.ts.map +1 -0
  260. package/dist/types/src/primitives/Curve.d.ts +55 -0
  261. package/dist/types/src/primitives/Curve.d.ts.map +1 -0
  262. package/dist/types/src/primitives/DRBG.d.ts +54 -0
  263. package/dist/types/src/primitives/DRBG.d.ts.map +1 -0
  264. package/dist/types/src/primitives/ECDSA.d.ts +39 -0
  265. package/dist/types/src/primitives/ECDSA.d.ts.map +1 -0
  266. package/dist/types/src/primitives/Hash.d.ts +411 -0
  267. package/dist/types/src/primitives/Hash.d.ts.map +1 -0
  268. package/dist/types/src/primitives/JacobianPoint.d.ts +164 -0
  269. package/dist/types/src/primitives/JacobianPoint.d.ts.map +1 -0
  270. package/dist/types/src/primitives/K256.d.ts +53 -0
  271. package/dist/types/src/primitives/K256.d.ts.map +1 -0
  272. package/dist/types/src/primitives/Mersenne.d.ts +72 -0
  273. package/dist/types/src/primitives/Mersenne.d.ts.map +1 -0
  274. package/dist/types/src/primitives/MontgomoryMethod.d.ts +96 -0
  275. package/dist/types/src/primitives/MontgomoryMethod.d.ts.map +1 -0
  276. package/dist/types/src/primitives/Point.d.ts +303 -0
  277. package/dist/types/src/primitives/Point.d.ts.map +1 -0
  278. package/dist/types/src/primitives/PrivateKey.d.ts +143 -0
  279. package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -0
  280. package/dist/types/src/primitives/PublicKey.d.ts +108 -0
  281. package/dist/types/src/primitives/PublicKey.d.ts.map +1 -0
  282. package/dist/types/src/primitives/Random.d.ts +14 -0
  283. package/dist/types/src/primitives/Random.d.ts.map +1 -0
  284. package/dist/types/src/primitives/ReductionContext.d.ts +308 -0
  285. package/dist/types/src/primitives/ReductionContext.d.ts.map +1 -0
  286. package/dist/types/src/primitives/Signature.d.ts +100 -0
  287. package/dist/types/src/primitives/Signature.d.ts.map +1 -0
  288. package/dist/types/src/primitives/SymmetricKey.d.ts +44 -0
  289. package/dist/types/src/primitives/SymmetricKey.d.ts.map +1 -0
  290. package/dist/types/src/primitives/TransactionSignature.d.ts +36 -0
  291. package/dist/types/src/primitives/TransactionSignature.d.ts.map +1 -0
  292. package/dist/types/src/primitives/index.d.ts +9 -0
  293. package/dist/types/src/primitives/index.d.ts.map +1 -0
  294. package/dist/types/src/primitives/utils.d.ts +118 -0
  295. package/dist/types/src/primitives/utils.d.ts.map +1 -0
  296. package/dist/types/src/script/LockingScript.d.ts +25 -0
  297. package/dist/types/src/script/LockingScript.d.ts.map +1 -0
  298. package/dist/types/src/script/OP.d.ts +193 -0
  299. package/dist/types/src/script/OP.d.ts.map +1 -0
  300. package/dist/types/src/script/Script.d.ts +148 -0
  301. package/dist/types/src/script/Script.d.ts.map +1 -0
  302. package/dist/types/src/script/ScriptChunk.d.ts +8 -0
  303. package/dist/types/src/script/ScriptChunk.d.ts.map +1 -0
  304. package/dist/types/src/script/ScriptTemplate.d.ts +33 -0
  305. package/dist/types/src/script/ScriptTemplate.d.ts.map +1 -0
  306. package/dist/types/src/script/Spend.d.ts +103 -0
  307. package/dist/types/src/script/Spend.d.ts.map +1 -0
  308. package/dist/types/src/script/UnlockingScript.d.ts +25 -0
  309. package/dist/types/src/script/UnlockingScript.d.ts.map +1 -0
  310. package/dist/types/src/script/index.d.ts +8 -0
  311. package/dist/types/src/script/index.d.ts.map +1 -0
  312. package/dist/types/src/script/templates/P2PKH.d.ts +37 -0
  313. package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -0
  314. package/dist/types/src/script/templates/RPuzzle.d.ts +47 -0
  315. package/dist/types/src/script/templates/RPuzzle.d.ts.map +1 -0
  316. package/dist/types/src/script/templates/index.d.ts +3 -0
  317. package/dist/types/src/script/templates/index.d.ts.map +1 -0
  318. package/dist/types/src/transaction/Broadcaster.d.ts +39 -0
  319. package/dist/types/src/transaction/Broadcaster.d.ts.map +1 -0
  320. package/dist/types/src/transaction/ChainTracker.d.ts +23 -0
  321. package/dist/types/src/transaction/ChainTracker.d.ts.map +1 -0
  322. package/dist/types/src/transaction/FeeModel.d.ts +12 -0
  323. package/dist/types/src/transaction/FeeModel.d.ts.map +1 -0
  324. package/dist/types/src/transaction/MerklePath.d.ts +91 -0
  325. package/dist/types/src/transaction/MerklePath.d.ts.map +1 -0
  326. package/dist/types/src/transaction/Transaction.d.ts +181 -0
  327. package/dist/types/src/transaction/Transaction.d.ts.map +1 -0
  328. package/dist/types/src/transaction/TransactionInput.d.ts +63 -0
  329. package/dist/types/src/transaction/TransactionInput.d.ts.map +1 -0
  330. package/dist/types/src/transaction/TransactionOutput.d.ts +36 -0
  331. package/dist/types/src/transaction/TransactionOutput.d.ts.map +1 -0
  332. package/dist/types/src/transaction/broadcasters/ARC.d.ts +28 -0
  333. package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +1 -0
  334. package/dist/types/src/transaction/broadcasters/index.d.ts +2 -0
  335. package/dist/types/src/transaction/broadcasters/index.d.ts.map +1 -0
  336. package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts +26 -0
  337. package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts.map +1 -0
  338. package/dist/types/src/transaction/fee-models/index.d.ts +2 -0
  339. package/dist/types/src/transaction/fee-models/index.d.ts.map +1 -0
  340. package/dist/types/src/transaction/index.d.ts +7 -0
  341. package/dist/types/src/transaction/index.d.ts.map +1 -0
  342. package/dist/types/tsconfig.types.tsbuildinfo +1 -0
  343. package/docs/README.md +9 -0
  344. package/docs/compat.md +2856 -0
  345. package/docs/getting-started/COMMONJS.md +94 -0
  346. package/docs/getting-started/REACT-TS.md +131 -0
  347. package/docs/getting-started/TS-NODE.md +106 -0
  348. package/docs/getting-started/VUE.md +103 -0
  349. package/docs/messages.md +146 -0
  350. package/docs/primitives.md +7440 -0
  351. package/docs/script.md +766 -0
  352. package/docs/transaction.md +741 -0
  353. package/jest.config.js +6 -0
  354. package/mod.ts +8 -0
  355. package/package.json +137 -0
  356. package/src/compat/BSM.ts +51 -0
  357. package/src/compat/ECIES.ts +557 -0
  358. package/src/compat/HD.ts +348 -0
  359. package/src/compat/Mnemonic.ts +295 -0
  360. package/src/compat/__tests/BSM.test.ts +38 -0
  361. package/src/compat/__tests/ECIES.test.ts +90 -0
  362. package/src/compat/__tests/HD.test.ts +405 -0
  363. package/src/compat/__tests/Mnemonic.test.ts +177 -0
  364. package/src/compat/__tests/Mnemonic.vectors.ts +172 -0
  365. package/src/compat/bip-39-wordlist-en.ts +2053 -0
  366. package/src/compat/index.ts +4 -0
  367. package/src/messages/EncryptedMessage.ts +70 -0
  368. package/src/messages/SignedMessage.ts +87 -0
  369. package/src/messages/__tests/EncryptedMessage.test.ts +36 -0
  370. package/src/messages/__tests/SignedMessage.test.ts +53 -0
  371. package/src/messages/index.ts +2 -0
  372. package/src/primitives/AESGCM.ts +479 -0
  373. package/src/primitives/BasePoint.ts +21 -0
  374. package/src/primitives/BigNumber.ts +4619 -0
  375. package/src/primitives/Curve.ts +1163 -0
  376. package/src/primitives/DRBG.ts +102 -0
  377. package/src/primitives/ECDSA.ts +164 -0
  378. package/src/primitives/Hash.ts +1420 -0
  379. package/src/primitives/JacobianPoint.ts +410 -0
  380. package/src/primitives/K256.ts +116 -0
  381. package/src/primitives/Mersenne.ts +123 -0
  382. package/src/primitives/MontgomoryMethod.ts +160 -0
  383. package/src/primitives/Point.ts +852 -0
  384. package/src/primitives/PrivateKey.ts +195 -0
  385. package/src/primitives/PublicKey.ts +154 -0
  386. package/src/primitives/Random.ts +55 -0
  387. package/src/primitives/ReductionContext.ts +528 -0
  388. package/src/primitives/Signature.ts +235 -0
  389. package/src/primitives/SymmetricKey.ts +75 -0
  390. package/src/primitives/TransactionSignature.ts +189 -0
  391. package/src/primitives/__tests/AESGCM.test.ts +338 -0
  392. package/src/primitives/__tests/BRC42.private.vectors.ts +33 -0
  393. package/src/primitives/__tests/BRC42.public.vectors.ts +33 -0
  394. package/src/primitives/__tests/BigNumber.arithmatic.test.ts +572 -0
  395. package/src/primitives/__tests/BigNumber.binary.test.ts +203 -0
  396. package/src/primitives/__tests/BigNumber.constructor.test.ts +176 -0
  397. package/src/primitives/__tests/BigNumber.dhGroup.test.ts +18 -0
  398. package/src/primitives/__tests/BigNumber.fixtures.ts +264 -0
  399. package/src/primitives/__tests/BigNumber.serializers.test.ts +157 -0
  400. package/src/primitives/__tests/BigNumber.utils.test.ts +347 -0
  401. package/src/primitives/__tests/Curve.unit.test.ts +192 -0
  402. package/src/primitives/__tests/DRBG.test.ts +18 -0
  403. package/src/primitives/__tests/DRBG.vectors.ts +167 -0
  404. package/src/primitives/__tests/ECDH.test.ts +31 -0
  405. package/src/primitives/__tests/ECDSA.test.ts +58 -0
  406. package/src/primitives/__tests/HMAC.test.ts +59 -0
  407. package/src/primitives/__tests/Hash.test.ts +121 -0
  408. package/src/primitives/__tests/PBKDF2.vectors.ts +119 -0
  409. package/src/primitives/__tests/PrivateKey.test.ts +17 -0
  410. package/src/primitives/__tests/PublicKey.test.ts +66 -0
  411. package/src/primitives/__tests/Random.test.ts +14 -0
  412. package/src/primitives/__tests/Reader.test.ts +296 -0
  413. package/src/primitives/__tests/ReductionContext.test.ts +279 -0
  414. package/src/primitives/__tests/SymmetricKey.test.ts +58 -0
  415. package/src/primitives/__tests/SymmetricKey.vectors.ts +40 -0
  416. package/src/primitives/__tests/Writer.test.ts +198 -0
  417. package/src/primitives/__tests/sighash.vectors.ts +3503 -0
  418. package/src/primitives/__tests/utils.test.ts +108 -0
  419. package/src/primitives/index.ts +8 -0
  420. package/src/primitives/utils.ts +665 -0
  421. package/src/script/LockingScript.ts +30 -0
  422. package/src/script/OP.ts +219 -0
  423. package/src/script/Script.ts +426 -0
  424. package/src/script/ScriptChunk.ts +7 -0
  425. package/src/script/ScriptTemplate.ts +36 -0
  426. package/src/script/Spend.ts +1379 -0
  427. package/src/script/UnlockingScript.ts +30 -0
  428. package/src/script/__tests/Script.test.ts +369 -0
  429. package/src/script/__tests/Spend.test.ts +248 -0
  430. package/src/script/__tests/script.invalid.vectors.ts +925 -0
  431. package/src/script/__tests/script.valid.vectors.ts +1120 -0
  432. package/src/script/__tests/scriptFromVector.ts +42 -0
  433. package/src/script/__tests/spend.valid.vectors.ts +2288 -0
  434. package/src/script/index.ts +7 -0
  435. package/src/script/templates/P2PKH.ts +109 -0
  436. package/src/script/templates/RPuzzle.ts +140 -0
  437. package/src/script/templates/index.ts +2 -0
  438. package/src/transaction/Broadcaster.ts +42 -0
  439. package/src/transaction/ChainTracker.ts +22 -0
  440. package/src/transaction/FeeModel.ts +13 -0
  441. package/src/transaction/MerklePath.ts +259 -0
  442. package/src/transaction/Transaction.ts +602 -0
  443. package/src/transaction/TransactionInput.ts +63 -0
  444. package/src/transaction/TransactionOutput.ts +37 -0
  445. package/src/transaction/__tests/MerklePath.test.ts +181 -0
  446. package/src/transaction/__tests/Transaction.test.ts +413 -0
  447. package/src/transaction/__tests/bigtx.vectors.ts +4 -0
  448. package/src/transaction/__tests/bump.invalid.vectors.ts +8 -0
  449. package/src/transaction/__tests/bump.valid.vectors.ts +4 -0
  450. package/src/transaction/__tests/tx.invalid.vectors.ts +281 -0
  451. package/src/transaction/__tests/tx.valid.vectors.ts +364 -0
  452. package/src/transaction/broadcasters/ARC.ts +106 -0
  453. package/src/transaction/broadcasters/__tests/ARC.test.ts +115 -0
  454. package/src/transaction/broadcasters/index.ts +1 -0
  455. package/src/transaction/fee-models/SatoshisPerKilobyte.ts +71 -0
  456. package/src/transaction/fee-models/index.ts +1 -0
  457. package/src/transaction/index.ts +6 -0
  458. package/ts2md.json +5 -0
  459. package/tsconfig.base.json +26 -0
  460. package/tsconfig.cjs.json +11 -0
  461. package/tsconfig.eslint.json +12 -0
  462. package/tsconfig.esm.json +9 -0
  463. package/tsconfig.json +17 -0
  464. package/tsconfig.types.json +11 -0
@@ -0,0 +1,39 @@
1
+ import Transaction from './Transaction.js';
2
+ /**
3
+ * Defines the structure of a successful broadcast response.
4
+ *
5
+ * @interface
6
+ * @property {string} status - The status of the response, indicating success.
7
+ * @property {string} txid - The transaction ID of the broadcasted transaction.
8
+ * @property {string} message - A human-readable success message.
9
+ */
10
+ export interface BroadcastResponse {
11
+ status: 'success';
12
+ txid: string;
13
+ message: string;
14
+ }
15
+ /**
16
+ * Defines the structure of a failed broadcast response.
17
+ *
18
+ * @interface
19
+ * @property {string} status - The status of the response, indicating an error.
20
+ * @property {string} code - A machine-readable error code representing the type of error encountered.
21
+ * @property {string} description - A detailed description of the error.
22
+ */
23
+ export interface BroadcastFailure {
24
+ status: 'error';
25
+ code: string;
26
+ description: string;
27
+ }
28
+ /**
29
+ * Represents the interface for a transaction broadcaster.
30
+ * This interface defines a standard method for broadcasting transactions.
31
+ *
32
+ * @interface
33
+ * @property {function} broadcast - A function that takes a Transaction object and returns a promise.
34
+ * The promise resolves to either a BroadcastResponse or a BroadcastFailure.
35
+ */
36
+ export interface Broadcaster {
37
+ broadcast: (transaction: Transaction) => Promise<BroadcastResponse | BroadcastFailure>;
38
+ }
39
+ //# sourceMappingURL=Broadcaster.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Broadcaster.d.ts","sourceRoot":"","sources":["../../../../src/transaction/Broadcaster.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,kBAAkB,CAAA;AAE1C;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,SAAS,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,CAAC,WAAW,EAAE,WAAW,KACpC,OAAO,CAAC,iBAAiB,GAAG,gBAAgB,CAAC,CAAA;CAC9C"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The Chain Tracker is responsible for verifying the validity of a given Merkle root
3
+ * for a specific block height within the blockchain.
4
+ *
5
+ * Chain Trackers ensure the integrity of the blockchain by
6
+ * validating new headers against the chain's history. They use accumulated
7
+ * proof-of-work and protocol adherence as metrics to assess the legitimacy of blocks.
8
+ *
9
+ * @interface ChainTracker
10
+ * @function isValidRootForHeight - A method to verify the validity of a Merkle root
11
+ * for a given block height.
12
+ *
13
+ * @example
14
+ * const chainTracker = {
15
+ * isValidRootForHeight: async (root, height) => {
16
+ * // Implementation to check if the Merkle root is valid for the specified block height.
17
+ * }
18
+ * };
19
+ */
20
+ export default interface ChainTracker {
21
+ isValidRootForHeight: (root: string, height: number) => Promise<boolean>;
22
+ }
23
+ //# sourceMappingURL=ChainTracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChainTracker.d.ts","sourceRoot":"","sources":["../../../../src/transaction/ChainTracker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,WAAW,YAAY;IACnC,oBAAoB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CACzE"}
@@ -0,0 +1,12 @@
1
+ import Transaction from './Transaction.js';
2
+ /**
3
+ * Represents the interface for a transaction fee model.
4
+ * This interface defines a standard method for computing a fee when given a transaction.
5
+ *
6
+ * @interface
7
+ * @property {function} computeFee - A function that takes a Transaction object and returns a BigNumber representing the number of satoshis the transaction should cost.
8
+ */
9
+ export default interface FeeModel {
10
+ computeFee: (transaction: Transaction) => Promise<number>;
11
+ }
12
+ //# sourceMappingURL=FeeModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FeeModel.d.ts","sourceRoot":"","sources":["../../../../src/transaction/FeeModel.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,kBAAkB,CAAA;AAG1C;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,WAAW,QAAQ;IAC/B,UAAU,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CAC1D"}
@@ -0,0 +1,91 @@
1
+ import { Reader } from '../primitives/utils.js';
2
+ import ChainTracker from './ChainTracker.js';
3
+ /**
4
+ * Represents a Merkle Path, which is used to provide a compact proof of inclusion for a
5
+ * transaction in a block. This class encapsulates all the details required for creating
6
+ * and verifying Merkle Proofs.
7
+ *
8
+ * @class MerklePath
9
+ * @property {number} blockHeight - The height of the block in which the transaction is included.
10
+ * @property {Array<Array<{offset: number, hash?: string, txid?: boolean, duplicate?: boolean}>>} path -
11
+ * A tree structure representing the Merkle Path, with each level containing information
12
+ * about the nodes involved in constructing the proof.
13
+ *
14
+ * @example
15
+ * // Creating and verifying a Merkle Path
16
+ * const merklePath = MerklePath.fromHex('...');
17
+ * const isValid = merklePath.verify(txid, chainTracker);
18
+ *
19
+ * @description
20
+ * The MerklePath class is useful for verifying transactions in a lightweight and efficient manner without
21
+ * needing the entire block data. This class offers functionalities for creating, converting,
22
+ * and verifying these proofs.
23
+ */
24
+ export default class MerklePath {
25
+ blockHeight: number;
26
+ path: Array<Array<{
27
+ offset: number;
28
+ hash?: string;
29
+ txid?: boolean;
30
+ duplicate?: boolean;
31
+ }>>;
32
+ /**
33
+ * Creates a MerklePath instance from a hexadecimal string.
34
+ *
35
+ * @static
36
+ * @param {string} hex - The hexadecimal string representation of the Merkle Path.
37
+ * @returns {MerklePath} - A new MerklePath instance.
38
+ */
39
+ static fromHex(hex: string): MerklePath;
40
+ static fromReader(reader: Reader): MerklePath;
41
+ /**
42
+ * Creates a MerklePath instance from a binary array.
43
+ *
44
+ * @static
45
+ * @param {number[]} bump - The binary array representation of the Merkle Path.
46
+ * @returns {MerklePath} - A new MerklePath instance.
47
+ */
48
+ static fromBinary(bump: number[]): MerklePath;
49
+ constructor(blockHeight: number, path: Array<Array<{
50
+ offset: number;
51
+ hash?: string;
52
+ txid?: boolean;
53
+ duplicate?: boolean;
54
+ }>>);
55
+ /**
56
+ * Converts the MerklePath to a binary array format.
57
+ *
58
+ * @returns {number[]} - The binary array representation of the Merkle Path.
59
+ */
60
+ toBinary(): number[];
61
+ /**
62
+ * Converts the MerklePath to a hexadecimal string format.
63
+ *
64
+ * @returns {string} - The hexadecimal string representation of the Merkle Path.
65
+ */
66
+ toHex(): string;
67
+ /**
68
+ * Computes the Merkle root from the provided transaction ID.
69
+ *
70
+ * @param {string} txid - The transaction ID to compute the Merkle root for. If not provided, the root will be computed from an unspecified branch, and not all branches will be validated!
71
+ * @returns {string} - The computed Merkle root as a hexadecimal string.
72
+ * @throws {Error} - If the transaction ID is not part of the Merkle Path.
73
+ */
74
+ computeRoot(txid?: string): string;
75
+ /**
76
+ * Verifies if the given transaction ID is part of the Merkle tree at the specified block height.
77
+ *
78
+ * @param {string} txid - The transaction ID to verify.
79
+ * @param {ChainTracker} chainTracker - The ChainTracker instance used to verify the Merkle root.
80
+ * @returns {boolean} - True if the transaction ID is valid within the Merkle Path at the specified block height.
81
+ */
82
+ verify(txid: string, chainTracker: ChainTracker): Promise<boolean>;
83
+ /**
84
+ * Combines this MerklePath with another to create a compound proof.
85
+ *
86
+ * @param {MerklePath} other - Another MerklePath to combine with this path.
87
+ * @throws {Error} - If the paths have different block heights or roots.
88
+ */
89
+ combine(other: MerklePath): void;
90
+ }
91
+ //# sourceMappingURL=MerklePath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MerklePath.d.ts","sourceRoot":"","sources":["../../../../src/transaction/MerklePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA0B,MAAM,wBAAwB,CAAA;AAEvE,OAAO,YAAY,MAAM,mBAAmB,CAAA;AAE5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC;QAChB,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,SAAS,CAAC,EAAE,OAAO,CAAA;KACpB,CAAC,CAAC,CAAA;IAEH;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,CAAE,GAAG,EAAE,MAAM,GAAG,UAAU;IAIxC,MAAM,CAAC,UAAU,CAAE,MAAM,EAAE,MAAM,GAAG,UAAU;IAgC9C;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAE,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU;gBAKjC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC;QAClD,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,SAAS,CAAC,EAAE,OAAO,CAAA;KACpB,CAAC,CAAC;IAsCH;;;;OAIG;IACH,QAAQ,IAAK,MAAM,EAAE;IA0BrB;;;;OAIG;IACH,KAAK,IAAK,MAAM;IAIhB;;;;;;OAMG;IACH,WAAW,CAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM;IAgCnC;;;;;;OAMG;IACG,MAAM,CAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAMzE;;;;;OAKG;IACH,OAAO,CAAE,KAAK,EAAE,UAAU,GAAG,IAAI;CA4BlC"}
@@ -0,0 +1,181 @@
1
+ import TransactionInput from './TransactionInput.js';
2
+ import TransactionOutput from './TransactionOutput.js';
3
+ import FeeModel from './FeeModel.js';
4
+ import { Broadcaster, BroadcastResponse, BroadcastFailure } from './Broadcaster.js';
5
+ import MerklePath from './MerklePath.js';
6
+ import ChainTracker from './ChainTracker.js';
7
+ /**
8
+ * Represents a complete Bitcoin transaction. This class encapsulates all the details
9
+ * required for creating, signing, and processing a Bitcoin transaction, including
10
+ * inputs, outputs, and various transaction-related methods.
11
+ *
12
+ * @class Transaction
13
+ * @property {number} version - The version number of the transaction. Used to specify
14
+ * which set of rules this transaction follows.
15
+ * @property {TransactionInput[]} inputs - An array of TransactionInput objects, representing
16
+ * the inputs for the transaction. Each input references a previous transaction's output.
17
+ * @property {TransactionOutput[]} outputs - An array of TransactionOutput objects, representing
18
+ * the outputs for the transaction. Each output specifies the amount of satoshis to be
19
+ * transferred and the conditions under which they can be spent.
20
+ * @property {number} lockTime - The lock time of the transaction. If non-zero, it specifies the
21
+ * earliest time or block height at which the transaction can be added to the block chain.
22
+ * @property {Record<string, any>} metadata - A key-value store for attaching additional data to
23
+ * the transaction object, not included in the transaction itself. Useful for adding descriptions, internal reference numbers, or other information.
24
+ * @property {MerkleProof} [merkleProof] - Optional. A merkle proof demonstrating the transaction's
25
+ * inclusion in a block. Useful for transaction verification using SPV.
26
+ *
27
+ * @example
28
+ * // Creating a new transaction
29
+ * let tx = new Transaction();
30
+ * tx.addInput(...);
31
+ * tx.addOutput(...);
32
+ * await tx.fee();
33
+ * await tx.sign();
34
+ * await tx.broadcast();
35
+ *
36
+ * @description
37
+ * The Transaction class provides comprehensive
38
+ * functionality to handle various aspects of transaction creation, including
39
+ * adding inputs and outputs, computing fees, signing the transaction, and
40
+ * generating its binary or hexadecimal representation.
41
+ */
42
+ export default class Transaction {
43
+ version: number;
44
+ inputs: TransactionInput[];
45
+ outputs: TransactionOutput[];
46
+ lockTime: number;
47
+ metadata: Record<string, any>;
48
+ merklePath?: MerklePath;
49
+ /**
50
+ * Creates a new transaction, linked to its inputs and their associated merkle paths, from a BEEF (BRC-62) structure.
51
+ * @param beef A binary representation of a transaction in BEEF format.
52
+ * @returns An anchored transaction, linked to its associated inputs populated with merkle paths.
53
+ */
54
+ static fromBEEF(beef: number[]): Transaction;
55
+ private static fromReader;
56
+ /**
57
+ * Creates a Transaction instance from a binary array.
58
+ *
59
+ * @static
60
+ * @param {number[]} bin - The binary array representation of the transaction.
61
+ * @returns {Transaction} - A new Transaction instance.
62
+ */
63
+ static fromBinary(bin: number[]): Transaction;
64
+ /**
65
+ * Creates a Transaction instance from a hexadecimal string.
66
+ *
67
+ * @static
68
+ * @param {string} hex - The hexadecimal string representation of the transaction.
69
+ * @returns {Transaction} - A new Transaction instance.
70
+ */
71
+ static fromHex(hex: string): Transaction;
72
+ /**
73
+ * Creates a Transaction instance from a hexadecimal string encoded BEEF.
74
+ *
75
+ * @static
76
+ * @param {string} hex - The hexadecimal string representation of the transaction BEEF.
77
+ * @returns {Transaction} - A new Transaction instance.
78
+ */
79
+ static fromHexBEEF(hex: string): Transaction;
80
+ constructor(version?: number, inputs?: TransactionInput[], outputs?: TransactionOutput[], lockTime?: number, metadata?: Record<string, any>, merklePath?: MerklePath);
81
+ /**
82
+ * Adds a new input to the transaction.
83
+ *
84
+ * @param {TransactionInput} input - The TransactionInput object to add to the transaction.
85
+ * @throws {Error} - If the input does not have a sourceTXID or sourceTransaction defined.
86
+ */
87
+ addInput(input: TransactionInput): void;
88
+ /**
89
+ * Adds a new output to the transaction.
90
+ *
91
+ * @param {TransactionOutput} output - The TransactionOutput object to add to the transaction.
92
+ */
93
+ addOutput(output: TransactionOutput): void;
94
+ /**
95
+ * Updates the transaction's metadata.
96
+ *
97
+ * @param {Record<string, any>} metadata - The metadata object to merge into the existing metadata.
98
+ */
99
+ updateMetadata(metadata: Record<string, any>): void;
100
+ /**
101
+ * Computes fees prior to signing.
102
+ * If no fee model is provided, uses a SatoshisPerKilobyte fee model that pays 10 sat/kb.
103
+ *
104
+ * @param model - The initialized fee model to use
105
+ * @param changeDistribution - Specifies how the change should be distributed
106
+ * amongst the change outputs
107
+ *
108
+ * TODO: Benford's law change distribution.
109
+ */
110
+ fee(model?: FeeModel, changeDistribution?: 'equal' | 'random'): Promise<void>;
111
+ /**
112
+ * Signs a transaction, hydrating all its unlocking scripts based on the provided script templates where they are available.
113
+ */
114
+ sign(): Promise<void>;
115
+ /**
116
+ * Broadcasts a transaction.
117
+ *
118
+ * @param broadcaster The Broadcaster instance wwhere the transaction will be sent
119
+ * @returns A BroadcastResponse or BroadcastFailure from the Broadcaster
120
+ */
121
+ broadcast(broadcaster: Broadcaster): Promise<BroadcastResponse | BroadcastFailure>;
122
+ /**
123
+ * Converts the transaction to a binary array format.
124
+ *
125
+ * @returns {number[]} - The binary array representation of the transaction.
126
+ */
127
+ toBinary(): number[];
128
+ /**
129
+ * Converts the transaction to a BRC-30 EF format.
130
+ *
131
+ * @returns {number[]} - The BRC-30 EF representation of the transaction.
132
+ */
133
+ toEF(): number[];
134
+ /**
135
+ * Converts the transaction to a hexadecimal string EF.
136
+ *
137
+ * @returns {string} - The hexadecimal string representation of the transaction EF.
138
+ */
139
+ toHexEF(): string;
140
+ /**
141
+ * Converts the transaction to a hexadecimal string format.
142
+ *
143
+ * @returns {string} - The hexadecimal string representation of the transaction.
144
+ */
145
+ toHex(): string;
146
+ /**
147
+ * Converts the transaction to a hexadecimal string BEEF.
148
+ *
149
+ * @returns {string} - The hexadecimal string representation of the transaction BEEF.
150
+ */
151
+ toHexBEEF(): string;
152
+ /**
153
+ * Calculates the transaction's hash.
154
+ *
155
+ * @param {'hex' | undefined} enc - The encoding to use for the hash. If 'hex', returns a hexadecimal string; otherwise returns a binary array.
156
+ * @returns {string | number[]} - The hash of the transaction in the specified format.
157
+ */
158
+ hash(enc?: 'hex'): number[] | string;
159
+ /**
160
+ * Calculates the transaction's ID.
161
+ *
162
+ * @param {'hex' | undefined} enc - The encoding to use for the ID. If 'hex', returns a hexadecimal string; otherwise returns a binary array.
163
+ * @returns {string | number[]} - The ID of the transaction in the specified format.
164
+ */
165
+ id(enc?: 'hex'): number[] | string;
166
+ /**
167
+ * Verifies the legitimacy of the Bitcoin transaction according to the rules of SPV by ensuring all the input transactions link back to valid block headers, the chain of spends for all inputs are valid, and the sum of inputs is not less than the sum of outputs.
168
+ *
169
+ * @param chainTracker - An instance of ChainTracker, a Bitcoin block header tracker. If the value is set to 'scripts only', headers will not be verified.
170
+ *
171
+ * @returns Whether the transaction is valid according to the rules of SPV.
172
+ */
173
+ verify(chainTracker: ChainTracker | 'scripts only'): Promise<boolean>;
174
+ /**
175
+ * Serializes this transaction, together with its inputs and the respective merkle proofs, into the BEEF (BRC-62) format. This enables efficient verification of its compliance with the rules of SPV.
176
+ *
177
+ * @returns The serialized BEEF structure
178
+ */
179
+ toBEEF(): number[];
180
+ }
181
+ //# sourceMappingURL=Transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Transaction.d.ts","sourceRoot":"","sources":["../../../../src/transaction/Transaction.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,uBAAuB,CAAA;AACpD,OAAO,iBAAiB,MAAM,wBAAwB,CAAA;AAMtD,OAAO,QAAQ,MAAM,eAAe,CAAA;AAEpC,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnF,OAAO,UAAU,MAAM,iBAAiB,CAAA;AAExC,OAAO,YAAY,MAAM,mBAAmB,CAAA;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,gBAAgB,EAAE,CAAA;IAC1B,OAAO,EAAE,iBAAiB,EAAE,CAAA;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC7B,UAAU,CAAC,EAAE,UAAU,CAAA;IAEvB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,WAAW;IA4D5C,OAAO,CAAC,MAAM,CAAC,UAAU;IAkCzB;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,WAAW;IAK7C;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW;IAIxC;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW;gBAK1C,OAAO,GAAE,MAAU,EACnB,MAAM,GAAE,gBAAgB,EAAO,EAC/B,OAAO,GAAE,iBAAiB,EAAO,EACjC,QAAQ,GAAE,MAAU,EACpB,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EAClC,UAAU,CAAC,EAAE,UAAU;IAUzB;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI;IAcvC;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAI1C;;;;OAIG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAOnD;;;;;;;;;OASG;IACG,GAAG,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,kBAAkB,GAAE,OAAO,GAAG,QAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiD5F;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAmB3B;;;;;OAKG;IACG,SAAS,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,GAAG,gBAAgB,CAAC;IAIxF;;;;OAIG;IACH,QAAQ,IAAI,MAAM,EAAE;IA2BpB;;;;OAIG;IACH,IAAI,IAAI,MAAM,EAAE;IA+BhB;;;;OAIG;IACH,OAAO,IAAI,MAAM;IAIjB;;;;OAIG;IACH,KAAK,IAAI,MAAM;IAIf;;;;OAIG;IACH,SAAS,IAAI,MAAM;IAInB;;;;;OAKG;IACH,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,GAAG,MAAM;IAIpC;;;;;OAKG;IACH,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,GAAG,MAAM;IASlC;;;;;;OAMG;IACG,MAAM,CAAC,YAAY,EAAE,YAAY,GAAG,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IA+D3E;;;;OAIG;IACH,MAAM,IAAI,MAAM,EAAE;CAoEnB"}
@@ -0,0 +1,63 @@
1
+ import UnlockingScript from '../script/UnlockingScript.js';
2
+ import Transaction from './Transaction.js';
3
+ /**
4
+ * Represents an input to a Bitcoin transaction.
5
+ * This interface defines the structure and components required to construct
6
+ * a transaction input in the Bitcoin blockchain.
7
+ *
8
+ * @interface TransactionInput
9
+ * @property {Transaction} [sourceTransaction] - Optional. The source transaction
10
+ * from which this input is derived. This is the transaction whose output
11
+ * is being spent by this input. Preferably provided if available.
12
+ * @property {string} [sourceTXID] - Optional. The transaction ID (TXID) of the source
13
+ * transaction. Required if the source transaction itself is not provided.
14
+ * This uniquely identifies the transaction within the blockchain.
15
+ * @property {number} sourceOutputIndex - The index of the output in the source transaction
16
+ * that this input is spending. It is zero-based, indicating the position of the
17
+ * output in the array of outputs of the source transaction.
18
+ * @property {UnlockingScript} [unlockingScript] - Optional. The script that 'unlocks' the
19
+ * source output for spending. This script typically contains signatures and
20
+ * public keys that evidence the ownership of the output.
21
+ * @property {Object} [unlockingScriptTemplate] - Optional. A template for generating the
22
+ * unlocking script. Useful when the unlocking script needs to be generated
23
+ * dynamically.
24
+ * @property {Function} unlockingScriptTemplate.sign - A function that, when given the
25
+ * current transaction and the index of this input, returns a Promise that
26
+ * resolves to the UnlockingScript.
27
+ * @property {Function} unlockingScriptTemplate.estimateLength - A function that estimates
28
+ * the length of the unlocking script, given the transaction and the input index.
29
+ * @property {number} sequence - A sequence number for the input. Used to enable
30
+ * updates to this input. If set to a non-final value (less than 0xFFFFFFFF),
31
+ * it indicates that the input may be replaced in the future.
32
+ *
33
+ * @example
34
+ * // Creating a simple transaction input
35
+ * let txInput = {
36
+ * sourceTXID: '123abc...',
37
+ * sourceOutputIndex: 0,
38
+ * sequence: 0xFFFFFFFF
39
+ * };
40
+ *
41
+ * // Using an unlocking script template
42
+ * txInput.unlockingScriptTemplate = {
43
+ * sign: async (tx, index) => { ... },
44
+ * estimateLength: async (tx, index) => { ... }
45
+ * };
46
+ *
47
+ * @description
48
+ * This interface links an input to a
49
+ * previous output and provides mechanisms (through unlocking scripts) to authorize the
50
+ * spending of that output.
51
+ */
52
+ export default interface TransactionInput {
53
+ sourceTransaction?: Transaction;
54
+ sourceTXID?: string;
55
+ sourceOutputIndex: number;
56
+ unlockingScript?: UnlockingScript;
57
+ unlockingScriptTemplate?: {
58
+ sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
59
+ estimateLength: (tx: Transaction, inputIndex: number) => Promise<number>;
60
+ };
61
+ sequence: number;
62
+ }
63
+ //# sourceMappingURL=TransactionInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactionInput.d.ts","sourceRoot":"","sources":["../../../../src/transaction/TransactionInput.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,8BAA8B,CAAA;AAC1D,OAAO,WAAW,MAAM,kBAAkB,CAAA;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,CAAC,OAAO,WAAW,gBAAgB;IACvC,iBAAiB,CAAC,EAAE,WAAW,CAAA;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,iBAAiB,EAAE,MAAM,CAAA;IACzB,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,uBAAuB,CAAC,EAAE;QACxB,IAAI,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,eAAe,CAAC,CAAA;QACvE,cAAc,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;KACzE,CAAA;IACD,QAAQ,EAAE,MAAM,CAAA;CACjB"}
@@ -0,0 +1,36 @@
1
+ import LockingScript from '../script/LockingScript.js';
2
+ /**
3
+ * Represents an output in a Bitcoin transaction.
4
+ * This interface defines the structure and components necessary to construct
5
+ * a transaction output, which secures owned Bitcoins to be unlocked later.
6
+ *
7
+ * @interface TransactionOutput
8
+ * @property {number} [satoshis] - Optional. The amount of satoshis (the smallest unit of Bitcoin) to be transferred by this output.
9
+ * @property {LockingScript} lockingScript - The script that 'locks' the satoshis,
10
+ * specifying the conditions under which they can be spent. This script is
11
+ * essential for securing the funds and typically contains cryptographic
12
+ * puzzles that need to be solved to spend the output.
13
+ * @property {boolean} [change] - Optional. A flag that indicates whether this output
14
+ * is a change output. If true, it means this output is returning funds back
15
+ * to the sender, usually as the 'change' from the transaction inputs.
16
+ *
17
+ * @example
18
+ * // Creating a simple transaction output
19
+ * let txOutput = {
20
+ * satoshis: 1000,
21
+ * lockingScript: LockingScript.fromASM('OP_DUP OP_HASH160 ... OP_EQUALVERIFY OP_CHECKSIG'),
22
+ * change: false
23
+ * };
24
+ *
25
+ * @description
26
+ * The TransactionOutput interface defines how bitcoins are to be distributed in a transaction, either to a recipient or
27
+ * back to the sender as change. The lockingScript is critical as it determines the conditions
28
+ * under which the output can be spent, typically requiring a digital signature matching the
29
+ * intended recipient's public key.
30
+ */
31
+ export default interface TransactionOutput {
32
+ satoshis?: number;
33
+ lockingScript: LockingScript;
34
+ change?: boolean;
35
+ }
36
+ //# sourceMappingURL=TransactionOutput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactionOutput.d.ts","sourceRoot":"","sources":["../../../../src/transaction/TransactionOutput.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,4BAA4B,CAAA;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,OAAO,WAAW,iBAAiB;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,aAAa,CAAA;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
@@ -0,0 +1,28 @@
1
+ import { BroadcastResponse, BroadcastFailure, Broadcaster } from '../Broadcaster.js';
2
+ import Transaction from '../Transaction.js';
3
+ /**
4
+ * Represents an ARC transaction broadcaster.
5
+ */
6
+ export default class ARC implements Broadcaster {
7
+ URL: string;
8
+ apiKey: string;
9
+ /**
10
+ * Constructs an instance of the ARC broadcaster.
11
+ *
12
+ * @param {string} URL - The URL endpoint for the ARC API.
13
+ * @param {string} apiKey - The API key used for authorization with the ARC API.
14
+ */
15
+ constructor(URL: string, apiKey: string);
16
+ /**
17
+ * Broadcasts a transaction via ARC.
18
+ * This method will attempt to use `window.fetch` if available (in browser environments).
19
+ * If running in a Node.js environment, it falls back to using the Node.js `https` module.
20
+ *
21
+ * @param {Transaction} tx - The transaction to be broadcasted.
22
+ * @returns {Promise<BroadcastResponse | BroadcastFailure>} A promise that resolves to either a success or failure response.
23
+ */
24
+ broadcast(tx: Transaction): Promise<BroadcastResponse | BroadcastFailure>;
25
+ /** Helper function for Node.js HTTPS requests */
26
+ private nodeFetch;
27
+ }
28
+ //# sourceMappingURL=ARC.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ARC.d.ts","sourceRoot":"","sources":["../../../../../src/transaction/broadcasters/ARC.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpF,OAAO,WAAW,MAAM,mBAAmB,CAAA;AAE3C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,GAAI,YAAW,WAAW;IAC7C,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IAEd;;;;;OAKG;gBACU,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAKxC;;;;;;;OAOG;IACG,SAAS,CAAE,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,GAAG,gBAAgB,CAAC;IAqDhF,iDAAiD;YACnC,SAAS;CAsBxB"}
@@ -0,0 +1,2 @@
1
+ export { default as ARC } from './ARC.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/transaction/broadcasters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,26 @@
1
+ import FeeModel from '../FeeModel.js';
2
+ import Transaction from '../Transaction.js';
3
+ /**
4
+ * Represents the "satoshis per kilobyte" transaction fee model.
5
+ */
6
+ export default class SatoshisPerKilobyte implements FeeModel {
7
+ /**
8
+ * @property
9
+ * Denotes the number of satoshis paid per kilobyte of transaction size.
10
+ */
11
+ value: number;
12
+ /**
13
+ * Constructs an instance of the sat/kb fee model.
14
+ *
15
+ * @param {number} value - The number of satoshis per kilobyte to charge as a fee.
16
+ */
17
+ constructor(value: number);
18
+ /**
19
+ * Computes the fee for a given transaction.
20
+ *
21
+ * @param tx The transaction for which a fee is to be computed.
22
+ * @returns The fee in satoshis for the transaction, as a BigNumber.
23
+ */
24
+ computeFee(tx: Transaction): Promise<number>;
25
+ }
26
+ //# sourceMappingURL=SatoshisPerKilobyte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SatoshisPerKilobyte.d.ts","sourceRoot":"","sources":["../../../../../src/transaction/fee-models/SatoshisPerKilobyte.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAA;AACrC,OAAO,WAAW,MAAM,mBAAmB,CAAA;AAG3C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,YAAW,QAAQ;IAC1D;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAA;IAEb;;;;OAIG;gBACS,KAAK,EAAE,MAAM;IAIzB;;;;;OAKG;IACG,UAAU,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;CAyCnD"}
@@ -0,0 +1,2 @@
1
+ export { default as SatoshisPerKilobyte } from './SatoshisPerKilobyte.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/transaction/fee-models/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,0BAA0B,CAAA"}
@@ -0,0 +1,7 @@
1
+ export { default as Transaction } from './Transaction.js';
2
+ export { default as MerklePath } from './MerklePath.js';
3
+ export type { default as TransactionInput } from './TransactionInput.js';
4
+ export type { default as TransactionOutput } from './TransactionOutput.js';
5
+ export type * as Broadcaster from './Broadcaster.js';
6
+ export type { default as ChainTracker } from './ChainTracker.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transaction/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACvD,YAAY,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxE,YAAY,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1E,YAAY,KAAK,WAAW,MAAM,kBAAkB,CAAA;AACpD,YAAY,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,mBAAmB,CAAA"}