@@ -449,9 +449,9 @@ export class ChainSessionManager {
449449 throw new ModifyExplicitSessionError ( 'Session address is required.' )
450450 }
451451
452- const existingExplicitSession : ExplicitSession = this . explicitSessions . find ( ( s ) =>
452+ const existingExplicitSession = this . explicitSessions . find ( ( s ) =>
453453 Address . isEqual ( s . sessionAddress ! , modifiedExplicitSession . sessionAddress ! ) ,
454- ) as ExplicitSession
454+ )
455455 if ( ! existingExplicitSession ) {
456456 throw new ModifyExplicitSessionError ( 'Session not found.' )
457457 }
@@ -487,6 +487,8 @@ export class ChainSessionManager {
487487 }
488488
489489 existingExplicitSession . permissions = modifiedExplicitSession . permissions
490+ existingExplicitSession . deadline = modifiedExplicitSession . deadline
491+ existingExplicitSession . valueLimit = modifiedExplicitSession . valueLimit
490492
491493 if ( this . transport ?. mode === TransportMode . POPUP ) {
492494 this . transport ?. closeWallet ( )
@@ -721,6 +723,20 @@ export class ChainSessionManager {
721723 throw new InitializationError ( `Explicit session init failed after ${ maxRetries } attempts: ${ lastError . message } ` )
722724 }
723725
726+ private async _refreshExplicitSession ( expiredSignerAddress : Address . Address ) : Promise < void > {
727+ if ( ! this . wallet || ! this . sessionManager || ! this . provider || ! this . isInitialized )
728+ throw new InitializationError ( 'Session is not initialized.' )
729+ // Find current explicit session
730+ const explicitSigner = this . explicitSessions . find ( ( s ) => Address . isEqual ( s . sessionAddress , expiredSignerAddress ) )
731+ if ( ! explicitSigner ) throw new ModifyExplicitSessionError ( 'Explicit session not found.' )
732+ // Update the deadline
733+ const newExplicitSession = {
734+ ...explicitSigner ,
735+ deadline : BigInt ( Math . floor ( Date . now ( ) / 1000 ) ) + BigInt ( 24 * 60 * 60 ) ,
736+ }
737+ await this . modifyExplicitSession ( newExplicitSession )
738+ }
739+
724740 /**
725741 * Checks if the current session has permission to execute a set of transactions.
726742 * @param transactions The transactions to check permissions for.
@@ -747,6 +763,19 @@ export class ChainSessionManager {
747763 await this . sessionManager . findSignersForCalls ( this . wallet . address , this . chainId , calls )
748764 return true
749765 } catch ( error ) {
766+ if ( error instanceof Error && error . message . includes ( 'Signer supporting call is expired' ) ) {
767+ // Extract the expired signer address from the message with address regex
768+ const expiredSignerAddress = error . message . match ( / ( 0 x [ 0 - 9 a - f A - F ] { 40 } ) / ) ?. [ 1 ]
769+ if ( expiredSignerAddress ) {
770+ // Refresh the session
771+ await this . _refreshExplicitSession ( Address . from ( expiredSignerAddress ) )
772+ // Retry the permission check
773+ return this . hasPermission ( transactions )
774+ } else {
775+ // Could not parse error message. Rethrow as this shouldn't happen.
776+ throw error
777+ }
778+ }
750779 // An error from findSignersForCalls indicates a permission failure.
751780 console . warn (
752781 `Permission check failed for chain ${ this . chainId } :` ,
0 commit comments