Skip to content

Sessions

Functions for managing Smart Sessions (Rhinestone + Biconomy) -- scoped session keys for AI agents.

Constants

typescript
SMART_SESSIONS_ADDRESS = "0x00000000002B0eCfbD0496EE71e01257dA0E37DE"
OWNABLE_VALIDATOR_ADDRESS = "0x2483DA3A338895199E5e538530213157e931Bf06"

buildSession

typescript
buildSession(
  sessionKeyAddress: Address,
  params: CreateSessionParams,
  chainId: number,
  sessionValidatorAddress?: Address
): Session

Build a Smart Sessions session structure.

ParameterTypeRequiredDescription
sessionKeyAddressAddressYesPublic address of the session key
paramsCreateSessionParamsYesSession parameters (actions, expiry, limits)
chainIdnumberYesChain ID for the session
sessionValidatorAddressAddressNoCustom session validator address

Validation:

  • expiresAt must be in the future
  • At least one action is required

Throws: SessionError

getSmartSessionsModule

typescript
getSmartSessionsModule(sessions?: Session[]): {
  address: Address;
  initData: Hex;
}

Get the Smart Sessions module installation config for use during wallet creation or module installation.

ParameterTypeRequiredDescription
sessionsSession[]NoInitial sessions to install

computePermissionId

typescript
computePermissionId(session: Session): Hex

Compute the deterministic permission ID for a session. This ID is used for revoking sessions and encoding use-session signatures.

getEnableDetails

typescript
getEnableDetails(
  sessions: Session[],
  account: Address,
  publicClients: PublicClient[],
  enableValidatorAddress?: Address
): Promise<EnableSessionData>

Get the data the owner must sign to enable a session on-chain.

ParameterTypeRequiredDescription
sessionsSession[]YesSessions to enable
accountAddressYesSmart account address
publicClientsPublicClient[]Yesviem public clients for chain queries
enableValidatorAddressAddressNoCustom validator address

Returns:

typescript
interface EnableSessionData {
  permissionEnableHash: Hex;
  mode: SmartSessionMode;
  permissionId: Hex;
  signature: Hex;
  enableSessionData: Hex;
}

encodeUseSessionSignature

typescript
encodeUseSessionSignature(permissionId: Hex, signature: Hex): Hex

Encode a signature for using an existing (already enabled) session.

encodeEnableSessionSignature

typescript
encodeEnableSessionSignature(
  permissionId: Hex,
  signature: Hex,
  enableSessionData: Hex
): Hex

Encode a signature for enabling and using a session in one step.

getRemoveAction

typescript
getRemoveAction(permissionId: Hex): {
  to: Address;
  value: bigint;
  data: Hex;
}

Get the transaction data to revoke a session on-chain. The returned object can be passed directly to execute().

SmartSessionMode

typescript
enum SmartSessionMode {
  USE = 0,
  ENABLE = 1,
}
ModeValueDescription
USE0Use an already-enabled session
ENABLE1Enable a new session and use it in the same UserOp

Released under the MIT License.