about summary refs log tree commit diff
path: root/src/platform/polyfills.native.ts
blob: b4d38f04fb7eaf80e675359c8cf4d8b9eeedbc4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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