react-native-quick-crypto 0.7.3 → 1.0.0-beta.2
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/QuickCrypto.podspec +34 -0
- package/README.md +13 -46
- package/android/CMakeLists.txt +32 -64
- package/android/build.gradle +52 -125
- package/android/gradle.properties +4 -4
- package/android/src/main/cpp/cpp-adapter.cpp +9 -54
- package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +38 -0
- package/cpp/random/HybridRandom.cpp +34 -0
- package/cpp/random/HybridRandom.hpp +44 -0
- package/cpp/utils/Utils.hpp +9 -0
- package/ios/QuickCryptoOnLoad.mm +19 -0
- package/lib/commonjs/index.js +39 -39
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/random.js +26 -12
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/{NativeQuickCrypto/rsa.js → specs/random.nitro.js} +1 -1
- package/lib/commonjs/{NativeQuickCrypto/aes.js.map → specs/random.nitro.js.map} +1 -1
- package/lib/commonjs/utils/conversion.js +22 -0
- package/lib/commonjs/utils/conversion.js.map +1 -0
- package/lib/commonjs/utils/index.js +12 -0
- package/lib/commonjs/utils/index.js.map +1 -0
- package/lib/commonjs/utils/types.js +2 -0
- package/lib/{module/NativeQuickCrypto/aes.js.map → commonjs/utils/types.js.map} +1 -1
- package/lib/module/index.js +38 -38
- package/lib/module/index.js.map +1 -1
- package/lib/module/random.js +26 -12
- package/lib/module/random.js.map +1 -1
- package/lib/module/specs/random.nitro.js +4 -0
- package/lib/module/{NativeQuickCrypto/rsa.js.map → specs/random.nitro.js.map} +1 -1
- package/lib/module/utils/conversion.js +16 -0
- package/lib/module/utils/conversion.js.map +1 -0
- package/lib/module/utils/index.js +8 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/module/utils/types.js +2 -0
- package/lib/{commonjs/NativeQuickCrypto/rsa.js.map → module/utils/types.js.map} +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/typescript/index.d.ts +10 -141
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/random.d.ts +4 -5
- package/lib/typescript/random.d.ts.map +1 -1
- package/lib/typescript/specs/random.nitro.d.ts +9 -0
- package/lib/typescript/specs/random.nitro.d.ts.map +1 -0
- package/lib/typescript/utils/conversion.d.ts +4 -0
- package/lib/typescript/utils/conversion.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +6 -0
- package/lib/typescript/utils/index.d.ts.map +1 -0
- package/lib/typescript/utils/types.d.ts +5 -0
- package/lib/typescript/utils/types.d.ts.map +1 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +45 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +26 -0
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +57 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +9 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +25 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +29 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +62 -0
- package/package.json +50 -106
- package/src/index.ts +38 -48
- package/src/random.ts +51 -48
- package/src/specs/random.nitro.ts +14 -0
- package/src/utils/conversion.ts +16 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/types.ts +15 -0
- package/LICENSE +0 -27
- package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoModule.java +0 -70
- package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoPackage.java +0 -25
- package/cpp/Cipher/MGLCipherHostObject.cpp +0 -663
- package/cpp/Cipher/MGLCipherHostObject.h +0 -90
- package/cpp/Cipher/MGLCreateCipherInstaller.cpp +0 -75
- package/cpp/Cipher/MGLCreateCipherInstaller.h +0 -22
- package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +0 -77
- package/cpp/Cipher/MGLCreateDecipherInstaller.h +0 -17
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +0 -134
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +0 -35
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +0 -63
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +0 -37
- package/cpp/Cipher/MGLPublicCipher.h +0 -124
- package/cpp/Cipher/MGLPublicCipherInstaller.h +0 -107
- package/cpp/Cipher/MGLRsa.cpp +0 -573
- package/cpp/Cipher/MGLRsa.h +0 -109
- package/cpp/HMAC/MGLHmacHostObject.cpp +0 -95
- package/cpp/HMAC/MGLHmacHostObject.h +0 -39
- package/cpp/HMAC/MGLHmacInstaller.cpp +0 -43
- package/cpp/HMAC/MGLHmacInstaller.h +0 -20
- package/cpp/Hash/MGLHashHostObject.cpp +0 -147
- package/cpp/Hash/MGLHashHostObject.h +0 -53
- package/cpp/Hash/MGLHashInstaller.cpp +0 -44
- package/cpp/Hash/MGLHashInstaller.h +0 -20
- package/cpp/JSIUtils/MGLJSIMacros.h +0 -110
- package/cpp/JSIUtils/MGLJSIUtils.h +0 -41
- package/cpp/JSIUtils/MGLSmartHostObject.cpp +0 -43
- package/cpp/JSIUtils/MGLSmartHostObject.h +0 -46
- package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +0 -24
- package/cpp/JSIUtils/MGLThreadAwareHostObject.h +0 -43
- package/cpp/JSIUtils/MGLTypedArray.cpp +0 -325
- package/cpp/JSIUtils/MGLTypedArray.h +0 -160
- package/cpp/MGLKeys.cpp +0 -1426
- package/cpp/MGLKeys.h +0 -203
- package/cpp/MGLQuickCryptoHostObject.cpp +0 -127
- package/cpp/MGLQuickCryptoHostObject.h +0 -30
- package/cpp/Random/MGLRandomHostObject.cpp +0 -96
- package/cpp/Random/MGLRandomHostObject.h +0 -27
- package/cpp/Sig/MGLSignHostObjects.cpp +0 -757
- package/cpp/Sig/MGLSignHostObjects.h +0 -128
- package/cpp/Sig/MGLSignInstaller.cpp +0 -24
- package/cpp/Sig/MGLSignInstaller.h +0 -29
- package/cpp/Sig/MGLVerifyInstaller.cpp +0 -24
- package/cpp/Sig/MGLVerifyInstaller.h +0 -22
- package/cpp/Utils/MGLDispatchQueue.cpp +0 -75
- package/cpp/Utils/MGLDispatchQueue.h +0 -55
- package/cpp/Utils/MGLUtils.cpp +0 -295
- package/cpp/Utils/MGLUtils.h +0 -358
- package/cpp/Utils/base64.h +0 -320
- package/cpp/Utils/logs.h +0 -38
- package/cpp/Utils/node.h +0 -13
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +0 -164
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +0 -29
- package/cpp/fastpbkdf2/fastpbkdf2.c +0 -352
- package/cpp/fastpbkdf2/fastpbkdf2.h +0 -68
- package/cpp/webcrypto/MGLWebCrypto.cpp +0 -125
- package/cpp/webcrypto/MGLWebCrypto.h +0 -32
- package/cpp/webcrypto/crypto_aes.cpp +0 -516
- package/cpp/webcrypto/crypto_aes.h +0 -79
- package/cpp/webcrypto/crypto_ec.cpp +0 -424
- package/cpp/webcrypto/crypto_ec.h +0 -78
- package/cpp/webcrypto/crypto_keygen.cpp +0 -86
- package/cpp/webcrypto/crypto_keygen.h +0 -38
- package/ios/QuickCrypto.xcodeproj/project.pbxproj +0 -274
- package/ios/QuickCryptoModule.h +0 -5
- package/ios/QuickCryptoModule.mm +0 -42
- package/lib/commonjs/Cipher.js +0 -502
- package/lib/commonjs/Cipher.js.map +0 -1
- package/lib/commonjs/Hash.js +0 -99
- package/lib/commonjs/Hash.js.map +0 -1
- package/lib/commonjs/Hashnames.js +0 -87
- package/lib/commonjs/Hashnames.js.map +0 -1
- package/lib/commonjs/Hmac.js +0 -79
- package/lib/commonjs/Hmac.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/Cipher.js +0 -30
- package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +0 -52
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/aes.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/hash.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/hash.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/hmac.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/hmac.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/keygen.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/keygen.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/random.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/random.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/sig.js +0 -19
- package/lib/commonjs/NativeQuickCrypto/sig.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/webcrypto.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +0 -1
- package/lib/commonjs/Utils.js +0 -608
- package/lib/commonjs/Utils.js.map +0 -1
- package/lib/commonjs/aes.js +0 -281
- package/lib/commonjs/aes.js.map +0 -1
- package/lib/commonjs/constants.js +0 -85
- package/lib/commonjs/constants.js.map +0 -1
- package/lib/commonjs/ec.js +0 -276
- package/lib/commonjs/ec.js.map +0 -1
- package/lib/commonjs/keygen.js +0 -56
- package/lib/commonjs/keygen.js.map +0 -1
- package/lib/commonjs/keys.js +0 -492
- package/lib/commonjs/keys.js.map +0 -1
- package/lib/commonjs/pbkdf2.js +0 -90
- package/lib/commonjs/pbkdf2.js.map +0 -1
- package/lib/commonjs/rsa.js +0 -248
- package/lib/commonjs/rsa.js.map +0 -1
- package/lib/commonjs/sig.js +0 -129
- package/lib/commonjs/sig.js.map +0 -1
- package/lib/commonjs/subtle.js +0 -448
- package/lib/commonjs/subtle.js.map +0 -1
- package/lib/commonjs/webcrypto.js +0 -14
- package/lib/commonjs/webcrypto.js.map +0 -1
- package/lib/module/Cipher.js +0 -491
- package/lib/module/Cipher.js.map +0 -1
- package/lib/module/Hash.js +0 -93
- package/lib/module/Hash.js.map +0 -1
- package/lib/module/Hashnames.js +0 -85
- package/lib/module/Hashnames.js.map +0 -1
- package/lib/module/Hmac.js +0 -74
- package/lib/module/Hmac.js.map +0 -1
- package/lib/module/NativeQuickCrypto/Cipher.js +0 -26
- package/lib/module/NativeQuickCrypto/Cipher.js.map +0 -1
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +0 -49
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
- package/lib/module/NativeQuickCrypto/aes.js +0 -4
- package/lib/module/NativeQuickCrypto/hash.js +0 -2
- package/lib/module/NativeQuickCrypto/hash.js.map +0 -1
- package/lib/module/NativeQuickCrypto/hmac.js +0 -2
- package/lib/module/NativeQuickCrypto/hmac.js.map +0 -1
- package/lib/module/NativeQuickCrypto/keygen.js +0 -4
- package/lib/module/NativeQuickCrypto/keygen.js.map +0 -1
- package/lib/module/NativeQuickCrypto/pbkdf2.js +0 -2
- package/lib/module/NativeQuickCrypto/pbkdf2.js.map +0 -1
- package/lib/module/NativeQuickCrypto/random.js +0 -2
- package/lib/module/NativeQuickCrypto/random.js.map +0 -1
- package/lib/module/NativeQuickCrypto/rsa.js +0 -4
- package/lib/module/NativeQuickCrypto/sig.js +0 -17
- package/lib/module/NativeQuickCrypto/sig.js.map +0 -1
- package/lib/module/NativeQuickCrypto/webcrypto.js +0 -4
- package/lib/module/NativeQuickCrypto/webcrypto.js.map +0 -1
- package/lib/module/Utils.js +0 -539
- package/lib/module/Utils.js.map +0 -1
- package/lib/module/aes.js +0 -274
- package/lib/module/aes.js.map +0 -1
- package/lib/module/constants.js +0 -81
- package/lib/module/constants.js.map +0 -1
- package/lib/module/ec.js +0 -267
- package/lib/module/ec.js.map +0 -1
- package/lib/module/keygen.js +0 -49
- package/lib/module/keygen.js.map +0 -1
- package/lib/module/keys.js +0 -477
- package/lib/module/keys.js.map +0 -1
- package/lib/module/pbkdf2.js +0 -84
- package/lib/module/pbkdf2.js.map +0 -1
- package/lib/module/rsa.js +0 -242
- package/lib/module/rsa.js.map +0 -1
- package/lib/module/sig.js +0 -124
- package/lib/module/sig.js.map +0 -1
- package/lib/module/subtle.js +0 -443
- package/lib/module/subtle.js.map +0 -1
- package/lib/module/webcrypto.js +0 -10
- package/lib/module/webcrypto.js.map +0 -1
- package/lib/typescript/Cipher.d.ts +0 -81
- package/lib/typescript/Cipher.d.ts.map +0 -1
- package/lib/typescript/Hash.d.ts +0 -44
- package/lib/typescript/Hash.d.ts.map +0 -1
- package/lib/typescript/Hashnames.d.ts +0 -11
- package/lib/typescript/Hashnames.d.ts.map +0 -1
- package/lib/typescript/Hmac.d.ts +0 -37
- package/lib/typescript/Hmac.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +0 -44
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +0 -33
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/aes.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/aes.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/hash.d.ts +0 -7
- package/lib/typescript/NativeQuickCrypto/hash.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/hmac.d.ts +0 -6
- package/lib/typescript/NativeQuickCrypto/hmac.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/keygen.d.ts +0 -4
- package/lib/typescript/NativeQuickCrypto/keygen.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/random.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/random.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/rsa.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/rsa.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/sig.d.ts +0 -23
- package/lib/typescript/NativeQuickCrypto/sig.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts +0 -39
- package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts.map +0 -1
- package/lib/typescript/Utils.d.ts +0 -48
- package/lib/typescript/Utils.d.ts.map +0 -1
- package/lib/typescript/aes.d.ts +0 -22
- package/lib/typescript/aes.d.ts.map +0 -1
- package/lib/typescript/constants.d.ts +0 -76
- package/lib/typescript/constants.d.ts.map +0 -1
- package/lib/typescript/ec.d.ts +0 -7
- package/lib/typescript/ec.d.ts.map +0 -1
- package/lib/typescript/keygen.d.ts +0 -6
- package/lib/typescript/keygen.d.ts.map +0 -1
- package/lib/typescript/keys.d.ts +0 -206
- package/lib/typescript/keys.d.ts.map +0 -1
- package/lib/typescript/pbkdf2.d.ts +0 -12
- package/lib/typescript/pbkdf2.d.ts.map +0 -1
- package/lib/typescript/rsa.d.ts +0 -12
- package/lib/typescript/rsa.d.ts.map +0 -1
- package/lib/typescript/sig.d.ts +0 -21
- package/lib/typescript/sig.d.ts.map +0 -1
- package/lib/typescript/subtle.d.ts +0 -15
- package/lib/typescript/subtle.d.ts.map +0 -1
- package/lib/typescript/webcrypto.d.ts +0 -9
- package/lib/typescript/webcrypto.d.ts.map +0 -1
- package/react-native-quick-crypto.podspec +0 -40
- package/src/Cipher.ts +0 -832
- package/src/Hash.ts +0 -132
- package/src/Hashnames.ts +0 -93
- package/src/Hmac.ts +0 -106
- package/src/NativeQuickCrypto/Cipher.ts +0 -102
- package/src/NativeQuickCrypto/NativeQuickCrypto.ts +0 -102
- package/src/NativeQuickCrypto/aes.ts +0 -14
- package/src/NativeQuickCrypto/hash.ts +0 -10
- package/src/NativeQuickCrypto/hmac.ts +0 -9
- package/src/NativeQuickCrypto/keygen.ts +0 -7
- package/src/NativeQuickCrypto/pbkdf2.ts +0 -16
- package/src/NativeQuickCrypto/random.ts +0 -12
- package/src/NativeQuickCrypto/rsa.ts +0 -12
- package/src/NativeQuickCrypto/sig.ts +0 -44
- package/src/NativeQuickCrypto/webcrypto.ts +0 -72
- package/src/Utils.ts +0 -777
- package/src/aes.ts +0 -402
- package/src/constants.ts +0 -79
- package/src/ec.ts +0 -375
- package/src/keygen.ts +0 -80
- package/src/keys.ts +0 -787
- package/src/pbkdf2.ts +0 -169
- package/src/rsa.ts +0 -370
- package/src/sig.ts +0 -164
- package/src/subtle.ts +0 -639
- package/src/webcrypto.ts +0 -8
- /package/android/src/main/{AndroidManifestNew.xml → AndroidManifest.xml} +0 -0
package/src/subtle.ts
DELETED
|
@@ -1,639 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ImportFormat,
|
|
3
|
-
type SubtleAlgorithm,
|
|
4
|
-
type KeyUsage,
|
|
5
|
-
CryptoKey,
|
|
6
|
-
KWebCryptoKeyFormat,
|
|
7
|
-
createSecretKey,
|
|
8
|
-
type AnyAlgorithm,
|
|
9
|
-
type JWK,
|
|
10
|
-
type CryptoKeyPair,
|
|
11
|
-
CipherOrWrapMode,
|
|
12
|
-
type EncryptDecryptParams,
|
|
13
|
-
type AesKeyGenParams,
|
|
14
|
-
} from './keys';
|
|
15
|
-
import {
|
|
16
|
-
hasAnyNotIn,
|
|
17
|
-
type BufferLike,
|
|
18
|
-
type BinaryLike,
|
|
19
|
-
normalizeAlgorithm,
|
|
20
|
-
lazyDOMException,
|
|
21
|
-
normalizeHashName,
|
|
22
|
-
HashContext,
|
|
23
|
-
type Operation,
|
|
24
|
-
validateMaxBufferLength,
|
|
25
|
-
bufferLikeToArrayBuffer,
|
|
26
|
-
} from './Utils';
|
|
27
|
-
import { ecImportKey, ecExportKey, ecGenerateKey, ecdsaSignVerify } from './ec';
|
|
28
|
-
import { pbkdf2DeriveBits } from './pbkdf2';
|
|
29
|
-
import { asyncDigest } from './Hash';
|
|
30
|
-
import {
|
|
31
|
-
aesCipher,
|
|
32
|
-
aesGenerateKey,
|
|
33
|
-
aesImportKey,
|
|
34
|
-
getAlgorithmName,
|
|
35
|
-
} from './aes';
|
|
36
|
-
import { rsaCipher, rsaExportKey, rsaImportKey, rsaKeyGenerate } from './rsa';
|
|
37
|
-
|
|
38
|
-
const exportKeySpki = async (key: CryptoKey): Promise<ArrayBuffer | any> => {
|
|
39
|
-
switch (key.algorithm.name) {
|
|
40
|
-
case 'RSASSA-PKCS1-v1_5':
|
|
41
|
-
// Fall through
|
|
42
|
-
case 'RSA-PSS':
|
|
43
|
-
// Fall through
|
|
44
|
-
case 'RSA-OAEP':
|
|
45
|
-
if (key.type === 'public') {
|
|
46
|
-
return rsaExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatSPKI);
|
|
47
|
-
}
|
|
48
|
-
break;
|
|
49
|
-
case 'ECDSA':
|
|
50
|
-
// Fall through
|
|
51
|
-
case 'ECDH':
|
|
52
|
-
if (key.type === 'public') {
|
|
53
|
-
return ecExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatSPKI);
|
|
54
|
-
}
|
|
55
|
-
break;
|
|
56
|
-
// case 'Ed25519':
|
|
57
|
-
// // Fall through
|
|
58
|
-
// case 'Ed448':
|
|
59
|
-
// // Fall through
|
|
60
|
-
// case 'X25519':
|
|
61
|
-
// // Fall through
|
|
62
|
-
// case 'X448':
|
|
63
|
-
// if (key.type === 'public') {
|
|
64
|
-
// return cfrgExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatSPKI);
|
|
65
|
-
// }
|
|
66
|
-
// break;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
throw new Error(
|
|
70
|
-
`Unable to export a spki ${key.algorithm.name} ${key.type} key`
|
|
71
|
-
);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const exportKeyPkcs8 = async (key: CryptoKey): Promise<ArrayBuffer | any> => {
|
|
75
|
-
switch (key.algorithm.name) {
|
|
76
|
-
case 'RSASSA-PKCS1-v1_5':
|
|
77
|
-
// Fall through
|
|
78
|
-
case 'RSA-PSS':
|
|
79
|
-
// Fall through
|
|
80
|
-
case 'RSA-OAEP':
|
|
81
|
-
if (key.type === 'private') {
|
|
82
|
-
return rsaExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatPKCS8);
|
|
83
|
-
}
|
|
84
|
-
break;
|
|
85
|
-
case 'ECDSA':
|
|
86
|
-
// Fall through
|
|
87
|
-
case 'ECDH':
|
|
88
|
-
if (key.type === 'private') {
|
|
89
|
-
return ecExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatPKCS8);
|
|
90
|
-
}
|
|
91
|
-
break;
|
|
92
|
-
// case 'Ed25519':
|
|
93
|
-
// // Fall through
|
|
94
|
-
// case 'Ed448':
|
|
95
|
-
// // Fall through
|
|
96
|
-
// case 'X25519':
|
|
97
|
-
// // Fall through
|
|
98
|
-
// case 'X448':
|
|
99
|
-
// if (key.type === 'private') {
|
|
100
|
-
// return cfrgExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatPKCS8);
|
|
101
|
-
// }
|
|
102
|
-
// break;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
throw new Error(
|
|
106
|
-
`Unable to export a pkcs8 ${key.algorithm.name} ${key.type} key`
|
|
107
|
-
);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const exportKeyRaw = (key: CryptoKey): ArrayBuffer | any => {
|
|
111
|
-
switch (key.algorithm.name) {
|
|
112
|
-
case 'ECDSA':
|
|
113
|
-
// Fall through
|
|
114
|
-
case 'ECDH':
|
|
115
|
-
if (key.type === 'public') {
|
|
116
|
-
return ecExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatRaw);
|
|
117
|
-
}
|
|
118
|
-
break;
|
|
119
|
-
// case 'Ed25519':
|
|
120
|
-
// // Fall through
|
|
121
|
-
// case 'Ed448':
|
|
122
|
-
// // Fall through
|
|
123
|
-
// case 'X25519':
|
|
124
|
-
// // Fall through
|
|
125
|
-
// case 'X448':
|
|
126
|
-
// if (key.type === 'public') {
|
|
127
|
-
// return require('internal/crypto/cfrg')
|
|
128
|
-
// .cfrgExportKey(key, kWebCryptoKeyFormatRaw);
|
|
129
|
-
// }
|
|
130
|
-
// break;
|
|
131
|
-
case 'AES-CTR':
|
|
132
|
-
// Fall through
|
|
133
|
-
case 'AES-CBC':
|
|
134
|
-
// Fall through
|
|
135
|
-
case 'AES-GCM':
|
|
136
|
-
// Fall through
|
|
137
|
-
case 'AES-KW':
|
|
138
|
-
// Fall through
|
|
139
|
-
case 'HMAC':
|
|
140
|
-
return key.keyObject.export();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
throw lazyDOMException(
|
|
144
|
-
`Unable to export a raw ${key.algorithm.name} ${key.type} key`,
|
|
145
|
-
'InvalidAccessError'
|
|
146
|
-
);
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const exportKeyJWK = (key: CryptoKey): ArrayBuffer | any => {
|
|
150
|
-
const jwk = key.keyObject.handle.exportJwk(
|
|
151
|
-
{
|
|
152
|
-
key_ops: key.usages,
|
|
153
|
-
ext: key.extractable,
|
|
154
|
-
},
|
|
155
|
-
true
|
|
156
|
-
);
|
|
157
|
-
switch (key.algorithm.name) {
|
|
158
|
-
case 'RSASSA-PKCS1-v1_5':
|
|
159
|
-
jwk.alg = normalizeHashName(key.algorithm.hash, HashContext.JwkRsa);
|
|
160
|
-
return jwk;
|
|
161
|
-
case 'RSA-PSS':
|
|
162
|
-
jwk.alg = normalizeHashName(key.algorithm.hash, HashContext.JwkRsaPss);
|
|
163
|
-
return jwk;
|
|
164
|
-
case 'RSA-OAEP':
|
|
165
|
-
jwk.alg = normalizeHashName(key.algorithm.hash, HashContext.JwkRsaOaep);
|
|
166
|
-
return jwk;
|
|
167
|
-
case 'ECDSA':
|
|
168
|
-
// Fall through
|
|
169
|
-
case 'ECDH':
|
|
170
|
-
jwk.crv ||= key.algorithm.namedCurve;
|
|
171
|
-
return jwk;
|
|
172
|
-
// case 'X25519':
|
|
173
|
-
// // Fall through
|
|
174
|
-
// case 'X448':
|
|
175
|
-
// jwk.crv ||= key.algorithm.name;
|
|
176
|
-
// return jwk;
|
|
177
|
-
// case 'Ed25519':
|
|
178
|
-
// // Fall through
|
|
179
|
-
// case 'Ed448':
|
|
180
|
-
// jwk.crv ||= key.algorithm.name;
|
|
181
|
-
// return jwk;
|
|
182
|
-
case 'AES-CTR':
|
|
183
|
-
// Fall through
|
|
184
|
-
case 'AES-CBC':
|
|
185
|
-
// Fall through
|
|
186
|
-
case 'AES-GCM':
|
|
187
|
-
// Fall through
|
|
188
|
-
case 'AES-KW':
|
|
189
|
-
jwk.alg = getAlgorithmName(key.algorithm.name, key.algorithm.length);
|
|
190
|
-
return jwk;
|
|
191
|
-
// case 'HMAC':
|
|
192
|
-
// jwk.alg = normalizeHashName(
|
|
193
|
-
// key.algorithm.hash.name,
|
|
194
|
-
// normalizeHashName.kContextJwkHmac);
|
|
195
|
-
// return jwk;
|
|
196
|
-
default:
|
|
197
|
-
// Fall through
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
throw lazyDOMException(
|
|
201
|
-
`JWK export not yet supported: ${key.algorithm.name}`,
|
|
202
|
-
'NotSupportedError'
|
|
203
|
-
);
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
const importGenericSecretKey = async (
|
|
207
|
-
{ name, length }: SubtleAlgorithm,
|
|
208
|
-
format: ImportFormat,
|
|
209
|
-
keyData: BufferLike | BinaryLike,
|
|
210
|
-
extractable: boolean,
|
|
211
|
-
keyUsages: KeyUsage[]
|
|
212
|
-
): Promise<CryptoKey> => {
|
|
213
|
-
if (extractable) {
|
|
214
|
-
throw new Error(`${name} keys are not extractable`);
|
|
215
|
-
}
|
|
216
|
-
if (hasAnyNotIn(keyUsages, ['deriveKey', 'deriveBits'])) {
|
|
217
|
-
throw new Error(`Unsupported key usage for a ${name} key`);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
switch (format) {
|
|
221
|
-
case 'raw': {
|
|
222
|
-
if (hasAnyNotIn(keyUsages, ['deriveKey', 'deriveBits'])) {
|
|
223
|
-
throw new Error(`Unsupported key usage for a ${name} key`);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const checkLength =
|
|
227
|
-
typeof keyData === 'string'
|
|
228
|
-
? keyData.length * 8
|
|
229
|
-
: keyData.byteLength * 8;
|
|
230
|
-
|
|
231
|
-
// The Web Crypto spec allows for key lengths that are not multiples of
|
|
232
|
-
// 8. We don't. Our check here is stricter than that defined by the spec
|
|
233
|
-
// in that we require that algorithm.length match keyData.length * 8 if
|
|
234
|
-
// algorithm.length is specified.
|
|
235
|
-
if (length !== undefined && length !== checkLength) {
|
|
236
|
-
throw new Error('Invalid key length');
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const keyObject = createSecretKey(keyData);
|
|
240
|
-
return new CryptoKey(keyObject, { name }, keyUsages, false);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
throw new Error(`Unable to import ${name} key with format ${format}`);
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
// const checkCryptoKeyUsages = (key: CryptoKey) => {
|
|
248
|
-
// if (
|
|
249
|
-
// (key.type === 'secret' || key.type === 'private') &&
|
|
250
|
-
// key.usages.length === 0
|
|
251
|
-
// ) {
|
|
252
|
-
// throw lazyDOMException(
|
|
253
|
-
// 'Usages cannot be empty when creating a key.',
|
|
254
|
-
// 'SyntaxError'
|
|
255
|
-
// );
|
|
256
|
-
// }
|
|
257
|
-
// };
|
|
258
|
-
|
|
259
|
-
const checkCryptoKeyPairUsages = (pair: CryptoKeyPair) => {
|
|
260
|
-
if (
|
|
261
|
-
!(pair.privateKey instanceof Buffer) &&
|
|
262
|
-
pair.privateKey &&
|
|
263
|
-
pair.privateKey.hasOwnProperty('keyUsages')
|
|
264
|
-
) {
|
|
265
|
-
const priv = pair.privateKey as CryptoKey;
|
|
266
|
-
if (priv.usages.length > 0) {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
console.log(pair.privateKey);
|
|
271
|
-
throw lazyDOMException(
|
|
272
|
-
'Usages cannot be empty when creating a key.',
|
|
273
|
-
'SyntaxError'
|
|
274
|
-
);
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
const signVerify = (
|
|
278
|
-
algorithm: SubtleAlgorithm,
|
|
279
|
-
key: CryptoKey,
|
|
280
|
-
data: BufferLike,
|
|
281
|
-
signature?: BufferLike
|
|
282
|
-
): ArrayBuffer | boolean => {
|
|
283
|
-
const usage: Operation = signature === undefined ? 'sign' : 'verify';
|
|
284
|
-
algorithm = normalizeAlgorithm(algorithm, usage);
|
|
285
|
-
|
|
286
|
-
if (!key.usages.includes(usage) || algorithm.name !== key.algorithm.name) {
|
|
287
|
-
throw lazyDOMException(
|
|
288
|
-
`Unable to use this key to ${usage}`,
|
|
289
|
-
'InvalidAccessError'
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
switch (algorithm.name) {
|
|
294
|
-
// case 'RSA-PSS':
|
|
295
|
-
// // Fall through
|
|
296
|
-
// case 'RSASSA-PKCS1-v1_5':
|
|
297
|
-
// return require('internal/crypto/rsa').rsaSignVerify(
|
|
298
|
-
// key,
|
|
299
|
-
// data,
|
|
300
|
-
// algorithm,
|
|
301
|
-
// signature
|
|
302
|
-
// );
|
|
303
|
-
case 'ECDSA':
|
|
304
|
-
return ecdsaSignVerify(key, data, algorithm, signature);
|
|
305
|
-
// case 'Ed25519':
|
|
306
|
-
// // Fall through
|
|
307
|
-
// case 'Ed448':
|
|
308
|
-
// return require('internal/crypto/cfrg').eddsaSignVerify(
|
|
309
|
-
// key,
|
|
310
|
-
// data,
|
|
311
|
-
// algorithm,
|
|
312
|
-
// signature
|
|
313
|
-
// );
|
|
314
|
-
// case 'HMAC':
|
|
315
|
-
// return require('internal/crypto/mac').hmacSignVerify(
|
|
316
|
-
// key,
|
|
317
|
-
// data,
|
|
318
|
-
// algorithm,
|
|
319
|
-
// signature
|
|
320
|
-
// );
|
|
321
|
-
}
|
|
322
|
-
throw lazyDOMException(
|
|
323
|
-
`Unrecognized algorithm name '${algorithm}' for '${usage}'`,
|
|
324
|
-
'NotSupportedError'
|
|
325
|
-
);
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
const cipherOrWrap = async (
|
|
329
|
-
mode: CipherOrWrapMode,
|
|
330
|
-
algorithm: EncryptDecryptParams, // | WrapUnwrapParams,
|
|
331
|
-
key: CryptoKey,
|
|
332
|
-
data: ArrayBuffer,
|
|
333
|
-
op: Operation
|
|
334
|
-
): Promise<ArrayBuffer> => {
|
|
335
|
-
// We use a Node.js style error here instead of a DOMException because
|
|
336
|
-
// the WebCrypto spec is not specific what kind of error is to be thrown
|
|
337
|
-
// in this case. Both Firefox and Chrome throw simple TypeErrors here.
|
|
338
|
-
// The key algorithm and cipher algorithm must match, and the
|
|
339
|
-
// key must have the proper usage.
|
|
340
|
-
if (
|
|
341
|
-
key.algorithm.name !== algorithm.name ||
|
|
342
|
-
!key.usages.includes(op as KeyUsage)
|
|
343
|
-
) {
|
|
344
|
-
throw lazyDOMException(
|
|
345
|
-
'The requested operation is not valid for the provided key',
|
|
346
|
-
'InvalidAccessError'
|
|
347
|
-
);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// While WebCrypto allows for larger input buffer sizes, we limit
|
|
351
|
-
// those to sizes that can fit within uint32_t because of limitations
|
|
352
|
-
// in the OpenSSL API.
|
|
353
|
-
validateMaxBufferLength(data, 'data');
|
|
354
|
-
|
|
355
|
-
switch (algorithm.name) {
|
|
356
|
-
case 'RSA-OAEP':
|
|
357
|
-
return rsaCipher(mode, key, data, algorithm);
|
|
358
|
-
case 'AES-CTR':
|
|
359
|
-
// Fall through
|
|
360
|
-
case 'AES-CBC':
|
|
361
|
-
// Fall through
|
|
362
|
-
case 'AES-GCM':
|
|
363
|
-
return aesCipher(mode, key, data, algorithm);
|
|
364
|
-
// case 'AES-KW':
|
|
365
|
-
// if (op === 'wrapKey' || op === 'unwrapKey') {
|
|
366
|
-
// return aesCipher(mode, key, data, algorithm);
|
|
367
|
-
// }
|
|
368
|
-
}
|
|
369
|
-
// @ts-ignore
|
|
370
|
-
throw lazyDOMException(
|
|
371
|
-
`Unrecognized algorithm name '${algorithm}' for '${op}'`,
|
|
372
|
-
'NotSupportedError'
|
|
373
|
-
);
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
export class Subtle {
|
|
377
|
-
async decrypt(
|
|
378
|
-
algorithm: EncryptDecryptParams,
|
|
379
|
-
key: CryptoKey,
|
|
380
|
-
data: BufferLike
|
|
381
|
-
): Promise<ArrayBuffer> {
|
|
382
|
-
const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'decrypt');
|
|
383
|
-
return cipherOrWrap(
|
|
384
|
-
CipherOrWrapMode.kWebCryptoCipherDecrypt,
|
|
385
|
-
normalizedAlgorithm as EncryptDecryptParams,
|
|
386
|
-
key,
|
|
387
|
-
bufferLikeToArrayBuffer(data),
|
|
388
|
-
'decrypt'
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
async digest(
|
|
393
|
-
algorithm: SubtleAlgorithm | AnyAlgorithm,
|
|
394
|
-
data: BufferLike
|
|
395
|
-
): Promise<ArrayBuffer> {
|
|
396
|
-
const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'digest');
|
|
397
|
-
return asyncDigest(normalizedAlgorithm, data);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
async deriveBits(
|
|
401
|
-
algorithm: SubtleAlgorithm,
|
|
402
|
-
baseKey: CryptoKey,
|
|
403
|
-
length: number
|
|
404
|
-
): Promise<ArrayBuffer> {
|
|
405
|
-
if (!baseKey.keyUsages.includes('deriveBits')) {
|
|
406
|
-
throw new Error('baseKey does not have deriveBits usage');
|
|
407
|
-
}
|
|
408
|
-
if (baseKey.algorithm.name !== algorithm.name)
|
|
409
|
-
throw new Error('Key algorithm mismatch');
|
|
410
|
-
switch (algorithm.name) {
|
|
411
|
-
// case 'X25519':
|
|
412
|
-
// // Fall through
|
|
413
|
-
// case 'X448':
|
|
414
|
-
// // Fall through
|
|
415
|
-
// case 'ECDH':
|
|
416
|
-
// return require('internal/crypto/diffiehellman')
|
|
417
|
-
// .ecdhDeriveBits(algorithm, baseKey, length);
|
|
418
|
-
// case 'HKDF':
|
|
419
|
-
// return require('internal/crypto/hkdf')
|
|
420
|
-
// .hkdfDeriveBits(algorithm, baseKey, length);
|
|
421
|
-
case 'PBKDF2':
|
|
422
|
-
return pbkdf2DeriveBits(algorithm, baseKey, length);
|
|
423
|
-
}
|
|
424
|
-
throw new Error(
|
|
425
|
-
`'subtle.deriveBits()' for ${algorithm.name} is not implemented.`
|
|
426
|
-
);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
async encrypt(
|
|
430
|
-
algorithm: EncryptDecryptParams,
|
|
431
|
-
key: CryptoKey,
|
|
432
|
-
data: BufferLike
|
|
433
|
-
): Promise<ArrayBuffer> {
|
|
434
|
-
const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'encrypt');
|
|
435
|
-
return cipherOrWrap(
|
|
436
|
-
CipherOrWrapMode.kWebCryptoCipherEncrypt,
|
|
437
|
-
normalizedAlgorithm as EncryptDecryptParams,
|
|
438
|
-
key,
|
|
439
|
-
bufferLikeToArrayBuffer(data),
|
|
440
|
-
'encrypt'
|
|
441
|
-
);
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
async exportKey(
|
|
445
|
-
format: ImportFormat,
|
|
446
|
-
key: CryptoKey
|
|
447
|
-
): Promise<ArrayBuffer | JWK> {
|
|
448
|
-
if (!key.extractable) throw new Error('key is not extractable');
|
|
449
|
-
|
|
450
|
-
switch (format) {
|
|
451
|
-
case 'spki':
|
|
452
|
-
return await exportKeySpki(key);
|
|
453
|
-
case 'pkcs8':
|
|
454
|
-
return await exportKeyPkcs8(key);
|
|
455
|
-
case 'jwk':
|
|
456
|
-
return exportKeyJWK(key);
|
|
457
|
-
case 'raw':
|
|
458
|
-
return exportKeyRaw(key);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
async generateKey(
|
|
463
|
-
algorithm: SubtleAlgorithm,
|
|
464
|
-
extractable: boolean,
|
|
465
|
-
keyUsages: KeyUsage[]
|
|
466
|
-
): Promise<CryptoKey | CryptoKeyPair> {
|
|
467
|
-
algorithm = normalizeAlgorithm(algorithm, 'generateKey');
|
|
468
|
-
let result: CryptoKey | CryptoKeyPair;
|
|
469
|
-
switch (algorithm.name) {
|
|
470
|
-
case 'RSASSA-PKCS1-v1_5':
|
|
471
|
-
// Fall through
|
|
472
|
-
case 'RSA-PSS':
|
|
473
|
-
// Fall through
|
|
474
|
-
case 'RSA-OAEP':
|
|
475
|
-
result = await rsaKeyGenerate(algorithm, extractable, keyUsages);
|
|
476
|
-
break;
|
|
477
|
-
// case 'Ed25519':
|
|
478
|
-
// // Fall through
|
|
479
|
-
// case 'Ed448':
|
|
480
|
-
// // Fall through
|
|
481
|
-
// case 'X25519':
|
|
482
|
-
// // Fall through
|
|
483
|
-
// case 'X448':
|
|
484
|
-
// resultType = 'CryptoKeyPair';
|
|
485
|
-
// result = await cfrgGenerateKey(algorithm, extractable, keyUsages);
|
|
486
|
-
// break;
|
|
487
|
-
case 'ECDSA':
|
|
488
|
-
// Fall through
|
|
489
|
-
case 'ECDH':
|
|
490
|
-
result = await ecGenerateKey(algorithm, extractable, keyUsages);
|
|
491
|
-
checkCryptoKeyPairUsages(result);
|
|
492
|
-
break;
|
|
493
|
-
// case 'HMAC':
|
|
494
|
-
// result = await hmacGenerateKey(algorithm, extractable, keyUsages);
|
|
495
|
-
// break;
|
|
496
|
-
case 'AES-CTR':
|
|
497
|
-
// Fall through
|
|
498
|
-
case 'AES-CBC':
|
|
499
|
-
// Fall through
|
|
500
|
-
case 'AES-GCM':
|
|
501
|
-
// Fall through
|
|
502
|
-
case 'AES-KW':
|
|
503
|
-
result = await aesGenerateKey(
|
|
504
|
-
algorithm as AesKeyGenParams,
|
|
505
|
-
extractable,
|
|
506
|
-
keyUsages
|
|
507
|
-
);
|
|
508
|
-
break;
|
|
509
|
-
default:
|
|
510
|
-
throw new Error(
|
|
511
|
-
`'subtle.generateKey()' is not implemented for ${algorithm.name}.
|
|
512
|
-
Unrecognized algorithm name`
|
|
513
|
-
);
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
return result;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
async importKey(
|
|
520
|
-
format: ImportFormat,
|
|
521
|
-
data: BufferLike | BinaryLike | JWK,
|
|
522
|
-
algorithm: SubtleAlgorithm | AnyAlgorithm,
|
|
523
|
-
extractable: boolean,
|
|
524
|
-
keyUsages: KeyUsage[]
|
|
525
|
-
): Promise<CryptoKey> {
|
|
526
|
-
const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'importKey');
|
|
527
|
-
let result: CryptoKey;
|
|
528
|
-
switch (normalizedAlgorithm.name) {
|
|
529
|
-
case 'RSASSA-PKCS1-v1_5':
|
|
530
|
-
// Fall through
|
|
531
|
-
case 'RSA-PSS':
|
|
532
|
-
// Fall through
|
|
533
|
-
case 'RSA-OAEP':
|
|
534
|
-
result = rsaImportKey(
|
|
535
|
-
format,
|
|
536
|
-
data as BufferLike | JWK,
|
|
537
|
-
normalizedAlgorithm,
|
|
538
|
-
extractable,
|
|
539
|
-
keyUsages
|
|
540
|
-
);
|
|
541
|
-
break;
|
|
542
|
-
case 'ECDSA':
|
|
543
|
-
// Fall through
|
|
544
|
-
case 'ECDH':
|
|
545
|
-
result = ecImportKey(
|
|
546
|
-
format,
|
|
547
|
-
data,
|
|
548
|
-
normalizedAlgorithm,
|
|
549
|
-
extractable,
|
|
550
|
-
keyUsages
|
|
551
|
-
);
|
|
552
|
-
break;
|
|
553
|
-
// case 'Ed25519':
|
|
554
|
-
// // Fall through
|
|
555
|
-
// case 'Ed448':
|
|
556
|
-
// // Fall through
|
|
557
|
-
// case 'X25519':
|
|
558
|
-
// // Fall through
|
|
559
|
-
// case 'X448':
|
|
560
|
-
// result = await require('internal/crypto/cfrg').cfrgImportKey(
|
|
561
|
-
// format,
|
|
562
|
-
// keyData,
|
|
563
|
-
// algorithm,
|
|
564
|
-
// extractable,
|
|
565
|
-
// keyUsages
|
|
566
|
-
// );
|
|
567
|
-
// break;
|
|
568
|
-
// case 'HMAC':
|
|
569
|
-
// result = await require('internal/crypto/mac').hmacImportKey(
|
|
570
|
-
// format,
|
|
571
|
-
// keyData,
|
|
572
|
-
// algorithm,
|
|
573
|
-
// extractable,
|
|
574
|
-
// keyUsages
|
|
575
|
-
// );
|
|
576
|
-
// break;
|
|
577
|
-
case 'AES-CTR':
|
|
578
|
-
// Fall through
|
|
579
|
-
case 'AES-CBC':
|
|
580
|
-
// Fall through
|
|
581
|
-
case 'AES-GCM':
|
|
582
|
-
// Fall through
|
|
583
|
-
case 'AES-KW':
|
|
584
|
-
result = await aesImportKey(
|
|
585
|
-
normalizedAlgorithm,
|
|
586
|
-
format,
|
|
587
|
-
data as BufferLike | JWK,
|
|
588
|
-
extractable,
|
|
589
|
-
keyUsages
|
|
590
|
-
);
|
|
591
|
-
break;
|
|
592
|
-
// case 'HKDF':
|
|
593
|
-
// // Fall through
|
|
594
|
-
case 'PBKDF2':
|
|
595
|
-
result = await importGenericSecretKey(
|
|
596
|
-
normalizedAlgorithm,
|
|
597
|
-
format,
|
|
598
|
-
data as BufferLike | BinaryLike,
|
|
599
|
-
extractable,
|
|
600
|
-
keyUsages
|
|
601
|
-
);
|
|
602
|
-
break;
|
|
603
|
-
default:
|
|
604
|
-
throw new Error(
|
|
605
|
-
`"subtle.importKey()" is not implemented for ${normalizedAlgorithm.name}`
|
|
606
|
-
);
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
if (
|
|
610
|
-
(result.type === 'secret' || result.type === 'private') &&
|
|
611
|
-
result.usages.length === 0
|
|
612
|
-
) {
|
|
613
|
-
throw new Error(
|
|
614
|
-
`Usages cannot be empty when importing a ${result.type} key.`
|
|
615
|
-
);
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
return result;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
async sign(
|
|
622
|
-
algorithm: SubtleAlgorithm,
|
|
623
|
-
key: CryptoKey,
|
|
624
|
-
data: BufferLike
|
|
625
|
-
): Promise<ArrayBuffer> {
|
|
626
|
-
return signVerify(algorithm, key, data) as ArrayBuffer;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
async verify(
|
|
630
|
-
algorithm: SubtleAlgorithm,
|
|
631
|
-
key: CryptoKey,
|
|
632
|
-
signature: BufferLike,
|
|
633
|
-
data: BufferLike
|
|
634
|
-
): Promise<ArrayBuffer> {
|
|
635
|
-
return signVerify(algorithm, key, data, signature) as ArrayBuffer;
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
export const subtle = new Subtle();
|
package/src/webcrypto.ts
DELETED
|
File without changes
|