mirror of
https://github.com/Instadapp/Swap-Aggregator-Subgraph.git
synced 2024-07-29 21:57:12 +00:00
24 lines
710 B
JavaScript
Executable File
24 lines
710 B
JavaScript
Executable File
export function getRandomValues(buf) {
|
|
if (typeof process !== 'undefined') {
|
|
var nodeCrypto = require('crypto');
|
|
var bytes = nodeCrypto.randomBytes(buf.length);
|
|
buf.set(bytes);
|
|
return;
|
|
}
|
|
if (window.crypto && window.crypto.getRandomValues) {
|
|
window.crypto.getRandomValues(buf);
|
|
return;
|
|
}
|
|
if (self.crypto && self.crypto.getRandomValues) {
|
|
self.crypto.getRandomValues(buf);
|
|
return;
|
|
}
|
|
// @ts-ignore
|
|
if (window.msCrypto && window.msCrypto.getRandomValues) {
|
|
// @ts-ignore
|
|
window.msCrypto.getRandomValues(buf);
|
|
return;
|
|
}
|
|
throw new Error('No secure random number generator available.');
|
|
}
|