pub struct Message {
pub id: String,
pub message_type: String,
pub from: String,
pub to: String,
pub created_at: f64,
pub ttl: u64,
pub content_type: String,
pub reply_to: Option<String>,
pub content: Vec<u8>,
pub signature: Vec<u8>,
}Expand description
A signed actor-to-actor message.
Messages are signed on creation using the sender’s SigningKey.
The signature covers the CBOR-serialized headers (including a BLAKE3
hash of the content), ensuring both integrity and authenticity.
§Examples
use ma_core::{generate_identity_from_secret, Message, SigningKey, Did};
let sender = generate_identity_from_secret([1u8; 32]).unwrap();
let recipient = generate_identity_from_secret([2u8; 32]).unwrap();
let sign_url = Did::new_url(&sender.subject_url.ipns, None::<String>).unwrap();
let signing_key = SigningKey::from_private_key_bytes(
sign_url,
hex::decode(&sender.signing_private_key_hex).unwrap().try_into().unwrap(),
).unwrap();
// Create a signed message
let msg = Message::new(
sender.document.id.clone(),
recipient.document.id.clone(),
"text/plain",
b"hello".to_vec(),
&signing_key,
).unwrap();
// Verify against sender's document
msg.verify_with_document(&sender.document).unwrap();
// Serialize to wire format
let bytes = msg.encode().unwrap();
let restored = Message::decode(&bytes).unwrap();
assert_eq!(msg.id, restored.id);Fields§
§id: String§message_type: String§from: String§to: String§created_at: f64§ttl: u64§content_type: String§reply_to: Option<String>§content: Vec<u8>§signature: Vec<u8>Implementations§
Source§impl Message
impl Message
pub fn new( from: impl Into<String>, to: impl Into<String>, content_type: impl Into<String>, content: Vec<u8>, signing_key: &SigningKey, ) -> Result<Self>
pub fn new_with_ttl( from: impl Into<String>, to: impl Into<String>, content_type: impl Into<String>, content: Vec<u8>, ttl: u64, signing_key: &SigningKey, ) -> Result<Self>
pub fn encode(&self) -> Result<Vec<u8>>
pub fn decode(bytes: &[u8]) -> Result<Self>
pub fn unsigned_headers(&self) -> Headers
pub fn headers(&self) -> Headers
pub fn sign(&mut self, signing_key: &SigningKey) -> Result<()>
pub fn verify_with_document(&self, sender_document: &Document) -> Result<()>
pub fn enclose_for(&self, recipient_document: &Document) -> Result<Envelope>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more