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

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 (298) hide show
  1. package/QuickCrypto.podspec +34 -0
  2. package/android/CMakeLists.txt +32 -64
  3. package/android/build.gradle +52 -125
  4. package/android/gradle.properties +4 -4
  5. package/android/src/main/cpp/cpp-adapter.cpp +9 -54
  6. package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +38 -0
  7. package/ios/QuickCryptoOnLoad.mm +19 -0
  8. package/lib/commonjs/index.js +39 -39
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/random.js +26 -12
  11. package/lib/commonjs/random.js.map +1 -1
  12. package/lib/commonjs/{NativeQuickCrypto/rsa.js → specs/random.nitro.js} +1 -1
  13. package/lib/commonjs/{NativeQuickCrypto/aes.js.map → specs/random.nitro.js.map} +1 -1
  14. package/lib/commonjs/utils/conversion.js +22 -0
  15. package/lib/commonjs/utils/conversion.js.map +1 -0
  16. package/lib/commonjs/utils/index.js +12 -0
  17. package/lib/commonjs/utils/index.js.map +1 -0
  18. package/lib/commonjs/utils/types.js +2 -0
  19. package/lib/{module/NativeQuickCrypto/aes.js.map → commonjs/utils/types.js.map} +1 -1
  20. package/lib/module/index.js +38 -38
  21. package/lib/module/index.js.map +1 -1
  22. package/lib/module/random.js +26 -12
  23. package/lib/module/random.js.map +1 -1
  24. package/lib/module/specs/random.nitro.js +4 -0
  25. package/lib/module/{NativeQuickCrypto/rsa.js.map → specs/random.nitro.js.map} +1 -1
  26. package/lib/module/utils/conversion.js +16 -0
  27. package/lib/module/utils/conversion.js.map +1 -0
  28. package/lib/module/utils/index.js +8 -0
  29. package/lib/module/utils/index.js.map +1 -0
  30. package/lib/module/utils/types.js +2 -0
  31. package/lib/{commonjs/NativeQuickCrypto/rsa.js.map → module/utils/types.js.map} +1 -1
  32. package/lib/tsconfig.tsbuildinfo +1 -0
  33. package/lib/typescript/index.d.ts +10 -141
  34. package/lib/typescript/index.d.ts.map +1 -1
  35. package/lib/typescript/random.d.ts +4 -5
  36. package/lib/typescript/random.d.ts.map +1 -1
  37. package/lib/typescript/specs/random.nitro.d.ts +9 -0
  38. package/lib/typescript/specs/random.nitro.d.ts.map +1 -0
  39. package/lib/typescript/utils/conversion.d.ts +4 -0
  40. package/lib/typescript/utils/conversion.d.ts.map +1 -0
  41. package/lib/typescript/utils/index.d.ts +6 -0
  42. package/lib/typescript/utils/index.d.ts.map +1 -0
  43. package/lib/typescript/utils/types.d.ts +5 -0
  44. package/lib/typescript/utils/types.d.ts.map +1 -0
  45. package/package.json +54 -108
  46. package/src/index.ts +38 -48
  47. package/src/random.ts +51 -48
  48. package/src/specs/random.nitro.ts +14 -0
  49. package/src/utils/conversion.ts +16 -0
  50. package/src/utils/index.ts +6 -0
  51. package/src/utils/types.ts +15 -0
  52. package/LICENSE +0 -27
  53. package/README.md +0 -203
  54. package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoModule.java +0 -70
  55. package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoPackage.java +0 -25
  56. package/cpp/Cipher/MGLCipherHostObject.cpp +0 -663
  57. package/cpp/Cipher/MGLCipherHostObject.h +0 -90
  58. package/cpp/Cipher/MGLCreateCipherInstaller.cpp +0 -75
  59. package/cpp/Cipher/MGLCreateCipherInstaller.h +0 -22
  60. package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +0 -77
  61. package/cpp/Cipher/MGLCreateDecipherInstaller.h +0 -17
  62. package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +0 -134
  63. package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +0 -35
  64. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +0 -63
  65. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +0 -37
  66. package/cpp/Cipher/MGLPublicCipher.h +0 -124
  67. package/cpp/Cipher/MGLPublicCipherInstaller.h +0 -107
  68. package/cpp/Cipher/MGLRsa.cpp +0 -573
  69. package/cpp/Cipher/MGLRsa.h +0 -109
  70. package/cpp/HMAC/MGLHmacHostObject.cpp +0 -95
  71. package/cpp/HMAC/MGLHmacHostObject.h +0 -39
  72. package/cpp/HMAC/MGLHmacInstaller.cpp +0 -43
  73. package/cpp/HMAC/MGLHmacInstaller.h +0 -20
  74. package/cpp/Hash/MGLHashHostObject.cpp +0 -147
  75. package/cpp/Hash/MGLHashHostObject.h +0 -53
  76. package/cpp/Hash/MGLHashInstaller.cpp +0 -44
  77. package/cpp/Hash/MGLHashInstaller.h +0 -20
  78. package/cpp/JSIUtils/MGLJSIMacros.h +0 -110
  79. package/cpp/JSIUtils/MGLJSIUtils.h +0 -41
  80. package/cpp/JSIUtils/MGLSmartHostObject.cpp +0 -43
  81. package/cpp/JSIUtils/MGLSmartHostObject.h +0 -46
  82. package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +0 -24
  83. package/cpp/JSIUtils/MGLThreadAwareHostObject.h +0 -43
  84. package/cpp/JSIUtils/MGLTypedArray.cpp +0 -325
  85. package/cpp/JSIUtils/MGLTypedArray.h +0 -160
  86. package/cpp/MGLKeys.cpp +0 -1426
  87. package/cpp/MGLKeys.h +0 -203
  88. package/cpp/MGLQuickCryptoHostObject.cpp +0 -127
  89. package/cpp/MGLQuickCryptoHostObject.h +0 -30
  90. package/cpp/Random/MGLRandomHostObject.cpp +0 -96
  91. package/cpp/Random/MGLRandomHostObject.h +0 -27
  92. package/cpp/Sig/MGLSignHostObjects.cpp +0 -757
  93. package/cpp/Sig/MGLSignHostObjects.h +0 -128
  94. package/cpp/Sig/MGLSignInstaller.cpp +0 -24
  95. package/cpp/Sig/MGLSignInstaller.h +0 -29
  96. package/cpp/Sig/MGLVerifyInstaller.cpp +0 -24
  97. package/cpp/Sig/MGLVerifyInstaller.h +0 -22
  98. package/cpp/Utils/MGLDispatchQueue.cpp +0 -75
  99. package/cpp/Utils/MGLDispatchQueue.h +0 -55
  100. package/cpp/Utils/MGLUtils.cpp +0 -295
  101. package/cpp/Utils/MGLUtils.h +0 -358
  102. package/cpp/Utils/base64.h +0 -320
  103. package/cpp/Utils/logs.h +0 -38
  104. package/cpp/Utils/node.h +0 -13
  105. package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +0 -164
  106. package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +0 -29
  107. package/cpp/fastpbkdf2/fastpbkdf2.c +0 -352
  108. package/cpp/fastpbkdf2/fastpbkdf2.h +0 -68
  109. package/cpp/webcrypto/MGLWebCrypto.cpp +0 -125
  110. package/cpp/webcrypto/MGLWebCrypto.h +0 -32
  111. package/cpp/webcrypto/crypto_aes.cpp +0 -516
  112. package/cpp/webcrypto/crypto_aes.h +0 -79
  113. package/cpp/webcrypto/crypto_ec.cpp +0 -424
  114. package/cpp/webcrypto/crypto_ec.h +0 -78
  115. package/cpp/webcrypto/crypto_keygen.cpp +0 -86
  116. package/cpp/webcrypto/crypto_keygen.h +0 -38
  117. package/ios/QuickCrypto.xcodeproj/project.pbxproj +0 -274
  118. package/ios/QuickCryptoModule.h +0 -5
  119. package/ios/QuickCryptoModule.mm +0 -42
  120. package/lib/commonjs/Cipher.js +0 -502
  121. package/lib/commonjs/Cipher.js.map +0 -1
  122. package/lib/commonjs/Hash.js +0 -99
  123. package/lib/commonjs/Hash.js.map +0 -1
  124. package/lib/commonjs/Hashnames.js +0 -87
  125. package/lib/commonjs/Hashnames.js.map +0 -1
  126. package/lib/commonjs/Hmac.js +0 -79
  127. package/lib/commonjs/Hmac.js.map +0 -1
  128. package/lib/commonjs/NativeQuickCrypto/Cipher.js +0 -30
  129. package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +0 -1
  130. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +0 -52
  131. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
  132. package/lib/commonjs/NativeQuickCrypto/aes.js +0 -6
  133. package/lib/commonjs/NativeQuickCrypto/hash.js +0 -2
  134. package/lib/commonjs/NativeQuickCrypto/hash.js.map +0 -1
  135. package/lib/commonjs/NativeQuickCrypto/hmac.js +0 -2
  136. package/lib/commonjs/NativeQuickCrypto/hmac.js.map +0 -1
  137. package/lib/commonjs/NativeQuickCrypto/keygen.js +0 -6
  138. package/lib/commonjs/NativeQuickCrypto/keygen.js.map +0 -1
  139. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +0 -2
  140. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +0 -1
  141. package/lib/commonjs/NativeQuickCrypto/random.js +0 -2
  142. package/lib/commonjs/NativeQuickCrypto/random.js.map +0 -1
  143. package/lib/commonjs/NativeQuickCrypto/sig.js +0 -19
  144. package/lib/commonjs/NativeQuickCrypto/sig.js.map +0 -1
  145. package/lib/commonjs/NativeQuickCrypto/webcrypto.js +0 -6
  146. package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +0 -1
  147. package/lib/commonjs/Utils.js +0 -608
  148. package/lib/commonjs/Utils.js.map +0 -1
  149. package/lib/commonjs/aes.js +0 -281
  150. package/lib/commonjs/aes.js.map +0 -1
  151. package/lib/commonjs/constants.js +0 -85
  152. package/lib/commonjs/constants.js.map +0 -1
  153. package/lib/commonjs/ec.js +0 -276
  154. package/lib/commonjs/ec.js.map +0 -1
  155. package/lib/commonjs/keygen.js +0 -56
  156. package/lib/commonjs/keygen.js.map +0 -1
  157. package/lib/commonjs/keys.js +0 -492
  158. package/lib/commonjs/keys.js.map +0 -1
  159. package/lib/commonjs/pbkdf2.js +0 -90
  160. package/lib/commonjs/pbkdf2.js.map +0 -1
  161. package/lib/commonjs/rsa.js +0 -248
  162. package/lib/commonjs/rsa.js.map +0 -1
  163. package/lib/commonjs/sig.js +0 -129
  164. package/lib/commonjs/sig.js.map +0 -1
  165. package/lib/commonjs/subtle.js +0 -448
  166. package/lib/commonjs/subtle.js.map +0 -1
  167. package/lib/commonjs/webcrypto.js +0 -14
  168. package/lib/commonjs/webcrypto.js.map +0 -1
  169. package/lib/module/Cipher.js +0 -491
  170. package/lib/module/Cipher.js.map +0 -1
  171. package/lib/module/Hash.js +0 -93
  172. package/lib/module/Hash.js.map +0 -1
  173. package/lib/module/Hashnames.js +0 -85
  174. package/lib/module/Hashnames.js.map +0 -1
  175. package/lib/module/Hmac.js +0 -74
  176. package/lib/module/Hmac.js.map +0 -1
  177. package/lib/module/NativeQuickCrypto/Cipher.js +0 -26
  178. package/lib/module/NativeQuickCrypto/Cipher.js.map +0 -1
  179. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +0 -49
  180. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
  181. package/lib/module/NativeQuickCrypto/aes.js +0 -4
  182. package/lib/module/NativeQuickCrypto/hash.js +0 -2
  183. package/lib/module/NativeQuickCrypto/hash.js.map +0 -1
  184. package/lib/module/NativeQuickCrypto/hmac.js +0 -2
  185. package/lib/module/NativeQuickCrypto/hmac.js.map +0 -1
  186. package/lib/module/NativeQuickCrypto/keygen.js +0 -4
  187. package/lib/module/NativeQuickCrypto/keygen.js.map +0 -1
  188. package/lib/module/NativeQuickCrypto/pbkdf2.js +0 -2
  189. package/lib/module/NativeQuickCrypto/pbkdf2.js.map +0 -1
  190. package/lib/module/NativeQuickCrypto/random.js +0 -2
  191. package/lib/module/NativeQuickCrypto/random.js.map +0 -1
  192. package/lib/module/NativeQuickCrypto/rsa.js +0 -4
  193. package/lib/module/NativeQuickCrypto/sig.js +0 -17
  194. package/lib/module/NativeQuickCrypto/sig.js.map +0 -1
  195. package/lib/module/NativeQuickCrypto/webcrypto.js +0 -4
  196. package/lib/module/NativeQuickCrypto/webcrypto.js.map +0 -1
  197. package/lib/module/Utils.js +0 -539
  198. package/lib/module/Utils.js.map +0 -1
  199. package/lib/module/aes.js +0 -274
  200. package/lib/module/aes.js.map +0 -1
  201. package/lib/module/constants.js +0 -81
  202. package/lib/module/constants.js.map +0 -1
  203. package/lib/module/ec.js +0 -267
  204. package/lib/module/ec.js.map +0 -1
  205. package/lib/module/keygen.js +0 -49
  206. package/lib/module/keygen.js.map +0 -1
  207. package/lib/module/keys.js +0 -477
  208. package/lib/module/keys.js.map +0 -1
  209. package/lib/module/pbkdf2.js +0 -84
  210. package/lib/module/pbkdf2.js.map +0 -1
  211. package/lib/module/rsa.js +0 -242
  212. package/lib/module/rsa.js.map +0 -1
  213. package/lib/module/sig.js +0 -124
  214. package/lib/module/sig.js.map +0 -1
  215. package/lib/module/subtle.js +0 -443
  216. package/lib/module/subtle.js.map +0 -1
  217. package/lib/module/webcrypto.js +0 -10
  218. package/lib/module/webcrypto.js.map +0 -1
  219. package/lib/typescript/Cipher.d.ts +0 -81
  220. package/lib/typescript/Cipher.d.ts.map +0 -1
  221. package/lib/typescript/Hash.d.ts +0 -44
  222. package/lib/typescript/Hash.d.ts.map +0 -1
  223. package/lib/typescript/Hashnames.d.ts +0 -11
  224. package/lib/typescript/Hashnames.d.ts.map +0 -1
  225. package/lib/typescript/Hmac.d.ts +0 -37
  226. package/lib/typescript/Hmac.d.ts.map +0 -1
  227. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +0 -44
  228. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts.map +0 -1
  229. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +0 -33
  230. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +0 -1
  231. package/lib/typescript/NativeQuickCrypto/aes.d.ts +0 -5
  232. package/lib/typescript/NativeQuickCrypto/aes.d.ts.map +0 -1
  233. package/lib/typescript/NativeQuickCrypto/hash.d.ts +0 -7
  234. package/lib/typescript/NativeQuickCrypto/hash.d.ts.map +0 -1
  235. package/lib/typescript/NativeQuickCrypto/hmac.d.ts +0 -6
  236. package/lib/typescript/NativeQuickCrypto/hmac.d.ts.map +0 -1
  237. package/lib/typescript/NativeQuickCrypto/keygen.d.ts +0 -4
  238. package/lib/typescript/NativeQuickCrypto/keygen.d.ts.map +0 -1
  239. package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts +0 -5
  240. package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts.map +0 -1
  241. package/lib/typescript/NativeQuickCrypto/random.d.ts +0 -5
  242. package/lib/typescript/NativeQuickCrypto/random.d.ts.map +0 -1
  243. package/lib/typescript/NativeQuickCrypto/rsa.d.ts +0 -5
  244. package/lib/typescript/NativeQuickCrypto/rsa.d.ts.map +0 -1
  245. package/lib/typescript/NativeQuickCrypto/sig.d.ts +0 -23
  246. package/lib/typescript/NativeQuickCrypto/sig.d.ts.map +0 -1
  247. package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts +0 -39
  248. package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts.map +0 -1
  249. package/lib/typescript/Utils.d.ts +0 -48
  250. package/lib/typescript/Utils.d.ts.map +0 -1
  251. package/lib/typescript/aes.d.ts +0 -22
  252. package/lib/typescript/aes.d.ts.map +0 -1
  253. package/lib/typescript/constants.d.ts +0 -76
  254. package/lib/typescript/constants.d.ts.map +0 -1
  255. package/lib/typescript/ec.d.ts +0 -7
  256. package/lib/typescript/ec.d.ts.map +0 -1
  257. package/lib/typescript/keygen.d.ts +0 -6
  258. package/lib/typescript/keygen.d.ts.map +0 -1
  259. package/lib/typescript/keys.d.ts +0 -206
  260. package/lib/typescript/keys.d.ts.map +0 -1
  261. package/lib/typescript/pbkdf2.d.ts +0 -12
  262. package/lib/typescript/pbkdf2.d.ts.map +0 -1
  263. package/lib/typescript/rsa.d.ts +0 -12
  264. package/lib/typescript/rsa.d.ts.map +0 -1
  265. package/lib/typescript/sig.d.ts +0 -21
  266. package/lib/typescript/sig.d.ts.map +0 -1
  267. package/lib/typescript/subtle.d.ts +0 -15
  268. package/lib/typescript/subtle.d.ts.map +0 -1
  269. package/lib/typescript/webcrypto.d.ts +0 -9
  270. package/lib/typescript/webcrypto.d.ts.map +0 -1
  271. package/react-native-quick-crypto.podspec +0 -40
  272. package/src/Cipher.ts +0 -832
  273. package/src/Hash.ts +0 -132
  274. package/src/Hashnames.ts +0 -93
  275. package/src/Hmac.ts +0 -106
  276. package/src/NativeQuickCrypto/Cipher.ts +0 -102
  277. package/src/NativeQuickCrypto/NativeQuickCrypto.ts +0 -102
  278. package/src/NativeQuickCrypto/aes.ts +0 -14
  279. package/src/NativeQuickCrypto/hash.ts +0 -10
  280. package/src/NativeQuickCrypto/hmac.ts +0 -9
  281. package/src/NativeQuickCrypto/keygen.ts +0 -7
  282. package/src/NativeQuickCrypto/pbkdf2.ts +0 -16
  283. package/src/NativeQuickCrypto/random.ts +0 -12
  284. package/src/NativeQuickCrypto/rsa.ts +0 -12
  285. package/src/NativeQuickCrypto/sig.ts +0 -44
  286. package/src/NativeQuickCrypto/webcrypto.ts +0 -72
  287. package/src/Utils.ts +0 -777
  288. package/src/aes.ts +0 -402
  289. package/src/constants.ts +0 -79
  290. package/src/ec.ts +0 -375
  291. package/src/keygen.ts +0 -80
  292. package/src/keys.ts +0 -787
  293. package/src/pbkdf2.ts +0 -169
  294. package/src/rsa.ts +0 -370
  295. package/src/sig.ts +0 -164
  296. package/src/subtle.ts +0 -639
  297. package/src/webcrypto.ts +0 -8
  298. /package/android/src/main/{AndroidManifestNew.xml → AndroidManifest.xml} +0 -0
package/cpp/MGLKeys.h DELETED
@@ -1,203 +0,0 @@
1
- //
2
- // MGLCipherKeys.h
3
- // react-native-quick-crypto
4
- //
5
- // Created by Oscar on 20.06.22.
6
- //
7
-
8
- #ifndef MGLCipherKeys_h
9
- #define MGLCipherKeys_h
10
-
11
- #include <jsi/jsi.h>
12
- #include <openssl/evp.h>
13
-
14
- #include <memory>
15
- #include <optional>
16
- #include <string>
17
-
18
- #ifdef ANDROID
19
- #include "Utils/MGLUtils.h"
20
- #include "JSIUtils/MGLSmartHostObject.h"
21
- #else
22
- #include "MGLUtils.h"
23
- #include "MGLSmartHostObject.h"
24
- #endif
25
-
26
- // This file should roughly match https://github.com/nodejs/node/blob/main/src/crypto/crypto_keys.cc
27
-
28
- namespace margelo {
29
-
30
- namespace jsi = facebook::jsi;
31
-
32
- enum PKEncodingType {
33
- // RSAPublicKey / RSAPrivateKey according to PKCS#1.
34
- kKeyEncodingPKCS1,
35
- // PrivateKeyInfo or EncryptedPrivateKeyInfo according to PKCS#8.
36
- kKeyEncodingPKCS8,
37
- // SubjectPublicKeyInfo according to X.509.
38
- kKeyEncodingSPKI,
39
- // ECPrivateKey according to SEC1.
40
- kKeyEncodingSEC1
41
- };
42
-
43
- enum PKFormatType { kKeyFormatDER, kKeyFormatPEM, kKeyFormatJWK };
44
-
45
- enum KeyType { kKeyTypeSecret, kKeyTypePublic, kKeyTypePrivate };
46
-
47
- enum KeyEncodingContext {
48
- kKeyContextInput,
49
- kKeyContextExport,
50
- kKeyContextGenerate
51
- };
52
-
53
- enum class ParseKeyResult {
54
- kParseKeyOk,
55
- kParseKeyNotRecognized,
56
- kParseKeyNeedPassphrase,
57
- kParseKeyFailed
58
- };
59
-
60
- enum class WebCryptoKeyExportStatus {
61
- OK,
62
- INVALID_KEY_TYPE,
63
- FAILED
64
- };
65
-
66
- struct AsymmetricKeyEncodingConfig {
67
- bool output_key_object_ = false;
68
- PKFormatType format_ = kKeyFormatDER;
69
- std::optional<PKEncodingType> type_ = std::nullopt;
70
- };
71
-
72
- using PublicKeyEncodingConfig = AsymmetricKeyEncodingConfig;
73
-
74
- struct PrivateKeyEncodingConfig : public AsymmetricKeyEncodingConfig {
75
- const EVP_CIPHER *cipher_;
76
- // The ByteSource alone is not enough to distinguish between "no passphrase"
77
- // and a zero-length passphrase (which can be a null pointer), therefore, we
78
- // use a NonCopyableMaybe.
79
- NonCopyableMaybe<ByteSource> passphrase_;
80
- };
81
-
82
- // Here node uses extends MemoryRetainer no clue what that is, something with
83
- // Snapshots stripped it for our implementation but if something doesn't work,
84
- // you know why
85
- class ManagedEVPPKey {
86
- public:
87
- ManagedEVPPKey() {}
88
- explicit ManagedEVPPKey(EVPKeyPointer &&pkey);
89
- ManagedEVPPKey(const ManagedEVPPKey &that);
90
- ManagedEVPPKey &operator=(const ManagedEVPPKey &that);
91
-
92
- operator bool() const;
93
- EVP_PKEY *get() const;
94
-
95
- static PublicKeyEncodingConfig GetPublicKeyEncodingFromJs(
96
- jsi::Runtime &runtime, const jsi::Value *arguments, unsigned int *offset,
97
- KeyEncodingContext context);
98
-
99
- static NonCopyableMaybe<PrivateKeyEncodingConfig> GetPrivateKeyEncodingFromJs(
100
- jsi::Runtime &runtime, const jsi::Value *arguments, unsigned int *offset,
101
- KeyEncodingContext context);
102
- //
103
- static ManagedEVPPKey GetParsedKey(jsi::Runtime &runtime,
104
- EVPKeyPointer &&pkey,
105
- ParseKeyResult ret,
106
- const char *default_msg);
107
-
108
- static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(jsi::Runtime &runtime,
109
- const jsi::Value *args,
110
- unsigned int *offset);
111
-
112
- static ManagedEVPPKey GetPrivateKeyFromJs(jsi::Runtime &runtime,
113
- const jsi::Value *args,
114
- unsigned int *offset,
115
- bool allow_key_object);
116
-
117
- static jsi::Value ToEncodedPublicKey(jsi::Runtime &runtime,
118
- ManagedEVPPKey key,
119
- const PublicKeyEncodingConfig &config);
120
-
121
- static jsi::Value ToEncodedPrivateKey(jsi::Runtime &runtime,
122
- ManagedEVPPKey key,
123
- const PrivateKeyEncodingConfig &config);
124
-
125
- private:
126
- size_t size_of_private_key() const;
127
- size_t size_of_public_key() const;
128
-
129
- EVPKeyPointer pkey_;
130
- };
131
-
132
- // Analogous to the KeyObjectData class on node
133
- // https://github.com/nodejs/node/blob/main/src/crypto/crypto_keys.h#L132
134
- class KeyObjectData {
135
- public:
136
- static std::shared_ptr<KeyObjectData> CreateSecret(ByteSource key);
137
-
138
- static std::shared_ptr<KeyObjectData> CreateAsymmetric(
139
- KeyType type,
140
- const ManagedEVPPKey& pkey);
141
-
142
- KeyType GetKeyType() const;
143
-
144
- // These functions allow unprotected access to the raw key material and should
145
- // only be used to implement cryptographic operations requiring the key.
146
- ManagedEVPPKey GetAsymmetricKey() const;
147
- std::string GetSymmetricKey() const;
148
- size_t GetSymmetricKeySize() const;
149
-
150
- private:
151
- explicit KeyObjectData(ByteSource symmetric_key);
152
-
153
- KeyObjectData(
154
- KeyType type,
155
- const ManagedEVPPKey& pkey);
156
-
157
- const KeyType key_type_;
158
- const ByteSource symmetric_key_;
159
- const size_t symmetric_key_len_;
160
- const ManagedEVPPKey asymmetric_key_;
161
- };
162
-
163
- // Analogous to the KeyObjectHandle class in node
164
- // https://github.com/nodejs/node/blob/main/src/crypto/crypto_keys.h#L164
165
- class JSI_EXPORT KeyObjectHandle: public jsi::HostObject {
166
- public:
167
- KeyObjectHandle() {}
168
- jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
169
- const std::shared_ptr<KeyObjectData>& Data();
170
-
171
- static std::shared_ptr<KeyObjectHandle> Create(std::shared_ptr<KeyObjectData> data);
172
-
173
- protected:
174
- jsi::Value Export(jsi::Runtime &rt);
175
- jsi::Value ExportJWK(jsi::Runtime &rt);
176
- jsi::Value ExportPublicKey(
177
- jsi::Runtime& rt,
178
- const PublicKeyEncodingConfig& config) const;
179
- jsi::Value ExportPrivateKey(
180
- jsi::Runtime& rt,
181
- const PrivateKeyEncodingConfig& config) const;
182
- jsi::Value ExportSecretKey(jsi::Runtime& rt) const;
183
- jsi::Value GetKeyDetail(jsi::Runtime &rt);
184
- jsi::Value GetAsymmetricKeyType(jsi::Runtime &rt) const;
185
- jsi::Value Init(jsi::Runtime &rt);
186
- jsi::Value InitECRaw(jsi::Runtime &rt);
187
- jsi::Value InitJWK(jsi::Runtime &rt);
188
-
189
- private:
190
- std::shared_ptr<KeyObjectData> data_;
191
- };
192
-
193
- WebCryptoKeyExportStatus PKEY_SPKI_Export(
194
- KeyObjectData* key_data,
195
- ByteSource* out);
196
-
197
- WebCryptoKeyExportStatus PKEY_PKCS8_Export(
198
- KeyObjectData* key_data,
199
- ByteSource* out);
200
-
201
- } // namespace margelo
202
-
203
- #endif /* MGLCipherKeys_h */
@@ -1,127 +0,0 @@
1
- // Copyright 2022 Margelo
2
- #include "MGLQuickCryptoHostObject.h"
3
-
4
- #include <ReactCommon/TurboModuleUtils.h>
5
- #include <jsi/jsi.h>
6
-
7
- #include <memory>
8
- #include <string>
9
- #include <vector>
10
-
11
- #ifdef ANDROID
12
- #include "Cipher/MGLCreateCipherInstaller.h"
13
- #include "Cipher/MGLCreateDecipherInstaller.h"
14
- #include "Cipher/MGLGenerateKeyPairInstaller.h"
15
- #include "Cipher/MGLGenerateKeyPairSyncInstaller.h"
16
- #include "Cipher/MGLPublicCipher.h"
17
- #include "Cipher/MGLPublicCipherInstaller.h"
18
- #include "HMAC/MGLHmacInstaller.h"
19
- #include "Hash/MGLHashInstaller.h"
20
- #include "Random/MGLRandomHostObject.h"
21
- #include "Sig/MGLSignInstaller.h"
22
- #include "Sig/MGLVerifyInstaller.h"
23
- #include "fastpbkdf2/MGLPbkdf2HostObject.h"
24
- #include "webcrypto/MGLWebCrypto.h"
25
- #else
26
- #include "MGLCreateCipherInstaller.h"
27
- #include "MGLCreateDecipherInstaller.h"
28
- #include "MGLGenerateKeyPairInstaller.h"
29
- #include "MGLGenerateKeyPairSyncInstaller.h"
30
- #include "MGLHashInstaller.h"
31
- #include "MGLHmacInstaller.h"
32
- #include "MGLPbkdf2HostObject.h"
33
- #include "MGLPublicCipher.h"
34
- #include "MGLPublicCipherInstaller.h"
35
- #include "MGLRandomHostObject.h"
36
- #include "MGLSignInstaller.h"
37
- #include "MGLVerifyInstaller.h"
38
- #include "MGLWebCrypto.h"
39
- #endif
40
-
41
- namespace margelo {
42
-
43
- namespace jsi = facebook::jsi;
44
-
45
- MGLQuickCryptoHostObject::MGLQuickCryptoHostObject(
46
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
47
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue)
48
- : MGLSmartHostObject(jsCallInvoker, workerQueue) {
49
- // HmacInstaller
50
- this->fields.push_back(getHmacFieldDefinition(jsCallInvoker, workerQueue));
51
-
52
- // HashInstaller
53
- this->fields.push_back(getHashFieldDefinition(jsCallInvoker, workerQueue));
54
-
55
- // createCipher
56
- this->fields.push_back(
57
- getCreateCipherFieldDefinition(jsCallInvoker, workerQueue));
58
-
59
- // createDecipher
60
- this->fields.push_back(
61
- getCreateDecipherFieldDefinition(jsCallInvoker, workerQueue));
62
-
63
- // publicEncrypt
64
- this->fields.push_back(
65
- getPublicCipherFieldDefinition<MGLPublicCipher::kPublic,
66
- EVP_PKEY_encrypt_init,
67
- EVP_PKEY_encrypt>(
68
- "publicEncrypt", jsCallInvoker, workerQueue));
69
-
70
- // privateDecrypt
71
- this->fields.push_back(
72
- getPublicCipherFieldDefinition<MGLPublicCipher::kPrivate,
73
- EVP_PKEY_decrypt_init,
74
- EVP_PKEY_decrypt>(
75
- "privateDecrypt", jsCallInvoker, workerQueue));
76
-
77
- // privateEncrypt
78
- this->fields.push_back(
79
- getPublicCipherFieldDefinition<MGLPublicCipher::kPrivate,
80
- EVP_PKEY_sign_init,
81
- EVP_PKEY_sign>(
82
- "privateEncrypt", jsCallInvoker, workerQueue));
83
-
84
- // publicDecrypt
85
- this->fields.push_back(
86
- getPublicCipherFieldDefinition<MGLPublicCipher::kPublic,
87
- EVP_PKEY_verify_recover_init,
88
- EVP_PKEY_verify_recover>(
89
- "publicDecrypt", jsCallInvoker, workerQueue));
90
-
91
- // generateKeyPair
92
- this->fields.push_back(
93
- getGenerateKeyPairFieldDefinition(jsCallInvoker, workerQueue));
94
-
95
- // generateKeyPairSync
96
- this->fields.push_back(
97
- getGenerateKeyPairSyncFieldDefinition(jsCallInvoker, workerQueue));
98
-
99
- // Pbkdf2HostObject
100
- this->fields.push_back(JSI_VALUE("pbkdf2", {
101
- auto hostObject =
102
- std::make_shared<MGLPbkdf2HostObject>(jsCallInvoker, workerQueue);
103
- return jsi::Object::createFromHostObject(runtime, hostObject);
104
- }));
105
-
106
- // RandomHostObject
107
- this->fields.push_back(JSI_VALUE("random", {
108
- auto hostObject =
109
- std::make_shared<MGLRandomHostObject>(jsCallInvoker, workerQueue);
110
- return jsi::Object::createFromHostObject(runtime, hostObject);
111
- }));
112
-
113
- // createSign
114
- this->fields.push_back(getSignFieldDefinition(jsCallInvoker, workerQueue));
115
-
116
- // createVerify
117
- this->fields.push_back(getVerifyFieldDefinition(jsCallInvoker, workerQueue));
118
-
119
- // subtle API
120
- this->fields.push_back(JSI_VALUE("webcrypto", {
121
- auto hostObject = std::make_shared<MGLWebCryptoHostObject>(
122
- jsCallInvoker, workerQueue);
123
- return jsi::Object::createFromHostObject(runtime, hostObject);
124
- }));
125
- }
126
-
127
- } // namespace margelo
@@ -1,30 +0,0 @@
1
- // Copyright 2022 Margelo
2
- #ifndef CPP_FASTCRYPTOHOSTOBJECT_H_
3
- #define CPP_FASTCRYPTOHOSTOBJECT_H_
4
-
5
- #include <ReactCommon/CallInvoker.h>
6
- #include <jsi/jsi.h>
7
-
8
- #include <memory>
9
-
10
- #include "JSIUtils/MGLSmartHostObject.h"
11
- #include "JSIUtils/MGLTypedArray.h"
12
- #include "Utils/MGLDispatchQueue.h"
13
-
14
- namespace margelo {
15
-
16
- namespace jsi = facebook::jsi;
17
- namespace react = facebook::react;
18
-
19
- class JSI_EXPORT MGLQuickCryptoHostObject : public MGLSmartHostObject {
20
- public:
21
- explicit MGLQuickCryptoHostObject(
22
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
23
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
24
-
25
- virtual ~MGLQuickCryptoHostObject() { invalidateJsiPropNameIDCache(); }
26
- };
27
-
28
- } // namespace margelo
29
-
30
- #endif // CPP_FASTCRYPTOHOSTOBJECT_H_
@@ -1,96 +0,0 @@
1
- //
2
- // Created by Szymon on 25/02/2022.
3
- //
4
-
5
- #include "MGLRandomHostObject.h"
6
-
7
- #ifdef ANDROID
8
- #include "JSIUtils/MGLTypedArray.h"
9
- #else
10
- #include "MGLTypedArray.h"
11
- #endif
12
- #include <openssl/bn.h>
13
- #include <openssl/dsa.h>
14
- #include <openssl/ec.h>
15
- #include <openssl/err.h>
16
- #include <openssl/evp.h>
17
- #include <openssl/kdf.h>
18
- #include <openssl/rand.h>
19
- #include <openssl/rsa.h>
20
- #include <openssl/ssl.h>
21
-
22
- #include <memory>
23
- #include <utility>
24
-
25
- namespace margelo {
26
- namespace jsi = facebook::jsi;
27
- namespace react = facebook::react;
28
-
29
- MGLRandomHostObject::MGLRandomHostObject(
30
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
31
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue)
32
- : MGLSmartHostObject(jsCallInvoker, workerQueue) {
33
- this->fields.push_back(buildPair(
34
- "randomFill", JSIF([=]) {
35
- if (count != 3) {
36
- throw jsi::JSError(runtime,
37
- "randomFill(..) expects exactly 4 arguments!");
38
- }
39
-
40
- if(!arguments[0].isObject() || !arguments[0].asObject(runtime).isArrayBuffer(runtime)) {
41
- throw std::runtime_error("First argument it not an array buffer");
42
- }
43
-
44
- if (!arguments[0].isObject()
45
- || !arguments[0].asObject(runtime).isArrayBuffer(runtime)) {
46
- throw std::runtime_error("First argument it not an array buffer");
47
- }
48
-
49
- auto result = arguments[0].asObject(runtime).getArrayBuffer(runtime);
50
- auto *resultData = result.data(runtime);
51
- auto resultPreventGC =
52
- std::make_shared<jsi::ArrayBuffer>(std::move(result));
53
-
54
- auto offset = (int)arguments[1].asNumber();
55
- auto size = arguments[2].asNumber();
56
-
57
- return react::createPromiseAsJSIValue(
58
- runtime, [=](jsi::Runtime &runtime,
59
- std::shared_ptr<react::Promise> promise) {
60
- // TODO(Szymon) implement check prime once we have bignums
61
- this->runOnWorkerThread([=]() {
62
- if (RAND_bytes(resultData + offset, size) != 1) {
63
- this->runOnJSThread([=]() {
64
- promise->reject("Sth went wrong with RAND_bytes");
65
- });
66
- }
67
- this->runOnJSThread([=]() {
68
- promise->resolve(
69
- jsi::ArrayBuffer(std::move(*resultPreventGC)));
70
- });
71
- });
72
- });
73
- }));
74
-
75
- this->fields.push_back(buildPair(
76
- "randomFillSync", JSIF([=]) {
77
- if (count != 3) {
78
- throw jsi::JSError(runtime,
79
- "randomFillSync(..) expects exactly 4 arguments!");
80
- }
81
-
82
- auto result = arguments[0].asObject(runtime).getArrayBuffer(runtime);
83
- auto *resultData = result.data(runtime);
84
- auto offset = (int)arguments[1].asNumber();
85
- auto size = arguments[2].asNumber();
86
-
87
- if (RAND_bytes(resultData + offset, size) != 1) {
88
- throw jsi::JSError(runtime, "Sth went wrong with RAND_bytes" +
89
- std::to_string(ERR_get_error()));
90
- }
91
-
92
- return result;
93
- }));
94
- }
95
-
96
- } // namespace margelo
@@ -1,27 +0,0 @@
1
- //
2
- // Created by Szymon on 25/02/2022.
3
- //
4
-
5
- #ifndef MGL_RANDOMHOSTOBJECT_H
6
- #define MGL_RANDOMHOSTOBJECT_H
7
-
8
- #include <memory>
9
-
10
- #ifdef ANDROID
11
- #include "JSIUtils/MGLSmartHostObject.h"
12
- #else
13
- #include "MGLSmartHostObject.h"
14
- #endif
15
-
16
- namespace margelo {
17
- namespace jsi = facebook::jsi;
18
-
19
- class MGLRandomHostObject : public MGLSmartHostObject {
20
- public:
21
- MGLRandomHostObject(
22
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
23
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
24
- };
25
-
26
- } // namespace margelo
27
- #endif // MGL_RANDOMHOSTOBJECT_H