{"version":3,"file":"OpenId4VcIssuerRecord.mjs","names":[],"sources":["../../../src/openid4vc-issuer/repository/OpenId4VcIssuerRecord.ts"],"sourcesContent":["import { BaseRecord, CredoError, isJsonObject, Kms, type RecordTags, type TagsBase, utils } from '@credo-ts/core'\nimport { credentialsSupportedToCredentialConfigurationsSupported } from '@openid4vc/openid4vci'\nimport { Transform, TransformationType } from 'class-transformer'\nimport type {\n  OpenId4VciAuthorizationServerConfig,\n  OpenId4VciCredentialConfigurationsSupportedWithFormats,\n  OpenId4VciCredentialIssuerMetadataDisplay,\n  OpenId4VcJwtIssuerEncoded,\n} from '../../shared'\nimport type { OpenId4VciBatchCredentialIssuanceOptions } from '../OpenId4VcIssuerServiceOptions'\n\nexport type OpenId4VcIssuerRecordTags = RecordTags<OpenId4VcIssuerRecord>\n\nexport type DefaultOpenId4VcIssuerRecordTags = {\n  issuerId: string\n}\n\nexport type OpenId4VcIssuerRecordSignedMetadata = {\n  signer: OpenId4VcJwtIssuerEncoded\n\n  /**\n   * The credential issuer metadata as a signed JWT\n   */\n  jwt: string\n}\n\nexport type OpenId4VcIssuerRecordProps = {\n  id?: string\n  createdAt?: Date\n  tags?: TagsBase\n\n  issuerId: string\n\n  /**\n   * The public jwk of the key used to sign access tokens for this issuer. Must include a `kid` parameter.\n   */\n  accessTokenPublicJwk: Kms.KmsJwkPublicAsymmetric\n\n  /**\n   * The DPoP signing algorithms supported by this issuer.\n   * If not provided, dPoP is considered unsupported.\n   */\n  dpopSigningAlgValuesSupported?: [Kms.KnownJwaSignatureAlgorithm, ...Kms.KnownJwaSignatureAlgorithm[]]\n\n  display?: OpenId4VciCredentialIssuerMetadataDisplay[]\n  authorizationServerConfigs?: OpenId4VciAuthorizationServerConfig[]\n\n  credentialConfigurationsSupported: OpenId4VciCredentialConfigurationsSupportedWithFormats\n\n  /**\n   * Indicate support for batch issuance of credentials\n   */\n  batchCredentialIssuance?: OpenId4VciBatchCredentialIssuanceOptions\n\n  /**\n   * When signed metadata is supported, this stores the\n   * signed jwt and signer information to update the JWT in the future.\n   */\n  signedMetadata?: OpenId4VcIssuerRecordSignedMetadata\n}\n\n/**\n * For OID4VC you need to expose metadata files. Each issuer needs to host this metadata. This is not the case for DIDComm where we can just have one /didcomm endpoint.\n * So we create a record per openid issuer/verifier that you want, and each tenant can create multiple issuers/verifiers which have different endpoints\n * and metadata files\n * */\nexport class OpenId4VcIssuerRecord extends BaseRecord<DefaultOpenId4VcIssuerRecordTags> {\n  public static readonly type = 'OpenId4VcIssuerRecord'\n  public readonly type = OpenId4VcIssuerRecord.type\n\n  public issuerId!: string\n\n  /**\n   * @deprecated accessTokenPublicJwk should be used\n   * @todo remove in migration\n   */\n  public accessTokenPublicKeyFingerprint?: string\n  public accessTokenPublicJwk?: Kms.KmsJwkPublicAsymmetric\n\n  /**\n   * Only here for class transformation. If credentialsSupported is set we transform\n   * it to the new credentialConfigurationsSupported format\n   */\n  // biome-ignore lint/correctness/noUnusedPrivateClassMembers: see above\n  private set credentialsSupported(credentialsSupported: Array<unknown>) {\n    if (this.credentialConfigurationsSupported) return\n\n    this.credentialConfigurationsSupported =\n      // biome-ignore lint/suspicious/noExplicitAny: no explanation\n      credentialsSupportedToCredentialConfigurationsSupported(credentialsSupported as any) as any\n  }\n\n  public credentialConfigurationsSupported!: OpenId4VciCredentialConfigurationsSupportedWithFormats\n\n  // Draft 11 to draft 13+ syntax\n  @Transform(({ type, value }) => {\n    if (type === TransformationType.PLAIN_TO_CLASS && Array.isArray(value)) {\n      return value.map((display) => {\n        if (display.logo?.uri) return display\n\n        const { url, ...logoRest } = display.logo ?? {}\n        return {\n          ...display,\n          logo: url\n            ? {\n                ...logoRest,\n                uri: url,\n              }\n            : undefined,\n        }\n      })\n    }\n\n    return value\n  })\n  public display?: OpenId4VciCredentialIssuerMetadataDisplay[]\n\n  // Adds the type field if missing (for older records)\n  @Transform(({ type, value }) => {\n    if (type === TransformationType.PLAIN_TO_CLASS && Array.isArray(value)) {\n      return value.map((config) => {\n        if (isJsonObject(config) && typeof config.type === 'undefined') {\n          return {\n            ...config,\n            type: 'direct',\n          }\n        }\n\n        return config\n      })\n    }\n\n    return value\n  })\n  public authorizationServerConfigs?: OpenId4VciAuthorizationServerConfig[]\n\n  public dpopSigningAlgValuesSupported?: [Kms.KnownJwaSignatureAlgorithm, ...Kms.KnownJwaSignatureAlgorithm[]]\n  public batchCredentialIssuance?: OpenId4VciBatchCredentialIssuanceOptions\n\n  public signedMetadata?: OpenId4VcIssuerRecordSignedMetadata\n\n  public get directAuthorizationServerConfigs() {\n    return this.authorizationServerConfigs?.filter((config) => config.type === 'direct')\n  }\n\n  public get chainedAuthorizationServerConfigs() {\n    return this.authorizationServerConfigs?.filter((config) => config.type === 'chained')\n  }\n\n  public get resolvedAccessTokenPublicJwk() {\n    if (this.accessTokenPublicJwk) {\n      return Kms.PublicJwk.fromPublicJwk(this.accessTokenPublicJwk)\n    }\n\n    // From before we introduced key ids, uses legacy key id\n    if (this.accessTokenPublicKeyFingerprint) {\n      const publicJwk = Kms.PublicJwk.fromFingerprint(this.accessTokenPublicKeyFingerprint)\n      publicJwk.keyId = publicJwk.legacyKeyId\n      return publicJwk\n    }\n\n    throw new CredoError(\n      'Neither accessTokenPublicJwk or accessTokenPublicKeyFingerprint defined. Unable to resolve access token public jwk.'\n    )\n  }\n\n  public constructor(props: OpenId4VcIssuerRecordProps) {\n    super()\n\n    if (props) {\n      this.id = props.id ?? utils.uuid()\n      this.createdAt = props.createdAt ?? new Date()\n      this._tags = props.tags ?? {}\n\n      this.issuerId = props.issuerId\n      this.accessTokenPublicJwk = props.accessTokenPublicJwk\n      this.credentialConfigurationsSupported = props.credentialConfigurationsSupported\n      this.dpopSigningAlgValuesSupported = props.dpopSigningAlgValuesSupported\n      this.display = props.display\n      this.authorizationServerConfigs = props.authorizationServerConfigs\n      this.batchCredentialIssuance = props.batchCredentialIssuance\n      this.signedMetadata = props.signedMetadata\n    }\n  }\n\n  public getTags() {\n    return {\n      ...this._tags,\n      issu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