react-native-quick-crypto 1.0.10 → 1.0.12

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 (293) hide show
  1. package/android/CMakeLists.txt +16 -0
  2. package/cpp/argon2/HybridArgon2.cpp +103 -0
  3. package/cpp/argon2/HybridArgon2.hpp +32 -0
  4. package/cpp/certificate/HybridCertificate.cpp +42 -0
  5. package/cpp/certificate/HybridCertificate.hpp +16 -0
  6. package/cpp/cipher/CCMCipher.cpp +4 -1
  7. package/cpp/cipher/ChaCha20Cipher.cpp +3 -1
  8. package/cpp/cipher/ChaCha20Poly1305Cipher.cpp +5 -5
  9. package/cpp/cipher/ChaCha20Poly1305Cipher.hpp +1 -2
  10. package/cpp/cipher/HybridCipher.cpp +68 -1
  11. package/cpp/cipher/HybridCipher.hpp +6 -0
  12. package/cpp/cipher/HybridRsaCipher.cpp +0 -13
  13. package/cpp/cipher/XChaCha20Poly1305Cipher.cpp +7 -5
  14. package/cpp/cipher/XChaCha20Poly1305Cipher.hpp +1 -2
  15. package/cpp/cipher/XSalsa20Cipher.cpp +4 -0
  16. package/cpp/cipher/XSalsa20Poly1305Cipher.cpp +7 -5
  17. package/cpp/cipher/XSalsa20Poly1305Cipher.hpp +1 -2
  18. package/cpp/dh/HybridDhKeyPair.cpp +179 -0
  19. package/cpp/dh/HybridDhKeyPair.hpp +37 -0
  20. package/cpp/dsa/HybridDsaKeyPair.cpp +128 -0
  21. package/cpp/dsa/HybridDsaKeyPair.hpp +32 -0
  22. package/cpp/ecdh/HybridECDH.cpp +42 -120
  23. package/cpp/ecdh/HybridECDH.hpp +1 -0
  24. package/cpp/keys/HybridKeyObjectHandle.cpp +150 -128
  25. package/cpp/keys/HybridKeyObjectHandle.hpp +6 -3
  26. package/cpp/keys/KeyObjectData.hpp +2 -0
  27. package/cpp/kmac/HybridKmac.cpp +83 -0
  28. package/cpp/kmac/HybridKmac.hpp +31 -0
  29. package/cpp/mldsa/HybridMlDsaKeyPair.cpp +11 -20
  30. package/cpp/mldsa/HybridMlDsaKeyPair.hpp +4 -2
  31. package/cpp/mlkem/HybridMlKemKeyPair.cpp +319 -0
  32. package/cpp/mlkem/HybridMlKemKeyPair.hpp +48 -0
  33. package/cpp/prime/HybridPrime.cpp +81 -0
  34. package/cpp/prime/HybridPrime.hpp +20 -0
  35. package/cpp/sign/SignUtils.hpp +9 -26
  36. package/cpp/utils/QuickCryptoUtils.cpp +44 -0
  37. package/cpp/utils/QuickCryptoUtils.hpp +39 -0
  38. package/cpp/x509/HybridX509Certificate.cpp +174 -0
  39. package/cpp/x509/HybridX509Certificate.hpp +51 -0
  40. package/lib/commonjs/argon2.js +39 -0
  41. package/lib/commonjs/argon2.js.map +1 -0
  42. package/lib/commonjs/certificate.js +35 -0
  43. package/lib/commonjs/certificate.js.map +1 -0
  44. package/lib/commonjs/cipher.js +23 -2
  45. package/lib/commonjs/cipher.js.map +1 -1
  46. package/lib/commonjs/dhKeyPair.js +109 -0
  47. package/lib/commonjs/dhKeyPair.js.map +1 -0
  48. package/lib/commonjs/dsa.js +92 -0
  49. package/lib/commonjs/dsa.js.map +1 -0
  50. package/lib/commonjs/ec.js +18 -18
  51. package/lib/commonjs/ec.js.map +1 -1
  52. package/lib/commonjs/ecdh.js +37 -0
  53. package/lib/commonjs/ecdh.js.map +1 -1
  54. package/lib/commonjs/ed.js +9 -9
  55. package/lib/commonjs/ed.js.map +1 -1
  56. package/lib/commonjs/hash.js +17 -12
  57. package/lib/commonjs/hash.js.map +1 -1
  58. package/lib/commonjs/hkdf.js.map +1 -1
  59. package/lib/commonjs/index.js +57 -0
  60. package/lib/commonjs/index.js.map +1 -1
  61. package/lib/commonjs/keys/classes.js +11 -9
  62. package/lib/commonjs/keys/classes.js.map +1 -1
  63. package/lib/commonjs/keys/generateKeyPair.js +11 -0
  64. package/lib/commonjs/keys/generateKeyPair.js.map +1 -1
  65. package/lib/commonjs/keys/index.js +24 -0
  66. package/lib/commonjs/keys/index.js.map +1 -1
  67. package/lib/commonjs/keys/signVerify.js +0 -2
  68. package/lib/commonjs/keys/signVerify.js.map +1 -1
  69. package/lib/commonjs/mlkem.js +219 -0
  70. package/lib/commonjs/mlkem.js.map +1 -0
  71. package/lib/commonjs/pbkdf2.js +18 -1
  72. package/lib/commonjs/pbkdf2.js.map +1 -1
  73. package/lib/commonjs/prime.js +84 -0
  74. package/lib/commonjs/prime.js.map +1 -0
  75. package/lib/commonjs/rsa.js +7 -7
  76. package/lib/commonjs/rsa.js.map +1 -1
  77. package/lib/commonjs/specs/argon2.nitro.js +6 -0
  78. package/lib/commonjs/specs/argon2.nitro.js.map +1 -0
  79. package/lib/commonjs/specs/certificate.nitro.js +6 -0
  80. package/lib/commonjs/specs/certificate.nitro.js.map +1 -0
  81. package/lib/commonjs/specs/dhKeyPair.nitro.js +6 -0
  82. package/lib/commonjs/specs/dhKeyPair.nitro.js.map +1 -0
  83. package/lib/commonjs/specs/dsaKeyPair.nitro.js +6 -0
  84. package/lib/commonjs/specs/dsaKeyPair.nitro.js.map +1 -0
  85. package/lib/commonjs/specs/kmac.nitro.js +6 -0
  86. package/lib/commonjs/specs/kmac.nitro.js.map +1 -0
  87. package/lib/commonjs/specs/mlKemKeyPair.nitro.js +6 -0
  88. package/lib/commonjs/specs/mlKemKeyPair.nitro.js.map +1 -0
  89. package/lib/commonjs/specs/prime.nitro.js +6 -0
  90. package/lib/commonjs/specs/prime.nitro.js.map +1 -0
  91. package/lib/commonjs/specs/x509certificate.nitro.js +6 -0
  92. package/lib/commonjs/specs/x509certificate.nitro.js.map +1 -0
  93. package/lib/commonjs/subtle.js +385 -114
  94. package/lib/commonjs/subtle.js.map +1 -1
  95. package/lib/commonjs/utils/conversion.js +3 -3
  96. package/lib/commonjs/utils/conversion.js.map +1 -1
  97. package/lib/commonjs/utils/hashnames.js +31 -0
  98. package/lib/commonjs/utils/hashnames.js.map +1 -1
  99. package/lib/commonjs/utils/types.js.map +1 -1
  100. package/lib/commonjs/x509certificate.js +189 -0
  101. package/lib/commonjs/x509certificate.js.map +1 -0
  102. package/lib/module/argon2.js +34 -0
  103. package/lib/module/argon2.js.map +1 -0
  104. package/lib/module/certificate.js +30 -0
  105. package/lib/module/certificate.js.map +1 -0
  106. package/lib/module/cipher.js +23 -3
  107. package/lib/module/cipher.js.map +1 -1
  108. package/lib/module/dhKeyPair.js +102 -0
  109. package/lib/module/dhKeyPair.js.map +1 -0
  110. package/lib/module/dsa.js +85 -0
  111. package/lib/module/dsa.js.map +1 -0
  112. package/lib/module/ec.js +6 -6
  113. package/lib/module/ec.js.map +1 -1
  114. package/lib/module/ecdh.js +37 -0
  115. package/lib/module/ecdh.js.map +1 -1
  116. package/lib/module/ed.js +1 -1
  117. package/lib/module/ed.js.map +1 -1
  118. package/lib/module/hash.js +17 -12
  119. package/lib/module/hash.js.map +1 -1
  120. package/lib/module/hkdf.js.map +1 -1
  121. package/lib/module/index.js +15 -0
  122. package/lib/module/index.js.map +1 -1
  123. package/lib/module/keys/classes.js +11 -9
  124. package/lib/module/keys/classes.js.map +1 -1
  125. package/lib/module/keys/generateKeyPair.js +11 -0
  126. package/lib/module/keys/generateKeyPair.js.map +1 -1
  127. package/lib/module/keys/index.js +25 -1
  128. package/lib/module/keys/index.js.map +1 -1
  129. package/lib/module/keys/signVerify.js +0 -2
  130. package/lib/module/keys/signVerify.js.map +1 -1
  131. package/lib/module/mlkem.js +211 -0
  132. package/lib/module/mlkem.js.map +1 -0
  133. package/lib/module/pbkdf2.js +18 -1
  134. package/lib/module/pbkdf2.js.map +1 -1
  135. package/lib/module/prime.js +77 -0
  136. package/lib/module/prime.js.map +1 -0
  137. package/lib/module/rsa.js +1 -1
  138. package/lib/module/rsa.js.map +1 -1
  139. package/lib/module/specs/argon2.nitro.js +4 -0
  140. package/lib/module/specs/argon2.nitro.js.map +1 -0
  141. package/lib/module/specs/certificate.nitro.js +4 -0
  142. package/lib/module/specs/certificate.nitro.js.map +1 -0
  143. package/lib/module/specs/dhKeyPair.nitro.js +4 -0
  144. package/lib/module/specs/dhKeyPair.nitro.js.map +1 -0
  145. package/lib/module/specs/dsaKeyPair.nitro.js +4 -0
  146. package/lib/module/specs/dsaKeyPair.nitro.js.map +1 -0
  147. package/lib/module/specs/kmac.nitro.js +4 -0
  148. package/lib/module/specs/kmac.nitro.js.map +1 -0
  149. package/lib/module/specs/mlKemKeyPair.nitro.js +4 -0
  150. package/lib/module/specs/mlKemKeyPair.nitro.js.map +1 -0
  151. package/lib/module/specs/prime.nitro.js +4 -0
  152. package/lib/module/specs/prime.nitro.js.map +1 -0
  153. package/lib/module/specs/x509certificate.nitro.js +4 -0
  154. package/lib/module/specs/x509certificate.nitro.js.map +1 -0
  155. package/lib/module/subtle.js +386 -116
  156. package/lib/module/subtle.js.map +1 -1
  157. package/lib/module/utils/conversion.js +3 -4
  158. package/lib/module/utils/conversion.js.map +1 -1
  159. package/lib/module/utils/hashnames.js +31 -0
  160. package/lib/module/utils/hashnames.js.map +1 -1
  161. package/lib/module/utils/types.js.map +1 -1
  162. package/lib/module/x509certificate.js +184 -0
  163. package/lib/module/x509certificate.js.map +1 -0
  164. package/lib/tsconfig.tsbuildinfo +1 -1
  165. package/lib/typescript/argon2.d.ts +16 -0
  166. package/lib/typescript/argon2.d.ts.map +1 -0
  167. package/lib/typescript/certificate.d.ts +8 -0
  168. package/lib/typescript/certificate.d.ts.map +1 -0
  169. package/lib/typescript/cipher.d.ts +15 -0
  170. package/lib/typescript/cipher.d.ts.map +1 -1
  171. package/lib/typescript/dhKeyPair.d.ts +19 -0
  172. package/lib/typescript/dhKeyPair.d.ts.map +1 -0
  173. package/lib/typescript/dsa.d.ts +19 -0
  174. package/lib/typescript/dsa.d.ts.map +1 -0
  175. package/lib/typescript/ec.d.ts +1 -1
  176. package/lib/typescript/ec.d.ts.map +1 -1
  177. package/lib/typescript/ecdh.d.ts +3 -0
  178. package/lib/typescript/ecdh.d.ts.map +1 -1
  179. package/lib/typescript/ed.d.ts +1 -1
  180. package/lib/typescript/ed.d.ts.map +1 -1
  181. package/lib/typescript/hash.d.ts.map +1 -1
  182. package/lib/typescript/hkdf.d.ts +2 -6
  183. package/lib/typescript/hkdf.d.ts.map +1 -1
  184. package/lib/typescript/index.d.ts +32 -4
  185. package/lib/typescript/index.d.ts.map +1 -1
  186. package/lib/typescript/keys/classes.d.ts +7 -5
  187. package/lib/typescript/keys/classes.d.ts.map +1 -1
  188. package/lib/typescript/keys/generateKeyPair.d.ts.map +1 -1
  189. package/lib/typescript/keys/index.d.ts +2 -2
  190. package/lib/typescript/keys/index.d.ts.map +1 -1
  191. package/lib/typescript/keys/signVerify.d.ts.map +1 -1
  192. package/lib/typescript/mlkem.d.ts +30 -0
  193. package/lib/typescript/mlkem.d.ts.map +1 -0
  194. package/lib/typescript/pbkdf2.d.ts +2 -2
  195. package/lib/typescript/pbkdf2.d.ts.map +1 -1
  196. package/lib/typescript/prime.d.ts +19 -0
  197. package/lib/typescript/prime.d.ts.map +1 -0
  198. package/lib/typescript/rsa.d.ts +1 -1
  199. package/lib/typescript/rsa.d.ts.map +1 -1
  200. package/lib/typescript/specs/argon2.nitro.d.ts +9 -0
  201. package/lib/typescript/specs/argon2.nitro.d.ts.map +1 -0
  202. package/lib/typescript/specs/certificate.nitro.d.ts +10 -0
  203. package/lib/typescript/specs/certificate.nitro.d.ts.map +1 -0
  204. package/lib/typescript/specs/cipher.nitro.d.ts +9 -0
  205. package/lib/typescript/specs/cipher.nitro.d.ts.map +1 -1
  206. package/lib/typescript/specs/dhKeyPair.nitro.d.ts +14 -0
  207. package/lib/typescript/specs/dhKeyPair.nitro.d.ts.map +1 -0
  208. package/lib/typescript/specs/dsaKeyPair.nitro.d.ts +13 -0
  209. package/lib/typescript/specs/dsaKeyPair.nitro.d.ts.map +1 -0
  210. package/lib/typescript/specs/ecdh.nitro.d.ts +1 -0
  211. package/lib/typescript/specs/ecdh.nitro.d.ts.map +1 -1
  212. package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +1 -0
  213. package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -1
  214. package/lib/typescript/specs/kmac.nitro.d.ts +10 -0
  215. package/lib/typescript/specs/kmac.nitro.d.ts.map +1 -0
  216. package/lib/typescript/specs/mlKemKeyPair.nitro.d.ts +18 -0
  217. package/lib/typescript/specs/mlKemKeyPair.nitro.d.ts.map +1 -0
  218. package/lib/typescript/specs/prime.nitro.d.ts +11 -0
  219. package/lib/typescript/specs/prime.nitro.d.ts.map +1 -0
  220. package/lib/typescript/specs/x509certificate.nitro.d.ts +34 -0
  221. package/lib/typescript/specs/x509certificate.nitro.d.ts.map +1 -0
  222. package/lib/typescript/subtle.d.ts +12 -0
  223. package/lib/typescript/subtle.d.ts.map +1 -1
  224. package/lib/typescript/utils/conversion.d.ts.map +1 -1
  225. package/lib/typescript/utils/hashnames.d.ts +1 -1
  226. package/lib/typescript/utils/hashnames.d.ts.map +1 -1
  227. package/lib/typescript/utils/types.d.ts +25 -9
  228. package/lib/typescript/utils/types.d.ts.map +1 -1
  229. package/lib/typescript/x509certificate.d.ts +64 -0
  230. package/lib/typescript/x509certificate.d.ts.map +1 -0
  231. package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +8 -0
  232. package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +80 -0
  233. package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +80 -0
  234. package/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp +12 -0
  235. package/nitrogen/generated/shared/c++/CipherInfo.hpp +104 -0
  236. package/nitrogen/generated/shared/c++/HybridArgon2Spec.cpp +22 -0
  237. package/nitrogen/generated/shared/c++/HybridArgon2Spec.hpp +66 -0
  238. package/nitrogen/generated/shared/c++/HybridCertificateSpec.cpp +23 -0
  239. package/nitrogen/generated/shared/c++/HybridCertificateSpec.hpp +64 -0
  240. package/nitrogen/generated/shared/c++/HybridCipherSpec.cpp +1 -0
  241. package/nitrogen/generated/shared/c++/HybridCipherSpec.hpp +4 -0
  242. package/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.cpp +27 -0
  243. package/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.hpp +69 -0
  244. package/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.cpp +26 -0
  245. package/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.hpp +68 -0
  246. package/nitrogen/generated/shared/c++/HybridECDHSpec.cpp +1 -0
  247. package/nitrogen/generated/shared/c++/HybridECDHSpec.hpp +1 -0
  248. package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +1 -0
  249. package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +1 -0
  250. package/nitrogen/generated/shared/c++/HybridKmacSpec.cpp +23 -0
  251. package/nitrogen/generated/shared/c++/HybridKmacSpec.hpp +66 -0
  252. package/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.cpp +31 -0
  253. package/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.hpp +74 -0
  254. package/nitrogen/generated/shared/c++/HybridPrimeSpec.cpp +24 -0
  255. package/nitrogen/generated/shared/c++/HybridPrimeSpec.hpp +67 -0
  256. package/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.cpp +46 -0
  257. package/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.hpp +96 -0
  258. package/package.json +4 -1
  259. package/src/argon2.ts +83 -0
  260. package/src/certificate.ts +41 -0
  261. package/src/cipher.ts +41 -3
  262. package/src/dhKeyPair.ts +156 -0
  263. package/src/dsa.ts +129 -0
  264. package/src/ec.ts +9 -9
  265. package/src/ecdh.ts +59 -0
  266. package/src/ed.ts +2 -2
  267. package/src/hash.ts +34 -11
  268. package/src/hkdf.ts +2 -7
  269. package/src/index.ts +16 -0
  270. package/src/keys/classes.ts +26 -14
  271. package/src/keys/generateKeyPair.ts +14 -0
  272. package/src/keys/index.ts +37 -2
  273. package/src/keys/signVerify.ts +0 -5
  274. package/src/mlkem.ts +350 -0
  275. package/src/pbkdf2.ts +34 -5
  276. package/src/prime.ts +134 -0
  277. package/src/rsa.ts +1 -1
  278. package/src/specs/argon2.nitro.ts +29 -0
  279. package/src/specs/certificate.nitro.ts +8 -0
  280. package/src/specs/cipher.nitro.ts +14 -0
  281. package/src/specs/dhKeyPair.nitro.ts +14 -0
  282. package/src/specs/dsaKeyPair.nitro.ts +13 -0
  283. package/src/specs/ecdh.nitro.ts +1 -0
  284. package/src/specs/keyObjectHandle.nitro.ts +5 -0
  285. package/src/specs/kmac.nitro.ts +12 -0
  286. package/src/specs/mlKemKeyPair.nitro.ts +32 -0
  287. package/src/specs/prime.nitro.ts +18 -0
  288. package/src/specs/x509certificate.nitro.ts +38 -0
  289. package/src/subtle.ts +821 -136
  290. package/src/utils/conversion.ts +10 -4
  291. package/src/utils/hashnames.ts +33 -2
  292. package/src/utils/types.ts +64 -8
  293. package/src/x509certificate.ts +277 -0
@@ -1,7 +1,6 @@
1
1
  import { Buffer as CraftzdogBuffer } from '@craftzdog/react-native-buffer';
2
2
  import { Buffer as SafeBuffer } from 'safe-buffer';
3
3
  import type { ABV, BinaryLikeNode, BufferLike } from './types';
4
- import { KeyObject } from '../keys/classes';
5
4
 
6
5
  /**
7
6
  * Converts supplied argument to an ArrayBuffer. Note this does not copy the
@@ -133,9 +132,16 @@ export function binaryLikeToArrayBuffer(
133
132
  // }
134
133
  // }
135
134
 
136
- // KeyObject
137
- if (input instanceof KeyObject) {
138
- return input.handle.exportKey();
135
+ // KeyObject — duck-typed via Symbol.toStringTag to avoid circular dependency
136
+ // with keys/classes. The type assertion must match KeyObjectHandle.exportKey().
137
+ if (
138
+ typeof input === 'object' &&
139
+ input != null &&
140
+ Object.prototype.toString.call(input) === '[object KeyObject]'
141
+ ) {
142
+ return (
143
+ input as { handle: { exportKey(): ArrayBuffer } }
144
+ ).handle.exportKey();
139
145
  }
140
146
 
141
147
  throw new Error(
@@ -63,6 +63,26 @@ const kHashNames: HashNames = {
63
63
  [HashContext.Node]: 'ripemd160',
64
64
  [HashContext.WebCrypto]: 'RIPEMD-160',
65
65
  },
66
+ 'sha3-256': {
67
+ [HashContext.Node]: 'sha3-256',
68
+ [HashContext.WebCrypto]: 'SHA3-256',
69
+ },
70
+ 'sha3-384': {
71
+ [HashContext.Node]: 'sha3-384',
72
+ [HashContext.WebCrypto]: 'SHA3-384',
73
+ },
74
+ 'sha3-512': {
75
+ [HashContext.Node]: 'sha3-512',
76
+ [HashContext.WebCrypto]: 'SHA3-512',
77
+ },
78
+ shake128: {
79
+ [HashContext.Node]: 'shake128',
80
+ [HashContext.WebCrypto]: 'cSHAKE128',
81
+ },
82
+ shake256: {
83
+ [HashContext.Node]: 'shake256',
84
+ [HashContext.WebCrypto]: 'cSHAKE256',
85
+ },
66
86
  };
67
87
 
68
88
  {
@@ -76,18 +96,29 @@ const kHashNames: HashNames = {
76
96
  kHashNames[alias] = kHashNames[keys[n]!]!;
77
97
  }
78
98
  }
99
+
100
+ // Add OpenSSL legacy RSA-* aliases (e.g. RSA-SHA256 -> sha256)
101
+ for (let n: number = 0; n < keys.length; n++) {
102
+ const key = keys[n]!;
103
+ if (key.startsWith('sha') || key === 'ripemd160') {
104
+ const rsaAlias = 'rsa-' + key;
105
+ if (kHashNames[rsaAlias] === undefined) {
106
+ kHashNames[rsaAlias] = kHashNames[key]!;
107
+ }
108
+ }
109
+ }
79
110
  }
80
111
 
81
112
  export function normalizeHashName(
82
113
  algo: string | HashAlgorithm | { name: string } | undefined,
83
114
  context: HashContext = HashContext.Node,
84
- ): HashAlgorithm {
115
+ ): string {
85
116
  if (typeof algo !== 'undefined') {
86
117
  const hashName =
87
118
  typeof algo === 'string' ? algo : algo.name || algo.toString();
88
119
  const normAlgo = hashName.toLowerCase();
89
120
  try {
90
- const alias = kHashNames[normAlgo]![context] as HashAlgorithm;
121
+ const alias = kHashNames[normAlgo]![context];
91
122
  if (alias) return alias;
92
123
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
93
124
  } catch (_e) {
@@ -40,7 +40,16 @@ export type BinaryLike =
40
40
 
41
41
  export type BinaryLikeNode = CipherKey | BinaryLike | KeyObject;
42
42
 
43
- export type DigestAlgorithm = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
43
+ export type DigestAlgorithm =
44
+ | 'SHA-1'
45
+ | 'SHA-256'
46
+ | 'SHA-384'
47
+ | 'SHA-512'
48
+ | 'SHA3-256'
49
+ | 'SHA3-384'
50
+ | 'SHA3-512'
51
+ | 'cSHAKE128'
52
+ | 'cSHAKE256';
44
53
 
45
54
  export type HashAlgorithm = DigestAlgorithm | 'SHA-224' | 'RIPEMD-160';
46
55
 
@@ -65,8 +74,27 @@ export type ECKeyPairAlgorithm = 'ECDSA' | 'ECDH';
65
74
  export type CFRGKeyPairAlgorithm = 'Ed25519' | 'Ed448' | 'X25519' | 'X448';
66
75
  export type CFRGKeyPairType = 'ed25519' | 'ed448' | 'x25519' | 'x448';
67
76
 
68
- export type PQCKeyPairAlgorithm = 'ML-DSA-44' | 'ML-DSA-65' | 'ML-DSA-87';
69
- export type PQCKeyPairType = 'ml-dsa-44' | 'ml-dsa-65' | 'ml-dsa-87';
77
+ export type PQCKeyPairAlgorithm =
78
+ | 'ML-DSA-44'
79
+ | 'ML-DSA-65'
80
+ | 'ML-DSA-87'
81
+ | 'ML-KEM-512'
82
+ | 'ML-KEM-768'
83
+ | 'ML-KEM-1024';
84
+ export type PQCKeyPairType =
85
+ | 'ml-dsa-44'
86
+ | 'ml-dsa-65'
87
+ | 'ml-dsa-87'
88
+ | 'ml-kem-512'
89
+ | 'ml-kem-768'
90
+ | 'ml-kem-1024';
91
+
92
+ export type MlKemAlgorithm = 'ML-KEM-512' | 'ML-KEM-768' | 'ML-KEM-1024';
93
+
94
+ export interface EncapsulateResult {
95
+ sharedKey: ArrayBuffer;
96
+ ciphertext: ArrayBuffer;
97
+ }
70
98
 
71
99
  // Node.js style key pair types (lowercase)
72
100
  export type RSAKeyPairType = 'rsa' | 'rsa-pss';
@@ -94,18 +122,23 @@ export type SignVerifyAlgorithm =
94
122
  | 'RSA-PSS'
95
123
  | 'ECDSA'
96
124
  | 'HMAC'
125
+ | 'KMAC128'
126
+ | 'KMAC256'
97
127
  | 'Ed25519'
98
128
  | 'Ed448'
99
129
  | 'ML-DSA-44'
100
130
  | 'ML-DSA-65'
101
131
  | 'ML-DSA-87';
102
132
 
133
+ export type Argon2Algorithm = 'Argon2d' | 'Argon2i' | 'Argon2id';
134
+
103
135
  export type DeriveBitsAlgorithm =
104
136
  | 'PBKDF2'
105
137
  | 'HKDF'
106
138
  | 'ECDH'
107
139
  | 'X25519'
108
- | 'X448';
140
+ | 'X448'
141
+ | Argon2Algorithm;
109
142
 
110
143
  export type EncryptDecryptAlgorithm =
111
144
  | 'RSA-OAEP'
@@ -193,15 +226,27 @@ export type NamedCurve = 'P-256' | 'P-384' | 'P-521';
193
226
 
194
227
  export type SubtleAlgorithm = {
195
228
  name: AnyAlgorithm;
196
- salt?: string;
229
+ salt?: string | BufferLike;
197
230
  iterations?: number;
198
- hash?: HashAlgorithm | { name: string };
231
+ hash?: HashAlgorithm | string | { name: string };
199
232
  namedCurve?: NamedCurve;
200
233
  length?: number;
201
234
  modulusLength?: number;
202
235
  publicExponent?: number | Uint8Array;
203
236
  saltLength?: number;
204
237
  public?: CryptoKey;
238
+ info?: BufferLike;
239
+ // Argon2 parameters
240
+ nonce?: BufferLike;
241
+ parallelism?: number;
242
+ tagLength?: number;
243
+ memory?: number;
244
+ passes?: number;
245
+ secretValue?: BufferLike;
246
+ associatedData?: BufferLike;
247
+ version?: number;
248
+ // KMAC parameters
249
+ customization?: BufferLike;
205
250
  };
206
251
 
207
252
  export type KeyPairType =
@@ -462,7 +507,14 @@ export type DiffieHellmanCallback = (
462
507
  // from @paulmillr/noble-curves
463
508
  export type Hex = string | Uint8Array;
464
509
 
465
- export type ImportFormat = 'raw' | 'raw-secret' | 'pkcs8' | 'spki' | 'jwk';
510
+ export type ImportFormat =
511
+ | 'raw'
512
+ | 'raw-public'
513
+ | 'raw-secret'
514
+ | 'raw-seed'
515
+ | 'pkcs8'
516
+ | 'spki'
517
+ | 'jwk';
466
518
 
467
519
  export type Operation =
468
520
  | 'encrypt'
@@ -474,7 +526,11 @@ export type Operation =
474
526
  | 'exportKey'
475
527
  | 'deriveBits'
476
528
  | 'wrapKey'
477
- | 'unwrapKey';
529
+ | 'unwrapKey'
530
+ | 'encapsulateBits'
531
+ | 'decapsulateBits'
532
+ | 'encapsulateKey'
533
+ | 'decapsulateKey';
478
534
 
479
535
  export interface KeyPairOptions {
480
536
  namedCurve: string;
@@ -0,0 +1,277 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ import { Buffer } from '@craftzdog/react-native-buffer';
3
+ import type { X509CertificateHandle } from './specs/x509certificate.nitro';
4
+ import { PublicKeyObject, KeyObject } from './keys';
5
+ import type { BinaryLike } from './utils';
6
+ import { binaryLikeToArrayBuffer } from './utils';
7
+
8
+ const X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT = 0x1;
9
+ const X509_CHECK_FLAG_NO_WILDCARDS = 0x2;
10
+ const X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS = 0x4;
11
+ const X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS = 0x8;
12
+ const X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS = 0x10;
13
+ const X509_CHECK_FLAG_NEVER_CHECK_SUBJECT = 0x20;
14
+
15
+ export interface X509LegacyObject {
16
+ subject: string;
17
+ issuer: string;
18
+ subjectaltname: string;
19
+ infoAccess: string;
20
+ ca: boolean;
21
+ modulus: undefined;
22
+ bits: undefined;
23
+ exponent: undefined;
24
+ valid_from: string;
25
+ valid_to: string;
26
+ fingerprint: string;
27
+ fingerprint256: string;
28
+ fingerprint512: string;
29
+ ext_key_usage: string[];
30
+ serialNumber: string;
31
+ raw: Buffer;
32
+ }
33
+
34
+ export interface CheckOptions {
35
+ subject?: 'default' | 'always' | 'never';
36
+ wildcards?: boolean;
37
+ partialWildcards?: boolean;
38
+ multiLabelWildcards?: boolean;
39
+ singleLabelSubdomains?: boolean;
40
+ }
41
+
42
+ function getFlags(options?: CheckOptions): number {
43
+ if (!options) return 0;
44
+
45
+ let flags = 0;
46
+
47
+ if (options.subject === 'always') {
48
+ flags |= X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT;
49
+ } else if (options.subject === 'never') {
50
+ flags |= X509_CHECK_FLAG_NEVER_CHECK_SUBJECT;
51
+ }
52
+
53
+ if (options.wildcards === false) {
54
+ flags |= X509_CHECK_FLAG_NO_WILDCARDS;
55
+ }
56
+
57
+ if (options.partialWildcards === false) {
58
+ flags |= X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS;
59
+ }
60
+
61
+ if (options.multiLabelWildcards === true) {
62
+ flags |= X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS;
63
+ }
64
+
65
+ if (options.singleLabelSubdomains === true) {
66
+ flags |= X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS;
67
+ }
68
+
69
+ return flags;
70
+ }
71
+
72
+ export class X509Certificate {
73
+ private readonly handle: X509CertificateHandle;
74
+ private readonly cache = new Map<string, unknown>();
75
+
76
+ constructor(buffer: BinaryLike) {
77
+ this.handle = NitroModules.createHybridObject<X509CertificateHandle>(
78
+ 'X509CertificateHandle',
79
+ );
80
+
81
+ let ab: ArrayBuffer;
82
+ if (typeof buffer === 'string') {
83
+ ab = Buffer.from(buffer).buffer as ArrayBuffer;
84
+ } else {
85
+ ab = binaryLikeToArrayBuffer(buffer);
86
+ }
87
+
88
+ this.handle.init(ab);
89
+ }
90
+
91
+ private cached<T>(key: string, compute: () => T): T {
92
+ if (this.cache.has(key)) {
93
+ return this.cache.get(key) as T;
94
+ }
95
+ const value = compute();
96
+ this.cache.set(key, value);
97
+ return value;
98
+ }
99
+
100
+ get subject(): string {
101
+ return this.cached('subject', () => this.handle.subject());
102
+ }
103
+
104
+ get subjectAltName(): string {
105
+ return this.cached('subjectAltName', () => this.handle.subjectAltName());
106
+ }
107
+
108
+ get issuer(): string {
109
+ return this.cached('issuer', () => this.handle.issuer());
110
+ }
111
+
112
+ get infoAccess(): string {
113
+ return this.cached('infoAccess', () => this.handle.infoAccess());
114
+ }
115
+
116
+ get validFrom(): string {
117
+ return this.cached('validFrom', () => this.handle.validFrom());
118
+ }
119
+
120
+ get validTo(): string {
121
+ return this.cached('validTo', () => this.handle.validTo());
122
+ }
123
+
124
+ get validFromDate(): Date {
125
+ return this.cached(
126
+ 'validFromDate',
127
+ () => new Date(this.handle.validFromDate()),
128
+ );
129
+ }
130
+
131
+ get validToDate(): Date {
132
+ return this.cached(
133
+ 'validToDate',
134
+ () => new Date(this.handle.validToDate()),
135
+ );
136
+ }
137
+
138
+ get fingerprint(): string {
139
+ return this.cached('fingerprint', () => this.handle.fingerprint());
140
+ }
141
+
142
+ get fingerprint256(): string {
143
+ return this.cached('fingerprint256', () => this.handle.fingerprint256());
144
+ }
145
+
146
+ get fingerprint512(): string {
147
+ return this.cached('fingerprint512', () => this.handle.fingerprint512());
148
+ }
149
+
150
+ get extKeyUsage(): string[] {
151
+ return this.cached('extKeyUsage', () => this.handle.keyUsage());
152
+ }
153
+
154
+ get keyUsage(): string[] {
155
+ return this.extKeyUsage;
156
+ }
157
+
158
+ get serialNumber(): string {
159
+ return this.cached('serialNumber', () => this.handle.serialNumber());
160
+ }
161
+
162
+ get signatureAlgorithm(): string {
163
+ return this.cached('signatureAlgorithm', () =>
164
+ this.handle.signatureAlgorithm(),
165
+ );
166
+ }
167
+
168
+ get signatureAlgorithmOid(): string {
169
+ return this.cached('signatureAlgorithmOid', () =>
170
+ this.handle.signatureAlgorithmOid(),
171
+ );
172
+ }
173
+
174
+ get ca(): boolean {
175
+ return this.cached('ca', () => this.handle.ca());
176
+ }
177
+
178
+ get raw(): Buffer {
179
+ return this.cached('raw', () => Buffer.from(this.handle.raw()));
180
+ }
181
+
182
+ get publicKey(): PublicKeyObject {
183
+ return this.cached(
184
+ 'publicKey',
185
+ () => new PublicKeyObject(this.handle.publicKey()),
186
+ );
187
+ }
188
+
189
+ get issuerCertificate(): undefined {
190
+ return undefined;
191
+ }
192
+
193
+ checkHost(name: string, options?: CheckOptions): string | undefined {
194
+ if (typeof name !== 'string') {
195
+ throw new TypeError('The "name" argument must be a string');
196
+ }
197
+ return this.handle.checkHost(name, getFlags(options));
198
+ }
199
+
200
+ checkEmail(email: string, options?: CheckOptions): string | undefined {
201
+ if (typeof email !== 'string') {
202
+ throw new TypeError('The "email" argument must be a string');
203
+ }
204
+ return this.handle.checkEmail(email, getFlags(options));
205
+ }
206
+
207
+ checkIP(ip: string): string | undefined {
208
+ if (typeof ip !== 'string') {
209
+ throw new TypeError('The "ip" argument must be a string');
210
+ }
211
+ return this.handle.checkIP(ip);
212
+ }
213
+
214
+ checkIssued(otherCert: X509Certificate): boolean {
215
+ if (!(otherCert instanceof X509Certificate)) {
216
+ throw new TypeError(
217
+ 'The "otherCert" argument must be an instance of X509Certificate',
218
+ );
219
+ }
220
+ return this.handle.checkIssued(otherCert.handle);
221
+ }
222
+
223
+ checkPrivateKey(pkey: KeyObject): boolean {
224
+ if (!(pkey instanceof KeyObject)) {
225
+ throw new TypeError(
226
+ 'The "pkey" argument must be an instance of KeyObject',
227
+ );
228
+ }
229
+ if (pkey.type !== 'private') {
230
+ throw new TypeError('The "pkey" argument must be a private key');
231
+ }
232
+ return this.handle.checkPrivateKey(pkey.handle);
233
+ }
234
+
235
+ verify(pkey: KeyObject): boolean {
236
+ if (!(pkey instanceof KeyObject)) {
237
+ throw new TypeError(
238
+ 'The "pkey" argument must be an instance of KeyObject',
239
+ );
240
+ }
241
+ if (pkey.type !== 'public') {
242
+ throw new TypeError(
243
+ `The "pkey" argument must be a public key, got '${pkey.type}'`,
244
+ );
245
+ }
246
+ return this.handle.verify(pkey.handle);
247
+ }
248
+
249
+ toString(): string {
250
+ return this.cached('pem', () => this.handle.pem());
251
+ }
252
+
253
+ toJSON(): string {
254
+ return this.toString();
255
+ }
256
+
257
+ toLegacyObject(): X509LegacyObject {
258
+ return {
259
+ subject: this.subject,
260
+ issuer: this.issuer,
261
+ subjectaltname: this.subjectAltName,
262
+ infoAccess: this.infoAccess,
263
+ ca: this.ca,
264
+ modulus: undefined,
265
+ bits: undefined,
266
+ exponent: undefined,
267
+ valid_from: this.validFrom,
268
+ valid_to: this.validTo,
269
+ fingerprint: this.fingerprint,
270
+ fingerprint256: this.fingerprint256,
271
+ fingerprint512: this.fingerprint512,
272
+ ext_key_usage: this.keyUsage,
273
+ serialNumber: this.serialNumber,
274
+ raw: this.raw,
275
+ };
276
+ }
277
+ }