Skip to content

Commit f5027d2

Browse files
Merge pull request #82 from Web3Auth/feat/allow-session-key-override
Allows dapp to override the session key
2 parents 01697a4 + ef5a409 commit f5027d2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Web3Auth.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
import { decodeToken } from "./utils";
4444

4545
export class Web3Auth extends SafeEventEmitter<Web3AuthSfaEvents> implements IWeb3Auth {
46-
readonly coreOptions: Omit<Web3AuthOptions, "storage"> & { storage: IAsyncStorage | IStorage | ISecureStore };
46+
readonly coreOptions: Omit<Web3AuthOptions, "storage"> & { storage: IAsyncStorage | IStorage | ISecureStore; sessionKey?: string };
4747

4848
readonly connectedAdapterName = WALLET_ADAPTERS.SFA;
4949

@@ -73,7 +73,7 @@ export class Web3Auth extends SafeEventEmitter<Web3AuthSfaEvents> implements IWe
7373

7474
private plugins: Record<string, IPlugin> = {};
7575

76-
constructor(options: Web3AuthOptions) {
76+
constructor(options: Web3AuthOptions & { sessionKey?: string }) {
7777
super();
7878
if (!options.clientId) throw WalletInitializationError.invalidParams("Please provide a valid clientId in constructor");
7979
if (!options.privateKeyProvider) throw WalletInitializationError.invalidParams("Please provide a valid privateKeyProvider in constructor");
@@ -126,7 +126,7 @@ export class Web3Auth extends SafeEventEmitter<Web3AuthSfaEvents> implements IWe
126126
throw WalletInitializationError.invalidParams("provider should have chainConfig and should be initialized with chainId and chainNamespace");
127127
}
128128

129-
const storageKey = `${this.baseStorageKey}_${this.coreOptions.chainConfig.chainNamespace === CHAIN_NAMESPACES.SOLANA ? "solana" : "eip"}_${this.coreOptions.usePnPKey ? "pnp" : "core_kit"}`;
129+
const storageKey = this.coreOptions.sessionKey || `${this.baseStorageKey}_${this.coreOptions.usePnPKey ? "pnp" : "core_kit"}`;
130130
this.currentStorage = new AsyncStorage(storageKey, this.coreOptions.storage);
131131
this.nodeDetails = fetchLocalConfig(this.coreOptions.web3AuthNetwork, KEY_TYPE.SECP256K1);
132132
this.authInstance = new Torus({
@@ -159,7 +159,8 @@ export class Web3Auth extends SafeEventEmitter<Web3AuthSfaEvents> implements IWe
159159
});
160160
if (data && data.privKey) {
161161
this.torusPrivKey = data.basePrivKey;
162-
await this.privKeyProvider.setupProvider(data.privKey);
162+
const finalPrivKey = await this.getFinalPrivKey(data.basePrivKey);
163+
await this.privKeyProvider.setupProvider(finalPrivKey);
163164
// setup aa provider after private key provider is setup
164165
if (this.accountAbstractionProvider) {
165166
await this.accountAbstractionProvider.setupProvider(this.privKeyProvider);

0 commit comments

Comments
 (0)