react-native-quick-crypto 1.0.0-beta.1 → 1.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/QuickCrypto.podspec +17 -4
  2. package/README.md +172 -0
  3. package/android/CMakeLists.txt +28 -17
  4. package/android/build.gradle +36 -3
  5. package/android/src/main/cpp/cpp-adapter.cpp +3 -10
  6. package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +15 -10
  7. package/cpp/ed25519/HybridEdKeyPair.cpp +268 -0
  8. package/cpp/ed25519/HybridEdKeyPair.hpp +85 -0
  9. package/cpp/pbkdf2/HybridPbkdf2.cpp +72 -0
  10. package/cpp/pbkdf2/HybridPbkdf2.hpp +35 -0
  11. package/cpp/random/HybridRandom.cpp +59 -0
  12. package/cpp/random/HybridRandom.hpp +33 -0
  13. package/cpp/utils/Utils.hpp +20 -0
  14. package/deps/fastpbkdf2/fastpbkdf2.c +352 -0
  15. package/deps/fastpbkdf2/fastpbkdf2.h +68 -0
  16. package/lib/commonjs/ed.js +42 -0
  17. package/lib/commonjs/ed.js.map +1 -0
  18. package/lib/commonjs/index.js +61 -10
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/commonjs/keys/classes.js +191 -0
  21. package/lib/commonjs/keys/classes.js.map +1 -0
  22. package/lib/commonjs/keys/generateKeyPair.js +148 -0
  23. package/lib/commonjs/keys/generateKeyPair.js.map +1 -0
  24. package/lib/commonjs/keys/index.js +62 -0
  25. package/lib/commonjs/keys/index.js.map +1 -0
  26. package/lib/commonjs/keys/signVerify.js +41 -0
  27. package/lib/commonjs/keys/signVerify.js.map +1 -0
  28. package/lib/commonjs/keys/utils.js +118 -0
  29. package/lib/commonjs/keys/utils.js.map +1 -0
  30. package/lib/commonjs/pbkdf2.js +89 -0
  31. package/lib/commonjs/pbkdf2.js.map +1 -0
  32. package/lib/commonjs/random.js +3 -3
  33. package/lib/commonjs/random.js.map +1 -1
  34. package/lib/commonjs/specs/edKeyPair.nitro.js +6 -0
  35. package/lib/commonjs/specs/edKeyPair.nitro.js.map +1 -0
  36. package/lib/commonjs/specs/keyObjectHandle.nitro.js +6 -0
  37. package/lib/commonjs/specs/keyObjectHandle.nitro.js.map +1 -0
  38. package/lib/commonjs/specs/pbkdf2.nitro.js +6 -0
  39. package/lib/commonjs/specs/pbkdf2.nitro.js.map +1 -0
  40. package/lib/commonjs/utils/conversion.js +101 -6
  41. package/lib/commonjs/utils/conversion.js.map +1 -1
  42. package/lib/commonjs/utils/errors.js +14 -0
  43. package/lib/commonjs/utils/errors.js.map +1 -0
  44. package/lib/commonjs/utils/hashnames.js +90 -0
  45. package/lib/commonjs/utils/hashnames.js.map +1 -0
  46. package/lib/commonjs/utils/index.js +54 -5
  47. package/lib/commonjs/utils/index.js.map +1 -1
  48. package/lib/commonjs/utils/types.js +38 -0
  49. package/lib/commonjs/utils/types.js.map +1 -1
  50. package/lib/commonjs/utils/validation.js +25 -0
  51. package/lib/commonjs/utils/validation.js.map +1 -0
  52. package/lib/module/ed.js +37 -0
  53. package/lib/module/ed.js.map +1 -0
  54. package/lib/module/index.js +16 -9
  55. package/lib/module/index.js.map +1 -1
  56. package/lib/module/keys/classes.js +182 -0
  57. package/lib/module/keys/classes.js.map +1 -0
  58. package/lib/module/keys/generateKeyPair.js +148 -0
  59. package/lib/module/keys/generateKeyPair.js.map +1 -0
  60. package/lib/module/keys/index.js +29 -0
  61. package/lib/module/keys/index.js.map +1 -0
  62. package/lib/module/keys/signVerify.js +41 -0
  63. package/lib/module/keys/signVerify.js.map +1 -0
  64. package/lib/module/keys/utils.js +110 -0
  65. package/lib/module/keys/utils.js.map +1 -0
  66. package/lib/module/pbkdf2.js +83 -0
  67. package/lib/module/pbkdf2.js.map +1 -0
  68. package/lib/module/random.js +1 -1
  69. package/lib/module/random.js.map +1 -1
  70. package/lib/module/specs/edKeyPair.nitro.js +4 -0
  71. package/lib/module/specs/edKeyPair.nitro.js.map +1 -0
  72. package/lib/module/specs/keyObjectHandle.nitro.js +4 -0
  73. package/lib/module/specs/keyObjectHandle.nitro.js.map +1 -0
  74. package/lib/module/specs/pbkdf2.nitro.js +4 -0
  75. package/lib/module/specs/pbkdf2.nitro.js.map +1 -0
  76. package/lib/module/utils/conversion.js +99 -8
  77. package/lib/module/utils/conversion.js.map +1 -1
  78. package/lib/module/utils/errors.js +10 -0
  79. package/lib/module/utils/errors.js.map +1 -0
  80. package/lib/module/utils/hashnames.js +88 -0
  81. package/lib/module/utils/hashnames.js.map +1 -0
  82. package/lib/module/utils/index.js +5 -5
  83. package/lib/module/utils/index.js.map +1 -1
  84. package/lib/module/utils/types.js +40 -0
  85. package/lib/module/utils/types.js.map +1 -1
  86. package/lib/module/utils/validation.js +19 -0
  87. package/lib/module/utils/validation.js.map +1 -0
  88. package/lib/tsconfig.tsbuildinfo +1 -1
  89. package/lib/typescript/ed.d.ts +17 -0
  90. package/lib/typescript/ed.d.ts.map +1 -0
  91. package/lib/typescript/index.d.ts +50 -9
  92. package/lib/typescript/index.d.ts.map +1 -1
  93. package/lib/typescript/keys/classes.d.ts +38 -0
  94. package/lib/typescript/keys/classes.d.ts.map +1 -0
  95. package/lib/typescript/keys/generateKeyPair.d.ts +1 -0
  96. package/lib/typescript/keys/generateKeyPair.d.ts.map +1 -0
  97. package/lib/typescript/keys/index.d.ts +4 -0
  98. package/lib/typescript/keys/index.d.ts.map +1 -0
  99. package/lib/typescript/keys/signVerify.d.ts +1 -0
  100. package/lib/typescript/keys/signVerify.d.ts.map +1 -0
  101. package/lib/typescript/keys/utils.d.ts +32 -0
  102. package/lib/typescript/keys/utils.d.ts.map +1 -0
  103. package/lib/typescript/pbkdf2.d.ts +12 -0
  104. package/lib/typescript/pbkdf2.d.ts.map +1 -0
  105. package/lib/typescript/random.d.ts +5 -5
  106. package/lib/typescript/random.d.ts.map +1 -1
  107. package/lib/typescript/specs/edKeyPair.nitro.d.ts +16 -0
  108. package/lib/typescript/specs/edKeyPair.nitro.d.ts.map +1 -0
  109. package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +15 -0
  110. package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -0
  111. package/lib/typescript/specs/pbkdf2.nitro.d.ts +9 -0
  112. package/lib/typescript/specs/pbkdf2.nitro.d.ts.map +1 -0
  113. package/lib/typescript/utils/conversion.d.ts +23 -2
  114. package/lib/typescript/utils/conversion.d.ts.map +1 -1
  115. package/lib/typescript/utils/errors.d.ts +7 -0
  116. package/lib/typescript/utils/errors.d.ts.map +1 -0
  117. package/lib/typescript/utils/hashnames.d.ts +11 -0
  118. package/lib/typescript/utils/hashnames.d.ts.map +1 -0
  119. package/lib/typescript/utils/index.d.ts +5 -5
  120. package/lib/typescript/utils/index.d.ts.map +1 -1
  121. package/lib/typescript/utils/types.d.ts +158 -1
  122. package/lib/typescript/utils/types.d.ts.map +1 -1
  123. package/lib/typescript/utils/validation.d.ts +8 -0
  124. package/lib/typescript/utils/validation.d.ts.map +1 -0
  125. package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +65 -0
  126. package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +27 -0
  127. package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +64 -0
  128. package/nitrogen/generated/android/QuickCryptoOnLoad.hpp +25 -0
  129. package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +58 -0
  130. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +17 -0
  131. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +27 -0
  132. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +38 -0
  133. package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +55 -0
  134. package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +12 -0
  135. package/nitrogen/generated/shared/c++/CFRGKeyPairType.hpp +86 -0
  136. package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp +29 -0
  137. package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp +74 -0
  138. package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +27 -0
  139. package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +93 -0
  140. package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp +22 -0
  141. package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp +66 -0
  142. package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +22 -0
  143. package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +65 -0
  144. package/nitrogen/generated/shared/c++/JWK.hpp +162 -0
  145. package/nitrogen/generated/shared/c++/JWKkty.hpp +86 -0
  146. package/nitrogen/generated/shared/c++/JWKuse.hpp +78 -0
  147. package/nitrogen/generated/shared/c++/KFormatType.hpp +65 -0
  148. package/nitrogen/generated/shared/c++/KeyDetail.hpp +93 -0
  149. package/nitrogen/generated/shared/c++/KeyEncoding.hpp +66 -0
  150. package/nitrogen/generated/shared/c++/KeyType.hpp +65 -0
  151. package/nitrogen/generated/shared/c++/KeyUsage.hpp +102 -0
  152. package/nitrogen/generated/shared/c++/NamedCurve.hpp +82 -0
  153. package/package.json +55 -34
  154. package/src/ed.ts +79 -0
  155. package/src/index.ts +15 -9
  156. package/src/keys/classes.ts +211 -0
  157. package/src/keys/generateKeyPair.ts +146 -0
  158. package/src/keys/index.ts +42 -0
  159. package/src/keys/signVerify.ts +39 -0
  160. package/src/keys/utils.ts +184 -0
  161. package/src/pbkdf2.ts +154 -0
  162. package/src/random.ts +19 -23
  163. package/src/specs/edKeyPair.nitro.ts +41 -0
  164. package/src/specs/keyObjectHandle.nitro.ts +32 -0
  165. package/src/specs/pbkdf2.nitro.ts +18 -0
  166. package/src/specs/random.nitro.ts +2 -2
  167. package/src/utils/conversion.ts +116 -9
  168. package/src/utils/errors.ts +15 -0
  169. package/src/utils/hashnames.ts +96 -0
  170. package/src/utils/index.ts +5 -6
  171. package/src/utils/types.ts +263 -3
  172. package/src/utils/validation.ts +35 -0
  173. package/ios/QuickCryptoOnLoad.mm +0 -19
@@ -0,0 +1,65 @@
1
+ ///
2
+ /// KeyType.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <cmath>
11
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
12
+ #include <NitroModules/JSIConverter.hpp>
13
+ #else
14
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
15
+ #endif
16
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
17
+ #include <NitroModules/NitroDefines.hpp>
18
+ #else
19
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
20
+ #endif
21
+
22
+ namespace margelo::nitro::crypto {
23
+
24
+ /**
25
+ * An enum which can be represented as a JavaScript enum (KeyType).
26
+ */
27
+ enum class KeyType {
28
+ SECRET SWIFT_NAME(secret) = 0,
29
+ PUBLIC SWIFT_NAME(public) = 1,
30
+ PRIVATE SWIFT_NAME(private) = 2,
31
+ } CLOSED_ENUM;
32
+
33
+ } // namespace margelo::nitro::crypto
34
+
35
+ namespace margelo::nitro {
36
+
37
+ using namespace margelo::nitro::crypto;
38
+
39
+ // C++ KeyType <> JS KeyType (enum)
40
+ template <>
41
+ struct JSIConverter<KeyType> {
42
+ static inline KeyType fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
43
+ int enumValue = JSIConverter<int>::fromJSI(runtime, arg);
44
+ return static_cast<KeyType>(enumValue);
45
+ }
46
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, KeyType arg) {
47
+ int enumValue = static_cast<int>(arg);
48
+ return JSIConverter<int>::toJSI(runtime, enumValue);
49
+ }
50
+ static inline bool canConvert(jsi::Runtime&, const jsi::Value& value) {
51
+ if (!value.isNumber()) {
52
+ return false;
53
+ }
54
+ double integer;
55
+ double fraction = modf(value.getNumber(), &integer);
56
+ if (fraction != 0.0) {
57
+ // It is some kind of floating point number - our enums are ints.
58
+ return false;
59
+ }
60
+ // Check if we are within the bounds of the enum.
61
+ return integer >= 0 && integer <= 2;
62
+ }
63
+ };
64
+
65
+ } // namespace margelo::nitro
@@ -0,0 +1,102 @@
1
+ ///
2
+ /// KeyUsage.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::crypto {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (KeyUsage).
30
+ */
31
+ enum class KeyUsage {
32
+ ENCRYPT SWIFT_NAME(encrypt) = 0,
33
+ DECRYPT SWIFT_NAME(decrypt) = 1,
34
+ SIGN SWIFT_NAME(sign) = 2,
35
+ VERIFY SWIFT_NAME(verify) = 3,
36
+ DERIVEKEY SWIFT_NAME(derivekey) = 4,
37
+ DERIVEBITS SWIFT_NAME(derivebits) = 5,
38
+ WRAPKEY SWIFT_NAME(wrapkey) = 6,
39
+ UNWRAPKEY SWIFT_NAME(unwrapkey) = 7,
40
+ } CLOSED_ENUM;
41
+
42
+ } // namespace margelo::nitro::crypto
43
+
44
+ namespace margelo::nitro {
45
+
46
+ using namespace margelo::nitro::crypto;
47
+
48
+ // C++ KeyUsage <> JS KeyUsage (union)
49
+ template <>
50
+ struct JSIConverter<KeyUsage> {
51
+ static inline KeyUsage fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
52
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
53
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
54
+ case hashString("encrypt"): return KeyUsage::ENCRYPT;
55
+ case hashString("decrypt"): return KeyUsage::DECRYPT;
56
+ case hashString("sign"): return KeyUsage::SIGN;
57
+ case hashString("verify"): return KeyUsage::VERIFY;
58
+ case hashString("deriveKey"): return KeyUsage::DERIVEKEY;
59
+ case hashString("deriveBits"): return KeyUsage::DERIVEBITS;
60
+ case hashString("wrapKey"): return KeyUsage::WRAPKEY;
61
+ case hashString("unwrapKey"): return KeyUsage::UNWRAPKEY;
62
+ default: [[unlikely]]
63
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum KeyUsage - invalid value!");
64
+ }
65
+ }
66
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, KeyUsage arg) {
67
+ switch (arg) {
68
+ case KeyUsage::ENCRYPT: return JSIConverter<std::string>::toJSI(runtime, "encrypt");
69
+ case KeyUsage::DECRYPT: return JSIConverter<std::string>::toJSI(runtime, "decrypt");
70
+ case KeyUsage::SIGN: return JSIConverter<std::string>::toJSI(runtime, "sign");
71
+ case KeyUsage::VERIFY: return JSIConverter<std::string>::toJSI(runtime, "verify");
72
+ case KeyUsage::DERIVEKEY: return JSIConverter<std::string>::toJSI(runtime, "deriveKey");
73
+ case KeyUsage::DERIVEBITS: return JSIConverter<std::string>::toJSI(runtime, "deriveBits");
74
+ case KeyUsage::WRAPKEY: return JSIConverter<std::string>::toJSI(runtime, "wrapKey");
75
+ case KeyUsage::UNWRAPKEY: return JSIConverter<std::string>::toJSI(runtime, "unwrapKey");
76
+ default: [[unlikely]]
77
+ throw std::invalid_argument("Cannot convert KeyUsage to JS - invalid value: "
78
+ + std::to_string(static_cast<int>(arg)) + "!");
79
+ }
80
+ }
81
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
82
+ if (!value.isString()) {
83
+ return false;
84
+ }
85
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
86
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
87
+ case hashString("encrypt"):
88
+ case hashString("decrypt"):
89
+ case hashString("sign"):
90
+ case hashString("verify"):
91
+ case hashString("deriveKey"):
92
+ case hashString("deriveBits"):
93
+ case hashString("wrapKey"):
94
+ case hashString("unwrapKey"):
95
+ return true;
96
+ default:
97
+ return false;
98
+ }
99
+ }
100
+ };
101
+
102
+ } // namespace margelo::nitro
@@ -0,0 +1,82 @@
1
+ ///
2
+ /// NamedCurve.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::crypto {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (NamedCurve).
30
+ */
31
+ enum class NamedCurve {
32
+ P_256 SWIFT_NAME(p256) = 0,
33
+ P_384 SWIFT_NAME(p384) = 1,
34
+ P_521 SWIFT_NAME(p521) = 2,
35
+ } CLOSED_ENUM;
36
+
37
+ } // namespace margelo::nitro::crypto
38
+
39
+ namespace margelo::nitro {
40
+
41
+ using namespace margelo::nitro::crypto;
42
+
43
+ // C++ NamedCurve <> JS NamedCurve (union)
44
+ template <>
45
+ struct JSIConverter<NamedCurve> {
46
+ static inline NamedCurve fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
47
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
48
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
49
+ case hashString("P-256"): return NamedCurve::P_256;
50
+ case hashString("P-384"): return NamedCurve::P_384;
51
+ case hashString("P-521"): return NamedCurve::P_521;
52
+ default: [[unlikely]]
53
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum NamedCurve - invalid value!");
54
+ }
55
+ }
56
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, NamedCurve arg) {
57
+ switch (arg) {
58
+ case NamedCurve::P_256: return JSIConverter<std::string>::toJSI(runtime, "P-256");
59
+ case NamedCurve::P_384: return JSIConverter<std::string>::toJSI(runtime, "P-384");
60
+ case NamedCurve::P_521: return JSIConverter<std::string>::toJSI(runtime, "P-521");
61
+ default: [[unlikely]]
62
+ throw std::invalid_argument("Cannot convert NamedCurve to JS - invalid value: "
63
+ + std::to_string(static_cast<int>(arg)) + "!");
64
+ }
65
+ }
66
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
67
+ if (!value.isString()) {
68
+ return false;
69
+ }
70
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
71
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
72
+ case hashString("P-256"):
73
+ case hashString("P-384"):
74
+ case hashString("P-521"):
75
+ return true;
76
+ default:
77
+ return false;
78
+ }
79
+ }
80
+ };
81
+
82
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-quick-crypto",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.10",
4
4
  "description": "A fast implementation of Node's `crypto` module written in C/C++ JSI",
5
5
  "type": "module",
6
6
  "main": "lib/commonjs/index",
@@ -8,19 +8,31 @@
8
8
  "types": "lib/typescript/index.d.ts",
9
9
  "react-native": "src/index",
10
10
  "source": "src/index",
11
+ "scripts": {
12
+ "clean": "del-cli android/build lib",
13
+ "tsc": "tsc --noEmit",
14
+ "typescript": "tsc --noEmit",
15
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
16
+ "lint:fix": "eslint \"**/*.{js,ts,tsx}\" --fix",
17
+ "format": "prettier --check \"**/*.{js,ts,tsx}\"",
18
+ "format:fix": "prettier --write \"**/*.{js,ts,tsx}\"",
19
+ "prepare": "bun clean && bun tsc && bob build",
20
+ "release": "release-it",
21
+ "specs": "nitro-codegen",
22
+ "test": "jest"
23
+ },
11
24
  "files": [
12
25
  "src",
13
- "react-native.config.js",
14
26
  "lib",
15
27
  "android/build.gradle",
16
28
  "android/gradle.properties",
17
29
  "android/CMakeLists.txt",
18
30
  "android/src",
19
- "ios/**/*.h",
20
- "ios/**/*.m",
21
- "ios/**/*.mm",
22
- "ios/**/*.cpp",
23
- "ios/**/*.swift",
31
+ "ios",
32
+ "cpp",
33
+ "deps",
34
+ "nitrogen",
35
+ "react-native.config.js",
24
36
  "app.plugin.js",
25
37
  "*.podspec",
26
38
  "README.md",
@@ -28,17 +40,6 @@
28
40
  "!**/__fixtures__",
29
41
  "!**/__mocks__"
30
42
  ],
31
- "scripts": {
32
- "clean": "del-cli lib",
33
- "tsc": "tsc --noEmit",
34
- "typescript": "tsc --noEmit",
35
- "lint": "eslint \"**/*.{js,ts,tsx}\"",
36
- "lint-fix": "eslint \"**/*.{js,ts,tsx}\" --fix",
37
- "prepare": "bun clean && bob build",
38
- "release-it": "bun prepare && release-it",
39
- "test": "jest",
40
- "postinstall": "bun tsc"
41
- },
42
43
  "keywords": [
43
44
  "react-native",
44
45
  "ios",
@@ -55,7 +56,8 @@
55
56
  },
56
57
  "authors": [
57
58
  "Szymon Kapała <szymon20000@gmail.com>",
58
- "Marc Rousavy <me@mrousavy.com> (https://github.com/mrousavy)"
59
+ "Marc Rousavy <me@mrousavy.com> (https://github.com/mrousavy)",
60
+ "Brad Anderson <brad@sankatygroup.com> (https://github.com/boorad)"
59
61
  ],
60
62
  "license": "MIT",
61
63
  "bugs": {
@@ -68,7 +70,6 @@
68
70
  "dependencies": {
69
71
  "@craftzdog/react-native-buffer": "6.0.5",
70
72
  "events": "3.3.0",
71
- "react-native-nitro-modules": "0.4.0",
72
73
  "react-native-quick-base64": "2.1.2",
73
74
  "readable-stream": "4.5.2",
74
75
  "string_decoder": "1.3.0",
@@ -76,28 +77,28 @@
76
77
  },
77
78
  "devDependencies": {
78
79
  "@eslint/compat": "^1.1.1",
79
- "@eslint/js": "10.0.0",
80
- "@release-it/bumper": "6.0.1",
80
+ "@eslint/js": "9.18.0",
81
+ "@release-it/bumper": "7.0.1",
81
82
  "@types/jest": "29.5.11",
82
83
  "@types/node": "22.0.0",
83
84
  "@types/react": "18.3.3",
84
- "@types/readable-stream": "4.0.11",
85
- "del-cli": "5.1.0",
85
+ "@types/readable-stream": "4.0.18",
86
+ "del-cli": "6.0.0",
86
87
  "eslint": "9.9.0",
87
- "eslint-plugin-react-native": "^4.1.0",
88
+ "eslint-plugin-react-native": "5.0.0",
88
89
  "jest": "29.7.0",
89
- "nitro-codegen": "0.4.0",
90
- "prettier": "3.2.5",
91
- "react": "18.3.1",
92
- "react-native": "0.74.5",
93
- "react-native-builder-bob": "0.29.1",
94
- "release-it": "17.6.0",
90
+ "nitro-codegen": "0.21.0",
91
+ "prettier": "3.3.3",
92
+ "react-native-builder-bob": "0.35.2",
93
+ "react-native-nitro-modules": "0.21.0",
94
+ "release-it": "18.1.1",
95
95
  "typescript": "5.1.6",
96
96
  "typescript-eslint": "^8.1.0"
97
97
  },
98
98
  "peerDependencies": {
99
99
  "react": "*",
100
- "react-native": "*"
100
+ "react-native": "*",
101
+ "react-native-nitro-modules": "*"
101
102
  },
102
103
  "release-it": {
103
104
  "npm": {
@@ -107,7 +108,22 @@
107
108
  "github": {
108
109
  "release": false
109
110
  },
110
- "plugins": {}
111
+ "hooks": {
112
+ "after:bump": "bun tsc && bun lint && bun format && bun prepare"
113
+ },
114
+ "plugins": {
115
+ "@release-it/bumper": {
116
+ "out": [
117
+ {
118
+ "file": "../../example/package.json",
119
+ "path": [
120
+ "version",
121
+ "dependencies.react-native-quick-crypto"
122
+ ]
123
+ }
124
+ ]
125
+ }
126
+ }
111
127
  },
112
128
  "react-native-builder-bob": {
113
129
  "source": "src",
@@ -123,5 +139,10 @@
123
139
  }
124
140
  ]
125
141
  ]
126
- }
142
+ },
143
+ "trustedDependencies": [
144
+ "react-native-quick-crypto",
145
+ "nitro-codegen",
146
+ "react-native-nitro-modules"
147
+ ]
127
148
  }
package/src/ed.ts ADDED
@@ -0,0 +1,79 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ import { binaryLikeToArrayBuffer as toAB } from './utils';
3
+ import type { EdKeyPair } from './specs/edKeyPair.nitro';
4
+ import type { BinaryLike, CFRGKeyPairType, KeyPairGenConfig } from './utils';
5
+
6
+ export class Ed {
7
+ type: CFRGKeyPairType;
8
+ config: KeyPairGenConfig;
9
+ native: EdKeyPair;
10
+
11
+ constructor(type: CFRGKeyPairType, config: KeyPairGenConfig) {
12
+ this.type = type;
13
+ this.config = config;
14
+ this.native = NitroModules.createHybridObject<EdKeyPair>('EdKeyPair');
15
+ this.native.setCurve(type);
16
+ }
17
+
18
+ async generateKeyPair(): Promise<void> {
19
+ this.native.generateKeyPair(
20
+ this.config.publicFormat || (-1 as number),
21
+ this.config.publicType || (-1 as number),
22
+ this.config.privateFormat || (-1 as number),
23
+ this.config.privateType || (-1 as number),
24
+ this.config.cipher as string,
25
+ this.config.passphrase as ArrayBuffer,
26
+ );
27
+ }
28
+
29
+ generateKeyPairSync(): void {
30
+ this.native.generateKeyPairSync(
31
+ this.config.publicFormat || (-1 as number),
32
+ this.config.publicType || (-1 as number),
33
+ this.config.privateFormat || (-1 as number),
34
+ this.config.privateType || (-1 as number),
35
+ this.config.cipher as string,
36
+ this.config.passphrase as ArrayBuffer,
37
+ );
38
+ }
39
+
40
+ getPublicKey(): ArrayBuffer {
41
+ return this.native.getPublicKey();
42
+ }
43
+
44
+ getPrivateKey(): ArrayBuffer {
45
+ return this.native.getPrivateKey();
46
+ }
47
+
48
+ async sign(message: BinaryLike, key?: BinaryLike): Promise<ArrayBuffer> {
49
+ return key
50
+ ? this.native.sign(toAB(message), toAB(key))
51
+ : this.native.sign(toAB(message));
52
+ }
53
+
54
+ signSync(message: BinaryLike, key?: BinaryLike): ArrayBuffer {
55
+ return key
56
+ ? this.native.signSync(toAB(message), toAB(key))
57
+ : this.native.signSync(toAB(message));
58
+ }
59
+
60
+ async verify(
61
+ signature: BinaryLike,
62
+ message: BinaryLike,
63
+ key?: BinaryLike,
64
+ ): Promise<boolean> {
65
+ return key
66
+ ? this.native.verify(toAB(signature), toAB(message), toAB(key))
67
+ : this.native.verify(toAB(signature), toAB(message));
68
+ }
69
+
70
+ verifySync(
71
+ signature: BinaryLike,
72
+ message: BinaryLike,
73
+ key?: BinaryLike,
74
+ ): boolean {
75
+ return key
76
+ ? this.native.verifySync(toAB(signature), toAB(message), toAB(key))
77
+ : this.native.verifySync(toAB(signature), toAB(message));
78
+ }
79
+ }
package/src/index.ts CHANGED
@@ -2,10 +2,13 @@
2
2
  import { Buffer } from '@craftzdog/react-native-buffer';
3
3
 
4
4
  // API imports
5
+ import * as keys from './keys';
6
+ import * as ed from './ed';
7
+ import * as pbkdf2 from './pbkdf2';
5
8
  import * as random from './random';
6
9
 
7
10
  // utils import
8
- import { utils } from './utils';
11
+ import * as utils from './utils';
9
12
 
10
13
  /**
11
14
  * Loosely matches Node.js {crypto} with some unimplemented functionality.
@@ -20,30 +23,28 @@ const QuickCrypto = {
20
23
  // createCipheriv,
21
24
  // createDecipher,
22
25
  // createDecipheriv,
23
- // createPublicKey,
24
- // createPrivateKey,
25
- // createSecretKey,
26
26
  // publicEncrypt,
27
27
  // publicDecrypt,
28
28
  // privateDecrypt,
29
29
  // generateKey,
30
- // generateKeyPair,
31
- // generateKeyPairSync,
32
30
  // generateKeySync,
33
31
  // createSign,
34
32
  // createVerify,
35
33
  // subtle,
36
34
  // constants,
37
- // ...pbkdf2,
35
+ ...keys,
36
+ ...ed,
37
+ ...pbkdf2,
38
38
  ...random,
39
39
  // getCiphers,
40
40
  // getHashes,
41
41
  // webcrypto,
42
- utils,
42
+ ...utils,
43
43
  };
44
44
 
45
45
  /**
46
- * Optional. Patch global.crypto with quickcrypto and global.Buffer with react-native-buffer.
46
+ * Optional. Patch global.crypto with react-native-quick-crypto and
47
+ * global.Buffer with react-native-buffer.
47
48
  */
48
49
  export const install = () => {
49
50
  // @ts-expect-error copyBytesFrom and poolSizets are missing from react-native-buffer
@@ -56,7 +57,12 @@ export const install = () => {
56
57
  // random, cipher, hash use nextTick
57
58
  global.process.nextTick = setImmediate;
58
59
 
60
+ // exports
59
61
  export default QuickCrypto;
62
+ export * from './ed';
63
+ export * from './pbkdf2';
64
+ export * from './random';
65
+ export * from './utils';
60
66
 
61
67
  // Additional exports for CommonJS compatibility
62
68
  module.exports = QuickCrypto;