{"version":3,"file":"didPeer.mjs","names":[],"sources":["../../../../../src/modules/dids/methods/peer/didPeer.ts"],"sourcesContent":["import { CredoError } from '../../../../error'\n\nimport { getAlternativeDidsForNumAlgo4Did } from './peerDidNumAlgo4'\n\nconst PEER_DID_REGEX =\n  /^did:peer:(([01](z)([1-9a-km-zA-HJ-NP-Z]{5,200}))|(2((.[AEVID](z)([1-9a-km-zA-HJ-NP-Z]{5,200}))+(.(S)[0-9a-zA-Z=]*)*))|([4](z[1-9a-km-zA-HJ-NP-Z]{46})(:z[1-9a-km-zA-HJ-NP-Z]{6,}){0,1}))$/\n\nexport function isValidPeerDid(did: string): boolean {\n  const isValid = PEER_DID_REGEX.test(did)\n\n  return isValid\n}\n\nexport enum PeerDidNumAlgo {\n  InceptionKeyWithoutDoc = 0,\n  GenesisDoc = 1,\n  MultipleInceptionKeyWithoutDoc = 2,\n  ShortFormAndLongForm = 4,\n}\n\nexport function getNumAlgoFromPeerDid(did: string) {\n  const numAlgo = Number(did[9])\n\n  if (\n    numAlgo !== PeerDidNumAlgo.InceptionKeyWithoutDoc &&\n    numAlgo !== PeerDidNumAlgo.GenesisDoc &&\n    numAlgo !== PeerDidNumAlgo.MultipleInceptionKeyWithoutDoc &&\n    numAlgo !== PeerDidNumAlgo.ShortFormAndLongForm\n  ) {\n    throw new CredoError(`Invalid peer did numAlgo: ${numAlgo}`)\n  }\n\n  return numAlgo as PeerDidNumAlgo\n}\n\n/**\n * Given a peer did, returns any alternative forms equivalent to it.\n *\n * @param did\n * @returns array of alternative dids or undefined if not applicable\n */\nexport function getAlternativeDidsForPeerDid(did: string) {\n  if (getNumAlgoFromPeerDid(did) === PeerDidNumAlgo.ShortFormAndLongForm) {\n    return getAlternativeDidsForNumAlgo4Did(did)\n  }\n}\n"],"mappings":";;;;;;;AAIA,MAAM,iBACJ;AAEF,SAAgB,eAAe,KAAsB;AAGnD,QAFgB,eAAe,KAAK,IAAI;;AAK1C,IAAY,0DAAL;AACL;AACA;AACA;AACA;;;AAGF,SAAgB,sBAAsB,KAAa;CACjD,MAAM,UAAU,OAAO,IAAI,GAAG;AAE9B,KACE,YAAY,eAAe,0BAC3B,YAAY,eAAe,cAC3B,YAAY,eAAe,kCAC3B,YAAY,eAAe,qBAE3B,OAAM,IAAI,WAAW,6BAA6B,UAAU;AAG9D,QAAO;;;;;;;;AAST,SAAgB,6BAA6B,KAAa;AACxD,KAAI,sBAAsB,IAAI,KAAK,eAAe,qBAChD,QAAO,iCAAiC,IAAI"}