Skip to main content

IdentityEncoder

Struct IdentityEncoder 

Source
pub struct IdentityEncoder;
Expand description

Encoder for x0x identity words.

Converts 256-bit cryptographic hashes (AgentId, UserId) into human-speakable four-word names using the 4,096-word dictionary.

Implementations§

Source§

impl IdentityEncoder

Source

pub fn new() -> Self

Creates a new identity encoder.

Source

pub fn decode_to_prefix(&self, identity: &str) -> Result<[u8; 6]>

Decodes 4 words back to a 48-bit (6-byte) prefix.

This is the reverse of encode_hash_prefix. The returned bytes can be used as a search prefix to locate agents on the gossip network.

Source

pub fn encode_agent(&self, agent_id: &[u8]) -> Result<IdentityWords>

Encodes an AgentId into 4 identity words.

The AgentId is the SHA-256 hash of the agent’s ML-DSA-65 public key. This produces an autonomous agent identity (4 words, no human backing).

Source

pub fn encode_full( &self, agent_id: &[u8], user_id: &[u8], ) -> Result<IdentityWords>

Encodes an AgentId and UserId into 8 identity words (4 @ 4).

This produces a full human-backed identity. The AgentId is the agent’s key hash, the UserId is the human’s key hash.

Source

pub fn encode_hex(&self, hex_str: &str) -> Result<IdentityWords>

Encodes a hex-encoded hash string into identity words.

Convenience method that accepts a hex string (as displayed by x0x agent).

Source

pub fn encode_hex_full( &self, agent_hex: &str, user_hex: &str, ) -> Result<IdentityWords>

Encodes two hex strings into a full 8-word identity.

Source

pub fn parse(&self, input: &str) -> Result<IdentityWords>

Parses an identity string into IdentityWords.

Accepts either:

  • 4 space-separated words (agent identity)
  • 8 words with @ separator (full identity): "word1 word2 word3 word4 @ word5 word6 word7 word8"
Source

pub fn matches(&self, hash: &[u8], words: &str) -> Result<bool>

Checks whether a 32-byte hash matches a set of identity words.

Compares the first 48 bits of the hash against the prefix encoded by the words. Useful for verifying that an agent found via gossip actually matches the searched identity words.

Trait Implementations§

Source§

impl Default for IdentityEncoder

Source§

fn default() -> Self

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

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> 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, 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