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/package.json CHANGED
@@ -1,40 +1,43 @@
1
1
  {
2
2
  "name": "react-native-quick-crypto",
3
- "version": "0.7.3",
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": "cd example && bun start",
35
- "pods": "cd example && bun install && bun pods",
36
- "bootstrap": "bun install && bun pods && bun example",
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,109 +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
- "readable-stream": "^4.5.2",
66
- "string_decoder": "^1.3.0",
67
- "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"
68
76
  },
69
77
  "devDependencies": {
70
- "@jamesacarr/eslint-formatter-github-actions": "^0.2.0",
71
- "@react-native/babel-preset": "^0.75.0-main",
72
- "@react-native/eslint-config": "^0.75.0-main",
73
- "@react-native/eslint-plugin": "^0.75.0-main",
74
- "@release-it/conventional-changelog": "^8.0.1",
75
- "@types/jest": "^29.5.11",
76
- "@types/node": "^22.0.0",
77
- "@types/react": "^18.0.33",
78
- "@types/readable-stream": "^4.0.11",
79
- "eslint": "^8.4.1",
80
- "eslint-config-prettier": "^9.1.0",
81
- "eslint-plugin-prettier": "^5.1.3",
82
- "jest": "^29.7.0",
83
- "prettier": "^3.2.5",
84
- "react": "^18.2.0",
85
- "react-native": "^0.72.7",
86
- "react-native-builder-bob": "^0.29.0",
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"
90
97
  },
91
98
  "peerDependencies": {
92
99
  "react": "*",
93
100
  "react-native": "*"
94
101
  },
95
102
  "release-it": {
96
- "git": {
97
- "commitMessage": "chore: release ${version}",
98
- "tagName": "v${version}"
99
- },
100
103
  "npm": {
101
104
  "publish": true
102
105
  },
106
+ "git": false,
103
107
  "github": {
104
- "release": true
108
+ "release": false
105
109
  },
106
- "plugins": {
107
- "@release-it/conventional-changelog": {
108
- "preset": {
109
- "name": "conventionalcommits",
110
- "types": [
111
- {
112
- "type": "feat",
113
- "section": "✨ Features"
114
- },
115
- {
116
- "type": "fix",
117
- "section": "🐛 Bug Fixes"
118
- },
119
- {
120
- "type": "perf",
121
- "section": "💨 Performance Improvements"
122
- },
123
- {
124
- "type": "chore(deps)",
125
- "section": "🛠️ Dependency Upgrades"
126
- },
127
- {
128
- "type": "docs",
129
- "section": "📚 Documentation"
130
- }
131
- ]
132
- }
133
- }
134
- }
135
- },
136
- "eslintConfig": {
137
- "root": true,
138
- "extends": [
139
- "@react-native",
140
- "prettier"
141
- ],
142
- "rules": {
143
- "no-dupe-class-members": "off",
144
- "prettier/prettier": [
145
- "error",
146
- {
147
- "quoteProps": "consistent",
148
- "singleQuote": true,
149
- "tabWidth": 2,
150
- "trailingComma": "es5",
151
- "useTabs": false
152
- }
153
- ]
154
- }
155
- },
156
- "eslintIgnore": [
157
- "node_modules/",
158
- "lib/"
159
- ],
160
- "prettier": {
161
- "quoteProps": "consistent",
162
- "singleQuote": true,
163
- "tabWidth": 2,
164
- "trailingComma": "es5",
165
- "useTabs": false
110
+ "plugins": {}
166
111
  },
167
112
  "react-native-builder-bob": {
168
113
  "source": "src",
@@ -173,7 +118,8 @@
173
118
  [
174
119
  "typescript",
175
120
  {
176
- "project": "tsconfig.json"
121
+ "project": "tsconfig.json",
122
+ "tsc": "../../node_modules/.bin/tsc"
177
123
  }
178
124
  ]
179
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