diff options
Diffstat (limited to 'src/platform')
-rw-r--r-- | src/platform/polyfills.native.ts | 21 | ||||
-rw-r--r-- | src/platform/polyfills.web.ts | 1 |
2 files changed, 22 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 diff --git a/src/platform/polyfills.web.ts b/src/platform/polyfills.web.ts new file mode 100644 index 000000000..c6035e5e3 --- /dev/null +++ b/src/platform/polyfills.web.ts @@ -0,0 +1 @@ +// do nothing |