commit
4bf2fbf985
|
@ -79,8 +79,10 @@ module.exports = {
|
||||||
if (!(buf instanceof Uint8Array)) {
|
if (!(buf instanceof Uint8Array)) {
|
||||||
throw new Error('Invalid type: buf not an Uint8Array');
|
throw new Error('Invalid type: buf not an Uint8Array');
|
||||||
}
|
}
|
||||||
if (typeof window !== 'undefined' && window.crypto) {
|
if (typeof window !== 'undefined' && window.crypto && window.crypto.getRandomValues) {
|
||||||
window.crypto.getRandomValues(buf);
|
window.crypto.getRandomValues(buf);
|
||||||
|
} else if (typeof window !== 'undefined' && typeof window.msCrypto === 'object' && typeof window.msCrypto.getRandomValues === 'function') {
|
||||||
|
window.msCrypto.getRandomValues(buf);
|
||||||
} else if (nodeCrypto) {
|
} else if (nodeCrypto) {
|
||||||
var bytes = nodeCrypto.randomBytes(buf.length);
|
var bytes = nodeCrypto.randomBytes(buf.length);
|
||||||
buf.set(bytes);
|
buf.set(bytes);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user