about summary refs log tree commit diff
path: root/src/platform/polyfills.native.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2022-06-15 17:40:18 -0500
committerPaul Frazee <pfrazee@gmail.com>2022-06-15 17:40:18 -0500
commit77b938845aa909a70f896b759b04ba7c1b1d9aa6 (patch)
tree0d5f65c3efa2c7702f4c5eee024248b73ec36f07 /src/platform/polyfills.native.ts
parentb2dd8d4f440243ac2eb12e7013d5a024b4e95f07 (diff)
downloadvoidsky-77b938845aa909a70f896b759b04ba7c1b1d9aa6.tar.zst
Polyfills for native crypto
Diffstat (limited to 'src/platform/polyfills.native.ts')
-rw-r--r--src/platform/polyfills.native.ts21
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