Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Commit 449c8cb

Browse files
committed
fix(crypto.js): 'getRandomValues()' must be called on 'crypto' object
1 parent 96ddcf6 commit 449c8cb

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

crypto.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@
88
import { Buffer } from 'buffer'
99

1010
const parent = typeof window === 'object' ? window : globalThis
11-
12-
// private global deps
13-
const { getRandomValues } = (parent.crypto ?? {})
14-
11+
const { crypto } = parent
1512

1613
/*
1714
* @param {number} size - The number of bytes to generate. The size must not be larger than 2**31 - 1.
1815
* @returns {Promise<Buffer>} - A promise that resolves with an instance of io.Buffer with random bytes.
1916
*/
2017
export function randomBytes (size) {
2118
const tmp = new Uint8Array(size)
22-
const bytes = getRandomValues(tmp)
19+
const bytes = crypto.getRandomValues(tmp)
2320
return Buffer.from(bytes)
2421
}
2522

0 commit comments

Comments
 (0)