react-native-quick-crypto 0.2.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 (143) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +84 -0
  3. package/android/.DS_Store +0 -0
  4. package/android/CMakeLists.txt +117 -0
  5. package/android/build.gradle +367 -0
  6. package/android/gradle/.DS_Store +0 -0
  7. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  8. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  9. package/android/gradle.properties +6 -0
  10. package/android/gradlew +183 -0
  11. package/android/gradlew.bat +100 -0
  12. package/android/src/.DS_Store +0 -0
  13. package/android/src/main/.DS_Store +0 -0
  14. package/android/src/main/AndroidManifest.xml +4 -0
  15. package/android/src/main/cpp/cpp-adapter.cpp +60 -0
  16. package/android/src/main/java/.DS_Store +0 -0
  17. package/android/src/main/java/com/.DS_Store +0 -0
  18. package/android/src/main/java/com/reactnativequickcrypto/QuickCryptoModule.java +70 -0
  19. package/android/src/main/java/com/reactnativequickcrypto/QuickCryptoPackage.java +26 -0
  20. package/cpp/.DS_Store +0 -0
  21. package/cpp/Cipher/MGLCipherHostObject.cpp +632 -0
  22. package/cpp/Cipher/MGLCipherHostObject.h +90 -0
  23. package/cpp/Cipher/MGLCreateCipherInstaller.cpp +74 -0
  24. package/cpp/Cipher/MGLCreateCipherInstaller.h +17 -0
  25. package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +74 -0
  26. package/cpp/Cipher/MGLCreateDecipherInstaller.h +17 -0
  27. package/cpp/HMAC/MGLHmacHostObject.cpp +95 -0
  28. package/cpp/HMAC/MGLHmacHostObject.h +39 -0
  29. package/cpp/HMAC/MGLHmacInstaller.cpp +43 -0
  30. package/cpp/HMAC/MGLHmacInstaller.h +20 -0
  31. package/cpp/Hash/MGLHashHostObject.cpp +147 -0
  32. package/cpp/Hash/MGLHashHostObject.h +53 -0
  33. package/cpp/Hash/MGLHashInstaller.cpp +46 -0
  34. package/cpp/Hash/MGLHashInstaller.h +20 -0
  35. package/cpp/JSIUtils/MGLJSIMacros.h +37 -0
  36. package/cpp/JSIUtils/MGLSmartHostObject.cpp +43 -0
  37. package/cpp/JSIUtils/MGLSmartHostObject.h +46 -0
  38. package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +24 -0
  39. package/cpp/JSIUtils/MGLThreadAwareHostObject.h +43 -0
  40. package/cpp/JSIUtils/MGLTypedArray.cpp +325 -0
  41. package/cpp/JSIUtils/MGLTypedArray.h +160 -0
  42. package/cpp/MGLQuickCryptoHostObject.cpp +64 -0
  43. package/cpp/MGLQuickCryptoHostObject.h +30 -0
  44. package/cpp/Random/MGLRandomHostObject.cpp +89 -0
  45. package/cpp/Random/MGLRandomHostObject.h +27 -0
  46. package/cpp/Utils/MGLDispatchQueue.cpp +75 -0
  47. package/cpp/Utils/MGLDispatchQueue.h +55 -0
  48. package/cpp/Utils/logs.h +38 -0
  49. package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +164 -0
  50. package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +29 -0
  51. package/cpp/fastpbkdf2/fastpbkdf2.c +352 -0
  52. package/cpp/fastpbkdf2/fastpbkdf2.h +68 -0
  53. package/ios/.DS_Store +0 -0
  54. package/ios/QuickCrypto.xcodeproj/project.pbxproj +274 -0
  55. package/ios/QuickCryptoModule.h +5 -0
  56. package/ios/QuickCryptoModule.mm +42 -0
  57. package/lib/.DS_Store +0 -0
  58. package/lib/commonjs/Cipher.js +293 -0
  59. package/lib/commonjs/Cipher.js.map +1 -0
  60. package/lib/commonjs/Hash.js +102 -0
  61. package/lib/commonjs/Hash.js.map +1 -0
  62. package/lib/commonjs/Hmac.js +104 -0
  63. package/lib/commonjs/Hmac.js.map +1 -0
  64. package/lib/commonjs/NativeQuickCrypto/Cipher.js +6 -0
  65. package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +1 -0
  66. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +61 -0
  67. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -0
  68. package/lib/commonjs/NativeQuickCrypto/hash.js +2 -0
  69. package/lib/commonjs/NativeQuickCrypto/hash.js.map +1 -0
  70. package/lib/commonjs/NativeQuickCrypto/hmac.js +2 -0
  71. package/lib/commonjs/NativeQuickCrypto/hmac.js.map +1 -0
  72. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +2 -0
  73. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +1 -0
  74. package/lib/commonjs/NativeQuickCrypto/random.js +2 -0
  75. package/lib/commonjs/NativeQuickCrypto/random.js.map +1 -0
  76. package/lib/commonjs/QuickCrypto.js +35 -0
  77. package/lib/commonjs/QuickCrypto.js.map +1 -0
  78. package/lib/commonjs/Utils.js +152 -0
  79. package/lib/commonjs/Utils.js.map +1 -0
  80. package/lib/commonjs/index.js +19 -0
  81. package/lib/commonjs/index.js.map +1 -0
  82. package/lib/commonjs/pbkdf2.js +64 -0
  83. package/lib/commonjs/pbkdf2.js.map +1 -0
  84. package/lib/commonjs/random.js +213 -0
  85. package/lib/commonjs/random.js.map +1 -0
  86. package/lib/module/Cipher.js +287 -0
  87. package/lib/module/Cipher.js.map +1 -0
  88. package/lib/module/Hash.js +87 -0
  89. package/lib/module/Hash.js.map +1 -0
  90. package/lib/module/Hmac.js +90 -0
  91. package/lib/module/Hmac.js.map +1 -0
  92. package/lib/module/NativeQuickCrypto/Cipher.js +2 -0
  93. package/lib/module/NativeQuickCrypto/Cipher.js.map +1 -0
  94. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +53 -0
  95. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -0
  96. package/lib/module/NativeQuickCrypto/hash.js +2 -0
  97. package/lib/module/NativeQuickCrypto/hash.js.map +1 -0
  98. package/lib/module/NativeQuickCrypto/hmac.js +2 -0
  99. package/lib/module/NativeQuickCrypto/hmac.js.map +1 -0
  100. package/lib/module/NativeQuickCrypto/pbkdf2.js +2 -0
  101. package/lib/module/NativeQuickCrypto/pbkdf2.js.map +1 -0
  102. package/lib/module/NativeQuickCrypto/random.js +2 -0
  103. package/lib/module/NativeQuickCrypto/random.js.map +1 -0
  104. package/lib/module/QuickCrypto.js +18 -0
  105. package/lib/module/QuickCrypto.js.map +1 -0
  106. package/lib/module/Utils.js +131 -0
  107. package/lib/module/Utils.js.map +1 -0
  108. package/lib/module/index.js +2 -0
  109. package/lib/module/index.js.map +1 -0
  110. package/lib/module/pbkdf2.js +51 -0
  111. package/lib/module/pbkdf2.js.map +1 -0
  112. package/lib/module/random.js +190 -0
  113. package/lib/module/random.js.map +1 -0
  114. package/lib/typescript/Cipher.d.ts +30 -0
  115. package/lib/typescript/Hash.d.ts +44 -0
  116. package/lib/typescript/Hmac.d.ts +37 -0
  117. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +22 -0
  118. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +19 -0
  119. package/lib/typescript/NativeQuickCrypto/hash.d.ts +6 -0
  120. package/lib/typescript/NativeQuickCrypto/hmac.d.ts +5 -0
  121. package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts +4 -0
  122. package/lib/typescript/NativeQuickCrypto/random.d.ts +4 -0
  123. package/lib/typescript/QuickCrypto.d.ts +31 -0
  124. package/lib/typescript/Utils.d.ts +13 -0
  125. package/lib/typescript/index.d.ts +1 -0
  126. package/lib/typescript/pbkdf2.d.ts +9 -0
  127. package/lib/typescript/random.d.ts +20 -0
  128. package/package.json +168 -0
  129. package/react-native-quick-crypto.podspec +44 -0
  130. package/src/Cipher.ts +322 -0
  131. package/src/Hash.ts +98 -0
  132. package/src/Hmac.ts +107 -0
  133. package/src/NativeQuickCrypto/Cipher.ts +25 -0
  134. package/src/NativeQuickCrypto/NativeQuickCrypto.ts +79 -0
  135. package/src/NativeQuickCrypto/hash.ts +10 -0
  136. package/src/NativeQuickCrypto/hmac.ts +9 -0
  137. package/src/NativeQuickCrypto/pbkdf2.ts +16 -0
  138. package/src/NativeQuickCrypto/random.ts +12 -0
  139. package/src/QuickCrypto.ts +23 -0
  140. package/src/Utils.ts +151 -0
  141. package/src/index.ts +1 -0
  142. package/src/pbkdf2.ts +96 -0
  143. package/src/random.ts +277 -0
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createHash = createHash;
7
+
8
+ require("react-native");
9
+
10
+ var _NativeQuickCrypto = require("./NativeQuickCrypto/NativeQuickCrypto");
11
+
12
+ var _Utils = require("./Utils");
13
+
14
+ var _stream = _interopRequireDefault(require("stream"));
15
+
16
+ var _reactNativeBuffer = require("@craftzdog/react-native-buffer");
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
+
22
+ global.process.nextTick = setImmediate;
23
+ const createInternalHash = _NativeQuickCrypto.NativeQuickCrypto.createHash;
24
+
25
+ function createHash(algorithm, options) {
26
+ return new Hash(algorithm, options);
27
+ }
28
+
29
+ class Hash extends _stream.default.Transform {
30
+ constructor(arg, options) {
31
+ super(options !== null && options !== void 0 ? options : undefined);
32
+
33
+ _defineProperty(this, "internalHash", void 0);
34
+
35
+ if (arg instanceof Hash) {
36
+ this.internalHash = arg.internalHash.copy(options === null || options === void 0 ? void 0 : options.outputLength);
37
+ } else {
38
+ this.internalHash = createInternalHash(arg, options === null || options === void 0 ? void 0 : options.outputLength);
39
+ }
40
+ }
41
+
42
+ copy(options) {
43
+ const copy = new Hash(this, options);
44
+ return copy;
45
+ }
46
+ /**
47
+ * Updates the hash content with the given `data`, the encoding of which
48
+ * is given in `inputEncoding`.
49
+ * If `encoding` is not provided, and the `data` is a string, an
50
+ * encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
51
+ *
52
+ * This can be called many times with new data as it is streamed.
53
+ * @since v0.1.92
54
+ * @param inputEncoding The `encoding` of the `data` string.
55
+ */
56
+
57
+
58
+ update(data, inputEncoding) {
59
+ if (data instanceof ArrayBuffer) {
60
+ this.internalHash.update(data);
61
+ return this;
62
+ }
63
+
64
+ const buffer = _reactNativeBuffer.Buffer.from(data, inputEncoding);
65
+
66
+ this.internalHash.update((0, _Utils.toArrayBuffer)(buffer));
67
+ return this;
68
+ }
69
+
70
+ _transform(chunk, encoding, callback) {
71
+ this.update(chunk, encoding);
72
+ callback();
73
+ }
74
+
75
+ _flush(callback) {
76
+ this.push(this.digest());
77
+ callback();
78
+ }
79
+ /**
80
+ * Calculates the digest of all of the data passed to be hashed (using the `hash.update()` method).
81
+ * If `encoding` is provided a string will be returned; otherwise
82
+ * a `Buffer` is returned.
83
+ *
84
+ * The `Hash` object can not be used again after `hash.digest()` method has been
85
+ * called. Multiple calls will cause an error to be thrown.
86
+ * @since v0.1.92
87
+ * @param encoding The `encoding` of the return value.
88
+ */
89
+
90
+
91
+ digest(encoding) {
92
+ const result = this.internalHash.digest();
93
+
94
+ if (encoding && encoding !== 'buffer') {
95
+ return _reactNativeBuffer.Buffer.from(result).toString(encoding);
96
+ }
97
+
98
+ return _reactNativeBuffer.Buffer.from(result);
99
+ }
100
+
101
+ }
102
+ //# sourceMappingURL=Hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["Hash.ts"],"names":["global","process","nextTick","setImmediate","createInternalHash","NativeQuickCrypto","createHash","algorithm","options","Hash","Stream","Transform","constructor","arg","undefined","internalHash","copy","outputLength","update","data","inputEncoding","ArrayBuffer","buffer","Buffer","from","_transform","chunk","encoding","callback","_flush","push","digest","result","toString"],"mappings":";;;;;;;AACA;;AACA;;AAEA;;AACA;;AACA;;;;;;AAOAA,MAAM,CAACC,OAAP,CAAeC,QAAf,GAA0BC,YAA1B;AAEA,MAA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AL,CAAYQ,KAAZ,EAAmBC,QAAnB;AACAC,IAAAA,QAAQ;AACT;;AAEDC,EAAAA,MAAM,CAACD,QAAD,EAAuB;AAC3B,SAAKE,IAAL,CAAU,KAAKC,MAAL,EAAV;AACAH,IAAAA,QAAQ;AACT;AAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAIEG,EAAAA,MAAM,CAACJ,QAAD,EAAkD;AACtD,UAAMK,MAAmB,GAAG,KAAKjB,YAAL,CAAkBgB,MAAlB,EAA5B;;AAEA,QAAIJ,QAAQ,IAAIA,QAAQ,KAAK,QAA7B,EAAuC;AACrC,aAAOJ,0BAAOC,IAAP,CAAYQ,MAAZ,EAAoBC,QAApB,CAA6BN,QAA7B,CAAP;AACD;;AAED,WAAOJ,0BAAOC,IAAP,CAAYQ,MAAZ,CAAP;AACD;;AAzEiC","sourcesContent":["/* eslint-disable no-dupe-class-members */\nimport 'react-native';\nimport { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';\nimport type { InternalHash } from './NativeQuickCrypto/hash';\nimport { Encoding, toArrayBuffer } from './Utils';\nimport Stream from 'stream';\nimport { Buffer } from '@craftzdog/react-native-buffer';\ninterface HashOptionsBase extends Stream.TransformOptions {\n outputLength?: number | undefined;\n}\n\ntype HashOptions = null | undefined | HashOptionsBase;\n\nglobal.process.nextTick = setImmediate;\n\nconst createInternalHash = NativeQuickCrypto.createHash;\n\ntype BinaryLike = ArrayBuffer;\n\nexport function createHash(algorithm: string, options?: HashOptions) {\n return new Hash(algorithm, options);\n}\n\nclass Hash extends Stream.Transform {\n private internalHash: InternalHash;\n\n constructor(other: Hash, options?: HashOptions);\n constructor(algorithm: string, options?: HashOptions);\n constructor(arg: string | Hash, options?: HashOptions) {\n super(options ?? undefined);\n if (arg instanceof Hash) {\n this.internalHash = arg.internalHash.copy(options?.outputLength);\n } else {\n this.internalHash = createInternalHash(arg, options?.outputLength);\n }\n }\n\n copy(options?: HashOptionsBase): Hash {\n const copy = new Hash(this, options);\n return copy;\n }\n /**\n * Updates the hash content with the given `data`, the encoding of which\n * is given in `inputEncoding`.\n * If `encoding` is not provided, and the `data` is a string, an\n * encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.\n *\n * This can be called many times with new data as it is streamed.\n * @since v0.1.92\n * @param inputEncoding The `encoding` of the `data` string.\n */\n update(data: string | BinaryLike, inputEncoding?: Encoding): Hash {\n if (data instanceof ArrayBuffer) {\n this.internalHash.update(data);\n return this;\n }\n const buffer = Buffer.from(data, inputEncoding);\n this.internalHash.update(toArrayBuffer(buffer));\n return this;\n }\n\n _transform(\n chunk: string | BinaryLike,\n encoding: Encoding,\n callback: () => void\n ) {\n this.update(chunk, encoding);\n callback();\n }\n\n _flush(callback: () => void) {\n this.push(this.digest());\n callback();\n }\n\n /**\n * Calculates the digest of all of the data passed to be hashed (using the `hash.update()` method).\n * If `encoding` is provided a string will be returned; otherwise\n * a `Buffer` is returned.\n *\n * The `Hash` object can not be used again after `hash.digest()` method has been\n * called. Multiple calls will cause an error to be thrown.\n * @since v0.1.92\n * @param encoding The `encoding` of the return value.\n */\n digest(): Buffer;\n digest(encoding: 'buffer'): Buffer;\n digest(encoding: Encoding): string;\n digest(encoding?: Encoding | 'buffer'): string | Buffer {\n const result: ArrayBuffer = this.internalHash.digest();\n\n if (encoding && encoding !== 'buffer') {\n return Buffer.from(result).toString(encoding);\n }\n\n return Buffer.from(result);\n }\n}\n"]}
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createHmac = createHmac;
7
+
8
+ var _NativeQuickCrypto = require("./NativeQuickCrypto/NativeQuickCrypto");
9
+
10
+ var _Utils = require("./Utils");
11
+
12
+ var _stream = _interopRequireDefault(require("stream"));
13
+
14
+ var _reactNativeBuffer = require("@craftzdog/react-native-buffer");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
+
20
+ const createInternalHmac = _NativeQuickCrypto.NativeQuickCrypto.createHmac;
21
+
22
+ function createHmac(algorithm, key, options) {
23
+ return new Hmac(algorithm, key, options);
24
+ }
25
+
26
+ class Hmac extends _stream.default.Transform {
27
+ constructor(algorithm, key, _options) {
28
+ super();
29
+
30
+ _defineProperty(this, "internalHmac", void 0);
31
+
32
+ _defineProperty(this, "isFinalized", false);
33
+
34
+ let keyAsString = (0, _Utils.binaryLikeToArrayBuffer)(key);
35
+
36
+ if (keyAsString === undefined) {
37
+ throw 'Wrong key type';
38
+ }
39
+
40
+ this.internalHmac = createInternalHmac(algorithm, keyAsString);
41
+ }
42
+ /**
43
+ * Updates the `Hmac` content with the given `data`, the encoding of which
44
+ * is given in `inputEncoding`.
45
+ * If `encoding` is not provided, and the `data` is a string, an
46
+ * encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
47
+ *
48
+ * This can be called many times with new data as it is streamed.
49
+ * @since v0.1.94
50
+ * @param inputEncoding The `encoding` of the `data` string.
51
+ */
52
+
53
+
54
+ update(data, inputEncoding) {
55
+ if (data instanceof ArrayBuffer) {
56
+ this.internalHmac.update(data);
57
+ return this;
58
+ }
59
+
60
+ if (typeof data === 'string') {
61
+ const buffer = _reactNativeBuffer.Buffer.from(data, inputEncoding);
62
+
63
+ this.internalHmac.update((0, _Utils.toArrayBuffer)(buffer));
64
+ return this;
65
+ }
66
+
67
+ this.internalHmac.update((0, _Utils.binaryLikeToArrayBuffer)(data));
68
+ return this;
69
+ }
70
+
71
+ _transform(chunk, encoding, callback) {
72
+ this.update(chunk, encoding);
73
+ callback();
74
+ }
75
+
76
+ _flush(callback) {
77
+ this.push(this.digest());
78
+ callback();
79
+ }
80
+ /**
81
+ * Calculates the HMAC digest of all of the data passed using `hmac.update()`.
82
+ * If `encoding` is
83
+ * provided a string is returned; otherwise a `Buffer` is returned;
84
+ *
85
+ * The `Hmac` object can not be used again after `hmac.digest()` has been
86
+ * called. Multiple calls to `hmac.digest()` will result in an error being thrown.
87
+ * @since v0.1.94
88
+ * @param encoding The `encoding` of the return value.
89
+ */
90
+
91
+
92
+ digest(encoding) {
93
+ const result = this.isFinalized ? new ArrayBuffer(0) : this.internalHmac.digest();
94
+ this.isFinalized = true;
95
+
96
+ if (encoding && encoding !== 'buffer') {
97
+ return _reactNativeBuffer.Buffer.from(result).toString(encoding);
98
+ }
99
+
100
+ return _reactNativeBuffer.Buffer.from(result);
101
+ }
102
+
103
+ }
104
+ //# sourceMappingURL=Hmac.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["Hmac.ts"],"names":["createInternalHmac","NativeQuickCrypto","createHmac","algorithm","key","options","Hmac","Stream","Transform","constructor","_options","keyAsString","undefined","internalHmac","update","data","inputEncoding","ArrayBuffer","buffer","Buffer","from","_transform","chunk","encoding","callback","_flush","push","digest","result","isFinalized","toString"],"mappings":";;;;;;;AACA;;AAEA;;AAMA;;AACA;;;;;;AAEA,MAAMA,kBAAkB,GAAGC,qCAAkBC,UAA7C;;AAEO,SAASA,UAAT,CACLC,SADK,EAELC,GAFK,EAGLC,OAHK,EAIL;AACA,SAAO,IAAIC,IAAJ,CAASH,SAAT,EAAoBC,GAApB,EAAyBC,OAAzB,CAAP;AACD;;AAED,MAAMC,IAAN,SAAmBC,gBAAOC,SAA1B,CAAoC;AAIlCC,EAAAA,WAAW,CACTN,SADS,EAETC,GAFS,EAGTM,QAHS,EAIT;AACA;;AADA;;AAAA,yCAN6B,KAM7B;;AAEA,QAAIC,WAAW,GAAG,oCAAwBP,GAAxB,CAAlB;;AAEA,QAAIO,WAAW,KAAKC,SAApB,EAA+B;AAC7B,YAAM,gBAAN;AACD;;AAED,SAAKC,YAAL,GAAoBb,kBAAkB,CACpCG,S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AAZ,CAAP;AACD;;AAnFiC","sourcesContent":["/* eslint-disable no-dupe-class-members */\nimport { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';\nimport type { InternalHmac } from './NativeQuickCrypto/hmac';\nimport {\n Encoding,\n toArrayBuffer,\n BinaryLike,\n binaryLikeToArrayBuffer,\n} from './Utils';\nimport Stream from 'stream';\nimport { Buffer } from '@craftzdog/react-native-buffer';\n\nconst createInternalHmac = NativeQuickCrypto.createHmac;\n\nexport function createHmac(\n algorithm: string,\n key: BinaryLike,\n options?: Stream.TransformOptions\n) {\n return new Hmac(algorithm, key, options);\n}\n\nclass Hmac extends Stream.Transform {\n private internalHmac: InternalHmac;\n private isFinalized: boolean = false;\n\n constructor(\n algorithm: string,\n key: BinaryLike,\n _options?: Stream.TransformOptions\n ) {\n super();\n let keyAsString = binaryLikeToArrayBuffer(key);\n\n if (keyAsString === undefined) {\n throw 'Wrong key type';\n }\n\n this.internalHmac = createInternalHmac(\n algorithm,\n keyAsString as ArrayBuffer\n );\n }\n\n /**\n * Updates the `Hmac` content with the given `data`, the encoding of which\n * is given in `inputEncoding`.\n * If `encoding` is not provided, and the `data` is a string, an\n * encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.\n *\n * This can be called many times with new data as it is streamed.\n * @since v0.1.94\n * @param inputEncoding The `encoding` of the `data` string.\n */\n update(data: string | BinaryLike, inputEncoding?: Encoding): Hmac {\n if (data instanceof ArrayBuffer) {\n this.internalHmac.update(data);\n return this;\n }\n if (typeof data === 'string') {\n const buffer = Buffer.from(data, inputEncoding);\n this.internalHmac.update(toArrayBuffer(buffer));\n return this;\n }\n\n this.internalHmac.update(binaryLikeToArrayBuffer(data));\n return this;\n }\n\n _transform(\n chunk: string | BinaryLike,\n encoding: Encoding,\n callback: () => void\n ) {\n this.update(chunk, encoding);\n callback();\n }\n\n _flush(callback: () => void) {\n this.push(this.digest());\n callback();\n }\n\n /**\n * Calculates the HMAC digest of all of the data passed using `hmac.update()`.\n * If `encoding` is\n * provided a string is returned; otherwise a `Buffer` is returned;\n *\n * The `Hmac` object can not be used again after `hmac.digest()` has been\n * called. Multiple calls to `hmac.digest()` will result in an error being thrown.\n * @since v0.1.94\n * @param encoding The `encoding` of the return value.\n */\n digest(): Buffer;\n digest(encoding: 'buffer'): Buffer;\n digest(encoding: Encoding): string;\n digest(encoding?: Encoding | 'buffer'): string | Buffer {\n const result: ArrayBuffer = this.isFinalized\n ? new ArrayBuffer(0)\n : this.internalHmac.digest();\n this.isFinalized = true;\n if (encoding && encoding !== 'buffer') {\n return Buffer.from(result).toString(encoding);\n }\n return Buffer.from(result);\n }\n}\n"]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=Cipher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NativeQuickCrypto = void 0;
7
+
8
+ var _reactNative = require("react-native");
9
+
10
+ // Check if the constructor exists. If not, try installing the JSI bindings.
11
+ if (global.__QuickCryptoProxy == null) {
12
+ // Get the native QuickCrypto ReactModule
13
+ const QuickCryptoModule = _reactNative.NativeModules.QuickCrypto;
14
+
15
+ if (QuickCryptoModule == null) {
16
+ var _NativeModules$Native, _NativeModules$Native2;
17
+
18
+ let message = 'Failed to install react-native-quick-crypto: The native `QuickCrypto` Module could not be found.';
19
+ message += '\n* Make sure react-native-quick-crypto is correctly autolinked (run `npx react-native config` to verify)';
20
+
21
+ if (_reactNative.Platform.OS === 'ios' || _reactNative.Platform.OS === 'macos') {
22
+ message += '\n* Make sure you ran `pod install` in the ios/ directory.';
23
+ }
24
+
25
+ if (_reactNative.Platform.OS === 'android') {
26
+ message += '\n* Make sure gradle is synced.';
27
+ } // check if Expo
28
+
29
+
30
+ const ExpoConstants = (_NativeModules$Native = _reactNative.NativeModules.NativeUnimoduleProxy) === null || _NativeModules$Native === void 0 ? void 0 : (_NativeModules$Native2 = _NativeModules$Native.modulesConstants) === null || _NativeModules$Native2 === void 0 ? void 0 : _NativeModules$Native2.ExponentConstants;
31
+
32
+ if (ExpoConstants != null) {
33
+ if (ExpoConstants.appOwnership === 'expo') {
34
+ // We're running Expo Go
35
+ throw new Error('react-native-quick-crypto is not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.');
36
+ } else {
37
+ // We're running Expo bare / standalone
38
+ message += '\n* Make sure you ran `expo prebuild`.';
39
+ }
40
+ }
41
+
42
+ message += '\n* Make sure you rebuilt the app.';
43
+ throw new Error(message);
44
+ } // Check if we are running on-device (JSI)
45
+
46
+
47
+ if (global.nativeCallSyncHook == null || QuickCryptoModule.install == null) {
48
+ throw new Error('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.');
49
+ } // Call the synchronous blocking install() function
50
+
51
+
52
+ const result = QuickCryptoModule.install();
53
+ if (result !== true) throw new Error(`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}`); // Check again if the constructor now exists. If not, throw an error.
54
+
55
+ if (global.__QuickCryptoProxy == null) throw new Error('Failed to install react-native-quick-crypto, the native initializer function does not exist. Are you trying to use QuickCrypto from different JS Runtimes?');
56
+ }
57
+
58
+ const proxy = global.__QuickCryptoProxy;
59
+ const NativeQuickCrypto = proxy;
60
+ exports.NativeQuickCrypto = NativeQuickCrypto;
61
+ //# sourceMappingURL=NativeQuickCrypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["NativeQuickCrypto.ts"],"names":["global","__QuickCryptoProxy","QuickCryptoModule","NativeModules","QuickCrypto","message","Platform","OS","ExpoConstants","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","Error","nativeCallSyncHook","install","result","proxy","NativeQuickCrypto"],"mappings":";;;;;;;AAAA;;AAsBA;AACA,IAAIA,MAAM,CAACC,kBAAP,IAA6B,IAAjC,EAAuC;AACrC;AACA,QAAMC,iBAAiB,GAAGC,2BAAcC,WAAxC;;AACA,MAAIF,iBAAiB,IAAI,IAAzB,EAA+B;AAAA;;AAC7B,QAAIG,OAAO,GACT,kGADF;AAEAA,IAAAA,OAAO,IACL,2GADF;;AAEA,QAAIC,sBAASC,EAAT,KAAgB,KAAhB,IAAyBD,sBAASC,EAAT,KAAgB,OAA7C,EAAsD;AACpDF,MAAAA,OAAO,IAAI,4DAAX;AACD;;AACD,QAAIC,sBAASC,EAAT,KAAgB,SAApB,EAA+B;AAC7BF,MAAAA,OAAO,IAAI,iCAAX;AACD,KAV4B,CAW7B;;;AACA,UAAMG,aAAa,4BACjBL,2BAAcM,oBADG,oFACjB,sBAAoCC,gBADnB,2DACjB,uBAAsDC,iBADxD;;AAEA,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACzB,UAAIA,aAAa,CAACI,YAAd,KAA+B,MAAnC,EAA2C;AACzC;AACA,cAAM,IAAIC,KAAJ,CACJ,uHADI,CAAN;AAGD,OALD,MAKO;AACL;AACAR,QAAAA,OAAO,IAAI,wCAAX;AACD;AACF;;AAEDA,IAAAA,OAAO,IAAI,oCAAX;AACA,UAAM,IAAIQ,KAAJ,CAAUR,OAAV,CAAN;AACD,GA/BoC,CAiCrC;;;AACA,MAAIL,MAAM,CAACc,kBAAP,IAA6B,IAA7B,IAAqCZ,iBAAiB,CAACa,OAAlB,IAA6B,IAAtE,EAA4E;AAC1E,UAAM,IAAIF,KAAJ,CACJ,oRADI,CAAN;AAGD,GAtCoC,CAwCrC;;;AACA,QAAMG,MAAM,GAAGd,iBAAiB,CAACa,OAAlB,EAAf;AACA,MAAIC,MAAM,KAAK,IAAf,EACE,MAAM,IAAIH,KAAJ,CACH,oKAAmKG,MAAO,EADvK,CAAN,CA3CmC,CA+CrC;;AACA,MAAIhB,MAAM,CAACC,kBAAP,IAA6B,IAAjC,EACE,MAAM,IAAIY,KAAJ,CACJ,4JADI,CAAN;AAGH;;AAED,MAAMI,KAAK,GAAGjB,MAAM,CAACC,kBAArB;AACO,MAAMiB,iBAAiB,GAAGD,KAA1B","sourcesContent":["import { NativeModules, Platform } from 'react-native';\nimport type { CreateHmacMethod } from './hmac';\nimport type { CreateHashMethod } from './hash';\nimport type { Pbkdf2Object } from './pbkdf2';\nimport type { RandomObject } from './random';\nimport type { CreateCipherMethod, CreateDecipherMethod } from './Cipher';\n\ninterface NativeQuickCryptoSpec {\n createHmac: CreateHmacMethod;\n pbkdf2: Pbkdf2Object;\n random: RandomObject;\n createHash: CreateHashMethod;\n createCipher: CreateCipherMethod;\n createDecipher: CreateDecipherMethod;\n}\n\n// global func declaration for JSI functions\ndeclare global {\n function nativeCallSyncHook(): unknown;\n var __QuickCryptoProxy: object | undefined;\n}\n\n// Check if the constructor exists. If not, try installing the JSI bindings.\nif (global.__QuickCryptoProxy == null) {\n // Get the native QuickCrypto ReactModule\n const QuickCryptoModule = NativeModules.QuickCrypto;\n if (QuickCryptoModule == null) {\n let message =\n 'Failed to install react-native-quick-crypto: The native `QuickCrypto` Module could not be found.';\n message +=\n '\\n* Make sure react-native-quick-crypto is correctly autolinked (run `npx react-native config` to verify)';\n if (Platform.OS === 'ios' || Platform.OS === 'macos') {\n message += '\\n* Make sure you ran `pod install` in the ios/ directory.';\n }\n if (Platform.OS === 'android') {\n message += '\\n* Make sure gradle is synced.';\n }\n // check if Expo\n const ExpoConstants =\n NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;\n if (ExpoConstants != null) {\n if (ExpoConstants.appOwnership === 'expo') {\n // We're running Expo Go\n throw new Error(\n 'react-native-quick-crypto is not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.'\n );\n } else {\n // We're running Expo bare / standalone\n message += '\\n* Make sure you ran `expo prebuild`.';\n }\n }\n\n message += '\\n* Make sure you rebuilt the app.';\n throw new Error(message);\n }\n\n // Check if we are running on-device (JSI)\n if (global.nativeCallSyncHook == null || QuickCryptoModule.install == null) {\n throw new Error(\n '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.'\n );\n }\n\n // Call the synchronous blocking install() function\n const result = QuickCryptoModule.install();\n if (result !== true)\n throw new Error(\n `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}`\n );\n\n // Check again if the constructor now exists. If not, throw an error.\n if (global.__QuickCryptoProxy == null)\n throw new Error(\n 'Failed to install react-native-quick-crypto, the native initializer function does not exist. Are you trying to use QuickCrypto from different JS Runtimes?'\n );\n}\n\nconst proxy = global.__QuickCryptoProxy;\nexport const NativeQuickCrypto = proxy as any as NativeQuickCryptoSpec;\n"]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=hmac.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=pbkdf2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=random.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.QuickCrypto = void 0;
7
+
8
+ var pbkdf2 = _interopRequireWildcard(require("./pbkdf2"));
9
+
10
+ var random = _interopRequireWildcard(require("./random"));
11
+
12
+ var _Cipher = require("./Cipher");
13
+
14
+ var _Hmac = require("./Hmac");
15
+
16
+ var _Hash = require("./Hash");
17
+
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
+
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
+
22
+ const QuickCrypto = {
23
+ createHmac: _Hmac.createHmac,
24
+ Hmac: _Hmac.createHmac,
25
+ Hash: _Hash.createHash,
26
+ createHash: _Hash.createHash,
27
+ createCipher: _Cipher.createCipher,
28
+ createCipheriv: _Cipher.createCipheriv,
29
+ createDecipher: _Cipher.createDecipher,
30
+ createDecipheriv: _Cipher.createDecipheriv,
31
+ ...pbkdf2,
32
+ ...random
33
+ };
34
+ exports.QuickCrypto = QuickCrypto;
35
+ //# sourceMappingURL=QuickCrypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["QuickCrypto.ts"],"names":["QuickCrypto","createHmac","Hmac","Hash","createHash","createCipher","createCipheriv","createDecipher","createDecipheriv","pbkdf2","random"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAMA;;AACA;;;;;;AAEO,MAAMA,WAAW,GAAG;AACzBC,EAAAA,UAAU,EAAVA,gBADyB;AAEzBC,EAAAA,IAAI,EAAED,gBAFmB;AAGzBE,EAAAA,IAAI,EAAEC,gBAHmB;AAIzBA,EAAAA,UAAU,EAAVA,gBAJyB;AAKzBC,EAAAA,YAAY,EAAZA,oBALyB;AAMzBC,EAAAA,cAAc,EAAdA,sBANyB;AAOzBC,EAAAA,cAAc,EAAdA,sBAPyB;AAQzBC,EAAAA,gBAAgB,EAAhBA,wBARyB;AASzB,KAAGC,MATsB;AAUzB,KAAGC;AAVsB,CAApB","sourcesContent":["import * as pbkdf2 from './pbkdf2';\nimport * as random from './random';\nimport {\n createCipher,\n createCipheriv,\n createDecipher,\n createDecipheriv,\n} from './Cipher';\nimport { createHmac } from './Hmac';\nimport { createHash } from './Hash';\n\nexport const QuickCrypto = {\n createHmac,\n Hmac: createHmac,\n Hash: createHash,\n createHash,\n createCipher,\n createCipheriv,\n createDecipher,\n createDecipheriv,\n ...pbkdf2,\n ...random,\n};\n"]}
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ab2str = ab2str;
7
+ exports.binaryLikeToArrayBuffer = binaryLikeToArrayBuffer;
8
+ exports.getDefaultEncoding = getDefaultEncoding;
9
+ exports.isBuffer = isBuffer;
10
+ exports.setDefaultEncoding = setDefaultEncoding;
11
+ exports.toArrayBuffer = toArrayBuffer;
12
+
13
+ var _reactNativeBuffer = require("@craftzdog/react-native-buffer");
14
+
15
+ // Mimics node behavior for default global encoding
16
+ let defaultEncoding = 'buffer';
17
+
18
+ function setDefaultEncoding(encoding) {
19
+ defaultEncoding = encoding;
20
+ }
21
+
22
+ function getDefaultEncoding() {
23
+ return defaultEncoding;
24
+ } // function slowCases(enc: string) {
25
+ // switch (enc.length) {
26
+ // case 4:
27
+ // if (enc === 'UTF8') return 'utf8';
28
+ // if (enc === 'ucs2' || enc === 'UCS2') return 'utf16le';
29
+ // enc = `${enc}`.toLowerCase();
30
+ // if (enc === 'utf8') return 'utf8';
31
+ // if (enc === 'ucs2') return 'utf16le';
32
+ // break;
33
+ // case 3:
34
+ // if (enc === 'hex' || enc === 'HEX' || `${enc}`.toLowerCase() === 'hex')
35
+ // return 'hex';
36
+ // break;
37
+ // case 5:
38
+ // if (enc === 'ascii') return 'ascii';
39
+ // if (enc === 'ucs-2') return 'utf16le';
40
+ // if (enc === 'UTF-8') return 'utf8';
41
+ // if (enc === 'ASCII') return 'ascii';
42
+ // if (enc === 'UCS-2') return 'utf16le';
43
+ // enc = `${enc}`.toLowerCase();
44
+ // if (enc === 'utf-8') return 'utf8';
45
+ // if (enc === 'ascii') return 'ascii';
46
+ // if (enc === 'ucs-2') return 'utf16le';
47
+ // break;
48
+ // case 6:
49
+ // if (enc === 'base64') return 'base64';
50
+ // if (enc === 'latin1' || enc === 'binary') return 'latin1';
51
+ // if (enc === 'BASE64') return 'base64';
52
+ // if (enc === 'LATIN1' || enc === 'BINARY') return 'latin1';
53
+ // enc = `${enc}`.toLowerCase();
54
+ // if (enc === 'base64') return 'base64';
55
+ // if (enc === 'latin1' || enc === 'binary') return 'latin1';
56
+ // break;
57
+ // case 7:
58
+ // if (
59
+ // enc === 'utf16le' ||
60
+ // enc === 'UTF16LE' ||
61
+ // `${enc}`.toLowerCase() === 'utf16le'
62
+ // )
63
+ // return 'utf16le';
64
+ // break;
65
+ // case 8:
66
+ // if (
67
+ // enc === 'utf-16le' ||
68
+ // enc === 'UTF-16LE' ||
69
+ // `${enc}`.toLowerCase() === 'utf-16le'
70
+ // )
71
+ // return 'utf16le';
72
+ // break;
73
+ // case 9:
74
+ // if (
75
+ // enc === 'base64url' ||
76
+ // enc === 'BASE64URL' ||
77
+ // `${enc}`.toLowerCase() === 'base64url'
78
+ // )
79
+ // return 'base64url';
80
+ // break;
81
+ // default:
82
+ // if (enc === '') return 'utf8';
83
+ // }
84
+ // }
85
+ // // Return undefined if there is no match.
86
+ // // Move the "slow cases" to a separate function to make sure this function gets
87
+ // // inlined properly. That prioritizes the common case.
88
+ // export function normalizeEncoding(enc?: string) {
89
+ // if (enc == null || enc === 'utf8' || enc === 'utf-8') return 'utf8';
90
+ // return slowCases(enc);
91
+ // }
92
+
93
+
94
+ function isBuffer(buf) {
95
+ var _buf$constructor;
96
+
97
+ return buf instanceof _reactNativeBuffer.Buffer || (buf === null || buf === void 0 ? void 0 : (_buf$constructor = buf.constructor) === null || _buf$constructor === void 0 ? void 0 : _buf$constructor.name) === 'Buffer';
98
+ }
99
+
100
+ function toArrayBuffer(buf) {
101
+ var _buf$buffer;
102
+
103
+ if (buf !== null && buf !== void 0 && (_buf$buffer = buf.buffer) !== null && _buf$buffer !== void 0 && _buf$buffer.slice) {
104
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
105
+ }
106
+
107
+ const ab = new ArrayBuffer(buf.length);
108
+ const view = new Uint8Array(ab);
109
+
110
+ for (let i = 0; i < buf.length; ++i) {
111
+ view[i] = buf[i];
112
+ }
113
+
114
+ return ab;
115
+ }
116
+
117
+ function binaryLikeToArrayBuffer(input) {
118
+ let encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf-8';
119
+
120
+ if (typeof input === 'string') {
121
+ const buffer = _reactNativeBuffer.Buffer.from(input, encoding);
122
+
123
+ return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
124
+ }
125
+
126
+ if (isBuffer(input)) {
127
+ return toArrayBuffer(input);
128
+ } // TODO add further binary types to BinaryLike, UInt8Array and so for have this array as property
129
+
130
+
131
+ if (input.buffer) {
132
+ return input.buffer;
133
+ }
134
+
135
+ if (!(input instanceof ArrayBuffer)) {
136
+ try {
137
+ const buffer = _reactNativeBuffer.Buffer.from(input);
138
+
139
+ return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
140
+ } catch {
141
+ throw 'error';
142
+ }
143
+ }
144
+
145
+ return input;
146
+ }
147
+
148
+ function ab2str(buf) {
149
+ let encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'hex';
150
+ return _reactNativeBuffer.Buffer.from(buf).toString(encoding);
151
+ }
152
+ //# sourceMappingURL=Utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["Utils.ts"],"names":["defaultEncoding","setDefaultEncoding","encoding","getDefaultEncoding","isBuffer","buf","Buffer","constructor","name","toArrayBuffer","buffer","slice","byteOffset","byteLength","ab","ArrayBuffer","length","view","Uint8Array","i","binaryLikeToArrayBuffer","input","from","ab2str","toString"],"mappings":";;;;;;;;;;;;AAAA;;AAeA;AACA,IAAIA,eAA+B,GAAG,QAAtC;;AAEO,SAASC,kBAAT,CAA4BC,QAA5B,EAAsD;AAC3DF,EAAAA,eAAe,GAAGE,QAAlB;AACD;;AAEM,SAASC,kBAAT,GAA8C;AACnD,SAAOH,eAAP;AACD,C,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAEO,SAASI,QAAT,CAAkBC,GAAlB,EAA2C;AAAA;;AAChD,SAAOA,GAAG,YAAYC,yBAAf,IAAyB,CAAAD,GAAG,SAAH,IAAAA,GAAG,WAAH,gCAAAA,GAAG,CAAEE,WAAL,sEAAkBC,IAAlB,MAA2B,QAA3D;AACD;;AAEM,SAASC,aAAT,CAAuBJ,GAAvB,EAAiD;AAAA;;AACtD,MAAIA,GAA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Ad,CACLD,MAAM,CAACE,UADF,EAELF,MAAM,CAACE,UAAP,GAAoBF,MAAM,CAACG,UAFtB,CAAP;AAID,KAND,CAME,MAAM;AACN,YAAM,OAAN;AACD;AACF;;AACD,SAAOQ,KAAP;AACD;;AAEM,SAASE,MAAT,CAAgBlB,GAAhB,EAA4D;AAAA,MAA1BH,QAA0B,uEAAP,KAAO;AACjE,SAAOI,0BAAOgB,IAAP,CAAYjB,GAAZ,EAAiBmB,QAAjB,CAA0BtB,QAA1B,CAAP;AACD","sourcesContent":["import { Buffer } from '@craftzdog/react-native-buffer';\n\nexport type BinaryLike = string | ArrayBuffer | Buffer;\n\nexport type BinaryToTextEncoding = 'base64' | 'base64url' | 'hex' | 'binary';\nexport type CharacterEncoding = 'utf8' | 'utf-8' | 'utf16le' | 'latin1';\nexport type LegacyCharacterEncoding = 'ascii' | 'binary' | 'ucs2' | 'ucs-2';\nexport type Encoding =\n | BinaryToTextEncoding\n | CharacterEncoding\n | LegacyCharacterEncoding;\n\n// TODO(osp) should buffer be part of the Encoding type?\nexport type CipherEncoding = Encoding | 'buffer';\n\n// Mimics node behavior for default global encoding\nlet defaultEncoding: CipherEncoding = 'buffer';\n\nexport function setDefaultEncoding(encoding: CipherEncoding) {\n defaultEncoding = encoding;\n}\n\nexport function getDefaultEncoding(): CipherEncoding {\n return defaultEncoding;\n}\n\n// function slowCases(enc: string) {\n// switch (enc.length) {\n// case 4:\n// if (enc === 'UTF8') return 'utf8';\n// if (enc === 'ucs2' || enc === 'UCS2') return 'utf16le';\n// enc = `${enc}`.toLowerCase();\n// if (enc === 'utf8') return 'utf8';\n// if (enc === 'ucs2') return 'utf16le';\n// break;\n// case 3:\n// if (enc === 'hex' || enc === 'HEX' || `${enc}`.toLowerCase() === 'hex')\n// return 'hex';\n// break;\n// case 5:\n// if (enc === 'ascii') return 'ascii';\n// if (enc === 'ucs-2') return 'utf16le';\n// if (enc === 'UTF-8') return 'utf8';\n// if (enc === 'ASCII') return 'ascii';\n// if (enc === 'UCS-2') return 'utf16le';\n// enc = `${enc}`.toLowerCase();\n// if (enc === 'utf-8') return 'utf8';\n// if (enc === 'ascii') return 'ascii';\n// if (enc === 'ucs-2') return 'utf16le';\n// break;\n// case 6:\n// if (enc === 'base64') return 'base64';\n// if (enc === 'latin1' || enc === 'binary') return 'latin1';\n// if (enc === 'BASE64') return 'base64';\n// if (enc === 'LATIN1' || enc === 'BINARY') return 'latin1';\n// enc = `${enc}`.toLowerCase();\n// if (enc === 'base64') return 'base64';\n// if (enc === 'latin1' || enc === 'binary') return 'latin1';\n// break;\n// case 7:\n// if (\n// enc === 'utf16le' ||\n// enc === 'UTF16LE' ||\n// `${enc}`.toLowerCase() === 'utf16le'\n// )\n// return 'utf16le';\n// break;\n// case 8:\n// if (\n// enc === 'utf-16le' ||\n// enc === 'UTF-16LE' ||\n// `${enc}`.toLowerCase() === 'utf-16le'\n// )\n// return 'utf16le';\n// break;\n// case 9:\n// if (\n// enc === 'base64url' ||\n// enc === 'BASE64URL' ||\n// `${enc}`.toLowerCase() === 'base64url'\n// )\n// return 'base64url';\n// break;\n// default:\n// if (enc === '') return 'utf8';\n// }\n// }\n\n// // Return undefined if there is no match.\n// // Move the \"slow cases\" to a separate function to make sure this function gets\n// // inlined properly. That prioritizes the common case.\n// export function normalizeEncoding(enc?: string) {\n// if (enc == null || enc === 'utf8' || enc === 'utf-8') return 'utf8';\n// return slowCases(enc);\n// }\n\nexport function isBuffer(buf: any): buf is Buffer {\n return buf instanceof Buffer || buf?.constructor?.name === 'Buffer';\n}\n\nexport function toArrayBuffer(buf: Buffer): ArrayBuffer {\n if (buf?.buffer?.slice) {\n return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);\n }\n const ab = new ArrayBuffer(buf.length);\n const view = new Uint8Array(ab);\n for (let i = 0; i < buf.length; ++i) {\n view[i] = buf[i];\n }\n return ab;\n}\n\nexport function binaryLikeToArrayBuffer(\n input: BinaryLike,\n encoding: string = 'utf-8'\n): ArrayBuffer {\n if (typeof input === 'string') {\n const buffer = Buffer.from(input, encoding);\n\n return buffer.buffer.slice(\n buffer.byteOffset,\n buffer.byteOffset + buffer.byteLength\n );\n }\n\n if (isBuffer(input)) {\n return toArrayBuffer(input);\n }\n\n // TODO add further binary types to BinaryLike, UInt8Array and so for have this array as property\n if ((input as any).buffer) {\n return (input as any).buffer;\n }\n\n if (!(input instanceof ArrayBuffer)) {\n try {\n const buffer = Buffer.from(input);\n return buffer.buffer.slice(\n buffer.byteOffset,\n buffer.byteOffset + buffer.byteLength\n );\n } catch {\n throw 'error';\n }\n }\n return input;\n}\n\nexport function ab2str(buf: ArrayBuffer, encoding: string = 'hex') {\n return Buffer.from(buf).toString(encoding);\n}\n"]}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _QuickCrypto = require("./QuickCrypto");
8
+
9
+ Object.keys(_QuickCrypto).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _QuickCrypto[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _QuickCrypto[key];
16
+ }
17
+ });
18
+ });
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './QuickCrypto';\n"]}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.pbkdf2 = pbkdf2;
7
+ exports.pbkdf2Sync = pbkdf2Sync;
8
+
9
+ var _NativeQuickCrypto = require("./NativeQuickCrypto/NativeQuickCrypto");
10
+
11
+ var _reactNativeBuffer = require("@craftzdog/react-native-buffer");
12
+
13
+ var _Utils = require("./Utils");
14
+
15
+ const WRONG_PASS = 'Password must be a string, a Buffer, a typed array or a DataView';
16
+ const WRON_SALT = `Salt must be a string, a Buffer, a typed array or a DataView`;
17
+
18
+ function sanitizeInput(input, errorMsg) {
19
+ try {
20
+ return (0, _Utils.binaryLikeToArrayBuffer)(input);
21
+ } catch (e) {
22
+ throw errorMsg;
23
+ }
24
+ }
25
+
26
+ const nativePbkdf2 = _NativeQuickCrypto.NativeQuickCrypto.pbkdf2;
27
+
28
+ function pbkdf2(password, salt, iterations, keylen, arg0, arg1) {
29
+ let digest = 'sha1';
30
+ let callback;
31
+
32
+ if (typeof arg0 === 'string') {
33
+ digest = arg0;
34
+
35
+ if (typeof arg1 === 'function') {
36
+ callback = arg1;
37
+ }
38
+ } else {
39
+ if (typeof arg0 === 'function') {
40
+ callback = arg0;
41
+ }
42
+ }
43
+
44
+ if (callback === undefined) {
45
+ throw new Error('No callback provided to pbkdf2');
46
+ }
47
+
48
+ const sanitizedPassword = sanitizeInput(password, WRONG_PASS);
49
+ const sanitizedSalt = sanitizeInput(salt, WRON_SALT);
50
+ nativePbkdf2.pbkdf2(sanitizedPassword, sanitizedSalt, iterations, keylen, digest).then(res => {
51
+ callback(null, _reactNativeBuffer.Buffer.from(res));
52
+ }, e => {
53
+ callback(e);
54
+ });
55
+ }
56
+
57
+ function pbkdf2Sync(password, salt, iterations, keylen, digest) {
58
+ const sanitizedPassword = sanitizeInput(password, WRONG_PASS);
59
+ const sanitizedSalt = sanitizeInput(salt, WRON_SALT);
60
+ const algo = digest ? digest : 'sha1';
61
+ let result = nativePbkdf2.pbkdf2Sync(sanitizedPassword, sanitizedSalt, iterations, keylen, algo);
62
+ return _reactNativeBuffer.Buffer.from(result);
63
+ }
64
+ //# sourceMappingURL=pbkdf2.js.map