fix: handle full DID in fromShortDid to prevent double did: prefix

This commit is contained in:
Julien Calixte
2026-03-17 02:12:20 +01:00
parent 163e3ee756
commit 0381ca00cc

View File

@@ -1,6 +1,8 @@
export const toShortDid = (did: string) => did.replace(/^did:(plc:)?/, "")
// did:plc:xxx → xxx, did:web:x → web:x
export const fromShortDid = (shortDid: string) =>
shortDid.includes(":") ? `did:${shortDid}` : `did:plc:${shortDid}`
// xxx → did:plc:xxx, web:x → did:web:x
export const fromShortDid = (shortDid: string) => {
if (shortDid.startsWith("did:")) return shortDid
return shortDid.includes(":") ? `did:${shortDid}` : `did:plc:${shortDid}`
}
// xxx → did:plc:xxx, web:x → did:web:x, did:plc:xxx → did:plc:xxx (passthrough)