@helios-lang/effect 0.1.15 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (399) hide show
  1. package/dist/Cardano/CoinSelection.js +130 -0
  2. package/dist/Cardano/CoinSelection.js.map +1 -0
  3. package/dist/{Ledger → Cardano/Ledger}/Address.js +31 -21
  4. package/dist/Cardano/Ledger/Address.js.map +1 -0
  5. package/dist/{Ledger → Cardano/Ledger}/AssetClass.js +16 -11
  6. package/dist/Cardano/Ledger/AssetClass.js.map +1 -0
  7. package/dist/Cardano/Ledger/Assets.js +235 -0
  8. package/dist/Cardano/Ledger/Assets.js.map +1 -0
  9. package/dist/Cardano/Ledger/Credential.js +53 -0
  10. package/dist/Cardano/Ledger/Credential.js.map +1 -0
  11. package/dist/Cardano/Ledger/DCert.js +117 -0
  12. package/dist/Cardano/Ledger/DCert.js.map +1 -0
  13. package/dist/Cardano/Ledger/DatumHash.js +25 -0
  14. package/dist/Cardano/Ledger/DatumHash.js.map +1 -0
  15. package/dist/Cardano/Ledger/MintingPolicy.js +40 -0
  16. package/dist/Cardano/Ledger/MintingPolicy.js.map +1 -0
  17. package/dist/Cardano/Ledger/NativeScript.js +140 -0
  18. package/dist/Cardano/Ledger/NativeScript.js.map +1 -0
  19. package/dist/Cardano/Ledger/PubKey.js +24 -0
  20. package/dist/Cardano/Ledger/PubKey.js.map +1 -0
  21. package/dist/{Ledger → Cardano/Ledger}/PubKeyHash.js +5 -5
  22. package/dist/Cardano/Ledger/PubKeyHash.js.map +1 -0
  23. package/dist/Cardano/Ledger/Redeemer.js +155 -0
  24. package/dist/Cardano/Ledger/Redeemer.js.map +1 -0
  25. package/dist/Cardano/Ledger/RewardAddress.js +93 -0
  26. package/dist/Cardano/Ledger/RewardAddress.js.map +1 -0
  27. package/dist/Cardano/Ledger/Signature.js +23 -0
  28. package/dist/Cardano/Ledger/Signature.js.map +1 -0
  29. package/dist/Cardano/Ledger/Tx.js +498 -0
  30. package/dist/Cardano/Ledger/Tx.js.map +1 -0
  31. package/dist/Cardano/Ledger/TxHash.js +38 -0
  32. package/dist/Cardano/Ledger/TxHash.js.map +1 -0
  33. package/dist/Cardano/Ledger/TxOutput.js +167 -0
  34. package/dist/Cardano/Ledger/TxOutput.js.map +1 -0
  35. package/dist/{Ledger → Cardano/Ledger}/TxOutputDatum.js +44 -8
  36. package/dist/Cardano/Ledger/TxOutputDatum.js.map +1 -0
  37. package/dist/Cardano/Ledger/UTxO.js +100 -0
  38. package/dist/Cardano/Ledger/UTxO.js.map +1 -0
  39. package/dist/{Ledger → Cardano/Ledger}/UTxORef.js +28 -6
  40. package/dist/Cardano/Ledger/UTxORef.js.map +1 -0
  41. package/dist/{Ledger → Cardano/Ledger}/ValidatorHash.js +5 -5
  42. package/dist/Cardano/Ledger/ValidatorHash.js.map +1 -0
  43. package/dist/{Ledger → Cardano/Ledger}/index.js +6 -0
  44. package/dist/Cardano/Ledger/index.js.map +1 -0
  45. package/dist/Cardano/Network/IsMainnet.js.map +1 -0
  46. package/dist/{Network → Cardano/Network}/Params.js +27 -3
  47. package/dist/Cardano/Network/Params.js.map +1 -0
  48. package/dist/Cardano/Network/UTxO.js +20 -0
  49. package/dist/Cardano/Network/UTxO.js.map +1 -0
  50. package/dist/Cardano/Network/UTxOsAt.js +4 -0
  51. package/dist/Cardano/Network/UTxOsAt.js.map +1 -0
  52. package/dist/Cardano/Network/errors.js +33 -0
  53. package/dist/Cardano/Network/errors.js.map +1 -0
  54. package/dist/{Network → Cardano/Network}/index.js +1 -0
  55. package/dist/Cardano/Network/index.js.map +1 -0
  56. package/dist/Cardano/TxBuilder.js +963 -0
  57. package/dist/Cardano/TxBuilder.js.map +1 -0
  58. package/dist/Cardano/Uplc/Builtins.js +1820 -0
  59. package/dist/Cardano/Uplc/Builtins.js.map +1 -0
  60. package/dist/Cardano/Uplc/Cek.js +716 -0
  61. package/dist/Cardano/Uplc/Cek.js.map +1 -0
  62. package/dist/Cardano/Uplc/Cost.js +956 -0
  63. package/dist/Cardano/Uplc/Cost.js.map +1 -0
  64. package/dist/{Uplc → Cardano/Uplc}/Data.js +143 -22
  65. package/dist/Cardano/Uplc/Data.js.map +1 -0
  66. package/dist/Cardano/Uplc/Script.js +118 -0
  67. package/dist/Cardano/Uplc/Script.js.map +1 -0
  68. package/dist/Cardano/Uplc/ScriptContext.js +259 -0
  69. package/dist/Cardano/Uplc/ScriptContext.js.map +1 -0
  70. package/dist/Cardano/Uplc/Term.js +384 -0
  71. package/dist/Cardano/Uplc/Term.js.map +1 -0
  72. package/dist/Cardano/Uplc/Type.js +131 -0
  73. package/dist/Cardano/Uplc/Type.js.map +1 -0
  74. package/dist/Cardano/Uplc/Value.js +315 -0
  75. package/dist/Cardano/Uplc/Value.js.map +1 -0
  76. package/dist/Cardano/Uplc/index.js +7 -0
  77. package/dist/Cardano/Uplc/index.js.map +1 -0
  78. package/dist/Cardano/Wallet.js +48 -0
  79. package/dist/Cardano/Wallet.js.map +1 -0
  80. package/dist/Cardano/index.js +7 -0
  81. package/dist/Cardano/index.js.map +1 -0
  82. package/dist/{internal → Codecs}/Base32.js +2 -2
  83. package/dist/Codecs/Base32.js.map +1 -0
  84. package/dist/{Bech32.js → Codecs/Bech32.js} +2 -2
  85. package/dist/Codecs/Bech32.js.map +1 -0
  86. package/dist/Codecs/BigEndian.js.map +1 -0
  87. package/dist/Codecs/Bits.js.map +1 -0
  88. package/dist/{internal → Codecs}/Bytes.js +23 -12
  89. package/dist/Codecs/Bytes.js.map +1 -0
  90. package/dist/{Cbor.js → Codecs/Cbor.js} +559 -328
  91. package/dist/Codecs/Cbor.js.map +1 -0
  92. package/dist/{internal → Codecs}/Flat.js +16 -0
  93. package/dist/Codecs/Flat.js.map +1 -0
  94. package/dist/Codecs/Float.js.map +1 -0
  95. package/dist/Codecs/LittleEndian.js +31 -0
  96. package/dist/Codecs/LittleEndian.js.map +1 -0
  97. package/dist/Codecs/Uint64.js +89 -0
  98. package/dist/Codecs/Uint64.js.map +1 -0
  99. package/dist/{internal → Codecs}/Utf8.js +7 -2
  100. package/dist/Codecs/Utf8.js.map +1 -0
  101. package/dist/Codecs/ZigZag.js +26 -0
  102. package/dist/Codecs/ZigZag.js.map +1 -0
  103. package/dist/Codecs/index.js +8 -0
  104. package/dist/Codecs/index.js.map +1 -0
  105. package/dist/Crypto/Bip32.js +131 -0
  106. package/dist/Crypto/Bip32.js.map +1 -0
  107. package/dist/Crypto/Bip39.js +2176 -0
  108. package/dist/Crypto/Bip39.js.map +1 -0
  109. package/dist/Crypto/Blake2b.js +156 -0
  110. package/dist/Crypto/Blake2b.js.map +1 -0
  111. package/dist/Crypto/Curve.js +92 -0
  112. package/dist/Crypto/Curve.js.map +1 -0
  113. package/dist/Crypto/Ed25519.js +323 -0
  114. package/dist/Crypto/Ed25519.js.map +1 -0
  115. package/dist/Crypto/EdDSA.js +222 -0
  116. package/dist/Crypto/EdDSA.js.map +1 -0
  117. package/dist/Crypto/Field.js +323 -0
  118. package/dist/Crypto/Field.js.map +1 -0
  119. package/dist/Crypto/Hmac.js +51 -0
  120. package/dist/Crypto/Hmac.js.map +1 -0
  121. package/dist/Crypto/Keccak.js +167 -0
  122. package/dist/Crypto/Keccak.js.map +1 -0
  123. package/dist/Crypto/Pbkdf2.js +45 -0
  124. package/dist/Crypto/Pbkdf2.js.map +1 -0
  125. package/dist/Crypto/Sha2_256.js +200 -0
  126. package/dist/Crypto/Sha2_256.js.map +1 -0
  127. package/dist/Crypto/Sha2_512.js +264 -0
  128. package/dist/Crypto/Sha2_512.js.map +1 -0
  129. package/dist/Crypto/Sha3_256.js +10 -0
  130. package/dist/Crypto/Sha3_256.js.map +1 -0
  131. package/dist/Crypto/errors.js +9 -0
  132. package/dist/Crypto/errors.js.map +1 -0
  133. package/dist/Crypto/index.js +12 -0
  134. package/dist/Crypto/index.js.map +1 -0
  135. package/dist/index.js +3 -5
  136. package/dist/index.js.map +1 -1
  137. package/package.json +24 -6
  138. package/tsconfig.build.json +1 -1
  139. package/types/Cardano/CoinSelection.d.ts +26 -0
  140. package/types/Cardano/CoinSelection.d.ts.map +1 -0
  141. package/types/{Ledger → Cardano/Ledger}/Address.d.ts +8 -7
  142. package/types/Cardano/Ledger/Address.d.ts.map +1 -0
  143. package/types/{Ledger → Cardano/Ledger}/AssetClass.d.ts +2 -2
  144. package/types/Cardano/Ledger/AssetClass.d.ts.map +1 -0
  145. package/types/Cardano/Ledger/Assets.d.ts +114 -0
  146. package/types/Cardano/Ledger/Assets.d.ts.map +1 -0
  147. package/types/{Ledger → Cardano/Ledger}/Credential.d.ts +10 -4
  148. package/types/Cardano/Ledger/Credential.d.ts.map +1 -0
  149. package/types/Cardano/Ledger/DCert.d.ts +40 -0
  150. package/types/Cardano/Ledger/DCert.d.ts.map +1 -0
  151. package/types/{Ledger → Cardano/Ledger}/DatumHash.d.ts +6 -5
  152. package/types/Cardano/Ledger/DatumHash.d.ts.map +1 -0
  153. package/types/{Ledger → Cardano/Ledger}/MintingPolicy.d.ts +11 -8
  154. package/types/Cardano/Ledger/MintingPolicy.d.ts.map +1 -0
  155. package/types/Cardano/Ledger/NativeScript.d.ts +105 -0
  156. package/types/Cardano/Ledger/NativeScript.d.ts.map +1 -0
  157. package/types/Cardano/Ledger/PubKey.d.ts +45 -0
  158. package/types/Cardano/Ledger/PubKey.d.ts.map +1 -0
  159. package/types/{Ledger → Cardano/Ledger}/PubKeyHash.d.ts +5 -5
  160. package/types/Cardano/Ledger/PubKeyHash.d.ts.map +1 -0
  161. package/types/Cardano/Ledger/Redeemer.d.ts +303 -0
  162. package/types/Cardano/Ledger/Redeemer.d.ts.map +1 -0
  163. package/types/Cardano/Ledger/RewardAddress.d.ts +60 -0
  164. package/types/Cardano/Ledger/RewardAddress.d.ts.map +1 -0
  165. package/types/Cardano/Ledger/Signature.d.ts +13 -0
  166. package/types/Cardano/Ledger/Signature.d.ts.map +1 -0
  167. package/types/Cardano/Ledger/Tx.d.ts +375 -0
  168. package/types/Cardano/Ledger/Tx.d.ts.map +1 -0
  169. package/types/{Ledger → Cardano/Ledger}/TxHash.d.ts +35 -5
  170. package/types/Cardano/Ledger/TxHash.d.ts.map +1 -0
  171. package/types/Cardano/Ledger/TxOutput.d.ts +438 -0
  172. package/types/Cardano/Ledger/TxOutput.d.ts.map +1 -0
  173. package/types/Cardano/Ledger/TxOutputDatum.d.ts +98 -0
  174. package/types/Cardano/Ledger/TxOutputDatum.d.ts.map +1 -0
  175. package/types/Cardano/Ledger/UTxO.d.ts +1420 -0
  176. package/types/Cardano/Ledger/UTxO.d.ts.map +1 -0
  177. package/types/Cardano/Ledger/UTxORef.d.ts +222 -0
  178. package/types/Cardano/Ledger/UTxORef.d.ts.map +1 -0
  179. package/types/{Ledger → Cardano/Ledger}/ValidatorHash.d.ts +5 -5
  180. package/types/Cardano/Ledger/ValidatorHash.d.ts.map +1 -0
  181. package/types/{Ledger → Cardano/Ledger}/index.d.ts +6 -0
  182. package/types/Cardano/Ledger/index.d.ts.map +1 -0
  183. package/types/Cardano/Network/IsMainnet.d.ts.map +1 -0
  184. package/types/{Network → Cardano/Network}/Params.d.ts +32 -4
  185. package/types/Cardano/Network/Params.d.ts.map +1 -0
  186. package/types/Cardano/Network/UTxO.d.ts +15 -0
  187. package/types/Cardano/Network/UTxO.d.ts.map +1 -0
  188. package/types/Cardano/Network/UTxOsAt.d.ts +9 -0
  189. package/types/Cardano/Network/UTxOsAt.d.ts.map +1 -0
  190. package/types/Cardano/Network/errors.d.ts +39 -0
  191. package/types/Cardano/Network/errors.d.ts.map +1 -0
  192. package/types/{Network → Cardano/Network}/index.d.ts +1 -0
  193. package/types/Cardano/Network/index.d.ts.map +1 -0
  194. package/types/Cardano/TxBuilder.d.ts +232 -0
  195. package/types/Cardano/TxBuilder.d.ts.map +1 -0
  196. package/types/Cardano/Uplc/Builtins.d.ts +163 -0
  197. package/types/Cardano/Uplc/Builtins.d.ts.map +1 -0
  198. package/types/Cardano/Uplc/Cek.d.ts +165 -0
  199. package/types/Cardano/Uplc/Cek.d.ts.map +1 -0
  200. package/types/Cardano/Uplc/Cost.d.ts +93 -0
  201. package/types/Cardano/Uplc/Cost.d.ts.map +1 -0
  202. package/types/{Uplc → Cardano/Uplc}/Data.d.ts +149 -15
  203. package/types/Cardano/Uplc/Data.d.ts.map +1 -0
  204. package/types/Cardano/Uplc/Script.d.ts +87 -0
  205. package/types/Cardano/Uplc/Script.d.ts.map +1 -0
  206. package/types/Cardano/Uplc/ScriptContext.d.ts +21 -0
  207. package/types/Cardano/Uplc/ScriptContext.d.ts.map +1 -0
  208. package/types/Cardano/Uplc/Term.d.ts +454 -0
  209. package/types/Cardano/Uplc/Term.d.ts.map +1 -0
  210. package/types/Cardano/Uplc/Type.d.ts +29 -0
  211. package/types/Cardano/Uplc/Type.d.ts.map +1 -0
  212. package/types/Cardano/Uplc/Value.d.ts +152 -0
  213. package/types/Cardano/Uplc/Value.d.ts.map +1 -0
  214. package/types/Cardano/Uplc/index.d.ts +7 -0
  215. package/types/Cardano/Uplc/index.d.ts.map +1 -0
  216. package/types/Cardano/Wallet.d.ts +73 -0
  217. package/types/Cardano/Wallet.d.ts.map +1 -0
  218. package/types/Cardano/index.d.ts +7 -0
  219. package/types/Cardano/index.d.ts.map +1 -0
  220. package/types/Codecs/Base32.d.ts.map +1 -0
  221. package/types/Codecs/Bech32.d.ts.map +1 -0
  222. package/types/Codecs/BigEndian.d.ts.map +1 -0
  223. package/types/Codecs/Bits.d.ts.map +1 -0
  224. package/types/{internal → Codecs}/Bytes.d.ts +7 -6
  225. package/types/Codecs/Bytes.d.ts.map +1 -0
  226. package/types/{Cbor.d.ts → Codecs/Cbor.d.ts} +77 -55
  227. package/types/Codecs/Cbor.d.ts.map +1 -0
  228. package/types/{internal → Codecs}/Flat.d.ts +2 -0
  229. package/types/Codecs/Flat.d.ts.map +1 -0
  230. package/types/Codecs/Float.d.ts.map +1 -0
  231. package/types/Codecs/LittleEndian.d.ts +19 -0
  232. package/types/Codecs/LittleEndian.d.ts.map +1 -0
  233. package/types/Codecs/Uint64.d.ts +16 -0
  234. package/types/Codecs/Uint64.d.ts.map +1 -0
  235. package/types/{internal → Codecs}/Utf8.d.ts +2 -2
  236. package/types/Codecs/Utf8.d.ts.map +1 -0
  237. package/types/Codecs/ZigZag.d.ts +3 -0
  238. package/types/Codecs/ZigZag.d.ts.map +1 -0
  239. package/types/Codecs/index.d.ts +8 -0
  240. package/types/Codecs/index.d.ts.map +1 -0
  241. package/types/Crypto/Bip32.d.ts +29 -0
  242. package/types/Crypto/Bip32.d.ts.map +1 -0
  243. package/types/Crypto/Bip39.d.ts +43 -0
  244. package/types/Crypto/Bip39.d.ts.map +1 -0
  245. package/types/Crypto/Blake2b.d.ts +16 -0
  246. package/types/Crypto/Blake2b.d.ts.map +1 -0
  247. package/types/Crypto/Curve.d.ts +161 -0
  248. package/types/Crypto/Curve.d.ts.map +1 -0
  249. package/types/Crypto/Ed25519.d.ts +155 -0
  250. package/types/Crypto/Ed25519.d.ts.map +1 -0
  251. package/types/Crypto/EdDSA.d.ts +159 -0
  252. package/types/Crypto/EdDSA.d.ts.map +1 -0
  253. package/types/Crypto/Field.d.ts +273 -0
  254. package/types/Crypto/Field.d.ts.map +1 -0
  255. package/types/Crypto/Hmac.d.ts +20 -0
  256. package/types/Crypto/Hmac.d.ts.map +1 -0
  257. package/types/Crypto/Keccak.d.ts +16 -0
  258. package/types/Crypto/Keccak.d.ts.map +1 -0
  259. package/types/Crypto/Pbkdf2.d.ts +15 -0
  260. package/types/Crypto/Pbkdf2.d.ts.map +1 -0
  261. package/types/Crypto/Sha2_256.d.ts +36 -0
  262. package/types/Crypto/Sha2_256.d.ts.map +1 -0
  263. package/types/Crypto/Sha2_512.d.ts +31 -0
  264. package/types/Crypto/Sha2_512.d.ts.map +1 -0
  265. package/types/Crypto/Sha3_256.d.ts +8 -0
  266. package/types/Crypto/Sha3_256.d.ts.map +1 -0
  267. package/types/Crypto/errors.d.ts +10 -0
  268. package/types/Crypto/errors.d.ts.map +1 -0
  269. package/types/Crypto/index.d.ts +12 -0
  270. package/types/Crypto/index.d.ts.map +1 -0
  271. package/types/index.d.ts +3 -5
  272. package/types/index.d.ts.map +1 -1
  273. package/dist/Address.js +0 -13
  274. package/dist/Address.js.map +0 -1
  275. package/dist/Bech32.js.map +0 -1
  276. package/dist/Cbor.js.map +0 -1
  277. package/dist/Ledger/Address.js.map +0 -1
  278. package/dist/Ledger/AssetClass.js.map +0 -1
  279. package/dist/Ledger/Assets.js +0 -120
  280. package/dist/Ledger/Assets.js.map +0 -1
  281. package/dist/Ledger/Credential.js +0 -17
  282. package/dist/Ledger/Credential.js.map +0 -1
  283. package/dist/Ledger/DatumHash.js +0 -21
  284. package/dist/Ledger/DatumHash.js.map +0 -1
  285. package/dist/Ledger/IsMainnet.js +0 -4
  286. package/dist/Ledger/IsMainnet.js.map +0 -1
  287. package/dist/Ledger/MintingPolicy.js +0 -45
  288. package/dist/Ledger/MintingPolicy.js.map +0 -1
  289. package/dist/Ledger/NetworkParams.js +0 -40
  290. package/dist/Ledger/NetworkParams.js.map +0 -1
  291. package/dist/Ledger/PubKeyHash.js.map +0 -1
  292. package/dist/Ledger/TxHash.js +0 -23
  293. package/dist/Ledger/TxHash.js.map +0 -1
  294. package/dist/Ledger/TxId.js +0 -23
  295. package/dist/Ledger/TxId.js.map +0 -1
  296. package/dist/Ledger/TxInput.js +0 -51
  297. package/dist/Ledger/TxInput.js.map +0 -1
  298. package/dist/Ledger/TxOutput.js +0 -118
  299. package/dist/Ledger/TxOutput.js.map +0 -1
  300. package/dist/Ledger/TxOutputDatum.js.map +0 -1
  301. package/dist/Ledger/TxOutputId.js +0 -55
  302. package/dist/Ledger/TxOutputId.js.map +0 -1
  303. package/dist/Ledger/UTxO.js +0 -43
  304. package/dist/Ledger/UTxO.js.map +0 -1
  305. package/dist/Ledger/UTxORef.js.map +0 -1
  306. package/dist/Ledger/ValidatorHash.js.map +0 -1
  307. package/dist/Ledger/index.js.map +0 -1
  308. package/dist/Network/IsMainnet.js.map +0 -1
  309. package/dist/Network/Params.js.map +0 -1
  310. package/dist/Network/UTxOsAt.js +0 -4
  311. package/dist/Network/UTxOsAt.js.map +0 -1
  312. package/dist/Network/errors.js +0 -16
  313. package/dist/Network/errors.js.map +0 -1
  314. package/dist/Network/index.js.map +0 -1
  315. package/dist/Uplc/Cek.js +0 -3
  316. package/dist/Uplc/Cek.js.map +0 -1
  317. package/dist/Uplc/Data.js.map +0 -1
  318. package/dist/Uplc/DataSchema.js +0 -118
  319. package/dist/Uplc/DataSchema.js.map +0 -1
  320. package/dist/Uplc/Primitive.js +0 -23
  321. package/dist/Uplc/Primitive.js.map +0 -1
  322. package/dist/Uplc/index.js +0 -3
  323. package/dist/Uplc/index.js.map +0 -1
  324. package/dist/internal/Base32.js.map +0 -1
  325. package/dist/internal/BigEndian.js.map +0 -1
  326. package/dist/internal/Bits.js.map +0 -1
  327. package/dist/internal/Bytes.js.map +0 -1
  328. package/dist/internal/Flat.js.map +0 -1
  329. package/dist/internal/Float.js.map +0 -1
  330. package/dist/internal/Utf8.js.map +0 -1
  331. package/tsconfig.build.tsbuildinfo +0 -1
  332. package/tsconfig.check.tsbuildinfo +0 -1
  333. package/tsconfig.tsbuildinfo +0 -1
  334. package/types/Address.d.ts +0 -5
  335. package/types/Address.d.ts.map +0 -1
  336. package/types/Bech32.d.ts.map +0 -1
  337. package/types/Cbor.d.ts.map +0 -1
  338. package/types/Ledger/Address.d.ts.map +0 -1
  339. package/types/Ledger/AssetClass.d.ts.map +0 -1
  340. package/types/Ledger/Assets.d.ts +0 -70
  341. package/types/Ledger/Assets.d.ts.map +0 -1
  342. package/types/Ledger/Credential.d.ts.map +0 -1
  343. package/types/Ledger/DatumHash.d.ts.map +0 -1
  344. package/types/Ledger/IsMainnet.d.ts +0 -6
  345. package/types/Ledger/IsMainnet.d.ts.map +0 -1
  346. package/types/Ledger/MintingPolicy.d.ts.map +0 -1
  347. package/types/Ledger/NetworkParams.d.ts +0 -40
  348. package/types/Ledger/NetworkParams.d.ts.map +0 -1
  349. package/types/Ledger/PubKeyHash.d.ts.map +0 -1
  350. package/types/Ledger/TxHash.d.ts.map +0 -1
  351. package/types/Ledger/TxId.d.ts +0 -70
  352. package/types/Ledger/TxId.d.ts.map +0 -1
  353. package/types/Ledger/TxInput.d.ts +0 -55
  354. package/types/Ledger/TxInput.d.ts.map +0 -1
  355. package/types/Ledger/TxOutput.d.ts +0 -63
  356. package/types/Ledger/TxOutput.d.ts.map +0 -1
  357. package/types/Ledger/TxOutputDatum.d.ts +0 -41
  358. package/types/Ledger/TxOutputDatum.d.ts.map +0 -1
  359. package/types/Ledger/TxOutputId.d.ts +0 -133
  360. package/types/Ledger/TxOutputId.d.ts.map +0 -1
  361. package/types/Ledger/UTxO.d.ts +0 -55
  362. package/types/Ledger/UTxO.d.ts.map +0 -1
  363. package/types/Ledger/UTxORef.d.ts +0 -133
  364. package/types/Ledger/UTxORef.d.ts.map +0 -1
  365. package/types/Ledger/ValidatorHash.d.ts.map +0 -1
  366. package/types/Ledger/index.d.ts.map +0 -1
  367. package/types/Network/IsMainnet.d.ts.map +0 -1
  368. package/types/Network/Params.d.ts.map +0 -1
  369. package/types/Network/UTxOsAt.d.ts +0 -9
  370. package/types/Network/UTxOsAt.d.ts.map +0 -1
  371. package/types/Network/errors.d.ts +0 -18
  372. package/types/Network/errors.d.ts.map +0 -1
  373. package/types/Network/index.d.ts.map +0 -1
  374. package/types/Uplc/Cek.d.ts +0 -72
  375. package/types/Uplc/Cek.d.ts.map +0 -1
  376. package/types/Uplc/Data.d.ts.map +0 -1
  377. package/types/Uplc/DataSchema.d.ts +0 -227
  378. package/types/Uplc/DataSchema.d.ts.map +0 -1
  379. package/types/Uplc/Primitive.d.ts +0 -26
  380. package/types/Uplc/Primitive.d.ts.map +0 -1
  381. package/types/Uplc/index.d.ts +0 -3
  382. package/types/Uplc/index.d.ts.map +0 -1
  383. package/types/internal/Base32.d.ts.map +0 -1
  384. package/types/internal/BigEndian.d.ts.map +0 -1
  385. package/types/internal/Bits.d.ts.map +0 -1
  386. package/types/internal/Bytes.d.ts.map +0 -1
  387. package/types/internal/Flat.d.ts.map +0 -1
  388. package/types/internal/Float.d.ts.map +0 -1
  389. package/types/internal/Utf8.d.ts.map +0 -1
  390. /package/dist/{Network → Cardano/Network}/IsMainnet.js +0 -0
  391. /package/dist/{internal → Codecs}/BigEndian.js +0 -0
  392. /package/dist/{internal → Codecs}/Bits.js +0 -0
  393. /package/dist/{internal → Codecs}/Float.js +0 -0
  394. /package/types/{Network → Cardano/Network}/IsMainnet.d.ts +0 -0
  395. /package/types/{internal → Codecs}/Base32.d.ts +0 -0
  396. /package/types/{Bech32.d.ts → Codecs/Bech32.d.ts} +0 -0
  397. /package/types/{internal → Codecs}/BigEndian.d.ts +0 -0
  398. /package/types/{internal → Codecs}/Bits.d.ts +0 -0
  399. /package/types/{internal → Codecs}/Float.d.ts +0 -0
@@ -0,0 +1,222 @@
1
+ import { Data, Either } from "effect";
2
+ import { CurveHelper } from "./Curve.js";
3
+ import * as Sha2_512 from "./Sha2_512.js";
4
+ export class BadPrivateKeyLength extends Data.TaggedError("Crypto.EdDSA.BadPrivateKeyLength") {
5
+ constructor(privateKey) {
6
+ super({
7
+ message: `expected extended privateKey with a length of 64 bytes, this privateKey is ${privateKey.length} bytes long (hint: pass hashPrivateKey = true)`
8
+ });
9
+ }
10
+ }
11
+ export class BadSignatureLength extends Data.TaggedError("Crypto.EdDSA.BadSignatureLength") {
12
+ constructor(signature) {
13
+ super({ message: `unexpected signature length ${signature.length}` });
14
+ }
15
+ }
16
+ export class BadPublicKeyLength extends Data.TaggedError("Crypto.EdDSA.BadPublicKeyLength") {
17
+ constructor(publicKey) {
18
+ super({ message: `unexpected publicKey length ${publicKey.length}` });
19
+ }
20
+ }
21
+ /**
22
+ * Edwards Digital Signing Algorithm
23
+ *
24
+ * Symbols based on the book "Elliptic Curves in Cryptography" by I.F. Blake, G. Seroussi and N.P. Smart
25
+ * See page 4 for an overview of the DSA algorithm.
26
+ * This book along with the first few sections of "Cryptography: An Introduction" by N.P. Smart are
27
+ * recommended reads in order to understand better the concepts of "scalars" and "CurvePoint" and
28
+ * their arithmatic over finite fields.
29
+ *
30
+ * Notation:
31
+ * privateKey: 64 bytes, first 32 bytes form the scalar integer `x`, the latter bytes are used for private nonce generation
32
+ * publicKey: 32 bytes
33
+ * x: bigint scalar representation of privateKey
34
+ * g: generator BASE point
35
+ * h: CurvePoint representation of publicKey
36
+ * m: (hashed) message, kept as bytes
37
+ * k: a practically random number, created by applying a one-way function to the message and part of the private key
38
+ * a: first part of signature
39
+ * b: second part of signature
40
+ * `*`: group multiplication of a CurvePoint by a scalar integer, or multiplication of 2 scalars (depending on context)
41
+ * `+`: CurvePoint addition or scalar addition depending on context
42
+ * `.`: byte concatenation
43
+ * `[n:N]`: slice bytes
44
+ * `f(a,h,m)`: a one-way function for publicy known information
45
+ * `mod()`: take modulo of a scalar wrt. the order of the Curve
46
+ * `hash()`: Sha512 hash function
47
+ * `encodeScalar`: turn a scalar integer into bytes
48
+ * `decodeScalar`: turn bytes into a scalar integer
49
+ * `encodePoint`: turn a CurvePoint into bytes
50
+ * `decodePoint`: turn bytes into a CurvePoint
51
+ *
52
+ * The algorithm below is approached from an additive perspective.
53
+ *
54
+ * 1. Generate 64 random private key bytes
55
+ * privateKey = random(64)
56
+ * 2. Generate the associated scalar `x`:
57
+ * x = decodeScalar(privateKey[0:32])
58
+ * 3. Generate public key CurvePoint:
59
+ * h = g*x
60
+ * 4. Encode public key:
61
+ * publicKey = encodePoint(h)
62
+ * 5. Create first part of a signature:
63
+ * k = decodeScalar(hash(privateKey[32:64] . m))
64
+ * a = g*k
65
+ * signature[0:32] = encodePoint(a)
66
+ * 6. Create second part of a signature:
67
+ * f(a,h,m) = decodeScalar(hash(signature[0:32] . publicKey . m))
68
+ * b = mod(k + f(a,h,m)*x)
69
+ * signature[32:64] = encodeScalar(b)
70
+ * 7. Verify a signature:
71
+ * a = decodePoint(signature[0:32])
72
+ * b = decodeScalar(signature[32:64])
73
+ * h = decodePoint(publicKey)
74
+ * f(a,h,m) = decodeScalar(hash(signature[0:32] . publicKey . m))
75
+ * g*b === a + h*f(a,h,m)
76
+ *
77
+ * We can show that this works by substituting the private calculations done upon signing (the arithmatic takes care of the mod() operator):
78
+ * g*(k + f(a,h,m)*x) === g*k + h*f(a,h,m)
79
+ * g*k + g*x*f(a,h,m) === g*k + h*f(a,h,m)
80
+ *
81
+ * We know that `g*x == h`, QED.
82
+ *
83
+ * The arithmatic details are handled by the CurvePoint class
84
+ */
85
+ export class EdDSA {
86
+ curve;
87
+ G;
88
+ Z;
89
+ codec;
90
+ /**
91
+ * @param curve
92
+ */
93
+ constructor(curve, G, Z, pointCodec) {
94
+ this.curve = curve;
95
+ this.G = G;
96
+ this.Z = Z;
97
+ this.codec = pointCodec;
98
+ }
99
+ /**
100
+ * Combination hash and decodeCurveInt
101
+ * @param bytes
102
+ * @returns
103
+ */
104
+ oneWay(...chunks) {
105
+ const l = chunks.reduce((prev, chunk) => chunk.length + prev, 0);
106
+ const bytes = new Uint8Array(l);
107
+ let offset = 0;
108
+ chunks.forEach((chunk) => {
109
+ bytes.set(chunk, offset);
110
+ offset += chunk.length;
111
+ });
112
+ return Either.getOrThrow(this.codec.decodeScalar(Sha2_512.hashSync(bytes)));
113
+ }
114
+ /**
115
+ * @param privateKeyBytes
116
+ * @param hashPrivateKey
117
+ * Defaults to true, set to false
118
+ * when used in Bip32 algorithm
119
+ * @returns 32 byte public key.
120
+ */
121
+ derivePublicKey(privateKeyBytes, hashPrivateKey = true) {
122
+ if (hashPrivateKey) {
123
+ privateKeyBytes = Sha2_512.hashSync(privateKeyBytes);
124
+ }
125
+ else {
126
+ if (privateKeyBytes.length != 64) {
127
+ return Either.left(new BadPrivateKeyLength(privateKeyBytes));
128
+ }
129
+ }
130
+ // we know that `privateKeyBytes` isn't empty, so `decodePrivateKey()` should never throw an error
131
+ const privateKey = Either.getOrThrow(this.codec.decodePrivateKey(privateKeyBytes));
132
+ const curveHelper = new CurveHelper(this.curve);
133
+ const publicKey = curveHelper.scale(this.curve.fromAffine(this.G), privateKey);
134
+ const publicKeyBytes = this.codec.encodePoint(this.curve.toAffine(publicKey));
135
+ return Either.right(publicKeyBytes);
136
+ }
137
+ /**
138
+ * Sign the message.
139
+ * Even though this implementation isn't constant time, it isn't vulnerable to a timing attack (see detailed notes in implementation below)
140
+ * @param message
141
+ * @param privateKeyBytes
142
+ * @param hashPrivateKey
143
+ * Defaults to true, Bip32 passes this as false
144
+ * @returns
145
+ * 64 byte signature.
146
+ */
147
+ sign(message, privateKeyBytes, hashPrivateKey = true) {
148
+ if (hashPrivateKey) {
149
+ privateKeyBytes = Sha2_512.hashSync(privateKeyBytes);
150
+ }
151
+ else {
152
+ if (privateKeyBytes.length != 64) {
153
+ return Either.left(new BadPrivateKeyLength(privateKeyBytes));
154
+ }
155
+ }
156
+ // Extract privateKey as integer
157
+ // (Not vulnerable to timing attack because there is no mixing with the message,
158
+ // so always takes the same amount of time for the same privateKey)
159
+ const privateKey = Either.getOrThrow(this.codec.decodePrivateKey(privateKeyBytes));
160
+ const curveHelper = new CurveHelper(this.curve);
161
+ // For convenience calculate publicKey here
162
+ // (Not vulnerable to timing attack because there is no mixing with the message,
163
+ // so always takes the same amount of time for the same privateKey)
164
+ const publicKey = curveHelper.scale(this.curve.fromAffine(this.G), privateKey);
165
+ const publicKeyBytes = this.codec.encodePoint(this.curve.toAffine(publicKey));
166
+ // Generate a practically random number
167
+ // (Not vulnerable to timing attack because sha2_512 runtime only depends on message length,
168
+ // so timing doesn't expose any bytes of the privateKey)
169
+ const k = this.oneWay(privateKeyBytes.slice(32, 64), message);
170
+ // First part of the signature
171
+ // (Not vulnerable to timing attack because variations in the message create huge random variations in k)
172
+ const a = curveHelper.scale(this.curve.fromAffine(this.G), k);
173
+ const aEncoded = this.codec.encodePoint(this.curve.toAffine(a));
174
+ // Second part of the signature
175
+ // (Not vulnerable to timing attack.
176
+ // Even though f is known publicly and changes with each message,
177
+ // and the f * x operation isn't constant time (bigint ops in JS aren't constant time),
178
+ // k also changes with each message, and the [k]BASE operation above
179
+ // is much more expensive than multiplying two big ints)
180
+ const f = this.oneWay(aEncoded, publicKeyBytes, message);
181
+ const b = this.Z.add(k, f * privateKey);
182
+ const bEncoded = this.codec.encodeScalar(b);
183
+ return Either.right(new Uint8Array(Array.from(aEncoded).concat(Array.from(bEncoded))));
184
+ }
185
+ /**
186
+ * Returns `true` if the signature is correct.
187
+ * Returns `false`:
188
+ * * if the signature is incorrect
189
+ * * if the signature doesn't lie on the curve,
190
+ * * if the publicKey doesn't lie on the curve
191
+ * Throw an error:
192
+ * * signature isn't 64 bytes long
193
+ * * publickey isn't 32 bytes long (asserted inside `decodePoint()`)
194
+ * @param signature
195
+ * @param message
196
+ * @param publicKey
197
+ * @returns
198
+ */
199
+ verify(signature, message, publicKey) {
200
+ if (signature.length != 64) {
201
+ return Either.left(new BadSignatureLength(signature));
202
+ }
203
+ const a = this.curve.fromAffine(Either.getOrThrow(this.codec.decodePoint(signature.slice(0, 32))));
204
+ if (!this.curve.isValidPoint(a)) {
205
+ return Either.right(false);
206
+ }
207
+ const b = Either.getOrThrow(this.codec.decodeScalar(signature.slice(32, 64)));
208
+ if (publicKey.length != 32) {
209
+ return Either.left(new BadPublicKeyLength(publicKey));
210
+ }
211
+ const h = this.curve.fromAffine(Either.getOrThrow(this.codec.decodePoint(publicKey)));
212
+ if (!this.curve.isValidPoint(h)) {
213
+ return Either.right(false);
214
+ }
215
+ const f = this.oneWay(signature.slice(0, 32), publicKey, message);
216
+ const curveHelper = new CurveHelper(this.curve);
217
+ const left = curveHelper.scale(this.curve.fromAffine(this.G), b);
218
+ const right = this.curve.add(a, curveHelper.scale(h, f));
219
+ return Either.right(this.curve.equals(left, right));
220
+ }
221
+ }
222
+ //# sourceMappingURL=EdDSA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EdDSA.js","sourceRoot":"","sources":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,CAAC,CAAC,CAAC,CAAA;QAExD,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;IACrD,CAAC;CACF"}
@@ -0,0 +1,323 @@
1
+ /**
2
+ * Positive modulo operator
3
+ * @param x
4
+ * @param modulo
5
+ * @returns
6
+ */
7
+ export function mod(x, modulo) {
8
+ const res = x % modulo;
9
+ if (res < 0n) {
10
+ return res + modulo;
11
+ }
12
+ else {
13
+ return res;
14
+ }
15
+ }
16
+ export class ScalarField {
17
+ /**
18
+ * Every operation is modulo this number
19
+ */
20
+ modulo;
21
+ constructor(modulo) {
22
+ this.modulo = modulo;
23
+ }
24
+ get ZERO() {
25
+ return 0n;
26
+ }
27
+ get ONE() {
28
+ return 1n;
29
+ }
30
+ /**
31
+ * @param a
32
+ * @param b
33
+ * @returns
34
+ */
35
+ add(a, ...b) {
36
+ return mod(b.reduce((sum, b) => sum + b, a), this.modulo);
37
+ }
38
+ /**
39
+ * @param a
40
+ * @param n
41
+ * @returns
42
+ */
43
+ scale(a, n) {
44
+ return mod(a * n, this.modulo);
45
+ }
46
+ /**
47
+ * Implemented separately from `scale` because it has a different meaning
48
+ * @param a
49
+ * @param b
50
+ * @returns
51
+ */
52
+ multiply(a, b) {
53
+ return mod(a * b, this.modulo);
54
+ }
55
+ /**
56
+ * @param a
57
+ * @param b
58
+ * @returns
59
+ */
60
+ equals(a, b) {
61
+ return mod(a, this.modulo) === mod(b, this.modulo);
62
+ }
63
+ /**
64
+ * Invert a number on a field (i.e. calculate n^-1 so that n*n^-1 = 1)
65
+ * This is an expensive iterative procedure that is only guaranteed to converge if the modulo is a prime number
66
+ * @param n
67
+ * @returns
68
+ */
69
+ invert(n) {
70
+ let a = mod(n, this.modulo);
71
+ let b = this.modulo;
72
+ let x = 0n;
73
+ let y = 1n;
74
+ let u = 1n;
75
+ let v = 0n;
76
+ while (a !== 0n) {
77
+ const q = b / a;
78
+ const r = b % a;
79
+ const m = x - u * q;
80
+ const n = y - v * q;
81
+ b = a;
82
+ a = r;
83
+ x = u;
84
+ y = v;
85
+ u = m;
86
+ v = n;
87
+ }
88
+ return mod(x, this.modulo);
89
+ }
90
+ }
91
+ /**
92
+ * Defines additional operations on a field (which use the basic operations as building blocks)
93
+ * * isZero(a)
94
+ * * isOne(a)
95
+ * * mod(a)
96
+ * * subtract(a, b)
97
+ * * negate(a)
98
+ * * square(a)
99
+ * * cube(a)
100
+ * * divide(a, b)
101
+ * * pow(a, p)
102
+ * * halve(a)
103
+ */
104
+ export class FieldHelper {
105
+ F;
106
+ /**
107
+ * @param F
108
+ */
109
+ constructor(F) {
110
+ this.F = F;
111
+ }
112
+ get ZERO() {
113
+ return this.F.ZERO;
114
+ }
115
+ get ONE() {
116
+ return this.F.ONE;
117
+ }
118
+ /**
119
+ * @param a
120
+ * @returns
121
+ */
122
+ isZero(a) {
123
+ return this.equals(a, this.ZERO);
124
+ }
125
+ /**
126
+ * @param a
127
+ * @returns
128
+ */
129
+ isOne(a) {
130
+ return this.equals(a, this.ONE);
131
+ }
132
+ /**
133
+ * @param a
134
+ * @returns
135
+ */
136
+ mod(a) {
137
+ return this.F.scale(a, 1n);
138
+ }
139
+ /**
140
+ * @param a
141
+ * @param bs
142
+ * @returns
143
+ */
144
+ add(a, ...bs) {
145
+ return this.F.add(a, ...bs);
146
+ }
147
+ /**
148
+ * @param a
149
+ * @param b
150
+ * @returns
151
+ */
152
+ subtract(a, b) {
153
+ const F = this.F;
154
+ return F.add(a, F.scale(b, -1n));
155
+ }
156
+ /**
157
+ * @param a
158
+ * @param s
159
+ * @returns
160
+ */
161
+ scale(a, s) {
162
+ return this.F.scale(a, s);
163
+ }
164
+ /**
165
+ * @param a
166
+ * @returns
167
+ */
168
+ negate(a) {
169
+ return this.F.scale(a, -1n);
170
+ }
171
+ /**
172
+ * @param a
173
+ * @param b
174
+ * @returns
175
+ */
176
+ multiply(a, b) {
177
+ return this.F.multiply(a, b);
178
+ }
179
+ /**
180
+ * @param a
181
+ * @returns
182
+ */
183
+ square(a) {
184
+ return this.F.multiply(a, a);
185
+ }
186
+ /**
187
+ * @param a
188
+ * @returns
189
+ */
190
+ cube(a) {
191
+ return this.F.multiply(a, this.F.multiply(a, a));
192
+ }
193
+ /**
194
+ * @param a
195
+ * @param b
196
+ * @returns
197
+ */
198
+ divide(a, b) {
199
+ return this.F.multiply(a, this.F.invert(b));
200
+ }
201
+ /**
202
+ * @param a
203
+ * @returns
204
+ */
205
+ invert(a) {
206
+ return this.F.invert(a);
207
+ }
208
+ /**
209
+ * Modular exponent
210
+ * TODO: would a non-recursive version of this algorithm be faster?
211
+ * @param a
212
+ * @param p
213
+ * @returns
214
+ */
215
+ pow(a, p) {
216
+ if (p == 0n) {
217
+ return this.F.ONE;
218
+ }
219
+ else if (p == 1n) {
220
+ return a;
221
+ }
222
+ else {
223
+ let t = this.pow(a, p / 2n);
224
+ t = this.F.multiply(t, t);
225
+ if (p % 2n != 0n) {
226
+ t = this.F.multiply(t, a);
227
+ }
228
+ return t;
229
+ }
230
+ }
231
+ /**
232
+ * @param a
233
+ * @param b
234
+ * @returns
235
+ */
236
+ equals(a, b) {
237
+ return this.F.equals(a, b);
238
+ }
239
+ /**
240
+ * @param a
241
+ * @returns
242
+ */
243
+ halve(a) {
244
+ return this.divide(a, this.F.scale(this.F.ONE, 2n));
245
+ }
246
+ }
247
+ export class QuadraticField {
248
+ /**
249
+ * Field used for each component
250
+ */
251
+ F;
252
+ /**
253
+ * We can always replace u^2 by this number (e.g. for complex numbers this is -1)
254
+ */
255
+ U2;
256
+ /**
257
+ * @param F
258
+ * Applied to each part separately
259
+ * @param U2
260
+ */
261
+ constructor(F, U2) {
262
+ this.F = F;
263
+ this.U2 = U2;
264
+ }
265
+ get ZERO() {
266
+ return [this.F.ZERO, this.F.ZERO];
267
+ }
268
+ get ONE() {
269
+ return [this.F.ONE, this.F.ZERO];
270
+ }
271
+ /**
272
+ * @param a
273
+ * @param b
274
+ * @returns
275
+ */
276
+ add([ax, ay], ...b) {
277
+ const F = this.F;
278
+ return [F.add(ax, ...b.map((b) => b[0])), F.add(ay, ...b.map((b) => b[1]))];
279
+ }
280
+ /**
281
+ * @param a
282
+ * @param s
283
+ * @returns
284
+ */
285
+ scale([ax, ay], s) {
286
+ const F = this.F;
287
+ return [F.scale(ax, s), F.scale(ay, s)];
288
+ }
289
+ /**
290
+ * @param a
291
+ * @param b
292
+ * @returns
293
+ */
294
+ multiply([ax, ay], [bx, by]) {
295
+ const F = this.F;
296
+ return [
297
+ F.add(F.multiply(ax, bx), F.multiply(F.multiply(ay, by), this.U2)),
298
+ F.add(F.multiply(ay, bx), F.multiply(by, ax))
299
+ ];
300
+ }
301
+ /**
302
+ * @param a
303
+ * @param b
304
+ * @returns
305
+ */
306
+ equals([ax, ay], [bx, by]) {
307
+ const F = this.F;
308
+ return F.equals(ax, bx) && F.equals(ay, by);
309
+ }
310
+ /**
311
+ * Using the following formula we can derive the inverse of complex field element
312
+ * (ax + u*ay)*(ax - u*ay) = ax^2 - u^2*ay^2
313
+ * (ax + u*ay)^-1 = (ax - u*ay)/(ax^2 - u^2*ay^2)
314
+ * @param a
315
+ * @returns
316
+ */
317
+ invert([ax, ay]) {
318
+ const F = new FieldHelper(this.F);
319
+ const f = F.invert(F.subtract(F.square(ax), F.multiply(F.square(ay), this.U2)));
320
+ return [F.multiply(ax, f), F.multiply(ay, F.negate(f))];
321
+ }
322
+ }
323
+ //# sourceMappingURL=Field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Field.js","sourceRoot":"","sources":["../../src/Crypto/Field.ts"],"names":[],"mappings":"AASA;;;;;GAKG;AACH,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,MAAc;IAC3C,MAAM,GAAG,GAAG,CAAC,GAAG,MAAM,CAAA;IAEtB,IAAI,GAAG,GAAG,EAAE,EAAE,CAAC;QACb,OAAO,GAAG,GAAG,MAAM,CAAA;IACrB,CAAC;SA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* as Bytes from "../Codecs/Bytes.js";
2
+ import * as Sha2_256 from "./Sha2_256.js";
3
+ import * as Sha2_512 from "./Sha2_512.js";
4
+ /**
5
+ * Hmac using sha2-256.
6
+ * @example
7
+ * bytesToHex(hmacSha2_256(textToBytes("key"), textToBytes("The quick brown fox jumps over the lazy dog"))) == "f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8"
8
+ * @param key
9
+ * @param message
10
+ * @returns
11
+ */
12
+ export function sha2_256Sync(key, message) {
13
+ return deriveSyncInternal(Sha2_256.hashSync, 64)(Bytes.toUint8Array(key), Bytes.toUint8Array(message));
14
+ }
15
+ /**
16
+ * Hmac using sha2-512.
17
+ * @example
18
+ * bytesToHex(hmacSha2_512(textToBytes("key"), textToBytes("The quick brown fox jumps over the lazy dog"))) == "b42af09057bac1e2d41708e48a902e09b5ff7f12ab428a4fe86653c73dd248fb82f948a549f7b791a5b41915ee4d1ec3935357e4e2317250d0372afa2ebeeb3a"
19
+ * @param key
20
+ * @param message
21
+ * @returns
22
+ */
23
+ export function sha2_512Sync(key, message) {
24
+ return deriveSyncInternal(Sha2_512.hashSync, 128)(Bytes.toUint8Array(key), Bytes.toUint8Array(message));
25
+ }
26
+ /**
27
+ * Don't use this directly, use hmacSyncSha2_256 or hmacSyncSha2_512 instead
28
+ * @param algorithm
29
+ * sync hashing function
30
+ * @param b
31
+ * blockSize of algorithm
32
+ * @returns
33
+ */
34
+ const deriveSyncInternal = (algorithm, blockSize) => (key, message) => {
35
+ if (key.length > blockSize) {
36
+ key = algorithm(key);
37
+ }
38
+ else {
39
+ key = key.slice();
40
+ }
41
+ while (key.length < blockSize) {
42
+ const tmp = new Uint8Array(key.length + 1);
43
+ tmp.set(key);
44
+ tmp[key.length] = 0x00;
45
+ key = tmp;
46
+ }
47
+ const iPadded = key.map((k) => k ^ 0x36);
48
+ const oPadded = key.map((k) => k ^ 0x5c);
49
+ return algorithm(Bytes.concat(oPadded, algorithm(Bytes.concat(iPadded, message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