Skip to content
Lattice

SessionKey

Git Source

Inherits: ISessionKey

Title: SessionKey

Author: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80)

Session-key facet. An admin registers scoped, expiring secondary keys (a (target, selector) allowlist + validity window); a registered key can then authorize batches through the ERC7821Executor signed-opData path without holding the owner key.

Stateless delegator — logic/storage live in SessionKeyLib. Enforces expiry, the allowlist (with ANY_* wildcards) and per-token cumulative spend limits, with post-batch approval resets on capped tokens. Revoking a key drops its grants and limits.

Note:

  • lattice-version: 0.1.0

Functions

registerSessionKey

Registers (or replaces) a session key with a validity window + a (target, selector) allowlist.

Admin only. Re-registering a key that was not revoked overwrites the validity window and adds the given permissions to its existing ones. After revokeSessionKey, a registration starts clean.

function registerSessionKey(address key, uint48 validAfter, uint48 validUntil, Permission[] calldata permissions)
        external
        virtual;

Parameters

NameTypeDescription
keyaddress
validAfteruint48
validUntiluint48
permissionsPermission[]

revokeSessionKey

Revokes a session key. Admin only.

Clears the validity window, invalidates every permission granted so far, and deletes the key's spend caps and spent counters. Re-registering the key restores none of them; set its limits again.

function revokeSessionKey(address key) external virtual;

Parameters

NameTypeDescription
keyaddress

isSessionKeyActive

Whether key is registered and currently within its validity window.

function isSessionKeyActive(address key) external view virtual returns (bool);

Parameters

NameTypeDescription
keyaddress

Returns

NameTypeDescription
<none>bool

sessionKeyValidity

The validity window of key (validUntil == 0 means unregistered/revoked).

function sessionKeyValidity(address key) external view virtual returns (uint48 validAfter, uint48 validUntil);

Parameters

NameTypeDescription
keyaddress

Returns

NameTypeDescription
validAfteruint48
validUntiluint48

isCallPermitted

Whether key is permitted to call (target, selector) (honoring wildcards; ANY_TARGET does not match the account itself).

function isCallPermitted(address key, address target, bytes4 selector) external view virtual returns (bool);

Parameters

NameTypeDescription
keyaddress
targetaddress
selectorbytes4

Returns

NameTypeDescription
<none>bool

setSpendLimit

Sets a cumulative spend cap for key on token (native sentinel 0xEee…EEeE), resetting the spent counter to 0. Admin only. A token with no cap set is uncapped.

function setSpendLimit(address key, address token, uint256 cap) external virtual;

Parameters

NameTypeDescription
keyaddress
tokenaddress
capuint256

spendLimit

The spend cap and amount already spent for key on token.

function spendLimit(address key, address token) external view virtual returns (uint256 cap, uint256 spent);

Parameters

NameTypeDescription
keyaddress
tokenaddress

Returns

NameTypeDescription
capuint256
spentuint256

exportSelectors

ERC-8153 selector export: this facet's cuttable selectors, tightly packed (4 bytes each).

Excludes exportSelectors() itself (0x0ef22643) - it is never cut into a diamond. Order matches forge inspect SessionKey methodIdentifiers (alphabetical by signature); kept in exact parity by ExportSelectorsParityTest. Chunks: isCallPermitted(address,address,bytes4) 0xe4aea089 isSessionKeyActive(address) 0xf4d2a194 registerSessionKey(address,uint48,uint48,(address,bytes4)[]) 0xc8337e5a revokeSessionKey(address) 0x84f4fc6a sessionKeyValidity(address) 0x78b6590d setSpendLimit(address,address,uint256) 0xba9735cc spendLimit(address,address) 0xab1c8674

function exportSelectors() external pure virtual returns (bytes memory selectors);

Returns

NameTypeDescription
selectorsbytes