diff --git a/apps/android/src/polyfills.ts b/apps/android/src/polyfills.ts new file mode 100644 index 0000000..421fcb0 --- /dev/null +++ b/apps/android/src/polyfills.ts @@ -0,0 +1,17 @@ +import * as ExpoCrypto from 'expo-crypto' + +// Noble's browser builds resolve the Web Crypto random source while their +// modules are being evaluated. Install the native Expo implementation before +// importing App (and therefore before importing @dsh-remote/crypto). +const currentCrypto = globalThis.crypto + +if (currentCrypto?.getRandomValues === undefined) { + Object.defineProperty(globalThis, 'crypto', { + value: { + ...currentCrypto, + getRandomValues: ExpoCrypto.getRandomValues, + randomUUID: ExpoCrypto.randomUUID, + }, + configurable: true, + }) +}