pub struct Agent {
pub id: String,
pub role: Option<String>,
pub for_parties: ForParties,
pub policies: Option<Vec<Policy>>,
pub metadata: HashMap<String, Value>,
}Expand description
Agent in a transaction (TAIP-5).
Agents are identified using Decentralized Identifiers (DIDs) and can be:
- Centralized services (exchanges, custodial wallets)
- End-user software (self-hosted wallets)
- Decentralized protocols (DeFi protocols, bridges)
Fields§
§id: StringDID of the agent.
role: Option<String>Role of the agent in this transaction (optional). Examples: “SettlementAddress”, “SourceAddress”, etc.
for_parties: ForPartiesDID or IRI of another Agent or Party that this agent acts on behalf of (REQUIRED per TAIP-5). Can be a single party or multiple parties.
policies: Option<Vec<Policy>>Policies of the agent according to TAIP-7 (optional).
metadata: HashMap<String, Value>Additional JSON-LD metadata for the agent. This allows for extensible metadata beyond the core fields.
Implementations§
Source§impl Agent
impl Agent
Sourcepub fn new(id: &str, role: &str, for_party: &str) -> Self
pub fn new(id: &str, role: &str, for_party: &str) -> Self
Create a new agent with the given DID, role, and for_party.
Sourcepub fn new_for_parties(id: &str, role: &str, for_parties: Vec<String>) -> Self
pub fn new_for_parties(id: &str, role: &str, for_parties: Vec<String>) -> Self
Create a new agent with multiple parties.
Sourcepub fn new_without_role(id: &str, for_party: &str) -> Self
pub fn new_without_role(id: &str, for_party: &str) -> Self
Create a new agent without a role.
Sourcepub fn with_metadata(
id: &str,
role: &str,
for_party: &str,
metadata: HashMap<String, Value>,
) -> Self
pub fn with_metadata( id: &str, role: &str, for_party: &str, metadata: HashMap<String, Value>, ) -> Self
Create a new agent with metadata.
Sourcepub fn with_policies(self, policies: Vec<Policy>) -> Self
pub fn with_policies(self, policies: Vec<Policy>) -> Self
Add policies to this agent.
Sourcepub fn add_policy(self, policy: Policy) -> Self
pub fn add_policy(self, policy: Policy) -> Self
Add a single policy to this agent.
Sourcepub fn add_metadata(&mut self, key: String, value: Value)
pub fn add_metadata(&mut self, key: String, value: Value)
Add a metadata field to the agent.
Sourcepub fn with_metadata_field(self, key: String, value: Value) -> Self
pub fn with_metadata_field(self, key: String, value: Value) -> Self
Add metadata using the builder pattern.
Sourcepub fn get_metadata(&self, key: &str) -> Option<&Value>
pub fn get_metadata(&self, key: &str) -> Option<&Value>
Get a metadata value by key.
Sourcepub fn for_parties(&self) -> &[String]
pub fn for_parties(&self) -> &[String]
Get all parties this agent acts for.
Sourcepub fn primary_party(&self) -> Option<&str>
pub fn primary_party(&self) -> Option<&str>
Get the first party this agent acts for (for backward compatibility).
Sourcepub fn add_for_party(&mut self, party_id: &str)
pub fn add_for_party(&mut self, party_id: &str)
Add a party this agent acts for.
Sourcepub fn set_for_parties(&mut self, parties: Vec<String>)
pub fn set_for_parties(&mut self, parties: Vec<String>)
Set all parties this agent acts for.