Skip to content

✨ Session keys #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
665b472
:sparkles: Adding low and intermediate api-levels
notdanilo Dec 23, 2024
b438e96
:recycle: Calculate entity pda from world.key instead of world.id
notdanilo Dec 30, 2024
9400db9
:lipstick: Fixing lint
notdanilo Dec 30, 2024
3ecca83
:white_check_mark: fixing world program AddEntity constraints and tests
notdanilo Dec 31, 2024
fe47a9f
:white_check_mark: Adding low-level api tests
notdanilo Dec 31, 2024
5751307
:sparkles: Re-exporting PROGRAM_ID and PROGRAM_IDL
notdanilo Jan 7, 2025
4a9b741
:recycle: Keeping Entity PDA derivation from World ID
notdanilo Jan 7, 2025
6b269f6
:recycle: Re-exporting WORLD_PROGRAM_ID and WORLD_PROGRAM_IDL
notdanilo Jan 7, 2025
52f5926
:construction: Setting up session keys for bolt_system::execute and w…
notdanilo Jan 10, 2025
b00e165
:construction: Updating ApplySystem signature
notdanilo Jan 17, 2025
2bc1efe
:construction: Getting session keys on the new system execution frame…
notdanilo Jan 17, 2025
8448b1a
:construction: Removing debug msg!
notdanilo Jan 20, 2025
a86aff4
:construction: Removing SessionToken from systems. They will be handl…
notdanilo Jan 20, 2025
3774e5a
:construction: Preparing tests for session tokens
notdanilo Jan 20, 2025
2675d13
:fire: Removing component initialize and update codes
notdanilo Jan 20, 2025
6074db2
:feature: Session token checks
notdanilo Jan 20, 2025
688ff07
:fire: Removing unnecessary bolt-component definitions
notdanilo Jan 20, 2025
5de45ec
:white_check_mark: Adding SessionProgram and reorganizing tests
notdanilo Jan 21, 2025
c5b6e77
:white_check_mark: Restructuring tests
notdanilo Jan 21, 2025
dd7f1dc
:rotating_light: Fixed linter
notdanilo Jan 21, 2025
74516e7
:fire: Removing debug logs in tests
notdanilo Jan 21, 2025
3382dd0
:white_check_mark: Grouping world, ecs, permissioning and delegation …
notdanilo Jan 22, 2025
06ffa74
:rotating_light: Fixed linter
notdanilo Jan 22, 2025
365c716
:fire: Removing duplicated file
notdanilo Jan 22, 2025
d8460e6
:white_check_mark: Renaming delegation to acceleration
notdanilo Jan 22, 2025
5578d04
:white_check_mark: Adding component authority permissioning test
notdanilo Jan 23, 2025
8a9eee4
:white_check_mark: Logging test groups, removing unnecessary tests
notdanilo Jan 23, 2025
652ebd3
:white_check_mark: Reorganizing permissioning tests
notdanilo Jan 23, 2025
b465118
:sparkles: Session Keys
notdanilo Jan 24, 2025
64b08dc
:adhesive_bandage: De-duplicating payer & authority from apply function
notdanilo Feb 7, 2025
fb2e552
:adhesive_bandage: Bunch of small fixes
notdanilo Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@ members = [
test = """
echo "Waiting for 2 seconds..."
sleep 2
echo "Running low level API tests..."
yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/bolt.low-level.api.ts
echo "Running intermediate level API tests..."
yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/bolt.intermediate-level.api.ts
yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/main.ts
"""

[test]
startup_wait = 5000
startup_wait = 15000
shutdown_wait = 2000
upgradeable = false

Expand All @@ -55,6 +52,11 @@ address = "DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh"
program = "tests/fixtures/delegation.so"
upgradeable = false

[[test.genesis]]
address="KeyspM2ssCJbqUhQ4k7sveSiY4WjnYsrXkC8oDbwde5"
program="tests/fixtures/session_keys.so"
upgradeable = false

[test.validator]
bind_address = "0.0.0.0"
ledger = ".anchor/test-ledger"
Expand Down
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ bolt-system = { path = "crates/programs/bolt-system", features = ["cpi"], versio
bolt-component = { path = "crates/programs/bolt-component", features = ["cpi"], version = "=0.2.0"}

## External crates
session-keys = { version = "=2.0.6", features = ["no-entrypoint"] }
anchor-lang = { version = "=0.30.1", features = ["init-if-needed"] }
anchor-cli = { version = "=0.30.1" }
anchor-client = { version = "=0.30.1" }
Expand Down
231 changes: 231 additions & 0 deletions clients/bolt-sdk/src/generated/idl/gpl_session.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
{
"address": "KeyspM2ssCJbqUhQ4k7sveSiY4WjnYsrXkC8oDbwde5",
"metadata": {
"name": "gpl_session",
"version": "2.0.6",
"spec": "0.1.0",
"description": "Gum Session Protocol (GPL Session)",
"repository": "https://github.com/magicblock-labs/gum-program-library"
},
"instructions": [
{
"name": "create_session",
"discriminator": [
242,
193,
143,
179,
150,
25,
122,
227
],
"accounts": [
{
"name": "session_token",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
115,
101,
115,
115,
105,
111,
110,
95,
116,
111,
107,
101,
110
]
},
{
"kind": "account",
"path": "target_program"
},
{
"kind": "account",
"path": "session_signer"
},
{
"kind": "account",
"path": "authority"
}
]
}
},
{
"name": "session_signer",
"writable": true,
"signer": true
},
{
"name": "authority",
"writable": true,
"signer": true
},
{
"name": "target_program",
"docs": [
"CHECK the target program is actually a program."
]
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
}
],
"args": [
{
"name": "top_up",
"type": {
"option": "bool"
}
},
{
"name": "valid_until",
"type": {
"option": "i64"
}
Comment on lines +91 to +94
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: valid_until is optional but no default expiration is enforced. This could lead to indefinite sessions if not properly handled in the implementation.

},
{
"name": "lamports",
"type": {
"option": "u64"
}
}
]
},
{
"name": "revoke_session",
"discriminator": [
86,
92,
198,
120,
144,
2,
7,
194
],
"accounts": [
{
"name": "session_token",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
115,
101,
115,
115,
105,
111,
110,
95,
116,
111,
107,
101,
110
]
},
{
"kind": "account",
"path": "session_token.target_program",
"account": "SessionToken"
},
{
"kind": "account",
"path": "session_token.session_signer",
"account": "SessionToken"
},
{
"kind": "account",
"path": "session_token.authority",
"account": "SessionToken"
}
]
}
},
{
"name": "authority",
"writable": true,
"relations": [
"session_token"
]
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
}
],
"args": []
}
],
"accounts": [
{
"name": "SessionToken",
"discriminator": [
233,
4,
115,
14,
46,
21,
1,
15
]
}
],
"errors": [
{
"code": 6000,
"name": "ValidityTooLong",
"msg": "Requested validity is too long"
},
{
"code": 6001,
"name": "InvalidToken",
"msg": "Invalid session token"
},
{
"code": 6002,
"name": "NoToken",
"msg": "No session token provided"
}
],
Comment on lines +188 to +204
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Error set appears incomplete - missing handling for expired sessions and insufficient funds scenarios.

"types": [
{
"name": "SessionToken",
"type": {
"kind": "struct",
"fields": [
{
"name": "authority",
"type": "pubkey"
},
{
"name": "target_program",
"type": "pubkey"
},
{
"name": "session_signer",
"type": "pubkey"
},
{
"name": "valid_until",
"type": "i64"
}
]
}
}
]
}
4 changes: 4 additions & 0 deletions clients/bolt-sdk/src/generated/idl/world.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
},
{
"name": "world"
},
{
"name": "session_token",
"optional": true
}
],
"args": [
Expand Down
2 changes: 2 additions & 0 deletions clients/bolt-sdk/src/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { PublicKey } from "@solana/web3.js";
import { type World as WorldProgram } from "./types/world";
import idl from "./idl/world.json";
import gpl_session from "./idl/gpl_session.json";
export * from "./accounts";
export * from "./errors";
export * from "./instructions";
Expand All @@ -30,3 +31,4 @@ export const PROGRAM_ID = new PublicKey(PROGRAM_ADDRESS);

export default WorldProgram;
export { idl as worldIdl };
export { gpl_session as sessionIdl };
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: sessionIdl export lacks JSDoc documentation unlike other exports in this file

4 changes: 4 additions & 0 deletions clients/bolt-sdk/src/generated/types/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export type World = {
{
name: "world";
},
{
name: "sessionToken";
optional: true;
},
];
args: [
{
Expand Down
24 changes: 23 additions & 1 deletion clients/bolt-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { PublicKey } from "@solana/web3.js";
import type BN from "bn.js";
import BN from "bn.js";
import { PROGRAM_ID as WORLD_PROGRAM_ID } from "./generated";
import { World as WORLD_PROGRAM_IDL } from "./generated/types";
export { BN };
export * from "./generated/accounts";
export * from "./generated/instructions";
export * from "./world/transactions";
Expand All @@ -11,6 +12,7 @@ export { DELEGATION_PROGRAM_ID } from "@magicblock-labs/ephemeral-rollups-sdk";

// Re-export anchor
import * as anchor from "@coral-xyz/anchor";
import { SessionProgram, Session } from "./session";
export { anchor };
export { Provider, Program, Wallet, web3, workspace } from "@coral-xyz/anchor";
export { WORLD_PROGRAM_ID, WORLD_PROGRAM_IDL };
Expand Down Expand Up @@ -68,6 +70,24 @@ export function FindEntityPda({
)[0];
}

export function FindSessionTokenPda({
sessionSigner,
authority,
}: {
sessionSigner: PublicKey;
authority: PublicKey;
}) {
return PublicKey.findProgramAddressSync(
[
Buffer.from("session_token"),
WORLD_PROGRAM_ID.toBytes(),
sessionSigner.toBytes(),
authority.toBytes(),
],
SessionProgram.programId,
)[0];
}

// TODO: seed must be Uint8Array like the other FindPda functions
export function FindComponentPda({
componentId,
Expand Down Expand Up @@ -99,3 +119,5 @@ export function SerializeArgs(args: any = {}) {
binaryData.byteLength,
);
}

export { SessionProgram, Session };
Loading