react-native-quick-crypto 1.0.9 → 1.0.11
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 +13 -0
- package/cpp/argon2/HybridArgon2.cpp +103 -0
- package/cpp/argon2/HybridArgon2.hpp +32 -0
- package/cpp/certificate/HybridCertificate.cpp +42 -0
- package/cpp/certificate/HybridCertificate.hpp +16 -0
- package/cpp/cipher/HybridCipher.cpp +58 -0
- package/cpp/cipher/HybridCipher.hpp +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/HybridDhKeyPair.cpp +179 -0
- package/cpp/dh/HybridDhKeyPair.hpp +37 -0
- package/cpp/dh/HybridDiffieHellman.cpp +10 -0
- package/cpp/dh/HybridDiffieHellman.hpp +1 -0
- package/cpp/dsa/HybridDsaKeyPair.cpp +128 -0
- package/cpp/dsa/HybridDsaKeyPair.hpp +32 -0
- package/cpp/ec/HybridEcKeyPair.cpp +21 -0
- package/cpp/ec/HybridEcKeyPair.hpp +1 -0
- package/cpp/ecdh/HybridECDH.cpp +35 -0
- package/cpp/ecdh/HybridECDH.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 +131 -1
- package/cpp/keys/HybridKeyObjectHandle.hpp +5 -1
- package/cpp/prime/HybridPrime.cpp +81 -0
- package/cpp/prime/HybridPrime.hpp +20 -0
- 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/argon2.js +39 -0
- package/lib/commonjs/argon2.js.map +1 -0
- package/lib/commonjs/certificate.js +35 -0
- package/lib/commonjs/certificate.js.map +1 -0
- package/lib/commonjs/cipher.js +8 -0
- package/lib/commonjs/cipher.js.map +1 -1
- package/lib/commonjs/dhKeyPair.js +109 -0
- package/lib/commonjs/dhKeyPair.js.map +1 -0
- package/lib/commonjs/diffie-hellman.js +4 -1
- package/lib/commonjs/diffie-hellman.js.map +1 -1
- package/lib/commonjs/dsa.js +92 -0
- package/lib/commonjs/dsa.js.map +1 -0
- package/lib/commonjs/ec.js +20 -25
- package/lib/commonjs/ec.js.map +1 -1
- package/lib/commonjs/ecdh.js +37 -0
- package/lib/commonjs/ecdh.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 +46 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys/classes.js +18 -12
- package/lib/commonjs/keys/classes.js.map +1 -1
- package/lib/commonjs/keys/generateKeyPair.js +11 -0
- package/lib/commonjs/keys/generateKeyPair.js.map +1 -1
- package/lib/commonjs/prime.js +84 -0
- package/lib/commonjs/prime.js.map +1 -0
- package/lib/commonjs/specs/argon2.nitro.js +6 -0
- package/lib/commonjs/specs/argon2.nitro.js.map +1 -0
- package/lib/commonjs/specs/certificate.nitro.js +6 -0
- package/lib/commonjs/specs/certificate.nitro.js.map +1 -0
- package/lib/commonjs/specs/dhKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/dhKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/specs/dsaKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/dsaKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/specs/prime.nitro.js +6 -0
- package/lib/commonjs/specs/prime.nitro.js.map +1 -0
- package/lib/commonjs/subtle.js +181 -39
- package/lib/commonjs/subtle.js.map +1 -1
- package/lib/commonjs/utils/types.js.map +1 -1
- package/lib/module/argon2.js +34 -0
- package/lib/module/argon2.js.map +1 -0
- package/lib/module/certificate.js +30 -0
- package/lib/module/certificate.js.map +1 -0
- package/lib/module/cipher.js +7 -0
- package/lib/module/cipher.js.map +1 -1
- package/lib/module/dhKeyPair.js +102 -0
- package/lib/module/dhKeyPair.js.map +1 -0
- package/lib/module/diffie-hellman.js +4 -0
- package/lib/module/diffie-hellman.js.map +1 -1
- package/lib/module/dsa.js +85 -0
- package/lib/module/dsa.js.map +1 -0
- package/lib/module/ec.js +19 -25
- package/lib/module/ec.js.map +1 -1
- package/lib/module/ecdh.js +37 -0
- package/lib/module/ecdh.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 +12 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys/classes.js +18 -12
- package/lib/module/keys/classes.js.map +1 -1
- package/lib/module/keys/generateKeyPair.js +11 -0
- package/lib/module/keys/generateKeyPair.js.map +1 -1
- package/lib/module/prime.js +77 -0
- package/lib/module/prime.js.map +1 -0
- package/lib/module/specs/argon2.nitro.js +4 -0
- package/lib/module/specs/argon2.nitro.js.map +1 -0
- package/lib/module/specs/certificate.nitro.js +4 -0
- package/lib/module/specs/certificate.nitro.js.map +1 -0
- package/lib/module/specs/dhKeyPair.nitro.js +4 -0
- package/lib/module/specs/dhKeyPair.nitro.js.map +1 -0
- package/lib/module/specs/dsaKeyPair.nitro.js +4 -0
- package/lib/module/specs/dsaKeyPair.nitro.js.map +1 -0
- package/lib/module/specs/prime.nitro.js +4 -0
- package/lib/module/specs/prime.nitro.js.map +1 -0
- package/lib/module/subtle.js +183 -42
- 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/argon2.d.ts +16 -0
- package/lib/typescript/argon2.d.ts.map +1 -0
- package/lib/typescript/certificate.d.ts +8 -0
- package/lib/typescript/certificate.d.ts.map +1 -0
- package/lib/typescript/cipher.d.ts +12 -0
- package/lib/typescript/cipher.d.ts.map +1 -1
- package/lib/typescript/dhKeyPair.d.ts +19 -0
- package/lib/typescript/dhKeyPair.d.ts.map +1 -0
- package/lib/typescript/diffie-hellman.d.ts +2 -0
- package/lib/typescript/diffie-hellman.d.ts.map +1 -1
- package/lib/typescript/dsa.d.ts +19 -0
- package/lib/typescript/dsa.d.ts.map +1 -0
- package/lib/typescript/ec.d.ts +1 -0
- package/lib/typescript/ec.d.ts.map +1 -1
- package/lib/typescript/ecdh.d.ts +3 -0
- package/lib/typescript/ecdh.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 +22 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/keys/classes.d.ts +4 -0
- package/lib/typescript/keys/classes.d.ts.map +1 -1
- package/lib/typescript/keys/generateKeyPair.d.ts.map +1 -1
- package/lib/typescript/prime.d.ts +19 -0
- package/lib/typescript/prime.d.ts.map +1 -0
- package/lib/typescript/specs/argon2.nitro.d.ts +9 -0
- package/lib/typescript/specs/argon2.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/certificate.nitro.d.ts +10 -0
- package/lib/typescript/specs/certificate.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/cipher.nitro.d.ts +9 -0
- package/lib/typescript/specs/cipher.nitro.d.ts.map +1 -1
- package/lib/typescript/specs/dhKeyPair.nitro.d.ts +14 -0
- package/lib/typescript/specs/dhKeyPair.nitro.d.ts.map +1 -0
- 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/dsaKeyPair.nitro.d.ts +13 -0
- package/lib/typescript/specs/dsaKeyPair.nitro.d.ts.map +1 -0
- 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/ecdh.nitro.d.ts +1 -0
- package/lib/typescript/specs/ecdh.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/specs/prime.nitro.d.ts +11 -0
- package/lib/typescript/specs/prime.nitro.d.ts.map +1 -0
- package/lib/typescript/subtle.d.ts +2 -0
- package/lib/typescript/subtle.d.ts.map +1 -1
- package/lib/typescript/utils/types.d.ts +24 -7
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +13 -5
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +1 -1
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +104 -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 +104 -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++/CipherInfo.hpp +104 -0
- package/nitrogen/generated/shared/c++/HybridArgon2Spec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridArgon2Spec.hpp +66 -0
- package/nitrogen/generated/shared/c++/HybridBlake3Spec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridBlake3Spec.hpp +1 -3
- package/nitrogen/generated/shared/c++/HybridCertificateSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridCertificateSpec.hpp +64 -0
- 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 +2 -1
- package/nitrogen/generated/shared/c++/HybridCipherSpec.hpp +5 -3
- package/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.cpp +27 -0
- package/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.hpp +69 -0
- package/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.cpp +2 -1
- package/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.hpp +3 -3
- package/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.hpp +68 -0
- package/nitrogen/generated/shared/c++/HybridECDHSpec.cpp +2 -1
- package/nitrogen/generated/shared/c++/HybridECDHSpec.hpp +3 -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++/HybridPrimeSpec.cpp +24 -0
- package/nitrogen/generated/shared/c++/HybridPrimeSpec.hpp +67 -0
- 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/argon2.ts +83 -0
- package/src/certificate.ts +41 -0
- package/src/cipher.ts +24 -0
- package/src/dhKeyPair.ts +156 -0
- package/src/diffie-hellman.ts +6 -0
- package/src/dsa.ts +129 -0
- package/src/ec.ts +23 -19
- package/src/ecdh.ts +59 -0
- package/src/ed.ts +1 -2
- package/src/hash.ts +11 -0
- package/src/index.ts +12 -0
- package/src/keys/classes.ts +26 -8
- package/src/keys/generateKeyPair.ts +14 -0
- package/src/prime.ts +134 -0
- package/src/specs/argon2.nitro.ts +29 -0
- package/src/specs/certificate.nitro.ts +8 -0
- package/src/specs/cipher.nitro.ts +14 -0
- package/src/specs/dhKeyPair.nitro.ts +14 -0
- package/src/specs/diffie-hellman.nitro.ts +1 -0
- package/src/specs/dsaKeyPair.nitro.ts +13 -0
- package/src/specs/ecKeyPair.nitro.ts +2 -0
- package/src/specs/ecdh.nitro.ts +1 -0
- package/src/specs/keyObjectHandle.nitro.ts +2 -0
- package/src/specs/prime.nitro.ts +18 -0
- package/src/subtle.ts +400 -42
- package/src/utils/types.ts +39 -5
- package/deps/ncrypto/WORKSPACE +0 -15
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// JWKkty.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
|
|
@@ -33,6 +33,7 @@ namespace margelo::nitro::crypto {
|
|
|
33
33
|
RSA SWIFT_NAME(rsa) = 1,
|
|
34
34
|
EC SWIFT_NAME(ec) = 2,
|
|
35
35
|
OCT SWIFT_NAME(oct) = 3,
|
|
36
|
+
OKP SWIFT_NAME(okp) = 4,
|
|
36
37
|
} CLOSED_ENUM;
|
|
37
38
|
|
|
38
39
|
} // namespace margelo::nitro::crypto
|
|
@@ -49,6 +50,7 @@ namespace margelo::nitro {
|
|
|
49
50
|
case hashString("RSA"): return margelo::nitro::crypto::JWKkty::RSA;
|
|
50
51
|
case hashString("EC"): return margelo::nitro::crypto::JWKkty::EC;
|
|
51
52
|
case hashString("oct"): return margelo::nitro::crypto::JWKkty::OCT;
|
|
53
|
+
case hashString("OKP"): return margelo::nitro::crypto::JWKkty::OKP;
|
|
52
54
|
default: [[unlikely]]
|
|
53
55
|
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum JWKkty - invalid value!");
|
|
54
56
|
}
|
|
@@ -59,6 +61,7 @@ namespace margelo::nitro {
|
|
|
59
61
|
case margelo::nitro::crypto::JWKkty::RSA: return JSIConverter<std::string>::toJSI(runtime, "RSA");
|
|
60
62
|
case margelo::nitro::crypto::JWKkty::EC: return JSIConverter<std::string>::toJSI(runtime, "EC");
|
|
61
63
|
case margelo::nitro::crypto::JWKkty::OCT: return JSIConverter<std::string>::toJSI(runtime, "oct");
|
|
64
|
+
case margelo::nitro::crypto::JWKkty::OKP: return JSIConverter<std::string>::toJSI(runtime, "OKP");
|
|
62
65
|
default: [[unlikely]]
|
|
63
66
|
throw std::invalid_argument("Cannot convert JWKkty to JS - invalid value: "
|
|
64
67
|
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
@@ -74,6 +77,7 @@ namespace margelo::nitro {
|
|
|
74
77
|
case hashString("RSA"):
|
|
75
78
|
case hashString("EC"):
|
|
76
79
|
case hashString("oct"):
|
|
80
|
+
case hashString("OKP"):
|
|
77
81
|
return true;
|
|
78
82
|
default:
|
|
79
83
|
return false;
|
|
@@ -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/argon2.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
2
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
3
|
+
import type { Argon2 as NativeArgon2 } from './specs/argon2.nitro';
|
|
4
|
+
import { binaryLikeToArrayBuffer } from './utils';
|
|
5
|
+
import type { BinaryLike } from './utils';
|
|
6
|
+
|
|
7
|
+
let native: NativeArgon2;
|
|
8
|
+
function getNative(): NativeArgon2 {
|
|
9
|
+
if (native == null) {
|
|
10
|
+
native = NitroModules.createHybridObject<NativeArgon2>('Argon2');
|
|
11
|
+
}
|
|
12
|
+
return native;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface Argon2Params {
|
|
16
|
+
message: BinaryLike;
|
|
17
|
+
nonce: BinaryLike;
|
|
18
|
+
parallelism: number;
|
|
19
|
+
tagLength: number;
|
|
20
|
+
memory: number;
|
|
21
|
+
passes: number;
|
|
22
|
+
secret?: BinaryLike;
|
|
23
|
+
associatedData?: BinaryLike;
|
|
24
|
+
version?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const ARGON2_VERSION = 0x13; // v1.3
|
|
28
|
+
|
|
29
|
+
function validateAlgorithm(algorithm: string): void {
|
|
30
|
+
if (
|
|
31
|
+
algorithm !== 'argon2d' &&
|
|
32
|
+
algorithm !== 'argon2i' &&
|
|
33
|
+
algorithm !== 'argon2id'
|
|
34
|
+
) {
|
|
35
|
+
throw new TypeError(`Unknown argon2 algorithm: ${algorithm}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function toAB(value: BinaryLike): ArrayBuffer {
|
|
40
|
+
return binaryLikeToArrayBuffer(value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function argon2Sync(algorithm: string, params: Argon2Params): Buffer {
|
|
44
|
+
validateAlgorithm(algorithm);
|
|
45
|
+
const version = params.version ?? ARGON2_VERSION;
|
|
46
|
+
const result = getNative().hashSync(
|
|
47
|
+
algorithm,
|
|
48
|
+
toAB(params.message),
|
|
49
|
+
toAB(params.nonce),
|
|
50
|
+
params.parallelism,
|
|
51
|
+
params.tagLength,
|
|
52
|
+
params.memory,
|
|
53
|
+
params.passes,
|
|
54
|
+
version,
|
|
55
|
+
params.secret ? toAB(params.secret) : undefined,
|
|
56
|
+
params.associatedData ? toAB(params.associatedData) : undefined,
|
|
57
|
+
);
|
|
58
|
+
return Buffer.from(result);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function argon2(
|
|
62
|
+
algorithm: string,
|
|
63
|
+
params: Argon2Params,
|
|
64
|
+
callback: (err: Error | null, result: Buffer) => void,
|
|
65
|
+
): void {
|
|
66
|
+
validateAlgorithm(algorithm);
|
|
67
|
+
const version = params.version ?? ARGON2_VERSION;
|
|
68
|
+
getNative()
|
|
69
|
+
.hash(
|
|
70
|
+
algorithm,
|
|
71
|
+
toAB(params.message),
|
|
72
|
+
toAB(params.nonce),
|
|
73
|
+
params.parallelism,
|
|
74
|
+
params.tagLength,
|
|
75
|
+
params.memory,
|
|
76
|
+
params.passes,
|
|
77
|
+
version,
|
|
78
|
+
params.secret ? toAB(params.secret) : undefined,
|
|
79
|
+
params.associatedData ? toAB(params.associatedData) : undefined,
|
|
80
|
+
)
|
|
81
|
+
.then(ab => callback(null, Buffer.from(ab)))
|
|
82
|
+
.catch((err: Error) => callback(err, Buffer.alloc(0)));
|
|
83
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
3
|
+
import type { Certificate as NativeCertificate } from './specs/certificate.nitro';
|
|
4
|
+
import type { BinaryLike } from './utils';
|
|
5
|
+
import { binaryLikeToArrayBuffer } from './utils';
|
|
6
|
+
|
|
7
|
+
let native: NativeCertificate;
|
|
8
|
+
function getNative(): NativeCertificate {
|
|
9
|
+
if (native == null) {
|
|
10
|
+
native = NitroModules.createHybridObject<NativeCertificate>('Certificate');
|
|
11
|
+
}
|
|
12
|
+
return native;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function toArrayBuffer(
|
|
16
|
+
spkac: BinaryLike,
|
|
17
|
+
encoding?: BufferEncoding,
|
|
18
|
+
): ArrayBuffer {
|
|
19
|
+
if (typeof spkac === 'string') {
|
|
20
|
+
return binaryLikeToArrayBuffer(spkac, encoding || 'utf8');
|
|
21
|
+
}
|
|
22
|
+
return binaryLikeToArrayBuffer(spkac);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class Certificate {
|
|
26
|
+
static exportChallenge(spkac: BinaryLike, encoding?: BufferEncoding): Buffer {
|
|
27
|
+
return Buffer.from(
|
|
28
|
+
getNative().exportChallenge(toArrayBuffer(spkac, encoding)),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static exportPublicKey(spkac: BinaryLike, encoding?: BufferEncoding): Buffer {
|
|
33
|
+
return Buffer.from(
|
|
34
|
+
getNative().exportPublicKey(toArrayBuffer(spkac, encoding)),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static verifySpkac(spkac: BinaryLike, encoding?: BufferEncoding): boolean {
|
|
39
|
+
return getNative().verifySpkac(toArrayBuffer(spkac, encoding));
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/cipher.ts
CHANGED
|
@@ -28,18 +28,42 @@ export type CipherOptions =
|
|
|
28
28
|
| CipherGCMOptions
|
|
29
29
|
| TransformOptions;
|
|
30
30
|
|
|
31
|
+
export interface CipherInfoResult {
|
|
32
|
+
name: string;
|
|
33
|
+
nid: number;
|
|
34
|
+
mode: string;
|
|
35
|
+
keyLength: number;
|
|
36
|
+
blockSize?: number;
|
|
37
|
+
ivLength?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
31
40
|
class CipherUtils {
|
|
32
41
|
private static native =
|
|
33
42
|
NitroModules.createHybridObject<NativeCipher>('Cipher');
|
|
34
43
|
public static getSupportedCiphers(): string[] {
|
|
35
44
|
return this.native.getSupportedCiphers();
|
|
36
45
|
}
|
|
46
|
+
public static getCipherInfo(
|
|
47
|
+
name: string,
|
|
48
|
+
keyLength?: number,
|
|
49
|
+
ivLength?: number,
|
|
50
|
+
): CipherInfoResult | undefined {
|
|
51
|
+
return this.native.getCipherInfo(name, keyLength, ivLength);
|
|
52
|
+
}
|
|
37
53
|
}
|
|
38
54
|
|
|
39
55
|
export function getCiphers(): string[] {
|
|
40
56
|
return CipherUtils.getSupportedCiphers();
|
|
41
57
|
}
|
|
42
58
|
|
|
59
|
+
export function getCipherInfo(
|
|
60
|
+
name: string,
|
|
61
|
+
options?: { keyLength?: number; ivLength?: number },
|
|
62
|
+
): CipherInfoResult | undefined {
|
|
63
|
+
if (typeof name !== 'string' || name.length === 0) return undefined;
|
|
64
|
+
return CipherUtils.getCipherInfo(name, options?.keyLength, options?.ivLength);
|
|
65
|
+
}
|
|
66
|
+
|
|
43
67
|
interface CipherArgs {
|
|
44
68
|
isCipher: boolean;
|
|
45
69
|
cipherType: string;
|
package/src/dhKeyPair.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
3
|
+
import { KeyObject, PublicKeyObject, PrivateKeyObject } from './keys';
|
|
4
|
+
import type { DhKeyPair } from './specs/dhKeyPair.nitro';
|
|
5
|
+
import type { GenerateKeyPairOptions, KeyPairGenConfig } from './utils/types';
|
|
6
|
+
import { KFormatType, KeyEncoding } from './utils';
|
|
7
|
+
import { DH_GROUPS } from './dh-groups';
|
|
8
|
+
|
|
9
|
+
export class DhKeyPairGen {
|
|
10
|
+
native: DhKeyPair;
|
|
11
|
+
|
|
12
|
+
constructor(options: GenerateKeyPairOptions) {
|
|
13
|
+
this.native = NitroModules.createHybridObject<DhKeyPair>('DhKeyPair');
|
|
14
|
+
|
|
15
|
+
const { groupName, prime, primeLength, generator } = options;
|
|
16
|
+
|
|
17
|
+
if (groupName) {
|
|
18
|
+
// Resolve named group to prime + generator
|
|
19
|
+
const group = DH_GROUPS[groupName];
|
|
20
|
+
if (!group) {
|
|
21
|
+
throw new Error(`Unknown DH group: ${groupName}`);
|
|
22
|
+
}
|
|
23
|
+
const primeBuf = Buffer.from(group.prime, 'hex');
|
|
24
|
+
this.native.setPrime(
|
|
25
|
+
primeBuf.buffer.slice(
|
|
26
|
+
primeBuf.byteOffset,
|
|
27
|
+
primeBuf.byteOffset + primeBuf.byteLength,
|
|
28
|
+
) as ArrayBuffer,
|
|
29
|
+
);
|
|
30
|
+
const gen = parseInt(group.generator, 16);
|
|
31
|
+
this.native.setGenerator(gen);
|
|
32
|
+
} else if (prime) {
|
|
33
|
+
// Custom prime as Buffer
|
|
34
|
+
const primeBuf = Buffer.from(prime);
|
|
35
|
+
this.native.setPrime(
|
|
36
|
+
primeBuf.buffer.slice(
|
|
37
|
+
primeBuf.byteOffset,
|
|
38
|
+
primeBuf.byteOffset + primeBuf.byteLength,
|
|
39
|
+
) as ArrayBuffer,
|
|
40
|
+
);
|
|
41
|
+
this.native.setGenerator(generator ?? 2);
|
|
42
|
+
} else if (primeLength) {
|
|
43
|
+
this.native.setPrimeLength(primeLength);
|
|
44
|
+
this.native.setGenerator(generator ?? 2);
|
|
45
|
+
} else {
|
|
46
|
+
throw new Error(
|
|
47
|
+
'DH key generation requires one of: groupName, prime, or primeLength',
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async generateKeyPair(): Promise<void> {
|
|
53
|
+
await this.native.generateKeyPair();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
generateKeyPairSync(): void {
|
|
57
|
+
this.native.generateKeyPairSync();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function dh_prepareKeyGenParams(
|
|
62
|
+
options: GenerateKeyPairOptions | undefined,
|
|
63
|
+
): DhKeyPairGen {
|
|
64
|
+
if (!options) {
|
|
65
|
+
throw new Error('Options are required for DH key generation');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return new DhKeyPairGen(options);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function dh_formatKeyPairOutput(
|
|
72
|
+
dh: DhKeyPairGen,
|
|
73
|
+
encoding: KeyPairGenConfig,
|
|
74
|
+
): {
|
|
75
|
+
publicKey: PublicKeyObject | Buffer | string | ArrayBuffer;
|
|
76
|
+
privateKey: PrivateKeyObject | Buffer | string | ArrayBuffer;
|
|
77
|
+
} {
|
|
78
|
+
const { publicFormat, privateFormat, cipher, passphrase } = encoding;
|
|
79
|
+
|
|
80
|
+
const publicKeyData = dh.native.getPublicKey();
|
|
81
|
+
const privateKeyData = dh.native.getPrivateKey();
|
|
82
|
+
|
|
83
|
+
const pub = KeyObject.createKeyObject(
|
|
84
|
+
'public',
|
|
85
|
+
publicKeyData,
|
|
86
|
+
KFormatType.DER,
|
|
87
|
+
KeyEncoding.SPKI,
|
|
88
|
+
) as PublicKeyObject;
|
|
89
|
+
|
|
90
|
+
const priv = KeyObject.createKeyObject(
|
|
91
|
+
'private',
|
|
92
|
+
privateKeyData,
|
|
93
|
+
KFormatType.DER,
|
|
94
|
+
KeyEncoding.PKCS8,
|
|
95
|
+
) as PrivateKeyObject;
|
|
96
|
+
|
|
97
|
+
let publicKey: PublicKeyObject | Buffer | string | ArrayBuffer;
|
|
98
|
+
let privateKey: PrivateKeyObject | Buffer | string | ArrayBuffer;
|
|
99
|
+
|
|
100
|
+
if (publicFormat === -1) {
|
|
101
|
+
publicKey = pub;
|
|
102
|
+
} else {
|
|
103
|
+
const format =
|
|
104
|
+
publicFormat === KFormatType.PEM ? KFormatType.PEM : KFormatType.DER;
|
|
105
|
+
const exported = pub.handle.exportKey(format, KeyEncoding.SPKI);
|
|
106
|
+
if (format === KFormatType.PEM) {
|
|
107
|
+
publicKey = Buffer.from(new Uint8Array(exported)).toString('utf-8');
|
|
108
|
+
} else {
|
|
109
|
+
publicKey = exported;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (privateFormat === -1) {
|
|
114
|
+
privateKey = priv;
|
|
115
|
+
} else {
|
|
116
|
+
const format =
|
|
117
|
+
privateFormat === KFormatType.PEM ? KFormatType.PEM : KFormatType.DER;
|
|
118
|
+
const exported = priv.handle.exportKey(
|
|
119
|
+
format,
|
|
120
|
+
KeyEncoding.PKCS8,
|
|
121
|
+
cipher,
|
|
122
|
+
passphrase,
|
|
123
|
+
);
|
|
124
|
+
if (format === KFormatType.PEM) {
|
|
125
|
+
privateKey = Buffer.from(new Uint8Array(exported)).toString('utf-8');
|
|
126
|
+
} else {
|
|
127
|
+
privateKey = exported;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return { publicKey, privateKey };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export async function dh_generateKeyPairNode(
|
|
135
|
+
options: GenerateKeyPairOptions | undefined,
|
|
136
|
+
encoding: KeyPairGenConfig,
|
|
137
|
+
): Promise<{
|
|
138
|
+
publicKey: PublicKeyObject | Buffer | string | ArrayBuffer;
|
|
139
|
+
privateKey: PrivateKeyObject | Buffer | string | ArrayBuffer;
|
|
140
|
+
}> {
|
|
141
|
+
const dh = dh_prepareKeyGenParams(options);
|
|
142
|
+
await dh.generateKeyPair();
|
|
143
|
+
return dh_formatKeyPairOutput(dh, encoding);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function dh_generateKeyPairNodeSync(
|
|
147
|
+
options: GenerateKeyPairOptions | undefined,
|
|
148
|
+
encoding: KeyPairGenConfig,
|
|
149
|
+
): {
|
|
150
|
+
publicKey: PublicKeyObject | Buffer | string | ArrayBuffer;
|
|
151
|
+
privateKey: PrivateKeyObject | Buffer | string | ArrayBuffer;
|
|
152
|
+
} {
|
|
153
|
+
const dh = dh_prepareKeyGenParams(options);
|
|
154
|
+
dh.generateKeyPairSync();
|
|
155
|
+
return dh_formatKeyPairOutput(dh, encoding);
|
|
156
|
+
}
|
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 };
|