rsnext/packages/next/server/web/sandbox/polyfills.ts

22 lines
672 B
TypeScript
Raw Normal View History

import { Crypto as WebCrypto } from 'next/dist/compiled/@peculiar/webcrypto'
import { CryptoKey } from 'next/dist/compiled/@peculiar/webcrypto'
import { v4 as uuid } from 'next/dist/compiled/uuid'
import { ReadableStream } from './readable-stream'
import crypto from 'crypto'
export function atob(b64Encoded: string) {
return Buffer.from(b64Encoded, 'base64').toString('binary')
}
export function btoa(str: string) {
return Buffer.from(str, 'binary').toString('base64')
}
export { CryptoKey, ReadableStream }
export class Crypto extends WebCrypto {
// @ts-ignore Remove once types are updated and we deprecate node 12
randomUUID = crypto.randomUUID || uuid
}