Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/secure-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ function secureRandom(count, options) {
if (typeof process != 'undefined' && typeof process.pid == 'number') {
return nodeRandom(count, options)
} else {
var crypto = window.crypto || window.msCrypto
var crypto;
if(typeof window !== 'undefined'){
crypto = window.crypto || window.msCrypto;
}
else if(self){
crypto = self.crypto || self.msCrypto;
}

if (!crypto) throw new Error("Your browser does not support window.crypto.")
return browserRandom(count, options)
}
Expand All @@ -46,7 +53,13 @@ function nodeRandom(count, options) {

function browserRandom(count, options) {
var nativeArr = new Uint8Array(count)
var crypto = window.crypto || window.msCrypto
var crypto;
if(typeof window !== 'undefined'){
crypto = window.crypto || window.msCrypto;
}
else if(self){
crypto = self.crypto || self.msCrypto;
}
crypto.getRandomValues(nativeArr)

switch (options.type) {
Expand Down