react-native-quick-crypto 0.7.2 → 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 (304) 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 +3 -3
  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/package.json +1 -0
  11. package/lib/commonjs/random.js +26 -12
  12. package/lib/commonjs/random.js.map +1 -1
  13. package/lib/commonjs/{NativeQuickCrypto/rsa.js → specs/random.nitro.js} +1 -1
  14. package/lib/commonjs/{NativeQuickCrypto/aes.js.map → specs/random.nitro.js.map} +1 -1
  15. package/lib/commonjs/utils/conversion.js +22 -0
  16. package/lib/commonjs/utils/conversion.js.map +1 -0
  17. package/lib/commonjs/utils/index.js +12 -0
  18. package/lib/commonjs/utils/index.js.map +1 -0
  19. package/lib/commonjs/utils/types.js +2 -0
  20. package/lib/{module/NativeQuickCrypto/aes.js.map → commonjs/utils/types.js.map} +1 -1
  21. package/lib/module/index.js +40 -38
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/package.json +1 -0
  24. package/lib/module/random.js +28 -12
  25. package/lib/module/random.js.map +1 -1
  26. package/lib/module/specs/random.nitro.js +4 -0
  27. package/lib/module/{NativeQuickCrypto/rsa.js.map → specs/random.nitro.js.map} +1 -1
  28. package/lib/module/utils/conversion.js +16 -0
  29. package/lib/module/utils/conversion.js.map +1 -0
  30. package/lib/module/utils/index.js +8 -0
  31. package/lib/module/utils/index.js.map +1 -0
  32. package/lib/module/utils/types.js +2 -0
  33. package/lib/{commonjs/NativeQuickCrypto/rsa.js.map → module/utils/types.js.map} +1 -1
  34. package/lib/tsconfig.tsbuildinfo +1 -0
  35. package/lib/typescript/index.d.ts +10 -141
  36. package/lib/typescript/index.d.ts.map +1 -1
  37. package/lib/typescript/random.d.ts +4 -5
  38. package/lib/typescript/random.d.ts.map +1 -1
  39. package/lib/typescript/specs/random.nitro.d.ts +9 -0
  40. package/lib/typescript/specs/random.nitro.d.ts.map +1 -0
  41. package/lib/typescript/utils/conversion.d.ts +4 -0
  42. package/lib/typescript/utils/conversion.d.ts.map +1 -0
  43. package/lib/typescript/utils/index.d.ts +6 -0
  44. package/lib/typescript/utils/index.d.ts.map +1 -0
  45. package/lib/typescript/utils/types.d.ts +5 -0
  46. package/lib/typescript/utils/types.d.ts.map +1 -0
  47. package/package.json +58 -108
  48. package/src/index.ts +38 -48
  49. package/src/random.ts +51 -48
  50. package/src/specs/random.nitro.ts +14 -0
  51. package/src/utils/conversion.ts +16 -0
  52. package/src/utils/index.ts +6 -0
  53. package/src/utils/types.ts +15 -0
  54. package/LICENSE +0 -27
  55. package/README.md +0 -203
  56. package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoModule.java +0 -70
  57. package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoPackage.java +0 -25
  58. package/cpp/Cipher/MGLCipherHostObject.cpp +0 -663
  59. package/cpp/Cipher/MGLCipherHostObject.h +0 -90
  60. package/cpp/Cipher/MGLCreateCipherInstaller.cpp +0 -75
  61. package/cpp/Cipher/MGLCreateCipherInstaller.h +0 -22
  62. package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +0 -77
  63. package/cpp/Cipher/MGLCreateDecipherInstaller.h +0 -17
  64. package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +0 -134
  65. package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +0 -35
  66. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +0 -63
  67. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +0 -37
  68. package/cpp/Cipher/MGLPublicCipher.h +0 -120
  69. package/cpp/Cipher/MGLPublicCipherInstaller.h +0 -107
  70. package/cpp/Cipher/MGLRsa.cpp +0 -573
  71. package/cpp/Cipher/MGLRsa.h +0 -109
  72. package/cpp/HMAC/MGLHmacHostObject.cpp +0 -95
  73. package/cpp/HMAC/MGLHmacHostObject.h +0 -39
  74. package/cpp/HMAC/MGLHmacInstaller.cpp +0 -43
  75. package/cpp/HMAC/MGLHmacInstaller.h +0 -20
  76. package/cpp/Hash/MGLHashHostObject.cpp +0 -147
  77. package/cpp/Hash/MGLHashHostObject.h +0 -53
  78. package/cpp/Hash/MGLHashInstaller.cpp +0 -44
  79. package/cpp/Hash/MGLHashInstaller.h +0 -20
  80. package/cpp/JSIUtils/MGLJSIMacros.h +0 -110
  81. package/cpp/JSIUtils/MGLJSIUtils.h +0 -41
  82. package/cpp/JSIUtils/MGLSmartHostObject.cpp +0 -43
  83. package/cpp/JSIUtils/MGLSmartHostObject.h +0 -46
  84. package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +0 -24
  85. package/cpp/JSIUtils/MGLThreadAwareHostObject.h +0 -43
  86. package/cpp/JSIUtils/MGLTypedArray.cpp +0 -325
  87. package/cpp/JSIUtils/MGLTypedArray.h +0 -160
  88. package/cpp/MGLKeys.cpp +0 -1426
  89. package/cpp/MGLKeys.h +0 -203
  90. package/cpp/MGLQuickCryptoHostObject.cpp +0 -124
  91. package/cpp/MGLQuickCryptoHostObject.h +0 -30
  92. package/cpp/Random/MGLRandomHostObject.cpp +0 -96
  93. package/cpp/Random/MGLRandomHostObject.h +0 -27
  94. package/cpp/Sig/MGLSignHostObjects.cpp +0 -757
  95. package/cpp/Sig/MGLSignHostObjects.h +0 -128
  96. package/cpp/Sig/MGLSignInstaller.cpp +0 -24
  97. package/cpp/Sig/MGLSignInstaller.h +0 -29
  98. package/cpp/Sig/MGLVerifyInstaller.cpp +0 -24
  99. package/cpp/Sig/MGLVerifyInstaller.h +0 -22
  100. package/cpp/Utils/MGLDispatchQueue.cpp +0 -75
  101. package/cpp/Utils/MGLDispatchQueue.h +0 -55
  102. package/cpp/Utils/MGLUtils.cpp +0 -295
  103. package/cpp/Utils/MGLUtils.h +0 -358
  104. package/cpp/Utils/base64.h +0 -320
  105. package/cpp/Utils/logs.h +0 -38
  106. package/cpp/Utils/node.h +0 -13
  107. package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +0 -164
  108. package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +0 -29
  109. package/cpp/fastpbkdf2/fastpbkdf2.c +0 -352
  110. package/cpp/fastpbkdf2/fastpbkdf2.h +0 -68
  111. package/cpp/webcrypto/MGLWebCrypto.cpp +0 -125
  112. package/cpp/webcrypto/MGLWebCrypto.h +0 -32
  113. package/cpp/webcrypto/crypto_aes.cpp +0 -516
  114. package/cpp/webcrypto/crypto_aes.h +0 -79
  115. package/cpp/webcrypto/crypto_ec.cpp +0 -424
  116. package/cpp/webcrypto/crypto_ec.h +0 -78
  117. package/cpp/webcrypto/crypto_keygen.cpp +0 -86
  118. package/cpp/webcrypto/crypto_keygen.h +0 -38
  119. package/ios/QuickCrypto.xcodeproj/project.pbxproj +0 -274
  120. package/ios/QuickCrypto.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  121. package/ios/QuickCrypto.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  122. package/ios/QuickCrypto.xcodeproj/project.xcworkspace/xcuserdata/brad.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  123. package/ios/QuickCrypto.xcodeproj/xcuserdata/brad.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  124. package/ios/QuickCryptoModule.h +0 -5
  125. package/ios/QuickCryptoModule.mm +0 -42
  126. package/lib/commonjs/Cipher.js +0 -502
  127. package/lib/commonjs/Cipher.js.map +0 -1
  128. package/lib/commonjs/Hash.js +0 -99
  129. package/lib/commonjs/Hash.js.map +0 -1
  130. package/lib/commonjs/Hashnames.js +0 -87
  131. package/lib/commonjs/Hashnames.js.map +0 -1
  132. package/lib/commonjs/Hmac.js +0 -79
  133. package/lib/commonjs/Hmac.js.map +0 -1
  134. package/lib/commonjs/NativeQuickCrypto/Cipher.js +0 -30
  135. package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +0 -1
  136. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +0 -52
  137. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
  138. package/lib/commonjs/NativeQuickCrypto/aes.js +0 -6
  139. package/lib/commonjs/NativeQuickCrypto/hash.js +0 -2
  140. package/lib/commonjs/NativeQuickCrypto/hash.js.map +0 -1
  141. package/lib/commonjs/NativeQuickCrypto/hmac.js +0 -2
  142. package/lib/commonjs/NativeQuickCrypto/hmac.js.map +0 -1
  143. package/lib/commonjs/NativeQuickCrypto/keygen.js +0 -6
  144. package/lib/commonjs/NativeQuickCrypto/keygen.js.map +0 -1
  145. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +0 -2
  146. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +0 -1
  147. package/lib/commonjs/NativeQuickCrypto/random.js +0 -2
  148. package/lib/commonjs/NativeQuickCrypto/random.js.map +0 -1
  149. package/lib/commonjs/NativeQuickCrypto/sig.js +0 -19
  150. package/lib/commonjs/NativeQuickCrypto/sig.js.map +0 -1
  151. package/lib/commonjs/NativeQuickCrypto/webcrypto.js +0 -6
  152. package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +0 -1
  153. package/lib/commonjs/Utils.js +0 -608
  154. package/lib/commonjs/Utils.js.map +0 -1
  155. package/lib/commonjs/aes.js +0 -281
  156. package/lib/commonjs/aes.js.map +0 -1
  157. package/lib/commonjs/constants.js +0 -85
  158. package/lib/commonjs/constants.js.map +0 -1
  159. package/lib/commonjs/ec.js +0 -276
  160. package/lib/commonjs/ec.js.map +0 -1
  161. package/lib/commonjs/keygen.js +0 -56
  162. package/lib/commonjs/keygen.js.map +0 -1
  163. package/lib/commonjs/keys.js +0 -492
  164. package/lib/commonjs/keys.js.map +0 -1
  165. package/lib/commonjs/pbkdf2.js +0 -90
  166. package/lib/commonjs/pbkdf2.js.map +0 -1
  167. package/lib/commonjs/rsa.js +0 -248
  168. package/lib/commonjs/rsa.js.map +0 -1
  169. package/lib/commonjs/sig.js +0 -129
  170. package/lib/commonjs/sig.js.map +0 -1
  171. package/lib/commonjs/subtle.js +0 -448
  172. package/lib/commonjs/subtle.js.map +0 -1
  173. package/lib/commonjs/webcrypto.js +0 -14
  174. package/lib/commonjs/webcrypto.js.map +0 -1
  175. package/lib/module/Cipher.js +0 -489
  176. package/lib/module/Cipher.js.map +0 -1
  177. package/lib/module/Hash.js +0 -91
  178. package/lib/module/Hash.js.map +0 -1
  179. package/lib/module/Hashnames.js +0 -83
  180. package/lib/module/Hashnames.js.map +0 -1
  181. package/lib/module/Hmac.js +0 -72
  182. package/lib/module/Hmac.js.map +0 -1
  183. package/lib/module/NativeQuickCrypto/Cipher.js +0 -24
  184. package/lib/module/NativeQuickCrypto/Cipher.js.map +0 -1
  185. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +0 -47
  186. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
  187. package/lib/module/NativeQuickCrypto/aes.js +0 -2
  188. package/lib/module/NativeQuickCrypto/hash.js +0 -2
  189. package/lib/module/NativeQuickCrypto/hash.js.map +0 -1
  190. package/lib/module/NativeQuickCrypto/hmac.js +0 -2
  191. package/lib/module/NativeQuickCrypto/hmac.js.map +0 -1
  192. package/lib/module/NativeQuickCrypto/keygen.js +0 -2
  193. package/lib/module/NativeQuickCrypto/keygen.js.map +0 -1
  194. package/lib/module/NativeQuickCrypto/pbkdf2.js +0 -2
  195. package/lib/module/NativeQuickCrypto/pbkdf2.js.map +0 -1
  196. package/lib/module/NativeQuickCrypto/random.js +0 -2
  197. package/lib/module/NativeQuickCrypto/random.js.map +0 -1
  198. package/lib/module/NativeQuickCrypto/rsa.js +0 -2
  199. package/lib/module/NativeQuickCrypto/sig.js +0 -15
  200. package/lib/module/NativeQuickCrypto/sig.js.map +0 -1
  201. package/lib/module/NativeQuickCrypto/webcrypto.js +0 -2
  202. package/lib/module/NativeQuickCrypto/webcrypto.js.map +0 -1
  203. package/lib/module/Utils.js +0 -537
  204. package/lib/module/Utils.js.map +0 -1
  205. package/lib/module/aes.js +0 -272
  206. package/lib/module/aes.js.map +0 -1
  207. package/lib/module/constants.js +0 -79
  208. package/lib/module/constants.js.map +0 -1
  209. package/lib/module/ec.js +0 -265
  210. package/lib/module/ec.js.map +0 -1
  211. package/lib/module/keygen.js +0 -47
  212. package/lib/module/keygen.js.map +0 -1
  213. package/lib/module/keys.js +0 -475
  214. package/lib/module/keys.js.map +0 -1
  215. package/lib/module/pbkdf2.js +0 -82
  216. package/lib/module/pbkdf2.js.map +0 -1
  217. package/lib/module/rsa.js +0 -240
  218. package/lib/module/rsa.js.map +0 -1
  219. package/lib/module/sig.js +0 -122
  220. package/lib/module/sig.js.map +0 -1
  221. package/lib/module/subtle.js +0 -441
  222. package/lib/module/subtle.js.map +0 -1
  223. package/lib/module/webcrypto.js +0 -8
  224. package/lib/module/webcrypto.js.map +0 -1
  225. package/lib/typescript/Cipher.d.ts +0 -81
  226. package/lib/typescript/Cipher.d.ts.map +0 -1
  227. package/lib/typescript/Hash.d.ts +0 -44
  228. package/lib/typescript/Hash.d.ts.map +0 -1
  229. package/lib/typescript/Hashnames.d.ts +0 -11
  230. package/lib/typescript/Hashnames.d.ts.map +0 -1
  231. package/lib/typescript/Hmac.d.ts +0 -37
  232. package/lib/typescript/Hmac.d.ts.map +0 -1
  233. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +0 -44
  234. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts.map +0 -1
  235. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +0 -33
  236. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +0 -1
  237. package/lib/typescript/NativeQuickCrypto/aes.d.ts +0 -5
  238. package/lib/typescript/NativeQuickCrypto/aes.d.ts.map +0 -1
  239. package/lib/typescript/NativeQuickCrypto/hash.d.ts +0 -7
  240. package/lib/typescript/NativeQuickCrypto/hash.d.ts.map +0 -1
  241. package/lib/typescript/NativeQuickCrypto/hmac.d.ts +0 -6
  242. package/lib/typescript/NativeQuickCrypto/hmac.d.ts.map +0 -1
  243. package/lib/typescript/NativeQuickCrypto/keygen.d.ts +0 -4
  244. package/lib/typescript/NativeQuickCrypto/keygen.d.ts.map +0 -1
  245. package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts +0 -5
  246. package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts.map +0 -1
  247. package/lib/typescript/NativeQuickCrypto/random.d.ts +0 -5
  248. package/lib/typescript/NativeQuickCrypto/random.d.ts.map +0 -1
  249. package/lib/typescript/NativeQuickCrypto/rsa.d.ts +0 -5
  250. package/lib/typescript/NativeQuickCrypto/rsa.d.ts.map +0 -1
  251. package/lib/typescript/NativeQuickCrypto/sig.d.ts +0 -23
  252. package/lib/typescript/NativeQuickCrypto/sig.d.ts.map +0 -1
  253. package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts +0 -39
  254. package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts.map +0 -1
  255. package/lib/typescript/Utils.d.ts +0 -48
  256. package/lib/typescript/Utils.d.ts.map +0 -1
  257. package/lib/typescript/aes.d.ts +0 -22
  258. package/lib/typescript/aes.d.ts.map +0 -1
  259. package/lib/typescript/constants.d.ts +0 -76
  260. package/lib/typescript/constants.d.ts.map +0 -1
  261. package/lib/typescript/ec.d.ts +0 -7
  262. package/lib/typescript/ec.d.ts.map +0 -1
  263. package/lib/typescript/keygen.d.ts +0 -6
  264. package/lib/typescript/keygen.d.ts.map +0 -1
  265. package/lib/typescript/keys.d.ts +0 -206
  266. package/lib/typescript/keys.d.ts.map +0 -1
  267. package/lib/typescript/pbkdf2.d.ts +0 -12
  268. package/lib/typescript/pbkdf2.d.ts.map +0 -1
  269. package/lib/typescript/rsa.d.ts +0 -12
  270. package/lib/typescript/rsa.d.ts.map +0 -1
  271. package/lib/typescript/sig.d.ts +0 -21
  272. package/lib/typescript/sig.d.ts.map +0 -1
  273. package/lib/typescript/subtle.d.ts +0 -15
  274. package/lib/typescript/subtle.d.ts.map +0 -1
  275. package/lib/typescript/webcrypto.d.ts +0 -9
  276. package/lib/typescript/webcrypto.d.ts.map +0 -1
  277. package/react-native-quick-crypto.podspec +0 -40
  278. package/src/Cipher.ts +0 -832
  279. package/src/Hash.ts +0 -132
  280. package/src/Hashnames.ts +0 -93
  281. package/src/Hmac.ts +0 -106
  282. package/src/NativeQuickCrypto/Cipher.ts +0 -102
  283. package/src/NativeQuickCrypto/NativeQuickCrypto.ts +0 -102
  284. package/src/NativeQuickCrypto/aes.ts +0 -14
  285. package/src/NativeQuickCrypto/hash.ts +0 -10
  286. package/src/NativeQuickCrypto/hmac.ts +0 -9
  287. package/src/NativeQuickCrypto/keygen.ts +0 -7
  288. package/src/NativeQuickCrypto/pbkdf2.ts +0 -16
  289. package/src/NativeQuickCrypto/random.ts +0 -12
  290. package/src/NativeQuickCrypto/rsa.ts +0 -12
  291. package/src/NativeQuickCrypto/sig.ts +0 -44
  292. package/src/NativeQuickCrypto/webcrypto.ts +0 -72
  293. package/src/Utils.ts +0 -777
  294. package/src/aes.ts +0 -402
  295. package/src/constants.ts +0 -79
  296. package/src/ec.ts +0 -375
  297. package/src/keygen.ts +0 -80
  298. package/src/keys.ts +0 -787
  299. package/src/pbkdf2.ts +0 -169
  300. package/src/rsa.ts +0 -370
  301. package/src/sig.ts +0 -164
  302. package/src/subtle.ts +0 -639
  303. package/src/webcrypto.ts +0 -8
  304. /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,124 +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, EVP_PKEY_encrypt>(
67
- "publicEncrypt", jsCallInvoker, workerQueue));
68
-
69
- // privateDecrypt
70
- this->fields.push_back(
71
- getPublicCipherFieldDefinition<MGLPublicCipher::kPrivate,
72
- EVP_PKEY_decrypt_init, EVP_PKEY_decrypt>(
73
- "privateDecrypt", jsCallInvoker, workerQueue));
74
-
75
- // privateEncrypt
76
- this->fields.push_back(
77
- getPublicCipherFieldDefinition<MGLPublicCipher::kPrivate,
78
- EVP_PKEY_sign_init, EVP_PKEY_sign>(
79
- "privateEncrypt", jsCallInvoker, workerQueue));
80
-
81
- // publicDecrypt
82
- this->fields.push_back(
83
- getPublicCipherFieldDefinition<MGLPublicCipher::kPublic,
84
- EVP_PKEY_verify_recover_init,
85
- EVP_PKEY_verify_recover>(
86
- "publicDecrypt", jsCallInvoker, workerQueue));
87
-
88
- // generateKeyPair
89
- this->fields.push_back(
90
- getGenerateKeyPairFieldDefinition(jsCallInvoker, workerQueue));
91
-
92
- // generateKeyPairSync
93
- this->fields.push_back(
94
- getGenerateKeyPairSyncFieldDefinition(jsCallInvoker, workerQueue));
95
-
96
- // Pbkdf2HostObject
97
- this->fields.push_back(JSI_VALUE("pbkdf2", {
98
- auto hostObject =
99
- std::make_shared<MGLPbkdf2HostObject>(jsCallInvoker, workerQueue);
100
- return jsi::Object::createFromHostObject(runtime, hostObject);
101
- }));
102
-
103
- // RandomHostObject
104
- this->fields.push_back(JSI_VALUE("random", {
105
- auto hostObject =
106
- std::make_shared<MGLRandomHostObject>(jsCallInvoker, workerQueue);
107
- return jsi::Object::createFromHostObject(runtime, hostObject);
108
- }));
109
-
110
- // createSign
111
- this->fields.push_back(getSignFieldDefinition(jsCallInvoker, workerQueue));
112
-
113
- // createVerify
114
- this->fields.push_back(getVerifyFieldDefinition(jsCallInvoker, workerQueue));
115
-
116
- // subtle API
117
- this->fields.push_back(JSI_VALUE("webcrypto", {
118
- auto hostObject = std::make_shared<MGLWebCryptoHostObject>(
119
- jsCallInvoker, workerQueue);
120
- return jsi::Object::createFromHostObject(runtime, hostObject);
121
- }));
122
- }
123
-
124
- } // 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