ethers.js/packages/crypto/lib/random.js
2022-04-11 17:14:19 -04:00

19 lines
572 B
JavaScript

import { randomBytes as crypto_random } from "crypto"; /*-browser*/
let locked = false;
const _randomBytes = function (length) {
return new Uint8Array(crypto_random(length));
};
let __randomBytes = _randomBytes;
export function randomBytes(length) {
return __randomBytes(length);
}
randomBytes._ = _randomBytes;
randomBytes.lock = function () { locked = true; };
randomBytes.register = function (func) {
if (locked) {
throw new Error("random is locked");
}
__randomBytes = func;
};
Object.freeze(randomBytes);
//# sourceMappingURL=random.js.map