Skip to main content

XIDDocument

Struct XIDDocument 

Source
pub struct XIDDocument { /* private fields */ }

Implementations§

Source§

impl XIDDocument

Source

pub fn new( key_options: XIDInceptionKeyOptions, mark_options: XIDGenesisMarkOptions, ) -> Self

Source

pub fn from_xid(xid: impl Into<XID>) -> Self

Source

pub fn resolution_methods(&self) -> &HashSet<URI>

Source

pub fn resolution_methods_mut(&mut self) -> &mut HashSet<URI>

Source

pub fn add_resolution_method(&mut self, method: URI)

Source

pub fn remove_resolution_method( &mut self, method: impl AsRef<URI>, ) -> Option<URI>

Source

pub fn keys(&self) -> &HashSet<Key>

Source

pub fn keys_mut(&mut self) -> &mut HashSet<Key>

Source

pub fn add_key(&mut self, key: Key) -> Result<()>

Source

pub fn find_key_by_public_keys( &self, key: &dyn PublicKeysProvider, ) -> Option<&Key>

Source

pub fn find_key_by_reference(&self, reference: &Reference) -> Option<&Key>

Source

pub fn private_key_envelope_for_key( &self, public_keys: &PublicKeys, password: Option<&str>, ) -> Result<Option<Envelope>>

Get the private key envelope for a specific key, optionally decrypting it.

§Arguments
  • public_keys - The public keys identifying the key to retrieve
  • password - Optional password for decryption
§Returns
  • Ok(None) if the key is not found or has no private key
  • Ok(Some(Envelope)) containing:
    • Decrypted PrivateKeys if unencrypted
    • Decrypted PrivateKeys if encrypted and correct password provided
    • Encrypted envelope if encrypted and no password provided
  • Err(Error::InvalidPassword) if encrypted and wrong password provided
§Examples
use bc_components::{PrivateKeyBase, PublicKeysProvider};
use bc_envelope::prelude::*;
use bc_xid::{XIDDocument, XIDGenesisMarkOptions, XIDInceptionKeyOptions};

let prvkey_base = PrivateKeyBase::new();
let doc = XIDDocument::new(
    XIDInceptionKeyOptions::PrivateKeyBase(prvkey_base.clone()),
    XIDGenesisMarkOptions::None,
);

// Get unencrypted private key
let key = doc.keys().iter().next().unwrap();
let envelope = doc
    .private_key_envelope_for_key(key.public_keys(), None)
    .unwrap()
    .unwrap();
Source

pub fn take_key(&mut self, key: &dyn PublicKeysProvider) -> Option<Key>

Source

pub fn remove_key(&mut self, key: &dyn PublicKeysProvider) -> Result<()>

Source

pub fn set_name_for_key( &mut self, key: &dyn PublicKeysProvider, name: impl Into<String>, ) -> Result<()>

Source

pub fn is_inception_signing_key( &self, signing_public_key: &SigningPublicKey, ) -> bool

Source

pub fn inception_signing_key(&self) -> Option<&SigningPublicKey>

Source

pub fn inception_key(&self) -> Option<&Key>

Source

pub fn remove_inception_key(&mut self) -> Option<Key>

Source

pub fn verification_key(&self) -> Option<&SigningPublicKey>

Source

pub fn encryption_key(&self) -> Option<&EncapsulationPublicKey>

Source

pub fn inception_private_keys(&self) -> Option<&PrivateKeys>

Get the private keys from the inception key, if available.

Returns None if there is no inception key or if the inception key does not have private key material (e.g., if it was encrypted and not decrypted).

Source

pub fn extract_inception_private_keys_from_envelope( envelope: &Envelope, password: &[u8], ) -> Result<Option<PrivateKeys>>

Extract private keys from an envelope containing an encrypted XIDDocument.

This is a convenience method that loads the document with the password and returns the inception key’s private keys if available.

Returns None if:

  • The document has no inception key
  • The inception key has no private key material
  • The password is incorrect
Source

pub fn is_empty(&self) -> bool

Source

pub fn delegates(&self) -> &HashSet<Delegate>

Source

pub fn delegates_mut(&mut self) -> &mut HashSet<Delegate>

Source

pub fn add_delegate(&mut self, delegate: Delegate) -> Result<()>

Source

pub fn find_delegate_by_xid( &self, xid_provider: &dyn XIDProvider, ) -> Option<&Delegate>

Source

pub fn find_delegate_by_reference( &self, reference: &Reference, ) -> Option<&Delegate>

Source

pub fn take_delegate( &mut self, xid_provider: &dyn XIDProvider, ) -> Option<Delegate>

Source

pub fn remove_delegate(&mut self, xid_provider: &dyn XIDProvider) -> Result<()>

Source

pub fn find_service_by_uri(&self, uri: impl AsRef<URI>) -> Option<&Service>

Source

pub fn services(&self) -> &HashSet<Service>

Source

pub fn add_service(&mut self, service: Service) -> Result<()>

Source

pub fn take_service(&mut self, uri: impl AsRef<URI>) -> Option<Service>

Source

pub fn check_services_consistency(&self) -> Result<()>

Source

pub fn check_service_consistency(&self, service: &Service) -> Result<()>

Source

pub fn check_contains_key(&self, key: &dyn PublicKeysProvider) -> Result<()>

Source

pub fn check_contains_delegate( &self, xid_provider: &dyn XIDProvider, ) -> Result<()>

Source

pub fn services_reference_key(&self, key: &dyn PublicKeysProvider) -> bool

Source

pub fn services_reference_delegate( &self, xid_provider: &dyn XIDProvider, ) -> bool

Source

pub fn remove_service(&mut self, uri: impl AsRef<URI>) -> Result<()>

Source

pub fn provenance(&self) -> Option<&ProvenanceMark>

Source

pub fn provenance_generator(&self) -> Option<&ProvenanceMarkGenerator>

Source

pub fn set_provenance(&mut self, provenance: Option<ProvenanceMark>)

Source

pub fn set_provenance_with_generator( &mut self, generator: ProvenanceMarkGenerator, mark: ProvenanceMark, )

Source

pub fn next_provenance_mark_with_embedded_generator( &mut self, password: Option<Vec<u8>>, date: Option<Date>, info: Option<CBOR>, ) -> Result<()>

Advance the provenance mark using the embedded generator.

This method uses the generator embedded in the document’s provenance to generate the next provenance mark. If the generator is encrypted, it will be decrypted using the provided password. After advancement, the generator remains in the document in decrypted state.

§Parameters
  • password: Optional password to decrypt the generator if encrypted. Pass as Vec<u8> or None.
  • date: Optional date for the new mark. If None, the current date is used.
  • info: Optional CBOR-encodable info to attach to the new mark.
§Errors

Returns an error if:

  • The document does not have a provenance mark (Error::NoProvenanceMark)
  • The document does not have a generator (Error::NoGenerator)
  • The generator is encrypted and the password is wrong (Error::InvalidPassword)
Source

pub fn next_provenance_mark_with_provided_generator( &mut self, generator: &mut ProvenanceMarkGenerator, date: Option<Date>, info: Option<CBOR>, ) -> Result<()>

Advance the provenance mark using a provided generator.

This method uses an external generator to generate the next provenance mark. The generator is not embedded in the document after advancement; the caller maintains ownership of the generator.

§Parameters
  • generator: Mutable reference to the external ProvenanceMarkGenerator.
  • date: Optional date for the new mark. If None, the current date is used.
  • info: Optional CBOR-encodable info to attach to the new mark.
§Errors

Returns an error if:

  • The document does not have a provenance mark (Error::NoProvenanceMark)
  • The document already has an embedded generator (Error::GeneratorConflict)
  • The provided generator’s chain ID doesn’t match the current mark’s chain ID
  • The provided generator’s next_seq doesn’t match the expected sequence number
Source

pub fn to_envelope( &self, private_key_options: XIDPrivateKeyOptions, generator_options: XIDGeneratorOptions, signing_options: XIDSigningOptions, ) -> Result<Envelope>

Convert XIDDocument to an Envelope.

Source

pub fn from_envelope( envelope: &Envelope, password: Option<&[u8]>, verify_signature: XIDVerifySignature, ) -> Result<Self>

Extract an XIDDocument from an envelope.

§Parameters
  • envelope: The envelope to extract the document from. Can be signed or unsigned.
  • password: Optional password to decrypt encrypted private keys. If private keys are encrypted and no password is provided, the keys will be stored without their private key material.
  • verify_signature: Signature verification mode. Use XIDVerifySignature::None to skip verification, or XIDVerifySignature::Inception to verify that the envelope is signed with the inception key.
§Returns

Returns Ok(XIDDocument) on success.

§Errors
  • Error::EnvelopeNotSigned: When verify_signature is Inception but the envelope is not signed.
  • Error::MissingInceptionKey: When verify_signature is Inception but the inception key is not found in the document.
  • Error::SignatureVerificationFailed: When the signature verification fails.
  • Error::InvalidXid: When the inception key does not match the XID.
  • Other errors from envelope parsing or key extraction.
Source

pub fn to_signed_envelope(&self, signing_key: &impl Signer) -> Envelope

Source

pub fn to_signed_envelope_opt( &self, signing_key: &impl Signer, private_key_options: XIDPrivateKeyOptions, ) -> Envelope

Trait Implementations§

Source§

impl AsRef<XIDDocument> for XIDDocument

Source§

fn as_ref(&self) -> &XIDDocument

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Attachable for XIDDocument

Source§

fn attachments(&self) -> &Attachments

Returns a reference to the attachments container.
Source§

fn attachments_mut(&mut self) -> &mut Attachments

Returns a mutable reference to the attachments container.
Source§

fn add_attachment( &mut self, payload: impl EnvelopeEncodable, vendor: &str, conforms_to: Option<&str>, )

Adds a new attachment with the specified payload and metadata. Read more
Source§

fn get_attachment(&self, digest: Digest) -> Option<&Envelope>

Retrieves an attachment by its digest. Read more
Source§

fn remove_attachment(&mut self, digest: Digest) -> Option<Envelope>

Removes an attachment by its digest. Read more
Source§

fn clear_attachments(&mut self)

Removes all attachments from the object.
Source§

fn has_attachments(&self) -> bool

Returns whether the object has any attachments. Read more
Source§

impl CBORTagged for XIDDocument

Source§

fn cbor_tags() -> Vec<Tag>

Returns the CBOR tags associated with this type. Read more
Source§

impl CBORTaggedDecodable for XIDDocument

Source§

fn from_untagged_cbor(cbor: CBOR) -> Result<Self>

Creates an instance of this type by decoding it from untagged CBOR. Read more
Source§

fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>
where Self: Sized,

Creates an instance of this type by decoding it from tagged CBOR. Read more
Source§

fn from_tagged_cbor_data(data: impl AsRef<[u8]>) -> Result<Self, Error>
where Self: Sized,

Creates an instance of this type by decoding it from binary encoded tagged CBOR. Read more
Source§

fn from_untagged_cbor_data(data: impl AsRef<[u8]>) -> Result<Self, Error>
where Self: Sized,

Creates an instance of this type by decoding it from binary encoded untagged CBOR. Read more
Source§

impl CBORTaggedEncodable for XIDDocument

Source§

fn untagged_cbor(&self) -> CBOR

Returns the untagged CBOR encoding of this instance. Read more
Source§

fn tagged_cbor(&self) -> CBOR

Returns the tagged CBOR encoding of this instance. Read more
Source§

fn tagged_cbor_data(&self) -> Vec<u8>

Returns the tagged value in CBOR binary representation. Read more
Source§

impl Clone for XIDDocument

Source§

fn clone(&self) -> XIDDocument

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 XIDDocument

Source§

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

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

impl Default for XIDDocument

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Edgeable for XIDDocument

Source§

fn edges(&self) -> &Edges

Returns a reference to the edges container.
Source§

fn edges_mut(&mut self) -> &mut Edges

Returns a mutable reference to the edges container.
Source§

fn add_edge(&mut self, edge_envelope: Envelope)

Adds a pre-constructed edge envelope.
Source§

fn get_edge(&self, digest: Digest) -> Option<&Envelope>

Retrieves an edge by its digest.
Source§

fn remove_edge(&mut self, digest: Digest) -> Option<Envelope>

Removes an edge by its digest.
Source§

fn clear_edges(&mut self)

Removes all edges.
Source§

fn has_edges(&self) -> bool

Returns whether the object has any edges.
Source§

impl From<&PrivateKeyBase> for XIDDocument

Source§

fn from(inception_key: &PrivateKeyBase) -> Self

Converts to this type from the input type.
Source§

impl From<PrivateKeyBase> for XIDDocument

Source§

fn from(inception_key: PrivateKeyBase) -> Self

Converts to this type from the input type.
Source§

impl From<PublicKeys> for XIDDocument

Source§

fn from(inception_key: PublicKeys) -> Self

Converts to this type from the input type.
Source§

impl From<XID> for XIDDocument

Source§

fn from(xid: XID) -> Self

Converts to this type from the input type.
Source§

impl From<XIDDocument> for CBOR

Source§

fn from(value: XIDDocument) -> Self

Converts to this type from the input type.
Source§

impl From<XIDDocument> for Envelope

Source§

fn from(value: XIDDocument) -> Self

Converts to this type from the input type.
Source§

impl From<XIDDocument> for XID

Source§

fn from(doc: XIDDocument) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for XIDDocument

Source§

fn eq(&self, other: &XIDDocument) -> 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 ReferenceProvider for XIDDocument

Source§

fn reference(&self) -> Reference

Returns a cryptographic reference that uniquely identifies this object. Read more
Source§

fn ref_hex(&self) -> String

Returns the reference data as a hexadecimal string. Read more
Source§

fn ref_data_short(&self) -> [u8; 4]

Returns the first four bytes of the reference. Read more
Source§

fn ref_hex_short(&self) -> String

Returns the first four bytes of the reference as a hexadecimal string. Read more
Source§

fn ref_bytewords(&self, prefix: Option<&str>) -> String

Returns the first four bytes of the reference as upper-case ByteWords. Read more
Source§

fn ref_bytemoji(&self, prefix: Option<&str>) -> String

Returns the first four bytes of the reference as Bytemoji. Read more
Source§

impl TryFrom<&Envelope> for XIDDocument

Source§

type Error = Error

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

fn try_from(envelope: &Envelope) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<CBOR> for XIDDocument

Source§

type Error = Error

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

fn try_from(cbor: CBOR) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Envelope> for XIDDocument

Source§

type Error = Error

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

fn try_from(envelope: Envelope) -> Result<Self>

Performs the conversion.
Source§

impl XIDProvider for XIDDocument

Source§

fn xid(&self) -> XID

Returns the XID for this object.
Source§

impl Eq for XIDDocument

Source§

impl StructuralPartialEq for XIDDocument

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> CBORDecodable for T
where T: TryFrom<CBOR, Error = Error>,

Source§

fn try_from_cbor(cbor: &CBOR) -> Result<Self, Error>

Source§

impl<T> CBOREncodable for T
where T: Into<CBOR> + Clone,

Source§

fn to_cbor(&self) -> CBOR

Converts this value to a CBOR object. Read more
Source§

fn to_cbor_data(&self) -> Vec<u8>

Converts this value directly to binary CBOR data. 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<T> EnvelopeEncodable for T
where T: Into<Envelope> + Clone,

Source§

fn into_envelope(self) -> Envelope

Converts the value into an envelope by using its Into<Envelope> implementation.

Source§

fn to_envelope(&self) -> Envelope
where Self: Clone,

Converts a reference to this value into a Gordian Envelope. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
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<T> URDecodable for T

Source§

fn from_ur(ur: impl AsRef<UR>) -> Result<Self, Error>
where Self: Sized,

Source§

fn from_ur_string(ur_string: impl Into<String>) -> Result<Self, Error>
where Self: Sized,

Source§

impl<T> UREncodable for T

Source§

fn ur(&self) -> UR

Returns the UR representation of the object.
Source§

fn ur_string(&self) -> String

Returns the UR string representation of the object.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> CBORCodable for T

Source§

impl<T> CBORTaggedCodable for T

Source§

impl<T> URCodable for T