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/package.json CHANGED
@@ -1,40 +1,43 @@
1
1
  {
2
2
  "name": "react-native-quick-crypto",
3
- "version": "0.7.2",
3
+ "version": "1.0.0-beta.1",
4
4
  "description": "A fast implementation of Node's `crypto` module written in C/C++ JSI",
5
- "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
5
+ "type": "module",
6
6
  "main": "lib/commonjs/index",
7
7
  "module": "lib/module/index",
8
8
  "types": "lib/typescript/index.d.ts",
9
- "react-native": "lib/module/index",
9
+ "react-native": "src/index",
10
10
  "source": "src/index",
11
11
  "files": [
12
12
  "src",
13
+ "react-native.config.js",
13
14
  "lib",
14
- "android/src",
15
15
  "android/build.gradle",
16
16
  "android/gradle.properties",
17
17
  "android/CMakeLists.txt",
18
- "ios",
19
- "cpp",
20
- "react-native-quick-crypto.podspec",
21
- "!lib/typescript/example",
22
- "!android/build",
23
- "!ios/build",
18
+ "android/src",
19
+ "ios/**/*.h",
20
+ "ios/**/*.m",
21
+ "ios/**/*.mm",
22
+ "ios/**/*.cpp",
23
+ "ios/**/*.swift",
24
+ "app.plugin.js",
25
+ "*.podspec",
26
+ "README.md",
24
27
  "!**/__tests__",
25
28
  "!**/__fixtures__",
26
29
  "!**/__mocks__"
27
30
  ],
28
31
  "scripts": {
32
+ "clean": "del-cli lib",
29
33
  "tsc": "tsc --noEmit",
30
34
  "typescript": "tsc --noEmit",
31
35
  "lint": "eslint \"**/*.{js,ts,tsx}\"",
32
- "prepare": "bob build",
33
- "release": "release-it",
34
- "example": "yarn --cwd example",
35
- "pods": "cd example && yarn pods",
36
- "bootstrap": "yarn example && yarn && yarn pods",
37
- "test": "jest"
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"
38
41
  },
39
42
  "keywords": [
40
43
  "react-native",
@@ -50,7 +53,10 @@
50
53
  "type": "git",
51
54
  "url": "git+https://github.com/margelo/react-native-quick-crypto.git"
52
55
  },
53
- "authors": "Szymon Kapała (szymon20000@gmail.com) & Marc Rousavy <me@mrousavy.com> (https://github.com/mrousavy)",
56
+ "authors": [
57
+ "Szymon Kapała <szymon20000@gmail.com>",
58
+ "Marc Rousavy <me@mrousavy.com> (https://github.com/mrousavy)"
59
+ ],
54
60
  "license": "MIT",
55
61
  "bugs": {
56
62
  "url": "https://github.com/margelo/react-native-quick-crypto/issues"
@@ -60,105 +66,48 @@
60
66
  "registry": "https://registry.npmjs.org/"
61
67
  },
62
68
  "dependencies": {
63
- "@craftzdog/react-native-buffer": "^6.0.5",
64
- "events": "^3.3.0",
65
- "react": "^18.2.0",
66
- "react-native": "^0.72.7",
67
- "readable-stream": "^4.5.2",
68
- "string_decoder": "^1.3.0",
69
- "util": "^0.12.5"
69
+ "@craftzdog/react-native-buffer": "6.0.5",
70
+ "events": "3.3.0",
71
+ "react-native-nitro-modules": "0.4.0",
72
+ "react-native-quick-base64": "2.1.2",
73
+ "readable-stream": "4.5.2",
74
+ "string_decoder": "1.3.0",
75
+ "util": "0.12.5"
70
76
  },
71
77
  "devDependencies": {
72
- "@jamesacarr/eslint-formatter-github-actions": "^0.2.0",
73
- "@react-native/babel-preset": "^0.75.0-main",
74
- "@react-native/eslint-config": "^0.75.0-main",
75
- "@react-native/eslint-plugin": "^0.75.0-main",
76
- "@release-it/conventional-changelog": "^8.0.1",
77
- "@types/jest": "^29.5.11",
78
- "@types/node": "^22.0.0",
79
- "@types/react": "^18.0.33",
80
- "@types/readable-stream": "^4.0.11",
81
- "eslint": "^8.4.1",
82
- "eslint-config-prettier": "^9.1.0",
83
- "eslint-plugin-prettier": "^5.1.3",
84
- "jest": "^29.7.0",
85
- "prettier": "^3.2.5",
86
- "react-native-builder-bob": "^0.28.1",
87
- "release-it": "^17.2.0",
88
- "sscrypto": "^1.1.1",
89
- "typescript": "^5.1.6"
78
+ "@eslint/compat": "^1.1.1",
79
+ "@eslint/js": "10.0.0",
80
+ "@release-it/bumper": "6.0.1",
81
+ "@types/jest": "29.5.11",
82
+ "@types/node": "22.0.0",
83
+ "@types/react": "18.3.3",
84
+ "@types/readable-stream": "4.0.11",
85
+ "del-cli": "5.1.0",
86
+ "eslint": "9.9.0",
87
+ "eslint-plugin-react-native": "^4.1.0",
88
+ "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",
95
+ "typescript": "5.1.6",
96
+ "typescript-eslint": "^8.1.0"
97
+ },
98
+ "peerDependencies": {
99
+ "react": "*",
100
+ "react-native": "*"
90
101
  },
91
102
  "release-it": {
92
- "git": {
93
- "commitMessage": "chore: release ${version}",
94
- "tagName": "v${version}"
95
- },
96
103
  "npm": {
97
104
  "publish": true
98
105
  },
106
+ "git": false,
99
107
  "github": {
100
- "release": true
108
+ "release": false
101
109
  },
102
- "plugins": {
103
- "@release-it/conventional-changelog": {
104
- "preset": {
105
- "name": "conventionalcommits",
106
- "types": [
107
- {
108
- "type": "feat",
109
- "section": "✨ Features"
110
- },
111
- {
112
- "type": "fix",
113
- "section": "🐛 Bug Fixes"
114
- },
115
- {
116
- "type": "perf",
117
- "section": "💨 Performance Improvements"
118
- },
119
- {
120
- "type": "chore(deps)",
121
- "section": "🛠️ Dependency Upgrades"
122
- },
123
- {
124
- "type": "docs",
125
- "section": "📚 Documentation"
126
- }
127
- ]
128
- }
129
- }
130
- }
131
- },
132
- "eslintConfig": {
133
- "root": true,
134
- "extends": [
135
- "@react-native",
136
- "prettier"
137
- ],
138
- "rules": {
139
- "no-dupe-class-members": "off",
140
- "prettier/prettier": [
141
- "error",
142
- {
143
- "quoteProps": "consistent",
144
- "singleQuote": true,
145
- "tabWidth": 2,
146
- "trailingComma": "es5",
147
- "useTabs": false
148
- }
149
- ]
150
- }
151
- },
152
- "eslintIgnore": [
153
- "node_modules/",
154
- "lib/"
155
- ],
156
- "prettier": {
157
- "quoteProps": "consistent",
158
- "singleQuote": true,
159
- "tabWidth": 2,
160
- "trailingComma": "es5",
161
- "useTabs": false
110
+ "plugins": {}
162
111
  },
163
112
  "react-native-builder-bob": {
164
113
  "source": "src",
@@ -169,7 +118,8 @@
169
118
  [
170
119
  "typescript",
171
120
  {
172
- "project": "tsconfig.json"
121
+ "project": "tsconfig.json",
122
+ "tsc": "../../node_modules/.bin/tsc"
173
123
  }
174
124
  ]
175
125
  ]
package/src/index.ts CHANGED
@@ -1,58 +1,45 @@
1
+ // polyfill imports
1
2
  import { Buffer } from '@craftzdog/react-native-buffer';
2
- import * as pbkdf2 from './pbkdf2';
3
+
4
+ // API imports
3
5
  import * as random from './random';
4
- import {
5
- createCipher,
6
- createCipheriv,
7
- createDecipher,
8
- createDecipheriv,
9
- publicEncrypt,
10
- publicDecrypt,
11
- privateDecrypt,
12
- generateKeyPair,
13
- generateKeyPairSync,
14
- } from './Cipher';
15
- import { generateKey, generateKeySync } from './keygen';
16
- import { createSign, createVerify } from './sig';
17
- import { createHmac } from './Hmac';
18
- import { createHash } from './Hash';
19
- import { constants } from './constants';
20
- import { subtle } from './subtle';
21
- import { getCiphers, getHashes } from './Utils';
22
- import webcrypto from './webcrypto';
23
- import { createPrivateKey, createPublicKey, createSecretKey } from './keys';
6
+
7
+ // utils import
8
+ import { utils } from './utils';
24
9
 
25
10
  /**
26
- * Loosely matches Node.js {crypto} with some unimplemented functionality
11
+ * Loosely matches Node.js {crypto} with some unimplemented functionality.
12
+ * See `docs/implementation-coverage.md` for status.
27
13
  */
28
14
  const QuickCrypto = {
29
- createHmac,
30
- Hmac: createHmac,
31
- Hash: createHash,
32
- createHash,
33
- createCipher,
34
- createCipheriv,
35
- createDecipher,
36
- createDecipheriv,
37
- createPublicKey,
38
- createPrivateKey,
39
- createSecretKey,
40
- publicEncrypt,
41
- publicDecrypt,
42
- privateDecrypt,
43
- generateKey,
44
- generateKeyPair,
45
- generateKeyPairSync,
46
- generateKeySync,
47
- createSign,
48
- createVerify,
49
- subtle,
50
- constants,
51
- ...pbkdf2,
15
+ // createHmac,
16
+ // Hmac: createHmac,
17
+ // Hash: createHash,
18
+ // createHash,
19
+ // createCipher,
20
+ // createCipheriv,
21
+ // createDecipher,
22
+ // createDecipheriv,
23
+ // createPublicKey,
24
+ // createPrivateKey,
25
+ // createSecretKey,
26
+ // publicEncrypt,
27
+ // publicDecrypt,
28
+ // privateDecrypt,
29
+ // generateKey,
30
+ // generateKeyPair,
31
+ // generateKeyPairSync,
32
+ // generateKeySync,
33
+ // createSign,
34
+ // createVerify,
35
+ // subtle,
36
+ // constants,
37
+ // ...pbkdf2,
52
38
  ...random,
53
- getCiphers,
54
- getHashes,
55
- webcrypto,
39
+ // getCiphers,
40
+ // getHashes,
41
+ // webcrypto,
42
+ utils,
56
43
  };
57
44
 
58
45
  /**
@@ -66,6 +53,9 @@ export const install = () => {
66
53
  global.crypto = QuickCrypto;
67
54
  };
68
55
 
56
+ // random, cipher, hash use nextTick
57
+ global.process.nextTick = setImmediate;
58
+
69
59
  export default QuickCrypto;
70
60
 
71
61
  // Additional exports for CommonJS compatibility
package/src/random.ts CHANGED
@@ -1,35 +1,43 @@
1
- import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
2
1
  import { Buffer } from '@craftzdog/react-native-buffer';
3
- import type { TypedArray } from './Utils';
4
-
5
- const random = NativeQuickCrypto.random;
6
-
7
- type ArrayBufferView = TypedArray | DataView | ArrayBufferLike | Buffer;
2
+ import type { ArrayBufferView, RandomCallback } from './utils/types';
3
+ import { abvToArrayBuffer } from './utils/conversion';
4
+ import { NitroModules } from 'react-native-nitro-modules';
5
+ import type { Random } from './specs/random.nitro';
6
+
7
+ // to use native bits in sub-functions, use getNative(). don't call it at top-level!
8
+ let random: Random;
9
+ function getNative(): Random {
10
+ if (random == null) {
11
+ // lazy-load the Nitro HybridObject
12
+ random = NitroModules.createHybridObject<Random>('Random');
13
+ }
14
+ return random;
15
+ }
8
16
 
9
17
  export function randomFill<T extends ArrayBufferView>(
10
18
  buffer: T,
11
- callback: (err: Error | null, buf: T) => void
19
+ callback: RandomCallback<T>
12
20
  ): void;
13
21
 
14
22
  export function randomFill<T extends ArrayBufferView>(
15
23
  buffer: T,
16
24
  offset: number,
17
- callback: (err: Error | null, buf: T) => void
25
+ callback: RandomCallback<T>
18
26
  ): void;
19
27
 
20
28
  export function randomFill<T extends ArrayBufferView>(
21
29
  buffer: T,
22
30
  offset: number,
23
31
  size: number,
24
- callback: (err: Error | null, buf: T) => void
32
+ callback: RandomCallback<T>
25
33
  ): void;
26
34
 
27
- export function randomFill(buffer: any, ...rest: any[]): void {
35
+ export function randomFill(buffer: ArrayBufferView, ...rest: unknown[]): void {
28
36
  if (typeof rest[rest.length - 1] !== 'function') {
29
37
  throw new Error('No callback provided to randomFill');
30
38
  }
31
39
 
32
- const callback = rest[rest.length - 1] as any as (
40
+ const callback = rest[rest.length - 1] as unknown as (
33
41
  err: Error | null,
34
42
  buf?: ArrayBuffer
35
43
  ) => void;
@@ -38,32 +46,23 @@ export function randomFill(buffer: any, ...rest: any[]): void {
38
46
  let size: number = buffer.byteLength;
39
47
 
40
48
  if (typeof rest[2] === 'function') {
41
- offset = rest[0];
42
- size = rest[1];
49
+ offset = rest[0] as number;
50
+ size = rest[1] as number;
43
51
  }
44
52
 
45
53
  if (typeof rest[1] === 'function') {
46
- offset = rest[0];
54
+ offset = rest[0] as number;
47
55
  }
48
56
 
49
- random
50
- .randomFill(
51
- Buffer.isBuffer(buffer)
52
- ? buffer.buffer
53
- : ArrayBuffer.isView(buffer)
54
- ? buffer.buffer
55
- : buffer,
56
- offset,
57
- size
58
- )
59
- .then(
60
- () => {
61
- callback(null, buffer);
62
- },
63
- (e: Error) => {
64
- callback(e);
65
- }
66
- );
57
+ getNative();
58
+ random.randomFill(abvToArrayBuffer(buffer), offset, size).then(
59
+ (res: ArrayBuffer) => {
60
+ callback(null, res);
61
+ },
62
+ (e: Error) => {
63
+ callback(e);
64
+ }
65
+ );
67
66
  }
68
67
 
69
68
  export function randomFillSync<T extends ArrayBufferView>(
@@ -72,12 +71,15 @@ export function randomFillSync<T extends ArrayBufferView>(
72
71
  size?: number
73
72
  ): T;
74
73
 
75
- export function randomFillSync(buffer: any, offset: number = 0, size?: number) {
76
- random.randomFillSync(
77
- buffer.buffer ? buffer.buffer : buffer,
78
- offset,
79
- size ?? buffer.byteLength
80
- );
74
+ export function randomFillSync(
75
+ buffer: ArrayBufferView,
76
+ offset: number = 0,
77
+ size?: number
78
+ ) {
79
+ getNative();
80
+ buffer = abvToArrayBuffer(buffer);
81
+ const res = random.randomFillSync(buffer, offset, size ?? buffer.byteLength);
82
+ buffer = res;
81
83
  return buffer;
82
84
  }
83
85
 
@@ -99,11 +101,11 @@ export function randomBytes(
99
101
  return buf;
100
102
  }
101
103
 
102
- randomFill(buf.buffer, 0, size, (error: Error | null) => {
104
+ randomFill(buf.buffer, 0, size, (error: Error | null, res: ArrayBuffer) => {
103
105
  if (error) {
104
106
  callback(error);
105
107
  }
106
- callback(null, buf);
108
+ callback(null, Buffer.from(res));
107
109
  });
108
110
  }
109
111
 
@@ -126,7 +128,7 @@ const RAND_MAX = 0xffffffffffff;
126
128
 
127
129
  // Cache random data to use in randomInt. The cache size must be evenly
128
130
  // divisible by 6 because each attempt to obtain a random int uses 6 bytes.
129
- const randomCache = new Buffer(6 * 1024);
131
+ let randomCache = new Buffer(6 * 1024);
130
132
  let randomCacheOffset = randomCache.length;
131
133
  let asyncCacheFillInProgress = false;
132
134
  const asyncCachePendingTasks: Task[] = [];
@@ -156,12 +158,12 @@ export function randomInt(
156
158
  typeof arg2 === 'undefined' || typeof arg2 === 'function';
157
159
 
158
160
  if (minNotSpecified) {
159
- callback = arg2 as any as undefined | RandomIntCallback;
161
+ callback = arg2 as undefined | RandomIntCallback;
160
162
  max = arg1;
161
163
  min = 0;
162
164
  } else {
163
165
  min = arg1;
164
- max = arg2 as any as number;
166
+ max = arg2 as number;
165
167
  }
166
168
  if (typeof callback !== 'undefined' && typeof callback !== 'function') {
167
169
  throw new TypeError('callback must be a function or undefined');
@@ -217,7 +219,7 @@ export function randomInt(
217
219
  if (x < randLimit) {
218
220
  const n = (x % range) + min;
219
221
  if (isSync) return n;
220
- process.nextTick(callback as Function, undefined, n);
222
+ process.nextTick(callback as RandomIntCallback, undefined, n);
221
223
  return;
222
224
  }
223
225
  }
@@ -237,12 +239,15 @@ function asyncRefillRandomIntCache() {
237
239
  if (asyncCacheFillInProgress) return;
238
240
 
239
241
  asyncCacheFillInProgress = true;
240
- randomFill(randomCache, (err) => {
242
+ randomFill(randomCache, (err, res) => {
241
243
  asyncCacheFillInProgress = false;
242
244
 
243
245
  const tasks = asyncCachePendingTasks;
244
246
  const errorReceiver = err && tasks.shift();
245
- if (!err) randomCacheOffset = 0;
247
+ if (!err) {
248
+ randomCache = Buffer.from(res);
249
+ randomCacheOffset = 0;
250
+ }
246
251
 
247
252
  // Restart all pending tasks. If an error occurred, we only notify a single
248
253
  // callback (errorReceiver) about it. This way, every async call to
@@ -289,9 +294,7 @@ export function randomUUID() {
289
294
  randomFillSync(buffer, 0, size);
290
295
 
291
296
  // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
292
- // eslint-disable-next-line no-bitwise
293
297
  buffer[6] = (buffer[6]! & 0x0f) | 0x40;
294
- // eslint-disable-next-line no-bitwise
295
298
  buffer[8] = (buffer[8]! & 0x3f) | 0x80;
296
299
 
297
300
  return (
@@ -0,0 +1,14 @@
1
+ import { type HybridObject } from 'react-native-nitro-modules';
2
+
3
+ export interface Random extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
4
+ randomFill(
5
+ buffer: ArrayBuffer,
6
+ offset: number,
7
+ size: number
8
+ ): Promise<ArrayBuffer>;
9
+ randomFillSync(
10
+ buffer: ArrayBuffer,
11
+ offset: number,
12
+ size: number
13
+ ): ArrayBuffer;
14
+ }
@@ -0,0 +1,16 @@
1
+ import { Buffer } from '@craftzdog/react-native-buffer';
2
+ import type { ArrayBufferView } from './types';
3
+
4
+ export const abvToArrayBuffer = (buffer: ArrayBufferView) => {
5
+ if (Buffer.isBuffer(buffer)) {
6
+ return buffer.buffer;
7
+ }
8
+ if (ArrayBuffer.isView(buffer)) {
9
+ return buffer.buffer;
10
+ }
11
+ return buffer;
12
+ };
13
+
14
+ export function ab2str(buf: ArrayBuffer, encoding: string = 'hex') {
15
+ return Buffer.from(buf).toString(encoding);
16
+ }
@@ -0,0 +1,6 @@
1
+ import { ab2str, abvToArrayBuffer } from "./conversion";
2
+
3
+ export const utils = {
4
+ ab2str,
5
+ abvToArrayBuffer,
6
+ };
@@ -0,0 +1,15 @@
1
+ export type ArrayBufferView = TypedArray | DataView | ArrayBufferLike | Buffer;
2
+
3
+ export type TypedArray =
4
+ | Uint8Array
5
+ | Uint8ClampedArray
6
+ | Uint16Array
7
+ | Uint32Array
8
+ | Int8Array
9
+ | Int16Array
10
+ | Int32Array
11
+ | Float32Array
12
+ | Float64Array;
13
+
14
+ export type RandomCallback<T> = (err: Error | null, value: T) => void;
15
+
package/LICENSE DELETED
@@ -1,27 +0,0 @@
1
- **react-native-quick-crypto**
2
-
3
- MIT License
4
-
5
- Copyright (c) 2021 Margelo GmbH
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in all
15
- copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- SOFTWARE.
24
-
25
- **NodeJS Crypto**
26
-
27
- See https://github.com/nodejs/node/blob/main/LICENSE