Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"eslint.format.enable": true,
"eslint.lintTask.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
"source.fixAll": "explicit"
},
"eslint.workingDirectories": [
{
Expand Down
2 changes: 1 addition & 1 deletion demo/rn-bare-example/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: '@react-native-community',
extends: '@react-native',
};
15 changes: 13 additions & 2 deletions demo/rn-bare-example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate
ios/.xcode.env.local
**/.xcode.env.local

# Android/IntelliJ
#
Expand Down Expand Up @@ -56,8 +56,19 @@ yarn-error.log
*.jsbundle

# Ruby / CocoaPods
/ios/Pods/
**/Pods/
/vendor/bundle/

# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

# testing
/coverage

# Yarn
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
1 change: 0 additions & 1 deletion demo/rn-bare-example/.node-version

This file was deleted.

2 changes: 1 addition & 1 deletion demo/rn-bare-example/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
170 changes: 155 additions & 15 deletions demo/rn-bare-example/App.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
import React, {useEffect, useState} from 'react';
import * as WebBrowser from '@toruslabs/react-native-web-browser';

import {
StyleSheet,
Text,
View,
Button,
ScrollView,
Dimensions,
ScrollView,
StyleSheet,
Text,
TextInput,
View,
} from 'react-native';
import * as WebBrowser from '@toruslabs/react-native-web-browser';
import EncryptedStorage from 'react-native-encrypted-storage';
import {useEffect, useState} from 'react';
import Web3Auth, {
LOGIN_PROVIDER,
IWeb3Auth,
LOGIN_PROVIDER,
OpenloginUserInfo,
} from '@web3auth/react-native-sdk';

import {ChainNamespace} from '@web3auth/react-native-sdk';
import EncryptedStorage from 'react-native-encrypted-storage';
import RPC from './ethersRPC'; // for using ethers.js

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

const chainConfig = {
chainNamespace: ChainNamespace.EIP155,
chainId: '0xaa36a7',
rpcTarget: 'https://rpc.ankr.com/eth_sepolia',
// Avoid using public rpcTarget in production.
// Use services like Infura, Quicknode etc
displayName: 'Ethereum Sepolia Testnet',
blockExplorerUrl: 'https://sepolia.etherscan.io',
ticker: 'ETH',
tickerName: 'Ethereum',
decimals: 18,
logo: 'https://cryptologos.cc/logos/ethereum-eth-logo.png',
};

export default function App() {
const [userInfo, setUserInfo] = useState<OpenloginUserInfo | undefined>();
const [key, setKey] = useState<string | undefined>('');
const [console, setConsole] = useState<string>('');
const [web3auth, setWeb3Auth] = useState<IWeb3Auth | null>(null);
const [email, setEmail] = React.useState('hello@tor.us');
const [email, setEmail] = useState('yash@tor.us');

const login = async () => {
try {
Expand All @@ -39,12 +56,8 @@ export default function App() {
setConsole('Logging in');
await web3auth.login({
loginProvider: LOGIN_PROVIDER.EMAIL_PASSWORDLESS,
redirectUrl: resolvedRedirectUrl,
mfaLevel: 'default',
curve: 'secp256k1',
extraLoginOptions: {
login_hint: email,
connection: 'email',
},
});
setConsole(`Logged in ${web3auth.privKey}`);
Expand All @@ -54,7 +67,6 @@ export default function App() {
uiConsole('Logged In');
}
} catch (e: unknown) {
console.log(e, (e as Error).stack);
setConsole((e as Error).message);
}
};
Expand All @@ -75,6 +87,124 @@ export default function App() {
}
};

const enableMFA = async () => {
if (!web3auth) {
setConsole('Web3auth not initialized');
return;
}

setConsole('Enable MFA');
await web3auth.enableMFA();
uiConsole('MFA enabled');
};

const launchWalletSerices = async () => {
if (!web3auth) {
setConsole('Web3auth not initialized');
return;
}

setConsole('Launch Wallet Services');
await web3auth.launchWalletServices(chainConfig);
};

const requestSignature = async () => {
if (!web3auth) {
setConsole('Web3auth not initialized');
return;
}
if (!key) {
setConsole('User not logged in');
return;
}

const address = await RPC.getAccounts(key);

// const params = [
// {
// challenge: 'Hello World',
// address,
// },
// null,
// ];
const params = ['Hello World', address];
// const params = [{ }];
// params.push('Hello World');
// params.push(address);

// const params = [
// address,
// {
// types: {
// EIP712Domain: [
// {
// name: 'name',
// type: 'string',
// },
// {
// name: 'version',
// type: 'string',
// },
// {
// name: 'chainId',
// type: 'uint256',
// },
// {
// name: 'verifyingContract',
// type: 'address',
// },
// ],
// Person: [
// {
// name: 'name',
// type: 'string',
// },
// {
// name: 'wallet',
// type: 'address',
// },
// ],
// Mail: [
// {
// name: 'from',
// type: 'Person',
// },
// {
// name: 'to',
// type: 'Person',
// },
// {
// name: 'contents',
// type: 'string',
// },
// ],
// },
// primaryType: 'Mail',
// domain: {
// name: 'Ether Mail',
// version: '1',
// chainId: chainConfig.chainId,
// verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
// },
// message: {
// from: {
// name: 'Cow',
// wallet: address,
// },
// to: {
// name: 'Bob',
// wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
// },
// contents: 'Hello, Bob!',
// },
// },
// ];

setConsole('Request Signature');
const res = await web3auth.request(chainConfig, 'personal_sign', params);
uiConsole(res);
};

useEffect(() => {
const init = async () => {
const auth = new Web3Auth(WebBrowser, EncryptedStorage, {
Expand All @@ -83,7 +213,8 @@ export default function App() {
useCoreKitKey: false,
loginConfig: {},
enableLogging: true,
buildEnv: 'development',
buildEnv: 'testing',
redirectUrl: resolvedRedirectUrl,
});
setWeb3Auth(auth);
await auth.init();
Expand Down Expand Up @@ -146,6 +277,15 @@ export default function App() {
const loggedInView = (
<View style={styles.buttonArea}>
<Button title="Get User Info" onPress={() => uiConsole(userInfo)} />
<Button title="Enable MFA" onPress={() => enableMFA()} />
<Button
title="launch Wallet Services"
onPress={() => launchWalletSerices()}
/>
<Button
title="Request Signature from Wallet Services"
onPress={() => requestSignature()}
/>
<Button title="Get Chain ID" onPress={() => getChainId()} />
<Button title="Get Accounts" onPress={() => getAccounts()} />
<Button title="Get Balance" onPress={() => getBalance()} />
Expand Down
7 changes: 5 additions & 2 deletions demo/rn-bare-example/Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
source 'https://rubygems.org'

# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby '>= 2.6.10'
ruby ">= 2.6.10"

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