@@ -9,14 +9,14 @@ import {
99 TextInput ,
1010 View ,
1111} from 'react-native' ;
12- import React , { useEffect , useState } from 'react' ;
12+ import { useEffect , useState } from 'react' ;
1313import Web3Auth , {
1414 IWeb3Auth ,
1515 LOGIN_PROVIDER ,
1616 OpenloginUserInfo ,
1717} from '@web3auth/react-native-sdk' ;
1818
19- import { ChainNamespace } from '@web3auth/react-native-sdk' ;
19+ import { ChainNamespace } from '@web3auth/react-native-sdk' ;
2020import EncryptedStorage from 'react-native-encrypted-storage' ;
2121import RPC from './ethersRPC' ; // for using ethers.js
2222
@@ -25,12 +25,26 @@ const resolvedRedirectUrl = `${scheme}://openlogin`;
2525const clientId =
2626 'BHr_dKcxC0ecKn_2dZQmQeNdjPgWykMkcodEHkVvPMo71qzOV6SgtoN8KCvFdLN7bf34JOm89vWQMLFmSfIo84A' ;
2727
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+
2842export default function App ( ) {
2943 const [ userInfo , setUserInfo ] = useState < OpenloginUserInfo | undefined > ( ) ;
3044 const [ key , setKey ] = useState < string | undefined > ( '' ) ;
3145 const [ console , setConsole ] = useState < string > ( '' ) ;
3246 const [ web3auth , setWeb3Auth ] = useState < IWeb3Auth | null > ( null ) ;
33- const [ email , setEmail ] = React . useState ( '[email protected] ' ) ; 47+ const [ email , setEmail ] = useState ( '[email protected] ' ) ; 3448
3549 const login = async ( ) => {
3650 try {
@@ -42,12 +56,8 @@ export default function App() {
4256 setConsole ( 'Logging in' ) ;
4357 await web3auth . login ( {
4458 loginProvider : LOGIN_PROVIDER . EMAIL_PASSWORDLESS ,
45- redirectUrl : resolvedRedirectUrl ,
46- mfaLevel : 'default' ,
47- curve : 'secp256k1' ,
4859 extraLoginOptions : {
4960 login_hint : email ,
50- connection : 'email' ,
5161 } ,
5262 } ) ;
5363 setConsole ( `Logged in ${ web3auth . privKey } ` ) ;
@@ -57,7 +67,6 @@ export default function App() {
5767 uiConsole ( 'Logged In' ) ;
5868 }
5969 } catch ( e : unknown ) {
60- console . log ( e , ( e as Error ) . stack ) ;
6170 setConsole ( ( e as Error ) . message ) ;
6271 }
6372 } ;
@@ -86,33 +95,115 @@ export default function App() {
8695
8796 setConsole ( 'Enable MFA' ) ;
8897 await web3auth . enableMFA ( ) ;
89- uiConsole ( 'MFA enabled' )
90- }
98+ uiConsole ( 'MFA enabled' ) ;
99+ } ;
91100
92- const launchWallerSerices = async ( ) => {
101+ const launchWalletSerices = async ( ) => {
93102 if ( ! web3auth ) {
94103 setConsole ( 'Web3auth not initialized' ) ;
95104 return ;
96105 }
97106
98107 setConsole ( 'Launch Wallet Services' ) ;
99- await web3auth . launchWalletServices ( {
100- loginProvider : LOGIN_PROVIDER . EMAIL_PASSWORDLESS ,
101- redirectUrl : resolvedRedirectUrl ,
102- mfaLevel : 'default' ,
103- curve : 'secp256k1' ,
104- extraLoginOptions : {
105- login_hint : email ,
106- connection : 'email' ,
107- } ,
108- } , {
109- chainNamespace : ChainNamespace . EIP155 ,
110- decimals : 18 ,
111- chainId : "0x1" ,
112- rpcTarget : "https://mainnet.infura.io/v3/daeee53504be4cd3a997d4f2718d33e0" ,
113- ticker : "ETH" ,
114- } ) ;
115- }
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+ } ;
116207
117208 useEffect ( ( ) => {
118209 const init = async ( ) => {
@@ -123,6 +214,7 @@ export default function App() {
123214 loginConfig : { } ,
124215 enableLogging : true ,
125216 buildEnv : 'testing' ,
217+ redirectUrl : resolvedRedirectUrl ,
126218 } ) ;
127219 setWeb3Auth ( auth ) ;
128220 await auth . init ( ) ;
@@ -186,7 +278,14 @@ export default function App() {
186278 < View style = { styles . buttonArea } >
187279 < Button title = "Get User Info" onPress = { ( ) => uiConsole ( userInfo ) } />
188280 < Button title = "Enable MFA" onPress = { ( ) => enableMFA ( ) } />
189- < Button title = "launch Wallet Services" onPress = { ( ) => launchWallerSerices ( ) } />
281+ < Button
282+ title = "launch Wallet Services"
283+ onPress = { ( ) => launchWalletSerices ( ) }
284+ />
285+ < Button
286+ title = "Request Signature from Wallet Services"
287+ onPress = { ( ) => requestSignature ( ) }
288+ />
190289 < Button title = "Get Chain ID" onPress = { ( ) => getChainId ( ) } />
191290 < Button title = "Get Accounts" onPress = { ( ) => getAccounts ( ) } />
192291 < Button title = "Get Balance" onPress = { ( ) => getBalance ( ) } />
@@ -204,7 +303,7 @@ export default function App() {
204303 onChangeText = { text => setEmail ( text ) }
205304 value = { email }
206305 // eslint-disable-next-line react-native/no-inline-styles
207- style = { { padding : 10 } }
306+ style = { { padding : 10 } }
208307 />
209308 < Button title = "Login with Web3Auth" onPress = { login } />
210309 </ View >
0 commit comments