Skip to content

Commit 03c3154

Browse files
committed
Fix rn bare example
1 parent bdedbaf commit 03c3154

File tree

7 files changed

+2842
-5385
lines changed

7 files changed

+2842
-5385
lines changed

demo/rn-bare-example/App.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ const redirectUrl = `${scheme}://auth`;
2525
// IMP END - Whitelist bundle ID
2626

2727
// IMP START - Dashboard Registration
28-
const clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ"; // get from https://dashboard.web3auth.io
28+
const clientId = "BCfIbiMcEwBkmyNxwn-DcYIfUU4QrpQgyOZZTNi5f_ygWMS1g_dNcuxylwDkIbVNhDtn7dAs-aMUhX0dtAYhvWk"; // get from https://dashboard.web3auth.io
2929
// IMP END - Dashboard Registration
3030

3131
// IMP START - SDK Initialization
3232
const chainConfig = {
3333
chainNamespace: ChainNamespace.EIP155,
3434
chainId: "0xaa36a7",
35-
rpcTarget: "https://1rpc.io/sepolia",
35+
rpcTarget: `https://api.web3auth.io/infura-service/v1/0xaa36a7/${clientId}`,
3636
// Avoid using public rpcTarget in production.
3737
// Use services like Infura, Quicknode etc
3838
displayName: "Ethereum Sepolia Testnet",
@@ -49,7 +49,7 @@ const privateKeyProvider = new EthereumPrivateKeyProvider({
4949
},
5050
});
5151

52-
const PIMLICO_API_KEY = "YOUR_PIMLICO_API_KEY";
52+
const PIMLICO_API_KEY = "pim_WDBELWbZeo9guUAr7HNFaF";
5353

5454
export const getDefaultBundlerUrl = (chainId: string): string => {
5555
return `https://api.pimlico.io/v2/${Number(chainId)}/rpc?apikey=${PIMLICO_API_KEY}`;
@@ -166,7 +166,7 @@ export default function App() {
166166

167167
setConsole("Logging in");
168168
// IMP START - Login
169-
await web3auth.login({
169+
await web3auth.connectTo({
170170
authConnection: AUTH_CONNECTION.EMAIL_PASSWORDLESS,
171171
extraLoginOptions: {
172172
login_hint: email,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module.exports = {
22
presets: ['module:@react-native/babel-preset'],
3+
plugins: ['@babel/plugin-transform-export-namespace-from'],
34
};

demo/rn-bare-example/globals.js

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,63 @@
11
global.Buffer = require("buffer").Buffer;
22

3-
import { install } from "react-native-quick-crypto";
3+
// Pure base64 implementation (no Buffer.from)
4+
const base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
45

5-
install();
6+
global.btoa =
7+
global.btoa ||
8+
function (str) {
9+
let result = "";
10+
for (let i = 0; i < str.length; i += 3) {
11+
const a = str.charCodeAt(i);
12+
const b = i + 1 < str.length ? str.charCodeAt(i + 1) : 0;
13+
const c = i + 2 < str.length ? str.charCodeAt(i + 2) : 0;
14+
result += base64Chars[a >> 2];
15+
result += base64Chars[((a & 3) << 4) | (b >> 4)];
16+
result += i + 1 < str.length ? base64Chars[((b & 15) << 2) | (c >> 6)] : "=";
17+
result += i + 2 < str.length ? base64Chars[c & 63] : "=";
18+
}
19+
return result;
20+
};
21+
22+
global.atob =
23+
global.atob ||
24+
function (str) {
25+
str = str.replace(/=+$/, "");
26+
let result = "";
27+
for (let i = 0; i < str.length; i += 4) {
28+
const a = base64Chars.indexOf(str[i]);
29+
const b = base64Chars.indexOf(str[i + 1]);
30+
const c = base64Chars.indexOf(str[i + 2]);
31+
const d = base64Chars.indexOf(str[i + 3]);
32+
result += String.fromCharCode((a << 2) | (b >> 4));
33+
if (c !== -1) result += String.fromCharCode(((b & 15) << 4) | (c >> 2));
34+
if (d !== -1) result += String.fromCharCode(((c & 3) << 6) | d);
35+
}
36+
return result;
37+
};
638

7-
// Needed so that 'stream-http' chooses the right default protocol.
8-
global.location = {
9-
protocol: "file:",
39+
global.base64FromArrayBuffer = function (buf) {
40+
const bytes = new Uint8Array(buf);
41+
let binary = "";
42+
for (let i = 0; i < bytes.length; i++) {
43+
binary += String.fromCharCode(bytes[i]);
44+
}
45+
return global.btoa(binary);
1046
};
1147

12-
global.process.version = "v16.0.0";
13-
if (!global.process.version) {
14-
global.process = require("process");
15-
console.log({ process: global.process });
16-
}
48+
global.base64ToArrayBuffer = function (base64) {
49+
const binary = global.atob(base64);
50+
const bytes = new Uint8Array(binary.length);
51+
for (let i = 0; i < binary.length; i++) {
52+
bytes[i] = binary.charCodeAt(i);
53+
}
54+
return bytes.buffer;
55+
};
1756

18-
process.browser = true;
57+
import { install } from "react-native-quick-crypto";
58+
59+
install();
60+
61+
global.location = { protocol: "file:" };
62+
global.process.version = "v16.0.0";
63+
process.browser = true;

demo/rn-bare-example/ios/Podfile.lock

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,9 @@ PODS:
963963
- ReactCommon/turbomodule/bridging
964964
- ReactCommon/turbomodule/core
965965
- Yoga
966-
- react-native-quick-crypto (0.7.5):
966+
- react-native-quick-base64 (2.2.2):
967+
- React-Core
968+
- react-native-quick-crypto (0.7.17):
967969
- DoubleConversion
968970
- glog
969971
- hermes-engine
@@ -1255,6 +1257,7 @@ DEPENDENCIES:
12551257
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
12561258
- react-native-encrypted-storage (from `../node_modules/react-native-encrypted-storage`)
12571259
- react-native-mmkv-storage (from `../node_modules/react-native-mmkv-storage`)
1260+
- react-native-quick-base64 (from `../node_modules/react-native-quick-base64`)
12581261
- react-native-quick-crypto (from `../node_modules/react-native-quick-crypto`)
12591262
- "react-native-web-browser (from `../node_modules/@toruslabs/react-native-web-browser`)"
12601263
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
@@ -1355,6 +1358,8 @@ EXTERNAL SOURCES:
13551358
:path: "../node_modules/react-native-encrypted-storage"
13561359
react-native-mmkv-storage:
13571360
:path: "../node_modules/react-native-mmkv-storage"
1361+
react-native-quick-base64:
1362+
:path: "../node_modules/react-native-quick-base64"
13581363
react-native-quick-crypto:
13591364
:path: "../node_modules/react-native-quick-crypto"
13601365
react-native-web-browser:
@@ -1444,7 +1449,8 @@ SPEC CHECKSUMS:
14441449
React-Mapbuffer: bf56147c9775491e53122a94c423ac201417e326
14451450
react-native-encrypted-storage: db300a3f2f0aba1e818417c1c0a6be549038deb7
14461451
react-native-mmkv-storage: 9e84e8d0cc66402128d01a642022de0145303491
1447-
react-native-quick-crypto: 7085e4e4607e7e8fa57f4193f994d5262d351e45
1452+
react-native-quick-base64: ad4ef249fdf5a82670fd3d606e7a596f16c945c8
1453+
react-native-quick-crypto: b2557b7d51ac87172cd40477122b59e2585eedd7
14481454
react-native-web-browser: 087b454e1e94b58b40ba73f54251d77486144d19
14491455
React-nativeconfig: 9f223cd321823afdecf59ed00861ab2d69ee0fc1
14501456
React-NativeModulesApple: ff7efaff7098639db5631236cfd91d60abff04c0
@@ -1470,8 +1476,8 @@ SPEC CHECKSUMS:
14701476
React-utils: 4476b7fcbbd95cfd002f3e778616155241d86e31
14711477
ReactCommon: ecad995f26e0d1e24061f60f4e5d74782f003f12
14721478
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
1473-
Yoga: ae3c32c514802d30f687a04a6a35b348506d411f
1479+
Yoga: 2f71ecf38d934aecb366e686278102a51679c308
14741480

14751481
PODFILE CHECKSUM: 3dac9911479fab8b2375358eac35d220bf61e989
14761482

1477-
COCOAPODS: 1.16.2
1483+
COCOAPODS: 1.15.2

demo/rn-bare-example/metro.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const config = {
1616
stream: require.resolve("readable-stream"),
1717
},
1818
sourceExts: [...defaultConfig.resolver.sourceExts, 'svg'],
19+
unstable_enablePackageExports: true,
1920
},
2021
};
2122

0 commit comments

Comments
 (0)