react-native-quick-crypto 0.7.3 → 0.7.4
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/README.md +13 -46
- package/android/build.gradle +1 -1
- package/android/gradle.properties +1 -1
- package/lib/commonjs/Cipher.js +113 -111
- package/lib/commonjs/Cipher.js.map +1 -1
- package/lib/commonjs/Hash.js +8 -5
- package/lib/commonjs/Hash.js.map +1 -1
- package/lib/commonjs/Hashnames.js +4 -1
- package/lib/commonjs/Hashnames.js.map +1 -1
- package/lib/commonjs/Hmac.js +5 -3
- package/lib/commonjs/Hmac.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/Cipher.js +7 -7
- package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +11 -4
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/sig.js.map +1 -1
- package/lib/commonjs/Utils.js +98 -63
- package/lib/commonjs/Utils.js.map +1 -1
- package/lib/commonjs/aes.js +9 -8
- package/lib/commonjs/aes.js.map +1 -1
- package/lib/commonjs/ec.js +2 -3
- package/lib/commonjs/ec.js.map +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keygen.js +4 -2
- package/lib/commonjs/keygen.js.map +1 -1
- package/lib/commonjs/keys.js +7 -2
- package/lib/commonjs/keys.js.map +1 -1
- package/lib/commonjs/pbkdf2.js +13 -21
- package/lib/commonjs/pbkdf2.js.map +1 -1
- package/lib/commonjs/random.js +6 -8
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/rsa.js.map +1 -1
- package/lib/commonjs/sig.js +1 -2
- package/lib/commonjs/sig.js.map +1 -1
- package/lib/commonjs/subtle.js +4 -3
- package/lib/commonjs/subtle.js.map +1 -1
- package/lib/module/Cipher.js +112 -110
- package/lib/module/Cipher.js.map +1 -1
- package/lib/module/Hash.js +7 -4
- package/lib/module/Hash.js.map +1 -1
- package/lib/module/Hashnames.js +4 -1
- package/lib/module/Hashnames.js.map +1 -1
- package/lib/module/Hmac.js +4 -2
- package/lib/module/Hmac.js.map +1 -1
- package/lib/module/NativeQuickCrypto/Cipher.js +7 -7
- package/lib/module/NativeQuickCrypto/Cipher.js.map +1 -1
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +11 -4
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
- package/lib/module/NativeQuickCrypto/sig.js.map +1 -1
- package/lib/module/Utils.js +95 -62
- package/lib/module/Utils.js.map +1 -1
- package/lib/module/aes.js +9 -8
- package/lib/module/aes.js.map +1 -1
- package/lib/module/ec.js +2 -3
- package/lib/module/ec.js.map +1 -1
- package/lib/module/keygen.js +4 -2
- package/lib/module/keygen.js.map +1 -1
- package/lib/module/keys.js +7 -2
- package/lib/module/keys.js.map +1 -1
- package/lib/module/pbkdf2.js +13 -21
- package/lib/module/pbkdf2.js.map +1 -1
- package/lib/module/random.js +6 -8
- package/lib/module/random.js.map +1 -1
- package/lib/module/rsa.js.map +1 -1
- package/lib/module/sig.js +0 -1
- package/lib/module/sig.js.map +1 -1
- package/lib/module/subtle.js +4 -3
- package/lib/module/subtle.js.map +1 -1
- package/lib/typescript/{Cipher.d.ts → src/Cipher.d.ts} +37 -33
- package/lib/typescript/src/Cipher.d.ts.map +1 -0
- package/lib/typescript/src/Hash.d.ts.map +1 -0
- package/lib/typescript/src/Hashnames.d.ts.map +1 -0
- package/lib/typescript/src/Hmac.d.ts.map +1 -0
- package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/Cipher.d.ts +5 -5
- package/lib/typescript/src/NativeQuickCrypto/Cipher.d.ts.map +1 -0
- package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/NativeQuickCrypto.d.ts +1 -1
- package/lib/typescript/src/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +1 -0
- package/lib/typescript/src/NativeQuickCrypto/aes.d.ts.map +1 -0
- package/lib/typescript/src/NativeQuickCrypto/hash.d.ts.map +1 -0
- package/lib/typescript/src/NativeQuickCrypto/hmac.d.ts.map +1 -0
- package/lib/typescript/src/NativeQuickCrypto/keygen.d.ts.map +1 -0
- package/lib/typescript/src/NativeQuickCrypto/pbkdf2.d.ts.map +1 -0
- package/lib/typescript/src/NativeQuickCrypto/random.d.ts.map +1 -0
- package/lib/typescript/src/NativeQuickCrypto/rsa.d.ts.map +1 -0
- package/lib/typescript/src/NativeQuickCrypto/sig.d.ts.map +1 -0
- package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/webcrypto.d.ts +1 -1
- package/lib/typescript/src/NativeQuickCrypto/webcrypto.d.ts.map +1 -0
- package/lib/typescript/{Utils.d.ts → src/Utils.d.ts} +18 -8
- package/lib/typescript/src/Utils.d.ts.map +1 -0
- package/lib/typescript/src/aes.d.ts.map +1 -0
- package/lib/typescript/src/constants.d.ts.map +1 -0
- package/lib/typescript/src/ec.d.ts.map +1 -0
- package/lib/typescript/{index.d.ts → src/index.d.ts} +5 -30
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/keygen.d.ts.map +1 -0
- package/lib/typescript/{keys.d.ts → src/keys.d.ts} +27 -25
- package/lib/typescript/src/keys.d.ts.map +1 -0
- package/lib/typescript/{pbkdf2.d.ts → src/pbkdf2.d.ts} +3 -4
- package/lib/typescript/src/pbkdf2.d.ts.map +1 -0
- package/lib/typescript/{random.d.ts → src/random.d.ts} +5 -5
- package/lib/typescript/src/random.d.ts.map +1 -0
- package/lib/typescript/src/rsa.d.ts.map +1 -0
- package/lib/typescript/{sig.d.ts → src/sig.d.ts} +5 -5
- package/lib/typescript/src/sig.d.ts.map +1 -0
- package/lib/typescript/src/subtle.d.ts.map +1 -0
- package/lib/typescript/src/webcrypto.d.ts.map +1 -0
- package/package.json +14 -41
- package/src/Cipher.ts +270 -212
- package/src/Hash.ts +14 -7
- package/src/Hashnames.ts +5 -2
- package/src/Hmac.ts +6 -5
- package/src/NativeQuickCrypto/Cipher.ts +21 -20
- package/src/NativeQuickCrypto/NativeQuickCrypto.ts +15 -11
- package/src/NativeQuickCrypto/aes.ts +1 -1
- package/src/NativeQuickCrypto/hash.ts +1 -1
- package/src/NativeQuickCrypto/hmac.ts +1 -1
- package/src/NativeQuickCrypto/keygen.ts +1 -1
- package/src/NativeQuickCrypto/pbkdf2.ts +2 -2
- package/src/NativeQuickCrypto/random.ts +2 -2
- package/src/NativeQuickCrypto/rsa.ts +1 -1
- package/src/NativeQuickCrypto/sig.ts +3 -1
- package/src/NativeQuickCrypto/webcrypto.ts +5 -5
- package/src/Utils.ts +175 -108
- package/src/aes.ts +29 -29
- package/src/ec.ts +18 -19
- package/src/keygen.ts +7 -7
- package/src/keys.ts +71 -65
- package/src/pbkdf2.ts +24 -48
- package/src/random.ts +37 -43
- package/src/rsa.ts +25 -23
- package/src/sig.ts +12 -13
- package/src/subtle.ts +50 -45
- package/lib/typescript/Cipher.d.ts.map +0 -1
- package/lib/typescript/Hash.d.ts.map +0 -1
- package/lib/typescript/Hashnames.d.ts.map +0 -1
- package/lib/typescript/Hmac.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/aes.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/hash.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/hmac.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/keygen.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/random.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/rsa.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/sig.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts.map +0 -1
- package/lib/typescript/Utils.d.ts.map +0 -1
- package/lib/typescript/aes.d.ts.map +0 -1
- package/lib/typescript/constants.d.ts.map +0 -1
- package/lib/typescript/ec.d.ts.map +0 -1
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/keygen.d.ts.map +0 -1
- package/lib/typescript/keys.d.ts.map +0 -1
- package/lib/typescript/pbkdf2.d.ts.map +0 -1
- package/lib/typescript/random.d.ts.map +0 -1
- package/lib/typescript/rsa.d.ts.map +0 -1
- package/lib/typescript/sig.d.ts.map +0 -1
- package/lib/typescript/subtle.d.ts.map +0 -1
- package/lib/typescript/webcrypto.d.ts.map +0 -1
- /package/lib/typescript/{Hash.d.ts → src/Hash.d.ts} +0 -0
- /package/lib/typescript/{Hashnames.d.ts → src/Hashnames.d.ts} +0 -0
- /package/lib/typescript/{Hmac.d.ts → src/Hmac.d.ts} +0 -0
- /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/aes.d.ts +0 -0
- /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/hash.d.ts +0 -0
- /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/hmac.d.ts +0 -0
- /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/keygen.d.ts +0 -0
- /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/pbkdf2.d.ts +0 -0
- /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/random.d.ts +0 -0
- /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/rsa.d.ts +0 -0
- /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/sig.d.ts +0 -0
- /package/lib/typescript/{aes.d.ts → src/aes.d.ts} +0 -0
- /package/lib/typescript/{constants.d.ts → src/constants.d.ts} +0 -0
- /package/lib/typescript/{ec.d.ts → src/ec.d.ts} +0 -0
- /package/lib/typescript/{keygen.d.ts → src/keygen.d.ts} +0 -0
- /package/lib/typescript/{rsa.d.ts → src/rsa.d.ts} +0 -0
- /package/lib/typescript/{subtle.d.ts → src/subtle.d.ts} +0 -0
- /package/lib/typescript/{webcrypto.d.ts → src/webcrypto.d.ts} +0 -0
package/src/aes.ts
CHANGED
|
@@ -52,7 +52,7 @@ export const getAlgorithmName = (name: string, length?: number) => {
|
|
|
52
52
|
if (length === undefined)
|
|
53
53
|
throw lazyDOMException(
|
|
54
54
|
`Invalid algorithm length: ${length}`,
|
|
55
|
-
'SyntaxError'
|
|
55
|
+
'SyntaxError',
|
|
56
56
|
);
|
|
57
57
|
switch (name) {
|
|
58
58
|
case 'AES-CBC':
|
|
@@ -84,7 +84,7 @@ function getVariant(name: AESAlgorithm, length: AESLength): AESKeyVariant {
|
|
|
84
84
|
case 256:
|
|
85
85
|
return AESKeyVariant.AES_CBC_256;
|
|
86
86
|
}
|
|
87
|
-
// @ts-
|
|
87
|
+
// @ts-expect-error unreachable code
|
|
88
88
|
break;
|
|
89
89
|
case 'AES-CTR':
|
|
90
90
|
switch (length) {
|
|
@@ -95,7 +95,7 @@ function getVariant(name: AESAlgorithm, length: AESLength): AESKeyVariant {
|
|
|
95
95
|
case 256:
|
|
96
96
|
return AESKeyVariant.AES_CTR_256;
|
|
97
97
|
}
|
|
98
|
-
// @ts-
|
|
98
|
+
// @ts-expect-error unreachable code
|
|
99
99
|
break;
|
|
100
100
|
case 'AES-GCM':
|
|
101
101
|
switch (length) {
|
|
@@ -106,7 +106,7 @@ function getVariant(name: AESAlgorithm, length: AESLength): AESKeyVariant {
|
|
|
106
106
|
case 256:
|
|
107
107
|
return AESKeyVariant.AES_GCM_256;
|
|
108
108
|
}
|
|
109
|
-
// @ts-
|
|
109
|
+
// @ts-expect-error unreachable code
|
|
110
110
|
break;
|
|
111
111
|
case 'AES-KW':
|
|
112
112
|
switch (length) {
|
|
@@ -117,14 +117,14 @@ function getVariant(name: AESAlgorithm, length: AESLength): AESKeyVariant {
|
|
|
117
117
|
case 256:
|
|
118
118
|
return AESKeyVariant.AES_KW_256;
|
|
119
119
|
}
|
|
120
|
-
// @ts-
|
|
120
|
+
// @ts-expect-error unreachable code
|
|
121
121
|
break;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
// @ts-
|
|
124
|
+
// @ts-expect-error unreachable code
|
|
125
125
|
throw lazyDOMException(
|
|
126
126
|
`Error getting variant ${name} at length: ${length}`,
|
|
127
|
-
'DataError'
|
|
127
|
+
'DataError',
|
|
128
128
|
);
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -132,7 +132,7 @@ function asyncAesCtrCipher(
|
|
|
132
132
|
mode: CipherOrWrapMode,
|
|
133
133
|
key: CryptoKey,
|
|
134
134
|
data: ArrayBuffer,
|
|
135
|
-
{ counter, length }: AesCtrParams
|
|
135
|
+
{ counter, length }: AesCtrParams,
|
|
136
136
|
): Promise<ArrayBuffer> {
|
|
137
137
|
validateByteLength(counter, 'algorithm.counter', 16);
|
|
138
138
|
// The length must specify an integer between 1 and 128. While
|
|
@@ -140,7 +140,7 @@ function asyncAesCtrCipher(
|
|
|
140
140
|
if (length === 0 || length > kMaxCounterLength) {
|
|
141
141
|
throw lazyDOMException(
|
|
142
142
|
'AES-CTR algorithm.length must be between 1 and 128',
|
|
143
|
-
'OperationError'
|
|
143
|
+
'OperationError',
|
|
144
144
|
);
|
|
145
145
|
}
|
|
146
146
|
|
|
@@ -150,7 +150,7 @@ function asyncAesCtrCipher(
|
|
|
150
150
|
data,
|
|
151
151
|
getVariant('AES-CTR', key.algorithm.length as AESLength),
|
|
152
152
|
bufferLikeToArrayBuffer(counter),
|
|
153
|
-
length
|
|
153
|
+
length,
|
|
154
154
|
);
|
|
155
155
|
}
|
|
156
156
|
|
|
@@ -158,7 +158,7 @@ function asyncAesCbcCipher(
|
|
|
158
158
|
mode: CipherOrWrapMode,
|
|
159
159
|
key: CryptoKey,
|
|
160
160
|
data: ArrayBuffer,
|
|
161
|
-
{ iv }: AesCbcParams
|
|
161
|
+
{ iv }: AesCbcParams,
|
|
162
162
|
): Promise<ArrayBuffer> {
|
|
163
163
|
validateByteLength(iv, 'algorithm.iv', 16);
|
|
164
164
|
return NativeQuickCrypto.webcrypto.aesCipher(
|
|
@@ -166,7 +166,7 @@ function asyncAesCbcCipher(
|
|
|
166
166
|
key.keyObject.handle,
|
|
167
167
|
data,
|
|
168
168
|
getVariant('AES-CBC', key.algorithm.length as AESLength),
|
|
169
|
-
bufferLikeToArrayBuffer(iv)
|
|
169
|
+
bufferLikeToArrayBuffer(iv),
|
|
170
170
|
);
|
|
171
171
|
}
|
|
172
172
|
|
|
@@ -187,12 +187,12 @@ function asyncAesGcmCipher(
|
|
|
187
187
|
mode: CipherOrWrapMode,
|
|
188
188
|
key: CryptoKey,
|
|
189
189
|
data: ArrayBuffer,
|
|
190
|
-
{ iv, additionalData, tagLength = 128 }: AesGcmParams
|
|
190
|
+
{ iv, additionalData, tagLength = 128 }: AesGcmParams,
|
|
191
191
|
) {
|
|
192
192
|
if (!kTagLengths.includes(tagLength)) {
|
|
193
193
|
throw lazyDOMException(
|
|
194
194
|
`${tagLength} is not a valid AES-GCM tag length`,
|
|
195
|
-
'OperationError'
|
|
195
|
+
'OperationError',
|
|
196
196
|
);
|
|
197
197
|
}
|
|
198
198
|
|
|
@@ -219,7 +219,7 @@ function asyncAesGcmCipher(
|
|
|
219
219
|
if (tagByteLength > tag.byteLength) {
|
|
220
220
|
throw lazyDOMException(
|
|
221
221
|
'The provided data is too small.',
|
|
222
|
-
'OperationError'
|
|
222
|
+
'OperationError',
|
|
223
223
|
);
|
|
224
224
|
}
|
|
225
225
|
|
|
@@ -239,7 +239,7 @@ function asyncAesGcmCipher(
|
|
|
239
239
|
bufferLikeToArrayBuffer(iv),
|
|
240
240
|
length,
|
|
241
241
|
bufferLikeToArrayBuffer(tag),
|
|
242
|
-
bufferLikeToArrayBuffer(additionalData || new ArrayBuffer(0))
|
|
242
|
+
bufferLikeToArrayBuffer(additionalData || new ArrayBuffer(0)),
|
|
243
243
|
);
|
|
244
244
|
}
|
|
245
245
|
|
|
@@ -247,7 +247,7 @@ export const aesCipher = (
|
|
|
247
247
|
mode: CipherOrWrapMode,
|
|
248
248
|
key: CryptoKey,
|
|
249
249
|
data: ArrayBuffer,
|
|
250
|
-
algorithm: EncryptDecryptParams // | WrapUnwrapParams
|
|
250
|
+
algorithm: EncryptDecryptParams, // | WrapUnwrapParams
|
|
251
251
|
): Promise<ArrayBuffer> => {
|
|
252
252
|
switch (algorithm.name) {
|
|
253
253
|
case 'AES-CTR':
|
|
@@ -265,7 +265,7 @@ export const aesCipher = (
|
|
|
265
265
|
export const aesGenerateKey = async (
|
|
266
266
|
algorithm: AesKeyGenParams,
|
|
267
267
|
extractable: boolean,
|
|
268
|
-
keyUsages: KeyUsage[]
|
|
268
|
+
keyUsages: KeyUsage[],
|
|
269
269
|
): Promise<CryptoKey> => {
|
|
270
270
|
const { name, length } = algorithm;
|
|
271
271
|
if (!name) {
|
|
@@ -274,7 +274,7 @@ export const aesGenerateKey = async (
|
|
|
274
274
|
if (!kAesKeyLengths.includes(length)) {
|
|
275
275
|
throw lazyDOMException(
|
|
276
276
|
'AES key length must be 128, 192, or 256 bits',
|
|
277
|
-
'OperationError'
|
|
277
|
+
'OperationError',
|
|
278
278
|
);
|
|
279
279
|
}
|
|
280
280
|
|
|
@@ -286,7 +286,7 @@ export const aesGenerateKey = async (
|
|
|
286
286
|
if (hasAnyNotIn(keyUsages, checkUsages)) {
|
|
287
287
|
throw lazyDOMException(
|
|
288
288
|
`Unsupported key usage for an AES key: ${keyUsages}`,
|
|
289
|
-
'SyntaxError'
|
|
289
|
+
'SyntaxError',
|
|
290
290
|
);
|
|
291
291
|
}
|
|
292
292
|
|
|
@@ -297,7 +297,7 @@ export const aesGenerateKey = async (
|
|
|
297
297
|
{
|
|
298
298
|
name: 'OperationError',
|
|
299
299
|
cause: err,
|
|
300
|
-
}
|
|
300
|
+
},
|
|
301
301
|
);
|
|
302
302
|
}
|
|
303
303
|
|
|
@@ -305,7 +305,7 @@ export const aesGenerateKey = async (
|
|
|
305
305
|
key as SecretKeyObject,
|
|
306
306
|
{ name, length },
|
|
307
307
|
Array.from(keyUsages),
|
|
308
|
-
extractable
|
|
308
|
+
extractable,
|
|
309
309
|
);
|
|
310
310
|
};
|
|
311
311
|
|
|
@@ -314,7 +314,7 @@ export const aesImportKey = async (
|
|
|
314
314
|
format: ImportFormat,
|
|
315
315
|
keyData: BufferLike | JWK,
|
|
316
316
|
extractable: boolean,
|
|
317
|
-
keyUsages: KeyUsage[]
|
|
317
|
+
keyUsages: KeyUsage[],
|
|
318
318
|
): Promise<CryptoKey> => {
|
|
319
319
|
const { name } = algorithm;
|
|
320
320
|
const checkUsages = ['wrapKey', 'unwrapKey'];
|
|
@@ -326,7 +326,7 @@ export const aesImportKey = async (
|
|
|
326
326
|
if (hasAnyNotIn(keyUsages, checkUsages)) {
|
|
327
327
|
throw lazyDOMException(
|
|
328
328
|
'Unsupported key usage for an AES key',
|
|
329
|
-
'SyntaxError'
|
|
329
|
+
'SyntaxError',
|
|
330
330
|
);
|
|
331
331
|
}
|
|
332
332
|
|
|
@@ -335,9 +335,9 @@ export const aesImportKey = async (
|
|
|
335
335
|
|
|
336
336
|
switch (format) {
|
|
337
337
|
case 'raw': {
|
|
338
|
-
const data = keyData as BufferLike;
|
|
338
|
+
const data = bufferLikeToArrayBuffer(keyData as BufferLike);
|
|
339
339
|
validateKeyLength(data.byteLength * 8);
|
|
340
|
-
keyObject = createSecretKey(
|
|
340
|
+
keyObject = createSecretKey(data);
|
|
341
341
|
break;
|
|
342
342
|
}
|
|
343
343
|
case 'jwk': {
|
|
@@ -365,7 +365,7 @@ export const aesImportKey = async (
|
|
|
365
365
|
) {
|
|
366
366
|
throw lazyDOMException(
|
|
367
367
|
'JWK "ext" Parameter and extractable mismatch',
|
|
368
|
-
'DataError'
|
|
368
|
+
'DataError',
|
|
369
369
|
);
|
|
370
370
|
}
|
|
371
371
|
|
|
@@ -379,7 +379,7 @@ export const aesImportKey = async (
|
|
|
379
379
|
if (data.alg !== getAlgorithmName(algorithm.name, length))
|
|
380
380
|
throw lazyDOMException(
|
|
381
381
|
'JWK "alg" does not match the requested algorithm',
|
|
382
|
-
'DataError'
|
|
382
|
+
'DataError',
|
|
383
383
|
);
|
|
384
384
|
}
|
|
385
385
|
|
|
@@ -389,7 +389,7 @@ export const aesImportKey = async (
|
|
|
389
389
|
default:
|
|
390
390
|
throw lazyDOMException(
|
|
391
391
|
`Unable to import AES key with format ${format}`,
|
|
392
|
-
'NotSupportedError'
|
|
392
|
+
'NotSupportedError',
|
|
393
393
|
);
|
|
394
394
|
}
|
|
395
395
|
|
package/src/ec.ts
CHANGED
|
@@ -80,7 +80,7 @@ import type { KeyObjectHandle } from './NativeQuickCrypto/webcrypto';
|
|
|
80
80
|
function verifyAcceptableEcKeyUse(
|
|
81
81
|
name: AnyAlgorithm,
|
|
82
82
|
isPublic: boolean,
|
|
83
|
-
usages: KeyUsage[]
|
|
83
|
+
usages: KeyUsage[],
|
|
84
84
|
): void {
|
|
85
85
|
let checkSet;
|
|
86
86
|
switch (name) {
|
|
@@ -93,20 +93,20 @@ function verifyAcceptableEcKeyUse(
|
|
|
93
93
|
default:
|
|
94
94
|
throw lazyDOMException(
|
|
95
95
|
'The algorithm is not supported',
|
|
96
|
-
'NotSupportedError'
|
|
96
|
+
'NotSupportedError',
|
|
97
97
|
);
|
|
98
98
|
}
|
|
99
99
|
if (hasAnyNotIn(usages, checkSet)) {
|
|
100
100
|
throw lazyDOMException(
|
|
101
101
|
`Unsupported key usage for a ${name} key`,
|
|
102
|
-
'SyntaxError'
|
|
102
|
+
'SyntaxError',
|
|
103
103
|
);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
function createECPublicKeyRaw(
|
|
108
108
|
namedCurve: NamedCurve | undefined,
|
|
109
|
-
keyData: ArrayBuffer
|
|
109
|
+
keyData: ArrayBuffer,
|
|
110
110
|
): PublicKeyObject {
|
|
111
111
|
if (!namedCurve) {
|
|
112
112
|
throw new Error('Invalid namedCurve');
|
|
@@ -122,7 +122,7 @@ function createECPublicKeyRaw(
|
|
|
122
122
|
|
|
123
123
|
export function ecExportKey(
|
|
124
124
|
key: CryptoKey,
|
|
125
|
-
format: KWebCryptoKeyFormat
|
|
125
|
+
format: KWebCryptoKeyFormat,
|
|
126
126
|
): ArrayBuffer {
|
|
127
127
|
return NativeQuickCrypto.webcrypto.ecExportKey(format, key.keyObject.handle);
|
|
128
128
|
}
|
|
@@ -132,7 +132,7 @@ export function ecImportKey(
|
|
|
132
132
|
keyData: BufferLike | BinaryLike | JWK,
|
|
133
133
|
algorithm: SubtleAlgorithm,
|
|
134
134
|
extractable: boolean,
|
|
135
|
-
keyUsages: KeyUsage[]
|
|
135
|
+
keyUsages: KeyUsage[],
|
|
136
136
|
): CryptoKey {
|
|
137
137
|
const { name, namedCurve } = algorithm;
|
|
138
138
|
|
|
@@ -178,7 +178,7 @@ export function ecImportKey(
|
|
|
178
178
|
if (data.crv !== namedCurve)
|
|
179
179
|
throw lazyDOMException(
|
|
180
180
|
'JWK "crv" does not match the requested algorithm',
|
|
181
|
-
'DataError'
|
|
181
|
+
'DataError',
|
|
182
182
|
);
|
|
183
183
|
|
|
184
184
|
verifyAcceptableEcKeyUse(name, data.d === undefined, keyUsages);
|
|
@@ -198,7 +198,7 @@ export function ecImportKey(
|
|
|
198
198
|
) {
|
|
199
199
|
throw lazyDOMException(
|
|
200
200
|
'JWK "ext" Parameter and extractable mismatch',
|
|
201
|
-
'DataError'
|
|
201
|
+
'DataError',
|
|
202
202
|
);
|
|
203
203
|
}
|
|
204
204
|
|
|
@@ -218,7 +218,7 @@ export function ecImportKey(
|
|
|
218
218
|
if (algNamedCurve !== namedCurve)
|
|
219
219
|
throw lazyDOMException(
|
|
220
220
|
'JWK "alg" does not match the requested algorithm',
|
|
221
|
-
'DataError'
|
|
221
|
+
'DataError',
|
|
222
222
|
);
|
|
223
223
|
}
|
|
224
224
|
|
|
@@ -235,7 +235,7 @@ export function ecImportKey(
|
|
|
235
235
|
case 'raw': {
|
|
236
236
|
const data = keyData as BufferLike | BinaryLike;
|
|
237
237
|
verifyAcceptableEcKeyUse(name, true, keyUsages);
|
|
238
|
-
|
|
238
|
+
const buffer =
|
|
239
239
|
typeof data === 'string'
|
|
240
240
|
? binaryLikeToArrayBuffer(data)
|
|
241
241
|
: bufferLikeToArrayBuffer(data);
|
|
@@ -271,7 +271,7 @@ export const ecdsaSignVerify = (
|
|
|
271
271
|
key: CryptoKey,
|
|
272
272
|
data: BufferLike,
|
|
273
273
|
{ hash }: SubtleAlgorithm,
|
|
274
|
-
signature?: BufferLike
|
|
274
|
+
signature?: BufferLike,
|
|
275
275
|
) => {
|
|
276
276
|
const mode: SignMode =
|
|
277
277
|
signature === undefined
|
|
@@ -296,32 +296,31 @@ export const ecdsaSignVerify = (
|
|
|
296
296
|
undefined, // salt length, not used with ECDSA
|
|
297
297
|
undefined, // pss padding, not used with ECDSA
|
|
298
298
|
DSASigEnc.kSigEncP1363,
|
|
299
|
-
bufferLikeToArrayBuffer(signature || new ArrayBuffer(0))
|
|
299
|
+
bufferLikeToArrayBuffer(signature || new ArrayBuffer(0)),
|
|
300
300
|
);
|
|
301
301
|
};
|
|
302
302
|
|
|
303
303
|
export const ecGenerateKey = async (
|
|
304
304
|
algorithm: SubtleAlgorithm,
|
|
305
305
|
extractable: boolean,
|
|
306
|
-
keyUsages: KeyUsage[]
|
|
306
|
+
keyUsages: KeyUsage[],
|
|
307
307
|
): Promise<CryptoKeyPair> => {
|
|
308
308
|
const { name, namedCurve } = algorithm;
|
|
309
309
|
|
|
310
310
|
if (!Object.keys(kNamedCurveAliases).includes(namedCurve || '')) {
|
|
311
311
|
throw lazyDOMException(
|
|
312
312
|
`Unrecognized namedCurve '${namedCurve}'`,
|
|
313
|
-
'NotSupportedError'
|
|
313
|
+
'NotSupportedError',
|
|
314
314
|
);
|
|
315
315
|
}
|
|
316
316
|
|
|
317
317
|
// const usageSet = new SafeSet(keyUsages);
|
|
318
318
|
switch (name) {
|
|
319
319
|
case 'ECDSA':
|
|
320
|
-
|
|
321
|
-
if (hasAnyNotIn(keyUsages, checkUsages)) {
|
|
320
|
+
if (hasAnyNotIn(keyUsages, ['sign', 'verify'])) {
|
|
322
321
|
throw lazyDOMException(
|
|
323
322
|
'Unsupported key usage for an ECDSA key',
|
|
324
|
-
'SyntaxError'
|
|
323
|
+
'SyntaxError',
|
|
325
324
|
);
|
|
326
325
|
}
|
|
327
326
|
break;
|
|
@@ -329,7 +328,7 @@ export const ecGenerateKey = async (
|
|
|
329
328
|
if (hasAnyNotIn(keyUsages, ['deriveKey', 'deriveBits'])) {
|
|
330
329
|
throw lazyDOMException(
|
|
331
330
|
'Unsupported key usage for an ECDH key',
|
|
332
|
-
'SyntaxError'
|
|
331
|
+
'SyntaxError',
|
|
333
332
|
);
|
|
334
333
|
}
|
|
335
334
|
// Fall through
|
|
@@ -368,7 +367,7 @@ export const ecGenerateKey = async (
|
|
|
368
367
|
priv,
|
|
369
368
|
keyAlgorithm,
|
|
370
369
|
privateUsages,
|
|
371
|
-
extractable
|
|
370
|
+
extractable,
|
|
372
371
|
);
|
|
373
372
|
|
|
374
373
|
return { publicKey, privateKey };
|
package/src/keygen.ts
CHANGED
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
|
|
10
10
|
export type KeyGenCallback = (
|
|
11
11
|
err: Error | undefined,
|
|
12
|
-
key?: SecretKeyObject
|
|
12
|
+
key?: SecretKeyObject,
|
|
13
13
|
) => void;
|
|
14
14
|
|
|
15
15
|
export const generateKeyPromise = (
|
|
16
16
|
type: SecretKeyType,
|
|
17
|
-
options: AesKeyGenParams // | HmacKeyGenParams
|
|
17
|
+
options: AesKeyGenParams, // | HmacKeyGenParams
|
|
18
18
|
): Promise<[Error | undefined, SecretKeyObject | undefined]> => {
|
|
19
19
|
return new Promise((resolve, reject) => {
|
|
20
20
|
generateKey(type, options, (err, key) => {
|
|
@@ -29,7 +29,7 @@ export const generateKeyPromise = (
|
|
|
29
29
|
export const generateKey = (
|
|
30
30
|
type: SecretKeyType,
|
|
31
31
|
options: AesKeyGenParams, // | HmacKeyGenParams,
|
|
32
|
-
callback: KeyGenCallback
|
|
32
|
+
callback: KeyGenCallback,
|
|
33
33
|
): void => {
|
|
34
34
|
validateLength(type, options.length);
|
|
35
35
|
if (!validateFunction(callback)) {
|
|
@@ -47,11 +47,11 @@ export const generateKey = (
|
|
|
47
47
|
|
|
48
48
|
export const generateKeySync = (
|
|
49
49
|
type: SecretKeyType,
|
|
50
|
-
options: AesKeyGenParams // | HmacKeyGenParams,
|
|
50
|
+
options: AesKeyGenParams, // | HmacKeyGenParams,
|
|
51
51
|
): SecretKeyObject => {
|
|
52
52
|
validateLength(type, options.length);
|
|
53
53
|
const handle = NativeQuickCrypto.webcrypto.generateSecretKeySync(
|
|
54
|
-
options.length
|
|
54
|
+
options.length,
|
|
55
55
|
);
|
|
56
56
|
return new SecretKeyObject(handle);
|
|
57
57
|
};
|
|
@@ -62,7 +62,7 @@ const validateLength = (type: SecretKeyType, length: number) => {
|
|
|
62
62
|
if (!kAesKeyLengths.includes(length)) {
|
|
63
63
|
throw lazyDOMException(
|
|
64
64
|
'AES key length must be 128, 192, or 256 bits',
|
|
65
|
-
'OperationError'
|
|
65
|
+
'OperationError',
|
|
66
66
|
);
|
|
67
67
|
}
|
|
68
68
|
break;
|
|
@@ -70,7 +70,7 @@ const validateLength = (type: SecretKeyType, length: number) => {
|
|
|
70
70
|
if (length < 8 || length > 2 ** 31 - 1) {
|
|
71
71
|
throw lazyDOMException(
|
|
72
72
|
'HMAC key length must be between 8 and 2^31 - 1',
|
|
73
|
-
'OperationError'
|
|
73
|
+
'OperationError',
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
76
|
break;
|