@ohos-ports/react-native-quick-crypto 0.0.0-stage → 1.1.8-beta.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 (1027) hide show
  1. package/QuickCrypto.podspec +259 -0
  2. package/README.md +170 -2
  3. package/android/CMakeLists.txt +155 -0
  4. package/android/build.gradle +176 -0
  5. package/android/gradle.properties +6 -0
  6. package/android/src/main/AndroidManifest.xml +3 -0
  7. package/android/src/main/cpp/cpp-adapter.cpp +8 -0
  8. package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +41 -0
  9. package/app.plugin.js +3 -0
  10. package/cpp/argon2/HybridArgon2.cpp +110 -0
  11. package/cpp/argon2/HybridArgon2.hpp +32 -0
  12. package/cpp/blake3/HybridBlake3.cpp +120 -0
  13. package/cpp/blake3/HybridBlake3.hpp +35 -0
  14. package/cpp/certificate/HybridCertificate.cpp +42 -0
  15. package/cpp/certificate/HybridCertificate.hpp +16 -0
  16. package/cpp/cipher/CCMCipher.cpp +211 -0
  17. package/cpp/cipher/CCMCipher.hpp +24 -0
  18. package/cpp/cipher/ChaCha20Cipher.cpp +91 -0
  19. package/cpp/cipher/ChaCha20Cipher.hpp +23 -0
  20. package/cpp/cipher/ChaCha20Poly1305Cipher.cpp +175 -0
  21. package/cpp/cipher/ChaCha20Poly1305Cipher.hpp +27 -0
  22. package/cpp/cipher/GCMCipher.cpp +65 -0
  23. package/cpp/cipher/GCMCipher.hpp +14 -0
  24. package/cpp/cipher/HybridCipher.cpp +403 -0
  25. package/cpp/cipher/HybridCipher.hpp +90 -0
  26. package/cpp/cipher/HybridCipherFactory.hpp +119 -0
  27. package/cpp/cipher/HybridRsaCipher.cpp +477 -0
  28. package/cpp/cipher/HybridRsaCipher.hpp +33 -0
  29. package/cpp/cipher/OCBCipher.cpp +55 -0
  30. package/cpp/cipher/OCBCipher.hpp +19 -0
  31. package/cpp/cipher/XChaCha20Poly1305Cipher.cpp +158 -0
  32. package/cpp/cipher/XChaCha20Poly1305Cipher.hpp +42 -0
  33. package/cpp/cipher/XSalsa20Cipher.cpp +127 -0
  34. package/cpp/cipher/XSalsa20Cipher.hpp +55 -0
  35. package/cpp/cipher/XSalsa20Poly1305Cipher.cpp +138 -0
  36. package/cpp/cipher/XSalsa20Poly1305Cipher.hpp +41 -0
  37. package/cpp/dh/HybridDhKeyPair.cpp +179 -0
  38. package/cpp/dh/HybridDhKeyPair.hpp +37 -0
  39. package/cpp/dh/HybridDiffieHellman.cpp +482 -0
  40. package/cpp/dh/HybridDiffieHellman.hpp +42 -0
  41. package/cpp/dsa/HybridDsaKeyPair.cpp +128 -0
  42. package/cpp/dsa/HybridDsaKeyPair.hpp +32 -0
  43. package/cpp/ec/HybridEcKeyPair.cpp +481 -0
  44. package/cpp/ec/HybridEcKeyPair.hpp +45 -0
  45. package/cpp/ecdh/HybridECDH.cpp +251 -0
  46. package/cpp/ecdh/HybridECDH.hpp +43 -0
  47. package/cpp/ed25519/HybridEdKeyPair.cpp +360 -0
  48. package/cpp/ed25519/HybridEdKeyPair.hpp +67 -0
  49. package/cpp/hash/HybridHash.cpp +190 -0
  50. package/cpp/hash/HybridHash.hpp +43 -0
  51. package/cpp/hkdf/HybridHkdf.cpp +115 -0
  52. package/cpp/hkdf/HybridHkdf.hpp +29 -0
  53. package/cpp/hmac/HybridHmac.cpp +102 -0
  54. package/cpp/hmac/HybridHmac.hpp +32 -0
  55. package/cpp/keys/HybridKeyObjectHandle.cpp +1519 -0
  56. package/cpp/keys/HybridKeyObjectHandle.hpp +78 -0
  57. package/cpp/keys/KeyObjectData.cpp +298 -0
  58. package/cpp/keys/KeyObjectData.hpp +73 -0
  59. package/cpp/keys/node.h +5 -0
  60. package/cpp/kmac/HybridKmac.cpp +83 -0
  61. package/cpp/kmac/HybridKmac.hpp +31 -0
  62. package/cpp/mldsa/HybridMlDsaKeyPair.cpp +243 -0
  63. package/cpp/mldsa/HybridMlDsaKeyPair.hpp +49 -0
  64. package/cpp/mlkem/HybridMlKemKeyPair.cpp +315 -0
  65. package/cpp/mlkem/HybridMlKemKeyPair.hpp +48 -0
  66. package/cpp/pbkdf2/HybridPbkdf2.cpp +50 -0
  67. package/cpp/pbkdf2/HybridPbkdf2.hpp +24 -0
  68. package/cpp/prime/HybridPrime.cpp +81 -0
  69. package/cpp/prime/HybridPrime.hpp +20 -0
  70. package/cpp/random/HybridRandom.cpp +48 -0
  71. package/cpp/random/HybridRandom.hpp +32 -0
  72. package/cpp/rsa/HybridRsaKeyPair.cpp +151 -0
  73. package/cpp/rsa/HybridRsaKeyPair.hpp +40 -0
  74. package/cpp/scrypt/HybridScrypt.cpp +64 -0
  75. package/cpp/scrypt/HybridScrypt.hpp +28 -0
  76. package/cpp/sign/HybridSignHandle.cpp +241 -0
  77. package/cpp/sign/HybridSignHandle.hpp +36 -0
  78. package/cpp/sign/HybridVerifyHandle.cpp +207 -0
  79. package/cpp/sign/HybridVerifyHandle.hpp +36 -0
  80. package/cpp/sign/SignUtils.hpp +91 -0
  81. package/cpp/slhdsa/HybridSlhDsaKeyPair.cpp +245 -0
  82. package/cpp/slhdsa/HybridSlhDsaKeyPair.hpp +48 -0
  83. package/cpp/turboshake/HybridTurboShake.cpp +379 -0
  84. package/cpp/turboshake/HybridTurboShake.hpp +28 -0
  85. package/cpp/utils/HybridUtils.cpp +399 -0
  86. package/cpp/utils/HybridUtils.hpp +28 -0
  87. package/cpp/utils/Macros.hpp +68 -0
  88. package/cpp/utils/QuickCryptoUtils.cpp +44 -0
  89. package/cpp/utils/QuickCryptoUtils.hpp +186 -0
  90. package/cpp/utils/base64.h +309 -0
  91. package/cpp/x509/HybridX509Certificate.cpp +174 -0
  92. package/cpp/x509/HybridX509Certificate.hpp +51 -0
  93. package/deps/blake3/LICENSE_A2 +202 -0
  94. package/deps/blake3/LICENSE_A2LLVM +219 -0
  95. package/deps/blake3/LICENSE_CC0 +121 -0
  96. package/deps/blake3/README.md +228 -0
  97. package/deps/blake3/c/README.md +403 -0
  98. package/deps/blake3/c/blake3.c +651 -0
  99. package/deps/blake3/c/blake3.h +86 -0
  100. package/deps/blake3/c/blake3_dispatch.c +332 -0
  101. package/deps/blake3/c/blake3_impl.h +333 -0
  102. package/deps/blake3/c/blake3_neon.c +367 -0
  103. package/deps/blake3/c/blake3_portable.c +160 -0
  104. package/deps/fastpbkdf2/fastpbkdf2.c +356 -0
  105. package/deps/fastpbkdf2/fastpbkdf2.h +68 -0
  106. package/deps/ncrypto/LICENSE +21 -0
  107. package/deps/ncrypto/README.md +18 -0
  108. package/deps/ncrypto/include/dh-primes.h +67 -0
  109. package/deps/ncrypto/include/ncrypto/aead.h +137 -0
  110. package/deps/ncrypto/include/ncrypto/version.h +14 -0
  111. package/deps/ncrypto/include/ncrypto.h +1759 -0
  112. package/deps/ncrypto/src/aead.cpp +302 -0
  113. package/deps/ncrypto/src/engine.cpp +93 -0
  114. package/deps/ncrypto/src/ncrypto.cpp +5426 -0
  115. package/deps/simdutf/LICENSE-APACHE +201 -0
  116. package/deps/simdutf/LICENSE-MIT +18 -0
  117. package/deps/simdutf/README.md +2782 -0
  118. package/deps/simdutf/include/simdutf/avx512.h +79 -0
  119. package/deps/simdutf/include/simdutf/base64_implementation.h +158 -0
  120. package/deps/simdutf/include/simdutf/base64_tables.h +887 -0
  121. package/deps/simdutf/include/simdutf/common_defs.h +186 -0
  122. package/deps/simdutf/include/simdutf/compiler_check.h +50 -0
  123. package/deps/simdutf/include/simdutf/constexpr_ptr.h +138 -0
  124. package/deps/simdutf/include/simdutf/encoding_types.h +189 -0
  125. package/deps/simdutf/include/simdutf/error.h +126 -0
  126. package/deps/simdutf/include/simdutf/implementation.h +7081 -0
  127. package/deps/simdutf/include/simdutf/internal/isadetection.h +325 -0
  128. package/deps/simdutf/include/simdutf/portability.h +285 -0
  129. package/deps/simdutf/include/simdutf/scalar/ascii.h +86 -0
  130. package/deps/simdutf/include/simdutf/scalar/atomic_util.h +105 -0
  131. package/deps/simdutf/include/simdutf/scalar/base64.h +911 -0
  132. package/deps/simdutf/include/simdutf/scalar/latin1.h +26 -0
  133. package/deps/simdutf/include/simdutf/scalar/latin1_to_utf16/latin1_to_utf16.h +52 -0
  134. package/deps/simdutf/include/simdutf/scalar/latin1_to_utf32/latin1_to_utf32.h +27 -0
  135. package/deps/simdutf/include/simdutf/scalar/latin1_to_utf8/latin1_to_utf8.h +191 -0
  136. package/deps/simdutf/include/simdutf/scalar/swap_bytes.h +35 -0
  137. package/deps/simdutf/include/simdutf/scalar/utf16.h +226 -0
  138. package/deps/simdutf/include/simdutf/scalar/utf16_to_latin1/utf16_to_latin1.h +108 -0
  139. package/deps/simdutf/include/simdutf/scalar/utf16_to_latin1/valid_utf16_to_latin1.h +40 -0
  140. package/deps/simdutf/include/simdutf/scalar/utf16_to_utf32/utf16_to_utf32.h +86 -0
  141. package/deps/simdutf/include/simdutf/scalar/utf16_to_utf32/valid_utf16_to_utf32.h +44 -0
  142. package/deps/simdutf/include/simdutf/scalar/utf16_to_utf8/utf16_to_utf8.h +295 -0
  143. package/deps/simdutf/include/simdutf/scalar/utf16_to_utf8/valid_utf16_to_utf8.h +91 -0
  144. package/deps/simdutf/include/simdutf/scalar/utf32.h +82 -0
  145. package/deps/simdutf/include/simdutf/scalar/utf32_to_latin1/utf32_to_latin1.h +68 -0
  146. package/deps/simdutf/include/simdutf/scalar/utf32_to_latin1/valid_utf32_to_latin1.h +67 -0
  147. package/deps/simdutf/include/simdutf/scalar/utf32_to_utf16/utf32_to_utf16.h +84 -0
  148. package/deps/simdutf/include/simdutf/scalar/utf32_to_utf16/valid_utf32_to_utf16.h +44 -0
  149. package/deps/simdutf/include/simdutf/scalar/utf32_to_utf8/utf32_to_utf8.h +142 -0
  150. package/deps/simdutf/include/simdutf/scalar/utf32_to_utf8/valid_utf32_to_utf8.h +72 -0
  151. package/deps/simdutf/include/simdutf/scalar/utf8.h +326 -0
  152. package/deps/simdutf/include/simdutf/scalar/utf8_to_latin1/utf8_to_latin1.h +225 -0
  153. package/deps/simdutf/include/simdutf/scalar/utf8_to_latin1/valid_utf8_to_latin1.h +87 -0
  154. package/deps/simdutf/include/simdutf/scalar/utf8_to_utf16/utf8_to_utf16.h +342 -0
  155. package/deps/simdutf/include/simdutf/scalar/utf8_to_utf16/valid_utf8_to_utf16.h +106 -0
  156. package/deps/simdutf/include/simdutf/scalar/utf8_to_utf32/utf8_to_utf32.h +299 -0
  157. package/deps/simdutf/include/simdutf/scalar/utf8_to_utf32/valid_utf8_to_utf32.h +83 -0
  158. package/deps/simdutf/include/simdutf/simdutf_version.h +26 -0
  159. package/deps/simdutf/include/simdutf.h +26 -0
  160. package/deps/simdutf/include/simdutf_c.h +342 -0
  161. package/deps/simdutf/src/arm64/arm_base64.cpp +791 -0
  162. package/deps/simdutf/src/arm64/arm_convert_latin1_to_utf16.cpp +24 -0
  163. package/deps/simdutf/src/arm64/arm_convert_latin1_to_utf32.cpp +24 -0
  164. package/deps/simdutf/src/arm64/arm_convert_latin1_to_utf8.cpp +70 -0
  165. package/deps/simdutf/src/arm64/arm_convert_utf16_to_latin1.cpp +61 -0
  166. package/deps/simdutf/src/arm64/arm_convert_utf16_to_utf32.cpp +185 -0
  167. package/deps/simdutf/src/arm64/arm_convert_utf16_to_utf8.cpp +780 -0
  168. package/deps/simdutf/src/arm64/arm_convert_utf32_to_latin1.cpp +60 -0
  169. package/deps/simdutf/src/arm64/arm_convert_utf32_to_utf16.cpp +208 -0
  170. package/deps/simdutf/src/arm64/arm_convert_utf32_to_utf8.cpp +505 -0
  171. package/deps/simdutf/src/arm64/arm_convert_utf8_to_latin1.cpp +69 -0
  172. package/deps/simdutf/src/arm64/arm_convert_utf8_to_utf16.cpp +313 -0
  173. package/deps/simdutf/src/arm64/arm_convert_utf8_to_utf32.cpp +179 -0
  174. package/deps/simdutf/src/arm64/arm_find.cpp +199 -0
  175. package/deps/simdutf/src/arm64/arm_utf16fix.cpp +185 -0
  176. package/deps/simdutf/src/arm64/arm_validate_utf16.cpp +165 -0
  177. package/deps/simdutf/src/arm64/arm_validate_utf32le.cpp +65 -0
  178. package/deps/simdutf/src/arm64/implementation.cpp +1442 -0
  179. package/deps/simdutf/src/encoding_types.cpp +67 -0
  180. package/deps/simdutf/src/error.cpp +3 -0
  181. package/deps/simdutf/src/fallback/implementation.cpp +589 -0
  182. package/deps/simdutf/src/generic/ascii_validation.h +50 -0
  183. package/deps/simdutf/src/generic/base64.h +233 -0
  184. package/deps/simdutf/src/generic/base64lengths.h +63 -0
  185. package/deps/simdutf/src/generic/buf_block_reader.h +109 -0
  186. package/deps/simdutf/src/generic/find.h +75 -0
  187. package/deps/simdutf/src/generic/utf16/change_endianness.h +24 -0
  188. package/deps/simdutf/src/generic/utf16/count_code_points_bytemask.h +58 -0
  189. package/deps/simdutf/src/generic/utf16/to_well_formed.h +93 -0
  190. package/deps/simdutf/src/generic/utf16/utf32_length_from_utf16.h +15 -0
  191. package/deps/simdutf/src/generic/utf16/utf8_length_from_utf16.h +35 -0
  192. package/deps/simdutf/src/generic/utf16/utf8_length_from_utf16_bytemask.h +199 -0
  193. package/deps/simdutf/src/generic/utf16.h +73 -0
  194. package/deps/simdutf/src/generic/utf32.h +136 -0
  195. package/deps/simdutf/src/generic/utf8/utf16_length_from_utf8_bytemask.h +53 -0
  196. package/deps/simdutf/src/generic/utf8.h +92 -0
  197. package/deps/simdutf/src/generic/utf8_to_latin1/utf8_to_latin1.h +316 -0
  198. package/deps/simdutf/src/generic/utf8_to_latin1/valid_utf8_to_latin1.h +78 -0
  199. package/deps/simdutf/src/generic/utf8_to_utf16/utf8_to_utf16.h +332 -0
  200. package/deps/simdutf/src/generic/utf8_to_utf16/valid_utf8_to_utf16.h +74 -0
  201. package/deps/simdutf/src/generic/utf8_to_utf32/utf8_to_utf32.h +318 -0
  202. package/deps/simdutf/src/generic/utf8_to_utf32/valid_utf8_to_utf32.h +42 -0
  203. package/deps/simdutf/src/generic/utf8_validation/utf8_lookup4_algorithm.h +223 -0
  204. package/deps/simdutf/src/generic/utf8_validation/utf8_validator.h +84 -0
  205. package/deps/simdutf/src/generic/validate_utf16.h +164 -0
  206. package/deps/simdutf/src/generic/validate_utf32.h +99 -0
  207. package/deps/simdutf/src/haswell/avx2_base64.cpp +837 -0
  208. package/deps/simdutf/src/haswell/avx2_convert_latin1_to_utf16.cpp +28 -0
  209. package/deps/simdutf/src/haswell/avx2_convert_latin1_to_utf32.cpp +20 -0
  210. package/deps/simdutf/src/haswell/avx2_convert_latin1_to_utf8.cpp +83 -0
  211. package/deps/simdutf/src/haswell/avx2_convert_utf16_to_latin1.cpp +83 -0
  212. package/deps/simdutf/src/haswell/avx2_convert_utf16_to_utf32.cpp +210 -0
  213. package/deps/simdutf/src/haswell/avx2_convert_utf16_to_utf8.cpp +602 -0
  214. package/deps/simdutf/src/haswell/avx2_convert_utf32_to_latin1.cpp +116 -0
  215. package/deps/simdutf/src/haswell/avx2_convert_utf32_to_utf16.cpp +164 -0
  216. package/deps/simdutf/src/haswell/avx2_convert_utf32_to_utf8.cpp +569 -0
  217. package/deps/simdutf/src/haswell/avx2_convert_utf8_to_latin1.cpp +60 -0
  218. package/deps/simdutf/src/haswell/avx2_convert_utf8_to_utf16.cpp +195 -0
  219. package/deps/simdutf/src/haswell/avx2_convert_utf8_to_utf32.cpp +135 -0
  220. package/deps/simdutf/src/haswell/avx2_utf16fix.cpp +173 -0
  221. package/deps/simdutf/src/haswell/avx2_validate_utf16.cpp +17 -0
  222. package/deps/simdutf/src/haswell/implementation.cpp +1447 -0
  223. package/deps/simdutf/src/icelake/icelake_ascii_validation.inl.cpp +19 -0
  224. package/deps/simdutf/src/icelake/icelake_base64.inl.cpp +630 -0
  225. package/deps/simdutf/src/icelake/icelake_common.inl.cpp +37 -0
  226. package/deps/simdutf/src/icelake/icelake_convert_latin1_to_utf16.inl.cpp +36 -0
  227. package/deps/simdutf/src/icelake/icelake_convert_latin1_to_utf32.inl.cpp +23 -0
  228. package/deps/simdutf/src/icelake/icelake_convert_latin1_to_utf8.inl.cpp +107 -0
  229. package/deps/simdutf/src/icelake/icelake_convert_utf16_to_latin1.inl.cpp +103 -0
  230. package/deps/simdutf/src/icelake/icelake_convert_utf16_to_utf32.inl.cpp +136 -0
  231. package/deps/simdutf/src/icelake/icelake_convert_utf16_to_utf8.inl.cpp +206 -0
  232. package/deps/simdutf/src/icelake/icelake_convert_utf32_to_latin1.inl.cpp +74 -0
  233. package/deps/simdutf/src/icelake/icelake_convert_utf32_to_utf16.inl.cpp +338 -0
  234. package/deps/simdutf/src/icelake/icelake_convert_utf32_to_utf8.inl.cpp +574 -0
  235. package/deps/simdutf/src/icelake/icelake_convert_utf8_to_latin1.inl.cpp +104 -0
  236. package/deps/simdutf/src/icelake/icelake_convert_utf8_to_utf16.inl.cpp +75 -0
  237. package/deps/simdutf/src/icelake/icelake_convert_valid_utf8_to_latin1.inl.cpp +69 -0
  238. package/deps/simdutf/src/icelake/icelake_find.inl.cpp +146 -0
  239. package/deps/simdutf/src/icelake/icelake_from_utf8.inl.cpp +266 -0
  240. package/deps/simdutf/src/icelake/icelake_from_valid_utf8.inl.cpp +136 -0
  241. package/deps/simdutf/src/icelake/icelake_macros.inl.cpp +143 -0
  242. package/deps/simdutf/src/icelake/icelake_utf16fix.cpp +138 -0
  243. package/deps/simdutf/src/icelake/icelake_utf32_validation.inl.cpp +63 -0
  244. package/deps/simdutf/src/icelake/icelake_utf8_common.inl.cpp +753 -0
  245. package/deps/simdutf/src/icelake/icelake_utf8_length_from_utf16.inl.cpp +269 -0
  246. package/deps/simdutf/src/icelake/icelake_utf8_validation.inl.cpp +116 -0
  247. package/deps/simdutf/src/icelake/implementation.cpp +1903 -0
  248. package/deps/simdutf/src/implementation.cpp +2526 -0
  249. package/deps/simdutf/src/lasx/implementation.cpp +1531 -0
  250. package/deps/simdutf/src/lasx/lasx_base64.cpp +695 -0
  251. package/deps/simdutf/src/lasx/lasx_convert_latin1_to_utf16.cpp +76 -0
  252. package/deps/simdutf/src/lasx/lasx_convert_latin1_to_utf32.cpp +55 -0
  253. package/deps/simdutf/src/lasx/lasx_convert_latin1_to_utf8.cpp +65 -0
  254. package/deps/simdutf/src/lasx/lasx_convert_utf16_to_latin1.cpp +64 -0
  255. package/deps/simdutf/src/lasx/lasx_convert_utf16_to_utf32.cpp +183 -0
  256. package/deps/simdutf/src/lasx/lasx_convert_utf16_to_utf8.cpp +550 -0
  257. package/deps/simdutf/src/lasx/lasx_convert_utf32_to_latin1.cpp +73 -0
  258. package/deps/simdutf/src/lasx/lasx_convert_utf32_to_utf16.cpp +218 -0
  259. package/deps/simdutf/src/lasx/lasx_convert_utf32_to_utf8.cpp +589 -0
  260. package/deps/simdutf/src/lasx/lasx_convert_utf8_to_latin1.cpp +72 -0
  261. package/deps/simdutf/src/lasx/lasx_convert_utf8_to_utf16.cpp +296 -0
  262. package/deps/simdutf/src/lasx/lasx_convert_utf8_to_utf32.cpp +190 -0
  263. package/deps/simdutf/src/lasx/lasx_find.cpp +64 -0
  264. package/deps/simdutf/src/lasx/lasx_validate_utf16.cpp +13 -0
  265. package/deps/simdutf/src/lasx/lasx_validate_utf32le.cpp +84 -0
  266. package/deps/simdutf/src/lsx/implementation.cpp +1417 -0
  267. package/deps/simdutf/src/lsx/lsx_base64.cpp +675 -0
  268. package/deps/simdutf/src/lsx/lsx_convert_latin1_to_utf16.cpp +39 -0
  269. package/deps/simdutf/src/lsx/lsx_convert_latin1_to_utf32.cpp +27 -0
  270. package/deps/simdutf/src/lsx/lsx_convert_latin1_to_utf8.cpp +56 -0
  271. package/deps/simdutf/src/lsx/lsx_convert_utf16_to_latin1.cpp +64 -0
  272. package/deps/simdutf/src/lsx/lsx_convert_utf16_to_utf32.cpp +133 -0
  273. package/deps/simdutf/src/lsx/lsx_convert_utf16_to_utf8.cpp +518 -0
  274. package/deps/simdutf/src/lsx/lsx_convert_utf32_to_latin1.cpp +66 -0
  275. package/deps/simdutf/src/lsx/lsx_convert_utf32_to_utf16.cpp +155 -0
  276. package/deps/simdutf/src/lsx/lsx_convert_utf32_to_utf8.cpp +459 -0
  277. package/deps/simdutf/src/lsx/lsx_convert_utf8_to_latin1.cpp +75 -0
  278. package/deps/simdutf/src/lsx/lsx_convert_utf8_to_utf16.cpp +291 -0
  279. package/deps/simdutf/src/lsx/lsx_convert_utf8_to_utf32.cpp +179 -0
  280. package/deps/simdutf/src/lsx/lsx_find.cpp +60 -0
  281. package/deps/simdutf/src/lsx/lsx_validate_utf16.cpp +13 -0
  282. package/deps/simdutf/src/lsx/lsx_validate_utf32le.cpp +68 -0
  283. package/deps/simdutf/src/ppc64/implementation.cpp +992 -0
  284. package/deps/simdutf/src/ppc64/ppc64_base64.cpp +480 -0
  285. package/deps/simdutf/src/ppc64/ppc64_base64_internal_tests.cpp +401 -0
  286. package/deps/simdutf/src/ppc64/ppc64_convert_latin1_to_utf16.cpp +12 -0
  287. package/deps/simdutf/src/ppc64/ppc64_convert_latin1_to_utf32.cpp +12 -0
  288. package/deps/simdutf/src/ppc64/ppc64_convert_latin1_to_utf8.cpp +149 -0
  289. package/deps/simdutf/src/ppc64/ppc64_convert_utf16_to_latin1.cpp +67 -0
  290. package/deps/simdutf/src/ppc64/ppc64_convert_utf16_to_utf32.cpp +87 -0
  291. package/deps/simdutf/src/ppc64/ppc64_convert_utf16_to_utf8.cpp +296 -0
  292. package/deps/simdutf/src/ppc64/ppc64_convert_utf32_to_latin1.cpp +57 -0
  293. package/deps/simdutf/src/ppc64/ppc64_convert_utf32_to_utf16.cpp +117 -0
  294. package/deps/simdutf/src/ppc64/ppc64_convert_utf32_to_utf8.cpp +166 -0
  295. package/deps/simdutf/src/ppc64/ppc64_convert_utf8_to_latin1.cpp +69 -0
  296. package/deps/simdutf/src/ppc64/ppc64_convert_utf8_to_utf16.cpp +211 -0
  297. package/deps/simdutf/src/ppc64/ppc64_convert_utf8_to_utf32.cpp +153 -0
  298. package/deps/simdutf/src/ppc64/ppc64_utf16_to_utf8_tables.h +1011 -0
  299. package/deps/simdutf/src/ppc64/ppc64_utf8_length_from_latin1.cpp +37 -0
  300. package/deps/simdutf/src/ppc64/ppc64_validate_utf16.cpp +19 -0
  301. package/deps/simdutf/src/ppc64/templates.cpp +91 -0
  302. package/deps/simdutf/src/rvv/implementation.cpp +138 -0
  303. package/deps/simdutf/src/rvv/rvv_find.cpp +27 -0
  304. package/deps/simdutf/src/rvv/rvv_helpers.inl.cpp +23 -0
  305. package/deps/simdutf/src/rvv/rvv_latin1_to.inl.cpp +71 -0
  306. package/deps/simdutf/src/rvv/rvv_length_from.inl.cpp +164 -0
  307. package/deps/simdutf/src/rvv/rvv_utf16_to.inl.cpp +399 -0
  308. package/deps/simdutf/src/rvv/rvv_utf16fix.cpp +110 -0
  309. package/deps/simdutf/src/rvv/rvv_utf32_to.inl.cpp +307 -0
  310. package/deps/simdutf/src/rvv/rvv_utf8_to.inl.cpp +435 -0
  311. package/deps/simdutf/src/rvv/rvv_validate.inl.cpp +275 -0
  312. package/deps/simdutf/src/simdutf/arm64/begin.h +2 -0
  313. package/deps/simdutf/src/simdutf/arm64/bitmanipulation.h +34 -0
  314. package/deps/simdutf/src/simdutf/arm64/end.h +2 -0
  315. package/deps/simdutf/src/simdutf/arm64/implementation.h +307 -0
  316. package/deps/simdutf/src/simdutf/arm64/intrinsics.h +10 -0
  317. package/deps/simdutf/src/simdutf/arm64/simd.h +547 -0
  318. package/deps/simdutf/src/simdutf/arm64/simd16-inl.h +403 -0
  319. package/deps/simdutf/src/simdutf/arm64/simd32-inl.h +129 -0
  320. package/deps/simdutf/src/simdutf/arm64/simd64-inl.h +28 -0
  321. package/deps/simdutf/src/simdutf/arm64.h +43 -0
  322. package/deps/simdutf/src/simdutf/fallback/begin.h +1 -0
  323. package/deps/simdutf/src/simdutf/fallback/bitmanipulation.h +13 -0
  324. package/deps/simdutf/src/simdutf/fallback/end.h +1 -0
  325. package/deps/simdutf/src/simdutf/fallback/implementation.h +331 -0
  326. package/deps/simdutf/src/simdutf/fallback.h +42 -0
  327. package/deps/simdutf/src/simdutf/haswell/begin.h +15 -0
  328. package/deps/simdutf/src/simdutf/haswell/bitmanipulation.h +35 -0
  329. package/deps/simdutf/src/simdutf/haswell/end.h +13 -0
  330. package/deps/simdutf/src/simdutf/haswell/implementation.h +338 -0
  331. package/deps/simdutf/src/simdutf/haswell/intrinsics.h +67 -0
  332. package/deps/simdutf/src/simdutf/haswell/simd.h +363 -0
  333. package/deps/simdutf/src/simdutf/haswell/simd16-inl.h +261 -0
  334. package/deps/simdutf/src/simdutf/haswell/simd32-inl.h +111 -0
  335. package/deps/simdutf/src/simdutf/haswell/simd64-inl.h +34 -0
  336. package/deps/simdutf/src/simdutf/haswell.h +63 -0
  337. package/deps/simdutf/src/simdutf/icelake/begin.h +14 -0
  338. package/deps/simdutf/src/simdutf/icelake/bitmanipulation.h +44 -0
  339. package/deps/simdutf/src/simdutf/icelake/end.h +12 -0
  340. package/deps/simdutf/src/simdutf/icelake/implementation.h +346 -0
  341. package/deps/simdutf/src/simdutf/icelake/intrinsics.h +138 -0
  342. package/deps/simdutf/src/simdutf/icelake/simd.h +17 -0
  343. package/deps/simdutf/src/simdutf/icelake/simd16-inl.h +90 -0
  344. package/deps/simdutf/src/simdutf/icelake/simd32-inl.h +47 -0
  345. package/deps/simdutf/src/simdutf/icelake.h +81 -0
  346. package/deps/simdutf/src/simdutf/lasx/begin.h +8 -0
  347. package/deps/simdutf/src/simdutf/lasx/bitmanipulation.h +25 -0
  348. package/deps/simdutf/src/simdutf/lasx/end.h +8 -0
  349. package/deps/simdutf/src/simdutf/lasx/implementation.h +310 -0
  350. package/deps/simdutf/src/simdutf/lasx/intrinsics.h +319 -0
  351. package/deps/simdutf/src/simdutf/lasx/simd.h +551 -0
  352. package/deps/simdutf/src/simdutf/lasx/simd16-inl.h +234 -0
  353. package/deps/simdutf/src/simdutf/lasx/simd32-inl.h +74 -0
  354. package/deps/simdutf/src/simdutf/lasx/simd64-inl.h +52 -0
  355. package/deps/simdutf/src/simdutf/lasx.h +49 -0
  356. package/deps/simdutf/src/simdutf/lsx/begin.h +2 -0
  357. package/deps/simdutf/src/simdutf/lsx/bitmanipulation.h +25 -0
  358. package/deps/simdutf/src/simdutf/lsx/end.h +2 -0
  359. package/deps/simdutf/src/simdutf/lsx/implementation.h +309 -0
  360. package/deps/simdutf/src/simdutf/lsx/intrinsics.h +196 -0
  361. package/deps/simdutf/src/simdutf/lsx/simd.h +421 -0
  362. package/deps/simdutf/src/simdutf/lsx/simd16-inl.h +242 -0
  363. package/deps/simdutf/src/simdutf/lsx/simd32-inl.h +69 -0
  364. package/deps/simdutf/src/simdutf/lsx/simd64-inl.h +50 -0
  365. package/deps/simdutf/src/simdutf/lsx.h +52 -0
  366. package/deps/simdutf/src/simdutf/ppc64/begin.h +1 -0
  367. package/deps/simdutf/src/simdutf/ppc64/bitmanipulation.h +29 -0
  368. package/deps/simdutf/src/simdutf/ppc64/end.h +1 -0
  369. package/deps/simdutf/src/simdutf/ppc64/implementation.h +348 -0
  370. package/deps/simdutf/src/simdutf/ppc64/intrinsics.h +19 -0
  371. package/deps/simdutf/src/simdutf/ppc64/simd.h +177 -0
  372. package/deps/simdutf/src/simdutf/ppc64/simd16-inl.h +327 -0
  373. package/deps/simdutf/src/simdutf/ppc64/simd32-inl.h +247 -0
  374. package/deps/simdutf/src/simdutf/ppc64/simd8-inl.h +618 -0
  375. package/deps/simdutf/src/simdutf/ppc64.h +40 -0
  376. package/deps/simdutf/src/simdutf/rvv/begin.h +7 -0
  377. package/deps/simdutf/src/simdutf/rvv/end.h +7 -0
  378. package/deps/simdutf/src/simdutf/rvv/implementation.h +321 -0
  379. package/deps/simdutf/src/simdutf/rvv/intrinsics.h +131 -0
  380. package/deps/simdutf/src/simdutf/rvv.h +41 -0
  381. package/deps/simdutf/src/simdutf/westmere/begin.h +8 -0
  382. package/deps/simdutf/src/simdutf/westmere/bitmanipulation.h +37 -0
  383. package/deps/simdutf/src/simdutf/westmere/end.h +8 -0
  384. package/deps/simdutf/src/simdutf/westmere/implementation.h +338 -0
  385. package/deps/simdutf/src/simdutf/westmere/intrinsics.h +38 -0
  386. package/deps/simdutf/src/simdutf/westmere/simd.h +379 -0
  387. package/deps/simdutf/src/simdutf/westmere/simd16-inl.h +242 -0
  388. package/deps/simdutf/src/simdutf/westmere/simd32-inl.h +151 -0
  389. package/deps/simdutf/src/simdutf/westmere/simd64-inl.h +33 -0
  390. package/deps/simdutf/src/simdutf/westmere.h +59 -0
  391. package/deps/simdutf/src/simdutf.cpp +152 -0
  392. package/deps/simdutf/src/simdutf_c.cpp +525 -0
  393. package/deps/simdutf/src/tables/utf16_to_utf8_tables.h +768 -0
  394. package/deps/simdutf/src/tables/utf32_to_utf16_tables.h +53 -0
  395. package/deps/simdutf/src/tables/utf8_to_utf16_tables.h +826 -0
  396. package/deps/simdutf/src/westmere/implementation.cpp +1479 -0
  397. package/deps/simdutf/src/westmere/internal/loader.cpp +7 -0
  398. package/deps/simdutf/src/westmere/internal/write_v_u16_11bits_to_utf8.cpp +66 -0
  399. package/deps/simdutf/src/westmere/sse_base64.cpp +672 -0
  400. package/deps/simdutf/src/westmere/sse_convert_latin1_to_utf16.cpp +21 -0
  401. package/deps/simdutf/src/westmere/sse_convert_latin1_to_utf32.cpp +31 -0
  402. package/deps/simdutf/src/westmere/sse_convert_latin1_to_utf8.cpp +71 -0
  403. package/deps/simdutf/src/westmere/sse_convert_utf16_to_latin1.cpp +70 -0
  404. package/deps/simdutf/src/westmere/sse_convert_utf16_to_utf32.cpp +206 -0
  405. package/deps/simdutf/src/westmere/sse_convert_utf16_to_utf8.cpp +504 -0
  406. package/deps/simdutf/src/westmere/sse_convert_utf32_to_latin1.cpp +82 -0
  407. package/deps/simdutf/src/westmere/sse_convert_utf32_to_utf16.cpp +209 -0
  408. package/deps/simdutf/src/westmere/sse_convert_utf32_to_utf8.cpp +589 -0
  409. package/deps/simdutf/src/westmere/sse_convert_utf8_to_latin1.cpp +58 -0
  410. package/deps/simdutf/src/westmere/sse_convert_utf8_to_utf16.cpp +197 -0
  411. package/deps/simdutf/src/westmere/sse_convert_utf8_to_utf32.cpp +141 -0
  412. package/deps/simdutf/src/westmere/sse_utf16fix.cpp +82 -0
  413. package/deps/simdutf/src/westmere/sse_validate_utf16.cpp +17 -0
  414. package/jest/index.js +16 -0
  415. package/lib/commonjs/argon2.js +88 -0
  416. package/lib/commonjs/argon2.js.map +1 -0
  417. package/lib/commonjs/blake3.js +99 -0
  418. package/lib/commonjs/blake3.js.map +1 -0
  419. package/lib/commonjs/certificate.js +35 -0
  420. package/lib/commonjs/certificate.js.map +1 -0
  421. package/lib/commonjs/cipher.js +299 -0
  422. package/lib/commonjs/cipher.js.map +1 -0
  423. package/lib/commonjs/constants.js +32 -0
  424. package/lib/commonjs/constants.js.map +1 -0
  425. package/lib/commonjs/dh-groups.js +29 -0
  426. package/lib/commonjs/dh-groups.js.map +1 -0
  427. package/lib/commonjs/dhKeyPair.js +112 -0
  428. package/lib/commonjs/dhKeyPair.js.map +1 -0
  429. package/lib/commonjs/diffie-hellman.js +151 -0
  430. package/lib/commonjs/diffie-hellman.js.map +1 -0
  431. package/lib/commonjs/dsa.js +101 -0
  432. package/lib/commonjs/dsa.js.map +1 -0
  433. package/lib/commonjs/ec.js +370 -0
  434. package/lib/commonjs/ec.js.map +1 -0
  435. package/lib/commonjs/ecdh.js +109 -0
  436. package/lib/commonjs/ecdh.js.map +1 -0
  437. package/lib/commonjs/ed.js +443 -0
  438. package/lib/commonjs/ed.js.map +1 -0
  439. package/lib/commonjs/expo-plugin/@types.js +2 -0
  440. package/lib/commonjs/expo-plugin/@types.js.map +1 -0
  441. package/lib/commonjs/expo-plugin/withRNQC.js +25 -0
  442. package/lib/commonjs/expo-plugin/withRNQC.js.map +1 -0
  443. package/lib/commonjs/expo-plugin/withSodiumAndroid.js +25 -0
  444. package/lib/commonjs/expo-plugin/withSodiumAndroid.js.map +1 -0
  445. package/lib/commonjs/expo-plugin/withSodiumIos.js +23 -0
  446. package/lib/commonjs/expo-plugin/withSodiumIos.js.map +1 -0
  447. package/lib/commonjs/expo-plugin/withXCode.js +109 -0
  448. package/lib/commonjs/expo-plugin/withXCode.js.map +1 -0
  449. package/lib/commonjs/hash.js +291 -0
  450. package/lib/commonjs/hash.js.map +1 -0
  451. package/lib/commonjs/hkdf.js +178 -0
  452. package/lib/commonjs/hkdf.js.map +1 -0
  453. package/lib/commonjs/hmac.js +125 -0
  454. package/lib/commonjs/hmac.js.map +1 -0
  455. package/lib/commonjs/index.js +356 -0
  456. package/lib/commonjs/index.js.map +1 -0
  457. package/lib/commonjs/keys/classes.js +280 -0
  458. package/lib/commonjs/keys/classes.js.map +1 -0
  459. package/lib/commonjs/keys/generateKeyPair.js +237 -0
  460. package/lib/commonjs/keys/generateKeyPair.js.map +1 -0
  461. package/lib/commonjs/keys/index.js +381 -0
  462. package/lib/commonjs/keys/index.js.map +1 -0
  463. package/lib/commonjs/keys/publicCipher.js +171 -0
  464. package/lib/commonjs/keys/publicCipher.js.map +1 -0
  465. package/lib/commonjs/keys/signVerify.js +227 -0
  466. package/lib/commonjs/keys/signVerify.js.map +1 -0
  467. package/lib/commonjs/keys/utils.js +181 -0
  468. package/lib/commonjs/keys/utils.js.map +1 -0
  469. package/lib/commonjs/mldsa.js +69 -0
  470. package/lib/commonjs/mldsa.js.map +1 -0
  471. package/lib/commonjs/mlkem.js +219 -0
  472. package/lib/commonjs/mlkem.js.map +1 -0
  473. package/lib/commonjs/native-nitro-bridge.js +344 -0
  474. package/lib/commonjs/nitro-node-shim.js +23 -0
  475. package/lib/commonjs/package.json +1 -0
  476. package/lib/commonjs/pbkdf2.js +106 -0
  477. package/lib/commonjs/pbkdf2.js.map +1 -0
  478. package/lib/commonjs/prime.js +84 -0
  479. package/lib/commonjs/prime.js.map +1 -0
  480. package/lib/commonjs/random.js +296 -0
  481. package/lib/commonjs/random.js.map +1 -0
  482. package/lib/commonjs/rsa.js +213 -0
  483. package/lib/commonjs/rsa.js.map +1 -0
  484. package/lib/commonjs/scrypt.js +139 -0
  485. package/lib/commonjs/scrypt.js.map +1 -0
  486. package/lib/commonjs/slhdsa.js +70 -0
  487. package/lib/commonjs/slhdsa.js.map +1 -0
  488. package/lib/commonjs/specs/argon2.nitro.js +6 -0
  489. package/lib/commonjs/specs/argon2.nitro.js.map +1 -0
  490. package/lib/commonjs/specs/blake3.nitro.js +6 -0
  491. package/lib/commonjs/specs/blake3.nitro.js.map +1 -0
  492. package/lib/commonjs/specs/certificate.nitro.js +6 -0
  493. package/lib/commonjs/specs/certificate.nitro.js.map +1 -0
  494. package/lib/commonjs/specs/cipher.nitro.js +6 -0
  495. package/lib/commonjs/specs/cipher.nitro.js.map +1 -0
  496. package/lib/commonjs/specs/dhKeyPair.nitro.js +6 -0
  497. package/lib/commonjs/specs/dhKeyPair.nitro.js.map +1 -0
  498. package/lib/commonjs/specs/diffie-hellman.nitro.js +6 -0
  499. package/lib/commonjs/specs/diffie-hellman.nitro.js.map +1 -0
  500. package/lib/commonjs/specs/dsaKeyPair.nitro.js +6 -0
  501. package/lib/commonjs/specs/dsaKeyPair.nitro.js.map +1 -0
  502. package/lib/commonjs/specs/ecKeyPair.nitro.js +6 -0
  503. package/lib/commonjs/specs/ecKeyPair.nitro.js.map +1 -0
  504. package/lib/commonjs/specs/ecdh.nitro.js +6 -0
  505. package/lib/commonjs/specs/ecdh.nitro.js.map +1 -0
  506. package/lib/commonjs/specs/edKeyPair.nitro.js +6 -0
  507. package/lib/commonjs/specs/edKeyPair.nitro.js.map +1 -0
  508. package/lib/commonjs/specs/hash.nitro.js +6 -0
  509. package/lib/commonjs/specs/hash.nitro.js.map +1 -0
  510. package/lib/commonjs/specs/hkdf.nitro.js +6 -0
  511. package/lib/commonjs/specs/hkdf.nitro.js.map +1 -0
  512. package/lib/commonjs/specs/hmac.nitro.js +6 -0
  513. package/lib/commonjs/specs/hmac.nitro.js.map +1 -0
  514. package/lib/commonjs/specs/keyObjectHandle.nitro.js +6 -0
  515. package/lib/commonjs/specs/keyObjectHandle.nitro.js.map +1 -0
  516. package/lib/commonjs/specs/kmac.nitro.js +6 -0
  517. package/lib/commonjs/specs/kmac.nitro.js.map +1 -0
  518. package/lib/commonjs/specs/mlDsaKeyPair.nitro.js +6 -0
  519. package/lib/commonjs/specs/mlDsaKeyPair.nitro.js.map +1 -0
  520. package/lib/commonjs/specs/mlKemKeyPair.nitro.js +6 -0
  521. package/lib/commonjs/specs/mlKemKeyPair.nitro.js.map +1 -0
  522. package/lib/commonjs/specs/pbkdf2.nitro.js +6 -0
  523. package/lib/commonjs/specs/pbkdf2.nitro.js.map +1 -0
  524. package/lib/commonjs/specs/prime.nitro.js +6 -0
  525. package/lib/commonjs/specs/prime.nitro.js.map +1 -0
  526. package/lib/commonjs/specs/random.nitro.js +6 -0
  527. package/lib/commonjs/specs/random.nitro.js.map +1 -0
  528. package/lib/commonjs/specs/rsaCipher.nitro.js +6 -0
  529. package/lib/commonjs/specs/rsaCipher.nitro.js.map +1 -0
  530. package/lib/commonjs/specs/rsaKeyPair.nitro.js +6 -0
  531. package/lib/commonjs/specs/rsaKeyPair.nitro.js.map +1 -0
  532. package/lib/commonjs/specs/scrypt.nitro.js +6 -0
  533. package/lib/commonjs/specs/scrypt.nitro.js.map +1 -0
  534. package/lib/commonjs/specs/sign.nitro.js +6 -0
  535. package/lib/commonjs/specs/sign.nitro.js.map +1 -0
  536. package/lib/commonjs/specs/slhDsaKeyPair.nitro.js +6 -0
  537. package/lib/commonjs/specs/slhDsaKeyPair.nitro.js.map +1 -0
  538. package/lib/commonjs/specs/turboshake.nitro.js +6 -0
  539. package/lib/commonjs/specs/turboshake.nitro.js.map +1 -0
  540. package/lib/commonjs/specs/utils.nitro.js +6 -0
  541. package/lib/commonjs/specs/utils.nitro.js.map +1 -0
  542. package/lib/commonjs/specs/x509certificate.nitro.js +6 -0
  543. package/lib/commonjs/specs/x509certificate.nitro.js.map +1 -0
  544. package/lib/commonjs/subtle.js +3211 -0
  545. package/lib/commonjs/subtle.js.map +1 -0
  546. package/lib/commonjs/utils/cipher.js +75 -0
  547. package/lib/commonjs/utils/cipher.js.map +1 -0
  548. package/lib/commonjs/utils/conversion.js +249 -0
  549. package/lib/commonjs/utils/conversion.js.map +1 -0
  550. package/lib/commonjs/utils/errors.js +73 -0
  551. package/lib/commonjs/utils/errors.js.map +1 -0
  552. package/lib/commonjs/utils/hashnames.js +122 -0
  553. package/lib/commonjs/utils/hashnames.js.map +1 -0
  554. package/lib/commonjs/utils/index.js +83 -0
  555. package/lib/commonjs/utils/index.js.map +1 -0
  556. package/lib/commonjs/utils/noble.js +82 -0
  557. package/lib/commonjs/utils/noble.js.map +1 -0
  558. package/lib/commonjs/utils/timingSafeEqual.js +29 -0
  559. package/lib/commonjs/utils/timingSafeEqual.js.map +1 -0
  560. package/lib/commonjs/utils/types.js +55 -0
  561. package/lib/commonjs/utils/types.js.map +1 -0
  562. package/lib/commonjs/utils/validation.js +144 -0
  563. package/lib/commonjs/utils/validation.js.map +1 -0
  564. package/lib/commonjs/x509certificate.js +189 -0
  565. package/lib/commonjs/x509certificate.js.map +1 -0
  566. package/lib/module/argon2.js +83 -0
  567. package/lib/module/argon2.js.map +1 -0
  568. package/lib/module/blake3.js +91 -0
  569. package/lib/module/blake3.js.map +1 -0
  570. package/lib/module/certificate.js +30 -0
  571. package/lib/module/certificate.js.map +1 -0
  572. package/lib/module/cipher.js +291 -0
  573. package/lib/module/cipher.js.map +1 -0
  574. package/lib/module/constants.js +28 -0
  575. package/lib/module/constants.js.map +1 -0
  576. package/lib/module/dh-groups.js +25 -0
  577. package/lib/module/dh-groups.js.map +1 -0
  578. package/lib/module/dhKeyPair.js +105 -0
  579. package/lib/module/dhKeyPair.js.map +1 -0
  580. package/lib/module/diffie-hellman.js +145 -0
  581. package/lib/module/diffie-hellman.js.map +1 -0
  582. package/lib/module/dsa.js +94 -0
  583. package/lib/module/dsa.js.map +1 -0
  584. package/lib/module/ec.js +358 -0
  585. package/lib/module/ec.js.map +1 -0
  586. package/lib/module/ecdh.js +103 -0
  587. package/lib/module/ecdh.js.map +1 -0
  588. package/lib/module/ed.js +433 -0
  589. package/lib/module/ed.js.map +1 -0
  590. package/lib/module/expo-plugin/@types.js +2 -0
  591. package/lib/module/expo-plugin/@types.js.map +1 -0
  592. package/lib/module/expo-plugin/withRNQC.js +21 -0
  593. package/lib/module/expo-plugin/withRNQC.js.map +1 -0
  594. package/lib/module/expo-plugin/withSodiumAndroid.js +20 -0
  595. package/lib/module/expo-plugin/withSodiumAndroid.js.map +1 -0
  596. package/lib/module/expo-plugin/withSodiumIos.js +17 -0
  597. package/lib/module/expo-plugin/withSodiumIos.js.map +1 -0
  598. package/lib/module/expo-plugin/withXCode.js +101 -0
  599. package/lib/module/expo-plugin/withXCode.js.map +1 -0
  600. package/lib/module/hash.js +282 -0
  601. package/lib/module/hash.js.map +1 -0
  602. package/lib/module/hkdf.js +168 -0
  603. package/lib/module/hkdf.js.map +1 -0
  604. package/lib/module/hmac.js +120 -0
  605. package/lib/module/hmac.js.map +1 -0
  606. package/lib/module/index.js +115 -0
  607. package/lib/module/index.js.map +1 -0
  608. package/lib/module/keys/classes.js +271 -0
  609. package/lib/module/keys/classes.js.map +1 -0
  610. package/lib/module/keys/generateKeyPair.js +231 -0
  611. package/lib/module/keys/generateKeyPair.js.map +1 -0
  612. package/lib/module/keys/index.js +246 -0
  613. package/lib/module/keys/index.js.map +1 -0
  614. package/lib/module/keys/publicCipher.js +164 -0
  615. package/lib/module/keys/publicCipher.js.map +1 -0
  616. package/lib/module/keys/signVerify.js +217 -0
  617. package/lib/module/keys/signVerify.js.map +1 -0
  618. package/lib/module/keys/utils.js +170 -0
  619. package/lib/module/keys/utils.js.map +1 -0
  620. package/lib/module/mldsa.js +63 -0
  621. package/lib/module/mldsa.js.map +1 -0
  622. package/lib/module/mlkem.js +211 -0
  623. package/lib/module/mlkem.js.map +1 -0
  624. package/lib/module/pbkdf2.js +100 -0
  625. package/lib/module/pbkdf2.js.map +1 -0
  626. package/lib/module/prime.js +77 -0
  627. package/lib/module/prime.js.map +1 -0
  628. package/lib/module/random.js +284 -0
  629. package/lib/module/random.js.map +1 -0
  630. package/lib/module/rsa.js +205 -0
  631. package/lib/module/rsa.js.map +1 -0
  632. package/lib/module/scrypt.js +134 -0
  633. package/lib/module/scrypt.js.map +1 -0
  634. package/lib/module/slhdsa.js +64 -0
  635. package/lib/module/slhdsa.js.map +1 -0
  636. package/lib/module/specs/argon2.nitro.js +4 -0
  637. package/lib/module/specs/argon2.nitro.js.map +1 -0
  638. package/lib/module/specs/blake3.nitro.js +4 -0
  639. package/lib/module/specs/blake3.nitro.js.map +1 -0
  640. package/lib/module/specs/certificate.nitro.js +4 -0
  641. package/lib/module/specs/certificate.nitro.js.map +1 -0
  642. package/lib/module/specs/cipher.nitro.js +4 -0
  643. package/lib/module/specs/cipher.nitro.js.map +1 -0
  644. package/lib/module/specs/dhKeyPair.nitro.js +4 -0
  645. package/lib/module/specs/dhKeyPair.nitro.js.map +1 -0
  646. package/lib/module/specs/diffie-hellman.nitro.js +4 -0
  647. package/lib/module/specs/diffie-hellman.nitro.js.map +1 -0
  648. package/lib/module/specs/dsaKeyPair.nitro.js +4 -0
  649. package/lib/module/specs/dsaKeyPair.nitro.js.map +1 -0
  650. package/lib/module/specs/ecKeyPair.nitro.js +4 -0
  651. package/lib/module/specs/ecKeyPair.nitro.js.map +1 -0
  652. package/lib/module/specs/ecdh.nitro.js +4 -0
  653. package/lib/module/specs/ecdh.nitro.js.map +1 -0
  654. package/lib/module/specs/edKeyPair.nitro.js +4 -0
  655. package/lib/module/specs/edKeyPair.nitro.js.map +1 -0
  656. package/lib/module/specs/hash.nitro.js +4 -0
  657. package/lib/module/specs/hash.nitro.js.map +1 -0
  658. package/lib/module/specs/hkdf.nitro.js +4 -0
  659. package/lib/module/specs/hkdf.nitro.js.map +1 -0
  660. package/lib/module/specs/hmac.nitro.js +4 -0
  661. package/lib/module/specs/hmac.nitro.js.map +1 -0
  662. package/lib/module/specs/keyObjectHandle.nitro.js +4 -0
  663. package/lib/module/specs/keyObjectHandle.nitro.js.map +1 -0
  664. package/lib/module/specs/kmac.nitro.js +4 -0
  665. package/lib/module/specs/kmac.nitro.js.map +1 -0
  666. package/lib/module/specs/mlDsaKeyPair.nitro.js +4 -0
  667. package/lib/module/specs/mlDsaKeyPair.nitro.js.map +1 -0
  668. package/lib/module/specs/mlKemKeyPair.nitro.js +4 -0
  669. package/lib/module/specs/mlKemKeyPair.nitro.js.map +1 -0
  670. package/lib/module/specs/pbkdf2.nitro.js +4 -0
  671. package/lib/module/specs/pbkdf2.nitro.js.map +1 -0
  672. package/lib/module/specs/prime.nitro.js +4 -0
  673. package/lib/module/specs/prime.nitro.js.map +1 -0
  674. package/lib/module/specs/random.nitro.js +4 -0
  675. package/lib/module/specs/random.nitro.js.map +1 -0
  676. package/lib/module/specs/rsaCipher.nitro.js +4 -0
  677. package/lib/module/specs/rsaCipher.nitro.js.map +1 -0
  678. package/lib/module/specs/rsaKeyPair.nitro.js +4 -0
  679. package/lib/module/specs/rsaKeyPair.nitro.js.map +1 -0
  680. package/lib/module/specs/scrypt.nitro.js +4 -0
  681. package/lib/module/specs/scrypt.nitro.js.map +1 -0
  682. package/lib/module/specs/sign.nitro.js +4 -0
  683. package/lib/module/specs/sign.nitro.js.map +1 -0
  684. package/lib/module/specs/slhDsaKeyPair.nitro.js +4 -0
  685. package/lib/module/specs/slhDsaKeyPair.nitro.js.map +1 -0
  686. package/lib/module/specs/turboshake.nitro.js +4 -0
  687. package/lib/module/specs/turboshake.nitro.js.map +1 -0
  688. package/lib/module/specs/utils.nitro.js +4 -0
  689. package/lib/module/specs/utils.nitro.js.map +1 -0
  690. package/lib/module/specs/x509certificate.nitro.js +4 -0
  691. package/lib/module/specs/x509certificate.nitro.js.map +1 -0
  692. package/lib/module/subtle.js +3205 -0
  693. package/lib/module/subtle.js.map +1 -0
  694. package/lib/module/utils/cipher.js +67 -0
  695. package/lib/module/utils/cipher.js.map +1 -0
  696. package/lib/module/utils/conversion.js +205 -0
  697. package/lib/module/utils/conversion.js.map +1 -0
  698. package/lib/module/utils/errors.js +67 -0
  699. package/lib/module/utils/errors.js.map +1 -0
  700. package/lib/module/utils/hashnames.js +120 -0
  701. package/lib/module/utils/hashnames.js.map +1 -0
  702. package/lib/module/utils/index.js +10 -0
  703. package/lib/module/utils/index.js.map +1 -0
  704. package/lib/module/utils/noble.js +76 -0
  705. package/lib/module/utils/noble.js.map +1 -0
  706. package/lib/module/utils/timingSafeEqual.js +25 -0
  707. package/lib/module/utils/timingSafeEqual.js.map +1 -0
  708. package/lib/module/utils/types.js +57 -0
  709. package/lib/module/utils/types.js.map +1 -0
  710. package/lib/module/utils/validation.js +131 -0
  711. package/lib/module/utils/validation.js.map +1 -0
  712. package/lib/module/x509certificate.js +184 -0
  713. package/lib/module/x509certificate.js.map +1 -0
  714. package/lib/typescript/argon2.d.ts +16 -0
  715. package/lib/typescript/argon2.d.ts.map +1 -0
  716. package/lib/typescript/blake3.d.ts +33 -0
  717. package/lib/typescript/blake3.d.ts.map +1 -0
  718. package/lib/typescript/certificate.d.ts +8 -0
  719. package/lib/typescript/certificate.d.ts.map +1 -0
  720. package/lib/typescript/cipher.d.ts +75 -0
  721. package/lib/typescript/cipher.d.ts.map +1 -0
  722. package/lib/typescript/constants.d.ts +21 -0
  723. package/lib/typescript/constants.d.ts.map +1 -0
  724. package/lib/typescript/dh-groups.d.ts +5 -0
  725. package/lib/typescript/dh-groups.d.ts.map +1 -0
  726. package/lib/typescript/dhKeyPair.d.ts +19 -0
  727. package/lib/typescript/dhKeyPair.d.ts.map +1 -0
  728. package/lib/typescript/diffie-hellman.d.ts +18 -0
  729. package/lib/typescript/diffie-hellman.d.ts.map +1 -0
  730. package/lib/typescript/dsa.d.ts +19 -0
  731. package/lib/typescript/dsa.d.ts.map +1 -0
  732. package/lib/typescript/ec.d.ts +24 -0
  733. package/lib/typescript/ec.d.ts.map +1 -0
  734. package/lib/typescript/ecdh.d.ts +19 -0
  735. package/lib/typescript/ecdh.d.ts.map +1 -0
  736. package/lib/typescript/ed.d.ts +47 -0
  737. package/lib/typescript/ed.d.ts.map +1 -0
  738. package/lib/typescript/expo-plugin/@types.d.ts +8 -0
  739. package/lib/typescript/expo-plugin/@types.d.ts.map +1 -0
  740. package/lib/typescript/expo-plugin/withRNQC.d.ts +4 -0
  741. package/lib/typescript/expo-plugin/withRNQC.d.ts.map +1 -0
  742. package/lib/typescript/expo-plugin/withSodiumAndroid.d.ts +4 -0
  743. package/lib/typescript/expo-plugin/withSodiumAndroid.d.ts.map +1 -0
  744. package/lib/typescript/expo-plugin/withSodiumIos.d.ts +4 -0
  745. package/lib/typescript/expo-plugin/withSodiumIos.d.ts.map +1 -0
  746. package/lib/typescript/expo-plugin/withXCode.d.ts +23 -0
  747. package/lib/typescript/expo-plugin/withXCode.d.ts.map +1 -0
  748. package/lib/typescript/hash.d.ts +126 -0
  749. package/lib/typescript/hash.d.ts.map +1 -0
  750. package/lib/typescript/hkdf.d.ts +26 -0
  751. package/lib/typescript/hkdf.d.ts.map +1 -0
  752. package/lib/typescript/hmac.d.ts +66 -0
  753. package/lib/typescript/hmac.d.ts.map +1 -0
  754. package/lib/typescript/index.d.ts +240 -0
  755. package/lib/typescript/index.d.ts.map +1 -0
  756. package/lib/typescript/keys/classes.d.ts +95 -0
  757. package/lib/typescript/keys/classes.d.ts.map +1 -0
  758. package/lib/typescript/keys/generateKeyPair.d.ts +17 -0
  759. package/lib/typescript/keys/generateKeyPair.d.ts.map +1 -0
  760. package/lib/typescript/keys/index.d.ts +26 -0
  761. package/lib/typescript/keys/index.d.ts.map +1 -0
  762. package/lib/typescript/keys/publicCipher.d.ts +23 -0
  763. package/lib/typescript/keys/publicCipher.d.ts.map +1 -0
  764. package/lib/typescript/keys/signVerify.d.ts +35 -0
  765. package/lib/typescript/keys/signVerify.d.ts.map +1 -0
  766. package/lib/typescript/keys/utils.d.ts +51 -0
  767. package/lib/typescript/keys/utils.d.ts.map +1 -0
  768. package/lib/typescript/mldsa.d.ts +18 -0
  769. package/lib/typescript/mldsa.d.ts.map +1 -0
  770. package/lib/typescript/mlkem.d.ts +30 -0
  771. package/lib/typescript/mlkem.d.ts.map +1 -0
  772. package/lib/typescript/pbkdf2.d.ts +12 -0
  773. package/lib/typescript/pbkdf2.d.ts.map +1 -0
  774. package/lib/typescript/prime.d.ts +19 -0
  775. package/lib/typescript/prime.d.ts.map +1 -0
  776. package/lib/typescript/random.d.ts +31 -0
  777. package/lib/typescript/random.d.ts.map +1 -0
  778. package/lib/typescript/rsa.d.ts +20 -0
  779. package/lib/typescript/rsa.d.ts.map +1 -0
  780. package/lib/typescript/scrypt.d.ts +18 -0
  781. package/lib/typescript/scrypt.d.ts.map +1 -0
  782. package/lib/typescript/slhdsa.d.ts +19 -0
  783. package/lib/typescript/slhdsa.d.ts.map +1 -0
  784. package/lib/typescript/specs/argon2.nitro.d.ts +9 -0
  785. package/lib/typescript/specs/argon2.nitro.d.ts.map +1 -0
  786. package/lib/typescript/specs/blake3.nitro.d.ts +15 -0
  787. package/lib/typescript/specs/blake3.nitro.d.ts.map +1 -0
  788. package/lib/typescript/specs/certificate.nitro.d.ts +10 -0
  789. package/lib/typescript/specs/certificate.nitro.d.ts.map +1 -0
  790. package/lib/typescript/specs/cipher.nitro.d.ts +38 -0
  791. package/lib/typescript/specs/cipher.nitro.d.ts.map +1 -0
  792. package/lib/typescript/specs/dhKeyPair.nitro.d.ts +14 -0
  793. package/lib/typescript/specs/dhKeyPair.nitro.d.ts.map +1 -0
  794. package/lib/typescript/specs/diffie-hellman.nitro.d.ts +18 -0
  795. package/lib/typescript/specs/diffie-hellman.nitro.d.ts.map +1 -0
  796. package/lib/typescript/specs/dsaKeyPair.nitro.d.ts +13 -0
  797. package/lib/typescript/specs/dsaKeyPair.nitro.d.ts.map +1 -0
  798. package/lib/typescript/specs/ecKeyPair.nitro.d.ts +21 -0
  799. package/lib/typescript/specs/ecKeyPair.nitro.d.ts.map +1 -0
  800. package/lib/typescript/specs/ecdh.nitro.d.ts +15 -0
  801. package/lib/typescript/specs/ecdh.nitro.d.ts.map +1 -0
  802. package/lib/typescript/specs/edKeyPair.nitro.d.ts +17 -0
  803. package/lib/typescript/specs/edKeyPair.nitro.d.ts.map +1 -0
  804. package/lib/typescript/specs/hash.nitro.d.ts +13 -0
  805. package/lib/typescript/specs/hash.nitro.d.ts.map +1 -0
  806. package/lib/typescript/specs/hkdf.nitro.d.ts +10 -0
  807. package/lib/typescript/specs/hkdf.nitro.d.ts.map +1 -0
  808. package/lib/typescript/specs/hmac.nitro.d.ts +10 -0
  809. package/lib/typescript/specs/hmac.nitro.d.ts.map +1 -0
  810. package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +27 -0
  811. package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -0
  812. package/lib/typescript/specs/kmac.nitro.d.ts +10 -0
  813. package/lib/typescript/specs/kmac.nitro.d.ts.map +1 -0
  814. package/lib/typescript/specs/mlDsaKeyPair.nitro.d.ts +16 -0
  815. package/lib/typescript/specs/mlDsaKeyPair.nitro.d.ts.map +1 -0
  816. package/lib/typescript/specs/mlKemKeyPair.nitro.d.ts +18 -0
  817. package/lib/typescript/specs/mlKemKeyPair.nitro.d.ts.map +1 -0
  818. package/lib/typescript/specs/pbkdf2.nitro.d.ts +9 -0
  819. package/lib/typescript/specs/pbkdf2.nitro.d.ts.map +1 -0
  820. package/lib/typescript/specs/prime.nitro.d.ts +11 -0
  821. package/lib/typescript/specs/prime.nitro.d.ts.map +1 -0
  822. package/lib/typescript/specs/random.nitro.d.ts +9 -0
  823. package/lib/typescript/specs/random.nitro.d.ts.map +1 -0
  824. package/lib/typescript/specs/rsaCipher.nitro.d.ts +54 -0
  825. package/lib/typescript/specs/rsaCipher.nitro.d.ts.map +1 -0
  826. package/lib/typescript/specs/rsaKeyPair.nitro.d.ts +20 -0
  827. package/lib/typescript/specs/rsaKeyPair.nitro.d.ts.map +1 -0
  828. package/lib/typescript/specs/scrypt.nitro.d.ts +9 -0
  829. package/lib/typescript/specs/scrypt.nitro.d.ts.map +1 -0
  830. package/lib/typescript/specs/sign.nitro.d.ts +19 -0
  831. package/lib/typescript/specs/sign.nitro.d.ts.map +1 -0
  832. package/lib/typescript/specs/slhDsaKeyPair.nitro.d.ts +16 -0
  833. package/lib/typescript/specs/slhDsaKeyPair.nitro.d.ts.map +1 -0
  834. package/lib/typescript/specs/turboshake.nitro.d.ts +11 -0
  835. package/lib/typescript/specs/turboshake.nitro.d.ts.map +1 -0
  836. package/lib/typescript/specs/utils.nitro.d.ts +8 -0
  837. package/lib/typescript/specs/utils.nitro.d.ts.map +1 -0
  838. package/lib/typescript/specs/x509certificate.nitro.d.ts +34 -0
  839. package/lib/typescript/specs/x509certificate.nitro.d.ts.map +1 -0
  840. package/lib/typescript/subtle.d.ts +33 -0
  841. package/lib/typescript/subtle.d.ts.map +1 -0
  842. package/lib/typescript/utils/cipher.d.ts +19 -0
  843. package/lib/typescript/utils/cipher.d.ts.map +1 -0
  844. package/lib/typescript/utils/conversion.d.ts +36 -0
  845. package/lib/typescript/utils/conversion.d.ts.map +1 -0
  846. package/lib/typescript/utils/errors.d.ts +19 -0
  847. package/lib/typescript/utils/errors.d.ts.map +1 -0
  848. package/lib/typescript/utils/hashnames.d.ts +13 -0
  849. package/lib/typescript/utils/hashnames.d.ts.map +1 -0
  850. package/lib/typescript/utils/index.d.ts +8 -0
  851. package/lib/typescript/utils/index.d.ts.map +1 -0
  852. package/lib/typescript/utils/noble.d.ts +19 -0
  853. package/lib/typescript/utils/noble.d.ts.map +1 -0
  854. package/lib/typescript/utils/timingSafeEqual.d.ts +3 -0
  855. package/lib/typescript/utils/timingSafeEqual.d.ts.map +1 -0
  856. package/lib/typescript/utils/types.d.ts +314 -0
  857. package/lib/typescript/utils/types.d.ts.map +1 -0
  858. package/lib/typescript/utils/validation.d.ts +15 -0
  859. package/lib/typescript/utils/validation.d.ts.map +1 -0
  860. package/lib/typescript/x509certificate.d.ts +64 -0
  861. package/lib/typescript/x509certificate.d.ts.map +1 -0
  862. package/nitrogen/generated/.gitattributes +1 -0
  863. package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +110 -0
  864. package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +27 -0
  865. package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +334 -0
  866. package/nitrogen/generated/android/QuickCryptoOnLoad.hpp +25 -0
  867. package/nitrogen/generated/android/kotlin/com/margelo/nitro/crypto/QuickCryptoOnLoad.kt +35 -0
  868. package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +60 -0
  869. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +17 -0
  870. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +27 -0
  871. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +38 -0
  872. package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +325 -0
  873. package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +16 -0
  874. package/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp +176 -0
  875. package/nitrogen/generated/shared/c++/CipherArgs.hpp +101 -0
  876. package/nitrogen/generated/shared/c++/CipherInfo.hpp +104 -0
  877. package/nitrogen/generated/shared/c++/HkdfMode.hpp +80 -0
  878. package/nitrogen/generated/shared/c++/HybridArgon2Spec.cpp +22 -0
  879. package/nitrogen/generated/shared/c++/HybridArgon2Spec.hpp +66 -0
  880. package/nitrogen/generated/shared/c++/HybridBlake3Spec.cpp +28 -0
  881. package/nitrogen/generated/shared/c++/HybridBlake3Spec.hpp +74 -0
  882. package/nitrogen/generated/shared/c++/HybridCertificateSpec.cpp +23 -0
  883. package/nitrogen/generated/shared/c++/HybridCertificateSpec.hpp +64 -0
  884. package/nitrogen/generated/shared/c++/HybridCipherFactorySpec.cpp +21 -0
  885. package/nitrogen/generated/shared/c++/HybridCipherFactorySpec.hpp +67 -0
  886. package/nitrogen/generated/shared/c++/HybridCipherSpec.cpp +29 -0
  887. package/nitrogen/generated/shared/c++/HybridCipherSpec.hpp +78 -0
  888. package/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.cpp +27 -0
  889. package/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.hpp +69 -0
  890. package/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.cpp +31 -0
  891. package/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.hpp +72 -0
  892. package/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.cpp +26 -0
  893. package/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.hpp +68 -0
  894. package/nitrogen/generated/shared/c++/HybridECDHSpec.cpp +28 -0
  895. package/nitrogen/generated/shared/c++/HybridECDHSpec.hpp +70 -0
  896. package/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.cpp +30 -0
  897. package/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.hpp +76 -0
  898. package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp +30 -0
  899. package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp +74 -0
  900. package/nitrogen/generated/shared/c++/HybridHashSpec.cpp +26 -0
  901. package/nitrogen/generated/shared/c++/HybridHashSpec.hpp +74 -0
  902. package/nitrogen/generated/shared/c++/HybridHkdfSpec.cpp +22 -0
  903. package/nitrogen/generated/shared/c++/HybridHkdfSpec.hpp +67 -0
  904. package/nitrogen/generated/shared/c++/HybridHmacSpec.cpp +23 -0
  905. package/nitrogen/generated/shared/c++/HybridHmacSpec.hpp +66 -0
  906. package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +39 -0
  907. package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +107 -0
  908. package/nitrogen/generated/shared/c++/HybridKmacSpec.cpp +23 -0
  909. package/nitrogen/generated/shared/c++/HybridKmacSpec.hpp +66 -0
  910. package/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.cpp +29 -0
  911. package/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.hpp +72 -0
  912. package/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.cpp +31 -0
  913. package/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.hpp +74 -0
  914. package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp +22 -0
  915. package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp +65 -0
  916. package/nitrogen/generated/shared/c++/HybridPrimeSpec.cpp +24 -0
  917. package/nitrogen/generated/shared/c++/HybridPrimeSpec.hpp +67 -0
  918. package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +22 -0
  919. package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +64 -0
  920. package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.cpp +25 -0
  921. package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.hpp +71 -0
  922. package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.cpp +29 -0
  923. package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.hpp +75 -0
  924. package/nitrogen/generated/shared/c++/HybridScryptSpec.cpp +22 -0
  925. package/nitrogen/generated/shared/c++/HybridScryptSpec.hpp +64 -0
  926. package/nitrogen/generated/shared/c++/HybridSignHandleSpec.cpp +23 -0
  927. package/nitrogen/generated/shared/c++/HybridSignHandleSpec.hpp +69 -0
  928. package/nitrogen/generated/shared/c++/HybridSlhDsaKeyPairSpec.cpp +29 -0
  929. package/nitrogen/generated/shared/c++/HybridSlhDsaKeyPairSpec.hpp +72 -0
  930. package/nitrogen/generated/shared/c++/HybridTurboShakeSpec.cpp +22 -0
  931. package/nitrogen/generated/shared/c++/HybridTurboShakeSpec.hpp +70 -0
  932. package/nitrogen/generated/shared/c++/HybridUtilsSpec.cpp +21 -0
  933. package/nitrogen/generated/shared/c++/HybridUtilsSpec.hpp +62 -0
  934. package/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.cpp +23 -0
  935. package/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.hpp +69 -0
  936. package/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.cpp +46 -0
  937. package/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.hpp +96 -0
  938. package/nitrogen/generated/shared/c++/JWK.hpp +185 -0
  939. package/nitrogen/generated/shared/c++/JWKkty.hpp +92 -0
  940. package/nitrogen/generated/shared/c++/JWKuse.hpp +76 -0
  941. package/nitrogen/generated/shared/c++/KFormatType.hpp +63 -0
  942. package/nitrogen/generated/shared/c++/KangarooTwelveVariant.hpp +76 -0
  943. package/nitrogen/generated/shared/c++/KeyDetail.hpp +108 -0
  944. package/nitrogen/generated/shared/c++/KeyEncoding.hpp +64 -0
  945. package/nitrogen/generated/shared/c++/KeyObject.hpp +83 -0
  946. package/nitrogen/generated/shared/c++/KeyType.hpp +63 -0
  947. package/nitrogen/generated/shared/c++/KeyUsage.hpp +116 -0
  948. package/nitrogen/generated/shared/c++/NamedCurve.hpp +80 -0
  949. package/nitrogen/generated/shared/c++/TurboShakeVariant.hpp +76 -0
  950. package/ohos/binding.gyp +33 -0
  951. package/ohos/build/Release/quick_crypto.node +0 -0
  952. package/ohos/quick_crypto_napi.cpp +1316 -0
  953. package/package.json +158 -4
  954. package/src/argon2.ts +161 -0
  955. package/src/blake3.ts +124 -0
  956. package/src/certificate.ts +41 -0
  957. package/src/cipher.ts +497 -0
  958. package/src/constants.ts +32 -0
  959. package/src/dh-groups.ts +27 -0
  960. package/src/dhKeyPair.ts +164 -0
  961. package/src/diffie-hellman.ts +195 -0
  962. package/src/dsa.ts +146 -0
  963. package/src/ec.ts +580 -0
  964. package/src/ecdh.ts +132 -0
  965. package/src/ed.ts +605 -0
  966. package/src/expo-plugin/@types.ts +7 -0
  967. package/src/expo-plugin/withRNQC.ts +23 -0
  968. package/src/expo-plugin/withSodiumAndroid.ts +24 -0
  969. package/src/expo-plugin/withSodiumIos.ts +25 -0
  970. package/src/expo-plugin/withXCode.ts +134 -0
  971. package/src/hash.ts +433 -0
  972. package/src/hkdf.ts +327 -0
  973. package/src/hmac.ts +150 -0
  974. package/src/index.ts +126 -0
  975. package/src/keys/classes.ts +369 -0
  976. package/src/keys/generateKeyPair.ts +358 -0
  977. package/src/keys/index.ts +383 -0
  978. package/src/keys/publicCipher.ts +256 -0
  979. package/src/keys/signVerify.ts +329 -0
  980. package/src/keys/utils.ts +263 -0
  981. package/src/mldsa.ts +125 -0
  982. package/src/mlkem.ts +350 -0
  983. package/src/pbkdf2.ts +183 -0
  984. package/src/prime.ts +134 -0
  985. package/src/random.ts +427 -0
  986. package/src/rsa.ts +333 -0
  987. package/src/scrypt.ts +201 -0
  988. package/src/slhdsa.ts +146 -0
  989. package/src/specs/argon2.nitro.ts +29 -0
  990. package/src/specs/blake3.nitro.ts +12 -0
  991. package/src/specs/certificate.nitro.ts +8 -0
  992. package/src/specs/cipher.nitro.ts +39 -0
  993. package/src/specs/dhKeyPair.nitro.ts +14 -0
  994. package/src/specs/diffie-hellman.nitro.ts +16 -0
  995. package/src/specs/dsaKeyPair.nitro.ts +13 -0
  996. package/src/specs/ecKeyPair.nitro.ts +40 -0
  997. package/src/specs/ecdh.nitro.ts +12 -0
  998. package/src/specs/edKeyPair.nitro.ts +43 -0
  999. package/src/specs/hash.nitro.ts +10 -0
  1000. package/src/specs/hkdf.nitro.ts +25 -0
  1001. package/src/specs/hmac.nitro.ts +7 -0
  1002. package/src/specs/keyObjectHandle.nitro.ts +56 -0
  1003. package/src/specs/kmac.nitro.ts +12 -0
  1004. package/src/specs/mlDsaKeyPair.nitro.ts +29 -0
  1005. package/src/specs/mlKemKeyPair.nitro.ts +32 -0
  1006. package/src/specs/pbkdf2.nitro.ts +18 -0
  1007. package/src/specs/prime.nitro.ts +18 -0
  1008. package/src/specs/random.nitro.ts +14 -0
  1009. package/src/specs/rsaCipher.nitro.ts +82 -0
  1010. package/src/specs/rsaKeyPair.nitro.ts +33 -0
  1011. package/src/specs/scrypt.nitro.ts +23 -0
  1012. package/src/specs/sign.nitro.ts +31 -0
  1013. package/src/specs/slhDsaKeyPair.nitro.ts +29 -0
  1014. package/src/specs/turboshake.nitro.ts +21 -0
  1015. package/src/specs/utils.nitro.ts +5 -0
  1016. package/src/specs/x509certificate.nitro.ts +38 -0
  1017. package/src/subtle.ts +4545 -0
  1018. package/src/utils/cipher.ts +82 -0
  1019. package/src/utils/conversion.ts +285 -0
  1020. package/src/utils/errors.ts +83 -0
  1021. package/src/utils/hashnames.ts +129 -0
  1022. package/src/utils/index.ts +7 -0
  1023. package/src/utils/noble.ts +85 -0
  1024. package/src/utils/timingSafeEqual.ts +28 -0
  1025. package/src/utils/types.ts +617 -0
  1026. package/src/utils/validation.ts +199 -0
  1027. package/src/x509certificate.ts +276 -0
@@ -0,0 +1,3205 @@
1
+ "use strict";
2
+
3
+ import { Buffer as SBuffer } from 'safe-buffer';
4
+ import { KFormatType, KeyEncoding, KeyType, kNamedCurveAliases } from './utils';
5
+ import { Buffer } from '@craftzdog/react-native-buffer';
6
+ import { CryptoKey, KeyObject, PublicKeyObject, PrivateKeyObject, SecretKeyObject } from './keys';
7
+ import { binaryLikeToArrayBuffer, bufferLikeToArrayBuffer } from './utils/conversion';
8
+ import { argon2Sync } from './argon2';
9
+ import { lazyDOMException } from './utils/errors';
10
+ import { normalizeHashName, HashContext } from './utils/hashnames';
11
+ import { validateJwkStructure, validateMaxBufferLength } from './utils/validation';
12
+ import { asyncDigest } from './hash';
13
+ import { createSecretKey, createPublicKey } from './keys';
14
+ import { NitroModules } from 'react-native-nitro-modules';
15
+ import { pbkdf2DeriveBits } from './pbkdf2';
16
+ import { ecImportKey, ecdsaSignVerify, ec_generateKeyPair, ecDeriveBits } from './ec';
17
+ import { rsa_generateKeyPair } from './rsa';
18
+ import { getRandomValues } from './random';
19
+ import { createHmac } from './hmac';
20
+ import { timingSafeEqual } from './utils/timingSafeEqual';
21
+ import { createSign, createVerify } from './keys/signVerify';
22
+ import { ed_generateKeyPairWebCrypto, x_generateKeyPairWebCrypto, xDeriveBits, Ed } from './ed';
23
+ import { mldsa_generateKeyPairWebCrypto } from './mldsa';
24
+ import { slhdsa_generateKeyPairWebCrypto, SLH_DSA_VARIANTS } from './slhdsa';
25
+ import { mlkem_generateKeyPairWebCrypto, MlKem } from './mlkem';
26
+ import { hkdfDeriveBits } from './hkdf';
27
+ // Temporary enums that need to be defined
28
+ var KWebCryptoKeyFormat = /*#__PURE__*/function (KWebCryptoKeyFormat) {
29
+ KWebCryptoKeyFormat[KWebCryptoKeyFormat["kWebCryptoKeyFormatRaw"] = 0] = "kWebCryptoKeyFormatRaw";
30
+ KWebCryptoKeyFormat[KWebCryptoKeyFormat["kWebCryptoKeyFormatSPKI"] = 1] = "kWebCryptoKeyFormatSPKI";
31
+ KWebCryptoKeyFormat[KWebCryptoKeyFormat["kWebCryptoKeyFormatPKCS8"] = 2] = "kWebCryptoKeyFormatPKCS8";
32
+ return KWebCryptoKeyFormat;
33
+ }(KWebCryptoKeyFormat || {});
34
+ var CipherOrWrapMode = /*#__PURE__*/function (CipherOrWrapMode) {
35
+ CipherOrWrapMode[CipherOrWrapMode["kWebCryptoCipherEncrypt"] = 0] = "kWebCryptoCipherEncrypt";
36
+ CipherOrWrapMode[CipherOrWrapMode["kWebCryptoCipherDecrypt"] = 1] = "kWebCryptoCipherDecrypt";
37
+ return CipherOrWrapMode;
38
+ }(CipherOrWrapMode || {}); // Placeholder functions that need to be implemented
39
+ function hasAnyNotIn(usages, allowed) {
40
+ return usages.some(usage => !allowed.includes(usage));
41
+ }
42
+
43
+ // Mirrors webidl.requiredArguments. Node throws TypeError when a SubtleCrypto
44
+ // method is called with fewer than the spec-required number of arguments
45
+ // (webcrypto.js:866 etc.); we relied on TypeScript types alone, which apps
46
+ // catching `instanceof TypeError` could not see at runtime.
47
+ function requireArgs(actual, required, method) {
48
+ if (actual < required) {
49
+ throw new TypeError(`Failed to execute '${method}' on 'SubtleCrypto': ${required} arguments required, but only ${actual} present.`);
50
+ }
51
+ }
52
+
53
+ // WebCrypto §18.4.4: algorithm name lookup is case-insensitive, but the
54
+ // canonical mixed-case form is preserved in the resulting `name` field
55
+ // (e.g. "aes-gcm" → "AES-GCM"). This map is built lazily on first call so
56
+ // the registry of canonical names below can stay declared after the
57
+ // function. Without this, callers who pass lowercase strings bypass the
58
+ // downstream `SUPPORTED_ALGORITHMS` set comparisons silently.
59
+ //
60
+ // The map's value type is `AnyAlgorithm` so callers can use the lookup
61
+ // result directly without re-asserting. The `as AnyAlgorithm` at insertion
62
+ // is the single contract boundary: every name in `SUPPORTED_ALGORITHMS` is
63
+ // already a member of `AnyAlgorithm` by construction.
64
+ let _canonicalAlgorithmNames = null;
65
+ function getCanonicalAlgorithmNames() {
66
+ if (_canonicalAlgorithmNames === null) {
67
+ const map = new Map();
68
+ for (const set of Object.values(SUPPORTED_ALGORITHMS)) {
69
+ if (!set) continue;
70
+ for (const name of set) {
71
+ map.set(name.toLowerCase(), name);
72
+ }
73
+ }
74
+ _canonicalAlgorithmNames = map;
75
+ }
76
+ return _canonicalAlgorithmNames;
77
+ }
78
+
79
+ // Per-algorithm WebIDL converter table. Mirrors Node's kAlgorithmDefinitions
80
+ // (lib/internal/crypto/util.js): each (algorithm, operation) pair maps to a
81
+ // dictionary converter name, or null when only the `name` member is required.
82
+ // Operation keys are missing when an algorithm cannot perform that operation,
83
+ // causing `normalizeAlgorithm` to reject the call.
84
+ const kAlgorithmDefinitions = {
85
+ 'AES-CBC': {
86
+ generateKey: 'AesKeyGenParams',
87
+ exportKey: null,
88
+ importKey: null,
89
+ encrypt: 'AesCbcParams',
90
+ decrypt: 'AesCbcParams',
91
+ 'get key length': 'AesDerivedKeyParams'
92
+ },
93
+ 'AES-CTR': {
94
+ generateKey: 'AesKeyGenParams',
95
+ exportKey: null,
96
+ importKey: null,
97
+ encrypt: 'AesCtrParams',
98
+ decrypt: 'AesCtrParams',
99
+ 'get key length': 'AesDerivedKeyParams'
100
+ },
101
+ 'AES-GCM': {
102
+ generateKey: 'AesKeyGenParams',
103
+ exportKey: null,
104
+ importKey: null,
105
+ encrypt: 'AeadParams',
106
+ decrypt: 'AeadParams',
107
+ 'get key length': 'AesDerivedKeyParams'
108
+ },
109
+ 'AES-KW': {
110
+ generateKey: 'AesKeyGenParams',
111
+ exportKey: null,
112
+ importKey: null,
113
+ 'get key length': 'AesDerivedKeyParams',
114
+ wrapKey: null,
115
+ unwrapKey: null
116
+ },
117
+ 'AES-OCB': {
118
+ generateKey: 'AesKeyGenParams',
119
+ exportKey: null,
120
+ importKey: null,
121
+ encrypt: 'AeadParams',
122
+ decrypt: 'AeadParams',
123
+ 'get key length': 'AesDerivedKeyParams'
124
+ },
125
+ Argon2d: {
126
+ deriveBits: 'Argon2Params',
127
+ 'get key length': null,
128
+ importKey: null
129
+ },
130
+ Argon2i: {
131
+ deriveBits: 'Argon2Params',
132
+ 'get key length': null,
133
+ importKey: null
134
+ },
135
+ Argon2id: {
136
+ deriveBits: 'Argon2Params',
137
+ 'get key length': null,
138
+ importKey: null
139
+ },
140
+ 'ChaCha20-Poly1305': {
141
+ generateKey: null,
142
+ exportKey: null,
143
+ importKey: null,
144
+ encrypt: 'AeadParams',
145
+ decrypt: 'AeadParams',
146
+ 'get key length': null
147
+ },
148
+ ECDH: {
149
+ generateKey: 'EcKeyGenParams',
150
+ exportKey: null,
151
+ importKey: 'EcKeyImportParams',
152
+ deriveBits: 'EcdhKeyDeriveParams'
153
+ },
154
+ ECDSA: {
155
+ generateKey: 'EcKeyGenParams',
156
+ exportKey: null,
157
+ importKey: 'EcKeyImportParams',
158
+ sign: 'EcdsaParams',
159
+ verify: 'EcdsaParams'
160
+ },
161
+ Ed25519: {
162
+ generateKey: null,
163
+ exportKey: null,
164
+ importKey: null,
165
+ sign: null,
166
+ verify: null
167
+ },
168
+ Ed448: {
169
+ generateKey: null,
170
+ exportKey: null,
171
+ importKey: null,
172
+ sign: 'ContextParams',
173
+ verify: 'ContextParams'
174
+ },
175
+ HKDF: {
176
+ importKey: null,
177
+ deriveBits: 'HkdfParams',
178
+ 'get key length': null
179
+ },
180
+ HMAC: {
181
+ generateKey: 'HmacKeyGenParams',
182
+ exportKey: null,
183
+ importKey: 'HmacImportParams',
184
+ sign: null,
185
+ verify: null,
186
+ 'get key length': 'HmacImportParams'
187
+ },
188
+ KMAC128: {
189
+ generateKey: 'KmacKeyGenParams',
190
+ exportKey: null,
191
+ importKey: 'KmacImportParams',
192
+ sign: 'KmacParams',
193
+ verify: 'KmacParams',
194
+ 'get key length': 'KmacImportParams'
195
+ },
196
+ KMAC256: {
197
+ generateKey: 'KmacKeyGenParams',
198
+ exportKey: null,
199
+ importKey: 'KmacImportParams',
200
+ sign: 'KmacParams',
201
+ verify: 'KmacParams',
202
+ 'get key length': 'KmacImportParams'
203
+ },
204
+ 'ML-DSA-44': {
205
+ generateKey: null,
206
+ exportKey: null,
207
+ importKey: null,
208
+ sign: 'ContextParams',
209
+ verify: 'ContextParams'
210
+ },
211
+ 'ML-DSA-65': {
212
+ generateKey: null,
213
+ exportKey: null,
214
+ importKey: null,
215
+ sign: 'ContextParams',
216
+ verify: 'ContextParams'
217
+ },
218
+ 'ML-DSA-87': {
219
+ generateKey: null,
220
+ exportKey: null,
221
+ importKey: null,
222
+ sign: 'ContextParams',
223
+ verify: 'ContextParams'
224
+ },
225
+ 'ML-KEM-512': {
226
+ generateKey: null,
227
+ exportKey: null,
228
+ importKey: null,
229
+ encapsulateBits: null,
230
+ decapsulateBits: null,
231
+ encapsulateKey: null,
232
+ decapsulateKey: null
233
+ },
234
+ 'ML-KEM-768': {
235
+ generateKey: null,
236
+ exportKey: null,
237
+ importKey: null,
238
+ encapsulateBits: null,
239
+ decapsulateBits: null,
240
+ encapsulateKey: null,
241
+ decapsulateKey: null
242
+ },
243
+ 'ML-KEM-1024': {
244
+ generateKey: null,
245
+ exportKey: null,
246
+ importKey: null,
247
+ encapsulateBits: null,
248
+ decapsulateBits: null,
249
+ encapsulateKey: null,
250
+ decapsulateKey: null
251
+ },
252
+ PBKDF2: {
253
+ importKey: null,
254
+ deriveBits: 'Pbkdf2Params',
255
+ 'get key length': null
256
+ },
257
+ 'RSA-OAEP': {
258
+ generateKey: 'RsaHashedKeyGenParams',
259
+ exportKey: null,
260
+ importKey: 'RsaHashedImportParams',
261
+ encrypt: 'RsaOaepParams',
262
+ decrypt: 'RsaOaepParams'
263
+ },
264
+ 'RSA-PSS': {
265
+ generateKey: 'RsaHashedKeyGenParams',
266
+ exportKey: null,
267
+ importKey: 'RsaHashedImportParams',
268
+ sign: 'RsaPssParams',
269
+ verify: 'RsaPssParams'
270
+ },
271
+ 'RSASSA-PKCS1-v1_5': {
272
+ generateKey: 'RsaHashedKeyGenParams',
273
+ exportKey: null,
274
+ importKey: 'RsaHashedImportParams',
275
+ sign: null,
276
+ verify: null
277
+ },
278
+ 'SHA-1': {
279
+ digest: null
280
+ },
281
+ 'SHA-256': {
282
+ digest: null
283
+ },
284
+ 'SHA-384': {
285
+ digest: null
286
+ },
287
+ 'SHA-512': {
288
+ digest: null
289
+ },
290
+ 'SHA3-256': {
291
+ digest: null
292
+ },
293
+ 'SHA3-384': {
294
+ digest: null
295
+ },
296
+ 'SHA3-512': {
297
+ digest: null
298
+ },
299
+ cSHAKE128: {
300
+ digest: 'CShakeParams'
301
+ },
302
+ cSHAKE256: {
303
+ digest: 'CShakeParams'
304
+ },
305
+ KT128: {
306
+ digest: 'KangarooTwelveParams'
307
+ },
308
+ KT256: {
309
+ digest: 'KangarooTwelveParams'
310
+ },
311
+ TurboSHAKE128: {
312
+ digest: 'TurboShakeParams'
313
+ },
314
+ TurboSHAKE256: {
315
+ digest: 'TurboShakeParams'
316
+ },
317
+ X25519: {
318
+ generateKey: null,
319
+ exportKey: null,
320
+ importKey: null,
321
+ deriveBits: 'EcdhKeyDeriveParams'
322
+ },
323
+ X448: {
324
+ generateKey: null,
325
+ exportKey: null,
326
+ importKey: null,
327
+ deriveBits: 'EcdhKeyDeriveParams'
328
+ }
329
+ };
330
+ for (const v of SLH_DSA_VARIANTS) {
331
+ kAlgorithmDefinitions[v] = {
332
+ generateKey: null,
333
+ exportKey: null,
334
+ importKey: null,
335
+ sign: null,
336
+ verify: null
337
+ };
338
+ }
339
+
340
+ // WebIDL dictionary member specs. Mirrors Node's per-converter
341
+ // `createDictionaryConverter` definitions in lib/internal/crypto/webidl.js.
342
+ // `required: true` causes `normalizeAlgorithm` to throw a TypeError when the
343
+ // member is missing — matching the spec'd WebCrypto behavior that
344
+ // `SubtleCrypto.supports` relies on via try/catch.
345
+
346
+ const kRequiredFields = {
347
+ AesKeyGenParams: [{
348
+ key: 'length',
349
+ required: true
350
+ }],
351
+ AesDerivedKeyParams: [{
352
+ key: 'length',
353
+ required: true
354
+ }],
355
+ AesCbcParams: [{
356
+ key: 'iv',
357
+ required: true
358
+ }],
359
+ AesCtrParams: [{
360
+ key: 'counter',
361
+ required: true
362
+ }, {
363
+ key: 'length',
364
+ required: true
365
+ }],
366
+ AeadParams: [{
367
+ key: 'iv',
368
+ required: true
369
+ }, {
370
+ key: 'tagLength'
371
+ }, {
372
+ key: 'additionalData'
373
+ }],
374
+ EcKeyGenParams: [{
375
+ key: 'namedCurve',
376
+ required: true
377
+ }],
378
+ EcKeyImportParams: [{
379
+ key: 'namedCurve',
380
+ required: true
381
+ }],
382
+ EcdsaParams: [{
383
+ key: 'hash',
384
+ required: true
385
+ }],
386
+ EcdhKeyDeriveParams: [{
387
+ key: 'public',
388
+ required: true
389
+ }],
390
+ HmacKeyGenParams: [{
391
+ key: 'hash',
392
+ required: true
393
+ }, {
394
+ key: 'length'
395
+ }],
396
+ HmacImportParams: [{
397
+ key: 'hash',
398
+ required: true
399
+ }, {
400
+ key: 'length'
401
+ }],
402
+ HkdfParams: [{
403
+ key: 'hash',
404
+ required: true
405
+ }, {
406
+ key: 'salt',
407
+ required: true
408
+ }, {
409
+ key: 'info',
410
+ required: true
411
+ }],
412
+ Pbkdf2Params: [{
413
+ key: 'hash',
414
+ required: true
415
+ }, {
416
+ key: 'iterations',
417
+ required: true
418
+ }, {
419
+ key: 'salt',
420
+ required: true
421
+ }],
422
+ RsaHashedKeyGenParams: [{
423
+ key: 'modulusLength',
424
+ required: true
425
+ }, {
426
+ key: 'publicExponent',
427
+ required: true
428
+ }, {
429
+ key: 'hash',
430
+ required: true
431
+ }],
432
+ RsaHashedImportParams: [{
433
+ key: 'hash',
434
+ required: true
435
+ }],
436
+ RsaOaepParams: [{
437
+ key: 'label'
438
+ }],
439
+ RsaPssParams: [{
440
+ key: 'saltLength',
441
+ required: true
442
+ }],
443
+ ContextParams: [{
444
+ key: 'context'
445
+ }],
446
+ Argon2Params: [{
447
+ key: 'nonce',
448
+ required: true
449
+ }, {
450
+ key: 'parallelism',
451
+ required: true
452
+ }, {
453
+ key: 'memory',
454
+ required: true
455
+ }, {
456
+ key: 'passes',
457
+ required: true
458
+ }, {
459
+ key: 'version'
460
+ }, {
461
+ key: 'secretValue'
462
+ }, {
463
+ key: 'associatedData'
464
+ }],
465
+ KmacKeyGenParams: [{
466
+ key: 'length'
467
+ }],
468
+ KmacImportParams: [{
469
+ key: 'length'
470
+ }],
471
+ KmacParams: [{
472
+ key: 'outputLength',
473
+ required: true
474
+ }, {
475
+ key: 'customization'
476
+ }],
477
+ CShakeParams: [{
478
+ key: 'outputLength',
479
+ required: true
480
+ }, {
481
+ key: 'functionName'
482
+ }, {
483
+ key: 'customization'
484
+ }],
485
+ KangarooTwelveParams: [{
486
+ key: 'outputLength',
487
+ required: true
488
+ }, {
489
+ key: 'customization'
490
+ }],
491
+ TurboShakeParams: [{
492
+ key: 'outputLength',
493
+ required: true
494
+ }, {
495
+ key: 'domainSeparation'
496
+ }]
497
+ };
498
+ function isBufferSource(value) {
499
+ return value instanceof ArrayBuffer || ArrayBuffer.isView(value);
500
+ }
501
+ function validateBufferSource(algorithm, key) {
502
+ const value = algorithm[key];
503
+ if (value === undefined) return undefined;
504
+ if (!isBufferSource(value)) {
505
+ throw new TypeError(`Failed to normalize algorithm: '${key}' must be a BufferSource`);
506
+ }
507
+ return bufferLikeToArrayBuffer(value);
508
+ }
509
+ function validateBinaryLike(algorithm, key) {
510
+ const value = algorithm[key];
511
+ if (value === undefined) return undefined;
512
+ try {
513
+ return binaryLikeToArrayBuffer(value);
514
+ } catch {
515
+ throw new TypeError(`Failed to normalize algorithm: '${key}' must be a BufferSource`);
516
+ }
517
+ }
518
+ function validateByteLength(buffer, key, length, message) {
519
+ if (buffer !== undefined && buffer.byteLength !== length) {
520
+ throw lazyDOMException(message ?? `${key} must be ${length} bytes`, 'OperationError');
521
+ }
522
+ }
523
+ function validateUnsignedInteger(algorithm, key) {
524
+ const value = algorithm[key];
525
+ if (value === undefined) return undefined;
526
+ const numberValue = Number(value);
527
+ if (!Number.isFinite(numberValue) || !Number.isInteger(numberValue) || numberValue < 0) {
528
+ throw new TypeError(`Failed to normalize algorithm: '${key}' must be an unsigned integer`);
529
+ }
530
+ algorithm[key] = numberValue;
531
+ return numberValue;
532
+ }
533
+ function validateHashAlgorithm(algorithm, converterName) {
534
+ const hash = algorithm.hash;
535
+ if (hash === undefined) return;
536
+ const normalizedHash = normalizeHashName(hash, HashContext.WebCrypto);
537
+ if (!['SHA-1', 'SHA-256', 'SHA-384', 'SHA-512', 'SHA3-256', 'SHA3-384', 'SHA3-512'].includes(normalizedHash)) {
538
+ throw lazyDOMException(`Unsupported ${converterName}.hash`, 'NotSupportedError');
539
+ }
540
+ algorithm.hash = {
541
+ name: normalizedHash
542
+ };
543
+ }
544
+ function validateAesLength(length) {
545
+ if (length !== undefined && length !== 128 && length !== 192 && length !== 256) {
546
+ throw lazyDOMException('Invalid key length', 'OperationError');
547
+ }
548
+ }
549
+ function validateMacLength(algorithm, key, zeroError) {
550
+ const length = validateUnsignedInteger(algorithm, key);
551
+ if (length === undefined) return;
552
+ if (length === 0) {
553
+ throw lazyDOMException(`${key} cannot be 0`, zeroError);
554
+ }
555
+ if (length % 8) {
556
+ throw lazyDOMException(`Unsupported ${key}`, 'NotSupportedError');
557
+ }
558
+ }
559
+ function validateAeadParams(algorithm) {
560
+ const iv = validateBufferSource(algorithm, 'iv');
561
+ const tagLength = validateUnsignedInteger(algorithm, 'tagLength');
562
+ validateBufferSource(algorithm, 'additionalData');
563
+ switch (algorithm.name) {
564
+ case 'AES-GCM':
565
+ if (tagLength !== undefined && ![32, 64, 96, 104, 112, 120, 128].includes(tagLength)) {
566
+ throw lazyDOMException(`${tagLength} is not a valid AES-GCM tag length`, 'OperationError');
567
+ }
568
+ break;
569
+ case 'AES-OCB':
570
+ if (iv !== undefined && (iv.byteLength < 1 || iv.byteLength > 15)) {
571
+ throw lazyDOMException('AES-OCB algorithm.iv must be between 1 and 15 bytes', 'OperationError');
572
+ }
573
+ if (tagLength !== undefined && ![64, 96, 128].includes(tagLength)) {
574
+ throw lazyDOMException(`${tagLength} is not a valid AES-OCB tag length`, 'OperationError');
575
+ }
576
+ break;
577
+ case 'ChaCha20-Poly1305':
578
+ validateByteLength(iv, 'algorithm.iv', 12, 'ChaCha20-Poly1305 IV must be exactly 12 bytes');
579
+ if (tagLength !== undefined && tagLength !== 128) {
580
+ throw lazyDOMException(`${tagLength} is not a valid ChaCha20-Poly1305 tag length`, 'OperationError');
581
+ }
582
+ break;
583
+ }
584
+ }
585
+ function validateNormalizedAlgorithm(converterName, algorithm) {
586
+ switch (converterName) {
587
+ case 'AesKeyGenParams':
588
+ case 'AesDerivedKeyParams':
589
+ validateAesLength(validateUnsignedInteger(algorithm, 'length'));
590
+ break;
591
+ case 'AesCbcParams':
592
+ validateByteLength(validateBufferSource(algorithm, 'iv'), 'algorithm.iv', 16, 'algorithm.iv must contain exactly 16 bytes');
593
+ break;
594
+ case 'AesCtrParams':
595
+ {
596
+ validateByteLength(validateBufferSource(algorithm, 'counter'), 'algorithm.counter', 16);
597
+ const length = validateUnsignedInteger(algorithm, 'length');
598
+ if (length !== undefined && (length === 0 || length > 128)) {
599
+ throw lazyDOMException('AES-CTR algorithm.length must be between 1 and 128', 'OperationError');
600
+ }
601
+ break;
602
+ }
603
+ case 'AeadParams':
604
+ validateAeadParams(algorithm);
605
+ break;
606
+ case 'EcdsaParams':
607
+ case 'HmacKeyGenParams':
608
+ case 'HmacImportParams':
609
+ case 'HkdfParams':
610
+ case 'Pbkdf2Params':
611
+ case 'RsaHashedKeyGenParams':
612
+ case 'RsaHashedImportParams':
613
+ validateHashAlgorithm(algorithm, converterName);
614
+ if (converterName === 'HmacKeyGenParams') {
615
+ validateMacLength(algorithm, 'length', 'OperationError');
616
+ }
617
+ if (converterName === 'HkdfParams') {
618
+ validateBinaryLike(algorithm, 'salt');
619
+ validateBinaryLike(algorithm, 'info');
620
+ } else if (converterName === 'Pbkdf2Params') {
621
+ const iterations = validateUnsignedInteger(algorithm, 'iterations');
622
+ if (iterations === 0) {
623
+ throw lazyDOMException('iterations cannot be zero', 'OperationError');
624
+ }
625
+ validateBinaryLike(algorithm, 'salt');
626
+ } else if (converterName === 'RsaHashedKeyGenParams') {
627
+ validateUnsignedInteger(algorithm, 'modulusLength');
628
+ validateBufferSource(algorithm, 'publicExponent');
629
+ }
630
+ break;
631
+ case 'RsaPssParams':
632
+ validateUnsignedInteger(algorithm, 'saltLength');
633
+ break;
634
+ case 'RsaOaepParams':
635
+ validateBufferSource(algorithm, 'label');
636
+ break;
637
+ case 'ContextParams':
638
+ validateBufferSource(algorithm, 'context');
639
+ break;
640
+ case 'EcdhKeyDeriveParams':
641
+ if (!(algorithm.public instanceof CryptoKey)) {
642
+ throw lazyDOMException('algorithm.public must be a public key', 'InvalidAccessError');
643
+ }
644
+ break;
645
+ case 'Argon2Params':
646
+ {
647
+ validateBufferSource(algorithm, 'nonce');
648
+ const parallelism = validateUnsignedInteger(algorithm, 'parallelism');
649
+ const memory = validateUnsignedInteger(algorithm, 'memory');
650
+ validateUnsignedInteger(algorithm, 'passes');
651
+ const version = validateUnsignedInteger(algorithm, 'version');
652
+ validateBufferSource(algorithm, 'secretValue');
653
+ validateBufferSource(algorithm, 'associatedData');
654
+ if (parallelism !== undefined && (parallelism === 0 || parallelism > 2 ** 24 - 1)) {
655
+ throw lazyDOMException('parallelism must be > 0 and < 16777215', 'OperationError');
656
+ }
657
+ if (memory !== undefined && parallelism !== undefined && memory < 8 * parallelism) {
658
+ throw lazyDOMException('memory must be at least 8 times the degree of parallelism', 'OperationError');
659
+ }
660
+ if (version !== undefined && version !== 0x13) {
661
+ throw lazyDOMException(`${version} is not a valid Argon2 version`, 'OperationError');
662
+ }
663
+ break;
664
+ }
665
+ case 'KmacKeyGenParams':
666
+ validateMacLength(algorithm, 'length', 'OperationError');
667
+ break;
668
+ case 'KmacImportParams':
669
+ validateMacLength(algorithm, 'length', 'DataError');
670
+ break;
671
+ case 'KmacParams':
672
+ validateMacLength(algorithm, 'outputLength', 'OperationError');
673
+ validateBufferSource(algorithm, 'customization');
674
+ break;
675
+ case 'CShakeParams':
676
+ case 'KangarooTwelveParams':
677
+ {
678
+ const outputLength = validateUnsignedInteger(algorithm, 'outputLength');
679
+ if (outputLength !== undefined && (outputLength === 0 || outputLength % 8)) {
680
+ throw lazyDOMException(`Invalid ${converterName} outputLength`, 'OperationError');
681
+ }
682
+ validateBufferSource(algorithm, 'functionName');
683
+ validateBufferSource(algorithm, 'customization');
684
+ break;
685
+ }
686
+ case 'TurboShakeParams':
687
+ {
688
+ const outputLength = validateUnsignedInteger(algorithm, 'outputLength');
689
+ const domainSeparation = validateUnsignedInteger(algorithm, 'domainSeparation');
690
+ if (outputLength !== undefined && (outputLength === 0 || outputLength % 8)) {
691
+ throw lazyDOMException('Invalid TurboShakeParams outputLength', 'OperationError');
692
+ }
693
+ if (domainSeparation !== undefined && (domainSeparation < 0x01 || domainSeparation > 0x7f)) {
694
+ throw lazyDOMException('TurboShakeParams.domainSeparation must be in range 0x01-0x7f', 'OperationError');
695
+ }
696
+ break;
697
+ }
698
+ }
699
+ }
700
+
701
+ // WebCrypto §18.4.4 algorithm normalization. Mirrors Node's normalizeAlgorithm
702
+ // in lib/internal/crypto/util.js: canonicalizes `name`, looks up the
703
+ // (name, op) → converter mapping, and rejects inputs that omit required
704
+ // dictionary members. Callers in Subtle.supports rely on this throwing for
705
+ // invalid params — without it, supports() over-reports capability (#1025).
706
+ function normalizeAlgorithm(algorithm, operation) {
707
+ if (typeof algorithm === 'string') {
708
+ return normalizeAlgorithm({
709
+ name: algorithm
710
+ }, operation);
711
+ }
712
+ const name = algorithm.name;
713
+ if (typeof name !== 'string') {
714
+ throw new TypeError("Algorithm: 'name' is required");
715
+ }
716
+ const map = getCanonicalAlgorithmNames();
717
+ const canonical = map.get(name.toLowerCase());
718
+ if (canonical === undefined) {
719
+ throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError');
720
+ }
721
+ const opMap = kAlgorithmDefinitions[canonical];
722
+ if (!opMap || !(operation in opMap)) {
723
+ throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError');
724
+ }
725
+ const converterName = opMap[operation];
726
+ if (converterName == null) {
727
+ return {
728
+ name: canonical
729
+ };
730
+ }
731
+ const fields = kRequiredFields[converterName];
732
+ if (!fields) {
733
+ return {
734
+ ...algorithm,
735
+ name: canonical
736
+ };
737
+ }
738
+ const out = {
739
+ name: canonical
740
+ };
741
+ const src = algorithm;
742
+ for (const field of fields) {
743
+ const value = src[field.key];
744
+ if (value === undefined) {
745
+ if (field.required) {
746
+ throw new TypeError(`Failed to normalize algorithm: '${field.key}' is required in '${converterName}'`);
747
+ }
748
+ continue;
749
+ }
750
+ out[field.key] = value;
751
+ }
752
+ validateNormalizedAlgorithm(converterName, out);
753
+ return out;
754
+ }
755
+ function getAlgorithmName(name, length) {
756
+ switch (name) {
757
+ case 'AES-CBC':
758
+ return `A${length}CBC`;
759
+ case 'AES-CTR':
760
+ return `A${length}CTR`;
761
+ case 'AES-GCM':
762
+ return `A${length}GCM`;
763
+ case 'AES-KW':
764
+ return `A${length}KW`;
765
+ case 'AES-OCB':
766
+ return `A${length}OCB`;
767
+ case 'ChaCha20-Poly1305':
768
+ return 'C20P';
769
+ default:
770
+ return `${name}${length}`;
771
+ }
772
+ }
773
+
774
+ // Mirrors Node's aliasKeyFormat (lib/internal/crypto/webcrypto.js): for
775
+ // algorithms whose import/export accepts both 'raw' and the disambiguated
776
+ // 'raw-secret' / 'raw-public', collapse the latter to 'raw'. Used per-algorithm
777
+ // — algorithms that demand the disambiguated form (KMAC, AES-OCB,
778
+ // ChaCha20-Poly1305, Argon2*, ML-DSA, ML-KEM) MUST NOT alias.
779
+ function aliasKeyFormat(format) {
780
+ if (format === 'raw-secret' || format === 'raw-public') return 'raw';
781
+ return format;
782
+ }
783
+ const kUncompressedSpkiLength = {
784
+ 'P-256': 91,
785
+ 'P-384': 120,
786
+ 'P-521': 158
787
+ };
788
+ function ecExportKey(key, format) {
789
+ const keyObject = key.keyObject;
790
+ if (format === KWebCryptoKeyFormat.kWebCryptoKeyFormatRaw) {
791
+ return bufferLikeToArrayBuffer(keyObject.handle.exportKey());
792
+ } else if (format === KWebCryptoKeyFormat.kWebCryptoKeyFormatSPKI) {
793
+ const exported = bufferLikeToArrayBuffer(keyObject.export({
794
+ format: 'der',
795
+ type: 'spki'
796
+ }));
797
+
798
+ // WebCrypto requires uncompressed point format for SPKI exports.
799
+ // If the key was imported in compressed form, re-export as uncompressed
800
+ // by reconstructing the point from the JWK x,y coordinates and
801
+ // round-tripping through initECRaw.
802
+ const namedCurve = key.algorithm.namedCurve;
803
+ const expected = namedCurve === undefined ? undefined : kUncompressedSpkiLength[namedCurve];
804
+ if (expected !== undefined && exported.byteLength !== expected) {
805
+ const jwk = keyObject.handle.exportJwk({}, false);
806
+ if (!jwk.x || !jwk.y) {
807
+ throw lazyDOMException('Failed to re-export EC public key as uncompressed SPKI', 'OperationError');
808
+ }
809
+ const x = Buffer.from(jwk.x, 'base64url');
810
+ const y = Buffer.from(jwk.y, 'base64url');
811
+ const raw = new Uint8Array(1 + x.length + y.length);
812
+ raw[0] = 0x04;
813
+ raw.set(x, 1);
814
+ raw.set(y, 1 + x.length);
815
+ const tmp = NitroModules.createHybridObject('KeyObjectHandle');
816
+ const curveAlias = kNamedCurveAliases[namedCurve];
817
+ if (!tmp.initECRaw(curveAlias, raw.buffer)) {
818
+ throw lazyDOMException('Failed to re-export EC public key as uncompressed SPKI', 'OperationError');
819
+ }
820
+ return bufferLikeToArrayBuffer(tmp.exportKey(KFormatType.DER, KeyEncoding.SPKI));
821
+ }
822
+ return exported;
823
+ } else if (format === KWebCryptoKeyFormat.kWebCryptoKeyFormatPKCS8) {
824
+ const exported = keyObject.export({
825
+ format: 'der',
826
+ type: 'pkcs8'
827
+ });
828
+ return bufferLikeToArrayBuffer(exported);
829
+ } else {
830
+ throw new Error(`Unsupported EC export format: ${format}`);
831
+ }
832
+ }
833
+ function rsaExportKey(key, format) {
834
+ const keyObject = key.keyObject;
835
+ if (format === KWebCryptoKeyFormat.kWebCryptoKeyFormatSPKI) {
836
+ // Export public key in SPKI format
837
+ const exported = keyObject.export({
838
+ format: 'der',
839
+ type: 'spki'
840
+ });
841
+ return bufferLikeToArrayBuffer(exported);
842
+ } else if (format === KWebCryptoKeyFormat.kWebCryptoKeyFormatPKCS8) {
843
+ // Export private key in PKCS8 format
844
+ const exported = keyObject.export({
845
+ format: 'der',
846
+ type: 'pkcs8'
847
+ });
848
+ return bufferLikeToArrayBuffer(exported);
849
+ } else {
850
+ throw new Error(`Unsupported RSA export format: ${format}`);
851
+ }
852
+ }
853
+ async function rsaCipher(mode, key, data, algorithm) {
854
+ const rsaParams = algorithm;
855
+
856
+ // Validate key type matches operation
857
+ const expectedType = mode === CipherOrWrapMode.kWebCryptoCipherEncrypt ? 'public' : 'private';
858
+ if (key.type !== expectedType) {
859
+ throw lazyDOMException('The requested operation is not valid for the provided key', 'InvalidAccessError');
860
+ }
861
+
862
+ // Get hash algorithm from key
863
+ const hashAlgorithm = normalizeHashName(key.algorithm.hash);
864
+
865
+ // Prepare label (optional)
866
+ const label = rsaParams.label ? bufferLikeToArrayBuffer(rsaParams.label) : undefined;
867
+
868
+ // Create RSA cipher instance
869
+ const rsaCipherModule = NitroModules.createHybridObject('RsaCipher');
870
+
871
+ // RSA-OAEP padding constant = 4
872
+ const RSA_PKCS1_OAEP_PADDING = 4;
873
+ if (mode === CipherOrWrapMode.kWebCryptoCipherEncrypt) {
874
+ // Encrypt with public key
875
+ return rsaCipherModule.encrypt(key.keyObject.handle, data, RSA_PKCS1_OAEP_PADDING, hashAlgorithm, label);
876
+ } else {
877
+ // Decrypt with private key
878
+ return rsaCipherModule.decrypt(key.keyObject.handle, data, RSA_PKCS1_OAEP_PADDING, hashAlgorithm, label);
879
+ }
880
+ }
881
+ async function aesCipher(mode, key, data, algorithm) {
882
+ const {
883
+ name
884
+ } = algorithm;
885
+ switch (name) {
886
+ case 'AES-CTR':
887
+ return aesCtrCipher(mode, key, data, algorithm);
888
+ case 'AES-CBC':
889
+ return aesCbcCipher(mode, key, data, algorithm);
890
+ case 'AES-GCM':
891
+ return aesGcmCipher(mode, key, data, algorithm);
892
+ case 'AES-OCB':
893
+ return aesOcbCipher(mode, key, data, algorithm);
894
+ default:
895
+ throw lazyDOMException(`Unsupported AES algorithm: ${name}`, 'NotSupportedError');
896
+ }
897
+ }
898
+ async function aesCtrCipher(mode, key, data, algorithm) {
899
+ // Validate counter and length
900
+ if (!algorithm.counter || algorithm.counter.byteLength !== 16) {
901
+ throw lazyDOMException('AES-CTR algorithm.counter must be 16 bytes', 'OperationError');
902
+ }
903
+ if (algorithm.length < 1 || algorithm.length > 128) {
904
+ throw lazyDOMException('AES-CTR algorithm.length must be between 1 and 128', 'OperationError');
905
+ }
906
+
907
+ // Get cipher type based on key length
908
+ const keyLength = key.algorithm.length;
909
+ const cipherType = `aes-${keyLength}-ctr`;
910
+
911
+ // Create cipher
912
+ const factory = NitroModules.createHybridObject('CipherFactory');
913
+ const cipher = factory.createCipher({
914
+ isCipher: mode === CipherOrWrapMode.kWebCryptoCipherEncrypt,
915
+ cipherType,
916
+ cipherKey: bufferLikeToArrayBuffer(key.keyObject.export()),
917
+ iv: bufferLikeToArrayBuffer(algorithm.counter)
918
+ });
919
+
920
+ // Process data
921
+ const updated = cipher.update(data);
922
+ const final = cipher.final();
923
+
924
+ // Concatenate results
925
+ const result = new Uint8Array(updated.byteLength + final.byteLength);
926
+ result.set(new Uint8Array(updated), 0);
927
+ result.set(new Uint8Array(final), updated.byteLength);
928
+ return result.buffer;
929
+ }
930
+ async function aesCbcCipher(mode, key, data, algorithm) {
931
+ // Validate IV
932
+ const iv = bufferLikeToArrayBuffer(algorithm.iv);
933
+ if (iv.byteLength !== 16) {
934
+ throw lazyDOMException('algorithm.iv must contain exactly 16 bytes', 'OperationError');
935
+ }
936
+
937
+ // Get cipher type based on key length
938
+ const keyLength = key.algorithm.length;
939
+ const cipherType = `aes-${keyLength}-cbc`;
940
+
941
+ // Create cipher
942
+ const factory = NitroModules.createHybridObject('CipherFactory');
943
+ const cipher = factory.createCipher({
944
+ isCipher: mode === CipherOrWrapMode.kWebCryptoCipherEncrypt,
945
+ cipherType,
946
+ cipherKey: bufferLikeToArrayBuffer(key.keyObject.export()),
947
+ iv
948
+ });
949
+
950
+ // Process data
951
+ const updated = cipher.update(data);
952
+ const final = cipher.final();
953
+
954
+ // Concatenate results
955
+ const result = new Uint8Array(updated.byteLength + final.byteLength);
956
+ result.set(new Uint8Array(updated), 0);
957
+ result.set(new Uint8Array(final), updated.byteLength);
958
+ return result.buffer;
959
+ }
960
+ async function aesAeadCipher(mode, key, data, config, additionalData, tagLength = 128) {
961
+ if (!config.validTagLengths.includes(tagLength)) {
962
+ throw lazyDOMException(`${tagLength} is not a valid ${config.algorithmName} tag length`, 'OperationError');
963
+ }
964
+ const tagByteLength = tagLength / 8;
965
+ const keyLength = key.algorithm.length;
966
+ const cipherType = `aes-${keyLength}-${config.cipherSuffix}`;
967
+ const factory = NitroModules.createHybridObject('CipherFactory');
968
+ const cipher = factory.createCipher({
969
+ isCipher: mode === CipherOrWrapMode.kWebCryptoCipherEncrypt,
970
+ cipherType,
971
+ cipherKey: bufferLikeToArrayBuffer(key.keyObject.export()),
972
+ iv: config.iv,
973
+ authTagLen: tagByteLength
974
+ });
975
+ let processData;
976
+ if (mode === CipherOrWrapMode.kWebCryptoCipherDecrypt) {
977
+ const dataView = new Uint8Array(data);
978
+ if (dataView.byteLength < tagByteLength) {
979
+ throw lazyDOMException('The provided data is too small.', 'OperationError');
980
+ }
981
+ const ciphertextLength = dataView.byteLength - tagByteLength;
982
+ processData = dataView.slice(0, ciphertextLength).buffer;
983
+ const authTag = dataView.slice(ciphertextLength).buffer;
984
+ cipher.setAuthTag(authTag);
985
+ } else {
986
+ processData = data;
987
+ }
988
+ if (additionalData) {
989
+ cipher.setAAD(bufferLikeToArrayBuffer(additionalData));
990
+ }
991
+ const updated = cipher.update(processData);
992
+ const final = cipher.final();
993
+ if (mode === CipherOrWrapMode.kWebCryptoCipherEncrypt) {
994
+ const tag = cipher.getAuthTag();
995
+ const result = new Uint8Array(updated.byteLength + final.byteLength + tag.byteLength);
996
+ result.set(new Uint8Array(updated), 0);
997
+ result.set(new Uint8Array(final), updated.byteLength);
998
+ result.set(new Uint8Array(tag), updated.byteLength + final.byteLength);
999
+ return result.buffer;
1000
+ } else {
1001
+ const result = new Uint8Array(updated.byteLength + final.byteLength);
1002
+ result.set(new Uint8Array(updated), 0);
1003
+ result.set(new Uint8Array(final), updated.byteLength);
1004
+ return result.buffer;
1005
+ }
1006
+ }
1007
+ async function aesGcmCipher(mode, key, data, algorithm) {
1008
+ return aesAeadCipher(mode, key, data, {
1009
+ algorithmName: 'AES-GCM',
1010
+ validTagLengths: [32, 64, 96, 104, 112, 120, 128],
1011
+ cipherSuffix: 'gcm',
1012
+ iv: bufferLikeToArrayBuffer(algorithm.iv)
1013
+ }, algorithm.additionalData, algorithm.tagLength);
1014
+ }
1015
+ async function aesOcbCipher(mode, key, data, algorithm) {
1016
+ const ivBuffer = bufferLikeToArrayBuffer(algorithm.iv);
1017
+ if (ivBuffer.byteLength < 1 || ivBuffer.byteLength > 15) {
1018
+ throw lazyDOMException('AES-OCB algorithm.iv must be between 1 and 15 bytes', 'OperationError');
1019
+ }
1020
+ return aesAeadCipher(mode, key, data, {
1021
+ algorithmName: 'AES-OCB',
1022
+ validTagLengths: [64, 96, 128],
1023
+ cipherSuffix: 'ocb',
1024
+ iv: ivBuffer
1025
+ }, algorithm.additionalData, algorithm.tagLength);
1026
+ }
1027
+ async function aesKwCipher(mode, key, data) {
1028
+ const isWrap = mode === CipherOrWrapMode.kWebCryptoCipherEncrypt;
1029
+
1030
+ // AES-KW requires input to be a multiple of 8 bytes (64 bits)
1031
+ if (data.byteLength % 8 !== 0) {
1032
+ throw lazyDOMException(`AES-KW input length must be a multiple of 8 bytes, got ${data.byteLength}`, 'OperationError');
1033
+ }
1034
+
1035
+ // AES-KW requires at least 16 bytes of input (128 bits)
1036
+ if (isWrap && data.byteLength < 16) {
1037
+ throw lazyDOMException(`AES-KW input must be at least 16 bytes, got ${data.byteLength}`, 'OperationError');
1038
+ }
1039
+
1040
+ // Get cipher type based on key length
1041
+ const keyLength = key.algorithm.length;
1042
+ // Use aes*-wrap for both operations (matching Node.js)
1043
+ const cipherType = `aes${keyLength}-wrap`;
1044
+
1045
+ // Export key material
1046
+ const exportedKey = key.keyObject.export();
1047
+ const cipherKey = bufferLikeToArrayBuffer(exportedKey);
1048
+
1049
+ // AES-KW uses a default IV as specified in RFC 3394
1050
+ const defaultWrapIV = new Uint8Array([0xa6, 0xa6, 0xa6, 0xa6, 0xa6, 0xa6, 0xa6, 0xa6]);
1051
+ const factory = NitroModules.createHybridObject('CipherFactory');
1052
+ const cipher = factory.createCipher({
1053
+ isCipher: isWrap,
1054
+ cipherType,
1055
+ cipherKey,
1056
+ iv: defaultWrapIV.buffer // RFC 3394 default IV for AES-KW
1057
+ });
1058
+
1059
+ // Process data
1060
+ const updated = cipher.update(data);
1061
+ const final = cipher.final();
1062
+
1063
+ // Concatenate results
1064
+ const result = new Uint8Array(updated.byteLength + final.byteLength);
1065
+ result.set(new Uint8Array(updated), 0);
1066
+ result.set(new Uint8Array(final), updated.byteLength);
1067
+ return result.buffer;
1068
+ }
1069
+ async function chaCha20Poly1305Cipher(mode, key, data, algorithm) {
1070
+ const {
1071
+ iv,
1072
+ additionalData,
1073
+ tagLength = 128
1074
+ } = algorithm;
1075
+
1076
+ // Validate IV (must be 12 bytes for ChaCha20-Poly1305)
1077
+ const ivBuffer = bufferLikeToArrayBuffer(iv);
1078
+ if (!ivBuffer || ivBuffer.byteLength !== 12) {
1079
+ throw lazyDOMException('ChaCha20-Poly1305 IV must be exactly 12 bytes', 'OperationError');
1080
+ }
1081
+
1082
+ // Validate tag length (only 128-bit supported)
1083
+ if (tagLength !== 128) {
1084
+ throw lazyDOMException('ChaCha20-Poly1305 only supports 128-bit auth tags', 'NotSupportedError');
1085
+ }
1086
+ const tagByteLength = 16; // 128 bits = 16 bytes
1087
+
1088
+ // Create cipher using existing ChaCha20-Poly1305 implementation
1089
+ const factory = NitroModules.createHybridObject('CipherFactory');
1090
+ const cipher = factory.createCipher({
1091
+ isCipher: mode === CipherOrWrapMode.kWebCryptoCipherEncrypt,
1092
+ cipherType: 'chacha20-poly1305',
1093
+ cipherKey: bufferLikeToArrayBuffer(key.keyObject.export()),
1094
+ iv: ivBuffer,
1095
+ authTagLen: tagByteLength
1096
+ });
1097
+ let processData;
1098
+ let authTag;
1099
+ if (mode === CipherOrWrapMode.kWebCryptoCipherDecrypt) {
1100
+ // For decryption, extract auth tag from end of data
1101
+ const dataView = new Uint8Array(data);
1102
+ if (dataView.byteLength < tagByteLength) {
1103
+ throw lazyDOMException('The provided data is too small.', 'OperationError');
1104
+ }
1105
+
1106
+ // Split data and tag
1107
+ const ciphertextLength = dataView.byteLength - tagByteLength;
1108
+ processData = dataView.slice(0, ciphertextLength).buffer;
1109
+ authTag = dataView.slice(ciphertextLength).buffer;
1110
+
1111
+ // Set auth tag for verification
1112
+ cipher.setAuthTag(authTag);
1113
+ } else {
1114
+ processData = data;
1115
+ }
1116
+
1117
+ // Set additional authenticated data if provided
1118
+ if (additionalData) {
1119
+ cipher.setAAD(bufferLikeToArrayBuffer(additionalData));
1120
+ }
1121
+
1122
+ // Process data
1123
+ const updated = cipher.update(processData);
1124
+ const final = cipher.final();
1125
+ if (mode === CipherOrWrapMode.kWebCryptoCipherEncrypt) {
1126
+ // For encryption, append auth tag to result
1127
+ const tag = cipher.getAuthTag();
1128
+ const result = new Uint8Array(updated.byteLength + final.byteLength + tag.byteLength);
1129
+ result.set(new Uint8Array(updated), 0);
1130
+ result.set(new Uint8Array(final), updated.byteLength);
1131
+ result.set(new Uint8Array(tag), updated.byteLength + final.byteLength);
1132
+ return result.buffer;
1133
+ } else {
1134
+ // For decryption, just concatenate plaintext
1135
+ const result = new Uint8Array(updated.byteLength + final.byteLength);
1136
+ result.set(new Uint8Array(updated), 0);
1137
+ result.set(new Uint8Array(final), updated.byteLength);
1138
+ return result.buffer;
1139
+ }
1140
+ }
1141
+ async function aesGenerateKey(algorithm, extractable, keyUsages) {
1142
+ const {
1143
+ length
1144
+ } = algorithm;
1145
+ const name = algorithm.name;
1146
+ if (!name) {
1147
+ throw lazyDOMException('Algorithm name is required', 'OperationError');
1148
+ }
1149
+
1150
+ // Validate key length
1151
+ if (![128, 192, 256].includes(length)) {
1152
+ throw lazyDOMException(`Invalid AES key length: ${length}. Must be 128, 192, or 256.`, 'OperationError');
1153
+ }
1154
+
1155
+ // Validate usages
1156
+ const validUsages = ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'];
1157
+ if (hasAnyNotIn(keyUsages, validUsages)) {
1158
+ throw lazyDOMException(`Unsupported key usage for ${name}`, 'SyntaxError');
1159
+ }
1160
+
1161
+ // Generate random key bytes
1162
+ const keyBytes = new Uint8Array(length / 8);
1163
+ getRandomValues(keyBytes);
1164
+
1165
+ // Create secret key
1166
+ const keyObject = createSecretKey(keyBytes);
1167
+
1168
+ // Construct algorithm object with guaranteed name
1169
+ const keyAlgorithm = {
1170
+ name,
1171
+ length
1172
+ };
1173
+ return new CryptoKey(keyObject, keyAlgorithm, keyUsages, extractable);
1174
+ }
1175
+ async function hmacGenerateKey(algorithm, extractable, keyUsages) {
1176
+ // Validate usages
1177
+ if (hasAnyNotIn(keyUsages, ['sign', 'verify'])) {
1178
+ throw lazyDOMException('Unsupported key usage for HMAC key', 'SyntaxError');
1179
+ }
1180
+
1181
+ // Get hash algorithm
1182
+ const hash = algorithm.hash;
1183
+ if (!hash) {
1184
+ throw lazyDOMException('HMAC algorithm requires a hash parameter', 'TypeError');
1185
+ }
1186
+ const hashName = normalizeHashName(hash);
1187
+
1188
+ // Determine key length
1189
+ let length = algorithm.length;
1190
+ if (length === undefined) {
1191
+ // Use hash output length as default key length
1192
+ switch (hashName) {
1193
+ case 'SHA-1':
1194
+ length = 160;
1195
+ break;
1196
+ case 'SHA-256':
1197
+ length = 256;
1198
+ break;
1199
+ case 'SHA-384':
1200
+ length = 384;
1201
+ break;
1202
+ case 'SHA-512':
1203
+ length = 512;
1204
+ break;
1205
+ default:
1206
+ length = 256;
1207
+ // Default to 256 bits
1208
+ }
1209
+ }
1210
+ if (length === 0) {
1211
+ throw lazyDOMException('Zero-length key is not supported', 'OperationError');
1212
+ }
1213
+
1214
+ // Generate random key bytes
1215
+ const keyBytes = new Uint8Array(Math.ceil(length / 8));
1216
+ getRandomValues(keyBytes);
1217
+
1218
+ // Create secret key
1219
+ const keyObject = createSecretKey(keyBytes);
1220
+
1221
+ // Construct algorithm object with hash normalized to { name: string } format per WebCrypto spec
1222
+ const webCryptoHashName = normalizeHashName(hash, HashContext.WebCrypto);
1223
+ const keyAlgorithm = {
1224
+ name: 'HMAC',
1225
+ hash: {
1226
+ name: webCryptoHashName
1227
+ },
1228
+ length
1229
+ };
1230
+ return new CryptoKey(keyObject, keyAlgorithm, keyUsages, extractable);
1231
+ }
1232
+ async function kmacGenerateKey(algorithm, extractable, keyUsages) {
1233
+ const {
1234
+ name
1235
+ } = algorithm;
1236
+ if (hasAnyNotIn(keyUsages, ['sign', 'verify'])) {
1237
+ throw lazyDOMException(`Unsupported key usage for ${name} key`, 'SyntaxError');
1238
+ }
1239
+ const defaultLength = name === 'KMAC128' ? 128 : 256;
1240
+ const length = algorithm.length ?? defaultLength;
1241
+ if (length === 0) {
1242
+ throw lazyDOMException('Zero-length key is not supported', 'OperationError');
1243
+ }
1244
+ const keyBytes = new Uint8Array(Math.ceil(length / 8));
1245
+ getRandomValues(keyBytes);
1246
+ const keyObject = createSecretKey(keyBytes);
1247
+ const keyAlgorithm = {
1248
+ name: name,
1249
+ length
1250
+ };
1251
+ return new CryptoKey(keyObject, keyAlgorithm, keyUsages, extractable);
1252
+ }
1253
+ function kmacSignVerify(key, data, algorithm, signature) {
1254
+ const {
1255
+ name
1256
+ } = algorithm;
1257
+
1258
+ // KmacParams.outputLength is required per
1259
+ // https://wicg.github.io/webcrypto-modern-algos/#KmacParams-dictionary
1260
+ // and the rename from `length` (commit ab8dc2b84c2). Mirror Node's
1261
+ // mac.js:213-223 by reading `outputLength` (in bits).
1262
+ if (typeof algorithm.outputLength !== 'number') {
1263
+ throw lazyDOMException(`${name}Params.outputLength is required`, 'OperationError');
1264
+ }
1265
+ const outputLengthBits = algorithm.outputLength;
1266
+ if (outputLengthBits % 8 !== 0) {
1267
+ throw lazyDOMException(`Unsupported ${name}Params outputLength`, 'NotSupportedError');
1268
+ }
1269
+ const outputLengthBytes = outputLengthBits / 8;
1270
+ const keyData = key.keyObject.export();
1271
+ const kmac = NitroModules.createHybridObject('Kmac');
1272
+ let customizationBuffer;
1273
+ if (algorithm.customization !== undefined) {
1274
+ customizationBuffer = bufferLikeToArrayBuffer(algorithm.customization);
1275
+ }
1276
+ kmac.createKmac(name, bufferLikeToArrayBuffer(keyData), outputLengthBytes, customizationBuffer);
1277
+ kmac.update(bufferLikeToArrayBuffer(data));
1278
+ const computed = kmac.digest();
1279
+ if (signature === undefined) {
1280
+ return computed;
1281
+ }
1282
+ const sigBuffer = bufferLikeToArrayBuffer(signature);
1283
+ if (computed.byteLength !== sigBuffer.byteLength) {
1284
+ return false;
1285
+ }
1286
+ return timingSafeEqual(new Uint8Array(computed), new Uint8Array(sigBuffer));
1287
+ }
1288
+ async function kmacImportKey(algorithm, format, data, extractable, keyUsages) {
1289
+ const {
1290
+ name
1291
+ } = algorithm;
1292
+ let keyObject;
1293
+ if (format === 'jwk') {
1294
+ const jwk = data;
1295
+ if (!jwk || typeof jwk !== 'object') {
1296
+ throw lazyDOMException('Invalid keyData', 'DataError');
1297
+ }
1298
+ if (jwk.kty !== 'oct') {
1299
+ throw lazyDOMException('Invalid JWK "kty" Parameter', 'DataError');
1300
+ }
1301
+ validateJwkStructure(jwk, extractable, keyUsages, 'sig');
1302
+ const expectedAlg = name === 'KMAC128' ? 'K128' : 'K256';
1303
+ if (jwk.alg !== undefined && jwk.alg !== expectedAlg) {
1304
+ throw lazyDOMException('JWK "alg" Parameter and algorithm name mismatch', 'DataError');
1305
+ }
1306
+ if (hasAnyNotIn(keyUsages, ['sign', 'verify'])) {
1307
+ throw lazyDOMException(`Unsupported key usage for ${name} key`, 'SyntaxError');
1308
+ }
1309
+ const handle = NitroModules.createHybridObject('KeyObjectHandle');
1310
+ let keyType;
1311
+ try {
1312
+ keyType = handle.initJwk(jwk, undefined);
1313
+ } catch (err) {
1314
+ throw lazyDOMException('Invalid keyData', {
1315
+ name: 'DataError',
1316
+ cause: err
1317
+ });
1318
+ }
1319
+ if (keyType === undefined || keyType !== 0) {
1320
+ throw lazyDOMException('Invalid keyData', 'DataError');
1321
+ }
1322
+ keyObject = new SecretKeyObject(handle);
1323
+ } else if (format === 'raw-secret') {
1324
+ // KMAC accepts only the disambiguated 'raw-secret' form (Node mac.js:141-145
1325
+ // returns undefined for plain 'raw' when not HMAC).
1326
+ if (hasAnyNotIn(keyUsages, ['sign', 'verify'])) {
1327
+ throw lazyDOMException(`Unsupported key usage for ${name} key`, 'SyntaxError');
1328
+ }
1329
+ keyObject = createSecretKey(data);
1330
+ } else {
1331
+ throw lazyDOMException(`Unable to import ${name} key with format ${format}`, 'NotSupportedError');
1332
+ }
1333
+ const exported = keyObject.export();
1334
+ const keyLength = exported.byteLength * 8;
1335
+ if (keyLength === 0) {
1336
+ throw lazyDOMException('Zero-length key is not supported', 'DataError');
1337
+ }
1338
+ if (algorithm.length !== undefined && algorithm.length !== keyLength) {
1339
+ throw lazyDOMException('Invalid key length', 'DataError');
1340
+ }
1341
+ const keyAlgorithm = {
1342
+ name: name,
1343
+ length: keyLength
1344
+ };
1345
+ return new CryptoKey(keyObject, keyAlgorithm, keyUsages, extractable);
1346
+ }
1347
+ function rsaImportKey(format, data, algorithm, extractable, keyUsages) {
1348
+ const {
1349
+ name
1350
+ } = algorithm;
1351
+ let checkSet;
1352
+ switch (name) {
1353
+ case 'RSASSA-PKCS1-v1_5':
1354
+ case 'RSA-PSS':
1355
+ checkSet = ['sign', 'verify'];
1356
+ break;
1357
+ case 'RSA-OAEP':
1358
+ checkSet = ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'];
1359
+ break;
1360
+ default:
1361
+ throw new Error(`Unsupported RSA algorithm: ${name}`);
1362
+ }
1363
+ const checkUsages = () => {
1364
+ if (hasAnyNotIn(keyUsages, checkSet)) {
1365
+ throw lazyDOMException(`Unsupported key usage for ${name} key`, 'SyntaxError');
1366
+ }
1367
+ };
1368
+ let keyObject;
1369
+ if (format === 'jwk') {
1370
+ const jwk = data;
1371
+ if (!jwk || typeof jwk !== 'object') {
1372
+ throw lazyDOMException('Invalid keyData', 'DataError');
1373
+ }
1374
+ if (jwk.kty !== 'RSA') {
1375
+ throw lazyDOMException('Invalid JWK "kty" Parameter', 'DataError');
1376
+ }
1377
+ const expectedUse = name === 'RSA-OAEP' ? 'enc' : 'sig';
1378
+ validateJwkStructure(jwk, extractable, keyUsages, expectedUse);
1379
+ checkUsages();
1380
+ if (jwk.alg !== undefined) {
1381
+ let jwkContext;
1382
+ switch (name) {
1383
+ case 'RSASSA-PKCS1-v1_5':
1384
+ jwkContext = HashContext.JwkRsa;
1385
+ break;
1386
+ case 'RSA-PSS':
1387
+ jwkContext = HashContext.JwkRsaPss;
1388
+ break;
1389
+ default:
1390
+ jwkContext = HashContext.JwkRsaOaep;
1391
+ }
1392
+ const expectedAlg = normalizeHashName(algorithm.hash, jwkContext);
1393
+ if (jwk.alg !== expectedAlg) {
1394
+ throw lazyDOMException('JWK "alg" does not match the requested algorithm', 'DataError');
1395
+ }
1396
+ }
1397
+ const handle = NitroModules.createHybridObject('KeyObjectHandle');
1398
+ let keyType;
1399
+ try {
1400
+ keyType = handle.initJwk(jwk, undefined);
1401
+ } catch (err) {
1402
+ throw lazyDOMException('Invalid keyData', {
1403
+ name: 'DataError',
1404
+ cause: err
1405
+ });
1406
+ }
1407
+ if (keyType === undefined) {
1408
+ throw lazyDOMException('Invalid keyData', 'DataError');
1409
+ }
1410
+ if (keyType === KeyType.PUBLIC) {
1411
+ keyObject = new PublicKeyObject(handle);
1412
+ } else if (keyType === KeyType.PRIVATE) {
1413
+ keyObject = new PrivateKeyObject(handle);
1414
+ } else {
1415
+ throw lazyDOMException('Invalid keyData', 'DataError');
1416
+ }
1417
+ } else if (format === 'spki') {
1418
+ checkUsages();
1419
+ const keyData = bufferLikeToArrayBuffer(data);
1420
+ keyObject = KeyObject.createKeyObject('public', keyData, KFormatType.DER, KeyEncoding.SPKI);
1421
+ } else if (format === 'pkcs8') {
1422
+ checkUsages();
1423
+ const keyData = bufferLikeToArrayBuffer(data);
1424
+ keyObject = KeyObject.createKeyObject('private', keyData, KFormatType.DER, KeyEncoding.PKCS8);
1425
+ } else {
1426
+ throw lazyDOMException(`Unsupported format for ${name} import: ${format}`, 'NotSupportedError');
1427
+ }
1428
+
1429
+ // Get the modulus length from the key and add it to the algorithm
1430
+ const keyDetails = keyObject.asymmetricKeyDetails;
1431
+
1432
+ // Convert publicExponent number to big-endian byte array
1433
+ let publicExponentBytes;
1434
+ if (keyDetails?.publicExponent) {
1435
+ const exp = keyDetails.publicExponent;
1436
+ // Convert number to big-endian bytes
1437
+ const bytes = [];
1438
+ let value = exp;
1439
+ while (value > 0) {
1440
+ bytes.unshift(value & 0xff);
1441
+ value = Math.floor(value / 256);
1442
+ }
1443
+ publicExponentBytes = new Uint8Array(bytes.length > 0 ? bytes : [0]);
1444
+ }
1445
+
1446
+ // Normalize hash to { name: string } format per WebCrypto spec
1447
+ const hashName = normalizeHashName(algorithm.hash, HashContext.WebCrypto);
1448
+ const normalizedHash = {
1449
+ name: hashName
1450
+ };
1451
+ const algorithmWithDetails = {
1452
+ ...algorithm,
1453
+ modulusLength: keyDetails?.modulusLength,
1454
+ publicExponent: publicExponentBytes,
1455
+ hash: normalizedHash
1456
+ };
1457
+ return new CryptoKey(keyObject, algorithmWithDetails, keyUsages, extractable);
1458
+ }
1459
+ async function hmacImportKey(algorithm, format, data, extractable, keyUsages) {
1460
+ const checkUsages = () => {
1461
+ if (hasAnyNotIn(keyUsages, ['sign', 'verify'])) {
1462
+ throw new Error('Unsupported key usage for an HMAC key');
1463
+ }
1464
+ };
1465
+ let keyObject;
1466
+ if (format === 'jwk') {
1467
+ const jwk = data;
1468
+ if (!jwk || typeof jwk !== 'object') {
1469
+ throw new Error('Invalid keyData');
1470
+ }
1471
+ if (jwk.kty !== 'oct') {
1472
+ throw new Error('Invalid JWK format for HMAC key');
1473
+ }
1474
+ validateJwkStructure(jwk, extractable, keyUsages, 'sig');
1475
+ checkUsages();
1476
+ if (algorithm.length !== undefined) {
1477
+ if (!jwk.k) {
1478
+ throw new Error('JWK missing key data');
1479
+ }
1480
+ const decoded = SBuffer.from(jwk.k, 'base64');
1481
+ const keyBitLength = decoded.length * 8;
1482
+ if (algorithm.length === 0) {
1483
+ throw new Error('Zero-length key is not supported');
1484
+ }
1485
+ if (algorithm.length !== keyBitLength) {
1486
+ throw new Error('Invalid key length');
1487
+ }
1488
+ }
1489
+ const handle = NitroModules.createHybridObject('KeyObjectHandle');
1490
+ let keyType;
1491
+ try {
1492
+ keyType = handle.initJwk(jwk, undefined);
1493
+ } catch (err) {
1494
+ throw lazyDOMException('Invalid keyData', {
1495
+ name: 'DataError',
1496
+ cause: err
1497
+ });
1498
+ }
1499
+ if (keyType === undefined || keyType !== 0) {
1500
+ throw lazyDOMException('Invalid keyData', 'DataError');
1501
+ }
1502
+ keyObject = new SecretKeyObject(handle);
1503
+ } else if (format === 'raw' || format === 'raw-secret') {
1504
+ // HMAC accepts both 'raw' and 'raw-secret' (Node mac.js:141-145).
1505
+ checkUsages();
1506
+ keyObject = createSecretKey(data);
1507
+ } else {
1508
+ throw lazyDOMException(`Unable to import HMAC key with format ${format}`, 'NotSupportedError');
1509
+ }
1510
+
1511
+ // Normalize hash to { name: string } format per WebCrypto spec
1512
+ const hashName = normalizeHashName(algorithm.hash, HashContext.WebCrypto);
1513
+ const normalizedAlgorithm = {
1514
+ ...algorithm,
1515
+ name: 'HMAC',
1516
+ hash: {
1517
+ name: hashName
1518
+ }
1519
+ };
1520
+ return new CryptoKey(keyObject, normalizedAlgorithm, keyUsages, extractable);
1521
+ }
1522
+ async function aesImportKey(algorithm, format, data, extractable, keyUsages) {
1523
+ const {
1524
+ name,
1525
+ length
1526
+ } = algorithm;
1527
+ const validUsages = ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'];
1528
+ const checkUsages = () => {
1529
+ if (hasAnyNotIn(keyUsages, validUsages)) {
1530
+ throw new Error(`Unsupported key usage for ${name}`);
1531
+ }
1532
+ };
1533
+
1534
+ // AES-OCB and ChaCha20-Poly1305 require the disambiguated 'raw-secret' form
1535
+ // and reject 'raw' (Node aes.js:243-249, chacha20_poly1305.js:104-134).
1536
+ // Other AES variants accept both 'raw' and 'raw-secret'.
1537
+ const requiresRawSecret = name === 'AES-OCB' || name === 'ChaCha20-Poly1305';
1538
+ const acceptsRaw = format === 'raw-secret' || format === 'raw' && !requiresRawSecret;
1539
+ let keyObject;
1540
+ let actualLength;
1541
+ if (format === 'jwk') {
1542
+ const jwk = data;
1543
+ if (jwk.kty !== 'oct') {
1544
+ throw new Error('Invalid JWK format for AES key');
1545
+ }
1546
+ validateJwkStructure(jwk, extractable, keyUsages, 'enc');
1547
+ checkUsages();
1548
+ const handle = NitroModules.createHybridObject('KeyObjectHandle');
1549
+ let keyType;
1550
+ try {
1551
+ keyType = handle.initJwk(jwk, undefined);
1552
+ } catch (err) {
1553
+ throw lazyDOMException('Invalid keyData', {
1554
+ name: 'DataError',
1555
+ cause: err
1556
+ });
1557
+ }
1558
+ if (keyType === undefined || keyType !== 0) {
1559
+ throw lazyDOMException('Invalid keyData', 'DataError');
1560
+ }
1561
+ keyObject = new SecretKeyObject(handle);
1562
+ const exported = keyObject.export();
1563
+ actualLength = exported.byteLength * 8;
1564
+ } else if (acceptsRaw) {
1565
+ checkUsages();
1566
+ const keyData = bufferLikeToArrayBuffer(data);
1567
+ actualLength = keyData.byteLength * 8;
1568
+ if (name === 'ChaCha20-Poly1305') {
1569
+ if (actualLength !== 256) {
1570
+ throw lazyDOMException('Invalid ChaCha20-Poly1305 key length', 'DataError');
1571
+ }
1572
+ } else if (![128, 192, 256].includes(actualLength)) {
1573
+ throw new Error('Invalid AES key length');
1574
+ }
1575
+ keyObject = createSecretKey(keyData);
1576
+ } else {
1577
+ throw lazyDOMException(`Unable to import ${name} key with format ${format}`, 'NotSupportedError');
1578
+ }
1579
+
1580
+ // Validate length if specified
1581
+ if (length !== undefined && length !== actualLength) {
1582
+ throw new Error(`Key length mismatch: expected ${length}, got ${actualLength}`);
1583
+ }
1584
+ return new CryptoKey(keyObject, {
1585
+ name,
1586
+ length: actualLength
1587
+ }, keyUsages, extractable);
1588
+ }
1589
+ function edImportKey(format, data, algorithm, extractable, keyUsages) {
1590
+ const {
1591
+ name
1592
+ } = algorithm;
1593
+ const isX = name === 'X25519' || name === 'X448';
1594
+ const allowedUsages = isX ? ['deriveKey', 'deriveBits'] : ['sign', 'verify'];
1595
+ const checkUsages = () => {
1596
+ if (hasAnyNotIn(keyUsages, allowedUsages)) {
1597
+ throw lazyDOMException(`Unsupported key usage for ${name} key`, 'SyntaxError');
1598
+ }
1599
+ };
1600
+ let keyObject;
1601
+ if (format === 'spki') {
1602
+ checkUsages();
1603
+ const keyData = bufferLikeToArrayBuffer(data);
1604
+ keyObject = KeyObject.createKeyObject('public', keyData, KFormatType.DER, KeyEncoding.SPKI);
1605
+ } else if (format === 'pkcs8') {
1606
+ checkUsages();
1607
+ const keyData = bufferLikeToArrayBuffer(data);
1608
+ keyObject = KeyObject.createKeyObject('private', keyData, KFormatType.DER, KeyEncoding.PKCS8);
1609
+ } else if (format === 'raw') {
1610
+ checkUsages();
1611
+ const keyData = bufferLikeToArrayBuffer(data);
1612
+ const handle = NitroModules.createHybridObject('KeyObjectHandle');
1613
+ handle.init(1, keyData);
1614
+ keyObject = new PublicKeyObject(handle);
1615
+ } else if (format === 'jwk') {
1616
+ const jwkData = data;
1617
+ if (!jwkData || typeof jwkData !== 'object') {
1618
+ throw lazyDOMException('Invalid keyData', 'DataError');
1619
+ }
1620
+ if (jwkData.kty !== 'OKP') {
1621
+ throw lazyDOMException('Invalid JWK "kty" Parameter', 'DataError');
1622
+ }
1623
+ const expectedUse = isX ? 'enc' : 'sig';
1624
+ validateJwkStructure(jwkData, extractable, keyUsages, expectedUse);
1625
+ if (jwkData.crv !== name) {
1626
+ throw lazyDOMException('JWK "crv" Parameter and algorithm name mismatch', 'DataError');
1627
+ }
1628
+ if (!isX && jwkData.alg !== undefined) {
1629
+ if (jwkData.alg !== name && jwkData.alg !== 'EdDSA') {
1630
+ throw lazyDOMException('JWK "alg" does not match the requested algorithm', 'DataError');
1631
+ }
1632
+ }
1633
+ checkUsages();
1634
+ const handle = NitroModules.createHybridObject('KeyObjectHandle');
1635
+ let keyType;
1636
+ try {
1637
+ keyType = handle.initJwk(jwkData);
1638
+ } catch (err) {
1639
+ throw lazyDOMException('Invalid JWK data', {
1640
+ name: 'DataError',
1641
+ cause: err
1642
+ });
1643
+ }
1644
+ if (keyType === undefined) {
1645
+ throw lazyDOMException('Invalid JWK data', 'DataError');
1646
+ }
1647
+ if (keyType === KeyType.PRIVATE) {
1648
+ keyObject = new PrivateKeyObject(handle);
1649
+ } else {
1650
+ keyObject = new PublicKeyObject(handle);
1651
+ }
1652
+ } else {
1653
+ throw lazyDOMException(`Unsupported format for ${name} import: ${format}`, 'NotSupportedError');
1654
+ }
1655
+ return new CryptoKey(keyObject, {
1656
+ name
1657
+ }, keyUsages, extractable);
1658
+ }
1659
+
1660
+ // Lengths (in bytes) of seedless ML-DSA / ML-KEM PKCS#8 encodings. A PKCS#8
1661
+ // blob of exactly this length contains only the expanded private key with no
1662
+ // seed; Node rejects these to keep cross-implementation interop intact.
1663
+ // Refs: node lib/internal/crypto/ml_dsa.js (mlDsaImportKey, pkcs8 case)
1664
+ // node lib/internal/crypto/ml_kem.js (mlKemImportKey, pkcs8 case)
1665
+ export const PQC_SEEDLESS_PKCS8_LENGTHS = {
1666
+ 'ML-DSA-44': 2588,
1667
+ 'ML-DSA-65': 4060,
1668
+ 'ML-DSA-87': 4924,
1669
+ 'ML-KEM-512': 1660,
1670
+ 'ML-KEM-768': 2428,
1671
+ 'ML-KEM-1024': 3196
1672
+ };
1673
+
1674
+ // Map from PQC algorithm name to display family. Used to render the
1675
+ // import-rejection error message in the same form Node emits.
1676
+ const PQC_FAMILY = {
1677
+ 'ML-DSA-44': 'ML-DSA',
1678
+ 'ML-DSA-65': 'ML-DSA',
1679
+ 'ML-DSA-87': 'ML-DSA',
1680
+ 'ML-KEM-512': 'ML-KEM',
1681
+ 'ML-KEM-768': 'ML-KEM',
1682
+ 'ML-KEM-1024': 'ML-KEM',
1683
+ 'SLH-DSA-SHA2-128s': 'SLH-DSA',
1684
+ 'SLH-DSA-SHA2-128f': 'SLH-DSA',
1685
+ 'SLH-DSA-SHA2-192s': 'SLH-DSA',
1686
+ 'SLH-DSA-SHA2-192f': 'SLH-DSA',
1687
+ 'SLH-DSA-SHA2-256s': 'SLH-DSA',
1688
+ 'SLH-DSA-SHA2-256f': 'SLH-DSA',
1689
+ 'SLH-DSA-SHAKE-128s': 'SLH-DSA',
1690
+ 'SLH-DSA-SHAKE-128f': 'SLH-DSA',
1691
+ 'SLH-DSA-SHAKE-192s': 'SLH-DSA',
1692
+ 'SLH-DSA-SHAKE-192f': 'SLH-DSA',
1693
+ 'SLH-DSA-SHAKE-256s': 'SLH-DSA',
1694
+ 'SLH-DSA-SHAKE-256f': 'SLH-DSA'
1695
+ };
1696
+ function pqcImportKeyObject(format, data, name) {
1697
+ if (format === 'spki') {
1698
+ return {
1699
+ keyObject: KeyObject.createKeyObject('public', bufferLikeToArrayBuffer(data), KFormatType.DER, KeyEncoding.SPKI),
1700
+ isPublic: true
1701
+ };
1702
+ } else if (format === 'pkcs8') {
1703
+ const ab = bufferLikeToArrayBuffer(data);
1704
+ const family = PQC_FAMILY[name];
1705
+ if (family !== undefined && ab.byteLength === PQC_SEEDLESS_PKCS8_LENGTHS[name]) {
1706
+ throw lazyDOMException(`Importing an ${family} PKCS#8 key without a seed is not supported`, 'NotSupportedError');
1707
+ }
1708
+ return {
1709
+ keyObject: KeyObject.createKeyObject('private', ab, KFormatType.DER, KeyEncoding.PKCS8),
1710
+ isPublic: false
1711
+ };
1712
+ } else if (format === 'raw-public') {
1713
+ // ML-DSA / ML-KEM reject plain 'raw' — only 'raw-public' is accepted for
1714
+ // public-key import (Node webcrypto.js:493-499, 506-511).
1715
+ const handle = NitroModules.createHybridObject('KeyObjectHandle');
1716
+ if (!handle.initPqcRaw(name, bufferLikeToArrayBuffer(data), true)) {
1717
+ throw lazyDOMException(`Failed to import ${name} raw public key`, 'DataError');
1718
+ }
1719
+ return {
1720
+ keyObject: new PublicKeyObject(handle),
1721
+ isPublic: true
1722
+ };
1723
+ } else if (format === 'raw-seed') {
1724
+ const handle = NitroModules.createHybridObject('KeyObjectHandle');
1725
+ if (!handle.initPqcRaw(name, bufferLikeToArrayBuffer(data), false)) {
1726
+ throw lazyDOMException(`Failed to import ${name} raw seed`, 'DataError');
1727
+ }
1728
+ return {
1729
+ keyObject: new PrivateKeyObject(handle),
1730
+ isPublic: false
1731
+ };
1732
+ } else if (format === 'jwk') {
1733
+ const jwkData = data;
1734
+ const isPublic = jwkData.priv === undefined;
1735
+ const handle = NitroModules.createHybridObject('KeyObjectHandle');
1736
+ let keyType;
1737
+ try {
1738
+ keyType = handle.initJwk(jwkData);
1739
+ } catch (err) {
1740
+ throw lazyDOMException('Invalid JWK data', {
1741
+ name: 'DataError',
1742
+ cause: err
1743
+ });
1744
+ }
1745
+ if (keyType === undefined) {
1746
+ throw lazyDOMException('Invalid JWK data', 'DataError');
1747
+ }
1748
+ return {
1749
+ keyObject: isPublic ? new PublicKeyObject(handle) : new PrivateKeyObject(handle),
1750
+ isPublic
1751
+ };
1752
+ }
1753
+ throw lazyDOMException(`Unsupported format for ${name} import: ${format}`, 'NotSupportedError');
1754
+ }
1755
+
1756
+ // Per WebCrypto AKP JWK rules, public-vs-private is determined by the presence
1757
+ // of `priv`. For binary formats it follows from the format itself.
1758
+ function pqcIsPublicImport(format, data) {
1759
+ if (format === 'jwk') {
1760
+ return typeof data === 'object' && data !== null && data.priv === undefined;
1761
+ }
1762
+ return format === 'spki' || format === 'raw-public';
1763
+ }
1764
+ function validatePqcJwk(data, name, extractable, keyUsages, expectedUse) {
1765
+ if (typeof data !== 'object' || data === null) {
1766
+ throw lazyDOMException('Invalid keyData', 'DataError');
1767
+ }
1768
+ const jwk = data;
1769
+ if (jwk.kty !== 'AKP') {
1770
+ throw lazyDOMException('Invalid JWK "kty" Parameter', 'DataError');
1771
+ }
1772
+ validateJwkStructure(jwk, extractable, keyUsages, expectedUse);
1773
+ if (jwk.alg !== name) {
1774
+ throw lazyDOMException('JWK "alg" Parameter and algorithm name mismatch', 'DataError');
1775
+ }
1776
+ }
1777
+
1778
+ // Validates that `format` is one of the formats PQC algorithms accept; rejects
1779
+ // plain 'raw' early so the format error wins over usage-based errors.
1780
+ function validatePqcFormat(format, name) {
1781
+ if (format !== 'spki' && format !== 'pkcs8' && format !== 'raw-public' && format !== 'raw-seed' && format !== 'jwk') {
1782
+ throw lazyDOMException(`Unsupported format for ${name} import: ${format}`, 'NotSupportedError');
1783
+ }
1784
+ }
1785
+ function mldsaImportKey(format, data, algorithm, extractable, keyUsages) {
1786
+ const {
1787
+ name
1788
+ } = algorithm;
1789
+ validatePqcFormat(format, name);
1790
+ if (format === 'jwk') {
1791
+ validatePqcJwk(data, name, extractable, keyUsages, 'sig');
1792
+ }
1793
+ const isPublic = pqcIsPublicImport(format, data);
1794
+ if (hasAnyNotIn(keyUsages, isPublic ? ['verify'] : ['sign'])) {
1795
+ throw lazyDOMException(`Unsupported key usage for ${name} key`, 'SyntaxError');
1796
+ }
1797
+ const {
1798
+ keyObject
1799
+ } = pqcImportKeyObject(format, data, name);
1800
+ return new CryptoKey(keyObject, {
1801
+ name
1802
+ }, keyUsages, extractable);
1803
+ }
1804
+ function slhdsaImportKey(format, data, algorithm, extractable, keyUsages) {
1805
+ return mldsaImportKey(format, data, algorithm, extractable, keyUsages);
1806
+ }
1807
+ function mlkemImportKey(format, data, algorithm, extractable, keyUsages) {
1808
+ const {
1809
+ name
1810
+ } = algorithm;
1811
+ validatePqcFormat(format, name);
1812
+ if (format === 'jwk') {
1813
+ validatePqcJwk(data, name, extractable, keyUsages, 'enc');
1814
+ }
1815
+ const isPublic = pqcIsPublicImport(format, data);
1816
+ const allowedUsages = isPublic ? ['encapsulateBits', 'encapsulateKey'] : ['decapsulateBits', 'decapsulateKey'];
1817
+ if (hasAnyNotIn(keyUsages, allowedUsages)) {
1818
+ throw lazyDOMException(`Unsupported key usage for ${name} key`, 'SyntaxError');
1819
+ }
1820
+ const {
1821
+ keyObject
1822
+ } = pqcImportKeyObject(format, data, name);
1823
+ return new CryptoKey(keyObject, {
1824
+ name
1825
+ }, keyUsages, extractable);
1826
+ }
1827
+ const exportKeySpki = async key => {
1828
+ switch (key.algorithm.name) {
1829
+ case 'RSASSA-PKCS1-v1_5':
1830
+ // Fall through
1831
+ case 'RSA-PSS':
1832
+ // Fall through
1833
+ case 'RSA-OAEP':
1834
+ if (key.type === 'public') {
1835
+ return rsaExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatSPKI);
1836
+ }
1837
+ break;
1838
+ case 'ECDSA':
1839
+ // Fall through
1840
+ case 'ECDH':
1841
+ if (key.type === 'public') {
1842
+ return ecExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatSPKI);
1843
+ }
1844
+ break;
1845
+ case 'Ed25519':
1846
+ // Fall through
1847
+ case 'Ed448':
1848
+ // Fall through
1849
+ case 'X25519':
1850
+ // Fall through
1851
+ case 'X448':
1852
+ if (key.type === 'public') {
1853
+ // Export Ed/X key in SPKI DER format
1854
+ return bufferLikeToArrayBuffer(key.keyObject.handle.exportKey(KFormatType.DER, KeyEncoding.SPKI));
1855
+ }
1856
+ break;
1857
+ case 'ML-DSA-44':
1858
+ // Fall through
1859
+ case 'ML-DSA-65':
1860
+ // Fall through
1861
+ case 'ML-DSA-87':
1862
+ // Fall through
1863
+ case 'SLH-DSA-SHA2-128s':
1864
+ case 'SLH-DSA-SHA2-128f':
1865
+ case 'SLH-DSA-SHA2-192s':
1866
+ case 'SLH-DSA-SHA2-192f':
1867
+ case 'SLH-DSA-SHA2-256s':
1868
+ case 'SLH-DSA-SHA2-256f':
1869
+ case 'SLH-DSA-SHAKE-128s':
1870
+ case 'SLH-DSA-SHAKE-128f':
1871
+ case 'SLH-DSA-SHAKE-192s':
1872
+ case 'SLH-DSA-SHAKE-192f':
1873
+ case 'SLH-DSA-SHAKE-256s':
1874
+ case 'SLH-DSA-SHAKE-256f':
1875
+ if (key.type === 'public') {
1876
+ // Export ML-DSA / SLH-DSA key in SPKI DER format
1877
+ return bufferLikeToArrayBuffer(key.keyObject.handle.exportKey(KFormatType.DER, KeyEncoding.SPKI));
1878
+ }
1879
+ break;
1880
+ case 'ML-KEM-512':
1881
+ // Fall through
1882
+ case 'ML-KEM-768':
1883
+ // Fall through
1884
+ case 'ML-KEM-1024':
1885
+ if (key.type === 'public') {
1886
+ return bufferLikeToArrayBuffer(key.keyObject.handle.exportKey(KFormatType.DER, KeyEncoding.SPKI));
1887
+ }
1888
+ break;
1889
+ }
1890
+ throw new Error(`Unable to export a spki ${key.algorithm.name} ${key.type} key`);
1891
+ };
1892
+ const exportKeyPkcs8 = async key => {
1893
+ switch (key.algorithm.name) {
1894
+ case 'RSASSA-PKCS1-v1_5':
1895
+ // Fall through
1896
+ case 'RSA-PSS':
1897
+ // Fall through
1898
+ case 'RSA-OAEP':
1899
+ if (key.type === 'private') {
1900
+ return rsaExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatPKCS8);
1901
+ }
1902
+ break;
1903
+ case 'ECDSA':
1904
+ // Fall through
1905
+ case 'ECDH':
1906
+ if (key.type === 'private') {
1907
+ return ecExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatPKCS8);
1908
+ }
1909
+ break;
1910
+ case 'Ed25519':
1911
+ // Fall through
1912
+ case 'Ed448':
1913
+ // Fall through
1914
+ case 'X25519':
1915
+ // Fall through
1916
+ case 'X448':
1917
+ if (key.type === 'private') {
1918
+ // Export Ed/X key in PKCS8 DER format
1919
+ return bufferLikeToArrayBuffer(key.keyObject.handle.exportKey(KFormatType.DER, KeyEncoding.PKCS8));
1920
+ }
1921
+ break;
1922
+ case 'ML-DSA-44':
1923
+ // Fall through
1924
+ case 'ML-DSA-65':
1925
+ // Fall through
1926
+ case 'ML-DSA-87':
1927
+ // Fall through
1928
+ case 'ML-KEM-512':
1929
+ // Fall through
1930
+ case 'ML-KEM-768':
1931
+ // Fall through
1932
+ case 'ML-KEM-1024':
1933
+ if (key.type === 'private') {
1934
+ const ab = bufferLikeToArrayBuffer(key.keyObject.handle.exportKey(KFormatType.DER, KeyEncoding.PKCS8));
1935
+ // 22 bytes of PKCS#8 ASN.1 + seed (32 ML-DSA, 64 ML-KEM). Guards
1936
+ // against a seedless KeyObject that was wrapped via toCryptoKey.
1937
+ const expected = key.algorithm.name.startsWith('ML-DSA') ? 54 : 86;
1938
+ if (ab.byteLength !== expected) {
1939
+ throw lazyDOMException('The operation failed for an operation-specific reason', 'OperationError');
1940
+ }
1941
+ return ab;
1942
+ }
1943
+ break;
1944
+ case 'SLH-DSA-SHA2-128s':
1945
+ case 'SLH-DSA-SHA2-128f':
1946
+ case 'SLH-DSA-SHA2-192s':
1947
+ case 'SLH-DSA-SHA2-192f':
1948
+ case 'SLH-DSA-SHA2-256s':
1949
+ case 'SLH-DSA-SHA2-256f':
1950
+ case 'SLH-DSA-SHAKE-128s':
1951
+ case 'SLH-DSA-SHAKE-128f':
1952
+ case 'SLH-DSA-SHAKE-192s':
1953
+ case 'SLH-DSA-SHAKE-192f':
1954
+ case 'SLH-DSA-SHAKE-256s':
1955
+ case 'SLH-DSA-SHAKE-256f':
1956
+ if (key.type === 'private') {
1957
+ return bufferLikeToArrayBuffer(key.keyObject.handle.exportKey(KFormatType.DER, KeyEncoding.PKCS8));
1958
+ }
1959
+ break;
1960
+ }
1961
+ throw new Error(`Unable to export a pkcs8 ${key.algorithm.name} ${key.type} key`);
1962
+ };
1963
+
1964
+ // Mirrors Node's export key matrix (lib/internal/crypto/webcrypto.js
1965
+ // exportKeyRawSecret / exportKeyRawPublic, lines 472-563):
1966
+ //
1967
+ // raw — AES-CTR/CBC/GCM/KW + HMAC (secret); ECDSA/ECDH/Ed/X (public)
1968
+ // raw-secret — AES-CTR/CBC/GCM/KW + HMAC + AES-OCB + KMAC + ChaCha20-Poly1305
1969
+ // raw-public — ECDSA/ECDH + Ed/X + ML-DSA + ML-KEM (public)
1970
+ const exportKeyRaw = (key, format) => {
1971
+ const name = key.algorithm.name;
1972
+ const isPublic = key.type === 'public';
1973
+ const isSecret = key.type === 'secret';
1974
+ const exportSecret = () => {
1975
+ const exported = key.keyObject.export();
1976
+ return exported.buffer.slice(exported.byteOffset, exported.byteOffset + exported.byteLength);
1977
+ };
1978
+ const exportRawPublic = () => bufferLikeToArrayBuffer(key.keyObject.handle.exportKey());
1979
+ const fail = () => {
1980
+ throw lazyDOMException(`Unable to export ${name} ${key.type} key using ${format} format`, 'NotSupportedError');
1981
+ };
1982
+
1983
+ // Symmetric: AES-CTR/CBC/GCM/KW and HMAC accept both 'raw' and 'raw-secret';
1984
+ // AES-OCB / KMAC* / ChaCha20-Poly1305 only 'raw-secret'.
1985
+ switch (name) {
1986
+ case 'AES-CTR':
1987
+ case 'AES-CBC':
1988
+ case 'AES-GCM':
1989
+ case 'AES-KW':
1990
+ case 'HMAC':
1991
+ if (!isSecret) return fail();
1992
+ if (format === 'raw' || format === 'raw-secret') return exportSecret();
1993
+ return fail();
1994
+ case 'AES-OCB':
1995
+ case 'KMAC128':
1996
+ case 'KMAC256':
1997
+ case 'ChaCha20-Poly1305':
1998
+ if (!isSecret) return fail();
1999
+ if (format === 'raw-secret') return exportSecret();
2000
+ return fail();
2001
+ case 'ECDSA':
2002
+ case 'ECDH':
2003
+ if (!isPublic) return fail();
2004
+ if (format === 'raw' || format === 'raw-public') {
2005
+ return ecExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatRaw);
2006
+ }
2007
+ return fail();
2008
+ case 'Ed25519':
2009
+ case 'Ed448':
2010
+ case 'X25519':
2011
+ case 'X448':
2012
+ if (!isPublic) return fail();
2013
+ if (format === 'raw' || format === 'raw-public') return exportRawPublic();
2014
+ return fail();
2015
+ case 'ML-DSA-44':
2016
+ case 'ML-DSA-65':
2017
+ case 'ML-DSA-87':
2018
+ case 'ML-KEM-512':
2019
+ case 'ML-KEM-768':
2020
+ case 'ML-KEM-1024':
2021
+ case 'SLH-DSA-SHA2-128s':
2022
+ case 'SLH-DSA-SHA2-128f':
2023
+ case 'SLH-DSA-SHA2-192s':
2024
+ case 'SLH-DSA-SHA2-192f':
2025
+ case 'SLH-DSA-SHA2-256s':
2026
+ case 'SLH-DSA-SHA2-256f':
2027
+ case 'SLH-DSA-SHAKE-128s':
2028
+ case 'SLH-DSA-SHAKE-128f':
2029
+ case 'SLH-DSA-SHAKE-192s':
2030
+ case 'SLH-DSA-SHAKE-192f':
2031
+ case 'SLH-DSA-SHAKE-256s':
2032
+ case 'SLH-DSA-SHAKE-256f':
2033
+ // ML-DSA / ML-KEM / SLH-DSA keys do not recognize plain 'raw' (Node
2034
+ // webcrypto.js lines 488-510).
2035
+ if (!isPublic) return fail();
2036
+ if (format === 'raw-public') return exportRawPublic();
2037
+ return fail();
2038
+ }
2039
+ return fail();
2040
+ };
2041
+ const exportKeyJWK = key => {
2042
+ const jwk = key.keyObject.handle.exportJwk({
2043
+ key_ops: [...key.usages],
2044
+ ext: key.extractable
2045
+ }, true);
2046
+ switch (key.algorithm.name) {
2047
+ case 'RSASSA-PKCS1-v1_5':
2048
+ jwk.alg = normalizeHashName(key.algorithm.hash, HashContext.JwkRsa);
2049
+ return jwk;
2050
+ case 'RSA-PSS':
2051
+ jwk.alg = normalizeHashName(key.algorithm.hash, HashContext.JwkRsaPss);
2052
+ return jwk;
2053
+ case 'RSA-OAEP':
2054
+ jwk.alg = normalizeHashName(key.algorithm.hash, HashContext.JwkRsaOaep);
2055
+ return jwk;
2056
+ case 'HMAC':
2057
+ jwk.alg = normalizeHashName(key.algorithm.hash, HashContext.JwkHmac);
2058
+ return jwk;
2059
+ case 'KMAC128':
2060
+ jwk.alg = 'K128';
2061
+ return jwk;
2062
+ case 'KMAC256':
2063
+ jwk.alg = 'K256';
2064
+ return jwk;
2065
+ case 'ECDSA':
2066
+ // Fall through
2067
+ case 'ECDH':
2068
+ jwk.crv ||= key.algorithm.namedCurve;
2069
+ return jwk;
2070
+ case 'Ed25519':
2071
+ // Fall through
2072
+ case 'Ed448':
2073
+ // Fall through
2074
+ case 'X25519':
2075
+ // Fall through
2076
+ case 'X448':
2077
+ return jwk;
2078
+ case 'ML-DSA-44':
2079
+ // Fall through
2080
+ case 'ML-DSA-65':
2081
+ // Fall through
2082
+ case 'ML-DSA-87':
2083
+ // Fall through
2084
+ case 'ML-KEM-512':
2085
+ // Fall through
2086
+ case 'ML-KEM-768':
2087
+ // Fall through
2088
+ case 'ML-KEM-1024':
2089
+ // Fall through
2090
+ case 'SLH-DSA-SHA2-128s':
2091
+ case 'SLH-DSA-SHA2-128f':
2092
+ case 'SLH-DSA-SHA2-192s':
2093
+ case 'SLH-DSA-SHA2-192f':
2094
+ case 'SLH-DSA-SHA2-256s':
2095
+ case 'SLH-DSA-SHA2-256f':
2096
+ case 'SLH-DSA-SHAKE-128s':
2097
+ case 'SLH-DSA-SHAKE-128f':
2098
+ case 'SLH-DSA-SHAKE-192s':
2099
+ case 'SLH-DSA-SHAKE-192f':
2100
+ case 'SLH-DSA-SHAKE-256s':
2101
+ case 'SLH-DSA-SHAKE-256f':
2102
+ return jwk;
2103
+ case 'AES-CTR':
2104
+ // Fall through
2105
+ case 'AES-CBC':
2106
+ // Fall through
2107
+ case 'AES-GCM':
2108
+ // Fall through
2109
+ case 'AES-KW':
2110
+ // Fall through
2111
+ case 'AES-OCB':
2112
+ // Fall through
2113
+ case 'ChaCha20-Poly1305':
2114
+ if (key.algorithm.length === undefined) {
2115
+ throw lazyDOMException(`Algorithm ${key.algorithm.name} missing required length property`, 'InvalidAccessError');
2116
+ }
2117
+ jwk.alg = getAlgorithmName(key.algorithm.name, key.algorithm.length);
2118
+ return jwk;
2119
+ default:
2120
+ // Fall through
2121
+ }
2122
+ throw lazyDOMException(`JWK export not yet supported: ${key.algorithm.name}`, 'NotSupportedError');
2123
+ };
2124
+
2125
+ // PBKDF2 import. Mirrors Node's importGenericSecretKey ordering
2126
+ // (keys.js:945-971): extractable → usage → format → length. Callers pre-alias
2127
+ // 'raw-secret' / 'raw-public' to 'raw' via aliasKeyFormat
2128
+ // (webcrypto.js:798-808).
2129
+ const pbkdf2ImportKey = async ({
2130
+ name,
2131
+ length
2132
+ }, format, keyData, extractable, keyUsages) => {
2133
+ if (extractable) {
2134
+ throw lazyDOMException(`${name} keys are not extractable`, 'SyntaxError');
2135
+ }
2136
+ if (hasAnyNotIn(keyUsages, ['deriveKey', 'deriveBits'])) {
2137
+ throw lazyDOMException(`Unsupported key usage for a ${name} key`, 'SyntaxError');
2138
+ }
2139
+ if (format !== 'raw') {
2140
+ throw lazyDOMException(`Unable to import ${name} key with format ${format}`, 'NotSupportedError');
2141
+ }
2142
+ const checkLength = typeof keyData === 'string' || SBuffer.isBuffer(keyData) ? keyData.length * 8 : keyData.byteLength * 8;
2143
+ if (length !== undefined && length !== checkLength) {
2144
+ throw lazyDOMException('Invalid key length', 'DataError');
2145
+ }
2146
+ const keyObject = createSecretKey(keyData);
2147
+ return new CryptoKey(keyObject, {
2148
+ name
2149
+ }, keyUsages, false);
2150
+ };
2151
+
2152
+ // Argon2 import. Node gates the format at the dispatcher level — only
2153
+ // 'raw-secret' enters importGenericSecretKey (webcrypto.js:813-822). To match
2154
+ // that, format is the first check here; remaining ordering matches Node's
2155
+ // importGenericSecretKey.
2156
+ const argon2ImportKey = async ({
2157
+ name,
2158
+ length
2159
+ }, format, keyData, extractable, keyUsages) => {
2160
+ if (format !== 'raw-secret') {
2161
+ throw lazyDOMException(`Unable to import ${name} key with format ${format}`, 'NotSupportedError');
2162
+ }
2163
+ if (extractable) {
2164
+ throw lazyDOMException(`${name} keys are not extractable`, 'SyntaxError');
2165
+ }
2166
+ if (hasAnyNotIn(keyUsages, ['deriveKey', 'deriveBits'])) {
2167
+ throw lazyDOMException(`Unsupported key usage for a ${name} key`, 'SyntaxError');
2168
+ }
2169
+ const checkLength = typeof keyData === 'string' || SBuffer.isBuffer(keyData) ? keyData.length * 8 : keyData.byteLength * 8;
2170
+ if (length !== undefined && length !== checkLength) {
2171
+ throw lazyDOMException('Invalid key length', 'DataError');
2172
+ }
2173
+ const keyObject = createSecretKey(keyData);
2174
+ return new CryptoKey(keyObject, {
2175
+ name
2176
+ }, keyUsages, false);
2177
+ };
2178
+ const hkdfImportKey = async (format, keyData, algorithm, extractable, keyUsages) => {
2179
+ const {
2180
+ name
2181
+ } = algorithm;
2182
+ // WebCrypto §28.7.6: HKDF keys are never extractable. The previous
2183
+ // implementation passed `extractable` through verbatim, allowing callers
2184
+ // to round-trip the input keying material via `exportKey` — defeating
2185
+ // the whole point of the deriveBits-only usage.
2186
+ if (extractable) {
2187
+ throw lazyDOMException(`${name} keys are not extractable`, 'SyntaxError');
2188
+ }
2189
+ if (hasAnyNotIn(keyUsages, ['deriveKey', 'deriveBits'])) {
2190
+ throw new Error(`Unsupported key usage for a ${name} key`);
2191
+ }
2192
+ switch (format) {
2193
+ case 'raw':
2194
+ {
2195
+ const keyObject = createSecretKey(keyData);
2196
+ return new CryptoKey(keyObject, {
2197
+ name
2198
+ }, keyUsages, false);
2199
+ }
2200
+ default:
2201
+ throw new Error(`Unable to import ${name} key with format ${format}`);
2202
+ }
2203
+ };
2204
+ const checkCryptoKeyPairUsages = pair => {
2205
+ if (pair.privateKey && pair.privateKey instanceof CryptoKey && pair.privateKey.keyUsages && pair.privateKey.keyUsages.length > 0) {
2206
+ return;
2207
+ }
2208
+ throw lazyDOMException('Usages cannot be empty when creating a key.', 'SyntaxError');
2209
+ };
2210
+ function argon2DeriveBits(algorithm, baseKey, length) {
2211
+ if (length === 0 || length % 8 !== 0) {
2212
+ throw lazyDOMException('Invalid Argon2 derived key length', 'OperationError');
2213
+ }
2214
+ if (length < 32) {
2215
+ throw lazyDOMException('Argon2 derived key length must be at least 32 bits', 'OperationError');
2216
+ }
2217
+ const {
2218
+ nonce,
2219
+ parallelism,
2220
+ memory,
2221
+ passes,
2222
+ secretValue,
2223
+ associatedData
2224
+ } = algorithm;
2225
+ const tagLength = length / 8;
2226
+ const message = baseKey.keyObject.export();
2227
+ const algName = algorithm.name.toLowerCase();
2228
+ const result = argon2Sync(algName, {
2229
+ message,
2230
+ nonce: nonce ?? new Uint8Array(0),
2231
+ parallelism: parallelism ?? 1,
2232
+ tagLength,
2233
+ memory: memory ?? 65536,
2234
+ passes: passes ?? 3,
2235
+ secret: secretValue,
2236
+ associatedData,
2237
+ version: algorithm.version
2238
+ });
2239
+ return bufferLikeToArrayBuffer(result);
2240
+ }
2241
+
2242
+ // Type guard to check if result is CryptoKeyPair
2243
+ export function isCryptoKeyPair(result) {
2244
+ return 'publicKey' in result && 'privateKey' in result;
2245
+ }
2246
+ function hmacSignVerify(key, data, signature) {
2247
+ // Get hash algorithm from key
2248
+ const hashName = normalizeHashName(key.algorithm.hash);
2249
+
2250
+ // Export the secret key material
2251
+ const keyData = key.keyObject.export();
2252
+
2253
+ // Create HMAC and compute digest
2254
+ const hmac = createHmac(hashName, keyData);
2255
+ hmac.update(bufferLikeToArrayBuffer(data));
2256
+ const computed = hmac.digest();
2257
+ if (signature === undefined) {
2258
+ // Sign operation - return the HMAC as ArrayBuffer
2259
+ return computed.buffer.slice(computed.byteOffset, computed.byteOffset + computed.byteLength);
2260
+ }
2261
+ const sigBuffer = bufferLikeToArrayBuffer(signature);
2262
+ const computedBuffer = computed.buffer.slice(computed.byteOffset, computed.byteOffset + computed.byteLength);
2263
+ if (computedBuffer.byteLength !== sigBuffer.byteLength) {
2264
+ return false;
2265
+ }
2266
+ return timingSafeEqual(new Uint8Array(computedBuffer), new Uint8Array(sigBuffer));
2267
+ }
2268
+ function rsaSignVerify(key, data, padding, signature, saltLength) {
2269
+ // Get hash algorithm from key
2270
+ const hashName = normalizeHashName(key.algorithm.hash);
2271
+
2272
+ // Determine RSA padding constant
2273
+ const RSA_PKCS1_PADDING = 1;
2274
+ const RSA_PKCS1_PSS_PADDING = 6;
2275
+ const paddingValue = padding === 'pss' ? RSA_PKCS1_PSS_PADDING : RSA_PKCS1_PADDING;
2276
+ if (signature === undefined) {
2277
+ // Sign operation
2278
+ const signer = createSign(hashName);
2279
+ signer.update(data);
2280
+ const sig = signer.sign({
2281
+ key: key,
2282
+ padding: paddingValue,
2283
+ saltLength
2284
+ });
2285
+ return sig.buffer.slice(sig.byteOffset, sig.byteOffset + sig.byteLength);
2286
+ }
2287
+
2288
+ // Verify operation
2289
+ const verifier = createVerify(hashName);
2290
+ verifier.update(data);
2291
+ return verifier.verify({
2292
+ key: key,
2293
+ padding: paddingValue,
2294
+ saltLength
2295
+ }, signature);
2296
+ }
2297
+ function edSignVerify(key, data, signature) {
2298
+ const isSign = signature === undefined;
2299
+ const expectedKeyType = isSign ? 'private' : 'public';
2300
+ if (key.type !== expectedKeyType) {
2301
+ throw lazyDOMException(`Key must be a ${expectedKeyType} key`, 'InvalidAccessError');
2302
+ }
2303
+
2304
+ // Get curve type from algorithm name (Ed25519 or Ed448)
2305
+ const algorithmName = key.algorithm.name;
2306
+ const curveType = algorithmName.toLowerCase();
2307
+
2308
+ // Create Ed instance with the curve
2309
+ const ed = new Ed(curveType, {});
2310
+
2311
+ // Export raw key bytes (exportKey with no format returns raw for Ed keys)
2312
+ const rawKey = key.keyObject.handle.exportKey();
2313
+ const dataBuffer = bufferLikeToArrayBuffer(data);
2314
+ if (isSign) {
2315
+ // Sign operation - use raw private key
2316
+ const sig = ed.signSync(dataBuffer, rawKey);
2317
+ return sig;
2318
+ } else {
2319
+ // Verify operation - use raw public key
2320
+ const signatureBuffer = bufferLikeToArrayBuffer(signature);
2321
+ return ed.verifySync(signatureBuffer, dataBuffer, rawKey);
2322
+ }
2323
+ }
2324
+ function mldsaSignVerify(key, data, signature) {
2325
+ const isSign = signature === undefined;
2326
+ const expectedKeyType = isSign ? 'private' : 'public';
2327
+ if (key.type !== expectedKeyType) {
2328
+ throw lazyDOMException(`Key must be a ${expectedKeyType} key`, 'InvalidAccessError');
2329
+ }
2330
+ const dataBuffer = bufferLikeToArrayBuffer(data);
2331
+ if (isSign) {
2332
+ const signer = createSign('');
2333
+ signer.update(dataBuffer);
2334
+ const sig = signer.sign({
2335
+ key: key
2336
+ });
2337
+ return sig.buffer.slice(sig.byteOffset, sig.byteOffset + sig.byteLength);
2338
+ } else {
2339
+ const signatureBuffer = bufferLikeToArrayBuffer(signature);
2340
+ const verifier = createVerify('');
2341
+ verifier.update(dataBuffer);
2342
+ return verifier.verify({
2343
+ key: key
2344
+ }, signatureBuffer);
2345
+ }
2346
+ }
2347
+ const signVerify = (algorithm, key, data, signature) => {
2348
+ const usage = signature === undefined ? 'sign' : 'verify';
2349
+ algorithm = normalizeAlgorithm(algorithm, usage);
2350
+ if (algorithm.name !== key.algorithm.name) {
2351
+ throw lazyDOMException('Key algorithm mismatch', 'InvalidAccessError');
2352
+ }
2353
+ if (!key.usages.includes(usage)) {
2354
+ throw lazyDOMException(`Unable to use this key to ${usage}`, 'InvalidAccessError');
2355
+ }
2356
+ switch (algorithm.name) {
2357
+ case 'ECDSA':
2358
+ return ecdsaSignVerify(key, data, algorithm, signature);
2359
+ case 'HMAC':
2360
+ return hmacSignVerify(key, data, signature);
2361
+ case 'RSASSA-PKCS1-v1_5':
2362
+ return rsaSignVerify(key, data, 'pkcs1', signature);
2363
+ case 'RSA-PSS':
2364
+ return rsaSignVerify(key, data, 'pss', signature, algorithm.saltLength);
2365
+ case 'Ed25519':
2366
+ case 'Ed448':
2367
+ return edSignVerify(key, data, signature);
2368
+ case 'ML-DSA-44':
2369
+ case 'ML-DSA-65':
2370
+ case 'ML-DSA-87':
2371
+ case 'SLH-DSA-SHA2-128s':
2372
+ case 'SLH-DSA-SHA2-128f':
2373
+ case 'SLH-DSA-SHA2-192s':
2374
+ case 'SLH-DSA-SHA2-192f':
2375
+ case 'SLH-DSA-SHA2-256s':
2376
+ case 'SLH-DSA-SHA2-256f':
2377
+ case 'SLH-DSA-SHAKE-128s':
2378
+ case 'SLH-DSA-SHAKE-128f':
2379
+ case 'SLH-DSA-SHAKE-192s':
2380
+ case 'SLH-DSA-SHAKE-192f':
2381
+ case 'SLH-DSA-SHAKE-256s':
2382
+ case 'SLH-DSA-SHAKE-256f':
2383
+ return mldsaSignVerify(key, data, signature);
2384
+ case 'KMAC128':
2385
+ case 'KMAC256':
2386
+ return kmacSignVerify(key, data, algorithm, signature);
2387
+ }
2388
+ throw lazyDOMException(`Unrecognized algorithm name '${algorithm.name}' for '${usage}'`, 'NotSupportedError');
2389
+ };
2390
+
2391
+ // Algorithm-mismatch and usage checks live at the public-method call sites
2392
+ // (encrypt / decrypt / wrapKey / unwrapKey) so spec-mandated message and
2393
+ // ordering — algorithm-mismatch first, then usage — is preserved
2394
+ // (Node webcrypto.js, commit 4cb1f284136).
2395
+ const cipherOrWrap = async (mode, algorithm, key, data) => {
2396
+ validateMaxBufferLength(data, 'data');
2397
+ switch (algorithm.name) {
2398
+ case 'RSA-OAEP':
2399
+ return rsaCipher(mode, key, data, algorithm);
2400
+ case 'AES-CTR':
2401
+ // Fall through
2402
+ case 'AES-CBC':
2403
+ // Fall through
2404
+ case 'AES-GCM':
2405
+ // Fall through
2406
+ case 'AES-OCB':
2407
+ return aesCipher(mode, key, data, algorithm);
2408
+ case 'AES-KW':
2409
+ return aesKwCipher(mode, key, data);
2410
+ case 'ChaCha20-Poly1305':
2411
+ return chaCha20Poly1305Cipher(mode, key, data, algorithm);
2412
+ }
2413
+ };
2414
+ const SUPPORTED_ALGORITHMS = {
2415
+ encrypt: new Set(['RSA-OAEP', 'AES-CTR', 'AES-CBC', 'AES-GCM', 'AES-OCB', 'ChaCha20-Poly1305']),
2416
+ decrypt: new Set(['RSA-OAEP', 'AES-CTR', 'AES-CBC', 'AES-GCM', 'AES-OCB', 'ChaCha20-Poly1305']),
2417
+ sign: new Set(['RSASSA-PKCS1-v1_5', 'RSA-PSS', 'ECDSA', 'HMAC', 'KMAC128', 'KMAC256', 'Ed25519', 'Ed448', 'ML-DSA-44', 'ML-DSA-65', 'ML-DSA-87', ...SLH_DSA_VARIANTS]),
2418
+ verify: new Set(['RSASSA-PKCS1-v1_5', 'RSA-PSS', 'ECDSA', 'HMAC', 'KMAC128', 'KMAC256', 'Ed25519', 'Ed448', 'ML-DSA-44', 'ML-DSA-65', 'ML-DSA-87', ...SLH_DSA_VARIANTS]),
2419
+ digest: new Set(['SHA-1', 'SHA-256', 'SHA-384', 'SHA-512', 'SHA3-256', 'SHA3-384', 'SHA3-512', 'cSHAKE128', 'cSHAKE256', 'TurboSHAKE128', 'TurboSHAKE256', 'KT128', 'KT256']),
2420
+ generateKey: new Set(['RSASSA-PKCS1-v1_5', 'RSA-PSS', 'RSA-OAEP', 'ECDSA', 'ECDH', 'Ed25519', 'Ed448', 'X25519', 'X448', 'AES-CTR', 'AES-CBC', 'AES-GCM', 'AES-KW', 'AES-OCB', 'ChaCha20-Poly1305', 'HMAC', 'KMAC128', 'KMAC256', 'ML-DSA-44', 'ML-DSA-65', 'ML-DSA-87', 'ML-KEM-512', 'ML-KEM-768', 'ML-KEM-1024', ...SLH_DSA_VARIANTS]),
2421
+ importKey: new Set(['RSASSA-PKCS1-v1_5', 'RSA-PSS', 'RSA-OAEP', 'ECDSA', 'ECDH', 'Ed25519', 'Ed448', 'X25519', 'X448', 'AES-CTR', 'AES-CBC', 'AES-GCM', 'AES-KW', 'AES-OCB', 'ChaCha20-Poly1305', 'HMAC', 'KMAC128', 'KMAC256', 'HKDF', 'PBKDF2', 'Argon2d', 'Argon2i', 'Argon2id', 'ML-DSA-44', 'ML-DSA-65', 'ML-DSA-87', 'ML-KEM-512', 'ML-KEM-768', 'ML-KEM-1024', ...SLH_DSA_VARIANTS]),
2422
+ exportKey: new Set(['RSASSA-PKCS1-v1_5', 'RSA-PSS', 'RSA-OAEP', 'ECDSA', 'ECDH', 'Ed25519', 'Ed448', 'X25519', 'X448', 'AES-CTR', 'AES-CBC', 'AES-GCM', 'AES-KW', 'AES-OCB', 'ChaCha20-Poly1305', 'HMAC', 'KMAC128', 'KMAC256', 'ML-DSA-44', 'ML-DSA-65', 'ML-DSA-87', 'ML-KEM-512', 'ML-KEM-768', 'ML-KEM-1024', ...SLH_DSA_VARIANTS]),
2423
+ deriveBits: new Set(['PBKDF2', 'HKDF', 'ECDH', 'X25519', 'X448', 'Argon2d', 'Argon2i', 'Argon2id']),
2424
+ wrapKey: new Set(['AES-CTR', 'AES-CBC', 'AES-GCM', 'AES-KW', 'AES-OCB', 'ChaCha20-Poly1305', 'RSA-OAEP']),
2425
+ unwrapKey: new Set(['AES-CTR', 'AES-CBC', 'AES-GCM', 'AES-KW', 'AES-OCB', 'ChaCha20-Poly1305', 'RSA-OAEP']),
2426
+ encapsulateBits: new Set(['ML-KEM-512', 'ML-KEM-768', 'ML-KEM-1024']),
2427
+ decapsulateBits: new Set(['ML-KEM-512', 'ML-KEM-768', 'ML-KEM-1024']),
2428
+ encapsulateKey: new Set(['ML-KEM-512', 'ML-KEM-768', 'ML-KEM-1024']),
2429
+ decapsulateKey: new Set(['ML-KEM-512', 'ML-KEM-768', 'ML-KEM-1024'])
2430
+ };
2431
+ const ASYMMETRIC_ALGORITHMS = new Set(['RSASSA-PKCS1-v1_5', 'RSA-PSS', 'RSA-OAEP', 'ECDSA', 'ECDH', 'Ed25519', 'Ed448', 'X25519', 'X448', 'ML-DSA-44', 'ML-DSA-65', 'ML-DSA-87', 'ML-KEM-512', 'ML-KEM-768', 'ML-KEM-1024', ...SLH_DSA_VARIANTS]);
2432
+
2433
+ // Per-algorithm validators for deriveBits (mirrors Node's hkdf.js:141-149,
2434
+ // pbkdf2.js:96-105, argon2.js:194-209). Used by Subtle.supports to reject
2435
+ // length values that the actual deriveBits implementation would reject.
2436
+ function validateKdfDeriveBitsLength(length, algName) {
2437
+ if (length === null || length === undefined) {
2438
+ throw lazyDOMException('length cannot be null', 'OperationError');
2439
+ }
2440
+ if (length % 8) {
2441
+ throw lazyDOMException('length must be a multiple of 8', 'OperationError');
2442
+ }
2443
+ if (algName.startsWith('Argon2') && length < 32) {
2444
+ throw lazyDOMException('length must be >= 32', 'OperationError');
2445
+ }
2446
+ }
2447
+
2448
+ // Mirrors Node's webcrypto.js:1652-1731 `check`. Normalizes the algorithm,
2449
+ // looks it up in SUPPORTED_ALGORITHMS, and runs per-algorithm validation
2450
+ // (deriveBits length validators, HMAC+SHA3 generateKey rejection).
2451
+ // `op` is the operation key in SUPPORTED_ALGORITHMS — wrapKey/unwrapKey fall
2452
+ // back to encrypt/decrypt to mirror Node's normalize fallback.
2453
+ function supportsCheck(op, alg, length) {
2454
+ let normalizedAlgorithm;
2455
+ try {
2456
+ normalizedAlgorithm = normalizeAlgorithm(alg, op);
2457
+ } catch {
2458
+ if (op === 'wrapKey') return supportsCheck('encrypt', alg);
2459
+ if (op === 'unwrapKey') return supportsCheck('decrypt', alg);
2460
+ return false;
2461
+ }
2462
+ const supported = SUPPORTED_ALGORITHMS[op];
2463
+ if (!supported || !supported.has(normalizedAlgorithm.name)) {
2464
+ if (op === 'wrapKey') return supportsCheck('encrypt', alg);
2465
+ if (op === 'unwrapKey') return supportsCheck('decrypt', alg);
2466
+ return false;
2467
+ }
2468
+ if (op === 'deriveBits') {
2469
+ const name = normalizedAlgorithm.name;
2470
+ if (name === 'HKDF' || name === 'PBKDF2' || name.startsWith('Argon2')) {
2471
+ try {
2472
+ validateKdfDeriveBitsLength(length, name);
2473
+ } catch {
2474
+ return false;
2475
+ }
2476
+ }
2477
+ }
2478
+ if (op === 'generateKey' && normalizedAlgorithm.name === 'HMAC') {
2479
+ const hashName = typeof normalizedAlgorithm.hash === 'string' ? normalizedAlgorithm.hash : normalizedAlgorithm.hash?.name;
2480
+ if (normalizedAlgorithm.length === undefined && typeof hashName === 'string' && hashName.startsWith('SHA3-')) {
2481
+ return false;
2482
+ }
2483
+ }
2484
+ return true;
2485
+ }
2486
+ function supportsImpl(operation, algorithm, lengthOrAdditionalAlgorithm) {
2487
+ switch (operation) {
2488
+ case 'decapsulateBits':
2489
+ case 'decapsulateKey':
2490
+ case 'decrypt':
2491
+ case 'deriveBits':
2492
+ case 'deriveKey':
2493
+ case 'digest':
2494
+ case 'encapsulateBits':
2495
+ case 'encapsulateKey':
2496
+ case 'encrypt':
2497
+ case 'exportKey':
2498
+ case 'generateKey':
2499
+ case 'getPublicKey':
2500
+ case 'importKey':
2501
+ case 'sign':
2502
+ case 'unwrapKey':
2503
+ case 'verify':
2504
+ case 'wrapKey':
2505
+ break;
2506
+ default:
2507
+ return false;
2508
+ }
2509
+ let length;
2510
+ if (operation === 'deriveKey') {
2511
+ // deriveKey decomposes to importKey of derived alg + deriveBits with that
2512
+ // alg's key length. Node webcrypto.js:1547-1563.
2513
+ if (lengthOrAdditionalAlgorithm != null) {
2514
+ const additional = lengthOrAdditionalAlgorithm;
2515
+ if (!supportsCheck('importKey', additional)) return false;
2516
+ try {
2517
+ length = getKeyLength(normalizeAlgorithm(additional, 'get key length'));
2518
+ } catch {
2519
+ return false;
2520
+ }
2521
+ return supportsCheck('deriveBits', algorithm, length);
2522
+ }
2523
+ // No additional algorithm given — only check the deriveBits side.
2524
+ return supportsCheck('deriveBits', algorithm);
2525
+ }
2526
+ if (operation === 'wrapKey') {
2527
+ // wrapKey decomposes to encrypt of wrapping alg + exportKey of wrapped alg.
2528
+ // Node webcrypto.js:1564-1572.
2529
+ if (lengthOrAdditionalAlgorithm != null) {
2530
+ const additional = lengthOrAdditionalAlgorithm;
2531
+ if (!supportsCheck('exportKey', additional)) return false;
2532
+ }
2533
+ return supportsCheck('wrapKey', algorithm);
2534
+ }
2535
+ if (operation === 'unwrapKey') {
2536
+ // unwrapKey decomposes to decrypt of wrapping alg + importKey of wrapped
2537
+ // alg. Node webcrypto.js:1573-1581.
2538
+ if (lengthOrAdditionalAlgorithm != null) {
2539
+ const additional = lengthOrAdditionalAlgorithm;
2540
+ if (!supportsCheck('importKey', additional)) return false;
2541
+ }
2542
+ return supportsCheck('unwrapKey', algorithm);
2543
+ }
2544
+ if (operation === 'deriveBits') {
2545
+ if (lengthOrAdditionalAlgorithm == null) {
2546
+ length = null;
2547
+ } else if (typeof lengthOrAdditionalAlgorithm === 'number') {
2548
+ length = lengthOrAdditionalAlgorithm;
2549
+ } else {
2550
+ return false;
2551
+ }
2552
+ return supportsCheck('deriveBits', algorithm, length);
2553
+ }
2554
+ if (operation === 'getPublicKey') {
2555
+ let normalized;
2556
+ try {
2557
+ normalized = normalizeAlgorithm(algorithm, 'exportKey');
2558
+ } catch {
2559
+ return false;
2560
+ }
2561
+ return ASYMMETRIC_ALGORITHMS.has(normalized.name);
2562
+ }
2563
+ if (operation === 'encapsulateKey' || operation === 'decapsulateKey') {
2564
+ // sharedKeyAlgorithm must support importKey, with HMAC/KMAC limited to
2565
+ // length === undefined or 256 (Node webcrypto.js:1610-1645).
2566
+ const additional = lengthOrAdditionalAlgorithm;
2567
+ let normalizedAdd;
2568
+ try {
2569
+ normalizedAdd = normalizeAlgorithm(additional, 'importKey');
2570
+ } catch {
2571
+ return false;
2572
+ }
2573
+ switch (normalizedAdd.name) {
2574
+ case 'AES-OCB':
2575
+ case 'AES-KW':
2576
+ case 'AES-GCM':
2577
+ case 'AES-CTR':
2578
+ case 'AES-CBC':
2579
+ case 'ChaCha20-Poly1305':
2580
+ case 'HKDF':
2581
+ case 'PBKDF2':
2582
+ case 'Argon2i':
2583
+ case 'Argon2d':
2584
+ case 'Argon2id':
2585
+ break;
2586
+ case 'HMAC':
2587
+ case 'KMAC128':
2588
+ case 'KMAC256':
2589
+ {
2590
+ const addLen = normalizedAdd.length;
2591
+ if (addLen !== undefined && addLen !== 256) return false;
2592
+ break;
2593
+ }
2594
+ default:
2595
+ return false;
2596
+ }
2597
+ return supportsCheck(operation, algorithm);
2598
+ }
2599
+ return supportsCheck(operation, algorithm);
2600
+ }
2601
+ export class Subtle {
2602
+ // Spec-compliant capability detector. Mirrors Node's webcrypto.js:1506-1649
2603
+ // `SubtleCrypto.supports`, including:
2604
+ // • composed-operation decomposition (deriveKey, wrapKey, unwrapKey,
2605
+ // encapsulateKey, decapsulateKey, getPublicKey)
2606
+ // • per-algorithm length validators for deriveBits (HKDF/PBKDF2/Argon2)
2607
+ // • HMAC + SHA3 generateKey with no length → false
2608
+ // Static-only per the WICG spec.
2609
+ static supports(operation, algorithm, lengthOrAdditionalAlgorithm = null) {
2610
+ return supportsImpl(operation, algorithm, lengthOrAdditionalAlgorithm);
2611
+ }
2612
+ async decrypt(algorithm, key, data) {
2613
+ requireArgs(arguments.length, 3, 'decrypt');
2614
+ const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'decrypt');
2615
+ if (normalizedAlgorithm.name !== key.algorithm.name) {
2616
+ throw lazyDOMException('Key algorithm mismatch', 'InvalidAccessError');
2617
+ }
2618
+ if (!key.usages.includes('decrypt')) {
2619
+ throw lazyDOMException('Unable to use this key to decrypt', 'InvalidAccessError');
2620
+ }
2621
+ return cipherOrWrap(CipherOrWrapMode.kWebCryptoCipherDecrypt, normalizedAlgorithm, key, bufferLikeToArrayBuffer(data));
2622
+ }
2623
+ async digest(algorithm, data) {
2624
+ requireArgs(arguments.length, 2, 'digest');
2625
+ const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'digest');
2626
+ return asyncDigest(normalizedAlgorithm, data);
2627
+ }
2628
+ async deriveBits(algorithm, baseKey, length = null) {
2629
+ requireArgs(arguments.length, 2, 'deriveBits');
2630
+ // WebCrypto §SubtleCrypto.deriveBits step 11: throw InvalidAccessError
2631
+ // unless `baseKey.[[usages]]` contains "deriveBits" specifically. The
2632
+ // previous `deriveBits || deriveKey` accept-either branch silently
2633
+ // promoted deriveKey-only keys into deriveBits use, contradicting the
2634
+ // spec usage gate.
2635
+ if (!baseKey.usages.includes('deriveBits')) {
2636
+ throw lazyDOMException('baseKey does not have deriveBits usage', 'InvalidAccessError');
2637
+ }
2638
+ const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'deriveBits');
2639
+ if (baseKey.algorithm.name !== normalizedAlgorithm.name) {
2640
+ throw lazyDOMException('Key algorithm mismatch', 'InvalidAccessError');
2641
+ }
2642
+ switch (normalizedAlgorithm.name) {
2643
+ case 'PBKDF2':
2644
+ if (length === null) {
2645
+ throw lazyDOMException('length cannot be null', 'OperationError');
2646
+ }
2647
+ return pbkdf2DeriveBits(normalizedAlgorithm, baseKey, length);
2648
+ case 'X25519':
2649
+ // Fall through
2650
+ case 'X448':
2651
+ return xDeriveBits(normalizedAlgorithm, baseKey, length);
2652
+ case 'ECDH':
2653
+ return ecDeriveBits(normalizedAlgorithm, baseKey, length);
2654
+ case 'HKDF':
2655
+ if (length === null) {
2656
+ throw lazyDOMException('length cannot be null', 'OperationError');
2657
+ }
2658
+ return hkdfDeriveBits(normalizedAlgorithm, baseKey, length);
2659
+ case 'Argon2d':
2660
+ case 'Argon2i':
2661
+ case 'Argon2id':
2662
+ if (length === null) {
2663
+ throw lazyDOMException('length cannot be null', 'OperationError');
2664
+ }
2665
+ return argon2DeriveBits(normalizedAlgorithm, baseKey, length);
2666
+ }
2667
+ throw lazyDOMException(`'subtle.deriveBits()' for ${normalizedAlgorithm.name} is not implemented.`, 'NotSupportedError');
2668
+ }
2669
+ async deriveKey(algorithm, baseKey, derivedKeyAlgorithm, extractable, keyUsages) {
2670
+ requireArgs(arguments.length, 5, 'deriveKey');
2671
+ const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'deriveBits');
2672
+ // Validate the derived-key algorithm up front (mirrors Node webcrypto.js:341).
2673
+ // The normalized form is unused — `this.importKey` re-normalizes below.
2674
+ normalizeAlgorithm(derivedKeyAlgorithm, 'importKey');
2675
+
2676
+ // Validate baseKey usage
2677
+ if (!baseKey.usages.includes('deriveKey')) {
2678
+ throw lazyDOMException('baseKey does not have deriveKey usage', 'InvalidAccessError');
2679
+ }
2680
+ if (baseKey.algorithm.name !== normalizedAlgorithm.name) {
2681
+ throw lazyDOMException('Key algorithm mismatch', 'InvalidAccessError');
2682
+ }
2683
+
2684
+ // Calculate required key length (may be null for KDF-derived material).
2685
+ // Mirrors Node webcrypto.js:350 — uses the raw derivedKeyAlgorithm with
2686
+ // op='get key length' so AES `length` survives normalization (the
2687
+ // 'importKey' converter for AES is null and strips dictionary members).
2688
+ const length = getKeyLength(normalizeAlgorithm(derivedKeyAlgorithm, 'get key length'));
2689
+
2690
+ // Step 1: Derive bits
2691
+ let derivedBits;
2692
+ switch (normalizedAlgorithm.name) {
2693
+ case 'PBKDF2':
2694
+ if (length === null) {
2695
+ throw lazyDOMException('length cannot be null', 'OperationError');
2696
+ }
2697
+ derivedBits = await pbkdf2DeriveBits(normalizedAlgorithm, baseKey, length);
2698
+ break;
2699
+ case 'X25519':
2700
+ // Fall through
2701
+ case 'X448':
2702
+ derivedBits = await xDeriveBits(normalizedAlgorithm, baseKey, length);
2703
+ break;
2704
+ case 'ECDH':
2705
+ derivedBits = await ecDeriveBits(normalizedAlgorithm, baseKey, length);
2706
+ break;
2707
+ case 'HKDF':
2708
+ if (length === null) {
2709
+ throw lazyDOMException('length cannot be null', 'OperationError');
2710
+ }
2711
+ derivedBits = hkdfDeriveBits(normalizedAlgorithm, baseKey, length);
2712
+ break;
2713
+ case 'Argon2d':
2714
+ case 'Argon2i':
2715
+ case 'Argon2id':
2716
+ if (length === null) {
2717
+ throw lazyDOMException('length cannot be null', 'OperationError');
2718
+ }
2719
+ derivedBits = argon2DeriveBits(normalizedAlgorithm, baseKey, length);
2720
+ break;
2721
+ default:
2722
+ throw lazyDOMException(`'subtle.deriveKey()' for ${normalizedAlgorithm.name} is not implemented.`, 'NotSupportedError');
2723
+ }
2724
+
2725
+ // Step 2: Import as key. Use 'raw-secret' so derived material flows into
2726
+ // AEADs / KMAC correctly — they reject plain 'raw' (Node webcrypto.js:381-385).
2727
+ return this.importKey('raw-secret', derivedBits, derivedKeyAlgorithm, extractable, keyUsages);
2728
+ }
2729
+ async encrypt(algorithm, key, data) {
2730
+ requireArgs(arguments.length, 3, 'encrypt');
2731
+ const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'encrypt');
2732
+ if (normalizedAlgorithm.name !== key.algorithm.name) {
2733
+ throw lazyDOMException('Key algorithm mismatch', 'InvalidAccessError');
2734
+ }
2735
+ if (!key.usages.includes('encrypt')) {
2736
+ throw lazyDOMException('Unable to use this key to encrypt', 'InvalidAccessError');
2737
+ }
2738
+ return cipherOrWrap(CipherOrWrapMode.kWebCryptoCipherEncrypt, normalizedAlgorithm, key, bufferLikeToArrayBuffer(data));
2739
+ }
2740
+ async exportKey(format, key) {
2741
+ requireArgs(arguments.length, 2, 'exportKey');
2742
+ if (!key.extractable) throw lazyDOMException('key is not extractable', 'InvalidAccessError');
2743
+ if (format === 'raw-seed') {
2744
+ const pqcAlgos = ['ML-KEM-512', 'ML-KEM-768', 'ML-KEM-1024', 'ML-DSA-44', 'ML-DSA-65', 'ML-DSA-87', ...SLH_DSA_VARIANTS];
2745
+ if (!pqcAlgos.includes(key.algorithm.name)) {
2746
+ throw lazyDOMException('raw-seed export only supported for PQC keys', 'NotSupportedError');
2747
+ }
2748
+ if (key.type !== 'private') {
2749
+ throw lazyDOMException('raw-seed export requires a private key', 'InvalidAccessError');
2750
+ }
2751
+ return bufferLikeToArrayBuffer(key.keyObject.handle.exportKey());
2752
+ }
2753
+ switch (format) {
2754
+ case 'spki':
2755
+ return await exportKeySpki(key);
2756
+ case 'pkcs8':
2757
+ return await exportKeyPkcs8(key);
2758
+ case 'jwk':
2759
+ return exportKeyJWK(key);
2760
+ case 'raw':
2761
+ case 'raw-secret':
2762
+ case 'raw-public':
2763
+ return exportKeyRaw(key, format);
2764
+ }
2765
+ }
2766
+ async wrapKey(format, key, wrappingKey, wrapAlgorithm) {
2767
+ requireArgs(arguments.length, 4, 'wrapKey');
2768
+ // Mirrors Node webcrypto.js:923-927: prefer the 'wrapKey' op (only
2769
+ // AES-KW defines it) and fall back to 'encrypt' for cipher-based wrap
2770
+ // algorithms like AES-GCM and RSA-OAEP.
2771
+ let normalizedWrapAlgorithm;
2772
+ try {
2773
+ normalizedWrapAlgorithm = normalizeAlgorithm(wrapAlgorithm, 'wrapKey');
2774
+ } catch {
2775
+ normalizedWrapAlgorithm = normalizeAlgorithm(wrapAlgorithm, 'encrypt');
2776
+ }
2777
+ if (normalizedWrapAlgorithm.name !== wrappingKey.algorithm.name) {
2778
+ throw lazyDOMException('Key algorithm mismatch', 'InvalidAccessError');
2779
+ }
2780
+ if (!wrappingKey.usages.includes('wrapKey')) {
2781
+ throw lazyDOMException('Unable to use this key to wrapKey', 'InvalidAccessError');
2782
+ }
2783
+
2784
+ // Step 1: Export the key
2785
+ const exported = await this.exportKey(format, key);
2786
+
2787
+ // Step 2: Convert to ArrayBuffer if JWK
2788
+ let keyData;
2789
+ if (format === 'jwk') {
2790
+ const jwkString = JSON.stringify(exported);
2791
+ const buffer = SBuffer.from(jwkString, 'utf8');
2792
+
2793
+ // For AES-KW, pad to multiple of 8 bytes (accounting for null terminator)
2794
+ if (normalizedWrapAlgorithm.name === 'AES-KW') {
2795
+ const length = buffer.length;
2796
+ // Add 1 for null terminator, then pad to multiple of 8
2797
+ const paddedLength = Math.ceil((length + 1) / 8) * 8;
2798
+ const paddedBuffer = SBuffer.alloc(paddedLength);
2799
+ buffer.copy(paddedBuffer);
2800
+ // Null terminator for JSON string (remaining bytes are already zeros from alloc)
2801
+ paddedBuffer.writeUInt8(0, length);
2802
+ keyData = bufferLikeToArrayBuffer(paddedBuffer);
2803
+ } else {
2804
+ keyData = bufferLikeToArrayBuffer(buffer);
2805
+ }
2806
+ } else {
2807
+ keyData = exported;
2808
+ }
2809
+
2810
+ // Step 3: Encrypt the exported key
2811
+ return cipherOrWrap(CipherOrWrapMode.kWebCryptoCipherEncrypt, normalizedWrapAlgorithm, wrappingKey, keyData);
2812
+ }
2813
+ async unwrapKey(format, wrappedKey, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages) {
2814
+ requireArgs(arguments.length, 7, 'unwrapKey');
2815
+ // Mirrors Node webcrypto.js:1006-1010: prefer 'unwrapKey', fall back to
2816
+ // 'decrypt' for cipher-based unwrap algorithms.
2817
+ let normalizedUnwrapAlgorithm;
2818
+ try {
2819
+ normalizedUnwrapAlgorithm = normalizeAlgorithm(unwrapAlgorithm, 'unwrapKey');
2820
+ } catch {
2821
+ normalizedUnwrapAlgorithm = normalizeAlgorithm(unwrapAlgorithm, 'decrypt');
2822
+ }
2823
+ if (normalizedUnwrapAlgorithm.name !== unwrappingKey.algorithm.name) {
2824
+ throw lazyDOMException('Key algorithm mismatch', 'InvalidAccessError');
2825
+ }
2826
+ if (!unwrappingKey.usages.includes('unwrapKey')) {
2827
+ throw lazyDOMException('Unable to use this key to unwrapKey', 'InvalidAccessError');
2828
+ }
2829
+
2830
+ // Step 1: Decrypt the wrapped key
2831
+ const decrypted = await cipherOrWrap(CipherOrWrapMode.kWebCryptoCipherDecrypt, normalizedUnwrapAlgorithm, unwrappingKey, bufferLikeToArrayBuffer(wrappedKey));
2832
+
2833
+ // Step 2: Convert to appropriate format
2834
+ let keyData;
2835
+ if (format === 'jwk') {
2836
+ const buffer = SBuffer.from(decrypted);
2837
+ // For AES-KW, the data may be padded - find the null terminator
2838
+ let jwkString;
2839
+ if (normalizedUnwrapAlgorithm.name === 'AES-KW') {
2840
+ // Find the null terminator (if present) to get the original string
2841
+ const nullIndex = buffer.indexOf(0);
2842
+ if (nullIndex !== -1) {
2843
+ jwkString = buffer.toString('utf8', 0, nullIndex);
2844
+ } else {
2845
+ // No null terminator, try to parse the whole buffer
2846
+ jwkString = buffer.toString('utf8').trim();
2847
+ }
2848
+ } else {
2849
+ jwkString = buffer.toString('utf8');
2850
+ }
2851
+ keyData = JSON.parse(jwkString);
2852
+ } else {
2853
+ keyData = decrypted;
2854
+ }
2855
+
2856
+ // Step 3: Import the key
2857
+ return this.importKey(format, keyData, unwrappedKeyAlgorithm, extractable, keyUsages);
2858
+ }
2859
+ async generateKey(algorithm, extractable, keyUsages) {
2860
+ requireArgs(arguments.length, 3, 'generateKey');
2861
+ algorithm = normalizeAlgorithm(algorithm, 'generateKey');
2862
+ let result;
2863
+ switch (algorithm.name) {
2864
+ case 'RSASSA-PKCS1-v1_5':
2865
+ // Fall through
2866
+ case 'RSA-PSS':
2867
+ // Fall through
2868
+ case 'RSA-OAEP':
2869
+ result = await rsa_generateKeyPair(algorithm, extractable, keyUsages);
2870
+ break;
2871
+ case 'ECDSA':
2872
+ // Fall through
2873
+ case 'ECDH':
2874
+ result = await ec_generateKeyPair(algorithm.name, algorithm.namedCurve, extractable, keyUsages);
2875
+ checkCryptoKeyPairUsages(result);
2876
+ break;
2877
+ case 'AES-CTR':
2878
+ // Fall through
2879
+ case 'AES-CBC':
2880
+ // Fall through
2881
+ case 'AES-GCM':
2882
+ // Fall through
2883
+ case 'AES-KW':
2884
+ // Fall through
2885
+ case 'AES-OCB':
2886
+ result = await aesGenerateKey(algorithm, extractable, keyUsages);
2887
+ break;
2888
+ case 'ChaCha20-Poly1305':
2889
+ {
2890
+ const length = algorithm.length ?? 256;
2891
+ if (length !== 256) {
2892
+ throw lazyDOMException('ChaCha20-Poly1305 only supports 256-bit keys', 'NotSupportedError');
2893
+ }
2894
+ result = await aesGenerateKey({
2895
+ name: 'ChaCha20-Poly1305',
2896
+ length: 256
2897
+ }, extractable, keyUsages);
2898
+ break;
2899
+ }
2900
+ case 'HMAC':
2901
+ result = await hmacGenerateKey(algorithm, extractable, keyUsages);
2902
+ break;
2903
+ case 'KMAC128':
2904
+ // Fall through
2905
+ case 'KMAC256':
2906
+ result = await kmacGenerateKey(algorithm, extractable, keyUsages);
2907
+ break;
2908
+ case 'Ed25519':
2909
+ // Fall through
2910
+ case 'Ed448':
2911
+ result = await ed_generateKeyPairWebCrypto(algorithm.name.toLowerCase(), extractable, keyUsages);
2912
+ checkCryptoKeyPairUsages(result);
2913
+ break;
2914
+ case 'ML-DSA-44':
2915
+ // Fall through
2916
+ case 'ML-DSA-65':
2917
+ // Fall through
2918
+ case 'ML-DSA-87':
2919
+ result = await mldsa_generateKeyPairWebCrypto(algorithm.name, extractable, keyUsages);
2920
+ checkCryptoKeyPairUsages(result);
2921
+ break;
2922
+ case 'SLH-DSA-SHA2-128s':
2923
+ case 'SLH-DSA-SHA2-128f':
2924
+ case 'SLH-DSA-SHA2-192s':
2925
+ case 'SLH-DSA-SHA2-192f':
2926
+ case 'SLH-DSA-SHA2-256s':
2927
+ case 'SLH-DSA-SHA2-256f':
2928
+ case 'SLH-DSA-SHAKE-128s':
2929
+ case 'SLH-DSA-SHAKE-128f':
2930
+ case 'SLH-DSA-SHAKE-192s':
2931
+ case 'SLH-DSA-SHAKE-192f':
2932
+ case 'SLH-DSA-SHAKE-256s':
2933
+ case 'SLH-DSA-SHAKE-256f':
2934
+ result = await slhdsa_generateKeyPairWebCrypto(algorithm.name, extractable, keyUsages);
2935
+ checkCryptoKeyPairUsages(result);
2936
+ break;
2937
+ case 'X25519':
2938
+ // Fall through
2939
+ case 'X448':
2940
+ result = await x_generateKeyPairWebCrypto(algorithm.name.toLowerCase(), extractable, keyUsages);
2941
+ checkCryptoKeyPairUsages(result);
2942
+ break;
2943
+ case 'ML-KEM-512':
2944
+ // Fall through
2945
+ case 'ML-KEM-768':
2946
+ // Fall through
2947
+ case 'ML-KEM-1024':
2948
+ result = await mlkem_generateKeyPairWebCrypto(algorithm.name, extractable, keyUsages);
2949
+ checkCryptoKeyPairUsages(result);
2950
+ break;
2951
+ default:
2952
+ throw new Error(`'subtle.generateKey()' is not implemented for ${algorithm.name}.
2953
+ Unrecognized algorithm name`);
2954
+ }
2955
+ return result;
2956
+ }
2957
+ async getPublicKey(key, keyUsages) {
2958
+ requireArgs(arguments.length, 2, 'getPublicKey');
2959
+ if (key.type === 'secret') {
2960
+ throw lazyDOMException('key must be a private key', 'NotSupportedError');
2961
+ }
2962
+ if (key.type !== 'private') {
2963
+ throw lazyDOMException('key must be a private key', 'InvalidAccessError');
2964
+ }
2965
+ const publicKeyObject = createPublicKey(key.keyObject);
2966
+ return publicKeyObject.toCryptoKey(key.algorithm, true, keyUsages);
2967
+ }
2968
+ async importKey(format, data, algorithm, extractable, keyUsages) {
2969
+ requireArgs(arguments.length, 5, 'importKey');
2970
+ // Per-algorithm format handling. Some algorithms alias raw-secret/raw-public
2971
+ // to 'raw' (RSA, EC, Ed/X, HMAC, HKDF, PBKDF2); others demand the
2972
+ // disambiguated form (KMAC, AES-OCB, ChaCha20-Poly1305, Argon2, ML-DSA,
2973
+ // ML-KEM). 'raw-seed' is never normalized — PQC import handles it directly.
2974
+ const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'importKey');
2975
+ let result;
2976
+ switch (normalizedAlgorithm.name) {
2977
+ case 'RSASSA-PKCS1-v1_5':
2978
+ // Fall through
2979
+ case 'RSA-PSS':
2980
+ // Fall through
2981
+ case 'RSA-OAEP':
2982
+ result = rsaImportKey(aliasKeyFormat(format), data, normalizedAlgorithm, extractable, keyUsages);
2983
+ break;
2984
+ case 'ECDSA':
2985
+ // Fall through
2986
+ case 'ECDH':
2987
+ result = ecImportKey(aliasKeyFormat(format), data, normalizedAlgorithm, extractable, keyUsages);
2988
+ break;
2989
+ case 'HMAC':
2990
+ // No aliasing — Node routes HMAC straight into mac.js, which accepts
2991
+ // 'raw' / 'raw-secret' / 'jwk' and rejects everything else
2992
+ // (webcrypto.js:774-781, mac.js:136-174).
2993
+ result = await hmacImportKey(normalizedAlgorithm, format, data, extractable, keyUsages);
2994
+ break;
2995
+ case 'KMAC128':
2996
+ // Fall through
2997
+ case 'KMAC256':
2998
+ result = await kmacImportKey(normalizedAlgorithm, format, data, extractable, keyUsages);
2999
+ break;
3000
+ case 'AES-CTR':
3001
+ // Fall through
3002
+ case 'AES-CBC':
3003
+ // Fall through
3004
+ case 'AES-GCM':
3005
+ // Fall through
3006
+ case 'AES-KW':
3007
+ // Fall through
3008
+ case 'AES-OCB':
3009
+ // Fall through
3010
+ case 'ChaCha20-Poly1305':
3011
+ result = await aesImportKey(normalizedAlgorithm, format, data, extractable, keyUsages);
3012
+ break;
3013
+ case 'PBKDF2':
3014
+ result = await pbkdf2ImportKey(normalizedAlgorithm, aliasKeyFormat(format), data, extractable, keyUsages);
3015
+ break;
3016
+ case 'Argon2d':
3017
+ case 'Argon2i':
3018
+ case 'Argon2id':
3019
+ result = await argon2ImportKey(normalizedAlgorithm, format, data, extractable, keyUsages);
3020
+ break;
3021
+ case 'HKDF':
3022
+ result = await hkdfImportKey(aliasKeyFormat(format), data, normalizedAlgorithm, extractable, keyUsages);
3023
+ break;
3024
+ case 'X25519':
3025
+ // Fall through
3026
+ case 'X448':
3027
+ // Fall through
3028
+ case 'Ed25519':
3029
+ // Fall through
3030
+ case 'Ed448':
3031
+ result = edImportKey(aliasKeyFormat(format), data, normalizedAlgorithm, extractable, keyUsages);
3032
+ break;
3033
+ case 'SLH-DSA-SHA2-128s':
3034
+ case 'SLH-DSA-SHA2-128f':
3035
+ case 'SLH-DSA-SHA2-192s':
3036
+ case 'SLH-DSA-SHA2-192f':
3037
+ case 'SLH-DSA-SHA2-256s':
3038
+ case 'SLH-DSA-SHA2-256f':
3039
+ case 'SLH-DSA-SHAKE-128s':
3040
+ case 'SLH-DSA-SHAKE-128f':
3041
+ case 'SLH-DSA-SHAKE-192s':
3042
+ case 'SLH-DSA-SHAKE-192f':
3043
+ case 'SLH-DSA-SHAKE-256s':
3044
+ case 'SLH-DSA-SHAKE-256f':
3045
+ result = slhdsaImportKey(format, data, normalizedAlgorithm, extractable, keyUsages);
3046
+ break;
3047
+ case 'ML-DSA-44':
3048
+ // Fall through
3049
+ case 'ML-DSA-65':
3050
+ // Fall through
3051
+ case 'ML-DSA-87':
3052
+ result = mldsaImportKey(format, data, normalizedAlgorithm, extractable, keyUsages);
3053
+ break;
3054
+ case 'ML-KEM-512':
3055
+ // Fall through
3056
+ case 'ML-KEM-768':
3057
+ // Fall through
3058
+ case 'ML-KEM-1024':
3059
+ result = mlkemImportKey(format, data, normalizedAlgorithm, extractable, keyUsages);
3060
+ break;
3061
+ default:
3062
+ throw new Error(`"subtle.importKey()" is not implemented for ${normalizedAlgorithm.name}`);
3063
+ }
3064
+ if ((result.type === 'secret' || result.type === 'private') && result.usages.length === 0) {
3065
+ throw new Error(`Usages cannot be empty when importing a ${result.type} key.`);
3066
+ }
3067
+ return result;
3068
+ }
3069
+ async sign(algorithm, key, data) {
3070
+ requireArgs(arguments.length, 3, 'sign');
3071
+ return signVerify(normalizeAlgorithm(algorithm, 'sign'), key, data);
3072
+ }
3073
+ async verify(algorithm, key, signature, data) {
3074
+ requireArgs(arguments.length, 4, 'verify');
3075
+ return signVerify(normalizeAlgorithm(algorithm, 'verify'), key, data, signature);
3076
+ }
3077
+ _encapsulateCore(algorithm, key) {
3078
+ const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'encapsulateBits');
3079
+ if (key.algorithm.name !== normalizedAlgorithm.name) {
3080
+ throw lazyDOMException('Key algorithm mismatch', 'InvalidAccessError');
3081
+ }
3082
+ const variant = normalizedAlgorithm.name;
3083
+ const mlkem = new MlKem(variant);
3084
+ const keyData = key.keyObject.handle.exportKey(KFormatType.DER, KeyEncoding.SPKI);
3085
+ mlkem.setPublicKey(bufferLikeToArrayBuffer(keyData), KFormatType.DER, KeyEncoding.SPKI);
3086
+ return mlkem.encapsulateSync();
3087
+ }
3088
+ _decapsulateCore(algorithm, key, ciphertext) {
3089
+ const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'decapsulateBits');
3090
+ if (key.algorithm.name !== normalizedAlgorithm.name) {
3091
+ throw lazyDOMException('Key algorithm mismatch', 'InvalidAccessError');
3092
+ }
3093
+ const variant = normalizedAlgorithm.name;
3094
+ const mlkem = new MlKem(variant);
3095
+ const keyData = key.keyObject.handle.exportKey(KFormatType.DER, KeyEncoding.PKCS8);
3096
+ mlkem.setPrivateKey(bufferLikeToArrayBuffer(keyData), KFormatType.DER, KeyEncoding.PKCS8);
3097
+ return mlkem.decapsulateSync(bufferLikeToArrayBuffer(ciphertext));
3098
+ }
3099
+ async encapsulateBits(algorithm, key) {
3100
+ requireArgs(arguments.length, 2, 'encapsulateBits');
3101
+ if (!key.usages.includes('encapsulateBits')) {
3102
+ throw lazyDOMException('Key does not have encapsulateBits usage', 'InvalidAccessError');
3103
+ }
3104
+ return this._encapsulateCore(algorithm, key);
3105
+ }
3106
+ async encapsulateKey(algorithm, key, sharedKeyAlgorithm, extractable, usages) {
3107
+ requireArgs(arguments.length, 5, 'encapsulateKey');
3108
+ if (!key.usages.includes('encapsulateKey')) {
3109
+ throw lazyDOMException('Key does not have encapsulateKey usage', 'InvalidAccessError');
3110
+ }
3111
+ const {
3112
+ sharedKey,
3113
+ ciphertext
3114
+ } = this._encapsulateCore(algorithm, key);
3115
+ // Node imports the encapsulated shared bits as 'raw-secret'
3116
+ // (webcrypto.js:1370-1374) so AEADs / KMAC accept the result.
3117
+ const importedKey = await this.importKey('raw-secret', sharedKey, sharedKeyAlgorithm, extractable, usages);
3118
+ return {
3119
+ key: importedKey,
3120
+ ciphertext
3121
+ };
3122
+ }
3123
+ async decapsulateBits(algorithm, key, ciphertext) {
3124
+ requireArgs(arguments.length, 3, 'decapsulateBits');
3125
+ if (!key.usages.includes('decapsulateBits')) {
3126
+ throw lazyDOMException('Key does not have decapsulateBits usage', 'InvalidAccessError');
3127
+ }
3128
+ return this._decapsulateCore(algorithm, key, ciphertext);
3129
+ }
3130
+ async decapsulateKey(algorithm, key, ciphertext, sharedKeyAlgorithm, extractable, usages) {
3131
+ requireArgs(arguments.length, 6, 'decapsulateKey');
3132
+ if (!key.usages.includes('decapsulateKey')) {
3133
+ throw lazyDOMException('Key does not have decapsulateKey usage', 'InvalidAccessError');
3134
+ }
3135
+ const sharedKey = this._decapsulateCore(algorithm, key, ciphertext);
3136
+ // Node imports the decapsulated shared bits as 'raw-secret'
3137
+ // (webcrypto.js:1490-1494).
3138
+ return this.importKey('raw-secret', sharedKey, sharedKeyAlgorithm, extractable, usages);
3139
+ }
3140
+ }
3141
+ export const subtle = new Subtle();
3142
+
3143
+ // Returns the number of bits to derive for an `importKey` algorithm, mirroring
3144
+ // Node's webcrypto.js:269-306 `getKeyLength`. Returns null for KDF algorithms
3145
+ // (HKDF / PBKDF2 / Argon2) — those carry their full derived secret without a
3146
+ // fixed key length. Throws OperationError on invalid AES / HMAC inputs rather
3147
+ // than silently coercing to a default (Node commit 4cb1f284136 behavior).
3148
+ function getKeyLength(algorithm) {
3149
+ const name = algorithm.name;
3150
+ const length = algorithm.length;
3151
+ switch (name) {
3152
+ case 'AES-CTR':
3153
+ case 'AES-CBC':
3154
+ case 'AES-GCM':
3155
+ case 'AES-KW':
3156
+ case 'AES-OCB':
3157
+ if (length !== 128 && length !== 192 && length !== 256) {
3158
+ throw lazyDOMException('Invalid key length', 'OperationError');
3159
+ }
3160
+ return length;
3161
+ case 'HMAC':
3162
+ {
3163
+ if (length === undefined) {
3164
+ return getHmacBlockSize(algorithm.hash?.name ?? algorithm.hash);
3165
+ }
3166
+ if (typeof length === 'number' && length !== 0) {
3167
+ return length;
3168
+ }
3169
+ throw lazyDOMException('Invalid key length', 'OperationError');
3170
+ }
3171
+ case 'KMAC128':
3172
+ return typeof length === 'number' ? length : 128;
3173
+ case 'KMAC256':
3174
+ return typeof length === 'number' ? length : 256;
3175
+ case 'ChaCha20-Poly1305':
3176
+ return 256;
3177
+ case 'HKDF':
3178
+ case 'PBKDF2':
3179
+ case 'Argon2d':
3180
+ case 'Argon2i':
3181
+ case 'Argon2id':
3182
+ return null;
3183
+ default:
3184
+ throw lazyDOMException(`Cannot determine key length for ${name}`, 'NotSupportedError');
3185
+ }
3186
+ }
3187
+ function getHmacBlockSize(name) {
3188
+ switch (name) {
3189
+ case 'SHA-1':
3190
+ case 'SHA-256':
3191
+ return 512;
3192
+ case 'SHA-384':
3193
+ case 'SHA-512':
3194
+ return 1024;
3195
+ case 'SHA3-256':
3196
+ case 'SHA3-384':
3197
+ case 'SHA3-512':
3198
+ // SHA-3 / HMAC interaction undefined — Node throws here too
3199
+ // (webcrypto-modern-algos issue #23).
3200
+ throw lazyDOMException('Explicit algorithm length member is required', 'NotSupportedError');
3201
+ default:
3202
+ throw lazyDOMException('Invalid key length', 'OperationError');
3203
+ }
3204
+ }
3205
+ //# sourceMappingURL=subtle.js.map