const DID_METHOD_PREFIX: &str = "did:keri:";
const PRODUCT_PREFIX: &str = "auths:";
pub fn product_id(did: &str) -> String {
match did.strip_prefix(DID_METHOD_PREFIX) {
Some(prefix) => format!("{PRODUCT_PREFIX}{prefix}"),
None => did.to_string(),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn maps_canonical_did_to_product_handle() {
assert_eq!(
product_id("did:keri:EPmeUXn8Gbk_4u0ilbMnA46y6Q_5X1nRIpjPxCDmejml"),
"auths:EPmeUXn8Gbk_4u0ilbMnA46y6Q_5X1nRIpjPxCDmejml"
);
}
#[test]
fn preserves_the_prefix_verbatim() {
let prefix = "EBb6li302WtvHTrhg4FUmFuiWjrQEb-2mOD1TYrVd6ge";
let shown = product_id(&format!("did:keri:{prefix}"));
assert!(shown.ends_with(prefix), "prefix must be preserved exactly");
}
#[test]
fn passes_through_non_did_strings_unchanged() {
assert_eq!(
product_id("auths:already-a-handle"),
"auths:already-a-handle"
);
assert_eq!(product_id(""), "");
assert_eq!(product_id("did:key:zDnaeh"), "did:key:zDnaeh");
}
#[test]
fn display_form_carries_no_protocol_method_token() {
let shown = product_id("did:keri:EPmeUXn8Gbk_4u0ilbMnA46y6Q");
assert!(!shown.contains("did:keri:"));
assert!(shown.starts_with("auths:"));
}
}