Skip to main content

stateset_core/models/
erc8004.rs

1//! ERC-8004 Trustless Agents models
2//!
3//! Provides identity, reputation, and validation data structures for
4//! trustless agent discovery across organizational boundaries.
5
6use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8use strum::{Display, EnumString};
9use uuid::Uuid;
10
11/// ERC-8004 registration file type URL (v1)
12pub const ERC8004_REGISTRATION_V1: &str = "https://eips.ethereum.org/EIPS/eip-8004#registration-v1";
13
14// =============================================================================
15// Registration File Models
16// =============================================================================
17
18/// Service endpoint advertised by an agent registration file.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct AgentServiceEndpoint {
21    pub name: String,
22    pub endpoint: String,
23    pub version: Option<String>,
24    pub skills: Option<Vec<String>>,
25    pub domains: Option<Vec<String>>,
26}
27
28/// Registration reference entry in the registration file.
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct AgentRegistrationRef {
31    #[serde(rename = "agentId")]
32    pub agent_id: String,
33    #[serde(rename = "agentRegistry")]
34    pub agent_registry: String,
35}
36
37/// Agent registration file (off-chain JSON referenced by agentURI).
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct AgentRegistrationFile {
40    #[serde(rename = "type")]
41    pub type_url: String,
42    pub name: String,
43    pub description: String,
44    pub image: String,
45    pub services: Vec<AgentServiceEndpoint>,
46    #[serde(rename = "x402Support")]
47    pub x402_support: bool,
48    pub active: bool,
49    pub registrations: Vec<AgentRegistrationRef>,
50    #[serde(default, rename = "supportedTrust")]
51    pub supported_trust: Option<Vec<String>>,
52}
53
54// =============================================================================
55// Identity Registry Models
56// =============================================================================
57
58/// Type of proof used to set or update agent wallet ownership.
59#[derive(Debug, Clone, Copy, PartialEq, Eq, Display, EnumString, Serialize, Deserialize)]
60#[serde(rename_all = "snake_case")]
61#[non_exhaustive]
62pub enum AgentWalletProofType {
63    #[strum(serialize = "eip712", serialize = "eip_712")]
64    Eip712,
65    #[strum(serialize = "erc1271", serialize = "erc_1271")]
66    Erc1271,
67}
68
69/// Identity record for an on-chain ERC-8004 agent.
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct AgentIdentity {
72    pub id: Uuid,
73    pub agent_registry: String,
74    pub agent_id: String,
75    pub agent_uri: String,
76    pub agent_wallet: Option<String>,
77    pub owner_address: Option<String>,
78    pub agent_card_id: Option<Uuid>,
79    pub registration: Option<String>,
80    pub registration_hash: Option<String>,
81    pub wallet_proof_type: Option<AgentWalletProofType>,
82    pub wallet_proof: Option<String>,
83    pub wallet_proof_chain_id: Option<u64>,
84    pub wallet_proof_deadline: Option<DateTime<Utc>>,
85    pub active: bool,
86    pub created_at: DateTime<Utc>,
87    pub updated_at: DateTime<Utc>,
88}
89
90/// Metadata entry for on-chain identity metadata.
91#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct AgentMetadataEntry {
93    pub metadata_key: String,
94    pub metadata_value: Vec<u8>,
95}
96
97/// Input for registering a new agent identity.
98#[derive(Debug, Clone, Default, Serialize, Deserialize)]
99pub struct CreateAgentIdentity {
100    pub agent_registry: String,
101    pub agent_id: String,
102    pub agent_uri: String,
103    pub agent_wallet: Option<String>,
104    pub owner_address: Option<String>,
105    pub agent_card_id: Option<Uuid>,
106    pub registration: Option<String>,
107    pub registration_hash: Option<String>,
108    pub wallet_proof_type: Option<AgentWalletProofType>,
109    pub wallet_proof: Option<String>,
110    pub wallet_proof_chain_id: Option<u64>,
111    pub wallet_proof_deadline: Option<DateTime<Utc>>,
112    pub active: Option<bool>,
113}
114
115/// Input for updating an agent identity.
116#[derive(Debug, Clone, Default, Serialize, Deserialize)]
117pub struct UpdateAgentIdentity {
118    pub agent_uri: Option<String>,
119    pub agent_wallet: Option<String>,
120    pub owner_address: Option<String>,
121    pub agent_card_id: Option<Uuid>,
122    pub registration: Option<String>,
123    pub registration_hash: Option<String>,
124    pub wallet_proof_type: Option<AgentWalletProofType>,
125    pub wallet_proof: Option<String>,
126    pub wallet_proof_chain_id: Option<u64>,
127    pub wallet_proof_deadline: Option<DateTime<Utc>>,
128    pub active: Option<bool>,
129}
130
131/// Filter for listing agent identities.
132#[derive(Debug, Clone, Default, Serialize, Deserialize)]
133pub struct AgentIdentityFilter {
134    pub agent_registry: Option<String>,
135    pub agent_id: Option<String>,
136    pub agent_wallet: Option<String>,
137    pub owner_address: Option<String>,
138    pub agent_card_id: Option<Uuid>,
139    pub active: Option<bool>,
140    pub limit: Option<u32>,
141    pub offset: Option<u32>,
142}
143
144// =============================================================================
145// Reputation Registry Models
146// =============================================================================
147
148/// Reputation feedback submitted by a client.
149#[derive(Debug, Clone, Serialize, Deserialize)]
150pub struct AgentFeedback {
151    pub id: Uuid,
152    pub agent_registry: String,
153    pub agent_id: String,
154    pub client_address: String,
155    pub feedback_index: u64,
156    pub value: i128,
157    pub value_decimals: u8,
158    pub tag1: Option<String>,
159    pub tag2: Option<String>,
160    pub endpoint: Option<String>,
161    pub feedback_uri: Option<String>,
162    pub feedback_hash: Option<String>,
163    pub is_revoked: bool,
164    pub created_at: DateTime<Utc>,
165    pub revoked_at: Option<DateTime<Utc>>,
166}
167
168/// Input for creating new feedback.
169#[derive(Debug, Clone, Default, Serialize, Deserialize)]
170pub struct CreateAgentFeedback {
171    pub agent_registry: String,
172    pub agent_id: String,
173    pub client_address: String,
174    pub value: i128,
175    pub value_decimals: u8,
176    pub tag1: Option<String>,
177    pub tag2: Option<String>,
178    pub endpoint: Option<String>,
179    pub feedback_uri: Option<String>,
180    pub feedback_hash: Option<String>,
181}
182
183/// Filter for reading feedback.
184#[derive(Debug, Clone, Default, Serialize, Deserialize)]
185pub struct AgentFeedbackFilter {
186    pub agent_registry: Option<String>,
187    pub agent_id: Option<String>,
188    pub client_addresses: Option<Vec<String>>,
189    pub tag1: Option<String>,
190    pub tag2: Option<String>,
191    pub include_revoked: Option<bool>,
192    pub limit: Option<u32>,
193    pub offset: Option<u32>,
194}
195
196/// Summary for feedback aggregation.
197#[derive(Debug, Clone, Serialize, Deserialize)]
198pub struct FeedbackSummary {
199    pub count: u64,
200    pub summary_value: i128,
201    pub summary_value_decimals: u8,
202}
203
204/// Feedback response appended by an agent or third party.
205#[derive(Debug, Clone, Serialize, Deserialize)]
206pub struct AgentFeedbackResponse {
207    pub id: Uuid,
208    pub agent_registry: String,
209    pub agent_id: String,
210    pub client_address: String,
211    pub feedback_index: u64,
212    pub responder_address: String,
213    pub response_uri: String,
214    pub response_hash: Option<String>,
215    pub created_at: DateTime<Utc>,
216}
217
218/// Input for appending a feedback response.
219#[derive(Debug, Clone, Default, Serialize, Deserialize)]
220pub struct CreateAgentFeedbackResponse {
221    pub agent_registry: String,
222    pub agent_id: String,
223    pub client_address: String,
224    pub feedback_index: u64,
225    pub responder_address: String,
226    pub response_uri: String,
227    pub response_hash: Option<String>,
228}
229
230// =============================================================================
231// Validation Registry Models
232// =============================================================================
233
234/// Validation request submitted by an agent owner/operator.
235#[derive(Debug, Clone, Serialize, Deserialize)]
236pub struct AgentValidationRequest {
237    pub request_hash: String,
238    pub agent_registry: String,
239    pub agent_id: String,
240    pub validator_address: String,
241    pub request_uri: String,
242    pub created_at: DateTime<Utc>,
243}
244
245/// Input for creating a validation request.
246#[derive(Debug, Clone, Default, Serialize, Deserialize)]
247pub struct CreateAgentValidationRequest {
248    pub request_hash: String,
249    pub agent_registry: String,
250    pub agent_id: String,
251    pub validator_address: String,
252    pub request_uri: String,
253}
254
255/// Validation response from a validator.
256#[derive(Debug, Clone, Serialize, Deserialize)]
257pub struct AgentValidationResponse {
258    pub id: Uuid,
259    pub request_hash: String,
260    pub agent_registry: String,
261    pub agent_id: String,
262    pub validator_address: String,
263    pub response: u8,
264    pub response_uri: Option<String>,
265    pub response_hash: Option<String>,
266    pub tag: Option<String>,
267    pub created_at: DateTime<Utc>,
268}
269
270/// Input for recording a validation response.
271#[derive(Debug, Clone, Default, Serialize, Deserialize)]
272pub struct CreateAgentValidationResponse {
273    pub response: u8,
274    pub response_uri: Option<String>,
275    pub response_hash: Option<String>,
276    pub tag: Option<String>,
277}
278
279/// Latest validation status for a request hash.
280#[derive(Debug, Clone, Serialize, Deserialize)]
281pub struct AgentValidationStatus {
282    pub validator_address: String,
283    pub agent_registry: String,
284    pub agent_id: String,
285    pub response: u8,
286    pub response_hash: Option<String>,
287    pub tag: Option<String>,
288    pub last_update: DateTime<Utc>,
289}
290
291/// Summary of validation responses for an agent.
292#[derive(Debug, Clone, Serialize, Deserialize)]
293pub struct ValidationSummary {
294    pub count: u64,
295    pub average_response: u8,
296}
297
298/// Filter for validation summaries.
299#[derive(Debug, Clone, Default, Serialize, Deserialize)]
300pub struct AgentValidationFilter {
301    pub agent_registry: Option<String>,
302    pub agent_id: Option<String>,
303    pub validator_addresses: Option<Vec<String>>,
304    pub tag: Option<String>,
305}