react-native-quick-crypto 0.6.0 → 0.7.0-rc.0

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 (196) hide show
  1. package/README.md +70 -18
  2. package/android/CMakeLists.txt +58 -61
  3. package/android/build.gradle +105 -53
  4. package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  5. package/android/gradle.properties +5 -5
  6. package/android/src/main/{AndroidManifest.xml → AndroidManifestNew.xml} +1 -2
  7. package/cpp/Cipher/MGLCipherHostObject.cpp +31 -5
  8. package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +21 -31
  9. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +4 -17
  10. package/cpp/Cipher/MGLPublicCipher.h +1 -1
  11. package/cpp/Cipher/MGLPublicCipherInstaller.h +6 -6
  12. package/cpp/Cipher/MGLRsa.cpp +224 -11
  13. package/cpp/Cipher/MGLRsa.h +13 -3
  14. package/cpp/Hash/MGLHashHostObject.cpp +1 -1
  15. package/cpp/Hash/MGLHashInstaller.cpp +2 -4
  16. package/cpp/JSIUtils/MGLJSIMacros.h +10 -0
  17. package/cpp/JSIUtils/MGLThreadAwareHostObject.h +1 -1
  18. package/cpp/MGLKeys.cpp +415 -471
  19. package/cpp/MGLKeys.h +70 -2
  20. package/cpp/MGLQuickCryptoHostObject.cpp +9 -0
  21. package/cpp/Random/MGLRandomHostObject.cpp +9 -2
  22. package/cpp/Sig/MGLSignHostObjects.cpp +1 -1
  23. package/cpp/Utils/MGLUtils.cpp +104 -32
  24. package/cpp/Utils/MGLUtils.h +172 -143
  25. package/cpp/Utils/node.h +13 -0
  26. package/cpp/webcrypto/MGLWebCrypto.cpp +63 -0
  27. package/cpp/webcrypto/MGLWebCrypto.h +34 -0
  28. package/cpp/webcrypto/crypto_ec.cpp +334 -0
  29. package/cpp/webcrypto/crypto_ec.h +65 -0
  30. package/ios/QuickCrypto.xcodeproj/project.pbxproj +4 -4
  31. package/lib/commonjs/@types/crypto-browserify.d.js.map +1 -1
  32. package/lib/commonjs/Cipher.js +53 -194
  33. package/lib/commonjs/Cipher.js.map +1 -1
  34. package/lib/commonjs/Hash.js +29 -29
  35. package/lib/commonjs/Hash.js.map +1 -1
  36. package/lib/commonjs/Hashnames.js +75 -0
  37. package/lib/commonjs/Hashnames.js.map +1 -0
  38. package/lib/commonjs/Hmac.js +6 -29
  39. package/lib/commonjs/Hmac.js.map +1 -1
  40. package/lib/commonjs/NativeQuickCrypto/Cipher.js +3 -5
  41. package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +1 -1
  42. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +11 -20
  43. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
  44. package/lib/commonjs/NativeQuickCrypto/hash.js.map +1 -1
  45. package/lib/commonjs/NativeQuickCrypto/hmac.js.map +1 -1
  46. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +1 -1
  47. package/lib/commonjs/NativeQuickCrypto/random.js.map +1 -1
  48. package/lib/commonjs/NativeQuickCrypto/sig.js.map +1 -1
  49. package/lib/commonjs/NativeQuickCrypto/webcrypto.js +6 -0
  50. package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +1 -0
  51. package/lib/commonjs/QuickCrypto.js +5 -14
  52. package/lib/commonjs/QuickCrypto.js.map +1 -1
  53. package/lib/commonjs/Utils.js +360 -48
  54. package/lib/commonjs/Utils.js.map +1 -1
  55. package/lib/commonjs/aes.js +324 -0
  56. package/lib/commonjs/aes.js.map +1 -0
  57. package/lib/commonjs/constants.js +1 -2
  58. package/lib/commonjs/constants.js.map +1 -1
  59. package/lib/commonjs/ec.js +288 -0
  60. package/lib/commonjs/ec.js.map +1 -0
  61. package/lib/commonjs/index.js +6 -10
  62. package/lib/commonjs/index.js.map +1 -1
  63. package/lib/commonjs/keys.js +280 -48
  64. package/lib/commonjs/keys.js.map +1 -1
  65. package/lib/commonjs/pbkdf2.js +44 -18
  66. package/lib/commonjs/pbkdf2.js.map +1 -1
  67. package/lib/commonjs/random.js +49 -68
  68. package/lib/commonjs/random.js.map +1 -1
  69. package/lib/commonjs/rsa.js +329 -0
  70. package/lib/commonjs/rsa.js.map +1 -0
  71. package/lib/commonjs/sig.js +13 -54
  72. package/lib/commonjs/sig.js.map +1 -1
  73. package/lib/commonjs/subtle.js +271 -0
  74. package/lib/commonjs/subtle.js.map +1 -0
  75. package/lib/module/@types/crypto-browserify.d.js.map +1 -1
  76. package/lib/module/Cipher.js +53 -188
  77. package/lib/module/Cipher.js.map +1 -1
  78. package/lib/module/Hash.js +27 -21
  79. package/lib/module/Hash.js.map +1 -1
  80. package/lib/module/Hashnames.js +71 -0
  81. package/lib/module/Hashnames.js.map +1 -0
  82. package/lib/module/Hmac.js +4 -21
  83. package/lib/module/Hmac.js.map +1 -1
  84. package/lib/module/NativeQuickCrypto/Cipher.js +3 -4
  85. package/lib/module/NativeQuickCrypto/Cipher.js.map +1 -1
  86. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +11 -17
  87. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
  88. package/lib/module/NativeQuickCrypto/hash.js.map +1 -1
  89. package/lib/module/NativeQuickCrypto/hmac.js.map +1 -1
  90. package/lib/module/NativeQuickCrypto/pbkdf2.js.map +1 -1
  91. package/lib/module/NativeQuickCrypto/random.js.map +1 -1
  92. package/lib/module/NativeQuickCrypto/sig.js.map +1 -1
  93. package/lib/module/NativeQuickCrypto/webcrypto.js +2 -0
  94. package/lib/module/NativeQuickCrypto/webcrypto.js.map +1 -0
  95. package/lib/module/QuickCrypto.js +2 -0
  96. package/lib/module/QuickCrypto.js.map +1 -1
  97. package/lib/module/Utils.js +319 -33
  98. package/lib/module/Utils.js.map +1 -1
  99. package/lib/module/aes.js +317 -0
  100. package/lib/module/aes.js.map +1 -0
  101. package/lib/module/constants.js.map +1 -1
  102. package/lib/module/ec.js +282 -0
  103. package/lib/module/ec.js.map +1 -0
  104. package/lib/module/index.js +7 -4
  105. package/lib/module/index.js.map +1 -1
  106. package/lib/module/keys.js +279 -43
  107. package/lib/module/keys.js.map +1 -1
  108. package/lib/module/pbkdf2.js +44 -13
  109. package/lib/module/pbkdf2.js.map +1 -1
  110. package/lib/module/random.js +46 -54
  111. package/lib/module/random.js.map +1 -1
  112. package/lib/module/rsa.js +323 -0
  113. package/lib/module/rsa.js.map +1 -0
  114. package/lib/module/sig.js +13 -46
  115. package/lib/module/sig.js.map +1 -1
  116. package/lib/module/subtle.js +265 -0
  117. package/lib/module/subtle.js.map +1 -0
  118. package/lib/typescript/src/Cipher.d.ts +72 -0
  119. package/lib/typescript/src/Cipher.d.ts.map +1 -0
  120. package/lib/typescript/{Hash.d.ts → src/Hash.d.ts} +8 -7
  121. package/lib/typescript/src/Hash.d.ts.map +1 -0
  122. package/lib/typescript/src/Hashnames.d.ts +11 -0
  123. package/lib/typescript/src/Hashnames.d.ts.map +1 -0
  124. package/lib/typescript/{Hmac.d.ts → src/Hmac.d.ts} +3 -3
  125. package/lib/typescript/src/Hmac.d.ts.map +1 -0
  126. package/lib/typescript/src/NativeQuickCrypto/Cipher.d.ts +34 -0
  127. package/lib/typescript/src/NativeQuickCrypto/Cipher.d.ts.map +1 -0
  128. package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/NativeQuickCrypto.d.ts +3 -0
  129. package/lib/typescript/src/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +1 -0
  130. package/lib/typescript/src/NativeQuickCrypto/hash.d.ts +7 -0
  131. package/lib/typescript/src/NativeQuickCrypto/hash.d.ts.map +1 -0
  132. package/lib/typescript/src/NativeQuickCrypto/hmac.d.ts +6 -0
  133. package/lib/typescript/src/NativeQuickCrypto/hmac.d.ts.map +1 -0
  134. package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/pbkdf2.d.ts +2 -1
  135. package/lib/typescript/src/NativeQuickCrypto/pbkdf2.d.ts.map +1 -0
  136. package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/random.d.ts +2 -1
  137. package/lib/typescript/src/NativeQuickCrypto/random.d.ts.map +1 -0
  138. package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/sig.d.ts +5 -4
  139. package/lib/typescript/src/NativeQuickCrypto/sig.d.ts.map +1 -0
  140. package/lib/typescript/src/NativeQuickCrypto/webcrypto.d.ts +27 -0
  141. package/lib/typescript/src/NativeQuickCrypto/webcrypto.d.ts.map +1 -0
  142. package/lib/typescript/{QuickCrypto.d.ts → src/QuickCrypto.d.ts} +16 -8
  143. package/lib/typescript/src/QuickCrypto.d.ts.map +1 -0
  144. package/lib/typescript/src/Utils.d.ts +44 -0
  145. package/lib/typescript/src/Utils.d.ts.map +1 -0
  146. package/lib/typescript/src/aes.d.ts +5 -0
  147. package/lib/typescript/src/aes.d.ts.map +1 -0
  148. package/lib/typescript/{constants.d.ts → src/constants.d.ts} +1 -0
  149. package/lib/typescript/src/constants.d.ts.map +1 -0
  150. package/lib/typescript/src/ec.d.ts +5 -0
  151. package/lib/typescript/src/ec.d.ts.map +1 -0
  152. package/lib/typescript/{index.d.ts → src/index.d.ts} +33 -27
  153. package/lib/typescript/src/index.d.ts.map +1 -0
  154. package/lib/typescript/src/keys.d.ts +154 -0
  155. package/lib/typescript/src/keys.d.ts.map +1 -0
  156. package/lib/typescript/src/pbkdf2.d.ts +12 -0
  157. package/lib/typescript/src/pbkdf2.d.ts.map +1 -0
  158. package/lib/typescript/{random.d.ts → src/random.d.ts} +7 -6
  159. package/lib/typescript/src/random.d.ts.map +1 -0
  160. package/lib/typescript/src/rsa.d.ts +4 -0
  161. package/lib/typescript/src/rsa.d.ts.map +1 -0
  162. package/lib/typescript/{sig.d.ts → src/sig.d.ts} +3 -3
  163. package/lib/typescript/src/sig.d.ts.map +1 -0
  164. package/lib/typescript/src/subtle.d.ts +11 -0
  165. package/lib/typescript/src/subtle.d.ts.map +1 -0
  166. package/package.json +35 -30
  167. package/react-native-quick-crypto.podspec +5 -4
  168. package/src/Cipher.ts +103 -100
  169. package/src/Hash.ts +42 -6
  170. package/src/Hashnames.ts +91 -0
  171. package/src/Hmac.ts +3 -3
  172. package/src/NativeQuickCrypto/Cipher.ts +1 -0
  173. package/src/NativeQuickCrypto/NativeQuickCrypto.ts +2 -0
  174. package/src/NativeQuickCrypto/webcrypto.ts +46 -0
  175. package/src/QuickCrypto.ts +2 -0
  176. package/src/Utils.ts +409 -5
  177. package/src/aes.ts +365 -0
  178. package/src/ec.ts +351 -0
  179. package/src/keys.ts +428 -54
  180. package/src/pbkdf2.ts +84 -11
  181. package/src/random.ts +37 -24
  182. package/src/rsa.ts +396 -0
  183. package/src/sig.ts +3 -2
  184. package/src/subtle.ts +358 -0
  185. package/lib/commonjs/@types/stream-browserify.d.js +0 -2
  186. package/lib/commonjs/@types/stream-browserify.d.js.map +0 -1
  187. package/lib/module/@types/stream-browserify.d.js +0 -2
  188. package/lib/module/@types/stream-browserify.d.js.map +0 -1
  189. package/lib/typescript/Cipher.d.ts +0 -87
  190. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +0 -32
  191. package/lib/typescript/NativeQuickCrypto/hash.d.ts +0 -6
  192. package/lib/typescript/NativeQuickCrypto/hmac.d.ts +0 -5
  193. package/lib/typescript/Utils.d.ts +0 -23
  194. package/lib/typescript/keys.d.ts +0 -60
  195. package/lib/typescript/pbkdf2.d.ts +0 -9
  196. package/src/@types/stream-browserify.d.ts +0 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EAGhB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGrE,eAAO,MAAM,kBAAkB;;;;CAIrB,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAErD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B,cAAc,EAAE,OAAO,CAAC;gBAGtB,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,eAAe,EAC7B,SAAS,EAAE,QAAQ,EAAE,EACrB,cAAc,EAAE,OAAO;IAQzB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,GAAG;IAoB3C,IAAI,IAAI,gDAGP;IAED,IAAI,WAAW,YAEd;IAED,IAAI,SAAS,oBAEZ;IAED,IAAI,MAAM,eAET;CACF;AAcD,cAAM,SAAS;IACb,MAAM,EAAE,eAAe,CAAC;IACxB,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAa;IAC9D,MAAM,CAAC,QAAQ,CAAC,EAAE,eAAe,GAAG,WAAW;gBAInC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe;CA+BlD;AAUD,qBAAa,eAAgB,SAAQ,SAAS;gBAChC,MAAM,EAAE,eAAe;IAQnC,MAAM,CAAC,OAAO,EAAE,eAAe;CAShC;AAiBD,cAAM,mBAAoB,SAAQ,SAAS;gBAC7B,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe;IAIjD,IAAI,iBAAiB,IAAI,iBAAiB,CAEzC;CAkBF;AAED,qBAAa,eAAgB,SAAQ,mBAAmB;gBAC1C,MAAM,EAAE,eAAe;IAInC,MAAM,CAAC,OAAO,EAAE,eAAe;CAWhC;AAED,qBAAa,gBAAiB,SAAQ,mBAAmB;gBAC3C,MAAM,EAAE,eAAe;IAInC,MAAM,CAAC,OAAO,EAAE,eAAe;CAchC"}
@@ -0,0 +1,12 @@
1
+ import { Buffer } from '@craftzdog/react-native-buffer';
2
+ import { type BinaryLike } from './Utils';
3
+ import type { CryptoKey, HashAlgorithm, SubtleAlgorithm } from './keys';
4
+ type Password = BinaryLike;
5
+ type Salt = BinaryLike;
6
+ type Pbkdf2Callback = (err: Error | null, derivedKey?: Buffer) => void;
7
+ export declare function pbkdf2(password: Password, salt: Salt, iterations: number, keylen: number, digest: HashAlgorithm, callback: Pbkdf2Callback): void;
8
+ export declare function pbkdf2(password: Password, salt: Salt, iterations: number, keylen: number, callback: Pbkdf2Callback): void;
9
+ export declare function pbkdf2Sync(password: Password, salt: Salt, iterations: number, keylen: number, digest?: HashAlgorithm): ArrayBuffer;
10
+ export declare function pbkdf2DeriveBits(algorithm: SubtleAlgorithm, baseKey: CryptoKey, length: number): Promise<ArrayBuffer>;
11
+ export {};
12
+ //# sourceMappingURL=pbkdf2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pbkdf2.d.ts","sourceRoot":"","sources":["../../../src/pbkdf2.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AACxD,OAAO,EACL,KAAK,UAAU,EAMhB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAOxE,KAAK,QAAQ,GAAG,UAAU,CAAC;AAC3B,KAAK,IAAI,GAAG,UAAU,CAAC;AACvB,KAAK,cAAc,GAAG,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAYvE,wBAAgB,MAAM,CACpB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,cAAc,GACvB,IAAI,CAAC;AACR,wBAAgB,MAAM,CACpB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,cAAc,GACvB,IAAI,CAAC;AA+CR,wBAAgB,UAAU,CACxB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,aAAa,GACrB,WAAW,CAcb;AAcD,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,eAAe,EAC1B,OAAO,EAAE,SAAS,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,CAsCtB"}
@@ -1,21 +1,22 @@
1
1
  import { Buffer } from '@craftzdog/react-native-buffer';
2
- declare type TypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array;
3
- declare type ArrayBufferView = TypedArray | DataView | ArrayBufferLike | Buffer;
2
+ type TypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array;
3
+ type ArrayBufferView = TypedArray | DataView | ArrayBufferLike | Buffer;
4
4
  export declare function randomFill<T extends ArrayBufferView>(buffer: T, callback: (err: Error | null, buf: T) => void): void;
5
5
  export declare function randomFill<T extends ArrayBufferView>(buffer: T, offset: number, callback: (err: Error | null, buf: T) => void): void;
6
6
  export declare function randomFill<T extends ArrayBufferView>(buffer: T, offset: number, size: number, callback: (err: Error | null, buf: T) => void): void;
7
7
  export declare function randomFillSync<T extends ArrayBufferView>(buffer: T, offset?: number, size?: number): T;
8
- export declare function randomBytes(size: number): ArrayBuffer;
9
- export declare function randomBytes(size: number, callback: (err: Error | null, buf?: ArrayBuffer) => void): void;
8
+ export declare function randomBytes(size: number): Buffer;
9
+ export declare function randomBytes(size: number, callback: (err: Error | null, buf?: Buffer) => void): void;
10
10
  export declare const rng: typeof randomBytes;
11
11
  export declare const pseudoRandomBytes: typeof randomBytes;
12
12
  export declare const prng: typeof randomBytes;
13
- declare type RandomIntCallback = (err: Error | null, value: number) => void;
13
+ type RandomIntCallback = (err: Error | null, value: number) => void;
14
14
  export declare function randomInt(max: number, callback: RandomIntCallback): void;
15
15
  export declare function randomInt(max: number): number;
16
16
  export declare function randomInt(min: number, max: number, callback: RandomIntCallback): void;
17
17
  export declare function randomInt(min: number, max: number): number;
18
- declare type DataType = Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array;
18
+ type DataType = Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array;
19
19
  export declare function getRandomValues(data: DataType): DataType;
20
20
  export declare function randomUUID(): string;
21
21
  export {};
22
+ //# sourceMappingURL=random.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../src/random.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAIxD,KAAK,UAAU,GACX,UAAU,GACV,iBAAiB,GACjB,WAAW,GACX,WAAW,GACX,SAAS,GACT,UAAU,GACV,UAAU,GACV,YAAY,GACZ,YAAY,CAAC;AACjB,KAAK,eAAe,GAAG,UAAU,GAAG,QAAQ,GAAG,eAAe,GAAG,MAAM,CAAC;AAExE,wBAAgB,UAAU,CAAC,CAAC,SAAS,eAAe,EAClD,MAAM,EAAE,CAAC,EACT,QAAQ,EAAE,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,IAAI,GAC5C,IAAI,CAAC;AAER,wBAAgB,UAAU,CAAC,CAAC,SAAS,eAAe,EAClD,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,IAAI,GAC5C,IAAI,CAAC;AAER,wBAAgB,UAAU,CAAC,CAAC,SAAS,eAAe,EAClD,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,IAAI,GAC5C,IAAI,CAAC;AA4CR,wBAAgB,cAAc,CAAC,CAAC,SAAS,eAAe,EACtD,MAAM,EAAE,CAAC,EACT,MAAM,CAAC,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,GACZ,CAAC,CAAC;AAWL,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;AAElD,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,IAAI,GAClD,IAAI,CAAC;AAqBR,eAAO,MAAM,GAAG,oBAAc,CAAC;AAC/B,eAAO,MAAM,iBAAiB,oBAAc,CAAC;AAC7C,eAAO,MAAM,IAAI,oBAAc,CAAC;AAEhC,KAAK,iBAAiB,GAAG,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AAuBpE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAC;AAC1E,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;AAC/C,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,iBAAiB,GAC1B,IAAI,CAAC;AACR,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;AAyH5D,KAAK,QAAQ,GACT,SAAS,GACT,UAAU,GACV,UAAU,GACV,UAAU,GACV,WAAW,GACX,WAAW,CAAC;AAChB,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,YAM7C;AASD,wBAAgB,UAAU,WAiCzB"}
@@ -0,0 +1,4 @@
1
+ import { type BufferLike } from './Utils';
2
+ import { CryptoKey, type ImportFormat, type JWK, type KeyUsage, type SubtleAlgorithm } from './keys';
3
+ export declare const rsaImportKey: (format: ImportFormat, keyData: BufferLike | JWK, algorithm: SubtleAlgorithm, extractable: boolean, keyUsages: KeyUsage[]) => CryptoKey;
4
+ //# sourceMappingURL=rsa.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rsa.d.ts","sourceRoot":"","sources":["../../../src/rsa.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,UAAU,EAKhB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,SAAS,EAGT,KAAK,YAAY,EACjB,KAAK,GAAG,EACR,KAAK,QAAQ,EACb,KAAK,eAAe,EAIrB,MAAM,QAAQ,CAAC;AA+MhB,eAAO,MAAM,YAAY,WACf,YAAY,WACX,UAAU,GAAG,GAAG,aACd,eAAe,eACb,OAAO,aACT,QAAQ,EAAE,KACpB,SAyHF,CAAC"}
@@ -1,7 +1,6 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
- import Stream from 'stream-browserify';
4
- import { BinaryLike } from './Utils';
2
+ import Stream from 'readable-stream';
3
+ import { type BinaryLike } from './Utils';
5
4
  declare class Verify extends Stream.Writable {
6
5
  private internal;
7
6
  constructor(algorithm: string, options: Stream.WritableOptions);
@@ -33,3 +32,4 @@ declare class Sign extends Stream.Writable {
33
32
  export declare function createSign(algorithm: string, options?: any): Sign;
34
33
  export declare function createVerify(algorithm: string, options?: any): Verify;
35
34
  export {};
35
+ //# sourceMappingURL=sig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sig.d.ts","sourceRoot":"","sources":["../../../src/sig.ts"],"names":[],"mappings":";AAEA,OAAO,MAAM,MAAM,iBAAiB,CAAC;AASrC,OAAO,EACL,KAAK,UAAU,EAGhB,MAAM,SAAS,CAAC;AAqCjB,cAAM,MAAO,SAAQ,MAAM,CAAC,QAAQ;IAClC,OAAO,CAAC,QAAQ,CAAiB;gBACrB,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,eAAe;IAM9D,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,QA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, CryptoKey, type AnyAlgorithm, type JWK } from './keys';
2
+ import { type BufferLike, type BinaryLike } from './Utils';
3
+ declare class Subtle {
4
+ digest(algorithm: SubtleAlgorithm | AnyAlgorithm, data: BufferLike): Promise<ArrayBuffer>;
5
+ deriveBits(algorithm: SubtleAlgorithm, baseKey: CryptoKey, length: number): Promise<ArrayBuffer>;
6
+ importKey(format: ImportFormat, data: BufferLike | BinaryLike | JWK, algorithm: SubtleAlgorithm, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
7
+ exportKey(format: ImportFormat, key: CryptoKey): Promise<ArrayBuffer | any>;
8
+ }
9
+ export declare const subtle: Subtle;
10
+ export {};
11
+ //# sourceMappingURL=subtle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subtle.d.ts","sourceRoot":"","sources":["../../../src/subtle.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,SAAS,EAGT,KAAK,YAAY,EACjB,KAAK,GAAG,EACT,MAAM,QAAQ,CAAC;AAChB,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,UAAU,EAKhB,MAAM,SAAS,CAAC;AA0LjB,cAAM,MAAM;IACJ,MAAM,CACV,SAAS,EAAE,eAAe,GAAG,YAAY,EACzC,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,WAAW,CAAC;IAKjB,UAAU,CACd,SAAS,EAAE,eAAe,EAC1B,OAAO,EAAE,SAAS,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC;IAyBjB,SAAS,CACb,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,UAAU,GAAG,UAAU,GAAG,GAAG,EACnC,SAAS,EAAE,eAAe,EAC1B,WAAW,EAAE,OAAO,EACpB,SAAS,EAAE,QAAQ,EAAE,GACpB,OAAO,CAAC,SAAS,CAAC;IAyFf,SAAS,CACb,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,WAAW,GAAG,GAAG,CAAC;CAe9B;AAED,eAAO,MAAM,MAAM,QAAe,CAAC"}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "react-native-quick-crypto",
3
- "version": "0.6.0",
3
+ "version": "0.7.0-rc.0",
4
4
  "description": "A fast implementation of Node's `crypto` module written in C/C++ JSI",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
7
- "types": "lib/typescript/index.d.ts",
7
+ "types": "lib/typescript/src/index.d.ts",
8
8
  "react-native": "lib/module/index",
9
9
  "source": "src/index",
10
10
  "files": [
@@ -26,7 +26,10 @@
26
26
  "lint": "eslint \"**/*.{js,ts,tsx}\"",
27
27
  "prepare": "bob build",
28
28
  "release": "release-it",
29
- "pods": "cd example/ios && pod-install --quiet"
29
+ "example": "yarn --cwd example",
30
+ "pods": "cd example && yarn pods",
31
+ "bootstrap": "yarn example && yarn && yarn pods",
32
+ "test": "jest"
30
33
  },
31
34
  "keywords": [
32
35
  "react-native",
@@ -49,25 +52,30 @@
49
52
  "registry": "https://registry.npmjs.org/"
50
53
  },
51
54
  "devDependencies": {
52
- "@jamesacarr/eslint-formatter-github-actions": "^0.1.0",
53
- "@react-native-community/eslint-config": "^3.2.0",
54
- "@react-native-community/eslint-plugin": "^1.3.0",
55
- "@release-it/conventional-changelog": "^3.3.0",
55
+ "@jamesacarr/eslint-formatter-github-actions": "^0.2.0",
56
+ "@react-native/babel-preset": "^0.75.0-main",
57
+ "@react-native/eslint-config": "^0.75.0-main",
58
+ "@react-native/eslint-plugin": "^0.75.0-main",
59
+ "@release-it/conventional-changelog": "^8.0.1",
60
+ "@types/chai": "^4.3.4",
61
+ "@types/jest": "^29.5.11",
62
+ "@types/mocha": "^10.0.1",
63
+ "@types/node": "^20.12.7",
56
64
  "@types/react": "^18.0.33",
57
- "@typescript-eslint/eslint-plugin": "^5.57.1",
58
- "eslint": "^8.37.0",
59
- "eslint-plugin-ft-flow": "^2.0.3",
65
+ "@types/readable-stream": "^4.0.11",
66
+ "eslint": "^8.4.1",
67
+ "eslint-config-prettier": "^8.5.0",
68
+ "eslint-plugin-prettier": "^4.0.0",
69
+ "jest": "^29.7.0",
60
70
  "prettier": "^2.4.0",
61
71
  "react": "^18.2.0",
62
- "react-native": "^0.71.6",
63
- "react-native-builder-bob": "^0.18.1",
64
- "release-it": "^14.11.5",
65
- "typescript": "4.8.4"
66
- },
67
- "peerDependencies": {
68
- "react": "*",
69
- "react-native": ">=0.71.0"
72
+ "react-native": "^0.72.7",
73
+ "react-native-builder-bob": "^0.23.2",
74
+ "release-it": "^17.0.0",
75
+ "sscrypto": "^1.1.1",
76
+ "typescript": "^5.1.6"
70
77
  },
78
+ "peerDependencies": {},
71
79
  "release-it": {
72
80
  "git": {
73
81
  "commitMessage": "chore: release ${version}",
@@ -112,7 +120,7 @@
112
120
  "eslintConfig": {
113
121
  "root": true,
114
122
  "extends": [
115
- "@react-native-community",
123
+ "@react-native",
116
124
  "prettier"
117
125
  ],
118
126
  "rules": {
@@ -126,13 +134,6 @@
126
134
  "useTabs": false
127
135
  }
128
136
  ]
129
- },
130
- "globals": {
131
- "BufferEncoding": true,
132
- "Buffer": true
133
- },
134
- "parserOptions": {
135
- "requireConfigFile": false
136
137
  }
137
138
  },
138
139
  "eslintIgnore": [
@@ -162,11 +163,15 @@
162
163
  },
163
164
  "dependencies": {
164
165
  "@craftzdog/react-native-buffer": "^6.0.5",
165
- "@types/node": "^17.0.31",
166
166
  "crypto-browserify": "^3.12.0",
167
167
  "events": "^3.3.0",
168
- "react-native-quick-base64": "^2.0.5",
169
- "stream-browserify": "^3.0.0",
170
- "string_decoder": "^1.3.0"
168
+ "react-native-quick-base64": "^2.1.1",
169
+ "readable-stream": "^4.5.2",
170
+ "string_decoder": "^1.3.0",
171
+ "util": "^0.12.5"
172
+ },
173
+ "resolutions": {
174
+ "browserify-sign": "4.2.2",
175
+ "react-native-quick-base64": "^2.1.1"
171
176
  }
172
177
  }
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
10
10
  s.license = package["license"]
11
11
  s.authors = package["authors"]
12
12
 
13
- s.platforms = { :ios => "11.0", :tvos => "12.0", :osx => "10.14" }
13
+ s.platforms = { :ios => "12.4", :tvos => "12.0", :osx => "10.14" }
14
14
  s.source = { :git => "https://github.com/mrousavy/react-native-quick-crypto.git", :tag => "#{s.version}" }
15
15
 
16
16
  # All source files that should be publicly visible
@@ -18,7 +18,8 @@ Pod::Spec.new do |s|
18
18
  s.source_files = [
19
19
  "ios/**/*.{h,m,mm}",
20
20
  "cpp/**/*.{h,c,cpp}",
21
- "ios/QuickCryptoModule.h"
21
+ "ios/QuickCryptoModule.h",
22
+ "node_modules/react-native-quick-base64/cpp/base64.h"
22
23
  ]
23
24
  # Any private headers that are not globally unique should be mentioned here.
24
25
  # Otherwise there will be a nameclash, since CocoaPods flattens out any header directories
@@ -33,12 +34,12 @@ Pod::Spec.new do |s|
33
34
  "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Headers/Private/React-Core\" "
34
35
  }
35
36
  s.xcconfig = {
36
- "CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
37
37
  "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/glog\" \"${PODS_ROOT}/Headers/Public/React-hermes\" \"${PODS_ROOT}/Headers/Public/hermes-engine\""
38
38
  }
39
39
 
40
- s.dependency "OpenSSL-Universal"
40
+ s.dependency "OpenSSL-Universal", "~> 1.1.2200"
41
41
  s.dependency "React-Core"
42
42
  s.dependency "React"
43
43
  s.dependency "React-callinvoker"
44
+ s.dependency "ReactCommon"
44
45
  end
package/src/Cipher.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /* eslint-disable no-dupe-class-members */
2
2
  import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
3
- import Stream from 'stream-browserify';
3
+ import Stream from 'readable-stream';
4
4
  import {
5
- BinaryLike,
5
+ type BinaryLike,
6
6
  binaryLikeToArrayBuffer,
7
- CipherEncoding,
8
- Encoding,
7
+ type CipherEncoding,
8
+ type Encoding,
9
9
  getDefaultEncoding,
10
10
  kEmptyObject,
11
11
  validateFunction,
@@ -13,21 +13,23 @@ import {
13
13
  validateString,
14
14
  validateUint32,
15
15
  validateInt32,
16
+ type BinaryLikeNode,
16
17
  } from './Utils';
17
- import { InternalCipher, RSAKeyVariant } from './NativeQuickCrypto/Cipher';
18
- // TODO(osp) re-enable type specific constructors
19
- // They are nice to have but not absolutely necessary
20
- // import type {
21
- // CipherCCMOptions,
22
- // CipherCCMTypes,
23
- // CipherGCMTypes,
24
- // CipherGCMOptions,
25
- // // CipherKey,
26
- // // KeyObject,
27
- // // TODO(Szymon) This types seem to be missing? Where did you get this definitions from?
28
- // // CipherOCBTypes,
29
- // // CipherOCBOptions,
30
- // } from 'crypto'; // Node crypto typings
18
+ import { type InternalCipher, RSAKeyVariant } from './NativeQuickCrypto/Cipher';
19
+ import type {
20
+ CipherCCMOptions,
21
+ CipherCCMTypes,
22
+ CipherGCMTypes,
23
+ CipherGCMOptions,
24
+ CipherOCBOptions,
25
+ CipherOCBTypes,
26
+ DecipherGCM,
27
+ DecipherOCB,
28
+ DecipherCCM,
29
+ CipherCCM,
30
+ CipherOCB,
31
+ CipherGCM,
32
+ } from 'crypto'; // @types/node
31
33
  import { StringDecoder } from 'string_decoder';
32
34
  import { Buffer } from '@craftzdog/react-native-buffer';
33
35
  import { Buffer as SBuffer } from 'safe-buffer';
@@ -106,7 +108,7 @@ class CipherCommon extends Stream.Transform {
106
108
 
107
109
  constructor(
108
110
  cipherType: string,
109
- cipherKey: BinaryLike,
111
+ cipherKey: BinaryLikeNode,
110
112
  isCipher: boolean,
111
113
  options: Record<string, any> = {},
112
114
  iv?: BinaryLike | null
@@ -204,12 +206,12 @@ class CipherCommon extends Stream.Transform {
204
206
  return this;
205
207
  }
206
208
 
207
- // protected getAuthTag(): Buffer {
208
- // return Buffer.from(this.internal.getAuthTag());
209
- // }
209
+ public getAuthTag(): ArrayBuffer {
210
+ return this.internal.getAuthTag();
211
+ }
210
212
 
211
213
  public setAuthTag(tag: Buffer): this {
212
- this.internal.setAuthTag(tag.buffer);
214
+ this.internal.setAuthTag(binaryLikeToArrayBuffer(tag));
213
215
  return this;
214
216
  }
215
217
  }
@@ -217,7 +219,7 @@ class CipherCommon extends Stream.Transform {
217
219
  class Cipher extends CipherCommon {
218
220
  constructor(
219
221
  cipherType: string,
220
- cipherKey: BinaryLike,
222
+ cipherKey: BinaryLikeNode,
221
223
  options: Record<string, any> = {},
222
224
  iv?: BinaryLike | null
223
225
  ) {
@@ -231,7 +233,7 @@ class Cipher extends CipherCommon {
231
233
  class Decipher extends CipherCommon {
232
234
  constructor(
233
235
  cipherType: string,
234
- cipherKey: BinaryLike,
236
+ cipherKey: BinaryLikeNode,
235
237
  options: Record<string, any> = {},
236
238
  iv?: BinaryLike | null
237
239
  ) {
@@ -243,100 +245,101 @@ class Decipher extends CipherCommon {
243
245
  }
244
246
  }
245
247
 
246
- // TODO(osp) This definitions cause typescript errors when using the API
247
- // export function createDecipher(
248
- // algorithm: CipherCCMTypes,
249
- // password: BinaryLike,
250
- // options: CipherCCMOptions
251
- // ): Decipher;
252
- // export function createDecipher(
253
- // algorithm: CipherGCMTypes,
254
- // password: BinaryLike,
255
- // options?: CipherGCMOptions
256
- // ): Decipher;
248
+ export function createDecipher(
249
+ algorithm: CipherCCMTypes,
250
+ password: BinaryLikeNode,
251
+ options: CipherCCMOptions
252
+ ): DecipherCCM;
253
+ export function createDecipher(
254
+ algorithm: CipherGCMTypes,
255
+ password: BinaryLikeNode,
256
+ options?: CipherGCMOptions
257
+ ): DecipherGCM;
257
258
  export function createDecipher(
258
259
  algorithm: string,
259
- password: BinaryLike,
260
- options?: Stream.TransformOptions
261
- ): Decipher {
260
+ password: BinaryLikeNode,
261
+ options?: CipherCCMOptions | CipherGCMOptions | Stream.TransformOptions
262
+ ): DecipherCCM | DecipherGCM | Decipher {
262
263
  return new Decipher(algorithm, password, options);
263
264
  }
264
265
 
265
- // TODO(osp) This definitions cause typescript errors when using the API
266
- // export function createDecipheriv(
267
- // algorithm: CipherCCMTypes,
268
- // key: BinaryLike,
269
- // iv: BinaryLike,
270
- // options: CipherCCMOptions
271
- // ): Decipher;
272
- // export function createDecipheriv(
273
- // algorithm: CipherOCBTypes,
274
- // key: BinaryLike,
275
- // iv: BinaryLike,
276
- // options: CipherOCBOptions
277
- // ): DecipherOCB;
278
- // export function createDecipheriv(
279
- // algorithm: CipherGCMTypes,
280
- // key: BinaryLike,
281
- // iv: BinaryLike,
282
- // options?: CipherGCMOptions
283
- // ): Decipher;
266
+ export function createDecipheriv(
267
+ algorithm: CipherCCMTypes,
268
+ key: BinaryLikeNode,
269
+ iv: BinaryLike,
270
+ options: CipherCCMOptions
271
+ ): DecipherCCM;
272
+ export function createDecipheriv(
273
+ algorithm: CipherOCBTypes,
274
+ key: BinaryLikeNode,
275
+ iv: BinaryLike,
276
+ options: CipherOCBOptions
277
+ ): DecipherOCB;
278
+ export function createDecipheriv(
279
+ algorithm: CipherGCMTypes,
280
+ key: BinaryLikeNode,
281
+ iv: BinaryLike,
282
+ options?: CipherGCMOptions
283
+ ): DecipherGCM;
284
284
  export function createDecipheriv(
285
285
  algorithm: string,
286
- key: BinaryLike,
286
+ key: BinaryLikeNode,
287
287
  iv: BinaryLike | null,
288
- options?: Stream.TransformOptions
289
- ): Decipher {
288
+ options?:
289
+ | CipherCCMOptions
290
+ | CipherOCBOptions
291
+ | CipherGCMOptions
292
+ | Stream.TransformOptions
293
+ ): DecipherCCM | DecipherOCB | DecipherGCM | Decipher {
290
294
  return new Decipher(algorithm, key, options, iv);
291
295
  }
292
296
 
293
- // TODO(osp) This definitions cause typescript errors when using the API
294
- // commenting them out for now
295
- // export function createCipher(
296
- // algorithm: CipherCCMTypes,
297
- // password: BinaryLike,
298
- // options: CipherCCMOptions
299
- // ): Cipher;
300
- // export function createCipher(
301
- // algorithm: CipherGCMTypes,
302
- // password: BinaryLike,
303
- // options?: CipherGCMOptions
304
- // ): Cipher;
297
+ export function createCipher(
298
+ algorithm: CipherCCMTypes,
299
+ password: BinaryLikeNode,
300
+ options: CipherCCMOptions
301
+ ): CipherCCM;
302
+ export function createCipher(
303
+ algorithm: CipherGCMTypes,
304
+ password: BinaryLikeNode,
305
+ options?: CipherGCMOptions
306
+ ): CipherGCM;
305
307
  export function createCipher(
306
308
  algorithm: string,
307
- password: BinaryLike,
308
- options?: Stream.TransformOptions
309
- ): Cipher {
309
+ password: BinaryLikeNode,
310
+ options?: CipherGCMOptions | CipherCCMOptions | Stream.TransformOptions
311
+ ): CipherCCM | CipherGCM | Cipher {
310
312
  return new Cipher(algorithm, password, options);
311
313
  }
312
314
 
313
- // TODO(osp) on all the createCipheriv methods, node seems to use a "KeyObject" is seems to be a thread safe
314
- // object that creates keys and what not. Not sure if we should support it.
315
- // Fow now I replaced all of them to BinaryLike
316
- // export function createCipheriv(
317
- // algorithm: CipherCCMTypes,
318
- // key: BinaryLike,
319
- // iv: BinaryLike,
320
- // options: CipherCCMOptions
321
- // ): Cipher;
322
- // export function createCipheriv(
323
- // algorithm: CipherOCBTypes,
324
- // key: BinaryLike,
325
- // iv: BinaryLike,
326
- // options: CipherOCBOptions
327
- // ): CipherOCB;
328
- // export function createCipheriv(
329
- // algorithm: CipherGCMTypes,
330
- // key: BinaryLike,
331
- // iv: BinaryLike,
332
- // options?: CipherGCMOptions
333
- // ): Cipher;
315
+ export function createCipheriv(
316
+ algorithm: CipherCCMTypes,
317
+ key: BinaryLikeNode,
318
+ iv: BinaryLike,
319
+ options: CipherCCMOptions
320
+ ): CipherCCM;
321
+ export function createCipheriv(
322
+ algorithm: CipherOCBTypes,
323
+ key: BinaryLikeNode,
324
+ iv: BinaryLike,
325
+ options: CipherOCBOptions
326
+ ): CipherOCB;
327
+ export function createCipheriv(
328
+ algorithm: CipherGCMTypes,
329
+ key: BinaryLikeNode,
330
+ iv: BinaryLike,
331
+ options?: CipherGCMOptions
332
+ ): CipherGCM;
334
333
  export function createCipheriv(
335
334
  algorithm: string,
336
- key: BinaryLike,
335
+ key: BinaryLikeNode,
337
336
  iv: BinaryLike | null,
338
- options?: Stream.TransformOptions
339
- ): Cipher {
337
+ options?:
338
+ | CipherCCMOptions
339
+ | CipherOCBOptions
340
+ | CipherGCMOptions
341
+ | Stream.TransformOptions
342
+ ): CipherCCM | CipherOCB | CipherGCM | Cipher {
340
343
  return new Cipher(algorithm, key, options, iv);
341
344
  }
342
345
 
package/src/Hash.ts CHANGED
@@ -2,9 +2,19 @@
2
2
  import 'react-native';
3
3
  import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
4
4
  import type { InternalHash } from './NativeQuickCrypto/hash';
5
- import { Encoding, toArrayBuffer } from './Utils';
6
- import Stream from 'stream-browserify';
5
+ import {
6
+ type Encoding,
7
+ toArrayBuffer,
8
+ validateMaxBufferLength,
9
+ normalizeHashName,
10
+ type BufferLike,
11
+ bufferLikeToArrayBuffer,
12
+ } from './Utils';
13
+ import Stream from 'readable-stream';
7
14
  import { Buffer } from '@craftzdog/react-native-buffer';
15
+ import { lazyDOMException } from './Utils';
16
+ import type { SubtleAlgorithm } from './keys';
17
+
8
18
  interface HashOptionsBase extends Stream.TransformOptions {
9
19
  outputLength?: number | undefined;
10
20
  }
@@ -15,8 +25,6 @@ global.process.nextTick = setImmediate;
15
25
 
16
26
  const createInternalHash = NativeQuickCrypto.createHash;
17
27
 
18
- type BinaryLike = ArrayBuffer;
19
-
20
28
  export function createHash(algorithm: string, options?: HashOptions) {
21
29
  return new Hash(algorithm, options);
22
30
  }
@@ -49,7 +57,7 @@ class Hash extends Stream.Transform {
49
57
  * @since v0.1.92
50
58
  * @param inputEncoding The `encoding` of the `data` string.
51
59
  */
52
- update(data: string | BinaryLike, inputEncoding?: Encoding): Hash {
60
+ update(data: string | ArrayBuffer, inputEncoding?: Encoding): Hash {
53
61
  if (data instanceof ArrayBuffer) {
54
62
  this.internalHash.update(data);
55
63
  return this;
@@ -60,7 +68,7 @@ class Hash extends Stream.Transform {
60
68
  }
61
69
 
62
70
  _transform(
63
- chunk: string | BinaryLike,
71
+ chunk: string | ArrayBuffer,
64
72
  encoding: Encoding,
65
73
  callback: () => void
66
74
  ) {
@@ -96,3 +104,31 @@ class Hash extends Stream.Transform {
96
104
  return Buffer.from(result);
97
105
  }
98
106
  }
107
+
108
+ // Implementation for WebCrypto subtle.digest()
109
+
110
+ export const asyncDigest = async (
111
+ algorithm: SubtleAlgorithm,
112
+ data: BufferLike
113
+ ): Promise<ArrayBuffer> => {
114
+ validateMaxBufferLength(data, 'data');
115
+
116
+ switch (algorithm.name) {
117
+ case 'SHA-1':
118
+ // Fall through
119
+ case 'SHA-256':
120
+ // Fall through
121
+ case 'SHA-384':
122
+ // Fall through
123
+ case 'SHA-512':
124
+ const normalizedHashName = normalizeHashName(algorithm.name);
125
+ const hash = new Hash(normalizedHashName);
126
+ hash.update(bufferLikeToArrayBuffer(data));
127
+ return hash.digest();
128
+ }
129
+
130
+ throw lazyDOMException(
131
+ `Unrecognized algorithm name: ${algorithm.name}`,
132
+ 'NotSupportedError'
133
+ );
134
+ };