@@ -102,7 +102,7 @@ export class Web3Auth extends SafeEventEmitter<Web3AuthSfaEvents> implements IWe
102102 }
103103
104104 get connected ( ) : boolean {
105- return Boolean ( this . sessionManager ?. sessionId ) ;
105+ return this . status === ADAPTER_STATUS . CONNECTED ;
106106 }
107107
108108 get provider ( ) : IProvider | null {
@@ -182,9 +182,16 @@ export class Web3Auth extends SafeEventEmitter<Web3AuthSfaEvents> implements IWe
182182
183183 const { chainNamespace, chainId } = this . coreOptions . chainConfig || { } ;
184184 if ( ! this . authInstance || ! this . privKeyProvider ) throw WalletInitializationError . notReady ( ) ;
185- const accounts = await this . privKeyProvider . provider . request < unknown , string [ ] > ( {
186- method : chainNamespace === CHAIN_NAMESPACES . EIP155 ? "eth_accounts" : "getAccounts" ,
187- } ) ;
185+ const [ accounts , publicKey ] = await Promise . all ( [
186+ this . privKeyProvider . provider . request < unknown , string [ ] > ( {
187+ method : chainNamespace === CHAIN_NAMESPACES . EIP155 ? "eth_accounts" : "getAccounts" ,
188+ } ) ,
189+ this . privKeyProvider . provider . request < unknown , string [ ] > ( {
190+ method : "public_key" ,
191+ } ) ,
192+ ] ) ;
193+ // const thresholdPrivKey = this._getBasePrivKey();
194+
188195 if ( accounts && accounts . length > 0 ) {
189196 const existingToken = getSavedToken ( accounts [ 0 ] as string , "SFA" ) ;
190197 if ( existingToken ) {
@@ -204,6 +211,35 @@ export class Web3Auth extends SafeEventEmitter<Web3AuthSfaEvents> implements IWe
204211 issuedAt : new Date ( ) . toISOString ( ) ,
205212 } ;
206213
214+ const additionalMetadata = {
215+ email : userInfo . email ,
216+ name : userInfo . name ,
217+ profileImage : userInfo . profileImage ,
218+ aggregateVerifier : userInfo . aggregateVerifier ,
219+ verifier : userInfo . verifier ,
220+ verifierId : userInfo . verifierId ,
221+ typeOfLogin : userInfo . typeOfLogin || "jwt" ,
222+ oAuthIdToken : userInfo . oAuthIdToken ,
223+ oAuthAccessToken : userInfo . oAuthAccessToken ,
224+ wallets : [ ] as unknown [ ] ,
225+ signatures : this . state . signatures ,
226+ network : this . coreOptions . web3AuthNetwork ,
227+ } ;
228+
229+ if ( this . coreOptions . usePnPKey ) {
230+ additionalMetadata . wallets . push ( {
231+ public_key : publicKey ,
232+ type : "web3auth_app_key" ,
233+ curve : chainNamespace === CHAIN_NAMESPACES . EIP155 ? KEY_TYPE . SECP256K1 : KEY_TYPE . ED25519 ,
234+ } ) ;
235+ } else {
236+ additionalMetadata . wallets . push ( {
237+ public_key : publicKey ,
238+ type : "web3auth_threshold_key" ,
239+ curve : chainNamespace === CHAIN_NAMESPACES . EIP155 ? KEY_TYPE . SECP256K1 : KEY_TYPE . ED25519 ,
240+ } ) ;
241+ }
242+
207243 const challenge = await signChallenge ( payload , chainNamespace ) ;
208244 const signedMessage = await this . _getSignedMessage ( challenge , accounts , chainNamespace ) ;
209245 const idToken = await verifySignedChallenge (
@@ -213,7 +249,9 @@ export class Web3Auth extends SafeEventEmitter<Web3AuthSfaEvents> implements IWe
213249 this . SFA_ISSUER ,
214250 this . coreOptions . sessionTime ,
215251 this . coreOptions . clientId ,
216- this . coreOptions . web3AuthNetwork as WEB3AUTH_NETWORK_TYPE
252+ this . coreOptions . web3AuthNetwork as WEB3AUTH_NETWORK_TYPE ,
253+ undefined ,
254+ additionalMetadata
217255 ) ;
218256 saveToken ( accounts [ 0 ] as string , "SFA" , idToken ) ;
219257 return {
@@ -318,11 +356,12 @@ export class Web3Auth extends SafeEventEmitter<Web3AuthSfaEvents> implements IWe
318356
319357 async logout ( ) : Promise < void > {
320358 if ( ! this . connected ) throw WalletLoginError . notConnectedError ( "Not logged in" ) ;
321- const sessionId = this . currentStorage . get < string > ( "sessionId" ) ;
322- if ( ! sessionId ) throw WalletLoginError . fromCode ( 5000 , "User not logged in" ) ;
323359
324- await this . sessionManager . invalidateSession ( ) ;
325- this . currentStorage . set ( "sessionId" , "" ) ;
360+ if ( this . coreOptions . mode !== SDK_MODE . NODE ) {
361+ await this . sessionManager . invalidateSession ( ) ;
362+ this . currentStorage . set ( "sessionId" , "" ) ;
363+ }
364+
326365 this . updateState ( {
327366 privKey : "" ,
328367 userInfo : {
@@ -415,18 +454,26 @@ export class Web3Auth extends SafeEventEmitter<Web3AuthSfaEvents> implements IWe
415454 let finalPrivKey = privKey . padStart ( 64 , "0" ) ;
416455 // get app scoped keys.
417456 if ( this . coreOptions . usePnPKey ) {
418- const pnpPrivKey = subkey ( finalPrivKey , Buffer . from ( this . coreOptions . clientId , "base64" ) ) ;
419- finalPrivKey = pnpPrivKey . padStart ( 64 , "0" ) ;
457+ finalPrivKey = this . getSubKey ( finalPrivKey ) ;
420458 }
421459 if ( this . coreOptions . chainConfig . chainNamespace === CHAIN_NAMESPACES . SOLANA ) {
422- if ( ! this . privKeyProvider . getEd25519Key ) {
423- throw WalletLoginError . fromCode ( 5000 , "Private key provider is not valid, Missing getEd25519Key function" ) ;
424- }
425- finalPrivKey = this . privKeyProvider . getEd25519Key ( finalPrivKey ) ;
460+ finalPrivKey = this . getEd25519Key ( finalPrivKey ) ;
426461 }
427462 return finalPrivKey ;
428463 }
429464
465+ private getSubKey ( privKey : string ) {
466+ const pnpPrivKey = subkey ( privKey , Buffer . from ( this . coreOptions . clientId , "base64" ) ) ;
467+ return pnpPrivKey . padStart ( 64 , "0" ) ;
468+ }
469+
470+ private getEd25519Key ( privKey : string ) {
471+ if ( ! this . privKeyProvider . getEd25519Key ) {
472+ throw WalletLoginError . fromCode ( 5000 , "Private key provider is not valid, Missing getEd25519Key function" ) ;
473+ }
474+ return this . privKeyProvider . getEd25519Key ( privKey ) ;
475+ }
476+
430477 private async getTorusKey ( loginParams : LoginParams ) : Promise < string > {
431478 const { verifier, verifierId, idToken, subVerifierInfoArray } = loginParams ;
432479
0 commit comments