Skip to content

Commit 3db4820

Browse files
Merge pull request #69 from Web3Auth/feat/add-core-kit-key
Feat/add core kit key
2 parents 51eb945 + 6b21862 commit 3db4820

File tree

209 files changed

+74220
-66982
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+74220
-66982
lines changed

.vscode/launch.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Attach to Hermes application - Experimental",
5+
"request": "attach",
6+
"type": "reactnativedirect",
7+
"cwd": "${workspaceFolder}"
8+
},
9+
{
10+
"name": "Debug Android Hermes - Experimental",
11+
"request": "launch",
12+
"type": "reactnativedirect",
13+
"cwd": "${workspaceFolder}/rn-bare-example",
14+
"platform": "android"
15+
},
16+
{
17+
"name": "Debug iOS Hermes - Experimental",
18+
"request": "launch",
19+
"type": "reactnativedirect",
20+
"cwd": "${workspaceFolder}/rn-bare-example",
21+
"platform": "ios"
22+
}
23+
]
24+
}

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
{
2+
"editor.formatOnSave": true,
3+
"editor.formatOnType": true,
4+
"eslint.alwaysShowStatus": true,
5+
"eslint.debug": false,
6+
"eslint.format.enable": true,
7+
"eslint.lintTask.enable": true,
8+
"editor.codeActionsOnSave": {
9+
"source.fixAll": true
10+
},
211
"eslint.workingDirectories": [
312
{
413
"directory": "example",

demo/rn-bare-example/.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: '@react-native-community',
4+
};
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,15 @@ local.properties
3131
*.iml
3232
*.hprof
3333
.cxx/
34+
*.keystore
35+
!debug.keystore
3436

3537
# node.js
3638
#
3739
node_modules/
3840
npm-debug.log
3941
yarn-error.log
4042

41-
# BUCK
42-
buck-out/
43-
\.buckd/
44-
*.keystore
45-
!debug.keystore
46-
4743
# fastlane
4844
#
4945
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
@@ -62,3 +58,6 @@ buck-out/
6258
# Ruby / CocoaPods
6359
/ios/Pods/
6460
/vendor/bundle/
61+
62+
# Temporary files created by Metro to check the health of the file watcher
63+
.metro-health-check*

demo/rn-bare-example/.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18

demo/rn-bare-example/App.tsx

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
import React, {useEffect, useState} from 'react';
2+
import {
3+
StyleSheet,
4+
Text,
5+
View,
6+
Button,
7+
ScrollView,
8+
Dimensions,
9+
} from 'react-native';
10+
import * as WebBrowser from '@toruslabs/react-native-web-browser';
11+
import EncryptedStorage from 'react-native-encrypted-storage';
12+
import Web3Auth, {
13+
LOGIN_PROVIDER,
14+
OPENLOGIN_NETWORK,
15+
IWeb3Auth,
16+
OpenloginUserInfo,
17+
} from '@web3auth/react-native-sdk';
18+
import RPC from './ethersRPC'; // for using ethers.js
19+
20+
const scheme = 'web3authrnbareaggregateexample'; // Or your desired app redirection scheme
21+
const resolvedRedirectUrl = `${scheme}://openlogin`;
22+
const clientId =
23+
'BHr_dKcxC0ecKn_2dZQmQeNdjPgWykMkcodEHkVvPMo71qzOV6SgtoN8KCvFdLN7bf34JOm89vWQMLFmSfIo84A';
24+
25+
export default function App() {
26+
const [userInfo, setUserInfo] = useState<OpenloginUserInfo | undefined>();
27+
const [key, setKey] = useState<string | undefined>('');
28+
const [console, setConsole] = useState<string>('');
29+
const [web3auth, setWeb3Auth] = useState<IWeb3Auth | null>(null);
30+
31+
const login = async () => {
32+
try {
33+
if (!web3auth) {
34+
setConsole('Web3auth not initialized');
35+
return;
36+
}
37+
38+
setConsole('Logging in');
39+
await web3auth.login({
40+
loginProvider: LOGIN_PROVIDER.EMAIL_PASSWORDLESS,
41+
redirectUrl: resolvedRedirectUrl,
42+
mfaLevel: 'default',
43+
curve: 'secp256k1',
44+
extraLoginOptions: {
45+
login_hint: '[email protected]',
46+
connection: 'email',
47+
},
48+
});
49+
setConsole(`Logged in ${web3auth.privKey}`);
50+
if (web3auth.privKey) {
51+
setUserInfo(web3auth.userInfo());
52+
setKey(web3auth.privKey);
53+
uiConsole('Logged In');
54+
}
55+
} catch (e) {
56+
setConsole(e.message);
57+
}
58+
};
59+
60+
const logout = async () => {
61+
if (!web3auth) {
62+
setConsole('Web3auth not initialized');
63+
return;
64+
}
65+
66+
setConsole('Logging out');
67+
await web3auth.logout();
68+
69+
if (!web3auth.privKey) {
70+
setUserInfo(undefined);
71+
setKey('');
72+
uiConsole('Logged out');
73+
}
74+
};
75+
76+
useEffect(() => {
77+
const init = async () => {
78+
const auth = new Web3Auth(WebBrowser, EncryptedStorage, {
79+
clientId,
80+
network: OPENLOGIN_NETWORK.TESTNET, // or other networks
81+
useCoreKitKey: false,
82+
loginConfig: {},
83+
});
84+
setWeb3Auth(auth);
85+
await auth.init();
86+
if (auth?.privKey) {
87+
uiConsole('Re logged in');
88+
setUserInfo(auth.userInfo());
89+
setKey(auth.privKey);
90+
window.console.log(auth.privKey);
91+
}
92+
};
93+
init();
94+
}, []);
95+
96+
const getChainId = async () => {
97+
setConsole('Getting chain id');
98+
const networkDetails = await RPC.getChainId();
99+
uiConsole(networkDetails);
100+
};
101+
102+
const getAccounts = async () => {
103+
if (!key) {
104+
setConsole('User not logged in');
105+
return;
106+
}
107+
setConsole('Getting account');
108+
const address = await RPC.getAccounts(key);
109+
uiConsole(address);
110+
};
111+
const getBalance = async () => {
112+
if (!key) {
113+
setConsole('User not logged in');
114+
return;
115+
}
116+
setConsole('Fetching balance');
117+
const balance = await RPC.getBalance(key);
118+
uiConsole(balance);
119+
};
120+
const sendTransaction = async () => {
121+
if (!key) {
122+
setConsole('User not logged in');
123+
return;
124+
}
125+
setConsole('Sending transaction');
126+
const tx = await RPC.sendTransaction(key);
127+
uiConsole(tx);
128+
};
129+
const signMessage = async () => {
130+
if (!key) {
131+
setConsole('User not logged in');
132+
return;
133+
}
134+
setConsole('Signing message');
135+
const message = await RPC.signMessage(key);
136+
uiConsole(message);
137+
};
138+
139+
const uiConsole = (...args) => {
140+
setConsole(JSON.stringify(args || {}, null, 2) + '\n\n\n\n' + console);
141+
};
142+
143+
const loggedInView = (
144+
<View style={styles.buttonArea}>
145+
<Button title="Get User Info" onPress={() => uiConsole(userInfo)} />
146+
<Button title="Get Chain ID" onPress={() => getChainId()} />
147+
<Button title="Get Accounts" onPress={() => getAccounts()} />
148+
<Button title="Get Balance" onPress={() => getBalance()} />
149+
<Button title="Send Transaction" onPress={() => sendTransaction()} />
150+
<Button title="Sign Message" onPress={() => signMessage()} />
151+
<Button title="Get Private Key" onPress={() => uiConsole(key)} />
152+
<Button title="Log Out" onPress={logout} />
153+
</View>
154+
);
155+
156+
const unloggedInView = (
157+
<View style={styles.buttonArea}>
158+
<Button title="Login with Web3Auth" onPress={login} />
159+
</View>
160+
);
161+
162+
return (
163+
<View style={styles.container}>
164+
{key ? loggedInView : unloggedInView}
165+
<View style={styles.consoleArea}>
166+
<Text style={styles.consoleText}>Console:</Text>
167+
<ScrollView style={styles.console}>
168+
<Text>{console}</Text>
169+
</ScrollView>
170+
</View>
171+
</View>
172+
);
173+
}
174+
175+
const styles = StyleSheet.create({
176+
container: {
177+
flex: 1,
178+
backgroundColor: '#fff',
179+
alignItems: 'center',
180+
justifyContent: 'center',
181+
paddingTop: 50,
182+
paddingBottom: 30,
183+
},
184+
consoleArea: {
185+
margin: 20,
186+
alignItems: 'center',
187+
justifyContent: 'center',
188+
flex: 1,
189+
},
190+
console: {
191+
flex: 1,
192+
backgroundColor: '#CCCCCC',
193+
color: '#ffffff',
194+
padding: 10,
195+
width: Dimensions.get('window').width - 60,
196+
},
197+
consoleText: {
198+
padding: 10,
199+
},
200+
buttonArea: {
201+
flex: 2,
202+
alignItems: 'center',
203+
justifyContent: 'space-around',
204+
paddingBottom: 30,
205+
},
206+
});
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source 'https://rubygems.org'
22

33
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4-
ruby '2.7.5'
4+
ruby '>= 2.6.10'
55

6-
gem 'cocoapods', '~> 1.11', '>= 1.11.2'
6+
gem 'cocoapods', '>= 1.11.3'

0 commit comments

Comments
 (0)