@dubsdotapp/expo 0.2.50 → 0.2.52

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dubsdotapp/expo",
3
- "version": "0.2.50",
3
+ "version": "0.2.52",
4
4
  "description": "React Native SDK for the Dubs betting platform",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -25,14 +25,15 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "bs58": "^5.0.0",
28
+ "expo-crypto": "~14.0.0",
28
29
  "tweetnacl": "^1.0.3"
29
30
  },
30
31
  "peerDependencies": {
31
32
  "@solana/web3.js": "^1.90.0",
32
- "react": ">=18.0.0",
33
- "react-native": ">=0.72.0",
33
+ "expo-device": ">=6.0.0",
34
34
  "expo-secure-store": ">=13.0.0",
35
- "expo-device": ">=6.0.0"
35
+ "react": ">=18.0.0",
36
+ "react-native": ">=0.72.0"
36
37
  },
37
38
  "peerDependenciesMeta": {
38
39
  "expo-secure-store": {
@@ -48,8 +49,8 @@
48
49
  "devDependencies": {
49
50
  "@solana/web3.js": "^1.95.0",
50
51
  "@types/react": "^18.2.0",
51
- "react": "^18.2.0",
52
52
  "expo-device": "^7.0.0",
53
+ "react": "^18.2.0",
53
54
  "react-native": "^0.73.0",
54
55
  "tsup": "^8.0.0",
55
56
  "typescript": "^5.3.0"
package/src/index.ts CHANGED
@@ -1,3 +1,6 @@
1
+ // Polyfill crypto.getRandomValues before anything else
2
+ import './polyfill';
3
+
1
4
  // Core
2
5
  export { DubsClient } from './client';
3
6
  export type { DubsClientConfig } from './client';
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Polyfill crypto.getRandomValues for React Native environments.
3
+ *
4
+ * This runs once at SDK import time, before tweetnacl, @solana/web3.js,
5
+ * uuid, jayson, or any other dependency tries to use crypto.
6
+ *
7
+ * Must be imported as the very first line in src/index.ts.
8
+ */
9
+ import { getRandomValues } from 'expo-crypto';
10
+
11
+ if (typeof global !== 'undefined') {
12
+ if (typeof global.crypto !== 'object') {
13
+ (global as any).crypto = {};
14
+ }
15
+ if (typeof global.crypto.getRandomValues !== 'function') {
16
+ (global.crypto as any).getRandomValues = getRandomValues;
17
+ }
18
+ }
19
+
20
+ // Also polyfill `self` so tweetnacl's init finds crypto via self.crypto
21
+ if (typeof self === 'undefined' && typeof globalThis !== 'undefined') {
22
+ (globalThis as any).self = globalThis;
23
+ }
@@ -1,35 +1,6 @@
1
1
  import nacl from 'tweetnacl';
2
2
  import bs58 from 'bs58';
3
3
 
4
- // tweetnacl checks self.crypto.getRandomValues at import time.
5
- // In some React Native environments this isn't set up yet.
6
- // Ensure PRNG is configured before any crypto operations.
7
- try {
8
- nacl.randomBytes(1);
9
- } catch {
10
- // Try globalThis.crypto (available in Hermes / RN 0.76+)
11
- const g = typeof globalThis !== 'undefined' ? globalThis : (typeof self !== 'undefined' ? self : undefined);
12
- if (g?.crypto?.getRandomValues) {
13
- nacl.setPRNG((x: Uint8Array, n: number) => {
14
- const v = new Uint8Array(n);
15
- g.crypto.getRandomValues(v);
16
- for (let i = 0; i < n; i++) x[i] = v[i];
17
- });
18
- } else {
19
- // Try expo-crypto as fallback
20
- try {
21
- const { getRandomValues } = require('expo-crypto');
22
- nacl.setPRNG((x: Uint8Array, n: number) => {
23
- const v = new Uint8Array(n);
24
- getRandomValues(v);
25
- for (let i = 0; i < n; i++) x[i] = v[i];
26
- });
27
- } catch {
28
- // PRNG will throw when used — unavoidable without a crypto source
29
- }
30
- }
31
- }
32
-
33
4
  export interface KeyPair {
34
5
  publicKey: Uint8Array;
35
6
  secretKey: Uint8Array;