import{ok,err}from"./_deps/shared/index.js";import{publicKeyToDid,didToPublicKeyBytes}from"./identity.js";export function publicKeyToPrivateMeDid(e){return publicKeyToDid(e).replace(/^did:key:/,"did:privateme:")}export function privateMeDidToPublicKeyBytes(e){if(!e.startsWith("did:privateme:z"))return err("INVALID_DID_FORMAT");const i=e.replace(/^did:privateme:/,"did:key:"),r=didToPublicKeyBytes(i);return r.ok?ok(r.value):err(r.error)}export function isPrivateMeDid(e){return e.startsWith("did:privateme:")}export function isDidKeyFormat(e){return e.startsWith("did:key:")}export function convertDidFormat(e){return isDidKeyFormat(e)?ok(e.replace(/^did:key:/,"did:privateme:")):isPrivateMeDid(e)?ok(e.replace(/^did:privateme:/,"did:key:")):err("UNSUPPORTED_DID_FORMAT")}export function normalizeDid(e){return isPrivateMeDid(e)?ok(e):isDidKeyFormat(e)?ok(e.replace(/^did:key:/,"did:privateme:")):err("UNSUPPORTED_DID_FORMAT")}export function parseDid(e){const i=e.indexOf("#"),r=i>=0?e.substring(0,i):e,t=i>=0?e.substring(i+1):void 0,d=r.split(":");return d.length<3||"did"!==d[0]?err("INVALID_DID_FORMAT"):ok({method:d[1],identifier:d.slice(2).join(":"),fragment:t})}