react-native-quick-crypto 0.7.3 → 0.7.5
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 +114 -112
- 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 +7 -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 +113 -111
- 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 +7 -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/{Hashnames.d.ts → src/Hashnames.d.ts} +2 -2
- 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 +3 -2
- 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} +9 -34
- 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} +30 -28
- 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 +272 -214
- package/src/Hash.ts +14 -7
- package/src/Hashnames.ts +10 -4
- 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 +6 -5
- package/src/Utils.ts +181 -108
- package/src/aes.ts +29 -29
- package/src/ec.ts +18 -19
- package/src/keygen.ts +7 -7
- package/src/keys.ts +73 -67
- 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/{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/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
|
|
8
|
+
type RandomBuffer = TypedArray | DataView | ArrayBufferLike | Buffer;
|
|
8
9
|
|
|
9
|
-
export function randomFill<T extends
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
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,
|
|
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
|
|
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(
|
|
76
|
-
|
|
77
|
-
|
|
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
|
|
94
|
+
randomFillSync(buf, 0, size);
|
|
99
95
|
return buf;
|
|
100
96
|
}
|
|
101
97
|
|
|
102
|
-
randomFill(buf
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
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:
|
|
26
|
+
function getPadding(options: EncodingOptions) {
|
|
27
27
|
return getIntOption('padding', options);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
function getSaltLength(options:
|
|
30
|
+
function getSaltLength(options: EncodingOptions) {
|
|
31
31
|
return getIntOption('saltLength', options);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function getDSASignatureEncoding(options:
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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?:
|
|
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?:
|
|
161
|
+
export function createVerify(algorithm: string, options?: WritableOptions) {
|
|
163
162
|
return new Verify(algorithm, options);
|
|
164
163
|
}
|