@zudojs/crypto 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (353) hide show
  1. package/README.md +43 -14
  2. package/dist/compare/compare.helper.d.ts +10 -2
  3. package/dist/compare/compare.helper.js +22 -6
  4. package/dist/cryptoCipher/cryptoCipher.core.d.ts +11 -1
  5. package/dist/cryptoCipher/cryptoCipher.core.js +19 -3
  6. package/dist/cryptoCipher/cryptoCipher.envelope.d.ts +7 -2
  7. package/dist/cryptoCipher/cryptoCipher.envelope.js +33 -14
  8. package/dist/cryptoCipher/cryptoCipher.string.d.ts +2 -1
  9. package/dist/cryptoCipher/cryptoCipher.string.js +2 -2
  10. package/dist/cryptoConstants/cryptoConstants.guard.d.ts +9 -0
  11. package/dist/cryptoConstants/cryptoConstants.guard.js +16 -1
  12. package/dist/cryptoConstants/cryptoConstants.security.d.ts +34 -1
  13. package/dist/cryptoConstants/cryptoConstants.security.js +34 -1
  14. package/dist/cryptoConstants/cryptoConstants.token.d.ts +2 -0
  15. package/dist/cryptoConstants/cryptoConstants.token.js +2 -0
  16. package/dist/cryptoConstants/cryptoConstants.type.d.ts +36 -14
  17. package/dist/cryptoConstants/cryptoConstants.type.js +36 -14
  18. package/dist/cryptoEncoding/cryptoEncoding.compare.d.ts +4 -1
  19. package/dist/cryptoEncoding/cryptoEncoding.compare.js +11 -4
  20. package/dist/cryptoEncoding/cryptoEncoding.core.d.ts +22 -0
  21. package/dist/cryptoEncoding/cryptoEncoding.core.js +41 -3
  22. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64.d.ts +10 -2
  23. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64.js +24 -16
  24. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64url.d.ts +9 -1
  25. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64url.js +23 -20
  26. package/dist/cryptoEncoding/encoding/cryptoEncoding.hex.d.ts +9 -2
  27. package/dist/cryptoEncoding/encoding/cryptoEncoding.hex.js +17 -11
  28. package/dist/cryptoErrors/cryptoErrors.helper.d.ts +30 -0
  29. package/dist/cryptoErrors/cryptoErrors.helper.js +72 -0
  30. package/dist/cryptoFactory/cryptoFactory.core.d.ts +37 -6
  31. package/dist/cryptoFactory/cryptoFactory.core.js +56 -30
  32. package/dist/cryptoFactory/cryptoFactory.password.d.ts +4 -3
  33. package/dist/cryptoFactory/cryptoFactory.password.js +4 -4
  34. package/dist/cryptoFactory/cryptoFactory.token.d.ts +9 -8
  35. package/dist/cryptoFactory/cryptoFactory.token.js +16 -15
  36. package/dist/cryptoHash/cryptoHash.codec.d.ts +2 -0
  37. package/dist/cryptoHash/cryptoHash.codec.js +12 -12
  38. package/dist/cryptoHash/cryptoHash.compare.d.ts +3 -1
  39. package/dist/cryptoHash/cryptoHash.compare.js +5 -9
  40. package/dist/cryptoHash/cryptoHash.core.d.ts +6 -2
  41. package/dist/cryptoHash/cryptoHash.core.js +9 -2
  42. package/dist/cryptoHash/cryptoHmac.core.d.ts +8 -5
  43. package/dist/cryptoHash/cryptoHmac.core.js +22 -9
  44. package/dist/cryptoKey/cryptoKey.factory.d.ts +29 -2
  45. package/dist/cryptoKey/cryptoKey.factory.js +82 -18
  46. package/dist/cryptoKey/cryptoKey.utils.d.ts +5 -3
  47. package/dist/cryptoKey/cryptoKey.utils.js +5 -3
  48. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.core.d.ts +7 -1
  49. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.core.js +40 -15
  50. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.salt.d.ts +2 -1
  51. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.salt.js +2 -3
  52. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.type.d.ts +5 -1
  53. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.validate.d.ts +2 -2
  54. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.validate.js +16 -6
  55. package/dist/cryptoPassword/cryptoPassword.codec.d.ts +15 -1
  56. package/dist/cryptoPassword/cryptoPassword.codec.js +127 -56
  57. package/dist/cryptoPassword/cryptoPassword.core.d.ts +17 -3
  58. package/dist/cryptoPassword/cryptoPassword.core.js +29 -21
  59. package/dist/cryptoPassword/cryptoPassword.helper.js +6 -5
  60. package/dist/cryptoPassword/cryptoPassword.type.d.ts +33 -5
  61. package/dist/cryptoPassword/cryptoPassword.validate.d.ts +14 -3
  62. package/dist/cryptoPassword/cryptoPassword.validate.js +51 -20
  63. package/dist/cryptoProvider/cryptoProvider.default.d.ts +18 -0
  64. package/dist/cryptoProvider/cryptoProvider.default.js +31 -0
  65. package/dist/cryptoProvider/cryptoProvider.interface.d.ts +9 -34
  66. package/dist/cryptoProvider/cryptoProvider.type.d.ts +32 -3
  67. package/dist/cryptoProvider/cryptoProvider.type.js +40 -1
  68. package/dist/cryptoProvider/index.d.ts +5 -2
  69. package/dist/cryptoProvider/index.js +2 -0
  70. package/dist/cryptoProvider/types/cryptoCipher.type.d.ts +11 -6
  71. package/dist/cryptoProvider/types/cryptoKeyDerivation.type.d.ts +39 -3
  72. package/dist/cryptoProvider/types/cryptoSignature.type.d.ts +5 -5
  73. package/dist/cryptoProvider/types/index.d.ts +1 -1
  74. package/dist/cryptoRandom/cryptoRandom.choice.d.ts +6 -3
  75. package/dist/cryptoRandom/cryptoRandom.choice.js +10 -6
  76. package/dist/cryptoRandom/cryptoRandom.core.d.ts +8 -5
  77. package/dist/cryptoRandom/cryptoRandom.core.js +8 -7
  78. package/dist/cryptoRandom/cryptoRandom.string.d.ts +11 -9
  79. package/dist/cryptoRandom/cryptoRandom.string.js +28 -29
  80. package/dist/cryptoService/cryptoService.core.d.ts +47 -9
  81. package/dist/cryptoService/cryptoService.core.js +65 -33
  82. package/dist/cryptoService/cryptoService.derivation.d.ts +3 -3
  83. package/dist/cryptoService/cryptoService.derivation.js +8 -6
  84. package/dist/cryptoService/cryptoService.encoding.js +6 -5
  85. package/dist/cryptoService/index.d.ts +1 -5
  86. package/dist/cryptoService/index.js +1 -5
  87. package/dist/cryptoService/operations/cryptoService.cipher.d.ts +3 -2
  88. package/dist/cryptoService/operations/cryptoService.cipher.js +13 -9
  89. package/dist/cryptoService/operations/cryptoService.hash.d.ts +3 -2
  90. package/dist/cryptoService/operations/cryptoService.hash.js +7 -8
  91. package/dist/cryptoService/operations/cryptoService.password.d.ts +7 -2
  92. package/dist/cryptoService/operations/cryptoService.password.js +20 -9
  93. package/dist/cryptoService/operations/cryptoService.token.d.ts +9 -4
  94. package/dist/cryptoService/operations/cryptoService.token.js +31 -17
  95. package/dist/cryptoSignature/cryptoSignature.core.d.ts +10 -2
  96. package/dist/cryptoSignature/cryptoSignature.core.js +7 -3
  97. package/dist/cryptoToken/cryptoToken.core.d.ts +15 -9
  98. package/dist/cryptoToken/cryptoToken.core.js +63 -38
  99. package/dist/cryptoToken/cryptoToken.hash.d.ts +9 -7
  100. package/dist/cryptoToken/cryptoToken.hash.js +19 -43
  101. package/dist/cryptoUtils/cryptoUtils.compare.d.ts +3 -1
  102. package/dist/cryptoUtils/cryptoUtils.compare.js +5 -14
  103. package/dist/cryptoUtils/cryptoUtils.number.d.ts +3 -0
  104. package/dist/cryptoUtils/cryptoUtils.number.js +12 -6
  105. package/dist/cryptoUtils/cryptoUtils.validation.d.ts +2 -2
  106. package/dist/cryptoUtils/cryptoUtils.validation.js +6 -8
  107. package/dist/cryptoUtils/encoding/cryptoUtils.base64.d.ts +4 -4
  108. package/dist/cryptoUtils/encoding/cryptoUtils.base64.js +5 -23
  109. package/dist/cryptoUtils/encoding/cryptoUtils.base64url.d.ts +4 -4
  110. package/dist/cryptoUtils/encoding/cryptoUtils.base64url.js +5 -32
  111. package/dist/cryptoUtils/encoding/cryptoUtils.hex.d.ts +4 -4
  112. package/dist/cryptoUtils/encoding/cryptoUtils.hex.js +5 -20
  113. package/dist/index.d.ts +1 -2
  114. package/dist/index.js +1 -2
  115. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.core.d.ts +6 -29
  116. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.core.js +0 -1
  117. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.helper.d.ts +9 -4
  118. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.helper.js +25 -43
  119. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.derivation.d.ts +7 -0
  120. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.derivation.js +89 -30
  121. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.password.d.ts +17 -10
  122. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.password.js +112 -72
  123. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.encryption.d.ts +3 -12
  124. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.encryption.js +74 -25
  125. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.hash.js +7 -2
  126. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.random.d.ts +6 -0
  127. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.random.js +18 -18
  128. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.signing.d.ts +10 -12
  129. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.signing.js +75 -20
  130. package/dist/node/signing/signing.conversion.d.ts +13 -3
  131. package/dist/node/signing/signing.conversion.js +35 -15
  132. package/dist/node/signing/signing.core.d.ts +2 -1
  133. package/dist/node/signing/signing.core.js +2 -3
  134. package/dist/node/signing/signing.utils.d.ts +10 -2
  135. package/dist/node/signing/signing.utils.js +26 -5
  136. package/package.json +18 -8
  137. package/dist/.tsbuildinfo +0 -1
  138. package/dist/compare/compare.helper.d.ts.map +0 -1
  139. package/dist/compare/compare.helper.js.map +0 -1
  140. package/dist/compare/index.d.ts.map +0 -1
  141. package/dist/compare/index.js.map +0 -1
  142. package/dist/cryptoAlgorithm/index.d.ts +0 -8
  143. package/dist/cryptoAlgorithm/index.d.ts.map +0 -1
  144. package/dist/cryptoAlgorithm/index.js +0 -8
  145. package/dist/cryptoAlgorithm/index.js.map +0 -1
  146. package/dist/cryptoCipher/cryptoCipher.core.d.ts.map +0 -1
  147. package/dist/cryptoCipher/cryptoCipher.core.js.map +0 -1
  148. package/dist/cryptoCipher/cryptoCipher.envelope.d.ts.map +0 -1
  149. package/dist/cryptoCipher/cryptoCipher.envelope.js.map +0 -1
  150. package/dist/cryptoCipher/cryptoCipher.string.d.ts.map +0 -1
  151. package/dist/cryptoCipher/cryptoCipher.string.js.map +0 -1
  152. package/dist/cryptoCipher/index.d.ts.map +0 -1
  153. package/dist/cryptoCipher/index.js.map +0 -1
  154. package/dist/cryptoConstants/cryptoConstants.config.d.ts.map +0 -1
  155. package/dist/cryptoConstants/cryptoConstants.config.js.map +0 -1
  156. package/dist/cryptoConstants/cryptoConstants.guard.d.ts.map +0 -1
  157. package/dist/cryptoConstants/cryptoConstants.guard.js.map +0 -1
  158. package/dist/cryptoConstants/cryptoConstants.security.d.ts.map +0 -1
  159. package/dist/cryptoConstants/cryptoConstants.security.js.map +0 -1
  160. package/dist/cryptoConstants/cryptoConstants.token.d.ts.map +0 -1
  161. package/dist/cryptoConstants/cryptoConstants.token.js.map +0 -1
  162. package/dist/cryptoConstants/cryptoConstants.type.d.ts.map +0 -1
  163. package/dist/cryptoConstants/cryptoConstants.type.js.map +0 -1
  164. package/dist/cryptoConstants/index.d.ts.map +0 -1
  165. package/dist/cryptoConstants/index.js.map +0 -1
  166. package/dist/cryptoEncoding/cryptoEncoding.arrayBuffer.d.ts.map +0 -1
  167. package/dist/cryptoEncoding/cryptoEncoding.arrayBuffer.js.map +0 -1
  168. package/dist/cryptoEncoding/cryptoEncoding.compare.d.ts.map +0 -1
  169. package/dist/cryptoEncoding/cryptoEncoding.compare.js.map +0 -1
  170. package/dist/cryptoEncoding/cryptoEncoding.core.d.ts.map +0 -1
  171. package/dist/cryptoEncoding/cryptoEncoding.core.js.map +0 -1
  172. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64.d.ts.map +0 -1
  173. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64.js.map +0 -1
  174. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64url.d.ts.map +0 -1
  175. package/dist/cryptoEncoding/encoding/cryptoEncoding.base64url.js.map +0 -1
  176. package/dist/cryptoEncoding/encoding/cryptoEncoding.hex.d.ts.map +0 -1
  177. package/dist/cryptoEncoding/encoding/cryptoEncoding.hex.js.map +0 -1
  178. package/dist/cryptoEncoding/encoding/index.d.ts.map +0 -1
  179. package/dist/cryptoEncoding/encoding/index.js.map +0 -1
  180. package/dist/cryptoEncoding/index.d.ts.map +0 -1
  181. package/dist/cryptoEncoding/index.js.map +0 -1
  182. package/dist/cryptoErrors/index.d.ts.map +0 -1
  183. package/dist/cryptoErrors/index.js.map +0 -1
  184. package/dist/cryptoFactory/cryptoFactory.core.d.ts.map +0 -1
  185. package/dist/cryptoFactory/cryptoFactory.core.js.map +0 -1
  186. package/dist/cryptoFactory/cryptoFactory.encoding.d.ts.map +0 -1
  187. package/dist/cryptoFactory/cryptoFactory.encoding.js.map +0 -1
  188. package/dist/cryptoFactory/cryptoFactory.options.d.ts +0 -2
  189. package/dist/cryptoFactory/cryptoFactory.options.d.ts.map +0 -1
  190. package/dist/cryptoFactory/cryptoFactory.options.js +0 -6
  191. package/dist/cryptoFactory/cryptoFactory.options.js.map +0 -1
  192. package/dist/cryptoFactory/cryptoFactory.password.d.ts.map +0 -1
  193. package/dist/cryptoFactory/cryptoFactory.password.js.map +0 -1
  194. package/dist/cryptoFactory/cryptoFactory.token.d.ts.map +0 -1
  195. package/dist/cryptoFactory/cryptoFactory.token.js.map +0 -1
  196. package/dist/cryptoFactory/index.d.ts.map +0 -1
  197. package/dist/cryptoFactory/index.js.map +0 -1
  198. package/dist/cryptoHash/cryptoHash.codec.d.ts.map +0 -1
  199. package/dist/cryptoHash/cryptoHash.codec.js.map +0 -1
  200. package/dist/cryptoHash/cryptoHash.compare.d.ts.map +0 -1
  201. package/dist/cryptoHash/cryptoHash.compare.js.map +0 -1
  202. package/dist/cryptoHash/cryptoHash.convenience.d.ts.map +0 -1
  203. package/dist/cryptoHash/cryptoHash.convenience.js.map +0 -1
  204. package/dist/cryptoHash/cryptoHash.core.d.ts.map +0 -1
  205. package/dist/cryptoHash/cryptoHash.core.js.map +0 -1
  206. package/dist/cryptoHash/cryptoHmac.core.d.ts.map +0 -1
  207. package/dist/cryptoHash/cryptoHmac.core.js.map +0 -1
  208. package/dist/cryptoHash/index.d.ts.map +0 -1
  209. package/dist/cryptoHash/index.js.map +0 -1
  210. package/dist/cryptoKey/cryptoKey.factory.d.ts.map +0 -1
  211. package/dist/cryptoKey/cryptoKey.factory.js.map +0 -1
  212. package/dist/cryptoKey/cryptoKey.type.d.ts.map +0 -1
  213. package/dist/cryptoKey/cryptoKey.type.js.map +0 -1
  214. package/dist/cryptoKey/cryptoKey.utils.d.ts.map +0 -1
  215. package/dist/cryptoKey/cryptoKey.utils.js.map +0 -1
  216. package/dist/cryptoKey/index.d.ts.map +0 -1
  217. package/dist/cryptoKey/index.js.map +0 -1
  218. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.core.d.ts.map +0 -1
  219. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.core.js.map +0 -1
  220. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.salt.d.ts.map +0 -1
  221. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.salt.js.map +0 -1
  222. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.type.d.ts.map +0 -1
  223. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.type.js.map +0 -1
  224. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.validate.d.ts.map +0 -1
  225. package/dist/cryptoKeyDerivation/cryptoKeyDerivation.validate.js.map +0 -1
  226. package/dist/cryptoKeyDerivation/index.d.ts.map +0 -1
  227. package/dist/cryptoKeyDerivation/index.js.map +0 -1
  228. package/dist/cryptoPassword/cryptoPassword.codec.d.ts.map +0 -1
  229. package/dist/cryptoPassword/cryptoPassword.codec.js.map +0 -1
  230. package/dist/cryptoPassword/cryptoPassword.core.d.ts.map +0 -1
  231. package/dist/cryptoPassword/cryptoPassword.core.js.map +0 -1
  232. package/dist/cryptoPassword/cryptoPassword.helper.d.ts.map +0 -1
  233. package/dist/cryptoPassword/cryptoPassword.helper.js.map +0 -1
  234. package/dist/cryptoPassword/cryptoPassword.type.d.ts.map +0 -1
  235. package/dist/cryptoPassword/cryptoPassword.type.js.map +0 -1
  236. package/dist/cryptoPassword/cryptoPassword.validate.d.ts.map +0 -1
  237. package/dist/cryptoPassword/cryptoPassword.validate.js.map +0 -1
  238. package/dist/cryptoPassword/index.d.ts.map +0 -1
  239. package/dist/cryptoPassword/index.js.map +0 -1
  240. package/dist/cryptoProvider/cryptoProvider.core.d.ts.map +0 -1
  241. package/dist/cryptoProvider/cryptoProvider.core.js.map +0 -1
  242. package/dist/cryptoProvider/cryptoProvider.interface.d.ts.map +0 -1
  243. package/dist/cryptoProvider/cryptoProvider.interface.js.map +0 -1
  244. package/dist/cryptoProvider/cryptoProvider.type.d.ts.map +0 -1
  245. package/dist/cryptoProvider/cryptoProvider.type.js.map +0 -1
  246. package/dist/cryptoProvider/index.d.ts.map +0 -1
  247. package/dist/cryptoProvider/index.js.map +0 -1
  248. package/dist/cryptoProvider/types/cryptoCipher.type.d.ts.map +0 -1
  249. package/dist/cryptoProvider/types/cryptoCipher.type.js.map +0 -1
  250. package/dist/cryptoProvider/types/cryptoHash.type.d.ts.map +0 -1
  251. package/dist/cryptoProvider/types/cryptoHash.type.js.map +0 -1
  252. package/dist/cryptoProvider/types/cryptoKeyDerivation.type.d.ts.map +0 -1
  253. package/dist/cryptoProvider/types/cryptoKeyDerivation.type.js.map +0 -1
  254. package/dist/cryptoProvider/types/cryptoRandom.type.d.ts.map +0 -1
  255. package/dist/cryptoProvider/types/cryptoRandom.type.js.map +0 -1
  256. package/dist/cryptoProvider/types/cryptoSignature.type.d.ts.map +0 -1
  257. package/dist/cryptoProvider/types/cryptoSignature.type.js.map +0 -1
  258. package/dist/cryptoProvider/types/index.d.ts.map +0 -1
  259. package/dist/cryptoProvider/types/index.js.map +0 -1
  260. package/dist/cryptoRandom/cryptoRandom.choice.d.ts.map +0 -1
  261. package/dist/cryptoRandom/cryptoRandom.choice.js.map +0 -1
  262. package/dist/cryptoRandom/cryptoRandom.core.d.ts.map +0 -1
  263. package/dist/cryptoRandom/cryptoRandom.core.js.map +0 -1
  264. package/dist/cryptoRandom/cryptoRandom.string.d.ts.map +0 -1
  265. package/dist/cryptoRandom/cryptoRandom.string.js.map +0 -1
  266. package/dist/cryptoRandom/index.d.ts.map +0 -1
  267. package/dist/cryptoRandom/index.js.map +0 -1
  268. package/dist/cryptoService/cryptoService.core.d.ts.map +0 -1
  269. package/dist/cryptoService/cryptoService.core.js.map +0 -1
  270. package/dist/cryptoService/cryptoService.derivation.d.ts.map +0 -1
  271. package/dist/cryptoService/cryptoService.derivation.js.map +0 -1
  272. package/dist/cryptoService/cryptoService.encoding.d.ts.map +0 -1
  273. package/dist/cryptoService/cryptoService.encoding.js.map +0 -1
  274. package/dist/cryptoService/index.d.ts.map +0 -1
  275. package/dist/cryptoService/index.js.map +0 -1
  276. package/dist/cryptoService/operations/cryptoService.cipher.d.ts.map +0 -1
  277. package/dist/cryptoService/operations/cryptoService.cipher.js.map +0 -1
  278. package/dist/cryptoService/operations/cryptoService.hash.d.ts.map +0 -1
  279. package/dist/cryptoService/operations/cryptoService.hash.js.map +0 -1
  280. package/dist/cryptoService/operations/cryptoService.password.d.ts.map +0 -1
  281. package/dist/cryptoService/operations/cryptoService.password.js.map +0 -1
  282. package/dist/cryptoService/operations/cryptoService.token.d.ts.map +0 -1
  283. package/dist/cryptoService/operations/cryptoService.token.js.map +0 -1
  284. package/dist/cryptoService/operations/index.d.ts.map +0 -1
  285. package/dist/cryptoService/operations/index.js.map +0 -1
  286. package/dist/cryptoSignature/cryptoSignature.core.d.ts.map +0 -1
  287. package/dist/cryptoSignature/cryptoSignature.core.js.map +0 -1
  288. package/dist/cryptoSignature/index.d.ts.map +0 -1
  289. package/dist/cryptoSignature/index.js.map +0 -1
  290. package/dist/cryptoToken/cryptoToken.core.d.ts.map +0 -1
  291. package/dist/cryptoToken/cryptoToken.core.js.map +0 -1
  292. package/dist/cryptoToken/cryptoToken.hash.d.ts.map +0 -1
  293. package/dist/cryptoToken/cryptoToken.hash.js.map +0 -1
  294. package/dist/cryptoToken/cryptoToken.utils.d.ts.map +0 -1
  295. package/dist/cryptoToken/cryptoToken.utils.js.map +0 -1
  296. package/dist/cryptoToken/index.d.ts.map +0 -1
  297. package/dist/cryptoToken/index.js.map +0 -1
  298. package/dist/cryptoUtils/cryptoUtils.compare.d.ts.map +0 -1
  299. package/dist/cryptoUtils/cryptoUtils.compare.js.map +0 -1
  300. package/dist/cryptoUtils/cryptoUtils.conversion.d.ts.map +0 -1
  301. package/dist/cryptoUtils/cryptoUtils.conversion.js.map +0 -1
  302. package/dist/cryptoUtils/cryptoUtils.number.d.ts.map +0 -1
  303. package/dist/cryptoUtils/cryptoUtils.number.js.map +0 -1
  304. package/dist/cryptoUtils/cryptoUtils.text.d.ts.map +0 -1
  305. package/dist/cryptoUtils/cryptoUtils.text.js.map +0 -1
  306. package/dist/cryptoUtils/cryptoUtils.validation.d.ts.map +0 -1
  307. package/dist/cryptoUtils/cryptoUtils.validation.js.map +0 -1
  308. package/dist/cryptoUtils/encoding/cryptoUtils.base64.d.ts.map +0 -1
  309. package/dist/cryptoUtils/encoding/cryptoUtils.base64.js.map +0 -1
  310. package/dist/cryptoUtils/encoding/cryptoUtils.base64url.d.ts.map +0 -1
  311. package/dist/cryptoUtils/encoding/cryptoUtils.base64url.js.map +0 -1
  312. package/dist/cryptoUtils/encoding/cryptoUtils.hex.d.ts.map +0 -1
  313. package/dist/cryptoUtils/encoding/cryptoUtils.hex.js.map +0 -1
  314. package/dist/cryptoUtils/encoding/index.d.ts.map +0 -1
  315. package/dist/cryptoUtils/encoding/index.js.map +0 -1
  316. package/dist/cryptoUtils/index.d.ts.map +0 -1
  317. package/dist/cryptoUtils/index.js.map +0 -1
  318. package/dist/index.d.ts.map +0 -1
  319. package/dist/index.js.map +0 -1
  320. package/dist/node/index.d.ts.map +0 -1
  321. package/dist/node/index.js.map +0 -1
  322. package/dist/node/nodeCryptoProvider/index.d.ts.map +0 -1
  323. package/dist/node/nodeCryptoProvider/index.js.map +0 -1
  324. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.core.d.ts.map +0 -1
  325. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.core.js.map +0 -1
  326. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.factory.d.ts.map +0 -1
  327. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.factory.js.map +0 -1
  328. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.helper.d.ts.map +0 -1
  329. package/dist/node/nodeCryptoProvider/nodeCryptoProvider.helper.js.map +0 -1
  330. package/dist/node/nodeCryptoProvider/operations/index.d.ts.map +0 -1
  331. package/dist/node/nodeCryptoProvider/operations/index.js.map +0 -1
  332. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.derivation.d.ts.map +0 -1
  333. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.derivation.js.map +0 -1
  334. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.password.d.ts.map +0 -1
  335. package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.password.js.map +0 -1
  336. package/dist/node/nodeCryptoProvider/primitives/index.d.ts.map +0 -1
  337. package/dist/node/nodeCryptoProvider/primitives/index.js.map +0 -1
  338. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.encryption.d.ts.map +0 -1
  339. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.encryption.js.map +0 -1
  340. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.hash.d.ts.map +0 -1
  341. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.hash.js.map +0 -1
  342. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.random.d.ts.map +0 -1
  343. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.random.js.map +0 -1
  344. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.signing.d.ts.map +0 -1
  345. package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.signing.js.map +0 -1
  346. package/dist/node/signing/index.d.ts.map +0 -1
  347. package/dist/node/signing/index.js.map +0 -1
  348. package/dist/node/signing/signing.conversion.d.ts.map +0 -1
  349. package/dist/node/signing/signing.conversion.js.map +0 -1
  350. package/dist/node/signing/signing.core.d.ts.map +0 -1
  351. package/dist/node/signing/signing.core.js.map +0 -1
  352. package/dist/node/signing/signing.utils.d.ts.map +0 -1
  353. package/dist/node/signing/signing.utils.js.map +0 -1
@@ -1,29 +1,66 @@
1
- import { createNodeCryptoProvider } from "../node/index.js";
1
+ import { getDefaultCryptoProvider } from "../cryptoProvider/cryptoProvider.default.js";
2
2
  import { encode } from "../cryptoEncoding/cryptoEncoding.core.js";
3
- let defaultProvider;
3
+ import { CryptoOperation } from "@zudojs/errors";
4
+ import { keyError } from "../cryptoErrors/cryptoErrors.helper.js";
5
+ import { CryptoAlgorithm, AES_GCM, KEY_SIZE, } from "../cryptoConstants/cryptoConstants.type.js";
6
+ import { isAeadAlgorithm, isHashAlgorithm, isKeyDerivationAlgorithm, isMacAlgorithm, isSymmetricKeyAlgorithm, } from "../cryptoConstants/cryptoConstants.guard.js";
4
7
  /**
5
- * Returns a lazily created default crypto provider.
8
+ * Domain-separation label used for key fingerprints.
6
9
  *
7
- * The provider abstraction keeps the key module free of direct
8
- * `node:crypto` usage while still allowing callers to inject their own.
10
+ * Fingerprints are `HMAC-SHA256(label, keyBytes)` rather than a bare hash
11
+ * of the key so that they cannot be confused with any other digest of the
12
+ * same bytes. They are only safe to expose for keys with at least 128 bits
13
+ * of entropy, which `createCryptoKey` enforces by length; a fingerprint of
14
+ * a low-entropy key is still an offline brute-force oracle.
9
15
  */
10
- function getDefaultProvider() {
11
- if (defaultProvider === undefined) {
12
- defaultProvider = createNodeCryptoProvider();
16
+ export const CRYPTO_KEY_FINGERPRINT_LABEL = "zudojs-crypto-key-fingerprint-v1";
17
+ const MIN_SYMMETRIC_KEY_BYTES = KEY_SIZE.MIN_SYMMETRIC_KEY_BITS / 8;
18
+ /**
19
+ * Returns the required key length (in bytes) for an algorithm, or a
20
+ * minimum when any length above it is acceptable.
21
+ */
22
+ export function expectedKeyLength(algorithm) {
23
+ if (isAeadAlgorithm(algorithm)) {
24
+ return { exact: AES_GCM.KEY_BYTES, minimum: AES_GCM.KEY_BYTES };
25
+ }
26
+ if (isMacAlgorithm(algorithm) || isKeyDerivationAlgorithm(algorithm)) {
27
+ return { minimum: MIN_SYMMETRIC_KEY_BYTES };
28
+ }
29
+ if (algorithm === CryptoAlgorithm.ED25519) {
30
+ // Raw 32-byte seed or a DER/PEM encoded key.
31
+ return { minimum: KEY_SIZE.ED25519_BITS / 8 };
32
+ }
33
+ throw keyError(`Algorithm "${String(algorithm)}" does not use cryptographic keys.`, CryptoOperation.KEY_IMPORT, typeof algorithm === "string" ? algorithm : undefined);
34
+ }
35
+ function validateKeyBytes(bytes, algorithm) {
36
+ if (!(bytes instanceof Uint8Array)) {
37
+ throw keyError("Cryptographic key material must be a Uint8Array.", CryptoOperation.KEY_IMPORT, algorithm);
38
+ }
39
+ if (bytes.byteLength === 0) {
40
+ throw keyError("Cryptographic key cannot be empty.", CryptoOperation.KEY_IMPORT, algorithm);
41
+ }
42
+ if (isHashAlgorithm(algorithm)) {
43
+ throw keyError(`Hash algorithm "${algorithm}" does not use cryptographic keys.`, CryptoOperation.KEY_IMPORT, algorithm);
44
+ }
45
+ const { exact, minimum } = expectedKeyLength(algorithm);
46
+ if (exact !== undefined && bytes.byteLength !== exact) {
47
+ throw keyError(`Algorithm "${algorithm}" requires a ${exact}-byte key, received ${bytes.byteLength} bytes.`, CryptoOperation.KEY_IMPORT, algorithm);
48
+ }
49
+ if (bytes.byteLength < minimum) {
50
+ throw keyError(`Algorithm "${algorithm}" requires a key of at least ${minimum} bytes, received ${bytes.byteLength} bytes.`, CryptoOperation.KEY_IMPORT, algorithm);
13
51
  }
14
- return defaultProvider;
15
52
  }
16
53
  /**
17
54
  * Creates a cryptographic key from raw bytes.
18
55
  *
56
+ * The key length is validated against the declared algorithm (exactly 32
57
+ * bytes for AES-256-GCM, at least 16 bytes for HMAC and derived keys).
19
58
  * Hashing and key-id generation are delegated to the supplied provider.
20
59
  */
21
- export async function createCryptoKey(bytes, options, provider = getDefaultProvider()) {
22
- if (bytes.byteLength === 0) {
23
- throw new TypeError("Cryptographic key cannot be empty.");
24
- }
60
+ export async function createCryptoKey(bytes, options, provider = getDefaultCryptoProvider()) {
61
+ validateKeyBytes(bytes, options.algorithm);
25
62
  const keyBytes = new Uint8Array(bytes);
26
- const digest = await provider.hash("sha256", keyBytes);
63
+ const digest = await provider.hmac("sha256", CRYPTO_KEY_FINGERPRINT_LABEL, keyBytes);
27
64
  const fingerprint = encode(digest, "hex");
28
65
  const createdAt = Date.now();
29
66
  const keyId = options.keyId ?? `key_${await generateKeyId(provider)}`;
@@ -40,17 +77,44 @@ export async function createCryptoKey(bytes, options, provider = getDefaultProvi
40
77
  });
41
78
  }
42
79
  /**
43
- * Generates a cryptographically secure random key.
80
+ * Generates a cryptographically secure random symmetric key.
44
81
  *
45
- * Randomness is delegated to the supplied provider.
82
+ * Only symmetric algorithms (AES-GCM, HMAC, KDF outputs) are accepted:
83
+ * random bytes are not a usable Ed25519 key, so asymmetric algorithms are
84
+ * rejected. Use `generateEd25519KeyPair` for signing keys.
46
85
  */
47
- export async function generateCryptoKey(length, options, provider = getDefaultProvider()) {
86
+ export async function generateCryptoKey(length, options, provider = getDefaultCryptoProvider()) {
87
+ if (!isSymmetricKeyAlgorithm(options.algorithm)) {
88
+ throw keyError(`Random key generation is only supported for symmetric algorithms, not "${String(options.algorithm)}".`, CryptoOperation.KEY_GENERATION, typeof options.algorithm === "string" ? options.algorithm : undefined);
89
+ }
48
90
  if (!Number.isInteger(length) || length <= 0) {
49
91
  throw new RangeError("Cryptographic key length must be a positive integer.");
50
92
  }
51
93
  const bytes = await provider.randomBytes(length);
52
94
  return createCryptoKey(bytes, options, provider);
53
95
  }
96
+ /**
97
+ * Returns the default key length in bytes for a symmetric algorithm.
98
+ */
99
+ export function defaultKeyLength(algorithm) {
100
+ if (isAeadAlgorithm(algorithm)) {
101
+ return AES_GCM.KEY_BYTES;
102
+ }
103
+ switch (algorithm) {
104
+ case CryptoAlgorithm.HMAC_SHA256:
105
+ case CryptoAlgorithm.PBKDF2_SHA256:
106
+ case CryptoAlgorithm.SCRYPT:
107
+ return 32;
108
+ case CryptoAlgorithm.HMAC_SHA384:
109
+ case CryptoAlgorithm.PBKDF2_SHA384:
110
+ return 48;
111
+ case CryptoAlgorithm.HMAC_SHA512:
112
+ case CryptoAlgorithm.PBKDF2_SHA512:
113
+ return 64;
114
+ default:
115
+ throw keyError(`Random key generation is only supported for symmetric algorithms, not "${String(algorithm)}".`, CryptoOperation.KEY_GENERATION, typeof algorithm === "string" ? algorithm : undefined);
116
+ }
117
+ }
54
118
  /**
55
119
  * Returns a defensive copy of a key's bytes.
56
120
  *
@@ -58,7 +122,7 @@ export async function generateCryptoKey(length, options, provider = getDefaultPr
58
122
  */
59
123
  export function exportCryptoKey(key) {
60
124
  if (!key.extractable) {
61
- throw new Error(`Cryptographic key "${key.keyId}" is not extractable.`);
125
+ throw keyError(`Cryptographic key "${key.keyId}" is not extractable.`, CryptoOperation.KEY_EXPORT, key.algorithm);
62
126
  }
63
127
  return key.bytes();
64
128
  }
@@ -1,9 +1,11 @@
1
1
  import type { CryptoKey } from "./cryptoKey.type.js";
2
2
  /**
3
- * Returns a stable SHA-256 fingerprint for a key.
3
+ * Returns the stable fingerprint of a key.
4
4
  *
5
- * The fingerprint can be used for identification without exposing
6
- * the secret key material.
5
+ * The fingerprint is `HMAC-SHA256(CRYPTO_KEY_FINGERPRINT_LABEL, keyBytes)`
6
+ * in hex. It can be used to identify a key without exposing the secret
7
+ * material, provided the key has at least 128 bits of entropy (which
8
+ * `createCryptoKey` enforces by minimum length).
7
9
  */
8
10
  export declare function getCryptoKeyFingerprint(key: CryptoKey): string;
9
11
  /**
@@ -1,8 +1,10 @@
1
1
  /**
2
- * Returns a stable SHA-256 fingerprint for a key.
2
+ * Returns the stable fingerprint of a key.
3
3
  *
4
- * The fingerprint can be used for identification without exposing
5
- * the secret key material.
4
+ * The fingerprint is `HMAC-SHA256(CRYPTO_KEY_FINGERPRINT_LABEL, keyBytes)`
5
+ * in hex. It can be used to identify a key without exposing the secret
6
+ * material, provided the key has at least 128 bits of entropy (which
7
+ * `createCryptoKey` enforces by minimum length).
6
8
  */
7
9
  export function getCryptoKeyFingerprint(key) {
8
10
  return key.fingerprint;
@@ -2,11 +2,17 @@ import type { DerivedKeyResult } from "../cryptoProvider/index.js";
2
2
  import { CryptoAlgorithm } from "../cryptoConstants/cryptoConstants.type.js";
3
3
  import type { Pbkdf2Options, ScryptOptions } from "./cryptoKeyDerivation.type.js";
4
4
  /**
5
- * Derives a key from a password using PBKDF2.
5
+ * Derives a key from a password using PBKDF2-HMAC.
6
+ *
7
+ * The digest option is honoured end to end and reflected in
8
+ * `result.algorithm` (`pbkdf2-sha256`, `pbkdf2-sha384` or `pbkdf2-sha512`).
6
9
  */
7
10
  export declare function derivePbkdf2(password: string | Uint8Array, options?: Pbkdf2Options): Promise<DerivedKeyResult>;
8
11
  /**
9
12
  * Derives a key using scrypt.
13
+ *
14
+ * `blockSize` and `maxMemory` are forwarded to the provider, so work
15
+ * factors above the default (e.g. N = 2^17) are usable.
10
16
  */
11
17
  export declare function deriveScrypt(password: string | Uint8Array, options?: ScryptOptions): Promise<DerivedKeyResult>;
12
18
  /**
@@ -1,50 +1,70 @@
1
- import { createNodeCryptoProvider } from "../node/index.js";
1
+ import { getDefaultCryptoProvider } from "../cryptoProvider/cryptoProvider.default.js";
2
2
  import { CryptoAlgorithm } from "../cryptoConstants/cryptoConstants.type.js";
3
+ import { PASSWORD_HASH } from "../cryptoConstants/cryptoConstants.security.js";
3
4
  import { validatePbkdf2Options, validateScryptOptions, } from "./cryptoKeyDerivation.validate.js";
4
- const provider = createNodeCryptoProvider();
5
+ function pbkdf2Label(digest) {
6
+ switch (digest) {
7
+ case "sha256":
8
+ return CryptoAlgorithm.PBKDF2_SHA256;
9
+ case "sha384":
10
+ return CryptoAlgorithm.PBKDF2_SHA384;
11
+ case "sha512":
12
+ return CryptoAlgorithm.PBKDF2_SHA512;
13
+ }
14
+ }
5
15
  /**
6
- * Derives a key from a password using PBKDF2.
16
+ * Derives a key from a password using PBKDF2-HMAC.
17
+ *
18
+ * The digest option is honoured end to end and reflected in
19
+ * `result.algorithm` (`pbkdf2-sha256`, `pbkdf2-sha384` or `pbkdf2-sha512`).
7
20
  */
8
21
  export async function derivePbkdf2(password, options = {}) {
9
- const iterations = options.iterations ?? 310_000;
22
+ const provider = options.provider ?? getDefaultCryptoProvider();
23
+ const iterations = options.iterations ?? PASSWORD_HASH.PBKDF2.ITERATIONS;
10
24
  const keyLength = options.keyLength ?? 32;
25
+ const digest = options.digest ?? "sha256";
11
26
  const salt = options.salt ??
12
27
  new Uint8Array(await provider.randomBytes(options.saltLength ?? 16));
13
- const digest = options.digest ?? "sha256";
14
- validatePbkdf2Options(iterations, keyLength, salt);
28
+ validatePbkdf2Options(iterations, keyLength, salt, digest);
15
29
  const key = await provider.deriveKey({
16
30
  password,
17
31
  salt,
18
32
  algorithm: "pbkdf2",
19
33
  keyLength,
20
34
  iterations,
35
+ digest,
21
36
  });
22
37
  return Object.freeze({
23
- algorithm: digest === "sha512"
24
- ? CryptoAlgorithm.PBKDF2_SHA512
25
- : CryptoAlgorithm.PBKDF2_SHA256,
38
+ algorithm: pbkdf2Label(digest),
39
+ digest,
26
40
  key,
27
41
  salt: new Uint8Array(salt),
28
42
  });
29
43
  }
30
44
  /**
31
45
  * Derives a key using scrypt.
46
+ *
47
+ * `blockSize` and `maxMemory` are forwarded to the provider, so work
48
+ * factors above the default (e.g. N = 2^17) are usable.
32
49
  */
33
50
  export async function deriveScrypt(password, options = {}) {
51
+ const provider = options.provider ?? getDefaultCryptoProvider();
34
52
  const keyLength = options.keyLength ?? 32;
35
- const cost = options.cost ?? 16_384;
36
- const blockSize = options.blockSize ?? 8;
37
- const parallelization = options.parallelization ?? 1;
53
+ const cost = options.cost ?? PASSWORD_HASH.SCRYPT.COST;
54
+ const blockSize = options.blockSize ?? PASSWORD_HASH.SCRYPT.BLOCK_SIZE;
55
+ const parallelization = options.parallelization ?? PASSWORD_HASH.SCRYPT.PARALLELIZATION;
38
56
  const salt = options.salt ??
39
57
  new Uint8Array(await provider.randomBytes(options.saltLength ?? 16));
40
- validateScryptOptions(keyLength, cost, blockSize, parallelization, salt);
58
+ validateScryptOptions(keyLength, cost, blockSize, parallelization, salt, options.maxMemory);
41
59
  const key = await provider.deriveKey({
42
- password: password instanceof Uint8Array ? password : Buffer.from(password, "utf8"),
60
+ password,
43
61
  salt,
44
62
  algorithm: "scrypt",
45
63
  keyLength,
46
64
  memoryCost: cost,
65
+ blockSize,
47
66
  parallelism: parallelization,
67
+ maxMemory: options.maxMemory,
48
68
  });
49
69
  return Object.freeze({
50
70
  algorithm: CryptoAlgorithm.SCRYPT,
@@ -62,6 +82,11 @@ export async function deriveKey(password, algorithm, options = {}) {
62
82
  ...options,
63
83
  digest: "sha256",
64
84
  });
85
+ case CryptoAlgorithm.PBKDF2_SHA384:
86
+ return derivePbkdf2(password, {
87
+ ...options,
88
+ digest: "sha384",
89
+ });
65
90
  case CryptoAlgorithm.PBKDF2_SHA512:
66
91
  return derivePbkdf2(password, {
67
92
  ...options,
@@ -70,7 +95,7 @@ export async function deriveKey(password, algorithm, options = {}) {
70
95
  case CryptoAlgorithm.SCRYPT:
71
96
  return deriveScrypt(password, options);
72
97
  default:
73
- throw new TypeError(`Unsupported key derivation algorithm: ${algorithm}.`);
98
+ throw new TypeError(`Unsupported key derivation algorithm: ${String(algorithm)}.`);
74
99
  }
75
100
  }
76
101
  //# sourceMappingURL=cryptoKeyDerivation.core.js.map
@@ -1,5 +1,6 @@
1
+ import type { CryptoProvider } from "../cryptoProvider/index.js";
1
2
  /**
2
3
  * Creates a random salt.
3
4
  */
4
- export declare function generateSalt(length?: number): Promise<Uint8Array>;
5
+ export declare function generateSalt(length?: number, provider?: CryptoProvider): Promise<Uint8Array>;
5
6
  //# sourceMappingURL=cryptoKeyDerivation.salt.d.ts.map
@@ -1,12 +1,11 @@
1
- import { createNodeCryptoProvider } from "../node/index.js";
1
+ import { getDefaultCryptoProvider } from "../cryptoProvider/cryptoProvider.default.js";
2
2
  /**
3
3
  * Creates a random salt.
4
4
  */
5
- export async function generateSalt(length = 16) {
5
+ export async function generateSalt(length = 16, provider = getDefaultCryptoProvider()) {
6
6
  if (!Number.isInteger(length) || length < 16) {
7
7
  throw new RangeError("Salt length must be an integer of at least 16 bytes.");
8
8
  }
9
- const provider = createNodeCryptoProvider();
10
9
  return provider.randomBytes(length);
11
10
  }
12
11
  //# sourceMappingURL=cryptoKeyDerivation.salt.js.map
@@ -1,12 +1,14 @@
1
+ import type { CryptoProvider, Pbkdf2Digest } from "../cryptoProvider/index.js";
1
2
  /**
2
3
  * Options for PBKDF2 key derivation.
3
4
  */
4
5
  export interface Pbkdf2Options {
5
6
  readonly iterations?: number;
6
7
  readonly keyLength?: number;
7
- readonly digest?: "sha256" | "sha384" | "sha512";
8
+ readonly digest?: Pbkdf2Digest;
8
9
  readonly salt?: Uint8Array;
9
10
  readonly saltLength?: number;
11
+ readonly provider?: CryptoProvider;
10
12
  }
11
13
  /**
12
14
  * Options for scrypt key derivation.
@@ -18,6 +20,8 @@ export interface ScryptOptions {
18
20
  readonly parallelization?: number;
19
21
  readonly salt?: Uint8Array;
20
22
  readonly saltLength?: number;
23
+ /** Memory upper bound in bytes; defaults to a value derived from cost/blockSize/parallelization. */
21
24
  readonly maxMemory?: number;
25
+ readonly provider?: CryptoProvider;
22
26
  }
23
27
  //# sourceMappingURL=cryptoKeyDerivation.type.d.ts.map
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Validates PBKDF2 key derivation options.
3
3
  */
4
- export declare function validatePbkdf2Options(iterations: number, keyLength: number, salt: Uint8Array): void;
4
+ export declare function validatePbkdf2Options(iterations: number, keyLength: number, salt: Uint8Array, digest?: unknown): void;
5
5
  /**
6
6
  * Validates scrypt key derivation options.
7
7
  */
8
- export declare function validateScryptOptions(keyLength: number, cost: number, blockSize: number, parallelization: number, salt: Uint8Array): void;
8
+ export declare function validateScryptOptions(keyLength: number, cost: number, blockSize: number, parallelization: number, salt: Uint8Array, maxMemory?: number): void;
9
9
  //# sourceMappingURL=cryptoKeyDerivation.validate.d.ts.map
@@ -1,21 +1,27 @@
1
+ import { PASSWORD_HASH } from "../cryptoConstants/cryptoConstants.security.js";
2
+ import { isPbkdf2Digest } from "../cryptoProvider/cryptoProvider.type.js";
1
3
  /**
2
4
  * Validates PBKDF2 key derivation options.
3
5
  */
4
- export function validatePbkdf2Options(iterations, keyLength, salt) {
5
- if (!Number.isInteger(iterations) || iterations < 100_000) {
6
- throw new RangeError("PBKDF2 iterations must be at least 100000.");
6
+ export function validatePbkdf2Options(iterations, keyLength, salt, digest = "sha256") {
7
+ if (!Number.isInteger(iterations) ||
8
+ iterations < PASSWORD_HASH.PBKDF2.MIN_ITERATIONS) {
9
+ throw new RangeError(`PBKDF2 iterations must be at least ${PASSWORD_HASH.PBKDF2.MIN_ITERATIONS}.`);
7
10
  }
8
11
  if (!Number.isInteger(keyLength) || keyLength < 16) {
9
12
  throw new RangeError("PBKDF2 keyLength must be at least 16 bytes.");
10
13
  }
11
- if (salt.byteLength < 16) {
14
+ if (!(salt instanceof Uint8Array) || salt.byteLength < 16) {
12
15
  throw new RangeError("PBKDF2 salt must be at least 16 bytes.");
13
16
  }
17
+ if (!isPbkdf2Digest(digest)) {
18
+ throw new TypeError(`Unsupported PBKDF2 digest: ${String(digest)}.`);
19
+ }
14
20
  }
15
21
  /**
16
22
  * Validates scrypt key derivation options.
17
23
  */
18
- export function validateScryptOptions(keyLength, cost, blockSize, parallelization, salt) {
24
+ export function validateScryptOptions(keyLength, cost, blockSize, parallelization, salt, maxMemory) {
19
25
  if (!Number.isInteger(keyLength) || keyLength < 16) {
20
26
  throw new RangeError("scrypt keyLength must be at least 16 bytes.");
21
27
  }
@@ -28,8 +34,12 @@ export function validateScryptOptions(keyLength, cost, blockSize, parallelizatio
28
34
  if (!Number.isInteger(parallelization) || parallelization <= 0) {
29
35
  throw new RangeError("scrypt parallelization must be a positive integer.");
30
36
  }
31
- if (salt.byteLength < 16) {
37
+ if (!(salt instanceof Uint8Array) || salt.byteLength < 16) {
32
38
  throw new RangeError("scrypt salt must be at least 16 bytes.");
33
39
  }
40
+ if (maxMemory !== undefined &&
41
+ (!Number.isInteger(maxMemory) || maxMemory <= 0)) {
42
+ throw new RangeError("scrypt maxMemory must be a positive integer.");
43
+ }
34
44
  }
35
45
  //# sourceMappingURL=cryptoKeyDerivation.validate.js.map
@@ -1,10 +1,24 @@
1
- import type { PasswordHashParameters } from "./cryptoPassword.type.js";
1
+ import type { Pbkdf2Digest } from "../cryptoProvider/cryptoProvider.type.js";
2
+ import type { PasswordHashParameters, Pbkdf2PasswordAlgorithm } from "./cryptoPassword.type.js";
2
3
  /**
3
4
  * Current password hash encoding format version.
4
5
  */
5
6
  export declare const PASSWORD_FORMAT_VERSION = "v1";
7
+ /**
8
+ * Returns the PBKDF2 password algorithm label for a digest.
9
+ */
10
+ export declare function pbkdf2PasswordAlgorithm(digest: Pbkdf2Digest): Pbkdf2PasswordAlgorithm;
6
11
  /**
7
12
  * Decodes an encoded password hash into its parameters.
13
+ *
14
+ * Supported formats:
15
+ *
16
+ * - `v1$scrypt$<N>$<r>$<p>$<salt>.<hash>`
17
+ * - `v1$pbkdf2-<digest>$<iterations>$<salt>.<hash>`
18
+ *
19
+ * All binary fields are canonical Base64URL. Parameters are validated
20
+ * against `PASSWORD_HASH.LIMITS`, so a decoded hash is always safe to
21
+ * re-derive.
8
22
  */
9
23
  export declare function decodePasswordHash(encoded: string): PasswordHashParameters;
10
24
  /**
@@ -1,30 +1,145 @@
1
1
  import { CryptoAlgorithm } from "../cryptoConstants/cryptoConstants.type.js";
2
- import { decodeBase64Url, parsePositiveInteger, validateParameters, } from "./cryptoPassword.validate.js";
2
+ import { decodeBase64Url, parsePositiveInteger, validateParameters, validatePbkdf2Parameters, } from "./cryptoPassword.validate.js";
3
3
  /**
4
4
  * Current password hash encoding format version.
5
5
  */
6
6
  export const PASSWORD_FORMAT_VERSION = "v1";
7
+ const PBKDF2_ALGORITHMS = new Map([
8
+ [CryptoAlgorithm.PBKDF2_SHA256, "sha256"],
9
+ [CryptoAlgorithm.PBKDF2_SHA384, "sha384"],
10
+ [CryptoAlgorithm.PBKDF2_SHA512, "sha512"],
11
+ ]);
12
+ /**
13
+ * Returns the PBKDF2 password algorithm label for a digest.
14
+ */
15
+ export function pbkdf2PasswordAlgorithm(digest) {
16
+ switch (digest) {
17
+ case "sha256":
18
+ return CryptoAlgorithm.PBKDF2_SHA256;
19
+ case "sha384":
20
+ return CryptoAlgorithm.PBKDF2_SHA384;
21
+ case "sha512":
22
+ return CryptoAlgorithm.PBKDF2_SHA512;
23
+ default:
24
+ throw new TypeError(`Unsupported PBKDF2 digest: ${String(digest)}.`);
25
+ }
26
+ }
7
27
  /**
8
28
  * Decodes an encoded password hash into its parameters.
29
+ *
30
+ * Supported formats:
31
+ *
32
+ * - `v1$scrypt$<N>$<r>$<p>$<salt>.<hash>`
33
+ * - `v1$pbkdf2-<digest>$<iterations>$<salt>.<hash>`
34
+ *
35
+ * All binary fields are canonical Base64URL. Parameters are validated
36
+ * against `PASSWORD_HASH.LIMITS`, so a decoded hash is always safe to
37
+ * re-derive.
9
38
  */
10
39
  export function decodePasswordHash(encoded) {
11
40
  if (typeof encoded !== "string" || encoded.length === 0) {
12
41
  throw new TypeError("Password hash must be a non-empty string.");
13
42
  }
14
43
  const parts = encoded.split("$");
15
- if (parts.length !== 6) {
16
- throw new TypeError("Invalid password hash format.");
17
- }
18
- const [version, algorithm, costPart, blockSizePart, parallelizationPart, payload,] = parts;
44
+ const version = parts[0];
45
+ const algorithm = parts[1];
19
46
  if (version !== PASSWORD_FORMAT_VERSION) {
20
- throw new TypeError(`Unsupported password hash version: ${version}.`);
47
+ throw new TypeError(`Unsupported password hash version: ${String(version)}.`);
48
+ }
49
+ if (algorithm === CryptoAlgorithm.SCRYPT) {
50
+ if (parts.length !== 6) {
51
+ throw new TypeError("Invalid password hash format.");
52
+ }
53
+ const [, , costPart, blockSizePart, parallelizationPart, payload] = parts;
54
+ const cost = parsePositiveInteger(costPart, "cost");
55
+ const blockSize = parsePositiveInteger(blockSizePart, "blockSize");
56
+ const parallelization = parsePositiveInteger(parallelizationPart, "parallelization");
57
+ const { salt, hash } = decodePayload(payload);
58
+ validateParameters({
59
+ saltBytes: salt.byteLength,
60
+ keyBytes: hash.byteLength,
61
+ cost,
62
+ blockSize,
63
+ parallelization,
64
+ });
65
+ return Object.freeze({
66
+ version,
67
+ algorithm: CryptoAlgorithm.SCRYPT,
68
+ salt,
69
+ hash,
70
+ cost,
71
+ blockSize,
72
+ parallelization,
73
+ });
74
+ }
75
+ const digest = algorithm === undefined ? undefined : PBKDF2_ALGORITHMS.get(algorithm);
76
+ if (digest !== undefined) {
77
+ if (parts.length !== 4) {
78
+ throw new TypeError("Invalid password hash format.");
79
+ }
80
+ const [, , iterationsPart, payload] = parts;
81
+ const iterations = parsePositiveInteger(iterationsPart, "iterations");
82
+ const { salt, hash } = decodePayload(payload);
83
+ validatePbkdf2Parameters({
84
+ saltBytes: salt.byteLength,
85
+ keyBytes: hash.byteLength,
86
+ iterations,
87
+ });
88
+ return Object.freeze({
89
+ version,
90
+ algorithm: algorithm,
91
+ digest,
92
+ salt,
93
+ hash,
94
+ iterations,
95
+ });
96
+ }
97
+ throw new TypeError(`Unsupported password hash algorithm: ${String(algorithm)}.`);
98
+ }
99
+ /**
100
+ * Encodes password hashing parameters into a portable string.
101
+ */
102
+ export function encodePasswordHash(parameters) {
103
+ if (parameters.version !== PASSWORD_FORMAT_VERSION) {
104
+ throw new TypeError(`Unsupported password hash version: ${parameters.version}.`);
21
105
  }
22
- if (algorithm !== CryptoAlgorithm.SCRYPT) {
23
- throw new TypeError(`Unsupported password hash algorithm: ${algorithm}.`);
106
+ const payload = [
107
+ Buffer.from(parameters.salt).toString("base64url"),
108
+ Buffer.from(parameters.hash).toString("base64url"),
109
+ ].join(".");
110
+ if (parameters.algorithm === CryptoAlgorithm.SCRYPT) {
111
+ validateParameters({
112
+ saltBytes: parameters.salt.byteLength,
113
+ keyBytes: parameters.hash.byteLength,
114
+ cost: parameters.cost,
115
+ blockSize: parameters.blockSize,
116
+ parallelization: parameters.parallelization,
117
+ });
118
+ return [
119
+ parameters.version,
120
+ parameters.algorithm,
121
+ parameters.cost,
122
+ parameters.blockSize,
123
+ parameters.parallelization,
124
+ payload,
125
+ ].join("$");
24
126
  }
25
- const cost = parsePositiveInteger(costPart, "cost");
26
- const blockSize = parsePositiveInteger(blockSizePart, "blockSize");
27
- const parallelization = parsePositiveInteger(parallelizationPart, "parallelization");
127
+ if (PBKDF2_ALGORITHMS.has(parameters.algorithm)) {
128
+ validatePbkdf2Parameters({
129
+ saltBytes: parameters.salt.byteLength,
130
+ keyBytes: parameters.hash.byteLength,
131
+ iterations: parameters.iterations,
132
+ });
133
+ return [
134
+ parameters.version,
135
+ parameters.algorithm,
136
+ parameters.iterations,
137
+ payload,
138
+ ].join("$");
139
+ }
140
+ throw new TypeError(`Unsupported password hash algorithm: ${String(parameters.algorithm)}.`);
141
+ }
142
+ function decodePayload(payload) {
28
143
  const payloadParts = payload.split(".");
29
144
  if (payloadParts.length !== 2) {
30
145
  throw new TypeError("Invalid password hash payload.");
@@ -38,50 +153,6 @@ export function decodePasswordHash(encoded) {
38
153
  if (hash.byteLength === 0) {
39
154
  throw new TypeError("Password hash cannot be empty.");
40
155
  }
41
- validateParameters({
42
- saltBytes: salt.byteLength,
43
- keyBytes: hash.byteLength,
44
- cost,
45
- blockSize,
46
- parallelization,
47
- });
48
- return Object.freeze({
49
- version,
50
- algorithm: CryptoAlgorithm.SCRYPT,
51
- salt,
52
- hash,
53
- cost,
54
- blockSize,
55
- parallelization,
56
- });
57
- }
58
- /**
59
- * Encodes password hashing parameters into a portable string.
60
- */
61
- export function encodePasswordHash(parameters) {
62
- if (parameters.algorithm !== CryptoAlgorithm.SCRYPT) {
63
- throw new TypeError("Only scrypt password hashes are supported.");
64
- }
65
- validateParameters({
66
- saltBytes: parameters.salt.byteLength,
67
- keyBytes: parameters.hash.byteLength,
68
- cost: parameters.cost,
69
- blockSize: parameters.blockSize,
70
- parallelization: parameters.parallelization,
71
- });
72
- if (parameters.version !== PASSWORD_FORMAT_VERSION) {
73
- throw new TypeError(`Unsupported password hash version: ${parameters.version}.`);
74
- }
75
- return [
76
- parameters.version,
77
- parameters.algorithm,
78
- parameters.cost,
79
- parameters.blockSize,
80
- parameters.parallelization,
81
- [
82
- Buffer.from(parameters.salt).toString("base64url"),
83
- Buffer.from(parameters.hash).toString("base64url"),
84
- ].join("."),
85
- ].join("$");
156
+ return { salt, hash };
86
157
  }
87
158
  //# sourceMappingURL=cryptoPassword.codec.js.map