cougr_core/accounts/traits.rs
1use soroban_sdk::{Address, BytesN, Env};
2
3use super::error::AccountError;
4use super::intent::{AuthResult, SignedIntent};
5use super::types::{AccountCapabilities, GameAction, SessionKey, SessionScope};
6
7/// Core account trait for Cougr game accounts.
8///
9/// All account types (Classic G-address and Contract C-address) implement
10/// this trait to provide unified authorization for game actions.
11pub trait CougrAccount {
12 /// Returns the Stellar address of this account.
13 fn address(&self) -> &Address;
14
15 /// Returns the capabilities supported by this account type.
16 fn capabilities(&self) -> AccountCapabilities;
17
18 /// Authorize a game action.
19 ///
20 /// For Classic accounts, this calls `address.require_auth()`.
21 /// For Contract accounts, this may use session keys or custom logic.
22 fn authorize(&self, env: &Env, action: &GameAction) -> Result<(), AccountError>;
23}
24
25/// Explicit intent-based authorization interface used by the account kernel.
26pub trait IntentAccount: CougrAccount {
27 fn authorize_intent(
28 &mut self,
29 env: &Env,
30 intent: &SignedIntent,
31 ) -> Result<AuthResult, AccountError>;
32}
33
34/// Session key management for contract accounts.
35///
36/// This trait provides session key functionality for gasless gameplay.
37/// Only contract accounts (C-addresses) support this capability.
38pub trait SessionKeyProvider: CougrAccount {
39 /// Create a new session key with the given scope.
40 fn create_session(
41 &mut self,
42 env: &Env,
43 scope: SessionScope,
44 ) -> Result<SessionKey, AccountError>;
45
46 /// Validate that a session key is still active and within scope.
47 fn validate_session(&self, env: &Env, key: &SessionKey) -> Result<bool, AccountError>;
48
49 /// Revoke an existing session key.
50 fn revoke_session(&mut self, env: &Env, key_id: &BytesN<32>) -> Result<(), AccountError>;
51}