@@ -716,6 +716,41 @@ export class ChainSessionManager {
716716 throw new InitializationError ( `Explicit session init failed after ${ maxRetries } attempts: ${ lastError . message } ` )
717717 }
718718
719+ /**
720+ * Checks if the current session has permission to execute a set of transactions.
721+ * @param transactions The transactions to check permissions for.
722+ * @returns A promise that resolves to true if the session has permission, false otherwise.
723+ */
724+ async hasPermission ( transactions : Transaction [ ] ) : Promise < boolean > {
725+ if ( ! this . wallet || ! this . sessionManager || ! this . provider || ! this . isInitialized ) {
726+ return false
727+ }
728+
729+ try {
730+ const calls : Payload . Call [ ] = transactions . map ( ( tx ) => ( {
731+ to : tx . to ,
732+ value : tx . value ?? 0n ,
733+ data : tx . data ?? '0x' ,
734+ gasLimit : tx . gasLimit ?? 0n ,
735+ delegateCall : tx . delegateCall ?? false ,
736+ onlyFallback : tx . onlyFallback ?? false ,
737+ behaviorOnError : tx . behaviorOnError ?? ( 'revert' as const ) ,
738+ } ) )
739+
740+ // Directly check if there are signers with the necessary permissions for all calls.
741+ // This will throw an error if any call is not supported.
742+ await this . sessionManager . findSignersForCalls ( this . wallet . address , this . chainId , calls )
743+ return true
744+ } catch ( error ) {
745+ // An error from findSignersForCalls indicates a permission failure.
746+ console . warn (
747+ `Permission check failed for chain ${ this . chainId } :` ,
748+ error instanceof Error ? error . message : String ( error ) ,
749+ )
750+ return false
751+ }
752+ }
753+
719754 /**
720755 * Checks if the current session has a valid signer.
721756 * @returns A promise that resolves to true if the session has a valid signer, false otherwise.
0 commit comments