9 stable releases

3.0.10 Nov 26, 2025
2.0.8 Sep 4, 2025
2.0.7 Apr 25, 2025
2.0.6 Jan 6, 2025
2.0.1 Sep 11, 2023

#3 in #gum

Download history 124/week @ 2025-08-13 94/week @ 2025-08-20 100/week @ 2025-08-27 263/week @ 2025-09-03 218/week @ 2025-09-10 131/week @ 2025-09-17 166/week @ 2025-09-24 111/week @ 2025-10-01 74/week @ 2025-10-08 121/week @ 2025-10-15 86/week @ 2025-10-22 96/week @ 2025-10-29 56/week @ 2025-11-05 41/week @ 2025-11-12 187/week @ 2025-11-19 22/week @ 2025-11-26

325 downloads per month
Used in bolt-lang

GPL-3.0-or-later

22KB
456 lines

GPL Session

Manage sessions in your Solana Anchor Programs.

Installation

cargo add session-keys --features no-entrypoint

Usage

  1. Import the dependencies
use session_keys::{SessionError, SessionToken, session_auth_or, Session};
  1. Derive the Session trait on your instruction struct
#[derive(Accounts, Session)]
pub struct Instruction<'info> {
    .....
    pub user: Account<'info, User>,

    #[session(
        // The ephemeral keypair signing the transaction
        signer = signer,
        // The authority of the user account which must have created the session
        authority = user.authority.key()
    )]
    // Session Tokens are passed as optional accounts
    pub session_token: Option<Account<'info, SessionToken>>,

    #[account(mut)]
    pub signer: Signer<'info>,
    .....
}
  1. Add the session_auth_or macro to your instruction handler with fallback logic on who the instruction should validate the signer when sessions are not present and an appropirate ErrorCode. If you've used require*! macros in anchor_lang you already know how this works.
#[session_auth_or(
    ctx.accounts.user.authority.key() == ctx.accounts.authority.key(),
    ErrorCode
)]
pub fn ix_handler(ctx: Context<Instruction>,) -> Result<()> {
.....
}

Example

See KamikazeJoe for an example of a game using session-keys.

Dependencies

~9–12MB
~244K SLoC