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.
- package/android/CMakeLists.txt +16 -0
- package/cpp/argon2/HybridArgon2.cpp +103 -0
- package/cpp/argon2/HybridArgon2.hpp +32 -0
- package/cpp/certificate/HybridCertificate.cpp +42 -0
- package/cpp/certificate/HybridCertificate.hpp +16 -0
- package/cpp/cipher/CCMCipher.cpp +4 -1
- package/cpp/cipher/ChaCha20Cipher.cpp +3 -1
- package/cpp/cipher/ChaCha20Poly1305Cipher.cpp +5 -5
- package/cpp/cipher/ChaCha20Poly1305Cipher.hpp +1 -2
- package/cpp/cipher/HybridCipher.cpp +68 -1
- package/cpp/cipher/HybridCipher.hpp +6 -0
- package/cpp/cipher/HybridRsaCipher.cpp +0 -13
- package/cpp/cipher/XChaCha20Poly1305Cipher.cpp +7 -5
- package/cpp/cipher/XChaCha20Poly1305Cipher.hpp +1 -2
- package/cpp/cipher/XSalsa20Cipher.cpp +4 -0
- package/cpp/cipher/XSalsa20Poly1305Cipher.cpp +7 -5
- package/cpp/cipher/XSalsa20Poly1305Cipher.hpp +1 -2
- package/cpp/dh/HybridDhKeyPair.cpp +179 -0
- package/cpp/dh/HybridDhKeyPair.hpp +37 -0
- package/cpp/dsa/HybridDsaKeyPair.cpp +128 -0
- package/cpp/dsa/HybridDsaKeyPair.hpp +32 -0
- package/cpp/ecdh/HybridECDH.cpp +42 -120
- package/cpp/ecdh/HybridECDH.hpp +1 -0
- package/cpp/keys/HybridKeyObjectHandle.cpp +150 -128
- package/cpp/keys/HybridKeyObjectHandle.hpp +6 -3
- package/cpp/keys/KeyObjectData.hpp +2 -0
- package/cpp/kmac/HybridKmac.cpp +83 -0
- package/cpp/kmac/HybridKmac.hpp +31 -0
- package/cpp/mldsa/HybridMlDsaKeyPair.cpp +11 -20
- package/cpp/mldsa/HybridMlDsaKeyPair.hpp +4 -2
- package/cpp/mlkem/HybridMlKemKeyPair.cpp +319 -0
- package/cpp/mlkem/HybridMlKemKeyPair.hpp +48 -0
- package/cpp/prime/HybridPrime.cpp +81 -0
- package/cpp/prime/HybridPrime.hpp +20 -0
- package/cpp/sign/SignUtils.hpp +9 -26
- package/cpp/utils/QuickCryptoUtils.cpp +44 -0
- package/cpp/utils/QuickCryptoUtils.hpp +39 -0
- package/cpp/x509/HybridX509Certificate.cpp +174 -0
- package/cpp/x509/HybridX509Certificate.hpp +51 -0
- package/lib/commonjs/argon2.js +39 -0
- package/lib/commonjs/argon2.js.map +1 -0
- package/lib/commonjs/certificate.js +35 -0
- package/lib/commonjs/certificate.js.map +1 -0
- package/lib/commonjs/cipher.js +23 -2
- package/lib/commonjs/cipher.js.map +1 -1
- package/lib/commonjs/dhKeyPair.js +109 -0
- package/lib/commonjs/dhKeyPair.js.map +1 -0
- package/lib/commonjs/dsa.js +92 -0
- package/lib/commonjs/dsa.js.map +1 -0
- package/lib/commonjs/ec.js +18 -18
- package/lib/commonjs/ec.js.map +1 -1
- package/lib/commonjs/ecdh.js +37 -0
- package/lib/commonjs/ecdh.js.map +1 -1
- package/lib/commonjs/ed.js +9 -9
- package/lib/commonjs/ed.js.map +1 -1
- package/lib/commonjs/hash.js +17 -12
- package/lib/commonjs/hash.js.map +1 -1
- package/lib/commonjs/hkdf.js.map +1 -1
- package/lib/commonjs/index.js +57 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys/classes.js +11 -9
- package/lib/commonjs/keys/classes.js.map +1 -1
- package/lib/commonjs/keys/generateKeyPair.js +11 -0
- package/lib/commonjs/keys/generateKeyPair.js.map +1 -1
- package/lib/commonjs/keys/index.js +24 -0
- package/lib/commonjs/keys/index.js.map +1 -1
- package/lib/commonjs/keys/signVerify.js +0 -2
- package/lib/commonjs/keys/signVerify.js.map +1 -1
- package/lib/commonjs/mlkem.js +219 -0
- package/lib/commonjs/mlkem.js.map +1 -0
- package/lib/commonjs/pbkdf2.js +18 -1
- package/lib/commonjs/pbkdf2.js.map +1 -1
- package/lib/commonjs/prime.js +84 -0
- package/lib/commonjs/prime.js.map +1 -0
- package/lib/commonjs/rsa.js +7 -7
- package/lib/commonjs/rsa.js.map +1 -1
- package/lib/commonjs/specs/argon2.nitro.js +6 -0
- package/lib/commonjs/specs/argon2.nitro.js.map +1 -0
- package/lib/commonjs/specs/certificate.nitro.js +6 -0
- package/lib/commonjs/specs/certificate.nitro.js.map +1 -0
- package/lib/commonjs/specs/dhKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/dhKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/specs/dsaKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/dsaKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/specs/kmac.nitro.js +6 -0
- package/lib/commonjs/specs/kmac.nitro.js.map +1 -0
- package/lib/commonjs/specs/mlKemKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/mlKemKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/specs/prime.nitro.js +6 -0
- package/lib/commonjs/specs/prime.nitro.js.map +1 -0
- package/lib/commonjs/specs/x509certificate.nitro.js +6 -0
- package/lib/commonjs/specs/x509certificate.nitro.js.map +1 -0
- package/lib/commonjs/subtle.js +385 -114
- package/lib/commonjs/subtle.js.map +1 -1
- package/lib/commonjs/utils/conversion.js +3 -3
- package/lib/commonjs/utils/conversion.js.map +1 -1
- package/lib/commonjs/utils/hashnames.js +31 -0
- package/lib/commonjs/utils/hashnames.js.map +1 -1
- package/lib/commonjs/utils/types.js.map +1 -1
- package/lib/commonjs/x509certificate.js +189 -0
- package/lib/commonjs/x509certificate.js.map +1 -0
- package/lib/module/argon2.js +34 -0
- package/lib/module/argon2.js.map +1 -0
- package/lib/module/certificate.js +30 -0
- package/lib/module/certificate.js.map +1 -0
- package/lib/module/cipher.js +23 -3
- package/lib/module/cipher.js.map +1 -1
- package/lib/module/dhKeyPair.js +102 -0
- package/lib/module/dhKeyPair.js.map +1 -0
- package/lib/module/dsa.js +85 -0
- package/lib/module/dsa.js.map +1 -0
- package/lib/module/ec.js +6 -6
- package/lib/module/ec.js.map +1 -1
- package/lib/module/ecdh.js +37 -0
- package/lib/module/ecdh.js.map +1 -1
- package/lib/module/ed.js +1 -1
- package/lib/module/ed.js.map +1 -1
- package/lib/module/hash.js +17 -12
- package/lib/module/hash.js.map +1 -1
- package/lib/module/hkdf.js.map +1 -1
- package/lib/module/index.js +15 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys/classes.js +11 -9
- package/lib/module/keys/classes.js.map +1 -1
- package/lib/module/keys/generateKeyPair.js +11 -0
- package/lib/module/keys/generateKeyPair.js.map +1 -1
- package/lib/module/keys/index.js +25 -1
- package/lib/module/keys/index.js.map +1 -1
- package/lib/module/keys/signVerify.js +0 -2
- package/lib/module/keys/signVerify.js.map +1 -1
- package/lib/module/mlkem.js +211 -0
- package/lib/module/mlkem.js.map +1 -0
- package/lib/module/pbkdf2.js +18 -1
- package/lib/module/pbkdf2.js.map +1 -1
- package/lib/module/prime.js +77 -0
- package/lib/module/prime.js.map +1 -0
- package/lib/module/rsa.js +1 -1
- package/lib/module/rsa.js.map +1 -1
- package/lib/module/specs/argon2.nitro.js +4 -0
- package/lib/module/specs/argon2.nitro.js.map +1 -0
- package/lib/module/specs/certificate.nitro.js +4 -0
- package/lib/module/specs/certificate.nitro.js.map +1 -0
- package/lib/module/specs/dhKeyPair.nitro.js +4 -0
- package/lib/module/specs/dhKeyPair.nitro.js.map +1 -0
- package/lib/module/specs/dsaKeyPair.nitro.js +4 -0
- package/lib/module/specs/dsaKeyPair.nitro.js.map +1 -0
- package/lib/module/specs/kmac.nitro.js +4 -0
- package/lib/module/specs/kmac.nitro.js.map +1 -0
- package/lib/module/specs/mlKemKeyPair.nitro.js +4 -0
- package/lib/module/specs/mlKemKeyPair.nitro.js.map +1 -0
- package/lib/module/specs/prime.nitro.js +4 -0
- package/lib/module/specs/prime.nitro.js.map +1 -0
- package/lib/module/specs/x509certificate.nitro.js +4 -0
- package/lib/module/specs/x509certificate.nitro.js.map +1 -0
- package/lib/module/subtle.js +386 -116
- package/lib/module/subtle.js.map +1 -1
- package/lib/module/utils/conversion.js +3 -4
- package/lib/module/utils/conversion.js.map +1 -1
- package/lib/module/utils/hashnames.js +31 -0
- package/lib/module/utils/hashnames.js.map +1 -1
- package/lib/module/utils/types.js.map +1 -1
- package/lib/module/x509certificate.js +184 -0
- package/lib/module/x509certificate.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/argon2.d.ts +16 -0
- package/lib/typescript/argon2.d.ts.map +1 -0
- package/lib/typescript/certificate.d.ts +8 -0
- package/lib/typescript/certificate.d.ts.map +1 -0
- package/lib/typescript/cipher.d.ts +15 -0
- package/lib/typescript/cipher.d.ts.map +1 -1
- package/lib/typescript/dhKeyPair.d.ts +19 -0
- package/lib/typescript/dhKeyPair.d.ts.map +1 -0
- package/lib/typescript/dsa.d.ts +19 -0
- package/lib/typescript/dsa.d.ts.map +1 -0
- package/lib/typescript/ec.d.ts +1 -1
- package/lib/typescript/ec.d.ts.map +1 -1
- package/lib/typescript/ecdh.d.ts +3 -0
- package/lib/typescript/ecdh.d.ts.map +1 -1
- package/lib/typescript/ed.d.ts +1 -1
- package/lib/typescript/ed.d.ts.map +1 -1
- package/lib/typescript/hash.d.ts.map +1 -1
- package/lib/typescript/hkdf.d.ts +2 -6
- package/lib/typescript/hkdf.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +32 -4
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/keys/classes.d.ts +7 -5
- package/lib/typescript/keys/classes.d.ts.map +1 -1
- package/lib/typescript/keys/generateKeyPair.d.ts.map +1 -1
- package/lib/typescript/keys/index.d.ts +2 -2
- package/lib/typescript/keys/index.d.ts.map +1 -1
- package/lib/typescript/keys/signVerify.d.ts.map +1 -1
- package/lib/typescript/mlkem.d.ts +30 -0
- package/lib/typescript/mlkem.d.ts.map +1 -0
- package/lib/typescript/pbkdf2.d.ts +2 -2
- package/lib/typescript/pbkdf2.d.ts.map +1 -1
- package/lib/typescript/prime.d.ts +19 -0
- package/lib/typescript/prime.d.ts.map +1 -0
- package/lib/typescript/rsa.d.ts +1 -1
- package/lib/typescript/rsa.d.ts.map +1 -1
- package/lib/typescript/specs/argon2.nitro.d.ts +9 -0
- package/lib/typescript/specs/argon2.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/certificate.nitro.d.ts +10 -0
- package/lib/typescript/specs/certificate.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/cipher.nitro.d.ts +9 -0
- package/lib/typescript/specs/cipher.nitro.d.ts.map +1 -1
- package/lib/typescript/specs/dhKeyPair.nitro.d.ts +14 -0
- package/lib/typescript/specs/dhKeyPair.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/dsaKeyPair.nitro.d.ts +13 -0
- package/lib/typescript/specs/dsaKeyPair.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/ecdh.nitro.d.ts +1 -0
- package/lib/typescript/specs/ecdh.nitro.d.ts.map +1 -1
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +1 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -1
- package/lib/typescript/specs/kmac.nitro.d.ts +10 -0
- package/lib/typescript/specs/kmac.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/mlKemKeyPair.nitro.d.ts +18 -0
- package/lib/typescript/specs/mlKemKeyPair.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/prime.nitro.d.ts +11 -0
- package/lib/typescript/specs/prime.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/x509certificate.nitro.d.ts +34 -0
- package/lib/typescript/specs/x509certificate.nitro.d.ts.map +1 -0
- package/lib/typescript/subtle.d.ts +12 -0
- package/lib/typescript/subtle.d.ts.map +1 -1
- package/lib/typescript/utils/conversion.d.ts.map +1 -1
- package/lib/typescript/utils/hashnames.d.ts +1 -1
- package/lib/typescript/utils/hashnames.d.ts.map +1 -1
- package/lib/typescript/utils/types.d.ts +25 -9
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/lib/typescript/x509certificate.d.ts +64 -0
- package/lib/typescript/x509certificate.d.ts.map +1 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +8 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +80 -0
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +80 -0
- package/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp +12 -0
- package/nitrogen/generated/shared/c++/CipherInfo.hpp +104 -0
- package/nitrogen/generated/shared/c++/HybridArgon2Spec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridArgon2Spec.hpp +66 -0
- package/nitrogen/generated/shared/c++/HybridCertificateSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridCertificateSpec.hpp +64 -0
- package/nitrogen/generated/shared/c++/HybridCipherSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridCipherSpec.hpp +4 -0
- package/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.cpp +27 -0
- package/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.hpp +69 -0
- package/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.hpp +68 -0
- package/nitrogen/generated/shared/c++/HybridECDHSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridECDHSpec.hpp +1 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +1 -0
- package/nitrogen/generated/shared/c++/HybridKmacSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridKmacSpec.hpp +66 -0
- package/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.cpp +31 -0
- package/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.hpp +74 -0
- package/nitrogen/generated/shared/c++/HybridPrimeSpec.cpp +24 -0
- package/nitrogen/generated/shared/c++/HybridPrimeSpec.hpp +67 -0
- package/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.cpp +46 -0
- package/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.hpp +96 -0
- package/package.json +4 -1
- package/src/argon2.ts +83 -0
- package/src/certificate.ts +41 -0
- package/src/cipher.ts +41 -3
- package/src/dhKeyPair.ts +156 -0
- package/src/dsa.ts +129 -0
- package/src/ec.ts +9 -9
- package/src/ecdh.ts +59 -0
- package/src/ed.ts +2 -2
- package/src/hash.ts +34 -11
- package/src/hkdf.ts +2 -7
- package/src/index.ts +16 -0
- package/src/keys/classes.ts +26 -14
- package/src/keys/generateKeyPair.ts +14 -0
- package/src/keys/index.ts +37 -2
- package/src/keys/signVerify.ts +0 -5
- package/src/mlkem.ts +350 -0
- package/src/pbkdf2.ts +34 -5
- package/src/prime.ts +134 -0
- package/src/rsa.ts +1 -1
- package/src/specs/argon2.nitro.ts +29 -0
- package/src/specs/certificate.nitro.ts +8 -0
- package/src/specs/cipher.nitro.ts +14 -0
- package/src/specs/dhKeyPair.nitro.ts +14 -0
- package/src/specs/dsaKeyPair.nitro.ts +13 -0
- package/src/specs/ecdh.nitro.ts +1 -0
- package/src/specs/keyObjectHandle.nitro.ts +5 -0
- package/src/specs/kmac.nitro.ts +12 -0
- package/src/specs/mlKemKeyPair.nitro.ts +32 -0
- package/src/specs/prime.nitro.ts +18 -0
- package/src/specs/x509certificate.nitro.ts +38 -0
- package/src/subtle.ts +821 -136
- package/src/utils/conversion.ts +10 -4
- package/src/utils/hashnames.ts +33 -2
- package/src/utils/types.ts +64 -8
- package/src/x509certificate.ts +277 -0
package/src/hash.ts
CHANGED
|
@@ -241,19 +241,38 @@ export const asyncDigest = async (
|
|
|
241
241
|
): Promise<ArrayBuffer> => {
|
|
242
242
|
validateMaxBufferLength(data, 'data');
|
|
243
243
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
244
|
+
const name = algorithm.name;
|
|
245
|
+
|
|
246
|
+
if (
|
|
247
|
+
name === 'SHA-1' ||
|
|
248
|
+
name === 'SHA-256' ||
|
|
249
|
+
name === 'SHA-384' ||
|
|
250
|
+
name === 'SHA-512' ||
|
|
251
|
+
name === 'SHA3-256' ||
|
|
252
|
+
name === 'SHA3-384' ||
|
|
253
|
+
name === 'SHA3-512'
|
|
254
|
+
) {
|
|
255
|
+
return internalDigest(algorithm, data);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (name === 'cSHAKE128' || name === 'cSHAKE256') {
|
|
259
|
+
if (typeof algorithm.length !== 'number' || algorithm.length <= 0) {
|
|
260
|
+
throw lazyDOMException(
|
|
261
|
+
'cSHAKE requires a length parameter',
|
|
262
|
+
'OperationError',
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
if (algorithm.length % 8) {
|
|
266
|
+
throw lazyDOMException(
|
|
267
|
+
'Unsupported CShakeParams length',
|
|
268
|
+
'NotSupportedError',
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
return internalDigest(algorithm, data, algorithm.length);
|
|
253
272
|
}
|
|
254
273
|
|
|
255
274
|
throw lazyDOMException(
|
|
256
|
-
`Unrecognized algorithm name: ${
|
|
275
|
+
`Unrecognized algorithm name: ${name}`,
|
|
257
276
|
'NotSupportedError',
|
|
258
277
|
);
|
|
259
278
|
};
|
|
@@ -261,9 +280,13 @@ export const asyncDigest = async (
|
|
|
261
280
|
const internalDigest = (
|
|
262
281
|
algorithm: SubtleAlgorithm,
|
|
263
282
|
data: BufferLike,
|
|
283
|
+
outputLength?: number,
|
|
264
284
|
): ArrayBuffer => {
|
|
265
285
|
const normalizedHashName = normalizeHashName(algorithm.name);
|
|
266
|
-
const hash = createHash(
|
|
286
|
+
const hash = createHash(
|
|
287
|
+
normalizedHashName,
|
|
288
|
+
outputLength ? { outputLength } : undefined,
|
|
289
|
+
);
|
|
267
290
|
hash.update(bufferLikeToArrayBuffer(data));
|
|
268
291
|
const result = hash.digest();
|
|
269
292
|
const arrayBuffer = new ArrayBuffer(result.length);
|
package/src/hkdf.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { NitroModules } from 'react-native-nitro-modules';
|
|
|
3
3
|
import type { Hkdf as HkdfNative } from './specs/hkdf.nitro';
|
|
4
4
|
import { binaryLikeToArrayBuffer, normalizeHashName } from './utils';
|
|
5
5
|
import type { BinaryLike } from './utils';
|
|
6
|
+
import type { CryptoKey } from './keys';
|
|
6
7
|
|
|
7
8
|
type KeyMaterial = BinaryLike;
|
|
8
9
|
type Salt = BinaryLike;
|
|
@@ -15,12 +16,6 @@ export interface HkdfAlgorithm {
|
|
|
15
16
|
info: BinaryLike;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export interface CryptoKeyInternal {
|
|
19
|
-
keyObject: {
|
|
20
|
-
export: () => Buffer;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
19
|
export interface HkdfCallback {
|
|
25
20
|
(err: Error | null, derivedKey?: Buffer): void;
|
|
26
21
|
}
|
|
@@ -122,7 +117,7 @@ export function hkdfSync(
|
|
|
122
117
|
|
|
123
118
|
export function hkdfDeriveBits(
|
|
124
119
|
algorithm: HkdfAlgorithm,
|
|
125
|
-
baseKey:
|
|
120
|
+
baseKey: CryptoKey,
|
|
126
121
|
length: number,
|
|
127
122
|
): ArrayBuffer {
|
|
128
123
|
const hash = algorithm.hash;
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
3
3
|
|
|
4
4
|
// API imports
|
|
5
|
+
import * as argon2Module from './argon2';
|
|
5
6
|
import * as keys from './keys';
|
|
6
7
|
import * as blake3 from './blake3';
|
|
7
8
|
import * as cipher from './cipher';
|
|
@@ -10,10 +11,14 @@ import { hashExports as hash } from './hash';
|
|
|
10
11
|
import { hmacExports as hmac } from './hmac';
|
|
11
12
|
import * as hkdf from './hkdf';
|
|
12
13
|
import * as pbkdf2 from './pbkdf2';
|
|
14
|
+
import * as prime from './prime';
|
|
13
15
|
import * as scrypt from './scrypt';
|
|
14
16
|
import * as random from './random';
|
|
15
17
|
import * as ecdh from './ecdh';
|
|
16
18
|
import * as dh from './diffie-hellman';
|
|
19
|
+
import * as mlkem from './mlkem';
|
|
20
|
+
import { Certificate } from './certificate';
|
|
21
|
+
import { X509Certificate } from './x509certificate';
|
|
17
22
|
import { getCurves } from './ec';
|
|
18
23
|
import { constants } from './constants';
|
|
19
24
|
|
|
@@ -26,6 +31,7 @@ import * as subtle from './subtle';
|
|
|
26
31
|
* See `docs/implementation-coverage.md` for status.
|
|
27
32
|
*/
|
|
28
33
|
const QuickCrypto = {
|
|
34
|
+
...argon2Module,
|
|
29
35
|
...keys,
|
|
30
36
|
...blake3,
|
|
31
37
|
...cipher,
|
|
@@ -34,12 +40,16 @@ const QuickCrypto = {
|
|
|
34
40
|
...hmac,
|
|
35
41
|
...hkdf,
|
|
36
42
|
...pbkdf2,
|
|
43
|
+
...prime,
|
|
37
44
|
...scrypt,
|
|
38
45
|
...random,
|
|
39
46
|
...ecdh,
|
|
40
47
|
...dh,
|
|
48
|
+
...mlkem,
|
|
41
49
|
...utils,
|
|
42
50
|
...subtle,
|
|
51
|
+
Certificate,
|
|
52
|
+
X509Certificate,
|
|
43
53
|
getCurves,
|
|
44
54
|
constants,
|
|
45
55
|
Buffer,
|
|
@@ -72,7 +82,11 @@ if (global.process.nextTick == null) {
|
|
|
72
82
|
|
|
73
83
|
// exports
|
|
74
84
|
export default QuickCrypto;
|
|
85
|
+
export * from './argon2';
|
|
75
86
|
export * from './blake3';
|
|
87
|
+
export { Certificate } from './certificate';
|
|
88
|
+
export { X509Certificate } from './x509certificate';
|
|
89
|
+
export type { CheckOptions, X509LegacyObject } from './x509certificate';
|
|
76
90
|
export * from './cipher';
|
|
77
91
|
export * from './ed';
|
|
78
92
|
export * from './keys';
|
|
@@ -80,11 +94,13 @@ export * from './hash';
|
|
|
80
94
|
export * from './hmac';
|
|
81
95
|
export * from './hkdf';
|
|
82
96
|
export * from './pbkdf2';
|
|
97
|
+
export * from './prime';
|
|
83
98
|
export * from './scrypt';
|
|
84
99
|
export * from './random';
|
|
85
100
|
export * from './ecdh';
|
|
86
101
|
export { getCurves } from './ec';
|
|
87
102
|
export * from './diffie-hellman';
|
|
103
|
+
export * from './mlkem';
|
|
88
104
|
export * from './utils';
|
|
89
105
|
export * from './subtle';
|
|
90
106
|
export { subtle, isCryptoKeyPair } from './subtle';
|
package/src/keys/classes.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { NitroModules } from 'react-native-nitro-modules';
|
|
|
3
3
|
import type {
|
|
4
4
|
AsymmetricKeyType,
|
|
5
5
|
EncodingOptions,
|
|
6
|
+
JWK,
|
|
6
7
|
KeyDetail,
|
|
7
8
|
KeyObjectHandle,
|
|
8
9
|
KeyUsage,
|
|
@@ -81,10 +82,10 @@ export class KeyObject {
|
|
|
81
82
|
|
|
82
83
|
export(options: { format: 'pem' } & EncodingOptions): string | Buffer;
|
|
83
84
|
export(options?: { format: 'der' } & EncodingOptions): Buffer;
|
|
84
|
-
export(options?: { format: 'jwk' } & EncodingOptions):
|
|
85
|
-
export(options?: EncodingOptions): string | Buffer;
|
|
85
|
+
export(options?: { format: 'jwk' } & EncodingOptions): JWK;
|
|
86
|
+
export(options?: EncodingOptions): string | Buffer | JWK;
|
|
86
87
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
87
|
-
export(_options?: EncodingOptions): string | Buffer {
|
|
88
|
+
export(_options?: EncodingOptions): string | Buffer | JWK {
|
|
88
89
|
// This is a placeholder and should be overridden by subclasses.
|
|
89
90
|
throw new Error('export() must be implemented by subclasses');
|
|
90
91
|
}
|
|
@@ -126,11 +127,22 @@ export class KeyObject {
|
|
|
126
127
|
this.type = type as 'public' | 'secret' | 'private';
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
static from(key: CryptoKey): KeyObject {
|
|
131
|
+
if (!(key instanceof CryptoKey)) {
|
|
132
|
+
throw new TypeError(
|
|
133
|
+
`The "key" argument must be an instance of CryptoKey. Received ${typeof key}`,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return key.keyObject;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
toCryptoKey(
|
|
140
|
+
algorithm: SubtleAlgorithm,
|
|
141
|
+
extractable: boolean,
|
|
142
|
+
keyUsages: KeyUsage[],
|
|
143
|
+
): CryptoKey {
|
|
144
|
+
return new CryptoKey(this, algorithm, keyUsages, extractable);
|
|
145
|
+
}
|
|
134
146
|
|
|
135
147
|
static createKeyObject(
|
|
136
148
|
type: string,
|
|
@@ -273,10 +285,10 @@ export class PublicKeyObject extends AsymmetricKeyObject {
|
|
|
273
285
|
|
|
274
286
|
export(options: { format: 'pem' } & EncodingOptions): string;
|
|
275
287
|
export(options: { format: 'der' } & EncodingOptions): Buffer;
|
|
276
|
-
export(options: { format: 'jwk' } & EncodingOptions):
|
|
277
|
-
export(options: EncodingOptions): string | Buffer {
|
|
288
|
+
export(options: { format: 'jwk' } & EncodingOptions): JWK;
|
|
289
|
+
export(options: EncodingOptions): string | Buffer | JWK {
|
|
278
290
|
if (options?.format === 'jwk') {
|
|
279
|
-
|
|
291
|
+
return this.handle.exportJwk({}, false);
|
|
280
292
|
}
|
|
281
293
|
const { format, type } = parsePublicKeyEncoding(
|
|
282
294
|
options,
|
|
@@ -298,13 +310,13 @@ export class PrivateKeyObject extends AsymmetricKeyObject {
|
|
|
298
310
|
|
|
299
311
|
export(options: { format: 'pem' } & EncodingOptions): string;
|
|
300
312
|
export(options: { format: 'der' } & EncodingOptions): Buffer;
|
|
301
|
-
export(options: { format: 'jwk' } & EncodingOptions):
|
|
302
|
-
export(options: EncodingOptions): string | Buffer {
|
|
313
|
+
export(options: { format: 'jwk' } & EncodingOptions): JWK;
|
|
314
|
+
export(options: EncodingOptions): string | Buffer | JWK {
|
|
303
315
|
if (options?.format === 'jwk') {
|
|
304
316
|
if (options.passphrase !== undefined) {
|
|
305
317
|
throw new Error('jwk does not support encryption');
|
|
306
318
|
}
|
|
307
|
-
|
|
319
|
+
return this.handle.exportJwk({}, false);
|
|
308
320
|
}
|
|
309
321
|
const { format, type, cipher, passphrase } = parsePrivateKeyEncoding(
|
|
310
322
|
options,
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { ed_generateKeyPair } from '../ed';
|
|
2
2
|
import { rsa_generateKeyPairNode, rsa_generateKeyPairNodeSync } from '../rsa';
|
|
3
3
|
import { ec_generateKeyPairNode, ec_generateKeyPairNodeSync } from '../ec';
|
|
4
|
+
import { dsa_generateKeyPairNode, dsa_generateKeyPairNodeSync } from '../dsa';
|
|
5
|
+
import {
|
|
6
|
+
dh_generateKeyPairNode,
|
|
7
|
+
dh_generateKeyPairNodeSync,
|
|
8
|
+
} from '../dhKeyPair';
|
|
4
9
|
import {
|
|
5
10
|
kEmptyObject,
|
|
6
11
|
validateFunction,
|
|
@@ -139,6 +144,7 @@ function internalGenerateKeyPair(
|
|
|
139
144
|
case 'rsa-pss':
|
|
140
145
|
case 'dsa':
|
|
141
146
|
case 'ec':
|
|
147
|
+
case 'dh':
|
|
142
148
|
break;
|
|
143
149
|
default: {
|
|
144
150
|
const err = new Error(`
|
|
@@ -158,6 +164,10 @@ function internalGenerateKeyPair(
|
|
|
158
164
|
result = await rsa_generateKeyPairNode(type, options, encoding);
|
|
159
165
|
} else if (type === 'ec') {
|
|
160
166
|
result = await ec_generateKeyPairNode(options, encoding);
|
|
167
|
+
} else if (type === 'dsa') {
|
|
168
|
+
result = await dsa_generateKeyPairNode(options, encoding);
|
|
169
|
+
} else if (type === 'dh') {
|
|
170
|
+
result = await dh_generateKeyPairNode(options, encoding);
|
|
161
171
|
} else {
|
|
162
172
|
throw new Error(`Unsupported key type: ${type}`);
|
|
163
173
|
}
|
|
@@ -184,6 +194,10 @@ function internalGenerateKeyPair(
|
|
|
184
194
|
result = rsa_generateKeyPairNodeSync(type, options, encoding);
|
|
185
195
|
} else if (type === 'ec') {
|
|
186
196
|
result = ec_generateKeyPairNodeSync(options, encoding);
|
|
197
|
+
} else if (type === 'dsa') {
|
|
198
|
+
result = dsa_generateKeyPairNodeSync(options, encoding);
|
|
199
|
+
} else if (type === 'dh') {
|
|
200
|
+
result = dh_generateKeyPairNodeSync(options, encoding);
|
|
187
201
|
} else {
|
|
188
202
|
throw new Error(`Unsupported key type: ${type}`);
|
|
189
203
|
}
|
package/src/keys/index.ts
CHANGED
|
@@ -27,17 +27,19 @@ import {
|
|
|
27
27
|
parsePrivateKeyEncoding,
|
|
28
28
|
parsePublicKeyEncoding,
|
|
29
29
|
} from './utils';
|
|
30
|
-
import
|
|
30
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
31
|
+
import type { BinaryLike, JWK, KeyObjectHandle } from '../utils';
|
|
31
32
|
import {
|
|
32
33
|
binaryLikeToArrayBuffer as toAB,
|
|
33
34
|
isStringOrBuffer,
|
|
34
35
|
KFormatType,
|
|
35
36
|
KeyEncoding,
|
|
37
|
+
KeyType,
|
|
36
38
|
} from '../utils';
|
|
37
39
|
import { randomBytes } from '../random';
|
|
38
40
|
|
|
39
41
|
interface KeyInputObject {
|
|
40
|
-
key: BinaryLike | KeyObject | CryptoKey;
|
|
42
|
+
key: BinaryLike | KeyObject | CryptoKey | JWK;
|
|
41
43
|
format?: 'pem' | 'der' | 'jwk';
|
|
42
44
|
type?: 'pkcs1' | 'pkcs8' | 'spki' | 'sec1';
|
|
43
45
|
passphrase?: BinaryLike;
|
|
@@ -123,6 +125,29 @@ function prepareAsymmetricKey(
|
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
function createPublicKey(key: KeyInput): PublicKeyObject {
|
|
128
|
+
if (typeof key === 'object' && 'key' in key && key.format === 'jwk') {
|
|
129
|
+
const handle =
|
|
130
|
+
NitroModules.createHybridObject<KeyObjectHandle>('KeyObjectHandle');
|
|
131
|
+
const keyType = handle.initJwk(key.key as JWK);
|
|
132
|
+
if (keyType === undefined) {
|
|
133
|
+
throw new Error('Failed to import JWK');
|
|
134
|
+
}
|
|
135
|
+
if (keyType === KeyType.PRIVATE) {
|
|
136
|
+
// Extract public from private
|
|
137
|
+
const exported = handle.exportKey(KFormatType.DER, KeyEncoding.SPKI);
|
|
138
|
+
const pubHandle =
|
|
139
|
+
NitroModules.createHybridObject<KeyObjectHandle>('KeyObjectHandle');
|
|
140
|
+
pubHandle.init(
|
|
141
|
+
KeyType.PUBLIC,
|
|
142
|
+
exported,
|
|
143
|
+
KFormatType.DER,
|
|
144
|
+
KeyEncoding.SPKI,
|
|
145
|
+
);
|
|
146
|
+
return new PublicKeyObject(pubHandle);
|
|
147
|
+
}
|
|
148
|
+
return new PublicKeyObject(handle);
|
|
149
|
+
}
|
|
150
|
+
|
|
126
151
|
const { data, format, type } = prepareAsymmetricKey(key, true);
|
|
127
152
|
|
|
128
153
|
// Map format string to KFormatType enum
|
|
@@ -144,6 +169,16 @@ function createPublicKey(key: KeyInput): PublicKeyObject {
|
|
|
144
169
|
}
|
|
145
170
|
|
|
146
171
|
function createPrivateKey(key: KeyInput): PrivateKeyObject {
|
|
172
|
+
if (typeof key === 'object' && 'key' in key && key.format === 'jwk') {
|
|
173
|
+
const handle =
|
|
174
|
+
NitroModules.createHybridObject<KeyObjectHandle>('KeyObjectHandle');
|
|
175
|
+
const keyType = handle.initJwk(key.key as JWK);
|
|
176
|
+
if (keyType === undefined || keyType !== KeyType.PRIVATE) {
|
|
177
|
+
throw new Error('Failed to import private key from JWK');
|
|
178
|
+
}
|
|
179
|
+
return new PrivateKeyObject(handle);
|
|
180
|
+
}
|
|
181
|
+
|
|
147
182
|
const { data, format, type } = prepareAsymmetricKey(key, false);
|
|
148
183
|
|
|
149
184
|
// Map format string to KFormatType enum
|
package/src/keys/signVerify.ts
CHANGED
|
@@ -119,12 +119,7 @@ function prepareKey(key: KeyInput, isPublic: boolean): PreparedKey {
|
|
|
119
119
|
|
|
120
120
|
const keyType = isPublic ? 'public' : 'private';
|
|
121
121
|
// Always convert to ArrayBuffer to avoid Nitro bridge string truncation bug
|
|
122
|
-
const originalLength =
|
|
123
|
-
typeof data === 'string' ? data.length : data.byteLength;
|
|
124
122
|
const keyData = toAB(data);
|
|
125
|
-
console.log(
|
|
126
|
-
`[prepareKey KeyInputObject] ${keyType} key, original length: ${originalLength}, ArrayBuffer size: ${keyData.byteLength}`,
|
|
127
|
-
);
|
|
128
123
|
const keyObject = KeyObject.createKeyObject(
|
|
129
124
|
keyType,
|
|
130
125
|
keyData,
|