Polyfills for native crypto

This commit is contained in:
Paul Frazee 2022-06-15 17:40:18 -05:00
parent b2dd8d4f44
commit 77b938845a
15 changed files with 243 additions and 81 deletions

View file

@ -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

View file

@ -0,0 +1 @@
// do nothing