Skip to main content

prova_agent_sdk/
types.rs

1use serde::{Deserialize, Serialize};
2use solana_sdk::pubkey::Pubkey;
3
4/// Tipos de acción soportados por el programa Prova on-chain.
5/// Los índices (0-6) corresponden al enum Anchor del contrato.
6#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
7#[serde(rename_all = "PascalCase")]
8#[repr(u8)]
9pub enum ActionType {
10    Transaction = 0,
11    Decision = 1,
12    ModelInvocation = 2,
13    ToolCall = 3,
14    ResourceAccess = 4,
15    PolicyCheck = 5,
16    Custom = 6,
17}
18
19/// Payload de una atestación antes de ser enviada on-chain.
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct AttestationPayload {
22    pub action_type: ActionType,
23    pub payload: serde_json::Value,
24    pub metadata: Option<serde_json::Value>,
25}
26
27/// Resultado de una atestación enviada on-chain.
28#[derive(Debug, Clone)]
29pub struct AttestResult {
30    pub tx_signature: String,
31    pub explorer_url: String,
32}
33
34/// Resultado de registrar un agente on-chain.
35#[derive(Debug, Clone)]
36pub struct RegisterAgentResult {
37    pub tx_signature: String,
38    pub agent_pda: Pubkey,
39    pub explorer_url: String,
40}
41
42/// Cuenta de agente leída on-chain.
43#[derive(Debug, Clone)]
44pub struct AgentAccount {
45    pub address: Pubkey,
46    pub operator: Pubkey,
47    pub agent_id: [u8; 32],
48    pub policy_root: [u8; 32],
49    pub attestation_count: u64,
50    pub created_at: i64,
51    pub revoked: bool,
52    pub bump: u8,
53}
54
55/// Parámetros para una sola atestación.
56#[derive(Debug, Clone)]
57pub struct AttestParams {
58    pub action_hash: [u8; 32],
59    pub action_type: ActionType,
60    pub privacy_mode: bool,
61}
62
63/// Configuración del cliente Prova.
64#[derive(Debug, Clone)]
65pub struct ProvaConfig {
66    pub rpc_url: String,
67    /// Program ID. Default: G11dBAzLQaADtHHM2AZNz3ThCDnkY5nhX3Ujddu1CMM1
68    pub program_id: Option<String>,
69}
70
71impl Default for ProvaConfig {
72    fn default() -> Self {
73        Self {
74            rpc_url: "https://api.devnet.solana.com".to_string(),
75            program_id: None,
76        }
77    }
78}
79
80// Mantenemos compatibilidad con los tipos anteriores
81pub type AttestationResult = AttestResult;
82
83#[derive(Debug, Clone)]
84pub struct VerifyResult {
85    pub valid: bool,
86    pub error: Option<String>,
87}
88
89#[derive(Debug, Clone)]
90pub struct HistoryQuery {
91    pub agent_id: String,
92    pub from_timestamp: Option<u64>,
93    pub to_timestamp: Option<u64>,
94    pub action_type: Option<ActionType>,
95    pub limit: Option<usize>,
96    pub offset: Option<usize>,
97}