"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.publicKeyToPrivateMeDid=publicKeyToPrivateMeDid,exports.privateMeDidToPublicKeyBytes=privateMeDidToPublicKeyBytes,exports.isPrivateMeDid=isPrivateMeDid,exports.isDidKeyFormat=isDidKeyFormat,exports.convertDidFormat=convertDidFormat,exports.normalizeDid=normalizeDid,exports.parseDid=parseDid;const shared_1=require("../_deps/shared/index.js"),identity_js_1=require("./identity.js");function publicKeyToPrivateMeDid(e){return(0,identity_js_1.publicKeyToDid)(e).replace(/^did:key:/,"did:privateme:")}function privateMeDidToPublicKeyBytes(e){if(!e.startsWith("did:privateme:z"))return(0,shared_1.err)("INVALID_DID_FORMAT");const i=e.replace(/^did:privateme:/,"did:key:"),r=(0,identity_js_1.didToPublicKeyBytes)(i);return r.ok?(0,shared_1.ok)(r.value):(0,shared_1.err)(r.error)}function isPrivateMeDid(e){return e.startsWith("did:privateme:")}function isDidKeyFormat(e){return e.startsWith("did:key:")}function convertDidFormat(e){return isDidKeyFormat(e)?(0,shared_1.ok)(e.replace(/^did:key:/,"did:privateme:")):isPrivateMeDid(e)?(0,shared_1.ok)(e.replace(/^did:privateme:/,"did:key:")):(0,shared_1.err)("UNSUPPORTED_DID_FORMAT")}function normalizeDid(e){return isPrivateMeDid(e)?(0,shared_1.ok)(e):isDidKeyFormat(e)?(0,shared_1.ok)(e.replace(/^did:key:/,"did:privateme:")):(0,shared_1.err)("UNSUPPORTED_DID_FORMAT")}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]?(0,shared_1.err)("INVALID_DID_FORMAT"):(0,shared_1.ok)({method:d[1],identifier:d.slice(2).join(":"),fragment:t})}