{"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,0BAAM,sBAAsB,WAAsB;CACvD,AAAO,YACL,AAAyC,gBACzC,cACA;AACA,QAAM,WAAW,gBAAgB,aAAa;;;;;;CAOhD,AAAO,8BAA8B,cAA4B,cAAyB;AACxF,SAAO,KAAK,kBAAkB,cAAc;GAC1C,0BAA0B,CAAC,aAAa,YAAY;GACpD,MAAM,gBAAgB;GACvB,CAAC;;;;;;CAOJ,AAAO,6BAA6B,cAA4B,cAAyB;AACvF,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