Skip to content

Commit 638fc29

Browse files
Merge pull request #93 from Web3Auth/feat/wallet-servies
Feat/wallet servies
2 parents a90e070 + 08bd7f0 commit 638fc29

File tree

141 files changed

+28126
-46751
lines changed

Some content is hidden

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

141 files changed

+28126
-46751
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"eslint.format.enable": true,
77
"eslint.lintTask.enable": true,
88
"editor.codeActionsOnSave": {
9-
"source.fixAll": true
9+
"source.fixAll": "explicit"
1010
},
1111
"eslint.workingDirectories": [
1212
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
root: true,
3-
extends: '@react-native-community',
3+
extends: '@react-native',
44
};

demo/rn-bare-example/.gitignore

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ DerivedData
2020
*.hmap
2121
*.ipa
2222
*.xcuserstate
23-
ios/.xcode.env.local
23+
**/.xcode.env.local
2424

2525
# Android/IntelliJ
2626
#
@@ -56,8 +56,19 @@ yarn-error.log
5656
*.jsbundle
5757

5858
# Ruby / CocoaPods
59-
/ios/Pods/
59+
**/Pods/
6060
/vendor/bundle/
6161

6262
# Temporary files created by Metro to check the health of the file watcher
6363
.metro-health-check*
64+
65+
# testing
66+
/coverage
67+
68+
# Yarn
69+
.yarn/*
70+
!.yarn/patches
71+
!.yarn/plugins
72+
!.yarn/releases
73+
!.yarn/sdks
74+
!.yarn/versions

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

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{}

demo/rn-bare-example/App.tsx

Lines changed: 155 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,50 @@
1-
import React, {useEffect, useState} from 'react';
1+
import * as WebBrowser from '@toruslabs/react-native-web-browser';
2+
23
import {
3-
StyleSheet,
4-
Text,
5-
View,
64
Button,
7-
ScrollView,
85
Dimensions,
6+
ScrollView,
7+
StyleSheet,
8+
Text,
99
TextInput,
10+
View,
1011
} from 'react-native';
11-
import * as WebBrowser from '@toruslabs/react-native-web-browser';
12-
import EncryptedStorage from 'react-native-encrypted-storage';
12+
import {useEffect, useState} from 'react';
1313
import Web3Auth, {
14-
LOGIN_PROVIDER,
1514
IWeb3Auth,
15+
LOGIN_PROVIDER,
1616
OpenloginUserInfo,
1717
} from '@web3auth/react-native-sdk';
18+
19+
import {ChainNamespace} from '@web3auth/react-native-sdk';
20+
import EncryptedStorage from 'react-native-encrypted-storage';
1821
import RPC from './ethersRPC'; // for using ethers.js
1922

2023
const scheme = 'web3authrnbareexample'; // Or your desired app redirection scheme
2124
const resolvedRedirectUrl = `${scheme}://openlogin`;
2225
const clientId =
2326
'BHr_dKcxC0ecKn_2dZQmQeNdjPgWykMkcodEHkVvPMo71qzOV6SgtoN8KCvFdLN7bf34JOm89vWQMLFmSfIo84A';
2427

28+
const chainConfig = {
29+
chainNamespace: ChainNamespace.EIP155,
30+
chainId: '0xaa36a7',
31+
rpcTarget: 'https://rpc.ankr.com/eth_sepolia',
32+
// Avoid using public rpcTarget in production.
33+
// Use services like Infura, Quicknode etc
34+
displayName: 'Ethereum Sepolia Testnet',
35+
blockExplorerUrl: 'https://sepolia.etherscan.io',
36+
ticker: 'ETH',
37+
tickerName: 'Ethereum',
38+
decimals: 18,
39+
logo: 'https://cryptologos.cc/logos/ethereum-eth-logo.png',
40+
};
41+
2542
export default function App() {
2643
const [userInfo, setUserInfo] = useState<OpenloginUserInfo | undefined>();
2744
const [key, setKey] = useState<string | undefined>('');
2845
const [console, setConsole] = useState<string>('');
2946
const [web3auth, setWeb3Auth] = useState<IWeb3Auth | null>(null);
30-
const [email, setEmail] = React.useState('hello@tor.us');
47+
const [email, setEmail] = useState('yash@tor.us');
3148

3249
const login = async () => {
3350
try {
@@ -39,12 +56,8 @@ export default function App() {
3956
setConsole('Logging in');
4057
await web3auth.login({
4158
loginProvider: LOGIN_PROVIDER.EMAIL_PASSWORDLESS,
42-
redirectUrl: resolvedRedirectUrl,
43-
mfaLevel: 'default',
44-
curve: 'secp256k1',
4559
extraLoginOptions: {
4660
login_hint: email,
47-
connection: 'email',
4861
},
4962
});
5063
setConsole(`Logged in ${web3auth.privKey}`);
@@ -54,7 +67,6 @@ export default function App() {
5467
uiConsole('Logged In');
5568
}
5669
} catch (e: unknown) {
57-
console.log(e, (e as Error).stack);
5870
setConsole((e as Error).message);
5971
}
6072
};
@@ -75,6 +87,124 @@ export default function App() {
7587
}
7688
};
7789

90+
const enableMFA = async () => {
91+
if (!web3auth) {
92+
setConsole('Web3auth not initialized');
93+
return;
94+
}
95+
96+
setConsole('Enable MFA');
97+
await web3auth.enableMFA();
98+
uiConsole('MFA enabled');
99+
};
100+
101+
const launchWalletSerices = async () => {
102+
if (!web3auth) {
103+
setConsole('Web3auth not initialized');
104+
return;
105+
}
106+
107+
setConsole('Launch Wallet Services');
108+
await web3auth.launchWalletServices(chainConfig);
109+
};
110+
111+
const requestSignature = async () => {
112+
if (!web3auth) {
113+
setConsole('Web3auth not initialized');
114+
return;
115+
}
116+
if (!key) {
117+
setConsole('User not logged in');
118+
return;
119+
}
120+
121+
const address = await RPC.getAccounts(key);
122+
123+
// const params = [
124+
// {
125+
// challenge: 'Hello World',
126+
// address,
127+
// },
128+
// null,
129+
// ];
130+
const params = ['Hello World', address];
131+
// const params = [{ }];
132+
// params.push('Hello World');
133+
// params.push(address);
134+
135+
// const params = [
136+
// address,
137+
// {
138+
// types: {
139+
// EIP712Domain: [
140+
// {
141+
// name: 'name',
142+
// type: 'string',
143+
// },
144+
// {
145+
// name: 'version',
146+
// type: 'string',
147+
// },
148+
// {
149+
// name: 'chainId',
150+
// type: 'uint256',
151+
// },
152+
// {
153+
// name: 'verifyingContract',
154+
// type: 'address',
155+
// },
156+
// ],
157+
// Person: [
158+
// {
159+
// name: 'name',
160+
// type: 'string',
161+
// },
162+
// {
163+
// name: 'wallet',
164+
// type: 'address',
165+
// },
166+
// ],
167+
// Mail: [
168+
// {
169+
// name: 'from',
170+
// type: 'Person',
171+
// },
172+
// {
173+
// name: 'to',
174+
// type: 'Person',
175+
// },
176+
// {
177+
// name: 'contents',
178+
// type: 'string',
179+
// },
180+
// ],
181+
// },
182+
// primaryType: 'Mail',
183+
// domain: {
184+
// name: 'Ether Mail',
185+
// version: '1',
186+
// chainId: chainConfig.chainId,
187+
// verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
188+
// },
189+
// message: {
190+
// from: {
191+
// name: 'Cow',
192+
// wallet: address,
193+
// },
194+
// to: {
195+
// name: 'Bob',
196+
// wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
197+
// },
198+
// contents: 'Hello, Bob!',
199+
// },
200+
// },
201+
// ];
202+
203+
setConsole('Request Signature');
204+
const res = await web3auth.request(chainConfig, 'personal_sign', params);
205+
uiConsole(res);
206+
};
207+
78208
useEffect(() => {
79209
const init = async () => {
80210
const auth = new Web3Auth(WebBrowser, EncryptedStorage, {
@@ -83,7 +213,8 @@ export default function App() {
83213
useCoreKitKey: false,
84214
loginConfig: {},
85215
enableLogging: true,
86-
buildEnv: 'development',
216+
buildEnv: 'testing',
217+
redirectUrl: resolvedRedirectUrl,
87218
});
88219
setWeb3Auth(auth);
89220
await auth.init();
@@ -146,6 +277,15 @@ export default function App() {
146277
const loggedInView = (
147278
<View style={styles.buttonArea}>
148279
<Button title="Get User Info" onPress={() => uiConsole(userInfo)} />
280+
<Button title="Enable MFA" onPress={() => enableMFA()} />
281+
<Button
282+
title="launch Wallet Services"
283+
onPress={() => launchWalletSerices()}
284+
/>
285+
<Button
286+
title="Request Signature from Wallet Services"
287+
onPress={() => requestSignature()}
288+
/>
149289
<Button title="Get Chain ID" onPress={() => getChainId()} />
150290
<Button title="Get Accounts" onPress={() => getAccounts()} />
151291
<Button title="Get Balance" onPress={() => getBalance()} />

demo/rn-bare-example/Gemfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
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.6.10'
4+
ruby ">= 2.6.10"
55

6-
gem 'cocoapods', '>= 1.11.3'
6+
# Cocoapods 1.15 introduced a bug which break the build. We will remove the upper
7+
# bound in the template on Cocoapods with next React Native release.
8+
gem 'cocoapods', '>= 1.13', '< 1.15'
9+
gem 'activesupport', '>= 6.1.7.5', '< 7.1.0'

0 commit comments

Comments
 (0)