pub trait Agent {
// Required methods
fn get_agent_did(&self) -> &str;
fn get_service_endpoint<'life0, 'life1, 'async_trait>(
&'life0 self,
to: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn send_message<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
message: &'life1 T,
to: Vec<&'life2 str>,
deliver: bool,
) -> Pin<Box<dyn Future<Output = Result<(String, Vec<DeliveryResult>)>> + Send + 'async_trait>>
where T: 'async_trait + TapMessageBody + Serialize + Send + Sync + Debug + 'static,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn receive_encrypted_message<'life0, 'life1, 'async_trait>(
&'life0 self,
jwe_value: &'life1 Value,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn receive_plain_message<'life0, 'async_trait>(
&'life0 self,
message: PlainMessage,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn receive_message<'life0, 'life1, 'async_trait>(
&'life0 self,
raw_message: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<PlainMessage>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn send_typed<'life0, 'async_trait, T>(
&'life0 self,
message: PlainMessage<T>,
deliver: bool,
) -> Pin<Box<dyn Future<Output = Result<(String, Vec<DeliveryResult>)>> + Send + 'async_trait>>
where T: 'async_trait + TapMessageBody + Send + Sync + Debug + 'static,
Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn send_with_context<'life0, 'life1, 'async_trait, T>(
&'life0 self,
message: &'life1 T,
deliver: bool,
) -> Pin<Box<dyn Future<Output = Result<(String, Vec<DeliveryResult>)>> + Send + 'async_trait>>
where T: TapMessageBody + MessageContext + Send + Sync + Debug + 'static + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn send_typed_with_context<'life0, 'async_trait, T>(
&'life0 self,
message: PlainMessage<T>,
deliver: bool,
) -> Pin<Box<dyn Future<Output = Result<(String, Vec<DeliveryResult>)>> + Send + 'async_trait>>
where T: TapMessageBody + MessageContext + Send + Sync + Debug + 'static + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn receive_typed<'life0, 'life1, 'async_trait, T>(
&'life0 self,
raw_message: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<PlainMessage<T>>> + Send + 'async_trait>>
where T: 'async_trait + TapMessageBody,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
The Agent trait defines the interface for all TAP agents
This trait supports both standalone agent usage and integration with TAP Node. The different receive methods are designed for different usage patterns:
§Usage Patterns
§Node Integration
- [
receive_encrypted_message]: Called by TAP Node for encrypted messages - [
receive_plain_message]: Called by TAP Node for verified/decrypted messages
§Standalone Usage
- [
receive_message]: Handles any message type (plain, signed, encrypted)
§Message Sending
- [
send_message]: Sends messages to recipients with optional delivery
§Examples
use tap_agent::{Agent, TapAgent};
use tap_msg::didcomm::PlainMessage;
async fn process_encrypted_message(agent: &TapAgent, jwe_json: &serde_json::Value) {
// This would typically be called by TAP Node
if let Err(e) = agent.receive_encrypted_message(jwe_json).await {
eprintln!("Failed to process encrypted message: {}", e);
}
}Required Methods§
Sourcefn get_agent_did(&self) -> &str
fn get_agent_did(&self) -> &str
Gets the agent’s DID
Sourcefn get_service_endpoint<'life0, 'life1, 'async_trait>(
&'life0 self,
to: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_service_endpoint<'life0, 'life1, 'async_trait>(
&'life0 self,
to: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Gets the service endpoint URL for a recipient
This method resolves how to reach a given recipient, which could be:
- A direct URL if
tois already a URL - A DID resolution if
tois a DID
Sourcefn send_message<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
message: &'life1 T,
to: Vec<&'life2 str>,
deliver: bool,
) -> Pin<Box<dyn Future<Output = Result<(String, Vec<DeliveryResult>)>> + Send + 'async_trait>>where
T: 'async_trait + TapMessageBody + Serialize + Send + Sync + Debug + 'static,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn send_message<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
message: &'life1 T,
to: Vec<&'life2 str>,
deliver: bool,
) -> Pin<Box<dyn Future<Output = Result<(String, Vec<DeliveryResult>)>> + Send + 'async_trait>>where
T: 'async_trait + TapMessageBody + Serialize + Send + Sync + Debug + 'static,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sourcefn receive_encrypted_message<'life0, 'life1, 'async_trait>(
&'life0 self,
jwe_value: &'life1 Value,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn receive_encrypted_message<'life0, 'life1, 'async_trait>(
&'life0 self,
jwe_value: &'life1 Value,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Receives an encrypted message (decrypt and process)
This method is typically called by TAP Node when routing encrypted messages to agents. The agent should:
- Parse the JWE from the JSON value
- Attempt to decrypt using its private keys
- Process the resulting PlainMessage
§Parameters
jwe_value: JSON representation of the encrypted message (JWE)
Sourcefn receive_plain_message<'life0, 'async_trait>(
&'life0 self,
message: PlainMessage,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn receive_plain_message<'life0, 'async_trait>(
&'life0 self,
message: PlainMessage,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Receives a plain message (already verified/decrypted)
This method is called by TAP Node after signature verification or by other agents after decryption. The message is ready for business logic processing.
§Parameters
message: The verified/decrypted PlainMessage
Sourcefn receive_message<'life0, 'life1, 'async_trait>(
&'life0 self,
raw_message: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<PlainMessage>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn receive_message<'life0, 'life1, 'async_trait>(
&'life0 self,
raw_message: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<PlainMessage>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Receives a raw message (for standalone usage - handles any message type)
This method handles the complete message processing pipeline for standalone agent usage. It can process:
- Plain messages (passed through)
- Signed messages (signature verified)
- Encrypted messages (decrypted)
§Parameters
raw_message: JSON string of any message type
§Returns
- The processed PlainMessage
Provided Methods§
Sourcefn send_typed<'life0, 'async_trait, T>(
&'life0 self,
message: PlainMessage<T>,
deliver: bool,
) -> Pin<Box<dyn Future<Output = Result<(String, Vec<DeliveryResult>)>> + Send + 'async_trait>>where
T: 'async_trait + TapMessageBody + Send + Sync + Debug + 'static,
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn send_typed<'life0, 'async_trait, T>(
&'life0 self,
message: PlainMessage<T>,
deliver: bool,
) -> Pin<Box<dyn Future<Output = Result<(String, Vec<DeliveryResult>)>> + Send + 'async_trait>>where
T: 'async_trait + TapMessageBody + Send + Sync + Debug + 'static,
Self: Sync + 'async_trait,
'life0: 'async_trait,
Sourcefn send_with_context<'life0, 'life1, 'async_trait, T>(
&'life0 self,
message: &'life1 T,
deliver: bool,
) -> Pin<Box<dyn Future<Output = Result<(String, Vec<DeliveryResult>)>> + Send + 'async_trait>>where
T: TapMessageBody + MessageContext + Send + Sync + Debug + 'static + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn send_with_context<'life0, 'life1, 'async_trait, T>(
&'life0 self,
message: &'life1 T,
deliver: bool,
) -> Pin<Box<dyn Future<Output = Result<(String, Vec<DeliveryResult>)>> + Send + 'async_trait>>where
T: TapMessageBody + MessageContext + Send + Sync + Debug + 'static + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Send a message with MessageContext support for automatic routing
This method uses MessageContext to automatically extract participants and routing hints for improved message delivery.
§Parameters
message: The message body that implements both TapMessageBody and MessageContextdeliver: Whether to actually deliver the message
§Returns
- Packed message string
- Vector of delivery results (empty if deliver=false)
Sourcefn send_typed_with_context<'life0, 'async_trait, T>(
&'life0 self,
message: PlainMessage<T>,
deliver: bool,
) -> Pin<Box<dyn Future<Output = Result<(String, Vec<DeliveryResult>)>> + Send + 'async_trait>>where
T: TapMessageBody + MessageContext + Send + Sync + Debug + 'static + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn send_typed_with_context<'life0, 'async_trait, T>(
&'life0 self,
message: PlainMessage<T>,
deliver: bool,
) -> Pin<Box<dyn Future<Output = Result<(String, Vec<DeliveryResult>)>> + Send + 'async_trait>>where
T: TapMessageBody + MessageContext + Send + Sync + Debug + 'static + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait,
Sourcefn receive_typed<'life0, 'life1, 'async_trait, T>(
&'life0 self,
raw_message: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<PlainMessage<T>>> + Send + 'async_trait>>where
T: 'async_trait + TapMessageBody,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn receive_typed<'life0, 'life1, 'async_trait, T>(
&'life0 self,
raw_message: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<PlainMessage<T>>> + Send + 'async_trait>>where
T: 'async_trait + TapMessageBody,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.