{"version":3,"file":"DidsModuleConfig.mjs","names":[],"sources":["../../../src/modules/dids/DidsModuleConfig.ts"],"sourcesContent":["import type { DidRegistrar, DidResolver } from './domain'\n\nimport {\n  JwkDidRegistrar,\n  JwkDidResolver,\n  KeyDidRegistrar,\n  KeyDidResolver,\n  PeerDidRegistrar,\n  PeerDidResolver,\n  WebDidResolver,\n} from './methods'\n\nconst DEFAULT_PUBLIC_DID_METHODS = ['web', 'indy', 'sov', 'cheqd', 'hedera', 'webvh']\n\n/**\n * DidsModuleConfigOptions defines the interface for the options of the DidsModuleConfig class.\n * This can contain optional parameters that have default values in the config class itself.\n */\nexport interface DidsModuleConfigOptions {\n  /**\n   * List of did registrars that should be used by the dids module. The registrar must\n   * be an instance of the {@link DidRegistrar} interface.\n   *\n   * If no registrars are provided, the default registrars will be used. `PeerDidRegistrar` and `KeyDidRegistrar`\n   * will ALWAYS be registered, as they are needed for connections, mediation and out of band modules to function.\n   * Other did methods can be disabled.\n   *\n   * @default [KeyDidRegistrar, PeerDidRegistrar, JwkDidRegistrar]\n   */\n  registrars?: DidRegistrar[]\n\n  /**\n   * List of did resolvers that should be used by the dids module. The resolver must\n   * be an instance of the {@link DidResolver} interface.\n   *\n   * If no resolvers are provided, the default resolvers will be used. `PeerDidResolver` and `KeyDidResolver`\n   * will ALWAYS be registered, as they are needed for connections, mediation and out of band modules to function.\n   * Other did methods can be disabled.\n   *\n   * @default [WebDidResolver, KeyDidResolver, PeerDidResolver, JwkDidResolver]\n   */\n  resolvers?: DidResolver[]\n\n  /**\n   * Did methods whose documents live in public, context-independent sources: resolving them\n   * yields the same result in any agent context, so their documents can be cached in the global\n   * scope shared across all agent contexts (when the resolver allows caching). Documents of\n   * other did methods are cached per agent context.\n   *\n   * @default ['web', 'indy', 'sov', 'cheqd', 'hedera', 'webvh']\n   */\n  publicDidMethods?: string[]\n}\n\nexport class DidsModuleConfig {\n  private options: DidsModuleConfigOptions\n  private _registrars: DidRegistrar[] | undefined\n  private _resolvers: DidResolver[] | undefined\n\n  public constructor(options?: DidsModuleConfigOptions) {\n    this.options = options ?? {}\n  }\n\n  /** See {@link DidsModuleConfigOptions.registrars} */\n  public get registrars(): DidRegistrar[] {\n    // This prevents creating new instances every time this property is accessed\n    if (this._registrars) return this._registrars\n\n    let registrars = this.options.registrars ?? [new KeyDidRegistrar(), new PeerDidRegistrar(), new JwkDidRegistrar()]\n\n    // Add peer did registrar if it is not included yet\n    if (!registrars.find((registrar) => registrar instanceof PeerDidRegistrar)) {\n      // Do not modify original options array\n      registrars = [...registrars, new PeerDidRegistrar()]\n    }\n\n    // Add key did registrar if it is not included yet\n    if (!registrars.find((registrar) => registrar instanceof KeyDidRegistrar)) {\n      // Do not modify original options array\n      registrars = [...registrars, new KeyDidRegistrar()]\n    }\n\n    this._registrars = registrars\n    return registrars\n  }\n\n  public addRegistrar(registrar: DidRegistrar) {\n    this.registrars.push(registrar)\n  }\n\n  /** See {@link DidsModuleConfigOptions.resolvers} */\n  public get resolvers(): DidResolver[] {\n    // This prevents creating new instances every time this property is accessed\n    if (this._resolvers) return this._resolvers\n\n    let resolvers = this.options.resolvers ?? [\n      new WebDidResolver(),\n      new KeyDidResolver(),\n      new PeerDidResolver(),\n      new JwkDidResolver(),\n    ]\n\n    // Add peer did resolver if it is not included yet\n    if (!resolvers.find((resolver) => resolver instanceof PeerDidResolver)) {\n      // Do not modify original options array\n      resolvers = [...resolvers, new PeerDidResolver()]\n    }\n\n    // Add key did resolver if it is not included yet\n    if (!resolvers.find((resolver) => resolver instanceof KeyDidResolver)) {\n      // Do not modify original options array\n      resolvers = [...resolvers, new KeyDidResolver()]\n    }\n\n    this._resolvers = resolvers\n    return resolvers\n  }\n\n  public addResolver(resolver: DidResolver) {\n    this.resolvers.push(resolver)\n  }\n\n  /** See {@link DidsModuleConfigOptions.publicDidMethods} */\n  public get publicDidMethods(): string[] {\n    return this.options.publicDidMethods ?? DEFAULT_PUBLIC_DID_METHODS\n  }\n}\n"],"mappings":";;;;;;;;;AA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