pub struct XID(/* private fields */);
Expand description
A XID (eXtensible IDentifier).
A XID is a unique 32-byte identifier for a subject entity (person, organization, device, or any other entity). XIDs have the following characteristics:
- They’re cryptographically tied to a public key at inception (the “inception key”)
- They remain stable throughout their lifecycle even as their keys and permissions change
- They can be extended to XID documents containing keys, endpoints, permissions, and delegation info
- They support key rotation and multiple verification schemes
- They allow for delegation of specific permissions to other entities
- They can include resolution methods to locate and verify the XID document
A XID is created by taking the SHA-256 hash of the CBOR encoding of a public signing key. This ensures the XID is cryptographically tied to the key.
As defined in BCR-2024-010.
Implementations§
Source§impl XID
impl XID
pub const XID_SIZE: usize = 32usize
Sourcepub fn from_data_ref(data: impl AsRef<[u8]>) -> Result<Self>
pub fn from_data_ref(data: impl AsRef<[u8]>) -> Result<Self>
Create a new XID from data.
Returns None
if the data is not the correct length.
Sourcepub fn new(genesis_key: impl AsRef<SigningPublicKey>) -> Self
pub fn new(genesis_key: impl AsRef<SigningPublicKey>) -> Self
Create a new XID from the given public key (the “genesis key”).
The XID is the SHA-256 digest of the CBOR encoding of the public key.
Sourcepub fn validate(&self, key: &SigningPublicKey) -> bool
pub fn validate(&self, key: &SigningPublicKey) -> bool
Validate the XID against the given public key.
Sourcepub fn from_hex(hex: impl AsRef<str>) -> Self
pub fn from_hex(hex: impl AsRef<str>) -> Self
Create a new XID from the given hexadecimal string.
§Panics
Panics if the string is not exactly 64 hexadecimal digits.
Sourcepub fn short_description(&self) -> String
pub fn short_description(&self) -> String
The first four bytes of the XID as a hexadecimal string.
Sourcepub fn bytewords_identifier(&self, prefix: bool) -> String
pub fn bytewords_identifier(&self, prefix: bool) -> String
The first four bytes of the XID as upper-case ByteWords.
Sourcepub fn bytemoji_identifier(&self, prefix: bool) -> String
pub fn bytemoji_identifier(&self, prefix: bool) -> String
The first four bytes of the XID as Bytemoji.
Trait Implementations§
Source§impl CBORTagged for XID
Implements CBORTagged trait to provide CBOR tag information for XID.
impl CBORTagged for XID
Implements CBORTagged trait to provide CBOR tag information for XID.
Source§impl CBORTaggedDecodable for XID
Implements CBORTaggedDecodable to provide CBOR decoding functionality for
XID.
impl CBORTaggedDecodable for XID
Implements CBORTaggedDecodable to provide CBOR decoding functionality for XID.
Source§fn from_untagged_cbor(cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(cbor: CBOR) -> Result<Self>
Source§fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
Source§impl CBORTaggedEncodable for XID
Implements CBORTaggedEncodable to provide CBOR encoding functionality for
XID.
impl CBORTaggedEncodable for XID
Implements CBORTaggedEncodable to provide CBOR encoding functionality for XID.
Source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Source§impl Display for XID
Implements Display formatting for XID showing a shortened hex
representation.
impl Display for XID
Implements Display formatting for XID showing a shortened hex representation.
Source§impl From<&PrivateKeyBase> for XID
Implements conversion from PrivateKeyBase reference to XID via the Schnorr
signing key.
impl From<&PrivateKeyBase> for XID
Implements conversion from PrivateKeyBase reference to XID via the Schnorr signing key.
Source§fn from(key: &PrivateKeyBase) -> Self
fn from(key: &PrivateKeyBase) -> Self
Source§impl From<&PublicKeys> for XID
Implements conversion from PublicKeys reference to XID via the signing
public key.
impl From<&PublicKeys> for XID
Implements conversion from PublicKeys reference to XID via the signing public key.
Source§fn from(key: &PublicKeys) -> Self
fn from(key: &PublicKeys) -> Self
Source§impl From<&SigningPublicKey> for XID
Implements conversion from SigningPublicKey reference to XID.
impl From<&SigningPublicKey> for XID
Implements conversion from SigningPublicKey reference to XID.
Source§fn from(key: &SigningPublicKey) -> Self
fn from(key: &SigningPublicKey) -> Self
Source§impl<'a> From<&'a XID> for &'a [u8]
Implements conversion from a XID reference to a byte slice reference.
impl<'a> From<&'a XID> for &'a [u8]
Implements conversion from a XID reference to a byte slice reference.
Source§impl<'a> From<&'a XID> for &'a [u8; 32]
Implements conversion from a XID reference to a byte array reference.
impl<'a> From<&'a XID> for &'a [u8; 32]
Implements conversion from a XID reference to a byte array reference.
Source§impl From<XID> for Vec<u8>
Implements conversion from XID to Vec<u8>
to allow access to the raw
bytes.
impl From<XID> for Vec<u8>
Implements conversion from XID to Vec<u8>
to allow access to the raw
bytes.
Source§impl Ord for XID
Implements Ord to allow XIDs to be fully ordered.
impl Ord for XID
Implements Ord to allow XIDs to be fully ordered.
Source§impl PartialOrd for XID
Implements PartialOrd to allow XIDs to be compared and partially ordered.
impl PartialOrd for XID
Implements PartialOrd to allow XIDs to be compared and partially ordered.
Source§impl ReferenceProvider for XID
Implements ReferenceProvider for XID to generate a Reference from the XID.
impl ReferenceProvider for XID
Implements ReferenceProvider for XID to generate a Reference from the XID.
Source§fn reference(&self) -> Reference
fn reference(&self) -> Reference
Source§fn ref_hex_short(&self) -> String
fn ref_hex_short(&self) -> String
Source§impl TryFrom<&SigningPrivateKey> for XID
Implements conversion from SigningPrivateKey reference to XID via the public
key.
impl TryFrom<&SigningPrivateKey> for XID
Implements conversion from SigningPrivateKey reference to XID via the public key.
Source§impl XIDProvider for XID
Implements XIDProvider for XID to return itself.
impl XIDProvider for XID
Implements XIDProvider for XID to return itself.
impl Copy for XID
impl Eq for XID
impl StructuralPartialEq for XID
Auto Trait Implementations§
impl Freeze for XID
impl RefUnwindSafe for XID
impl Send for XID
impl Sync for XID
impl Unpin for XID
impl UnwindSafe for XID
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
Source§impl<T> CBORDecodable for T
impl<T> CBORDecodable for T
Source§impl<T> CBOREncodable for T
impl<T> CBOREncodable for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)