Crates.io | session-keys |
lib.rs | session-keys |
version | 2.0.5 |
source | src |
created_at | 2023-09-11 01:13:47.980859 |
updated_at | 2024-06-21 08:26:29.950364 |
description | Gum Session Protocol (GPL Session) |
homepage | |
repository | https://github.com/magicblock-labs/gum-program-library |
max_upload_size | |
id | 969110 |
size | 10,157 |
Manage sessions in your Solana Anchor Programs.
cargo add session-keys --features no-entrypoint
use session_keys::{SessionError, SessionToken, session_auth_or, Session};
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>,
.....
}
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<()> {
.....
}
See KamikazeJoe for an example of a game using session-keys.