Polyfills for native crypto
This commit is contained in:
parent
b2dd8d4f44
commit
77b938845a
15 changed files with 243 additions and 81 deletions
21
src/platform/polyfills.native.ts
Normal file
21
src/platform/polyfills.native.ts
Normal 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
|
1
src/platform/polyfills.web.ts
Normal file
1
src/platform/polyfills.web.ts
Normal file
|
@ -0,0 +1 @@
|
|||
// do nothing
|
Loading…
Add table
Add a link
Reference in a new issue