react-native-quick-crypto 1.0.9 → 1.0.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 +9 -2
- package/README.md +13 -9
- package/android/CMakeLists.txt +4 -0
- package/cpp/cipher/HybridCipherFactory.hpp +15 -1
- package/cpp/cipher/OCBCipher.cpp +4 -4
- package/cpp/cipher/XChaCha20Poly1305Cipher.cpp +161 -0
- package/cpp/cipher/XChaCha20Poly1305Cipher.hpp +43 -0
- package/cpp/cipher/XSalsa20Poly1305Cipher.cpp +145 -0
- package/cpp/cipher/XSalsa20Poly1305Cipher.hpp +42 -0
- package/cpp/dh/HybridDiffieHellman.cpp +10 -0
- package/cpp/dh/HybridDiffieHellman.hpp +1 -0
- package/cpp/ec/HybridEcKeyPair.cpp +21 -0
- package/cpp/ec/HybridEcKeyPair.hpp +1 -0
- package/cpp/hash/HybridHash.cpp +1 -1
- package/cpp/hash/HybridHash.hpp +1 -1
- package/cpp/hmac/HybridHmac.cpp +1 -1
- package/cpp/hmac/HybridHmac.hpp +1 -1
- package/cpp/keys/HybridKeyObjectHandle.cpp +112 -1
- package/cpp/keys/HybridKeyObjectHandle.hpp +5 -1
- package/deps/ncrypto/.bazelrc +0 -1
- package/deps/ncrypto/.bazelversion +1 -1
- package/deps/ncrypto/.github/workflows/commitlint.yml +16 -0
- package/deps/ncrypto/.github/workflows/linter.yml +2 -2
- package/deps/ncrypto/.github/workflows/release-please.yml +16 -0
- package/deps/ncrypto/.github/workflows/ubuntu.yml +82 -0
- package/deps/ncrypto/.release-please-manifest.json +3 -0
- package/deps/ncrypto/BUILD.bazel +9 -1
- package/deps/ncrypto/CHANGELOG.md +37 -0
- package/deps/ncrypto/CMakeLists.txt +35 -11
- package/deps/ncrypto/MODULE.bazel +16 -1
- package/deps/ncrypto/MODULE.bazel.lock +299 -118
- package/deps/ncrypto/cmake/ncrypto-flags.cmake +1 -0
- package/deps/ncrypto/include/ncrypto/aead.h +137 -0
- package/deps/ncrypto/include/ncrypto/version.h +14 -0
- package/deps/ncrypto/include/ncrypto.h +85 -230
- package/deps/ncrypto/ncrypto.pc.in +10 -0
- package/deps/ncrypto/release-please-config.json +11 -0
- package/deps/ncrypto/src/CMakeLists.txt +31 -6
- package/deps/ncrypto/src/aead.cpp +302 -0
- package/deps/ncrypto/src/ncrypto.cpp +274 -556
- package/deps/ncrypto/tests/BUILD.bazel +2 -0
- package/deps/ncrypto/tests/basic.cpp +772 -2
- package/deps/ncrypto/tools/run-clang-format.sh +5 -5
- package/lib/commonjs/diffie-hellman.js +4 -1
- package/lib/commonjs/diffie-hellman.js.map +1 -1
- package/lib/commonjs/ec.js +20 -25
- package/lib/commonjs/ec.js.map +1 -1
- package/lib/commonjs/ed.js +1 -2
- package/lib/commonjs/ed.js.map +1 -1
- package/lib/commonjs/hash.js +7 -0
- package/lib/commonjs/hash.js.map +1 -1
- package/lib/commonjs/index.js +11 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys/classes.js +9 -5
- package/lib/commonjs/keys/classes.js.map +1 -1
- package/lib/commonjs/subtle.js +82 -31
- package/lib/commonjs/subtle.js.map +1 -1
- package/lib/commonjs/utils/types.js.map +1 -1
- package/lib/module/diffie-hellman.js +4 -0
- package/lib/module/diffie-hellman.js.map +1 -1
- package/lib/module/ec.js +19 -25
- package/lib/module/ec.js.map +1 -1
- package/lib/module/ed.js +1 -2
- package/lib/module/ed.js.map +1 -1
- package/lib/module/hash.js +6 -0
- package/lib/module/hash.js.map +1 -1
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys/classes.js +9 -5
- package/lib/module/keys/classes.js.map +1 -1
- package/lib/module/subtle.js +83 -32
- package/lib/module/subtle.js.map +1 -1
- package/lib/module/utils/types.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/diffie-hellman.d.ts +2 -0
- package/lib/typescript/diffie-hellman.d.ts.map +1 -1
- package/lib/typescript/ec.d.ts +1 -0
- package/lib/typescript/ec.d.ts.map +1 -1
- package/lib/typescript/ed.d.ts.map +1 -1
- package/lib/typescript/hash.d.ts +2 -0
- package/lib/typescript/hash.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +5 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/keys/classes.d.ts +2 -0
- package/lib/typescript/keys/classes.d.ts.map +1 -1
- package/lib/typescript/specs/diffie-hellman.nitro.d.ts +1 -0
- package/lib/typescript/specs/diffie-hellman.nitro.d.ts.map +1 -1
- package/lib/typescript/specs/ecKeyPair.nitro.d.ts +1 -0
- package/lib/typescript/specs/ecKeyPair.nitro.d.ts.map +1 -1
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +2 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -1
- package/lib/typescript/subtle.d.ts.map +1 -1
- package/lib/typescript/utils/types.d.ts +12 -5
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +8 -5
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +1 -1
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +54 -54
- package/nitrogen/generated/android/QuickCryptoOnLoad.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/crypto/QuickCryptoOnLoad.kt +1 -1
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +2 -2
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +1 -1
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +1 -1
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +54 -54
- package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +5 -1
- package/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp +1 -1
- package/nitrogen/generated/shared/c++/CipherArgs.hpp +34 -19
- package/nitrogen/generated/shared/c++/HybridBlake3Spec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridBlake3Spec.hpp +1 -3
- package/nitrogen/generated/shared/c++/HybridCipherFactorySpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCipherFactorySpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCipherSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCipherSpec.hpp +1 -3
- package/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.cpp +2 -1
- package/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.hpp +3 -3
- package/nitrogen/generated/shared/c++/HybridECDHSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridECDHSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.cpp +2 -1
- package/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridHashSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridHashSpec.hpp +2 -4
- package/nitrogen/generated/shared/c++/HybridHkdfSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridHkdfSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridHmacSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridHmacSpec.hpp +3 -4
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +3 -1
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +8 -4
- package/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.hpp +1 -3
- package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.hpp +1 -3
- package/nitrogen/generated/shared/c++/HybridScryptSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridScryptSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridSignHandleSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridSignHandleSpec.hpp +1 -3
- package/nitrogen/generated/shared/c++/HybridUtilsSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUtilsSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.hpp +1 -3
- package/nitrogen/generated/shared/c++/JWK.hpp +84 -68
- package/nitrogen/generated/shared/c++/JWKkty.hpp +5 -1
- package/nitrogen/generated/shared/c++/JWKuse.hpp +1 -1
- package/nitrogen/generated/shared/c++/KFormatType.hpp +1 -1
- package/nitrogen/generated/shared/c++/KeyDetail.hpp +39 -23
- package/nitrogen/generated/shared/c++/KeyEncoding.hpp +1 -1
- package/nitrogen/generated/shared/c++/KeyObject.hpp +21 -5
- package/nitrogen/generated/shared/c++/KeyType.hpp +1 -1
- package/nitrogen/generated/shared/c++/KeyUsage.hpp +1 -1
- package/nitrogen/generated/shared/c++/NamedCurve.hpp +1 -1
- package/package.json +1 -1
- package/src/diffie-hellman.ts +6 -0
- package/src/ec.ts +23 -19
- package/src/ed.ts +1 -2
- package/src/hash.ts +11 -0
- package/src/index.ts +3 -0
- package/src/keys/classes.ts +10 -3
- package/src/specs/diffie-hellman.nitro.ts +1 -0
- package/src/specs/ecKeyPair.nitro.ts +2 -0
- package/src/specs/keyObjectHandle.nitro.ts +2 -0
- package/src/subtle.ts +131 -32
- package/src/utils/types.ts +18 -3
- package/deps/ncrypto/WORKSPACE +0 -15
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// KeyDetail.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -17,6 +17,16 @@
|
|
|
17
17
|
#else
|
|
18
18
|
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
19
|
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
20
30
|
|
|
21
31
|
|
|
22
32
|
|
|
@@ -28,7 +38,7 @@ namespace margelo::nitro::crypto {
|
|
|
28
38
|
/**
|
|
29
39
|
* A struct which can be represented as a JavaScript object (KeyDetail).
|
|
30
40
|
*/
|
|
31
|
-
struct KeyDetail {
|
|
41
|
+
struct KeyDetail final {
|
|
32
42
|
public:
|
|
33
43
|
std::optional<double> length SWIFT_PRIVATE;
|
|
34
44
|
std::optional<double> publicExponent SWIFT_PRIVATE;
|
|
@@ -41,6 +51,9 @@ namespace margelo::nitro::crypto {
|
|
|
41
51
|
public:
|
|
42
52
|
KeyDetail() = default;
|
|
43
53
|
explicit KeyDetail(std::optional<double> length, std::optional<double> publicExponent, std::optional<double> modulusLength, std::optional<std::string> hashAlgorithm, std::optional<std::string> mgf1HashAlgorithm, std::optional<double> saltLength, std::optional<std::string> namedCurve): length(length), publicExponent(publicExponent), modulusLength(modulusLength), hashAlgorithm(hashAlgorithm), mgf1HashAlgorithm(mgf1HashAlgorithm), saltLength(saltLength), namedCurve(namedCurve) {}
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
friend bool operator==(const KeyDetail& lhs, const KeyDetail& rhs) = default;
|
|
44
57
|
};
|
|
45
58
|
|
|
46
59
|
} // namespace margelo::nitro::crypto
|
|
@@ -53,24 +66,24 @@ namespace margelo::nitro {
|
|
|
53
66
|
static inline margelo::nitro::crypto::KeyDetail fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
54
67
|
jsi::Object obj = arg.asObject(runtime);
|
|
55
68
|
return margelo::nitro::crypto::KeyDetail(
|
|
56
|
-
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "length")),
|
|
57
|
-
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "publicExponent")),
|
|
58
|
-
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "modulusLength")),
|
|
59
|
-
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "hashAlgorithm")),
|
|
60
|
-
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "mgf1HashAlgorithm")),
|
|
61
|
-
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "saltLength")),
|
|
62
|
-
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "namedCurve"))
|
|
69
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "length"))),
|
|
70
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "publicExponent"))),
|
|
71
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "modulusLength"))),
|
|
72
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "hashAlgorithm"))),
|
|
73
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mgf1HashAlgorithm"))),
|
|
74
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "saltLength"))),
|
|
75
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "namedCurve")))
|
|
63
76
|
);
|
|
64
77
|
}
|
|
65
78
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::KeyDetail& arg) {
|
|
66
79
|
jsi::Object obj(runtime);
|
|
67
|
-
obj.setProperty(runtime, "length", JSIConverter<std::optional<double>>::toJSI(runtime, arg.length));
|
|
68
|
-
obj.setProperty(runtime, "publicExponent", JSIConverter<std::optional<double>>::toJSI(runtime, arg.publicExponent));
|
|
69
|
-
obj.setProperty(runtime, "modulusLength", JSIConverter<std::optional<double>>::toJSI(runtime, arg.modulusLength));
|
|
70
|
-
obj.setProperty(runtime, "hashAlgorithm", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.hashAlgorithm));
|
|
71
|
-
obj.setProperty(runtime, "mgf1HashAlgorithm", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.mgf1HashAlgorithm));
|
|
72
|
-
obj.setProperty(runtime, "saltLength", JSIConverter<std::optional<double>>::toJSI(runtime, arg.saltLength));
|
|
73
|
-
obj.setProperty(runtime, "namedCurve", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.namedCurve));
|
|
80
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "length"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.length));
|
|
81
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "publicExponent"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.publicExponent));
|
|
82
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "modulusLength"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.modulusLength));
|
|
83
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "hashAlgorithm"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.hashAlgorithm));
|
|
84
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "mgf1HashAlgorithm"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.mgf1HashAlgorithm));
|
|
85
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "saltLength"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.saltLength));
|
|
86
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "namedCurve"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.namedCurve));
|
|
74
87
|
return obj;
|
|
75
88
|
}
|
|
76
89
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -78,13 +91,16 @@ namespace margelo::nitro {
|
|
|
78
91
|
return false;
|
|
79
92
|
}
|
|
80
93
|
jsi::Object obj = value.getObject(runtime);
|
|
81
|
-
if (!
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (!JSIConverter<std::optional<
|
|
85
|
-
if (!JSIConverter<std::optional<
|
|
86
|
-
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "
|
|
87
|
-
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "
|
|
94
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "length")))) return false;
|
|
98
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "publicExponent")))) return false;
|
|
99
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "modulusLength")))) return false;
|
|
100
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "hashAlgorithm")))) return false;
|
|
101
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mgf1HashAlgorithm")))) return false;
|
|
102
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "saltLength")))) return false;
|
|
103
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "namedCurve")))) return false;
|
|
88
104
|
return true;
|
|
89
105
|
}
|
|
90
106
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// KeyObject.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -17,6 +17,16 @@
|
|
|
17
17
|
#else
|
|
18
18
|
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
19
|
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
20
30
|
|
|
21
31
|
|
|
22
32
|
|
|
@@ -27,13 +37,16 @@ namespace margelo::nitro::crypto {
|
|
|
27
37
|
/**
|
|
28
38
|
* A struct which can be represented as a JavaScript object (KeyObject).
|
|
29
39
|
*/
|
|
30
|
-
struct KeyObject {
|
|
40
|
+
struct KeyObject final {
|
|
31
41
|
public:
|
|
32
42
|
bool extractable SWIFT_PRIVATE;
|
|
33
43
|
|
|
34
44
|
public:
|
|
35
45
|
KeyObject() = default;
|
|
36
46
|
explicit KeyObject(bool extractable): extractable(extractable) {}
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
friend bool operator==(const KeyObject& lhs, const KeyObject& rhs) = default;
|
|
37
50
|
};
|
|
38
51
|
|
|
39
52
|
} // namespace margelo::nitro::crypto
|
|
@@ -46,12 +59,12 @@ namespace margelo::nitro {
|
|
|
46
59
|
static inline margelo::nitro::crypto::KeyObject fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
47
60
|
jsi::Object obj = arg.asObject(runtime);
|
|
48
61
|
return margelo::nitro::crypto::KeyObject(
|
|
49
|
-
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, "extractable"))
|
|
62
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "extractable")))
|
|
50
63
|
);
|
|
51
64
|
}
|
|
52
65
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::KeyObject& arg) {
|
|
53
66
|
jsi::Object obj(runtime);
|
|
54
|
-
obj.setProperty(runtime, "extractable", JSIConverter<bool>::toJSI(runtime, arg.extractable));
|
|
67
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "extractable"), JSIConverter<bool>::toJSI(runtime, arg.extractable));
|
|
55
68
|
return obj;
|
|
56
69
|
}
|
|
57
70
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -59,7 +72,10 @@ namespace margelo::nitro {
|
|
|
59
72
|
return false;
|
|
60
73
|
}
|
|
61
74
|
jsi::Object obj = value.getObject(runtime);
|
|
62
|
-
if (!
|
|
75
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "extractable")))) return false;
|
|
63
79
|
return true;
|
|
64
80
|
}
|
|
65
81
|
};
|
package/package.json
CHANGED
package/src/diffie-hellman.ts
CHANGED
|
@@ -111,6 +111,10 @@ export class DiffieHellman {
|
|
|
111
111
|
}
|
|
112
112
|
this._hybrid.setPrivateKey(keyBuf.buffer as ArrayBuffer);
|
|
113
113
|
}
|
|
114
|
+
|
|
115
|
+
get verifyError(): number {
|
|
116
|
+
return this._hybrid.getVerifyError();
|
|
117
|
+
}
|
|
114
118
|
}
|
|
115
119
|
|
|
116
120
|
export function createDiffieHellman(
|
|
@@ -189,3 +193,5 @@ export function getDiffieHellman(groupName: string): DiffieHellman {
|
|
|
189
193
|
// group.prime and group.generator are hex strings
|
|
190
194
|
return new DiffieHellman(group.prime, group.generator, 'hex');
|
|
191
195
|
}
|
|
196
|
+
|
|
197
|
+
export { getDiffieHellman as createDiffieHellmanGroup };
|
package/src/ec.ts
CHANGED
|
@@ -34,6 +34,23 @@ import {
|
|
|
34
34
|
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
35
35
|
import { ECDH } from './ecdh';
|
|
36
36
|
|
|
37
|
+
class EcUtils {
|
|
38
|
+
private static _native: EcKeyPair | undefined;
|
|
39
|
+
private static get native(): EcKeyPair {
|
|
40
|
+
if (!this._native) {
|
|
41
|
+
this._native = NitroModules.createHybridObject<EcKeyPair>('EcKeyPair');
|
|
42
|
+
}
|
|
43
|
+
return this._native;
|
|
44
|
+
}
|
|
45
|
+
public static getSupportedCurves(): string[] {
|
|
46
|
+
return this.native.getSupportedCurves();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getCurves(): string[] {
|
|
51
|
+
return EcUtils.getSupportedCurves();
|
|
52
|
+
}
|
|
53
|
+
|
|
37
54
|
export class Ec {
|
|
38
55
|
native: EcKeyPair;
|
|
39
56
|
|
|
@@ -488,8 +505,7 @@ export function ecDeriveBits(
|
|
|
488
505
|
baseKey: CryptoKey,
|
|
489
506
|
length: number | null,
|
|
490
507
|
): ArrayBuffer {
|
|
491
|
-
const
|
|
492
|
-
const publicKey = publicParams.public;
|
|
508
|
+
const publicKey = algorithm.public;
|
|
493
509
|
|
|
494
510
|
if (!publicKey) {
|
|
495
511
|
throw new Error('Public key is required for ECDH derivation');
|
|
@@ -508,31 +524,19 @@ export function ecDeriveBits(
|
|
|
508
524
|
throw new Error('Curve name is missing');
|
|
509
525
|
}
|
|
510
526
|
|
|
511
|
-
|
|
512
|
-
|
|
527
|
+
const opensslCurve =
|
|
528
|
+
kNamedCurveAliases[namedCurve as keyof typeof kNamedCurveAliases];
|
|
529
|
+
const ecdh = new ECDH(opensslCurve);
|
|
513
530
|
|
|
514
|
-
|
|
515
|
-
const jwkPrivate = baseKey.keyObject.export({ format: 'jwk' }) as any;
|
|
531
|
+
const jwkPrivate = baseKey.keyObject.handle.exportJwk({}, false);
|
|
516
532
|
if (!jwkPrivate.d) throw new Error('Invalid private key');
|
|
517
533
|
const privateBytes = Buffer.from(jwkPrivate.d, 'base64');
|
|
518
|
-
|
|
519
534
|
ecdh.setPrivateKey(privateBytes);
|
|
520
535
|
|
|
521
|
-
|
|
522
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
523
|
-
const jwkPublic = publicKey.keyObject.export({ format: 'jwk' }) as any;
|
|
524
|
-
|
|
525
|
-
// HybridECDH `computeSecret` takes public key.
|
|
526
|
-
// My implementation `HybridECDH.cpp` `computeSecret` expects what?
|
|
527
|
-
// `derive_secret` -> `EVP_PKEY_derive_set_peer`
|
|
528
|
-
// `computeSecret` calls `EC_POINT_oct2point`. So it expects an uncompressed/compressed point (04... or 02/03...).
|
|
529
|
-
// JWK gives `x` and `y`. We can construct the uncompressed point 04 + x + y.
|
|
530
|
-
|
|
536
|
+
const jwkPublic = publicKey.keyObject.handle.exportJwk({}, false);
|
|
531
537
|
if (!jwkPublic.x || !jwkPublic.y) throw new Error('Invalid public key');
|
|
532
538
|
const x = Buffer.from(jwkPublic.x, 'base64');
|
|
533
539
|
const y = Buffer.from(jwkPublic.y, 'base64');
|
|
534
|
-
|
|
535
|
-
// Uncompressed point: 0x04 || x || y
|
|
536
540
|
const publicBytes = Buffer.concat([Buffer.from([0x04]), x, y]);
|
|
537
541
|
|
|
538
542
|
const secret = ecdh.computeSecret(publicBytes);
|
package/src/ed.ts
CHANGED
|
@@ -427,8 +427,7 @@ export function xDeriveBits(
|
|
|
427
427
|
baseKey: CryptoKey,
|
|
428
428
|
length: number | null,
|
|
429
429
|
): ArrayBuffer {
|
|
430
|
-
const
|
|
431
|
-
const publicKey = publicParams.public;
|
|
430
|
+
const publicKey = algorithm.public;
|
|
432
431
|
|
|
433
432
|
if (!publicKey) {
|
|
434
433
|
throw new Error('Public key is required for X25519/X448 derivation');
|
package/src/hash.ts
CHANGED
|
@@ -272,8 +272,19 @@ const internalDigest = (
|
|
|
272
272
|
return arrayBuffer;
|
|
273
273
|
};
|
|
274
274
|
|
|
275
|
+
export function hash(
|
|
276
|
+
algorithm: string,
|
|
277
|
+
data: BinaryLike,
|
|
278
|
+
outputEncoding?: Encoding,
|
|
279
|
+
): string | Buffer {
|
|
280
|
+
const h = createHash(algorithm);
|
|
281
|
+
h.update(data);
|
|
282
|
+
return outputEncoding ? h.digest(outputEncoding) : h.digest();
|
|
283
|
+
}
|
|
284
|
+
|
|
275
285
|
export const hashExports = {
|
|
276
286
|
createHash,
|
|
277
287
|
getHashes,
|
|
288
|
+
hash,
|
|
278
289
|
asyncDigest,
|
|
279
290
|
};
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import * as scrypt from './scrypt';
|
|
|
14
14
|
import * as random from './random';
|
|
15
15
|
import * as ecdh from './ecdh';
|
|
16
16
|
import * as dh from './diffie-hellman';
|
|
17
|
+
import { getCurves } from './ec';
|
|
17
18
|
import { constants } from './constants';
|
|
18
19
|
|
|
19
20
|
// utils import
|
|
@@ -39,6 +40,7 @@ const QuickCrypto = {
|
|
|
39
40
|
...dh,
|
|
40
41
|
...utils,
|
|
41
42
|
...subtle,
|
|
43
|
+
getCurves,
|
|
42
44
|
constants,
|
|
43
45
|
Buffer,
|
|
44
46
|
};
|
|
@@ -81,6 +83,7 @@ export * from './pbkdf2';
|
|
|
81
83
|
export * from './scrypt';
|
|
82
84
|
export * from './random';
|
|
83
85
|
export * from './ecdh';
|
|
86
|
+
export { getCurves } from './ec';
|
|
84
87
|
export * from './diffie-hellman';
|
|
85
88
|
export * from './utils';
|
|
86
89
|
export * from './subtle';
|
package/src/keys/classes.ts
CHANGED
|
@@ -89,6 +89,13 @@ export class KeyObject {
|
|
|
89
89
|
throw new Error('export() must be implemented by subclasses');
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
equals(otherKeyObject: KeyObject): boolean {
|
|
93
|
+
if (!(otherKeyObject instanceof KeyObject)) {
|
|
94
|
+
throw new TypeError('otherKeyObject must be a KeyObject');
|
|
95
|
+
}
|
|
96
|
+
return this.handle.keyEquals(otherKeyObject.handle);
|
|
97
|
+
}
|
|
98
|
+
|
|
92
99
|
constructor(type: string, handle: KeyObjectHandle);
|
|
93
100
|
constructor(type: string, key: ArrayBuffer);
|
|
94
101
|
constructor(type: string, handleOrKey: KeyObjectHandle | ArrayBuffer) {
|
|
@@ -197,9 +204,9 @@ export class SecretKeyObject extends KeyObject {
|
|
|
197
204
|
super('secret', handle);
|
|
198
205
|
}
|
|
199
206
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
207
|
+
get symmetricKeySize(): number {
|
|
208
|
+
return this.handle.getSymmetricKeySize();
|
|
209
|
+
}
|
|
203
210
|
|
|
204
211
|
export(options: { format: 'pem' } & EncodingOptions): never;
|
|
205
212
|
export(options: { format: 'der' } & EncodingOptions): Buffer;
|
|
@@ -29,4 +29,6 @@ export interface KeyObjectHandle
|
|
|
29
29
|
initECRaw(namedCurve: string, keyData: ArrayBuffer): boolean;
|
|
30
30
|
initJwk(keyData: JWK, namedCurve?: NamedCurve): KeyType | undefined;
|
|
31
31
|
keyDetail(): KeyDetail;
|
|
32
|
+
keyEquals(other: KeyObjectHandle): boolean;
|
|
33
|
+
getSymmetricKeySize(): number;
|
|
32
34
|
}
|