Skip to content
24 changes: 24 additions & 0 deletions apps/iframe/src/requests/permissionless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EIP1193UnauthorizedError,
EIP1193UnsupportedMethodError,
EIP1193UserRejectedRequestError,
HappyWalletCapability,
type Msgs,
type ProviderMsgsFromApp,
requestPayloadIsHappyMethod,
Expand All @@ -17,6 +18,7 @@ import {
InvalidAddressError,
type Transaction,
type TransactionReceipt,
type WalletCapabilities,
hexToBigInt,
isAddress,
parseSignature,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions support/wallet-common/lib/interfaces/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
])

/**
Expand Down
Loading