react-native-quick-crypto 1.0.0-beta.1 → 1.0.0-beta.10
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/QuickCrypto.podspec +17 -4
- package/README.md +172 -0
- package/android/CMakeLists.txt +28 -17
- package/android/build.gradle +36 -3
- package/android/src/main/cpp/cpp-adapter.cpp +3 -10
- package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +15 -10
- package/cpp/ed25519/HybridEdKeyPair.cpp +268 -0
- package/cpp/ed25519/HybridEdKeyPair.hpp +85 -0
- package/cpp/pbkdf2/HybridPbkdf2.cpp +72 -0
- package/cpp/pbkdf2/HybridPbkdf2.hpp +35 -0
- package/cpp/random/HybridRandom.cpp +59 -0
- package/cpp/random/HybridRandom.hpp +33 -0
- package/cpp/utils/Utils.hpp +20 -0
- package/deps/fastpbkdf2/fastpbkdf2.c +352 -0
- package/deps/fastpbkdf2/fastpbkdf2.h +68 -0
- package/lib/commonjs/ed.js +42 -0
- package/lib/commonjs/ed.js.map +1 -0
- package/lib/commonjs/index.js +61 -10
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys/classes.js +191 -0
- package/lib/commonjs/keys/classes.js.map +1 -0
- package/lib/commonjs/keys/generateKeyPair.js +148 -0
- package/lib/commonjs/keys/generateKeyPair.js.map +1 -0
- package/lib/commonjs/keys/index.js +62 -0
- package/lib/commonjs/keys/index.js.map +1 -0
- package/lib/commonjs/keys/signVerify.js +41 -0
- package/lib/commonjs/keys/signVerify.js.map +1 -0
- package/lib/commonjs/keys/utils.js +118 -0
- package/lib/commonjs/keys/utils.js.map +1 -0
- package/lib/commonjs/pbkdf2.js +89 -0
- package/lib/commonjs/pbkdf2.js.map +1 -0
- package/lib/commonjs/random.js +3 -3
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/specs/edKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/edKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/specs/keyObjectHandle.nitro.js +6 -0
- package/lib/commonjs/specs/keyObjectHandle.nitro.js.map +1 -0
- package/lib/commonjs/specs/pbkdf2.nitro.js +6 -0
- package/lib/commonjs/specs/pbkdf2.nitro.js.map +1 -0
- package/lib/commonjs/utils/conversion.js +101 -6
- package/lib/commonjs/utils/conversion.js.map +1 -1
- package/lib/commonjs/utils/errors.js +14 -0
- package/lib/commonjs/utils/errors.js.map +1 -0
- package/lib/commonjs/utils/hashnames.js +90 -0
- package/lib/commonjs/utils/hashnames.js.map +1 -0
- package/lib/commonjs/utils/index.js +54 -5
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/types.js +38 -0
- package/lib/commonjs/utils/types.js.map +1 -1
- package/lib/commonjs/utils/validation.js +25 -0
- package/lib/commonjs/utils/validation.js.map +1 -0
- package/lib/module/ed.js +37 -0
- package/lib/module/ed.js.map +1 -0
- package/lib/module/index.js +16 -9
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys/classes.js +182 -0
- package/lib/module/keys/classes.js.map +1 -0
- package/lib/module/keys/generateKeyPair.js +148 -0
- package/lib/module/keys/generateKeyPair.js.map +1 -0
- package/lib/module/keys/index.js +29 -0
- package/lib/module/keys/index.js.map +1 -0
- package/lib/module/keys/signVerify.js +41 -0
- package/lib/module/keys/signVerify.js.map +1 -0
- package/lib/module/keys/utils.js +110 -0
- package/lib/module/keys/utils.js.map +1 -0
- package/lib/module/pbkdf2.js +83 -0
- package/lib/module/pbkdf2.js.map +1 -0
- package/lib/module/random.js +1 -1
- package/lib/module/random.js.map +1 -1
- package/lib/module/specs/edKeyPair.nitro.js +4 -0
- package/lib/module/specs/edKeyPair.nitro.js.map +1 -0
- package/lib/module/specs/keyObjectHandle.nitro.js +4 -0
- package/lib/module/specs/keyObjectHandle.nitro.js.map +1 -0
- package/lib/module/specs/pbkdf2.nitro.js +4 -0
- package/lib/module/specs/pbkdf2.nitro.js.map +1 -0
- package/lib/module/utils/conversion.js +99 -8
- package/lib/module/utils/conversion.js.map +1 -1
- package/lib/module/utils/errors.js +10 -0
- package/lib/module/utils/errors.js.map +1 -0
- package/lib/module/utils/hashnames.js +88 -0
- package/lib/module/utils/hashnames.js.map +1 -0
- package/lib/module/utils/index.js +5 -5
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/types.js +40 -0
- package/lib/module/utils/types.js.map +1 -1
- package/lib/module/utils/validation.js +19 -0
- package/lib/module/utils/validation.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/ed.d.ts +17 -0
- package/lib/typescript/ed.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +50 -9
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/keys/classes.d.ts +38 -0
- package/lib/typescript/keys/classes.d.ts.map +1 -0
- package/lib/typescript/keys/generateKeyPair.d.ts +1 -0
- package/lib/typescript/keys/generateKeyPair.d.ts.map +1 -0
- package/lib/typescript/keys/index.d.ts +4 -0
- package/lib/typescript/keys/index.d.ts.map +1 -0
- package/lib/typescript/keys/signVerify.d.ts +1 -0
- package/lib/typescript/keys/signVerify.d.ts.map +1 -0
- package/lib/typescript/keys/utils.d.ts +32 -0
- package/lib/typescript/keys/utils.d.ts.map +1 -0
- package/lib/typescript/pbkdf2.d.ts +12 -0
- package/lib/typescript/pbkdf2.d.ts.map +1 -0
- package/lib/typescript/random.d.ts +5 -5
- package/lib/typescript/random.d.ts.map +1 -1
- package/lib/typescript/specs/edKeyPair.nitro.d.ts +16 -0
- package/lib/typescript/specs/edKeyPair.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +15 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/pbkdf2.nitro.d.ts +9 -0
- package/lib/typescript/specs/pbkdf2.nitro.d.ts.map +1 -0
- package/lib/typescript/utils/conversion.d.ts +23 -2
- package/lib/typescript/utils/conversion.d.ts.map +1 -1
- package/lib/typescript/utils/errors.d.ts +7 -0
- package/lib/typescript/utils/errors.d.ts.map +1 -0
- package/lib/typescript/utils/hashnames.d.ts +11 -0
- package/lib/typescript/utils/hashnames.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +5 -5
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/lib/typescript/utils/types.d.ts +158 -1
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/lib/typescript/utils/validation.d.ts +8 -0
- package/lib/typescript/utils/validation.d.ts.map +1 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +65 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +27 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +64 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.hpp +25 -0
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +58 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +27 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +38 -0
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +55 -0
- package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +12 -0
- package/nitrogen/generated/shared/c++/CFRGKeyPairType.hpp +86 -0
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp +74 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +27 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +93 -0
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp +66 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +65 -0
- package/nitrogen/generated/shared/c++/JWK.hpp +162 -0
- package/nitrogen/generated/shared/c++/JWKkty.hpp +86 -0
- package/nitrogen/generated/shared/c++/JWKuse.hpp +78 -0
- package/nitrogen/generated/shared/c++/KFormatType.hpp +65 -0
- package/nitrogen/generated/shared/c++/KeyDetail.hpp +93 -0
- package/nitrogen/generated/shared/c++/KeyEncoding.hpp +66 -0
- package/nitrogen/generated/shared/c++/KeyType.hpp +65 -0
- package/nitrogen/generated/shared/c++/KeyUsage.hpp +102 -0
- package/nitrogen/generated/shared/c++/NamedCurve.hpp +82 -0
- package/package.json +55 -34
- package/src/ed.ts +79 -0
- package/src/index.ts +15 -9
- package/src/keys/classes.ts +211 -0
- package/src/keys/generateKeyPair.ts +146 -0
- package/src/keys/index.ts +42 -0
- package/src/keys/signVerify.ts +39 -0
- package/src/keys/utils.ts +184 -0
- package/src/pbkdf2.ts +154 -0
- package/src/random.ts +19 -23
- package/src/specs/edKeyPair.nitro.ts +41 -0
- package/src/specs/keyObjectHandle.nitro.ts +32 -0
- package/src/specs/pbkdf2.nitro.ts +18 -0
- package/src/specs/random.nitro.ts +2 -2
- package/src/utils/conversion.ts +116 -9
- package/src/utils/errors.ts +15 -0
- package/src/utils/hashnames.ts +96 -0
- package/src/utils/index.ts +5 -6
- package/src/utils/types.ts +263 -3
- package/src/utils/validation.ts +35 -0
- package/ios/QuickCryptoOnLoad.mm +0 -19
|
@@ -3,10 +3,59 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.utils = void 0;
|
|
7
6
|
var _conversion = require("./conversion");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
Object.keys(_conversion).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _conversion[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _conversion[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _errors = require("./errors");
|
|
18
|
+
Object.keys(_errors).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _errors[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _errors[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _hashnames = require("./hashnames");
|
|
29
|
+
Object.keys(_hashnames).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _hashnames[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _hashnames[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _types = require("./types");
|
|
40
|
+
Object.keys(_types).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _types[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
var _validation = require("./validation");
|
|
51
|
+
Object.keys(_validation).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _validation[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _validation[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
12
61
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_conversion","require","
|
|
1
|
+
{"version":3,"names":["_conversion","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_errors","_hashnames","_types","_validation"],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":";;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,WAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,WAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,WAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,OAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,OAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,OAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,OAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,UAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,UAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,UAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,UAAA,CAAAN,GAAA;IAAA;EAAA;AAAA;AACA,IAAAO,MAAA,GAAAX,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAS,MAAA,EAAAR,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAO,MAAA,CAAAP,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAG,MAAA,CAAAP,GAAA;IAAA;EAAA;AAAA;AACA,IAAAQ,WAAA,GAAAZ,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAU,WAAA,EAAAT,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAQ,WAAA,CAAAR,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAI,WAAA,CAAAR,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -1,2 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.KeyVariant = exports.KeyType = exports.KeyEncoding = exports.KFormatType = void 0;
|
|
7
|
+
// @types/node
|
|
8
|
+
// On node this value is defined on the native side, for now I'm just creating it here in JS
|
|
9
|
+
// TODO(osp) move this into native side to make sure they always match
|
|
10
|
+
let KFormatType = exports.KFormatType = /*#__PURE__*/function (KFormatType) {
|
|
11
|
+
KFormatType[KFormatType["kKeyFormatDER"] = 0] = "kKeyFormatDER";
|
|
12
|
+
KFormatType[KFormatType["kKeyFormatPEM"] = 1] = "kKeyFormatPEM";
|
|
13
|
+
KFormatType[KFormatType["kKeyFormatJWK"] = 2] = "kKeyFormatJWK";
|
|
14
|
+
return KFormatType;
|
|
15
|
+
}({}); // Same as KFormatType, this enum needs to be defined on the native side
|
|
16
|
+
let KeyType = exports.KeyType = /*#__PURE__*/function (KeyType) {
|
|
17
|
+
KeyType[KeyType["Secret"] = 0] = "Secret";
|
|
18
|
+
KeyType[KeyType["Public"] = 1] = "Public";
|
|
19
|
+
KeyType[KeyType["Private"] = 2] = "Private";
|
|
20
|
+
return KeyType;
|
|
21
|
+
}({});
|
|
22
|
+
let KeyEncoding = exports.KeyEncoding = /*#__PURE__*/function (KeyEncoding) {
|
|
23
|
+
KeyEncoding[KeyEncoding["kKeyEncodingPKCS1"] = 0] = "kKeyEncodingPKCS1";
|
|
24
|
+
KeyEncoding[KeyEncoding["kKeyEncodingPKCS8"] = 1] = "kKeyEncodingPKCS8";
|
|
25
|
+
KeyEncoding[KeyEncoding["kKeyEncodingSPKI"] = 2] = "kKeyEncodingSPKI";
|
|
26
|
+
KeyEncoding[KeyEncoding["kKeyEncodingSEC1"] = 3] = "kKeyEncodingSEC1";
|
|
27
|
+
return KeyEncoding;
|
|
28
|
+
}({}); // Note: removed CryptoKey class from this type (from 0.x) because Nitro doesn't
|
|
29
|
+
// handle custom JS objects. We might need to make it a JS object.
|
|
30
|
+
let KeyVariant = exports.KeyVariant = /*#__PURE__*/function (KeyVariant) {
|
|
31
|
+
KeyVariant[KeyVariant["RSA_SSA_PKCS1_v1_5"] = 0] = "RSA_SSA_PKCS1_v1_5";
|
|
32
|
+
KeyVariant[KeyVariant["RSA_PSS"] = 1] = "RSA_PSS";
|
|
33
|
+
KeyVariant[KeyVariant["RSA_OAEP"] = 2] = "RSA_OAEP";
|
|
34
|
+
KeyVariant[KeyVariant["DSA"] = 3] = "DSA";
|
|
35
|
+
KeyVariant[KeyVariant["EC"] = 4] = "EC";
|
|
36
|
+
KeyVariant[KeyVariant["NID"] = 5] = "NID";
|
|
37
|
+
KeyVariant[KeyVariant["DH"] = 6] = "DH";
|
|
38
|
+
return KeyVariant;
|
|
39
|
+
}({});
|
|
2
40
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["utils/types.ts"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["KFormatType","exports","KeyType","KeyEncoding","KeyVariant"],"sourceRoot":"../../../src","sources":["utils/types.ts"],"mappings":";;;;;;AAEyC;AAiHzC;AACA;AAAA,IACYA,WAAW,GAAAC,OAAA,CAAAD,WAAA,0BAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA,OAMvB;AAAA,IACYE,OAAO,GAAAD,OAAA,CAAAC,OAAA,0BAAPA,OAAO;EAAPA,OAAO,CAAPA,OAAO;EAAPA,OAAO,CAAPA,OAAO;EAAPA,OAAO,CAAPA,OAAO;EAAA,OAAPA,OAAO;AAAA;AAAA,IAMPC,WAAW,GAAAF,OAAA,CAAAE,WAAA,0BAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA,OAwGvB;AACA;AAAA,IA2BYC,UAAU,GAAAH,OAAA,CAAAG,UAAA,0BAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isStringOrBuffer = isStringOrBuffer;
|
|
7
|
+
exports.validateFunction = validateFunction;
|
|
8
|
+
exports.validateObject = validateObject;
|
|
9
|
+
function validateFunction(f) {
|
|
10
|
+
return f !== null && typeof f === 'function';
|
|
11
|
+
}
|
|
12
|
+
function isStringOrBuffer(val) {
|
|
13
|
+
return typeof val === 'string' || ArrayBuffer.isView(val) || val instanceof ArrayBuffer;
|
|
14
|
+
}
|
|
15
|
+
function validateObject(value, name, options) {
|
|
16
|
+
const useDefaultOptions = options == null;
|
|
17
|
+
const allowArray = useDefaultOptions ? false : options.allowArray;
|
|
18
|
+
const allowFunction = useDefaultOptions ? false : options.allowFunction;
|
|
19
|
+
const nullable = useDefaultOptions ? false : options.nullable;
|
|
20
|
+
if (!nullable && value === null || !allowArray && Array.isArray(value) || typeof value !== 'object' && (!allowFunction || typeof value !== 'function')) {
|
|
21
|
+
throw new Error(`${name} is not a valid object $${value}`);
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["validateFunction","f","isStringOrBuffer","val","ArrayBuffer","isView","validateObject","value","name","options","useDefaultOptions","allowArray","allowFunction","nullable","Array","isArray","Error"],"sourceRoot":"../../../src","sources":["utils/validation.ts"],"mappings":";;;;;;;;AAAO,SAASA,gBAAgBA,CAACC,CAAU,EAAW;EACpD,OAAOA,CAAC,KAAK,IAAI,IAAI,OAAOA,CAAC,KAAK,UAAU;AAC9C;AAEO,SAASC,gBAAgBA,CAACC,GAAY,EAA+B;EAC1E,OACE,OAAOA,GAAG,KAAK,QAAQ,IACvBC,WAAW,CAACC,MAAM,CAACF,GAAG,CAAC,IACvBA,GAAG,YAAYC,WAAW;AAE9B;AAEO,SAASE,cAAcA,CAC5BC,KAAc,EACdC,IAAY,EACZC,OAIQ,EACI;EACZ,MAAMC,iBAAiB,GAAGD,OAAO,IAAI,IAAI;EACzC,MAAME,UAAU,GAAGD,iBAAiB,GAAG,KAAK,GAAGD,OAAO,CAACE,UAAU;EACjE,MAAMC,aAAa,GAAGF,iBAAiB,GAAG,KAAK,GAAGD,OAAO,CAACG,aAAa;EACvE,MAAMC,QAAQ,GAAGH,iBAAiB,GAAG,KAAK,GAAGD,OAAO,CAACI,QAAQ;EAC7D,IACG,CAACA,QAAQ,IAAIN,KAAK,KAAK,IAAI,IAC3B,CAACI,UAAU,IAAIG,KAAK,CAACC,OAAO,CAACR,KAAK,CAAE,IACpC,OAAOA,KAAK,KAAK,QAAQ,KACvB,CAACK,aAAa,IAAI,OAAOL,KAAK,KAAK,UAAU,CAAE,EAClD;IACA,MAAM,IAAIS,KAAK,CAAC,GAAGR,IAAI,2BAA2BD,KAAK,EAAE,CAAC;EAC5D;EACA,OAAO,IAAI;AACb","ignoreList":[]}
|
package/lib/module/ed.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
4
|
+
import { binaryLikeToArrayBuffer as toAB } from './utils';
|
|
5
|
+
export class Ed {
|
|
6
|
+
constructor(type, config) {
|
|
7
|
+
this.type = type;
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.native = NitroModules.createHybridObject('EdKeyPair');
|
|
10
|
+
this.native.setCurve(type);
|
|
11
|
+
}
|
|
12
|
+
async generateKeyPair() {
|
|
13
|
+
this.native.generateKeyPair(this.config.publicFormat || -1, this.config.publicType || -1, this.config.privateFormat || -1, this.config.privateType || -1, this.config.cipher, this.config.passphrase);
|
|
14
|
+
}
|
|
15
|
+
generateKeyPairSync() {
|
|
16
|
+
this.native.generateKeyPairSync(this.config.publicFormat || -1, this.config.publicType || -1, this.config.privateFormat || -1, this.config.privateType || -1, this.config.cipher, this.config.passphrase);
|
|
17
|
+
}
|
|
18
|
+
getPublicKey() {
|
|
19
|
+
return this.native.getPublicKey();
|
|
20
|
+
}
|
|
21
|
+
getPrivateKey() {
|
|
22
|
+
return this.native.getPrivateKey();
|
|
23
|
+
}
|
|
24
|
+
async sign(message, key) {
|
|
25
|
+
return key ? this.native.sign(toAB(message), toAB(key)) : this.native.sign(toAB(message));
|
|
26
|
+
}
|
|
27
|
+
signSync(message, key) {
|
|
28
|
+
return key ? this.native.signSync(toAB(message), toAB(key)) : this.native.signSync(toAB(message));
|
|
29
|
+
}
|
|
30
|
+
async verify(signature, message, key) {
|
|
31
|
+
return key ? this.native.verify(toAB(signature), toAB(message), toAB(key)) : this.native.verify(toAB(signature), toAB(message));
|
|
32
|
+
}
|
|
33
|
+
verifySync(signature, message, key) {
|
|
34
|
+
return key ? this.native.verifySync(toAB(signature), toAB(message), toAB(key)) : this.native.verifySync(toAB(signature), toAB(message));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=ed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NitroModules","binaryLikeToArrayBuffer","toAB","Ed","constructor","type","config","native","createHybridObject","setCurve","generateKeyPair","publicFormat","publicType","privateFormat","privateType","cipher","passphrase","generateKeyPairSync","getPublicKey","getPrivateKey","sign","message","key","signSync","verify","signature","verifySync"],"sourceRoot":"../../src","sources":["ed.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AACzD,SAASC,uBAAuB,IAAIC,IAAI,QAAQ,SAAS;AAIzD,OAAO,MAAMC,EAAE,CAAC;EAKdC,WAAWA,CAACC,IAAqB,EAAEC,MAAwB,EAAE;IAC3D,IAAI,CAACD,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,MAAM,GAAGP,YAAY,CAACQ,kBAAkB,CAAY,WAAW,CAAC;IACrE,IAAI,CAACD,MAAM,CAACE,QAAQ,CAACJ,IAAI,CAAC;EAC5B;EAEA,MAAMK,e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OA,GAAG,GACN,IAAI,CAACf,MAAM,CAACgB,QAAQ,CAACrB,IAAI,CAACmB,OAAO,CAAC,EAAEnB,IAAI,CAACoB,GAAG,CAAC,CAAC,GAC9C,IAAI,CAACf,MAAM,CAACgB,QAAQ,CAACrB,IAAI,CAACmB,OAAO,CAAC,CAAC;EACzC;EAEA,MAAMG,MAAMA,CACVC,SAAqB,EACrBJ,OAAmB,EACnBC,GAAgB,EACE;IAClB,OAAOA,GAAG,GACN,IAAI,CAACf,MAAM,CAACiB,MAAM,CAACtB,IAAI,CAACuB,SAAS,CAAC,EAAEvB,IAAI,CAACmB,OAAO,CAAC,EAAEnB,IAAI,CAACoB,GAAG,CAAC,CAAC,GAC7D,IAAI,CAACf,MAAM,CAACiB,MAAM,CAACtB,IAAI,CAACuB,SAAS,CAAC,EAAEvB,IAAI,CAACmB,OAAO,CAAC,CAAC;EACxD;EAEAK,UAAUA,CACRD,SAAqB,EACrBJ,OAAmB,EACnBC,GAAgB,EACP;IACT,OAAOA,GAAG,GACN,IAAI,CAACf,MAAM,CAACmB,UAAU,CAACxB,IAAI,CAACuB,SAAS,CAAC,EAAEvB,IAAI,CAACmB,OAAO,CAAC,EAAEnB,IAAI,CAACoB,GAAG,CAAC,CAAC,GACjE,IAAI,CAACf,MAAM,CAACmB,UAAU,CAACxB,IAAI,CAACuB,SAAS,CAAC,EAAEvB,IAAI,CAACmB,OAAO,CAAC,CAAC;EAC5D;AACF","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -4,10 +4,13 @@
|
|
|
4
4
|
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
5
5
|
|
|
6
6
|
// API imports
|
|
7
|
+
import * as keys from './keys';
|
|
8
|
+
import * as ed from './ed';
|
|
9
|
+
import * as pbkdf2 from './pbkdf2';
|
|
7
10
|
import * as random from './random';
|
|
8
11
|
|
|
9
12
|
// utils import
|
|
10
|
-
import
|
|
13
|
+
import * as utils from './utils';
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* Loosely matches Node.js {crypto} with some unimplemented functionality.
|
|
@@ -22,30 +25,28 @@ const QuickCrypto = {
|
|
|
22
25
|
// createCipheriv,
|
|
23
26
|
// createDecipher,
|
|
24
27
|
// createDecipheriv,
|
|
25
|
-
// createPublicKey,
|
|
26
|
-
// createPrivateKey,
|
|
27
|
-
// createSecretKey,
|
|
28
28
|
// publicEncrypt,
|
|
29
29
|
// publicDecrypt,
|
|
30
30
|
// privateDecrypt,
|
|
31
31
|
// generateKey,
|
|
32
|
-
// generateKeyPair,
|
|
33
|
-
// generateKeyPairSync,
|
|
34
32
|
// generateKeySync,
|
|
35
33
|
// createSign,
|
|
36
34
|
// createVerify,
|
|
37
35
|
// subtle,
|
|
38
36
|
// constants,
|
|
39
|
-
|
|
37
|
+
...keys,
|
|
38
|
+
...ed,
|
|
39
|
+
...pbkdf2,
|
|
40
40
|
...random,
|
|
41
41
|
// getCiphers,
|
|
42
42
|
// getHashes,
|
|
43
43
|
// webcrypto,
|
|
44
|
-
utils
|
|
44
|
+
...utils
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* Optional. Patch global.crypto with
|
|
48
|
+
* Optional. Patch global.crypto with react-native-quick-crypto and
|
|
49
|
+
* global.Buffer with react-native-buffer.
|
|
49
50
|
*/
|
|
50
51
|
export const install = () => {
|
|
51
52
|
// @ts-expect-error copyBytesFrom and poolSizets are missing from react-native-buffer
|
|
@@ -57,7 +58,13 @@ export const install = () => {
|
|
|
57
58
|
|
|
58
59
|
// random, cipher, hash use nextTick
|
|
59
60
|
global.process.nextTick = setImmediate;
|
|
61
|
+
|
|
62
|
+
// exports
|
|
60
63
|
export default QuickCrypto;
|
|
64
|
+
export * from './ed';
|
|
65
|
+
export * from './pbkdf2';
|
|
66
|
+
export * from './random';
|
|
67
|
+
export * from './utils';
|
|
61
68
|
|
|
62
69
|
// Additional exports for CommonJS compatibility
|
|
63
70
|
module.exports = QuickCrypto;
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Buffer","random","utils","QuickCrypto","install","global","crypto","process","nextTick","setImmediate","module","exports","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA,SAASA,MAAM,QAAQ,gCAAgC;;AAEvD;AACA,OAAO,KAAKC,MAAM,MAAM,UAAU;;AAElC;AACA,
|
|
1
|
+
{"version":3,"names":["Buffer","keys","ed","pbkdf2","random","utils","QuickCrypto","install","global","crypto","process","nextTick","setImmediate","module","exports","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA,SAASA,MAAM,QAAQ,gCAAgC;;AAEvD;AACA,OAAO,KAAKC,IAAI,MAAM,QAAQ;AAC9B,OAAO,KAAKC,EAAE,MAAM,MAAM;AAC1B,OAAO,KAAKC,MAAM,MAAM,UAAU;AAClC,OAAO,KAAKC,MAAM,MAAM,UAAU;;AAElC;AACA,OAAO,KAAKC,KAAK,MAAM,SAAS;;AAEhC;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAG;EAClB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,GAAGL,IAAI;EACP,GAAGC,EAAE;EACL,GAAGC,MAAM;EACT,GAAGC,MAAM;EACT;EACA;EACA;EACA,GAAGC;AACL,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,MAAME,OAAO,GAAGA,CAAA,KAAM;EAC3B;EACAC,MAAM,CAACR,MAAM,GAAGA,MAAM;;EAEtB;EACAQ,MAAM,CAACC,MAAM,GAAGH,WAAW;AAC7B,CAAC;;AAED;AACAE,MAAM,CAACE,OAAO,CAACC,QAAQ,GAAGC,YAAY;;AAEtC;AACA,eAAeN,WAAW;AAC1B,cAAc,MAAM;AACpB,cAAc,UAAU;AACxB,cAAc,UAAU;AACxB,cAAc,SAAS;;AAEvB;AACAO,MAAM,CAACC,OAAO,GAAGR,WAAW;AAC5BO,MAAM,CAACC,OAAO,CAACC,OAAO,GAAGT,WAAW;AACpCO,MAAM,CAACC,OAAO,CAACP,OAAO,GAAGA,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { parsePrivateKeyEncoding, parsePublicKeyEncoding } from './utils';
|
|
4
|
+
export class CryptoKey {
|
|
5
|
+
constructor(keyObject, keyAlgorithm, keyUsages, keyExtractable) {
|
|
6
|
+
this.keyObject = keyObject;
|
|
7
|
+
this.keyAlgorithm = keyAlgorithm;
|
|
8
|
+
this.keyUsages = keyUsages;
|
|
9
|
+
this.keyExtractable = keyExtractable;
|
|
10
|
+
}
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
+
inspect(_depth, _options) {
|
|
13
|
+
throw new Error('CryptoKey.inspect is not implemented');
|
|
14
|
+
// if (depth < 0) return this;
|
|
15
|
+
|
|
16
|
+
// const opts = {
|
|
17
|
+
// ...options,
|
|
18
|
+
// depth: options.depth == null ? null : options.depth - 1,
|
|
19
|
+
// };
|
|
20
|
+
|
|
21
|
+
// return `CryptoKey ${inspect(
|
|
22
|
+
// {
|
|
23
|
+
// type: this.type,
|
|
24
|
+
// extractable: this.extractable,
|
|
25
|
+
// algorithm: this.algorithm,
|
|
26
|
+
// usages: this.usages,
|
|
27
|
+
// },
|
|
28
|
+
// opts
|
|
29
|
+
// )}`;
|
|
30
|
+
}
|
|
31
|
+
get type() {
|
|
32
|
+
// if (!(this instanceof CryptoKey)) throw new Error('Invalid CryptoKey');
|
|
33
|
+
return this.keyObject.type;
|
|
34
|
+
}
|
|
35
|
+
get extractable() {
|
|
36
|
+
return this.keyExtractable;
|
|
37
|
+
}
|
|
38
|
+
get algorithm() {
|
|
39
|
+
return this.keyAlgorithm;
|
|
40
|
+
}
|
|
41
|
+
get usages() {
|
|
42
|
+
return this.keyUsages;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export class KeyObject {
|
|
46
|
+
type = 'unknown';
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
48
|
+
export(_options) {
|
|
49
|
+
return new ArrayBuffer(0);
|
|
50
|
+
}
|
|
51
|
+
constructor(type, handle) {
|
|
52
|
+
if (type !== 'secret' && type !== 'public' && type !== 'private') throw new Error(`invalid KeyObject type: ${type}`);
|
|
53
|
+
this.handle = handle;
|
|
54
|
+
this.type = type;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// get type(): string {
|
|
58
|
+
// return this.type;
|
|
59
|
+
// }
|
|
60
|
+
|
|
61
|
+
// static from(key) {
|
|
62
|
+
// if (!isCryptoKey(key))
|
|
63
|
+
// throw new ERR_INVALID_ARG_TYPE('key', 'CryptoKey', key);
|
|
64
|
+
// return key[kKeyObject];
|
|
65
|
+
// }
|
|
66
|
+
|
|
67
|
+
// equals(otherKeyObject) {
|
|
68
|
+
// if (!isKeyObject(otherKeyObject)) {
|
|
69
|
+
// throw new ERR_INVALID_ARG_TYPE(
|
|
70
|
+
// 'otherKeyObject',
|
|
71
|
+
// 'KeyObject',
|
|
72
|
+
// otherKeyObject
|
|
73
|
+
// );
|
|
74
|
+
// }
|
|
75
|
+
|
|
76
|
+
// return (
|
|
77
|
+
// otherKeyObject.type === this.type &&
|
|
78
|
+
// this[kHandle].equals(otherKeyObject[kHandle])
|
|
79
|
+
// );
|
|
80
|
+
// }
|
|
81
|
+
}
|
|
82
|
+
export class SecretKeyObject extends KeyObject {
|
|
83
|
+
constructor(handle) {
|
|
84
|
+
super('secret', handle);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// get symmetricKeySize() {
|
|
88
|
+
// return this[kHandle].getSymmetricKeySize();
|
|
89
|
+
// }
|
|
90
|
+
|
|
91
|
+
export(options) {
|
|
92
|
+
if (options !== undefined) {
|
|
93
|
+
if (options.format === 'jwk') {
|
|
94
|
+
throw new Error('SecretKey export for jwk is not implemented');
|
|
95
|
+
// return this.handle.exportJwk({}, false);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return this.handle.exportKey();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// const kAsymmetricKeyType = Symbol('kAsymmetricKeyType');
|
|
103
|
+
// const kAsymmetricKeyDetails = Symbol('kAsymmetricKeyDetails');
|
|
104
|
+
|
|
105
|
+
// function normalizeKeyDetails(details = {}) {
|
|
106
|
+
// if (details.publicExponent !== undefined) {
|
|
107
|
+
// return {
|
|
108
|
+
// ...details,
|
|
109
|
+
// publicExponent: bigIntArrayToUnsignedBigInt(
|
|
110
|
+
// new Uint8Array(details.publicExponent)
|
|
111
|
+
// ),
|
|
112
|
+
// };
|
|
113
|
+
// }
|
|
114
|
+
// return details;
|
|
115
|
+
// }
|
|
116
|
+
|
|
117
|
+
export class AsymmetricKeyObject extends KeyObject {
|
|
118
|
+
constructor(type, handle) {
|
|
119
|
+
super(type, handle);
|
|
120
|
+
}
|
|
121
|
+
get asymmetricKeyType() {
|
|
122
|
+
if (!this._asymmetricKeyType) {
|
|
123
|
+
this._asymmetricKeyType = this.handle.getAsymmetricKeyType();
|
|
124
|
+
}
|
|
125
|
+
return this._asymmetricKeyType;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// get asymmetricKeyDetails() {
|
|
129
|
+
// switch (this._asymmetricKeyType) {
|
|
130
|
+
// case 'rsa':
|
|
131
|
+
// case 'rsa-pss':
|
|
132
|
+
// case 'dsa':
|
|
133
|
+
// case 'ec':
|
|
134
|
+
// return (
|
|
135
|
+
// this[kAsymmetricKeyDetails] ||
|
|
136
|
+
// (this[kAsymmetricKeyDetails] = normalizeKeyDetails(
|
|
137
|
+
// this[kHandle].keyDetail({})
|
|
138
|
+
// ))
|
|
139
|
+
// );
|
|
140
|
+
// default:
|
|
141
|
+
// return {};
|
|
142
|
+
// }
|
|
143
|
+
// }
|
|
144
|
+
}
|
|
145
|
+
export class PublicKeyObject extends AsymmetricKeyObject {
|
|
146
|
+
constructor(handle) {
|
|
147
|
+
super('public', handle);
|
|
148
|
+
}
|
|
149
|
+
export(options) {
|
|
150
|
+
if (options?.format === 'jwk') {
|
|
151
|
+
throw new Error('PublicKey export for jwk is not implemented');
|
|
152
|
+
// return this.handle.exportJwk({}, false);
|
|
153
|
+
}
|
|
154
|
+
const {
|
|
155
|
+
format,
|
|
156
|
+
type
|
|
157
|
+
} = parsePublicKeyEncoding(options, this.asymmetricKeyType);
|
|
158
|
+
return this.handle.exportKey(format, type);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
export class PrivateKeyObject extends AsymmetricKeyObject {
|
|
162
|
+
constructor(handle) {
|
|
163
|
+
super('private', handle);
|
|
164
|
+
}
|
|
165
|
+
export(options) {
|
|
166
|
+
if (options?.format === 'jwk') {
|
|
167
|
+
if (options.passphrase !== undefined) {
|
|
168
|
+
throw new Error('jwk does not support encryption');
|
|
169
|
+
}
|
|
170
|
+
throw new Error('PrivateKey export for jwk is not implemented');
|
|
171
|
+
// return this.handle.exportJwk({}, false);
|
|
172
|
+
}
|
|
173
|
+
const {
|
|
174
|
+
format,
|
|
175
|
+
type,
|
|
176
|
+
cipher,
|
|
177
|
+
passphrase
|
|
178
|
+
} = parsePrivateKeyEncoding(options, this.asymmetricKeyType);
|
|
179
|
+
return this.handle.exportKey(format, type, cipher, passphrase);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=classes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["parsePrivateKeyEncoding","parsePublicKeyEncoding","CryptoKey","constructor","keyObject","keyAlgorithm","keyUsages","keyExtractable","inspect","_depth","_options","Error","type","extractable","algorithm","usages","KeyObject","export","ArrayBuffer","handle","SecretKeyObject","options","undefined","format","exportKey","AsymmetricKeyObject","asymmetricKeyType","_asymmetricKeyType","getAsymmetricKeyType","PublicKeyObject","PrivateKeyObject","passphrase","cipher"],"sourceRoot":"../../../src","sources":["keys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C7B,MAAM,IAAIZ,KAAK,CAAC,6CAA6C,CAAC;MAC9D;IACF;IACA,MAAM;MAAEY,MAAM;MAAEX;IAAK,CAAC,GAAGX,sBAAsB,CAC7CoB,OAAO,EACP,IAAI,CAACK,iBACP,CAAC;IACD,OAAO,IAAI,CAACP,MAAM,CAACK,SAAS,CAACD,MAAM,EAAEX,IAAI,CAAC;EAC5C;AACF;AAEA,OAAO,MAAMkB,gBAAgB,SAASL,mBAAmB,CAAC;EACxDtB,WAAWA,CAACgB,MAAuB,EAAE;IACnC,KAAK,CAAC,SAAS,EAAEA,MAAM,CAAC;EAC1B;EAEAF,MAAMA,CAACI,OAAwB,EAAE;IAC/B,IAAIA,OAAO,EAAEE,MAAM,KAAK,KAAK,EAAE;MAC7B,IAAIF,OAAO,CAACU,UAAU,KAAKT,SAAS,EAAE;QACpC,MAAM,IAAIX,KAAK,CAAC,iCAAiC,CAAC;MACpD;MACA,MAAM,IAAIA,KAAK,CAAC,8CAA8C,CAAC;MAC/D;IACF;IACA,MAAM;MAAEY,MAAM;MAAEX,IAAI;MAAEoB,MAAM;MAAED;IAAW,CAAC,GAAG/B,uBAAuB,CAClEqB,OAAO,EACP,IAAI,CAACK,iBACP,CAAC;IACD,OAAO,IAAI,CAACP,MAAM,CAACK,SAAS,CAACD,MAAM,EAAEX,IAAI,EAAEoB,MAAM,EAAED,UAAU,CAAC;EAChE;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// import { ed25519 } from '../ed25519';
|
|
2
|
+
// import {
|
|
3
|
+
// kEmptyObject,
|
|
4
|
+
// validateFunction,
|
|
5
|
+
// type CryptoKeyPair,
|
|
6
|
+
// type GenerateKeyPairCallback,
|
|
7
|
+
// type GenerateKeyPairOptions,
|
|
8
|
+
// type GenerateKeyPairPromiseReturn,
|
|
9
|
+
// type GenerateKeyPairReturn,
|
|
10
|
+
// type KeyPairGenConfig,
|
|
11
|
+
// type KeyPairType,
|
|
12
|
+
// } from '../utils';
|
|
13
|
+
// import { parsePrivateKeyEncoding, parsePublicKeyEncoding } from './utils';
|
|
14
|
+
|
|
15
|
+
// export const generateKeyPair = (
|
|
16
|
+
// type: KeyPairType,
|
|
17
|
+
// options: GenerateKeyPairOptions,
|
|
18
|
+
// callback: GenerateKeyPairCallback,
|
|
19
|
+
// ): void => {
|
|
20
|
+
// validateFunction(callback);
|
|
21
|
+
// internalGenerateKeyPair(true, type, options, callback);
|
|
22
|
+
// };
|
|
23
|
+
|
|
24
|
+
// // Promisify generateKeyPair
|
|
25
|
+
// // (attempted to use util.promisify, to no avail)
|
|
26
|
+
// export const generateKeyPairPromise = (
|
|
27
|
+
// type: KeyPairType,
|
|
28
|
+
// options: GenerateKeyPairOptions,
|
|
29
|
+
// ): Promise<GenerateKeyPairPromiseReturn> => {
|
|
30
|
+
// return new Promise((resolve, reject) => {
|
|
31
|
+
// generateKeyPair(type, options, (err, publicKey, privateKey) => {
|
|
32
|
+
// if (err) {
|
|
33
|
+
// reject([err, undefined]);
|
|
34
|
+
// } else {
|
|
35
|
+
// resolve([undefined, { publicKey, privateKey }]);
|
|
36
|
+
// }
|
|
37
|
+
// });
|
|
38
|
+
// });
|
|
39
|
+
// };
|
|
40
|
+
|
|
41
|
+
// // generateKeyPairSync
|
|
42
|
+
// export function generateKeyPairSync(type: KeyPairType): CryptoKeyPair;
|
|
43
|
+
// export function generateKeyPairSync(
|
|
44
|
+
// type: KeyPairType,
|
|
45
|
+
// options: GenerateKeyPairOptions,
|
|
46
|
+
// ): CryptoKeyPair;
|
|
47
|
+
// export function generateKeyPairSync(
|
|
48
|
+
// type: KeyPairType,
|
|
49
|
+
// options?: GenerateKeyPairOptions,
|
|
50
|
+
// ): CryptoKeyPair {
|
|
51
|
+
// const [err, publicKey, privateKey] = internalGenerateKeyPair(
|
|
52
|
+
// false,
|
|
53
|
+
// type,
|
|
54
|
+
// options,
|
|
55
|
+
// undefined,
|
|
56
|
+
// )!;
|
|
57
|
+
|
|
58
|
+
// if (err) {
|
|
59
|
+
// throw err;
|
|
60
|
+
// }
|
|
61
|
+
|
|
62
|
+
// return {
|
|
63
|
+
// publicKey,
|
|
64
|
+
// privateKey,
|
|
65
|
+
// };
|
|
66
|
+
// }
|
|
67
|
+
|
|
68
|
+
// function parseKeyPairEncoding(
|
|
69
|
+
// keyType: string,
|
|
70
|
+
// options: GenerateKeyPairOptions = kEmptyObject,
|
|
71
|
+
// ): KeyPairGenConfig {
|
|
72
|
+
// const { publicKeyEncoding, privateKeyEncoding } = options;
|
|
73
|
+
|
|
74
|
+
// let publicFormat, publicType;
|
|
75
|
+
// if (publicKeyEncoding == null) {
|
|
76
|
+
// publicFormat = publicType = -1;
|
|
77
|
+
// } else if (typeof publicKeyEncoding === 'object') {
|
|
78
|
+
// ({ format: publicFormat, type: publicType } = parsePublicKeyEncoding(
|
|
79
|
+
// publicKeyEncoding,
|
|
80
|
+
// keyType,
|
|
81
|
+
// 'publicKeyEncoding',
|
|
82
|
+
// ));
|
|
83
|
+
// } else {
|
|
84
|
+
// throw new Error(
|
|
85
|
+
// 'Invalid argument options.publicKeyEncoding',
|
|
86
|
+
// publicKeyEncoding,
|
|
87
|
+
// );
|
|
88
|
+
// }
|
|
89
|
+
|
|
90
|
+
// let privateFormat, privateType, cipher, passphrase;
|
|
91
|
+
// if (privateKeyEncoding == null) {
|
|
92
|
+
// privateFormat = privateType = -1;
|
|
93
|
+
// } else if (typeof privateKeyEncoding === 'object') {
|
|
94
|
+
// ({
|
|
95
|
+
// format: privateFormat,
|
|
96
|
+
// type: privateType,
|
|
97
|
+
// cipher,
|
|
98
|
+
// passphrase,
|
|
99
|
+
// } = parsePrivateKeyEncoding(
|
|
100
|
+
// privateKeyEncoding,
|
|
101
|
+
// keyType,
|
|
102
|
+
// 'privateKeyEncoding',
|
|
103
|
+
// ));
|
|
104
|
+
// } else {
|
|
105
|
+
// throw new Error(
|
|
106
|
+
// 'Invalid argument options.privateKeyEncoding',
|
|
107
|
+
// publicKeyEncoding as ErrorOptions,
|
|
108
|
+
// );
|
|
109
|
+
// }
|
|
110
|
+
|
|
111
|
+
// return {
|
|
112
|
+
// publicFormat,
|
|
113
|
+
// publicType,
|
|
114
|
+
// privateFormat,
|
|
115
|
+
// privateType,
|
|
116
|
+
// cipher,
|
|
117
|
+
// passphrase,
|
|
118
|
+
// };
|
|
119
|
+
// }
|
|
120
|
+
|
|
121
|
+
// function internalGenerateKeyPair(
|
|
122
|
+
// isAsync: boolean,
|
|
123
|
+
// type: KeyPairType,
|
|
124
|
+
// options: GenerateKeyPairOptions | undefined,
|
|
125
|
+
// callback: GenerateKeyPairCallback | undefined,
|
|
126
|
+
// ): GenerateKeyPairReturn | void {
|
|
127
|
+
// const encoding = parseKeyPairEncoding(type, options);
|
|
128
|
+
|
|
129
|
+
// switch (type) {
|
|
130
|
+
// case 'ed25519':
|
|
131
|
+
// case 'ed448':
|
|
132
|
+
// case 'x25519':
|
|
133
|
+
// case 'x448': {
|
|
134
|
+
// return ed25519.utils.generateKeyPair(isAsync, type, encoding, callback);
|
|
135
|
+
// }
|
|
136
|
+
// default:
|
|
137
|
+
// // Fall through
|
|
138
|
+
// }
|
|
139
|
+
|
|
140
|
+
// const err = new Error(`
|
|
141
|
+
// Invalid Argument options: '${type}' scheme not supported for
|
|
142
|
+
// generateKeyPair(). Currently not all encryption methods are supported in
|
|
143
|
+
// this library. Check docs/implementation_coverage.md for status.
|
|
144
|
+
// `);
|
|
145
|
+
// return [err, undefined, undefined];
|
|
146
|
+
// }
|
|
147
|
+
"use strict";
|
|
148
|
+
//# sourceMappingURL=generateKeyPair.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["keys/generateKeyPair.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;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;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;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;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { CryptoKey, KeyObject, SecretKeyObject, PublicKeyObject, PrivateKeyObject } from './classes';
|
|
4
|
+
// import { generateKeyPair } from './generateKeyPair';
|
|
5
|
+
// import { sign, verify } from './signVerify';
|
|
6
|
+
import { isCryptoKey, parseKeyEncoding, parsePrivateKeyEncoding, parsePublicKeyEncoding } from './utils';
|
|
7
|
+
export {
|
|
8
|
+
// Node Public API
|
|
9
|
+
// createSecretKey,
|
|
10
|
+
// createPublicKey,
|
|
11
|
+
// createPrivateKey,
|
|
12
|
+
CryptoKey,
|
|
13
|
+
// generateKeyPair,
|
|
14
|
+
KeyObject,
|
|
15
|
+
// InternalCryptoKey,
|
|
16
|
+
// sign,
|
|
17
|
+
// verify,
|
|
18
|
+
|
|
19
|
+
// Node Internal API
|
|
20
|
+
parsePublicKeyEncoding, parsePrivateKeyEncoding, parseKeyEncoding,
|
|
21
|
+
// preparePrivateKey,
|
|
22
|
+
// preparePublicOrPrivateKey,
|
|
23
|
+
// prepareSecretKey,
|
|
24
|
+
SecretKeyObject, PublicKeyObject, PrivateKeyObject,
|
|
25
|
+
// isKeyObject,
|
|
26
|
+
isCryptoKey
|
|
27
|
+
// importGenericSecretKey,
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CryptoKey","KeyObject","SecretKeyObject","PublicKeyObject","PrivateKeyObject","isCryptoKey","parseKeyEncoding","parsePrivateKeyEncoding","parsePublicKeyEncoding"],"sourceRoot":"../../../src","sources":["keys/index.ts"],"mappings":";;AAAA,SACEA,SAAS,EACTC,SAAS,EACTC,eAAe,EACfC,eAAe,EACfC,gBAAgB,QACX,WAAW;AAClB;AACA;AACA,SACEC,WAAW,EACXC,gBAAgB,EAChBC,uBAAuB,EACvBC,sBAAsB,QACjB,SAAS;AAEhB;AACE;AACA;AACA;AACA;AACAR,SAAS;AACT;AACAC,SAAS;AACT;AACA;AACA;;AAEA;AACAO,sBAAsB,EACtBD,uBAAuB,EACvBD,gBAAgB;AAChB;AACA;AACA;AACAJ,eAAe,EACfC,eAAe,EACfC,gBAAgB;AAChB;AACAC;AACA;AAAA","ignoreList":[]}
|