diff --git a/apps/iframe/src/requests/permissionless.ts b/apps/iframe/src/requests/permissionless.ts index fd5b3da380..6251ba04cd 100644 --- a/apps/iframe/src/requests/permissionless.ts +++ b/apps/iframe/src/requests/permissionless.ts @@ -5,6 +5,7 @@ import { EIP1193UnauthorizedError, EIP1193UnsupportedMethodError, EIP1193UserRejectedRequestError, + HappyWalletCapability, type Msgs, type ProviderMsgsFromApp, requestPayloadIsHappyMethod, @@ -17,6 +18,7 @@ import { InvalidAddressError, type Transaction, type TransactionReceipt, + type WalletCapabilities, hexToBigInt, isAddress, parseSignature, @@ -269,6 +271,28 @@ export async function dispatchHandlers(request: ProviderMsgsFromApp[Msgs.Request // The app may have bypassed the permission check, but this doesn't do anything. return null + case "wallet_getCapabilities": { + // This method SHOULD return an error if the user has not + // already authorized a connection between the application and + // the requested address. + checkAuthenticated() + const queryAddress = request.payload.params?.[0] + if (!queryAddress) { + throw new Error("Missing address parameter") + } + + const currentChainId = getCurrentChain().chainId + + const capabilities: WalletCapabilities = { + [currentChainId]: Object.fromEntries( + Object.values(HappyWalletCapability).map((capability) => [capability, { supported: true }]), + ), + } + + // c.f. https://www.eip5792.xyz/reference/getCapabilities#returns + return capabilities + } + case HappyMethodNames.REQUEST_SESSION_KEY: { const user = getUser() const targetContractAddress = request.payload.params[0] as Address diff --git a/support/wallet-common/lib/interfaces/permissions.ts b/support/wallet-common/lib/interfaces/permissions.ts index 0047327fd8..1e210e86db 100644 --- a/support/wallet-common/lib/interfaces/permissions.ts +++ b/support/wallet-common/lib/interfaces/permissions.ts @@ -66,6 +66,7 @@ const safeList = new Set([ "wallet_revokePermissions", // https://github.com/MetaMask/metamask-improvement-proposals/blob/main/MIPs/mip-2.md "web3_clientVersion", "web3_sha3", + "wallet_getCapabilities", ]) /**