Smart Wallet UX
Scopes & Permissions
Designing safe session scopes.
Scopes & Permissions
A Session Key is only safe if its scope is tightly defined.
1. Contract Scoping (The Allowlist)
Restrict the key to interacting with only specific contracts.
permission GameContractScope -> 1.0.0 {
parameters: {
gameContract: address
}
when: {
context.target == parameters.gameContract
}
}2. Function Scoping (Least Privilege)
Restrict the key to specific functions on that contract.
permission GameFunctionScope -> 1.0.0 {
parameters: {
gameContract: address,
moveSelector: bytes4,
attackSelector: bytes4
}
when: {
context.target == parameters.gameContract,
any {
calldata.selector == parameters.moveSelector,
calldata.selector == parameters.attackSelector
}
}
}3. Value Scoping (Spend Limits)
If the session involves spending tokens (e.g., buying in-game items), cap the total spend.
permission SessionSpendCap -> 1.0.0 {
parameters: {
maxSpend: uint256
}
when: {
calldata.amount <= parameters.maxSpend
}
}4. Time Scoping (TTL)
Ensure the key expires automatically.
permission SessionExpiry -> 1.0.0 {
parameters: {
expiresAt: uint256
}
when: {
context.timestamp < parameters.expiresAt
}
}Stack scopes for safety
Combine contract, function, value, and time limits to build safe session keys.