UNPKG

@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 • 5.43 kB
{"version":3,"file":"DidRepository.mjs","names":[],"sources":["../../../../src/modules/dids/repository/DidRepository.ts"],"sourcesContent":["import type { AgentContext } from '../../../agent'\nimport { EventEmitter } from '../../../agent/EventEmitter'\nimport { InjectionSymbols } from '../../../constants'\nimport { inject, injectable } from '../../../plugins'\nimport { Repository } from '../../../storage/Repository'\nimport type { StorageService } from '../../../storage/StorageService'\nimport { PublicJwk } from '../../kms'\nimport type { DidDocumentKey } from '../DidsApiOptions'\nimport type { DidDocument } from '../domain'\nimport { DidDocumentRole } from '../domain/DidDocumentRole'\nimport type { CustomDidTags } from './DidRecord'\nimport { DidRecord } from './DidRecord'\n\n@injectable()\nexport class DidRepository extends Repository<DidRecord> {\n public constructor(\n @inject(InjectionSymbols.StorageService) storageService: StorageService<DidRecord>,\n eventEmitter: EventEmitter\n ) {\n super(DidRecord, storageService, eventEmitter)\n }\n\n /**\n * Finds a {@link DidRecord}, containing the specified recipientKey that was received by this agent.\n * To find a {@link DidRecord} that was created by this agent, use {@link DidRepository.findCreatedDidByRecipientKey}.\n */\n public findReceivedDidByRecipientKey(agentContext: AgentContext, recipientKey: PublicJwk) {\n return this.findSingleByQuery(agentContext, {\n recipientKeyFingerprints: [recipientKey.fingerprint],\n role: DidDocumentRole.Received,\n })\n }\n\n /**\n * Finds a {@link DidRecord}, containing the specified recipientKey that was created by this agent.\n * To find a {@link DidRecord} that was received by this agent, use {@link DidRepository.findReceivedDidByRecipientKey}.\n */\n public findCreatedDidByRecipientKey(agentContext: AgentContext, recipientKey: PublicJwk) {\n return this.findSingleByQuery(agentContext, {\n recipientKeyFingerprints: [recipientKey.fingerprint],\n role: DidDocumentRole.Created,\n })\n }\n\n public findAllByRecipientKey(agentContext: AgentContext, recipientKey: PublicJwk) {\n return this.findByQuery(agentContext, { recipientKeyFingerprints: [recipientKey.fingerprint] })\n }\n\n public findAllByDid(agentContext: AgentContext, did: string) {\n return this.findByQuery(agentContext, { $or: [{ alternativeDids: [did] }, { did }] })\n }\n\n public findReceivedDid(agentContext: AgentContext, receivedDid: string) {\n return this.findSingleByQuery(agentContext, {\n $or: [{ alternativeDids: [receivedDid] }, { did: receivedDid }],\n role: DidDocumentRole.Received,\n })\n }\n\n public findCreatedDid(agentContext: AgentContext, createdDid: string) {\n return this.findSingleByQuery(agentContext, {\n $or: [{ alternativeDids: [createdDid] }, { did: createdDid }],\n role: DidDocumentRole.Created,\n })\n }\n\n public getCreatedDids(agentContext: AgentContext, { method, did }: { method?: string; did?: string }) {\n return this.findByQuery(agentContext, {\n role: DidDocumentRole.Created,\n method,\n $or: did ? [{ alternativeDids: [did] }, { did }] : undefined,\n })\n }\n\n public async storeCreatedDid(\n agentContext: AgentContext,\n { did, didDocument, tags, keys }: StoreDidOptions & { keys?: DidDocumentKey[] }\n ) {\n const didRecord = new DidRecord({\n did,\n didDocument,\n role: DidDocumentRole.Created,\n tags,\n keys,\n })\n\n await this.save(agentContext, didRecord)\n\n return didRecord\n }\n\n public async storeReceivedDid(agentContext: AgentContext, { did, didDocument, tags }: StoreDidOptions) {\n const didRecord = new DidRecord({\n did,\n didDocument,\n role: DidDocumentRole.Received,\n tags,\n })\n\n await this.save(agentContext, didRecord)\n\n return didRecord\n }\n}\n\ninterface StoreDidOptions {\n did: string\n didDocument?: DidDocument\n tags?: CustomDidTags\n keys?: DidDocumentKey[]\n}\n"],"mappings":";;;;;;;;;;;AAcO,IAAM,gBAAN,MAAM,sBAAsB,WAAsB;CACvD,YACE,gBACA,cACA;EACA,MAAM,WAAW,gBAAgB,YAAY;CAC/C;;;;;CAMA,8BAAqC,cAA4B,cAAyB;EACxF,OAAO,KAAK,kBAAkB,cAAc;GAC1C,0BAA0B,CAAC,aAAa,WAAW;GAC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