Skip to content

Commit

Permalink
Fixes rehydrate login
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1995 committed May 21, 2024
1 parent 7eeec53 commit 35094ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/Web3Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class Web3Auth extends SafeEventEmitter implements IWeb3Auth {
return null;
}

set provider(_: IProvider | null) {
throw new Error("Not implemented");
}

async init(): Promise<void> {
if (this.status !== ADAPTER_STATUS.NOT_READY) throw WalletInitializationError.notReady("Already initialized");
if (
Expand All @@ -112,8 +116,8 @@ class Web3Auth extends SafeEventEmitter implements IWeb3Auth {
) {
throw WalletInitializationError.invalidParams("provider should have chainConfig and should be initialized with chainId and chainNamespace");
}
this.chainConfig = this.privKeyProvider.currentChainConfig;
this.currentChainNamespace = this.privKeyProvider.currentChainConfig.chainNamespace;
this.chainConfig = this.coreOptions.chainConfig;
this.currentChainNamespace = this.chainConfig.chainNamespace;

const storageKey = `${this.baseStorageKey}_${this.currentChainNamespace === CHAIN_NAMESPACES.SOLANA ? "solana" : "eip"}_${this.coreOptions.usePnPKey ? "pnp" : "core_kit"}`;
this.currentStorage = BrowserStorage.getInstance(storageKey, this.coreOptions.storageKey);
Expand Down Expand Up @@ -146,12 +150,11 @@ class Web3Auth extends SafeEventEmitter implements IWeb3Auth {
this.currentStorage.set("sessionId", "");
});
if (data && data.privKey) {
this.torusPrivKey = data.privKey;
const finalPrivKey = await this.getFinalPrivKey(data.privKey);
await this.privKeyProvider.setupProvider(finalPrivKey);
this.torusPrivKey = data.basePrivKey;
await this.privKeyProvider.setupProvider(data.privKey);
this.updateState(data);
this.emit(ADAPTER_EVENTS.CONNECTED, { reconnected: true });
this.status = ADAPTER_STATUS.CONNECTED;
this.emit(ADAPTER_EVENTS.CONNECTED, { reconnected: true });
}
}
if (!this.state.privKey) {
Expand Down Expand Up @@ -353,10 +356,10 @@ class Web3Auth extends SafeEventEmitter implements IWeb3Auth {
const sessionId = OpenloginSessionManager.generateRandomSessionKey();
this.sessionManager.sessionId = sessionId;

await this.sessionManager.createSession({ privKey: finalPrivKey, userInfo, signatures, passkeyToken });
await this.sessionManager.createSession({ basePrivKey: privKey, privKey: finalPrivKey, userInfo, signatures, passkeyToken });

// update the local state.
this.updateState({ privKey: finalPrivKey, userInfo, signatures, passkeyToken });
this.updateState({ privKey: finalPrivKey, basePrivKey: privKey, userInfo, signatures, passkeyToken });
this.currentStorage.set("sessionId", sessionId);
this.emit(ADAPTER_EVENTS.CONNECTED, { reconnected: false });
this.status = ADAPTER_STATUS.CONNECTED;
Expand Down
1 change: 1 addition & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface Auth0UserInfo {
}

export interface SessionData {
basePrivKey?: string;
privKey?: string;
userInfo?: OpenloginUserInfo;
signatures?: string[];
Expand Down

0 comments on commit 35094ad

Please sign in to comment.