MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / normalize_and_validate

Method normalize_and_validate

atomic-cli/src/commands/identity/lookup_key.rs:116–137  ·  view source on GitHub ↗

Normalize user input (case, optional prefixes) and validate it as a base32-encoded Ed25519 public key.

(&self)

Source from the content-addressed store, hash-verified

114 /// Normalize user input (case, optional prefixes) and validate it as a
115 /// base32-encoded Ed25519 public key.
116 fn normalize_and_validate(&self) -> CliResult<String> {
117 let input = self.public_key.trim();
118
119 if input.starts_with(DID_ATOMIC_PREFIX) {
120 return Err(CliError::InvalidArgument {
121 message: format!(
122 "'{input}' is a did:atomic: identifier. A did:atomic: value is a \
123 fingerprint of the public key (base32 of blake3(pubkey)), not the \
124 key itself, so it cannot be used for lookup. Provide the raw \
125 base32 public key instead (52 chars, A-Z2-7)."
126 ),
127 });
128 }
129
130 let normalized = input.to_ascii_uppercase();
131
132 let key = PublicKey::from_base32(&normalized).map_err(|e| CliError::InvalidArgument {
133 message: format!("Invalid public key: {e}"),
134 })?;
135
136 Ok(key.to_base32())
137 }
138
139 /// Map a remote error, giving a clear message for the common 404 case.
140 fn map_remote_error(&self, e: RemoteError, canonical: &str) -> CliError {

Callers 4

executeMethod · 0.80

Calls 1

to_base32Method · 0.45

Tested by 3