{"version":3,"file":"DidDocumentBuilder.mjs","names":[],"sources":["../../../../src/modules/dids/domain/DidDocumentBuilder.ts"],"sourcesContent":["import { asArray } from '../../../utils'\nimport { DidDocument } from './DidDocument'\nimport type { DidDocumentService } from './service'\nimport { VerificationMethod } from './verificationMethod'\n\nexport class DidDocumentBuilder {\n  private didDocument: DidDocument\n\n  public constructor(id: string) {\n    this.didDocument = new DidDocument({\n      id,\n    })\n  }\n\n  public addContext(context: string) {\n    const currentContexts = asArray(this.didDocument.context)\n    if (currentContexts.includes(context)) return this\n\n    this.didDocument.context = [...currentContexts, context]\n    return this\n  }\n\n  public addController(controller: string) {\n    const currentControllers = asArray(this.didDocument.controller)\n    if (currentControllers.includes(controller)) return this\n\n    this.didDocument.controller = [...currentControllers, controller]\n    return this\n  }\n\n  public addService(service: DidDocumentService) {\n    if (!this.didDocument.service) {\n      this.didDocument.service = []\n    }\n\n    this.didDocument.service.push(service)\n\n    return this\n  }\n\n  public addVerificationMethod(verificationMethod: VerificationMethod) {\n    if (!this.didDocument.verificationMethod) {\n      this.didDocument.verificationMethod = []\n    }\n\n    this.didDocument.verificationMethod.push(\n      verificationMethod instanceof VerificationMethod ? verificationMethod : new VerificationMethod(verificationMethod)\n    )\n\n    return this\n  }\n\n  public addAuthentication(authentication: string | VerificationMethod) {\n    if (!this.didDocument.authentication) {\n      this.didDocument.authentication = []\n    }\n\n    const verificationMethod =\n      authentication instanceof VerificationMethod || typeof authentication === 'string'\n        ? authentication\n        : new VerificationMethod(authentication)\n\n    this.didDocument.authentication.push(verificationMethod)\n\n    return this\n  }\n\n  public addAssertionMethod(assertionMethod: string | VerificationMethod) {\n    if (!this.didDocument.assertionMethod) {\n      this.didDocument.assertionMethod = []\n    }\n\n    const verificationMethod =\n      assertionMethod instanceof VerificationMethod || typeof assertionMethod === 'string'\n        ? assertionMethod\n        : new VerificationMethod(assertionMethod)\n\n    this.didDocument.assertionMethod.push(verificationMethod)\n\n    return this\n  }\n\n  public addCapabilityDelegation(capabilityDelegation: string | VerificationMethod) {\n    if (!this.didDocument.capabilityDelegation) {\n      this.didDocument.capabilityDelegation = []\n    }\n\n    const verificationMethod =\n      capabilityDelegation instanceof VerificationMethod || typeof capabilityDelegation === 'string'\n        ? capabilityDelegation\n        : new VerificationMethod(capabilityDelegation)\n\n    this.didDocument.capabilityDelegation.push(verificationMethod)\n\n    return this\n  }\n  public addCapabilityInvocation(capabilityInvocation: string | VerificationMethod) {\n    if (!this.didDocument.capabilityInvocation) {\n      this.didDocument.capabilityInvocation = []\n    }\n\n    const verificationMethod =\n      capabilityInvocation instanceof VerificationMethod || typeof capabilityInvocation === 'string'\n        ? capabilityInvocation\n        : new VerificationMethod(capabilityInvocation)\n\n    this.didDocument.capabilityInvocation.push(verificationMethod)\n\n    return this\n  }\n\n  public addKeyAgreement(keyAgreement: string | VerificationMethod) {\n    if (!this.didDocument.keyAgreement) {\n      this.didDocument.keyAgreement = []\n    }\n\n    const verificationMethod =\n      keyAgreement instanceof VerificationMethod || typeof keyAgreement === 'string'\n        ? keyAgreement\n        : new VerificationMethod(keyAgreement)\n\n    this.didDocument.keyAgreement.push(verificationMethod)\n\n    return this\n  }\n\n  public build(): DidDocument {\n    return this.didDocument\n  }\n}\n"],"mappings":";;;;;;;;;AAKA,IAAa,qBAAb,MAAgC;CAG9B,AAAO,YAAY,IAAY;AAC7B,OAAK,cAAc,IAAI,YAAY,EACjC,IACD,CAAC;;CAGJ,AAAO,WAAW,SAAiB;EACjC,MAAM,kBAAkB,QAAQ,KAAK,YAAY,QAAQ;AACzD,MAAI,gBAAgB,SAAS,QAAQ,CAAE,QAAO;AAE9C,OAAK,YAAY,UAAU,CAAC,GAAG,iBAAiB,QAAQ;AACxD,SAAO;;CAGT,AAAO,cAAc,YAAoB;EACvC,MAAM,qBAAqB,QAAQ,KAAK,YAAY,WAAW;AAC/D,MAAI,mBAAmB,SAAS,WAAW,CAAE,QAAO;AAEpD,OAAK,YAAY,aAAa,CAAC,GAAG,oBAAoB,WAA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