react-native-quick-crypto 0.2.0 → 0.3.0
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 +23 -6
- package/cpp/Cipher/MGLCipherHostObject.cpp +64 -48
- package/cpp/Cipher/MGLCipherKeys.cpp +1469 -0
- package/cpp/Cipher/MGLCipherKeys.h +124 -0
- package/cpp/Cipher/MGLCreateCipherInstaller.cpp +56 -53
- package/cpp/Cipher/MGLCreateCipherInstaller.h +5 -0
- package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +56 -53
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +107 -0
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +32 -0
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +60 -0
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +35 -0
- package/cpp/Cipher/MGLPublicCipher.h +120 -0
- package/cpp/Cipher/MGLPublicCipherInstaller.h +113 -0
- package/cpp/Cipher/MGLRsa.cpp +188 -0
- package/cpp/Cipher/MGLRsa.h +61 -0
- package/cpp/JSIUtils/MGLJSIUtils.h +24 -0
- package/cpp/JSIUtils/MGLThreadAwareHostObject.h +1 -1
- package/cpp/MGLQuickCryptoHostObject.cpp +42 -3
- package/cpp/Utils/MGLUtils.cpp +156 -0
- package/cpp/Utils/MGLUtils.h +254 -0
- package/lib/commonjs/Cipher.js +307 -0
- package/lib/commonjs/Cipher.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/Cipher.js +11 -0
- package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
- package/lib/commonjs/QuickCrypto.js +8 -0
- package/lib/commonjs/QuickCrypto.js.map +1 -1
- package/lib/commonjs/Utils.js +82 -1
- package/lib/commonjs/Utils.js.map +1 -1
- package/lib/commonjs/constants.js +86 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/index.js +5 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys.js +207 -0
- package/lib/commonjs/keys.js.map +1 -0
- package/lib/module/Cipher.js +296 -3
- package/lib/module/Cipher.js.map +1 -1
- package/lib/module/NativeQuickCrypto/Cipher.js +9 -1
- package/lib/module/NativeQuickCrypto/Cipher.js.map +1 -1
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
- package/lib/module/QuickCrypto.js +8 -1
- package/lib/module/QuickCrypto.js.map +1 -1
- package/lib/module/Utils.js +67 -1
- package/lib/module/Utils.js.map +1 -1
- package/lib/module/constants.js +79 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys.js +193 -0
- package/lib/module/keys.js.map +1 -0
- package/lib/typescript/Cipher.d.ts +58 -1
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +10 -0
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +6 -1
- package/lib/typescript/QuickCrypto.d.ts +105 -1
- package/lib/typescript/Utils.d.ts +11 -0
- package/lib/typescript/constants.d.ts +75 -0
- package/lib/typescript/index.d.ts +2 -0
- package/lib/typescript/keys.d.ts +60 -0
- package/package.json +5 -5
- package/react-native-quick-crypto.podspec +1 -1
- package/src/.DS_Store +0 -0
- package/src/Cipher.ts +444 -3
- package/src/NativeQuickCrypto/Cipher.ts +44 -0
- package/src/NativeQuickCrypto/NativeQuickCrypto.ts +13 -1
- package/src/QuickCrypto.ts +12 -0
- package/src/Utils.ts +91 -0
- package/src/constants.ts +79 -0
- package/src/index.ts +4 -0
- package/src/keys.ts +297 -0
package/lib/commonjs/Cipher.js
CHANGED
|
@@ -7,6 +7,9 @@ exports.createCipher = createCipher;
|
|
|
7
7
|
exports.createCipheriv = createCipheriv;
|
|
8
8
|
exports.createDecipher = createDecipher;
|
|
9
9
|
exports.createDecipheriv = createDecipheriv;
|
|
10
|
+
exports.generateKeyPair = generateKeyPair;
|
|
11
|
+
exports.generateKeyPairSync = generateKeyPairSync;
|
|
12
|
+
exports.publicEncrypt = exports.publicDecrypt = exports.privateDecrypt = void 0;
|
|
10
13
|
|
|
11
14
|
var _NativeQuickCrypto = require("./NativeQuickCrypto/NativeQuickCrypto");
|
|
12
15
|
|
|
@@ -14,16 +17,29 @@ var _stream = _interopRequireDefault(require("stream"));
|
|
|
14
17
|
|
|
15
18
|
var _Utils = require("./Utils");
|
|
16
19
|
|
|
20
|
+
var _Cipher = require("./NativeQuickCrypto/Cipher");
|
|
21
|
+
|
|
17
22
|
var _string_decoder = require("string_decoder");
|
|
18
23
|
|
|
24
|
+
var _reactNativeBuffer = require("@craftzdog/react-native-buffer");
|
|
25
|
+
|
|
19
26
|
var _safeBuffer = require("safe-buffer");
|
|
20
27
|
|
|
28
|
+
var _constants = require("./constants");
|
|
29
|
+
|
|
30
|
+
var _keys = require("./keys");
|
|
31
|
+
|
|
21
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
33
|
|
|
23
34
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
24
35
|
|
|
36
|
+
// make sure that nextTick is there
|
|
37
|
+
global.process.nextTick = setImmediate;
|
|
25
38
|
const createInternalCipher = _NativeQuickCrypto.NativeQuickCrypto.createCipher;
|
|
26
39
|
const createInternalDecipher = _NativeQuickCrypto.NativeQuickCrypto.createDecipher;
|
|
40
|
+
const _publicEncrypt = _NativeQuickCrypto.NativeQuickCrypto.publicEncrypt;
|
|
41
|
+
const _publicDecrypt = _NativeQuickCrypto.NativeQuickCrypto.publicDecrypt;
|
|
42
|
+
const _privateDecrypt = _NativeQuickCrypto.NativeQuickCrypto.privateDecrypt;
|
|
27
43
|
|
|
28
44
|
function getUIntOption(options, key) {
|
|
29
45
|
let value;
|
|
@@ -289,5 +305,296 @@ function createCipher(algorithm, password, options) {
|
|
|
289
305
|
|
|
290
306
|
function createCipheriv(algorithm, key, iv, options) {
|
|
291
307
|
return new Cipher(algorithm, key, options, iv);
|
|
308
|
+
} // RSA Functions
|
|
309
|
+
// Follows closely the model implemented in node
|
|
310
|
+
// TODO(osp) types...
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
function rsaFunctionFor(method, defaultPadding, keyType) {
|
|
314
|
+
return (options, buffer) => {
|
|
315
|
+
const {
|
|
316
|
+
format,
|
|
317
|
+
type,
|
|
318
|
+
data,
|
|
319
|
+
passphrase
|
|
320
|
+
} = keyType === 'private' ? (0, _keys.preparePrivateKey)(options) : (0, _keys.preparePublicOrPrivateKey)(options);
|
|
321
|
+
const padding = options.padding || defaultPadding;
|
|
322
|
+
const {
|
|
323
|
+
oaepHash,
|
|
324
|
+
encoding
|
|
325
|
+
} = options;
|
|
326
|
+
let {
|
|
327
|
+
oaepLabel
|
|
328
|
+
} = options;
|
|
329
|
+
if (oaepHash !== undefined) (0, _Utils.validateString)(oaepHash, 'key.oaepHash');
|
|
330
|
+
if (oaepLabel !== undefined) oaepLabel = (0, _Utils.binaryLikeToArrayBuffer)(oaepLabel, encoding);
|
|
331
|
+
buffer = (0, _Utils.binaryLikeToArrayBuffer)(buffer, encoding);
|
|
332
|
+
const rawRes = method(data, format, type, passphrase, buffer, padding, oaepHash, oaepLabel);
|
|
333
|
+
return _reactNativeBuffer.Buffer.from(rawRes);
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const publicEncrypt = rsaFunctionFor(_publicEncrypt, _constants.constants.RSA_PKCS1_OAEP_PADDING, 'public');
|
|
338
|
+
exports.publicEncrypt = publicEncrypt;
|
|
339
|
+
const publicDecrypt = rsaFunctionFor(_publicDecrypt, _constants.constants.RSA_PKCS1_PADDING, 'public'); // const privateEncrypt = rsaFunctionFor(_privateEncrypt, constants.RSA_PKCS1_PADDING,
|
|
340
|
+
// 'private');
|
|
341
|
+
|
|
342
|
+
exports.publicDecrypt = publicDecrypt;
|
|
343
|
+
const privateDecrypt = rsaFunctionFor(_privateDecrypt, _constants.constants.RSA_PKCS1_OAEP_PADDING, 'private'); // _ _ __ _____ _
|
|
344
|
+
// | | | |/ / | __ \ (_)
|
|
345
|
+
// __ _ ___ _ __ ___ _ __ __ _| |_ ___| ' / ___ _ _| |__) |_ _ _ _ __
|
|
346
|
+
// / _` |/ _ \ '_ \ / _ \ '__/ _` | __/ _ \ < / _ \ | | | ___/ _` | | '__|
|
|
347
|
+
// | (_| | __/ | | | __/ | | (_| | || __/ . \ __/ |_| | | | (_| | | |
|
|
348
|
+
// \__, |\___|_| |_|\___|_| \__,_|\__\___|_|\_\___|\__, |_| \__,_|_|_|
|
|
349
|
+
// __/ | __/ |
|
|
350
|
+
// |___/ |___/
|
|
351
|
+
|
|
352
|
+
exports.privateDecrypt = privateDecrypt;
|
|
353
|
+
|
|
354
|
+
function parseKeyEncoding(keyType) {
|
|
355
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _Utils.kEmptyObject;
|
|
356
|
+
const {
|
|
357
|
+
publicKeyEncoding,
|
|
358
|
+
privateKeyEncoding
|
|
359
|
+
} = options;
|
|
360
|
+
let publicFormat, publicType;
|
|
361
|
+
|
|
362
|
+
if (publicKeyEncoding == null) {
|
|
363
|
+
publicFormat = publicType = undefined;
|
|
364
|
+
} else if (typeof publicKeyEncoding === 'object') {
|
|
365
|
+
({
|
|
366
|
+
format: publicFormat,
|
|
367
|
+
type: publicType
|
|
368
|
+
} = (0, _keys.parsePublicKeyEncoding)(publicKeyEncoding, keyType, 'publicKeyEncoding'));
|
|
369
|
+
} else {
|
|
370
|
+
throw new Error('Invalid argument options.publicKeyEncoding', publicKeyEncoding);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
let privateFormat, privateType, cipher, passphrase;
|
|
374
|
+
|
|
375
|
+
if (privateKeyEncoding == null) {
|
|
376
|
+
privateFormat = privateType = undefined;
|
|
377
|
+
} else if (typeof privateKeyEncoding === 'object') {
|
|
378
|
+
({
|
|
379
|
+
format: privateFormat,
|
|
380
|
+
type: privateType,
|
|
381
|
+
cipher,
|
|
382
|
+
passphrase
|
|
383
|
+
} = (0, _keys.parsePrivateKeyEncoding)(privateKeyEncoding, keyType, 'privateKeyEncoding'));
|
|
384
|
+
} else {
|
|
385
|
+
throw new Error('Invalid argument options.privateKeyEncoding', publicKeyEncoding);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return [publicFormat, publicType, privateFormat, privateType, cipher, passphrase];
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function internalGenerateKeyPair(isAsync, type, options, callback) {
|
|
392
|
+
// On node a very complex "job" chain is created, we are going for a far simpler approach and calling
|
|
393
|
+
// an internal function that basically executes the same byte shuffling on the native side
|
|
394
|
+
const encoding = parseKeyEncoding(type, options); // if (options !== undefined)
|
|
395
|
+
// validateObject(options, 'options');
|
|
396
|
+
|
|
397
|
+
switch (type) {
|
|
398
|
+
case 'rsa-pss':
|
|
399
|
+
case 'rsa':
|
|
400
|
+
{
|
|
401
|
+
(0, _Utils.validateObject)(options, 'options');
|
|
402
|
+
const {
|
|
403
|
+
modulusLength
|
|
404
|
+
} = options;
|
|
405
|
+
(0, _Utils.validateUint32)(modulusLength, 'options.modulusLength');
|
|
406
|
+
let {
|
|
407
|
+
publicExponent
|
|
408
|
+
} = options;
|
|
409
|
+
|
|
410
|
+
if (publicExponent == null) {
|
|
411
|
+
publicExponent = 0x10001;
|
|
412
|
+
} else {
|
|
413
|
+
(0, _Utils.validateUint32)(publicExponent, 'options.publicExponent');
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (type === 'rsa') {
|
|
417
|
+
if (isAsync) {
|
|
418
|
+
_NativeQuickCrypto.NativeQuickCrypto.generateKeyPair(_Cipher.RSAKeyVariant.kKeyVariantRSA_SSA_PKCS1_v1_5, modulusLength, publicExponent, ...encoding).then(_ref => {
|
|
419
|
+
let [err, publicKey, privateKey] = _ref;
|
|
420
|
+
|
|
421
|
+
if (typeof publicKey === 'object') {
|
|
422
|
+
publicKey = _reactNativeBuffer.Buffer.from(publicKey);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (typeof privateKey === 'object') {
|
|
426
|
+
privateKey = _reactNativeBuffer.Buffer.from(privateKey);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
callback === null || callback === void 0 ? void 0 : callback(err, publicKey, privateKey);
|
|
430
|
+
}).catch(err => {
|
|
431
|
+
callback === null || callback === void 0 ? void 0 : callback(err, undefined, undefined);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
return;
|
|
435
|
+
} else {
|
|
436
|
+
let [err, publicKey, privateKey] = _NativeQuickCrypto.NativeQuickCrypto.generateKeyPairSync(_Cipher.RSAKeyVariant.kKeyVariantRSA_SSA_PKCS1_v1_5, modulusLength, publicExponent, ...encoding);
|
|
437
|
+
|
|
438
|
+
if (typeof publicKey === 'object') {
|
|
439
|
+
publicKey = _reactNativeBuffer.Buffer.from(publicKey);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (typeof privateKey === 'object') {
|
|
443
|
+
privateKey = _reactNativeBuffer.Buffer.from(privateKey);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return [err, publicKey, privateKey];
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const {
|
|
451
|
+
hash,
|
|
452
|
+
mgf1Hash,
|
|
453
|
+
hashAlgorithm,
|
|
454
|
+
mgf1HashAlgorithm,
|
|
455
|
+
saltLength
|
|
456
|
+
} = options; // // We don't have a process object on RN
|
|
457
|
+
// // const pendingDeprecation = getOptionValue('--pending-deprecation');
|
|
458
|
+
|
|
459
|
+
if (saltLength !== undefined) (0, _Utils.validateInt32)(saltLength, 'options.saltLength', 0);
|
|
460
|
+
if (hashAlgorithm !== undefined) (0, _Utils.validateString)(hashAlgorithm, 'options.hashAlgorithm');
|
|
461
|
+
if (mgf1HashAlgorithm !== undefined) (0, _Utils.validateString)(mgf1HashAlgorithm, 'options.mgf1HashAlgorithm');
|
|
462
|
+
|
|
463
|
+
if (hash !== undefined) {
|
|
464
|
+
// pendingDeprecation && process.emitWarning(
|
|
465
|
+
// '"options.hash" is deprecated, ' +
|
|
466
|
+
// 'use "options.hashAlgorithm" instead.',
|
|
467
|
+
// 'DeprecationWarning',
|
|
468
|
+
// 'DEP0154');
|
|
469
|
+
(0, _Utils.validateString)(hash, 'options.hash');
|
|
470
|
+
|
|
471
|
+
if (hashAlgorithm && hash !== hashAlgorithm) {
|
|
472
|
+
throw new Error(`Invalid Argument options.hash ${hash}`);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
if (mgf1Hash !== undefined) {
|
|
477
|
+
// pendingDeprecation && process.emitWarning(
|
|
478
|
+
// '"options.mgf1Hash" is deprecated, ' +
|
|
479
|
+
// 'use "options.mgf1HashAlgorithm" instead.',
|
|
480
|
+
// 'DeprecationWarning',
|
|
481
|
+
// 'DEP0154');
|
|
482
|
+
(0, _Utils.validateString)(mgf1Hash, 'options.mgf1Hash');
|
|
483
|
+
|
|
484
|
+
if (mgf1HashAlgorithm && mgf1Hash !== mgf1HashAlgorithm) {
|
|
485
|
+
throw new Error(`Invalid Argument options.mgf1Hash ${mgf1Hash}`);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
return _NativeQuickCrypto.NativeQuickCrypto.generateKeyPairSync(_Cipher.RSAKeyVariant.kKeyVariantRSA_PSS, modulusLength, publicExponent, hashAlgorithm || hash, mgf1HashAlgorithm || mgf1Hash, saltLength, ...encoding);
|
|
490
|
+
}
|
|
491
|
+
// case 'dsa': {
|
|
492
|
+
// validateObject(options, 'options');
|
|
493
|
+
// const { modulusLength } = options!;
|
|
494
|
+
// validateUint32(modulusLength, 'options.modulusLength');
|
|
495
|
+
// let { divisorLength } = options!;
|
|
496
|
+
// if (divisorLength == null) {
|
|
497
|
+
// divisorLength = -1;
|
|
498
|
+
// } else validateInt32(divisorLength, 'options.divisorLength', 0);
|
|
499
|
+
// // return new DsaKeyPairGenJob(
|
|
500
|
+
// // mode,
|
|
501
|
+
// // modulusLength,
|
|
502
|
+
// // divisorLength,
|
|
503
|
+
// // ...encoding);
|
|
504
|
+
// }
|
|
505
|
+
// case 'ec': {
|
|
506
|
+
// validateObject(options, 'options');
|
|
507
|
+
// const { namedCurve } = options!;
|
|
508
|
+
// validateString(namedCurve, 'options.namedCurve');
|
|
509
|
+
// let { paramEncoding } = options!;
|
|
510
|
+
// if (paramEncoding == null || paramEncoding === 'named')
|
|
511
|
+
// paramEncoding = OPENSSL_EC_NAMED_CURVE;
|
|
512
|
+
// else if (paramEncoding === 'explicit')
|
|
513
|
+
// paramEncoding = OPENSSL_EC_EXPLICIT_CURVE;
|
|
514
|
+
// else
|
|
515
|
+
// throw new Error(`Invalid Argument options.paramEncoding ${paramEncoding}`);
|
|
516
|
+
// // throw new ERR_INVALID_ARG_VALUE('options.paramEncoding', paramEncoding);
|
|
517
|
+
// // return new EcKeyPairGenJob(mode, namedCurve, paramEncoding, ...encoding);
|
|
518
|
+
// }
|
|
519
|
+
// case 'ed25519':
|
|
520
|
+
// case 'ed448':
|
|
521
|
+
// case 'x25519':
|
|
522
|
+
// case 'x448': {
|
|
523
|
+
// let id;
|
|
524
|
+
// switch (type) {
|
|
525
|
+
// case 'ed25519':
|
|
526
|
+
// id = EVP_PKEY_ED25519;
|
|
527
|
+
// break;
|
|
528
|
+
// case 'ed448':
|
|
529
|
+
// id = EVP_PKEY_ED448;
|
|
530
|
+
// break;
|
|
531
|
+
// case 'x25519':
|
|
532
|
+
// id = EVP_PKEY_X25519;
|
|
533
|
+
// break;
|
|
534
|
+
// case 'x448':
|
|
535
|
+
// id = EVP_PKEY_X448;
|
|
536
|
+
// break;
|
|
537
|
+
// }
|
|
538
|
+
// return new NidKeyPairGenJob(mode, id, ...encoding);
|
|
539
|
+
// }
|
|
540
|
+
// case 'dh': {
|
|
541
|
+
// validateObject(options, 'options');
|
|
542
|
+
// const { group, primeLength, prime, generator } = options;
|
|
543
|
+
// if (group != null) {
|
|
544
|
+
// if (prime != null)
|
|
545
|
+
// throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'prime');
|
|
546
|
+
// if (primeLength != null)
|
|
547
|
+
// throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'primeLength');
|
|
548
|
+
// if (generator != null)
|
|
549
|
+
// throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'generator');
|
|
550
|
+
// validateString(group, 'options.group');
|
|
551
|
+
// return new DhKeyPairGenJob(mode, group, ...encoding);
|
|
552
|
+
// }
|
|
553
|
+
// if (prime != null) {
|
|
554
|
+
// if (primeLength != null)
|
|
555
|
+
// throw new ERR_INCOMPATIBLE_OPTION_PAIR('prime', 'primeLength');
|
|
556
|
+
// validateBuffer(prime, 'options.prime');
|
|
557
|
+
// } else if (primeLength != null) {
|
|
558
|
+
// validateInt32(primeLength, 'options.primeLength', 0);
|
|
559
|
+
// } else {
|
|
560
|
+
// throw new ERR_MISSING_OPTION(
|
|
561
|
+
// 'At least one of the group, prime, or primeLength options'
|
|
562
|
+
// );
|
|
563
|
+
// }
|
|
564
|
+
// if (generator != null) {
|
|
565
|
+
// validateInt32(generator, 'options.generator', 0);
|
|
566
|
+
// }
|
|
567
|
+
// return new DhKeyPairGenJob(
|
|
568
|
+
// mode,
|
|
569
|
+
// prime != null ? prime : primeLength,
|
|
570
|
+
// generator == null ? 2 : generator,
|
|
571
|
+
// ...encoding
|
|
572
|
+
// );
|
|
573
|
+
// }
|
|
574
|
+
|
|
575
|
+
default: // Fall through
|
|
576
|
+
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
throw new Error(`Invalid Argument options: ${type} scheme not supported. Currently not all encryption methods are supported in quick-crypto!`);
|
|
580
|
+
} // TODO(osp) put correct types (e.g. type -> 'rsa', etc..)
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
function generateKeyPair(type, options, callback) {
|
|
584
|
+
if (typeof options === 'function') {
|
|
585
|
+
callback = options;
|
|
586
|
+
options = undefined;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
(0, _Utils.validateFunction)(callback);
|
|
590
|
+
internalGenerateKeyPair(true, type, options, callback);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
function generateKeyPairSync(type, options) {
|
|
594
|
+
const [_, publicKey, privateKey] = internalGenerateKeyPair(false, type, options, undefined);
|
|
595
|
+
return {
|
|
596
|
+
publicKey,
|
|
597
|
+
privateKey
|
|
598
|
+
};
|
|
292
599
|
}
|
|
293
600
|
//# sourceMappingURL=Cipher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Cipher.ts"],"names":["createInternalCipher","NativeQuickCrypto","createCipher","createInternalDecipher","createDecipher","getUIntOption","options","key","value","Error","normalizeEncoding","enc","retried","toLowerCase","validateEncoding","data","encoding","normalizedEncoding","length","getDecoder","decoder","StringDecoder","CipherCommon","Stream","Transform","constructor","cipherType","cipherKey","isCipher","iv","cipherKeyBuffer","authTagLength","args","cipher_type","cipher_key","auth_tag_len","internal","update","inputEncoding","outputEncoding","defaultEncoding","ArrayBuffer","isView","ret","write","SBuffer","from","final","end","_transform","chunk","callback","push","_flush","setAutoPadding","autoPadding","setAAD","buffer","plaintextLength","setAuthTag","tag","Cipher","Decipher","algorithm","password","createDecipheriv","createCipheriv"],"mappings":";;;;;;;;;;AACA;;AACA;;AACA;;AAqBA;;AAEA;;;;;;AAEA,MAAMA,oBAAoB,GAAGC,qCAAkBC,YAA/C;AACA,MAAMC,sBAAsB,GAAGF,qCAAkBG,cAAjD;;AAEA,SAASC,aAAT,CAAuBC,OAAvB,EAAqDC,GAArD,EAAkE;AAChE,MAAIC,KAAJ;;AACA,MAAIF,OAAO,IAAI,CAACE,KAAK,GAAGF,OAAO,CAACC,GAAD,CAAhB,KAA0B,IAAzC,EAA+C;AAC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;AACD,C,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAAS2D,gBAAT,CACLF,SADK,EAELxD,GAFK,EAGLsB,EAHK,EAILvB,OAJK,EAKK;AACV,SAAO,IAAIwD,QAAJ,CAAaC,SAAb,EAAwBxD,GAAxB,EAA6BD,OAA7B,EAAsCuB,EAAtC,CAAP;AACD,C,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAAS3B,YAAT,CACL6D,SADK,EAELC,QAFK,EAGL1D,OAHK,EAIG;AACR,SAAO,IAAIuD,MAAJ,CAAWE,SAAX,EAAsBC,QAAtB,EAAgC1D,OAAhC,CAAP;AACD,C,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAAS4D,cAAT,CACLH,SADK,EAELxD,GAFK,EAGLsB,EAHK,EAILvB,OAJK,EAKG;AACR,SAAO,IAAIuD,MAAJ,CAAWE,SAAX,EAAsBxD,GAAtB,EAA2BD,OAA3B,EAAoCuB,EAApC,CAAP;AACD","sourcesContent":["/* eslint-disable no-dupe-class-members */\nimport { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';\nimport Stream from 'stream';\nimport {\n BinaryLike,\n binaryLikeToArrayBuffer,\n CipherEncoding,\n Encoding,\n getDefaultEncoding,\n} from './Utils';\nimport type { InternalCipher } from './NativeQuickCrypto/Cipher';\n// TODO(osp) re-enable type specific constructors\n// They are nice to have but not absolutely necessary\n// import type {\n// CipherCCMOptions,\n// CipherCCMTypes,\n// CipherGCMTypes,\n// CipherGCMOptions,\n// // CipherKey,\n// // KeyObject,\n// // TODO @Szymon20000 This types seem to be missing? Where did you get this definitions from?\n// // CipherOCBTypes,\n// // CipherOCBOptions,\n// } from 'crypto'; // Node crypto typings\nimport { StringDecoder } from 'string_decoder';\nimport type { Buffer } from '@craftzdog/react-native-buffer';\nimport { Buffer as SBuffer } from 'safe-buffer';\n\nconst createInternalCipher = NativeQuickCrypto.createCipher;\nconst createInternalDecipher = NativeQuickCrypto.createDecipher;\n\nfunction getUIntOption(options: Record<string, any>, key: string) {\n let value;\n if (options && (value = options[key]) != null) {\n // >>> Turns any type into a positive integer (also sets the sign bit to 0)\n // eslint-disable-next-line no-bitwise\n if (value >>> 0 !== value) throw new Error(`options.${key}: ${value}`);\n return value;\n }\n return -1;\n}\n\nfunction normalizeEncoding(enc: string) {\n if (!enc) return 'utf8';\n var retried;\n while (true) {\n switch (enc) {\n case 'utf8':\n case 'utf-8':\n return 'utf8';\n case 'ucs2':\n case 'ucs-2':\n case 'utf16le':\n case 'utf-16le':\n return 'utf16le';\n case 'latin1':\n case 'binary':\n return 'latin1';\n case 'base64':\n case 'ascii':\n case 'hex':\n return enc;\n default:\n if (retried) return; // undefined\n enc = ('' + enc).toLowerCase();\n retried = true;\n }\n }\n}\n\nfunction validateEncoding(data: string, encoding: string) {\n const normalizedEncoding = normalizeEncoding(encoding);\n const length = data.length;\n\n if (normalizedEncoding === 'hex' && length % 2 !== 0) {\n throw new Error(`Encoding ${encoding} not valid for data length ${length}`);\n }\n}\n\nfunction getDecoder(decoder?: StringDecoder, encoding?: BufferEncoding) {\n return decoder ?? new StringDecoder(encoding);\n}\n\nclass CipherCommon extends Stream.Transform {\n private internal: InternalCipher;\n private decoder: StringDecoder | undefined;\n\n constructor(\n cipherType: string,\n cipherKey: BinaryLike,\n isCipher: boolean,\n options: Record<string, any> = {},\n iv?: BinaryLike | null\n ) {\n super(options);\n const cipherKeyBuffer = binaryLikeToArrayBuffer(cipherKey);\n // TODO(osp) This might not be smart, check again after release\n const authTagLength = getUIntOption(options, 'authTagLength');\n const args = {\n cipher_type: cipherType,\n cipher_key: cipherKeyBuffer,\n iv,\n ...options,\n auth_tag_len: authTagLength,\n };\n this.internal = isCipher\n ? createInternalCipher(args)\n : createInternalDecipher(args);\n }\n\n update(\n data: BinaryLike,\n inputEncoding?: CipherEncoding,\n outputEncoding?: CipherEncoding\n ): ArrayBuffer | string {\n const defaultEncoding = getDefaultEncoding();\n inputEncoding = inputEncoding ?? defaultEncoding;\n outputEncoding = outputEncoding ?? defaultEncoding;\n\n if (typeof data === 'string') {\n validateEncoding(data, inputEncoding);\n } else if (!ArrayBuffer.isView(data)) {\n throw new Error('Invalid data argument');\n }\n\n if (typeof data === 'string') {\n // On node this is handled on the native side\n // on our case we need to correctly send the arraybuffer to the jsi side\n inputEncoding = inputEncoding === 'buffer' ? 'utf8' : inputEncoding;\n data = binaryLikeToArrayBuffer(data, inputEncoding);\n } else {\n data = binaryLikeToArrayBuffer(data as any, inputEncoding);\n }\n\n const ret = this.internal.update(data);\n\n if (outputEncoding && outputEncoding !== 'buffer') {\n this.decoder = getDecoder(this.decoder, outputEncoding);\n\n return this.decoder!.write(SBuffer.from(ret) as any);\n }\n\n return ret;\n }\n\n final(): ArrayBuffer;\n final(outputEncoding: BufferEncoding | 'buffer'): string;\n final(outputEncoding?: BufferEncoding | 'buffer'): ArrayBuffer | string {\n const ret = this.internal.final();\n\n if (outputEncoding && outputEncoding !== 'buffer') {\n this.decoder = getDecoder(this.decoder, outputEncoding);\n\n return this.decoder!.end(SBuffer.from(ret) as any);\n }\n\n return ret;\n }\n\n _transform(chunk: BinaryLike, encoding: Encoding, callback: () => void) {\n this.push(this.update(chunk, encoding));\n callback();\n }\n\n _flush(callback: () => void) {\n this.push(this.final());\n callback();\n }\n\n public setAutoPadding(autoPadding?: boolean): this {\n this.internal.setAutoPadding(!!autoPadding);\n return this;\n }\n\n public setAAD(\n buffer: Buffer,\n options?: {\n plaintextLength: number;\n }\n ): this {\n this.internal.setAAD({\n data: buffer.buffer,\n plaintextLength: options?.plaintextLength,\n });\n return this;\n }\n\n // protected getAuthTag(): Buffer {\n // return Buffer.from(this.internal.getAuthTag());\n // }\n\n public setAuthTag(tag: Buffer): this {\n this.internal.setAuthTag(tag.buffer);\n return this;\n }\n}\n\nclass Cipher extends CipherCommon {\n constructor(\n cipherType: string,\n cipherKey: BinaryLike,\n options: Record<string, any> = {},\n iv?: BinaryLike | null\n ) {\n if (iv != null) {\n iv = binaryLikeToArrayBuffer(iv);\n }\n super(cipherType, cipherKey, true, options, iv);\n }\n}\n\nclass Decipher extends CipherCommon {\n constructor(\n cipherType: string,\n cipherKey: BinaryLike,\n options: Record<string, any> = {},\n iv?: BinaryLike | null\n ) {\n if (iv != null) {\n iv = binaryLikeToArrayBuffer(iv);\n }\n\n super(cipherType, cipherKey, false, options, iv);\n }\n}\n\n// TODO(osp) This definitions cause typescript errors when using the API\n// export function createDecipher(\n// algorithm: CipherCCMTypes,\n// password: BinaryLike,\n// options: CipherCCMOptions\n// ): Decipher;\n// export function createDecipher(\n// algorithm: CipherGCMTypes,\n// password: BinaryLike,\n// options?: CipherGCMOptions\n// ): Decipher;\nexport function createDecipher(\n algorithm: string,\n password: BinaryLike,\n options?: Stream.TransformOptions\n): Decipher {\n return new Decipher(algorithm, password, options);\n}\n\n// TODO(osp) This definitions cause typescript errors when using the API\n// export function createDecipheriv(\n// algorithm: CipherCCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherCCMOptions\n// ): Decipher;\n// export function createDecipheriv(\n// algorithm: CipherOCBTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherOCBOptions\n// ): DecipherOCB;\n// export function createDecipheriv(\n// algorithm: CipherGCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options?: CipherGCMOptions\n// ): Decipher;\nexport function createDecipheriv(\n algorithm: string,\n key: BinaryLike,\n iv: BinaryLike | null,\n options?: Stream.TransformOptions\n): Decipher {\n return new Decipher(algorithm, key, options, iv);\n}\n\n// TODO(osp) This definitions cause typescript errors when using the API\n// commenting them out for now\n// export function createCipher(\n// algorithm: CipherCCMTypes,\n// password: BinaryLike,\n// options: CipherCCMOptions\n// ): Cipher;\n// export function createCipher(\n// algorithm: CipherGCMTypes,\n// password: BinaryLike,\n// options?: CipherGCMOptions\n// ): Cipher;\nexport function createCipher(\n algorithm: string,\n password: BinaryLike,\n options?: Stream.TransformOptions\n): Cipher {\n return new Cipher(algorithm, password, options);\n}\n\n// TODO(osp) on all the createCipheriv methods, node seems to use a \"KeyObject\" is seems to be a thread safe\n// object that creates keys and what not. Not sure if we should support it.\n// Fow now I replaced all of them to BinaryLike\n// export function createCipheriv(\n// algorithm: CipherCCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherCCMOptions\n// ): Cipher;\n// export function createCipheriv(\n// algorithm: CipherOCBTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherOCBOptions\n// ): CipherOCB;\n// export function createCipheriv(\n// algorithm: CipherGCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options?: CipherGCMOptions\n// ): Cipher;\nexport function createCipheriv(\n algorithm: string,\n key: BinaryLike,\n iv: BinaryLike | null,\n options?: Stream.TransformOptions\n): Cipher {\n return new Cipher(algorithm, key, options, iv);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["Cipher.ts"],"names":["global","process","nextTick","setImmediate","createInternalCipher","NativeQuickCrypto","createCipher","createInternalDecipher","createDecipher","_publicEncrypt","publicEncrypt","_publicDecrypt","publicDecrypt","_privateDecrypt","privateDecrypt","getUIntOption","options","key","value","Error","normalizeEncoding","enc","retried","toLowerCase","validateEncoding","data","encoding","normalizedEncoding","length","getDecoder","decoder","StringDecoder","CipherCommon","Stream","Transform","constructor","cipherType","cipherKey","isCipher","iv","cipherKeyBuffer","authTagLength","args","cipher_type","cipher_key","auth_tag_len","internal","update","inputEncoding","outputEncoding","defaultEncoding","ArrayBuffer","isView","ret","write","SBuffer","from","final","end","_transform","chunk","callback","push","_flush","setAutoPadding","autoPadding","setAAD","buffer","plaintextLength","setAuthTag","tag","Cipher","Decipher","algorithm","password","createDecipheriv","createCipheriv","rsaFunctionFor","method","defaultPadding","keyType","format","type","passphrase","padding","oaepHash","oaepLabel","undefined","rawRes","Buffer","constants","RSA_PKCS1_OAEP_PADDING","RSA_PKCS1_PADDING","parseKeyEncoding","kEmptyObject","publicKeyEncoding","privateKeyEncoding","publicFormat","publicType","privateFormat","privateType","cipher","internalGenerateKeyPair","isAsync","modulusLength","publicExponent","generateKeyPair","RSAKeyVariant","kKeyVariantRSA_SSA_PKCS1_v1_5","then","err","publicKey","privateKey","catch","generateKeyPairSync","hash","mgf1Hash","hashAlgorithm","mgf1HashAlgorithm","saltLength","kKeyVariantRSA_PSS","_"],"mappings":";;;;;;;;;;;;;AACA;;AACA;;AACA;;AAaA;;AAcA;;AACA;;AACA;;AACA;;AACA;;;;;;AAOA;AACAA,MAAM,CAACC,OAAP,CAAeC,QAAf,GAA0BC,YAA1B;AAEA,MAAMC,oBAAoB,GAAGC,qCAAkBC,YAA/C;AACA,MAAMC,sBAAsB,GAAGF,qCAAkBG,cAAjD;AACA,MAAMC,cAAc,GAAGJ,qCAAkBK,aAAzC;AACA,MAAMC,cAAc,GAAGN,qCAAkBO,aAAzC;AACA,MAAMC,eAAe,GAAGR,qCAAkBS,cAA1C;;AAEA,SAASC,aAAT,CAAuBC,OAAvB,EAAqDC,GAArD,EAAkE;AAChE,MAAIC,KAAJ;;AACA,MAAIF,OAAO,IAAI,CAACE,KAAK,GAAGF,OAAO,CAACC,GAAD,CAAhB,KAA0B,IAAzC,EAA+C;AAC7C;AACA;AACA,QAAIC,KAAK,KAAK,CAAV,KAAgBA,KAApB,EAA2B,MAAM,IAAIC,KAAJ,CAAW,WAAUF,GAAI,KAAIC,KAAM,EAAnC,CAAN;AAC3B,WAAOA,KAAP;AACD;;AACD,SAAO,CAAC,CAAR;AACD;;AAED,SAASE,iBAAT,CAA2BC,GAA3B,EAAwC;AACtC,MAAI,CAACA,GAAL,EAAU,OAAO,MAAP;AACV,MAAIC,OAAJ;;AACA,SAAO,IAAP,EAAa;AACX,YAAQD,GAAR;A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;AACF,YAAIF,aAAa,KAAK9B,SAAtB,EACE,2BAAe8B,aAAf,EAA8B,uBAA9B;AACF,YAAIC,iBAAiB,KAAK/B,SAA1B,EACE,2BAAe+B,iBAAf,EAAkC,2BAAlC;;AACF,YAAIH,IAAI,KAAK5B,SAAb,EAAwB;AACtB;AACA;AACA;AACA;AACA;AACA,qCAAe4B,IAAf,EAAqB,cAArB;;AACA,cAAIE,aAAa,IAAIF,IAAI,KAAKE,aAA9B,EAA6C;AAC3C,kBAAM,IAAIlG,KAAJ,CAAW,iCAAgCgG,IAAK,EAAhD,CAAN;AACD;AACF;;AACD,YAAIC,QAAQ,KAAK7B,SAAjB,EAA4B;AAC1B;AACA;AACA;AACA;AACA;AACA,qCAAe6B,QAAf,EAAyB,kBAAzB;;AACA,cAAIE,iBAAiB,IAAIF,QAAQ,KAAKE,iBAAtC,EAAyD;AACvD,kBAAM,IAAInG,KAAJ,CAAW,qCAAoCiG,QAAS,EAAxD,CAAN;AACD;AACF;;AAED,eAAO/G,qCAAkB6G,mBAAlB,CACLP,sBAAca,kBADT,EAELhB,aAFK,EAGLC,cAHK,EAILY,aAAa,IAAIF,IAJZ,EAKLG,iBAAiB,IAAIF,QALhB,EAMLG,UANK,EAOL,GAAG7F,QAPE,CAAP;AASD;AACD;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,YA/LF,CAgME;;AAhMF;;AAkMA,QAAM,IAAIP,KAAJ,CACH,6BAA4B+D,IAAK,4FAD9B,CAAN;AAGD,C,CAED;;;AAUO,SAASwB,eAAT,CACLxB,IADK,EAELlE,OAFK,EAGL6C,QAHK,EAIL;AACA,MAAI,OAAO7C,OAAP,KAAmB,UAAvB,EAAmC;AACjC6C,IAAAA,QAAQ,GAAG7C,OAAX;AACAA,IAAAA,OAAO,GAAGuE,SAAV;AACD;;AAED,+BAAiB1B,QAAjB;AAEAyC,EAAAA,uBAAuB,CAAC,IAAD,EAAOpB,IAAP,EAAalE,OAAb,EAAsB6C,QAAtB,CAAvB;AACD;;AAUM,SAASqD,mBAAT,CACLhC,IADK,EAELlE,OAFK,EAGgC;AACrC,QAAM,CAACyG,CAAD,EAAIV,SAAJ,EAAeC,UAAf,IAA6BV,uBAAuB,CACxD,KADwD,EAExDpB,IAFwD,EAGxDlE,OAHwD,EAIxDuE,SAJwD,CAA1D;AAOA,SAAO;AACLwB,IAAAA,SADK;AAELC,IAAAA;AAFK,GAAP;AAID","sourcesContent":["/* eslint-disable no-dupe-class-members */\nimport { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';\nimport Stream from 'stream';\nimport {\n BinaryLike,\n binaryLikeToArrayBuffer,\n CipherEncoding,\n Encoding,\n getDefaultEncoding,\n kEmptyObject,\n validateFunction,\n validateObject,\n validateString,\n validateUint32,\n validateInt32,\n} from './Utils';\nimport { InternalCipher, RSAKeyVariant } from './NativeQuickCrypto/Cipher';\n// TODO(osp) re-enable type specific constructors\n// They are nice to have but not absolutely necessary\n// import type {\n// CipherCCMOptions,\n// CipherCCMTypes,\n// CipherGCMTypes,\n// CipherGCMOptions,\n// // CipherKey,\n// // KeyObject,\n// // TODO(Szymon) This types seem to be missing? Where did you get this definitions from?\n// // CipherOCBTypes,\n// // CipherOCBOptions,\n// } from 'crypto'; // Node crypto typings\nimport { StringDecoder } from 'string_decoder';\nimport { Buffer } from '@craftzdog/react-native-buffer';\nimport { Buffer as SBuffer } from 'safe-buffer';\nimport { constants } from './constants';\nimport {\n parsePrivateKeyEncoding,\n parsePublicKeyEncoding,\n preparePrivateKey,\n preparePublicOrPrivateKey,\n} from './keys';\n\n// make sure that nextTick is there\nglobal.process.nextTick = setImmediate;\n\nconst createInternalCipher = NativeQuickCrypto.createCipher;\nconst createInternalDecipher = NativeQuickCrypto.createDecipher;\nconst _publicEncrypt = NativeQuickCrypto.publicEncrypt;\nconst _publicDecrypt = NativeQuickCrypto.publicDecrypt;\nconst _privateDecrypt = NativeQuickCrypto.privateDecrypt;\n\nfunction getUIntOption(options: Record<string, any>, key: string) {\n let value;\n if (options && (value = options[key]) != null) {\n // >>> Turns any type into a positive integer (also sets the sign bit to 0)\n // eslint-disable-next-line no-bitwise\n if (value >>> 0 !== value) throw new Error(`options.${key}: ${value}`);\n return value;\n }\n return -1;\n}\n\nfunction normalizeEncoding(enc: string) {\n if (!enc) return 'utf8';\n var retried;\n while (true) {\n switch (enc) {\n case 'utf8':\n case 'utf-8':\n return 'utf8';\n case 'ucs2':\n case 'ucs-2':\n case 'utf16le':\n case 'utf-16le':\n return 'utf16le';\n case 'latin1':\n case 'binary':\n return 'latin1';\n case 'base64':\n case 'ascii':\n case 'hex':\n return enc;\n default:\n if (retried) return; // undefined\n enc = ('' + enc).toLowerCase();\n retried = true;\n }\n }\n}\n\nfunction validateEncoding(data: string, encoding: string) {\n const normalizedEncoding = normalizeEncoding(encoding);\n const length = data.length;\n\n if (normalizedEncoding === 'hex' && length % 2 !== 0) {\n throw new Error(`Encoding ${encoding} not valid for data length ${length}`);\n }\n}\n\nfunction getDecoder(decoder?: StringDecoder, encoding?: BufferEncoding) {\n return decoder ?? new StringDecoder(encoding);\n}\n\nclass CipherCommon extends Stream.Transform {\n private internal: InternalCipher;\n private decoder: StringDecoder | undefined;\n\n constructor(\n cipherType: string,\n cipherKey: BinaryLike,\n isCipher: boolean,\n options: Record<string, any> = {},\n iv?: BinaryLike | null\n ) {\n super(options);\n const cipherKeyBuffer = binaryLikeToArrayBuffer(cipherKey);\n // TODO(osp) This might not be smart, check again after release\n const authTagLength = getUIntOption(options, 'authTagLength');\n const args = {\n cipher_type: cipherType,\n cipher_key: cipherKeyBuffer,\n iv,\n ...options,\n auth_tag_len: authTagLength,\n };\n this.internal = isCipher\n ? createInternalCipher(args)\n : createInternalDecipher(args);\n }\n\n update(\n data: BinaryLike,\n inputEncoding?: CipherEncoding,\n outputEncoding?: CipherEncoding\n ): ArrayBuffer | string {\n const defaultEncoding = getDefaultEncoding();\n inputEncoding = inputEncoding ?? defaultEncoding;\n outputEncoding = outputEncoding ?? defaultEncoding;\n\n if (typeof data === 'string') {\n validateEncoding(data, inputEncoding);\n } else if (!ArrayBuffer.isView(data)) {\n throw new Error('Invalid data argument');\n }\n\n if (typeof data === 'string') {\n // On node this is handled on the native side\n // on our case we need to correctly send the arraybuffer to the jsi side\n inputEncoding = inputEncoding === 'buffer' ? 'utf8' : inputEncoding;\n data = binaryLikeToArrayBuffer(data, inputEncoding);\n } else {\n data = binaryLikeToArrayBuffer(data as any, inputEncoding);\n }\n\n const ret = this.internal.update(data);\n\n if (outputEncoding && outputEncoding !== 'buffer') {\n this.decoder = getDecoder(this.decoder, outputEncoding);\n\n return this.decoder!.write(SBuffer.from(ret) as any);\n }\n\n return ret;\n }\n\n final(): ArrayBuffer;\n final(outputEncoding: BufferEncoding | 'buffer'): string;\n final(outputEncoding?: BufferEncoding | 'buffer'): ArrayBuffer | string {\n const ret = this.internal.final();\n\n if (outputEncoding && outputEncoding !== 'buffer') {\n this.decoder = getDecoder(this.decoder, outputEncoding);\n\n return this.decoder!.end(SBuffer.from(ret) as any);\n }\n\n return ret;\n }\n\n _transform(chunk: BinaryLike, encoding: Encoding, callback: () => void) {\n this.push(this.update(chunk, encoding));\n callback();\n }\n\n _flush(callback: () => void) {\n this.push(this.final());\n callback();\n }\n\n public setAutoPadding(autoPadding?: boolean): this {\n this.internal.setAutoPadding(!!autoPadding);\n return this;\n }\n\n public setAAD(\n buffer: Buffer,\n options?: {\n plaintextLength: number;\n }\n ): this {\n this.internal.setAAD({\n data: buffer.buffer,\n plaintextLength: options?.plaintextLength,\n });\n return this;\n }\n\n // protected getAuthTag(): Buffer {\n // return Buffer.from(this.internal.getAuthTag());\n // }\n\n public setAuthTag(tag: Buffer): this {\n this.internal.setAuthTag(tag.buffer);\n return this;\n }\n}\n\nclass Cipher extends CipherCommon {\n constructor(\n cipherType: string,\n cipherKey: BinaryLike,\n options: Record<string, any> = {},\n iv?: BinaryLike | null\n ) {\n if (iv != null) {\n iv = binaryLikeToArrayBuffer(iv);\n }\n super(cipherType, cipherKey, true, options, iv);\n }\n}\n\nclass Decipher extends CipherCommon {\n constructor(\n cipherType: string,\n cipherKey: BinaryLike,\n options: Record<string, any> = {},\n iv?: BinaryLike | null\n ) {\n if (iv != null) {\n iv = binaryLikeToArrayBuffer(iv);\n }\n\n super(cipherType, cipherKey, false, options, iv);\n }\n}\n\n// TODO(osp) This definitions cause typescript errors when using the API\n// export function createDecipher(\n// algorithm: CipherCCMTypes,\n// password: BinaryLike,\n// options: CipherCCMOptions\n// ): Decipher;\n// export function createDecipher(\n// algorithm: CipherGCMTypes,\n// password: BinaryLike,\n// options?: CipherGCMOptions\n// ): Decipher;\nexport function createDecipher(\n algorithm: string,\n password: BinaryLike,\n options?: Stream.TransformOptions\n): Decipher {\n return new Decipher(algorithm, password, options);\n}\n\n// TODO(osp) This definitions cause typescript errors when using the API\n// export function createDecipheriv(\n// algorithm: CipherCCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherCCMOptions\n// ): Decipher;\n// export function createDecipheriv(\n// algorithm: CipherOCBTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherOCBOptions\n// ): DecipherOCB;\n// export function createDecipheriv(\n// algorithm: CipherGCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options?: CipherGCMOptions\n// ): Decipher;\nexport function createDecipheriv(\n algorithm: string,\n key: BinaryLike,\n iv: BinaryLike | null,\n options?: Stream.TransformOptions\n): Decipher {\n return new Decipher(algorithm, key, options, iv);\n}\n\n// TODO(osp) This definitions cause typescript errors when using the API\n// commenting them out for now\n// export function createCipher(\n// algorithm: CipherCCMTypes,\n// password: BinaryLike,\n// options: CipherCCMOptions\n// ): Cipher;\n// export function createCipher(\n// algorithm: CipherGCMTypes,\n// password: BinaryLike,\n// options?: CipherGCMOptions\n// ): Cipher;\nexport function createCipher(\n algorithm: string,\n password: BinaryLike,\n options?: Stream.TransformOptions\n): Cipher {\n return new Cipher(algorithm, password, options);\n}\n\n// TODO(osp) on all the createCipheriv methods, node seems to use a \"KeyObject\" is seems to be a thread safe\n// object that creates keys and what not. Not sure if we should support it.\n// Fow now I replaced all of them to BinaryLike\n// export function createCipheriv(\n// algorithm: CipherCCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherCCMOptions\n// ): Cipher;\n// export function createCipheriv(\n// algorithm: CipherOCBTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options: CipherOCBOptions\n// ): CipherOCB;\n// export function createCipheriv(\n// algorithm: CipherGCMTypes,\n// key: BinaryLike,\n// iv: BinaryLike,\n// options?: CipherGCMOptions\n// ): Cipher;\nexport function createCipheriv(\n algorithm: string,\n key: BinaryLike,\n iv: BinaryLike | null,\n options?: Stream.TransformOptions\n): Cipher {\n return new Cipher(algorithm, key, options, iv);\n}\n\n// RSA Functions\n// Follows closely the model implemented in node\n\n// TODO(osp) types...\nfunction rsaFunctionFor(\n method: (\n data: ArrayBuffer,\n format: number,\n type: any,\n passphrase: any,\n buffer: ArrayBuffer,\n padding: number,\n oaepHash: any,\n oaepLabel: any\n ) => Buffer,\n defaultPadding: number,\n keyType: 'public' | 'private'\n) {\n return (\n options: {\n key: any;\n encoding?: string;\n format?: any;\n padding?: any;\n oaepHash?: any;\n oaepLabel?: any;\n passphrase?: string;\n },\n buffer: BinaryLike\n ) => {\n const { format, type, data, passphrase } =\n keyType === 'private'\n ? preparePrivateKey(options)\n : preparePublicOrPrivateKey(options);\n const padding = options.padding || defaultPadding;\n const { oaepHash, encoding } = options;\n let { oaepLabel } = options;\n if (oaepHash !== undefined) validateString(oaepHash, 'key.oaepHash');\n if (oaepLabel !== undefined)\n oaepLabel = binaryLikeToArrayBuffer(oaepLabel, encoding);\n buffer = binaryLikeToArrayBuffer(buffer, encoding);\n\n const rawRes = method(\n data,\n format,\n type,\n passphrase,\n buffer,\n padding,\n oaepHash,\n oaepLabel\n );\n\n return Buffer.from(rawRes);\n };\n}\n\nexport const publicEncrypt = rsaFunctionFor(\n _publicEncrypt,\n constants.RSA_PKCS1_OAEP_PADDING,\n 'public'\n);\nexport const publicDecrypt = rsaFunctionFor(\n _publicDecrypt,\n constants.RSA_PKCS1_PADDING,\n 'public'\n);\n// const privateEncrypt = rsaFunctionFor(_privateEncrypt, constants.RSA_PKCS1_PADDING,\n// 'private');\nexport const privateDecrypt = rsaFunctionFor(\n _privateDecrypt,\n constants.RSA_PKCS1_OAEP_PADDING,\n 'private'\n);\n\n// _ _ __ _____ _\n// | | | |/ / | __ \\ (_)\n// __ _ ___ _ __ ___ _ __ __ _| |_ ___| ' / ___ _ _| |__) |_ _ _ _ __\n// / _` |/ _ \\ '_ \\ / _ \\ '__/ _` | __/ _ \\ < / _ \\ | | | ___/ _` | | '__|\n// | (_| | __/ | | | __/ | | (_| | || __/ . \\ __/ |_| | | | (_| | | |\n// \\__, |\\___|_| |_|\\___|_| \\__,_|\\__\\___|_|\\_\\___|\\__, |_| \\__,_|_|_|\n// __/ | __/ |\n// |___/ |___/\ntype GenerateKeyPairOptions = {\n modulusLength: number; // Key size in bits (RSA, DSA).\n publicExponent?: number; // Public exponent (RSA). Default: 0x10001.\n hashAlgorithm?: string; // Name of the message digest (RSA-PSS).\n mgf1HashAlgorithm?: string; // string Name of the message digest used by MGF1 (RSA-PSS).\n saltLength?: number; // Minimal salt length in bytes (RSA-PSS).\n divisorLength?: number; // Size of q in bits (DSA).\n namedCurve?: string; // Name of the curve to use (EC).\n prime?: Buffer; // The prime parameter (DH).\n primeLength?: number; // Prime length in bits (DH).\n generator?: number; // Custom generator (DH). Default: 2.\n groupName?: string; // Diffie-Hellman group name (DH). See crypto.getDiffieHellman().\n publicKeyEncoding?: any; // See keyObject.export().\n privateKeyEncoding?: any; // See keyObject.export().\n paramEncoding?: string;\n hash?: any;\n mgf1Hash?: any;\n};\ntype GenerateKeyPairCallback = (\n error: unknown | null,\n publicKey?: Buffer,\n privateKey?: Buffer\n) => void;\n\nfunction parseKeyEncoding(\n keyType: string,\n options: GenerateKeyPairOptions = kEmptyObject\n) {\n const { publicKeyEncoding, privateKeyEncoding } = options;\n\n let publicFormat, publicType;\n if (publicKeyEncoding == null) {\n publicFormat = publicType = undefined;\n } else if (typeof publicKeyEncoding === 'object') {\n ({ format: publicFormat, type: publicType } = parsePublicKeyEncoding(\n publicKeyEncoding,\n keyType,\n 'publicKeyEncoding'\n ));\n } else {\n throw new Error(\n 'Invalid argument options.publicKeyEncoding',\n publicKeyEncoding\n );\n }\n\n let privateFormat, privateType, cipher, passphrase;\n if (privateKeyEncoding == null) {\n privateFormat = privateType = undefined;\n } else if (typeof privateKeyEncoding === 'object') {\n ({\n format: privateFormat,\n type: privateType,\n cipher,\n passphrase,\n } = parsePrivateKeyEncoding(\n privateKeyEncoding,\n keyType,\n 'privateKeyEncoding'\n ));\n } else {\n throw new Error(\n 'Invalid argument options.privateKeyEncoding',\n publicKeyEncoding\n );\n }\n\n return [\n publicFormat,\n publicType,\n privateFormat,\n privateType,\n cipher,\n passphrase,\n ];\n}\n\nfunction internalGenerateKeyPair(\n isAsync: boolean,\n type: string,\n options: GenerateKeyPairOptions | undefined,\n callback: GenerateKeyPairCallback | undefined\n) {\n // On node a very complex \"job\" chain is created, we are going for a far simpler approach and calling\n // an internal function that basically executes the same byte shuffling on the native side\n const encoding = parseKeyEncoding(type, options);\n\n // if (options !== undefined)\n // validateObject(options, 'options');\n\n switch (type) {\n case 'rsa-pss':\n case 'rsa': {\n validateObject<GenerateKeyPairOptions>(options, 'options');\n const { modulusLength } = options!;\n validateUint32(modulusLength, 'options.modulusLength');\n\n let { publicExponent } = options!;\n if (publicExponent == null) {\n publicExponent = 0x10001;\n } else {\n validateUint32(publicExponent, 'options.publicExponent');\n }\n\n if (type === 'rsa') {\n if (isAsync) {\n NativeQuickCrypto.generateKeyPair(\n RSAKeyVariant.kKeyVariantRSA_SSA_PKCS1_v1_5,\n modulusLength,\n publicExponent,\n ...encoding\n )\n .then(([err, publicKey, privateKey]) => {\n if (typeof publicKey === 'object') {\n publicKey = Buffer.from(publicKey);\n }\n if (typeof privateKey === 'object') {\n privateKey = Buffer.from(privateKey);\n }\n callback?.(err, publicKey, privateKey);\n })\n .catch((err) => {\n callback?.(err, undefined, undefined);\n });\n return;\n } else {\n let [err, publicKey, privateKey] =\n NativeQuickCrypto.generateKeyPairSync(\n RSAKeyVariant.kKeyVariantRSA_SSA_PKCS1_v1_5,\n modulusLength,\n publicExponent,\n ...encoding\n );\n\n if (typeof publicKey === 'object') {\n publicKey = Buffer.from(publicKey);\n }\n if (typeof privateKey === 'object') {\n privateKey = Buffer.from(privateKey);\n }\n\n return [err, publicKey, privateKey];\n }\n }\n\n const { hash, mgf1Hash, hashAlgorithm, mgf1HashAlgorithm, saltLength } =\n options!;\n\n // // We don't have a process object on RN\n // // const pendingDeprecation = getOptionValue('--pending-deprecation');\n\n if (saltLength !== undefined)\n validateInt32(saltLength, 'options.saltLength', 0);\n if (hashAlgorithm !== undefined)\n validateString(hashAlgorithm, 'options.hashAlgorithm');\n if (mgf1HashAlgorithm !== undefined)\n validateString(mgf1HashAlgorithm, 'options.mgf1HashAlgorithm');\n if (hash !== undefined) {\n // pendingDeprecation && process.emitWarning(\n // '\"options.hash\" is deprecated, ' +\n // 'use \"options.hashAlgorithm\" instead.',\n // 'DeprecationWarning',\n // 'DEP0154');\n validateString(hash, 'options.hash');\n if (hashAlgorithm && hash !== hashAlgorithm) {\n throw new Error(`Invalid Argument options.hash ${hash}`);\n }\n }\n if (mgf1Hash !== undefined) {\n // pendingDeprecation && process.emitWarning(\n // '\"options.mgf1Hash\" is deprecated, ' +\n // 'use \"options.mgf1HashAlgorithm\" instead.',\n // 'DeprecationWarning',\n // 'DEP0154');\n validateString(mgf1Hash, 'options.mgf1Hash');\n if (mgf1HashAlgorithm && mgf1Hash !== mgf1HashAlgorithm) {\n throw new Error(`Invalid Argument options.mgf1Hash ${mgf1Hash}`);\n }\n }\n\n return NativeQuickCrypto.generateKeyPairSync(\n RSAKeyVariant.kKeyVariantRSA_PSS,\n modulusLength,\n publicExponent,\n hashAlgorithm || hash,\n mgf1HashAlgorithm || mgf1Hash,\n saltLength,\n ...encoding\n );\n }\n // case 'dsa': {\n // validateObject(options, 'options');\n // const { modulusLength } = options!;\n // validateUint32(modulusLength, 'options.modulusLength');\n\n // let { divisorLength } = options!;\n // if (divisorLength == null) {\n // divisorLength = -1;\n // } else validateInt32(divisorLength, 'options.divisorLength', 0);\n\n // // return new DsaKeyPairGenJob(\n // // mode,\n // // modulusLength,\n // // divisorLength,\n // // ...encoding);\n // }\n // case 'ec': {\n // validateObject(options, 'options');\n // const { namedCurve } = options!;\n // validateString(namedCurve, 'options.namedCurve');\n // let { paramEncoding } = options!;\n // if (paramEncoding == null || paramEncoding === 'named')\n // paramEncoding = OPENSSL_EC_NAMED_CURVE;\n // else if (paramEncoding === 'explicit')\n // paramEncoding = OPENSSL_EC_EXPLICIT_CURVE;\n // else\n // throw new Error(`Invalid Argument options.paramEncoding ${paramEncoding}`);\n // // throw new ERR_INVALID_ARG_VALUE('options.paramEncoding', paramEncoding);\n\n // // return new EcKeyPairGenJob(mode, namedCurve, paramEncoding, ...encoding);\n // }\n // case 'ed25519':\n // case 'ed448':\n // case 'x25519':\n // case 'x448': {\n // let id;\n // switch (type) {\n // case 'ed25519':\n // id = EVP_PKEY_ED25519;\n // break;\n // case 'ed448':\n // id = EVP_PKEY_ED448;\n // break;\n // case 'x25519':\n // id = EVP_PKEY_X25519;\n // break;\n // case 'x448':\n // id = EVP_PKEY_X448;\n // break;\n // }\n // return new NidKeyPairGenJob(mode, id, ...encoding);\n // }\n // case 'dh': {\n // validateObject(options, 'options');\n // const { group, primeLength, prime, generator } = options;\n // if (group != null) {\n // if (prime != null)\n // throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'prime');\n // if (primeLength != null)\n // throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'primeLength');\n // if (generator != null)\n // throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'generator');\n\n // validateString(group, 'options.group');\n\n // return new DhKeyPairGenJob(mode, group, ...encoding);\n // }\n\n // if (prime != null) {\n // if (primeLength != null)\n // throw new ERR_INCOMPATIBLE_OPTION_PAIR('prime', 'primeLength');\n\n // validateBuffer(prime, 'options.prime');\n // } else if (primeLength != null) {\n // validateInt32(primeLength, 'options.primeLength', 0);\n // } else {\n // throw new ERR_MISSING_OPTION(\n // 'At least one of the group, prime, or primeLength options'\n // );\n // }\n\n // if (generator != null) {\n // validateInt32(generator, 'options.generator', 0);\n // }\n // return new DhKeyPairGenJob(\n // mode,\n // prime != null ? prime : primeLength,\n // generator == null ? 2 : generator,\n // ...encoding\n // );\n // }\n default:\n // Fall through\n }\n throw new Error(\n `Invalid Argument options: ${type} scheme not supported. Currently not all encryption methods are supported in quick-crypto!`\n );\n}\n\n// TODO(osp) put correct types (e.g. type -> 'rsa', etc..)\nexport function generateKeyPair(\n type: string,\n callback: GenerateKeyPairCallback\n): void;\nexport function generateKeyPair(\n type: string,\n options: GenerateKeyPairOptions,\n callback: GenerateKeyPairCallback\n): void;\nexport function generateKeyPair(\n type: string,\n options?: GenerateKeyPairCallback | GenerateKeyPairOptions,\n callback?: GenerateKeyPairCallback\n) {\n if (typeof options === 'function') {\n callback = options;\n options = undefined;\n }\n\n validateFunction(callback);\n\n internalGenerateKeyPair(true, type, options, callback);\n}\n\nexport function generateKeyPairSync(type: string): {\n publicKey: any;\n privateKey: any;\n};\nexport function generateKeyPairSync(\n type: string,\n options: GenerateKeyPairOptions\n): { publicKey: any; privateKey: any };\nexport function generateKeyPairSync(\n type: string,\n options?: GenerateKeyPairOptions\n): { publicKey: any; privateKey: any } {\n const [_, publicKey, privateKey] = internalGenerateKeyPair(\n false,\n type,\n options,\n undefined\n )!;\n\n return {\n publicKey,\n privateKey,\n };\n}\n"]}
|
|
@@ -3,4 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.RSAKeyVariant = void 0;
|
|
7
|
+
// TODO(osp) on node this is defined on the native side
|
|
8
|
+
// Need to do the same so that values are always in sync
|
|
9
|
+
let RSAKeyVariant;
|
|
10
|
+
exports.RSAKeyVariant = RSAKeyVariant;
|
|
11
|
+
|
|
12
|
+
(function (RSAKeyVariant) {
|
|
13
|
+
RSAKeyVariant[RSAKeyVariant["kKeyVariantRSA_SSA_PKCS1_v1_5"] = 0] = "kKeyVariantRSA_SSA_PKCS1_v1_5";
|
|
14
|
+
RSAKeyVariant[RSAKeyVariant["kKeyVariantRSA_PSS"] = 1] = "kKeyVariantRSA_PSS";
|
|
15
|
+
RSAKeyVariant[RSAKeyVariant["kKeyVariantRSA_OAEP"] = 2] = "kKeyVariantRSA_OAEP";
|
|
16
|
+
})(RSAKeyVariant || (exports.RSAKeyVariant = RSAKeyVariant = {}));
|
|
6
17
|
//# sourceMappingURL=Cipher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
1
|
+
{"version":3,"sources":["Cipher.ts"],"names":["RSAKeyVariant"],"mappings":";;;;;;AAGA;AACA;IACYA,a;;;WAAAA,a;AAAAA,EAAAA,a,CAAAA,a;AAAAA,EAAAA,a,CAAAA,a;AAAAA,EAAAA,a,CAAAA,a;GAAAA,a,6BAAAA,a","sourcesContent":["import type { BinaryLike } from 'src/Utils';\nimport type { Buffer } from '@craftzdog/react-native-buffer';\n\n// TODO(osp) on node this is defined on the native side\n// Need to do the same so that values are always in sync\nexport enum RSAKeyVariant {\n kKeyVariantRSA_SSA_PKCS1_v1_5,\n kKeyVariantRSA_PSS,\n kKeyVariantRSA_OAEP,\n}\n\nexport type InternalCipher = {\n update: (data: BinaryLike | ArrayBufferView) => ArrayBuffer;\n final: () => ArrayBuffer;\n copy: () => void;\n setAAD: (args: {\n data: BinaryLike;\n plaintextLength?: number;\n }) => InternalCipher;\n setAutoPadding: (autoPad: boolean) => boolean;\n setAuthTag: (tag: ArrayBuffer) => boolean;\n};\n\nexport type CreateCipherMethod = (params: {\n cipher_type: string;\n cipher_key: ArrayBuffer;\n auth_tag_len: number;\n}) => InternalCipher;\n\nexport type CreateDecipherMethod = (params: {\n cipher_type: string;\n cipher_key: ArrayBuffer;\n auth_tag_len: number;\n}) => InternalCipher;\n\nexport type PublicEncryptMethod = (\n data: ArrayBuffer,\n format: number,\n type: any,\n passphrase: any,\n buffer: ArrayBuffer,\n padding: number,\n oaepHash: any,\n oaepLabel: any\n) => Buffer;\nexport type PrivateDecryptMethod = (\n data: ArrayBuffer,\n format: number,\n type: any,\n passphrase: any,\n buffer: ArrayBuffer,\n padding: number,\n oaepHash: any,\n oaepLabel: any\n) => Buffer;\n\nexport type GenerateKeyPairMethod = (\n keyVariant: RSAKeyVariant,\n modulusLength: number,\n publicExponent: number,\n ...rest: any[]\n) => Promise<[error: unknown, publicBuffer: any, privateBuffer: any]>;\n\nexport type GenerateKeyPairSyncMethod = (\n keyVariant: RSAKeyVariant,\n modulusLength: number,\n publicExponent: number,\n ...rest: any[]\n) => [error: unknown, publicBuffer: any, privateBuffer: any];\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["NativeQuickCrypto.ts"],"names":["global","__QuickCryptoProxy","QuickCryptoModule","NativeModules","QuickCrypto","message","Platform","OS","ExpoConstants","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","Error","nativeCallSyncHook","install","result","proxy","NativeQuickCrypto"],"mappings":";;;;;;;AAAA;;
|
|
1
|
+
{"version":3,"sources":["NativeQuickCrypto.ts"],"names":["global","__QuickCryptoProxy","QuickCryptoModule","NativeModules","QuickCrypto","message","Platform","OS","ExpoConstants","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","Error","nativeCallSyncHook","install","result","proxy","NativeQuickCrypto"],"mappings":";;;;;;;AAAA;;AAkCA;AACA,IAAIA,MAAM,CAACC,kBAAP,IAA6B,IAAjC,EAAuC;AACrC;AACA,QAAMC,iBAAiB,GAAGC,2BAAcC,WAAxC;;AACA,MAAIF,iBAAiB,IAAI,IAAzB,EAA+B;AAAA;;AAC7B,QAAIG,OAAO,GACT,kGADF;AAEAA,IAAAA,OAAO,IACL,2GADF;;AAEA,QAAIC,sBAASC,EAAT,KAAgB,KAAhB,IAAyBD,sBAASC,EAAT,KAAgB,OAA7C,EAAsD;AACpDF,MAAAA,OAAO,IAAI,4DAAX;AACD;;AACD,QAAIC,sBAASC,EAAT,KAAgB,SAApB,EAA+B;AAC7BF,MAAAA,OAAO,IAAI,iCAAX;AACD,KAV4B,CAW7B;;;AACA,UAAMG,aAAa,4BACjBL,2BAAcM,oBADG,oFACjB,sBAAoCC,gBADnB,2DACjB,uBAAsDC,iBADxD;;AAEA,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACzB,UAAIA,aAAa,CAACI,YAAd,KAA+B,MAAnC,EAA2C;AACzC;AACA,cAAM,IAAIC,KAAJ,CACJ,uHADI,CAAN;AAGD,OALD,MAKO;AACL;AACAR,QAAAA,OAAO,IAAI,wCAAX;AACD;AACF;;AAEDA,IAAAA,OAAO,IAAI,oCAAX;AACA,UAAM,IAAIQ,KAAJ,CAAUR,OAAV,CAAN;AACD,GA/BoC,CAiCrC;;;AACA,MAAIL,MAAM,CAACc,kBAAP,IAA6B,IAA7B,IAAqCZ,iBAAiB,CAACa,OAAlB,IAA6B,IAAtE,EAA4E;AAC1E,UAAM,IAAIF,KAAJ,CACJ,oRADI,CAAN;AAGD,GAtCoC,CAwCrC;;;AACA,QAAMG,MAAM,GAAGd,iBAAiB,CAACa,OAAlB,EAAf;AACA,MAAIC,MAAM,KAAK,IAAf,EACE,MAAM,IAAIH,KAAJ,CACH,oKAAmKG,MAAO,EADvK,CAAN,CA3CmC,CA+CrC;;AACA,MAAIhB,MAAM,CAACC,kBAAP,IAA6B,IAAjC,EACE,MAAM,IAAIY,KAAJ,CACJ,4JADI,CAAN;AAGH;;AAED,MAAMI,KAAK,GAAGjB,MAAM,CAACC,kBAArB;AACO,MAAMiB,iBAAiB,GAAGD,KAA1B","sourcesContent":["import { NativeModules, Platform } from 'react-native';\nimport type { CreateHmacMethod } from './hmac';\nimport type { CreateHashMethod } from './hash';\nimport type { Pbkdf2Object } from './pbkdf2';\nimport type { RandomObject } from './random';\nimport type {\n CreateCipherMethod,\n CreateDecipherMethod,\n PublicEncryptMethod,\n PrivateDecryptMethod,\n GenerateKeyPairMethod,\n GenerateKeyPairSyncMethod,\n} from './Cipher';\n\ninterface NativeQuickCryptoSpec {\n createHmac: CreateHmacMethod;\n pbkdf2: Pbkdf2Object;\n random: RandomObject;\n createHash: CreateHashMethod;\n createCipher: CreateCipherMethod;\n createDecipher: CreateDecipherMethod;\n publicEncrypt: PublicEncryptMethod;\n publicDecrypt: PublicEncryptMethod;\n privateDecrypt: PrivateDecryptMethod;\n generateKeyPair: GenerateKeyPairMethod;\n generateKeyPairSync: GenerateKeyPairSyncMethod;\n}\n\n// global func declaration for JSI functions\ndeclare global {\n function nativeCallSyncHook(): unknown;\n var __QuickCryptoProxy: object | undefined;\n}\n\n// Check if the constructor exists. If not, try installing the JSI bindings.\nif (global.__QuickCryptoProxy == null) {\n // Get the native QuickCrypto ReactModule\n const QuickCryptoModule = NativeModules.QuickCrypto;\n if (QuickCryptoModule == null) {\n let message =\n 'Failed to install react-native-quick-crypto: The native `QuickCrypto` Module could not be found.';\n message +=\n '\\n* Make sure react-native-quick-crypto is correctly autolinked (run `npx react-native config` to verify)';\n if (Platform.OS === 'ios' || Platform.OS === 'macos') {\n message += '\\n* Make sure you ran `pod install` in the ios/ directory.';\n }\n if (Platform.OS === 'android') {\n message += '\\n* Make sure gradle is synced.';\n }\n // check if Expo\n const ExpoConstants =\n NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;\n if (ExpoConstants != null) {\n if (ExpoConstants.appOwnership === 'expo') {\n // We're running Expo Go\n throw new Error(\n 'react-native-quick-crypto is not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.'\n );\n } else {\n // We're running Expo bare / standalone\n message += '\\n* Make sure you ran `expo prebuild`.';\n }\n }\n\n message += '\\n* Make sure you rebuilt the app.';\n throw new Error(message);\n }\n\n // Check if we are running on-device (JSI)\n if (global.nativeCallSyncHook == null || QuickCryptoModule.install == null) {\n throw new Error(\n 'Failed to install react-native-quick-crypto: React Native is not running on-device. QuickCrypto can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'\n );\n }\n\n // Call the synchronous blocking install() function\n const result = QuickCryptoModule.install();\n if (result !== true)\n throw new Error(\n `Failed to install react-native-quick-crypto: The native QuickCrypto Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`\n );\n\n // Check again if the constructor now exists. If not, throw an error.\n if (global.__QuickCryptoProxy == null)\n throw new Error(\n 'Failed to install react-native-quick-crypto, the native initializer function does not exist. Are you trying to use QuickCrypto from different JS Runtimes?'\n );\n}\n\nconst proxy = global.__QuickCryptoProxy;\nexport const NativeQuickCrypto = proxy as any as NativeQuickCryptoSpec;\n"]}
|
|
@@ -15,6 +15,8 @@ var _Hmac = require("./Hmac");
|
|
|
15
15
|
|
|
16
16
|
var _Hash = require("./Hash");
|
|
17
17
|
|
|
18
|
+
var _constants = require("./constants");
|
|
19
|
+
|
|
18
20
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
21
|
|
|
20
22
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -28,6 +30,12 @@ const QuickCrypto = {
|
|
|
28
30
|
createCipheriv: _Cipher.createCipheriv,
|
|
29
31
|
createDecipher: _Cipher.createDecipher,
|
|
30
32
|
createDecipheriv: _Cipher.createDecipheriv,
|
|
33
|
+
publicEncrypt: _Cipher.publicEncrypt,
|
|
34
|
+
publicDecrypt: _Cipher.publicDecrypt,
|
|
35
|
+
privateDecrypt: _Cipher.privateDecrypt,
|
|
36
|
+
generateKeyPair: _Cipher.generateKeyPair,
|
|
37
|
+
generateKeyPairSync: _Cipher.generateKeyPairSync,
|
|
38
|
+
constants: _constants.constants,
|
|
31
39
|
...pbkdf2,
|
|
32
40
|
...random
|
|
33
41
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["QuickCrypto.ts"],"names":["QuickCrypto","createHmac","Hmac","Hash","createHash","createCipher","createCipheriv","createDecipher","createDecipheriv","pbkdf2","random"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;
|
|
1
|
+
{"version":3,"sources":["QuickCrypto.ts"],"names":["QuickCrypto","createHmac","Hmac","Hash","createHash","createCipher","createCipheriv","createDecipher","createDecipheriv","publicEncrypt","publicDecrypt","privateDecrypt","generateKeyPair","generateKeyPairSync","constants","pbkdf2","random"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAWA;;AACA;;AACA;;;;;;AAEO,MAAMA,WAAW,GAAG;AACzBC,EAAAA,UAAU,EAAVA,gBADyB;AAEzBC,EAAAA,IAAI,EAAED,gBAFmB;AAGzBE,EAAAA,IAAI,EAAEC,gBAHmB;AAIzBA,EAAAA,UAAU,EAAVA,gBAJyB;AAKzBC,EAAAA,YAAY,EAAZA,oBALyB;AAMzBC,EAAAA,cAAc,EAAdA,sBANyB;AAOzBC,EAAAA,cAAc,EAAdA,sBAPyB;AAQzBC,EAAAA,gBAAgB,EAAhBA,wBARyB;AASzBC,EAAAA,aAAa,EAAbA,qBATyB;AAUzBC,EAAAA,aAAa,EAAbA,qBAVyB;AAWzBC,EAAAA,cAAc,EAAdA,sBAXyB;AAYzBC,EAAAA,eAAe,EAAfA,uBAZyB;AAazBC,EAAAA,mBAAmB,EAAnBA,2BAbyB;AAczBC,EAAAA,SAAS,EAATA,oBAdyB;AAezB,KAAGC,MAfsB;AAgBzB,KAAGC;AAhBsB,CAApB","sourcesContent":["import * as pbkdf2 from './pbkdf2';\nimport * as random from './random';\nimport {\n createCipher,\n createCipheriv,\n createDecipher,\n createDecipheriv,\n publicEncrypt,\n publicDecrypt,\n privateDecrypt,\n generateKeyPair,\n generateKeyPairSync,\n} from './Cipher';\nimport { createHmac } from './Hmac';\nimport { createHash } from './Hash';\nimport { constants } from './constants';\n\nexport const QuickCrypto = {\n createHmac,\n Hmac: createHmac,\n Hash: createHash,\n createHash,\n createCipher,\n createCipheriv,\n createDecipher,\n createDecipheriv,\n publicEncrypt,\n publicDecrypt,\n privateDecrypt,\n generateKeyPair,\n generateKeyPairSync,\n constants,\n ...pbkdf2,\n ...random,\n};\n"]}
|