Skip to content

Commit 96e35c3

Browse files
committed
Remove hasPermission. Check signer is in topology only
1 parent 5673a4c commit 96e35c3

2 files changed

Lines changed: 12 additions & 31 deletions

File tree

packages/wallet/dapp-client/src/ChainSessionManager.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -696,38 +696,20 @@ export class ChainSessionManager {
696696
}
697697

698698
/**
699-
* Checks if the current session has permission to execute a set of transactions.
700-
* @param transactions The transactions to check permissions for.
701-
* @returns A promise that resolves to true if the session has permission, false otherwise.
699+
* Checks if the current session has a valid signer.
700+
* @returns A promise that resolves to true if the session has a valid signer, false otherwise.
702701
*/
703-
async hasPermission(transactions: Transaction[]): Promise<boolean> {
702+
async hasValidSigner(): Promise<boolean> {
704703
if (!this.wallet || !this.sessionManager || !this.provider || !this.isInitialized) {
705704
return false
706705
}
707706

708-
try {
709-
const calls: Payload.Call[] = transactions.map((tx) => ({
710-
to: tx.to,
711-
value: tx.value ?? 0n,
712-
data: tx.data ?? '0x',
713-
gasLimit: tx.gasLimit ?? 0n,
714-
delegateCall: tx.delegateCall ?? false,
715-
onlyFallback: tx.onlyFallback ?? false,
716-
behaviorOnError: tx.behaviorOnError ?? ('revert' as const),
717-
}))
718-
719-
// Directly check if there are signers with the necessary permissions for all calls.
720-
// This will throw an error if any call is not supported.
721-
await this.sessionManager.findSignersForCalls(this.wallet.address, this.chainId, calls)
707+
const signerValidity = await this.sessionManager.listSignerValidity(this.chainId)
708+
if (signerValidity.some((s) => s.isValid)) {
722709
return true
723-
} catch (error) {
724-
// An error from findSignersForCalls indicates a permission failure.
725-
console.warn(
726-
`Permission check failed for chain ${this.chainId}:`,
727-
error instanceof Error ? error.message : String(error),
728-
)
729-
return false
730710
}
711+
// SessionSignerInvalidReason available here
712+
return false
731713
}
732714

733715
/**

packages/wallet/dapp-client/src/DappClient.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,17 +544,16 @@ export class DappClient {
544544
}
545545

546546
/**
547-
* Checks if the current session has permission to execute a set of transactions on a specific chain.
548-
* @param chainId The chain ID on which to check the permissions.
549-
* @param transactions An array of transactions to check permissions for.
550-
* @returns A promise that resolves to true if the session has permission, otherwise false.
547+
* Checks if the current session has a valid signer.
548+
* @param chainId The chain ID on which to check the signer.
549+
* @returns A promise that resolves to true if the session has a valid signer, otherwise false.
551550
*/
552-
async hasPermission(chainId: number, transactions: Transaction[]): Promise<boolean> {
551+
async hasValidSigner(chainId: number): Promise<boolean> {
553552
const chainSessionManager = this.chainSessionManagers.get(chainId)
554553
if (!chainSessionManager || !chainSessionManager.isInitialized) {
555554
return false
556555
}
557-
return await chainSessionManager.hasPermission(transactions)
556+
return await chainSessionManager.hasValidSigner()
558557
}
559558

560559
/**

0 commit comments

Comments
 (0)