@zudojs/crypto 0.1.0 → 1.1.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 (354) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -14
  3. package/dist/compare/compare.helper.d.ts +10 -2
  4. package/dist/compare/compare.helper.js +22 -6
  5. package/dist/cryptoCipher/cryptoCipher.core.d.ts +11 -1
  6. package/dist/cryptoCipher/cryptoCipher.core.js +19 -3
  7. package/dist/cryptoCipher/cryptoCipher.envelope.d.ts +7 -2
  8. package/dist/cryptoCipher/cryptoCipher.envelope.js +33 -14
  9. package/dist/cryptoCipher/cryptoCipher.string.d.ts +2 -1
  10. package/dist/cryptoCipher/cryptoCipher.string.js +2 -2
  11. package/dist/cryptoConstants/cryptoConstants.guard.d.ts +9 -0
  12. package/dist/cryptoConstants/cryptoConstants.guard.js +16 -1
  13. package/dist/cryptoConstants/cryptoConstants.security.d.ts +42 -1
  14. package/dist/cryptoConstants/cryptoConstants.security.js +42 -1
  15. package/dist/cryptoConstants/cryptoConstants.token.d.ts +2 -0
  16. package/dist/cryptoConstants/cryptoConstants.token.js +2 -0
  17. package/dist/cryptoConstants/cryptoConstants.type.d.ts +36 -14
  18. package/dist/cryptoConstants/cryptoConstants.type.js +36 -14
  19. package/dist/cryptoEncoding/cryptoEncoding.compare.d.ts +4 -1
  20. package/dist/cryptoEncoding/cryptoEncoding.compare.js +11 -4
  21. package/dist/cryptoEncoding/cryptoEncoding.core.d.ts +22 -0
  22. package/dist/cryptoEncoding/cryptoEncoding.core.js +41 -3
  23. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64.d.ts +10 -2
  24. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64.js +24 -16
  25. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64url.d.ts +9 -1
  26. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64url.js +23 -20
  27. package/dist/cryptoEncoding/encoding/cryptoEncoding.hex.d.ts +9 -2
  28. package/dist/cryptoEncoding/encoding/cryptoEncoding.hex.js +17 -11
  29. package/dist/cryptoErrors/cryptoErrors.helper.d.ts +30 -0
  30. package/dist/cryptoErrors/cryptoErrors.helper.js +72 -0
  31. package/dist/cryptoFactory/cryptoFactory.core.d.ts +37 -6
  32. package/dist/cryptoFactory/cryptoFactory.core.js +56 -30
  33. package/dist/cryptoFactory/cryptoFactory.password.d.ts +4 -3
  34. package/dist/cryptoFactory/cryptoFactory.password.js +4 -4
  35. package/dist/cryptoFactory/cryptoFactory.token.d.ts +9 -8
  36. package/dist/cryptoFactory/cryptoFactory.token.js +16 -15
  37. package/dist/cryptoHash/cryptoHash.codec.d.ts +2 -0
  38. package/dist/cryptoHash/cryptoHash.codec.js +12 -12
  39. package/dist/cryptoHash/cryptoHash.compare.d.ts +3 -1
  40. package/dist/cryptoHash/cryptoHash.compare.js +5 -9
  41. package/dist/cryptoHash/cryptoHash.core.d.ts +6 -2
  42. package/dist/cryptoHash/cryptoHash.core.js +9 -2
  43. package/dist/cryptoHash/cryptoHmac.core.d.ts +8 -5
  44. package/dist/cryptoHash/cryptoHmac.core.js +22 -9
  45. package/dist/cryptoKey/cryptoKey.factory.d.ts +29 -2
  46. package/dist/cryptoKey/cryptoKey.factory.js +82 -18
  47. package/dist/cryptoKey/cryptoKey.utils.d.ts +5 -3
  48. package/dist/cryptoKey/cryptoKey.utils.js +5 -3
  49. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.core.d.ts +7 -1
  50. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.core.js +40 -15
  51. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.salt.d.ts +2 -1
  52. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.salt.js +2 -3
  53. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.type.d.ts +5 -1
  54. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.validate.d.ts +13 -2
  55. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.validate.js +53 -16
  56. package/dist/cryptoPassword/cryptoPassword.codec.d.ts +15 -1
  57. package/dist/cryptoPassword/cryptoPassword.codec.js +127 -56
  58. package/dist/cryptoPassword/cryptoPassword.core.d.ts +17 -3
  59. package/dist/cryptoPassword/cryptoPassword.core.js +29 -21
  60. package/dist/cryptoPassword/cryptoPassword.helper.js +6 -5
  61. package/dist/cryptoPassword/cryptoPassword.type.d.ts +33 -5
  62. package/dist/cryptoPassword/cryptoPassword.validate.d.ts +14 -3
  63. package/dist/cryptoPassword/cryptoPassword.validate.js +51 -20
  64. package/dist/cryptoProvider/cryptoProvider.default.d.ts +18 -0
  65. package/dist/cryptoProvider/cryptoProvider.default.js +31 -0
  66. package/dist/cryptoProvider/cryptoProvider.interface.d.ts +9 -34
  67. package/dist/cryptoProvider/cryptoProvider.type.d.ts +32 -3
  68. package/dist/cryptoProvider/cryptoProvider.type.js +40 -1
  69. package/dist/cryptoProvider/index.d.ts +5 -2
  70. package/dist/cryptoProvider/index.js +2 -0
  71. package/dist/cryptoProvider/types/cryptoCipher.type.d.ts +11 -6
  72. package/dist/cryptoProvider/types/cryptoKeyDerivation.type.d.ts +39 -3
  73. package/dist/cryptoProvider/types/cryptoSignature.type.d.ts +5 -5
  74. package/dist/cryptoProvider/types/index.d.ts +1 -1
  75. package/dist/cryptoRandom/cryptoRandom.choice.d.ts +6 -3
  76. package/dist/cryptoRandom/cryptoRandom.choice.js +10 -6
  77. package/dist/cryptoRandom/cryptoRandom.core.d.ts +8 -5
  78. package/dist/cryptoRandom/cryptoRandom.core.js +8 -7
  79. package/dist/cryptoRandom/cryptoRandom.string.d.ts +11 -9
  80. package/dist/cryptoRandom/cryptoRandom.string.js +28 -29
  81. package/dist/cryptoService/cryptoService.core.d.ts +47 -9
  82. package/dist/cryptoService/cryptoService.core.js +65 -33
  83. package/dist/cryptoService/cryptoService.derivation.d.ts +3 -3
  84. package/dist/cryptoService/cryptoService.derivation.js +8 -6
  85. package/dist/cryptoService/cryptoService.encoding.js +6 -5
  86. package/dist/cryptoService/index.d.ts +1 -5
  87. package/dist/cryptoService/index.js +1 -5
  88. package/dist/cryptoService/operations/cryptoService.cipher.d.ts +3 -2
  89. package/dist/cryptoService/operations/cryptoService.cipher.js +13 -9
  90. package/dist/cryptoService/operations/cryptoService.hash.d.ts +3 -2
  91. package/dist/cryptoService/operations/cryptoService.hash.js +7 -8
  92. package/dist/cryptoService/operations/cryptoService.password.d.ts +7 -2
  93. package/dist/cryptoService/operations/cryptoService.password.js +20 -9
  94. package/dist/cryptoService/operations/cryptoService.token.d.ts +9 -4
  95. package/dist/cryptoService/operations/cryptoService.token.js +31 -17
  96. package/dist/cryptoSignature/cryptoSignature.core.d.ts +10 -2
  97. package/dist/cryptoSignature/cryptoSignature.core.js +7 -3
  98. package/dist/cryptoToken/cryptoToken.core.d.ts +15 -9
  99. package/dist/cryptoToken/cryptoToken.core.js +63 -38
  100. package/dist/cryptoToken/cryptoToken.hash.d.ts +9 -7
  101. package/dist/cryptoToken/cryptoToken.hash.js +19 -43
  102. package/dist/cryptoUtils/cryptoUtils.compare.d.ts +3 -1
  103. package/dist/cryptoUtils/cryptoUtils.compare.js +5 -14
  104. package/dist/cryptoUtils/cryptoUtils.number.d.ts +3 -0
  105. package/dist/cryptoUtils/cryptoUtils.number.js +12 -6
  106. package/dist/cryptoUtils/cryptoUtils.validation.d.ts +2 -2
  107. package/dist/cryptoUtils/cryptoUtils.validation.js +6 -8
  108. package/dist/cryptoUtils/encoding/cryptoUtils.base64.d.ts +4 -4
  109. package/dist/cryptoUtils/encoding/cryptoUtils.base64.js +5 -23
  110. package/dist/cryptoUtils/encoding/cryptoUtils.base64url.d.ts +4 -4
  111. package/dist/cryptoUtils/encoding/cryptoUtils.base64url.js +5 -32
  112. package/dist/cryptoUtils/encoding/cryptoUtils.hex.d.ts +4 -4
  113. package/dist/cryptoUtils/encoding/cryptoUtils.hex.js +5 -20
  114. package/dist/index.d.ts +1 -2
  115. package/dist/index.js +1 -2
  116. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.core.d.ts +6 -29
  117. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.core.js +0 -1
  118. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.helper.d.ts +9 -4
  119. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.helper.js +25 -43
  120. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.derivation.d.ts +7 -0
  121. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.derivation.js +112 -30
  122. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.password.d.ts +17 -10
  123. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.password.js +112 -72
  124. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.encryption.d.ts +3 -12
  125. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.encryption.js +74 -25
  126. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.hash.js +7 -2
  127. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.random.d.ts +6 -0
  128. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.random.js +18 -18
  129. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.signing.d.ts +10 -12
  130. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.signing.js +75 -20
  131. package/dist/node/signing/signing.conversion.d.ts +13 -3
  132. package/dist/node/signing/signing.conversion.js +35 -15
  133. package/dist/node/signing/signing.core.d.ts +2 -1
  134. package/dist/node/signing/signing.core.js +2 -3
  135. package/dist/node/signing/signing.utils.d.ts +10 -2
  136. package/dist/node/signing/signing.utils.js +26 -5
  137. package/package.json +28 -14
  138. package/dist/.tsbuildinfo +0 -1
  139. package/dist/compare/compare.helper.d.ts.map +0 -1
  140. package/dist/compare/compare.helper.js.map +0 -1
  141. package/dist/compare/index.d.ts.map +0 -1
  142. package/dist/compare/index.js.map +0 -1
  143. package/dist/cryptoAlgorithm/index.d.ts +0 -8
  144. package/dist/cryptoAlgorithm/index.d.ts.map +0 -1
  145. package/dist/cryptoAlgorithm/index.js +0 -8
  146. package/dist/cryptoAlgorithm/index.js.map +0 -1
  147. package/dist/cryptoCipher/cryptoCipher.core.d.ts.map +0 -1
  148. package/dist/cryptoCipher/cryptoCipher.core.js.map +0 -1
  149. package/dist/cryptoCipher/cryptoCipher.envelope.d.ts.map +0 -1
  150. package/dist/cryptoCipher/cryptoCipher.envelope.js.map +0 -1
  151. package/dist/cryptoCipher/cryptoCipher.string.d.ts.map +0 -1
  152. package/dist/cryptoCipher/cryptoCipher.string.js.map +0 -1
  153. package/dist/cryptoCipher/index.d.ts.map +0 -1
  154. package/dist/cryptoCipher/index.js.map +0 -1
  155. package/dist/cryptoConstants/cryptoConstants.config.d.ts.map +0 -1
  156. package/dist/cryptoConstants/cryptoConstants.config.js.map +0 -1
  157. package/dist/cryptoConstants/cryptoConstants.guard.d.ts.map +0 -1
  158. package/dist/cryptoConstants/cryptoConstants.guard.js.map +0 -1
  159. package/dist/cryptoConstants/cryptoConstants.security.d.ts.map +0 -1
  160. package/dist/cryptoConstants/cryptoConstants.security.js.map +0 -1
  161. package/dist/cryptoConstants/cryptoConstants.token.d.ts.map +0 -1
  162. package/dist/cryptoConstants/cryptoConstants.token.js.map +0 -1
  163. package/dist/cryptoConstants/cryptoConstants.type.d.ts.map +0 -1
  164. package/dist/cryptoConstants/cryptoConstants.type.js.map +0 -1
  165. package/dist/cryptoConstants/index.d.ts.map +0 -1
  166. package/dist/cryptoConstants/index.js.map +0 -1
  167. package/dist/cryptoEncoding/cryptoEncoding.arrayBuffer.d.ts.map +0 -1
  168. package/dist/cryptoEncoding/cryptoEncoding.arrayBuffer.js.map +0 -1
  169. package/dist/cryptoEncoding/cryptoEncoding.compare.d.ts.map +0 -1
  170. package/dist/cryptoEncoding/cryptoEncoding.compare.js.map +0 -1
  171. package/dist/cryptoEncoding/cryptoEncoding.core.d.ts.map +0 -1
  172. package/dist/cryptoEncoding/cryptoEncoding.core.js.map +0 -1
  173. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64.d.ts.map +0 -1
  174. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64.js.map +0 -1
  175. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64url.d.ts.map +0 -1
  176. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64url.js.map +0 -1
  177. package/dist/cryptoEncoding/encoding/cryptoEncoding.hex.d.ts.map +0 -1
  178. package/dist/cryptoEncoding/encoding/cryptoEncoding.hex.js.map +0 -1
  179. package/dist/cryptoEncoding/encoding/index.d.ts.map +0 -1
  180. package/dist/cryptoEncoding/encoding/index.js.map +0 -1
  181. package/dist/cryptoEncoding/index.d.ts.map +0 -1
  182. package/dist/cryptoEncoding/index.js.map +0 -1
  183. package/dist/cryptoErrors/index.d.ts.map +0 -1
  184. package/dist/cryptoErrors/index.js.map +0 -1
  185. package/dist/cryptoFactory/cryptoFactory.core.d.ts.map +0 -1
  186. package/dist/cryptoFactory/cryptoFactory.core.js.map +0 -1
  187. package/dist/cryptoFactory/cryptoFactory.encoding.d.ts.map +0 -1
  188. package/dist/cryptoFactory/cryptoFactory.encoding.js.map +0 -1
  189. package/dist/cryptoFactory/cryptoFactory.options.d.ts +0 -2
  190. package/dist/cryptoFactory/cryptoFactory.options.d.ts.map +0 -1
  191. package/dist/cryptoFactory/cryptoFactory.options.js +0 -6
  192. package/dist/cryptoFactory/cryptoFactory.options.js.map +0 -1
  193. package/dist/cryptoFactory/cryptoFactory.password.d.ts.map +0 -1
  194. package/dist/cryptoFactory/cryptoFactory.password.js.map +0 -1
  195. package/dist/cryptoFactory/cryptoFactory.token.d.ts.map +0 -1
  196. package/dist/cryptoFactory/cryptoFactory.token.js.map +0 -1
  197. package/dist/cryptoFactory/index.d.ts.map +0 -1
  198. package/dist/cryptoFactory/index.js.map +0 -1
  199. package/dist/cryptoHash/cryptoHash.codec.d.ts.map +0 -1
  200. package/dist/cryptoHash/cryptoHash.codec.js.map +0 -1
  201. package/dist/cryptoHash/cryptoHash.compare.d.ts.map +0 -1
  202. package/dist/cryptoHash/cryptoHash.compare.js.map +0 -1
  203. package/dist/cryptoHash/cryptoHash.convenience.d.ts.map +0 -1
  204. package/dist/cryptoHash/cryptoHash.convenience.js.map +0 -1
  205. package/dist/cryptoHash/cryptoHash.core.d.ts.map +0 -1
  206. package/dist/cryptoHash/cryptoHash.core.js.map +0 -1
  207. package/dist/cryptoHash/cryptoHmac.core.d.ts.map +0 -1
  208. package/dist/cryptoHash/cryptoHmac.core.js.map +0 -1
  209. package/dist/cryptoHash/index.d.ts.map +0 -1
  210. package/dist/cryptoHash/index.js.map +0 -1
  211. package/dist/cryptoKey/cryptoKey.factory.d.ts.map +0 -1
  212. package/dist/cryptoKey/cryptoKey.factory.js.map +0 -1
  213. package/dist/cryptoKey/cryptoKey.type.d.ts.map +0 -1
  214. package/dist/cryptoKey/cryptoKey.type.js.map +0 -1
  215. package/dist/cryptoKey/cryptoKey.utils.d.ts.map +0 -1
  216. package/dist/cryptoKey/cryptoKey.utils.js.map +0 -1
  217. package/dist/cryptoKey/index.d.ts.map +0 -1
  218. package/dist/cryptoKey/index.js.map +0 -1
  219. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.core.d.ts.map +0 -1
  220. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.core.js.map +0 -1
  221. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.salt.d.ts.map +0 -1
  222. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.salt.js.map +0 -1
  223. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.type.d.ts.map +0 -1
  224. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.type.js.map +0 -1
  225. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.validate.d.ts.map +0 -1
  226. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.validate.js.map +0 -1
  227. package/dist/cryptoKeyDerivation/index.d.ts.map +0 -1
  228. package/dist/cryptoKeyDerivation/index.js.map +0 -1
  229. package/dist/cryptoPassword/cryptoPassword.codec.d.ts.map +0 -1
  230. package/dist/cryptoPassword/cryptoPassword.codec.js.map +0 -1
  231. package/dist/cryptoPassword/cryptoPassword.core.d.ts.map +0 -1
  232. package/dist/cryptoPassword/cryptoPassword.core.js.map +0 -1
  233. package/dist/cryptoPassword/cryptoPassword.helper.d.ts.map +0 -1
  234. package/dist/cryptoPassword/cryptoPassword.helper.js.map +0 -1
  235. package/dist/cryptoPassword/cryptoPassword.type.d.ts.map +0 -1
  236. package/dist/cryptoPassword/cryptoPassword.type.js.map +0 -1
  237. package/dist/cryptoPassword/cryptoPassword.validate.d.ts.map +0 -1
  238. package/dist/cryptoPassword/cryptoPassword.validate.js.map +0 -1
  239. package/dist/cryptoPassword/index.d.ts.map +0 -1
  240. package/dist/cryptoPassword/index.js.map +0 -1
  241. package/dist/cryptoProvider/cryptoProvider.core.d.ts.map +0 -1
  242. package/dist/cryptoProvider/cryptoProvider.core.js.map +0 -1
  243. package/dist/cryptoProvider/cryptoProvider.interface.d.ts.map +0 -1
  244. package/dist/cryptoProvider/cryptoProvider.interface.js.map +0 -1
  245. package/dist/cryptoProvider/cryptoProvider.type.d.ts.map +0 -1
  246. package/dist/cryptoProvider/cryptoProvider.type.js.map +0 -1
  247. package/dist/cryptoProvider/index.d.ts.map +0 -1
  248. package/dist/cryptoProvider/index.js.map +0 -1
  249. package/dist/cryptoProvider/types/cryptoCipher.type.d.ts.map +0 -1
  250. package/dist/cryptoProvider/types/cryptoCipher.type.js.map +0 -1
  251. package/dist/cryptoProvider/types/cryptoHash.type.d.ts.map +0 -1
  252. package/dist/cryptoProvider/types/cryptoHash.type.js.map +0 -1
  253. package/dist/cryptoProvider/types/cryptoKeyDerivation.type.d.ts.map +0 -1
  254. package/dist/cryptoProvider/types/cryptoKeyDerivation.type.js.map +0 -1
  255. package/dist/cryptoProvider/types/cryptoRandom.type.d.ts.map +0 -1
  256. package/dist/cryptoProvider/types/cryptoRandom.type.js.map +0 -1
  257. package/dist/cryptoProvider/types/cryptoSignature.type.d.ts.map +0 -1
  258. package/dist/cryptoProvider/types/cryptoSignature.type.js.map +0 -1
  259. package/dist/cryptoProvider/types/index.d.ts.map +0 -1
  260. package/dist/cryptoProvider/types/index.js.map +0 -1
  261. package/dist/cryptoRandom/cryptoRandom.choice.d.ts.map +0 -1
  262. package/dist/cryptoRandom/cryptoRandom.choice.js.map +0 -1
  263. package/dist/cryptoRandom/cryptoRandom.core.d.ts.map +0 -1
  264. package/dist/cryptoRandom/cryptoRandom.core.js.map +0 -1
  265. package/dist/cryptoRandom/cryptoRandom.string.d.ts.map +0 -1
  266. package/dist/cryptoRandom/cryptoRandom.string.js.map +0 -1
  267. package/dist/cryptoRandom/index.d.ts.map +0 -1
  268. package/dist/cryptoRandom/index.js.map +0 -1
  269. package/dist/cryptoService/cryptoService.core.d.ts.map +0 -1
  270. package/dist/cryptoService/cryptoService.core.js.map +0 -1
  271. package/dist/cryptoService/cryptoService.derivation.d.ts.map +0 -1
  272. package/dist/cryptoService/cryptoService.derivation.js.map +0 -1
  273. package/dist/cryptoService/cryptoService.encoding.d.ts.map +0 -1
  274. package/dist/cryptoService/cryptoService.encoding.js.map +0 -1
  275. package/dist/cryptoService/index.d.ts.map +0 -1
  276. package/dist/cryptoService/index.js.map +0 -1
  277. package/dist/cryptoService/operations/cryptoService.cipher.d.ts.map +0 -1
  278. package/dist/cryptoService/operations/cryptoService.cipher.js.map +0 -1
  279. package/dist/cryptoService/operations/cryptoService.hash.d.ts.map +0 -1
  280. package/dist/cryptoService/operations/cryptoService.hash.js.map +0 -1
  281. package/dist/cryptoService/operations/cryptoService.password.d.ts.map +0 -1
  282. package/dist/cryptoService/operations/cryptoService.password.js.map +0 -1
  283. package/dist/cryptoService/operations/cryptoService.token.d.ts.map +0 -1
  284. package/dist/cryptoService/operations/cryptoService.token.js.map +0 -1
  285. package/dist/cryptoService/operations/index.d.ts.map +0 -1
  286. package/dist/cryptoService/operations/index.js.map +0 -1
  287. package/dist/cryptoSignature/cryptoSignature.core.d.ts.map +0 -1
  288. package/dist/cryptoSignature/cryptoSignature.core.js.map +0 -1
  289. package/dist/cryptoSignature/index.d.ts.map +0 -1
  290. package/dist/cryptoSignature/index.js.map +0 -1
  291. package/dist/cryptoToken/cryptoToken.core.d.ts.map +0 -1
  292. package/dist/cryptoToken/cryptoToken.core.js.map +0 -1
  293. package/dist/cryptoToken/cryptoToken.hash.d.ts.map +0 -1
  294. package/dist/cryptoToken/cryptoToken.hash.js.map +0 -1
  295. package/dist/cryptoToken/cryptoToken.utils.d.ts.map +0 -1
  296. package/dist/cryptoToken/cryptoToken.utils.js.map +0 -1
  297. package/dist/cryptoToken/index.d.ts.map +0 -1
  298. package/dist/cryptoToken/index.js.map +0 -1
  299. package/dist/cryptoUtils/cryptoUtils.compare.d.ts.map +0 -1
  300. package/dist/cryptoUtils/cryptoUtils.compare.js.map +0 -1
  301. package/dist/cryptoUtils/cryptoUtils.conversion.d.ts.map +0 -1
  302. package/dist/cryptoUtils/cryptoUtils.conversion.js.map +0 -1
  303. package/dist/cryptoUtils/cryptoUtils.number.d.ts.map +0 -1
  304. package/dist/cryptoUtils/cryptoUtils.number.js.map +0 -1
  305. package/dist/cryptoUtils/cryptoUtils.text.d.ts.map +0 -1
  306. package/dist/cryptoUtils/cryptoUtils.text.js.map +0 -1
  307. package/dist/cryptoUtils/cryptoUtils.validation.d.ts.map +0 -1
  308. package/dist/cryptoUtils/cryptoUtils.validation.js.map +0 -1
  309. package/dist/cryptoUtils/encoding/cryptoUtils.base64.d.ts.map +0 -1
  310. package/dist/cryptoUtils/encoding/cryptoUtils.base64.js.map +0 -1
  311. package/dist/cryptoUtils/encoding/cryptoUtils.base64url.d.ts.map +0 -1
  312. package/dist/cryptoUtils/encoding/cryptoUtils.base64url.js.map +0 -1
  313. package/dist/cryptoUtils/encoding/cryptoUtils.hex.d.ts.map +0 -1
  314. package/dist/cryptoUtils/encoding/cryptoUtils.hex.js.map +0 -1
  315. package/dist/cryptoUtils/encoding/index.d.ts.map +0 -1
  316. package/dist/cryptoUtils/encoding/index.js.map +0 -1
  317. package/dist/cryptoUtils/index.d.ts.map +0 -1
  318. package/dist/cryptoUtils/index.js.map +0 -1
  319. package/dist/index.d.ts.map +0 -1
  320. package/dist/index.js.map +0 -1
  321. package/dist/node/index.d.ts.map +0 -1
  322. package/dist/node/index.js.map +0 -1
  323. package/dist/node/nodeCryptoProvider/index.d.ts.map +0 -1
  324. package/dist/node/nodeCryptoProvider/index.js.map +0 -1
  325. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.core.d.ts.map +0 -1
  326. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.core.js.map +0 -1
  327. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.factory.d.ts.map +0 -1
  328. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.factory.js.map +0 -1
  329. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.helper.d.ts.map +0 -1
  330. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.helper.js.map +0 -1
  331. package/dist/node/nodeCryptoProvider/operations/index.d.ts.map +0 -1
  332. package/dist/node/nodeCryptoProvider/operations/index.js.map +0 -1
  333. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.derivation.d.ts.map +0 -1
  334. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.derivation.js.map +0 -1
  335. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.password.d.ts.map +0 -1
  336. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.password.js.map +0 -1
  337. package/dist/node/nodeCryptoProvider/primitives/index.d.ts.map +0 -1
  338. package/dist/node/nodeCryptoProvider/primitives/index.js.map +0 -1
  339. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.encryption.d.ts.map +0 -1
  340. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.encryption.js.map +0 -1
  341. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.hash.d.ts.map +0 -1
  342. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.hash.js.map +0 -1
  343. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.random.d.ts.map +0 -1
  344. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.random.js.map +0 -1
  345. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.signing.d.ts.map +0 -1
  346. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.signing.js.map +0 -1
  347. package/dist/node/signing/index.d.ts.map +0 -1
  348. package/dist/node/signing/index.js.map +0 -1
  349. package/dist/node/signing/signing.conversion.d.ts.map +0 -1
  350. package/dist/node/signing/signing.conversion.js.map +0 -1
  351. package/dist/node/signing/signing.core.d.ts.map +0 -1
  352. package/dist/node/signing/signing.core.js.map +0 -1
  353. package/dist/node/signing/signing.utils.d.ts.map +0 -1
  354. package/dist/node/signing/signing.utils.js.map +0 -1
@@ -1,26 +1,47 @@
1
+ import type { CryptoProvider } from "../cryptoProvider/index.js";
1
2
  import { CryptoService } from "../cryptoService/cryptoService.core.js";
2
3
  import { CryptoAlgorithm } from "../cryptoConstants/cryptoConstants.type.js";
3
4
  import type { CryptoKey } from "../cryptoKey/cryptoKey.type.js";
5
+ import type { PasswordHashResult } from "../cryptoPassword/cryptoPassword.type.js";
4
6
  import type { PasswordHashOptions } from "./cryptoFactory.password.js";
5
7
  import type { CryptoEncoding } from "./cryptoFactory.encoding.js";
8
+ import type { TokenEncoding } from "../cryptoToken/cryptoToken.core.js";
6
9
  /**
7
10
  * Configuration used to create a CryptoFactory.
8
11
  */
9
12
  export interface CryptoFactoryOptions {
10
13
  readonly defaultKeyAlgorithm?: CryptoAlgorithm;
14
+ /** Default scrypt parameters; per-call options are merged on top. */
11
15
  readonly password?: PasswordHashOptions;
12
- readonly encoding?: CryptoEncoding;
16
+ /** Default binary encoding for tokens and `encode`/`decode`. */
17
+ readonly encoding?: TokenEncoding;
18
+ /** Provider used for every operation. */
19
+ readonly provider?: CryptoProvider;
13
20
  }
14
21
  /**
15
22
  * Central factory for constructing and accessing crypto services.
23
+ *
24
+ * Options are deep-copied on construction, so later mutation of the
25
+ * caller's option objects cannot change the factory's behaviour.
16
26
  */
17
27
  export declare class CryptoFactory {
18
28
  private readonly options;
29
+ private readonly configuredProvider;
19
30
  private readonly service;
20
31
  constructor(options?: CryptoFactoryOptions);
32
+ private get provider();
21
33
  /** Returns the configured crypto service. */
22
34
  getService(): CryptoService;
23
- /** Generates a key using the configured default algorithm. */
35
+ /**
36
+ * Returns the provider backing this factory (the process-wide default
37
+ * when none was configured).
38
+ */
39
+ getProvider(): CryptoProvider;
40
+ /**
41
+ * Generates a symmetric key using the configured default algorithm.
42
+ *
43
+ * Asymmetric algorithms are rejected.
44
+ */
24
45
  createKey(algorithm?: CryptoAlgorithm): Promise<CryptoKey>;
25
46
  /** Generates a secure opaque token. */
26
47
  createToken(bytes?: number, prefix?: string): Promise<string>;
@@ -38,16 +59,20 @@ export declare class CryptoFactory {
38
59
  createCsrfToken(): Promise<string>;
39
60
  /** Generates a numeric one-time password. */
40
61
  createOtp(digits?: number): Promise<string>;
41
- /** Hashes a password using the configured password options. */
42
- createPasswordHash(password: string, options?: PasswordHashOptions): Promise<import("../index.js").PasswordHashResult>;
62
+ /**
63
+ * Hashes a password using the configured password options.
64
+ *
65
+ * Per-call options are layered on top of the configured defaults.
66
+ */
67
+ createPasswordHash(password: string, options?: PasswordHashOptions): Promise<PasswordHashResult>;
43
68
  /** Verifies a password against a stored hash. */
44
69
  verifyPassword(password: string, encodedHash: string): Promise<boolean>;
45
70
  /** Encodes bytes using the configured default encoding. */
46
71
  encode(value: Uint8Array, encoding?: CryptoEncoding): string;
47
72
  /** Decodes binary data using the configured default encoding. */
48
73
  decode(value: string, encoding?: CryptoEncoding): Uint8Array;
49
- /** Returns the factory configuration. */
50
- getOptions(): Readonly<CryptoFactoryOptions>;
74
+ /** Returns a frozen copy of the factory configuration. */
75
+ getOptions(): Readonly<Required<Omit<CryptoFactoryOptions, "provider">>>;
51
76
  }
52
77
  /**
53
78
  * Creates a configured CryptoFactory.
@@ -55,6 +80,12 @@ export declare class CryptoFactory {
55
80
  export declare function createCryptoFactory(options?: CryptoFactoryOptions): CryptoFactory;
56
81
  /**
57
82
  * Default application crypto factory.
83
+ *
84
+ * Construction is trivial (no provider is created until first use).
58
85
  */
59
86
  export declare const cryptoFactory: CryptoFactory;
87
+ /**
88
+ * Returns the default application crypto factory.
89
+ */
90
+ export declare function getCryptoFactory(): CryptoFactory;
60
91
  //# sourceMappingURL=cryptoFactory.core.d.ts.map
@@ -1,78 +1,97 @@
1
+ import { getDefaultCryptoProvider } from "../cryptoProvider/cryptoProvider.default.js";
1
2
  import { CryptoService, createCryptoService, } from "../cryptoService/cryptoService.core.js";
2
3
  import { CryptoAlgorithm } from "../cryptoConstants/cryptoConstants.type.js";
3
- import { generateCryptoKey } from "../cryptoKey/cryptoKey.factory.js";
4
+ import { generateCryptoKey, defaultKeyLength, } from "../cryptoKey/cryptoKey.factory.js";
5
+ import { assertBinaryEncoding } from "../cryptoEncoding/cryptoEncoding.core.js";
4
6
  import { factoryCreateToken, factoryCreateApiKey, factoryCreateSessionToken, factoryCreateRefreshToken, factoryCreateVerificationToken, factoryCreatePasswordResetToken, factoryCreateCsrfToken, factoryCreateOtp, } from "./cryptoFactory.token.js";
5
7
  import { factoryCreatePasswordHash, factoryVerifyPassword, } from "./cryptoFactory.password.js";
6
8
  import { factoryEncode, factoryDecode } from "./cryptoFactory.encoding.js";
7
9
  /**
8
10
  * Central factory for constructing and accessing crypto services.
11
+ *
12
+ * Options are deep-copied on construction, so later mutation of the
13
+ * caller's option objects cannot change the factory's behaviour.
9
14
  */
10
15
  export class CryptoFactory {
11
16
  options;
17
+ configuredProvider;
12
18
  service;
13
19
  constructor(options = {}) {
20
+ const encoding = options.encoding ?? "base64url";
21
+ assertBinaryEncoding(encoding);
22
+ this.configuredProvider = options.provider;
14
23
  this.options = Object.freeze({
15
- ...options,
16
24
  defaultKeyAlgorithm: options.defaultKeyAlgorithm ?? CryptoAlgorithm.AES_256_GCM,
17
- encoding: options.encoding ?? "base64url",
25
+ password: Object.freeze({ ...(options.password ?? {}) }),
26
+ encoding,
18
27
  });
19
- this.service = createCryptoService();
28
+ this.service = createCryptoService({ provider: options.provider });
29
+ }
30
+ get provider() {
31
+ return this.configuredProvider ?? getDefaultCryptoProvider();
20
32
  }
21
33
  /** Returns the configured crypto service. */
22
34
  getService() {
23
35
  return this.service;
24
36
  }
25
- /** Generates a key using the configured default algorithm. */
37
+ /**
38
+ * Returns the provider backing this factory (the process-wide default
39
+ * when none was configured).
40
+ */
41
+ getProvider() {
42
+ return this.provider;
43
+ }
44
+ /**
45
+ * Generates a symmetric key using the configured default algorithm.
46
+ *
47
+ * Asymmetric algorithms are rejected.
48
+ */
26
49
  async createKey(algorithm = this.options.defaultKeyAlgorithm) {
27
- const length = algorithm.includes("256")
28
- ? 32
29
- : algorithm.includes("384")
30
- ? 48
31
- : algorithm.includes("512")
32
- ? 64
33
- : 32;
34
- return generateCryptoKey(length, { algorithm, extractable: true });
50
+ return generateCryptoKey(defaultKeyLength(algorithm), { algorithm, extractable: true }, this.provider);
35
51
  }
36
52
  /** Generates a secure opaque token. */
37
53
  async createToken(bytes = 32, prefix) {
38
- return factoryCreateToken(bytes, prefix, this.options
39
- .encoding);
54
+ return factoryCreateToken(bytes, prefix, this.options.encoding, this.provider);
40
55
  }
41
56
  /** Generates an API key. */
42
57
  async createApiKey() {
43
- return factoryCreateApiKey();
58
+ return factoryCreateApiKey(this.provider);
44
59
  }
45
60
  /** Generates a session token. */
46
61
  async createSessionToken() {
47
- return factoryCreateSessionToken();
62
+ return factoryCreateSessionToken(this.provider);
48
63
  }
49
64
  /** Generates a refresh token. */
50
65
  async createRefreshToken() {
51
- return factoryCreateRefreshToken();
66
+ return factoryCreateRefreshToken(this.provider);
52
67
  }
53
68
  /** Generates an email or account verification token. */
54
69
  async createVerificationToken() {
55
- return factoryCreateVerificationToken();
70
+ return factoryCreateVerificationToken(this.provider);
56
71
  }
57
72
  /** Generates a password reset token. */
58
73
  async createPasswordResetToken() {
59
- return factoryCreatePasswordResetToken();
74
+ return factoryCreatePasswordResetToken(this.provider);
60
75
  }
61
76
  /** Generates a CSRF token. */
62
77
  async createCsrfToken() {
63
- return factoryCreateCsrfToken();
78
+ return factoryCreateCsrfToken(this.provider);
64
79
  }
65
80
  /** Generates a numeric one-time password. */
66
81
  async createOtp(digits = 6) {
67
- return factoryCreateOtp(digits);
82
+ return factoryCreateOtp(digits, this.provider);
68
83
  }
69
- /** Hashes a password using the configured password options. */
84
+ /**
85
+ * Hashes a password using the configured password options.
86
+ *
87
+ * Per-call options are layered on top of the configured defaults.
88
+ */
70
89
  async createPasswordHash(password, options) {
71
- return factoryCreatePasswordHash(password, options ?? this.options.password);
90
+ return factoryCreatePasswordHash(password, { ...this.options.password, ...options }, this.provider);
72
91
  }
73
92
  /** Verifies a password against a stored hash. */
74
93
  async verifyPassword(password, encodedHash) {
75
- return factoryVerifyPassword(password, encodedHash);
94
+ return factoryVerifyPassword(password, encodedHash, this.provider);
76
95
  }
77
96
  /** Encodes bytes using the configured default encoding. */
78
97
  encode(value, encoding = this.options.encoding) {
@@ -82,13 +101,12 @@ export class CryptoFactory {
82
101
  decode(value, encoding = this.options.encoding) {
83
102
  return factoryDecode(value, encoding);
84
103
  }
85
- /** Returns the factory configuration. */
104
+ /** Returns a frozen copy of the factory configuration. */
86
105
  getOptions() {
87
106
  return Object.freeze({
88
- ...this.options,
89
- password: this.options.password
90
- ? Object.freeze({ ...this.options.password })
91
- : undefined,
107
+ defaultKeyAlgorithm: this.options.defaultKeyAlgorithm,
108
+ encoding: this.options.encoding,
109
+ password: Object.freeze({ ...this.options.password }),
92
110
  });
93
111
  }
94
112
  }
@@ -100,6 +118,14 @@ export function createCryptoFactory(options = {}) {
100
118
  }
101
119
  /**
102
120
  * Default application crypto factory.
121
+ *
122
+ * Construction is trivial (no provider is created until first use).
103
123
  */
104
124
  export const cryptoFactory = createCryptoFactory();
125
+ /**
126
+ * Returns the default application crypto factory.
127
+ */
128
+ export function getCryptoFactory() {
129
+ return cryptoFactory;
130
+ }
105
131
  //# sourceMappingURL=cryptoFactory.core.js.map
@@ -1,5 +1,6 @@
1
- import type { PasswordHashOptions } from "../cryptoPassword/cryptoPassword.type.js";
1
+ import type { CryptoProvider } from "../cryptoProvider/index.js";
2
+ import type { PasswordHashOptions, PasswordHashResult } from "../cryptoPassword/cryptoPassword.type.js";
2
3
  export type { PasswordHashOptions };
3
- export declare function factoryCreatePasswordHash(password: string, options?: PasswordHashOptions): Promise<import("../cryptoPassword/cryptoPassword.type.js").PasswordHashResult>;
4
- export declare function factoryVerifyPassword(password: string, encodedHash: string): Promise<boolean>;
4
+ export declare function factoryCreatePasswordHash(password: string, options?: PasswordHashOptions, provider?: CryptoProvider): Promise<PasswordHashResult>;
5
+ export declare function factoryVerifyPassword(password: string, encodedHash: string, provider?: CryptoProvider): Promise<boolean>;
5
6
  //# sourceMappingURL=cryptoFactory.password.d.ts.map
@@ -1,8 +1,8 @@
1
1
  import { hashPassword, verifyPassword, } from "../cryptoPassword/cryptoPassword.core.js";
2
- export async function factoryCreatePasswordHash(password, options) {
3
- return hashPassword(password, options);
2
+ export async function factoryCreatePasswordHash(password, options, provider) {
3
+ return hashPassword(password, { ...options, provider });
4
4
  }
5
- export async function factoryVerifyPassword(password, encodedHash) {
6
- return verifyPassword(password, encodedHash);
5
+ export async function factoryVerifyPassword(password, encodedHash, provider) {
6
+ return verifyPassword(password, encodedHash, provider);
7
7
  }
8
8
  //# sourceMappingURL=cryptoFactory.password.js.map
@@ -1,10 +1,11 @@
1
+ import type { CryptoProvider } from "../cryptoProvider/index.js";
1
2
  import type { TokenEncoding } from "../cryptoToken/cryptoToken.core.js";
2
- export declare function factoryCreateToken(bytes?: number, prefix?: string, encoding?: TokenEncoding): Promise<string>;
3
- export declare function factoryCreateApiKey(): Promise<string>;
4
- export declare function factoryCreateSessionToken(): Promise<string>;
5
- export declare function factoryCreateRefreshToken(): Promise<string>;
6
- export declare function factoryCreateVerificationToken(): Promise<string>;
7
- export declare function factoryCreatePasswordResetToken(): Promise<string>;
8
- export declare function factoryCreateCsrfToken(): Promise<string>;
9
- export declare function factoryCreateOtp(digits?: number): Promise<string>;
3
+ export declare function factoryCreateToken(bytes?: number, prefix?: string, encoding?: TokenEncoding, provider?: CryptoProvider): Promise<string>;
4
+ export declare function factoryCreateApiKey(provider?: CryptoProvider): Promise<string>;
5
+ export declare function factoryCreateSessionToken(provider?: CryptoProvider): Promise<string>;
6
+ export declare function factoryCreateRefreshToken(provider?: CryptoProvider): Promise<string>;
7
+ export declare function factoryCreateVerificationToken(provider?: CryptoProvider): Promise<string>;
8
+ export declare function factoryCreatePasswordResetToken(provider?: CryptoProvider): Promise<string>;
9
+ export declare function factoryCreateCsrfToken(provider?: CryptoProvider): Promise<string>;
10
+ export declare function factoryCreateOtp(digits?: number, provider?: CryptoProvider): Promise<string>;
10
11
  //# sourceMappingURL=cryptoFactory.token.d.ts.map
@@ -1,30 +1,31 @@
1
1
  import { generateToken, generateApiKey, generateSessionToken, generateRefreshToken, generateVerificationToken, generatePasswordResetToken, generateCsrfToken, generateOtp, } from "../cryptoToken/cryptoToken.core.js";
2
- export async function factoryCreateToken(bytes = 32, prefix, encoding = "base64url") {
2
+ export async function factoryCreateToken(bytes = 32, prefix, encoding = "base64url", provider) {
3
3
  return generateToken({
4
4
  bytes,
5
5
  encoding,
6
6
  prefix,
7
+ provider,
7
8
  });
8
9
  }
9
- export async function factoryCreateApiKey() {
10
- return generateApiKey();
10
+ export async function factoryCreateApiKey(provider) {
11
+ return generateApiKey(undefined, undefined, provider);
11
12
  }
12
- export async function factoryCreateSessionToken() {
13
- return generateSessionToken();
13
+ export async function factoryCreateSessionToken(provider) {
14
+ return generateSessionToken(undefined, provider);
14
15
  }
15
- export async function factoryCreateRefreshToken() {
16
- return generateRefreshToken();
16
+ export async function factoryCreateRefreshToken(provider) {
17
+ return generateRefreshToken(undefined, provider);
17
18
  }
18
- export async function factoryCreateVerificationToken() {
19
- return generateVerificationToken();
19
+ export async function factoryCreateVerificationToken(provider) {
20
+ return generateVerificationToken(undefined, provider);
20
21
  }
21
- export async function factoryCreatePasswordResetToken() {
22
- return generatePasswordResetToken();
22
+ export async function factoryCreatePasswordResetToken(provider) {
23
+ return generatePasswordResetToken(undefined, provider);
23
24
  }
24
- export async function factoryCreateCsrfToken() {
25
- return generateCsrfToken();
25
+ export async function factoryCreateCsrfToken(provider) {
26
+ return generateCsrfToken(undefined, provider);
26
27
  }
27
- export async function factoryCreateOtp(digits = 6) {
28
- return generateOtp(digits);
28
+ export async function factoryCreateOtp(digits = 6, provider) {
29
+ return generateOtp(digits, provider);
29
30
  }
30
31
  //# sourceMappingURL=cryptoFactory.token.js.map
@@ -5,6 +5,8 @@ import type { HashEncoding } from "./cryptoHash.core.js";
5
5
  export declare function encodeDigest(digest: Uint8Array, encoding: HashEncoding): string;
6
6
  /**
7
7
  * Decodes a hash string into bytes.
8
+ *
9
+ * Input must be a non-empty, canonical encoding.
8
10
  */
9
11
  export declare function decodeDigest(digest: string, encoding?: HashEncoding): Uint8Array;
10
12
  //# sourceMappingURL=cryptoHash.codec.d.ts.map
@@ -1,37 +1,37 @@
1
+ import { toHex, fromHex } from "../cryptoEncoding/encoding/cryptoEncoding.hex.js";
2
+ import { toBase64, fromBase64, } from "../cryptoEncoding/encoding/cryptoEncoding.base64.js";
3
+ import { toBase64Url, fromBase64Url, } from "../cryptoEncoding/encoding/cryptoEncoding.base64url.js";
1
4
  /**
2
5
  * Converts a hash result into its encoded representation.
3
6
  */
4
7
  export function encodeDigest(digest, encoding) {
5
- const buffer = Buffer.from(digest);
6
8
  switch (encoding) {
7
9
  case "hex":
8
- return buffer.toString("hex");
10
+ return toHex(digest);
9
11
  case "base64":
10
- return buffer.toString("base64");
12
+ return toBase64(digest);
11
13
  case "base64url":
12
- return buffer.toString("base64url");
14
+ return toBase64Url(digest);
13
15
  default:
14
16
  throw new TypeError(`Unsupported hash encoding: ${String(encoding)}.`);
15
17
  }
16
18
  }
17
19
  /**
18
20
  * Decodes a hash string into bytes.
21
+ *
22
+ * Input must be a non-empty, canonical encoding.
19
23
  */
20
24
  export function decodeDigest(digest, encoding = "hex") {
21
25
  if (typeof digest !== "string" || digest.length === 0) {
22
26
  throw new TypeError("Digest must be a non-empty string.");
23
27
  }
24
28
  switch (encoding) {
25
- case "hex": {
26
- if (!/^[0-9a-fA-F]+$/.test(digest) || digest.length % 2 !== 0) {
27
- throw new TypeError("Invalid hexadecimal digest.");
28
- }
29
- return new Uint8Array(Buffer.from(digest, "hex"));
30
- }
29
+ case "hex":
30
+ return fromHex(digest);
31
31
  case "base64":
32
- return new Uint8Array(Buffer.from(digest, "base64"));
32
+ return fromBase64(digest);
33
33
  case "base64url":
34
- return new Uint8Array(Buffer.from(digest, "base64url"));
34
+ return fromBase64Url(digest);
35
35
  default:
36
36
  throw new TypeError(`Unsupported hash encoding: ${String(encoding)}.`);
37
37
  }
@@ -1,5 +1,7 @@
1
1
  /**
2
- * Performs a constant-time comparison of two digest strings.
2
+ * Performs a constant-time comparison of two digests.
3
+ *
4
+ * Alias of `timingSafeEqual` kept for API compatibility.
3
5
  */
4
6
  export declare function equalDigests(left: Uint8Array, right: Uint8Array): boolean;
5
7
  //# sourceMappingURL=cryptoHash.compare.d.ts.map
@@ -1,14 +1,10 @@
1
+ import { timingSafeEqual } from "../compare/compare.helper.js";
1
2
  /**
2
- * Performs a constant-time comparison of two digest strings.
3
+ * Performs a constant-time comparison of two digests.
4
+ *
5
+ * Alias of `timingSafeEqual` kept for API compatibility.
3
6
  */
4
7
  export function equalDigests(left, right) {
5
- if (left.byteLength !== right.byteLength) {
6
- return false;
7
- }
8
- let difference = 0;
9
- for (let index = 0; index < left.byteLength; index += 1) {
10
- difference |= left[index] ^ right[index];
11
- }
12
- return difference === 0;
8
+ return timingSafeEqual(left, right);
13
9
  }
14
10
  //# sourceMappingURL=cryptoHash.compare.js.map
@@ -1,19 +1,23 @@
1
- import type { HashAlgorithm } from "../cryptoProvider/index.js";
1
+ import type { CryptoProvider, HashAlgorithm, CryptoInput } from "../cryptoProvider/index.js";
2
2
  import type { HashResult, HashEncoding } from "../cryptoProvider/types/cryptoHash.type.js";
3
3
  export type { HashResult, HashEncoding, } from "../cryptoProvider/types/cryptoHash.type.js";
4
4
  /**
5
5
  * Converts supported input data into bytes.
6
6
  */
7
- export type HashInput = string | Uint8Array | ArrayBuffer;
7
+ export type HashInput = CryptoInput;
8
8
  /**
9
9
  * Options for hashing data.
10
10
  */
11
11
  export interface HashOptions {
12
12
  readonly algorithm?: HashAlgorithm;
13
13
  readonly encoding?: HashEncoding;
14
+ readonly provider?: CryptoProvider;
14
15
  }
15
16
  /**
16
17
  * Hashes arbitrary data using a cryptographic hash algorithm.
18
+ *
19
+ * Only the SHA-2 and SHA-3 family is accepted; weak digests such as md5
20
+ * or sha1 are rejected at runtime even when passed as plain strings.
17
21
  */
18
22
  export declare function hash(input: HashInput, options?: HashOptions): Promise<HashResult>;
19
23
  //# sourceMappingURL=cryptoHash.core.d.ts.map
@@ -1,11 +1,18 @@
1
- import { createNodeCryptoProvider } from "../node/index.js";
1
+ import { getDefaultCryptoProvider } from "../cryptoProvider/cryptoProvider.default.js";
2
+ import { isHashAlgorithmName } from "../cryptoProvider/cryptoProvider.type.js";
2
3
  import { encodeDigest } from "./cryptoHash.codec.js";
3
- const provider = createNodeCryptoProvider();
4
4
  /**
5
5
  * Hashes arbitrary data using a cryptographic hash algorithm.
6
+ *
7
+ * Only the SHA-2 and SHA-3 family is accepted; weak digests such as md5
8
+ * or sha1 are rejected at runtime even when passed as plain strings.
6
9
  */
7
10
  export async function hash(input, options = {}) {
8
11
  const algorithm = options.algorithm ?? "sha256";
12
+ if (!isHashAlgorithmName(algorithm)) {
13
+ throw new TypeError(`Unsupported hash algorithm: ${String(algorithm)}.`);
14
+ }
15
+ const provider = options.provider ?? getDefaultCryptoProvider();
9
16
  const digest = await provider.hash(algorithm, input);
10
17
  const encoding = options.encoding ?? "hex";
11
18
  return Object.freeze({
@@ -1,19 +1,22 @@
1
- import type { HmacAlgorithm, HashEncoding } from "../cryptoProvider/index.js";
1
+ import type { CryptoProvider, HmacAlgorithm, HashEncoding } from "../cryptoProvider/index.js";
2
2
  import type { HashInput } from "./cryptoHash.core.js";
3
3
  /**
4
4
  * Calculates a keyed HMAC.
5
+ *
6
+ * The key must be at least `KEY_SIZE.MIN_HMAC_KEY_BYTES` (16) bytes so
7
+ * that a missing or empty secret cannot silently produce forgeable tags.
5
8
  */
6
- export declare function hmac(input: HashInput, key: Uint8Array, algorithm?: HmacAlgorithm, encoding?: HashEncoding): Promise<string>;
9
+ export declare function hmac(input: HashInput, key: Uint8Array, algorithm?: HmacAlgorithm, encoding?: HashEncoding, provider?: CryptoProvider): Promise<string>;
7
10
  /**
8
11
  * Calculates a SHA-256 HMAC.
9
12
  */
10
- export declare function hmacSha256(input: HashInput, key: Uint8Array, encoding?: HashEncoding): Promise<string>;
13
+ export declare function hmacSha256(input: HashInput, key: Uint8Array, encoding?: HashEncoding, provider?: CryptoProvider): Promise<string>;
11
14
  /**
12
15
  * Calculates a SHA-384 HMAC.
13
16
  */
14
- export declare function hmacSha384(input: HashInput, key: Uint8Array, encoding?: HashEncoding): Promise<string>;
17
+ export declare function hmacSha384(input: HashInput, key: Uint8Array, encoding?: HashEncoding, provider?: CryptoProvider): Promise<string>;
15
18
  /**
16
19
  * Calculates a SHA-512 HMAC.
17
20
  */
18
- export declare function hmacSha512(input: HashInput, key: Uint8Array, encoding?: HashEncoding): Promise<string>;
21
+ export declare function hmacSha512(input: HashInput, key: Uint8Array, encoding?: HashEncoding, provider?: CryptoProvider): Promise<string>;
19
22
  //# sourceMappingURL=cryptoHmac.core.d.ts.map
@@ -1,29 +1,42 @@
1
- import { createNodeCryptoProvider } from "../node/index.js";
1
+ import { getDefaultCryptoProvider } from "../cryptoProvider/cryptoProvider.default.js";
2
+ import { isHmacAlgorithmName } from "../cryptoProvider/cryptoProvider.type.js";
3
+ import { KEY_SIZE } from "../cryptoConstants/cryptoConstants.type.js";
2
4
  import { encodeDigest } from "./cryptoHash.codec.js";
3
- const provider = createNodeCryptoProvider();
4
5
  /**
5
6
  * Calculates a keyed HMAC.
7
+ *
8
+ * The key must be at least `KEY_SIZE.MIN_HMAC_KEY_BYTES` (16) bytes so
9
+ * that a missing or empty secret cannot silently produce forgeable tags.
6
10
  */
7
- export async function hmac(input, key, algorithm = "sha256", encoding = "hex") {
11
+ export async function hmac(input, key, algorithm = "sha256", encoding = "hex", provider = getDefaultCryptoProvider()) {
12
+ if (!isHmacAlgorithmName(algorithm)) {
13
+ throw new TypeError(`Unsupported HMAC algorithm: ${String(algorithm)}.`);
14
+ }
15
+ if (!(key instanceof Uint8Array)) {
16
+ throw new TypeError("HMAC key must be a Uint8Array.");
17
+ }
18
+ if (key.byteLength < KEY_SIZE.MIN_HMAC_KEY_BYTES) {
19
+ throw new RangeError(`HMAC key must be at least ${KEY_SIZE.MIN_HMAC_KEY_BYTES} bytes.`);
20
+ }
8
21
  const digest = await provider.hmac(algorithm, key, input);
9
22
  return encodeDigest(digest, encoding);
10
23
  }
11
24
  /**
12
25
  * Calculates a SHA-256 HMAC.
13
26
  */
14
- export async function hmacSha256(input, key, encoding = "hex") {
15
- return hmac(input, key, "sha256", encoding);
27
+ export async function hmacSha256(input, key, encoding = "hex", provider) {
28
+ return hmac(input, key, "sha256", encoding, provider);
16
29
  }
17
30
  /**
18
31
  * Calculates a SHA-384 HMAC.
19
32
  */
20
- export async function hmacSha384(input, key, encoding = "hex") {
21
- return hmac(input, key, "sha384", encoding);
33
+ export async function hmacSha384(input, key, encoding = "hex", provider) {
34
+ return hmac(input, key, "sha384", encoding, provider);
22
35
  }
23
36
  /**
24
37
  * Calculates a SHA-512 HMAC.
25
38
  */
26
- export async function hmacSha512(input, key, encoding = "hex") {
27
- return hmac(input, key, "sha512", encoding);
39
+ export async function hmacSha512(input, key, encoding = "hex", provider) {
40
+ return hmac(input, key, "sha512", encoding, provider);
28
41
  }
29
42
  //# sourceMappingURL=cryptoHmac.core.js.map
@@ -1,17 +1,44 @@
1
1
  import type { CryptoProvider } from "../cryptoProvider/index.js";
2
+ import { CryptoAlgorithm } from "../cryptoConstants/cryptoConstants.type.js";
2
3
  import type { CryptoKey, CryptoKeyOptions } from "./cryptoKey.type.js";
4
+ /**
5
+ * Domain-separation label used for key fingerprints.
6
+ *
7
+ * Fingerprints are `HMAC-SHA256(label, keyBytes)` rather than a bare hash
8
+ * of the key so that they cannot be confused with any other digest of the
9
+ * same bytes. They are only safe to expose for keys with at least 128 bits
10
+ * of entropy, which `createCryptoKey` enforces by length; a fingerprint of
11
+ * a low-entropy key is still an offline brute-force oracle.
12
+ */
13
+ export declare const CRYPTO_KEY_FINGERPRINT_LABEL = "zudojs-crypto-key-fingerprint-v1";
14
+ /**
15
+ * Returns the required key length (in bytes) for an algorithm, or a
16
+ * minimum when any length above it is acceptable.
17
+ */
18
+ export declare function expectedKeyLength(algorithm: CryptoAlgorithm): {
19
+ readonly exact?: number;
20
+ readonly minimum: number;
21
+ };
3
22
  /**
4
23
  * Creates a cryptographic key from raw bytes.
5
24
  *
25
+ * The key length is validated against the declared algorithm (exactly 32
26
+ * bytes for AES-256-GCM, at least 16 bytes for HMAC and derived keys).
6
27
  * Hashing and key-id generation are delegated to the supplied provider.
7
28
  */
8
29
  export declare function createCryptoKey(bytes: Uint8Array, options: CryptoKeyOptions, provider?: CryptoProvider): Promise<CryptoKey>;
9
30
  /**
10
- * Generates a cryptographically secure random key.
31
+ * Generates a cryptographically secure random symmetric key.
11
32
  *
12
- * Randomness is delegated to the supplied provider.
33
+ * Only symmetric algorithms (AES-GCM, HMAC, KDF outputs) are accepted:
34
+ * random bytes are not a usable Ed25519 key, so asymmetric algorithms are
35
+ * rejected. Use `generateEd25519KeyPair` for signing keys.
13
36
  */
14
37
  export declare function generateCryptoKey(length: number, options: CryptoKeyOptions, provider?: CryptoProvider): Promise<CryptoKey>;
38
+ /**
39
+ * Returns the default key length in bytes for a symmetric algorithm.
40
+ */
41
+ export declare function defaultKeyLength(algorithm: CryptoAlgorithm): number;
15
42
  /**
16
43
  * Returns a defensive copy of a key's bytes.
17
44
  *