Skip to main content

auths_cli/commands/
verify_helpers.rs

1use anyhow::{Context, Result, anyhow};
2
3/// Parse witness key arguments ("did:key:z6Mk...:abcd1234...") into (DID, pk_bytes) tuples.
4pub fn parse_witness_keys(keys: &[String]) -> Result<Vec<(String, Vec<u8>)>> {
5    keys.iter()
6        .map(|s| {
7            // Find the last ':' to split DID from hex key
8            let last_colon = s
9                .rfind(':')
10                .ok_or_else(|| anyhow!("Invalid witness key format '{}': expected DID:hex", s))?;
11            let did = &s[..last_colon];
12            let pk_hex = &s[last_colon + 1..];
13            let pk_bytes = hex::decode(pk_hex)
14                .with_context(|| format!("Invalid hex in witness key for '{}'", did))?;
15            Ok((did.to_string(), pk_bytes))
16        })
17        .collect()
18}