Skip to content

Commit 96fc0df

Browse files
author
Musab Hussain
committed
dappShare feature
1 parent 079e1ae commit 96fc0df

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/Web3Auth.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ class Web3Auth {
3434
}
3535

3636
async login(options: SdkLoginParams): Promise<State> {
37+
//check for share
38+
if (this.initParams.loginConfig) {
39+
var loginConfigItem = Object.values(this.initParams.loginConfig)[0];
40+
if (loginConfigItem) {
41+
var share = await this.keyStore.get(loginConfigItem.verifier);
42+
if (share) {
43+
options.dappShare = share
44+
}
45+
}
46+
}
47+
3748
const result = await this.request("login", options.redirectUrl, options);
3849
if (result.type !== "success" || !result.url) {
3950
log.error(`[Web3Auth] login flow failed with error type ${result.type}`);
@@ -42,10 +53,17 @@ class Web3Auth {
4253

4354
const fragment = new URL(result.url).hash;
4455
const decodedPayload = base64url.decode(fragment);
45-
const state = JSON.parse(decodedPayload);
56+
const state = JSON.parse(decodedPayload) as State;
4657

4758
await this.keyStore.set("sessionId", state?.sessionId);
4859

60+
if (state.userInfo?.dappShare.length > 0) {
61+
this.keyStore.set(
62+
state.userInfo?.verifier,
63+
state.userInfo?.dappShare,
64+
)
65+
}
66+
4967
return state;
5068
}
5169

@@ -144,8 +162,19 @@ class Web3Auth {
144162
signature: (await sign(Buffer.from(sessionId, "hex"), hashData)).toString("hex"),
145163
timeout: 1
146164
});
165+
166+
this.keyStore.remove("ephemPublicKey");
167+
this.keyStore.remove("ivKey");
168+
this.keyStore.remove("mac");
169+
170+
if (this.initParams.loginConfig) {
171+
var loginConfigItem = Object.values(this.initParams.loginConfig)[0];
172+
if (loginConfigItem) {
173+
this.keyStore.remove(loginConfigItem.verifier);
174+
}
175+
}
147176
} catch (ex) {
148-
console.log(ex);
177+
log.error(ex);
149178
}
150179
}
151180
}

0 commit comments

Comments
 (0)