Browse Source

Change randomize method from Math.random to Crypto

master
Eduard Kuzmenko 3 years ago
parent
commit
e976d1c5bc
  1. 5
      src/lib/polyfill.ts

5
src/lib/polyfill.ts

@ -23,9 +23,14 @@ Object.defineProperty(Uint8Array.prototype, 'hex', {
Uint8Array.prototype.randomize = function() { Uint8Array.prototype.randomize = function() {
//secureRandom.nextBytes(this); //secureRandom.nextBytes(this);
if(crypto && 'getRandomValues' in crypto) {
crypto.getRandomValues(this);
} else {
for(let i = 0; i < this.length; ++i) { for(let i = 0; i < this.length; ++i) {
this[i] = nextRandomInt(255); this[i] = nextRandomInt(255);
} }
}
return this; return this;
}; };

Loading…
Cancel
Save