Skip to content

Commit 66b40af

Browse files
authored
✨ Session keys (#126)
1 parent 5298a2f commit 66b40af

File tree

42 files changed

+2579
-2008
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2579
-2008
lines changed

Diff for: Anchor.toml

+7-5
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,11 @@ members = [
3939
test = """
4040
echo "Waiting for 2 seconds..."
4141
sleep 2
42-
echo "Running low level API tests..."
43-
yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/bolt.low-level.api.ts
44-
echo "Running intermediate level API tests..."
45-
yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/bolt.intermediate-level.api.ts
42+
yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/main.ts
4643
"""
4744

4845
[test]
49-
startup_wait = 5000
46+
startup_wait = 15000
5047
shutdown_wait = 2000
5148
upgradeable = false
5249

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

55+
[[test.genesis]]
56+
address="KeyspM2ssCJbqUhQ4k7sveSiY4WjnYsrXkC8oDbwde5"
57+
program="tests/fixtures/session_keys.so"
58+
upgradeable = false
59+
5860
[test.validator]
5961
bind_address = "0.0.0.0"
6062
ledger = ".anchor/test-ledger"

Diff for: Cargo.lock

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ bolt-system = { path = "crates/programs/bolt-system", features = ["cpi"], versio
3434
bolt-component = { path = "crates/programs/bolt-component", features = ["cpi"], version = "=0.2.0"}
3535

3636
## External crates
37+
session-keys = { version = "=2.0.6", features = ["no-entrypoint"] }
3738
anchor-lang = { version = "=0.30.1", features = ["init-if-needed"] }
3839
anchor-cli = { version = "=0.30.1" }
3940
anchor-client = { version = "=0.30.1" }

Diff for: clients/bolt-sdk/src/generated/idl/gpl_session.json

+231
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
{
2+
"address": "KeyspM2ssCJbqUhQ4k7sveSiY4WjnYsrXkC8oDbwde5",
3+
"metadata": {
4+
"name": "gpl_session",
5+
"version": "2.0.6",
6+
"spec": "0.1.0",
7+
"description": "Gum Session Protocol (GPL Session)",
8+
"repository": "https://github.com/magicblock-labs/gum-program-library"
9+
},
10+
"instructions": [
11+
{
12+
"name": "create_session",
13+
"discriminator": [
14+
242,
15+
193,
16+
143,
17+
179,
18+
150,
19+
25,
20+
122,
21+
227
22+
],
23+
"accounts": [
24+
{
25+
"name": "session_token",
26+
"writable": true,
27+
"pda": {
28+
"seeds": [
29+
{
30+
"kind": "const",
31+
"value": [
32+
115,
33+
101,
34+
115,
35+
115,
36+
105,
37+
111,
38+
110,
39+
95,
40+
116,
41+
111,
42+
107,
43+
101,
44+
110
45+
]
46+
},
47+
{
48+
"kind": "account",
49+
"path": "target_program"
50+
},
51+
{
52+
"kind": "account",
53+
"path": "session_signer"
54+
},
55+
{
56+
"kind": "account",
57+
"path": "authority"
58+
}
59+
]
60+
}
61+
},
62+
{
63+
"name": "session_signer",
64+
"writable": true,
65+
"signer": true
66+
},
67+
{
68+
"name": "authority",
69+
"writable": true,
70+
"signer": true
71+
},
72+
{
73+
"name": "target_program",
74+
"docs": [
75+
"CHECK the target program is actually a program."
76+
]
77+
},
78+
{
79+
"name": "system_program",
80+
"address": "11111111111111111111111111111111"
81+
}
82+
],
83+
"args": [
84+
{
85+
"name": "top_up",
86+
"type": {
87+
"option": "bool"
88+
}
89+
},
90+
{
91+
"name": "valid_until",
92+
"type": {
93+
"option": "i64"
94+
}
95+
},
96+
{
97+
"name": "lamports",
98+
"type": {
99+
"option": "u64"
100+
}
101+
}
102+
]
103+
},
104+
{
105+
"name": "revoke_session",
106+
"discriminator": [
107+
86,
108+
92,
109+
198,
110+
120,
111+
144,
112+
2,
113+
7,
114+
194
115+
],
116+
"accounts": [
117+
{
118+
"name": "session_token",
119+
"writable": true,
120+
"pda": {
121+
"seeds": [
122+
{
123+
"kind": "const",
124+
"value": [
125+
115,
126+
101,
127+
115,
128+
115,
129+
105,
130+
111,
131+
110,
132+
95,
133+
116,
134+
111,
135+
107,
136+
101,
137+
110
138+
]
139+
},
140+
{
141+
"kind": "account",
142+
"path": "session_token.target_program",
143+
"account": "SessionToken"
144+
},
145+
{
146+
"kind": "account",
147+
"path": "session_token.session_signer",
148+
"account": "SessionToken"
149+
},
150+
{
151+
"kind": "account",
152+
"path": "session_token.authority",
153+
"account": "SessionToken"
154+
}
155+
]
156+
}
157+
},
158+
{
159+
"name": "authority",
160+
"writable": true,
161+
"relations": [
162+
"session_token"
163+
]
164+
},
165+
{
166+
"name": "system_program",
167+
"address": "11111111111111111111111111111111"
168+
}
169+
],
170+
"args": []
171+
}
172+
],
173+
"accounts": [
174+
{
175+
"name": "SessionToken",
176+
"discriminator": [
177+
233,
178+
4,
179+
115,
180+
14,
181+
46,
182+
21,
183+
1,
184+
15
185+
]
186+
}
187+
],
188+
"errors": [
189+
{
190+
"code": 6000,
191+
"name": "ValidityTooLong",
192+
"msg": "Requested validity is too long"
193+
},
194+
{
195+
"code": 6001,
196+
"name": "InvalidToken",
197+
"msg": "Invalid session token"
198+
},
199+
{
200+
"code": 6002,
201+
"name": "NoToken",
202+
"msg": "No session token provided"
203+
}
204+
],
205+
"types": [
206+
{
207+
"name": "SessionToken",
208+
"type": {
209+
"kind": "struct",
210+
"fields": [
211+
{
212+
"name": "authority",
213+
"type": "pubkey"
214+
},
215+
{
216+
"name": "target_program",
217+
"type": "pubkey"
218+
},
219+
{
220+
"name": "session_signer",
221+
"type": "pubkey"
222+
},
223+
{
224+
"name": "valid_until",
225+
"type": "i64"
226+
}
227+
]
228+
}
229+
}
230+
]
231+
}

Diff for: clients/bolt-sdk/src/generated/idl/world.json

+4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
},
112112
{
113113
"name": "world"
114+
},
115+
{
116+
"name": "session_token",
117+
"optional": true
114118
}
115119
],
116120
"args": [

Diff for: clients/bolt-sdk/src/generated/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { PublicKey } from "@solana/web3.js";
99
import { type World as WorldProgram } from "./types/world";
1010
import idl from "./idl/world.json";
11+
import gpl_session from "./idl/gpl_session.json";
1112
export * from "./accounts";
1213
export * from "./errors";
1314
export * from "./instructions";
@@ -30,3 +31,4 @@ export const PROGRAM_ID = new PublicKey(PROGRAM_ADDRESS);
3031

3132
export default WorldProgram;
3233
export { idl as worldIdl };
34+
export { gpl_session as sessionIdl };

Diff for: clients/bolt-sdk/src/generated/types/world.ts

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ export type World = {
9191
{
9292
name: "world";
9393
},
94+
{
95+
name: "sessionToken";
96+
optional: true;
97+
},
9498
];
9599
args: [
96100
{

Diff for: clients/bolt-sdk/src/index.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { PublicKey } from "@solana/web3.js";
2-
import type BN from "bn.js";
2+
import BN from "bn.js";
33
import { PROGRAM_ID as WORLD_PROGRAM_ID } from "./generated";
44
import { World as WORLD_PROGRAM_IDL } from "./generated/types";
5+
export { BN };
56
export * from "./generated/accounts";
67
export * from "./generated/instructions";
78
export * from "./world/transactions";
@@ -11,6 +12,7 @@ export { DELEGATION_PROGRAM_ID } from "@magicblock-labs/ephemeral-rollups-sdk";
1112

1213
// Re-export anchor
1314
import * as anchor from "@coral-xyz/anchor";
15+
import { SessionProgram, Session } from "./session";
1416
export { anchor };
1517
export { Provider, Program, Wallet, web3, workspace } from "@coral-xyz/anchor";
1618
export { WORLD_PROGRAM_ID, WORLD_PROGRAM_IDL };
@@ -68,6 +70,24 @@ export function FindEntityPda({
6870
)[0];
6971
}
7072

73+
export function FindSessionTokenPda({
74+
sessionSigner,
75+
authority,
76+
}: {
77+
sessionSigner: PublicKey;
78+
authority: PublicKey;
79+
}) {
80+
return PublicKey.findProgramAddressSync(
81+
[
82+
Buffer.from("session_token"),
83+
WORLD_PROGRAM_ID.toBytes(),
84+
sessionSigner.toBytes(),
85+
authority.toBytes(),
86+
],
87+
SessionProgram.programId,
88+
)[0];
89+
}
90+
7191
// TODO: seed must be Uint8Array like the other FindPda functions
7292
export function FindComponentPda({
7393
componentId,
@@ -99,3 +119,5 @@ export function SerializeArgs(args: any = {}) {
99119
binaryData.byteLength,
100120
);
101121
}
122+
123+
export { SessionProgram, Session };

0 commit comments

Comments
 (0)