UNPKG

get-random-values-polypony

Version:

Synchronous randombytes function that works in node, the browser & react-native!

2 lines 1.07 kB
const BigInt64Array=global.BigInt64Array||class{},BigUint64Array=global.BigUint64Array||class{};module.exports=function(getRandomValues){const name=getRandomValues.name+"Limited",impl=function(input){// Quick checking for most common case if(!(input instanceof Uint8Array)){let wrongType;if(input instanceof Float32Array?wrongType="Float32":input instanceof Float64Array?wrongType="Float64":input instanceof DataView?wrongType="DataView":input instanceof BigInt64Array?wrongType="BigInt64":input instanceof BigUint64Array&&(wrongType="BigUint64"),void 0!==wrongType)throw new Error("Failed to execute 'getRandomValues' on 'Crypto': The provided ArrayBufferView is of type '"+wrongType+"', which is not an integer array type.")}if("byteLength"in input&&65536<input.byteLength)throw new Error("Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length ("+input.byteLength+") exceeds the number of bytes of entropy available via this API (65536).");return getRandomValues(input)};return Object.defineProperty(impl,"name",{value:name,writable:!1}),impl};