Skip to content

Commit

Permalink
Fix crypto polyfill (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Jun 6, 2024
1 parent c27fd55 commit 9c8f010
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions extension/src/crypto-polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import * as crypto from 'crypto'

globalThis.crypto = {
getRandomValues: (buffer: Buffer) => {
const buf = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength)
if (!(buf instanceof Uint8Array)) {
throw new TypeError('expected Uint8Array')
}
if (buf.length > 65536) {
const e = new Error()
// @ts-expect-error
e.code = 22
e.message = `Failed to execute 'getRandomValues' on 'Crypto': The 'ArrayBufferView's byte length (${buf.length}) exceeds the number of bytes of entropy available via this API (65536).`
e.name = 'QuotaExceededError'
throw e
}
const bytes = crypto.randomBytes(buf.length)
buf.set(bytes)
return buf
}
} as any
if (globalThis.crypto == null) {
Object.defineProperty(globalThis, 'crypto', {
value: crypto
})
}

0 comments on commit 9c8f010

Please sign in to comment.