{"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,YAAmB,IAAY;EAC7B,KAAK,cAAc,IAAI,YAAY,EACjC,GACF,CAAC;CACH;CAEA,WAAkB,SAAiB;EACjC,MAAM,kBAAkB,QAAQ,KAAK,YAAY,OAAO;EACxD,IAAI,gBAAgB,SAAS,OAAO,GAAG,OAAO;EAE9C,KAAK,YAAY,UAAU,CAAC,GAAG,iBAAiB,OAAO;EACvD,OAAO;CACT;CAEA,cAAqB,YAAoB;EACvC,MAAM,qBAAqB,QAAQ,KAAK,YAAY,UAAU;EAC9D,IAAI,mBAAmB,SAAS,UAAU,GAAG,OAAO;EAEpD,KAAK,YAAY,aAAa,CAAC,GAAG,oBAAoB,UAAU;EAChE,OAAO;C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