Skip to content

Commit 42c8804

Browse files
Merge pull request #55 from musab1234/master
SDK updates Session Management and dApp Share
2 parents a978df5 + 69322c5 commit 42c8804

File tree

16 files changed

+825
-244
lines changed

16 files changed

+825
-244
lines changed

example/App.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { StatusBar } from "expo-status-bar";
2+
import { useEffect, useRef, useState } from "react";
3+
import { StyleSheet, Text, View, Button } from "react-native";
14
import Web3Auth, { LOGIN_PROVIDER, OPENLOGIN_NETWORK, State } from "@web3auth/react-native-sdk";
25
import { Buffer } from "buffer";
36
import Constants, { AppOwnership } from "expo-constants";
47
import * as Linking from "expo-linking";
5-
import { StatusBar } from "expo-status-bar";
68
import * as WebBrowser from "expo-web-browser";
7-
import { useState } from "react";
8-
import { Button, StyleSheet, Text, View } from "react-native";
9+
import * as SecureStore from 'expo-secure-store';
910

1011
global.Buffer = global.Buffer || Buffer;
1112

@@ -29,15 +30,25 @@ export default function App() {
2930
const [key, setKey] = useState("");
3031
const [errorMsg, setErrorMsg] = useState("");
3132
const [userInfo, setUserInfo] = useState<State>(null);
33+
34+
var web3auth = useRef<Web3Auth>();
35+
36+
useEffect(() => {
37+
web3auth.current = new Web3Auth(WebBrowser, SecureStore, {
38+
clientId: "BDj1toq1N1xYgDIJ00ADR-QPJ71ESzJcB3ijVHP1TsIX7nsx_lu6uLoJQMPze1vpGDt--Ew95RGxz-RgOh1tcxM",
39+
network: OPENLOGIN_NETWORK.TESTNET,
40+
});
41+
web3auth.current.init().then(function(state) {
42+
setKey(state.privKey || "no key");
43+
setUserInfo(state);
44+
});
45+
}, []);
46+
3247
const login = async () => {
3348
try {
34-
const web3auth = new Web3Auth(WebBrowser, {
35-
clientId: "BA0mVyeHATikwuXVhXWCNjAxHthlw0w84mUhLuxlC4KZKjvmBsbdbmEWTizJ26YzrbKSWbOZbtGYdVDm0ESuYSg",
36-
network: OPENLOGIN_NETWORK.TESTNET,
37-
});
38-
const state = await web3auth.login({
39-
redirectUrl: resolvedRedirectUrl,
49+
const state = await web3auth.current.login({
4050
loginProvider: LOGIN_PROVIDER.GOOGLE,
51+
redirectUrl: resolvedRedirectUrl,
4152
});
4253
setKey(state.privKey || "no key");
4354
setUserInfo(state);

example/metro.config.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ module.exports = {
2828
)
2929
),
3030

31-
extraNodeModules: modules.reduce((acc, name) => {
32-
acc[name] = path.join(__dirname, "node_modules", name);
33-
return acc;
34-
}, {}),
31+
extraNodeModules: {
32+
... {
33+
stream: path.join(__dirname, "node_modules", 'stream-browserify'),
34+
crypto: path.join(__dirname, "node_modules", 'crypto-browserify')
35+
},
36+
... modules.reduce((acc, name) => {
37+
acc[name] = path.join(__dirname, "node_modules", name);
38+
return acc;
39+
}, {})
40+
},
3541
},
3642

3743
transformer: {

example/package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"react": "^17.0.1",
2020
"react-dom": "^17.0.1",
2121
"react-native": "^0.68.2",
22-
"react-native-web": "0.17.7"
22+
"react-native-web": "0.17.7",
23+
"expo-secure-store": "~11.2.0"
2324
},
2425
"devDependencies": {
2526
"@babel/core": "^7.18.9",

example_general/App.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
* @format
99
*/
1010

11-
import React, {useState} from 'react';
11+
import React, {useEffect, useRef, useState} from 'react';
1212
import * as WebBrowser from '@toruslabs/react-native-web-browser';
13+
import EncryptedStorage from 'react-native-encrypted-storage';
1314
import Web3Auth, {
1415
LOGIN_PROVIDER,
1516
OPENLOGIN_NETWORK,
@@ -28,24 +29,34 @@ const App = () => {
2829
const [key, setKey] = useState('');
2930
const [errorMsg, setErrorMsg] = useState('');
3031
const [userInfo, setUserInfo] = useState<State | null>(null);
32+
33+
var web3auth = useRef<Web3Auth>();
34+
35+
useEffect(() => {
36+
web3auth.current = new Web3Auth(WebBrowser, EncryptedStorage, {
37+
clientId: "BDj1toq1N1xYgDIJ00ADR-QPJ71ESzJcB3ijVHP1TsIX7nsx_lu6uLoJQMPze1vpGDt--Ew95RGxz-RgOh1tcxM",
38+
network: OPENLOGIN_NETWORK.TESTNET,
39+
});
40+
web3auth.current.init().then(function(state) {
41+
setKey(state.privKey || "no key");
42+
setUserInfo(state);
43+
});
44+
}, []);
45+
3146
const login = async () => {
3247
try {
33-
const web3auth = new Web3Auth(WebBrowser, {
34-
clientId:
35-
'BA0mVyeHATikwuXVhXWCNjAxHthlw0w84mUhLuxlC4KZKjvmBsbdbmEWTizJ26YzrbKSWbOZbtGYdVDm0ESuYSg',
36-
network: OPENLOGIN_NETWORK.TESTNET,
37-
});
38-
const state = await web3auth.login({
48+
const state = await web3auth.current.login({
3949
loginProvider: LOGIN_PROVIDER.GOOGLE,
4050
redirectUrl: resolvedRedirectUrl,
4151
});
42-
setKey(state.privKey || 'no key');
52+
setKey(state.privKey || "no key");
4353
setUserInfo(state);
4454
} catch (e) {
4555
console.error(e);
4656
setErrorMsg(String(e));
4757
}
4858
};
59+
4960
return (
5061
<View style={styles.container}>
5162
{key !== '' ? <Text>Key: {key}</Text> : null}

example_general/metro.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ module.exports = {
1212
experimentalImportSupport: false,
1313
inlineRequires: true,
1414
},
15+
extraNodeModules: {
16+
... {
17+
stream: path.join(__dirname, "node_modules", 'stream-browserify'),
18+
crypto: path.join(__dirname, "node_modules", 'crypto-browserify')
19+
}
20+
},
1521
}),
1622
},
1723
};

example_general/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
1111
},
1212
"dependencies": {
13+
"@toruslabs/react-native-web-browser": "^1.0.1",
14+
"@web3auth/react-native-sdk": "file:../",
1315
"react": "18.1.0",
1416
"react-native": "0.70.1",
15-
"@toruslabs/react-native-web-browser": "^1.0.1",
16-
"@web3auth/react-native-sdk": "file:../"
17+
"react-native-encrypted-storage": "^4.0.3"
1718
},
1819
"devDependencies": {
1920
"@babel/core": "^7.12.9",

example_general/yarn.lock

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,12 +1617,21 @@
16171617
"@typescript-eslint/types" "5.39.0"
16181618
eslint-visitor-keys "^3.3.0"
16191619

1620+
"@wangshijun/secp256k1@^4.0.3":
1621+
version "4.0.3"
1622+
resolved "https://registry.yarnpkg.com/@wangshijun/secp256k1/-/secp256k1-4.0.3.tgz#20fc976dc0abc252ed653ee75d1b63d484267b07"
1623+
integrity sha512-07nXubNoGKpnJruT9wNGS4PP6+5qYKA+psd0Tdh/XVqkDf+S+MQ2y9o7Fh8g8pg/ScfPCgjL1O4N+w/21pQY+w==
1624+
dependencies:
1625+
elliptic "^6.5.2"
1626+
16201627
"@web3auth/react-native-sdk@file:..":
1621-
version "3.1.0"
1628+
version "3.3.0"
16221629
dependencies:
1630+
"@wangshijun/secp256k1" "^4.0.3"
16231631
base64url "^3.0.1"
16241632
buffer "^6.0.3"
1625-
loglevel "^1.8.0"
1633+
crypto-js "^4.1.1"
1634+
loglevel "^1.8.1"
16261635
react-native-url-polyfill "^1.3.0"
16271636

16281637
abab@^2.0.3, abab@^2.0.5:
@@ -2060,6 +2069,11 @@ bl@^4.1.0:
20602069
inherits "^2.0.4"
20612070
readable-stream "^3.4.0"
20622071

2072+
bn.js@^4.11.9:
2073+
version "4.12.0"
2074+
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88"
2075+
integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==
2076+
20632077
brace-expansion@^1.1.7:
20642078
version "1.1.11"
20652079
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
@@ -2091,6 +2105,11 @@ braces@^3.0.2:
20912105
dependencies:
20922106
fill-range "^7.0.1"
20932107

2108+
brorand@^1.1.0:
2109+
version "1.1.0"
2110+
resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f"
2111+
integrity sha512-cKV8tMCEpQs4hK/ik71d6LrPOnpkpGBR0wzxqr68g2m/LB2GxVYQroAjMJZRVM1Y4BCjCKc3vAamxSzOY2RP+w==
2112+
20942113
browser-process-hrtime@^1.0.0:
20952114
version "1.0.0"
20962115
resolved "https://registry.yarnpkg.com/browser-process-hrtime/-/browser-process-hrtime-1.0.0.tgz#3c9b4b7d782c8121e56f10106d84c0d0ffc94626"
@@ -2465,6 +2484,11 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2:
24652484
shebang-command "^2.0.0"
24662485
which "^2.0.1"
24672486

2487+
crypto-js@^4.1.1:
2488+
version "4.1.1"
2489+
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.1.1.tgz#9e485bcf03521041bd85844786b83fb7619736cf"
2490+
integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==
2491+
24682492
cssom@^0.4.4:
24692493
version "0.4.4"
24702494
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.4.4.tgz#5a66cf93d2d0b661d80bf6a44fb65f5c2e4e0a10"
@@ -2650,6 +2674,19 @@ electron-to-chromium@^1.4.251:
26502674
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.275.tgz#db25c8e39c9cc910a996d1ec9b73eee834cb0ac1"
26512675
integrity sha512-aJeQQ+Hl9Jyyzv4chBqYJwmVRY46N5i2BEX5Cuyk/5gFCUZ5F3i7Hnba6snZftWla7Gglwc5pIgcd+E7cW+rPg==
26522676

2677+
elliptic@^6.5.2:
2678+
version "6.5.4"
2679+
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb"
2680+
integrity sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==
2681+
dependencies:
2682+
bn.js "^4.11.9"
2683+
brorand "^1.1.0"
2684+
hash.js "^1.0.0"
2685+
hmac-drbg "^1.0.1"
2686+
inherits "^2.0.4"
2687+
minimalistic-assert "^1.0.1"
2688+
minimalistic-crypto-utils "^1.0.1"
2689+
26532690
emittery@^0.7.1:
26542691
version "0.7.2"
26552692
resolved "https://registry.yarnpkg.com/emittery/-/emittery-0.7.2.tgz#25595908e13af0f5674ab419396e2fb394cdfa82"
@@ -3486,6 +3523,14 @@ has@^1.0.3:
34863523
dependencies:
34873524
function-bind "^1.1.1"
34883525

3526+
hash.js@^1.0.0, hash.js@^1.0.3:
3527+
version "1.1.7"
3528+
resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.7.tgz#0babca538e8d4ee4a0f8988d68866537a003cf42"
3529+
integrity sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==
3530+
dependencies:
3531+
inherits "^2.0.3"
3532+
minimalistic-assert "^1.0.1"
3533+
34893534
34903535
version "0.8.0"
34913536
resolved "https://registry.yarnpkg.com/hermes-estree/-/hermes-estree-0.8.0.tgz#530be27243ca49f008381c1f3e8b18fb26bf9ec0"
@@ -3505,6 +3550,15 @@ hermes-profile-transformer@^0.0.6:
35053550
dependencies:
35063551
source-map "^0.7.3"
35073552

3553+
hmac-drbg@^1.0.1:
3554+
version "1.0.1"
3555+
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
3556+
integrity sha512-Tti3gMqLdZfhOQY1Mzf/AanLiqh1WTiJgEj26ZuYQ9fbkLomzGchCws4FyrSd4VkpBfiNhaE1On+lOz894jvXg==
3557+
dependencies:
3558+
hash.js "^1.0.3"
3559+
minimalistic-assert "^1.0.0"
3560+
minimalistic-crypto-utils "^1.0.1"
3561+
35083562
hosted-git-info@^2.1.4:
35093563
version "2.8.9"
35103564
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9"
@@ -4661,10 +4715,10 @@ logkitty@^0.7.1:
46614715
dayjs "^1.8.15"
46624716
yargs "^15.1.0"
46634717

4664-
loglevel@^1.8.0:
4665-
version "1.8.0"
4666-
resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.8.0.tgz#e7ec73a57e1e7b419cb6c6ac06bf050b67356114"
4667-
integrity sha512-G6A/nJLRgWOuuwdNuA6koovfEV1YpqqAG4pRUlFaz3jj2QNZ8M4vBqnVA+HBTmU/AMNUtlOsMmSpF6NyOjztbA==
4718+
loglevel@^1.8.1:
4719+
version "1.8.1"
4720+
resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.8.1.tgz#5c621f83d5b48c54ae93b6156353f555963377b4"
4721+
integrity sha512-tCRIJM51SHjAayKwC+QAg8hT8vg6z7GSgLJKGvzuPb1Wc+hLzqtuVLxp6/HzSPOozuK+8ErAhy7U/sVzw8Dgfg==
46684722

46694723
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0:
46704724
version "1.4.0"
@@ -5155,6 +5209,16 @@ mimic-fn@^2.1.0:
51555209
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
51565210
integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==
51575211

5212+
minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1:
5213+
version "1.0.1"
5214+
resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7"
5215+
integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==
5216+
5217+
minimalistic-crypto-utils@^1.0.1:
5218+
version "1.0.1"
5219+
resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a"
5220+
integrity sha512-JIYlbt6g8i5jKfJ3xz7rF0LXmv2TkDxBLUkiBeZ7bAx4GnnNMr8xFpGnOxn6GhTEHx3SjRrZEoU+j04prX1ktg==
5221+
51585222
minimatch@^3.0.2, minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2:
51595223
version "3.1.2"
51605224
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
@@ -5804,6 +5868,11 @@ react-native-codegen@^0.70.5:
58045868
jscodeshift "^0.13.1"
58055869
nullthrows "^1.1.1"
58065870

5871+
react-native-encrypted-storage@^4.0.3:
5872+
version "4.0.3"
5873+
resolved "https://registry.yarnpkg.com/react-native-encrypted-storage/-/react-native-encrypted-storage-4.0.3.tgz#2a4d65459870511e8f4ccd22f02433dab7fa5e91"
5874+
integrity sha512-0pJA4Aj2S1PIJEbU7pN/Qvf7JIJx3hFywx+i+bLHtgK0/6Zryf1V2xVsWcrD50dfiu3jY1eN2gesQ5osGxE7jA==
5875+
58075876
react-native-gradle-plugin@^0.70.3:
58085877
version "0.70.3"
58095878
resolved "https://registry.yarnpkg.com/react-native-gradle-plugin/-/react-native-gradle-plugin-0.70.3.tgz#cbcf0619cbfbddaa9128701aa2d7b4145f9c4fc8"

0 commit comments

Comments
 (0)