@credo-ts/core 0.6.0-pr-2539-20251127092008 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/_virtual/{_@oxc-project_runtime@0.97.0 → _@oxc-project_runtime@0.99.0}/helpers/assertClassBrand.mjs +1 -1
- package/build/_virtual/{_@oxc-project_runtime@0.97.0 → _@oxc-project_runtime@0.99.0}/helpers/checkPrivateRedeclaration.mjs +1 -1
- package/build/_virtual/{_@oxc-project_runtime@0.97.0 → _@oxc-project_runtime@0.99.0}/helpers/classPrivateFieldGet2.mjs +1 -1
- package/build/_virtual/{_@oxc-project_runtime@0.97.0 → _@oxc-project_runtime@0.99.0}/helpers/classPrivateFieldInitSpec.mjs +1 -1
- package/build/_virtual/{_@oxc-project_runtime@0.97.0 → _@oxc-project_runtime@0.99.0}/helpers/classPrivateFieldSet2.mjs +1 -1
- package/build/_virtual/{_@oxc-project_runtime@0.97.0 → _@oxc-project_runtime@0.99.0}/helpers/decorate.mjs +1 -1
- package/build/_virtual/{_@oxc-project_runtime@0.97.0 → _@oxc-project_runtime@0.99.0}/helpers/decorateMetadata.mjs +1 -1
- package/build/_virtual/{_@oxc-project_runtime@0.97.0 → _@oxc-project_runtime@0.99.0}/helpers/decorateParam.mjs +1 -1
- package/build/_virtual/rolldown_runtime.mjs +10 -5
- package/build/agent/AgentModules.d.mts.map +1 -1
- package/build/agent/AgentModules.mjs.map +1 -1
- package/build/agent/EventEmitter.mjs +3 -3
- package/build/agent/context/DefaultAgentContextProvider.mjs +2 -2
- package/build/crypto/JwsService.mjs +5 -5
- package/build/crypto/JwsService.mjs.map +1 -1
- package/build/crypto/webcrypto/types.mjs +4 -4
- package/build/crypto/webcrypto/types.mjs.map +1 -1
- package/build/modules/cache/CachedStorageService.mjs +3 -3
- package/build/modules/cache/singleContextLruCache/SingleContextLruCacheRecord.mjs +2 -2
- package/build/modules/cache/singleContextLruCache/SingleContextLruCacheRepository.mjs +3 -3
- package/build/modules/dcql/DcqlService.mjs +2 -2
- package/build/modules/dcql/DcqlService.mjs.map +1 -1
- package/build/modules/dids/DidsApi.mjs +2 -2
- package/build/modules/dids/domain/DidDocument.mjs +3 -3
- package/build/modules/dids/domain/DidDocument.mjs.map +1 -1
- package/build/modules/dids/domain/key-type/keyDidMapping.mjs +1 -1
- package/build/modules/dids/domain/key-type/keyDidMapping.mjs.map +1 -1
- package/build/modules/dids/domain/service/DidCommV1Service.mjs +2 -2
- package/build/modules/dids/domain/service/DidCommV2Service.mjs +2 -2
- package/build/modules/dids/domain/service/DidDocumentService.mjs +2 -2
- package/build/modules/dids/domain/service/IndyAgentService.mjs +2 -2
- package/build/modules/dids/domain/service/LegacyDidCommV2Service.mjs +2 -2
- package/build/modules/dids/domain/verificationMethod/VerificationMethod.mjs +2 -2
- package/build/modules/dids/findMatchingEd25519Key.mjs +2 -2
- package/build/modules/dids/findMatchingEd25519Key.mjs.map +1 -1
- package/build/modules/dids/helpers.mjs +1 -1
- package/build/modules/dids/helpers.mjs.map +1 -1
- package/build/modules/dids/repository/DidRecord.mjs +2 -2
- package/build/modules/dids/repository/DidRepository.mjs +3 -3
- package/build/modules/dids/services/DidRegistrarService.mjs +3 -3
- package/build/modules/dids/services/DidResolverService.mjs +3 -3
- package/build/modules/dids/types.d.mts +1 -1
- package/build/modules/dif-presentation-exchange/DifPresentationExchangeService.mjs +2 -2
- package/build/modules/generic-records/GenericRecordsApi.mjs +3 -3
- package/build/modules/generic-records/repository/GenericRecordsRepository.mjs +3 -3
- package/build/modules/generic-records/services/GenericRecordService.mjs +2 -2
- package/build/modules/kms/KeyManagementApi.mjs +2 -2
- package/build/modules/kms/KeyManagementModuleConfig.mjs +3 -3
- package/build/modules/kms/index.d.mts +2 -2
- package/build/modules/kms/index.mjs +2 -2
- package/build/modules/kms/jwk/PublicJwk.d.mts +2 -2
- package/build/modules/kms/jwk/PublicJwk.mjs +4 -4
- package/build/modules/kms/jwk/PublicJwk.mjs.map +1 -1
- package/build/modules/kms/jwk/equals.d.mts +2 -2
- package/build/modules/kms/jwk/equals.mjs +2 -2
- package/build/modules/kms/jwk/equals.mjs.map +1 -1
- package/build/modules/kms/jwk/index.d.mts +1 -1
- package/build/modules/kms/jwk/index.mjs +1 -1
- package/build/modules/mdoc/Mdoc.mjs +4 -4
- package/build/modules/mdoc/Mdoc.mjs.map +1 -1
- package/build/modules/mdoc/MdocApi.mjs +2 -2
- package/build/modules/mdoc/MdocDeviceResponse.mjs +1 -1
- package/build/modules/mdoc/MdocDeviceResponse.mjs.map +1 -1
- package/build/modules/mdoc/MdocService.mjs +2 -2
- package/build/modules/mdoc/repository/MdocRepository.mjs +3 -3
- package/build/modules/sd-jwt-vc/SdJwtVcApi.mjs +2 -2
- package/build/modules/sd-jwt-vc/SdJwtVcOptions.d.mts +10 -5
- package/build/modules/sd-jwt-vc/SdJwtVcOptions.d.mts.map +1 -1
- package/build/modules/sd-jwt-vc/SdJwtVcService.d.mts.map +1 -1
- package/build/modules/sd-jwt-vc/SdJwtVcService.mjs +8 -8
- package/build/modules/sd-jwt-vc/SdJwtVcService.mjs.map +1 -1
- package/build/modules/sd-jwt-vc/repository/SdJwtVcRepository.mjs +3 -3
- package/build/modules/sd-jwt-vc/typeMetadata.d.mts +17 -2
- package/build/modules/sd-jwt-vc/typeMetadata.d.mts.map +1 -1
- package/build/modules/sd-jwt-vc/utils.mjs +1 -1
- package/build/modules/sd-jwt-vc/utils.mjs.map +1 -1
- package/build/modules/vc/W3cCredentialService.mjs +2 -2
- package/build/modules/vc/W3cCredentialsApi.mjs +2 -2
- package/build/modules/vc/W3cV2CredentialService.mjs +2 -2
- package/build/modules/vc/W3cV2CredentialsApi.mjs +2 -2
- package/build/modules/vc/data-integrity/SignatureSuiteRegistry.mjs +3 -3
- package/build/modules/vc/data-integrity/W3cJsonLdCredentialService.mjs +2 -2
- package/build/modules/vc/data-integrity/models/DataIntegrityProof.mjs +2 -2
- package/build/modules/vc/data-integrity/models/LinkedDataProof.mjs +2 -2
- package/build/modules/vc/data-integrity/models/W3cJsonLdVerifiableCredential.mjs +2 -2
- package/build/modules/vc/data-integrity/models/W3cJsonLdVerifiablePresentation.mjs +2 -2
- package/build/modules/vc/jwt-vc/W3cJwtCredentialService.mjs +2 -2
- package/build/modules/vc/jwt-vc/W3cV2JwtCredentialService.mjs +2 -2
- package/build/modules/vc/models/credential/W3cCredential.mjs +2 -2
- package/build/modules/vc/models/credential/W3cCredentialSchema.mjs +2 -2
- package/build/modules/vc/models/credential/W3cCredentialStatus.mjs +2 -2
- package/build/modules/vc/models/credential/W3cCredentialSubject.mjs +2 -2
- package/build/modules/vc/models/credential/W3cIssuer.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2Credential.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2CredentialSchema.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2CredentialStatus.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2CredentialSubject.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2EnvelopedVerifiableCredential.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2Evidence.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2Issuer.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2LocalizedValue.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2RefreshService.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2TermsOfUse.mjs +2 -2
- package/build/modules/vc/models/presentation/W3cHolder.mjs +2 -2
- package/build/modules/vc/models/presentation/W3cPresentation.mjs +2 -2
- package/build/modules/vc/models/presentation/W3cV2EnvelopedVerifiablePresentation.mjs +2 -2
- package/build/modules/vc/models/presentation/W3cV2Holder.mjs +2 -2
- package/build/modules/vc/models/presentation/W3cV2Presentation.mjs +2 -2
- package/build/modules/vc/repository/W3cCredentialRepository.mjs +3 -3
- package/build/modules/vc/repository/W3cV2CredentialRepository.mjs +3 -3
- package/build/modules/vc/sd-jwt-vc/W3cV2SdJwtCredentialService.mjs +1 -1
- package/build/modules/x509/X509Api.mjs +2 -2
- package/build/modules/x509/X509Certificate.mjs +2 -2
- package/build/modules/x509/X509Certificate.mjs.map +1 -1
- package/build/modules/x509/X509ModuleConfig.mjs +3 -3
- package/build/modules/x509/X509Service.mjs +1 -1
- package/build/storage/BaseRecord.mjs +2 -2
- package/build/storage/StorageService.d.mts.map +1 -1
- package/build/storage/migration/StorageUpdateService.mjs +3 -3
- package/build/storage/migration/repository/StorageVersionRepository.mjs +3 -3
- package/build/utils/MessageValidator.mjs +1 -1
- package/build/utils/MessageValidator.mjs.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DcqlService.mjs","names":["DcqlService","allRecords: Array<SdJwtVcRecord | W3cCredentialRecord | W3cV2CredentialRecord | MdocRecord>","credentialRecordsWithFormatDuplicates: typeof credentialRecords","dcqlCredentials: DcqlCredential[]","credentials: DcqlCredentialsForRequest","match","dcqlPresentation: DcqlPresentation","encodedDcqlPresentation: DcqlEncodedPresentations","getDcqlVcPresentationsToCreate","createdPresentation: VerifiablePresentation","encodedCreatedPresentation: string | Record<string, unknown>","key"],"sources":["../../../src/modules/dcql/DcqlService.ts"],"sourcesContent":["import {\n DcqlCredential,\n DcqlCredentialQuery,\n DcqlMdocCredential,\n DcqlPresentationResult,\n DcqlQuery,\n DcqlSdJwtVcCredential,\n DcqlW3cVcCredential,\n} from 'dcql'\nimport { injectable } from 'tsyringe'\nimport type { AgentContext } from '../../agent'\nimport { isNonEmptyArray, type JsonObject, type JsonValue, mapNonEmptyArray } from '../../types'\nimport { asArray, TypedArrayEncoder } from '../../utils'\nimport {\n CredentialMultiInstanceUseMode,\n canUseInstanceFromCredentialRecord,\n useInstanceFromCredentialRecord,\n} from '../../utils/credentialUse'\nimport { DidsApi, getPublicJwkFromVerificationMethod, VerificationMethod } from '../dids'\nimport type { VerifiablePresentation } from '../dif-presentation-exchange/index'\nimport {\n MdocApi,\n MdocDeviceResponse,\n type MdocNameSpaces,\n MdocRecord,\n type MdocSessionTranscriptOptions,\n} from '../mdoc'\nimport { SdJwtVcApi, SdJwtVcRecord, SdJwtVcService } from '../sd-jwt-vc'\nimport { buildDisclosureFrameForPayload } from '../sd-jwt-vc/disclosureFrame'\nimport {\n ClaimFormat,\n SignatureSuiteRegistry,\n W3cCredentialRecord,\n W3cCredentialRepository,\n W3cCredentialService,\n W3cJsonLdCredentialService,\n W3cJsonLdVerifiableCredential,\n W3cPresentation,\n W3cV2CredentialRecord,\n W3cV2CredentialRepository,\n W3cV2CredentialService,\n W3cV2EnvelopedVerifiableCredential,\n W3cV2Presentation,\n} from '../vc'\nimport { purposes } from '../vc/data-integrity/libraries/jsonld-signatures'\nimport { W3cV2SdJwtCredentialService, W3cV2SdJwtVerifiableCredential } from '../vc/sd-jwt-vc'\nimport { X509Certificate } from '../x509'\nimport { DcqlError } from './DcqlError'\nimport type {\n DcqlCredentialsForRequest,\n DcqlEncodedPresentations,\n DcqlFailedCredential,\n DcqlPresentation,\n DcqlQueryResult,\n DcqlValidCredential,\n} from './models'\nimport { dcqlGetPresentationsToCreate as getDcqlVcPresentationsToCreate } from './utils'\n\nexport interface DcqlSelectCredentialsForRequestOptions {\n /**\n * The usage mode to apply to the credentials when selecting credentials.\n *\n * If and usage mode is selected that require a new instance to be used, and there's no\n * new instances available, an error will be thrown.\n *\n * It does not actually select the credential from the record yet, it just filters\n * out records that don't match the filter.\n */\n useMode?: CredentialMultiInstanceUseMode\n}\n\n@injectable()\nexport class DcqlService {\n /**\n * Queries the wallet for credentials that match the given dcql query. This only does an initial query based on the\n * schema of the input descriptors. It does not do any further filtering based on the constraints in the input descriptors.\n */\n private async queryCredentialsForDcqlQuery(\n agentContext: AgentContext,\n dcqlQuery: DcqlQuery\n ): Promise<Array<SdJwtVcRecord | W3cCredentialRecord | W3cV2CredentialRecord | MdocRecord>> {\n const formats = new Set(dcqlQuery.credentials.map((c) => c.format))\n const allRecords: Array<SdJwtVcRecord | W3cCredentialRecord | W3cV2CredentialRecord | MdocRecord> = []\n\n const mdocDoctypes = dcqlQuery.credentials\n .filter((credentialQuery) => credentialQuery.format === 'mso_mdoc')\n .map((c) => c.meta?.doctype_value)\n\n const mdocApi = this.getMdocApi(agentContext)\n if (mdocDoctypes.every((doctype) => doctype !== undefined)) {\n const mdocRecords = await mdocApi.findAllByQuery({\n $or: mdocDoctypes.map((docType) => ({\n docType: docType,\n })),\n })\n allRecords.push(...mdocRecords)\n } else if (formats.has('mso_mdoc')) {\n const mdocRecords = await mdocApi.getAll()\n allRecords.push(...mdocRecords)\n }\n\n const sdJwts = dcqlQuery.credentials.filter(\n (credentialQuery): credentialQuery is DcqlCredentialQuery.SdJwtVc =>\n (credentialQuery.format === 'vc+sd-jwt' && !(credentialQuery.meta && 'type_values' in credentialQuery.meta)) ||\n credentialQuery.format === 'dc+sd-jwt'\n )\n\n const sdJwtVctValues = sdJwts.flatMap((c) => c.meta?.vct_values)\n\n const sdJwtVcApi = this.getSdJwtVcApi(agentContext)\n if (sdJwtVctValues.every((vct) => vct !== undefined)) {\n const sdjwtVcRecords = await sdJwtVcApi.findAllByQuery({\n $or: sdJwtVctValues.map((vct) => ({\n vct: vct as string,\n })),\n })\n allRecords.push(...sdjwtVcRecords)\n } else if (sdJwts.length > 0) {\n const sdJwtVcRecords = await sdJwtVcApi.getAll()\n allRecords.push(...sdJwtVcRecords)\n }\n\n const w3cCredentialRepository = agentContext.dependencyManager.resolve(W3cCredentialRepository)\n if (formats.has('jwt_vc_json')) {\n const w3cRecords = await w3cCredentialRepository.findByQuery(agentContext, {\n claimFormat: ClaimFormat.JwtVc,\n\n // For jwt_vc_json we query the non-exapnded types\n $or: dcqlQuery.credentials\n .flatMap((c) => (c.format === 'jwt_vc_json' ? c.meta.type_values : []))\n .map((typeValues) => ({\n types: typeValues,\n })),\n })\n allRecords.push(...w3cRecords)\n }\n\n if (formats.has('ldp_vc')) {\n const w3cRecords = await w3cCredentialRepository.findByQuery(agentContext, {\n claimFormat: ClaimFormat.LdpVc,\n\n // For LDP_VC we query the expanded types\n $or: dcqlQuery.credentials\n .flatMap((c) => (c.format === 'jwt_vc_json' ? c.meta.type_values : []))\n .map((typeValues) => ({\n expandedTypes: typeValues,\n })),\n })\n allRecords.push(...w3cRecords)\n }\n\n const w3cSdJwts = dcqlQuery.credentials.filter(\n (credentialQuery): credentialQuery is DcqlCredentialQuery.W3cVc & { format: 'vc+sd-jwt' } =>\n credentialQuery.format === 'vc+sd-jwt' && !!credentialQuery.meta && 'type_values' in credentialQuery.meta\n )\n\n if (w3cSdJwts.length > 0) {\n const w3cV2CredentialRepository = agentContext.dependencyManager.resolve(W3cV2CredentialRepository)\n\n const w3cV2Records = await w3cV2CredentialRepository.findByQuery(agentContext, {\n claimFormat: ClaimFormat.SdJwtW3cVc,\n $or: dcqlQuery.credentials\n .flatMap((c) => (c.format === 'vc+sd-jwt' && c.meta && 'type_values' in c.meta ? c.meta.type_values : []))\n .map((typeValues) => ({\n types: typeValues,\n })),\n })\n\n allRecords.push(...w3cV2Records)\n }\n\n return allRecords\n }\n\n public async getDcqlCredentialRepresentation(\n agentContext: AgentContext,\n presentation: VerifiablePresentation,\n queryCredential: DcqlQuery['credentials'][number]\n ): Promise<DcqlCredential> {\n // SD-JWT credential can be used as both dc+sd-jwt and vc+sd-jwt\n // At some point we might want to look at the header value of the sd-jwt (vc+sd-jwt vc dc+sd-jwt)\n if (presentation.claimFormat === ClaimFormat.SdJwtDc) {\n return {\n cryptographic_holder_binding: true,\n credential_format: queryCredential.format === 'dc+sd-jwt' ? 'dc+sd-jwt' : 'vc+sd-jwt',\n vct: presentation.prettyClaims.vct as string,\n claims: presentation.prettyClaims as DcqlSdJwtVcCredential.Claims,\n } satisfies DcqlSdJwtVcCredential\n }\n if (presentation.claimFormat === ClaimFormat.MsoMdoc) {\n if (presentation.documents.length !== 1) {\n throw new DcqlError('MDOC presentations must contain exactly one document')\n }\n return {\n cryptographic_holder_binding: true,\n credential_format: 'mso_mdoc',\n doctype: presentation.documents[0].docType,\n namespaces: presentation.documents[0].issuerSignedNamespaces,\n } satisfies DcqlMdocCredential\n }\n if (presentation.claimFormat === ClaimFormat.JwtVp) {\n const vc = Array.isArray(presentation.verifiableCredential)\n ? presentation.verifiableCredential[0].jsonCredential\n : presentation.verifiableCredential\n\n return {\n cryptographic_holder_binding: true,\n credential_format: 'jwt_vc_json',\n claims: vc.jsonCredential as { [key: string]: JsonValue },\n type: vc.type,\n } satisfies DcqlW3cVcCredential\n }\n if (presentation.claimFormat === ClaimFormat.LdpVp) {\n const vc = Array.isArray(presentation.verifiableCredential)\n ? (presentation.verifiableCredential[0] as W3cJsonLdVerifiableCredential)\n : (presentation.verifiableCredential as W3cJsonLdVerifiableCredential)\n\n const w3cJsonLdCredentialService = agentContext.dependencyManager.resolve(W3cJsonLdCredentialService)\n const expandedTypes = await w3cJsonLdCredentialService.getExpandedTypesForCredential(agentContext, vc)\n\n return {\n cryptographic_holder_binding: true,\n credential_format: 'ldp_vc',\n claims: vc.jsonCredential as DcqlW3cVcCredential.Claims,\n type: expandedTypes,\n } satisfies DcqlW3cVcCredential\n }\n if (presentation.claimFormat === ClaimFormat.SdJwtW3cVp) {\n const vc = Array.isArray(presentation.resolvedPresentation.verifiableCredential)\n ? presentation.resolvedPresentation.verifiableCredential[0].resolvedCredential\n : presentation.resolvedPresentation.verifiableCredential.resolvedCredential\n\n return {\n cryptographic_holder_binding: true,\n credential_format: 'vc+sd-jwt',\n type: asArray(vc.type),\n claims: vc.toJSON() as { [key: string]: JsonValue },\n } satisfies DcqlW3cVcCredential\n }\n\n throw new DcqlError('Unsupported claim format for presentation')\n }\n\n public async getCredentialsForRequest(agentContext: AgentContext, dcqlQuery: DcqlQuery): Promise<DcqlQueryResult> {\n const credentialRecords = await this.queryCredentialsForDcqlQuery(agentContext, dcqlQuery)\n const credentialRecordsWithFormatDuplicates: typeof credentialRecords = []\n const parsedQuery = DcqlQuery.parse(dcqlQuery)\n\n const dcqlCredentials: DcqlCredential[] = credentialRecords.flatMap((record): DcqlCredential | DcqlCredential[] => {\n if (record.type === 'MdocRecord') {\n credentialRecordsWithFormatDuplicates.push(record)\n\n // We always extract the first mdoc for querying\n const mdoc = record.firstCredential\n\n const akiValues = mdoc.issuerSignedCertificateChain\n .map((c) => {\n const akiHex = X509Certificate.fromRawCertificate(c).authorityKeyIdentifier\n return akiHex ? TypedArrayEncoder.toBase64URL(TypedArrayEncoder.fromHex(akiHex)) : undefined\n })\n .filter((aki) => aki !== undefined)\n\n return {\n authority: isNonEmptyArray(akiValues)\n ? {\n type: 'aki',\n values: akiValues,\n }\n : undefined,\n credential_format: 'mso_mdoc',\n doctype: mdoc.docType,\n namespaces: mdoc.issuerSignedNamespaces,\n cryptographic_holder_binding: true,\n } satisfies DcqlCredential\n }\n\n if (record.type === 'SdJwtVcRecord') {\n const sdJwtVc = record.firstCredential\n const claims = sdJwtVc.prettyClaims as DcqlSdJwtVcCredential.Claims\n\n const akiValues = (sdJwtVc.header.x5c as string[] | undefined)\n ?.map((c) => {\n const akiHex = X509Certificate.fromEncodedCertificate(c).authorityKeyIdentifier\n return akiHex ? TypedArrayEncoder.toBase64URL(TypedArrayEncoder.fromHex(akiHex)) : undefined\n })\n .filter((aki) => aki !== undefined)\n\n const authority =\n akiValues && isNonEmptyArray(akiValues)\n ? ({\n type: 'aki',\n values: akiValues,\n } as const)\n : undefined\n\n // To keep correct mapping of input credential index, we add it twice here (for dc+sd-jwt and vc+sd-jwt)\n credentialRecordsWithFormatDuplicates.push(record, record)\n return [\n {\n authority,\n credential_format: 'dc+sd-jwt',\n vct: record.getTags().vct,\n claims,\n cryptographic_holder_binding: true,\n } satisfies DcqlSdJwtVcCredential,\n {\n authority,\n credential_format: 'vc+sd-jwt',\n vct: record.getTags().vct,\n claims,\n cryptographic_holder_binding: true,\n } satisfies DcqlSdJwtVcCredential,\n ] satisfies [DcqlSdJwtVcCredential, DcqlSdJwtVcCredential]\n }\n\n if (record.type === 'W3cCredentialRecord') {\n const firstCredential = record.firstCredential\n credentialRecordsWithFormatDuplicates.push(record)\n if (firstCredential.claimFormat === ClaimFormat.LdpVc) {\n return {\n credential_format: 'ldp_vc',\n type: record.getTags().expandedTypes ?? [],\n claims: firstCredential.jsonCredential as DcqlW3cVcCredential.Claims,\n cryptographic_holder_binding: true,\n } satisfies DcqlW3cVcCredential\n }\n\n return {\n credential_format: 'jwt_vc_json',\n type: firstCredential.type,\n claims: firstCredential.jsonCredential as DcqlW3cVcCredential.Claims,\n cryptographic_holder_binding: true,\n } satisfies DcqlW3cVcCredential\n }\n\n if (record.type === 'W3cV2CredentialRecord') {\n credentialRecordsWithFormatDuplicates.push(record)\n const firstCredential = record.firstCredential\n\n return {\n credential_format: 'vc+sd-jwt',\n type: asArray(firstCredential.resolvedCredential.type),\n claims: firstCredential.resolvedCredential.toJSON() as DcqlW3cVcCredential.Claims,\n cryptographic_holder_binding: true,\n } satisfies DcqlW3cVcCredential\n }\n\n throw new DcqlError('Unsupported record type')\n })\n\n const queryResult = DcqlQuery.query(parsedQuery, dcqlCredentials)\n\n const matchesWithRecord = Object.fromEntries(\n Object.entries(queryResult.credential_matches).map(([credential_query_id, result]) => {\n const failedCredentials = result.failed_credentials\n ? mapNonEmptyArray(result.failed_credentials, (credential) => {\n const record = credentialRecordsWithFormatDuplicates[credential.input_credential_index]\n const updatedCredential: DcqlFailedCredential = {\n ...credential,\n record,\n claims: credential.claims.success\n ? {\n ...credential.claims,\n success: true,\n valid_claim_sets: mapNonEmptyArray(credential.claims.valid_claim_sets, (claimSet) => ({\n ...claimSet,\n ...(record.type === 'SdJwtVcRecord'\n ? // NOTE: we cast from SdJwtVcPayload (which is Record<string, unknown> to { [key: string]: JsonValue })\n // Otherwise TypeScript explains, but I'm not sure why Record<string, unknown> wouldn't be applicable to { [key: string]: JsonValue }\n {\n output: agentContext.dependencyManager\n .resolve(SdJwtVcService)\n .applyDisclosuresForPayload(record.encoded, claimSet.output as JsonObject)\n .prettyClaims as { [key: string]: JsonValue },\n }\n : record.type === 'W3cV2CredentialRecord' &&\n record.firstCredential instanceof W3cV2SdJwtVerifiableCredential\n ? {\n output: agentContext.dependencyManager\n .resolve(SdJwtVcService)\n .applyDisclosuresForPayload(\n record.firstCredential.encoded,\n claimSet.output as JsonObject\n ).prettyClaims as { [key: string]: JsonValue },\n }\n : {}),\n })),\n }\n : credential.claims,\n }\n return updatedCredential\n })\n : undefined\n\n // If not success, valid_credentials will be undefined, so we only have to map failed_credentials\n if (!result.success) {\n return [\n credential_query_id,\n {\n ...result,\n failed_credentials: failedCredentials,\n },\n ]\n }\n\n return [\n credential_query_id,\n {\n ...result,\n failed_credentials: failedCredentials,\n valid_credentials: mapNonEmptyArray(result.valid_credentials, (credential) => {\n const record = credentialRecordsWithFormatDuplicates[credential.input_credential_index]\n const updatedCredential: DcqlValidCredential = {\n ...credential,\n record,\n claims: {\n ...credential.claims,\n valid_claim_sets: mapNonEmptyArray(credential.claims.valid_claim_sets, (claimSet) => ({\n ...claimSet,\n ...(record.type === 'SdJwtVcRecord'\n ? // NOTE: we cast from SdJwtVcPayload (which is Record<string, unknown> to { [key: string]: JsonValue })\n // Otherwise TypeScript explains, but I'm not sure why Record<string, unknown> wouldn't be applicable to { [key: string]: JsonValue }\n {\n output: agentContext.dependencyManager\n .resolve(SdJwtVcService)\n .applyDisclosuresForPayload(record.encoded, claimSet.output as JsonObject).prettyClaims as {\n [key: string]: JsonValue\n },\n }\n : record.type === 'W3cV2CredentialRecord' &&\n record.firstCredential instanceof W3cV2SdJwtVerifiableCredential\n ? {\n output: agentContext.dependencyManager\n .resolve(SdJwtVcService)\n .applyDisclosuresForPayload(record.firstCredential.encoded, claimSet.output as JsonObject)\n .prettyClaims as { [key: string]: JsonValue },\n }\n : {}),\n })),\n },\n }\n return updatedCredential\n }),\n },\n ]\n })\n )\n\n return {\n ...queryResult,\n credential_matches: matchesWithRecord,\n }\n }\n\n public async assertValidDcqlPresentation(\n agentContext: AgentContext,\n dcqlPresentation: DcqlPresentation,\n dcqlQuery: DcqlQuery\n ) {\n const internalDcqlPresentation = Object.fromEntries(\n await Promise.all(\n Object.entries(dcqlPresentation).map(async ([credentialId, presentations]) => {\n const queryCredential = dcqlQuery.credentials.find((c) => c.id === credentialId)\n if (!queryCredential) {\n throw new DcqlError(\n `DCQL presentation contains presentation entry for credential id '${credentialId}', but this id is not present in the DCQL query`\n )\n }\n\n return [\n credentialId,\n await Promise.all(\n presentations.map((presentation) =>\n this.getDcqlCredentialRepresentation(agentContext, presentation, queryCredential)\n )\n ),\n ]\n })\n )\n )\n\n const presentationResult = DcqlPresentationResult.fromDcqlPresentation(internalDcqlPresentation, { dcqlQuery })\n\n if (!presentationResult.can_be_satisfied) {\n throw new DcqlError('Presentations do not satisfy the DCQL query.', {\n additionalMessages: Object.entries(presentationResult.credential_matches ?? {})\n .flatMap(([queryId, match]) =>\n match.success\n ? undefined\n : !match.failed_credentials\n ? `Unable to match query credential '${queryId}'. No prsentations provided`\n : match.failed_credentials.map(\n (failedCredential) =>\n `Presentation at index ${failedCredential.input_credential_index} does not match query credential '${queryId}'. ${JSON.stringify(\n {\n ...(failedCredential.claims.success\n ? {}\n : { claims: failedCredential.claims.failed_claim_sets.map((cs) => cs.issues) }),\n ...(failedCredential.trusted_authorities.success\n ? {}\n : {\n trusted_authorities:\n failedCredential.trusted_authorities.failed_trusted_authorities.map(\n (ta) => ta.issues\n ),\n }),\n ...(failedCredential.meta.success ? {} : { meta: failedCredential.meta.issues }),\n },\n null,\n 2\n )}`\n )\n )\n .filter((message) => message !== undefined),\n })\n }\n\n return presentationResult\n }\n\n private dcqlCredentialForRequestForValidCredential(validCredential: DcqlValidCredential) {\n if (validCredential.record.type === 'MdocRecord') {\n return {\n claimFormat: ClaimFormat.MsoMdoc,\n credentialRecord: validCredential.record,\n disclosedPayload: validCredential.claims.valid_claim_sets[0].output as MdocNameSpaces,\n } as const\n }\n if (validCredential.record.type === 'SdJwtVcRecord') {\n return {\n claimFormat: ClaimFormat.SdJwtDc,\n credentialRecord: validCredential.record,\n disclosedPayload: validCredential.claims.valid_claim_sets[0].output as JsonObject,\n } as const\n }\n\n if (validCredential.record.type === 'W3cCredentialRecord') {\n return {\n claimFormat: validCredential.record.firstCredential.claimFormat,\n credentialRecord: validCredential.record,\n disclosedPayload: validCredential.record.firstCredential.jsonCredential as JsonObject,\n } as const\n }\n\n if (validCredential.record.type === 'W3cV2CredentialRecord') {\n return {\n claimFormat: validCredential.record.firstCredential.claimFormat,\n credentialRecord: validCredential.record,\n disclosedPayload: validCredential.claims.valid_claim_sets[0].output as JsonObject,\n } as const\n }\n\n throw new DcqlError('Unsupported record type for DCQL')\n }\n\n /**\n * Selects the credentials to use based on the output from `getCredentialsForRequest`\n * Use this method if you don't want to manually select the credentials yourself.\n */\n public selectCredentialsForRequest(\n dcqlQueryResult: DcqlQueryResult,\n { useMode = CredentialMultiInstanceUseMode.NewOrFirst }: DcqlSelectCredentialsForRequestOptions = {}\n ): DcqlCredentialsForRequest {\n if (!dcqlQueryResult.can_be_satisfied) {\n throw new DcqlError(\n 'Cannot select the credentials for the dcql query presentation if the request cannot be satisfied'\n )\n }\n\n const credentials: DcqlCredentialsForRequest = {}\n\n if (dcqlQueryResult.credential_sets) {\n credentialSetLoop: for (const credentialSet of dcqlQueryResult.credential_sets) {\n // undefined defaults to true\n if (credentialSet.required === false) continue\n const fullfillableOptions = credentialSet.matching_options\n\n if (!fullfillableOptions) {\n throw new DcqlError('Invalid dcql query result. No option is fullfillable')\n }\n\n for (const fullfillableOption of fullfillableOptions) {\n const optionMatches = fullfillableOption.map((credentialQueryId) => {\n const credentialMatch = dcqlQueryResult.credential_matches[credentialQueryId]\n if (!credentialMatch.success) return undefined\n const match = credentialMatch.valid_credentials.find((match: DcqlValidCredential) =>\n canUseInstanceFromCredentialRecord({ credentialRecord: match.record, useMode })\n )\n\n if (!match) return undefined\n return {\n match,\n credentialQueryId,\n }\n })\n\n if (optionMatches.every((c) => c !== undefined)) {\n for (const { match, credentialQueryId } of optionMatches) {\n credentials[credentialQueryId] = [this.dcqlCredentialForRequestForValidCredential(match)]\n }\n\n continue credentialSetLoop\n }\n }\n\n throw new DcqlError(\n 'Unable to select credentials for credential set. No new credential instance available on any of the available credentials.'\n )\n }\n } else {\n for (const credentialQuery of dcqlQueryResult.credentials) {\n const credentialMatch = dcqlQueryResult.credential_matches[credentialQuery.id]\n if (!credentialMatch.success) {\n throw new DcqlError(\n `Invalid dcql query result for credential query id '${credentialQuery.id}'. Cannot auto-select credentials`\n )\n }\n\n const credential = credentialMatch.valid_credentials.find((match: DcqlValidCredential) =>\n canUseInstanceFromCredentialRecord({ credentialRecord: match.record, useMode })\n )\n if (!credential) {\n throw new DcqlError(\n `Unable to select credential for credential query id '${credentialQuery.id}'. No new credential instance available on any of the available credentials.`\n )\n }\n\n credentials[credentialQuery.id] = [this.dcqlCredentialForRequestForValidCredential(credential)]\n }\n }\n\n return credentials\n }\n\n public validateDcqlQuery(dcqlQuery: DcqlQuery | DcqlQuery.Input | unknown): DcqlQuery {\n const parsed = DcqlQuery.parse(dcqlQuery as DcqlQuery)\n DcqlQuery.validate(parsed)\n return parsed\n }\n\n public async createPresentation(\n agentContext: AgentContext,\n options: {\n credentialQueryToCredential: DcqlCredentialsForRequest\n challenge: string\n domain?: string\n mdocSessionTranscript?: MdocSessionTranscriptOptions\n }\n ): Promise<{\n dcqlPresentation: DcqlPresentation\n encodedDcqlPresentation: DcqlEncodedPresentations\n }> {\n const { domain, challenge, mdocSessionTranscript } = options\n\n const dcqlPresentation: DcqlPresentation = {}\n const encodedDcqlPresentation: DcqlEncodedPresentations = {}\n const vcPresentationsToCreate = getDcqlVcPresentationsToCreate(options.credentialQueryToCredential)\n\n for (const [credentialQueryId, presentationsToCreate] of Object.entries(vcPresentationsToCreate)) {\n for (const presentationToCreate of presentationsToCreate) {\n let createdPresentation: VerifiablePresentation\n let encodedCreatedPresentation: string | Record<string, unknown>\n\n if (presentationToCreate.claimFormat === ClaimFormat.MsoMdoc) {\n const mdocRecord = presentationToCreate.credentialRecord\n if (!mdocSessionTranscript) {\n throw new DcqlError('Missing mdoc session transcript options for creating MDOC presentation.')\n }\n\n const { credentialInstance } = await useInstanceFromCredentialRecord({\n agentContext,\n useMode: presentationToCreate.useMode,\n credentialRecord: mdocRecord,\n })\n\n const deviceResponse = await MdocDeviceResponse.createDeviceResponse(agentContext, {\n mdocs: [credentialInstance],\n documentRequests: [\n {\n docType: mdocRecord.getTags().docType,\n nameSpaces: Object.fromEntries(\n Object.entries(presentationToCreate.disclosedPayload).map(([key, value]) => {\n // FIXME: we need the DCQL query here to get the intent_to_retain from query (currently hardcoded to false)\n return [key, Object.fromEntries(Object.entries(value).map(([key]) => [key, false]))]\n })\n ),\n },\n ],\n sessionTranscriptOptions: mdocSessionTranscript,\n })\n const deviceResponseBase64Url = TypedArrayEncoder.toBase64URL(deviceResponse)\n\n encodedCreatedPresentation = deviceResponseBase64Url\n createdPresentation = MdocDeviceResponse.fromBase64Url(deviceResponseBase64Url)\n } else if (presentationToCreate.claimFormat === ClaimFormat.SdJwtDc) {\n const presentationFrame = buildDisclosureFrameForPayload(presentationToCreate.disclosedPayload)\n\n if (!domain) {\n throw new DcqlError('Missing domain property for creating SdJwtVc presentation.')\n }\n\n const { credentialInstance } = await useInstanceFromCredentialRecord({\n agentContext,\n useMode: presentationToCreate.useMode,\n credentialRecord: presentationToCreate.credentialRecord,\n })\n\n const sdJwtVcApi = this.getSdJwtVcApi(agentContext)\n const presentation = await sdJwtVcApi.present({\n sdJwtVc: credentialInstance,\n presentationFrame,\n verifierMetadata: {\n audience: domain,\n nonce: challenge,\n issuedAt: Math.floor(Date.now() / 1000),\n },\n additionalPayload: presentationToCreate.additionalPayload,\n })\n\n encodedCreatedPresentation = presentation\n createdPresentation = sdJwtVcApi.fromCompact(presentation)\n } else if (presentationToCreate.claimFormat === ClaimFormat.JwtVp) {\n const { credentialInstance } = await useInstanceFromCredentialRecord({\n agentContext,\n useMode: presentationToCreate.useMode,\n credentialRecord: presentationToCreate.credentialRecord,\n })\n\n if (!credentialInstance.credentialSubjectIds[0]) {\n throw new DcqlError('Cannot create presentation for credentials without subject id')\n }\n\n // Determine a suitable verification method for the presentation\n const verificationMethod = await this.getVerificationMethodForSubjectId(\n agentContext,\n credentialInstance.credentialSubjectIds[0]\n )\n\n const w3cCredentialService = agentContext.resolve(W3cCredentialService)\n const w3cPresentation = new W3cPresentation({\n verifiableCredential: [credentialInstance],\n holder: verificationMethod.controller,\n })\n\n const publicJwk = getPublicJwkFromVerificationMethod(verificationMethod)\n\n const signedPresentation = await w3cCredentialService.signPresentation<ClaimFormat.JwtVp>(agentContext, {\n format: ClaimFormat.JwtVp,\n alg: publicJwk.signatureAlgorithm,\n verificationMethod: verificationMethod.id,\n presentation: w3cPresentation,\n challenge,\n domain,\n })\n\n encodedCreatedPresentation = signedPresentation.encoded\n createdPresentation = signedPresentation\n } else if (presentationToCreate.claimFormat === ClaimFormat.LdpVp) {\n const { credentialInstance } = await useInstanceFromCredentialRecord({\n agentContext,\n useMode: presentationToCreate.useMode,\n credentialRecord: presentationToCreate.credentialRecord,\n })\n\n if (!credentialInstance.credentialSubjectIds[0]) {\n throw new DcqlError('Cannot create presentation for credentials without subject id')\n }\n\n // Determine a suitable verification method for the presentation\n const verificationMethod = await this.getVerificationMethodForSubjectId(\n agentContext,\n credentialInstance.credentialSubjectIds[0]\n )\n\n const w3cCredentialService = agentContext.resolve(W3cCredentialService)\n const w3cPresentation = new W3cPresentation({\n verifiableCredential: [credentialInstance],\n holder: verificationMethod.controller,\n })\n\n const signedPresentation = await w3cCredentialService.signPresentation(agentContext, {\n format: ClaimFormat.LdpVp,\n // TODO: we should move the check for which proof to use for a presentation to earlier\n // as then we know when determining which VPs to submit already if the proof types are supported\n // by the verifier, and we can then just add this to the vpToCreate interface\n proofType: this.getProofTypeForLdpVc(agentContext, verificationMethod),\n proofPurpose: new purposes.AuthenticationProofPurpose({ challenge, domain }),\n verificationMethod: verificationMethod.id,\n presentation: w3cPresentation,\n challenge,\n domain,\n })\n\n encodedCreatedPresentation = signedPresentation.encoded\n createdPresentation = signedPresentation\n } else if (presentationToCreate.claimFormat === ClaimFormat.JwtW3cVp) {\n const w3cV2CredentialService = agentContext.resolve(W3cV2CredentialService)\n const w3cV2Presentation = new W3cV2Presentation({\n holder: presentationToCreate.credentialRecord.firstCredential.resolvedCredential.credentialSubjectIds[0],\n verifiableCredential: [\n W3cV2EnvelopedVerifiableCredential.fromVerifiableCredential(\n presentationToCreate.credentialRecord.firstCredential\n ),\n ],\n })\n\n const signedPresentation = await w3cV2CredentialService.signPresentation<ClaimFormat.JwtW3cVp>(agentContext, {\n format: ClaimFormat.JwtW3cVp,\n presentation: w3cV2Presentation,\n challenge,\n domain,\n })\n\n encodedCreatedPresentation = signedPresentation.encoded\n createdPresentation = signedPresentation\n } else if (presentationToCreate.claimFormat === ClaimFormat.SdJwtW3cVp) {\n const presentationFrame = buildDisclosureFrameForPayload(presentationToCreate.disclosedPayload)\n if (!domain) {\n throw new DcqlError('Missing domain property for creating SdJwtVc presentation.')\n }\n\n const w3cV2SdJwtCredentialService = agentContext.resolve(W3cV2SdJwtCredentialService)\n const sdJwtVc = await w3cV2SdJwtCredentialService.present(agentContext, {\n credential: presentationToCreate.credentialRecord.firstCredential.encoded,\n presentationFrame,\n })\n\n const w3cV2CredentialService = agentContext.resolve(W3cV2CredentialService)\n const w3cV2Presentation = new W3cV2Presentation({\n holder: presentationToCreate.credentialRecord.firstCredential.resolvedCredential.credentialSchemaIds[0],\n verifiableCredential: [W3cV2EnvelopedVerifiableCredential.fromVerifiableCredential(sdJwtVc)],\n })\n\n const signedPresentation = await w3cV2CredentialService.signPresentation<ClaimFormat.SdJwtW3cVp>(\n agentContext,\n {\n format: ClaimFormat.SdJwtW3cVp,\n presentation: w3cV2Presentation,\n challenge,\n domain,\n }\n )\n\n encodedCreatedPresentation = signedPresentation.encoded\n createdPresentation = signedPresentation\n } else {\n throw new DcqlError('Unsupported presentation format.')\n }\n\n if (!dcqlPresentation[credentialQueryId]) {\n dcqlPresentation[credentialQueryId] = [createdPresentation]\n } else {\n dcqlPresentation[credentialQueryId].push(createdPresentation)\n }\n\n if (!encodedDcqlPresentation[credentialQueryId]) {\n encodedDcqlPresentation[credentialQueryId] = [encodedCreatedPresentation]\n } else {\n encodedDcqlPresentation[credentialQueryId].push(encodedCreatedPresentation)\n }\n }\n }\n\n return {\n dcqlPresentation,\n encodedDcqlPresentation,\n }\n }\n\n private getSdJwtVcApi(agentContext: AgentContext) {\n return agentContext.dependencyManager.resolve(SdJwtVcApi)\n }\n\n private getMdocApi(agentContext: AgentContext) {\n return agentContext.dependencyManager.resolve(MdocApi)\n }\n\n private async getVerificationMethodForSubjectId(agentContext: AgentContext, subjectId: string) {\n const didsApi = agentContext.dependencyManager.resolve(DidsApi)\n\n if (!subjectId.startsWith('did:')) {\n throw new DcqlError(`Only dids are supported as credentialSubject id. ${subjectId} is not a valid did`)\n }\n\n const didDocument = await didsApi.resolveDidDocument(subjectId)\n\n if (!didDocument.authentication || didDocument.authentication.length === 0) {\n throw new DcqlError(`No authentication verificationMethods found for did ${subjectId} in did document`)\n }\n\n // the signature suite to use for the presentation is dependant on the credentials we share.\n // 1. Get the verification method for this given proof purpose in this DID document\n let [verificationMethod] = didDocument.authentication\n if (typeof verificationMethod === 'string') {\n verificationMethod = didDocument.dereferenceKey(verificationMethod, ['authentication'])\n }\n\n return verificationMethod\n }\n\n // FIXME: We need to take into account OpenID4VP metadata (probably providing supported/allowed algs to the DCQL create presentation method)\n private getProofTypeForLdpVc(agentContext: AgentContext, verificationMethod: VerificationMethod) {\n // For each of the supported algs, find the key types, then find the proof types\n const signatureSuiteRegistry = agentContext.dependencyManager.resolve(SignatureSuiteRegistry)\n\n const publicJwk = getPublicJwkFromVerificationMethod(verificationMethod)\n const supportedSignatureSuites = signatureSuiteRegistry.getAllByPublicJwkType(publicJwk)\n if (supportedSignatureSuites.length === 0) {\n throw new DcqlError(\n `Couldn't find a supported signature suite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mBACpB,kBAAiB,qBAAqB,CAAC,oBAAoB;OAE3D,kBAAiB,mBAAmB,KAAK,oBAAoB;AAG/D,OAAI,CAAC,wBAAwB,mBAC3B,yBAAwB,qBAAqB,CAAC,2BAA2B;OAEzE,yBAAwB,mBAAmB,KAAK,2BAA2B;;AAKjF,SAAO;GACL;GACA;GACD;;CAGH,AAAQ,cAAc,cAA4B;AAChD,SAAO,aAAa,kBAAkB,QAAQ,WAAW;;CAG3D,AAAQ,WAAW,cAA4B;AAC7C,SAAO,aAAa,kBAAkB,QAAQ,QAAQ;;CAGxD,MAAc,kCAAkC,cAA4B,WAAmB;EAC7F,MAAM,UAAU,aAAa,kBAAkB,QAAQ,QAAQ;AAE/D,MAAI,CAAC,UAAU,WAAW,OAAO,CAC/B,OAAM,IAAI,UAAU,oDAAoD,UAAU,qBAAqB;EAGzG,MAAM,cAAc,MAAM,QAAQ,mBAAmB,UAAU;AAE/D,MAAI,CAAC,YAAY,kBAAkB,YAAY,eAAe,WAAW,EACvE,OAAM,IAAI,UAAU,uDAAuD,UAAU,kBAAkB;EAKzG,IAAI,CAAC,sBAAsB,YAAY;AACvC,MAAI,OAAO,uBAAuB,SAChC,sBAAqB,YAAY,eAAe,oBAAoB,CAAC,iBAAiB,CAAC;AAGzF,SAAO;;CAIT,AAAQ,qBAAqB,cAA4B,oBAAwC;EAE/F,MAAM,yBAAyB,aAAa,kBAAkB,QAAQ,uBAAuB;EAE7F,MAAM,YAAY,mCAAmC,mBAAmB;EACxE,MAAM,2BAA2B,uBAAuB,sBAAsB,UAAU;AACxF,MAAI,yBAAyB,WAAW,EACtC,OAAM,IAAI,UACR,+DAA+D,UAAU,0BAC1E;AAGH,SAAO,yBAAyB,GAAG;;;0BA10BtC,YAAY"}
|
|
1
|
+
{"version":3,"file":"DcqlService.mjs","names":["DcqlService","allRecords: Array<SdJwtVcRecord | W3cCredentialRecord | W3cV2CredentialRecord | MdocRecord>","credentialRecordsWithFormatDuplicates: typeof credentialRecords","dcqlCredentials: DcqlCredential[]","credentials: DcqlCredentialsForRequest","match","dcqlPresentation: DcqlPresentation","encodedDcqlPresentation: DcqlEncodedPresentations","getDcqlVcPresentationsToCreate","createdPresentation: VerifiablePresentation","encodedCreatedPresentation: string | Record<string, unknown>","key"],"sources":["../../../src/modules/dcql/DcqlService.ts"],"sourcesContent":["import {\n DcqlCredential,\n DcqlCredentialQuery,\n DcqlMdocCredential,\n DcqlPresentationResult,\n DcqlQuery,\n DcqlSdJwtVcCredential,\n DcqlW3cVcCredential,\n} from 'dcql'\nimport { injectable } from 'tsyringe'\nimport type { AgentContext } from '../../agent'\nimport { isNonEmptyArray, type JsonObject, type JsonValue, mapNonEmptyArray } from '../../types'\nimport { asArray, TypedArrayEncoder } from '../../utils'\nimport {\n CredentialMultiInstanceUseMode,\n canUseInstanceFromCredentialRecord,\n useInstanceFromCredentialRecord,\n} from '../../utils/credentialUse'\nimport { DidsApi, getPublicJwkFromVerificationMethod, VerificationMethod } from '../dids'\nimport type { VerifiablePresentation } from '../dif-presentation-exchange/index'\nimport {\n MdocApi,\n MdocDeviceResponse,\n type MdocNameSpaces,\n MdocRecord,\n type MdocSessionTranscriptOptions,\n} from '../mdoc'\nimport { SdJwtVcApi, SdJwtVcRecord, SdJwtVcService } from '../sd-jwt-vc'\nimport { buildDisclosureFrameForPayload } from '../sd-jwt-vc/disclosureFrame'\nimport {\n ClaimFormat,\n SignatureSuiteRegistry,\n W3cCredentialRecord,\n W3cCredentialRepository,\n W3cCredentialService,\n W3cJsonLdCredentialService,\n W3cJsonLdVerifiableCredential,\n W3cPresentation,\n W3cV2CredentialRecord,\n W3cV2CredentialRepository,\n W3cV2CredentialService,\n W3cV2EnvelopedVerifiableCredential,\n W3cV2Presentation,\n} from '../vc'\nimport { purposes } from '../vc/data-integrity/libraries/jsonld-signatures'\nimport { W3cV2SdJwtCredentialService, W3cV2SdJwtVerifiableCredential } from '../vc/sd-jwt-vc'\nimport { X509Certificate } from '../x509'\nimport { DcqlError } from './DcqlError'\nimport type {\n DcqlCredentialsForRequest,\n DcqlEncodedPresentations,\n DcqlFailedCredential,\n DcqlPresentation,\n DcqlQueryResult,\n DcqlValidCredential,\n} from './models'\nimport { dcqlGetPresentationsToCreate as getDcqlVcPresentationsToCreate } from './utils'\n\nexport interface DcqlSelectCredentialsForRequestOptions {\n /**\n * The usage mode to apply to the credentials when selecting credentials.\n *\n * If and usage mode is selected that require a new instance to be used, and there's no\n * new instances available, an error will be thrown.\n *\n * It does not actually select the credential from the record yet, it just filters\n * out records that don't match the filter.\n */\n useMode?: CredentialMultiInstanceUseMode\n}\n\n@injectable()\nexport class DcqlService {\n /**\n * Queries the wallet for credentials that match the given dcql query. This only does an initial query based on the\n * schema of the input descriptors. It does not do any further filtering based on the constraints in the input descriptors.\n */\n private async queryCredentialsForDcqlQuery(\n agentContext: AgentContext,\n dcqlQuery: DcqlQuery\n ): Promise<Array<SdJwtVcRecord | W3cCredentialRecord | W3cV2CredentialRecord | MdocRecord>> {\n const formats = new Set(dcqlQuery.credentials.map((c) => c.format))\n const allRecords: Array<SdJwtVcRecord | W3cCredentialRecord | W3cV2CredentialRecord | MdocRecord> = []\n\n const mdocDoctypes = dcqlQuery.credentials\n .filter((credentialQuery) => credentialQuery.format === 'mso_mdoc')\n .map((c) => c.meta?.doctype_value)\n\n const mdocApi = this.getMdocApi(agentContext)\n if (mdocDoctypes.every((doctype) => doctype !== undefined)) {\n const mdocRecords = await mdocApi.findAllByQuery({\n $or: mdocDoctypes.map((docType) => ({\n docType: docType,\n })),\n })\n allRecords.push(...mdocRecords)\n } else if (formats.has('mso_mdoc')) {\n const mdocRecords = await mdocApi.getAll()\n allRecords.push(...mdocRecords)\n }\n\n const sdJwts = dcqlQuery.credentials.filter(\n (credentialQuery): credentialQuery is DcqlCredentialQuery.SdJwtVc =>\n (credentialQuery.format === 'vc+sd-jwt' && !(credentialQuery.meta && 'type_values' in credentialQuery.meta)) ||\n credentialQuery.format === 'dc+sd-jwt'\n )\n\n const sdJwtVctValues = sdJwts.flatMap((c) => c.meta?.vct_values)\n\n const sdJwtVcApi = this.getSdJwtVcApi(agentContext)\n if (sdJwtVctValues.every((vct) => vct !== undefined)) {\n const sdjwtVcRecords = await sdJwtVcApi.findAllByQuery({\n $or: sdJwtVctValues.map((vct) => ({\n vct: vct as string,\n })),\n })\n allRecords.push(...sdjwtVcRecords)\n } else if (sdJwts.length > 0) {\n const sdJwtVcRecords = await sdJwtVcApi.getAll()\n allRecords.push(...sdJwtVcRecords)\n }\n\n const w3cCredentialRepository = agentContext.dependencyManager.resolve(W3cCredentialRepository)\n if (formats.has('jwt_vc_json')) {\n const w3cRecords = await w3cCredentialRepository.findByQuery(agentContext, {\n claimFormat: ClaimFormat.JwtVc,\n\n // For jwt_vc_json we query the non-exapnded types\n $or: dcqlQuery.credentials\n .flatMap((c) => (c.format === 'jwt_vc_json' ? c.meta.type_values : []))\n .map((typeValues) => ({\n types: typeValues,\n })),\n })\n allRecords.push(...w3cRecords)\n }\n\n if (formats.has('ldp_vc')) {\n const w3cRecords = await w3cCredentialRepository.findByQuery(agentContext, {\n claimFormat: ClaimFormat.LdpVc,\n\n // For LDP_VC we query the expanded types\n $or: dcqlQuery.credentials\n .flatMap((c) => (c.format === 'jwt_vc_json' ? c.meta.type_values : []))\n .map((typeValues) => ({\n expandedTypes: typeValues,\n })),\n })\n allRecords.push(...w3cRecords)\n }\n\n const w3cSdJwts = dcqlQuery.credentials.filter(\n (credentialQuery): credentialQuery is DcqlCredentialQuery.W3cVc & { format: 'vc+sd-jwt' } =>\n credentialQuery.format === 'vc+sd-jwt' && !!credentialQuery.meta && 'type_values' in credentialQuery.meta\n )\n\n if (w3cSdJwts.length > 0) {\n const w3cV2CredentialRepository = agentContext.dependencyManager.resolve(W3cV2CredentialRepository)\n\n const w3cV2Records = await w3cV2CredentialRepository.findByQuery(agentContext, {\n claimFormat: ClaimFormat.SdJwtW3cVc,\n $or: dcqlQuery.credentials\n .flatMap((c) => (c.format === 'vc+sd-jwt' && c.meta && 'type_values' in c.meta ? c.meta.type_values : []))\n .map((typeValues) => ({\n types: typeValues,\n })),\n })\n\n allRecords.push(...w3cV2Records)\n }\n\n return allRecords\n }\n\n public async getDcqlCredentialRepresentation(\n agentContext: AgentContext,\n presentation: VerifiablePresentation,\n queryCredential: DcqlQuery['credentials'][number]\n ): Promise<DcqlCredential> {\n // SD-JWT credential can be used as both dc+sd-jwt and vc+sd-jwt\n // At some point we might want to look at the header value of the sd-jwt (vc+sd-jwt vc dc+sd-jwt)\n if (presentation.claimFormat === ClaimFormat.SdJwtDc) {\n return {\n cryptographic_holder_binding: true,\n credential_format: queryCredential.format === 'dc+sd-jwt' ? 'dc+sd-jwt' : 'vc+sd-jwt',\n vct: presentation.prettyClaims.vct as string,\n claims: presentation.prettyClaims as DcqlSdJwtVcCredential.Claims,\n } satisfies DcqlSdJwtVcCredential\n }\n if (presentation.claimFormat === ClaimFormat.MsoMdoc) {\n if (presentation.documents.length !== 1) {\n throw new DcqlError('MDOC presentations must contain exactly one document')\n }\n return {\n cryptographic_holder_binding: true,\n credential_format: 'mso_mdoc',\n doctype: presentation.documents[0].docType,\n namespaces: presentation.documents[0].issuerSignedNamespaces,\n } satisfies DcqlMdocCredential\n }\n if (presentation.claimFormat === ClaimFormat.JwtVp) {\n const vc = Array.isArray(presentation.verifiableCredential)\n ? presentation.verifiableCredential[0].jsonCredential\n : presentation.verifiableCredential\n\n return {\n cryptographic_holder_binding: true,\n credential_format: 'jwt_vc_json',\n claims: vc.jsonCredential as { [key: string]: JsonValue },\n type: vc.type,\n } satisfies DcqlW3cVcCredential\n }\n if (presentation.claimFormat === ClaimFormat.LdpVp) {\n const vc = Array.isArray(presentation.verifiableCredential)\n ? (presentation.verifiableCredential[0] as W3cJsonLdVerifiableCredential)\n : (presentation.verifiableCredential as W3cJsonLdVerifiableCredential)\n\n const w3cJsonLdCredentialService = agentContext.dependencyManager.resolve(W3cJsonLdCredentialService)\n const expandedTypes = await w3cJsonLdCredentialService.getExpandedTypesForCredential(agentContext, vc)\n\n return {\n cryptographic_holder_binding: true,\n credential_format: 'ldp_vc',\n claims: vc.jsonCredential as DcqlW3cVcCredential.Claims,\n type: expandedTypes,\n } satisfies DcqlW3cVcCredential\n }\n if (presentation.claimFormat === ClaimFormat.SdJwtW3cVp) {\n const vc = Array.isArray(presentation.resolvedPresentation.verifiableCredential)\n ? presentation.resolvedPresentation.verifiableCredential[0].resolvedCredential\n : presentation.resolvedPresentation.verifiableCredential.resolvedCredential\n\n return {\n cryptographic_holder_binding: true,\n credential_format: 'vc+sd-jwt',\n type: asArray(vc.type),\n claims: vc.toJSON() as { [key: string]: JsonValue },\n } satisfies DcqlW3cVcCredential\n }\n\n throw new DcqlError('Unsupported claim format for presentation')\n }\n\n public async getCredentialsForRequest(agentContext: AgentContext, dcqlQuery: DcqlQuery): Promise<DcqlQueryResult> {\n const credentialRecords = await this.queryCredentialsForDcqlQuery(agentContext, dcqlQuery)\n const credentialRecordsWithFormatDuplicates: typeof credentialRecords = []\n const parsedQuery = DcqlQuery.parse(dcqlQuery)\n\n const dcqlCredentials: DcqlCredential[] = credentialRecords.flatMap((record): DcqlCredential | DcqlCredential[] => {\n if (record.type === 'MdocRecord') {\n credentialRecordsWithFormatDuplicates.push(record)\n\n // We always extract the first mdoc for querying\n const mdoc = record.firstCredential\n\n const akiValues = mdoc.issuerSignedCertificateChain\n .map((c) => {\n const akiHex = X509Certificate.fromRawCertificate(c).authorityKeyIdentifier\n return akiHex ? TypedArrayEncoder.toBase64URL(TypedArrayEncoder.fromHex(akiHex)) : undefined\n })\n .filter((aki) => aki !== undefined)\n\n return {\n authority: isNonEmptyArray(akiValues)\n ? {\n type: 'aki',\n values: akiValues,\n }\n : undefined,\n credential_format: 'mso_mdoc',\n doctype: mdoc.docType,\n namespaces: mdoc.issuerSignedNamespaces,\n cryptographic_holder_binding: true,\n } satisfies DcqlCredential\n }\n\n if (record.type === 'SdJwtVcRecord') {\n const sdJwtVc = record.firstCredential\n const claims = sdJwtVc.prettyClaims as DcqlSdJwtVcCredential.Claims\n\n const akiValues = (sdJwtVc.header.x5c as string[] | undefined)\n ?.map((c) => {\n const akiHex = X509Certificate.fromEncodedCertificate(c).authorityKeyIdentifier\n return akiHex ? TypedArrayEncoder.toBase64URL(TypedArrayEncoder.fromHex(akiHex)) : undefined\n })\n .filter((aki) => aki !== undefined)\n\n const authority =\n akiValues && isNonEmptyArray(akiValues)\n ? ({\n type: 'aki',\n values: akiValues,\n } as const)\n : undefined\n\n // To keep correct mapping of input credential index, we add it twice here (for dc+sd-jwt and vc+sd-jwt)\n credentialRecordsWithFormatDuplicates.push(record, record)\n return [\n {\n authority,\n credential_format: 'dc+sd-jwt',\n vct: record.getTags().vct,\n claims,\n cryptographic_holder_binding: true,\n } satisfies DcqlSdJwtVcCredential,\n {\n authority,\n credential_format: 'vc+sd-jwt',\n vct: record.getTags().vct,\n claims,\n cryptographic_holder_binding: true,\n } satisfies DcqlSdJwtVcCredential,\n ] satisfies [DcqlSdJwtVcCredential, DcqlSdJwtVcCredential]\n }\n\n if (record.type === 'W3cCredentialRecord') {\n const firstCredential = record.firstCredential\n credentialRecordsWithFormatDuplicates.push(record)\n if (firstCredential.claimFormat === ClaimFormat.LdpVc) {\n return {\n credential_format: 'ldp_vc',\n type: record.getTags().expandedTypes ?? [],\n claims: firstCredential.jsonCredential as DcqlW3cVcCredential.Claims,\n cryptographic_holder_binding: true,\n } satisfies DcqlW3cVcCredential\n }\n\n return {\n credential_format: 'jwt_vc_json',\n type: firstCredential.type,\n claims: firstCredential.jsonCredential as DcqlW3cVcCredential.Claims,\n cryptographic_holder_binding: true,\n } satisfies DcqlW3cVcCredential\n }\n\n if (record.type === 'W3cV2CredentialRecord') {\n credentialRecordsWithFormatDuplicates.push(record)\n const firstCredential = record.firstCredential\n\n return {\n credential_format: 'vc+sd-jwt',\n type: asArray(firstCredential.resolvedCredential.type),\n claims: firstCredential.resolvedCredential.toJSON() as DcqlW3cVcCredential.Claims,\n cryptographic_holder_binding: true,\n } satisfies DcqlW3cVcCredential\n }\n\n throw new DcqlError('Unsupported record type')\n })\n\n const queryResult = DcqlQuery.query(parsedQuery, dcqlCredentials)\n\n const matchesWithRecord = Object.fromEntries(\n Object.entries(queryResult.credential_matches).map(([credential_query_id, result]) => {\n const failedCredentials = result.failed_credentials\n ? mapNonEmptyArray(result.failed_credentials, (credential) => {\n const record = credentialRecordsWithFormatDuplicates[credential.input_credential_index]\n const updatedCredential: DcqlFailedCredential = {\n ...credential,\n record,\n claims: credential.claims.success\n ? {\n ...credential.claims,\n success: true,\n valid_claim_sets: mapNonEmptyArray(credential.claims.valid_claim_sets, (claimSet) => ({\n ...claimSet,\n ...(record.type === 'SdJwtVcRecord'\n ? // NOTE: we cast from SdJwtVcPayload (which is Record<string, unknown> to { [key: string]: JsonValue })\n // Otherwise TypeScript explains, but I'm not sure why Record<string, unknown> wouldn't be applicable to { [key: string]: JsonValue }\n {\n output: agentContext.dependencyManager\n .resolve(SdJwtVcService)\n .applyDisclosuresForPayload(record.encoded, claimSet.output as JsonObject)\n .prettyClaims as { [key: string]: JsonValue },\n }\n : record.type === 'W3cV2CredentialRecord' &&\n record.firstCredential instanceof W3cV2SdJwtVerifiableCredential\n ? {\n output: agentContext.dependencyManager\n .resolve(SdJwtVcService)\n .applyDisclosuresForPayload(\n record.firstCredential.encoded,\n claimSet.output as JsonObject\n ).prettyClaims as { [key: string]: JsonValue },\n }\n : {}),\n })),\n }\n : credential.claims,\n }\n return updatedCredential\n })\n : undefined\n\n // If not success, valid_credentials will be undefined, so we only have to map failed_credentials\n if (!result.success) {\n return [\n credential_query_id,\n {\n ...result,\n failed_credentials: failedCredentials,\n },\n ]\n }\n\n return [\n credential_query_id,\n {\n ...result,\n failed_credentials: failedCredentials,\n valid_credentials: mapNonEmptyArray(result.valid_credentials, (credential) => {\n const record = credentialRecordsWithFormatDuplicates[credential.input_credential_index]\n const updatedCredential: DcqlValidCredential = {\n ...credential,\n record,\n claims: {\n ...credential.claims,\n valid_claim_sets: mapNonEmptyArray(credential.claims.valid_claim_sets, (claimSet) => ({\n ...claimSet,\n ...(record.type === 'SdJwtVcRecord'\n ? // NOTE: we cast from SdJwtVcPayload (which is Record<string, unknown> to { [key: string]: JsonValue })\n // Otherwise TypeScript explains, but I'm not sure why Record<string, unknown> wouldn't be applicable to { [key: string]: JsonValue }\n {\n output: agentContext.dependencyManager\n .resolve(SdJwtVcService)\n .applyDisclosuresForPayload(record.encoded, claimSet.output as JsonObject).prettyClaims as {\n [key: string]: JsonValue\n },\n }\n : record.type === 'W3cV2CredentialRecord' &&\n record.firstCredential instanceof W3cV2SdJwtVerifiableCredential\n ? {\n output: agentContext.dependencyManager\n .resolve(SdJwtVcService)\n .applyDisclosuresForPayload(record.firstCredential.encoded, claimSet.output as JsonObject)\n .prettyClaims as { [key: string]: JsonValue },\n }\n : {}),\n })),\n },\n }\n return updatedCredential\n }),\n },\n ]\n })\n )\n\n return {\n ...queryResult,\n credential_matches: matchesWithRecord,\n }\n }\n\n public async assertValidDcqlPresentation(\n agentContext: AgentContext,\n dcqlPresentation: DcqlPresentation,\n dcqlQuery: DcqlQuery\n ) {\n const internalDcqlPresentation = Object.fromEntries(\n await Promise.all(\n Object.entries(dcqlPresentation).map(async ([credentialId, presentations]) => {\n const queryCredential = dcqlQuery.credentials.find((c) => c.id === credentialId)\n if (!queryCredential) {\n throw new DcqlError(\n `DCQL presentation contains presentation entry for credential id '${credentialId}', but this id is not present in the DCQL query`\n )\n }\n\n return [\n credentialId,\n await Promise.all(\n presentations.map((presentation) =>\n this.getDcqlCredentialRepresentation(agentContext, presentation, queryCredential)\n )\n ),\n ]\n })\n )\n )\n\n const presentationResult = DcqlPresentationResult.fromDcqlPresentation(internalDcqlPresentation, { dcqlQuery })\n\n if (!presentationResult.can_be_satisfied) {\n throw new DcqlError('Presentations do not satisfy the DCQL query.', {\n additionalMessages: Object.entries(presentationResult.credential_matches ?? {})\n .flatMap(([queryId, match]) =>\n match.success\n ? undefined\n : !match.failed_credentials\n ? `Unable to match query credential '${queryId}'. No prsentations provided`\n : match.failed_credentials.map(\n (failedCredential) =>\n `Presentation at index ${failedCredential.input_credential_index} does not match query credential '${queryId}'. ${JSON.stringify(\n {\n ...(failedCredential.claims.success\n ? {}\n : { claims: failedCredential.claims.failed_claim_sets.map((cs) => cs.issues) }),\n ...(failedCredential.trusted_authorities.success\n ? {}\n : {\n trusted_authorities:\n failedCredential.trusted_authorities.failed_trusted_authorities.map(\n (ta) => ta.issues\n ),\n }),\n ...(failedCredential.meta.success ? {} : { meta: failedCredential.meta.issues }),\n },\n null,\n 2\n )}`\n )\n )\n .filter((message) => message !== undefined),\n })\n }\n\n return presentationResult\n }\n\n private dcqlCredentialForRequestForValidCredential(validCredential: DcqlValidCredential) {\n if (validCredential.record.type === 'MdocRecord') {\n return {\n claimFormat: ClaimFormat.MsoMdoc,\n credentialRecord: validCredential.record,\n disclosedPayload: validCredential.claims.valid_claim_sets[0].output as MdocNameSpaces,\n } as const\n }\n if (validCredential.record.type === 'SdJwtVcRecord') {\n return {\n claimFormat: ClaimFormat.SdJwtDc,\n credentialRecord: validCredential.record,\n disclosedPayload: validCredential.claims.valid_claim_sets[0].output as JsonObject,\n } as const\n }\n\n if (validCredential.record.type === 'W3cCredentialRecord') {\n return {\n claimFormat: validCredential.record.firstCredential.claimFormat,\n credentialRecord: validCredential.record,\n disclosedPayload: validCredential.record.firstCredential.jsonCredential as JsonObject,\n } as const\n }\n\n if (validCredential.record.type === 'W3cV2CredentialRecord') {\n return {\n claimFormat: validCredential.record.firstCredential.claimFormat,\n credentialRecord: validCredential.record,\n disclosedPayload: validCredential.claims.valid_claim_sets[0].output as JsonObject,\n } as const\n }\n\n throw new DcqlError('Unsupported record type for DCQL')\n }\n\n /**\n * Selects the credentials to use based on the output from `getCredentialsForRequest`\n * Use this method if you don't want to manually select the credentials yourself.\n */\n public selectCredentialsForRequest(\n dcqlQueryResult: DcqlQueryResult,\n { useMode = CredentialMultiInstanceUseMode.NewOrFirst }: DcqlSelectCredentialsForRequestOptions = {}\n ): DcqlCredentialsForRequest {\n if (!dcqlQueryResult.can_be_satisfied) {\n throw new DcqlError(\n 'Cannot select the credentials for the dcql query presentation if the request cannot be satisfied'\n )\n }\n\n const credentials: DcqlCredentialsForRequest = {}\n\n if (dcqlQueryResult.credential_sets) {\n credentialSetLoop: for (const credentialSet of dcqlQueryResult.credential_sets) {\n // undefined defaults to true\n if (credentialSet.required === false) continue\n const fullfillableOptions = credentialSet.matching_options\n\n if (!fullfillableOptions) {\n throw new DcqlError('Invalid dcql query result. No option is fullfillable')\n }\n\n for (const fullfillableOption of fullfillableOptions) {\n const optionMatches = fullfillableOption.map((credentialQueryId) => {\n const credentialMatch = dcqlQueryResult.credential_matches[credentialQueryId]\n if (!credentialMatch.success) return undefined\n const match = credentialMatch.valid_credentials.find((match: DcqlValidCredential) =>\n canUseInstanceFromCredentialRecord({ credentialRecord: match.record, useMode })\n )\n\n if (!match) return undefined\n return {\n match,\n credentialQueryId,\n }\n })\n\n if (optionMatches.every((c) => c !== undefined)) {\n for (const { match, credentialQueryId } of optionMatches) {\n credentials[credentialQueryId] = [this.dcqlCredentialForRequestForValidCredential(match)]\n }\n\n continue credentialSetLoop\n }\n }\n\n throw new DcqlError(\n 'Unable to select credentials for credential set. No new credential instance available on any of the available credentials.'\n )\n }\n } else {\n for (const credentialQuery of dcqlQueryResult.credentials) {\n const credentialMatch = dcqlQueryResult.credential_matches[credentialQuery.id]\n if (!credentialMatch.success) {\n throw new DcqlError(\n `Invalid dcql query result for credential query id '${credentialQuery.id}'. Cannot auto-select credentials`\n )\n }\n\n const credential = credentialMatch.valid_credentials.find((match: DcqlValidCredential) =>\n canUseInstanceFromCredentialRecord({ credentialRecord: match.record, useMode })\n )\n if (!credential) {\n throw new DcqlError(\n `Unable to select credential for credential query id '${credentialQuery.id}'. No new credential instance available on any of the available credentials.`\n )\n }\n\n credentials[credentialQuery.id] = [this.dcqlCredentialForRequestForValidCredential(credential)]\n }\n }\n\n return credentials\n }\n\n public validateDcqlQuery(dcqlQuery: DcqlQuery | DcqlQuery.Input | unknown): DcqlQuery {\n const parsed = DcqlQuery.parse(dcqlQuery as DcqlQuery)\n DcqlQuery.validate(parsed)\n return parsed\n }\n\n public async createPresentation(\n agentContext: AgentContext,\n options: {\n credentialQueryToCredential: DcqlCredentialsForRequest\n challenge: string\n domain?: string\n mdocSessionTranscript?: MdocSessionTranscriptOptions\n }\n ): Promise<{\n dcqlPresentation: DcqlPresentation\n encodedDcqlPresentation: DcqlEncodedPresentations\n }> {\n const { domain, challenge, mdocSessionTranscript } = options\n\n const dcqlPresentation: DcqlPresentation = {}\n const encodedDcqlPresentation: DcqlEncodedPresentations = {}\n const vcPresentationsToCreate = getDcqlVcPresentationsToCreate(options.credentialQueryToCredential)\n\n for (const [credentialQueryId, presentationsToCreate] of Object.entries(vcPresentationsToCreate)) {\n for (const presentationToCreate of presentationsToCreate) {\n let createdPresentation: VerifiablePresentation\n let encodedCreatedPresentation: string | Record<string, unknown>\n\n if (presentationToCreate.claimFormat === ClaimFormat.MsoMdoc) {\n const mdocRecord = presentationToCreate.credentialRecord\n if (!mdocSessionTranscript) {\n throw new DcqlError('Missing mdoc session transcript options for creating MDOC presentation.')\n }\n\n const { credentialInstance } = await useInstanceFromCredentialRecord({\n agentContext,\n useMode: presentationToCreate.useMode,\n credentialRecord: mdocRecord,\n })\n\n const deviceResponse = await MdocDeviceResponse.createDeviceResponse(agentContext, {\n mdocs: [credentialInstance],\n documentRequests: [\n {\n docType: mdocRecord.getTags().docType,\n nameSpaces: Object.fromEntries(\n Object.entries(presentationToCreate.disclosedPayload).map(([key, value]) => {\n // FIXME: we need the DCQL query here to get the intent_to_retain from query (currently hardcoded to false)\n return [key, Object.fromEntries(Object.entries(value).map(([key]) => [key, false]))]\n })\n ),\n },\n ],\n sessionTranscriptOptions: mdocSessionTranscript,\n })\n const deviceResponseBase64Url = TypedArrayEncoder.toBase64URL(deviceResponse)\n\n encodedCreatedPresentation = deviceResponseBase64Url\n createdPresentation = MdocDeviceResponse.fromBase64Url(deviceResponseBase64Url)\n } else if (presentationToCreate.claimFormat === ClaimFormat.SdJwtDc) {\n const presentationFrame = buildDisclosureFrameForPayload(presentationToCreate.disclosedPayload)\n\n if (!domain) {\n throw new DcqlError('Missing domain property for creating SdJwtVc presentation.')\n }\n\n const { credentialInstance } = await useInstanceFromCredentialRecord({\n agentContext,\n useMode: presentationToCreate.useMode,\n credentialRecord: presentationToCreate.credentialRecord,\n })\n\n const sdJwtVcApi = this.getSdJwtVcApi(agentContext)\n const presentation = await sdJwtVcApi.present({\n sdJwtVc: credentialInstance,\n presentationFrame,\n verifierMetadata: {\n audience: domain,\n nonce: challenge,\n issuedAt: Math.floor(Date.now() / 1000),\n },\n additionalPayload: presentationToCreate.additionalPayload,\n })\n\n encodedCreatedPresentation = presentation\n createdPresentation = sdJwtVcApi.fromCompact(presentation)\n } else if (presentationToCreate.claimFormat === ClaimFormat.JwtVp) {\n const { credentialInstance } = await useInstanceFromCredentialRecord({\n agentContext,\n useMode: presentationToCreate.useMode,\n credentialRecord: presentationToCreate.credentialRecord,\n })\n\n if (!credentialInstance.credentialSubjectIds[0]) {\n throw new DcqlError('Cannot create presentation for credentials without subject id')\n }\n\n // Determine a suitable verification method for the presentation\n const verificationMethod = await this.getVerificationMethodForSubjectId(\n agentContext,\n credentialInstance.credentialSubjectIds[0]\n )\n\n const w3cCredentialService = agentContext.resolve(W3cCredentialService)\n const w3cPresentation = new W3cPresentation({\n verifiableCredential: [credentialInstance],\n holder: verificationMethod.controller,\n })\n\n const publicJwk = getPublicJwkFromVerificationMethod(verificationMethod)\n\n const signedPresentation = await w3cCredentialService.signPresentation<ClaimFormat.JwtVp>(agentContext, {\n format: ClaimFormat.JwtVp,\n alg: publicJwk.signatureAlgorithm,\n verificationMethod: verificationMethod.id,\n presentation: w3cPresentation,\n challenge,\n domain,\n })\n\n encodedCreatedPresentation = signedPresentation.encoded\n createdPresentation = signedPresentation\n } else if (presentationToCreate.claimFormat === ClaimFormat.LdpVp) {\n const { credentialInstance } = await useInstanceFromCredentialRecord({\n agentContext,\n useMode: presentationToCreate.useMode,\n credentialRecord: presentationToCreate.credentialRecord,\n })\n\n if (!credentialInstance.credentialSubjectIds[0]) {\n throw new DcqlError('Cannot create presentation for credentials without subject id')\n }\n\n // Determine a suitable verification method for the presentation\n const verificationMethod = await this.getVerificationMethodForSubjectId(\n agentContext,\n credentialInstance.credentialSubjectIds[0]\n )\n\n const w3cCredentialService = agentContext.resolve(W3cCredentialService)\n const w3cPresentation = new W3cPresentation({\n verifiableCredential: [credentialInstance],\n holder: verificationMethod.controller,\n })\n\n const signedPresentation = await w3cCredentialService.signPresentation(agentContext, {\n format: ClaimFormat.LdpVp,\n // TODO: we should move the check for which proof to use for a presentation to earlier\n // as then we know when determining which VPs to submit already if the proof types are supported\n // by the verifier, and we can then just add this to the vpToCreate interface\n proofType: this.getProofTypeForLdpVc(agentContext, verificationMethod),\n proofPurpose: new purposes.AuthenticationProofPurpose({ challenge, domain }),\n verificationMethod: verificationMethod.id,\n presentation: w3cPresentation,\n challenge,\n domain,\n })\n\n encodedCreatedPresentation = signedPresentation.encoded\n createdPresentation = signedPresentation\n } else if (presentationToCreate.claimFormat === ClaimFormat.JwtW3cVp) {\n const w3cV2CredentialService = agentContext.resolve(W3cV2CredentialService)\n const w3cV2Presentation = new W3cV2Presentation({\n holder: presentationToCreate.credentialRecord.firstCredential.resolvedCredential.credentialSubjectIds[0],\n verifiableCredential: [\n W3cV2EnvelopedVerifiableCredential.fromVerifiableCredential(\n presentationToCreate.credentialRecord.firstCredential\n ),\n ],\n })\n\n const signedPresentation = await w3cV2CredentialService.signPresentation<ClaimFormat.JwtW3cVp>(agentContext, {\n format: ClaimFormat.JwtW3cVp,\n presentation: w3cV2Presentation,\n challenge,\n domain,\n })\n\n encodedCreatedPresentation = signedPresentation.encoded\n createdPresentation = signedPresentation\n } else if (presentationToCreate.claimFormat === ClaimFormat.SdJwtW3cVp) {\n const presentationFrame = buildDisclosureFrameForPayload(presentationToCreate.disclosedPayload)\n if (!domain) {\n throw new DcqlError('Missing domain property for creating SdJwtVc presentation.')\n }\n\n const w3cV2SdJwtCredentialService = agentContext.resolve(W3cV2SdJwtCredentialService)\n const sdJwtVc = await w3cV2SdJwtCredentialService.present(agentContext, {\n credential: presentationToCreate.credentialRecord.firstCredential.encoded,\n presentationFrame,\n })\n\n const w3cV2CredentialService = agentContext.resolve(W3cV2CredentialService)\n const w3cV2Presentation = new W3cV2Presentation({\n holder: presentationToCreate.credentialRecord.firstCredential.resolvedCredential.credentialSchemaIds[0],\n verifiableCredential: [W3cV2EnvelopedVerifiableCredential.fromVerifiableCredential(sdJwtVc)],\n })\n\n const signedPresentation = await w3cV2CredentialService.signPresentation<ClaimFormat.SdJwtW3cVp>(\n agentContext,\n {\n format: ClaimFormat.SdJwtW3cVp,\n presentation: w3cV2Presentation,\n challenge,\n domain,\n }\n )\n\n encodedCreatedPresentation = signedPresentation.encoded\n createdPresentation = signedPresentation\n } else {\n throw new DcqlError('Unsupported presentation format.')\n }\n\n if (!dcqlPresentation[credentialQueryId]) {\n dcqlPresentation[credentialQueryId] = [createdPresentation]\n } else {\n dcqlPresentation[credentialQueryId].push(createdPresentation)\n }\n\n if (!encodedDcqlPresentation[credentialQueryId]) {\n encodedDcqlPresentation[credentialQueryId] = [encodedCreatedPresentation]\n } else {\n encodedDcqlPresentation[credentialQueryId].push(encodedCreatedPresentation)\n }\n }\n }\n\n return {\n dcqlPresentation,\n encodedDcqlPresentation,\n }\n }\n\n private getSdJwtVcApi(agentContext: AgentContext) {\n return agentContext.dependencyManager.resolve(SdJwtVcApi)\n }\n\n private getMdocApi(agentContext: AgentContext) {\n return agentContext.dependencyManager.resolve(MdocApi)\n }\n\n private async getVerificationMethodForSubjectId(agentContext: AgentContext, subjectId: string) {\n const didsApi = agentContext.dependencyManager.resolve(DidsApi)\n\n if (!subjectId.startsWith('did:')) {\n throw new DcqlError(`Only dids are supported as credentialSubject id. ${subjectId} is not a valid did`)\n }\n\n const didDocument = await didsApi.resolveDidDocument(subjectId)\n\n if (!didDocument.authentication || didDocument.authentication.length === 0) {\n throw new DcqlError(`No authentication verificationMethods found for did ${subjectId} in did document`)\n }\n\n // the signature suite to use for the presentation is dependant on the credentials we share.\n // 1. Get the verification method for this given proof purpose in this DID document\n let [verificationMethod] = didDocument.authentication\n if (typeof verificationMethod === 'string') {\n verificationMethod = didDocument.dereferenceKey(verificationMethod, ['authentication'])\n }\n\n return verificationMethod\n }\n\n // FIXME: We need to take into account OpenID4VP metadata (probably providing supported/allowed algs to the DCQL create presentation method)\n private getProofTypeForLdpVc(agentContext: AgentContext, verificationMethod: VerificationMethod) {\n // For each of the supported algs, find the key types, then find the proof types\n const signatureSuiteRegistry = agentContext.dependencyManager.resolve(SignatureSuiteRegistry)\n\n const publicJwk = getPublicJwkFromVerificationMethod(verificationMethod)\n const supportedSignatureSuites = signatureSuiteRegistry.getAllByPublicJwkType(publicJwk)\n if (supportedSignatureSuites.length === 0) {\n throw new DcqlError(\n `Couldn't find a supported signature suite for the given jwk ${publicJwk.jwkTypeHumanDescription}`\n )\n }\n\n return supportedSignatureSuites[0].proofType\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEO,wBAAMA,cAAY;;;;;CAKvB,MAAc,6BACZ,cACA,WAC0F;EAC1F,MAAM,UAAU,IAAI,IAAI,UAAU,YAAY,KAAK,MAAM,EAAE,OAAO,CAAC;EACnE,MAAMC,aAA8F,EAAE;EAEtG,MAAM,eAAe,UAAU,YAC5B,QAAQ,oBAAoB,gBAAgB,WAAW,WAAW,CAClE,KAAK,MAAM,EAAE,MAAM,cAAc;EAEpC,MAAM,UAAU,KAAK,WAAW,aAAa;AAC7C,MAAI,aAAa,OAAO,YAAY,YAAY,OAAU,EAAE;GAC1D,MAAM,cAAc,MAAM,QAAQ,eAAe,EAC/C,KAAK,aAAa,KAAK,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AQ,mBAAmB,UAAU;AAE/D,MAAI,CAAC,YAAY,kBAAkB,YAAY,eAAe,WAAW,EACvE,OAAM,IAAI,UAAU,uDAAuD,UAAU,kBAAkB;EAKzG,IAAI,CAAC,sBAAsB,YAAY;AACvC,MAAI,OAAO,uBAAuB,SAChC,sBAAqB,YAAY,eAAe,oBAAoB,CAAC,iBAAiB,CAAC;AAGzF,SAAO;;CAIT,AAAQ,qBAAqB,cAA4B,oBAAwC;EAE/F,MAAM,yBAAyB,aAAa,kBAAkB,QAAQ,uBAAuB;EAE7F,MAAM,YAAY,mCAAmC,mBAAmB;EACxE,MAAM,2BAA2B,uBAAuB,sBAAsB,UAAU;AACxF,MAAI,yBAAyB,WAAW,EACtC,OAAM,IAAI,UACR,+DAA+D,UAAU,0BAC1E;AAGH,SAAO,yBAAyB,GAAG;;;0BA10BtC,YAAY"}
|
|
@@ -5,8 +5,8 @@ import { CredoError } from "../../error/CredoError.mjs";
|
|
|
5
5
|
import { RecordNotFoundError } from "../../error/RecordNotFoundError.mjs";
|
|
6
6
|
import "../../error/index.mjs";
|
|
7
7
|
import { injectable } from "../../plugins/index.mjs";
|
|
8
|
-
import { __decorateMetadata } from "../../_virtual/_@oxc-project_runtime@0.
|
|
9
|
-
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.
|
|
8
|
+
import { __decorateMetadata } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
9
|
+
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
10
10
|
import "../../agent/index.mjs";
|
|
11
11
|
import { KeyManagementApi } from "../kms/KeyManagementApi.mjs";
|
|
12
12
|
import "../kms/index.mjs";
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { CredoError } from "../../../error/CredoError.mjs";
|
|
4
4
|
import "../../../error/index.mjs";
|
|
5
|
-
import { __decorateMetadata } from "../../../_virtual/_@oxc-project_runtime@0.
|
|
6
|
-
import { __decorate } from "../../../_virtual/_@oxc-project_runtime@0.
|
|
5
|
+
import { __decorateMetadata } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
6
|
+
import { __decorate } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
7
7
|
import { TypedArrayEncoder } from "../../../utils/TypedArrayEncoder.mjs";
|
|
8
8
|
import { JsonTransformer } from "../../../utils/JsonTransformer.mjs";
|
|
9
9
|
import { IsStringOrStringArray } from "../../../utils/transformers.mjs";
|
|
@@ -77,7 +77,7 @@ var DidDocument = class DidDocument {
|
|
|
77
77
|
const verificationMethod = typeof key === "string" ? this.dereferenceVerificationMethod(key) : key;
|
|
78
78
|
if (getPublicJwkFromVerificationMethod(verificationMethod).equals(publicJwk)) return verificationMethod;
|
|
79
79
|
}
|
|
80
|
-
throw new CredoError(`Unable to locate verification method with public key ${publicJwk.
|
|
80
|
+
throw new CredoError(`Unable to locate verification method with public key ${publicJwk.jwkTypeHumanDescription} in purposes ${purposes}`);
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Returns all of the service endpoints matching the given type.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DidDocument.mjs","names":["recipientKeys: Array<{\n verificationMethod: VerificationMethod\n publicJwk: PublicJwk<Ed25519PublicJwk | X25519PublicJwk>\n }>","seenVerificationMethodIds: string[]","key: VerificationMethod[] | (string | VerificationMethod)[] | undefined"],"sources":["../../../../src/modules/dids/domain/DidDocument.ts"],"sourcesContent":["import { Expose, Type } from 'class-transformer'\nimport { IsArray, IsOptional, IsString, ValidateNested } from 'class-validator'\nimport { CredoError } from '../../../error'\nimport { TypedArrayEncoder } from '../../../utils'\nimport { JsonTransformer } from '../../../utils/JsonTransformer'\nimport { IsStringOrStringArray } from '../../../utils/transformers'\nimport { Ed25519PublicJwk, PublicJwk, X25519PublicJwk } from '../../kms'\nimport { findMatchingEd25519Key } from '../findMatchingEd25519Key'\nimport { getPublicJwkFromVerificationMethod } from './key-type'\nimport type { DidDocumentService } from './service'\nimport { DidCommV1Service, IndyAgentService } from './service'\nimport { ServiceTransformer } from './service/ServiceTransformer'\nimport { IsStringOrVerificationMethod, VerificationMethod, VerificationMethodTransformer } from './verificationMethod'\n\nexport type DidPurpose =\n | 'authentication'\n | 'keyAgreement'\n | 'assertionMethod'\n | 'capabilityInvocation'\n | 'capabilityDelegation'\n\ntype DidVerificationMethods = DidPurpose | 'verificationMethod'\n\ninterface DidDocumentOptions {\n context?: string | string[]\n id: string\n alsoKnownAs?: string[]\n controller?: string | string[]\n verificationMethod?: VerificationMethod[]\n service?: DidDocumentService[]\n authentication?: Array<string | VerificationMethod>\n assertionMethod?: Array<string | VerificationMethod>\n keyAgreement?: Array<string | VerificationMethod>\n capabilityInvocation?: Array<string | VerificationMethod>\n capabilityDelegation?: Array<string | VerificationMethod>\n}\n\nexport class DidDocument {\n @Expose({ name: '@context' })\n @IsStringOrStringArray()\n public context: string | string[] = ['https://www.w3.org/ns/did/v1']\n\n @IsString()\n public id!: string\n\n @IsArray()\n @IsString({ each: true })\n @IsOptional()\n public alsoKnownAs?: string[]\n\n @IsStringOrStringArray()\n @IsOptional()\n public controller?: string | string[]\n\n @IsArray()\n @ValidateNested({ each: true })\n @Type(() => VerificationMethod)\n @IsOptional()\n public verificationMethod?: VerificationMethod[]\n\n @IsArray()\n @ServiceTransformer()\n @IsOptional()\n public service?: DidDocumentService[]\n\n @IsArray()\n @VerificationMethodTransformer()\n @IsStringOrVerificationMethod({ each: true })\n @IsOptional()\n public authentication?: Array<string | VerificationMethod>\n\n @IsArray()\n @VerificationMethodTransformer()\n @IsStringOrVerificationMethod({ each: true })\n @IsOptional()\n public assertionMethod?: Array<string | VerificationMethod>\n\n @IsArray()\n @VerificationMethodTransformer()\n @IsStringOrVerificationMethod({ each: true })\n @IsOptional()\n public keyAgreement?: Array<string | VerificationMethod>\n\n @IsArray()\n @VerificationMethodTransformer()\n @IsStringOrVerificationMethod({ each: true })\n @IsOptional()\n public capabilityInvocation?: Array<string | VerificationMethod>\n\n @IsArray()\n @VerificationMethodTransformer()\n @IsStringOrVerificationMethod({ each: true })\n @IsOptional()\n public capabilityDelegation?: Array<string | VerificationMethod>\n\n public constructor(options: DidDocumentOptions) {\n if (options) {\n this.context = options.context ?? this.context\n this.id = options.id\n this.alsoKnownAs = options.alsoKnownAs\n this.controller = options.controller\n this.verificationMethod = options.verificationMethod\n this.service = options.service\n this.authentication = options.authentication\n this.assertionMethod = options.assertionMethod\n this.keyAgreement = options.keyAgreement\n this.capabilityInvocation = options.capabilityInvocation\n this.capabilityDelegation = options.capabilityDelegation\n }\n }\n\n public dereferenceVerificationMethod(keyId: string) {\n // TODO: once we use JSON-LD we should use that to resolve references in did documents.\n // for now we check whether the key id ends with the keyId.\n // so if looking for #123 and key.id is did:key:123#123, it is valid. But #123 as key.id is also valid\n const verificationMethod = this.verificationMethod?.find((key) => key.id.endsWith(keyId))\n\n if (!verificationMethod) {\n throw new CredoError(`Unable to locate verification method with id '${keyId}'`)\n }\n\n return verificationMethod\n }\n\n public dereferenceKey(keyId: string, allowedPurposes?: DidVerificationMethods[]) {\n const allPurposes: DidVerificationMethods[] = [\n 'authentication',\n 'keyAgreement',\n 'assertionMethod',\n 'capabilityInvocation',\n 'capabilityDelegation',\n 'verificationMethod',\n ]\n\n const purposes = allowedPurposes ?? allPurposes\n\n for (const purpose of purposes) {\n for (const key of this[purpose] ?? []) {\n if (typeof key === 'string' && key.endsWith(keyId)) {\n return this.dereferenceVerificationMethod(key)\n }\n if (typeof key !== 'string' && key.id.endsWith(keyId)) {\n return key\n }\n }\n }\n\n throw new CredoError(`Unable to locate verification method with id '${keyId}' in purposes ${purposes}`)\n }\n\n public findVerificationMethodByPublicKey(publicJwk: PublicJwk, allowedPurposes?: DidVerificationMethods[]) {\n const allPurposes: DidVerificationMethods[] = [\n 'authentication',\n 'keyAgreement',\n 'assertionMethod',\n 'capabilityInvocation',\n 'capabilityDelegation',\n 'verificationMethod',\n ]\n\n const purposes = allowedPurposes ?? allPurposes\n\n for (const purpose of purposes) {\n for (const key of this[purpose] ?? []) {\n const verificationMethod = typeof key === 'string' ? this.dereferenceVerificationMethod(key) : key\n if (getPublicJwkFromVerificationMethod(verificationMethod).equals(publicJwk)) return verificationMethod\n }\n }\n\n throw new CredoError(\n `Unable to locate verification method with public key ${publicJwk.jwkTypehumanDescription} in purposes ${purposes}`\n )\n }\n\n /**\n * Returns all of the service endpoints matching the given type.\n *\n * @param type The type of service(s) to query.\n */\n public getServicesByType<S extends DidDocumentService = DidDocumentService>(type: string): S[] {\n return (this.service?.filter((service) => service.type === type) ?? []) as S[]\n }\n\n /**\n * Returns all of the service endpoints matching the given class\n *\n * @param classType The class to query services.\n */\n public getServicesByClassType<S extends DidDocumentService = DidDocumentService>(\n classType: new (...args: never[]) => S\n ): S[] {\n return (this.service?.filter((service) => service instanceof classType) ?? []) as S[]\n }\n\n /**\n * Get all DIDComm services ordered by priority descending. This means the highest\n * priority will be the first entry.\n */\n public get didCommServices(): Array<IndyAgentService | DidCommV1Service> {\n const didCommServiceTypes = [IndyAgentService.type, DidCommV1Service.type]\n const services = (this.service?.filter((service) => didCommServiceTypes.includes(service.type)) ?? []) as Array<\n IndyAgentService | DidCommV1Service\n >\n\n // Sort services based on indicated priority\n return services.sort((a, b) => a.priority - b.priority)\n }\n\n // TODO: it would probably be easier if we add a utility to each service so we don't have to handle logic for all service types here\n public get recipientKeys(): PublicJwk<Ed25519PublicJwk | X25519PublicJwk>[] {\n return this.getRecipientKeysWithVerificationMethod({\n // False for now to avoid breaking changes\n mapX25519ToEd25519: false,\n }).map(({ publicJwk }) => publicJwk)\n }\n\n /**\n * Returns the recipient keys with their verification method matches\n *\n * We should probably deprecate recipientKeys in favour of this one\n */\n public getRecipientKeysWithVerificationMethod<MapX25519ToEd25519 extends boolean>({\n mapX25519ToEd25519,\n }: {\n mapX25519ToEd25519: MapX25519ToEd25519\n }): Array<{\n verificationMethod: VerificationMethod\n publicJwk: PublicJwk<MapX25519ToEd25519 extends true ? Ed25519PublicJwk : Ed25519PublicJwk | X25519PublicJwk>\n }> {\n const recipientKeys: Array<{\n verificationMethod: VerificationMethod\n publicJwk: PublicJwk<Ed25519PublicJwk | X25519PublicJwk>\n }> = []\n\n const seenVerificationMethodIds: string[] = []\n for (const service of this.didCommServices) {\n if (service.type === IndyAgentService.type) {\n for (const publicKeyBase58 of service.recipientKeys) {\n const publicJwk = PublicJwk.fromPublicKey({\n kty: 'OKP',\n crv: 'Ed25519',\n publicKey: TypedArrayEncoder.fromBase58(publicKeyBase58),\n })\n const verificationMethod = [...(this.verificationMethod ?? []), ...(this.authentication ?? [])]\n .map((v) => (typeof v === 'string' ? this.dereferenceVerificationMethod(v) : v))\n .find((v) => {\n const vPublicJwk = getPublicJwkFromVerificationMethod(v)\n return vPublicJwk.equals(publicJwk)\n })\n\n if (!verificationMethod) {\n throw new CredoError('Could not find verification method for IndyAgentService recipient key')\n }\n\n // Skip adding if already present\n if (seenVerificationMethodIds.includes(verificationMethod.id)) {\n continue\n }\n\n recipientKeys.push({\n publicJwk,\n verificationMethod,\n })\n }\n } else if (service.type === DidCommV1Service.type) {\n for (const recipientKey of service.recipientKeys) {\n const verificationMethod = this.dereferenceKey(recipientKey, ['authentication', 'keyAgreement'])\n if (seenVerificationMethodIds.includes(verificationMethod.id)) {\n // Skip adding if already present\n continue\n }\n\n const publicJwk = getPublicJwkFromVerificationMethod(verificationMethod)\n\n if (!publicJwk.is(Ed25519PublicJwk, X25519PublicJwk)) {\n throw new CredoError(\n 'Expected either Ed25519PublicJwk or X25519PublicJwk for DidcommV1Service recipient key'\n )\n }\n\n recipientKeys.push({\n publicJwk,\n verificationMethod,\n })\n }\n }\n }\n\n if (!mapX25519ToEd25519) {\n return recipientKeys as Array<{\n verificationMethod: VerificationMethod\n publicJwk: PublicJwk<MapX25519ToEd25519 extends true ? Ed25519PublicJwk : Ed25519PublicJwk | X25519PublicJwk>\n }>\n }\n\n return recipientKeys.map(({ publicJwk, verificationMethod }) => {\n if (publicJwk.is(Ed25519PublicJwk)) return { publicJwk, verificationMethod }\n\n const matchingEd25519Key = findMatchingEd25519Key(publicJwk as PublicJwk<X25519PublicJwk>, this)\n\n // For DIDcomm v1 if you use X25519 you MUST also include the Ed25519 key\n if (!matchingEd25519Key) {\n throw new CredoError(\n `Unable to find matching Ed25519 key for X25519 verification method with id ${verificationMethod.id}`\n )\n }\n\n return matchingEd25519Key\n })\n }\n\n public toJSON() {\n return JsonTransformer.toJSON(this)\n }\n\n public static fromJSON(didDocument: unknown) {\n return JsonTransformer.fromJSON(didDocument, DidDocument)\n }\n}\n\n/**\n * Extracting the verification method for signature type\n * @param type Signature type\n * @param didDocument DidDocument\n * @returns verification method\n */\nexport async function findVerificationMethodByKeyType(\n keyType: string,\n didDocument: DidDocument\n): Promise<VerificationMethod | null> {\n const didVerificationMethods: DidVerificationMethods[] = [\n 'verificationMethod',\n 'authentication',\n 'keyAgreement',\n 'assertionMethod',\n 'capabilityInvocation',\n 'capabilityDelegation',\n ]\n for (const purpose of didVerificationMethods) {\n const key: VerificationMethod[] | (string | VerificationMethod)[] | undefined = didDocument[purpose]\n if (Array.isArray(key)) {\n for (const method of key) {\n if (typeof method !== 'string') {\n if (method.type === keyType) {\n return method\n }\n }\n }\n }\n }\n\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAa,cAAb,MAAa,YAAY;CA0DvB,AAAO,YAAY,SAA6B;OAvDzC,UAA6B,CAAC,+BAA+B;AAwDlE,MAAI,SAAS;AACX,QAAK,UAAU,QAAQ,WAAW,KAAK;AACvC,QAAK,KAAK,QAAQ;AAClB,QAAK,cAAc,QAAQ;AAC3B,QAAK,aAAa,QAAQ;AAC1B,QAAK,qBAAqB,QAAQ;AAClC,QAAK,UAAU,QAAQ;AACvB,QAAK,iBAAiB,QAAQ;AAC9B,QAAK,kBAAkB,QAAQ;AAC/B,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;EACA;EACA;EACA;EACA;EACA;EACD,EAC6C;EAC5C,MAAMC,MAA0E,YAAY;AAC5F,MAAI,MAAM,QAAQ,IAAI,EACpB;QAAK,MAAM,UAAU,IACnB,KAAI,OAAO,WAAW,UACpB;QAAI,OAAO,SAAS,QAClB,QAAO;;;;AAOjB,QAAO"}
|
|
1
|
+
{"version":3,"file":"DidDocument.mjs","names":["recipientKeys: Array<{\n verificationMethod: VerificationMethod\n publicJwk: PublicJwk<Ed25519PublicJwk | X25519PublicJwk>\n }>","seenVerificationMethodIds: string[]","key: VerificationMethod[] | (string | VerificationMethod)[] | undefined"],"sources":["../../../../src/modules/dids/domain/DidDocument.ts"],"sourcesContent":["import { Expose, Type } from 'class-transformer'\nimport { IsArray, IsOptional, IsString, ValidateNested } from 'class-validator'\nimport { CredoError } from '../../../error'\nimport { TypedArrayEncoder } from '../../../utils'\nimport { JsonTransformer } from '../../../utils/JsonTransformer'\nimport { IsStringOrStringArray } from '../../../utils/transformers'\nimport { Ed25519PublicJwk, PublicJwk, X25519PublicJwk } from '../../kms'\nimport { findMatchingEd25519Key } from '../findMatchingEd25519Key'\nimport { getPublicJwkFromVerificationMethod } from './key-type'\nimport type { DidDocumentService } from './service'\nimport { DidCommV1Service, IndyAgentService } from './service'\nimport { ServiceTransformer } from './service/ServiceTransformer'\nimport { IsStringOrVerificationMethod, VerificationMethod, VerificationMethodTransformer } from './verificationMethod'\n\nexport type DidPurpose =\n | 'authentication'\n | 'keyAgreement'\n | 'assertionMethod'\n | 'capabilityInvocation'\n | 'capabilityDelegation'\n\ntype DidVerificationMethods = DidPurpose | 'verificationMethod'\n\ninterface DidDocumentOptions {\n context?: string | string[]\n id: string\n alsoKnownAs?: string[]\n controller?: string | string[]\n verificationMethod?: VerificationMethod[]\n service?: DidDocumentService[]\n authentication?: Array<string | VerificationMethod>\n assertionMethod?: Array<string | VerificationMethod>\n keyAgreement?: Array<string | VerificationMethod>\n capabilityInvocation?: Array<string | VerificationMethod>\n capabilityDelegation?: Array<string | VerificationMethod>\n}\n\nexport class DidDocument {\n @Expose({ name: '@context' })\n @IsStringOrStringArray()\n public context: string | string[] = ['https://www.w3.org/ns/did/v1']\n\n @IsString()\n public id!: string\n\n @IsArray()\n @IsString({ each: true })\n @IsOptional()\n public alsoKnownAs?: string[]\n\n @IsStringOrStringArray()\n @IsOptional()\n public controller?: string | string[]\n\n @IsArray()\n @ValidateNested({ each: true })\n @Type(() => VerificationMethod)\n @IsOptional()\n public verificationMethod?: VerificationMethod[]\n\n @IsArray()\n @ServiceTransformer()\n @IsOptional()\n public service?: DidDocumentService[]\n\n @IsArray()\n @VerificationMethodTransformer()\n @IsStringOrVerificationMethod({ each: true })\n @IsOptional()\n public authentication?: Array<string | VerificationMethod>\n\n @IsArray()\n @VerificationMethodTransformer()\n @IsStringOrVerificationMethod({ each: true })\n @IsOptional()\n public assertionMethod?: Array<string | VerificationMethod>\n\n @IsArray()\n @VerificationMethodTransformer()\n @IsStringOrVerificationMethod({ each: true })\n @IsOptional()\n public keyAgreement?: Array<string | VerificationMethod>\n\n @IsArray()\n @VerificationMethodTransformer()\n @IsStringOrVerificationMethod({ each: true })\n @IsOptional()\n public capabilityInvocation?: Array<string | VerificationMethod>\n\n @IsArray()\n @VerificationMethodTransformer()\n @IsStringOrVerificationMethod({ each: true })\n @IsOptional()\n public capabilityDelegation?: Array<string | VerificationMethod>\n\n public constructor(options: DidDocumentOptions) {\n if (options) {\n this.context = options.context ?? this.context\n this.id = options.id\n this.alsoKnownAs = options.alsoKnownAs\n this.controller = options.controller\n this.verificationMethod = options.verificationMethod\n this.service = options.service\n this.authentication = options.authentication\n this.assertionMethod = options.assertionMethod\n this.keyAgreement = options.keyAgreement\n this.capabilityInvocation = options.capabilityInvocation\n this.capabilityDelegation = options.capabilityDelegation\n }\n }\n\n public dereferenceVerificationMethod(keyId: string) {\n // TODO: once we use JSON-LD we should use that to resolve references in did documents.\n // for now we check whether the key id ends with the keyId.\n // so if looking for #123 and key.id is did:key:123#123, it is valid. But #123 as key.id is also valid\n const verificationMethod = this.verificationMethod?.find((key) => key.id.endsWith(keyId))\n\n if (!verificationMethod) {\n throw new CredoError(`Unable to locate verification method with id '${keyId}'`)\n }\n\n return verificationMethod\n }\n\n public dereferenceKey(keyId: string, allowedPurposes?: DidVerificationMethods[]) {\n const allPurposes: DidVerificationMethods[] = [\n 'authentication',\n 'keyAgreement',\n 'assertionMethod',\n 'capabilityInvocation',\n 'capabilityDelegation',\n 'verificationMethod',\n ]\n\n const purposes = allowedPurposes ?? allPurposes\n\n for (const purpose of purposes) {\n for (const key of this[purpose] ?? []) {\n if (typeof key === 'string' && key.endsWith(keyId)) {\n return this.dereferenceVerificationMethod(key)\n }\n if (typeof key !== 'string' && key.id.endsWith(keyId)) {\n return key\n }\n }\n }\n\n throw new CredoError(`Unable to locate verification method with id '${keyId}' in purposes ${purposes}`)\n }\n\n public findVerificationMethodByPublicKey(publicJwk: PublicJwk, allowedPurposes?: DidVerificationMethods[]) {\n const allPurposes: DidVerificationMethods[] = [\n 'authentication',\n 'keyAgreement',\n 'assertionMethod',\n 'capabilityInvocation',\n 'capabilityDelegation',\n 'verificationMethod',\n ]\n\n const purposes = allowedPurposes ?? allPurposes\n\n for (const purpose of purposes) {\n for (const key of this[purpose] ?? []) {\n const verificationMethod = typeof key === 'string' ? this.dereferenceVerificationMethod(key) : key\n if (getPublicJwkFromVerificationMethod(verificationMethod).equals(publicJwk)) return verificationMethod\n }\n }\n\n throw new CredoError(\n `Unable to locate verification method with public key ${publicJwk.jwkTypeHumanDescription} in purposes ${purposes}`\n )\n }\n\n /**\n * Returns all of the service endpoints matching the given type.\n *\n * @param type The type of service(s) to query.\n */\n public getServicesByType<S extends DidDocumentService = DidDocumentService>(type: string): S[] {\n return (this.service?.filter((service) => service.type === type) ?? []) as S[]\n }\n\n /**\n * Returns all of the service endpoints matching the given class\n *\n * @param classType The class to query services.\n */\n public getServicesByClassType<S extends DidDocumentService = DidDocumentService>(\n classType: new (...args: never[]) => S\n ): S[] {\n return (this.service?.filter((service) => service instanceof classType) ?? []) as S[]\n }\n\n /**\n * Get all DIDComm services ordered by priority descending. This means the highest\n * priority will be the first entry.\n */\n public get didCommServices(): Array<IndyAgentService | DidCommV1Service> {\n const didCommServiceTypes = [IndyAgentService.type, DidCommV1Service.type]\n const services = (this.service?.filter((service) => didCommServiceTypes.includes(service.type)) ?? []) as Array<\n IndyAgentService | DidCommV1Service\n >\n\n // Sort services based on indicated priority\n return services.sort((a, b) => a.priority - b.priority)\n }\n\n // TODO: it would probably be easier if we add a utility to each service so we don't have to handle logic for all service types here\n public get recipientKeys(): PublicJwk<Ed25519PublicJwk | X25519PublicJwk>[] {\n return this.getRecipientKeysWithVerificationMethod({\n // False for now to avoid breaking changes\n mapX25519ToEd25519: false,\n }).map(({ publicJwk }) => publicJwk)\n }\n\n /**\n * Returns the recipient keys with their verification method matches\n *\n * We should probably deprecate recipientKeys in favour of this one\n */\n public getRecipientKeysWithVerificationMethod<MapX25519ToEd25519 extends boolean>({\n mapX25519ToEd25519,\n }: {\n mapX25519ToEd25519: MapX25519ToEd25519\n }): Array<{\n verificationMethod: VerificationMethod\n publicJwk: PublicJwk<MapX25519ToEd25519 extends true ? Ed25519PublicJwk : Ed25519PublicJwk | X25519PublicJwk>\n }> {\n const recipientKeys: Array<{\n verificationMethod: VerificationMethod\n publicJwk: PublicJwk<Ed25519PublicJwk | X25519PublicJwk>\n }> = []\n\n const seenVerificationMethodIds: string[] = []\n for (const service of this.didCommServices) {\n if (service.type === IndyAgentService.type) {\n for (const publicKeyBase58 of service.recipientKeys) {\n const publicJwk = PublicJwk.fromPublicKey({\n kty: 'OKP',\n crv: 'Ed25519',\n publicKey: TypedArrayEncoder.fromBase58(publicKeyBase58),\n })\n const verificationMethod = [...(this.verificationMethod ?? []), ...(this.authentication ?? [])]\n .map((v) => (typeof v === 'string' ? this.dereferenceVerificationMethod(v) : v))\n .find((v) => {\n const vPublicJwk = getPublicJwkFromVerificationMethod(v)\n return vPublicJwk.equals(publicJwk)\n })\n\n if (!verificationMethod) {\n throw new CredoError('Could not find verification method for IndyAgentService recipient key')\n }\n\n // Skip adding if already present\n if (seenVerificationMethodIds.includes(verificationMethod.id)) {\n continue\n }\n\n recipientKeys.push({\n publicJwk,\n verificationMethod,\n })\n }\n } else if (service.type === DidCommV1Service.type) {\n for (const recipientKey of service.recipientKeys) {\n const verificationMethod = this.dereferenceKey(recipientKey, ['authentication', 'keyAgreement'])\n if (seenVerificationMethodIds.includes(verificationMethod.id)) {\n // Skip adding if already present\n continue\n }\n\n const publicJwk = getPublicJwkFromVerificationMethod(verificationMethod)\n\n if (!publicJwk.is(Ed25519PublicJwk, X25519PublicJwk)) {\n throw new CredoError(\n 'Expected either Ed25519PublicJwk or X25519PublicJwk for DidcommV1Service recipient key'\n )\n }\n\n recipientKeys.push({\n publicJwk,\n verificationMethod,\n })\n }\n }\n }\n\n if (!mapX25519ToEd25519) {\n return recipientKeys as Array<{\n verificationMethod: VerificationMethod\n publicJwk: PublicJwk<MapX25519ToEd25519 extends true ? Ed25519PublicJwk : Ed25519PublicJwk | X25519PublicJwk>\n }>\n }\n\n return recipientKeys.map(({ publicJwk, verificationMethod }) => {\n if (publicJwk.is(Ed25519PublicJwk)) return { publicJwk, verificationMethod }\n\n const matchingEd25519Key = findMatchingEd25519Key(publicJwk as PublicJwk<X25519PublicJwk>, this)\n\n // For DIDcomm v1 if you use X25519 you MUST also include the Ed25519 key\n if (!matchingEd25519Key) {\n throw new CredoError(\n `Unable to find matching Ed25519 key for X25519 verification method with id ${verificationMethod.id}`\n )\n }\n\n return matchingEd25519Key\n })\n }\n\n public toJSON() {\n return JsonTransformer.toJSON(this)\n }\n\n public static fromJSON(didDocument: unknown) {\n return JsonTransformer.fromJSON(didDocument, DidDocument)\n }\n}\n\n/**\n * Extracting the verification method for signature type\n * @param type Signature type\n * @param didDocument DidDocument\n * @returns verification method\n */\nexport async function findVerificationMethodByKeyType(\n keyType: string,\n didDocument: DidDocument\n): Promise<VerificationMethod | null> {\n const didVerificationMethods: DidVerificationMethods[] = [\n 'verificationMethod',\n 'authentication',\n 'keyAgreement',\n 'assertionMethod',\n 'capabilityInvocation',\n 'capabilityDelegation',\n ]\n for (const purpose of didVerificationMethods) {\n const key: VerificationMethod[] | (string | VerificationMethod)[] | undefined = didDocument[purpose]\n if (Array.isArray(key)) {\n for (const method of key) {\n if (typeof method !== 'string') {\n if (method.type === keyType) {\n return method\n }\n }\n }\n }\n }\n\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAa,cAAb,MAAa,YAAY;CA0DvB,AAAO,YAAY,SAA6B;OAvDzC,UAA6B,CAAC,+BAA+B;AAwDlE,MAAI,SAAS;AACX,QAAK,UAAU,QAAQ,WAAW,KAAK;AACvC,QAAK,KAAK,QAAQ;AAClB,QAAK,cAAc,QAAQ;AAC3B,QAAK,aAAa,QAAQ;AAC1B,QAAK,qBAAqB,QAAQ;AAClC,QAAK,UAAU,QAAQ;AACvB,QAAK,iBAAiB,QAAQ;AAC9B,QAAK,kBAAkB,QAAQ;AAC/B,QAAK,eAAe,QAAQ;AAC5B,QAAK,uBAAuB,QAAQ;AACpC,QAAK,uBAAuB,QAAQ;;;CAIxC,AAAO,8BAA8B,OAAe;EAIlD,MAAM,qBAAqB,KAAK,oBAAoB,MAAM,QAAQ,IAAI,GAAG,SAAS,MAAM,CAAC;AAEzF,MAAI,CAAC,mBACH,OAAM,IAAI,WAAW,iDAAiD,MAAM,GAAG;AAGjF,SAAO;;CAGT,AAAO,eAAe,OAAe,iBAA4C;EAU/E,MAAM,WAAW,mBAT6B;GAC5C;GACA;GACA;GACA;GACA;GACA;GACD;AAID,OAAK,MAAM,WAAW,SACpB,MAAK,MAAM,OAAO,KAAK,YAAY,EAAE,EAAE;AACrC,OAAI,OAAO,QAAQ,YAAY,IAAI,SAAS,MAAM,CAChD,QAAO,KAAK,8BAA8B,IAAI;AAEhD,OAAI,OAAO,QAAQ,YAA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SAAS,EAAE,MAAM,MAAM,CAAC;CACxB,YAAY;;;;CAGZ,uBAAuB;CACvB,YAAY;;;;CAGZ,SAAS;CACT,eAAe,EAAE,MAAM,MAAM,CAAC;CAC9B,WAAW,mBAAmB;CAC9B,YAAY;;;;CAGZ,SAAS;CACT,oBAAoB;CACpB,YAAY;;;;CAGZ,SAAS;CACT,+BAA+B;CAC/B,6BAA6B,EAAE,MAAM,MAAM,CAAC;CAC5C,YAAY;;;;CAGZ,SAAS;CACT,+BAA+B;CAC/B,6BAA6B,EAAE,MAAM,MAAM,CAAC;CAC5C,YAAY;;;;CAGZ,SAAS;CACT,+BAA+B;CAC/B,6BAA6B,EAAE,MAAM,MAAM,CAAC;CAC5C,YAAY;;;;CAGZ,SAAS;CACT,+BAA+B;CAC/B,6BAA6B,EAAE,MAAM,MAAM,CAAC;CAC5C,YAAY;;;;CAGZ,SAAS;CACT,+BAA+B;CAC/B,6BAA6B,EAAE,MAAM,MAAM,CAAC;CAC5C,YAAY;;;;;;;;;AA0Of,eAAsB,gCACpB,SACA,aACoC;AASpC,MAAK,MAAM,WAR8C;EACvD;EACA;EACA;EACA;EACA;EACA;EACD,EAC6C;EAC5C,MAAMC,MAA0E,YAAY;AAC5F,MAAI,MAAM,QAAQ,IAAI,EACpB;QAAK,MAAM,UAAU,IACnB,KAAI,OAAO,WAAW,UACpB;QAAI,OAAO,SAAS,QAClB,QAAO;;;;AAOjB,QAAO"}
|
|
@@ -37,7 +37,7 @@ function getPublicJwkFromVerificationMethod(verificationMethod) {
|
|
|
37
37
|
function getKeyDidMappingByPublicJwk(jwk) {
|
|
38
38
|
const jwkTypeClass = jwk instanceof PublicJwk ? jwk.JwkClass : jwk;
|
|
39
39
|
const keyDid = supportedKeyDids.find((supportedKeyDid) => supportedKeyDid.PublicJwkTypes.includes(jwkTypeClass));
|
|
40
|
-
if (!keyDid) throw new CredoError(`Unsupported did mapping for jwk '${jwk instanceof PublicJwk ? jwk.
|
|
40
|
+
if (!keyDid) throw new CredoError(`Unsupported did mapping for jwk '${jwk instanceof PublicJwk ? jwk.jwkTypeHumanDescription : jwk.name}'`);
|
|
41
41
|
return keyDid;
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyDidMapping.mjs","names":["keyDid"],"sources":["../../../../../src/modules/dids/domain/key-type/keyDidMapping.ts"],"sourcesContent":["import { CredoError } from '../../../../error'\nimport type { Constructor } from '../../../../utils/mixins'\nimport { PublicJwk } from '../../../kms'\nimport type { SupportedPublicJwkClass } from '../../../kms/jwk/PublicJwk'\nimport type { VerificationMethod } from '../verificationMethod'\nimport { getPublicJwkFromMultikey, isMultikey } from '../verificationMethod'\nimport { getPublicJwkFromJsonWebKey2020, isJsonWebKey2020 } from '../verificationMethod/JsonWebKey2020'\nimport { keyDidEd25519 } from './ed25519'\nimport { keyDidJsonWebKey } from './keyDidJsonWebKey'\nimport { keyDidSecp256k1 } from './secp256k1'\nimport { keyDidX25519 } from './x25519'\n\nexport interface KeyDidMapping<\n PublicJwkType extends InstanceType<SupportedPublicJwkClass> = InstanceType<SupportedPublicJwkClass>,\n> {\n PublicJwkTypes: Array<Constructor<PublicJwkType>>\n getVerificationMethods: (did: string, publicJwk: PublicJwk<PublicJwkType>) => VerificationMethod[]\n getPublicJwkFromVerificationMethod(verificationMethod: VerificationMethod): PublicJwk\n supportedVerificationMethodTypes: string[]\n}\n\nconst supportedKeyDids = [keyDidEd25519, keyDidX25519, keyDidJsonWebKey, keyDidSecp256k1]\n\n// TODO: at some point we should update all usages to Jwk / Multikey methods\n// so we don't need key type specific verification methods anymore\nexport function getVerificationMethodsForPublicJwk(publicJwk: PublicJwk, did: string) {\n const { getVerificationMethods } = getKeyDidMappingByPublicJwk(publicJwk)\n\n return getVerificationMethods(did, publicJwk)\n}\n\nexport function getSupportedVerificationMethodTypesForPublicJwk(\n publicJwk: PublicJwk | SupportedPublicJwkClass\n): string[] {\n const { supportedVerificationMethodTypes } = getKeyDidMappingByPublicJwk(publicJwk)\n\n return supportedVerificationMethodTypes\n}\n\nexport function getPublicJwkFromVerificationMethod(verificationMethod: VerificationMethod): PublicJwk {\n // This is a special verification method, as it supports basically all key types.\n if (isJsonWebKey2020(verificationMethod)) {\n return getPublicJwkFromJsonWebKey2020(verificationMethod)\n }\n\n if (isMultikey(verificationMethod)) {\n return getPublicJwkFromMultikey(verificationMethod)\n }\n\n const keyDid = supportedKeyDids.find((keyDid) =>\n keyDid.supportedVerificationMethodTypes.includes(verificationMethod.type)\n )\n if (!keyDid) {\n throw new CredoError(`Unsupported key did from verification method type '${verificationMethod.type}'`)\n }\n\n return keyDid.getPublicJwkFromVerificationMethod(verificationMethod)\n}\n\nfunction getKeyDidMappingByPublicJwk(jwk: PublicJwk | SupportedPublicJwkClass): KeyDidMapping {\n const jwkTypeClass = jwk instanceof PublicJwk ? jwk.JwkClass : jwk\n\n const keyDid = supportedKeyDids.find((supportedKeyDid) =>\n // biome-ignore lint/suspicious/noExplicitAny: no explanation\n supportedKeyDid.PublicJwkTypes.includes(jwkTypeClass as any)\n )\n\n if (!keyDid) {\n throw new CredoError(\n `Unsupported did mapping for jwk '${jwk instanceof PublicJwk ? jwk.
|
|
1
|
+
{"version":3,"file":"keyDidMapping.mjs","names":["keyDid"],"sources":["../../../../../src/modules/dids/domain/key-type/keyDidMapping.ts"],"sourcesContent":["import { CredoError } from '../../../../error'\nimport type { Constructor } from '../../../../utils/mixins'\nimport { PublicJwk } from '../../../kms'\nimport type { SupportedPublicJwkClass } from '../../../kms/jwk/PublicJwk'\nimport type { VerificationMethod } from '../verificationMethod'\nimport { getPublicJwkFromMultikey, isMultikey } from '../verificationMethod'\nimport { getPublicJwkFromJsonWebKey2020, isJsonWebKey2020 } from '../verificationMethod/JsonWebKey2020'\nimport { keyDidEd25519 } from './ed25519'\nimport { keyDidJsonWebKey } from './keyDidJsonWebKey'\nimport { keyDidSecp256k1 } from './secp256k1'\nimport { keyDidX25519 } from './x25519'\n\nexport interface KeyDidMapping<\n PublicJwkType extends InstanceType<SupportedPublicJwkClass> = InstanceType<SupportedPublicJwkClass>,\n> {\n PublicJwkTypes: Array<Constructor<PublicJwkType>>\n getVerificationMethods: (did: string, publicJwk: PublicJwk<PublicJwkType>) => VerificationMethod[]\n getPublicJwkFromVerificationMethod(verificationMethod: VerificationMethod): PublicJwk\n supportedVerificationMethodTypes: string[]\n}\n\nconst supportedKeyDids = [keyDidEd25519, keyDidX25519, keyDidJsonWebKey, keyDidSecp256k1]\n\n// TODO: at some point we should update all usages to Jwk / Multikey methods\n// so we don't need key type specific verification methods anymore\nexport function getVerificationMethodsForPublicJwk(publicJwk: PublicJwk, did: string) {\n const { getVerificationMethods } = getKeyDidMappingByPublicJwk(publicJwk)\n\n return getVerificationMethods(did, publicJwk)\n}\n\nexport function getSupportedVerificationMethodTypesForPublicJwk(\n publicJwk: PublicJwk | SupportedPublicJwkClass\n): string[] {\n const { supportedVerificationMethodTypes } = getKeyDidMappingByPublicJwk(publicJwk)\n\n return supportedVerificationMethodTypes\n}\n\nexport function getPublicJwkFromVerificationMethod(verificationMethod: VerificationMethod): PublicJwk {\n // This is a special verification method, as it supports basically all key types.\n if (isJsonWebKey2020(verificationMethod)) {\n return getPublicJwkFromJsonWebKey2020(verificationMethod)\n }\n\n if (isMultikey(verificationMethod)) {\n return getPublicJwkFromMultikey(verificationMethod)\n }\n\n const keyDid = supportedKeyDids.find((keyDid) =>\n keyDid.supportedVerificationMethodTypes.includes(verificationMethod.type)\n )\n if (!keyDid) {\n throw new CredoError(`Unsupported key did from verification method type '${verificationMethod.type}'`)\n }\n\n return keyDid.getPublicJwkFromVerificationMethod(verificationMethod)\n}\n\nfunction getKeyDidMappingByPublicJwk(jwk: PublicJwk | SupportedPublicJwkClass): KeyDidMapping {\n const jwkTypeClass = jwk instanceof PublicJwk ? jwk.JwkClass : jwk\n\n const keyDid = supportedKeyDids.find((supportedKeyDid) =>\n // biome-ignore lint/suspicious/noExplicitAny: no explanation\n supportedKeyDid.PublicJwkTypes.includes(jwkTypeClass as any)\n )\n\n if (!keyDid) {\n throw new CredoError(\n `Unsupported did mapping for jwk '${jwk instanceof PublicJwk ? jwk.jwkTypeHumanDescription : jwk.name}'`\n )\n }\n\n return keyDid as KeyDidMapping\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,MAAM,mBAAmB;CAAC;CAAe;CAAc;CAAkB;CAAgB;AAIzF,SAAgB,mCAAmC,WAAsB,KAAa;CACpF,MAAM,EAAE,2BAA2B,4BAA4B,UAAU;AAEzE,QAAO,uBAAuB,KAAK,UAAU;;AAG/C,SAAgB,gDACd,WACU;CACV,MAAM,EAAE,qCAAqC,4BAA4B,UAAU;AAEnF,QAAO;;AAGT,SAAgB,mCAAmC,oBAAmD;AAEpG,KAAI,iBAAiB,mBAAmB,CACtC,QAAO,+BAA+B,mBAAmB;AAG3D,KAAI,WAAW,mBAAmB,CAChC,QAAO,yBAAyB,mBAAmB;CAGrD,MAAM,SAAS,iBAAiB,MAAM,aACpCA,SAAO,iCAAiC,SAAS,mBAAmB,KAAK,CAC1E;AACD,KAAI,CAAC,OACH,OAAM,IAAI,WAAW,sDAAsD,mBAAmB,KAAK,GAAG;AAGxG,QAAO,OAAO,mCAAmC,mBAAmB;;AAGtE,SAAS,4BAA4B,KAAyD;CAC5F,MAAM,eAAe,eAAe,YAAY,IAAI,WAAW;CAE/D,MAAM,SAAS,iBAAiB,MAAM,oBAEpC,gBAAgB,eAAe,SAAS,aAAoB,CAC7D;AAED,KAAI,CAAC,OACH,OAAM,IAAI,WACR,oCAAoC,eAAe,YAAY,IAAI,0BAA0B,IAAI,KAAK,GACvG;AAGH,QAAO"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.
|
|
4
|
-
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
+
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
4
|
+
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
5
5
|
import { IsUri } from "../../../../utils/validators.mjs";
|
|
6
6
|
import "../../../../utils/index.mjs";
|
|
7
7
|
import { getProtocolScheme } from "../../../../utils/uri.mjs";
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { CredoError } from "../../../../error/CredoError.mjs";
|
|
4
4
|
import "../../../../error/index.mjs";
|
|
5
|
-
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.
|
|
6
|
-
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.
|
|
5
|
+
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
6
|
+
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
7
7
|
import { IsInstanceOrArrayOfInstances, IsUri } from "../../../../utils/validators.mjs";
|
|
8
8
|
import "../../../../utils/index.mjs";
|
|
9
9
|
import { DidDocumentService } from "./DidDocumentService.mjs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.
|
|
4
|
-
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
+
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
4
|
+
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
5
5
|
import { isJsonObject } from "../../../../types.mjs";
|
|
6
6
|
import { IsString, ValidateBy, buildMessage, isString } from "class-validator";
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.
|
|
4
|
-
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
+
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
4
|
+
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
5
5
|
import { IsUri } from "../../../../utils/validators.mjs";
|
|
6
6
|
import "../../../../utils/index.mjs";
|
|
7
7
|
import { getProtocolScheme } from "../../../../utils/uri.mjs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.
|
|
4
|
-
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
+
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
4
|
+
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
5
5
|
import { IsUri } from "../../../../utils/validators.mjs";
|
|
6
6
|
import "../../../../utils/index.mjs";
|
|
7
7
|
import { DidDocumentService } from "./DidDocumentService.mjs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.
|
|
4
|
-
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
+
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
4
|
+
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
5
5
|
import { IsOptional, IsString } from "class-validator";
|
|
6
6
|
|
|
7
7
|
//#region src/modules/dids/domain/verificationMethod/VerificationMethod.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { asymmetricPublicJwkMatches } from "../kms/jwk/equals.mjs";
|
|
4
4
|
import { X25519PublicJwk } from "../kms/jwk/kty/okp/X25519PublicJwk.mjs";
|
|
5
5
|
import { Ed25519PublicJwk } from "../kms/jwk/kty/okp/Ed25519PublicJwk.mjs";
|
|
6
6
|
import "../kms/index.mjs";
|
|
@@ -31,7 +31,7 @@ function findMatchingEd25519Key(x25519Key, didDocument) {
|
|
|
31
31
|
};
|
|
32
32
|
}).find((v) => {
|
|
33
33
|
if (!v.publicJwk.is(Ed25519PublicJwk)) return false;
|
|
34
|
-
return
|
|
34
|
+
return asymmetricPublicJwkMatches(v.publicJwk.convertTo(X25519PublicJwk).toJson(), x25519Key.toJson());
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findMatchingEd25519Key.mjs","names":[],"sources":["../../../src/modules/dids/findMatchingEd25519Key.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"findMatchingEd25519Key.mjs","names":[],"sources":["../../../src/modules/dids/findMatchingEd25519Key.ts"],"sourcesContent":["import { asymmetricPublicJwkMatches, Ed25519PublicJwk, PublicJwk, X25519PublicJwk } from '../kms'\nimport { DidDocument } from './domain/DidDocument'\nimport { getPublicJwkFromVerificationMethod } from './domain/key-type/keyDidMapping'\nimport { VerificationMethod } from './domain/verificationMethod'\n\n/**\n * Tries to find a matching Ed25519 key to the supplied X25519 key\n * @param x25519Key X25519 key\n * @param didDocument Did document containing all the keys\n * @returns a matching Ed25519 key or `undefined` (if no matching key found)\n */\nexport function findMatchingEd25519Key(\n x25519Key: PublicJwk<X25519PublicJwk>,\n didDocument: DidDocument\n): { publicJwk: PublicJwk<Ed25519PublicJwk>; verificationMethod: VerificationMethod } | undefined {\n const verificationMethods = didDocument.verificationMethod ?? []\n const keyAgreements = didDocument.keyAgreement ?? []\n const authentications = didDocument.authentication ?? []\n const allKeyReferences: VerificationMethod[] = [\n ...verificationMethods,\n ...authentications.filter((keyAgreement): keyAgreement is VerificationMethod => typeof keyAgreement !== 'string'),\n ...keyAgreements.filter((keyAgreement): keyAgreement is VerificationMethod => typeof keyAgreement !== 'string'),\n ]\n\n return allKeyReferences\n .map((keyReference) => {\n const verificationMethod = didDocument.dereferenceKey(keyReference.id)\n return {\n publicJwk: getPublicJwkFromVerificationMethod(verificationMethod),\n verificationMethod,\n }\n })\n\n .find((v): v is typeof v & { publicJwk: PublicJwk<Ed25519PublicJwk> } => {\n if (!v.publicJwk.is(Ed25519PublicJwk)) return false\n\n const keyX25519 = v.publicJwk.convertTo(X25519PublicJwk)\n return asymmetricPublicJwkMatches(keyX25519.toJson(), x25519Key.toJson())\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAWA,SAAgB,uBACd,WACA,aACgG;CAChG,MAAM,sBAAsB,YAAY,sBAAsB,EAAE;CAChE,MAAM,gBAAgB,YAAY,gBAAgB,EAAE;CACpD,MAAM,kBAAkB,YAAY,kBAAkB,EAAE;AAOxD,QAN+C;EAC7C,GAAG;EACH,GAAG,gBAAgB,QAAQ,iBAAqD,OAAO,iBAAiB,SAAS;EACjH,GAAG,cAAc,QAAQ,iBAAqD,OAAO,iBAAiB,SAAS;EAChH,CAGE,KAAK,iBAAiB;EACrB,MAAM,qBAAqB,YAAY,eAAe,aAAa,GAAG;AACtE,SAAO;GACL,WAAW,mCAAmC,mBAAmB;GACjE;GACD;GACD,CAED,MAAM,MAAkE;AACvE,MAAI,CAAC,EAAE,UAAU,GAAG,iBAAiB,CAAE,QAAO;AAG9C,SAAO,2BADW,EAAE,UAAU,UAAU,gBAAgB,CACZ,QAAQ,EAAE,UAAU,QAAQ,CAAC;GACzE"}
|
|
@@ -29,7 +29,7 @@ function verkeyToDidKey(verkey) {
|
|
|
29
29
|
function didKeyToEd25519PublicJwk(key) {
|
|
30
30
|
const didKey = DidKey.fromDid(key);
|
|
31
31
|
if (didKey.publicJwk.is(Ed25519PublicJwk)) return didKey.publicJwk;
|
|
32
|
-
throw new CredoError(`Expected public jwk to have kty OKP with crv Ed25519, found ${didKey.publicJwk.
|
|
32
|
+
throw new CredoError(`Expected public jwk to have kty OKP with crv Ed25519, found ${didKey.publicJwk.jwkTypeHumanDescription}`);
|
|
33
33
|
}
|
|
34
34
|
function verkeyToPublicJwk(verkey) {
|
|
35
35
|
return PublicJwk.fromPublicKey({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../src/modules/dids/helpers.ts"],"sourcesContent":["import { CredoError } from '../../error'\nimport { isDid, TypedArrayEncoder } from '../../utils'\nimport { Ed25519PublicJwk, PublicJwk } from '../kms'\n\nimport { DidKey } from './methods/key/DidKey'\n\nexport function isDidKey(key: string) {\n return isDid(key, 'key')\n}\n\nexport function didKeyToVerkey(key: string) {\n if (isDidKey(key)) {\n const publicKey = DidKey.fromDid(key).publicJwk.publicKey\n if (publicKey.kty !== 'OKP' || publicKey.crv !== 'Ed25519') {\n throw new CredoError('Expected OKP key with crv Ed25519')\n }\n\n const publicKeyBase58 = TypedArrayEncoder.toBase58(publicKey.publicKey)\n return publicKeyBase58\n }\n\n return key\n}\n\nexport function verkeyToDidKey(verkey: string) {\n if (isDidKey(verkey)) return verkey\n\n const ed25519Key = verkeyToPublicJwk(verkey)\n const didKey = new DidKey(ed25519Key)\n return didKey.did\n}\n\nexport function didKeyToEd25519PublicJwk(key: string) {\n const didKey = DidKey.fromDid(key)\n if (didKey.publicJwk.is(Ed25519PublicJwk)) {\n return didKey.publicJwk as PublicJwk<Ed25519PublicJwk>\n }\n\n throw new CredoError(\n `Expected public jwk to have kty OKP with crv Ed25519, found ${didKey.publicJwk.
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../src/modules/dids/helpers.ts"],"sourcesContent":["import { CredoError } from '../../error'\nimport { isDid, TypedArrayEncoder } from '../../utils'\nimport { Ed25519PublicJwk, PublicJwk } from '../kms'\n\nimport { DidKey } from './methods/key/DidKey'\n\nexport function isDidKey(key: string) {\n return isDid(key, 'key')\n}\n\nexport function didKeyToVerkey(key: string) {\n if (isDidKey(key)) {\n const publicKey = DidKey.fromDid(key).publicJwk.publicKey\n if (publicKey.kty !== 'OKP' || publicKey.crv !== 'Ed25519') {\n throw new CredoError('Expected OKP key with crv Ed25519')\n }\n\n const publicKeyBase58 = TypedArrayEncoder.toBase58(publicKey.publicKey)\n return publicKeyBase58\n }\n\n return key\n}\n\nexport function verkeyToDidKey(verkey: string) {\n if (isDidKey(verkey)) return verkey\n\n const ed25519Key = verkeyToPublicJwk(verkey)\n const didKey = new DidKey(ed25519Key)\n return didKey.did\n}\n\nexport function didKeyToEd25519PublicJwk(key: string) {\n const didKey = DidKey.fromDid(key)\n if (didKey.publicJwk.is(Ed25519PublicJwk)) {\n return didKey.publicJwk as PublicJwk<Ed25519PublicJwk>\n }\n\n throw new CredoError(\n `Expected public jwk to have kty OKP with crv Ed25519, found ${didKey.publicJwk.jwkTypeHumanDescription}`\n )\n}\n\nexport function verkeyToPublicJwk(verkey: string) {\n const ed25519Key = PublicJwk.fromPublicKey({\n kty: 'OKP',\n crv: 'Ed25519',\n publicKey: TypedArrayEncoder.fromBase58(verkey),\n }) as PublicJwk<Ed25519PublicJwk>\n return ed25519Key\n}\n"],"mappings":";;;;;;;;;;;;;AAMA,SAAgB,SAAS,KAAa;AACpC,QAAO,MAAM,KAAK,MAAM;;AAG1B,SAAgB,eAAe,KAAa;AAC1C,KAAI,SAAS,IAAI,EAAE;EACjB,MAAM,YAAY,OAAO,QAAQ,IAAI,CAAC,UAAU;AAChD,MAAI,UAAU,QAAQ,SAAS,UAAU,QAAQ,UAC/C,OAAM,IAAI,WAAW,oCAAoC;AAI3D,SADwB,kBAAkB,SAAS,UAAU,UAAU;;AAIzE,QAAO;;AAGT,SAAgB,eAAe,QAAgB;AAC7C,KAAI,SAAS,OAAO,CAAE,QAAO;AAI7B,QADe,IAAI,OADA,kBAAkB,OAAO,CACP,CACvB;;AAGhB,SAAgB,yBAAyB,KAAa;CACpD,MAAM,SAAS,OAAO,QAAQ,IAAI;AAClC,KAAI,OAAO,UAAU,GAAG,iBAAiB,CACvC,QAAO,OAAO;AAGhB,OAAM,IAAI,WACR,+DAA+D,OAAO,UAAU,0BACjF;;AAGH,SAAgB,kBAAkB,QAAgB;AAMhD,QALmB,UAAU,cAAc;EACzC,KAAK;EACL,KAAK;EACL,WAAW,kBAAkB,WAAW,OAAO;EAChD,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { __decorateMetadata } from "../../../_virtual/_@oxc-project_runtime@0.
|
|
4
|
-
import { __decorate } from "../../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
+
import { __decorateMetadata } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
4
|
+
import { __decorate } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
5
5
|
import { BaseRecord } from "../../../storage/BaseRecord.mjs";
|
|
6
6
|
import { parseDid } from "../domain/parse.mjs";
|
|
7
7
|
import { DidDocument } from "../domain/DidDocument.mjs";
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import { InjectionSymbols } from "../../../constants.mjs";
|
|
4
4
|
import { inject, injectable } from "../../../plugins/index.mjs";
|
|
5
|
-
import { __decorateMetadata } from "../../../_virtual/_@oxc-project_runtime@0.
|
|
6
|
-
import { __decorate } from "../../../_virtual/_@oxc-project_runtime@0.
|
|
5
|
+
import { __decorateMetadata } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
6
|
+
import { __decorate } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
7
7
|
import "../../kms/index.mjs";
|
|
8
8
|
import { DidDocumentRole } from "../domain/DidDocumentRole.mjs";
|
|
9
9
|
import { DidRecord } from "./DidRecord.mjs";
|
|
10
|
-
import { __decorateParam } from "../../../_virtual/_@oxc-project_runtime@0.
|
|
10
|
+
import { __decorateParam } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateParam.mjs";
|
|
11
11
|
import { EventEmitter } from "../../../agent/EventEmitter.mjs";
|
|
12
12
|
import { Repository } from "../../../storage/Repository.mjs";
|
|
13
13
|
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { InjectionSymbols } from "../../../constants.mjs";
|
|
4
4
|
import { inject, injectable } from "../../../plugins/index.mjs";
|
|
5
|
-
import { __decorateMetadata } from "../../../_virtual/_@oxc-project_runtime@0.
|
|
6
|
-
import { __decorate } from "../../../_virtual/_@oxc-project_runtime@0.
|
|
5
|
+
import { __decorateMetadata } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
6
|
+
import { __decorate } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
7
7
|
import { tryParseDid } from "../domain/parse.mjs";
|
|
8
|
-
import { __decorateParam } from "../../../_virtual/_@oxc-project_runtime@0.
|
|
8
|
+
import { __decorateParam } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateParam.mjs";
|
|
9
9
|
import { DidsModuleConfig } from "../DidsModuleConfig.mjs";
|
|
10
10
|
import { DidResolverService } from "./DidResolverService.mjs";
|
|
11
11
|
|