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/random.ts CHANGED
@@ -1,105 +1,101 @@
1
+ import { abvToArrayBuffer } from './Utils';
1
2
  import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
2
3
  import { Buffer } from '@craftzdog/react-native-buffer';
3
4
  import type { TypedArray } from './Utils';
4
5
 
5
6
  const random = NativeQuickCrypto.random;
6
7
 
7
- type ArrayBufferView = TypedArray | DataView | ArrayBufferLike | Buffer;
8
+ type RandomBuffer = TypedArray | DataView | ArrayBufferLike | Buffer;
8
9
 
9
- export function randomFill<T extends ArrayBufferView>(
10
+ export function randomFill<T extends RandomBuffer>(
10
11
  buffer: T,
11
- callback: (err: Error | null, buf: T) => void
12
+ callback: (err: Error | null, buf: T) => void,
12
13
  ): void;
13
14
 
14
- export function randomFill<T extends ArrayBufferView>(
15
+ export function randomFill<T extends RandomBuffer>(
15
16
  buffer: T,
16
17
  offset: number,
17
- callback: (err: Error | null, buf: T) => void
18
+ callback: (err: Error | null, buf: T) => void,
18
19
  ): void;
19
20
 
20
- export function randomFill<T extends ArrayBufferView>(
21
+ export function randomFill<T extends RandomBuffer>(
21
22
  buffer: T,
22
23
  offset: number,
23
24
  size: number,
24
- callback: (err: Error | null, buf: T) => void
25
+ callback: (err: Error | null, buf: T) => void,
25
26
  ): void;
26
27
 
27
- export function randomFill(buffer: any, ...rest: any[]): void {
28
+ export function randomFill(buffer: RandomBuffer, ...rest: unknown[]): void {
28
29
  if (typeof rest[rest.length - 1] !== 'function') {
29
30
  throw new Error('No callback provided to randomFill');
30
31
  }
31
32
 
32
- const callback = rest[rest.length - 1] as any as (
33
+ const callback = rest[rest.length - 1] as unknown as (
33
34
  err: Error | null,
34
- buf?: ArrayBuffer
35
+ buf?: ArrayBuffer,
35
36
  ) => void;
36
37
 
37
38
  let offset: number = 0;
38
39
  let size: number = buffer.byteLength;
39
40
 
40
41
  if (typeof rest[2] === 'function') {
41
- offset = rest[0];
42
- size = rest[1];
42
+ offset = rest[0] as number;
43
+ size = rest[1] as number;
43
44
  }
44
45
 
45
46
  if (typeof rest[1] === 'function') {
46
- offset = rest[0];
47
+ offset = rest[0] as number;
47
48
  }
48
49
 
49
50
  random
50
- .randomFill(
51
- Buffer.isBuffer(buffer)
52
- ? buffer.buffer
53
- : ArrayBuffer.isView(buffer)
54
- ? buffer.buffer
55
- : buffer,
56
- offset,
57
- size
58
- )
51
+ .randomFill(abvToArrayBuffer(buffer as ArrayBufferView), offset, size)
59
52
  .then(
60
- () => {
61
- callback(null, buffer);
53
+ (res: ArrayBuffer) => {
54
+ callback(null, res);
62
55
  },
63
56
  (e: Error) => {
64
57
  callback(e);
65
- }
58
+ },
66
59
  );
67
60
  }
68
61
 
69
- export function randomFillSync<T extends ArrayBufferView>(
62
+ export function randomFillSync<T extends RandomBuffer>(
70
63
  buffer: T,
71
64
  offset?: number,
72
- size?: number
65
+ size?: number,
73
66
  ): T;
74
67
 
75
- export function randomFillSync(buffer: any, offset: number = 0, size?: number) {
76
- random.randomFillSync(
77
- buffer.buffer ? buffer.buffer : buffer,
68
+ export function randomFillSync(
69
+ buffer: RandomBuffer,
70
+ offset: number = 0,
71
+ size?: number,
72
+ ) {
73
+ return random.randomFillSync(
74
+ abvToArrayBuffer(buffer as ArrayBufferView),
78
75
  offset,
79
- size ?? buffer.byteLength
76
+ size ?? buffer.byteLength,
80
77
  );
81
- return buffer;
82
78
  }
83
79
 
84
80
  export function randomBytes(size: number): Buffer;
85
81
 
86
82
  export function randomBytes(
87
83
  size: number,
88
- callback: (err: Error | null, buf?: Buffer) => void
84
+ callback: (err: Error | null, buf?: Buffer) => void,
89
85
  ): void;
90
86
 
91
87
  export function randomBytes(
92
88
  size: number,
93
- callback?: (err: Error | null, buf?: Buffer) => void
89
+ callback?: (err: Error | null, buf?: Buffer) => void,
94
90
  ): void | Buffer {
95
91
  const buf = new Buffer(size);
96
92
 
97
93
  if (callback === undefined) {
98
- randomFillSync(buf.buffer, 0, size);
94
+ randomFillSync(buf, 0, size);
99
95
  return buf;
100
96
  }
101
97
 
102
- randomFill(buf.buffer, 0, size, (error: Error | null) => {
98
+ randomFill(buf, 0, size, (error: Error | null) => {
103
99
  if (error) {
104
100
  callback(error);
105
101
  }
@@ -139,13 +135,13 @@ export function randomInt(max: number): number;
139
135
  export function randomInt(
140
136
  min: number,
141
137
  max: number,
142
- callback: RandomIntCallback
138
+ callback: RandomIntCallback,
143
139
  ): void;
144
140
  export function randomInt(min: number, max: number): number;
145
141
  export function randomInt(
146
142
  arg1: number,
147
143
  arg2?: number | RandomIntCallback,
148
- callback?: RandomIntCallback
144
+ callback?: RandomIntCallback,
149
145
  ): void | number {
150
146
  // Detect optional min syntax
151
147
  // randomInt(max)
@@ -156,12 +152,12 @@ export function randomInt(
156
152
  typeof arg2 === 'undefined' || typeof arg2 === 'function';
157
153
 
158
154
  if (minNotSpecified) {
159
- callback = arg2 as any as undefined | RandomIntCallback;
155
+ callback = arg2 as undefined | RandomIntCallback;
160
156
  max = arg1;
161
157
  min = 0;
162
158
  } else {
163
159
  min = arg1;
164
- max = arg2 as any as number;
160
+ max = arg2 as number;
165
161
  }
166
162
  if (typeof callback !== 'undefined' && typeof callback !== 'function') {
167
163
  throw new TypeError('callback must be a function or undefined');
@@ -217,7 +213,7 @@ export function randomInt(
217
213
  if (x < randLimit) {
218
214
  const n = (x % range) + min;
219
215
  if (isSync) return n;
220
- process.nextTick(callback as Function, undefined, n);
216
+ process.nextTick(callback as RandomIntCallback, undefined, n);
221
217
  return;
222
218
  }
223
219
  }
@@ -289,9 +285,7 @@ export function randomUUID() {
289
285
  randomFillSync(buffer, 0, size);
290
286
 
291
287
  // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
292
- // eslint-disable-next-line no-bitwise
293
288
  buffer[6] = (buffer[6]! & 0x0f) | 0x40;
294
- // eslint-disable-next-line no-bitwise
295
289
  buffer[8] = (buffer[8]! & 0x3f) | 0x80;
296
290
 
297
291
  return (
package/src/rsa.ts CHANGED
@@ -43,7 +43,7 @@ export enum RSAKeyVariant {
43
43
  function verifyAcceptableRsaKeyUse(
44
44
  name: AnyAlgorithm,
45
45
  isPublic: boolean,
46
- usages: KeyUsage[]
46
+ usages: KeyUsage[],
47
47
  ): void {
48
48
  let checkSet;
49
49
  switch (name) {
@@ -58,13 +58,13 @@ function verifyAcceptableRsaKeyUse(
58
58
  default:
59
59
  throw lazyDOMException(
60
60
  'The algorithm is not supported',
61
- 'NotSupportedError'
61
+ 'NotSupportedError',
62
62
  );
63
63
  }
64
64
  if (hasAnyNotIn(usages, checkSet)) {
65
65
  throw lazyDOMException(
66
66
  `Unsupported key usage for an ${name} key`,
67
- 'SyntaxError'
67
+ 'SyntaxError',
68
68
  );
69
69
  }
70
70
  }
@@ -73,14 +73,14 @@ const rsaOaepCipher = (
73
73
  mode: CipherOrWrapMode,
74
74
  key: CryptoKey,
75
75
  data: ArrayBuffer,
76
- { label }: RsaOaepParams
76
+ { label }: RsaOaepParams,
77
77
  ): Promise<ArrayBuffer> => {
78
78
  const type =
79
79
  mode === CipherOrWrapMode.kWebCryptoCipherEncrypt ? 'public' : 'private';
80
80
  if (key.type !== type) {
81
81
  throw lazyDOMException(
82
82
  'The requested operation is not valid for the provided key',
83
- 'InvalidAccessError'
83
+ 'InvalidAccessError',
84
84
  );
85
85
  }
86
86
  if (label !== undefined) {
@@ -93,7 +93,7 @@ const rsaOaepCipher = (
93
93
  data,
94
94
  RSAKeyVariant.RSA_OAEP,
95
95
  normalizeHashName(key.algorithm.hash) as DigestAlgorithm,
96
- label !== undefined ? bufferLikeToArrayBuffer(label) : undefined
96
+ label !== undefined ? bufferLikeToArrayBuffer(label) : undefined,
97
97
  );
98
98
  };
99
99
 
@@ -102,17 +102,19 @@ export const rsaCipher = rsaOaepCipher;
102
102
  export const rsaKeyGenerate = async (
103
103
  algorithm: SubtleAlgorithm,
104
104
  extractable: boolean,
105
- keyUsages: KeyUsage[]
105
+ keyUsages: KeyUsage[],
106
106
  ): Promise<CryptoKeyPair> => {
107
107
  const { name, modulusLength, publicExponent, hash: rawHash } = algorithm;
108
108
  const hash: HashAlgorithm = normalizeHashName(rawHash);
109
109
 
110
110
  // const usageSet = new SafeSet(keyUsages);
111
- const publicExponentConverted = bigIntArrayToUnsignedInt(publicExponent);
111
+ const publicExponentConverted = bigIntArrayToUnsignedInt(
112
+ publicExponent as Uint8Array,
113
+ );
112
114
  if (publicExponentConverted === undefined) {
113
115
  throw lazyDOMException(
114
116
  'The publicExponent must be equivalent to an unsigned 32-bit value',
115
- 'OperationError'
117
+ 'OperationError',
116
118
  );
117
119
  }
118
120
 
@@ -123,7 +125,7 @@ export const rsaKeyGenerate = async (
123
125
  ) {
124
126
  throw lazyDOMException(
125
127
  'Unsupported key usage for a RSA key',
126
- 'SyntaxError'
128
+ 'SyntaxError',
127
129
  );
128
130
  }
129
131
  break;
@@ -131,7 +133,7 @@ export const rsaKeyGenerate = async (
131
133
  if (hasAnyNotIn(keyUsages, ['sign', 'verify'])) {
132
134
  throw lazyDOMException(
133
135
  'Unsupported key usage for a RSA key',
134
- 'SyntaxError'
136
+ 'SyntaxError',
135
137
  );
136
138
  }
137
139
  }
@@ -143,7 +145,7 @@ export const rsaKeyGenerate = async (
143
145
  if (err) {
144
146
  throw lazyDOMException(
145
147
  'The operation failed for an operation-specific reason',
146
- { name: 'OperationError', cause: err }
148
+ { name: 'OperationError', cause: err },
147
149
  );
148
150
  }
149
151
 
@@ -177,7 +179,7 @@ export const rsaKeyGenerate = async (
177
179
  priv,
178
180
  keyAlgorithm,
179
181
  privateUsages,
180
- extractable
182
+ extractable,
181
183
  );
182
184
 
183
185
  return { publicKey, privateKey };
@@ -185,19 +187,19 @@ export const rsaKeyGenerate = async (
185
187
 
186
188
  export const rsaExportKey = (
187
189
  key: CryptoKey,
188
- format: KWebCryptoKeyFormat
190
+ format: KWebCryptoKeyFormat,
189
191
  ): ArrayBuffer => {
190
192
  const variant = KeyVariantLookup[key.algorithm.name];
191
193
  if (variant === undefined) {
192
194
  throw lazyDOMException(
193
195
  `Unrecognized algorithm name '${key.algorithm.name}'`,
194
- 'NotSupportedError'
196
+ 'NotSupportedError',
195
197
  );
196
198
  }
197
199
  return NativeQuickCrypto.webcrypto.rsaExportKey(
198
200
  format,
199
201
  key.keyObject.handle,
200
- variant
202
+ variant,
201
203
  );
202
204
  };
203
205
 
@@ -206,7 +208,7 @@ export const rsaImportKey = (
206
208
  keyData: BufferLike | JWK,
207
209
  algorithm: SubtleAlgorithm,
208
210
  extractable: boolean,
209
- keyUsages: KeyUsage[]
211
+ keyUsages: KeyUsage[],
210
212
  ): CryptoKey => {
211
213
  // const usagesSet = new SafeSet(keyUsages);
212
214
  let keyObject: PublicKeyObject | PrivateKeyObject;
@@ -254,7 +256,7 @@ export const rsaImportKey = (
254
256
  verifyAcceptableRsaKeyUse(
255
257
  algorithm.name,
256
258
  data.d === undefined,
257
- keyUsages
259
+ keyUsages,
258
260
  );
259
261
 
260
262
  if (keyUsages.length > 0 && data.use !== undefined) {
@@ -272,19 +274,19 @@ export const rsaImportKey = (
272
274
  ) {
273
275
  throw lazyDOMException(
274
276
  'JWK "ext" Parameter and extractable mismatch',
275
- 'DataError'
277
+ 'DataError',
276
278
  );
277
279
  }
278
280
 
279
281
  if (data.alg !== undefined) {
280
282
  const hash = normalizeHashName(
281
283
  data.alg as HashAlgorithm,
282
- HashContext.WebCrypto
284
+ HashContext.WebCrypto,
283
285
  );
284
286
  if (hash !== algorithm.hash)
285
287
  throw lazyDOMException(
286
288
  'JWK "alg" does not match the requested algorithm',
287
- 'DataError'
289
+ 'DataError',
288
290
  );
289
291
  }
290
292
 
@@ -303,7 +305,7 @@ export const rsaImportKey = (
303
305
  default:
304
306
  throw lazyDOMException(
305
307
  `Unable to import RSA key with format ${format}`,
306
- 'NotSupportedError'
308
+ 'NotSupportedError',
307
309
  );
308
310
  }
309
311
 
@@ -326,7 +328,7 @@ export const rsaImportKey = (
326
328
  hash: algorithm.hash,
327
329
  },
328
330
  keyUsages,
329
- extractable
331
+ extractable,
330
332
  );
331
333
  };
332
334
 
package/src/sig.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
2
2
  import type { InternalSign, InternalVerify } from './NativeQuickCrypto/sig';
3
- import Stream from 'readable-stream';
3
+ import Stream, { type WritableOptions } from 'readable-stream';
4
4
 
5
5
  // TODO(osp) same as publicCipher on node this are defined on C++ and exposed to node
6
6
  // Do the same here
@@ -23,15 +23,15 @@ import {
23
23
  const createInternalSign = NativeQuickCrypto.createSign;
24
24
  const createInternalVerify = NativeQuickCrypto.createVerify;
25
25
 
26
- function getPadding(options: any) {
26
+ function getPadding(options: EncodingOptions) {
27
27
  return getIntOption('padding', options);
28
28
  }
29
29
 
30
- function getSaltLength(options: any) {
30
+ function getSaltLength(options: EncodingOptions) {
31
31
  return getIntOption('saltLength', options);
32
32
  }
33
33
 
34
- function getDSASignatureEncoding(options: any) {
34
+ function getDSASignatureEncoding(options: EncodingOptions) {
35
35
  if (typeof options === 'object') {
36
36
  const { dsaEncoding = 'der' } = options;
37
37
  if (dsaEncoding === 'der') return DSASigEnc.kSigEncDER;
@@ -42,10 +42,9 @@ function getDSASignatureEncoding(options: any) {
42
42
  return DSASigEnc.kSigEncDER;
43
43
  }
44
44
 
45
- function getIntOption(name: string, options: any) {
45
+ function getIntOption(name: keyof EncodingOptions, options: EncodingOptions) {
46
46
  const value = options[name];
47
47
  if (value !== undefined) {
48
- // eslint-disable-next-line no-bitwise
49
48
  if (value === value >> 0) {
50
49
  return value;
51
50
  }
@@ -56,7 +55,7 @@ function getIntOption(name: string, options: any) {
56
55
 
57
56
  class Verify extends Stream.Writable {
58
57
  private internal: InternalVerify;
59
- constructor(algorithm: string, options: Stream.WritableOptions) {
58
+ constructor(algorithm: string, options?: WritableOptions) {
60
59
  super(options);
61
60
  this.internal = createInternalVerify();
62
61
  this.internal.init(algorithm);
@@ -96,7 +95,7 @@ class Verify extends Stream.Writable {
96
95
  binaryLikeToArrayBuffer(signature),
97
96
  rsaPadding,
98
97
  pssSaltLength,
99
- dsaSigEnc
98
+ dsaSigEnc,
100
99
  );
101
100
 
102
101
  return ret;
@@ -105,7 +104,7 @@ class Verify extends Stream.Writable {
105
104
 
106
105
  class Sign extends Stream.Writable {
107
106
  private internal: InternalSign;
108
- constructor(algorithm: string, options: Stream.WritableOptions) {
107
+ constructor(algorithm: string, options?: WritableOptions) {
109
108
  super(options);
110
109
  this.internal = createInternalSign();
111
110
  this.internal.init(algorithm);
@@ -143,22 +142,22 @@ class Sign extends Stream.Writable {
143
142
  passphrase,
144
143
  rsaPadding,
145
144
  pssSaltLength,
146
- dsaSigEnc
145
+ dsaSigEnc,
147
146
  );
148
147
 
149
148
  encoding = encoding || getDefaultEncoding();
150
149
  if (encoding && encoding !== 'buffer') {
151
- return Buffer.from(ret).toString(encoding as any);
150
+ return Buffer.from(ret).toString(encoding as BufferEncoding);
152
151
  }
153
152
 
154
153
  return Buffer.from(ret);
155
154
  }
156
155
  }
157
156
 
158
- export function createSign(algorithm: string, options?: any) {
157
+ export function createSign(algorithm: string, options?: WritableOptions) {
159
158
  return new Sign(algorithm, options);
160
159
  }
161
160
 
162
- export function createVerify(algorithm: string, options?: any) {
161
+ export function createVerify(algorithm: string, options?: WritableOptions) {
163
162
  return new Verify(algorithm, options);
164
163
  }