@dubsdotapp/expo 0.2.51 → 0.2.53
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/README.md +14 -1
- package/dist/index.js +14 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
- package/src/index.ts +3 -0
- package/src/polyfill.ts +23 -0
- package/src/wallet/phantom-deeplink/crypto.ts +0 -45
- package/src/wallet/phantom-deeplink/ensure-self.ts +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dubsdotapp/expo",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.53",
|
|
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
|
-
"
|
|
33
|
-
"react-native": ">=0.72.0",
|
|
33
|
+
"expo-device": ">=6.0.0",
|
|
34
34
|
"expo-secure-store": ">=13.0.0",
|
|
35
|
-
"
|
|
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
package/src/polyfill.ts
ADDED
|
@@ -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,49 +1,6 @@
|
|
|
1
|
-
import './ensure-self';
|
|
2
1
|
import nacl from 'tweetnacl';
|
|
3
2
|
import bs58 from 'bs58';
|
|
4
3
|
|
|
5
|
-
// ── Lazy PRNG fallback ──
|
|
6
|
-
// If tweetnacl's own init didn't find crypto (e.g. self polyfill didn't help,
|
|
7
|
-
// or globalThis.crypto wasn't ready at module eval time), configure PRNG
|
|
8
|
-
// on first use — by that time the Hermes runtime is fully initialized.
|
|
9
|
-
let prngChecked = false;
|
|
10
|
-
|
|
11
|
-
function ensurePRNG(): void {
|
|
12
|
-
if (prngChecked) return;
|
|
13
|
-
prngChecked = true;
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
nacl.randomBytes(1);
|
|
17
|
-
return; // Already works
|
|
18
|
-
} catch {
|
|
19
|
-
// PRNG not configured — try fallbacks
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Try globalThis.crypto (Hermes / RN 0.76+)
|
|
23
|
-
const g = typeof globalThis !== 'undefined' ? globalThis : undefined;
|
|
24
|
-
if (g?.crypto?.getRandomValues) {
|
|
25
|
-
nacl.setPRNG((x: Uint8Array, n: number) => {
|
|
26
|
-
const v = new Uint8Array(n);
|
|
27
|
-
g.crypto.getRandomValues(v);
|
|
28
|
-
for (let i = 0; i < n; i++) x[i] = v[i];
|
|
29
|
-
});
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Try expo-crypto
|
|
34
|
-
try {
|
|
35
|
-
const { getRandomValues } = require('expo-crypto');
|
|
36
|
-
nacl.setPRNG((x: Uint8Array, n: number) => {
|
|
37
|
-
const v = new Uint8Array(n);
|
|
38
|
-
getRandomValues(v);
|
|
39
|
-
for (let i = 0; i < n; i++) x[i] = v[i];
|
|
40
|
-
});
|
|
41
|
-
return;
|
|
42
|
-
} catch {}
|
|
43
|
-
|
|
44
|
-
console.error('[Dubs] No PRNG available — crypto operations will fail. Install expo-crypto or use Hermes.');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
4
|
export interface KeyPair {
|
|
48
5
|
publicKey: Uint8Array;
|
|
49
6
|
secretKey: Uint8Array;
|
|
@@ -51,7 +8,6 @@ export interface KeyPair {
|
|
|
51
8
|
|
|
52
9
|
/** Generate an x25519 keypair for Diffie-Hellman key exchange with Phantom. */
|
|
53
10
|
export function generateKeyPair(): KeyPair {
|
|
54
|
-
ensurePRNG();
|
|
55
11
|
const kp = nacl.box.keyPair();
|
|
56
12
|
return { publicKey: kp.publicKey, secretKey: kp.secretKey };
|
|
57
13
|
}
|
|
@@ -69,7 +25,6 @@ export function encryptPayload(
|
|
|
69
25
|
payload: object,
|
|
70
26
|
sharedSecret: Uint8Array,
|
|
71
27
|
): { nonce: string; ciphertext: string } {
|
|
72
|
-
ensurePRNG();
|
|
73
28
|
const nonce = nacl.randomBytes(24);
|
|
74
29
|
const message = new TextEncoder().encode(JSON.stringify(payload));
|
|
75
30
|
const encrypted = nacl.box.after(message, nonce, sharedSecret);
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// Ensure `self` is defined for tweetnacl's PRNG initialization.
|
|
2
|
-
// tweetnacl checks `self.crypto.getRandomValues` at import time.
|
|
3
|
-
// In React Native custom dev builds, `self` may not be set, but
|
|
4
|
-
// Hermes (RN 0.76+) provides `globalThis.crypto`. Bridge the gap.
|
|
5
|
-
if (typeof self === 'undefined') {
|
|
6
|
-
if (typeof globalThis !== 'undefined') {
|
|
7
|
-
(globalThis as any).self = globalThis;
|
|
8
|
-
}
|
|
9
|
-
}
|