Protocol
Session keys
A session key is a short-lived key the passkey authorises for a fixed set of calls, with cumulative caps, a rate limit and an expiry the EntryPoint enforces.
What a session key is
A session key is an ordinary secp256k1 key pair that the app generates and keeps, for example in page memory. The passkey authorises it once for a list of call shapes. After that, the app can sign operations with the session key without a Face ID prompt per action, and the account checks every call against the grant.
A session key signs the raw userOpHash (no EIP-191 prefix). The account signature is:
0x01 ++ abi.encode(address sessionKey, bytes ecdsaSignature) // ecdsaSignature = r ++ s ++ v, 65 bytesGranting
function grantSession(
address key,
uint48 validUntil, // unix seconds, must be in the future
uint32 period, // seconds per rate window, > 0
uint32 maxUsesPerPeriod, // operations per window, > 0
Scope[] calldata scopes // 1 to 8 scopes
) external onlySelf;onlySelf means the call must come from the account itself, which only happens through execute(account, 0, data) in an operation signed by a passkey. A scope may not target the account or the EntryPoint; such a grant reverts with BadSession. Granting the same key again replaces its scopes and resets its spend and its rate window.
The Scope struct
struct Scope {
address target; // contract the key may call
bytes4 selector; // function it may call there
uint8 amountArg; // index of a uint256 argument to cap, or 255 for none
uint128 maxValue; // total native HYPE the key may send with these calls
uint128 maxAmount; // total of the amountArg argument over the session
}| Field | Meaning |
|---|---|
target | Exact contract address. No wildcards. |
selector | Exact 4-byte function selector. A call without a selector never matches. |
amountArg | The argument index after the selector (0 is the first). The account reads the 32-byte word at offset 4 + 32 * amountArg of the call data, so it must point at a static argument such as a uint256 amount. 255 (NO_AMOUNT_ARG) disables the amount cap. |
maxValue | Cap on the sum of native value sent with matching calls over the whole session. 0 means the key can send no HYPE. |
maxAmount | Cap on the sum of the amountArg argument over the whole session. |
For example, a scope with target a token, selector transfer(address,uint256), amountArg = 1 and maxAmount = 100e18 lets the key send at most 100 tokens in total, to anyone, for the life of the session, and nothing else.
Validation, step by step
- 1else fails
ecrecover(userOpHash, sig)equals thesessionKeynamed in the signature - 2The session for that key is activeelse fails
- 3Rate window:else reverts
usesInPeriod < maxUsesPerPeriod, then one use is booked - 4else reverts
callDataisexecute(...)or a non-emptyexecuteBatch(...) - 5For every inner call:else revertstarget is not the account and not the EntryPoint; data has a selector; a scope matches target and selector; total value stays within
maxValue; total amount stays withinmaxAmount - 6Returnspasses
validUntil << 160. The EntryPoint refuses the op after that time.
Gates 3 to 5 revert instead of returning a failure code. Validation books spend call by call; if call 3 of a batch is out of scope, the revert discards what calls 1 and 2 booked, so no partial spend can persist. A reverted validation also means the bundler drops the operation at simulation and it never reaches a bundle.
Cumulative caps
Spend is tracked per scope, over the whole session, not per operation or per window. Inside one operation the account adds every matching call's value and amount before comparing with the caps, so splitting a transfer across a batch cannot exceed a scope. If several scopes share a target and selector, the first one in the list is the one charged.
Spend is booked during validation. If the inner call later reverts during execution, the booked spend stays. The caps count what the key was allowed to try, which errs on the safe side.
Rate limit
maxUsesPerPeriod operations are allowed per window of period seconds. A window opens at the first operation after the previous one ended; a batch counts as one use. An operation over the rate reverts with SessionRateExceeded.
Sponsored session operations are also limited by the paymaster: 50 per account per UTC day at the current setting, raised by the stake boost. See Paymaster.
The rate window reads block.timestamp during validation. ERC-7562 forbids that opcode in validation for the shared public mempool. The HIP-ID bundler is a private mempool and accepts it, so these operations are meant for this bundler or for direct submission to the EntryPoint, not for public ERC-7562 bundlers.
Expiry
Validation returns validUntil in bits 160 to 207 of validationData. The EntryPoint itself refuses the operation once that time has passed, so expiry does not depend on the bundler or on any later call to the account. The bundler also refuses operations whose validity ends within 10 seconds.
Revoking
revokeSession(key) is one passkey-signed call through execute(account, 0, data). It deactivates the key at once; any later operation signed by it fails at gate 2. Several keys can be revoked in one executeBatch.
import { revokeSessionCall } from "@/sdk/hipid";
const callData = revokeSessionCall(account, sessionKeyAddress); // then sponsor, sign with the passkey, sendThe Stocks preset
Tokenized equities already trade on Elysium as tokens bridged from HyperCore: the Wrapped xStock family (wNVDAx, wSPYx, wQQQx and more) and the EQX family (EQNVDA, EQTSLA, EQAAPL and more). Many look-alike tokens use the same names, so the list in lib/stocks.ts keeps only tokens that pass one on-chain check: on Elysium, l2Gateway() is the canonical bridge gateway and l1Address() is the HyperEVM contract that Hyperliquid links to the HyperCore spot token. scripts/verify-stock-tokens.py re-runs that check for all 18. The issuers are third parties; the check proves which contracts are the bridged originals, not what backs them.
The preset compiles to one scope per stock: transfer(address,uint256) on that token, amount argument 1, a cap in the token's own decimals, no HYPE. With a 24 hour lifetime the session cap is a daily cap per stock. Up to 8 stocks fit in one key.
import { erc20TransferScope, grantSessionCall } from "@/sdk/hipid";
import { STOCK_TOKENS } from "@/lib/stocks";
const picked = STOCK_TOKENS.filter((t) => ["wNVDAx", "EQNVDA", "EQTSLA"].includes(t.symbol));
const scopes = picked.map((t) => erc20TransferScope(t.address, 10n ** BigInt(t.decimals))); // 1 share each
const callData = grantSessionCall(account, key, now + 86_400, 86_400, 20, scopes); // then sponsor, Face ID, sendGranted and revoked on Elysium mainnet from the production site with a passkey: grant 0xf27bfc67…bf59 (8 scopes, read back with session(key)), revoke 0x41b4d6c7…ba56. The live marks on the home page come from the bundler's GET /v1/stocks: HIP-3 stock perps streamed from Hyperliquid. Trading those perps from the account waits for EL1 precompiles.
What it can never do
- Call the account itself. Every admin function (
addPasskey,removePasskey,grantSession,revokeSession,setGuardian,cancelRecovery) isonlySelf, and a session call targeting the account is refused at gate 5. So a key cannot extend itself, grant another key, or touch passkeys. - Call the EntryPoint. Refused at gate 5, so the key cannot withdraw the account's EntryPoint deposit.
- Send a plain native transfer. A call with fewer than 4 bytes of data is refused, whatever
maxValuesays. Value can only travel with a scoped function call. - Use any entry point other than execute and executeBatch. Calling an admin function directly as
callDatais refused at gate 4. - Outlive its expiry or survive a revoke. See above.
Reentrancy
A scoped target could try to call back into the account during execution. It gets nowhere: admin functions require msg.sender == address(this), and inside that callback msg.sender is the target. execute and executeBatch require msg.sender == entryPoint. The only way to reach an admin function is an operation the EntryPoint validated with a passkey signature. test_reentryFromScopedTargetFails grants a scope to a contract that calls addPasskey on the account, and checks that the call reverts with NotSelf and the passkey count is unchanged.
Tests
| Test | Checks |
|---|---|
testFuzz_sessionBatchNeverExceedsScope | Random 4-call transfer batches over two rounds against a random cap: the approved total never exceeds the cap and the recorded spend equals it exactly |
testFuzz_sessionValueCap | Two calls with random native value: the approved total never exceeds maxValue |
test_sessionCumulativeCap | 60 then 41 against a cap of 100: the second is refused |
test_sessionRejectsSelfAndOtherTargets | Self-call, an unscoped selector and a direct admin call are all refused |
test_sessionCannotGrantOnSelf | A grant whose scope targets the account reverts |
test_sessionRateLimit | Third use in a window refused, allowed again in the next window |
test_sessionRevoked | A revoked key fails |
test_sessionWrongSigner | A signature by another key claiming the session address fails |
test_sessionWithinScope | An in-scope transfer passes and returns validUntil for the EntryPoint |
Fuzz tests run 512 cases each (foundry.toml).



