diff options
author | Paul Frazee <pfrazee@gmail.com> | 2022-06-15 17:40:18 -0500 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2022-06-15 17:40:18 -0500 |
commit | 77b938845aa909a70f896b759b04ba7c1b1d9aa6 (patch) | |
tree | 0d5f65c3efa2c7702f4c5eee024248b73ec36f07 /src/platform/polyfills.native.ts | |
parent | b2dd8d4f440243ac2eb12e7013d5a024b4e95f07 (diff) | |
download | voidsky-77b938845aa909a70f896b759b04ba7c1b1d9aa6.tar.zst |
Polyfills for native crypto
Diffstat (limited to 'src/platform/polyfills.native.ts')
-rw-r--r-- | src/platform/polyfills.native.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/platform/polyfills.native.ts b/src/platform/polyfills.native.ts new file mode 100644 index 000000000..b4d38f04f --- /dev/null +++ b/src/platform/polyfills.native.ts @@ -0,0 +1,21 @@ +import {generateSecureRandom} from 'react-native-securerandom' +import crypto from 'msrcrypto' +import '@zxing/text-encoding' // TextEncoder / TextDecoder + +export const whenWebCrypto = new Promise(async (resolve, reject) => { + try { + const bytes = await generateSecureRandom(48) + crypto.initPrng(Array.from(bytes)) + + // @ts-ignore global.window exists -prf + if (!global.window.crypto) { + // @ts-ignore global.window exists -prf + global.window.crypto = crypto + } + resolve(true) + } catch (e: any) { + reject(e) + } +}) + +export const webcrypto = crypto |