react-native-quick-crypto 1.0.8 → 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.
Files changed (171) hide show
  1. package/QuickCrypto.podspec +56 -6
  2. package/README.md +17 -11
  3. package/android/CMakeLists.txt +4 -0
  4. package/android/build.gradle +3 -0
  5. package/cpp/cipher/HybridCipherFactory.hpp +15 -1
  6. package/cpp/cipher/OCBCipher.cpp +4 -4
  7. package/cpp/cipher/XChaCha20Poly1305Cipher.cpp +161 -0
  8. package/cpp/cipher/XChaCha20Poly1305Cipher.hpp +43 -0
  9. package/cpp/cipher/XSalsa20Poly1305Cipher.cpp +145 -0
  10. package/cpp/cipher/XSalsa20Poly1305Cipher.hpp +42 -0
  11. package/cpp/dh/HybridDiffieHellman.cpp +10 -0
  12. package/cpp/dh/HybridDiffieHellman.hpp +1 -0
  13. package/cpp/ec/HybridEcKeyPair.cpp +21 -0
  14. package/cpp/ec/HybridEcKeyPair.hpp +1 -0
  15. package/cpp/hash/HybridHash.cpp +1 -1
  16. package/cpp/hash/HybridHash.hpp +1 -1
  17. package/cpp/hmac/HybridHmac.cpp +1 -1
  18. package/cpp/hmac/HybridHmac.hpp +1 -1
  19. package/cpp/keys/HybridKeyObjectHandle.cpp +112 -1
  20. package/cpp/keys/HybridKeyObjectHandle.hpp +5 -1
  21. package/deps/ncrypto/.bazelrc +0 -1
  22. package/deps/ncrypto/.bazelversion +1 -1
  23. package/deps/ncrypto/.github/workflows/commitlint.yml +16 -0
  24. package/deps/ncrypto/.github/workflows/linter.yml +2 -2
  25. package/deps/ncrypto/.github/workflows/release-please.yml +16 -0
  26. package/deps/ncrypto/.github/workflows/ubuntu.yml +82 -0
  27. package/deps/ncrypto/.release-please-manifest.json +3 -0
  28. package/deps/ncrypto/BUILD.bazel +9 -1
  29. package/deps/ncrypto/CHANGELOG.md +37 -0
  30. package/deps/ncrypto/CMakeLists.txt +35 -11
  31. package/deps/ncrypto/MODULE.bazel +16 -1
  32. package/deps/ncrypto/MODULE.bazel.lock +299 -118
  33. package/deps/ncrypto/cmake/ncrypto-flags.cmake +1 -0
  34. package/deps/ncrypto/include/ncrypto/aead.h +137 -0
  35. package/deps/ncrypto/include/ncrypto/version.h +14 -0
  36. package/deps/ncrypto/include/ncrypto.h +85 -230
  37. package/deps/ncrypto/ncrypto.pc.in +10 -0
  38. package/deps/ncrypto/release-please-config.json +11 -0
  39. package/deps/ncrypto/src/CMakeLists.txt +31 -6
  40. package/deps/ncrypto/src/aead.cpp +302 -0
  41. package/deps/ncrypto/src/ncrypto.cpp +274 -556
  42. package/deps/ncrypto/tests/BUILD.bazel +2 -0
  43. package/deps/ncrypto/tests/basic.cpp +772 -2
  44. package/deps/ncrypto/tools/run-clang-format.sh +5 -5
  45. package/lib/commonjs/diffie-hellman.js +4 -1
  46. package/lib/commonjs/diffie-hellman.js.map +1 -1
  47. package/lib/commonjs/ec.js +20 -25
  48. package/lib/commonjs/ec.js.map +1 -1
  49. package/lib/commonjs/ed.js +1 -2
  50. package/lib/commonjs/ed.js.map +1 -1
  51. package/lib/commonjs/hash.js +7 -0
  52. package/lib/commonjs/hash.js.map +1 -1
  53. package/lib/commonjs/index.js +24 -2
  54. package/lib/commonjs/index.js.map +1 -1
  55. package/lib/commonjs/keys/classes.js +9 -5
  56. package/lib/commonjs/keys/classes.js.map +1 -1
  57. package/lib/commonjs/subtle.js +82 -31
  58. package/lib/commonjs/subtle.js.map +1 -1
  59. package/lib/commonjs/utils/types.js.map +1 -1
  60. package/lib/module/diffie-hellman.js +4 -0
  61. package/lib/module/diffie-hellman.js.map +1 -1
  62. package/lib/module/ec.js +19 -25
  63. package/lib/module/ec.js.map +1 -1
  64. package/lib/module/ed.js +1 -2
  65. package/lib/module/ed.js.map +1 -1
  66. package/lib/module/hash.js +6 -0
  67. package/lib/module/hash.js.map +1 -1
  68. package/lib/module/index.js +10 -1
  69. package/lib/module/index.js.map +1 -1
  70. package/lib/module/keys/classes.js +9 -5
  71. package/lib/module/keys/classes.js.map +1 -1
  72. package/lib/module/subtle.js +83 -32
  73. package/lib/module/subtle.js.map +1 -1
  74. package/lib/module/utils/types.js.map +1 -1
  75. package/lib/tsconfig.tsbuildinfo +1 -1
  76. package/lib/typescript/diffie-hellman.d.ts +2 -0
  77. package/lib/typescript/diffie-hellman.d.ts.map +1 -1
  78. package/lib/typescript/ec.d.ts +1 -0
  79. package/lib/typescript/ec.d.ts.map +1 -1
  80. package/lib/typescript/ed.d.ts.map +1 -1
  81. package/lib/typescript/hash.d.ts +2 -0
  82. package/lib/typescript/hash.d.ts.map +1 -1
  83. package/lib/typescript/index.d.ts +7 -0
  84. package/lib/typescript/index.d.ts.map +1 -1
  85. package/lib/typescript/keys/classes.d.ts +2 -0
  86. package/lib/typescript/keys/classes.d.ts.map +1 -1
  87. package/lib/typescript/specs/diffie-hellman.nitro.d.ts +1 -0
  88. package/lib/typescript/specs/diffie-hellman.nitro.d.ts.map +1 -1
  89. package/lib/typescript/specs/ecKeyPair.nitro.d.ts +1 -0
  90. package/lib/typescript/specs/ecKeyPair.nitro.d.ts.map +1 -1
  91. package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +2 -0
  92. package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -1
  93. package/lib/typescript/subtle.d.ts.map +1 -1
  94. package/lib/typescript/utils/types.d.ts +12 -5
  95. package/lib/typescript/utils/types.d.ts.map +1 -1
  96. package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +8 -5
  97. package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +1 -1
  98. package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +54 -54
  99. package/nitrogen/generated/android/QuickCryptoOnLoad.hpp +1 -1
  100. package/nitrogen/generated/android/kotlin/com/margelo/nitro/crypto/QuickCryptoOnLoad.kt +1 -1
  101. package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +2 -2
  102. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +1 -1
  103. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +1 -1
  104. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +1 -1
  105. package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +54 -54
  106. package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +5 -1
  107. package/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp +1 -1
  108. package/nitrogen/generated/shared/c++/CipherArgs.hpp +34 -19
  109. package/nitrogen/generated/shared/c++/HybridBlake3Spec.cpp +1 -1
  110. package/nitrogen/generated/shared/c++/HybridBlake3Spec.hpp +1 -3
  111. package/nitrogen/generated/shared/c++/HybridCipherFactorySpec.cpp +1 -1
  112. package/nitrogen/generated/shared/c++/HybridCipherFactorySpec.hpp +1 -1
  113. package/nitrogen/generated/shared/c++/HybridCipherSpec.cpp +1 -1
  114. package/nitrogen/generated/shared/c++/HybridCipherSpec.hpp +1 -3
  115. package/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.cpp +2 -1
  116. package/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.hpp +3 -3
  117. package/nitrogen/generated/shared/c++/HybridECDHSpec.cpp +1 -1
  118. package/nitrogen/generated/shared/c++/HybridECDHSpec.hpp +2 -3
  119. package/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.cpp +2 -1
  120. package/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.hpp +2 -3
  121. package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp +1 -1
  122. package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp +2 -3
  123. package/nitrogen/generated/shared/c++/HybridHashSpec.cpp +1 -1
  124. package/nitrogen/generated/shared/c++/HybridHashSpec.hpp +2 -4
  125. package/nitrogen/generated/shared/c++/HybridHkdfSpec.cpp +1 -1
  126. package/nitrogen/generated/shared/c++/HybridHkdfSpec.hpp +2 -3
  127. package/nitrogen/generated/shared/c++/HybridHmacSpec.cpp +1 -1
  128. package/nitrogen/generated/shared/c++/HybridHmacSpec.hpp +3 -4
  129. package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +3 -1
  130. package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +8 -4
  131. package/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.cpp +1 -1
  132. package/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.hpp +2 -3
  133. package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp +1 -1
  134. package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp +2 -3
  135. package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +1 -1
  136. package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +2 -3
  137. package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.cpp +1 -1
  138. package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.hpp +1 -3
  139. package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.cpp +1 -1
  140. package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.hpp +1 -3
  141. package/nitrogen/generated/shared/c++/HybridScryptSpec.cpp +1 -1
  142. package/nitrogen/generated/shared/c++/HybridScryptSpec.hpp +2 -3
  143. package/nitrogen/generated/shared/c++/HybridSignHandleSpec.cpp +1 -1
  144. package/nitrogen/generated/shared/c++/HybridSignHandleSpec.hpp +1 -3
  145. package/nitrogen/generated/shared/c++/HybridUtilsSpec.cpp +1 -1
  146. package/nitrogen/generated/shared/c++/HybridUtilsSpec.hpp +2 -3
  147. package/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.cpp +1 -1
  148. package/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.hpp +1 -3
  149. package/nitrogen/generated/shared/c++/JWK.hpp +84 -68
  150. package/nitrogen/generated/shared/c++/JWKkty.hpp +5 -1
  151. package/nitrogen/generated/shared/c++/JWKuse.hpp +1 -1
  152. package/nitrogen/generated/shared/c++/KFormatType.hpp +1 -1
  153. package/nitrogen/generated/shared/c++/KeyDetail.hpp +39 -23
  154. package/nitrogen/generated/shared/c++/KeyEncoding.hpp +1 -1
  155. package/nitrogen/generated/shared/c++/KeyObject.hpp +21 -5
  156. package/nitrogen/generated/shared/c++/KeyType.hpp +1 -1
  157. package/nitrogen/generated/shared/c++/KeyUsage.hpp +1 -1
  158. package/nitrogen/generated/shared/c++/NamedCurve.hpp +1 -1
  159. package/package.json +10 -7
  160. package/src/diffie-hellman.ts +6 -0
  161. package/src/ec.ts +23 -19
  162. package/src/ed.ts +1 -2
  163. package/src/hash.ts +11 -0
  164. package/src/index.ts +9 -0
  165. package/src/keys/classes.ts +10 -3
  166. package/src/specs/diffie-hellman.nitro.ts +1 -0
  167. package/src/specs/ecKeyPair.nitro.ts +2 -0
  168. package/src/specs/keyObjectHandle.nitro.ts +2 -0
  169. package/src/subtle.ts +131 -32
  170. package/src/utils/types.ts +18 -3
  171. package/deps/ncrypto/WORKSPACE +0 -15
@@ -2,7 +2,7 @@
2
2
  /// KFormatType.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  #pragma once
@@ -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 © 2025 Marc Rousavy @ Margelo
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 (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "length"))) return false;
82
- if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "publicExponent"))) return false;
83
- if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "modulusLength"))) return false;
84
- if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "hashAlgorithm"))) return false;
85
- if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "mgf1HashAlgorithm"))) return false;
86
- if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "saltLength"))) return false;
87
- if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "namedCurve"))) return false;
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
  /// KeyEncoding.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  #pragma once
@@ -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 © 2025 Marc Rousavy @ Margelo
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 (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, "extractable"))) return false;
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
  };
@@ -2,7 +2,7 @@
2
2
  /// KeyType.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  #pragma once
@@ -2,7 +2,7 @@
2
2
  /// KeyUsage.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  #pragma once
@@ -2,7 +2,7 @@
2
2
  /// NamedCurve.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  #pragma once
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-quick-crypto",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "A fast implementation of Node's `crypto` module written in C/C++ JSI",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -18,7 +18,7 @@
18
18
  "format:fix": "prettier --write \"**/*.{js,ts,tsx}\"",
19
19
  "prepare": "bun clean && bun tsc && bob build",
20
20
  "release": "release-it",
21
- "specs": "nitro-codegen",
21
+ "specs": "nitrogen",
22
22
  "test": "jest"
23
23
  },
24
24
  "files": [
@@ -75,7 +75,6 @@
75
75
  "dependencies": {
76
76
  "@craftzdog/react-native-buffer": "6.1.0",
77
77
  "events": "3.3.0",
78
- "react-native-quick-base64": "2.2.2",
79
78
  "readable-stream": "4.5.2",
80
79
  "safe-buffer": "^5.2.1",
81
80
  "util": "0.12.5"
@@ -89,14 +88,15 @@
89
88
  "expo": "^54.0.25",
90
89
  "expo-build-properties": "^1.0.0",
91
90
  "jest": "29.7.0",
92
- "nitro-codegen": "0.29.1",
91
+ "nitrogen": "0.33.2",
93
92
  "react-native-builder-bob": "0.40.15",
94
- "react-native-nitro-modules": "0.29.1"
93
+ "react-native-nitro-modules": "0.33.2"
95
94
  },
96
95
  "peerDependencies": {
97
96
  "react": "*",
98
97
  "react-native": "*",
99
98
  "react-native-nitro-modules": ">=0.29.1",
99
+ "react-native-quick-base64": ">=2.1.0",
100
100
  "expo": ">=48.0.0",
101
101
  "expo-build-properties": "*"
102
102
  },
@@ -111,7 +111,10 @@
111
111
  "release-it": {
112
112
  "npm": {
113
113
  "publish": true,
114
- "skipChecks": true
114
+ "skipChecks": true,
115
+ "versionArgs": [
116
+ "--workspaces-update=false"
117
+ ]
115
118
  },
116
119
  "git": false,
117
120
  "github": {
@@ -151,7 +154,7 @@
151
154
  },
152
155
  "trustedDependencies": [
153
156
  "react-native-quick-crypto",
154
- "nitro-codegen",
157
+ "nitrogen",
155
158
  "react-native-nitro-modules"
156
159
  ]
157
160
  }
@@ -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 publicParams = algorithm as SubtleAlgorithm & { public?: CryptoKey };
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
- // Create new ECDH instance (Node.js style wrapper)
512
- const ecdh = new ECDH(namedCurve);
527
+ const opensslCurve =
528
+ kNamedCurveAliases[namedCurve as keyof typeof kNamedCurveAliases];
529
+ const ecdh = new ECDH(opensslCurve);
513
530
 
514
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
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
- // Public key
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 publicParams = algorithm as SubtleAlgorithm & { public?: CryptoKey };
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,7 +40,9 @@ const QuickCrypto = {
39
40
  ...dh,
40
41
  ...utils,
41
42
  ...subtle,
43
+ getCurves,
42
44
  constants,
45
+ Buffer,
43
46
  };
44
47
 
45
48
  /**
@@ -52,6 +55,10 @@ export const install = () => {
52
55
 
53
56
  // @ts-expect-error subtle isn't fully implemented and Cryptokey is missing
54
57
  global.crypto = QuickCrypto;
58
+
59
+ // Install base64 globals (base64ToArrayBuffer, base64FromArrayBuffer)
60
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
61
+ require('react-native-quick-base64');
55
62
  };
56
63
 
57
64
  // random, cipher, hash use nextTick
@@ -76,11 +83,13 @@ export * from './pbkdf2';
76
83
  export * from './scrypt';
77
84
  export * from './random';
78
85
  export * from './ecdh';
86
+ export { getCurves } from './ec';
79
87
  export * from './diffie-hellman';
80
88
  export * from './utils';
81
89
  export * from './subtle';
82
90
  export { subtle, isCryptoKeyPair } from './subtle';
83
91
  export { constants } from './constants';
92
+ export { Buffer } from '@craftzdog/react-native-buffer';
84
93
 
85
94
  // Additional exports for CommonJS compatibility
86
95
  module.exports = QuickCrypto;
@@ -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
- // get symmetricKeySize() {
201
- // return this.handle.getSymmetricKeySize();
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;
@@ -12,4 +12,5 @@ export interface DiffieHellman
12
12
  getPrivateKey(): ArrayBuffer;
13
13
  setPublicKey(publicKey: ArrayBuffer): void;
14
14
  setPrivateKey(privateKey: ArrayBuffer): void;
15
+ getVerifyError(): number;
15
16
  }
@@ -35,4 +35,6 @@ export interface EcKeyPair
35
35
  signature: ArrayBuffer,
36
36
  hashAlgorithm: string,
37
37
  ): boolean;
38
+
39
+ getSupportedCurves(): string[];
38
40
  }
@@ -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
  }