react-native-quick-crypto 0.4.6 → 0.6.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.
@@ -186,4 +186,20 @@ export function getRandomValues(data) {
186
186
  randomFillSync(data, 0);
187
187
  return data;
188
188
  }
189
+ const byteToHex = [];
190
+
191
+ for (let i = 0; i < 256; ++i) {
192
+ byteToHex.push((i + 0x100).toString(16).slice(1));
193
+ } // Based on https://github.com/uuidjs/uuid/blob/main/src/v4.js
194
+
195
+
196
+ export function randomUUID() {
197
+ const size = 16;
198
+ const buffer = new Buffer(size);
199
+ randomFillSync(buffer, 0, size); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
200
+
201
+ buffer[6] = buffer[6] & 0x0f | 0x40;
202
+ buffer[8] = buffer[8] & 0x3f | 0x80;
203
+ return (byteToHex[buffer[0]] + byteToHex[buffer[1]] + byteToHex[buffer[2]] + byteToHex[buffer[3]] + '-' + byteToHex[buffer[4]] + byteToHex[buffer[5]] + '-' + byteToHex[buffer[6]] + byteToHex[buffer[7]] + '-' + byteToHex[buffer[8]] + byteToHex[buffer[9]] + '-' + byteToHex[buffer[10]] + byteToHex[buffer[11]] + byteToHex[buffer[12]] + byteToHex[buffer[13]] + byteToHex[buffer[14]] + byteToHex[buffer[15]]).toLowerCase();
204
+ }
189
205
  //# sourceMappingURL=random.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["random.ts"],"names":["NativeQuickCrypto","Buffer","random","randomFill","buffer","Error","callback","offset","size","byteLength","isBuffer","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,iB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;AAC1B;AACAU,IAAAA,sBAAsB,CAACiB,IAAvB,CAA4B;AAAEZ,MAAAA,GAAF;AAAOD,MAAAA,GAAP;AAAYxB,MAAAA;AAAZ,KAA5B;AACAsC,IAAAA,yBAAyB;AAC1B;AACF;;AAED,SAASA,yBAAT,GAAqC;AACnC,MAAInB,wBAAJ,EAA8B;AAE9BA,EAAAA,wBAAwB,GAAG,IAA3B;AACAtB,EAAAA,UAAU,CAACmB,WAAD,EAAeuB,GAAD,IAAS;AAC/BpB,IAAAA,wBAAwB,GAAG,KAA3B;AAEA,UAAMqB,KAAK,GAAGpB,sBAAd;AACA,UAAMqB,aAAa,GAAGF,GAAG,IAAIC,KAAK,CAACE,KAAN,EAA7B;AACA,QAAI,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,CAAC7C,QAA1B,CAAT;AACD,KAFD,EAX+B,CAe/B;;AACA,QAAIyC,aAAJ,EAAmBA,aAAa,CAACzC,QAAd,CAAuBuC,GAAvB,EAA4B,CAA5B;AACpB,GAjBS,CAAV;AAkBD,C,CAED;AACA;AACA;AACA;AACA;;;AAQA,OAAO,SAASO,eAAT,CAAyBC,IAAzB,EAAyC;AAC9C,MAAIA,IAAI,CAAC5C,UAAL,GAAkB,KAAtB,EAA6B;AAC3B,UAAM,IAAIJ,KAAJ,CAAU,2CAAV,CAAN;AACD;;AACDQ,EAAAA,cAAc,CAACwC,IAAD,EAAO,CAAP,CAAd;AACA,SAAOA,IAAP;AACD","sourcesContent":["import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';\nimport { Buffer } from '@craftzdog/react-native-buffer';\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(Buffer.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 = 0xffffffffffff;\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"]}
1
+ {"version":3,"sources":["random.ts"],"names":["NativeQuickCrypto","Buffer","random","randomFill","buffer","Error","callback","offset","size","byteLength","isBuffer","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","byteToHex","i","toString","slice","randomUUID","toLowerCase"],"mappings":"AAAA,SAASA,iBAAT,QAAkC,uCAAlC;AACA,SAASC,MAAT,QAAuB,gCAAvB;AAEA,MAAMC,MAAM,GAAGF,iBAAiB,CAACE,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,mDAAN;AACAC,IAAAA,IAAI,mDAAJ;AACD;;AAED,MAAI,8DAA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AC,CAAD,CAAN,GAAY,IAAb,GAAqB,IAAjC;AAEA,SAAO,CACLkD,SAAS,CAAClD,MAAM,CAAC,CAAD,CAAP,CAAT,GACAkD,SAAS,CAAClD,MAAM,CAAC,CAAD,CAAP,CADT,GAEAkD,SAAS,CAAClD,MAAM,CAAC,CAAD,CAAP,CAFT,GAGAkD,SAAS,CAAClD,MAAM,CAAC,CAAD,CAAP,CAHT,GAIA,GAJA,GAKAkD,SAAS,CAAClD,MAAM,CAAC,CAAD,CAAP,CALT,GAMAkD,SAAS,CAAClD,MAAM,CAAC,CAAD,CAAP,CANT,GAOA,GAPA,GAQAkD,SAAS,CAAClD,MAAM,CAAC,CAAD,CAAP,CART,GASAkD,SAAS,CAAClD,MAAM,CAAC,CAAD,CAAP,CATT,GAUA,GAVA,GAWAkD,SAAS,CAAClD,MAAM,CAAC,CAAD,CAAP,CAXT,GAYAkD,SAAS,CAAClD,MAAM,CAAC,CAAD,CAAP,CAZT,GAaA,GAbA,GAcAkD,SAAS,CAAClD,MAAM,CAAC,EAAD,CAAP,CAdT,GAeAkD,SAAS,CAAClD,MAAM,CAAC,EAAD,CAAP,CAfT,GAgBAkD,SAAS,CAAClD,MAAM,CAAC,EAAD,CAAP,CAhBT,GAiBAkD,SAAS,CAAClD,MAAM,CAAC,EAAD,CAAP,CAjBT,GAkBAkD,SAAS,CAAClD,MAAM,CAAC,EAAD,CAAP,CAlBT,GAmBAkD,SAAS,CAAClD,MAAM,CAAC,EAAD,CAAP,CApBJ,EAqBLuD,WArBK,EAAP;AAsBD","sourcesContent":["import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';\nimport { Buffer } from '@craftzdog/react-native-buffer';\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(Buffer.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 = 0xffffffffffff;\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\nconst byteToHex: string[] = [];\n\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\n\n// Based on https://github.com/uuidjs/uuid/blob/main/src/v4.js\nexport function randomUUID() {\n const size = 16;\n const buffer = new Buffer(size);\n randomFillSync(buffer, 0, size);\n\n // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n buffer[6] = (buffer[6] & 0x0f) | 0x40;\n buffer[8] = (buffer[8] & 0x3f) | 0x80;\n\n return (\n byteToHex[buffer[0]] +\n byteToHex[buffer[1]] +\n byteToHex[buffer[2]] +\n byteToHex[buffer[3]] +\n '-' +\n byteToHex[buffer[4]] +\n byteToHex[buffer[5]] +\n '-' +\n byteToHex[buffer[6]] +\n byteToHex[buffer[7]] +\n '-' +\n byteToHex[buffer[8]] +\n byteToHex[buffer[9]] +\n '-' +\n byteToHex[buffer[10]] +\n byteToHex[buffer[11]] +\n byteToHex[buffer[12]] +\n byteToHex[buffer[13]] +\n byteToHex[buffer[14]] +\n byteToHex[buffer[15]]\n ).toLowerCase();\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { BinaryLike } from 'src/Utils';
1
+ import type { BinaryLike } from '../Utils';
2
2
  import type { Buffer } from '@craftzdog/react-native-buffer';
3
3
  export declare enum RSAKeyVariant {
4
4
  kKeyVariantRSA_SSA_PKCS1_v1_5 = 0,
@@ -15,6 +15,7 @@ export declare const QuickCrypto: {
15
15
  randomInt(min: number, max: number, callback: (err: Error | null, value: number) => void): void;
16
16
  randomInt(min: number, max: number): number;
17
17
  getRandomValues(data: Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array): Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array;
18
+ randomUUID(): string;
18
19
  rng: typeof random.randomBytes;
19
20
  pseudoRandomBytes: typeof random.randomBytes;
20
21
  prng: typeof random.randomBytes;
@@ -15,6 +15,7 @@ declare const crypto: {
15
15
  randomInt(min: number, max: number, callback: (err: Error | null, value: number) => void): void;
16
16
  randomInt(min: number, max: number): number;
17
17
  getRandomValues(data: Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array): Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array;
18
+ randomUUID(): string;
18
19
  rng: typeof import("./random").randomBytes;
19
20
  pseudoRandomBytes: typeof import("./random").randomBytes;
20
21
  prng: typeof import("./random").randomBytes;
@@ -173,7 +174,6 @@ declare const crypto: {
173
174
  hkdf(digest: string, irm: FallbackCrypto.KeyObject | FallbackCrypto.BinaryLike, salt: FallbackCrypto.BinaryLike, info: FallbackCrypto.BinaryLike, keylen: number, callback: (err: Error | null, derivedKey: ArrayBuffer) => void): void;
174
175
  hkdfSync(digest: string, ikm: FallbackCrypto.KeyObject | FallbackCrypto.BinaryLike, salt: FallbackCrypto.BinaryLike, info: FallbackCrypto.BinaryLike, keylen: number): ArrayBuffer;
175
176
  secureHeapUsed(): FallbackCrypto.SecureHeapUsage;
176
- randomUUID(options?: FallbackCrypto.RandomUUIDOptions | undefined): string;
177
177
  generatePrime(size: number, callback: (err: Error | null, prime: ArrayBuffer) => void): void;
178
178
  generatePrime(size: number, options: FallbackCrypto.GeneratePrimeOptionsBigInt, callback: (err: Error | null, prime: bigint) => void): void;
179
179
  generatePrime(size: number, options: FallbackCrypto.GeneratePrimeOptionsArrayBuffer, callback: (err: Error | null, prime: ArrayBuffer) => void): void;
@@ -17,4 +17,5 @@ export declare function randomInt(min: number, max: number, callback: RandomIntC
17
17
  export declare function randomInt(min: number, max: number): number;
18
18
  declare type DataType = Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array;
19
19
  export declare function getRandomValues(data: DataType): DataType;
20
+ export declare function randomUUID(): string;
20
21
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-quick-crypto",
3
- "version": "0.4.6",
3
+ "version": "0.6.0",
4
4
  "description": "A fast implementation of Node's `crypto` module written in C/C++ JSI",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -50,23 +50,23 @@
50
50
  },
51
51
  "devDependencies": {
52
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",
53
+ "@react-native-community/eslint-config": "^3.2.0",
54
+ "@react-native-community/eslint-plugin": "^1.3.0",
55
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.28.0",
59
- "eslint": "^8.17.0",
56
+ "@types/react": "^18.0.33",
57
+ "@typescript-eslint/eslint-plugin": "^5.57.1",
58
+ "eslint": "^8.37.0",
59
+ "eslint-plugin-ft-flow": "^2.0.3",
60
60
  "prettier": "^2.4.0",
61
- "react": "^17.0.2",
62
- "react-native": "^0.66.0",
61
+ "react": "^18.2.0",
62
+ "react-native": "^0.71.6",
63
63
  "react-native-builder-bob": "^0.18.1",
64
64
  "release-it": "^14.11.5",
65
- "typescript": "^4.7.4"
65
+ "typescript": "4.8.4"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "react": "*",
69
- "react-native": "*"
69
+ "react-native": ">=0.71.0"
70
70
  },
71
71
  "release-it": {
72
72
  "git": {
@@ -130,6 +130,9 @@
130
130
  "globals": {
131
131
  "BufferEncoding": true,
132
132
  "Buffer": true
133
+ },
134
+ "parserOptions": {
135
+ "requireConfigFile": false
133
136
  }
134
137
  },
135
138
  "eslintIgnore": [
@@ -158,12 +161,12 @@
158
161
  ]
159
162
  },
160
163
  "dependencies": {
161
- "@craftzdog/react-native-buffer": "^6.0.4",
164
+ "@craftzdog/react-native-buffer": "^6.0.5",
162
165
  "@types/node": "^17.0.31",
166
+ "crypto-browserify": "^3.12.0",
163
167
  "events": "^3.3.0",
164
- "react-native-quick-base64": "^2.0.2",
168
+ "react-native-quick-base64": "^2.0.5",
165
169
  "stream-browserify": "^3.0.0",
166
- "string_decoder": "^1.3.0",
167
- "crypto-browserify": "^3.12.0"
170
+ "string_decoder": "^1.3.0"
168
171
  }
169
172
  }
package/src/Cipher.ts CHANGED
@@ -749,7 +749,6 @@ export function generateKeyPairSync(
749
749
  type: string,
750
750
  options?: GenerateKeyPairOptions
751
751
  ): { publicKey: any; privateKey: any } {
752
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
753
752
  const [_, publicKey, privateKey] = internalGenerateKeyPair(
754
753
  false,
755
754
  type,
@@ -1,4 +1,4 @@
1
- import type { BinaryLike } from 'src/Utils';
1
+ import type { BinaryLike } from '../Utils';
2
2
  import type { Buffer } from '@craftzdog/react-native-buffer';
3
3
 
4
4
  // TODO(osp) on node this is defined on the native side
package/src/random.ts CHANGED
@@ -274,3 +274,43 @@ export function getRandomValues(data: DataType) {
274
274
  randomFillSync(data, 0);
275
275
  return data;
276
276
  }
277
+
278
+ const byteToHex: string[] = [];
279
+
280
+ for (let i = 0; i < 256; ++i) {
281
+ byteToHex.push((i + 0x100).toString(16).slice(1));
282
+ }
283
+
284
+ // Based on https://github.com/uuidjs/uuid/blob/main/src/v4.js
285
+ export function randomUUID() {
286
+ const size = 16;
287
+ const buffer = new Buffer(size);
288
+ randomFillSync(buffer, 0, size);
289
+
290
+ // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
291
+ buffer[6] = (buffer[6] & 0x0f) | 0x40;
292
+ buffer[8] = (buffer[8] & 0x3f) | 0x80;
293
+
294
+ return (
295
+ byteToHex[buffer[0]] +
296
+ byteToHex[buffer[1]] +
297
+ byteToHex[buffer[2]] +
298
+ byteToHex[buffer[3]] +
299
+ '-' +
300
+ byteToHex[buffer[4]] +
301
+ byteToHex[buffer[5]] +
302
+ '-' +
303
+ byteToHex[buffer[6]] +
304
+ byteToHex[buffer[7]] +
305
+ '-' +
306
+ byteToHex[buffer[8]] +
307
+ byteToHex[buffer[9]] +
308
+ '-' +
309
+ byteToHex[buffer[10]] +
310
+ byteToHex[buffer[11]] +
311
+ byteToHex[buffer[12]] +
312
+ byteToHex[buffer[13]] +
313
+ byteToHex[buffer[14]] +
314
+ byteToHex[buffer[15]]
315
+ ).toLowerCase();
316
+ }
package/android/.DS_Store DELETED
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/cpp/.DS_Store DELETED
Binary file
package/ios/.DS_Store DELETED
Binary file
package/lib/.DS_Store DELETED
Binary file
package/src/.DS_Store DELETED
Binary file