mirror of
https://github.com/cupcakearmy/occulto.git
synced 2025-09-06 22:10:45 +00:00
* rewrite * testing worklflow * sprcify version * config stuff * add hash as buffer * delete docs * use typedarray everywhere and docs * readme * aes * cleanup * rsa * testing with playwright * fix playwright * readme * docs * update deps * use headless * add prepublish * build pipeline * move types up * move types up * add types legacy * packaging * versions bump * cleanup * maybe this time * drop support for commonjs * version bump * cleanup
21 lines
543 B
TypeScript
21 lines
543 B
TypeScript
import { isBrowser } from '../utils/base.js'
|
|
|
|
let crypto: typeof window.crypto | null = null
|
|
|
|
export async function getCrypto(): Promise<typeof window.crypto> {
|
|
if (!crypto) {
|
|
if (isBrowser) crypto = window.crypto
|
|
else if (typeof require !== 'undefined') {
|
|
const { webcrypto } = await require('crypto')
|
|
crypto = webcrypto
|
|
} else {
|
|
// @ts-ignore
|
|
const { webcrypto } = await import('crypto')
|
|
crypto = webcrypto as any
|
|
}
|
|
}
|
|
|
|
if (!crypto) throw new Error('No crypto available')
|
|
return crypto
|
|
}
|