Skip to content

Commit

Permalink
fix getRandomValues return value (tradle#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvayngrib committed Sep 25, 2017
1 parent 637fde6 commit daec565
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Expand Up @@ -7,7 +7,8 @@ exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = r
if (typeof window === 'object') {
if (!window.crypto) window.crypto = {}
if (!window.crypto.getRandomValues) {
window.crypto.getRandomValues = function (arr) {
window.crypto.getRandomValues = function getRandomValues (arr) {
let orig = arr
if (arr.byteLength != arr.length) {
// Get access to the underlying raw bytes
arr = new Uint8Array(arr.buffer)
Expand All @@ -16,6 +17,8 @@ if (typeof window === 'object') {
for (var i = 0; i < bytes.length; i++) {
arr[i] = bytes[i]
}

return orig
}
}
}
Expand Down

0 comments on commit daec565

Please sign in to comment.