react-native-quick-crypto 0.7.2 → 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.
Files changed (202) hide show
  1. package/README.md +13 -46
  2. package/cpp/Cipher/MGLPublicCipher.h +5 -1
  3. package/cpp/Cipher/MGLPublicCipherInstaller.h +1 -1
  4. package/cpp/MGLQuickCryptoHostObject.cpp +8 -5
  5. package/lib/commonjs/Cipher.js +113 -111
  6. package/lib/commonjs/Cipher.js.map +1 -1
  7. package/lib/commonjs/Hash.js +8 -5
  8. package/lib/commonjs/Hash.js.map +1 -1
  9. package/lib/commonjs/Hashnames.js +4 -1
  10. package/lib/commonjs/Hashnames.js.map +1 -1
  11. package/lib/commonjs/Hmac.js +5 -3
  12. package/lib/commonjs/Hmac.js.map +1 -1
  13. package/lib/commonjs/NativeQuickCrypto/Cipher.js +7 -7
  14. package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +1 -1
  15. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +11 -4
  16. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
  17. package/lib/commonjs/NativeQuickCrypto/sig.js.map +1 -1
  18. package/lib/commonjs/Utils.js +98 -63
  19. package/lib/commonjs/Utils.js.map +1 -1
  20. package/lib/commonjs/aes.js +9 -8
  21. package/lib/commonjs/aes.js.map +1 -1
  22. package/lib/commonjs/ec.js +2 -3
  23. package/lib/commonjs/ec.js.map +1 -1
  24. package/lib/commonjs/index.js +1 -1
  25. package/lib/commonjs/index.js.map +1 -1
  26. package/lib/commonjs/keygen.js +4 -2
  27. package/lib/commonjs/keygen.js.map +1 -1
  28. package/lib/commonjs/keys.js +7 -2
  29. package/lib/commonjs/keys.js.map +1 -1
  30. package/lib/commonjs/package.json +1 -0
  31. package/lib/commonjs/pbkdf2.js +13 -21
  32. package/lib/commonjs/pbkdf2.js.map +1 -1
  33. package/lib/commonjs/random.js +6 -8
  34. package/lib/commonjs/random.js.map +1 -1
  35. package/lib/commonjs/rsa.js.map +1 -1
  36. package/lib/commonjs/sig.js +1 -2
  37. package/lib/commonjs/sig.js.map +1 -1
  38. package/lib/commonjs/subtle.js +4 -3
  39. package/lib/commonjs/subtle.js.map +1 -1
  40. package/lib/module/Cipher.js +114 -110
  41. package/lib/module/Cipher.js.map +1 -1
  42. package/lib/module/Hash.js +9 -4
  43. package/lib/module/Hash.js.map +1 -1
  44. package/lib/module/Hashnames.js +6 -1
  45. package/lib/module/Hashnames.js.map +1 -1
  46. package/lib/module/Hmac.js +6 -2
  47. package/lib/module/Hmac.js.map +1 -1
  48. package/lib/module/NativeQuickCrypto/Cipher.js +9 -7
  49. package/lib/module/NativeQuickCrypto/Cipher.js.map +1 -1
  50. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +13 -4
  51. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
  52. package/lib/module/NativeQuickCrypto/aes.js +2 -0
  53. package/lib/module/NativeQuickCrypto/hash.js +1 -1
  54. package/lib/module/NativeQuickCrypto/hmac.js +1 -1
  55. package/lib/module/NativeQuickCrypto/keygen.js +2 -0
  56. package/lib/module/NativeQuickCrypto/pbkdf2.js +1 -1
  57. package/lib/module/NativeQuickCrypto/random.js +1 -1
  58. package/lib/module/NativeQuickCrypto/rsa.js +2 -0
  59. package/lib/module/NativeQuickCrypto/sig.js +2 -0
  60. package/lib/module/NativeQuickCrypto/sig.js.map +1 -1
  61. package/lib/module/NativeQuickCrypto/webcrypto.js +2 -0
  62. package/lib/module/Utils.js +97 -62
  63. package/lib/module/Utils.js.map +1 -1
  64. package/lib/module/aes.js +11 -8
  65. package/lib/module/aes.js.map +1 -1
  66. package/lib/module/constants.js +2 -0
  67. package/lib/module/constants.js.map +1 -1
  68. package/lib/module/ec.js +4 -3
  69. package/lib/module/ec.js.map +1 -1
  70. package/lib/module/index.js +2 -0
  71. package/lib/module/index.js.map +1 -1
  72. package/lib/module/keygen.js +6 -2
  73. package/lib/module/keygen.js.map +1 -1
  74. package/lib/module/keys.js +9 -2
  75. package/lib/module/keys.js.map +1 -1
  76. package/lib/module/package.json +1 -0
  77. package/lib/module/pbkdf2.js +15 -21
  78. package/lib/module/pbkdf2.js.map +1 -1
  79. package/lib/module/random.js +8 -8
  80. package/lib/module/random.js.map +1 -1
  81. package/lib/module/rsa.js +2 -0
  82. package/lib/module/rsa.js.map +1 -1
  83. package/lib/module/sig.js +2 -1
  84. package/lib/module/sig.js.map +1 -1
  85. package/lib/module/subtle.js +6 -3
  86. package/lib/module/subtle.js.map +1 -1
  87. package/lib/module/webcrypto.js +2 -0
  88. package/lib/module/webcrypto.js.map +1 -1
  89. package/lib/typescript/{Cipher.d.ts → src/Cipher.d.ts} +37 -33
  90. package/lib/typescript/src/Cipher.d.ts.map +1 -0
  91. package/lib/typescript/src/Hash.d.ts.map +1 -0
  92. package/lib/typescript/src/Hashnames.d.ts.map +1 -0
  93. package/lib/typescript/src/Hmac.d.ts.map +1 -0
  94. package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/Cipher.d.ts +5 -5
  95. package/lib/typescript/src/NativeQuickCrypto/Cipher.d.ts.map +1 -0
  96. package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/NativeQuickCrypto.d.ts +1 -1
  97. package/lib/typescript/src/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +1 -0
  98. package/lib/typescript/src/NativeQuickCrypto/aes.d.ts.map +1 -0
  99. package/lib/typescript/src/NativeQuickCrypto/hash.d.ts.map +1 -0
  100. package/lib/typescript/src/NativeQuickCrypto/hmac.d.ts.map +1 -0
  101. package/lib/typescript/src/NativeQuickCrypto/keygen.d.ts.map +1 -0
  102. package/lib/typescript/src/NativeQuickCrypto/pbkdf2.d.ts.map +1 -0
  103. package/lib/typescript/src/NativeQuickCrypto/random.d.ts.map +1 -0
  104. package/lib/typescript/src/NativeQuickCrypto/rsa.d.ts.map +1 -0
  105. package/lib/typescript/src/NativeQuickCrypto/sig.d.ts.map +1 -0
  106. package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/webcrypto.d.ts +1 -1
  107. package/lib/typescript/src/NativeQuickCrypto/webcrypto.d.ts.map +1 -0
  108. package/lib/typescript/{Utils.d.ts → src/Utils.d.ts} +18 -8
  109. package/lib/typescript/src/Utils.d.ts.map +1 -0
  110. package/lib/typescript/src/aes.d.ts.map +1 -0
  111. package/lib/typescript/src/constants.d.ts.map +1 -0
  112. package/lib/typescript/src/ec.d.ts.map +1 -0
  113. package/lib/typescript/{index.d.ts → src/index.d.ts} +5 -30
  114. package/lib/typescript/src/index.d.ts.map +1 -0
  115. package/lib/typescript/src/keygen.d.ts.map +1 -0
  116. package/lib/typescript/{keys.d.ts → src/keys.d.ts} +27 -25
  117. package/lib/typescript/src/keys.d.ts.map +1 -0
  118. package/lib/typescript/{pbkdf2.d.ts → src/pbkdf2.d.ts} +3 -4
  119. package/lib/typescript/src/pbkdf2.d.ts.map +1 -0
  120. package/lib/typescript/{random.d.ts → src/random.d.ts} +5 -5
  121. package/lib/typescript/src/random.d.ts.map +1 -0
  122. package/lib/typescript/src/rsa.d.ts.map +1 -0
  123. package/lib/typescript/{sig.d.ts → src/sig.d.ts} +5 -5
  124. package/lib/typescript/src/sig.d.ts.map +1 -0
  125. package/lib/typescript/src/subtle.d.ts.map +1 -0
  126. package/lib/typescript/src/webcrypto.d.ts.map +1 -0
  127. package/package.json +23 -46
  128. package/src/Cipher.ts +270 -212
  129. package/src/Hash.ts +14 -7
  130. package/src/Hashnames.ts +5 -2
  131. package/src/Hmac.ts +6 -5
  132. package/src/NativeQuickCrypto/Cipher.ts +21 -20
  133. package/src/NativeQuickCrypto/NativeQuickCrypto.ts +15 -11
  134. package/src/NativeQuickCrypto/aes.ts +1 -1
  135. package/src/NativeQuickCrypto/hash.ts +1 -1
  136. package/src/NativeQuickCrypto/hmac.ts +1 -1
  137. package/src/NativeQuickCrypto/keygen.ts +1 -1
  138. package/src/NativeQuickCrypto/pbkdf2.ts +2 -2
  139. package/src/NativeQuickCrypto/random.ts +2 -2
  140. package/src/NativeQuickCrypto/rsa.ts +1 -1
  141. package/src/NativeQuickCrypto/sig.ts +3 -1
  142. package/src/NativeQuickCrypto/webcrypto.ts +5 -5
  143. package/src/Utils.ts +175 -108
  144. package/src/aes.ts +29 -29
  145. package/src/ec.ts +18 -19
  146. package/src/keygen.ts +7 -7
  147. package/src/keys.ts +71 -65
  148. package/src/pbkdf2.ts +24 -48
  149. package/src/random.ts +37 -43
  150. package/src/rsa.ts +25 -23
  151. package/src/sig.ts +12 -13
  152. package/src/subtle.ts +50 -45
  153. package/ios/QuickCrypto.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  154. package/ios/QuickCrypto.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  155. package/ios/QuickCrypto.xcodeproj/project.xcworkspace/xcuserdata/brad.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  156. package/ios/QuickCrypto.xcodeproj/xcuserdata/brad.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  157. package/lib/typescript/Cipher.d.ts.map +0 -1
  158. package/lib/typescript/Hash.d.ts.map +0 -1
  159. package/lib/typescript/Hashnames.d.ts.map +0 -1
  160. package/lib/typescript/Hmac.d.ts.map +0 -1
  161. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts.map +0 -1
  162. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +0 -1
  163. package/lib/typescript/NativeQuickCrypto/aes.d.ts.map +0 -1
  164. package/lib/typescript/NativeQuickCrypto/hash.d.ts.map +0 -1
  165. package/lib/typescript/NativeQuickCrypto/hmac.d.ts.map +0 -1
  166. package/lib/typescript/NativeQuickCrypto/keygen.d.ts.map +0 -1
  167. package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts.map +0 -1
  168. package/lib/typescript/NativeQuickCrypto/random.d.ts.map +0 -1
  169. package/lib/typescript/NativeQuickCrypto/rsa.d.ts.map +0 -1
  170. package/lib/typescript/NativeQuickCrypto/sig.d.ts.map +0 -1
  171. package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts.map +0 -1
  172. package/lib/typescript/Utils.d.ts.map +0 -1
  173. package/lib/typescript/aes.d.ts.map +0 -1
  174. package/lib/typescript/constants.d.ts.map +0 -1
  175. package/lib/typescript/ec.d.ts.map +0 -1
  176. package/lib/typescript/index.d.ts.map +0 -1
  177. package/lib/typescript/keygen.d.ts.map +0 -1
  178. package/lib/typescript/keys.d.ts.map +0 -1
  179. package/lib/typescript/pbkdf2.d.ts.map +0 -1
  180. package/lib/typescript/random.d.ts.map +0 -1
  181. package/lib/typescript/rsa.d.ts.map +0 -1
  182. package/lib/typescript/sig.d.ts.map +0 -1
  183. package/lib/typescript/subtle.d.ts.map +0 -1
  184. package/lib/typescript/webcrypto.d.ts.map +0 -1
  185. /package/lib/typescript/{Hash.d.ts → src/Hash.d.ts} +0 -0
  186. /package/lib/typescript/{Hashnames.d.ts → src/Hashnames.d.ts} +0 -0
  187. /package/lib/typescript/{Hmac.d.ts → src/Hmac.d.ts} +0 -0
  188. /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/aes.d.ts +0 -0
  189. /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/hash.d.ts +0 -0
  190. /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/hmac.d.ts +0 -0
  191. /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/keygen.d.ts +0 -0
  192. /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/pbkdf2.d.ts +0 -0
  193. /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/random.d.ts +0 -0
  194. /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/rsa.d.ts +0 -0
  195. /package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/sig.d.ts +0 -0
  196. /package/lib/typescript/{aes.d.ts → src/aes.d.ts} +0 -0
  197. /package/lib/typescript/{constants.d.ts → src/constants.d.ts} +0 -0
  198. /package/lib/typescript/{ec.d.ts → src/ec.d.ts} +0 -0
  199. /package/lib/typescript/{keygen.d.ts → src/keygen.d.ts} +0 -0
  200. /package/lib/typescript/{rsa.d.ts → src/rsa.d.ts} +0 -0
  201. /package/lib/typescript/{subtle.d.ts → src/subtle.d.ts} +0 -0
  202. /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-ignore
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-ignore
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-ignore
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-ignore
120
+ // @ts-expect-error unreachable code
121
121
  break;
122
122
  }
123
123
 
124
- // @ts-ignore
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(keyData);
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
- let buffer =
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
- const checkUsages = ['sign', 'verify'];
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;