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,190 @@
|
|
|
1
|
+
import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
|
|
2
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
3
|
+
import { isBuffer } from '../src/Utils';
|
|
4
|
+
const random = NativeQuickCrypto.random;
|
|
5
|
+
export function randomFill(buffer) {
|
|
6
|
+
var _ref, _ref2;
|
|
7
|
+
|
|
8
|
+
if (typeof (_ref = (arguments.length <= 1 ? 0 : arguments.length - 1) - 1 + 1, _ref < 1 || arguments.length <= _ref ? undefined : arguments[_ref]) !== 'function') {
|
|
9
|
+
throw new Error('No callback provided to randomDill');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const callback = (_ref2 = (arguments.length <= 1 ? 0 : arguments.length - 1) - 1 + 1, _ref2 < 1 || arguments.length <= _ref2 ? undefined : arguments[_ref2]);
|
|
13
|
+
let offset = 0;
|
|
14
|
+
let size = buffer.byteLength;
|
|
15
|
+
|
|
16
|
+
if (typeof (arguments.length <= 3 ? undefined : arguments[3]) === 'function') {
|
|
17
|
+
offset = arguments.length <= 1 ? undefined : arguments[1];
|
|
18
|
+
size = arguments.length <= 2 ? undefined : arguments[2];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (typeof (arguments.length <= 2 ? undefined : arguments[2]) === 'function') {
|
|
22
|
+
offset = arguments.length <= 1 ? undefined : arguments[1];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
random.randomFill(isBuffer(buffer) ? buffer.buffer : buffer, offset, size).then(() => {
|
|
26
|
+
callback(null, buffer);
|
|
27
|
+
}, e => {
|
|
28
|
+
callback(e);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export function randomFillSync(buffer) {
|
|
32
|
+
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
33
|
+
let size = arguments.length > 2 ? arguments[2] : undefined;
|
|
34
|
+
random.randomFillSync(buffer.buffer ? buffer.buffer : buffer, offset, size !== null && size !== void 0 ? size : buffer.byteLength);
|
|
35
|
+
return buffer;
|
|
36
|
+
}
|
|
37
|
+
export function randomBytes(size, callback) {
|
|
38
|
+
const buf = new Buffer(size);
|
|
39
|
+
|
|
40
|
+
if (callback === undefined) {
|
|
41
|
+
randomFillSync(buf.buffer, 0, size);
|
|
42
|
+
return buf;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
randomFill(buf.buffer, 0, size, error => {
|
|
46
|
+
if (error) {
|
|
47
|
+
callback(error);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
callback(null, buf);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export const rng = randomBytes;
|
|
54
|
+
export const pseudoRandomBytes = randomBytes;
|
|
55
|
+
export const prng = randomBytes;
|
|
56
|
+
// The rest of the file is taken from https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js
|
|
57
|
+
// Largest integer we can read from a buffer.
|
|
58
|
+
// e.g.: Buffer.from("ff".repeat(6), "hex").readUIntBE(0, 6);
|
|
59
|
+
const RAND_MAX = 0xffffffffffff; // Cache random data to use in randomInt. The cache size must be evenly
|
|
60
|
+
// divisible by 6 because each attempt to obtain a random int uses 6 bytes.
|
|
61
|
+
|
|
62
|
+
const randomCache = new Buffer(6 * 1024);
|
|
63
|
+
let randomCacheOffset = randomCache.length;
|
|
64
|
+
let asyncCacheFillInProgress = false;
|
|
65
|
+
const asyncCachePendingTasks = []; // Generates an integer in [min, max) range where min is inclusive and max is
|
|
66
|
+
// exclusive.
|
|
67
|
+
|
|
68
|
+
export function randomInt(arg1, arg2, callback) {
|
|
69
|
+
// Detect optional min syntax
|
|
70
|
+
// randomInt(max)
|
|
71
|
+
// randomInt(max, callback)
|
|
72
|
+
let max;
|
|
73
|
+
let min;
|
|
74
|
+
const minNotSpecified = typeof arg2 === 'undefined' || typeof arg2 === 'function';
|
|
75
|
+
|
|
76
|
+
if (minNotSpecified) {
|
|
77
|
+
callback = arg2;
|
|
78
|
+
max = arg1;
|
|
79
|
+
min = 0;
|
|
80
|
+
} else {
|
|
81
|
+
min = arg1;
|
|
82
|
+
max = arg2;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const isSync = typeof callback === 'undefined';
|
|
86
|
+
|
|
87
|
+
if (!Number.isSafeInteger(min)) {
|
|
88
|
+
// todo throw new ERR_INVALID_ARG_TYPE('min', 'a safe integer', min);
|
|
89
|
+
throw 'ERR_INVALID_ARG_TYPE';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!Number.isSafeInteger(max)) {
|
|
93
|
+
// todo throw new ERR_INVALID_ARG_TYPE('max', 'a safe integer', max);
|
|
94
|
+
throw 'ERR_INVALID_ARG_TYPE';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (max <= min) {
|
|
98
|
+
/* todo throw new ERR_OUT_OF_RANGE(
|
|
99
|
+
'max',
|
|
100
|
+
`greater than the value of "min" (${min})`,
|
|
101
|
+
max
|
|
102
|
+
);*/
|
|
103
|
+
throw 'ERR_OUT_OF_RANGE';
|
|
104
|
+
} // First we generate a random int between [0..range)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
const range = max - min;
|
|
108
|
+
|
|
109
|
+
if (!(range <= RAND_MAX)) {
|
|
110
|
+
/* todo throw new ERR_OUT_OF_RANGE(
|
|
111
|
+
`max${minNotSpecified ? '' : ' - min'}`,
|
|
112
|
+
`<= ${RAND_MAX}`,
|
|
113
|
+
range
|
|
114
|
+
);*/
|
|
115
|
+
throw 'ERR_OUT_OF_RANGE';
|
|
116
|
+
} // For (x % range) to produce an unbiased value greater than or equal to 0 and
|
|
117
|
+
// less than range, x must be drawn randomly from the set of integers greater
|
|
118
|
+
// than or equal to 0 and less than randLimit.
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
const randLimit = RAND_MAX - RAND_MAX % range; // If we don't have a callback, or if there is still data in the cache, we can
|
|
122
|
+
// do this synchronously, which is super fast.
|
|
123
|
+
|
|
124
|
+
while (isSync || randomCacheOffset < randomCache.length) {
|
|
125
|
+
if (randomCacheOffset === randomCache.length) {
|
|
126
|
+
// This might block the thread for a bit, but we are in sync mode.
|
|
127
|
+
randomFillSync(randomCache);
|
|
128
|
+
randomCacheOffset = 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const x = randomCache.readUIntBE(randomCacheOffset, 6);
|
|
132
|
+
randomCacheOffset += 6;
|
|
133
|
+
|
|
134
|
+
if (x < randLimit) {
|
|
135
|
+
const n = x % range + min;
|
|
136
|
+
if (isSync) return n;
|
|
137
|
+
process.nextTick(callback, undefined, n);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
} // At this point, we are in async mode with no data in the cache. We cannot
|
|
141
|
+
// simply refill the cache, because another async call to randomInt might
|
|
142
|
+
// already be doing that. Instead, queue this call for when the cache has
|
|
143
|
+
// been refilled.
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
if (callback !== undefined) {
|
|
147
|
+
// it is (typescript doesn't know it)
|
|
148
|
+
asyncCachePendingTasks.push({
|
|
149
|
+
min,
|
|
150
|
+
max,
|
|
151
|
+
callback
|
|
152
|
+
});
|
|
153
|
+
asyncRefillRandomIntCache();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function asyncRefillRandomIntCache() {
|
|
158
|
+
if (asyncCacheFillInProgress) return;
|
|
159
|
+
asyncCacheFillInProgress = true;
|
|
160
|
+
randomFill(randomCache, err => {
|
|
161
|
+
asyncCacheFillInProgress = false;
|
|
162
|
+
const tasks = asyncCachePendingTasks;
|
|
163
|
+
const errorReceiver = err && tasks.shift();
|
|
164
|
+
if (!err) randomCacheOffset = 0; // Restart all pending tasks. If an error occurred, we only notify a single
|
|
165
|
+
// callback (errorReceiver) about it. This way, every async call to
|
|
166
|
+
// randomInt has a chance of being successful, and it avoids complex
|
|
167
|
+
// exception handling here.
|
|
168
|
+
|
|
169
|
+
tasks.splice(0).forEach(task => {
|
|
170
|
+
randomInt(task.min, task.max, task.callback);
|
|
171
|
+
}); // This is the only call that might throw, and is therefore done at the end.
|
|
172
|
+
|
|
173
|
+
if (errorReceiver) errorReceiver.callback(err, 0);
|
|
174
|
+
});
|
|
175
|
+
} // Really just the Web Crypto API alternative
|
|
176
|
+
// to require('crypto').randomFillSync() with an
|
|
177
|
+
// additional limitation that the input buffer is
|
|
178
|
+
// not allowed to exceed 65536 bytes, and can only
|
|
179
|
+
// be an integer-type TypedArray.
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
export function getRandomValues(data) {
|
|
183
|
+
if (data.byteLength > 65536) {
|
|
184
|
+
throw new Error('The requested length exceeds 65,536 bytes');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
randomFillSync(data, 0);
|
|
188
|
+
return data;
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=random.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["random.ts"],"names":["NativeQuickCrypto","Buffer","isBuffer","random","randomFill","buffer","Error","callback","offset","size","byteLength","then","e","randomFillSync","randomBytes","buf","undefined","error","rng","pseudoRandomBytes","prng","RAND_MAX","randomCache","randomCacheOffset","length","asyncCacheFillInProgress","asyncCachePendingTasks","randomInt","arg1","arg2","max","min","minNotSpecified","isSync","Number","isSafeInteger","range","randLimit","x","readUIntBE","n","process","nextTick","push","asyncRefillRandomIntCache","err","tasks","errorReceiver","shift","splice","forEach","task","getRandomValues","data"],"mappings":"AAAA,SAASA,iBAAT,QAAkC,uCAAlC;AACA,SAASC,MAAT,QAAuB,gCAAvB;AACA,SAASC,QAAT,QAAyB,cAAzB;AAEA,MAAMC,MAAM,GAAGH,iBAAiB,CAACG,MAAjC;AAgCA,OAAO,SAASC,UAAT,CAAoBC,MAApB,EAAuD;AAAA;;AAC5D,MAAI,eAAY,qDAAc,CAA1B,8EAAiC,UAArC,EAAiD;AAC/C,UAAM,IAAIC,KAAJ,CAAU,oCAAV,CAAN;AACD;;AAED,QAAMC,QAAQ,YAAQ,qDAAc,CAAtB,4EAAd;AAKA,MAAIC,MAAc,GAAG,CAArB;AACA,MAAIC,IAAY,GAAGJ,MAAM,CAACK,UAA1B;;AAEA,MAAI,8DAAmB,UAAvB,EAAmC;AACjCF,IAAAA,MAAM,mDAA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CAACH,GAAL,EAAUtB,iBAAiB,GAAG,CAApB,CALqB,CAO/B;AACA;AACA;AACA;;AACAuB,IAAAA,KAAK,CAACG,MAAN,CAAa,CAAb,EAAgBC,OAAhB,CAAyBC,IAAD,IAAU;AAChCxB,MAAAA,SAAS,CAACwB,IAAI,CAACpB,GAAN,EAAWoB,IAAI,CAACrB,GAAhB,EAAqBqB,IAAI,CAAC5C,QAA1B,CAAT;AACD,KAFD,EAX+B,CAe/B;;AACA,QAAIwC,aAAJ,EAAmBA,aAAa,CAACxC,QAAd,CAAuBsC,GAAvB,EAA4B,CAA5B;AACpB,GAjBS,CAAV;AAkBD,C,CAED;AACA;AACA;AACA;AACA;;;AAQA,OAAO,SAASO,eAAT,CAAyBC,IAAzB,EAAyC;AAC9C,MAAIA,IAAI,CAAC3C,UAAL,GAAkB,KAAtB,EAA6B;AAC3B,UAAM,IAAIJ,KAAJ,CAAU,2CAAV,CAAN;AACD;;AACDO,EAAAA,cAAc,CAACwC,IAAD,EAAO,CAAP,CAAd;AACA,SAAOA,IAAP;AACD","sourcesContent":["import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';\nimport { Buffer } from '@craftzdog/react-native-buffer';\nimport { isBuffer } from '../src/Utils';\n\nconst random = NativeQuickCrypto.random;\n\ntype TypedArray =\n | Uint8Array\n | Uint8ClampedArray\n | Uint16Array\n | Uint32Array\n | Int8Array\n | Int16Array\n | Int32Array\n | Float32Array\n | Float64Array;\ntype ArrayBufferView = TypedArray | DataView | ArrayBufferLike | Buffer;\n\nexport function randomFill<T extends ArrayBufferView>(\n buffer: T,\n callback: (err: Error | null, buf: T) => void\n): void;\n\nexport function randomFill<T extends ArrayBufferView>(\n buffer: T,\n offset: number,\n callback: (err: Error | null, buf: T) => void\n): void;\n\nexport function randomFill<T extends ArrayBufferView>(\n buffer: T,\n offset: number,\n size: number,\n callback: (err: Error | null, buf: T) => void\n): void;\n\nexport function randomFill(buffer: any, ...rest: any[]): void {\n if (typeof rest[rest.length - 1] !== 'function') {\n throw new Error('No callback provided to randomDill');\n }\n\n const callback = rest[rest.length - 1] as any as (\n err: Error | null,\n buf?: ArrayBuffer\n ) => void;\n\n let offset: number = 0;\n let size: number = buffer.byteLength;\n\n if (typeof rest[2] === 'function') {\n offset = rest[0];\n size = rest[1];\n }\n\n if (typeof rest[1] === 'function') {\n offset = rest[0];\n }\n\n random\n .randomFill(isBuffer(buffer) ? buffer.buffer : buffer, offset, size)\n .then(\n () => {\n callback(null, buffer);\n },\n (e: Error) => {\n callback(e);\n }\n );\n}\n\nexport function randomFillSync<T extends ArrayBufferView>(\n buffer: T,\n offset?: number,\n size?: number\n): T;\n\nexport function randomFillSync(buffer: any, offset: number = 0, size?: number) {\n random.randomFillSync(\n buffer.buffer ? buffer.buffer : buffer,\n offset,\n size ?? buffer.byteLength\n );\n return buffer;\n}\n\nexport function randomBytes(size: number): ArrayBuffer;\n\nexport function randomBytes(\n size: number,\n callback: (err: Error | null, buf?: ArrayBuffer) => void\n): void;\n\nexport function randomBytes(\n size: number,\n callback?: (err: Error | null, buf?: ArrayBuffer) => void\n): void | ArrayBuffer {\n const buf = new Buffer(size);\n\n if (callback === undefined) {\n randomFillSync(buf.buffer, 0, size);\n return buf;\n }\n\n randomFill(buf.buffer, 0, size, (error: Error | null) => {\n if (error) {\n callback(error);\n }\n callback(null, buf);\n });\n}\n\nexport const rng = randomBytes;\nexport const pseudoRandomBytes = randomBytes;\nexport const prng = randomBytes;\n\ntype RandomIntCallback = (err: Error | null, value: number) => void;\ntype Task = {\n min: number;\n max: number;\n callback: RandomIntCallback;\n};\n\n// The rest of the file is taken from https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js\n\n// Largest integer we can read from a buffer.\n// e.g.: Buffer.from(\"ff\".repeat(6), \"hex\").readUIntBE(0, 6);\nconst RAND_MAX = 0xffff_ffff_ffff;\n\n// Cache random data to use in randomInt. The cache size must be evenly\n// divisible by 6 because each attempt to obtain a random int uses 6 bytes.\nconst randomCache = new Buffer(6 * 1024);\nlet randomCacheOffset = randomCache.length;\nlet asyncCacheFillInProgress = false;\nconst asyncCachePendingTasks: Task[] = [];\n\n// Generates an integer in [min, max) range where min is inclusive and max is\n// exclusive.\n\nexport function randomInt(max: number, callback: RandomIntCallback): void;\nexport function randomInt(max: number): number;\nexport function randomInt(\n min: number,\n max: number,\n callback: RandomIntCallback\n): void;\nexport function randomInt(min: number, max: number): number;\nexport function randomInt(\n arg1: number,\n arg2?: number | RandomIntCallback,\n callback?: RandomIntCallback\n): void | number {\n // Detect optional min syntax\n // randomInt(max)\n // randomInt(max, callback)\n let max: number;\n let min: number;\n const minNotSpecified =\n typeof arg2 === 'undefined' || typeof arg2 === 'function';\n\n if (minNotSpecified) {\n callback = arg2 as any as undefined | RandomIntCallback;\n max = arg1;\n min = 0;\n } else {\n min = arg1;\n max = arg2 as any as number;\n }\n\n const isSync = typeof callback === 'undefined';\n if (!Number.isSafeInteger(min)) {\n // todo throw new ERR_INVALID_ARG_TYPE('min', 'a safe integer', min);\n throw 'ERR_INVALID_ARG_TYPE';\n }\n if (!Number.isSafeInteger(max)) {\n // todo throw new ERR_INVALID_ARG_TYPE('max', 'a safe integer', max);\n throw 'ERR_INVALID_ARG_TYPE';\n }\n if (max <= min) {\n /* todo throw new ERR_OUT_OF_RANGE(\n 'max',\n `greater than the value of \"min\" (${min})`,\n max\n );*/\n throw 'ERR_OUT_OF_RANGE';\n }\n\n // First we generate a random int between [0..range)\n const range = max - min;\n\n if (!(range <= RAND_MAX)) {\n /* todo throw new ERR_OUT_OF_RANGE(\n `max${minNotSpecified ? '' : ' - min'}`,\n `<= ${RAND_MAX}`,\n range\n );*/\n throw 'ERR_OUT_OF_RANGE';\n }\n\n // For (x % range) to produce an unbiased value greater than or equal to 0 and\n // less than range, x must be drawn randomly from the set of integers greater\n // than or equal to 0 and less than randLimit.\n const randLimit = RAND_MAX - (RAND_MAX % range);\n\n // If we don't have a callback, or if there is still data in the cache, we can\n // do this synchronously, which is super fast.\n while (isSync || randomCacheOffset < randomCache.length) {\n if (randomCacheOffset === randomCache.length) {\n // This might block the thread for a bit, but we are in sync mode.\n randomFillSync(randomCache);\n randomCacheOffset = 0;\n }\n\n const x = randomCache.readUIntBE(randomCacheOffset, 6);\n randomCacheOffset += 6;\n\n if (x < randLimit) {\n const n = (x % range) + min;\n if (isSync) return n;\n process.nextTick(callback as Function, undefined, n);\n return;\n }\n }\n\n // At this point, we are in async mode with no data in the cache. We cannot\n // simply refill the cache, because another async call to randomInt might\n // already be doing that. Instead, queue this call for when the cache has\n // been refilled.\n if (callback !== undefined) {\n // it is (typescript doesn't know it)\n asyncCachePendingTasks.push({ min, max, callback });\n asyncRefillRandomIntCache();\n }\n}\n\nfunction asyncRefillRandomIntCache() {\n if (asyncCacheFillInProgress) return;\n\n asyncCacheFillInProgress = true;\n randomFill(randomCache, (err) => {\n asyncCacheFillInProgress = false;\n\n const tasks = asyncCachePendingTasks;\n const errorReceiver = err && tasks.shift();\n if (!err) randomCacheOffset = 0;\n\n // Restart all pending tasks. If an error occurred, we only notify a single\n // callback (errorReceiver) about it. This way, every async call to\n // randomInt has a chance of being successful, and it avoids complex\n // exception handling here.\n tasks.splice(0).forEach((task) => {\n randomInt(task.min, task.max, task.callback);\n });\n\n // This is the only call that might throw, and is therefore done at the end.\n if (errorReceiver) errorReceiver.callback(err, 0);\n });\n}\n\n// Really just the Web Crypto API alternative\n// to require('crypto').randomFillSync() with an\n// additional limitation that the input buffer is\n// not allowed to exceed 65536 bytes, and can only\n// be an integer-type TypedArray.\ntype DataType =\n | Int8Array\n | Int16Array\n | Int32Array\n | Uint8Array\n | Uint16Array\n | Uint32Array;\nexport function getRandomValues(data: DataType) {\n if (data.byteLength > 65536) {\n throw new Error('The requested length exceeds 65,536 bytes');\n }\n randomFillSync(data, 0);\n return data;\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import Stream from 'stream';
|
|
3
|
+
import { BinaryLike, CipherEncoding, Encoding } from './Utils';
|
|
4
|
+
import type { Buffer } from '@craftzdog/react-native-buffer';
|
|
5
|
+
declare class CipherCommon extends Stream.Transform {
|
|
6
|
+
private internal;
|
|
7
|
+
private decoder;
|
|
8
|
+
constructor(cipherType: string, cipherKey: BinaryLike, isCipher: boolean, options?: Record<string, any>, iv?: BinaryLike | null);
|
|
9
|
+
update(data: BinaryLike, inputEncoding?: CipherEncoding, outputEncoding?: CipherEncoding): ArrayBuffer | string;
|
|
10
|
+
final(): ArrayBuffer;
|
|
11
|
+
final(outputEncoding: BufferEncoding | 'buffer'): string;
|
|
12
|
+
_transform(chunk: BinaryLike, encoding: Encoding, callback: () => void): void;
|
|
13
|
+
_flush(callback: () => void): void;
|
|
14
|
+
setAutoPadding(autoPadding?: boolean): this;
|
|
15
|
+
setAAD(buffer: Buffer, options?: {
|
|
16
|
+
plaintextLength: number;
|
|
17
|
+
}): this;
|
|
18
|
+
setAuthTag(tag: Buffer): this;
|
|
19
|
+
}
|
|
20
|
+
declare class Cipher extends CipherCommon {
|
|
21
|
+
constructor(cipherType: string, cipherKey: BinaryLike, options?: Record<string, any>, iv?: BinaryLike | null);
|
|
22
|
+
}
|
|
23
|
+
declare class Decipher extends CipherCommon {
|
|
24
|
+
constructor(cipherType: string, cipherKey: BinaryLike, options?: Record<string, any>, iv?: BinaryLike | null);
|
|
25
|
+
}
|
|
26
|
+
export declare function createDecipher(algorithm: string, password: BinaryLike, options?: Stream.TransformOptions): Decipher;
|
|
27
|
+
export declare function createDecipheriv(algorithm: string, key: BinaryLike, iv: BinaryLike | null, options?: Stream.TransformOptions): Decipher;
|
|
28
|
+
export declare function createCipher(algorithm: string, password: BinaryLike, options?: Stream.TransformOptions): Cipher;
|
|
29
|
+
export declare function createCipheriv(algorithm: string, key: BinaryLike, iv: BinaryLike | null, options?: Stream.TransformOptions): Cipher;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import 'react-native';
|
|
3
|
+
import { Encoding } from './Utils';
|
|
4
|
+
import Stream from 'stream';
|
|
5
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
6
|
+
interface HashOptionsBase extends Stream.TransformOptions {
|
|
7
|
+
outputLength?: number | undefined;
|
|
8
|
+
}
|
|
9
|
+
declare type HashOptions = null | undefined | HashOptionsBase;
|
|
10
|
+
declare type BinaryLike = ArrayBuffer;
|
|
11
|
+
export declare function createHash(algorithm: string, options?: HashOptions): Hash;
|
|
12
|
+
declare class Hash extends Stream.Transform {
|
|
13
|
+
private internalHash;
|
|
14
|
+
constructor(other: Hash, options?: HashOptions);
|
|
15
|
+
constructor(algorithm: string, options?: HashOptions);
|
|
16
|
+
copy(options?: HashOptionsBase): Hash;
|
|
17
|
+
/**
|
|
18
|
+
* Updates the hash content with the given `data`, the encoding of which
|
|
19
|
+
* is given in `inputEncoding`.
|
|
20
|
+
* If `encoding` is not provided, and the `data` is a string, an
|
|
21
|
+
* encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
|
|
22
|
+
*
|
|
23
|
+
* This can be called many times with new data as it is streamed.
|
|
24
|
+
* @since v0.1.92
|
|
25
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
26
|
+
*/
|
|
27
|
+
update(data: string | BinaryLike, inputEncoding?: Encoding): Hash;
|
|
28
|
+
_transform(chunk: string | BinaryLike, encoding: Encoding, callback: () => void): void;
|
|
29
|
+
_flush(callback: () => void): void;
|
|
30
|
+
/**
|
|
31
|
+
* Calculates the digest of all of the data passed to be hashed (using the `hash.update()` method).
|
|
32
|
+
* If `encoding` is provided a string will be returned; otherwise
|
|
33
|
+
* a `Buffer` is returned.
|
|
34
|
+
*
|
|
35
|
+
* The `Hash` object can not be used again after `hash.digest()` method has been
|
|
36
|
+
* called. Multiple calls will cause an error to be thrown.
|
|
37
|
+
* @since v0.1.92
|
|
38
|
+
* @param encoding The `encoding` of the return value.
|
|
39
|
+
*/
|
|
40
|
+
digest(): Buffer;
|
|
41
|
+
digest(encoding: 'buffer'): Buffer;
|
|
42
|
+
digest(encoding: Encoding): string;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Encoding, BinaryLike } from './Utils';
|
|
3
|
+
import Stream from 'stream';
|
|
4
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
5
|
+
export declare function createHmac(algorithm: string, key: BinaryLike, options?: Stream.TransformOptions): Hmac;
|
|
6
|
+
declare class Hmac extends Stream.Transform {
|
|
7
|
+
private internalHmac;
|
|
8
|
+
private isFinalized;
|
|
9
|
+
constructor(algorithm: string, key: BinaryLike, _options?: Stream.TransformOptions);
|
|
10
|
+
/**
|
|
11
|
+
* Updates the `Hmac` content with the given `data`, the encoding of which
|
|
12
|
+
* is given in `inputEncoding`.
|
|
13
|
+
* If `encoding` is not provided, and the `data` is a string, an
|
|
14
|
+
* encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
|
|
15
|
+
*
|
|
16
|
+
* This can be called many times with new data as it is streamed.
|
|
17
|
+
* @since v0.1.94
|
|
18
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
19
|
+
*/
|
|
20
|
+
update(data: string | BinaryLike, inputEncoding?: Encoding): Hmac;
|
|
21
|
+
_transform(chunk: string | BinaryLike, encoding: Encoding, callback: () => void): void;
|
|
22
|
+
_flush(callback: () => void): void;
|
|
23
|
+
/**
|
|
24
|
+
* Calculates the HMAC digest of all of the data passed using `hmac.update()`.
|
|
25
|
+
* If `encoding` is
|
|
26
|
+
* provided a string is returned; otherwise a `Buffer` is returned;
|
|
27
|
+
*
|
|
28
|
+
* The `Hmac` object can not be used again after `hmac.digest()` has been
|
|
29
|
+
* called. Multiple calls to `hmac.digest()` will result in an error being thrown.
|
|
30
|
+
* @since v0.1.94
|
|
31
|
+
* @param encoding The `encoding` of the return value.
|
|
32
|
+
*/
|
|
33
|
+
digest(): Buffer;
|
|
34
|
+
digest(encoding: 'buffer'): Buffer;
|
|
35
|
+
digest(encoding: Encoding): string;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BinaryLike } from 'src/Utils';
|
|
2
|
+
export declare type InternalCipher = {
|
|
3
|
+
update: (data: BinaryLike | ArrayBufferView) => ArrayBuffer;
|
|
4
|
+
final: () => ArrayBuffer;
|
|
5
|
+
copy: () => void;
|
|
6
|
+
setAAD: (args: {
|
|
7
|
+
data: BinaryLike;
|
|
8
|
+
plaintextLength?: number;
|
|
9
|
+
}) => InternalCipher;
|
|
10
|
+
setAutoPadding: (autoPad: boolean) => boolean;
|
|
11
|
+
setAuthTag: (tag: ArrayBuffer) => boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare type CreateCipherMethod = (params: {
|
|
14
|
+
cipher_type: string;
|
|
15
|
+
cipher_key: ArrayBuffer;
|
|
16
|
+
auth_tag_len: number;
|
|
17
|
+
}) => InternalCipher;
|
|
18
|
+
export declare type CreateDecipherMethod = (params: {
|
|
19
|
+
cipher_type: string;
|
|
20
|
+
cipher_key: ArrayBuffer;
|
|
21
|
+
auth_tag_len: number;
|
|
22
|
+
}) => InternalCipher;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CreateHmacMethod } from './hmac';
|
|
2
|
+
import type { CreateHashMethod } from './hash';
|
|
3
|
+
import type { Pbkdf2Object } from './pbkdf2';
|
|
4
|
+
import type { RandomObject } from './random';
|
|
5
|
+
import type { CreateCipherMethod, CreateDecipherMethod } from './Cipher';
|
|
6
|
+
interface NativeQuickCryptoSpec {
|
|
7
|
+
createHmac: CreateHmacMethod;
|
|
8
|
+
pbkdf2: Pbkdf2Object;
|
|
9
|
+
random: RandomObject;
|
|
10
|
+
createHash: CreateHashMethod;
|
|
11
|
+
createCipher: CreateCipherMethod;
|
|
12
|
+
createDecipher: CreateDecipherMethod;
|
|
13
|
+
}
|
|
14
|
+
declare global {
|
|
15
|
+
function nativeCallSyncHook(): unknown;
|
|
16
|
+
var __QuickCryptoProxy: object | undefined;
|
|
17
|
+
}
|
|
18
|
+
export declare const NativeQuickCrypto: NativeQuickCryptoSpec;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare type Pbkdf2Object = {
|
|
2
|
+
pbkdf2: (password: ArrayBuffer, salt: ArrayBuffer, iterations: number, keylen: number, digest: string) => Promise<ArrayBuffer>;
|
|
3
|
+
pbkdf2Sync: (password: ArrayBuffer, salt: ArrayBuffer, iterations: number, keylen: number, digest: string) => ArrayBuffer;
|
|
4
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as random from './random';
|
|
2
|
+
import { createCipher, createCipheriv, createDecipher, createDecipheriv } from './Cipher';
|
|
3
|
+
import { createHmac } from './Hmac';
|
|
4
|
+
import { createHash } from './Hash';
|
|
5
|
+
export declare const QuickCrypto: {
|
|
6
|
+
randomFill<T extends import("@craftzdog/react-native-buffer").Buffer | ArrayBufferLike | (Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array) | DataView>(buffer: T, callback: (err: Error | null, buf: T) => void): void;
|
|
7
|
+
randomFill<T_1 extends import("@craftzdog/react-native-buffer").Buffer | ArrayBufferLike | (Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array) | DataView>(buffer: T_1, offset: number, callback: (err: Error | null, buf: T_1) => void): void;
|
|
8
|
+
randomFill<T_2 extends import("@craftzdog/react-native-buffer").Buffer | ArrayBufferLike | (Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array) | DataView>(buffer: T_2, offset: number, size: number, callback: (err: Error | null, buf: T_2) => void): void;
|
|
9
|
+
randomFillSync<T_3 extends import("@craftzdog/react-native-buffer").Buffer | ArrayBufferLike | (Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array) | DataView>(buffer: T_3, offset?: number | undefined, size?: number | undefined): T_3;
|
|
10
|
+
randomBytes(size: number): ArrayBuffer;
|
|
11
|
+
randomBytes(size: number, callback: (err: Error | null, buf?: ArrayBuffer | undefined) => void): void;
|
|
12
|
+
randomInt(max: number, callback: (err: Error | null, value: number) => void): void;
|
|
13
|
+
randomInt(max: number): number;
|
|
14
|
+
randomInt(min: number, max: number, callback: (err: Error | null, value: number) => void): void;
|
|
15
|
+
randomInt(min: number, max: number): number;
|
|
16
|
+
getRandomValues(data: Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array): Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array;
|
|
17
|
+
rng: typeof random.randomBytes;
|
|
18
|
+
pseudoRandomBytes: typeof random.randomBytes;
|
|
19
|
+
prng: typeof random.randomBytes;
|
|
20
|
+
pbkdf2(password: import("./Utils").BinaryLike, salt: import("./Utils").BinaryLike, iterations: number, keylen: number, digest: string, callback: (err: Error | null, derivedKey?: import("@craftzdog/react-native-buffer").Buffer | undefined) => void): void;
|
|
21
|
+
pbkdf2(password: import("./Utils").BinaryLike, salt: import("./Utils").BinaryLike, iterations: number, keylen: number, callback: (err: Error | null, derivedKey?: import("@craftzdog/react-native-buffer").Buffer | undefined) => void): void;
|
|
22
|
+
pbkdf2Sync(password: import("./Utils").BinaryLike, salt: import("./Utils").BinaryLike, iterations: number, keylen: number, digest?: string | undefined): import("@craftzdog/react-native-buffer").Buffer;
|
|
23
|
+
createHmac: typeof createHmac;
|
|
24
|
+
Hmac: typeof createHmac;
|
|
25
|
+
Hash: typeof createHash;
|
|
26
|
+
createHash: typeof createHash;
|
|
27
|
+
createCipher: typeof createCipher;
|
|
28
|
+
createCipheriv: typeof createCipheriv;
|
|
29
|
+
createDecipher: typeof createDecipher;
|
|
30
|
+
createDecipheriv: typeof createDecipheriv;
|
|
31
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
2
|
+
export declare type BinaryLike = string | ArrayBuffer | Buffer;
|
|
3
|
+
export declare type BinaryToTextEncoding = 'base64' | 'base64url' | 'hex' | 'binary';
|
|
4
|
+
export declare type CharacterEncoding = 'utf8' | 'utf-8' | 'utf16le' | 'latin1';
|
|
5
|
+
export declare type LegacyCharacterEncoding = 'ascii' | 'binary' | 'ucs2' | 'ucs-2';
|
|
6
|
+
export declare type Encoding = BinaryToTextEncoding | CharacterEncoding | LegacyCharacterEncoding;
|
|
7
|
+
export declare type CipherEncoding = Encoding | 'buffer';
|
|
8
|
+
export declare function setDefaultEncoding(encoding: CipherEncoding): void;
|
|
9
|
+
export declare function getDefaultEncoding(): CipherEncoding;
|
|
10
|
+
export declare function isBuffer(buf: any): buf is Buffer;
|
|
11
|
+
export declare function toArrayBuffer(buf: Buffer): ArrayBuffer;
|
|
12
|
+
export declare function binaryLikeToArrayBuffer(input: BinaryLike, encoding?: string): ArrayBuffer;
|
|
13
|
+
export declare function ab2str(buf: ArrayBuffer, encoding?: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './QuickCrypto';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
2
|
+
import { BinaryLike } from './Utils';
|
|
3
|
+
declare type Password = BinaryLike;
|
|
4
|
+
declare type Salt = BinaryLike;
|
|
5
|
+
declare type Pbkdf2Callback = (err: Error | null, derivedKey?: Buffer) => void;
|
|
6
|
+
export declare function pbkdf2(password: Password, salt: Salt, iterations: number, keylen: number, digest: string, callback: Pbkdf2Callback): void;
|
|
7
|
+
export declare function pbkdf2(password: Password, salt: Salt, iterations: number, keylen: number, callback: Pbkdf2Callback): void;
|
|
8
|
+
export declare function pbkdf2Sync(password: Password, salt: Salt, iterations: number, keylen: number, digest?: string): Buffer;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
2
|
+
declare type TypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array;
|
|
3
|
+
declare type ArrayBufferView = TypedArray | DataView | ArrayBufferLike | Buffer;
|
|
4
|
+
export declare function randomFill<T extends ArrayBufferView>(buffer: T, callback: (err: Error | null, buf: T) => void): void;
|
|
5
|
+
export declare function randomFill<T extends ArrayBufferView>(buffer: T, offset: number, callback: (err: Error | null, buf: T) => void): void;
|
|
6
|
+
export declare function randomFill<T extends ArrayBufferView>(buffer: T, offset: number, size: number, callback: (err: Error | null, buf: T) => void): void;
|
|
7
|
+
export declare function randomFillSync<T extends ArrayBufferView>(buffer: T, offset?: number, size?: number): T;
|
|
8
|
+
export declare function randomBytes(size: number): ArrayBuffer;
|
|
9
|
+
export declare function randomBytes(size: number, callback: (err: Error | null, buf?: ArrayBuffer) => void): void;
|
|
10
|
+
export declare const rng: typeof randomBytes;
|
|
11
|
+
export declare const pseudoRandomBytes: typeof randomBytes;
|
|
12
|
+
export declare const prng: typeof randomBytes;
|
|
13
|
+
declare type RandomIntCallback = (err: Error | null, value: number) => void;
|
|
14
|
+
export declare function randomInt(max: number, callback: RandomIntCallback): void;
|
|
15
|
+
export declare function randomInt(max: number): number;
|
|
16
|
+
export declare function randomInt(min: number, max: number, callback: RandomIntCallback): void;
|
|
17
|
+
export declare function randomInt(min: number, max: number): number;
|
|
18
|
+
declare type DataType = Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array;
|
|
19
|
+
export declare function getRandomValues(data: DataType): DataType;
|
|
20
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-quick-crypto",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A fast implementation of Node's `crypto` module written in C/C++ JSI",
|
|
5
|
+
"main": "lib/commonjs/index",
|
|
6
|
+
"module": "lib/module/index",
|
|
7
|
+
"types": "lib/typescript/index.d.ts",
|
|
8
|
+
"react-native": "src/index",
|
|
9
|
+
"source": "src/index",
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"lib",
|
|
13
|
+
"android",
|
|
14
|
+
"ios",
|
|
15
|
+
"cpp",
|
|
16
|
+
"react-native-quick-crypto.podspec",
|
|
17
|
+
"!lib/typescript/example",
|
|
18
|
+
"!android/build",
|
|
19
|
+
"!ios/build",
|
|
20
|
+
"!**/__tests__",
|
|
21
|
+
"!**/__fixtures__",
|
|
22
|
+
"!**/__mocks__"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"typescript": "tsc --noEmit",
|
|
26
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
27
|
+
"prepare": "bob build",
|
|
28
|
+
"release": "release-it",
|
|
29
|
+
"pods": "cd example && pod-install --quiet"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"react-native",
|
|
33
|
+
"ios",
|
|
34
|
+
"android",
|
|
35
|
+
"jsi",
|
|
36
|
+
"crypto",
|
|
37
|
+
"c++",
|
|
38
|
+
"fast",
|
|
39
|
+
"web3"
|
|
40
|
+
],
|
|
41
|
+
"repository": "https://github.com/margelo/react-native-quick-crypto",
|
|
42
|
+
"authors": "Szymon Kapała (szymon20000@gmail.com) & Marc Rousavy <me@mrousavy.com> (https://github.com/mrousavy)",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/margelo/react-native-quick-crypto/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/margelo/react-native-quick-crypto#readme",
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"registry": "https://registry.npmjs.org/"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@jamesacarr/eslint-formatter-github-actions": "^0.1.0",
|
|
53
|
+
"@react-native-community/eslint-config": "^3.0.1",
|
|
54
|
+
"@react-native-community/eslint-plugin": "^1.1.0",
|
|
55
|
+
"@release-it/conventional-changelog": "^3.3.0",
|
|
56
|
+
"@types/react": "^17.0.21",
|
|
57
|
+
"@types/react-native": "^0.65.5",
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^5.14.0",
|
|
59
|
+
"eslint": "^7.32.0",
|
|
60
|
+
"prettier": "^2.4.0",
|
|
61
|
+
"react": "^17.0.2",
|
|
62
|
+
"react-native": "^0.66.0",
|
|
63
|
+
"react-native-builder-bob": "^0.18.1",
|
|
64
|
+
"release-it": "^14.11.5",
|
|
65
|
+
"typescript": "^4.4.3"
|
|
66
|
+
},
|
|
67
|
+
"peerDependencies": {
|
|
68
|
+
"react": "*",
|
|
69
|
+
"react-native": "*"
|
|
70
|
+
},
|
|
71
|
+
"release-it": {
|
|
72
|
+
"git": {
|
|
73
|
+
"commitMessage": "chore: release ${version}",
|
|
74
|
+
"tagName": "v${version}"
|
|
75
|
+
},
|
|
76
|
+
"npm": {
|
|
77
|
+
"publish": true
|
|
78
|
+
},
|
|
79
|
+
"github": {
|
|
80
|
+
"release": true
|
|
81
|
+
},
|
|
82
|
+
"plugins": {
|
|
83
|
+
"@release-it/conventional-changelog": {
|
|
84
|
+
"preset": {
|
|
85
|
+
"name": "conventionalcommits",
|
|
86
|
+
"types": [
|
|
87
|
+
{
|
|
88
|
+
"type": "feat",
|
|
89
|
+
"section": "✨ Features"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"type": "fix",
|
|
93
|
+
"section": "🐛 Bug Fixes"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"type": "perf",
|
|
97
|
+
"section": "💨 Performance Improvements"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"type": "chore(deps)",
|
|
101
|
+
"section": "🛠️ Dependency Upgrades"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"type": "docs",
|
|
105
|
+
"section": "📚 Documentation"
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
"eslintConfig": {
|
|
113
|
+
"root": true,
|
|
114
|
+
"extends": [
|
|
115
|
+
"@react-native-community",
|
|
116
|
+
"prettier"
|
|
117
|
+
],
|
|
118
|
+
"rules": {
|
|
119
|
+
"prettier/prettier": [
|
|
120
|
+
"error",
|
|
121
|
+
{
|
|
122
|
+
"quoteProps": "consistent",
|
|
123
|
+
"singleQuote": true,
|
|
124
|
+
"tabWidth": 2,
|
|
125
|
+
"trailingComma": "es5",
|
|
126
|
+
"useTabs": false
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
"globals": {
|
|
131
|
+
"BufferEncoding": true
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
"eslintIgnore": [
|
|
135
|
+
"node_modules/",
|
|
136
|
+
"lib/"
|
|
137
|
+
],
|
|
138
|
+
"prettier": {
|
|
139
|
+
"quoteProps": "consistent",
|
|
140
|
+
"singleQuote": true,
|
|
141
|
+
"tabWidth": 2,
|
|
142
|
+
"trailingComma": "es5",
|
|
143
|
+
"useTabs": false
|
|
144
|
+
},
|
|
145
|
+
"react-native-builder-bob": {
|
|
146
|
+
"source": "src",
|
|
147
|
+
"output": "lib",
|
|
148
|
+
"targets": [
|
|
149
|
+
"commonjs",
|
|
150
|
+
"module",
|
|
151
|
+
[
|
|
152
|
+
"typescript",
|
|
153
|
+
{
|
|
154
|
+
"project": "tsconfig.build.json"
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
]
|
|
158
|
+
},
|
|
159
|
+
"dependencies": {
|
|
160
|
+
"@craftzdog/react-native-buffer": "^6.0.4",
|
|
161
|
+
"@types/node": "^17.0.31",
|
|
162
|
+
"events": "^3.3.0",
|
|
163
|
+
"react-native-quick-base64": "^2.0.2",
|
|
164
|
+
"stream": "^0.0.2",
|
|
165
|
+
"stream-browserify": "^3.0.0",
|
|
166
|
+
"string_decoder": "^1.3.0"
|
|
167
|
+
}
|
|
168
|
+
}
|