@bsv/sdk 1.0.26 → 1.0.29

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