Skip to main content

Document

Struct Document 

Source
pub struct Document {
    pub context: Vec<String>,
    pub id: String,
    pub controller: Vec<String>,
    pub verification_method: Vec<VerificationMethod>,
    pub assertion_method: Vec<String>,
    pub key_agreement: Vec<String>,
    pub proof: Proof,
    pub identity: Option<String>,
    pub created_at: String,
    pub updated_at: String,
    pub ma: Option<Ipld>,
}
Expand description

A did:ma: DID document.

Contains verification methods, proof, and optional extension data. Documents are signed with Ed25519 over a BLAKE3 hash of the dag-cbor-serialized payload (all fields except proof).

§Examples

use ma_did::{generate_identity, Document};

let id = generate_identity(
    "k51qzi5uqu5dj9807pbuod1pplf0vxh8m4lfy3ewl9qbm2s8dsf9ugdf9gedhr"
).unwrap();

// Verify the signature
id.document.verify().unwrap();

// Validate structural correctness
id.document.validate().unwrap();

// Round-trip through JSON
let json = id.document.marshal().unwrap();
let restored = Document::unmarshal(&json).unwrap();
assert_eq!(id.document, restored);

// Round-trip through CBOR
let cbor = id.document.to_cbor().unwrap();
let restored = Document::from_cbor(&cbor).unwrap();
assert_eq!(id.document, restored);

§Extension namespace

The ma field is an opaque IPLD value for application-defined extension data. did-ma does not interpret or validate its contents. Using Ipld gives native support for CID links and dag-cbor/dag-json round-tripping.

use std::collections::BTreeMap;
use ipld_core::ipld::Ipld;
use ma_did::{Did, Document};

let did = Did::new_url("k51qzi5uqu5dj9807pbuod1pplf0vxh8m4lfy3ewl9qbm2s8dsf9ugdf9gedhr", None::<String>).unwrap();
let mut doc = Document::new(&did, &did);
let ma = Ipld::Map(BTreeMap::from([
    ("type".into(), Ipld::String("agent".into())),
    ("services".into(), Ipld::Map(BTreeMap::new())),
]));
doc.set_ma(ma);
assert!(doc.ma.is_some());
doc.clear_ma();
assert!(doc.ma.is_none());

Fields§

§context: Vec<String>§id: String§controller: Vec<String>§verification_method: Vec<VerificationMethod>§assertion_method: Vec<String>§key_agreement: Vec<String>§proof: Proof§identity: Option<String>§created_at: String§updated_at: String§ma: Option<Ipld>

Implementations§

Source§

impl Document

Source

pub fn new(identity: &Did, controller: &Did) -> Document

Source

pub fn set_ma(&mut self, ma: Ipld)

Set the opaque ma extension namespace.

Source

pub fn clear_ma(&mut self)

Clear the ma extension namespace.

Source

pub fn to_cbor(&self) -> Result<Vec<u8>, MaError>

Source

pub fn from_cbor(bytes: &[u8]) -> Result<Document, MaError>

Source

pub fn marshal(&self) -> Result<String, MaError>

Source

pub fn unmarshal(s: &str) -> Result<Document, MaError>

Source

pub fn add_controller( &mut self, controller: impl Into<String>, ) -> Result<(), MaError>

Source

pub fn add_verification_method( &mut self, method: VerificationMethod, ) -> Result<(), MaError>

Source

pub fn get_verification_method_by_id( &self, method_id: &str, ) -> Result<&VerificationMethod, MaError>

Source

pub fn set_identity( &mut self, identity: impl Into<String>, ) -> Result<(), MaError>

Source

pub fn touch(&mut self)

Update the updatedAt timestamp to the current time.

Source

pub fn assertion_method_public_key(&self) -> Result<VerifyingKey, MaError>

Source

pub fn key_agreement_public_key_bytes(&self) -> Result<[u8; 32], MaError>

Source

pub fn payload_document(&self) -> Document

Source

pub fn payload_bytes(&self) -> Result<Vec<u8>, MaError>

Source

pub fn payload_hash(&self) -> Result<[u8; 32], MaError>

Source

pub fn sign( &mut self, signing_key: &SigningKey, verification_method: &VerificationMethod, ) -> Result<(), MaError>

Source

pub fn verify(&self) -> Result<(), MaError>

Source

pub fn validate(&self) -> Result<(), MaError>

Trait Implementations§

Source§

impl Clone for Document

Source§

fn clone(&self) -> Document

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Document

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Document, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Document

Source§

fn eq(&self, other: &Document) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Document

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Document

Source§

impl StructuralPartialEq for Document

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> RpcMessage for T
where T: Debug + Serialize + DeserializeOwned + Send + Sync + Unpin + 'static,