react-native-quick-crypto 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +11 -63
  2. package/android/CMakeLists.txt +2 -0
  3. package/cpp/Cipher/MGLRsa.cpp +179 -3
  4. package/cpp/Cipher/MGLRsa.h +40 -0
  5. package/cpp/JSIUtils/MGLJSIUtils.h +8 -0
  6. package/cpp/MGLKeys.cpp +41 -43
  7. package/cpp/MGLKeys.h +9 -2
  8. package/cpp/MGLQuickCryptoHostObject.cpp +6 -6
  9. package/cpp/Sig/MGLSignHostObjects.cpp +22 -15
  10. package/cpp/Utils/MGLUtils.cpp +71 -1
  11. package/cpp/Utils/MGLUtils.h +55 -1
  12. package/cpp/webcrypto/MGLWebCrypto.cpp +89 -37
  13. package/cpp/webcrypto/MGLWebCrypto.h +5 -7
  14. package/cpp/webcrypto/crypto_aes.cpp +516 -0
  15. package/cpp/webcrypto/crypto_aes.h +79 -0
  16. package/cpp/webcrypto/crypto_ec.cpp +4 -20
  17. package/cpp/webcrypto/crypto_ec.h +0 -5
  18. package/cpp/webcrypto/crypto_keygen.cpp +86 -0
  19. package/cpp/webcrypto/crypto_keygen.h +38 -0
  20. package/lib/commonjs/Cipher.js +3 -1
  21. package/lib/commonjs/Cipher.js.map +1 -1
  22. package/lib/commonjs/Hashnames.js +20 -8
  23. package/lib/commonjs/Hashnames.js.map +1 -1
  24. package/lib/commonjs/NativeQuickCrypto/Cipher.js +13 -1
  25. package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +1 -1
  26. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
  27. package/lib/commonjs/NativeQuickCrypto/aes.js +6 -0
  28. package/lib/commonjs/NativeQuickCrypto/aes.js.map +1 -0
  29. package/lib/commonjs/NativeQuickCrypto/keygen.js +6 -0
  30. package/lib/commonjs/NativeQuickCrypto/keygen.js.map +1 -0
  31. package/lib/commonjs/NativeQuickCrypto/rsa.js +6 -0
  32. package/lib/commonjs/NativeQuickCrypto/rsa.js.map +1 -0
  33. package/lib/commonjs/Utils.js +30 -6
  34. package/lib/commonjs/Utils.js.map +1 -1
  35. package/lib/commonjs/aes.js +184 -227
  36. package/lib/commonjs/aes.js.map +1 -1
  37. package/lib/commonjs/index.js +12 -2
  38. package/lib/commonjs/index.js.map +1 -1
  39. package/lib/commonjs/keygen.js +56 -0
  40. package/lib/commonjs/keygen.js.map +1 -0
  41. package/lib/commonjs/keys.js +74 -5
  42. package/lib/commonjs/keys.js.map +1 -1
  43. package/lib/commonjs/rsa.js +115 -196
  44. package/lib/commonjs/rsa.js.map +1 -1
  45. package/lib/commonjs/sig.js.map +1 -1
  46. package/lib/commonjs/subtle.js +140 -78
  47. package/lib/commonjs/subtle.js.map +1 -1
  48. package/lib/commonjs/webcrypto.js +14 -0
  49. package/lib/commonjs/webcrypto.js.map +1 -0
  50. package/lib/module/Cipher.js +3 -1
  51. package/lib/module/Cipher.js.map +1 -1
  52. package/lib/module/Hashnames.js +20 -8
  53. package/lib/module/Hashnames.js.map +1 -1
  54. package/lib/module/NativeQuickCrypto/Cipher.js +12 -0
  55. package/lib/module/NativeQuickCrypto/Cipher.js.map +1 -1
  56. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
  57. package/lib/module/NativeQuickCrypto/aes.js +2 -0
  58. package/lib/module/NativeQuickCrypto/aes.js.map +1 -0
  59. package/lib/module/NativeQuickCrypto/keygen.js +2 -0
  60. package/lib/module/NativeQuickCrypto/keygen.js.map +1 -0
  61. package/lib/module/NativeQuickCrypto/rsa.js +2 -0
  62. package/lib/module/NativeQuickCrypto/rsa.js.map +1 -0
  63. package/lib/module/Utils.js +26 -5
  64. package/lib/module/Utils.js.map +1 -1
  65. package/lib/module/aes.js +183 -228
  66. package/lib/module/aes.js.map +1 -1
  67. package/lib/module/index.js +11 -2
  68. package/lib/module/index.js.map +1 -1
  69. package/lib/module/keygen.js +47 -0
  70. package/lib/module/keygen.js.map +1 -0
  71. package/lib/module/keys.js +68 -4
  72. package/lib/module/keys.js.map +1 -1
  73. package/lib/module/rsa.js +115 -198
  74. package/lib/module/rsa.js.map +1 -1
  75. package/lib/module/sig.js.map +1 -1
  76. package/lib/module/subtle.js +143 -82
  77. package/lib/module/subtle.js.map +1 -1
  78. package/lib/module/webcrypto.js +8 -0
  79. package/lib/module/webcrypto.js.map +1 -0
  80. package/lib/typescript/Cipher.d.ts +0 -1
  81. package/lib/typescript/Cipher.d.ts.map +1 -1
  82. package/lib/typescript/Hash.d.ts.map +1 -1
  83. package/lib/typescript/Hashnames.d.ts +2 -2
  84. package/lib/typescript/Hashnames.d.ts.map +1 -1
  85. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +5 -0
  86. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts.map +1 -1
  87. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +4 -1
  88. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +1 -1
  89. package/lib/typescript/NativeQuickCrypto/aes.d.ts +5 -0
  90. package/lib/typescript/NativeQuickCrypto/aes.d.ts.map +1 -0
  91. package/lib/typescript/NativeQuickCrypto/keygen.d.ts +4 -0
  92. package/lib/typescript/NativeQuickCrypto/keygen.d.ts.map +1 -0
  93. package/lib/typescript/NativeQuickCrypto/rsa.d.ts +5 -0
  94. package/lib/typescript/NativeQuickCrypto/rsa.d.ts.map +1 -0
  95. package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts +12 -2
  96. package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts.map +1 -1
  97. package/lib/typescript/Utils.d.ts +4 -4
  98. package/lib/typescript/Utils.d.ts.map +1 -1
  99. package/lib/typescript/aes.d.ts +18 -1
  100. package/lib/typescript/aes.d.ts.map +1 -1
  101. package/lib/typescript/ec.d.ts.map +1 -1
  102. package/lib/typescript/index.d.ts +27 -24
  103. package/lib/typescript/index.d.ts.map +1 -1
  104. package/lib/typescript/keygen.d.ts +6 -0
  105. package/lib/typescript/keygen.d.ts.map +1 -0
  106. package/lib/typescript/keys.d.ts +58 -17
  107. package/lib/typescript/keys.d.ts.map +1 -1
  108. package/lib/typescript/rsa.d.ts +9 -1
  109. package/lib/typescript/rsa.d.ts.map +1 -1
  110. package/lib/typescript/sig.d.ts +3 -17
  111. package/lib/typescript/sig.d.ts.map +1 -1
  112. package/lib/typescript/subtle.d.ts +6 -5
  113. package/lib/typescript/subtle.d.ts.map +1 -1
  114. package/lib/typescript/webcrypto.d.ts +9 -0
  115. package/lib/typescript/webcrypto.d.ts.map +1 -0
  116. package/package.json +12 -12
  117. package/src/Cipher.ts +1 -1
  118. package/src/Hashnames.ts +23 -21
  119. package/src/NativeQuickCrypto/Cipher.ts +32 -0
  120. package/src/NativeQuickCrypto/NativeQuickCrypto.ts +6 -0
  121. package/src/NativeQuickCrypto/aes.ts +14 -0
  122. package/src/NativeQuickCrypto/keygen.ts +7 -0
  123. package/src/NativeQuickCrypto/rsa.ts +12 -0
  124. package/src/NativeQuickCrypto/webcrypto.ts +26 -2
  125. package/src/Utils.ts +37 -8
  126. package/src/aes.ts +259 -222
  127. package/src/index.ts +10 -1
  128. package/src/keygen.ts +80 -0
  129. package/src/keys.ts +143 -30
  130. package/src/rsa.ts +161 -187
  131. package/src/sig.ts +7 -23
  132. package/src/subtle.ts +211 -93
  133. package/src/webcrypto.ts +8 -0
package/src/index.ts CHANGED
@@ -12,15 +12,18 @@ import {
12
12
  generateKeyPair,
13
13
  generateKeyPairSync,
14
14
  } from './Cipher';
15
+ import { generateKey, generateKeySync } from './keygen';
15
16
  import { createSign, createVerify } from './sig';
16
17
  import { createHmac } from './Hmac';
17
18
  import { createHash } from './Hash';
18
19
  import { constants } from './constants';
19
20
  import { subtle } from './subtle';
20
21
  import { getCiphers, getHashes } from './Utils';
22
+ import webcrypto from './webcrypto';
23
+ import { createPrivateKey, createPublicKey, createSecretKey } from './keys';
21
24
 
22
25
  /**
23
- * Loosesly matches Node.js {crypto} with some unimplemented functionality
26
+ * Loosely matches Node.js {crypto} with some unimplemented functionality
24
27
  */
25
28
  const QuickCrypto = {
26
29
  createHmac,
@@ -31,11 +34,16 @@ const QuickCrypto = {
31
34
  createCipheriv,
32
35
  createDecipher,
33
36
  createDecipheriv,
37
+ createPublicKey,
38
+ createPrivateKey,
39
+ createSecretKey,
34
40
  publicEncrypt,
35
41
  publicDecrypt,
36
42
  privateDecrypt,
43
+ generateKey,
37
44
  generateKeyPair,
38
45
  generateKeyPairSync,
46
+ generateKeySync,
39
47
  createSign,
40
48
  createVerify,
41
49
  subtle,
@@ -44,6 +52,7 @@ const QuickCrypto = {
44
52
  ...random,
45
53
  getCiphers,
46
54
  getHashes,
55
+ webcrypto,
47
56
  };
48
57
 
49
58
  /**
package/src/keygen.ts ADDED
@@ -0,0 +1,80 @@
1
+ import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
2
+ import { lazyDOMException, validateFunction } from './Utils';
3
+ import { kAesKeyLengths } from './aes';
4
+ import {
5
+ SecretKeyObject,
6
+ type SecretKeyType,
7
+ type AesKeyGenParams,
8
+ } from './keys';
9
+
10
+ export type KeyGenCallback = (
11
+ err: Error | undefined,
12
+ key?: SecretKeyObject
13
+ ) => void;
14
+
15
+ export const generateKeyPromise = (
16
+ type: SecretKeyType,
17
+ options: AesKeyGenParams // | HmacKeyGenParams
18
+ ): Promise<[Error | undefined, SecretKeyObject | undefined]> => {
19
+ return new Promise((resolve, reject) => {
20
+ generateKey(type, options, (err, key) => {
21
+ if (err) {
22
+ reject([err, undefined]);
23
+ }
24
+ resolve([undefined, key]);
25
+ });
26
+ });
27
+ };
28
+
29
+ export const generateKey = (
30
+ type: SecretKeyType,
31
+ options: AesKeyGenParams, // | HmacKeyGenParams,
32
+ callback: KeyGenCallback
33
+ ): void => {
34
+ validateLength(type, options.length);
35
+ if (!validateFunction(callback)) {
36
+ throw lazyDOMException('Callback is not a function', 'SyntaxError');
37
+ }
38
+ NativeQuickCrypto.webcrypto
39
+ .generateSecretKey(options.length)
40
+ .then((handle) => {
41
+ callback(undefined, new SecretKeyObject(handle));
42
+ })
43
+ .catch((err) => {
44
+ callback(err, undefined);
45
+ });
46
+ };
47
+
48
+ export const generateKeySync = (
49
+ type: SecretKeyType,
50
+ options: AesKeyGenParams // | HmacKeyGenParams,
51
+ ): SecretKeyObject => {
52
+ validateLength(type, options.length);
53
+ const handle = NativeQuickCrypto.webcrypto.generateSecretKeySync(
54
+ options.length
55
+ );
56
+ return new SecretKeyObject(handle);
57
+ };
58
+
59
+ const validateLength = (type: SecretKeyType, length: number) => {
60
+ switch (type) {
61
+ case 'aes':
62
+ if (!kAesKeyLengths.includes(length)) {
63
+ throw lazyDOMException(
64
+ 'AES key length must be 128, 192, or 256 bits',
65
+ 'OperationError'
66
+ );
67
+ }
68
+ break;
69
+ case 'hmac':
70
+ if (length < 8 || length > 2 ** 31 - 1) {
71
+ throw lazyDOMException(
72
+ 'HMAC key length must be between 8 and 2^31 - 1',
73
+ 'OperationError'
74
+ );
75
+ }
76
+ break;
77
+ default:
78
+ throw new Error(`Unsupported key type '${type}' for generateKey()`);
79
+ }
80
+ };
package/src/keys.ts CHANGED
@@ -2,6 +2,8 @@ import {
2
2
  type BinaryLike,
3
3
  binaryLikeToArrayBuffer,
4
4
  isStringOrBuffer,
5
+ type BufferLike,
6
+ type TypedArray,
5
7
  } from './Utils';
6
8
  import type { KeyObjectHandle } from './NativeQuickCrypto/webcrypto';
7
9
  import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
@@ -27,25 +29,30 @@ export type AnyAlgorithm =
27
29
  | 'PBKDF2'
28
30
  | 'HKDF';
29
31
 
30
- export type HashAlgorithm = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
32
+ export type HashAlgorithm =
33
+ | 'SHA-1'
34
+ | 'SHA-224'
35
+ | 'SHA-256'
36
+ | 'SHA-384'
37
+ | 'SHA-512'
38
+ | 'RIPEMD-160';
39
+
40
+ export type DigestAlgorithm = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
31
41
 
32
42
  export type KeyPairType = 'rsa' | 'rsa-pss' | 'ec';
33
43
 
34
44
  export type RSAKeyPairAlgorithm = 'RSASSA-PKCS1-v1_5' | 'RSA-PSS' | 'RSA-OAEP';
35
45
  export type ECKeyPairAlgorithm = 'ECDSA' | 'ECDH';
36
46
  export type CFRGKeyPairAlgorithm = 'Ed25519' | 'Ed448' | 'X25519' | 'X448';
47
+ export type AESAlgorithm = 'AES-CTR' | 'AES-CBC' | 'AES-GCM' | 'AES-KW';
37
48
 
38
49
  export type KeyPairAlgorithm =
39
50
  | RSAKeyPairAlgorithm
40
51
  | ECKeyPairAlgorithm
41
52
  | CFRGKeyPairAlgorithm;
42
53
 
43
- export type SecretKeyAlgorithm =
44
- | 'HMAC'
45
- | 'AES-CTR'
46
- | 'AES-CBC'
47
- | 'AES-GCM'
48
- | 'AES-KW';
54
+ export type SecretKeyAlgorithm = 'HMAC' | AESAlgorithm;
55
+ export type SecretKeyType = 'hmac' | 'aes';
49
56
 
50
57
  export type SignVerifyAlgorithm =
51
58
  | 'RSASSA-PKCS1-v1_5'
@@ -62,6 +69,49 @@ export type DeriveBitsAlgorithm =
62
69
  | 'X25519'
63
70
  | 'X448';
64
71
 
72
+ export type RsaOaepParams = {
73
+ name: 'RSA-OAEP';
74
+ label?: BufferLike;
75
+ };
76
+
77
+ export type AesCbcParams = {
78
+ name: 'AES-CBC';
79
+ iv: BufferLike;
80
+ };
81
+
82
+ export type AesCtrParams = {
83
+ name: 'AES-CTR';
84
+ counter: TypedArray;
85
+ length: number;
86
+ };
87
+
88
+ export type AesGcmParams = {
89
+ name: 'AES-GCM';
90
+ iv: BufferLike;
91
+ tagLength?: TagLength;
92
+ additionalData?: BufferLike;
93
+ };
94
+
95
+ export type AesKwParams = {
96
+ name: 'AES-KW';
97
+ wrappingKey?: BufferLike;
98
+ };
99
+
100
+ export type AesKeyGenParams = {
101
+ length: AESLength;
102
+ name?: AESAlgorithm;
103
+ };
104
+
105
+ export type TagLength = 32 | 64 | 96 | 104 | 112 | 120 | 128;
106
+
107
+ export type AESLength = 128 | 192 | 256;
108
+
109
+ export type EncryptDecryptParams =
110
+ | AesCbcParams
111
+ | AesCtrParams
112
+ | AesGcmParams
113
+ | RsaOaepParams;
114
+
65
115
  export type EncryptDecryptAlgorithm =
66
116
  | 'RSA-OAEP'
67
117
  | 'AES-CTR'
@@ -97,6 +147,8 @@ export enum KFormatType {
97
147
  kKeyFormatJWK,
98
148
  }
99
149
 
150
+ export type KFormat = 'der' | 'pem' | 'jwk';
151
+
100
152
  // Same as KFormatType, this enum needs to be defined on the native side
101
153
  export enum KeyType {
102
154
  Secret,
@@ -104,6 +156,10 @@ export enum KeyType {
104
156
  Private,
105
157
  }
106
158
 
159
+ export type KTypePrivate = 'pkcs1' | 'pkcs8' | 'sec1';
160
+ export type KTypePublic = 'pkcs1' | 'spki';
161
+ export type KType = KTypePrivate | KTypePublic;
162
+
107
163
  // Same as KFormatType, this enum needs to be defined on the native side
108
164
  export enum KWebCryptoKeyFormat {
109
165
  kWebCryptoKeyFormatRaw,
@@ -132,14 +188,18 @@ export enum KeyEncoding {
132
188
  kKeyEncodingSEC1,
133
189
  }
134
190
 
191
+ export type DSAEncoding = 'der' | 'ieee-p1363';
192
+
135
193
  export type EncodingOptions = {
136
- key: any;
137
- type?: string;
194
+ key?: any;
195
+ type?: KType;
138
196
  encoding?: string;
139
- format?: string;
197
+ dsaEncoding?: DSAEncoding;
198
+ format?: KFormat;
140
199
  padding?: number;
141
200
  cipher?: string;
142
201
  passphrase?: string | ArrayBuffer;
202
+ saltLength?: number;
143
203
  };
144
204
 
145
205
  export type AsymmetricKeyType = 'rsa' | 'rsa-pss' | 'dsa' | 'ec' | undefined;
@@ -181,6 +241,13 @@ export type CryptoKeyPair = {
181
241
  privateKey: KeyPairKey;
182
242
  };
183
243
 
244
+ export enum CipherOrWrapMode {
245
+ kWebCryptoCipherEncrypt,
246
+ kWebCryptoCipherDecrypt,
247
+ // kWebCryptoWrapKey,
248
+ // kWebCryptoUnwrapKey,
249
+ }
250
+
184
251
  function option(name: string, objName: string | undefined) {
185
252
  return objName === undefined
186
253
  ? `options.${name}`
@@ -322,14 +389,7 @@ function parseKeyEncoding(
322
389
  }
323
390
 
324
391
  function prepareAsymmetricKey(
325
- key:
326
- | BinaryLike
327
- | {
328
- key: any;
329
- encoding?: string;
330
- format?: any;
331
- passphrase?: string | ArrayBuffer;
332
- },
392
+ key: BinaryLike | EncodingOptions,
333
393
  ctx: KeyInputContext
334
394
  ): {
335
395
  format: KFormatType;
@@ -352,14 +412,12 @@ function prepareAsymmetricKey(
352
412
  data: binaryLikeToArrayBuffer(key),
353
413
  };
354
414
  } else if (typeof key === 'object') {
355
- const {
356
- key: data,
357
- encoding,
358
- // format
359
- } = key;
415
+ const { key: data, encoding } = key;
360
416
  // // The 'key' property can be a KeyObject as well to allow specifying
361
417
  // // additional options such as padding along with the key.
362
- // if (isKeyObject(data)) return { data: getKeyObjectHandle(data, ctx) };
418
+ // if (isKeyObject(data)) {
419
+ // return { data: getKeyObjectHandle(data, ctx) };
420
+ // }
363
421
  // else if (isCryptoKey(data))
364
422
  // return { data: getKeyObjectHandle(data[kKeyObject], ctx) };
365
423
  // else if (isJwk(data) && format === 'jwk')
@@ -392,11 +450,7 @@ export function preparePrivateKey(key: BinaryLike | EncodingOptions) {
392
450
  }
393
451
 
394
452
  // TODO(osp) any here is a node KeyObject
395
- export function preparePublicOrPrivateKey(
396
- key:
397
- | BinaryLike
398
- | { key: any; encoding?: string; format?: any; padding?: number }
399
- ) {
453
+ export function preparePublicOrPrivateKey(key: BinaryLike | EncodingOptions) {
400
454
  return prepareAsymmetricKey(key, KeyInputContext.kConsumePublic);
401
455
  }
402
456
 
@@ -422,6 +476,29 @@ export function parsePrivateKeyEncoding(
422
476
  return parseKeyEncoding(enc, keyType, false, objName);
423
477
  }
424
478
 
479
+ // function getKeyObjectHandle(key: any, ctx: KeyInputContext) {
480
+ // if (ctx === KeyInputContext.kConsumePublic) {
481
+ // throw new Error(
482
+ // 'Invalid argument type for "key". Need ArrayBuffer, TypeArray, KeyObject, CryptoKey, string'
483
+ // );
484
+ // }
485
+
486
+ // if (key.type !== 'private') {
487
+ // if (
488
+ // ctx === KeyInputContext.kConsumePrivate ||
489
+ // ctx === KeyInputContext.kCreatePublic
490
+ // )
491
+ // throw new Error(`Invalid KeyObject type: ${key.type}, expected 'public'`);
492
+ // if (key.type !== 'public') {
493
+ // throw new Error(
494
+ // `Invalid KeyObject type: ${key.type}, expected 'private' or 'public'`
495
+ // );
496
+ // }
497
+ // }
498
+
499
+ // return key.handle;
500
+ // }
501
+
425
502
  function prepareSecretKey(
426
503
  key: BinaryLike,
427
504
  encoding?: string,
@@ -467,6 +544,42 @@ export function createSecretKey(key: any, encoding?: string) {
467
544
  return new SecretKeyObject(handle);
468
545
  }
469
546
 
547
+ export function createPublicKey(
548
+ key: BinaryLike | EncodingOptions
549
+ ): PublicKeyObject {
550
+ const { format, type, data, passphrase } = prepareAsymmetricKey(
551
+ key,
552
+ KeyInputContext.kCreatePublic
553
+ );
554
+ const handle = NativeQuickCrypto.webcrypto.createKeyObjectHandle();
555
+ if (format === KFormatType.kKeyFormatJWK) {
556
+ handle.init(KeyType.Public, data);
557
+ } else {
558
+ handle.init(KeyType.Public, data, format, type, passphrase);
559
+ }
560
+ return new PublicKeyObject(handle);
561
+ }
562
+
563
+ export const createPrivateKey = (
564
+ key: BinaryLike | EncodingOptions
565
+ ): PrivateKeyObject => {
566
+ const { format, type, data, passphrase } = prepareAsymmetricKey(
567
+ key,
568
+ KeyInputContext.kCreatePrivate
569
+ );
570
+ const handle = NativeQuickCrypto.webcrypto.createKeyObjectHandle();
571
+ if (format === KFormatType.kKeyFormatJWK) {
572
+ handle.init(KeyType.Private, data);
573
+ } else {
574
+ handle.init(KeyType.Private, data, format, type, passphrase);
575
+ }
576
+ return new PrivateKeyObject(handle);
577
+ };
578
+
579
+ // const isKeyObject = (obj: any): obj is KeyObject => {
580
+ // return obj != null && obj.keyType !== undefined;
581
+ // };
582
+
470
583
  export class CryptoKey {
471
584
  keyObject: KeyObject;
472
585
  keyAlgorithm: SubtleAlgorithm;
@@ -572,7 +685,7 @@ export class SecretKeyObject extends KeyObject {
572
685
  // return this[kHandle].getSymmetricKeySize();
573
686
  // }
574
687
 
575
- export(options: EncodingOptions) {
688
+ export(options?: EncodingOptions) {
576
689
  if (options !== undefined) {
577
690
  if (options.format === 'jwk') {
578
691
  throw new Error('SecretKey export for jwk is not implemented');