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
impl IdentityEncoder
Sourcepub fn decode_to_prefix(&self, identity: &str) -> Result<[u8; 6]>
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.
Sourcepub fn encode_agent(&self, agent_id: &[u8]) -> Result<IdentityWords>
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).
Sourcepub fn encode_full(
&self,
agent_id: &[u8],
user_id: &[u8],
) -> Result<IdentityWords>
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.
Sourcepub fn encode_hex(&self, hex_str: &str) -> Result<IdentityWords>
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).
Sourcepub fn encode_hex_full(
&self,
agent_hex: &str,
user_hex: &str,
) -> Result<IdentityWords>
pub fn encode_hex_full( &self, agent_hex: &str, user_hex: &str, ) -> Result<IdentityWords>
Encodes two hex strings into a full 8-word identity.
Sourcepub fn parse(&self, input: &str) -> Result<IdentityWords>
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"
Sourcepub fn matches(&self, hash: &[u8], words: &str) -> Result<bool>
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.