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/src/Hash.ts DELETED
@@ -1,132 +0,0 @@
1
- import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
2
- import type { InternalHash } from './NativeQuickCrypto/hash';
3
- import {
4
- type Encoding,
5
- toArrayBuffer,
6
- validateMaxBufferLength,
7
- normalizeHashName,
8
- type BufferLike,
9
- bufferLikeToArrayBuffer,
10
- } from './Utils';
11
- import Stream from 'readable-stream';
12
- import { Buffer } from '@craftzdog/react-native-buffer';
13
- import { lazyDOMException } from './Utils';
14
- import type { SubtleAlgorithm } from './keys';
15
-
16
- interface HashOptionsBase extends Stream.TransformOptions {
17
- outputLength?: number | undefined;
18
- }
19
-
20
- type HashOptions = null | undefined | HashOptionsBase;
21
-
22
- global.process.nextTick = setImmediate;
23
-
24
- const createInternalHash = NativeQuickCrypto.createHash;
25
-
26
- export function createHash(algorithm: string, options?: HashOptions) {
27
- return new Hash(algorithm, options);
28
- }
29
-
30
- class Hash extends Stream.Transform {
31
- private internalHash: InternalHash;
32
-
33
- constructor(other: Hash, options?: HashOptions);
34
- constructor(algorithm: string, options?: HashOptions);
35
- constructor(arg: string | Hash, options?: HashOptions) {
36
- super(options ?? undefined);
37
- if (arg instanceof Hash) {
38
- this.internalHash = arg.internalHash.copy(options?.outputLength);
39
- } else {
40
- this.internalHash = createInternalHash(arg, options?.outputLength);
41
- }
42
- }
43
-
44
- copy(options?: HashOptionsBase): Hash {
45
- const copy = new Hash(this, options);
46
- return copy;
47
- }
48
- /**
49
- * Updates the hash content with the given `data`, the encoding of which
50
- * is given in `inputEncoding`.
51
- * If `encoding` is not provided, and the `data` is a string, an
52
- * encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
53
- *
54
- * This can be called many times with new data as it is streamed.
55
- * @since v0.1.92
56
- * @param inputEncoding The `encoding` of the `data` string.
57
- */
58
- update(data: string | ArrayBuffer, inputEncoding?: Encoding): Hash {
59
- if (data instanceof ArrayBuffer) {
60
- this.internalHash.update(data);
61
- return this;
62
- }
63
- const buffer = Buffer.from(data, inputEncoding);
64
- this.internalHash.update(toArrayBuffer(buffer));
65
- return this;
66
- }
67
-
68
- _transform(
69
- chunk: string | ArrayBuffer,
70
- encoding: Encoding,
71
- callback: () => void
72
- ) {
73
- this.update(chunk, encoding);
74
- callback();
75
- }
76
-
77
- _flush(callback: () => void) {
78
- this.push(this.digest());
79
- callback();
80
- }
81
-
82
- /**
83
- * Calculates the digest of all of the data passed to be hashed (using the `hash.update()` method).
84
- * If `encoding` is provided a string will be returned; otherwise
85
- * a `Buffer` is returned.
86
- *
87
- * The `Hash` object can not be used again after `hash.digest()` method has been
88
- * called. Multiple calls will cause an error to be thrown.
89
- * @since v0.1.92
90
- * @param encoding The `encoding` of the return value.
91
- */
92
- digest(): Buffer;
93
- digest(encoding: 'buffer'): Buffer;
94
- digest(encoding: Encoding): string;
95
- digest(encoding?: Encoding | 'buffer'): string | Buffer {
96
- const result: ArrayBuffer = this.internalHash.digest();
97
-
98
- if (encoding && encoding !== 'buffer') {
99
- return Buffer.from(result).toString(encoding);
100
- }
101
-
102
- return Buffer.from(result);
103
- }
104
- }
105
-
106
- // Implementation for WebCrypto subtle.digest()
107
-
108
- export const asyncDigest = async (
109
- algorithm: SubtleAlgorithm,
110
- data: BufferLike
111
- ): Promise<ArrayBuffer> => {
112
- validateMaxBufferLength(data, 'data');
113
-
114
- switch (algorithm.name) {
115
- case 'SHA-1':
116
- // Fall through
117
- case 'SHA-256':
118
- // Fall through
119
- case 'SHA-384':
120
- // Fall through
121
- case 'SHA-512':
122
- const normalizedHashName = normalizeHashName(algorithm.name);
123
- const hash = new Hash(normalizedHashName);
124
- hash.update(bufferLikeToArrayBuffer(data));
125
- return hash.digest();
126
- }
127
-
128
- throw lazyDOMException(
129
- `Unrecognized algorithm name: ${algorithm.name}`,
130
- 'NotSupportedError'
131
- );
132
- };
package/src/Hashnames.ts DELETED
@@ -1,93 +0,0 @@
1
- import type { HashAlgorithm } from './keys';
2
-
3
- export enum HashContext {
4
- Node,
5
- WebCrypto,
6
- JwkRsa,
7
- JwkRsaPss,
8
- JwkRsaOaep,
9
- JwkHmac,
10
- }
11
-
12
- // WebCrypto and JWK use a bunch of different names for the
13
- // standard set of SHA-* digest algorithms... which is ... fun.
14
- // Here we provide a utility for mapping between them in order
15
- // make it easier in the code.
16
-
17
- type HashNames = {
18
- [key: string]: { [key in HashContext as string]: string };
19
- };
20
-
21
- const kHashNames: HashNames = {
22
- sha1: {
23
- [HashContext.Node]: 'sha1',
24
- [HashContext.WebCrypto]: 'SHA-1',
25
- [HashContext.JwkRsa]: 'RS1',
26
- [HashContext.JwkRsaPss]: 'PS1',
27
- [HashContext.JwkRsaOaep]: 'RSA-OAEP',
28
- [HashContext.JwkHmac]: 'HS1',
29
- },
30
- sha224: {
31
- [HashContext.Node]: 'sha224',
32
- [HashContext.WebCrypto]: 'SHA-224',
33
- [HashContext.JwkRsa]: 'RS224',
34
- [HashContext.JwkRsaPss]: 'PS224',
35
- [HashContext.JwkRsaOaep]: 'RSA-OAEP-224',
36
- [HashContext.JwkHmac]: 'HS224',
37
- },
38
- sha256: {
39
- [HashContext.Node]: 'sha256',
40
- [HashContext.WebCrypto]: 'SHA-256',
41
- [HashContext.JwkRsa]: 'RS256',
42
- [HashContext.JwkRsaPss]: 'PS256',
43
- [HashContext.JwkRsaOaep]: 'RSA-OAEP-256',
44
- [HashContext.JwkHmac]: 'HS256',
45
- },
46
- sha384: {
47
- [HashContext.Node]: 'sha384',
48
- [HashContext.WebCrypto]: 'SHA-384',
49
- [HashContext.JwkRsa]: 'RS384',
50
- [HashContext.JwkRsaPss]: 'PS384',
51
- [HashContext.JwkRsaOaep]: 'RSA-OAEP-384',
52
- [HashContext.JwkHmac]: 'HS384',
53
- },
54
- sha512: {
55
- [HashContext.Node]: 'sha512',
56
- [HashContext.WebCrypto]: 'SHA-512',
57
- [HashContext.JwkRsa]: 'RS512',
58
- [HashContext.JwkRsaPss]: 'PS512',
59
- [HashContext.JwkRsaOaep]: 'RSA-OAEP-512',
60
- [HashContext.JwkHmac]: 'HS512',
61
- },
62
- ripemd160: {
63
- [HashContext.Node]: 'ripemd160',
64
- [HashContext.WebCrypto]: 'RIPEMD-160',
65
- },
66
- };
67
-
68
- {
69
- // Index the aliases
70
- const keys: string[] = Object.keys(kHashNames);
71
- for (let n: number = 0; n < keys.length; n++) {
72
- const contexts: string[] = Object.keys(kHashNames[keys[n]!]!);
73
- for (let i: number = 0; i < contexts.length; i++) {
74
- const alias: string = kHashNames[keys[n]!]![contexts[i]!]!.toLowerCase();
75
- if (kHashNames[alias] === undefined)
76
- kHashNames[alias] = kHashNames[keys[n]!]!;
77
- }
78
- }
79
- }
80
-
81
- export function normalizeHashName(
82
- algo: string | HashAlgorithm | undefined,
83
- context: HashContext = HashContext.Node
84
- ): HashAlgorithm {
85
- if (typeof algo !== 'undefined') {
86
- const normAlgo = algo.toString().toLowerCase();
87
- try {
88
- const alias = kHashNames[normAlgo]![context] as HashAlgorithm;
89
- if (alias) return alias;
90
- } catch (_e) {}
91
- }
92
- throw new Error(`Invalid Hash Algorithm: ${algo}`);
93
- }
package/src/Hmac.ts DELETED
@@ -1,106 +0,0 @@
1
- import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
2
- import type { InternalHmac } from './NativeQuickCrypto/hmac';
3
- import {
4
- type Encoding,
5
- toArrayBuffer,
6
- type BinaryLike,
7
- binaryLikeToArrayBuffer,
8
- } from './Utils';
9
- import Stream from 'readable-stream';
10
- import { Buffer } from '@craftzdog/react-native-buffer';
11
-
12
- const createInternalHmac = NativeQuickCrypto.createHmac;
13
-
14
- export function createHmac(
15
- algorithm: string,
16
- key: BinaryLike,
17
- options?: Stream.TransformOptions
18
- ) {
19
- return new Hmac(algorithm, key, options);
20
- }
21
-
22
- class Hmac extends Stream.Transform {
23
- private internalHmac: InternalHmac;
24
- private isFinalized: boolean = false;
25
-
26
- constructor(
27
- algorithm: string,
28
- key: BinaryLike,
29
- _options?: Stream.TransformOptions
30
- ) {
31
- super();
32
- let keyAsString = binaryLikeToArrayBuffer(key);
33
-
34
- if (keyAsString === undefined) {
35
- throw 'Wrong key type';
36
- }
37
-
38
- this.internalHmac = createInternalHmac(
39
- algorithm,
40
- keyAsString as ArrayBuffer
41
- );
42
- }
43
-
44
- /**
45
- * Updates the `Hmac` content with the given `data`, the encoding of which
46
- * is given in `inputEncoding`.
47
- * If `encoding` is not provided, and the `data` is a string, an
48
- * encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
49
- *
50
- * This can be called many times with new data as it is streamed.
51
- * @since v0.1.94
52
- * @param inputEncoding The `encoding` of the `data` string.
53
- */
54
- update(data: string | BinaryLike, inputEncoding?: Encoding): Hmac {
55
- if (data instanceof ArrayBuffer) {
56
- this.internalHmac.update(data);
57
- return this;
58
- }
59
- if (typeof data === 'string') {
60
- const buffer = Buffer.from(data, inputEncoding);
61
- this.internalHmac.update(toArrayBuffer(buffer));
62
- return this;
63
- }
64
-
65
- this.internalHmac.update(binaryLikeToArrayBuffer(data));
66
- return this;
67
- }
68
-
69
- _transform(
70
- chunk: string | BinaryLike,
71
- encoding: Encoding,
72
- callback: () => void
73
- ) {
74
- this.update(chunk, encoding);
75
- callback();
76
- }
77
-
78
- _flush(callback: () => void) {
79
- this.push(this.digest());
80
- callback();
81
- }
82
-
83
- /**
84
- * Calculates the HMAC digest of all of the data passed using `hmac.update()`.
85
- * If `encoding` is
86
- * provided a string is returned; otherwise a `Buffer` is returned;
87
- *
88
- * The `Hmac` object can not be used again after `hmac.digest()` has been
89
- * called. Multiple calls to `hmac.digest()` will result in an error being thrown.
90
- * @since v0.1.94
91
- * @param encoding The `encoding` of the return value.
92
- */
93
- digest(): Buffer;
94
- digest(encoding: 'buffer'): Buffer;
95
- digest(encoding: Encoding): string;
96
- digest(encoding?: Encoding | 'buffer'): string | Buffer {
97
- const result: ArrayBuffer = this.isFinalized
98
- ? new ArrayBuffer(0)
99
- : this.internalHmac.digest();
100
- this.isFinalized = true;
101
- if (encoding && encoding !== 'buffer') {
102
- return Buffer.from(result).toString(encoding);
103
- }
104
- return Buffer.from(result);
105
- }
106
- }
@@ -1,102 +0,0 @@
1
- import type { GenerateKeyPairReturn } from '../Cipher';
2
- import type { BinaryLike } from '../Utils';
3
- import type { Buffer } from '@craftzdog/react-native-buffer';
4
- import type {
5
- EncodingOptions,
6
- PrivateKeyObject,
7
- PublicKeyObject,
8
- SecretKeyObject,
9
- } from '../keys';
10
-
11
- // TODO: until shared, keep in sync with C++ side (cpp/Utils/MGLUtils.h)
12
- export enum KeyVariant {
13
- RSA_SSA_PKCS1_v1_5,
14
- RSA_PSS,
15
- RSA_OAEP,
16
- DSA,
17
- EC,
18
- NID,
19
- DH,
20
- }
21
-
22
- export const KeyVariantLookup: Record<string, KeyVariant> = {
23
- 'RSASSA-PKCS1-v1_5': KeyVariant.RSA_SSA_PKCS1_v1_5,
24
- 'RSA-PSS': KeyVariant.RSA_PSS,
25
- 'RSA-OAEP': KeyVariant.RSA_OAEP,
26
- 'ECDSA': KeyVariant.DSA,
27
- 'ECDH': KeyVariant.EC,
28
- 'Ed25519': KeyVariant.NID,
29
- 'Ed448': KeyVariant.NID,
30
- 'X25519': KeyVariant.NID,
31
- 'X448': KeyVariant.NID,
32
- 'DH': KeyVariant.DH,
33
- };
34
-
35
- export type InternalCipher = {
36
- update: (data: BinaryLike | ArrayBufferView) => ArrayBuffer;
37
- final: () => ArrayBuffer;
38
- copy: () => void;
39
- setAAD: (args: {
40
- data: BinaryLike;
41
- plaintextLength?: number;
42
- }) => InternalCipher;
43
- setAutoPadding: (autoPad: boolean) => boolean;
44
- setAuthTag: (tag: ArrayBuffer) => boolean;
45
- getAuthTag: () => ArrayBuffer;
46
- };
47
-
48
- export type CreateCipherMethod = (params: {
49
- cipher_type: string;
50
- cipher_key: ArrayBuffer;
51
- auth_tag_len: number;
52
- }) => InternalCipher;
53
-
54
- export type CreateDecipherMethod = (params: {
55
- cipher_type: string;
56
- cipher_key: ArrayBuffer;
57
- auth_tag_len: number;
58
- }) => InternalCipher;
59
-
60
- export type PublicEncryptMethod = (
61
- data: ArrayBuffer,
62
- format: number,
63
- type: any,
64
- passphrase: any,
65
- buffer: ArrayBuffer,
66
- padding: number,
67
- oaepHash: any,
68
- oaepLabel: any
69
- ) => Buffer;
70
- export type PrivateDecryptMethod = (
71
- data: ArrayBuffer,
72
- format: number,
73
- type: any,
74
- passphrase: any,
75
- buffer: ArrayBuffer,
76
- padding: number,
77
- oaepHash: any,
78
- oaepLabel: any
79
- ) => Buffer;
80
-
81
- export type GenerateKeyPairMethod = (
82
- keyVariant: KeyVariant,
83
- ...rest: any[]
84
- ) => Promise<GenerateKeyPairReturn>;
85
-
86
- export type GenerateKeyPairSyncMethod = (
87
- keyVariant: KeyVariant,
88
- ...rest: any[]
89
- ) => GenerateKeyPairReturn;
90
-
91
- export type CreatePublicKeyMethod = (
92
- key: BinaryLike | EncodingOptions
93
- ) => PublicKeyObject;
94
-
95
- export type CreatePrivateKeyMethod = (
96
- key: BinaryLike | EncodingOptions
97
- ) => PrivateKeyObject;
98
-
99
- export type CreateSecretKeyMethod = (
100
- key: BinaryLike | EncodingOptions,
101
- encoding?: string
102
- ) => SecretKeyObject;
@@ -1,102 +0,0 @@
1
- import { NativeModules, Platform } from 'react-native';
2
- import type { CreateHmacMethod } from './hmac';
3
- import type { CreateHashMethod } from './hash';
4
- import type { Pbkdf2Object } from './pbkdf2';
5
- import type { RandomObject } from './random';
6
- import type {
7
- CreateCipherMethod,
8
- CreateDecipherMethod,
9
- PublicEncryptMethod,
10
- PrivateDecryptMethod,
11
- GenerateKeyPairMethod,
12
- GenerateKeyPairSyncMethod,
13
- CreatePublicKeyMethod,
14
- CreatePrivateKeyMethod,
15
- CreateSecretKeyMethod,
16
- } from './Cipher';
17
- import type { CreateSignMethod, CreateVerifyMethod } from './sig';
18
- import type { webcrypto } from './webcrypto';
19
-
20
- interface NativeQuickCryptoSpec {
21
- createHmac: CreateHmacMethod;
22
- pbkdf2: Pbkdf2Object;
23
- random: RandomObject;
24
- createHash: CreateHashMethod;
25
- createCipher: CreateCipherMethod;
26
- createDecipher: CreateDecipherMethod;
27
- createPublicKey: CreatePublicKeyMethod;
28
- createPrivateKey: CreatePrivateKeyMethod;
29
- createSecretKey: CreateSecretKeyMethod;
30
- publicEncrypt: PublicEncryptMethod;
31
- publicDecrypt: PublicEncryptMethod;
32
- privateDecrypt: PrivateDecryptMethod;
33
- generateKeyPair: GenerateKeyPairMethod;
34
- generateKeyPairSync: GenerateKeyPairSyncMethod;
35
- createSign: CreateSignMethod;
36
- createVerify: CreateVerifyMethod;
37
- webcrypto: webcrypto;
38
- }
39
-
40
- // global func declaration for JSI functions
41
- declare global {
42
- function nativeCallSyncHook(): unknown;
43
- var __QuickCryptoProxy: object | undefined;
44
- }
45
-
46
- // Check if the constructor exists. If not, try installing the JSI bindings.
47
- if (global.__QuickCryptoProxy == null) {
48
- // Get the native QuickCrypto ReactModule
49
- const QuickCryptoModule = NativeModules.QuickCrypto;
50
- if (QuickCryptoModule == null) {
51
- let message =
52
- 'Failed to install react-native-quick-crypto: The native `QuickCrypto` Module could not be found.';
53
- message +=
54
- '\n* Make sure react-native-quick-crypto is correctly autolinked (run `npx react-native config` to verify)';
55
- if (Platform.OS === 'ios' || Platform.OS === 'macos') {
56
- message += '\n* Make sure you ran `pod install` in the ios/ directory.';
57
- }
58
- if (Platform.OS === 'android') {
59
- message += '\n* Make sure gradle is synced.';
60
- }
61
- // check if Expo
62
- const ExpoConstants =
63
- NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;
64
- if (ExpoConstants != null) {
65
- if (ExpoConstants.appOwnership === 'expo') {
66
- // We're running Expo Go
67
- throw new Error(
68
- 'react-native-quick-crypto is not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.'
69
- );
70
- } else {
71
- // We're running Expo bare / standalone
72
- message += '\n* Make sure you ran `expo prebuild`.';
73
- }
74
- }
75
-
76
- message += '\n* Make sure you rebuilt the app.';
77
- throw new Error(message);
78
- }
79
-
80
- // Check if we are running on-device (JSI)
81
- if (global.nativeCallSyncHook == null || QuickCryptoModule.install == null) {
82
- throw new Error(
83
- 'Failed to install react-native-quick-crypto: React Native is not running on-device. QuickCrypto can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'
84
- );
85
- }
86
-
87
- // Call the synchronous blocking install() function
88
- const result = QuickCryptoModule.install();
89
- if (result !== true)
90
- throw new Error(
91
- `Failed to install react-native-quick-crypto: The native QuickCrypto Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`
92
- );
93
-
94
- // Check again if the constructor now exists. If not, throw an error.
95
- if (global.__QuickCryptoProxy == null)
96
- throw new Error(
97
- 'Failed to install react-native-quick-crypto, the native initializer function does not exist. Are you trying to use QuickCrypto from different JS Runtimes?'
98
- );
99
- }
100
-
101
- const proxy = global.__QuickCryptoProxy;
102
- export const NativeQuickCrypto = proxy as any as NativeQuickCryptoSpec;
@@ -1,14 +0,0 @@
1
- import type { AESKeyVariant } from '../aes';
2
- import type { CipherOrWrapMode } from '../keys';
3
- import type { KeyObjectHandle } from './webcrypto';
4
-
5
- export type AESCipher = (
6
- mode: CipherOrWrapMode,
7
- handle: KeyObjectHandle,
8
- data: ArrayBuffer,
9
- variant: AESKeyVariant,
10
- iv_or_counter?: ArrayBuffer,
11
- length?: number,
12
- authTag?: ArrayBuffer,
13
- additionalData?: ArrayBuffer
14
- ) => Promise<ArrayBuffer>;
@@ -1,10 +0,0 @@
1
- export type InternalHash = {
2
- update: (data: ArrayBuffer) => InternalHash;
3
- digest: () => ArrayBuffer;
4
- copy: (len?: number) => InternalHash;
5
- };
6
-
7
- export type CreateHashMethod = (
8
- algorithm: string,
9
- outputLength?: number
10
- ) => InternalHash;
@@ -1,9 +0,0 @@
1
- export type InternalHmac = {
2
- update: (data: ArrayBuffer) => InternalHmac;
3
- digest: () => ArrayBuffer;
4
- };
5
-
6
- export type CreateHmacMethod = (
7
- algorithm: string,
8
- key?: ArrayBuffer
9
- ) => InternalHmac;
@@ -1,7 +0,0 @@
1
- import type { KeyObjectHandle } from './webcrypto';
2
-
3
- export type GenerateSecretKeyMethod = (
4
- length: number
5
- ) => Promise<KeyObjectHandle>;
6
-
7
- export type GenerateSecretKeySyncMethod = (length: number) => KeyObjectHandle;
@@ -1,16 +0,0 @@
1
- export type Pbkdf2Object = {
2
- pbkdf2: (
3
- password: ArrayBuffer,
4
- salt: ArrayBuffer,
5
- iterations: number,
6
- keylen: number,
7
- digest: string
8
- ) => Promise<ArrayBuffer>;
9
- pbkdf2Sync: (
10
- password: ArrayBuffer,
11
- salt: ArrayBuffer,
12
- iterations: number,
13
- keylen: number,
14
- digest: string
15
- ) => ArrayBuffer;
16
- };
@@ -1,12 +0,0 @@
1
- export type RandomObject = {
2
- randomFill: (
3
- buffer: ArrayBuffer,
4
- offset: number,
5
- size: number
6
- ) => Promise<ArrayBuffer>;
7
- randomFillSync: (
8
- buffer: ArrayBuffer,
9
- offset: number,
10
- size: number
11
- ) => ArrayBuffer;
12
- };
@@ -1,12 +0,0 @@
1
- import type { CipherOrWrapMode, DigestAlgorithm } from '../keys';
2
- import type { RSAKeyVariant } from '../rsa';
3
- import type { KeyObjectHandle } from './webcrypto';
4
-
5
- export type RSACipher = (
6
- mode: CipherOrWrapMode,
7
- handle: KeyObjectHandle,
8
- data: ArrayBuffer,
9
- variant: RSAKeyVariant,
10
- hash: DigestAlgorithm,
11
- label?: ArrayBuffer
12
- ) => Promise<ArrayBuffer>;
@@ -1,44 +0,0 @@
1
- // TODO Add real types to sign/verify, the problem is that because of encryption schemes
2
-
3
- import type { KeyObjectHandle } from './webcrypto';
4
-
5
- // they will have variable amount of parameters
6
- export type InternalSign = {
7
- init: (algorithm: string) => void;
8
- update: (data: ArrayBuffer) => void;
9
- sign: (...args: any) => Uint8Array; // returns raw bytes
10
- };
11
-
12
- export type InternalVerify = {
13
- init: (algorithm: string) => void;
14
- update: (data: ArrayBuffer) => void;
15
- verify: (...args: any) => boolean;
16
- };
17
-
18
- export type CreateSignMethod = () => InternalSign;
19
-
20
- export type CreateVerifyMethod = () => InternalVerify;
21
-
22
- export enum DSASigEnc {
23
- kSigEncDER,
24
- kSigEncP1363,
25
- }
26
-
27
- export enum SignMode {
28
- kSignJobModeSign,
29
- kSignJobModeVerify,
30
- }
31
-
32
- export type SignVerify = (
33
- mode: SignMode,
34
- handle: KeyObjectHandle,
35
- unused1: undefined,
36
- unused2: undefined,
37
- unused3: undefined,
38
- data: ArrayBuffer,
39
- digest: string | undefined,
40
- salt_length: number | undefined,
41
- padding: number | undefined,
42
- dsa_encoding: DSASigEnc | undefined,
43
- signature: ArrayBuffer | undefined
44
- ) => ArrayBuffer | boolean;