1- import React , { useEffect , useState } from 'react' ;
1+ import * as WebBrowser from '@toruslabs/react-native-web-browser' ;
2+
23import {
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' ;
1313import 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' ;
1821import RPC from './ethersRPC' ; // for using ethers.js
1922
2023const scheme = 'web3authrnbareexample' ; // Or your desired app redirection scheme
2124const resolvedRedirectUrl = `${ scheme } ://openlogin` ;
2225const 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+
2542export 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 ( ) } />
0 commit comments