gpl-session

Crates.iogpl-session
lib.rsgpl-session
version2.0.0
sourcesrc
created_at2023-04-03 14:34:30.388728
updated_at2023-08-03 06:47:21.998197
descriptionGum Session Protocol (GPL Session)
homepage
repositoryhttps://github.com/gumhq/gpl
max_upload_size
id829129
size10,071
(abishekk92)

documentation

README

GPL Session

Manage sessions in your Solana Anchor Programs.

Installation

cargo add gpl-session --features no-entrypoint

If you're using anchor 0.26.0

cargo add gpl-session@0.2.0 --features no-entrypoint

Usage

  1. Import the dependencies
use gpl_session::{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<()> {
.....
}

Commit count: 74

cargo fmt