-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from Web3Auth/feat/add-core-kit-key
Feat/add core kit key
- Loading branch information
Showing
209 changed files
with
74,220 additions
and
66,982 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Attach to Hermes application - Experimental", | ||
"request": "attach", | ||
"type": "reactnativedirect", | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
{ | ||
"name": "Debug Android Hermes - Experimental", | ||
"request": "launch", | ||
"type": "reactnativedirect", | ||
"cwd": "${workspaceFolder}/rn-bare-example", | ||
"platform": "android" | ||
}, | ||
{ | ||
"name": "Debug iOS Hermes - Experimental", | ||
"request": "launch", | ||
"type": "reactnativedirect", | ||
"cwd": "${workspaceFolder}/rn-bare-example", | ||
"platform": "ios" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
root: true, | ||
extends: '@react-native-community', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
18 |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
import React, {useEffect, useState} from 'react'; | ||
import { | ||
StyleSheet, | ||
Text, | ||
View, | ||
Button, | ||
ScrollView, | ||
Dimensions, | ||
} from 'react-native'; | ||
import * as WebBrowser from '@toruslabs/react-native-web-browser'; | ||
import EncryptedStorage from 'react-native-encrypted-storage'; | ||
import Web3Auth, { | ||
LOGIN_PROVIDER, | ||
OPENLOGIN_NETWORK, | ||
IWeb3Auth, | ||
OpenloginUserInfo, | ||
} from '@web3auth/react-native-sdk'; | ||
import RPC from './ethersRPC'; // for using ethers.js | ||
|
||
const scheme = 'web3authrnbareaggregateexample'; // Or your desired app redirection scheme | ||
const resolvedRedirectUrl = `${scheme}://openlogin`; | ||
const clientId = | ||
'BHr_dKcxC0ecKn_2dZQmQeNdjPgWykMkcodEHkVvPMo71qzOV6SgtoN8KCvFdLN7bf34JOm89vWQMLFmSfIo84A'; | ||
|
||
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 login = async () => { | ||
try { | ||
if (!web3auth) { | ||
setConsole('Web3auth not initialized'); | ||
return; | ||
} | ||
|
||
setConsole('Logging in'); | ||
await web3auth.login({ | ||
loginProvider: LOGIN_PROVIDER.EMAIL_PASSWORDLESS, | ||
redirectUrl: resolvedRedirectUrl, | ||
mfaLevel: 'default', | ||
curve: 'secp256k1', | ||
extraLoginOptions: { | ||
login_hint: '[email protected]', | ||
connection: 'email', | ||
}, | ||
}); | ||
setConsole(`Logged in ${web3auth.privKey}`); | ||
if (web3auth.privKey) { | ||
setUserInfo(web3auth.userInfo()); | ||
setKey(web3auth.privKey); | ||
uiConsole('Logged In'); | ||
} | ||
} catch (e) { | ||
setConsole(e.message); | ||
} | ||
}; | ||
|
||
const logout = async () => { | ||
if (!web3auth) { | ||
setConsole('Web3auth not initialized'); | ||
return; | ||
} | ||
|
||
setConsole('Logging out'); | ||
await web3auth.logout(); | ||
|
||
if (!web3auth.privKey) { | ||
setUserInfo(undefined); | ||
setKey(''); | ||
uiConsole('Logged out'); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
const init = async () => { | ||
const auth = new Web3Auth(WebBrowser, EncryptedStorage, { | ||
clientId, | ||
network: OPENLOGIN_NETWORK.TESTNET, // or other networks | ||
useCoreKitKey: false, | ||
loginConfig: {}, | ||
}); | ||
setWeb3Auth(auth); | ||
await auth.init(); | ||
if (auth?.privKey) { | ||
uiConsole('Re logged in'); | ||
setUserInfo(auth.userInfo()); | ||
setKey(auth.privKey); | ||
window.console.log(auth.privKey); | ||
} | ||
}; | ||
init(); | ||
}, []); | ||
|
||
const getChainId = async () => { | ||
setConsole('Getting chain id'); | ||
const networkDetails = await RPC.getChainId(); | ||
uiConsole(networkDetails); | ||
}; | ||
|
||
const getAccounts = async () => { | ||
if (!key) { | ||
setConsole('User not logged in'); | ||
return; | ||
} | ||
setConsole('Getting account'); | ||
const address = await RPC.getAccounts(key); | ||
uiConsole(address); | ||
}; | ||
const getBalance = async () => { | ||
if (!key) { | ||
setConsole('User not logged in'); | ||
return; | ||
} | ||
setConsole('Fetching balance'); | ||
const balance = await RPC.getBalance(key); | ||
uiConsole(balance); | ||
}; | ||
const sendTransaction = async () => { | ||
if (!key) { | ||
setConsole('User not logged in'); | ||
return; | ||
} | ||
setConsole('Sending transaction'); | ||
const tx = await RPC.sendTransaction(key); | ||
uiConsole(tx); | ||
}; | ||
const signMessage = async () => { | ||
if (!key) { | ||
setConsole('User not logged in'); | ||
return; | ||
} | ||
setConsole('Signing message'); | ||
const message = await RPC.signMessage(key); | ||
uiConsole(message); | ||
}; | ||
|
||
const uiConsole = (...args) => { | ||
setConsole(JSON.stringify(args || {}, null, 2) + '\n\n\n\n' + console); | ||
}; | ||
|
||
const loggedInView = ( | ||
<View style={styles.buttonArea}> | ||
<Button title="Get User Info" onPress={() => uiConsole(userInfo)} /> | ||
<Button title="Get Chain ID" onPress={() => getChainId()} /> | ||
<Button title="Get Accounts" onPress={() => getAccounts()} /> | ||
<Button title="Get Balance" onPress={() => getBalance()} /> | ||
<Button title="Send Transaction" onPress={() => sendTransaction()} /> | ||
<Button title="Sign Message" onPress={() => signMessage()} /> | ||
<Button title="Get Private Key" onPress={() => uiConsole(key)} /> | ||
<Button title="Log Out" onPress={logout} /> | ||
</View> | ||
); | ||
|
||
const unloggedInView = ( | ||
<View style={styles.buttonArea}> | ||
<Button title="Login with Web3Auth" onPress={login} /> | ||
</View> | ||
); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
{key ? loggedInView : unloggedInView} | ||
<View style={styles.consoleArea}> | ||
<Text style={styles.consoleText}>Console:</Text> | ||
<ScrollView style={styles.console}> | ||
<Text>{console}</Text> | ||
</ScrollView> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: '#fff', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
paddingTop: 50, | ||
paddingBottom: 30, | ||
}, | ||
consoleArea: { | ||
margin: 20, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
flex: 1, | ||
}, | ||
console: { | ||
flex: 1, | ||
backgroundColor: '#CCCCCC', | ||
color: '#ffffff', | ||
padding: 10, | ||
width: Dimensions.get('window').width - 60, | ||
}, | ||
consoleText: { | ||
padding: 10, | ||
}, | ||
buttonArea: { | ||
flex: 2, | ||
alignItems: 'center', | ||
justifyContent: 'space-around', | ||
paddingBottom: 30, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
source 'https://rubygems.org' | ||
|
||
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version | ||
ruby '2.7.5' | ||
ruby '>= 2.6.10' | ||
|
||
gem 'cocoapods', '~> 1.11', '>= 1.11.2' | ||
gem 'cocoapods', '>= 1.11.3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
CFPropertyList (3.0.6) | ||
rexml | ||
activesupport (7.0.5) | ||
concurrent-ruby (~> 1.0, >= 1.0.2) | ||
i18n (>= 1.6, < 2) | ||
minitest (>= 5.1) | ||
tzinfo (~> 2.0) | ||
addressable (2.8.4) | ||
public_suffix (>= 2.0.2, < 6.0) | ||
algoliasearch (1.27.5) | ||
httpclient (~> 2.8, >= 2.8.3) | ||
json (>= 1.5.1) | ||
atomos (0.1.3) | ||
claide (1.1.0) | ||
cocoapods (1.12.1) | ||
addressable (~> 2.8) | ||
claide (>= 1.0.2, < 2.0) | ||
cocoapods-core (= 1.12.1) | ||
cocoapods-deintegrate (>= 1.0.3, < 2.0) | ||
cocoapods-downloader (>= 1.6.0, < 2.0) | ||
cocoapods-plugins (>= 1.0.0, < 2.0) | ||
cocoapods-search (>= 1.0.0, < 2.0) | ||
cocoapods-trunk (>= 1.6.0, < 2.0) | ||
cocoapods-try (>= 1.1.0, < 2.0) | ||
colored2 (~> 3.1) | ||
escape (~> 0.0.4) | ||
fourflusher (>= 2.3.0, < 3.0) | ||
gh_inspector (~> 1.0) | ||
molinillo (~> 0.8.0) | ||
nap (~> 1.0) | ||
ruby-macho (>= 2.3.0, < 3.0) | ||
xcodeproj (>= 1.21.0, < 2.0) | ||
cocoapods-core (1.12.1) | ||
activesupport (>= 5.0, < 8) | ||
addressable (~> 2.8) | ||
algoliasearch (~> 1.0) | ||
concurrent-ruby (~> 1.1) | ||
fuzzy_match (~> 2.0.4) | ||
nap (~> 1.0) | ||
netrc (~> 0.11) | ||
public_suffix (~> 4.0) | ||
typhoeus (~> 1.0) | ||
cocoapods-deintegrate (1.0.5) | ||
cocoapods-downloader (1.6.3) | ||
cocoapods-plugins (1.0.0) | ||
nap | ||
cocoapods-search (1.0.1) | ||
cocoapods-trunk (1.6.0) | ||
nap (>= 0.8, < 2.0) | ||
netrc (~> 0.11) | ||
cocoapods-try (1.2.0) | ||
colored2 (3.1.2) | ||
concurrent-ruby (1.2.2) | ||
escape (0.0.4) | ||
ethon (0.16.0) | ||
ffi (>= 1.15.0) | ||
ffi (1.15.5) | ||
fourflusher (2.3.1) | ||
fuzzy_match (2.0.4) | ||
gh_inspector (1.1.3) | ||
httpclient (2.8.3) | ||
i18n (1.14.1) | ||
concurrent-ruby (~> 1.0) | ||
json (2.6.3) | ||
minitest (5.18.0) | ||
molinillo (0.8.0) | ||
nanaimo (0.3.0) | ||
nap (1.1.0) | ||
netrc (0.11.0) | ||
public_suffix (4.0.7) | ||
rexml (3.2.5) | ||
ruby-macho (2.5.1) | ||
typhoeus (1.4.0) | ||
ethon (>= 0.9.0) | ||
tzinfo (2.0.6) | ||
concurrent-ruby (~> 1.0) | ||
xcodeproj (1.22.0) | ||
CFPropertyList (>= 2.3.3, < 4.0) | ||
atomos (~> 0.1.3) | ||
claide (>= 1.0.2, < 2.0) | ||
colored2 (~> 3.1) | ||
nanaimo (~> 0.3.0) | ||
rexml (~> 3.2.4) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
cocoapods (>= 1.11.3) | ||
|
||
RUBY VERSION | ||
ruby 2.7.7p221 | ||
|
||
BUNDLED WITH | ||
2.3.26 |
File renamed without changes.
Oops, something went wrong.