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.
- package/LICENSE +21 -0
- package/README.md +84 -0
- package/android/.DS_Store +0 -0
- package/android/CMakeLists.txt +117 -0
- package/android/build.gradle +367 -0
- package/android/gradle/.DS_Store +0 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +6 -0
- package/android/gradlew +183 -0
- package/android/gradlew.bat +100 -0
- package/android/src/.DS_Store +0 -0
- package/android/src/main/.DS_Store +0 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/cpp/cpp-adapter.cpp +60 -0
- package/android/src/main/java/.DS_Store +0 -0
- package/android/src/main/java/com/.DS_Store +0 -0
- package/android/src/main/java/com/reactnativequickcrypto/QuickCryptoModule.java +70 -0
- package/android/src/main/java/com/reactnativequickcrypto/QuickCryptoPackage.java +26 -0
- package/cpp/.DS_Store +0 -0
- package/cpp/Cipher/MGLCipherHostObject.cpp +632 -0
- package/cpp/Cipher/MGLCipherHostObject.h +90 -0
- package/cpp/Cipher/MGLCreateCipherInstaller.cpp +74 -0
- package/cpp/Cipher/MGLCreateCipherInstaller.h +17 -0
- package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +74 -0
- package/cpp/Cipher/MGLCreateDecipherInstaller.h +17 -0
- package/cpp/HMAC/MGLHmacHostObject.cpp +95 -0
- package/cpp/HMAC/MGLHmacHostObject.h +39 -0
- package/cpp/HMAC/MGLHmacInstaller.cpp +43 -0
- package/cpp/HMAC/MGLHmacInstaller.h +20 -0
- package/cpp/Hash/MGLHashHostObject.cpp +147 -0
- package/cpp/Hash/MGLHashHostObject.h +53 -0
- package/cpp/Hash/MGLHashInstaller.cpp +46 -0
- package/cpp/Hash/MGLHashInstaller.h +20 -0
- package/cpp/JSIUtils/MGLJSIMacros.h +37 -0
- package/cpp/JSIUtils/MGLSmartHostObject.cpp +43 -0
- package/cpp/JSIUtils/MGLSmartHostObject.h +46 -0
- package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +24 -0
- package/cpp/JSIUtils/MGLThreadAwareHostObject.h +43 -0
- package/cpp/JSIUtils/MGLTypedArray.cpp +325 -0
- package/cpp/JSIUtils/MGLTypedArray.h +160 -0
- package/cpp/MGLQuickCryptoHostObject.cpp +64 -0
- package/cpp/MGLQuickCryptoHostObject.h +30 -0
- package/cpp/Random/MGLRandomHostObject.cpp +89 -0
- package/cpp/Random/MGLRandomHostObject.h +27 -0
- package/cpp/Utils/MGLDispatchQueue.cpp +75 -0
- package/cpp/Utils/MGLDispatchQueue.h +55 -0
- package/cpp/Utils/logs.h +38 -0
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +164 -0
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +29 -0
- package/cpp/fastpbkdf2/fastpbkdf2.c +352 -0
- package/cpp/fastpbkdf2/fastpbkdf2.h +68 -0
- package/ios/.DS_Store +0 -0
- package/ios/QuickCrypto.xcodeproj/project.pbxproj +274 -0
- package/ios/QuickCryptoModule.h +5 -0
- package/ios/QuickCryptoModule.mm +42 -0
- package/lib/.DS_Store +0 -0
- package/lib/commonjs/Cipher.js +293 -0
- package/lib/commonjs/Cipher.js.map +1 -0
- package/lib/commonjs/Hash.js +102 -0
- package/lib/commonjs/Hash.js.map +1 -0
- package/lib/commonjs/Hmac.js +104 -0
- package/lib/commonjs/Hmac.js.map +1 -0
- package/lib/commonjs/NativeQuickCrypto/Cipher.js +6 -0
- package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +1 -0
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +61 -0
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -0
- package/lib/commonjs/NativeQuickCrypto/hash.js +2 -0
- package/lib/commonjs/NativeQuickCrypto/hash.js.map +1 -0
- package/lib/commonjs/NativeQuickCrypto/hmac.js +2 -0
- package/lib/commonjs/NativeQuickCrypto/hmac.js.map +1 -0
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +2 -0
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +1 -0
- package/lib/commonjs/NativeQuickCrypto/random.js +2 -0
- package/lib/commonjs/NativeQuickCrypto/random.js.map +1 -0
- package/lib/commonjs/QuickCrypto.js +35 -0
- package/lib/commonjs/QuickCrypto.js.map +1 -0
- package/lib/commonjs/Utils.js +152 -0
- package/lib/commonjs/Utils.js.map +1 -0
- package/lib/commonjs/index.js +19 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/pbkdf2.js +64 -0
- package/lib/commonjs/pbkdf2.js.map +1 -0
- package/lib/commonjs/random.js +213 -0
- package/lib/commonjs/random.js.map +1 -0
- package/lib/module/Cipher.js +287 -0
- package/lib/module/Cipher.js.map +1 -0
- package/lib/module/Hash.js +87 -0
- package/lib/module/Hash.js.map +1 -0
- package/lib/module/Hmac.js +90 -0
- package/lib/module/Hmac.js.map +1 -0
- package/lib/module/NativeQuickCrypto/Cipher.js +2 -0
- package/lib/module/NativeQuickCrypto/Cipher.js.map +1 -0
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +53 -0
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -0
- package/lib/module/NativeQuickCrypto/hash.js +2 -0
- package/lib/module/NativeQuickCrypto/hash.js.map +1 -0
- package/lib/module/NativeQuickCrypto/hmac.js +2 -0
- package/lib/module/NativeQuickCrypto/hmac.js.map +1 -0
- package/lib/module/NativeQuickCrypto/pbkdf2.js +2 -0
- package/lib/module/NativeQuickCrypto/pbkdf2.js.map +1 -0
- package/lib/module/NativeQuickCrypto/random.js +2 -0
- package/lib/module/NativeQuickCrypto/random.js.map +1 -0
- package/lib/module/QuickCrypto.js +18 -0
- package/lib/module/QuickCrypto.js.map +1 -0
- package/lib/module/Utils.js +131 -0
- package/lib/module/Utils.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/pbkdf2.js +51 -0
- package/lib/module/pbkdf2.js.map +1 -0
- package/lib/module/random.js +190 -0
- package/lib/module/random.js.map +1 -0
- package/lib/typescript/Cipher.d.ts +30 -0
- package/lib/typescript/Hash.d.ts +44 -0
- package/lib/typescript/Hmac.d.ts +37 -0
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +22 -0
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +19 -0
- package/lib/typescript/NativeQuickCrypto/hash.d.ts +6 -0
- package/lib/typescript/NativeQuickCrypto/hmac.d.ts +5 -0
- package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts +4 -0
- package/lib/typescript/NativeQuickCrypto/random.d.ts +4 -0
- package/lib/typescript/QuickCrypto.d.ts +31 -0
- package/lib/typescript/Utils.d.ts +13 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/pbkdf2.d.ts +9 -0
- package/lib/typescript/random.d.ts +20 -0
- package/package.json +168 -0
- package/react-native-quick-crypto.podspec +44 -0
- package/src/Cipher.ts +322 -0
- package/src/Hash.ts +98 -0
- package/src/Hmac.ts +107 -0
- package/src/NativeQuickCrypto/Cipher.ts +25 -0
- package/src/NativeQuickCrypto/NativeQuickCrypto.ts +79 -0
- package/src/NativeQuickCrypto/hash.ts +10 -0
- package/src/NativeQuickCrypto/hmac.ts +9 -0
- package/src/NativeQuickCrypto/pbkdf2.ts +16 -0
- package/src/NativeQuickCrypto/random.ts +12 -0
- package/src/QuickCrypto.ts +23 -0
- package/src/Utils.ts +151 -0
- package/src/index.ts +1 -0
- package/src/pbkdf2.ts +96 -0
- package/src/random.ts +277 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["Hash.ts"],"names":["NativeQuickCrypto","toArrayBuffer","Stream","Buffer","global","process","nextTick","setImmediate","createInternalHash","createHash","algorithm","options","Hash","Transform","constructor","arg","undefined","internalHash","copy","outputLength","update","data","inputEncoding","ArrayBuffer","buffer","from","_transform","chunk","encoding","callback","_flush","push","digest","result","toString"],"mappings":";;AAAA;AACA,OAAO,cAAP;AACA,SAASA,iBAAT,QAAkC,uCAAlC;AAEA,SAAmBC,aAAnB,QAAwC,SAAxC;AACA,OAAOC,MAAP,MAAmB,QAAnB;AACA,SAASC,MAAT,QAAuB,gCAAvB;AAOAC,MAAM,CAACC,OAAP,CAAeC,QAAf,GAA0BC,YAA1B;AAEA,MAAMC,kBAAkB,GAAGR,iBAAiB,CAACS,UAA7C;AAIA,OAAO,SAASA,UAAT,CAAoBC,SAApB,EAAuCC,OAAvC,EAA8D;AACnE,SAAO,IAAIC,IAAJ,CAASF,SAAT,EAAoBC,OAApB,CAAP;AACD;;AAED,MAAMC,IAAN,SAAmBV,MAAM,CAACW,SAA1B,CAAoC;AAKlCC,EAAAA,WAAW,CAACC,GAAD,EAAqBJ,OAArB,EAA4C;AACrD,UAAMA,OAAN,aAAMA,OAAN,cAAMA,OAAN,GAAiBK,SAAjB;;AADqD;;AAErD,QAAID,GAAG,YAAYH,IAAnB,EAAyB;AACvB,WAAKK,YAAL,GAAoBF,GAAG,CAACE,YAAJ,CAAiBC,IAAjB,CAAsBP,OAAtB,aAAsBA,OAAtB,uBAAsBA,OAAO,CAAEQ,YAA/B,CAApB;AACD,KAFD,MAEO;AACL,WAAKF,YAAL,GAAoBT,kBAAkB,CAACO,GAAD,EAAMJ,OAAN,aAAMA,OAAN,uBAAMA,OAAO,CAAEQ,YAAf,CAAtC;AACD;AACF;;AAEDD,EAAAA,IAAI,CAACP,OAAD,EAAkC;AACpC,UAAMO,IAAI,GAAG,IAAIN,IAAJ,CAAS,IAAT,EAAeD,OAAf,CAAb;AACA,WAAOO,IAAP;AACD;AACD;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACEE,EAAAA,MAAM,CAACC,IAAD,EAA4BC,aAA5B,EAA4D;AAChE,QAAID,IAAI,YAAYE,WAApB,EAAiC;AAC/B,WAAKN,YAAL,CAAkBG,MAAlB,CAAyBC,IAAzB;AACA,aAAO,IAAP;AACD;;AACD,UAAMG,MAAM,GAAGrB,MAAM,CAACsB,IAAP,CAAYJ,IAAZ,EAAkBC,aAAlB,CAAf;AACA,SAAKL,YAAL,CAAkBG,MAAlB,CAAyBnB,aAAa,CAACuB,MAAD,CAAtC;AACA,WAAO,IAAP;AACD;;AAEDE,EAAAA,UAAU,CACRC,KADQ,EAERC,QAFQ,EAGRC,QAHQ,EAIR;AACA,SAAKT,MAAL,CAAYO,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,KAAKhB,YAAL,CAAkBe,MAAlB,EAA5B;;AAEA,QAAIJ,QAAQ,IAAIA,QAAQ,KAAK,QAA7B,EAAuC;AACrC,aAAOzB,MAAM,CAACsB,IAAP,CAAYQ,MAAZ,EAAoBC,QAApB,CAA6BN,QAA7B,CAAP;AACD;;AAED,WAAOzB,MAAM,CAACsB,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,90 @@
|
|
|
1
|
+
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; }
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-dupe-class-members */
|
|
4
|
+
import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
|
|
5
|
+
import { toArrayBuffer, binaryLikeToArrayBuffer } from './Utils';
|
|
6
|
+
import Stream from 'stream';
|
|
7
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
8
|
+
const createInternalHmac = NativeQuickCrypto.createHmac;
|
|
9
|
+
export function createHmac(algorithm, key, options) {
|
|
10
|
+
return new Hmac(algorithm, key, options);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class Hmac extends Stream.Transform {
|
|
14
|
+
constructor(algorithm, key, _options) {
|
|
15
|
+
super();
|
|
16
|
+
|
|
17
|
+
_defineProperty(this, "internalHmac", void 0);
|
|
18
|
+
|
|
19
|
+
_defineProperty(this, "isFinalized", false);
|
|
20
|
+
|
|
21
|
+
let keyAsString = binaryLikeToArrayBuffer(key);
|
|
22
|
+
|
|
23
|
+
if (keyAsString === undefined) {
|
|
24
|
+
throw 'Wrong key type';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
this.internalHmac = createInternalHmac(algorithm, keyAsString);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Updates the `Hmac` content with the given `data`, the encoding of which
|
|
31
|
+
* is given in `inputEncoding`.
|
|
32
|
+
* If `encoding` is not provided, and the `data` is a string, an
|
|
33
|
+
* encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
|
|
34
|
+
*
|
|
35
|
+
* This can be called many times with new data as it is streamed.
|
|
36
|
+
* @since v0.1.94
|
|
37
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
update(data, inputEncoding) {
|
|
42
|
+
if (data instanceof ArrayBuffer) {
|
|
43
|
+
this.internalHmac.update(data);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (typeof data === 'string') {
|
|
48
|
+
const buffer = Buffer.from(data, inputEncoding);
|
|
49
|
+
this.internalHmac.update(toArrayBuffer(buffer));
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
this.internalHmac.update(binaryLikeToArrayBuffer(data));
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
_transform(chunk, encoding, callback) {
|
|
58
|
+
this.update(chunk, encoding);
|
|
59
|
+
callback();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
_flush(callback) {
|
|
63
|
+
this.push(this.digest());
|
|
64
|
+
callback();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Calculates the HMAC digest of all of the data passed using `hmac.update()`.
|
|
68
|
+
* If `encoding` is
|
|
69
|
+
* provided a string is returned; otherwise a `Buffer` is returned;
|
|
70
|
+
*
|
|
71
|
+
* The `Hmac` object can not be used again after `hmac.digest()` has been
|
|
72
|
+
* called. Multiple calls to `hmac.digest()` will result in an error being thrown.
|
|
73
|
+
* @since v0.1.94
|
|
74
|
+
* @param encoding The `encoding` of the return value.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
digest(encoding) {
|
|
79
|
+
const result = this.isFinalized ? new ArrayBuffer(0) : this.internalHmac.digest();
|
|
80
|
+
this.isFinalized = true;
|
|
81
|
+
|
|
82
|
+
if (encoding && encoding !== 'buffer') {
|
|
83
|
+
return Buffer.from(result).toString(encoding);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return Buffer.from(result);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=Hmac.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["Hmac.ts"],"names":["NativeQuickCrypto","toArrayBuffer","binaryLikeToArrayBuffer","Stream","Buffer","createInternalHmac","createHmac","algorithm","key","options","Hmac","Transform","constructor","_options","keyAsString","undefined","internalHmac","update","data","inputEncoding","ArrayBuffer","buffer","from","_transform","chunk","encoding","callback","_flush","push","digest","result","isFinalized","toString"],"mappings":";;AAAA;AACA,SAASA,iBAAT,QAAkC,uCAAlC;AAEA,SAEEC,aAFF,EAIEC,uBAJF,QAKO,SALP;AAMA,OAAOC,MAAP,MAAmB,QAAnB;AACA,SAASC,MAAT,QAAuB,gCAAvB;AAEA,MAAMC,kBAAkB,GAAGL,iBAAiB,CAACM,UAA7C;AAEA,OAAO,SAASA,UAAT,CACLC,SADK,EAELC,GAFK,EAGLC,OAHK,EAIL;AACA,SAAO,IAAIC,IAAJ,CAASH,SAAT,EAAoBC,GAApB,EAAyBC,OAAzB,CAAP;AACD;;AAED,MAAMC,IAAN,SAAmBP,MAAM,CAACQ,SAA1B,CAAoC;AAIlCC,EAAAA,WAAW,CACTL,SADS,EAETC,GAFS,EAGTK,QAHS,EAIT;AACA;;AADA;;AAAA,yCAN6B,KAM7B;;AAEA,QAAIC,WAAW,GAAGZ,uBAAuB,CAACM,GAAD,CAAzC;;AAEA,QAAIM,WAAW,KAAKC,SAApB,EAA+B;AAC7B,YAAM,gBAAN;AACD;;AAED,SAAKC,YAAL,GAAoBX,kBAAkB,CACpCE,SADoC,EAEpCO,WAFoC,CAAtC;AAID;AAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACEG,EAAAA,MAAM,CAACC,IAAD,EAA4BC,aAA5B,EAA4D;AAChE,QAAID,IAAI,YAAYE,WAApB,EAAiC;AAC/B,WAAKJ,YAAL,CAAkBC,MAAlB,CAAyBC,IAAzB;AACA,aAAO,IAAP;AACD;;AACD,QAAI,OAAOA,IAAP,KAAgB,QAApB,EAA8B;AAC5B,YAAMG,MAAM,GAAGjB,MAAM,CAACkB,IAAP,CAAYJ,IAAZ,EAAkBC,aAAlB,CAAf;AACA,WAAKH,YAAL,CAAkBC,MAAlB,CAAyBhB,aAAa,CAACoB,MAAD,CAAtC;AACA,aAAO,IAAP;AACD;;AAED,SAAKL,YAAL,CAAkBC,MAAlB,CAAyBf,uBAAuB,CAACgB,IAAD,CAAhD;AACA,WAAO,IAAP;AACD;;AAEDK,EAAAA,UAAU,CACRC,KADQ,EAERC,QAFQ,EAGRC,QAHQ,EAIR;AACA,SAAKT,MAAL,CAAYO,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,KAAKC,WAAL,GACxB,IAAIX,WAAJ,CAAgB,CAAhB,CADwB,GAExB,KAAKJ,YAAL,CAAkBa,MAAlB,EAFJ;AAGA,SAAKE,WAAL,GAAmB,IAAnB;;AACA,QAAIN,QAAQ,IAAIA,QAAQ,KAAK,QAA7B,EAAuC;AACrC,aAAOrB,MAAM,CAACkB,IAAP,CAAYQ,MAAZ,EAAoBE,QAApB,CAA6BP,QAA7B,CAAP;AACD;;AACD,WAAOrB,MAAM,CAACkB,IAAP,CAAYQ,MAAZ,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 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
// Check if the constructor exists. If not, try installing the JSI bindings.
|
|
4
|
+
if (global.__QuickCryptoProxy == null) {
|
|
5
|
+
// Get the native QuickCrypto ReactModule
|
|
6
|
+
const QuickCryptoModule = NativeModules.QuickCrypto;
|
|
7
|
+
|
|
8
|
+
if (QuickCryptoModule == null) {
|
|
9
|
+
var _NativeModules$Native, _NativeModules$Native2;
|
|
10
|
+
|
|
11
|
+
let message = 'Failed to install react-native-quick-crypto: The native `QuickCrypto` Module could not be found.';
|
|
12
|
+
message += '\n* Make sure react-native-quick-crypto is correctly autolinked (run `npx react-native config` to verify)';
|
|
13
|
+
|
|
14
|
+
if (Platform.OS === 'ios' || Platform.OS === 'macos') {
|
|
15
|
+
message += '\n* Make sure you ran `pod install` in the ios/ directory.';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (Platform.OS === 'android') {
|
|
19
|
+
message += '\n* Make sure gradle is synced.';
|
|
20
|
+
} // check if Expo
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const ExpoConstants = (_NativeModules$Native = NativeModules.NativeUnimoduleProxy) === null || _NativeModules$Native === void 0 ? void 0 : (_NativeModules$Native2 = _NativeModules$Native.modulesConstants) === null || _NativeModules$Native2 === void 0 ? void 0 : _NativeModules$Native2.ExponentConstants;
|
|
24
|
+
|
|
25
|
+
if (ExpoConstants != null) {
|
|
26
|
+
if (ExpoConstants.appOwnership === 'expo') {
|
|
27
|
+
// We're running Expo Go
|
|
28
|
+
throw new Error('react-native-quick-crypto is not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.');
|
|
29
|
+
} else {
|
|
30
|
+
// We're running Expo bare / standalone
|
|
31
|
+
message += '\n* Make sure you ran `expo prebuild`.';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
message += '\n* Make sure you rebuilt the app.';
|
|
36
|
+
throw new Error(message);
|
|
37
|
+
} // Check if we are running on-device (JSI)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if (global.nativeCallSyncHook == null || QuickCryptoModule.install == null) {
|
|
41
|
+
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.');
|
|
42
|
+
} // Call the synchronous blocking install() function
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
const result = QuickCryptoModule.install();
|
|
46
|
+
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.
|
|
47
|
+
|
|
48
|
+
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?');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const proxy = global.__QuickCryptoProxy;
|
|
52
|
+
export const NativeQuickCrypto = proxy;
|
|
53
|
+
//# sourceMappingURL=NativeQuickCrypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["NativeQuickCrypto.ts"],"names":["NativeModules","Platform","global","__QuickCryptoProxy","QuickCryptoModule","QuickCrypto","message","OS","ExpoConstants","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","Error","nativeCallSyncHook","install","result","proxy","NativeQuickCrypto"],"mappings":"AAAA,SAASA,aAAT,EA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A,MAAId,MAAM,CAACC,kBAAP,IAA6B,IAAjC,EACE,MAAM,IAAIU,KAAJ,CACJ,4JADI,CAAN;AAGH;;AAED,MAAMI,KAAK,GAAGf,MAAM,CAACC,kBAArB;AACA,OAAO,MAAMe,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 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as pbkdf2 from './pbkdf2';
|
|
2
|
+
import * as random from './random';
|
|
3
|
+
import { createCipher, createCipheriv, createDecipher, createDecipheriv } from './Cipher';
|
|
4
|
+
import { createHmac } from './Hmac';
|
|
5
|
+
import { createHash } from './Hash';
|
|
6
|
+
export const QuickCrypto = {
|
|
7
|
+
createHmac,
|
|
8
|
+
Hmac: createHmac,
|
|
9
|
+
Hash: createHash,
|
|
10
|
+
createHash,
|
|
11
|
+
createCipher,
|
|
12
|
+
createCipheriv,
|
|
13
|
+
createDecipher,
|
|
14
|
+
createDecipheriv,
|
|
15
|
+
...pbkdf2,
|
|
16
|
+
...random
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=QuickCrypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["QuickCrypto.ts"],"names":["pbkdf2","random","createCipher","createCipheriv","createDecipher","createDecipheriv","createHmac","createHash","QuickCrypto","Hmac","Hash"],"mappings":"AAAA,OAAO,KAAKA,MAAZ,MAAwB,UAAxB;AACA,OAAO,KAAKC,MAAZ,MAAwB,UAAxB;AACA,SACEC,YADF,EAEEC,cAFF,EAGEC,cAHF,EAIEC,gBAJF,QAKO,UALP;AAMA,SAASC,UAAT,QAA2B,QAA3B;AACA,SAASC,UAAT,QAA2B,QAA3B;AAEA,OAAO,MAAMC,WAAW,GAAG;AACzBF,EAAAA,UADyB;AAEzBG,EAAAA,IAAI,EAAEH,UAFmB;AAGzBI,EAAAA,IAAI,EAAEH,UAHmB;AAIzBA,EAAAA,UAJyB;AAKzBL,EAAAA,YALyB;AAMzBC,EAAAA,cANyB;AAOzBC,EAAAA,cAPyB;AAQzBC,EAAAA,gBARyB;AASzB,KAAGL,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,131 @@
|
|
|
1
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
2
|
+
// Mimics node behavior for default global encoding
|
|
3
|
+
let defaultEncoding = 'buffer';
|
|
4
|
+
export function setDefaultEncoding(encoding) {
|
|
5
|
+
defaultEncoding = encoding;
|
|
6
|
+
}
|
|
7
|
+
export function getDefaultEncoding() {
|
|
8
|
+
return defaultEncoding;
|
|
9
|
+
} // function slowCases(enc: string) {
|
|
10
|
+
// switch (enc.length) {
|
|
11
|
+
// case 4:
|
|
12
|
+
// if (enc === 'UTF8') return 'utf8';
|
|
13
|
+
// if (enc === 'ucs2' || enc === 'UCS2') return 'utf16le';
|
|
14
|
+
// enc = `${enc}`.toLowerCase();
|
|
15
|
+
// if (enc === 'utf8') return 'utf8';
|
|
16
|
+
// if (enc === 'ucs2') return 'utf16le';
|
|
17
|
+
// break;
|
|
18
|
+
// case 3:
|
|
19
|
+
// if (enc === 'hex' || enc === 'HEX' || `${enc}`.toLowerCase() === 'hex')
|
|
20
|
+
// return 'hex';
|
|
21
|
+
// break;
|
|
22
|
+
// case 5:
|
|
23
|
+
// if (enc === 'ascii') return 'ascii';
|
|
24
|
+
// if (enc === 'ucs-2') return 'utf16le';
|
|
25
|
+
// if (enc === 'UTF-8') return 'utf8';
|
|
26
|
+
// if (enc === 'ASCII') return 'ascii';
|
|
27
|
+
// if (enc === 'UCS-2') return 'utf16le';
|
|
28
|
+
// enc = `${enc}`.toLowerCase();
|
|
29
|
+
// if (enc === 'utf-8') return 'utf8';
|
|
30
|
+
// if (enc === 'ascii') return 'ascii';
|
|
31
|
+
// if (enc === 'ucs-2') return 'utf16le';
|
|
32
|
+
// break;
|
|
33
|
+
// case 6:
|
|
34
|
+
// if (enc === 'base64') return 'base64';
|
|
35
|
+
// if (enc === 'latin1' || enc === 'binary') return 'latin1';
|
|
36
|
+
// if (enc === 'BASE64') return 'base64';
|
|
37
|
+
// if (enc === 'LATIN1' || enc === 'BINARY') return 'latin1';
|
|
38
|
+
// enc = `${enc}`.toLowerCase();
|
|
39
|
+
// if (enc === 'base64') return 'base64';
|
|
40
|
+
// if (enc === 'latin1' || enc === 'binary') return 'latin1';
|
|
41
|
+
// break;
|
|
42
|
+
// case 7:
|
|
43
|
+
// if (
|
|
44
|
+
// enc === 'utf16le' ||
|
|
45
|
+
// enc === 'UTF16LE' ||
|
|
46
|
+
// `${enc}`.toLowerCase() === 'utf16le'
|
|
47
|
+
// )
|
|
48
|
+
// return 'utf16le';
|
|
49
|
+
// break;
|
|
50
|
+
// case 8:
|
|
51
|
+
// if (
|
|
52
|
+
// enc === 'utf-16le' ||
|
|
53
|
+
// enc === 'UTF-16LE' ||
|
|
54
|
+
// `${enc}`.toLowerCase() === 'utf-16le'
|
|
55
|
+
// )
|
|
56
|
+
// return 'utf16le';
|
|
57
|
+
// break;
|
|
58
|
+
// case 9:
|
|
59
|
+
// if (
|
|
60
|
+
// enc === 'base64url' ||
|
|
61
|
+
// enc === 'BASE64URL' ||
|
|
62
|
+
// `${enc}`.toLowerCase() === 'base64url'
|
|
63
|
+
// )
|
|
64
|
+
// return 'base64url';
|
|
65
|
+
// break;
|
|
66
|
+
// default:
|
|
67
|
+
// if (enc === '') return 'utf8';
|
|
68
|
+
// }
|
|
69
|
+
// }
|
|
70
|
+
// // Return undefined if there is no match.
|
|
71
|
+
// // Move the "slow cases" to a separate function to make sure this function gets
|
|
72
|
+
// // inlined properly. That prioritizes the common case.
|
|
73
|
+
// export function normalizeEncoding(enc?: string) {
|
|
74
|
+
// if (enc == null || enc === 'utf8' || enc === 'utf-8') return 'utf8';
|
|
75
|
+
// return slowCases(enc);
|
|
76
|
+
// }
|
|
77
|
+
|
|
78
|
+
export function isBuffer(buf) {
|
|
79
|
+
var _buf$constructor;
|
|
80
|
+
|
|
81
|
+
return buf instanceof Buffer || (buf === null || buf === void 0 ? void 0 : (_buf$constructor = buf.constructor) === null || _buf$constructor === void 0 ? void 0 : _buf$constructor.name) === 'Buffer';
|
|
82
|
+
}
|
|
83
|
+
export function toArrayBuffer(buf) {
|
|
84
|
+
var _buf$buffer;
|
|
85
|
+
|
|
86
|
+
if (buf !== null && buf !== void 0 && (_buf$buffer = buf.buffer) !== null && _buf$buffer !== void 0 && _buf$buffer.slice) {
|
|
87
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const ab = new ArrayBuffer(buf.length);
|
|
91
|
+
const view = new Uint8Array(ab);
|
|
92
|
+
|
|
93
|
+
for (let i = 0; i < buf.length; ++i) {
|
|
94
|
+
view[i] = buf[i];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return ab;
|
|
98
|
+
}
|
|
99
|
+
export function binaryLikeToArrayBuffer(input) {
|
|
100
|
+
let encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf-8';
|
|
101
|
+
|
|
102
|
+
if (typeof input === 'string') {
|
|
103
|
+
const buffer = Buffer.from(input, encoding);
|
|
104
|
+
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (isBuffer(input)) {
|
|
108
|
+
return toArrayBuffer(input);
|
|
109
|
+
} // TODO add further binary types to BinaryLike, UInt8Array and so for have this array as property
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
if (input.buffer) {
|
|
113
|
+
return input.buffer;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (!(input instanceof ArrayBuffer)) {
|
|
117
|
+
try {
|
|
118
|
+
const buffer = Buffer.from(input);
|
|
119
|
+
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
120
|
+
} catch {
|
|
121
|
+
throw 'error';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return input;
|
|
126
|
+
}
|
|
127
|
+
export function ab2str(buf) {
|
|
128
|
+
let encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'hex';
|
|
129
|
+
return Buffer.from(buf).toString(encoding);
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=Utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["Utils.ts"],"names":["Buffer","defaultEncoding","setDefaultEncoding","encoding","getDefaultEncoding","isBuffer","buf","constructor","name","toArrayBuffer","buffer","slice","byteOffset","byteLength","ab","ArrayBuffer","length","view","Uint8Array","i","binaryLikeToArrayBuffer","input","from","ab2str","toString"],"mappings":"AAAA,SAASA,MAAT,QAAuB,gCAAvB;AAeA;AACA,IAAIC,eAA+B,GAAG,QAAtC;AAEA,OAAO,SAASC,kBAAT,CAA4BC,QAA5B,EAAsD;AAC3DF,EAAAA,eAAe,GAAGE,QAAlB;AACD;AAED,OAAO,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;;AAEA,OAAO,SAASI,QAAT,CAAkBC,GAAlB,EAA2C;AAAA;;AAChD,SAAOA,GAAG,YAAYN,MAAf,IAAyB,CAAAM,GAAG,SAAH,IAAAA,GAAG,WAAH,gCAAAA,GAAG,CAAEC,WAAL,sEAAkBC,IAAlB,MAA2B,QAA3D;AACD;AAED,OAAO,SAASC,aAAT,CAAuBH,GAAvB,EAAiD;AAAA;;AACtD,MAAIA,GAAJ,aAAIA,GAAJ,8BAAIA,GAAG,CAAEI,MAAT,wCAAI,YAAaC,KAAjB,EAAwB;AACtB,WAAOL,GAAG,CAACI,MAAJ,CAAWC,KAAX,CAAiBL,GAAG,CAACM,UAArB,EAAiCN,GAAG,CAACM,UAAJ,GAAiBN,GAAG,CAACO,UAAtD,CAAP;AACD;;AACD,Q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,QAA0B,uEAAP,KAAO;AACjE,SAAOH,MAAM,CAACsB,IAAP,CAAYhB,GAAZ,EAAiBkB,QAAjB,CAA0BrB,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 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAd","sourcesContent":["export * from './QuickCrypto';\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
|
|
2
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
3
|
+
import { binaryLikeToArrayBuffer } from './Utils';
|
|
4
|
+
const WRONG_PASS = 'Password must be a string, a Buffer, a typed array or a DataView';
|
|
5
|
+
const WRON_SALT = `Salt must be a string, a Buffer, a typed array or a DataView`;
|
|
6
|
+
|
|
7
|
+
function sanitizeInput(input, errorMsg) {
|
|
8
|
+
try {
|
|
9
|
+
return binaryLikeToArrayBuffer(input);
|
|
10
|
+
} catch (e) {
|
|
11
|
+
throw errorMsg;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const nativePbkdf2 = NativeQuickCrypto.pbkdf2;
|
|
16
|
+
export function pbkdf2(password, salt, iterations, keylen, arg0, arg1) {
|
|
17
|
+
let digest = 'sha1';
|
|
18
|
+
let callback;
|
|
19
|
+
|
|
20
|
+
if (typeof arg0 === 'string') {
|
|
21
|
+
digest = arg0;
|
|
22
|
+
|
|
23
|
+
if (typeof arg1 === 'function') {
|
|
24
|
+
callback = arg1;
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
if (typeof arg0 === 'function') {
|
|
28
|
+
callback = arg0;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (callback === undefined) {
|
|
33
|
+
throw new Error('No callback provided to pbkdf2');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const sanitizedPassword = sanitizeInput(password, WRONG_PASS);
|
|
37
|
+
const sanitizedSalt = sanitizeInput(salt, WRON_SALT);
|
|
38
|
+
nativePbkdf2.pbkdf2(sanitizedPassword, sanitizedSalt, iterations, keylen, digest).then(res => {
|
|
39
|
+
callback(null, Buffer.from(res));
|
|
40
|
+
}, e => {
|
|
41
|
+
callback(e);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export function pbkdf2Sync(password, salt, iterations, keylen, digest) {
|
|
45
|
+
const sanitizedPassword = sanitizeInput(password, WRONG_PASS);
|
|
46
|
+
const sanitizedSalt = sanitizeInput(salt, WRON_SALT);
|
|
47
|
+
const algo = digest ? digest : 'sha1';
|
|
48
|
+
let result = nativePbkdf2.pbkdf2Sync(sanitizedPassword, sanitizedSalt, iterations, keylen, algo);
|
|
49
|
+
return Buffer.from(result);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=pbkdf2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["pbkdf2.ts"],"names":["NativeQuickCrypto","Buffer","binaryLikeToArrayBuffer","WRONG_PASS","WRON_SALT","sanitizeInput","input","errorMsg","e","nativePbkdf2","pbkdf2","password","salt","iterations","keylen","arg0","arg1","digest","callback","undefined","Error","sanitizedPassword","sanitizedSalt","then","res","from","pbkdf2Sync","algo","result"],"mappings":"AAAA,SAASA,iBAAT,QAAkC,uCAAlC;AACA,SAASC,MAAT,QAAuB,gCAAvB;AACA,SAAqBC,uBAArB,QAAoD,SAApD;AAEA,MAAMC,UAAU,GACd,kEADF;AAEA,MAAMC,SAAS,GAAI,8DAAnB;;AAMA,SAASC,aAAT,CAAuBC,KAAvB,EAA0CC,QAA1C,EAAyE;AACvE,MAAI;AACF,WAAOL,uBAAuB,CAACI,KAAD,CAA9B;AACD,GAFD,CAEE,OAAO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GjB,aAAa,CAACO,IAAD,EAAOR,SAAP,CAAnC;AAEA,QAAMuB,IAAI,GAAGV,MAAM,GAAGA,MAAH,GAAY,MAA/B;AACA,MAAIW,MAAmB,GAAGnB,YAAY,CAACiB,UAAb,CACxBL,iBADwB,EAExBC,aAFwB,EAGxBT,UAHwB,EAIxBC,MAJwB,EAKxBa,IALwB,CAA1B;AAQA,SAAO1B,MAAM,CAACwB,IAAP,CAAYG,MAAZ,CAAP;AACD","sourcesContent":["import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';\nimport { Buffer } from '@craftzdog/react-native-buffer';\nimport { BinaryLike, binaryLikeToArrayBuffer } from './Utils';\n\nconst WRONG_PASS =\n 'Password must be a string, a Buffer, a typed array or a DataView';\nconst WRON_SALT = `Salt must be a string, a Buffer, a typed array or a DataView`;\n\ntype Password = BinaryLike;\ntype Salt = BinaryLike;\ntype Pbkdf2Callback = (err: Error | null, derivedKey?: Buffer) => void;\n\nfunction sanitizeInput(input: BinaryLike, errorMsg: string): ArrayBuffer {\n try {\n return binaryLikeToArrayBuffer(input);\n } catch (e: any) {\n throw errorMsg;\n }\n}\n\nconst nativePbkdf2 = NativeQuickCrypto.pbkdf2;\n\nexport function pbkdf2(\n password: Password,\n salt: Salt,\n iterations: number,\n keylen: number,\n digest: string,\n callback: Pbkdf2Callback\n): void;\nexport function pbkdf2(\n password: Password,\n salt: Salt,\n iterations: number,\n keylen: number,\n callback: Pbkdf2Callback\n): void;\nexport function pbkdf2(\n password: Password,\n salt: Salt,\n iterations: number,\n keylen: number,\n arg0?: unknown,\n arg1?: unknown\n): void {\n let digest = 'sha1';\n let callback: undefined | Pbkdf2Callback;\n if (typeof arg0 === 'string') {\n digest = arg0;\n if (typeof arg1 === 'function') {\n callback = arg1 as Pbkdf2Callback;\n }\n } else {\n if (typeof arg0 === 'function') {\n callback = arg0 as Pbkdf2Callback;\n }\n }\n if (callback === undefined) {\n throw new Error('No callback provided to pbkdf2');\n }\n\n const sanitizedPassword = sanitizeInput(password, WRONG_PASS);\n const sanitizedSalt = sanitizeInput(salt, WRON_SALT);\n\n nativePbkdf2\n .pbkdf2(sanitizedPassword, sanitizedSalt, iterations, keylen, digest)\n .then(\n (res: ArrayBuffer) => {\n callback!(null, Buffer.from(res));\n },\n (e: Error) => {\n callback!(e);\n }\n );\n}\nexport function pbkdf2Sync(\n password: Password,\n salt: Salt,\n iterations: number,\n keylen: number,\n digest?: string\n): Buffer {\n const sanitizedPassword = sanitizeInput(password, WRONG_PASS);\n const sanitizedSalt = sanitizeInput(salt, WRON_SALT);\n\n const algo = digest ? digest : 'sha1';\n let result: ArrayBuffer = nativePbkdf2.pbkdf2Sync(\n sanitizedPassword,\n sanitizedSalt,\n iterations,\n keylen,\n algo\n );\n\n return Buffer.from(result);\n}\n"]}
|