Skip to content

Commit

Permalink
Merge pull request #195 from Web3Auth/tkey-rn-storage-module
Browse files Browse the repository at this point in the history
Add RN Storage Module to tKey Examples
  • Loading branch information
yashovardhan authored Aug 23, 2023
2 parents 65b7c4f + 2c7e180 commit e34b742
Show file tree
Hide file tree
Showing 10 changed files with 488 additions and 389 deletions.
34 changes: 14 additions & 20 deletions tkey-react-native/tkey-react-native-firebase-example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import auth from '@react-native-firebase/auth';
// @ts-ignore
import {decode as atob} from 'base-64';
import {Dialog, Input} from '@rneui/themed';
import EncryptedStorage from 'react-native-encrypted-storage';
import BN from 'bn.js';
import {ShareSerializationModule} from '@tkey/share-serialization';
import {SfaServiceProvider} from '@tkey/service-provider-sfa';
import {ReactNativeStorageModule} from '@tkey/react-native-storage';
import EncryptedStorage from 'react-native-encrypted-storage';

async function signInWithEmailPassword() {
try {
Expand Down Expand Up @@ -190,36 +190,31 @@ export default function App() {

const setDeviceShare = async () => {
try {
const metadata = await tKeyInstance.getMetadata();
const tKeyPubX = metadata.pubKey.x.toString(16, 64);
const generateShareResult = await tKeyInstance.generateNewShare();
const share = await tKeyInstance.outputShareStore(
generateShareResult.newShareIndex,
).share.share;
EncryptedStorage.setItem(
`deviceShare${tKeyPubX}`,
share.toString(16, 64),
);
uiConsole('Device Share Set', share.toString(16, 64));
await (
tKeyInstance.modules.reactNativeStorage as ReactNativeStorageModule
).storeDeviceShare(share);
uiConsole('Device Share Set', JSON.stringify(share));
} catch (error) {
uiConsole('Error', (error as any)?.message.toString(), 'error');
}
};

const getDeviceShare = async () => {
try {
const metadata = await tKeyInstance.getMetadata();
const tKeyPubX = metadata.pubKey.x.toString(16, 64);
const shareHex = await EncryptedStorage.getItem(`deviceShare${tKeyPubX}`);
if (shareHex && shareHex !== '0') {
const shareBN = new BN(shareHex as any, 'hex');
const share = await (
tKeyInstance.modules.reactNativeStorage as ReactNativeStorageModule
).getStoreFromReactNativeStorage();

if (share) {
uiConsole(
'Device Share Captured Successfully across',
tKeyPubX,
':',
shareBN,
JSON.stringify(share),
);
return shareBN;
return share;
}
uiConsole('Device Share Not found');
return null;
Expand All @@ -231,8 +226,7 @@ export default function App() {
const deleteDeviceShare = async () => {
try {
const metadata = await tKeyInstance.getMetadata();
const tKeyPubX = metadata.pubKey.x.toString(16, 64);
await EncryptedStorage.removeItem(`deviceShare${tKeyPubX}`);
await EncryptedStorage.removeItem(metadata.pubKey.x.toString('hex'));
uiConsole('Device Share Deleted');
} catch (error) {
uiConsole('Error', (error as any)?.message.toString(), 'error');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,83 @@
{
"project_info": {
"project_number": "461819774167",
"firebase_url": "https://web3auth-oauth-logins-default-rtdb.asia-southeast1.firebasedatabase.app",
"project_id": "web3auth-oauth-logins",
"storage_bucket": "web3auth-oauth-logins.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:4ebbd2bfa882323e5b9c92",
"android_client_info": {
"package_name": "com.example.androidsfaexample"
}
},
"oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCL2uSXiGvQcfZ00IJ1g2uwC-7IcGZGVfQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "461819774167-3ebuiqr1ef4kjbvchpckvl1buqt2mr4c.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.w3arnfirebase"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:df1f7ea1f763036e5b9c92",
"android_client_info": {
"package_name": "com.example.tkey_android"
}
},
"oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCL2uSXiGvQcfZ00IJ1g2uwC-7IcGZGVfQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "461819774167-3ebuiqr1ef4kjbvchpckvl1buqt2mr4c.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.w3arnfirebase"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:4b1a78bf91d324f95b9c92",
Expand Down Expand Up @@ -113,11 +186,83 @@
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:0296d14ab6a06abe5b9c92",
"android_client_info": {
"package_name": "com.sfarndemo"
}
},
"oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCL2uSXiGvQcfZ00IJ1g2uwC-7IcGZGVfQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "461819774167-3ebuiqr1ef4kjbvchpckvl1buqt2mr4c.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.w3arnfirebase"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:2691fc0225e6543a5b9c92",
"android_client_info": {
"package_name": "com.tkeyfirebaseexample"
}
},
"oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCL2uSXiGvQcfZ00IJ1g2uwC-7IcGZGVfQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "461819774167-3ebuiqr1ef4kjbvchpckvl1buqt2mr4c.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.w3arnfirebase"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:28440ba70afe767f5b9c92",
"android_client_info": {
"package_name": "com.tkeyrnfirebaseexample"
"package_name": "com.tkeyrnexample"
}
},
"oauth_client": [
Expand Down Expand Up @@ -151,20 +296,84 @@
},
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:3c22c536b06b68135b9c92",
"mobilesdk_app_id": "1:461819774167:android:bc6cf2871e083d7a5b9c92",
"android_client_info": {
"package_name": "com.web3authrnbarefirebase"
}
},
"oauth_client": [
{
"client_id": "461819774167-l7oslag3sa2vllbl1b9ghhcf6e6rhvjj.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.web3authrnbarefirebase",
"certificate_hash": "5e8f16062ea3cd2c4a0d547876baa6f38cabf625"
}
},
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCL2uSXiGvQcfZ00IJ1g2uwC-7IcGZGVfQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "461819774167-3ebuiqr1ef4kjbvchpckvl1buqt2mr4c.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.w3arnfirebase"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:3308fe04b56010945b9c92",
"android_client_info": {
"package_name": "com.web3authsfafirebase"
}
},
"oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCL2uSXiGvQcfZ00IJ1g2uwC-7IcGZGVfQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "461819774167-3ebuiqr1ef4kjbvchpckvl1buqt2mr4c.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.w3arnfirebase"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:aac2a2911fd308555b9c92",
"android_client_info": {
"package_name": "org.torusresearch.customauthexample"
}
},
"oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>461819774167-7h3bonpnjq446b5tjtr4a2h2rmafpl41.apps.googleusercontent.com</string>
<string>461819774167-qmruq7s79rier74t7jksgi65cngb000v.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.461819774167-7h3bonpnjq446b5tjtr4a2h2rmafpl41</string>
<string>com.googleusercontent.apps.461819774167-qmruq7s79rier74t7jksgi65cngb000v</string>
<key>ANDROID_CLIENT_ID</key>
<string>461819774167-l7oslag3sa2vllbl1b9ghhcf6e6rhvjj.apps.googleusercontent.com</string>
<key>API_KEY</key>
Expand All @@ -15,7 +15,7 @@
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>tkeyrnfirebaseexample</string>
<string>com.tkeyfirebasexample</string>
<key>PROJECT_ID</key>
<string>web3auth-oauth-logins</string>
<key>STORAGE_BUCKET</key>
Expand All @@ -31,6 +31,8 @@
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:461819774167:ios:9c7c84383fdbf3e15b9c92</string>
<string>1:461819774167:ios:7aa421541a09daba5b9c92</string>
<key>DATABASE_URL</key>
<string>https://web3auth-oauth-logins-default-rtdb.asia-southeast1.firebasedatabase.app</string>
</dict>
</plist>
Loading

0 comments on commit e34b742

Please sign in to comment.