@credo-ts/core
Version:
<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1
1 lines • 4.86 kB
Source Map (JSON)
{"version":3,"file":"PeerDidResolver.mjs","names":[],"sources":["../../../../../src/modules/dids/methods/peer/PeerDidResolver.ts"],"sourcesContent":["import type { AgentContext } from '../../../../agent'\nimport { CredoError } from '../../../../error'\nimport type { DidDocument } from '../../domain'\nimport type { DidResolver } from '../../domain/DidResolver'\nimport { DidRepository } from '../../repository'\nimport type { DidResolutionResult } from '../../types'\n\nimport { getNumAlgoFromPeerDid, isValidPeerDid, PeerDidNumAlgo } from './didPeer'\nimport { didToNumAlgo0DidDocument } from './peerDidNumAlgo0'\nimport { didToNumAlgo2DidDocument } from './peerDidNumAlgo2'\nimport { didToNumAlgo4DidDocument, isShortFormDidPeer4 } from './peerDidNumAlgo4'\n\nexport class PeerDidResolver implements DidResolver {\n public readonly supportedMethods = ['peer']\n\n /**\n * No remote resolving done, did document is fetched from storage. To not pollute the cache we don't allow caching\n */\n public readonly allowsCaching = false\n\n /**\n * Did peer records are often server from local did doucment, but it's easier to handle it in\n * the peer did resolver.\n */\n public readonly allowsLocalDidRecord = false\n\n public async resolve(agentContext: AgentContext, did: string): Promise<DidResolutionResult> {\n const didRepository = agentContext.dependencyManager.resolve(DidRepository)\n\n const didDocumentMetadata = {}\n\n try {\n let didDocument: DidDocument\n\n if (!isValidPeerDid(did)) {\n throw new CredoError(`did ${did} is not a valid peer did`)\n }\n\n const numAlgo = getNumAlgoFromPeerDid(did)\n\n // For method 0, generate from did\n if (numAlgo === PeerDidNumAlgo.InceptionKeyWithoutDoc) {\n didDocument = didToNumAlgo0DidDocument(did)\n }\n // For Method 1, retrieve from storage\n else if (numAlgo === PeerDidNumAlgo.GenesisDoc) {\n // We can have multiple did document records stored for a single did (one created and one received). In this case it\n // doesn't matter which one we use, and they should be identical. So we just take the first one.\n const [didDocumentRecord] = await didRepository.findAllByDid(agentContext, did)\n\n if (!didDocumentRecord) {\n throw new CredoError(`No did record found for peer did ${did}.`)\n }\n\n if (!didDocumentRecord.didDocument) {\n throw new CredoError(`Found did record for method 1 peer did (${did}), but no did document.`)\n }\n\n didDocument = didDocumentRecord.didDocument\n }\n // For Method 2, generate from did\n else if (numAlgo === PeerDidNumAlgo.MultipleInceptionKeyWithoutDoc) {\n didDocument = didToNumAlgo2DidDocument(did)\n }\n // For Method 4, if short form is received, attempt to get the didDocument from stored record\n else {\n if (isShortFormDidPeer4(did)) {\n const [didRecord] = await didRepository.findAllByDid(agentContext, did)\n\n if (!didRecord) {\n throw new CredoError(`No did record found for peer did ${did}.`)\n }\n didDocument = didToNumAlgo4DidDocument(didRecord.did)\n } else {\n didDocument = didToNumAlgo4DidDocument(did)\n }\n }\n\n return {\n didDocument,\n didDocumentMetadata,\n didResolutionMetadata: { contentType: 'application/did+ld+json' },\n }\n } catch (error) {\n agentContext.config.logger.error(`Error resolving did '${did}'`, {\n error,\n })\n\n return {\n didDocument: null,\n didDocumentMetadata,\n didResolutionMetadata: {\n error: 'notFound',\n message: `resolver_error: Unable to resolve did '${did}': ${error}`,\n },\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;AAYA,IAAa,kBAAb,MAAoD;;EAClD,KAAgB,mBAAmB,CAAC,MAAM;EAK1C,KAAgB,gBAAgB;EAMhC,KAAgB,uBAAuB;;CAEvC,MAAa,QAAQ,cAA4B,KAA2C;EAC1F,MAAM,gBAAgB,aAAa,kBAAkB,QAAQ,aAAa;EAE1E,MAAM,sBAAsB,CAAC;EAE7B,IAAI;GACF,IAAI;GAEJ,IAAI,CAAC,eAAe,GAAG,GACrB,MAAM,IAAI,WAAW,OAAO,IAAI,yBAAyB;GAG3D,MAAM,UAAU,sBAAsB,GAAG;GAGzC,IAAI,YAAA,GACF,cAAc,yBAAyB,GAAG;QAGvC,IAAI,YAAA,GAA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