react-native-quick-crypto 1.0.10 → 1.0.11
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 +9 -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/HybridCipher.cpp +58 -0
- package/cpp/cipher/HybridCipher.hpp +4 -0
- 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 +35 -0
- package/cpp/ecdh/HybridECDH.hpp +1 -0
- package/cpp/keys/HybridKeyObjectHandle.cpp +19 -0
- package/cpp/prime/HybridPrime.cpp +81 -0
- package/cpp/prime/HybridPrime.hpp +20 -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 +8 -0
- 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/ecdh.js +37 -0
- package/lib/commonjs/ecdh.js.map +1 -1
- package/lib/commonjs/index.js +35 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys/classes.js +9 -7
- 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/prime.js +84 -0
- package/lib/commonjs/prime.js.map +1 -0
- 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/prime.nitro.js +6 -0
- package/lib/commonjs/specs/prime.nitro.js.map +1 -0
- package/lib/commonjs/subtle.js +101 -10
- package/lib/commonjs/subtle.js.map +1 -1
- package/lib/commonjs/utils/types.js.map +1 -1
- 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 +7 -0
- 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/ecdh.js +37 -0
- package/lib/module/ecdh.js.map +1 -1
- package/lib/module/index.js +9 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys/classes.js +9 -7
- 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/prime.js +77 -0
- package/lib/module/prime.js.map +1 -0
- 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/prime.nitro.js +4 -0
- package/lib/module/specs/prime.nitro.js.map +1 -0
- package/lib/module/subtle.js +102 -12
- package/lib/module/subtle.js.map +1 -1
- package/lib/module/utils/types.js.map +1 -1
- 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 +12 -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/ecdh.d.ts +3 -0
- package/lib/typescript/ecdh.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +17 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/keys/classes.d.ts +2 -0
- package/lib/typescript/keys/classes.d.ts.map +1 -1
- package/lib/typescript/keys/generateKeyPair.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/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/prime.nitro.d.ts +11 -0
- package/lib/typescript/specs/prime.nitro.d.ts.map +1 -0
- package/lib/typescript/subtle.d.ts +2 -0
- package/lib/typescript/subtle.d.ts.map +1 -1
- package/lib/typescript/utils/types.d.ts +13 -3
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +5 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +50 -0
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +50 -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++/HybridPrimeSpec.cpp +24 -0
- package/nitrogen/generated/shared/c++/HybridPrimeSpec.hpp +67 -0
- package/package.json +1 -1
- package/src/argon2.ts +83 -0
- package/src/certificate.ts +41 -0
- package/src/cipher.ts +24 -0
- package/src/dhKeyPair.ts +156 -0
- package/src/dsa.ts +129 -0
- package/src/ecdh.ts +59 -0
- package/src/index.ts +9 -0
- package/src/keys/classes.ts +16 -5
- package/src/keys/generateKeyPair.ts +14 -0
- package/src/prime.ts +134 -0
- 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/prime.nitro.ts +18 -0
- package/src/subtle.ts +271 -12
- package/src/utils/types.ts +22 -3
package/src/subtle.ts
CHANGED
|
@@ -28,11 +28,12 @@ import {
|
|
|
28
28
|
} from './keys';
|
|
29
29
|
import type { CryptoKeyPair } from './utils/types';
|
|
30
30
|
import { bufferLikeToArrayBuffer } from './utils/conversion';
|
|
31
|
+
import { argon2Sync } from './argon2';
|
|
31
32
|
import { lazyDOMException } from './utils/errors';
|
|
32
33
|
import { normalizeHashName, HashContext } from './utils/hashnames';
|
|
33
34
|
import { validateMaxBufferLength } from './utils/validation';
|
|
34
35
|
import { asyncDigest } from './hash';
|
|
35
|
-
import { createSecretKey } from './keys';
|
|
36
|
+
import { createSecretKey, createPublicKey } from './keys';
|
|
36
37
|
import { NitroModules } from 'react-native-nitro-modules';
|
|
37
38
|
import type { KeyObjectHandle } from './specs/keyObjectHandle.nitro';
|
|
38
39
|
import type { RsaCipher } from './specs/rsaCipher.nitro';
|
|
@@ -56,12 +57,6 @@ import {
|
|
|
56
57
|
} from './ed';
|
|
57
58
|
import { mldsa_generateKeyPairWebCrypto, type MlDsaVariant } from './mldsa';
|
|
58
59
|
import { hkdfDeriveBits, type HkdfAlgorithm } from './hkdf';
|
|
59
|
-
// import { pbkdf2DeriveBits } from './pbkdf2';
|
|
60
|
-
// import { aesCipher, aesGenerateKey, aesImportKey, getAlgorithmName } from './aes';
|
|
61
|
-
// import { rsaCipher, rsaExportKey, rsaImportKey, rsaKeyGenerate } from './rsa';
|
|
62
|
-
// import { normalizeAlgorithm, type Operation } from './algorithms';
|
|
63
|
-
// import { hmacImportKey } from './mac';
|
|
64
|
-
|
|
65
60
|
// Temporary enums that need to be defined
|
|
66
61
|
|
|
67
62
|
enum KWebCryptoKeyFormat {
|
|
@@ -113,12 +108,12 @@ function getAlgorithmName(name: string, length: number): string {
|
|
|
113
108
|
function ecExportKey(key: CryptoKey, format: KWebCryptoKeyFormat): ArrayBuffer {
|
|
114
109
|
const keyObject = key.keyObject;
|
|
115
110
|
|
|
116
|
-
if (format === KWebCryptoKeyFormat.
|
|
117
|
-
|
|
111
|
+
if (format === KWebCryptoKeyFormat.kWebCryptoKeyFormatRaw) {
|
|
112
|
+
return bufferLikeToArrayBuffer(keyObject.handle.exportKey());
|
|
113
|
+
} else if (format === KWebCryptoKeyFormat.kWebCryptoKeyFormatSPKI) {
|
|
118
114
|
const exported = keyObject.export({ format: 'der', type: 'spki' });
|
|
119
115
|
return bufferLikeToArrayBuffer(exported);
|
|
120
116
|
} else if (format === KWebCryptoKeyFormat.kWebCryptoKeyFormatPKCS8) {
|
|
121
|
-
// Export private key in PKCS8 format
|
|
122
117
|
const exported = keyObject.export({ format: 'der', type: 'pkcs8' });
|
|
123
118
|
return bufferLikeToArrayBuffer(exported);
|
|
124
119
|
} else {
|
|
@@ -1364,6 +1359,45 @@ const checkCryptoKeyPairUsages = (pair: CryptoKeyPair) => {
|
|
|
1364
1359
|
);
|
|
1365
1360
|
};
|
|
1366
1361
|
|
|
1362
|
+
function argon2DeriveBits(
|
|
1363
|
+
algorithm: SubtleAlgorithm,
|
|
1364
|
+
baseKey: CryptoKey,
|
|
1365
|
+
length: number,
|
|
1366
|
+
): ArrayBuffer {
|
|
1367
|
+
if (length === 0 || length % 8 !== 0) {
|
|
1368
|
+
throw lazyDOMException(
|
|
1369
|
+
'Invalid Argon2 derived key length',
|
|
1370
|
+
'OperationError',
|
|
1371
|
+
);
|
|
1372
|
+
}
|
|
1373
|
+
if (length < 32) {
|
|
1374
|
+
throw lazyDOMException(
|
|
1375
|
+
'Argon2 derived key length must be at least 32 bits',
|
|
1376
|
+
'OperationError',
|
|
1377
|
+
);
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
const { nonce, parallelism, memory, passes, secretValue, associatedData } =
|
|
1381
|
+
algorithm;
|
|
1382
|
+
const tagLength = length / 8;
|
|
1383
|
+
const message = baseKey.keyObject.export();
|
|
1384
|
+
const algName = algorithm.name.toLowerCase();
|
|
1385
|
+
|
|
1386
|
+
const result = argon2Sync(algName, {
|
|
1387
|
+
message,
|
|
1388
|
+
nonce: nonce ?? new Uint8Array(0),
|
|
1389
|
+
parallelism: parallelism ?? 1,
|
|
1390
|
+
tagLength,
|
|
1391
|
+
memory: memory ?? 65536,
|
|
1392
|
+
passes: passes ?? 3,
|
|
1393
|
+
secret: secretValue,
|
|
1394
|
+
associatedData,
|
|
1395
|
+
version: algorithm.version,
|
|
1396
|
+
});
|
|
1397
|
+
|
|
1398
|
+
return bufferLikeToArrayBuffer(result);
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1367
1401
|
// Type guard to check if result is CryptoKeyPair
|
|
1368
1402
|
export function isCryptoKeyPair(
|
|
1369
1403
|
result: CryptoKey | CryptoKeyPair,
|
|
@@ -1604,7 +1638,205 @@ const cipherOrWrap = async (
|
|
|
1604
1638
|
}
|
|
1605
1639
|
};
|
|
1606
1640
|
|
|
1641
|
+
const SUPPORTED_ALGORITHMS: Record<string, Set<string>> = {
|
|
1642
|
+
encrypt: new Set([
|
|
1643
|
+
'RSA-OAEP',
|
|
1644
|
+
'AES-CTR',
|
|
1645
|
+
'AES-CBC',
|
|
1646
|
+
'AES-GCM',
|
|
1647
|
+
'AES-OCB',
|
|
1648
|
+
'ChaCha20-Poly1305',
|
|
1649
|
+
]),
|
|
1650
|
+
decrypt: new Set([
|
|
1651
|
+
'RSA-OAEP',
|
|
1652
|
+
'AES-CTR',
|
|
1653
|
+
'AES-CBC',
|
|
1654
|
+
'AES-GCM',
|
|
1655
|
+
'AES-OCB',
|
|
1656
|
+
'ChaCha20-Poly1305',
|
|
1657
|
+
]),
|
|
1658
|
+
sign: new Set([
|
|
1659
|
+
'RSASSA-PKCS1-v1_5',
|
|
1660
|
+
'RSA-PSS',
|
|
1661
|
+
'ECDSA',
|
|
1662
|
+
'HMAC',
|
|
1663
|
+
'Ed25519',
|
|
1664
|
+
'Ed448',
|
|
1665
|
+
'ML-DSA-44',
|
|
1666
|
+
'ML-DSA-65',
|
|
1667
|
+
'ML-DSA-87',
|
|
1668
|
+
]),
|
|
1669
|
+
verify: new Set([
|
|
1670
|
+
'RSASSA-PKCS1-v1_5',
|
|
1671
|
+
'RSA-PSS',
|
|
1672
|
+
'ECDSA',
|
|
1673
|
+
'HMAC',
|
|
1674
|
+
'Ed25519',
|
|
1675
|
+
'Ed448',
|
|
1676
|
+
'ML-DSA-44',
|
|
1677
|
+
'ML-DSA-65',
|
|
1678
|
+
'ML-DSA-87',
|
|
1679
|
+
]),
|
|
1680
|
+
digest: new Set(['SHA-1', 'SHA-256', 'SHA-384', 'SHA-512']),
|
|
1681
|
+
generateKey: new Set([
|
|
1682
|
+
'RSASSA-PKCS1-v1_5',
|
|
1683
|
+
'RSA-PSS',
|
|
1684
|
+
'RSA-OAEP',
|
|
1685
|
+
'ECDSA',
|
|
1686
|
+
'ECDH',
|
|
1687
|
+
'Ed25519',
|
|
1688
|
+
'Ed448',
|
|
1689
|
+
'X25519',
|
|
1690
|
+
'X448',
|
|
1691
|
+
'AES-CTR',
|
|
1692
|
+
'AES-CBC',
|
|
1693
|
+
'AES-GCM',
|
|
1694
|
+
'AES-KW',
|
|
1695
|
+
'AES-OCB',
|
|
1696
|
+
'ChaCha20-Poly1305',
|
|
1697
|
+
'HMAC',
|
|
1698
|
+
'ML-DSA-44',
|
|
1699
|
+
'ML-DSA-65',
|
|
1700
|
+
'ML-DSA-87',
|
|
1701
|
+
]),
|
|
1702
|
+
importKey: new Set([
|
|
1703
|
+
'RSASSA-PKCS1-v1_5',
|
|
1704
|
+
'RSA-PSS',
|
|
1705
|
+
'RSA-OAEP',
|
|
1706
|
+
'ECDSA',
|
|
1707
|
+
'ECDH',
|
|
1708
|
+
'Ed25519',
|
|
1709
|
+
'Ed448',
|
|
1710
|
+
'X25519',
|
|
1711
|
+
'X448',
|
|
1712
|
+
'AES-CTR',
|
|
1713
|
+
'AES-CBC',
|
|
1714
|
+
'AES-GCM',
|
|
1715
|
+
'AES-KW',
|
|
1716
|
+
'AES-OCB',
|
|
1717
|
+
'ChaCha20-Poly1305',
|
|
1718
|
+
'HMAC',
|
|
1719
|
+
'HKDF',
|
|
1720
|
+
'PBKDF2',
|
|
1721
|
+
'Argon2d',
|
|
1722
|
+
'Argon2i',
|
|
1723
|
+
'Argon2id',
|
|
1724
|
+
'ML-DSA-44',
|
|
1725
|
+
'ML-DSA-65',
|
|
1726
|
+
'ML-DSA-87',
|
|
1727
|
+
]),
|
|
1728
|
+
exportKey: new Set([
|
|
1729
|
+
'RSASSA-PKCS1-v1_5',
|
|
1730
|
+
'RSA-PSS',
|
|
1731
|
+
'RSA-OAEP',
|
|
1732
|
+
'ECDSA',
|
|
1733
|
+
'ECDH',
|
|
1734
|
+
'Ed25519',
|
|
1735
|
+
'Ed448',
|
|
1736
|
+
'X25519',
|
|
1737
|
+
'X448',
|
|
1738
|
+
'AES-CTR',
|
|
1739
|
+
'AES-CBC',
|
|
1740
|
+
'AES-GCM',
|
|
1741
|
+
'AES-KW',
|
|
1742
|
+
'AES-OCB',
|
|
1743
|
+
'ChaCha20-Poly1305',
|
|
1744
|
+
'HMAC',
|
|
1745
|
+
'ML-DSA-44',
|
|
1746
|
+
'ML-DSA-65',
|
|
1747
|
+
'ML-DSA-87',
|
|
1748
|
+
]),
|
|
1749
|
+
deriveBits: new Set([
|
|
1750
|
+
'PBKDF2',
|
|
1751
|
+
'HKDF',
|
|
1752
|
+
'ECDH',
|
|
1753
|
+
'X25519',
|
|
1754
|
+
'X448',
|
|
1755
|
+
'Argon2d',
|
|
1756
|
+
'Argon2i',
|
|
1757
|
+
'Argon2id',
|
|
1758
|
+
]),
|
|
1759
|
+
wrapKey: new Set([
|
|
1760
|
+
'AES-CTR',
|
|
1761
|
+
'AES-CBC',
|
|
1762
|
+
'AES-GCM',
|
|
1763
|
+
'AES-KW',
|
|
1764
|
+
'AES-OCB',
|
|
1765
|
+
'ChaCha20-Poly1305',
|
|
1766
|
+
'RSA-OAEP',
|
|
1767
|
+
]),
|
|
1768
|
+
unwrapKey: new Set([
|
|
1769
|
+
'AES-CTR',
|
|
1770
|
+
'AES-CBC',
|
|
1771
|
+
'AES-GCM',
|
|
1772
|
+
'AES-KW',
|
|
1773
|
+
'AES-OCB',
|
|
1774
|
+
'ChaCha20-Poly1305',
|
|
1775
|
+
'RSA-OAEP',
|
|
1776
|
+
]),
|
|
1777
|
+
};
|
|
1778
|
+
|
|
1779
|
+
const ASYMMETRIC_ALGORITHMS = new Set([
|
|
1780
|
+
'RSASSA-PKCS1-v1_5',
|
|
1781
|
+
'RSA-PSS',
|
|
1782
|
+
'RSA-OAEP',
|
|
1783
|
+
'ECDSA',
|
|
1784
|
+
'ECDH',
|
|
1785
|
+
'Ed25519',
|
|
1786
|
+
'Ed448',
|
|
1787
|
+
'X25519',
|
|
1788
|
+
'X448',
|
|
1789
|
+
'ML-DSA-44',
|
|
1790
|
+
'ML-DSA-65',
|
|
1791
|
+
'ML-DSA-87',
|
|
1792
|
+
]);
|
|
1793
|
+
|
|
1607
1794
|
export class Subtle {
|
|
1795
|
+
static supports(
|
|
1796
|
+
operation: string,
|
|
1797
|
+
algorithm: SubtleAlgorithm | AnyAlgorithm,
|
|
1798
|
+
_lengthOrAdditionalAlgorithm?: unknown,
|
|
1799
|
+
): boolean {
|
|
1800
|
+
let normalizedAlgorithm: SubtleAlgorithm;
|
|
1801
|
+
try {
|
|
1802
|
+
normalizedAlgorithm = normalizeAlgorithm(
|
|
1803
|
+
algorithm,
|
|
1804
|
+
(operation === 'getPublicKey' ? 'exportKey' : operation) as Operation,
|
|
1805
|
+
);
|
|
1806
|
+
} catch {
|
|
1807
|
+
return false;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
const name = normalizedAlgorithm.name;
|
|
1811
|
+
|
|
1812
|
+
if (operation === 'getPublicKey') {
|
|
1813
|
+
return ASYMMETRIC_ALGORITHMS.has(name);
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
if (operation === 'deriveKey') {
|
|
1817
|
+
// deriveKey decomposes to deriveBits + importKey of additional algorithm
|
|
1818
|
+
if (!SUPPORTED_ALGORITHMS.deriveBits?.has(name)) return false;
|
|
1819
|
+
if (_lengthOrAdditionalAlgorithm != null) {
|
|
1820
|
+
try {
|
|
1821
|
+
const additionalAlg = normalizeAlgorithm(
|
|
1822
|
+
_lengthOrAdditionalAlgorithm as SubtleAlgorithm | AnyAlgorithm,
|
|
1823
|
+
'importKey',
|
|
1824
|
+
);
|
|
1825
|
+
return (
|
|
1826
|
+
SUPPORTED_ALGORITHMS.importKey?.has(additionalAlg.name) ?? false
|
|
1827
|
+
);
|
|
1828
|
+
} catch {
|
|
1829
|
+
return false;
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
return true;
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
const supported = SUPPORTED_ALGORITHMS[operation];
|
|
1836
|
+
if (!supported) return false;
|
|
1837
|
+
return supported.has(name);
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1608
1840
|
async decrypt(
|
|
1609
1841
|
algorithm: EncryptDecryptParams,
|
|
1610
1842
|
key: CryptoKey,
|
|
@@ -1660,6 +1892,10 @@ export class Subtle {
|
|
|
1660
1892
|
baseKey,
|
|
1661
1893
|
length,
|
|
1662
1894
|
);
|
|
1895
|
+
case 'Argon2d':
|
|
1896
|
+
case 'Argon2i':
|
|
1897
|
+
case 'Argon2id':
|
|
1898
|
+
return argon2DeriveBits(algorithm, baseKey, length);
|
|
1663
1899
|
}
|
|
1664
1900
|
throw new Error(
|
|
1665
1901
|
`'subtle.deriveBits()' for ${algorithm.name} is not implemented.`,
|
|
@@ -1711,6 +1947,11 @@ export class Subtle {
|
|
|
1711
1947
|
length,
|
|
1712
1948
|
);
|
|
1713
1949
|
break;
|
|
1950
|
+
case 'Argon2d':
|
|
1951
|
+
case 'Argon2i':
|
|
1952
|
+
case 'Argon2id':
|
|
1953
|
+
derivedBits = argon2DeriveBits(algorithm, baseKey, length);
|
|
1954
|
+
break;
|
|
1714
1955
|
default:
|
|
1715
1956
|
throw new Error(
|
|
1716
1957
|
`'subtle.deriveKey()' for ${algorithm.name} is not implemented.`,
|
|
@@ -1748,7 +1989,7 @@ export class Subtle {
|
|
|
1748
1989
|
): Promise<ArrayBuffer | JWK> {
|
|
1749
1990
|
if (!key.extractable) throw new Error('key is not extractable');
|
|
1750
1991
|
|
|
1751
|
-
if (format === 'raw-secret') format = 'raw';
|
|
1992
|
+
if (format === 'raw-secret' || format === 'raw-public') format = 'raw';
|
|
1752
1993
|
|
|
1753
1994
|
switch (format) {
|
|
1754
1995
|
case 'spki':
|
|
@@ -1977,6 +2218,21 @@ export class Subtle {
|
|
|
1977
2218
|
return result;
|
|
1978
2219
|
}
|
|
1979
2220
|
|
|
2221
|
+
async getPublicKey(
|
|
2222
|
+
key: CryptoKey,
|
|
2223
|
+
keyUsages: KeyUsage[],
|
|
2224
|
+
): Promise<CryptoKey> {
|
|
2225
|
+
if (key.type === 'secret') {
|
|
2226
|
+
throw lazyDOMException('key must be a private key', 'NotSupportedError');
|
|
2227
|
+
}
|
|
2228
|
+
if (key.type !== 'private') {
|
|
2229
|
+
throw lazyDOMException('key must be a private key', 'InvalidAccessError');
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
const publicKeyObject = createPublicKey(key.keyObject);
|
|
2233
|
+
return publicKeyObject.toCryptoKey(key.algorithm, true, keyUsages);
|
|
2234
|
+
}
|
|
2235
|
+
|
|
1980
2236
|
async importKey(
|
|
1981
2237
|
format: ImportFormat,
|
|
1982
2238
|
data: BufferLike | BinaryLike | JWK,
|
|
@@ -1984,7 +2240,7 @@ export class Subtle {
|
|
|
1984
2240
|
extractable: boolean,
|
|
1985
2241
|
keyUsages: KeyUsage[],
|
|
1986
2242
|
): Promise<CryptoKey> {
|
|
1987
|
-
if (format === 'raw-secret') format = 'raw';
|
|
2243
|
+
if (format === 'raw-secret' || format === 'raw-public') format = 'raw';
|
|
1988
2244
|
const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'importKey');
|
|
1989
2245
|
let result: CryptoKey;
|
|
1990
2246
|
switch (normalizedAlgorithm.name) {
|
|
@@ -2041,6 +2297,9 @@ export class Subtle {
|
|
|
2041
2297
|
);
|
|
2042
2298
|
break;
|
|
2043
2299
|
case 'PBKDF2':
|
|
2300
|
+
case 'Argon2d':
|
|
2301
|
+
case 'Argon2i':
|
|
2302
|
+
case 'Argon2id':
|
|
2044
2303
|
result = await importGenericSecretKey(
|
|
2045
2304
|
normalizedAlgorithm,
|
|
2046
2305
|
format,
|
package/src/utils/types.ts
CHANGED
|
@@ -100,12 +100,15 @@ export type SignVerifyAlgorithm =
|
|
|
100
100
|
| 'ML-DSA-65'
|
|
101
101
|
| 'ML-DSA-87';
|
|
102
102
|
|
|
103
|
+
export type Argon2Algorithm = 'Argon2d' | 'Argon2i' | 'Argon2id';
|
|
104
|
+
|
|
103
105
|
export type DeriveBitsAlgorithm =
|
|
104
106
|
| 'PBKDF2'
|
|
105
107
|
| 'HKDF'
|
|
106
108
|
| 'ECDH'
|
|
107
109
|
| 'X25519'
|
|
108
|
-
| 'X448'
|
|
110
|
+
| 'X448'
|
|
111
|
+
| Argon2Algorithm;
|
|
109
112
|
|
|
110
113
|
export type EncryptDecryptAlgorithm =
|
|
111
114
|
| 'RSA-OAEP'
|
|
@@ -193,7 +196,7 @@ export type NamedCurve = 'P-256' | 'P-384' | 'P-521';
|
|
|
193
196
|
|
|
194
197
|
export type SubtleAlgorithm = {
|
|
195
198
|
name: AnyAlgorithm;
|
|
196
|
-
salt?: string;
|
|
199
|
+
salt?: string | BufferLike;
|
|
197
200
|
iterations?: number;
|
|
198
201
|
hash?: HashAlgorithm | { name: string };
|
|
199
202
|
namedCurve?: NamedCurve;
|
|
@@ -202,6 +205,16 @@ export type SubtleAlgorithm = {
|
|
|
202
205
|
publicExponent?: number | Uint8Array;
|
|
203
206
|
saltLength?: number;
|
|
204
207
|
public?: CryptoKey;
|
|
208
|
+
info?: BufferLike;
|
|
209
|
+
// Argon2 parameters
|
|
210
|
+
nonce?: BufferLike;
|
|
211
|
+
parallelism?: number;
|
|
212
|
+
tagLength?: number;
|
|
213
|
+
memory?: number;
|
|
214
|
+
passes?: number;
|
|
215
|
+
secretValue?: BufferLike;
|
|
216
|
+
associatedData?: BufferLike;
|
|
217
|
+
version?: number;
|
|
205
218
|
};
|
|
206
219
|
|
|
207
220
|
export type KeyPairType =
|
|
@@ -462,7 +475,13 @@ export type DiffieHellmanCallback = (
|
|
|
462
475
|
// from @paulmillr/noble-curves
|
|
463
476
|
export type Hex = string | Uint8Array;
|
|
464
477
|
|
|
465
|
-
export type ImportFormat =
|
|
478
|
+
export type ImportFormat =
|
|
479
|
+
| 'raw'
|
|
480
|
+
| 'raw-public'
|
|
481
|
+
| 'raw-secret'
|
|
482
|
+
| 'pkcs8'
|
|
483
|
+
| 'spki'
|
|
484
|
+
| 'jwk';
|
|
466
485
|
|
|
467
486
|
export type Operation =
|
|
468
487
|
| 'encrypt'
|