@bsv/sdk 1.0.29 → 1.0.31

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 (329) hide show
  1. package/dist/cjs/mod.js +25 -0
  2. package/dist/cjs/mod.js.map +1 -0
  3. package/dist/cjs/package.json +49 -0
  4. package/dist/cjs/src/compat/BSM.js +77 -0
  5. package/dist/cjs/src/compat/BSM.js.map +1 -0
  6. package/dist/cjs/src/compat/ECIES.js +512 -0
  7. package/dist/cjs/src/compat/ECIES.js.map +1 -0
  8. package/dist/cjs/src/compat/HD.js +344 -0
  9. package/dist/cjs/src/compat/HD.js.map +1 -0
  10. package/dist/cjs/src/compat/Mnemonic.js +298 -0
  11. package/dist/cjs/src/compat/Mnemonic.js.map +1 -0
  12. package/dist/cjs/src/compat/bip-39-wordlist-en.js +2057 -0
  13. package/dist/cjs/src/compat/bip-39-wordlist-en.js.map +1 -0
  14. package/dist/cjs/src/compat/index.js +37 -0
  15. package/dist/cjs/src/compat/index.js.map +1 -0
  16. package/dist/cjs/src/messages/EncryptedMessage.js +69 -0
  17. package/dist/cjs/src/messages/EncryptedMessage.js.map +1 -0
  18. package/dist/cjs/src/messages/SignedMessage.js +85 -0
  19. package/dist/cjs/src/messages/SignedMessage.js.map +1 -0
  20. package/dist/cjs/src/messages/index.js +29 -0
  21. package/dist/cjs/src/messages/index.js.map +1 -0
  22. package/dist/cjs/src/primitives/AESGCM.js +384 -0
  23. package/dist/cjs/src/primitives/AESGCM.js.map +1 -0
  24. package/dist/cjs/src/primitives/BasePoint.js +19 -0
  25. package/dist/cjs/src/primitives/BasePoint.js.map +1 -0
  26. package/dist/cjs/src/primitives/BigNumber.js +4272 -0
  27. package/dist/cjs/src/primitives/BigNumber.js.map +1 -0
  28. package/dist/cjs/src/primitives/Curve.js +1126 -0
  29. package/dist/cjs/src/primitives/Curve.js.map +1 -0
  30. package/dist/cjs/src/primitives/DRBG.js +99 -0
  31. package/dist/cjs/src/primitives/DRBG.js.map +1 -0
  32. package/dist/cjs/src/primitives/ECDSA.js +169 -0
  33. package/dist/cjs/src/primitives/ECDSA.js.map +1 -0
  34. package/dist/cjs/src/primitives/Hash.js +1387 -0
  35. package/dist/cjs/src/primitives/Hash.js.map +1 -0
  36. package/dist/cjs/src/primitives/JacobianPoint.js +400 -0
  37. package/dist/cjs/src/primitives/JacobianPoint.js.map +1 -0
  38. package/dist/cjs/src/primitives/K256.js +111 -0
  39. package/dist/cjs/src/primitives/K256.js.map +1 -0
  40. package/dist/cjs/src/primitives/Mersenne.js +118 -0
  41. package/dist/cjs/src/primitives/Mersenne.js.map +1 -0
  42. package/dist/cjs/src/primitives/MontgomoryMethod.js +150 -0
  43. package/dist/cjs/src/primitives/MontgomoryMethod.js.map +1 -0
  44. package/dist/cjs/src/primitives/Point.js +819 -0
  45. package/dist/cjs/src/primitives/Point.js.map +1 -0
  46. package/dist/cjs/src/primitives/PrivateKey.js +246 -0
  47. package/dist/cjs/src/primitives/PrivateKey.js.map +1 -0
  48. package/dist/cjs/src/primitives/PublicKey.js +168 -0
  49. package/dist/cjs/src/primitives/PublicKey.js.map +1 -0
  50. package/dist/cjs/src/primitives/Random.js +57 -0
  51. package/dist/cjs/src/primitives/Random.js.map +1 -0
  52. package/dist/cjs/src/primitives/ReductionContext.js +490 -0
  53. package/dist/cjs/src/primitives/ReductionContext.js.map +1 -0
  54. package/dist/cjs/src/primitives/Signature.js +357 -0
  55. package/dist/cjs/src/primitives/Signature.js.map +1 -0
  56. package/dist/cjs/src/primitives/SymmetricKey.js +82 -0
  57. package/dist/cjs/src/primitives/SymmetricKey.js.map +1 -0
  58. package/dist/cjs/src/primitives/TransactionSignature.js +172 -0
  59. package/dist/cjs/src/primitives/TransactionSignature.js.map +1 -0
  60. package/dist/cjs/src/primitives/index.js +51 -0
  61. package/dist/cjs/src/primitives/index.js.map +1 -0
  62. package/dist/cjs/src/primitives/utils.js +624 -0
  63. package/dist/cjs/src/primitives/utils.js.map +1 -0
  64. package/dist/cjs/src/script/LockingScript.js +35 -0
  65. package/dist/cjs/src/script/LockingScript.js.map +1 -0
  66. package/dist/cjs/src/script/OP.js +207 -0
  67. package/dist/cjs/src/script/OP.js.map +1 -0
  68. package/dist/cjs/src/script/Script.js +435 -0
  69. package/dist/cjs/src/script/Script.js.map +1 -0
  70. package/dist/cjs/src/script/ScriptChunk.js +3 -0
  71. package/dist/cjs/src/script/ScriptChunk.js.map +1 -0
  72. package/dist/cjs/src/script/ScriptTemplate.js +3 -0
  73. package/dist/cjs/src/script/ScriptTemplate.js.map +1 -0
  74. package/dist/cjs/src/script/Spend.js +1252 -0
  75. package/dist/cjs/src/script/Spend.js.map +1 -0
  76. package/dist/cjs/src/script/UnlockingScript.js +35 -0
  77. package/dist/cjs/src/script/UnlockingScript.js.map +1 -0
  78. package/dist/cjs/src/script/index.js +32 -0
  79. package/dist/cjs/src/script/index.js.map +1 -0
  80. package/dist/cjs/src/script/templates/P2PKH.js +120 -0
  81. package/dist/cjs/src/script/templates/P2PKH.js.map +1 -0
  82. package/dist/cjs/src/script/templates/RPuzzle.js +125 -0
  83. package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -0
  84. package/dist/cjs/src/script/templates/index.js +11 -0
  85. package/dist/cjs/src/script/templates/index.js.map +1 -0
  86. package/dist/cjs/src/transaction/Broadcaster.js +3 -0
  87. package/dist/cjs/src/transaction/Broadcaster.js.map +1 -0
  88. package/dist/cjs/src/transaction/ChainTracker.js +3 -0
  89. package/dist/cjs/src/transaction/ChainTracker.js.map +1 -0
  90. package/dist/cjs/src/transaction/FeeModel.js +3 -0
  91. package/dist/cjs/src/transaction/FeeModel.js.map +1 -0
  92. package/dist/cjs/src/transaction/MerklePath.js +239 -0
  93. package/dist/cjs/src/transaction/MerklePath.js.map +1 -0
  94. package/dist/cjs/src/transaction/Transaction.js +616 -0
  95. package/dist/cjs/src/transaction/Transaction.js.map +1 -0
  96. package/dist/cjs/src/transaction/TransactionInput.js +3 -0
  97. package/dist/cjs/src/transaction/TransactionInput.js.map +1 -0
  98. package/dist/cjs/src/transaction/TransactionOutput.js +3 -0
  99. package/dist/cjs/src/transaction/TransactionOutput.js.map +1 -0
  100. package/dist/cjs/src/transaction/broadcasters/ARC.js +112 -0
  101. package/dist/cjs/src/transaction/broadcasters/ARC.js.map +1 -0
  102. package/dist/cjs/src/transaction/broadcasters/index.js +9 -0
  103. package/dist/cjs/src/transaction/broadcasters/index.js.map +1 -0
  104. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js +69 -0
  105. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -0
  106. package/dist/cjs/src/transaction/fee-models/index.js +9 -0
  107. package/dist/cjs/src/transaction/fee-models/index.js.map +1 -0
  108. package/dist/cjs/src/transaction/index.js +11 -0
  109. package/dist/cjs/src/transaction/index.js.map +1 -0
  110. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
  111. package/dist/esm/mod.js +9 -0
  112. package/dist/esm/mod.js.map +1 -0
  113. package/dist/esm/src/compat/BSM.js +45 -0
  114. package/dist/esm/src/compat/BSM.js.map +1 -0
  115. package/dist/esm/src/compat/ECIES.js +483 -0
  116. package/dist/esm/src/compat/ECIES.js.map +1 -0
  117. package/dist/esm/src/compat/HD.js +322 -0
  118. package/dist/esm/src/compat/HD.js.map +1 -0
  119. package/dist/esm/src/compat/Mnemonic.js +272 -0
  120. package/dist/esm/src/compat/Mnemonic.js.map +1 -0
  121. package/dist/esm/src/compat/bip-39-wordlist-en.js +2054 -0
  122. package/dist/esm/src/compat/bip-39-wordlist-en.js.map +1 -0
  123. package/dist/esm/src/compat/index.js +5 -0
  124. package/dist/esm/src/compat/index.js.map +1 -0
  125. package/dist/esm/src/messages/EncryptedMessage.js +61 -0
  126. package/dist/esm/src/messages/EncryptedMessage.js.map +1 -0
  127. package/dist/esm/src/messages/SignedMessage.js +77 -0
  128. package/dist/esm/src/messages/SignedMessage.js.map +1 -0
  129. package/dist/esm/src/messages/index.js +3 -0
  130. package/dist/esm/src/messages/index.js.map +1 -0
  131. package/dist/esm/src/primitives/AESGCM.js +371 -0
  132. package/dist/esm/src/primitives/AESGCM.js.map +1 -0
  133. package/dist/esm/src/primitives/BasePoint.js +16 -0
  134. package/dist/esm/src/primitives/BasePoint.js.map +1 -0
  135. package/dist/esm/src/primitives/BigNumber.js +4307 -0
  136. package/dist/esm/src/primitives/BigNumber.js.map +1 -0
  137. package/dist/esm/src/primitives/Curve.js +1141 -0
  138. package/dist/esm/src/primitives/Curve.js.map +1 -0
  139. package/dist/esm/src/primitives/DRBG.js +98 -0
  140. package/dist/esm/src/primitives/DRBG.js.map +1 -0
  141. package/dist/esm/src/primitives/ECDSA.js +161 -0
  142. package/dist/esm/src/primitives/ECDSA.js.map +1 -0
  143. package/dist/esm/src/primitives/Hash.js +1391 -0
  144. package/dist/esm/src/primitives/Hash.js.map +1 -0
  145. package/dist/esm/src/primitives/JacobianPoint.js +398 -0
  146. package/dist/esm/src/primitives/JacobianPoint.js.map +1 -0
  147. package/dist/esm/src/primitives/K256.js +105 -0
  148. package/dist/esm/src/primitives/K256.js.map +1 -0
  149. package/dist/esm/src/primitives/Mersenne.js +117 -0
  150. package/dist/esm/src/primitives/Mersenne.js.map +1 -0
  151. package/dist/esm/src/primitives/MontgomoryMethod.js +149 -0
  152. package/dist/esm/src/primitives/MontgomoryMethod.js.map +1 -0
  153. package/dist/esm/src/primitives/Point.js +816 -0
  154. package/dist/esm/src/primitives/Point.js.map +1 -0
  155. package/dist/esm/src/primitives/PrivateKey.js +240 -0
  156. package/dist/esm/src/primitives/PrivateKey.js.map +1 -0
  157. package/dist/esm/src/primitives/PublicKey.js +162 -0
  158. package/dist/esm/src/primitives/PublicKey.js.map +1 -0
  159. package/dist/esm/src/primitives/Random.js +56 -0
  160. package/dist/esm/src/primitives/Random.js.map +1 -0
  161. package/dist/esm/src/primitives/ReductionContext.js +486 -0
  162. package/dist/esm/src/primitives/ReductionContext.js.map +1 -0
  163. package/dist/esm/src/primitives/Signature.js +360 -0
  164. package/dist/esm/src/primitives/Signature.js.map +1 -0
  165. package/dist/esm/src/primitives/SymmetricKey.js +76 -0
  166. package/dist/esm/src/primitives/SymmetricKey.js.map +1 -0
  167. package/dist/esm/src/primitives/TransactionSignature.js +144 -0
  168. package/dist/esm/src/primitives/TransactionSignature.js.map +1 -0
  169. package/dist/esm/src/primitives/index.js +13 -0
  170. package/dist/esm/src/primitives/index.js.map +1 -0
  171. package/dist/esm/src/primitives/utils.js +609 -0
  172. package/dist/esm/src/primitives/utils.js.map +1 -0
  173. package/dist/esm/src/script/LockingScript.js +29 -0
  174. package/dist/esm/src/script/LockingScript.js.map +1 -0
  175. package/dist/esm/src/script/OP.js +205 -0
  176. package/dist/esm/src/script/OP.js.map +1 -0
  177. package/dist/esm/src/script/Script.js +430 -0
  178. package/dist/esm/src/script/Script.js.map +1 -0
  179. package/dist/esm/src/script/ScriptChunk.js +2 -0
  180. package/dist/esm/src/script/ScriptChunk.js.map +1 -0
  181. package/dist/esm/src/script/ScriptTemplate.js +2 -0
  182. package/dist/esm/src/script/ScriptTemplate.js.map +1 -0
  183. package/dist/esm/src/script/Spend.js +1240 -0
  184. package/dist/esm/src/script/Spend.js.map +1 -0
  185. package/dist/esm/src/script/UnlockingScript.js +29 -0
  186. package/dist/esm/src/script/UnlockingScript.js.map +1 -0
  187. package/dist/esm/src/script/index.js +7 -0
  188. package/dist/esm/src/script/index.js.map +1 -0
  189. package/dist/esm/src/script/templates/P2PKH.js +113 -0
  190. package/dist/esm/src/script/templates/P2PKH.js.map +1 -0
  191. package/dist/esm/src/script/templates/RPuzzle.js +119 -0
  192. package/dist/esm/src/script/templates/RPuzzle.js.map +1 -0
  193. package/dist/esm/src/script/templates/index.js +3 -0
  194. package/dist/esm/src/script/templates/index.js.map +1 -0
  195. package/dist/esm/src/transaction/Broadcaster.js +2 -0
  196. package/dist/esm/src/transaction/Broadcaster.js.map +1 -0
  197. package/dist/esm/src/transaction/ChainTracker.js +2 -0
  198. package/dist/esm/src/transaction/ChainTracker.js.map +1 -0
  199. package/dist/esm/src/transaction/FeeModel.js +2 -0
  200. package/dist/esm/src/transaction/FeeModel.js.map +1 -0
  201. package/dist/esm/src/transaction/MerklePath.js +237 -0
  202. package/dist/esm/src/transaction/MerklePath.js.map +1 -0
  203. package/dist/esm/src/transaction/Transaction.js +617 -0
  204. package/dist/esm/src/transaction/Transaction.js.map +1 -0
  205. package/dist/esm/src/transaction/TransactionInput.js +2 -0
  206. package/dist/esm/src/transaction/TransactionInput.js.map +1 -0
  207. package/dist/esm/src/transaction/TransactionOutput.js +2 -0
  208. package/dist/esm/src/transaction/TransactionOutput.js.map +1 -0
  209. package/dist/esm/src/transaction/broadcasters/ARC.js +111 -0
  210. package/dist/esm/src/transaction/broadcasters/ARC.js.map +1 -0
  211. package/dist/esm/src/transaction/broadcasters/index.js +2 -0
  212. package/dist/esm/src/transaction/broadcasters/index.js.map +1 -0
  213. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js +71 -0
  214. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -0
  215. package/dist/esm/src/transaction/fee-models/index.js +2 -0
  216. package/dist/esm/src/transaction/fee-models/index.js.map +1 -0
  217. package/dist/esm/src/transaction/index.js +3 -0
  218. package/dist/esm/src/transaction/index.js.map +1 -0
  219. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
  220. package/dist/types/mod.d.ts +9 -0
  221. package/dist/types/mod.d.ts.map +1 -0
  222. package/dist/types/src/compat/BSM.d.ts +28 -0
  223. package/dist/types/src/compat/BSM.d.ts.map +1 -0
  224. package/dist/types/src/compat/ECIES.d.ts +62 -0
  225. package/dist/types/src/compat/ECIES.d.ts.map +1 -0
  226. package/dist/types/src/compat/HD.d.ts +131 -0
  227. package/dist/types/src/compat/HD.d.ts.map +1 -0
  228. package/dist/types/src/compat/Mnemonic.d.ts +132 -0
  229. package/dist/types/src/compat/Mnemonic.d.ts.map +1 -0
  230. package/dist/types/src/compat/bip-39-wordlist-en.d.ts +5 -0
  231. package/dist/types/src/compat/bip-39-wordlist-en.d.ts.map +1 -0
  232. package/dist/types/src/compat/index.d.ts +5 -0
  233. package/dist/types/src/compat/index.d.ts.map +1 -0
  234. package/dist/types/src/messages/EncryptedMessage.d.ts +20 -0
  235. package/dist/types/src/messages/EncryptedMessage.d.ts.map +1 -0
  236. package/dist/types/src/messages/SignedMessage.d.ts +21 -0
  237. package/dist/types/src/messages/SignedMessage.d.ts.map +1 -0
  238. package/dist/types/src/messages/index.d.ts +3 -0
  239. package/dist/types/src/messages/index.d.ts.map +1 -0
  240. package/dist/types/src/primitives/AESGCM.d.ts +14 -0
  241. package/dist/types/src/primitives/AESGCM.d.ts.map +1 -0
  242. package/dist/types/src/primitives/BasePoint.d.ts +22 -0
  243. package/dist/types/src/primitives/BasePoint.d.ts.map +1 -0
  244. package/dist/types/src/primitives/BigNumber.d.ts +1895 -0
  245. package/dist/types/src/primitives/BigNumber.d.ts.map +1 -0
  246. package/dist/types/src/primitives/Curve.d.ts +55 -0
  247. package/dist/types/src/primitives/Curve.d.ts.map +1 -0
  248. package/dist/types/src/primitives/DRBG.d.ts +54 -0
  249. package/dist/types/src/primitives/DRBG.d.ts.map +1 -0
  250. package/dist/types/src/primitives/ECDSA.d.ts +39 -0
  251. package/dist/types/src/primitives/ECDSA.d.ts.map +1 -0
  252. package/dist/types/src/primitives/Hash.d.ts +450 -0
  253. package/dist/types/src/primitives/Hash.d.ts.map +1 -0
  254. package/dist/types/src/primitives/JacobianPoint.d.ts +164 -0
  255. package/dist/types/src/primitives/JacobianPoint.d.ts.map +1 -0
  256. package/dist/types/src/primitives/K256.d.ts +53 -0
  257. package/dist/types/src/primitives/K256.d.ts.map +1 -0
  258. package/dist/types/src/primitives/Mersenne.d.ts +72 -0
  259. package/dist/types/src/primitives/Mersenne.d.ts.map +1 -0
  260. package/dist/types/src/primitives/MontgomoryMethod.d.ts +96 -0
  261. package/dist/types/src/primitives/MontgomoryMethod.d.ts.map +1 -0
  262. package/dist/types/src/primitives/Point.d.ts +303 -0
  263. package/dist/types/src/primitives/Point.d.ts.map +1 -0
  264. package/dist/types/src/primitives/PrivateKey.d.ts +174 -0
  265. package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -0
  266. package/dist/types/src/primitives/PublicKey.d.ts +120 -0
  267. package/dist/types/src/primitives/PublicKey.d.ts.map +1 -0
  268. package/dist/types/src/primitives/Random.d.ts +14 -0
  269. package/dist/types/src/primitives/Random.d.ts.map +1 -0
  270. package/dist/types/src/primitives/ReductionContext.d.ts +308 -0
  271. package/dist/types/src/primitives/ReductionContext.d.ts.map +1 -0
  272. package/dist/types/src/primitives/Signature.d.ts +162 -0
  273. package/dist/types/src/primitives/Signature.d.ts.map +1 -0
  274. package/dist/types/src/primitives/SymmetricKey.d.ts +55 -0
  275. package/dist/types/src/primitives/SymmetricKey.d.ts.map +1 -0
  276. package/dist/types/src/primitives/TransactionSignature.d.ts +36 -0
  277. package/dist/types/src/primitives/TransactionSignature.d.ts.map +1 -0
  278. package/dist/types/src/primitives/index.d.ts +13 -0
  279. package/dist/types/src/primitives/index.d.ts.map +1 -0
  280. package/dist/types/src/primitives/utils.d.ts +124 -0
  281. package/dist/types/src/primitives/utils.d.ts.map +1 -0
  282. package/dist/types/src/script/LockingScript.d.ts +25 -0
  283. package/dist/types/src/script/LockingScript.d.ts.map +1 -0
  284. package/dist/types/src/script/OP.d.ts +193 -0
  285. package/dist/types/src/script/OP.d.ts.map +1 -0
  286. package/dist/types/src/script/Script.d.ts +148 -0
  287. package/dist/types/src/script/Script.d.ts.map +1 -0
  288. package/dist/types/src/script/ScriptChunk.d.ts +8 -0
  289. package/dist/types/src/script/ScriptChunk.d.ts.map +1 -0
  290. package/dist/types/src/script/ScriptTemplate.d.ts +33 -0
  291. package/dist/types/src/script/ScriptTemplate.d.ts.map +1 -0
  292. package/dist/types/src/script/Spend.d.ts +103 -0
  293. package/dist/types/src/script/Spend.d.ts.map +1 -0
  294. package/dist/types/src/script/UnlockingScript.d.ts +25 -0
  295. package/dist/types/src/script/UnlockingScript.d.ts.map +1 -0
  296. package/dist/types/src/script/index.d.ts +8 -0
  297. package/dist/types/src/script/index.d.ts.map +1 -0
  298. package/dist/types/src/script/templates/P2PKH.d.ts +40 -0
  299. package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -0
  300. package/dist/types/src/script/templates/RPuzzle.d.ts +47 -0
  301. package/dist/types/src/script/templates/RPuzzle.d.ts.map +1 -0
  302. package/dist/types/src/script/templates/index.d.ts +3 -0
  303. package/dist/types/src/script/templates/index.d.ts.map +1 -0
  304. package/dist/types/src/transaction/Broadcaster.d.ts +39 -0
  305. package/dist/types/src/transaction/Broadcaster.d.ts.map +1 -0
  306. package/dist/types/src/transaction/ChainTracker.d.ts +23 -0
  307. package/dist/types/src/transaction/ChainTracker.d.ts.map +1 -0
  308. package/dist/types/src/transaction/FeeModel.d.ts +12 -0
  309. package/dist/types/src/transaction/FeeModel.d.ts.map +1 -0
  310. package/dist/types/src/transaction/MerklePath.d.ts +91 -0
  311. package/dist/types/src/transaction/MerklePath.d.ts.map +1 -0
  312. package/dist/types/src/transaction/Transaction.d.ts +215 -0
  313. package/dist/types/src/transaction/Transaction.d.ts.map +1 -0
  314. package/dist/types/src/transaction/TransactionInput.d.ts +63 -0
  315. package/dist/types/src/transaction/TransactionInput.d.ts.map +1 -0
  316. package/dist/types/src/transaction/TransactionOutput.d.ts +36 -0
  317. package/dist/types/src/transaction/TransactionOutput.d.ts.map +1 -0
  318. package/dist/types/src/transaction/broadcasters/ARC.d.ts +28 -0
  319. package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +1 -0
  320. package/dist/types/src/transaction/broadcasters/index.d.ts +2 -0
  321. package/dist/types/src/transaction/broadcasters/index.d.ts.map +1 -0
  322. package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts +26 -0
  323. package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts.map +1 -0
  324. package/dist/types/src/transaction/fee-models/index.d.ts +2 -0
  325. package/dist/types/src/transaction/fee-models/index.d.ts.map +1 -0
  326. package/dist/types/src/transaction/index.d.ts +7 -0
  327. package/dist/types/src/transaction/index.d.ts.map +1 -0
  328. package/dist/types/tsconfig.types.tsbuildinfo +1 -0
  329. package/package.json +1 -1
@@ -0,0 +1,1387 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pbkdf2 = exports.sha512hmac = exports.sha256hmac = exports.hash160 = exports.hash256 = exports.sha512 = exports.sha256 = exports.sha1 = exports.ripemd160 = exports.SHA512HMAC = exports.SHA256HMAC = exports.SHA512 = exports.SHA1 = exports.SHA256 = exports.RIPEMD160 = exports.toArray = void 0;
4
+ const assert = (expression, message = 'Hash assertion failed') => {
5
+ if (!expression) {
6
+ throw new Error(message);
7
+ }
8
+ };
9
+ /**
10
+ * The BaseHash class is an abstract base class for cryptographic hash functions.
11
+ * It provides a common structure and functionality for hash function classes.
12
+ *
13
+ * @class BaseHash
14
+ *
15
+ * @property pending - Stores partially processed message segments.
16
+ * @property pendingTotal - The total number of characters that are being stored in `pending`
17
+ * @property blockSize - The size of each block to processed.
18
+ * @property outSize - The size of the final hash output.
19
+ * @property endian - The endianness used during processing, can either be 'big' or 'little'.
20
+ * @property _delta8 - The block size divided by 8, useful in various computations.
21
+ * @property _delta32 - The block size divided by 32, useful in various computations.
22
+ * @property padLength - The length of padding to be added to finalize the computation.
23
+ * @property hmacStrength - The HMAC strength value.
24
+ *
25
+ * @param blockSize - The size of the block to be hashed.
26
+ * @param outSize - The size of the resulting hash.
27
+ * @param hmacStrength - The strength of the HMAC.
28
+ * @param padLength - The length of the padding to be added.
29
+ *
30
+ * @example
31
+ * Sub-classes would extend this base BaseHash class like:
32
+ * class RIPEMD160 extends BaseHash {
33
+ * constructor () {
34
+ * super(512, 160, 192, 64);
35
+ * // ...
36
+ * }
37
+ * // ...
38
+ * }
39
+ */
40
+ class BaseHash {
41
+ constructor(blockSize, outSize, hmacStrength, padLength) {
42
+ this.pending = null;
43
+ this.pendingTotal = 0;
44
+ this.blockSize = blockSize;
45
+ this.outSize = outSize;
46
+ this.hmacStrength = hmacStrength;
47
+ this.padLength = padLength / 8;
48
+ this.endian = 'big';
49
+ this._delta8 = this.blockSize / 8;
50
+ this._delta32 = this.blockSize / 32;
51
+ }
52
+ _update(msg, start) {
53
+ throw new Error('Not implemented');
54
+ }
55
+ _digest() {
56
+ throw new Error('Not implemented');
57
+ }
58
+ _digestHex() {
59
+ throw new Error('Not implemented');
60
+ }
61
+ /**
62
+ * Converts the input message into an array, pads it, and joins into 32bit blocks.
63
+ * If there is enough data, it tries updating the hash computation.
64
+ *
65
+ * @method update
66
+ * @param msg - The message segment to include in the hashing computation.
67
+ * @param enc - The encoding of the message. If 'hex', the string will be treated as such, 'utf8' otherwise.
68
+ *
69
+ * @returns Returns the instance of the object for chaining.
70
+ *
71
+ * @example
72
+ * sha256.update('Hello World', 'utf8');
73
+ */
74
+ update(msg, enc) {
75
+ // Convert message to array, pad it, and join into 32bit blocks
76
+ msg = toArray(msg, enc);
77
+ if (this.pending == null) {
78
+ this.pending = msg;
79
+ }
80
+ else {
81
+ this.pending = this.pending.concat(msg);
82
+ }
83
+ this.pendingTotal += msg.length;
84
+ // Enough data, try updating
85
+ if (this.pending.length >= this._delta8) {
86
+ msg = this.pending;
87
+ // Process pending data in blocks
88
+ const r = msg.length % this._delta8;
89
+ this.pending = msg.slice(msg.length - r, msg.length);
90
+ if (this.pending.length === 0) {
91
+ this.pending = null;
92
+ }
93
+ msg = join32(msg, 0, msg.length - r, this.endian);
94
+ for (let i = 0; i < msg.length; i += this._delta32) {
95
+ this._update(msg, i);
96
+ }
97
+ }
98
+ return this;
99
+ }
100
+ /**
101
+ * Finalizes the hash computation and returns the hash value/result.
102
+ *
103
+ * @method digest
104
+ *
105
+ * @returns Returns the final hash value.
106
+ *
107
+ * @example
108
+ * const hash = sha256.digest();
109
+ */
110
+ digest() {
111
+ this.update(this._pad());
112
+ assert(this.pending === null);
113
+ return this._digest();
114
+ }
115
+ ;
116
+ /**
117
+ * Finalizes the hash computation and returns the hash value/result as a hex string.
118
+ *
119
+ * @method digest
120
+ *
121
+ * @returns Returns the final hash value as a hex string.
122
+ *
123
+ * @example
124
+ * const hash = sha256.digestHex();
125
+ */
126
+ digestHex() {
127
+ this.update(this._pad());
128
+ assert(this.pending === null);
129
+ return this._digestHex();
130
+ }
131
+ ;
132
+ /**
133
+ * [Private Method] Used internally to prepare the padding for the final stage of the hash computation.
134
+ *
135
+ * @method _pad
136
+ * @private
137
+ *
138
+ * @returns Returns an array denoting the padding.
139
+ */
140
+ _pad() {
141
+ let len = this.pendingTotal;
142
+ const bytes = this._delta8;
143
+ const k = bytes - ((len + this.padLength) % bytes);
144
+ const res = new Array(k + this.padLength);
145
+ res[0] = 0x80;
146
+ let i;
147
+ for (i = 1; i < k; i++) {
148
+ res[i] = 0;
149
+ }
150
+ // Append length
151
+ len <<= 3;
152
+ let t;
153
+ if (this.endian === 'big') {
154
+ for (t = 8; t < this.padLength; t++) {
155
+ res[i++] = 0;
156
+ }
157
+ res[i++] = 0;
158
+ res[i++] = 0;
159
+ res[i++] = 0;
160
+ res[i++] = 0;
161
+ res[i++] = (len >>> 24) & 0xff;
162
+ res[i++] = (len >>> 16) & 0xff;
163
+ res[i++] = (len >>> 8) & 0xff;
164
+ res[i++] = len & 0xff;
165
+ }
166
+ else {
167
+ res[i++] = len & 0xff;
168
+ res[i++] = (len >>> 8) & 0xff;
169
+ res[i++] = (len >>> 16) & 0xff;
170
+ res[i++] = (len >>> 24) & 0xff;
171
+ res[i++] = 0;
172
+ res[i++] = 0;
173
+ res[i++] = 0;
174
+ res[i++] = 0;
175
+ for (t = 8; t < this.padLength; t++) {
176
+ res[i++] = 0;
177
+ }
178
+ }
179
+ return res;
180
+ }
181
+ }
182
+ function isSurrogatePair(msg, i) {
183
+ if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) {
184
+ return false;
185
+ }
186
+ if (i < 0 || i + 1 >= msg.length) {
187
+ return false;
188
+ }
189
+ return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
190
+ }
191
+ /**
192
+ *
193
+ * @param msg
194
+ * @param enc Optional. Encoding to use if msg is string. Default is 'utf8'.
195
+ * @returns array of byte values from msg. If msg is an array, a copy is returned.
196
+ */
197
+ function toArray(msg, enc) {
198
+ if (Array.isArray(msg)) {
199
+ return msg.slice();
200
+ }
201
+ if (!msg) {
202
+ return [];
203
+ }
204
+ const res = [];
205
+ if (typeof msg === 'string') {
206
+ if (enc !== 'hex') {
207
+ // Inspired by stringToUtf8ByteArray() in closure-library by Google
208
+ // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
209
+ // Apache License 2.0
210
+ // https://github.com/google/closure-library/blob/master/LICENSE
211
+ let p = 0;
212
+ for (let i = 0; i < msg.length; i++) {
213
+ let c = msg.charCodeAt(i);
214
+ if (c < 128) {
215
+ res[p++] = c;
216
+ }
217
+ else if (c < 2048) {
218
+ res[p++] = (c >> 6) | 192;
219
+ res[p++] = (c & 63) | 128;
220
+ }
221
+ else if (isSurrogatePair(msg, i)) {
222
+ c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
223
+ res[p++] = (c >> 18) | 240;
224
+ res[p++] = ((c >> 12) & 63) | 128;
225
+ res[p++] = ((c >> 6) & 63) | 128;
226
+ res[p++] = (c & 63) | 128;
227
+ }
228
+ else {
229
+ res[p++] = (c >> 12) | 224;
230
+ res[p++] = ((c >> 6) & 63) | 128;
231
+ res[p++] = (c & 63) | 128;
232
+ }
233
+ }
234
+ }
235
+ else {
236
+ msg = msg.replace(/[^a-z0-9]+/ig, '');
237
+ if (msg.length % 2 !== 0) {
238
+ msg = '0' + msg;
239
+ }
240
+ for (let i = 0; i < msg.length; i += 2) {
241
+ res.push(parseInt(msg[i] + msg[i + 1], 16));
242
+ }
243
+ }
244
+ }
245
+ else {
246
+ msg = msg;
247
+ for (let i = 0; i < msg.length; i++) {
248
+ res[i] = msg[i] | 0;
249
+ }
250
+ }
251
+ return res;
252
+ }
253
+ exports.toArray = toArray;
254
+ function htonl(w) {
255
+ const res = (w >>> 24) |
256
+ ((w >>> 8) & 0xff00) |
257
+ ((w << 8) & 0xff0000) |
258
+ ((w & 0xff) << 24);
259
+ return res >>> 0;
260
+ }
261
+ function toHex32(msg, endian) {
262
+ let res = '';
263
+ for (let i = 0; i < msg.length; i++) {
264
+ let w = msg[i];
265
+ if (endian === 'little') {
266
+ w = htonl(w);
267
+ }
268
+ res += zero8(w.toString(16));
269
+ }
270
+ return res;
271
+ }
272
+ function zero8(word) {
273
+ if (word.length === 7) {
274
+ return '0' + word;
275
+ }
276
+ else if (word.length === 6) {
277
+ return '00' + word;
278
+ }
279
+ else if (word.length === 5) {
280
+ return '000' + word;
281
+ }
282
+ else if (word.length === 4) {
283
+ return '0000' + word;
284
+ }
285
+ else if (word.length === 3) {
286
+ return '00000' + word;
287
+ }
288
+ else if (word.length === 2) {
289
+ return '000000' + word;
290
+ }
291
+ else if (word.length === 1) {
292
+ return '0000000' + word;
293
+ }
294
+ else {
295
+ return word;
296
+ }
297
+ }
298
+ function join32(msg, start, end, endian) {
299
+ const len = end - start;
300
+ assert(len % 4 === 0);
301
+ const res = new Array(len / 4);
302
+ for (let i = 0, k = start; i < res.length; i++, k += 4) {
303
+ let w;
304
+ if (endian === 'big') {
305
+ w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
306
+ }
307
+ else {
308
+ w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
309
+ }
310
+ res[i] = w >>> 0;
311
+ }
312
+ return res;
313
+ }
314
+ function split32(msg, endian) {
315
+ const res = new Array(msg.length * 4);
316
+ for (let i = 0, k = 0; i < msg.length; i++, k += 4) {
317
+ const m = msg[i];
318
+ if (endian === 'big') {
319
+ res[k] = m >>> 24;
320
+ res[k + 1] = (m >>> 16) & 0xff;
321
+ res[k + 2] = (m >>> 8) & 0xff;
322
+ res[k + 3] = m & 0xff;
323
+ }
324
+ else {
325
+ res[k + 3] = m >>> 24;
326
+ res[k + 2] = (m >>> 16) & 0xff;
327
+ res[k + 1] = (m >>> 8) & 0xff;
328
+ res[k] = m & 0xff;
329
+ }
330
+ }
331
+ return res;
332
+ }
333
+ function rotr32(w, b) {
334
+ return (w >>> b) | (w << (32 - b));
335
+ }
336
+ function rotl32(w, b) {
337
+ return (w << b) | (w >>> (32 - b));
338
+ }
339
+ function sum32(a, b) {
340
+ return (a + b) >>> 0;
341
+ }
342
+ function SUM32_3(a, b, c) {
343
+ return (a + b + c) >>> 0;
344
+ }
345
+ function SUM32_4(a, b, c, d) {
346
+ return (a + b + c + d) >>> 0;
347
+ }
348
+ function SUM32_5(a, b, c, d, e) {
349
+ return (a + b + c + d + e) >>> 0;
350
+ }
351
+ function FT_1(s, x, y, z) {
352
+ if (s === 0) {
353
+ return ch32(x, y, z);
354
+ }
355
+ if (s === 1 || s === 3) {
356
+ return p32(x, y, z);
357
+ }
358
+ if (s === 2) {
359
+ return maj32(x, y, z);
360
+ }
361
+ }
362
+ function ch32(x, y, z) {
363
+ return (x & y) ^ ((~x) & z);
364
+ }
365
+ function maj32(x, y, z) {
366
+ return (x & y) ^ (x & z) ^ (y & z);
367
+ }
368
+ function p32(x, y, z) {
369
+ return x ^ y ^ z;
370
+ }
371
+ function S0_256(x) {
372
+ return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
373
+ }
374
+ function S1_256(x) {
375
+ return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
376
+ }
377
+ function G0_256(x) {
378
+ return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
379
+ }
380
+ function G1_256(x) {
381
+ return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
382
+ }
383
+ const r = [
384
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
385
+ 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
386
+ 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
387
+ 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
388
+ 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
389
+ ];
390
+ const rh = [
391
+ 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
392
+ 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
393
+ 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
394
+ 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
395
+ 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
396
+ ];
397
+ const s = [
398
+ 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
399
+ 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
400
+ 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
401
+ 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
402
+ 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
403
+ ];
404
+ const sh = [
405
+ 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
406
+ 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
407
+ 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
408
+ 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
409
+ 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
410
+ ];
411
+ function f(j, x, y, z) {
412
+ if (j <= 15) {
413
+ return x ^ y ^ z;
414
+ }
415
+ else if (j <= 31) {
416
+ return (x & y) | ((~x) & z);
417
+ }
418
+ else if (j <= 47) {
419
+ return (x | (~y)) ^ z;
420
+ }
421
+ else if (j <= 63) {
422
+ return (x & z) | (y & (~z));
423
+ }
424
+ else {
425
+ return x ^ (y | (~z));
426
+ }
427
+ }
428
+ function K(j) {
429
+ if (j <= 15) {
430
+ return 0x00000000;
431
+ }
432
+ else if (j <= 31) {
433
+ return 0x5a827999;
434
+ }
435
+ else if (j <= 47) {
436
+ return 0x6ed9eba1;
437
+ }
438
+ else if (j <= 63) {
439
+ return 0x8f1bbcdc;
440
+ }
441
+ else {
442
+ return 0xa953fd4e;
443
+ }
444
+ }
445
+ function Kh(j) {
446
+ if (j <= 15) {
447
+ return 0x50a28be6;
448
+ }
449
+ else if (j <= 31) {
450
+ return 0x5c4dd124;
451
+ }
452
+ else if (j <= 47) {
453
+ return 0x6d703ef3;
454
+ }
455
+ else if (j <= 63) {
456
+ return 0x7a6d76e9;
457
+ }
458
+ else {
459
+ return 0x00000000;
460
+ }
461
+ }
462
+ function sum64(buf, pos, ah, al) {
463
+ const bh = buf[pos];
464
+ const bl = buf[pos + 1];
465
+ const lo = (al + bl) >>> 0;
466
+ const hi = (lo < al ? 1 : 0) + ah + bh;
467
+ buf[pos] = hi >>> 0;
468
+ buf[pos + 1] = lo;
469
+ }
470
+ function sum64_hi(ah, al, bh, bl) {
471
+ const lo = (al + bl) >>> 0;
472
+ const hi = (lo < al ? 1 : 0) + ah + bh;
473
+ return hi >>> 0;
474
+ }
475
+ function sum64_lo(ah, al, bh, bl) {
476
+ const lo = al + bl;
477
+ return lo >>> 0;
478
+ }
479
+ function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) {
480
+ let carry = 0;
481
+ let lo = al;
482
+ lo = (lo + bl) >>> 0;
483
+ carry += lo < al ? 1 : 0;
484
+ lo = (lo + cl) >>> 0;
485
+ carry += lo < cl ? 1 : 0;
486
+ lo = (lo + dl) >>> 0;
487
+ carry += lo < dl ? 1 : 0;
488
+ const hi = ah + bh + ch + dh + carry;
489
+ return hi >>> 0;
490
+ }
491
+ function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) {
492
+ const lo = al + bl + cl + dl;
493
+ return lo >>> 0;
494
+ }
495
+ function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
496
+ let carry = 0;
497
+ let lo = al;
498
+ lo = (lo + bl) >>> 0;
499
+ carry += lo < al ? 1 : 0;
500
+ lo = (lo + cl) >>> 0;
501
+ carry += lo < cl ? 1 : 0;
502
+ lo = (lo + dl) >>> 0;
503
+ carry += lo < dl ? 1 : 0;
504
+ lo = (lo + el) >>> 0;
505
+ carry += lo < el ? 1 : 0;
506
+ const hi = ah + bh + ch + dh + eh + carry;
507
+ return hi >>> 0;
508
+ }
509
+ function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
510
+ const lo = al + bl + cl + dl + el;
511
+ return lo >>> 0;
512
+ }
513
+ function rotr64_hi(ah, al, num) {
514
+ const r = (al << (32 - num)) | (ah >>> num);
515
+ return r >>> 0;
516
+ }
517
+ function rotr64_lo(ah, al, num) {
518
+ const r = (ah << (32 - num)) | (al >>> num);
519
+ return r >>> 0;
520
+ }
521
+ function shr64_hi(ah, al, num) {
522
+ return ah >>> num;
523
+ }
524
+ function shr64_lo(ah, al, num) {
525
+ const r = (ah << (32 - num)) | (al >>> num);
526
+ return r >>> 0;
527
+ }
528
+ /**
529
+ * An implementation of RIPEMD160 cryptographic hash function. Extends the BaseHash class.
530
+ * It provides a way to compute a 'digest' for any kind of input data; transforming the data
531
+ * into a unique output of fixed size. The output is deterministic; it will always be
532
+ * the same for the same input.
533
+ *
534
+ * @class RIPEMD160
535
+ * @param None
536
+ *
537
+ * @constructor
538
+ * Use the RIPEMD160 constructor to create an instance of RIPEMD160 hash function.
539
+ *
540
+ * @example
541
+ * const ripemd160 = new RIPEMD160();
542
+ *
543
+ * @property h - Array that is updated iteratively as part of hashing computation.
544
+ */
545
+ class RIPEMD160 extends BaseHash {
546
+ constructor() {
547
+ super(512, 160, 192, 64);
548
+ this.endian = 'little';
549
+ this.h = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
550
+ this.endian = 'little';
551
+ }
552
+ _update(msg, start) {
553
+ let A = this.h[0];
554
+ let B = this.h[1];
555
+ let C = this.h[2];
556
+ let D = this.h[3];
557
+ let E = this.h[4];
558
+ let Ah = A;
559
+ let Bh = B;
560
+ let Ch = C;
561
+ let Dh = D;
562
+ let Eh = E;
563
+ let T;
564
+ for (let j = 0; j < 80; j++) {
565
+ T = sum32(rotl32(SUM32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)), s[j]), E);
566
+ A = E;
567
+ E = D;
568
+ D = rotl32(C, 10);
569
+ C = B;
570
+ B = T;
571
+ T = sum32(rotl32(SUM32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)), sh[j]), Eh);
572
+ Ah = Eh;
573
+ Eh = Dh;
574
+ Dh = rotl32(Ch, 10);
575
+ Ch = Bh;
576
+ Bh = T;
577
+ }
578
+ T = SUM32_3(this.h[1], C, Dh);
579
+ this.h[1] = SUM32_3(this.h[2], D, Eh);
580
+ this.h[2] = SUM32_3(this.h[3], E, Ah);
581
+ this.h[3] = SUM32_3(this.h[4], A, Bh);
582
+ this.h[4] = SUM32_3(this.h[0], B, Ch);
583
+ this.h[0] = T;
584
+ }
585
+ _digest() {
586
+ return split32(this.h, 'little');
587
+ }
588
+ _digestHex() {
589
+ return toHex32(this.h, 'little');
590
+ }
591
+ }
592
+ exports.RIPEMD160 = RIPEMD160;
593
+ /**
594
+ * An implementation of SHA256 cryptographic hash function. Extends the BaseHash class.
595
+ * It provides a way to compute a 'digest' for any kind of input data; transforming the data
596
+ * into a unique output of fixed size. The output is deterministic; it will always be
597
+ * the same for the same input.
598
+ *
599
+ * @class SHA256
600
+ * @param None
601
+ *
602
+ * @constructor
603
+ * Use the SHA256 constructor to create an instance of SHA256 hash function.
604
+ *
605
+ * @example
606
+ * const sha256 = new SHA256();
607
+ *
608
+ * @property h - The initial hash constants
609
+ * @property W - Provides a way to recycle usage of the array memory.
610
+ * @property k - The round constants used for each round of SHA-256
611
+ */
612
+ class SHA256 extends BaseHash {
613
+ constructor() {
614
+ super(512, 256, 192, 64);
615
+ this.h = [
616
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
617
+ 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
618
+ ];
619
+ this.k = [
620
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
621
+ 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
622
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
623
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
624
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
625
+ 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
626
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
627
+ 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
628
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
629
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
630
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
631
+ 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
632
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
633
+ 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
634
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
635
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
636
+ ];
637
+ this.W = new Array(64);
638
+ }
639
+ _update(msg, start) {
640
+ const W = this.W;
641
+ let i;
642
+ for (i = 0; i < 16; i++) {
643
+ W[i] = msg[start + i];
644
+ }
645
+ for (; i < W.length; i++) {
646
+ W[i] = SUM32_4(G1_256(W[i - 2]), W[i - 7], G0_256(W[i - 15]), W[i - 16]);
647
+ }
648
+ let a = this.h[0];
649
+ let b = this.h[1];
650
+ let c = this.h[2];
651
+ let d = this.h[3];
652
+ let e = this.h[4];
653
+ let f = this.h[5];
654
+ let g = this.h[6];
655
+ let h = this.h[7];
656
+ assert(this.k.length === W.length);
657
+ for (i = 0; i < W.length; i++) {
658
+ const T1 = SUM32_5(h, S1_256(e), ch32(e, f, g), this.k[i], W[i]);
659
+ const T2 = sum32(S0_256(a), maj32(a, b, c));
660
+ h = g;
661
+ g = f;
662
+ f = e;
663
+ e = sum32(d, T1);
664
+ d = c;
665
+ c = b;
666
+ b = a;
667
+ a = sum32(T1, T2);
668
+ }
669
+ this.h[0] = sum32(this.h[0], a);
670
+ this.h[1] = sum32(this.h[1], b);
671
+ this.h[2] = sum32(this.h[2], c);
672
+ this.h[3] = sum32(this.h[3], d);
673
+ this.h[4] = sum32(this.h[4], e);
674
+ this.h[5] = sum32(this.h[5], f);
675
+ this.h[6] = sum32(this.h[6], g);
676
+ this.h[7] = sum32(this.h[7], h);
677
+ }
678
+ ;
679
+ _digest() {
680
+ return split32(this.h, 'big');
681
+ }
682
+ _digestHex() {
683
+ return toHex32(this.h, 'big');
684
+ }
685
+ }
686
+ exports.SHA256 = SHA256;
687
+ /**
688
+ * An implementation of SHA1 cryptographic hash function. Extends the BaseHash class.
689
+ * It provides a way to compute a 'digest' for any kind of input data; transforming the data
690
+ * into a unique output of fixed size. The output is deterministic; it will always be
691
+ * the same for the same input.
692
+ *
693
+ * @class SHA1
694
+ * @param None
695
+ *
696
+ * @constructor
697
+ * Use the SHA1 constructor to create an instance of SHA1 hash function.
698
+ *
699
+ * @example
700
+ * const sha1 = new SHA1();
701
+ *
702
+ * @property h - The initial hash constants.
703
+ * @property W - Provides a way to recycle usage of the array memory.
704
+ * @property k - The round constants used for each round of SHA-1.
705
+ */
706
+ class SHA1 extends BaseHash {
707
+ constructor() {
708
+ super(512, 160, 80, 64);
709
+ this.k = [
710
+ 0x5A827999, 0x6ED9EBA1,
711
+ 0x8F1BBCDC, 0xCA62C1D6
712
+ ];
713
+ this.h = [
714
+ 0x67452301, 0xefcdab89, 0x98badcfe,
715
+ 0x10325476, 0xc3d2e1f0
716
+ ];
717
+ this.W = new Array(80);
718
+ }
719
+ _update(msg, start) {
720
+ const W = this.W;
721
+ let i;
722
+ for (i = 0; i < 16; i++) {
723
+ W[i] = msg[start + i];
724
+ }
725
+ for (; i < W.length; i++) {
726
+ W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
727
+ }
728
+ let a = this.h[0];
729
+ let b = this.h[1];
730
+ let c = this.h[2];
731
+ let d = this.h[3];
732
+ let e = this.h[4];
733
+ for (i = 0; i < W.length; i++) {
734
+ const s = ~~(i / 20);
735
+ const t = SUM32_5(rotl32(a, 5), FT_1(s, b, c, d), e, W[i], this.k[s]);
736
+ e = d;
737
+ d = c;
738
+ c = rotl32(b, 30);
739
+ b = a;
740
+ a = t;
741
+ }
742
+ this.h[0] = sum32(this.h[0], a);
743
+ this.h[1] = sum32(this.h[1], b);
744
+ this.h[2] = sum32(this.h[2], c);
745
+ this.h[3] = sum32(this.h[3], d);
746
+ this.h[4] = sum32(this.h[4], e);
747
+ }
748
+ _digest() {
749
+ return split32(this.h, 'big');
750
+ }
751
+ _digestHex() {
752
+ return toHex32(this.h, 'big');
753
+ }
754
+ }
755
+ exports.SHA1 = SHA1;
756
+ /**
757
+ * An implementation of SHA512 cryptographic hash function. Extends the BaseHash class.
758
+ * It provides a way to compute a 'digest' for any kind of input data; transforming the data
759
+ * into a unique output of fixed size. The output is deterministic; it will always be
760
+ * the same for the same input.
761
+ *
762
+ * @class SHA512
763
+ * @param None
764
+ *
765
+ * @constructor
766
+ * Use the SHA512 constructor to create an instance of SHA512 hash function.
767
+ *
768
+ * @example
769
+ * const sha512 = new SHA512();
770
+ *
771
+ * @property h - The initial hash constants.
772
+ * @property W - Provides a way to recycle usage of the array memory.
773
+ * @property k - The round constants used for each round of SHA-512.
774
+ */
775
+ class SHA512 extends BaseHash {
776
+ constructor() {
777
+ super(1024, 512, 192, 128);
778
+ this.h = [
779
+ 0x6a09e667, 0xf3bcc908,
780
+ 0xbb67ae85, 0x84caa73b,
781
+ 0x3c6ef372, 0xfe94f82b,
782
+ 0xa54ff53a, 0x5f1d36f1,
783
+ 0x510e527f, 0xade682d1,
784
+ 0x9b05688c, 0x2b3e6c1f,
785
+ 0x1f83d9ab, 0xfb41bd6b,
786
+ 0x5be0cd19, 0x137e2179
787
+ ];
788
+ this.k = [
789
+ 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
790
+ 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
791
+ 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
792
+ 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
793
+ 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
794
+ 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
795
+ 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
796
+ 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
797
+ 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
798
+ 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
799
+ 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
800
+ 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
801
+ 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
802
+ 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
803
+ 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
804
+ 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
805
+ 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
806
+ 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
807
+ 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
808
+ 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
809
+ 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
810
+ 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
811
+ 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
812
+ 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
813
+ 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
814
+ 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
815
+ 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
816
+ 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
817
+ 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
818
+ 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
819
+ 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
820
+ 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
821
+ 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
822
+ 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
823
+ 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
824
+ 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
825
+ 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
826
+ 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
827
+ 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
828
+ 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
829
+ ];
830
+ this.W = new Array(160);
831
+ }
832
+ _prepareBlock(msg, start) {
833
+ const W = this.W;
834
+ // 32 x 32bit words
835
+ let i;
836
+ for (i = 0; i < 32; i++) {
837
+ W[i] = msg[start + i];
838
+ }
839
+ for (; i < W.length; i += 2) {
840
+ const c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
841
+ const c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
842
+ const c1_hi = W[i - 14]; // i - 7
843
+ const c1_lo = W[i - 13];
844
+ const c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
845
+ const c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
846
+ const c3_hi = W[i - 32]; // i - 16
847
+ const c3_lo = W[i - 31];
848
+ W[i] = sum64_4_hi(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo);
849
+ W[i + 1] = sum64_4_lo(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo);
850
+ }
851
+ }
852
+ _update(msg, start) {
853
+ this._prepareBlock(msg, start);
854
+ const W = this.W;
855
+ let ah = this.h[0];
856
+ let al = this.h[1];
857
+ let bh = this.h[2];
858
+ let bl = this.h[3];
859
+ let ch = this.h[4];
860
+ let cl = this.h[5];
861
+ let dh = this.h[6];
862
+ let dl = this.h[7];
863
+ let eh = this.h[8];
864
+ let el = this.h[9];
865
+ let fh = this.h[10];
866
+ let fl = this.h[11];
867
+ let gh = this.h[12];
868
+ let gl = this.h[13];
869
+ let hh = this.h[14];
870
+ let hl = this.h[15];
871
+ assert(this.k.length === W.length);
872
+ for (let i = 0; i < W.length; i += 2) {
873
+ let c0_hi = hh;
874
+ let c0_lo = hl;
875
+ let c1_hi = s1_512_hi(eh, el);
876
+ let c1_lo = s1_512_lo(eh, el);
877
+ const c2_hi = ch64_hi(eh, el, fh, fl, gh, gl);
878
+ const c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
879
+ const c3_hi = this.k[i];
880
+ const c3_lo = this.k[i + 1];
881
+ const c4_hi = W[i];
882
+ const c4_lo = W[i + 1];
883
+ const T1_hi = sum64_5_hi(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo, c4_hi, c4_lo);
884
+ const T1_lo = sum64_5_lo(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo, c4_hi, c4_lo);
885
+ c0_hi = s0_512_hi(ah, al);
886
+ c0_lo = s0_512_lo(ah, al);
887
+ c1_hi = maj64_hi(ah, al, bh, bl, ch, cl);
888
+ c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
889
+ const T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
890
+ const T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
891
+ hh = gh;
892
+ hl = gl;
893
+ gh = fh;
894
+ gl = fl;
895
+ fh = eh;
896
+ fl = el;
897
+ eh = sum64_hi(dh, dl, T1_hi, T1_lo);
898
+ el = sum64_lo(dl, dl, T1_hi, T1_lo);
899
+ dh = ch;
900
+ dl = cl;
901
+ ch = bh;
902
+ cl = bl;
903
+ bh = ah;
904
+ bl = al;
905
+ ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
906
+ al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
907
+ }
908
+ sum64(this.h, 0, ah, al);
909
+ sum64(this.h, 2, bh, bl);
910
+ sum64(this.h, 4, ch, cl);
911
+ sum64(this.h, 6, dh, dl);
912
+ sum64(this.h, 8, eh, el);
913
+ sum64(this.h, 10, fh, fl);
914
+ sum64(this.h, 12, gh, gl);
915
+ sum64(this.h, 14, hh, hl);
916
+ }
917
+ _digest() {
918
+ return split32(this.h, 'big');
919
+ }
920
+ _digestHex() {
921
+ return toHex32(this.h, 'big');
922
+ }
923
+ }
924
+ exports.SHA512 = SHA512;
925
+ function ch64_hi(xh, xl, yh, yl, zh, zl) {
926
+ let r = (xh & yh) ^ ((~xh) & zh);
927
+ if (r < 0) {
928
+ r += 0x100000000;
929
+ }
930
+ return r;
931
+ }
932
+ function ch64_lo(xh, xl, yh, yl, zh, zl) {
933
+ let r = (xl & yl) ^ ((~xl) & zl);
934
+ if (r < 0) {
935
+ r += 0x100000000;
936
+ }
937
+ return r;
938
+ }
939
+ function maj64_hi(xh, xl, yh, yl, zh, zl) {
940
+ let r = (xh & yh) ^ (xh & zh) ^ (yh & zh);
941
+ if (r < 0) {
942
+ r += 0x100000000;
943
+ }
944
+ return r;
945
+ }
946
+ function maj64_lo(xh, xl, yh, yl, zh, zl) {
947
+ let r = (xl & yl) ^ (xl & zl) ^ (yl & zl);
948
+ if (r < 0) {
949
+ r += 0x100000000;
950
+ }
951
+ return r;
952
+ }
953
+ function s0_512_hi(xh, xl) {
954
+ const c0_hi = rotr64_hi(xh, xl, 28);
955
+ const c1_hi = rotr64_hi(xl, xh, 2); // 34
956
+ const c2_hi = rotr64_hi(xl, xh, 7); // 39
957
+ let r = c0_hi ^ c1_hi ^ c2_hi;
958
+ if (r < 0) {
959
+ r += 0x100000000;
960
+ }
961
+ return r;
962
+ }
963
+ function s0_512_lo(xh, xl) {
964
+ const c0_lo = rotr64_lo(xh, xl, 28);
965
+ const c1_lo = rotr64_lo(xl, xh, 2); // 34
966
+ const c2_lo = rotr64_lo(xl, xh, 7); // 39
967
+ let r = c0_lo ^ c1_lo ^ c2_lo;
968
+ if (r < 0) {
969
+ r += 0x100000000;
970
+ }
971
+ return r;
972
+ }
973
+ function s1_512_hi(xh, xl) {
974
+ const c0_hi = rotr64_hi(xh, xl, 14);
975
+ const c1_hi = rotr64_hi(xh, xl, 18);
976
+ const c2_hi = rotr64_hi(xl, xh, 9); // 41
977
+ let r = c0_hi ^ c1_hi ^ c2_hi;
978
+ if (r < 0) {
979
+ r += 0x100000000;
980
+ }
981
+ return r;
982
+ }
983
+ function s1_512_lo(xh, xl) {
984
+ const c0_lo = rotr64_lo(xh, xl, 14);
985
+ const c1_lo = rotr64_lo(xh, xl, 18);
986
+ const c2_lo = rotr64_lo(xl, xh, 9); // 41
987
+ let r = c0_lo ^ c1_lo ^ c2_lo;
988
+ if (r < 0) {
989
+ r += 0x100000000;
990
+ }
991
+ return r;
992
+ }
993
+ function g0_512_hi(xh, xl) {
994
+ const c0_hi = rotr64_hi(xh, xl, 1);
995
+ const c1_hi = rotr64_hi(xh, xl, 8);
996
+ const c2_hi = shr64_hi(xh, xl, 7);
997
+ let r = c0_hi ^ c1_hi ^ c2_hi;
998
+ if (r < 0) {
999
+ r += 0x100000000;
1000
+ }
1001
+ return r;
1002
+ }
1003
+ function g0_512_lo(xh, xl) {
1004
+ const c0_lo = rotr64_lo(xh, xl, 1);
1005
+ const c1_lo = rotr64_lo(xh, xl, 8);
1006
+ const c2_lo = shr64_lo(xh, xl, 7);
1007
+ let r = c0_lo ^ c1_lo ^ c2_lo;
1008
+ if (r < 0) {
1009
+ r += 0x100000000;
1010
+ }
1011
+ return r;
1012
+ }
1013
+ function g1_512_hi(xh, xl) {
1014
+ const c0_hi = rotr64_hi(xh, xl, 19);
1015
+ const c1_hi = rotr64_hi(xl, xh, 29); // 61
1016
+ const c2_hi = shr64_hi(xh, xl, 6);
1017
+ let r = c0_hi ^ c1_hi ^ c2_hi;
1018
+ if (r < 0) {
1019
+ r += 0x100000000;
1020
+ }
1021
+ return r;
1022
+ }
1023
+ function g1_512_lo(xh, xl) {
1024
+ const c0_lo = rotr64_lo(xh, xl, 19);
1025
+ const c1_lo = rotr64_lo(xl, xh, 29); // 61
1026
+ const c2_lo = shr64_lo(xh, xl, 6);
1027
+ let r = c0_lo ^ c1_lo ^ c2_lo;
1028
+ if (r < 0) {
1029
+ r += 0x100000000;
1030
+ }
1031
+ return r;
1032
+ }
1033
+ /**
1034
+ * The `SHA256HMAC` class is used to create Hash-based Message Authentication Code (HMAC) using the SHA-256 cryptographic hash function.
1035
+ *
1036
+ * HMAC is a specific type of MAC involving a cryptographic hash function and a secret cryptographic key. It may be used to simultaneously verify both the data integrity and the authenticity of a message.
1037
+ *
1038
+ * This class also uses the SHA-256 cryptographic hash algorithm that produces a 256-bit (32-byte) hash value.
1039
+ *
1040
+ * @property inner - Represents the inner hash of SHA-256.
1041
+ * @property outer - Represents the outer hash of SHA-256.
1042
+ * @property blockSize - The block size for the SHA-256 hash function, in bytes. It's set to 64 bytes.
1043
+ * @property outSize - The output size of the SHA-256 hash function, in bytes. It's set to 32 bytes.
1044
+ */
1045
+ class SHA256HMAC {
1046
+ /**
1047
+ * The constructor for the `SHA256HMAC` class.
1048
+ *
1049
+ * It initializes the `SHA256HMAC` object and sets up the inner and outer padded keys.
1050
+ * If the key size is larger than the blockSize, it is digested using SHA-256.
1051
+ * If the key size is less than the blockSize, it is padded with zeroes.
1052
+ *
1053
+ * @constructor
1054
+ * @param key - The key to use to create the HMAC. Can be a number array or a string in hexadecimal format.
1055
+ *
1056
+ * @example
1057
+ * const myHMAC = new SHA256HMAC('deadbeef');
1058
+ */
1059
+ constructor(key) {
1060
+ this.blockSize = 64;
1061
+ this.outSize = 32;
1062
+ key = toArray(key, 'hex');
1063
+ // Shorten key, if needed
1064
+ if (key.length > this.blockSize) {
1065
+ key = new SHA256().update(key).digest();
1066
+ }
1067
+ assert(key.length <= this.blockSize);
1068
+ // Add padding to key
1069
+ let i;
1070
+ for (i = key.length; i < this.blockSize; i++) {
1071
+ key.push(0);
1072
+ }
1073
+ for (i = 0; i < key.length; i++) {
1074
+ key[i] ^= 0x36;
1075
+ }
1076
+ this.inner = new SHA256().update(key);
1077
+ // 0x36 ^ 0x5c = 0x6a
1078
+ for (i = 0; i < key.length; i++) {
1079
+ key[i] ^= 0x6a;
1080
+ }
1081
+ this.outer = new SHA256().update(key);
1082
+ }
1083
+ /**
1084
+ * Updates the `SHA256HMAC` object with part of the message to be hashed.
1085
+ *
1086
+ * @method update
1087
+ * @param msg - Part of the message to hash. Can be a number array or a string.
1088
+ * @param enc - If 'hex', then the input is encoded as hexadecimal. If undefined or not 'hex', then no encoding is performed.
1089
+ * @returns Returns the instance of `SHA256HMAC` for chaining calls.
1090
+ *
1091
+ * @example
1092
+ * myHMAC.update('deadbeef', 'hex');
1093
+ */
1094
+ update(msg, enc) {
1095
+ this.inner.update(msg, enc);
1096
+ return this;
1097
+ }
1098
+ /**
1099
+ * Finalizes the HMAC computation and returns the resultant hash.
1100
+ *
1101
+ * @method digest
1102
+ * @returns Returns the digest of the hashed data. Can be a number array or a string.
1103
+ *
1104
+ * @example
1105
+ * let hashedMessage = myHMAC.digest();
1106
+ */
1107
+ digest() {
1108
+ this.outer.update(this.inner.digest());
1109
+ return this.outer.digest();
1110
+ }
1111
+ /**
1112
+ * Finalizes the HMAC computation and returns the resultant hash as a hex string.
1113
+ *
1114
+ * @method digest
1115
+ * @returns Returns the digest of the hashed data as a hex string
1116
+ *
1117
+ * @example
1118
+ * let hashedMessage = myHMAC.digestHex();
1119
+ */
1120
+ digestHex() {
1121
+ this.outer.update(this.inner.digest());
1122
+ return this.outer.digestHex();
1123
+ }
1124
+ }
1125
+ exports.SHA256HMAC = SHA256HMAC;
1126
+ /**
1127
+ * The `SHA512HMAC` class is used to create Hash-based Message Authentication Code (HMAC) using the SHA-512 cryptographic hash function.
1128
+ *
1129
+ * HMAC is a specific type of MAC involving a cryptographic hash function and a secret cryptographic key. It may be used to simultaneously verify both the data integrity and the authenticity of a message.
1130
+ *
1131
+ * This class also uses the SHA-512 cryptographic hash algorithm that produces a 512-bit (64-byte) hash value.
1132
+ *
1133
+ * @property inner - Represents the inner hash of SHA-512.
1134
+ * @property outer - Represents the outer hash of SHA-512.
1135
+ * @property blockSize - The block size for the SHA-512 hash function, in bytes. It's set to 128 bytes.
1136
+ * @property outSize - The output size of the SHA-512 hash function, in bytes. It's set to 64 bytes.
1137
+ */
1138
+ class SHA512HMAC {
1139
+ /**
1140
+ * The constructor for the `SHA512HMAC` class.
1141
+ *
1142
+ * It initializes the `SHA512HMAC` object and sets up the inner and outer padded keys.
1143
+ * If the key size is larger than the blockSize, it is digested using SHA-512.
1144
+ * If the key size is less than the blockSize, it is padded with zeroes.
1145
+ *
1146
+ * @constructor
1147
+ * @param key - The key to use to create the HMAC. Can be a number array or a string in hexadecimal format.
1148
+ *
1149
+ * @example
1150
+ * const myHMAC = new SHA512HMAC('deadbeef');
1151
+ */
1152
+ constructor(key) {
1153
+ this.blockSize = 128;
1154
+ this.outSize = 32;
1155
+ key = toArray(key, 'hex');
1156
+ // Shorten key, if needed
1157
+ if (key.length > this.blockSize) {
1158
+ key = new SHA512().update(key).digest();
1159
+ }
1160
+ assert(key.length <= this.blockSize);
1161
+ // Add padding to key
1162
+ let i;
1163
+ for (i = key.length; i < this.blockSize; i++) {
1164
+ key.push(0);
1165
+ }
1166
+ for (i = 0; i < key.length; i++) {
1167
+ key[i] ^= 0x36;
1168
+ }
1169
+ this.inner = new SHA512().update(key);
1170
+ // 0x36 ^ 0x5c = 0x6a
1171
+ for (i = 0; i < key.length; i++) {
1172
+ key[i] ^= 0x6a;
1173
+ }
1174
+ this.outer = new SHA512().update(key);
1175
+ }
1176
+ /**
1177
+ * Updates the `SHA512HMAC` object with part of the message to be hashed.
1178
+ *
1179
+ * @method update
1180
+ * @param msg - Part of the message to hash. Can be a number array or a string.
1181
+ * @param enc - If 'hex', then the input is encoded as hexadecimal. If undefined or not 'hex', then no encoding is performed.
1182
+ * @returns Returns the instance of `SHA512HMAC` for chaining calls.
1183
+ *
1184
+ * @example
1185
+ * myHMAC.update('deadbeef', 'hex');
1186
+ */
1187
+ update(msg, enc) {
1188
+ this.inner.update(msg, enc);
1189
+ return this;
1190
+ }
1191
+ /**
1192
+ * Finalizes the HMAC computation and returns the resultant hash.
1193
+ *
1194
+ * @method digest
1195
+ * @returns Returns the digest of the hashed data as a number array.
1196
+ *
1197
+ * @example
1198
+ * let hashedMessage = myHMAC.digest();
1199
+ */
1200
+ digest() {
1201
+ this.outer.update(this.inner.digest());
1202
+ return this.outer.digest();
1203
+ }
1204
+ /**
1205
+ * Finalizes the HMAC computation and returns the resultant hash as a hex string.
1206
+ *
1207
+ * @method digest
1208
+ * @returns Returns the digest of the hashed data as a hex string
1209
+ *
1210
+ * @example
1211
+ * let hashedMessage = myHMAC.digestHex();
1212
+ */
1213
+ digestHex() {
1214
+ this.outer.update(this.inner.digest());
1215
+ return this.outer.digestHex();
1216
+ }
1217
+ }
1218
+ exports.SHA512HMAC = SHA512HMAC;
1219
+ /**
1220
+ * Computes RIPEMD160 hash of a given message.
1221
+ * @function ripemd160
1222
+ * @param msg - The message to compute the hash for.
1223
+ * @param enc - The encoding of msg if string. Default is 'utf8'.
1224
+ *
1225
+ * @returns the computed RIPEMD160 hash of the message.
1226
+ *
1227
+ * @example
1228
+ * const digest = ripemd160('Hello, world!');
1229
+ */
1230
+ const ripemd160 = (msg, enc) => {
1231
+ return new RIPEMD160().update(msg, enc).digest();
1232
+ };
1233
+ exports.ripemd160 = ripemd160;
1234
+ /**
1235
+ * Computes SHA1 hash of a given message.
1236
+ * @function sha1
1237
+ * @param msg - The message to compute the hash for.
1238
+ * @param enc - The encoding of msg if string. Default is 'utf8'.
1239
+ *
1240
+ * @returns the computed SHA1 hash of the message.
1241
+ *
1242
+ * @example
1243
+ * const digest = sha1('Hello, world!');
1244
+ */
1245
+ const sha1 = (msg, enc) => {
1246
+ return new SHA1().update(msg, enc).digest();
1247
+ };
1248
+ exports.sha1 = sha1;
1249
+ /**
1250
+ * Computes SHA256 hash of a given message.
1251
+ * @function sha256
1252
+ * @param msg - The message to compute the hash for.
1253
+ * @param enc - The encoding of msg if string. Default is 'utf8'.
1254
+ *
1255
+ * @returns the computed SHA256 hash of the message.
1256
+ *
1257
+ * @example
1258
+ * const digest = sha256('Hello, world!');
1259
+ */
1260
+ const sha256 = (msg, enc) => {
1261
+ return new SHA256().update(msg, enc).digest();
1262
+ };
1263
+ exports.sha256 = sha256;
1264
+ /**
1265
+ * Computes SHA512 hash of a given message.
1266
+ * @function sha512
1267
+ * @param msg - The message to compute the hash for.
1268
+ * @param enc - The encoding of msg if string. Default is 'utf8'.
1269
+ *
1270
+ * @returns the computed SHA512 hash of the message.
1271
+ *
1272
+ * @example
1273
+ * const digest = sha512('Hello, world!');
1274
+ */
1275
+ const sha512 = (msg, enc) => {
1276
+ return new SHA512().update(msg, enc).digest();
1277
+ };
1278
+ exports.sha512 = sha512;
1279
+ /**
1280
+ * Performs a 'double hash' using SHA256. This means the data is hashed twice
1281
+ * with SHA256. First, the SHA256 hash of the message is computed, then the
1282
+ * SHA256 hash of the resulting hash is computed.
1283
+ * @function hash256
1284
+ * @param msg - The message to compute the hash for.
1285
+ * @param enc - The encoding of msg if string. Default is 'utf8'.
1286
+ *
1287
+ * @returns the double hashed SHA256 output.
1288
+ *
1289
+ * @example
1290
+ * const doubleHash = hash256('Hello, world!');
1291
+ */
1292
+ const hash256 = (msg, enc) => {
1293
+ const first = new SHA256().update(msg, enc).digest();
1294
+ return new SHA256().update(first).digest();
1295
+ };
1296
+ exports.hash256 = hash256;
1297
+ /**
1298
+ * Computes SHA256 hash of a given message and then computes a RIPEMD160 hash of the result.
1299
+ *
1300
+ * @function hash160
1301
+ * @param msg - The message to compute the hash for.
1302
+ * @param enc - The encoding of msg if string. Default is 'utf8'.
1303
+ *
1304
+ * @returns the RIPEMD160 hash of the SHA256 hash of the input message.
1305
+ *
1306
+ * @example
1307
+ * const hash = hash160('Hello, world!');
1308
+ */
1309
+ const hash160 = (msg, enc) => {
1310
+ const first = new SHA256().update(msg, enc).digest();
1311
+ return new RIPEMD160().update(first).digest();
1312
+ };
1313
+ exports.hash160 = hash160;
1314
+ /**
1315
+ * Computes SHA256 HMAC of a given message with a given key.
1316
+ * @function sha256hmac
1317
+ * @param key - The key used to compute the HMAC
1318
+ * @param msg - The message to compute the hash for.
1319
+ * @param enc - The encoding of msg if string. Default is 'utf8'.
1320
+ *
1321
+ * @returns the computed HMAC of the message.
1322
+ *
1323
+ * @example
1324
+ * const digest = sha256hmac('deadbeef', 'ffff001d');
1325
+ */
1326
+ const sha256hmac = (key, msg, enc) => {
1327
+ return new SHA256HMAC(key).update(msg, enc).digest();
1328
+ };
1329
+ exports.sha256hmac = sha256hmac;
1330
+ /**
1331
+ * Computes SHA512 HMAC of a given message with a given key.
1332
+ * @function sha512hmac
1333
+ * @param key - The key used to compute the HMAC
1334
+ * @param msg - The message to compute the hash for.
1335
+ * @param enc - The encoding of msg if string. Default is 'utf8'.
1336
+ *
1337
+ * @returns the computed HMAC of the message.
1338
+ *
1339
+ * @example
1340
+ * const digest = sha512hmac('deadbeef', 'ffff001d');
1341
+ */
1342
+ const sha512hmac = (key, msg, enc) => {
1343
+ return new SHA512HMAC(key).update(msg, enc).digest();
1344
+ };
1345
+ exports.sha512hmac = sha512hmac;
1346
+ /**
1347
+ * Limited SHA-512-only PBKDF2 function for use in deprecated BIP39 code.
1348
+ * @function pbkdf2
1349
+ * @param password - The PBKDF2 password
1350
+ * @param salt - The PBKDF2 salt
1351
+ * @param iterations - The number of of iterations to run
1352
+ * @param keylen - The length of the key
1353
+ * @param digest - The digest (must be sha512 for this implementation)
1354
+ *
1355
+ * @returns The computed key
1356
+ */
1357
+ function pbkdf2(password, salt, iterations, keylen, digest = 'sha512') {
1358
+ if (digest !== 'sha512') {
1359
+ throw new Error('Only sha512 is supported in this PBKDF2 implementation');
1360
+ }
1361
+ const DK = new Array(keylen);
1362
+ const block1 = [...salt, 0, 0, 0, 0];
1363
+ const s = Buffer.from('hello');
1364
+ let destPos = 0;
1365
+ const hLen = 64;
1366
+ const l = Math.ceil(keylen / hLen);
1367
+ for (let i = 1; i <= l; i++) {
1368
+ block1[salt.length] = (i >> 24) & 0xFF; // MSB
1369
+ block1[salt.length + 1] = (i >> 16) & 0xFF;
1370
+ block1[salt.length + 2] = (i >> 8) & 0xFF;
1371
+ block1[salt.length + 3] = i & 0xFF; // LSB
1372
+ const T = (0, exports.sha512hmac)(password, block1);
1373
+ let U = T;
1374
+ for (let j = 1; j < iterations; j++) {
1375
+ U = (0, exports.sha512hmac)(password, U);
1376
+ for (let k = 0; k < hLen; k++)
1377
+ T[k] ^= U[k];
1378
+ }
1379
+ for (let i = 0; i < T.length; i++) {
1380
+ DK[destPos + i] = T[i];
1381
+ }
1382
+ destPos += hLen;
1383
+ }
1384
+ return DK.slice(0, keylen);
1385
+ }
1386
+ exports.pbkdf2 = pbkdf2;
1387
+ //# sourceMappingURL=Hash.js.map