Fix crypto.random.getRandomBytes when loading openpgp.js inside a worker (#997)

This commit is contained in:
descampsk 2019-10-25 13:20:54 +02:00 committed by Daniel Huigens
parent 114184c6f2
commit 810b8daab2

View File

@ -39,8 +39,8 @@ export default {
*/
getRandomBytes: async function(length) {
const buf = new Uint8Array(length);
if (typeof window !== 'undefined' && window.crypto && window.crypto.getRandomValues) {
window.crypto.getRandomValues(buf);
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
crypto.getRandomValues(buf);
} else if (typeof window !== 'undefined' && typeof window.msCrypto === 'object' && typeof window.msCrypto.getRandomValues === 'function') {
window.msCrypto.getRandomValues(buf);
} else if (nodeCrypto) {