@oxyhq/services 5.15.6 → 5.15.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,10 @@
3
3
  *
4
4
  * This file ensures that required polyfills are available
5
5
  * before any crypto operations are performed.
6
+ *
7
+ * Polyfills included:
8
+ * - Buffer: Required by bip39 and other crypto libraries
9
+ * - crypto.getRandomValues: Required by bip39 for secure random number generation
6
10
  */
7
11
 
8
12
  // Import Buffer polyfill for React Native compatibility
@@ -18,11 +22,59 @@ const getGlobalObject = (): typeof globalThis => {
18
22
  return {} as typeof globalThis;
19
23
  };
20
24
 
21
- // Make Buffer available globally for libraries that depend on it
22
25
  const globalObject = getGlobalObject();
26
+
27
+ // Make Buffer available globally for libraries that depend on it
23
28
  if (!globalObject.Buffer) {
24
29
  (globalObject as unknown as { Buffer: typeof Buffer }).Buffer = Buffer;
25
30
  }
26
31
 
32
+ // Polyfill crypto.getRandomValues for React Native
33
+ // This is required by bip39 and other crypto libraries
34
+ type CryptoLike = {
35
+ getRandomValues: <T extends ArrayBufferView>(array: T) => T;
36
+ };
37
+
38
+ // Cache for expo-crypto module
39
+ let expoCryptoModule: typeof import('expo-crypto') | null = null;
40
+
41
+ /**
42
+ * Get random bytes using expo-crypto (synchronous)
43
+ * This is a synchronous wrapper that loads expo-crypto lazily
44
+ */
45
+ function getRandomBytesSync(byteCount: number): Uint8Array {
46
+ if (!expoCryptoModule) {
47
+ // Try to require expo-crypto synchronously
48
+ try {
49
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
50
+ expoCryptoModule = require('expo-crypto');
51
+ } catch {
52
+ throw new Error('expo-crypto is required for crypto.getRandomValues polyfill');
53
+ }
54
+ }
55
+ // TypeScript guard - expoCryptoModule is guaranteed to be non-null here
56
+ const cryptoModule = expoCryptoModule;
57
+ if (!cryptoModule) {
58
+ throw new Error('Failed to load expo-crypto module');
59
+ }
60
+ return cryptoModule.getRandomBytes(byteCount);
61
+ }
62
+
63
+ const cryptoPolyfill: CryptoLike = {
64
+ getRandomValues<T extends ArrayBufferView>(array: T): T {
65
+ const bytes = getRandomBytesSync(array.byteLength);
66
+ const uint8View = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
67
+ uint8View.set(bytes);
68
+ return array;
69
+ },
70
+ };
71
+
72
+ // Only polyfill if crypto or crypto.getRandomValues is not available
73
+ if (typeof globalObject.crypto === 'undefined') {
74
+ (globalObject as unknown as { crypto: CryptoLike }).crypto = cryptoPolyfill;
75
+ } else if (typeof globalObject.crypto.getRandomValues !== 'function') {
76
+ (globalObject.crypto as CryptoLike).getRandomValues = cryptoPolyfill.getRandomValues;
77
+ }
78
+
27
79
  // Re-export Buffer for convenience
28
80
  export { Buffer };
@@ -287,7 +287,7 @@ const TextField = forwardRef<TextFieldHandles, Props>(
287
287
  height: null,
288
288
  });
289
289
 
290
- const timer = React.useRef<NodeJS.Timeout | undefined>(undefined);
290
+ const timer = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
291
291
  const root = React.useRef<NativeTextInput | undefined | null>(null);
292
292
 
293
293
  const { scale } = theme.animation;
@@ -339,7 +339,7 @@ const TextField = forwardRef<TextFieldHandles, Props>(
339
339
  timer.current = setTimeout(
340
340
  () => setDisplayPlaceholder(true),
341
341
  50
342
- ) as unknown as NodeJS.Timeout;
342
+ );
343
343
  }
344
344
  } else {
345
345
  // hidePlaceholder
@@ -314,7 +314,7 @@ const AccountSettingsScreen: React.FC<BaseScreenProps & { initialField?: string;
314
314
  // Use a ref to track if we've already set the initial field to avoid loops
315
315
  const hasSetInitialFieldRef = useRef(false);
316
316
  const previousInitialFieldRef = useRef<string | undefined>(undefined);
317
- const initialFieldTimeoutRef = useRef<NodeJS.Timeout | null>(null);
317
+ const initialFieldTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
318
318
 
319
319
  // Delay constant for scroll completion
320
320
  const SCROLL_DELAY_MS = 600;
@@ -1,9 +0,0 @@
1
- declare module 'expo-random' {
2
- export interface RandomOptions {
3
- byteCount?: number;
4
- }
5
-
6
- export function getRandomBytes(byteCount: number): Uint8Array;
7
- export function getRandomBytesAsync(byteCount: number): Promise<Uint8Array>;
8
- }
9
-
@@ -1,9 +0,0 @@
1
- declare module 'expo-random' {
2
- export interface RandomOptions {
3
- byteCount?: number;
4
- }
5
-
6
- export function getRandomBytes(byteCount: number): Uint8Array;
7
- export function getRandomBytesAsync(byteCount: number): Promise<Uint8Array>;
8
- }
9
-