Skip to content

Commit

Permalink
add fallback for randombytes
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Jul 10, 2024
1 parent d34f502 commit 0568e55
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ function equalConstTime(b1: Buffer, b2: Buffer): boolean {
not, since the functions are different and does
not convert using browserify */
function randomBytes(size: number): Buffer {
if (typeof browserCrypto.getRandomValues === "undefined") {
return Buffer.from(browserCrypto.randomBytes(size));
}
const arr = new Uint8Array(size);
browserCrypto.getRandomValues(arr);
return Buffer.from(arr);
Expand Down

0 comments on commit 0568e55

Please sign in to comment.