dcql 0.2.21-alpha-20250217192848 → 0.2.21
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/dist/index.js +14 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -590,24 +590,23 @@ var getCredentialQueryParser = (credentialQuery, ctx) => {
|
|
590
590
|
var runCredentialQuery = (credentialQuery, ctx) => {
|
591
591
|
const { credentials, presentation } = ctx;
|
592
592
|
const claimSets = credentialQuery.claim_sets ?? [void 0];
|
593
|
-
const credentialQueryResult =
|
594
|
-
claimSets.length
|
595
|
-
).fill([]);
|
593
|
+
const credentialQueryResult = [];
|
596
594
|
for (const [claimSetIndex, claim_set] of claimSets.entries()) {
|
597
595
|
const credentialParser = getCredentialQueryParser(credentialQuery, {
|
598
596
|
claimSet: claim_set,
|
599
597
|
presentation
|
600
598
|
});
|
599
|
+
const claimSetResult = [];
|
601
600
|
for (const [credentialIndex, credential] of credentials.entries()) {
|
602
601
|
if (claimSetIndex > 0) {
|
603
|
-
const previous = credentialQueryResult[claimSetIndex - 1]
|
602
|
+
const previous = credentialQueryResult[claimSetIndex - 1][credentialIndex];
|
604
603
|
if (previous?.success || !previous) {
|
605
|
-
|
604
|
+
claimSetResult[credentialIndex] = void 0;
|
606
605
|
continue;
|
607
606
|
}
|
608
607
|
}
|
609
608
|
const parseResult = v7.safeParse(credentialParser, credential);
|
610
|
-
|
609
|
+
claimSetResult.push({
|
611
610
|
...parseResult,
|
612
611
|
...parseResult.issues && {
|
613
612
|
flattened: v7.flatten(parseResult.issues)
|
@@ -616,6 +615,7 @@ var runCredentialQuery = (credentialQuery, ctx) => {
|
|
616
615
|
claim_set_index: credentialQuery.claim_sets ? claimSetIndex : void 0
|
617
616
|
});
|
618
617
|
}
|
618
|
+
credentialQueryResult.push(claimSetResult);
|
619
619
|
}
|
620
620
|
return credentialQueryResult;
|
621
621
|
};
|
@@ -854,16 +854,15 @@ var DcqlPresentationResult;
|
|
854
854
|
];
|
855
855
|
})
|
856
856
|
);
|
857
|
-
let invalidMatches =
|
857
|
+
let invalidMatches = {};
|
858
858
|
const validMatches = {};
|
859
859
|
for (const [queryId, presentationQueryResult] of Object.entries(presentationQueriesResults)) {
|
860
860
|
for (const presentationQueryResultForClaimSet of presentationQueryResult) {
|
861
861
|
const result = presentationQueryResultForClaimSet[0];
|
862
|
-
if (result
|
862
|
+
if (result?.success) {
|
863
863
|
const { issues, input_credential_index, ...rest } = result;
|
864
864
|
validMatches[queryId] = { ...rest, presentation_id: queryId };
|
865
|
-
} else {
|
866
|
-
if (!invalidMatches) invalidMatches = {};
|
865
|
+
} else if (result?.success === false) {
|
867
866
|
const { input_credential_index, ...rest } = result;
|
868
867
|
invalidMatches[queryId] = {
|
869
868
|
...rest,
|
@@ -872,6 +871,9 @@ var DcqlPresentationResult;
|
|
872
871
|
}
|
873
872
|
}
|
874
873
|
}
|
874
|
+
invalidMatches = Object.fromEntries(
|
875
|
+
Object.entries(invalidMatches ?? {}).filter(([queryId, result]) => validMatches[queryId] === void 0)
|
876
|
+
);
|
875
877
|
const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {
|
876
878
|
const matchingOptions = set.options.filter(
|
877
879
|
(option) => option.every((credentialQueryId) => validMatches[credentialQueryId]?.success)
|
@@ -881,12 +883,12 @@ var DcqlPresentationResult;
|
|
881
883
|
matching_options: matchingOptions.length > 0 ? matchingOptions : void 0
|
882
884
|
};
|
883
885
|
});
|
884
|
-
const dqclQueryMatched = credentialSetResults ? credentialSetResults.every((set) => !set.required || set.matching_options) :
|
886
|
+
const dqclQueryMatched = credentialSetResults ? credentialSetResults.every((set) => !set.required || set.matching_options) : Object.keys(invalidMatches).length === 0;
|
885
887
|
return {
|
886
888
|
...dcqlQuery,
|
887
889
|
canBeSatisfied: dqclQueryMatched,
|
888
890
|
valid_matches: validMatches,
|
889
|
-
invalid_matches: invalidMatches,
|
891
|
+
invalid_matches: Object.keys(invalidMatches).length === 0 ? void 0 : {},
|
890
892
|
credential_sets: credentialSetResults
|
891
893
|
};
|
892
894
|
};
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/dcql-error/e-base.ts","../src/dcql-error/e-dcql.ts","../src/dcql-presentation/m-dcql-credential-presentation.ts","../src/u-dcql-credential.ts","../src/u-dcql.ts","../src/u-model.ts","../src/dcql-presentation/m-dcql-presentation-result.ts","../src/dcql-parser/dcql-credential-query-result.ts","../src/dcql-parser/dcql-claims-query-result.ts","../src/dcql-query/m-dcql-claims-query.ts","../src/dcql-query-result/m-dcql-query-result.ts","../src/dcql-query/m-dcql-credential-query.ts","../src/dcql-query/m-dcql-credential-set-query.ts","../src/dcql-presentation/m-dcql-presentation.ts","../src/dcql-query-result/run-dcql-query.ts","../src/dcql-query/m-dcql-query.ts"],"sourcesContent":["export * from './dcql-error/index.js'\nexport * from './dcql-presentation/index.js'\nexport * from './dcql-query-result/index.js'\nexport * from './dcql-query/index.js'\n\nexport {\n DcqlCredential,\n DcqlMdocCredential,\n DcqlSdJwtVcCredential,\n DcqlW3cVcCredential,\n} from './u-dcql-credential.js'\n","function isObject(value: unknown): value is Record<string, unknown> {\n return !!value && !Array.isArray(value) && typeof value === 'object'\n}\n\nclass UnknownCauseError extends Error {\n [key: string]: unknown\n}\n\nexport function getCauseFromUnknown(cause: unknown): Error | undefined {\n if (cause instanceof Error) {\n return cause\n }\n\n const type = typeof cause\n if (type === 'undefined' || type === 'function' || cause === null) {\n return undefined\n }\n\n // Primitive types just get wrapped in an error\n if (type !== 'object') {\n return new Error(String(cause))\n }\n\n // If it's an object, we'll create a synthetic error\n if (isObject(cause)) {\n const err = new UnknownCauseError()\n for (const key in cause) {\n err[key] = cause[key]\n }\n return err\n }\n\n return undefined\n}\n\nexport const isDcqlError = (cause: unknown): cause is DcqlError => {\n if (cause instanceof DcqlError) {\n return true\n }\n if (cause instanceof Error && cause.name === 'DcqlError') {\n // https://github.com/trpc/trpc/pull/4848\n return true\n }\n\n return false\n}\n\nexport function getDcqlErrorFromUnknown(cause: unknown): DcqlError {\n if (isDcqlError(cause)) {\n return cause\n }\n\n const dcqlError = new DcqlError({\n code: 'INTERNAL_SERVER_ERROR',\n cause,\n })\n\n // Inherit stack from error\n if (cause instanceof Error && cause.stack) {\n dcqlError.stack = cause.stack\n }\n\n return dcqlError\n}\n\ntype DCQL_ERROR_CODE = 'PARSE_ERROR' | 'INTERNAL_SERVER_ERROR' | 'NOT_IMPLEMENTED' | 'BAD_REQUEST'\n\nexport class DcqlError extends Error {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore override doesn't work in all environments due to \"This member cannot have an 'override' modifier because it is not declared in the base class 'Error'\"\n public override readonly cause?: Error\n public readonly code\n\n constructor(opts: {\n message?: string\n code: DCQL_ERROR_CODE\n cause?: unknown\n }) {\n const cause = getCauseFromUnknown(opts.cause)\n const message = opts.message ?? cause?.message ?? opts.code\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore https://github.com/tc39/proposal-error-cause\n super(message, { cause })\n\n this.code = opts.code\n this.name = 'DcqlError'\n\n if (!this.cause) {\n // < ES2022 / < Node 16.9.0 compatability\n this.cause = cause\n }\n }\n}\n","import { DcqlError } from './e-base.js'\n\nexport class DcqlCredentialSetError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlUndefinedClaimSetIdError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlNonUniqueCredentialQueryIdsError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlParseError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'PARSE_ERROR', ...opts })\n }\n}\n\nexport class DcqlInvalidClaimsQueryIdError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlMissingClaimSetParseError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'PARSE_ERROR', ...opts })\n }\n}\n\nexport class DcqlInvalidPresentationRecordError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlPresentationResultError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n","import * as v from 'valibot'\nimport { DcqlMdocCredential, DcqlSdJwtVcCredential, DcqlW3cVcCredential } from '../u-dcql-credential'\nimport type { InferModelTypes } from '../u-model'\nimport { Model } from '../u-model'\n\nexport namespace DcqlMdocPresentation {\n export const vModel = DcqlMdocCredential.vModel\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlMdocPresentation = DcqlMdocPresentation.Model['Output']\n\nexport namespace DcqlSdJwtVcPresentation {\n export const vModel = DcqlSdJwtVcCredential.vModel\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlSdJwtVcPresentation = DcqlSdJwtVcPresentation.Model['Output']\n\nexport namespace DcqlW3cVcPresentation {\n export const vModel = DcqlW3cVcCredential.vModel\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlW3cVcPresentation = DcqlW3cVcPresentation.Model['Output']\n\nexport namespace DcqlCredentialPresentation {\n export const model = new Model({\n vModel: v.variant('credential_format', [\n DcqlMdocPresentation.vModel,\n DcqlSdJwtVcPresentation.vModel,\n DcqlW3cVcPresentation.vModel,\n ]),\n })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlCredentialPresentation = DcqlCredentialPresentation.Model['Output']\n","import * as v from 'valibot'\nimport { vJsonRecord, vNonEmptyArray } from './u-dcql.js'\nimport type { InferModelTypes } from './u-model.js'\nimport { Model } from './u-model.js'\n\nexport namespace DcqlMdocCredential {\n export const vNamespaces = v.record(v.string(), v.record(v.string(), v.unknown()))\n export const vModel = v.object({\n credential_format: v.literal('mso_mdoc'),\n doctype: v.string(),\n namespaces: vNamespaces,\n })\n\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n export type NameSpaces = v.InferOutput<typeof vNamespaces>\n}\nexport type DcqlMdocCredential = DcqlMdocCredential.Model['Output']\n\nexport namespace DcqlSdJwtVcCredential {\n export const vClaims = vJsonRecord\n export const vModel = v.object({\n credential_format: v.picklist(['vc+sd-jwt', 'dc+sd-jwt']),\n vct: v.string(),\n claims: vClaims,\n })\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n export type Claims = Model['Output']['claims']\n}\nexport type DcqlSdJwtVcCredential = DcqlSdJwtVcCredential.Model['Output']\n\nexport namespace DcqlW3cVcCredential {\n export const vClaims = vJsonRecord\n export const vModel = v.object({\n credential_format: v.picklist(['jwt_vc_json-ld', 'jwt_vc_json']),\n claims: vClaims,\n })\n\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n export type Claims = Model['Output']['claims']\n}\nexport type DcqlW3cVcCredential = DcqlW3cVcCredential.Model['Output']\n\nexport namespace DcqlCredential {\n export const vModel = v.variant('credential_format', [\n DcqlMdocCredential.vModel,\n DcqlSdJwtVcCredential.vModel,\n DcqlW3cVcCredential.vModel,\n ])\n\n export const vParseSuccess = v.object({\n success: v.literal(true),\n typed: v.literal(true),\n issues: v.optional(v.undefined()),\n input_credential_index: v.number(),\n claim_set_index: v.union([v.number(), v.undefined()]),\n output: DcqlCredential.vModel,\n })\n\n export const vParseFailure = v.object({\n success: v.literal(false),\n typed: v.boolean(),\n output: v.unknown(),\n issues: v.pipe(v.array(v.unknown()), vNonEmptyArray()),\n input_credential_index: v.number(),\n claim_set_index: v.union([v.number(), v.undefined()]),\n })\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlCredential = DcqlCredential.Model['Output']\n","import * as v from 'valibot'\nimport type { UnknownBaseSchema } from './u-model'\nexport const idRegex = /^[a-zA-Z0-9_-]+$/\n\nexport const vNonEmptyArray = <T extends unknown[]>() => {\n return v.custom<[T[number], ...T]>((input) => (input as T).length > 0)\n}\n\nexport const vIdString = v.pipe(v.string(), v.regex(idRegex), v.nonEmpty())\n\nexport type Json = string | number | boolean | null | { [key: string]: Json } | Json[]\n\ninterface HasToJson {\n toJson(): Json\n}\n\nfunction isToJsonable(value: unknown): value is HasToJson {\n if (value === null || typeof value !== 'object') return false\n\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n const toJsonFn = (value as any).toJson\n return typeof toJsonFn === 'function'\n}\n\nexport const vWithJT = <Schema extends UnknownBaseSchema>(schema: Schema) =>\n v.pipe(\n v.custom<v.InferInput<Schema>>(() => true),\n v.rawTransform<v.InferInput<Schema>, v.InferOutput<Schema>>(({ dataset, addIssue, NEVER }) => {\n const result = v.safeParse(schema, dataset.value)\n if (result.success) return dataset.value\n\n if (!isToJsonable(dataset.value)) {\n for (const safeParseIssue of result.issues) {\n addIssue({\n ...safeParseIssue,\n expected: safeParseIssue.expected ?? undefined,\n })\n }\n\n return NEVER\n }\n\n let json: Json\n\n try {\n json = dataset.value.toJson()\n } catch (error) {\n for (const safeParseIssue of result.issues) {\n addIssue({\n ...safeParseIssue,\n expected: safeParseIssue.expected ?? undefined,\n })\n }\n addIssue({ message: 'Json Transformation failed' })\n return NEVER\n }\n\n const safeParseResult: v.SafeParseResult<Schema> = v.safeParse(schema, json)\n if (safeParseResult.success) return dataset.value\n\n for (const safeParseIssue of safeParseResult.issues) {\n addIssue({\n ...safeParseIssue,\n expected: safeParseIssue.expected ?? undefined,\n })\n }\n\n return NEVER\n })\n )\n\nexport const vJsonLiteral = v.union([v.string(), v.number(), v.boolean(), v.null()])\n\nexport type JsonLiteral = v.InferOutput<typeof vJsonLiteral>\n\nexport const vJson: v.GenericSchema<Json> = v.lazy(() =>\n v.union([vJsonLiteral, v.array(vJson), v.record(v.string(), vJson)])\n)\n\nexport const vJsonWithJT: v.GenericSchema<Json> = v.lazy(() =>\n vWithJT(v.union([vJsonLiteral, v.array(vJson), v.record(v.string(), vJson)]))\n)\n\nexport const vJsonRecord = v.record(v.string(), vJson)\nexport type JsonRecord = v.InferOutput<typeof vJsonRecord>\n\nexport const vStringToJson = v.rawTransform<string, Json>(({ dataset, addIssue, NEVER }) => {\n try {\n return JSON.parse(dataset.value) as Json\n } catch (error) {\n addIssue({ message: 'Invalid JSON' })\n return NEVER\n }\n})\n","import * as v from 'valibot'\nimport { DcqlParseError } from './dcql-error/e-dcql'\n\nexport type UnknownBaseSchema = v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>\n\ntype EnsureOutputAssignableToInput<T extends UnknownBaseSchema> = v.InferOutput<T> extends v.InferInput<T> ? T : never\n\nexport class Model<T extends UnknownBaseSchema> {\n constructor(private input: { vModel: EnsureOutputAssignableToInput<T> }) {}\n\n public get v() {\n return this.input.vModel\n }\n\n public parse(input: T) {\n const result = this.safeParse(input)\n\n if (result.success) {\n return result.output\n }\n\n return new DcqlParseError({\n message: JSON.stringify(result.flattened),\n cause: result.error,\n })\n }\n\n public safeParse(\n input: unknown\n ):\n | { success: true; output: v.InferOutput<T> }\n | { success: false; flattened: v.FlatErrors<T>; error: v.ValiError<T> } {\n const res = v.safeParse(this.input.vModel, input)\n if (res.success) {\n return { success: true, output: res.output }\n }\n return {\n success: false,\n error: new v.ValiError(res.issues),\n flattened: v.flatten<T>(res.issues),\n }\n }\n\n public is(input: unknown): input is v.InferOutput<T> {\n return v.is(this.v, input)\n }\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\nexport type InferModelTypes<T extends Model<any>> = T extends Model<infer U>\n ? {\n Input: v.InferInput<U>\n Output: v.InferOutput<U>\n }\n : never\n","import * as v from 'valibot'\n\nimport { DcqlInvalidPresentationRecordError, DcqlPresentationResultError } from '../dcql-error/e-dcql.js'\nimport { runCredentialQuery } from '../dcql-parser/dcql-credential-query-result.js'\nimport { DcqlQueryResult } from '../dcql-query-result/m-dcql-query-result.js'\nimport type { DcqlQuery } from '../dcql-query/m-dcql-query.js'\nimport { DcqlCredential } from '../u-dcql-credential.js'\nimport { vIdString } from '../u-dcql.js'\nimport type { DcqlCredentialPresentation } from './m-dcql-credential-presentation.js'\n\nexport namespace DcqlPresentationResult {\n export const vModel = v.object({\n ...v.omit(DcqlQueryResult.vModel, ['credential_matches']).entries,\n\n invalid_matches: v.union([\n v.record(\n v.pipe(vIdString),\n v.object({\n ...v.omit(DcqlCredential.vParseFailure, ['input_credential_index']).entries,\n presentation_id: v.pipe(vIdString),\n })\n ),\n v.undefined(),\n ]),\n\n valid_matches: v.record(\n v.pipe(vIdString),\n v.object({\n ...v.omit(DcqlCredential.vParseSuccess, ['issues', 'input_credential_index']).entries,\n presentation_id: v.pipe(vIdString),\n })\n ),\n })\n\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n\n export const parse = (input: Input | DcqlQueryResult) => {\n return v.parse(vModel, input)\n }\n\n /**\n * Query if the presentation record can be satisfied by the provided presentations\n * considering the dcql query\n *\n * @param dcqlQuery\n * @param dcqlPresentation\n */\n export const fromDcqlPresentation = (\n dcqlPresentation: Record<string, DcqlCredentialPresentation>,\n ctx: { dcqlQuery: DcqlQuery }\n ): Output => {\n const { dcqlQuery } = ctx\n\n const presentationQueriesResults = Object.fromEntries(\n Object.entries(dcqlPresentation).map(([queryId, presentation]) => {\n const credentialQuery = dcqlQuery.credentials.find((c) => c.id === queryId)\n if (!credentialQuery) {\n throw new DcqlPresentationResultError({\n message: `Query ${queryId} not found in the dcql query. Cannot validate presentation.`,\n })\n }\n\n return [\n queryId,\n runCredentialQuery(credentialQuery, {\n presentation: true,\n credentials: [presentation],\n }),\n ]\n })\n )\n\n let invalidMatches: DcqlPresentationResult['invalid_matches'] = undefined\n const validMatches: DcqlPresentationResult['valid_matches'] = {}\n\n for (const [queryId, presentationQueryResult] of Object.entries(presentationQueriesResults)) {\n for (const presentationQueryResultForClaimSet of presentationQueryResult) {\n // biome-ignore lint/style/noNonNullAssertion: <explanation>\n const result = presentationQueryResultForClaimSet[0]!\n if (result.success) {\n const { issues, input_credential_index, ...rest } = result\n validMatches[queryId] = { ...rest, presentation_id: queryId }\n } else {\n if (!invalidMatches) invalidMatches = {}\n const { input_credential_index, ...rest } = result\n invalidMatches[queryId] = {\n ...rest,\n presentation_id: queryId,\n }\n }\n }\n }\n\n const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {\n const matchingOptions = set.options.filter((option) =>\n option.every((credentialQueryId) => validMatches[credentialQueryId]?.success)\n )\n\n return {\n ...set,\n matching_options: matchingOptions.length > 0 ? (matchingOptions as [string[], ...string[][]]) : undefined,\n }\n }) as DcqlQueryResult.Output['credential_sets']\n\n const dqclQueryMatched = credentialSetResults\n ? credentialSetResults.every((set) => !set.required || set.matching_options)\n : !invalidMatches\n\n return {\n ...dcqlQuery,\n canBeSatisfied: dqclQueryMatched,\n valid_matches: validMatches,\n invalid_matches: invalidMatches,\n credential_sets: credentialSetResults,\n }\n }\n\n export const validate = (dcqlQueryResult: DcqlPresentationResult) => {\n if (!dcqlQueryResult.canBeSatisfied) {\n throw new DcqlInvalidPresentationRecordError({\n message: 'Invalid Presentation record',\n cause: dcqlQueryResult,\n })\n }\n\n return dcqlQueryResult satisfies Output\n }\n}\nexport type DcqlPresentationResult = DcqlPresentationResult.Output\n","import * as v from 'valibot'\nimport type { DcqlQueryResult } from '../dcql-query-result/m-dcql-query-result.js'\nimport type { DcqlCredentialQuery } from '../dcql-query/m-dcql-credential-query.js'\nimport type { DcqlCredential } from '../u-dcql-credential.js'\nimport type {} from '../u-dcql.js'\nimport { getCredentialQueryParser } from './dcql-claims-query-result.js'\n\nexport const runCredentialQuery = (\n credentialQuery: DcqlCredentialQuery,\n ctx: {\n credentials: DcqlCredential[]\n presentation: boolean\n }\n): DcqlQueryResult.CredentialQueryResult => {\n const { credentials, presentation } = ctx\n const claimSets = credentialQuery.claim_sets ?? [undefined]\n\n const credentialQueryResult: v.InferInput<typeof DcqlQueryResult.vCredentialQueryResult> = new Array(\n claimSets.length\n ).fill([])\n\n for (const [claimSetIndex, claim_set] of claimSets.entries()) {\n const credentialParser = getCredentialQueryParser(credentialQuery, {\n claimSet: claim_set,\n presentation,\n })\n\n for (const [credentialIndex, credential] of credentials.entries()) {\n if (claimSetIndex > 0) {\n // if one the credential was successfully parsed against a previous claimsset we don't need to further validate other claim sets\n const previous = credentialQueryResult[claimSetIndex - 1]?.[credentialIndex]\n\n // if the previous credential was successfully parsed we don't need to further validate the current credential\n // we set all further parsing attempts to undefined\n if (previous?.success || !previous) {\n // biome-ignore lint/style/noNonNullAssertion: <explanation>\n credentialQueryResult[claimSetIndex]![credentialIndex] = undefined\n continue\n }\n }\n\n const parseResult = v.safeParse(credentialParser, credential)\n credentialQueryResult[claimSetIndex]?.push({\n ...parseResult,\n ...(parseResult.issues && {\n flattened: v.flatten<typeof credentialParser>(parseResult.issues),\n }),\n input_credential_index: credentialIndex,\n claim_set_index: credentialQuery.claim_sets ? claimSetIndex : undefined,\n })\n }\n }\n\n return credentialQueryResult as DcqlQueryResult.CredentialQueryResult\n}\n","import * as v from 'valibot'\nimport { DcqlInvalidClaimsQueryIdError, DcqlMissingClaimSetParseError } from '../dcql-error/e-dcql.js'\nimport { DcqlClaimsQuery } from '../dcql-query/m-dcql-claims-query.js'\nimport type { DcqlCredentialQuery } from '../dcql-query/m-dcql-credential-query.js'\nimport { vWithJT } from '../u-dcql.js'\nimport { vJson, vJsonRecord } from '../u-dcql.js'\n\nconst getClaimParser = (input: {\n value?: string | number | boolean\n values?: (string | number | boolean)[]\n}) => {\n const { value, values } = input\n if (value) {\n return vWithJT(v.literal(value))\n }\n\n if (values) {\n return vWithJT(v.union(values.map((val) => v.literal(val))))\n }\n\n return v.nonNullish(v.any())\n}\n\nexport const getNamespacesParser = (claimsQueries: DcqlClaimsQuery.Mdoc[]) => {\n const claimsForNamespace: Record<string, DcqlClaimsQuery.MdocPath[]> = {}\n\n for (const claimQuery of claimsQueries) {\n // Normalize the query to the latest path syntax\n const mdocPathQuery: DcqlClaimsQuery.MdocPath = v.is(DcqlClaimsQuery.vMdocNamespace, claimQuery)\n ? {\n id: claimQuery.id,\n path: [claimQuery.namespace, claimQuery.claim_name],\n values: claimQuery.values,\n }\n : claimQuery\n\n const namespace = mdocPathQuery.path[0]\n if (claimsForNamespace[namespace]) {\n claimsForNamespace[namespace]?.push({ ...mdocPathQuery })\n } else {\n claimsForNamespace[namespace] = [{ ...mdocPathQuery }]\n }\n }\n\n const parsersForNamespaces = Object.entries(claimsForNamespace).map(([namespace, claims]) => {\n const claimParsers = Object.fromEntries(claims.map((claim) => [claim.path[1], getClaimParser(claim)]))\n return [namespace, v.object(claimParsers)]\n })\n\n return v.object(Object.fromEntries(parsersForNamespaces))\n}\n\nconst getClaimQueryParser = (\n claimQuery: DcqlClaimsQuery.W3cAndSdJwtVc,\n ctx: { index: number; presentation: boolean }\n): typeof vJson => {\n const { index, presentation } = ctx\n const pathElement = claimQuery.path[index]\n const isLast = index === claimQuery.path.length - 1\n\n const vClaimParser = getClaimParser(claimQuery)\n\n if (typeof pathElement === 'number') {\n const elementParser = isLast ? vClaimParser : getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 })\n\n if (presentation) {\n // We allow both the concrete value and an array of one value\n return v.union([\n v.pipe(\n v.array(vJson),\n v.length(1),\n v.transform((input) => input[0]),\n elementParser\n ),\n elementParser,\n ])\n }\n\n return v.pipe(\n v.array(vJson),\n v.transform((input) => input[pathElement]),\n elementParser\n )\n }\n if (typeof pathElement === 'string') {\n return v.object({\n [pathElement]: isLast ? vClaimParser : getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 }),\n })\n }\n return isLast ? v.array(vClaimParser) : v.array(getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 }))\n}\n\nexport const getJsonClaimsParser = (claimsQueries: DcqlClaimsQuery.W3cAndSdJwtVc[], ctx: { presentation: boolean }) => {\n const claimParser = v.intersect(\n claimsQueries.map(\n (claimQuery) =>\n getClaimQueryParser(claimQuery, {\n ...ctx,\n index: 0,\n }) as typeof vJsonRecord\n )\n )\n\n return claimParser\n}\n\nexport const getMdocClaimsQueriesForClaimSet = (\n claimsQueries: DcqlClaimsQuery.Mdoc[],\n claimSet: string[]\n): DcqlClaimsQuery.Mdoc[] => {\n return claimSet.map((credential_id) => {\n const query = claimsQueries.find((query) => query.id === credential_id)\n if (!query) {\n throw new DcqlInvalidClaimsQueryIdError({\n message: `Claims-query with id '${credential_id}' not found.`,\n })\n }\n\n return query\n })\n}\n\nexport const getJsonClaimsQueriesForClaimSet = (\n claimsQueries: DcqlClaimsQuery.W3cAndSdJwtVc[],\n claimSet: string[]\n): DcqlClaimsQuery.W3cAndSdJwtVc[] => {\n return claimSet.map((credential_id) => {\n const query = claimsQueries.find((query) => query.id === credential_id)\n if (!query) {\n throw new DcqlInvalidClaimsQueryIdError({\n message: `Claims-query with id '${credential_id}' not found.`,\n })\n }\n return query\n })\n}\n\nconst getMdocParser = (\n credentialQuery: DcqlCredentialQuery.Mdoc,\n ctx: { claimSet?: NonNullable<DcqlCredentialQuery['claim_sets']>[number] }\n) => {\n const { claimSet } = ctx\n\n const vDoctype = credentialQuery.meta?.doctype_value ? v.literal(credentialQuery.meta.doctype_value) : v.string()\n\n const claimSetQueries =\n credentialQuery.claims && claimSet\n ? getMdocClaimsQueriesForClaimSet(credentialQuery.claims, claimSet)\n : credentialQuery.claims\n\n const credentialParser = v.object({\n credential_format: v.literal('mso_mdoc'),\n doctype: vDoctype,\n namespaces: claimSetQueries\n ? getNamespacesParser(claimSetQueries)\n : v.record(v.string(), v.record(v.string(), v.unknown())),\n })\n\n return credentialParser\n}\n\nconst getW3cVcSdJwtVcParser = (\n credentialQuery: DcqlCredentialQuery.SdJwtVc | DcqlCredentialQuery.W3cVc,\n ctx: {\n claimSet?: NonNullable<DcqlCredentialQuery['claim_sets']>[number]\n presentation: boolean\n }\n) => {\n const { claimSet } = ctx\n const claimSetQueries =\n credentialQuery.claims && claimSet\n ? getJsonClaimsQueriesForClaimSet(credentialQuery.claims, claimSet)\n : credentialQuery.claims\n\n if (credentialQuery.format === 'vc+sd-jwt' || credentialQuery.format === 'dc+sd-jwt') {\n return v.object({\n credential_format: v.literal(credentialQuery.format),\n vct: credentialQuery.meta?.vct_values ? v.picklist(credentialQuery.meta.vct_values) : v.string(),\n claims: claimSetQueries ? getJsonClaimsParser(claimSetQueries, ctx) : vJsonRecord,\n })\n }\n const credentialParser = v.object({\n credential_format: v.picklist(['jwt_vc_json', 'jwt_vc_json-ld']),\n claims: claimSetQueries ? getJsonClaimsParser(claimSetQueries, ctx) : vJsonRecord,\n })\n\n return credentialParser\n}\n\nexport const getCredentialQueryParser = (\n credentialQuery: DcqlCredentialQuery,\n ctx: {\n claimSet?: NonNullable<DcqlCredentialQuery['claim_sets']>[number]\n presentation: boolean\n }\n) => {\n if (credentialQuery.claim_sets && !ctx.claimSet) {\n throw new DcqlMissingClaimSetParseError({\n message: 'credentialQuery specifies claim_sets but no claim_set for parsing is provided.',\n })\n }\n\n if (credentialQuery.format === 'mso_mdoc') {\n return getMdocParser(credentialQuery, ctx)\n }\n return getW3cVcSdJwtVcParser(credentialQuery, ctx)\n}\n","import * as v from 'valibot'\nimport { vIdString, vNonEmptyArray } from '../u-dcql.js'\n\n/**\n * Specifies claims withing a requested Credential.\n */\nexport namespace DcqlClaimsQuery {\n export const vValue = v.union([v.string(), v.pipe(v.number(), v.integer()), v.boolean()])\n\n export const vPath = v.union([v.string(), v.pipe(v.number(), v.integer(), v.minValue(0)), v.null()])\n\n export const vW3cSdJwtVc = v.object({\n id: v.pipe(\n v.optional(vIdString),\n v.description(\n 'A string identifying the particular claim. The value MUST be a non-empty string consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular claims array, the same id MUST NOT be present more than once.'\n )\n ),\n path: v.pipe(\n v.array(vPath),\n vNonEmptyArray(),\n v.description(\n 'A non-empty array representing a claims path pointer that specifies the path to a claim within the Verifiable Credential.'\n )\n ),\n values: v.pipe(\n v.optional(v.array(vValue)),\n v.description(\n 'An array of strings, integers or boolean values that specifies the expected values of the claim. If the values property is present, the Wallet SHOULD return the claim only if the type and value of the claim both match for at least one of the elements in the array.'\n )\n ),\n })\n export type W3cAndSdJwtVc = v.InferOutput<typeof vW3cSdJwtVc>\n\n const vMdocBase = v.object({\n id: v.pipe(\n v.optional(vIdString),\n v.description(\n 'A string identifying the particular claim. The value MUST be a non-empty string consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular claims array, the same id MUST NOT be present more than once.'\n )\n ),\n values: v.pipe(\n v.optional(v.array(vValue)),\n v.description(\n 'An array of strings, integers or boolean values that specifies the expected values of the claim. If the values property is present, the Wallet SHOULD return the claim only if the type and value of the claim both match for at least one of the elements in the array.'\n )\n ),\n })\n\n // Syntax up until Draft 23 of OID4VP. Keeping due to Draft 23 having\n // reach ID-3 status and thus being targeted by several implementations\n export const vMdocNamespace = v.object({\n ...vMdocBase.entries,\n\n namespace: v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the namespace of the data element within the mdoc, e.g., org.iso.18013.5.1.'\n )\n ),\n claim_name: v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the data element identifier of the data element within the provided namespace in the mdoc, e.g., first_name.'\n )\n ),\n })\n\n // Syntax starting from Draft 24 of OID4VP\n export const vMdocPath = v.object({\n ...vMdocBase.entries,\n\n intent_to_retain: v.pipe(\n v.optional(v.boolean()),\n v.description(\n 'A boolean that is equivalent to `IntentToRetain` variable defined in Section 8.3.2.1.2.1 of [@ISO.18013-5].'\n )\n ),\n\n path: v.pipe(\n v.tuple([\n v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the namespace of the data element within the mdoc, e.g., org.iso.18013.5.1.'\n )\n ),\n v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the data element identifier of the data element within the provided namespace in the mdoc, e.g., first_name.'\n )\n ),\n ]),\n v.description(\n 'An array defining a claims path pointer into an mdoc. It must contain two elements of type string. The first element refers to a namespace and the second element refers to a data element identifier.'\n )\n ),\n })\n export const vMdoc = v.union([vMdocNamespace, vMdocPath])\n export type MdocNamespace = v.InferOutput<typeof vMdocNamespace>\n export type MdocPath = v.InferOutput<typeof vMdocPath>\n export type Mdoc = v.InferOutput<typeof vMdoc>\n\n export const vModel = v.union([vMdoc, vW3cSdJwtVc])\n export type Input = v.InferInput<typeof vModel>\n export type Out = v.InferOutput<typeof vModel>\n}\nexport type DcqlClaimsQuery = DcqlClaimsQuery.Out\n","import * as v from 'valibot'\nimport { DcqlCredentialQuery } from '../dcql-query/m-dcql-credential-query.js'\nimport { CredentialSetQuery } from '../dcql-query/m-dcql-credential-set-query.js'\nimport { DcqlCredential } from '../u-dcql-credential.js'\nimport { vIdString, vNonEmptyArray } from '../u-dcql.js'\n\nexport namespace DcqlQueryResult {\n export const vCredentialQueryResult = v.pipe(\n v.array(v.array(v.union([v.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure]))),\n vNonEmptyArray()\n )\n\n export type CredentialQueryResult = v.InferOutput<typeof vCredentialQueryResult>\n\n export const vModel = v.object({\n credentials: v.pipe(\n v.array(DcqlCredentialQuery.vModel),\n vNonEmptyArray(),\n v.description(\n 'REQUIRED. A non-empty array of Credential Queries that specify the requested Verifiable Credentials.'\n )\n ),\n\n credential_matches: v.record(\n v.pipe(vIdString),\n v.union([\n v.object({\n ...DcqlCredential.vParseSuccess.entries,\n all: v.pipe(\n v.array(\n v.pipe(\n v.array(v.union([v.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure])),\n vNonEmptyArray()\n )\n ),\n vNonEmptyArray()\n ),\n }),\n v.object({\n success: DcqlCredential.vParseFailure.entries.success,\n all: v.pipe(\n v.array(\n v.pipe(\n v.array(v.union([v.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure])),\n vNonEmptyArray()\n )\n ),\n vNonEmptyArray()\n ),\n }),\n ])\n ),\n\n credential_sets: v.optional(\n v.pipe(\n v.array(\n v.object({\n ...CredentialSetQuery.vModel.entries,\n matching_options: v.union([v.undefined(), v.pipe(v.array(v.array(v.string())), vNonEmptyArray())]),\n })\n ),\n vNonEmptyArray(),\n v.description(\n 'OPTIONAL. A non-empty array of credential set queries that specifies additional constraints on which of the requested Verifiable Credentials to return.'\n )\n )\n ),\n\n canBeSatisfied: v.boolean(),\n })\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n\n export type CredentialMatch = Input['credential_matches'][number]\n export type CredentialMatchRecord = Input['credential_matches']\n}\nexport type DcqlQueryResult = DcqlQueryResult.Output\n","import * as v from 'valibot'\nimport { DcqlUndefinedClaimSetIdError } from '../dcql-error/e-dcql.js'\nimport { idRegex, vIdString, vNonEmptyArray } from '../u-dcql.js'\nimport { DcqlClaimsQuery } from './m-dcql-claims-query.js'\n\n/**\n * A Credential Query is an object representing a request for a presentation of one Credential.\n */\nexport namespace DcqlCredentialQuery {\n const vBase = v.object({\n id: v.pipe(\n v.string(),\n v.regex(idRegex),\n v.description(\n `REQUIRED. A string identifying the Credential in the response and, if provided, the constraints in 'credential_sets'.`\n )\n ),\n claim_sets: v.pipe(\n v.optional(v.pipe(v.array(v.pipe(v.array(vIdString), vNonEmptyArray())), vNonEmptyArray())),\n v.description(\n `OPTIONAL. A non-empty array containing arrays of identifiers for elements in 'claims' that specifies which combinations of 'claims' for the Credential are requested.`\n )\n ),\n })\n\n export const vMdoc = v.object({\n ...vBase.entries,\n format: v.pipe(\n v.literal('mso_mdoc'),\n v.description('REQUIRED. A string that specifies the format of the requested Verifiable Credential.')\n ),\n claims: v.pipe(\n v.optional(v.pipe(v.array(DcqlClaimsQuery.vMdoc), vNonEmptyArray())),\n v.description('OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.')\n ),\n meta: v.pipe(\n v.optional(\n v.object({\n doctype_value: v.pipe(\n v.optional(v.string()),\n v.description(\n 'OPTIONAL. String that specifies an allowed value for the doctype of the requested Verifiable Credential.'\n )\n ),\n })\n ),\n v.description(\n 'OPTIONAL. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential.'\n )\n ),\n })\n export type Mdoc = v.InferOutput<typeof vMdoc>\n\n export const vSdJwtVc = v.object({\n ...vBase.entries,\n format: v.pipe(\n v.picklist(['vc+sd-jwt', 'dc+sd-jwt']),\n v.description('REQUIRED. A string that specifies the format of the requested Verifiable Credential.')\n ),\n claims: v.pipe(\n v.optional(v.pipe(v.array(DcqlClaimsQuery.vW3cSdJwtVc), vNonEmptyArray())),\n v.description('OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.')\n ),\n meta: v.pipe(\n v.optional(\n v.pipe(\n v.object({\n vct_values: v.optional(v.array(v.string())),\n }),\n v.description(\n 'OPTIONAL. An array of strings that specifies allowed values for the type of the requested Verifiable Credential.'\n )\n )\n ),\n v.description(\n 'OPTIONAL. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential.'\n )\n ),\n })\n export type SdJwtVc = v.InferOutput<typeof vSdJwtVc>\n\n export const vW3cVc = v.object({\n ...vBase.entries,\n format: v.picklist(['jwt_vc_json', 'jwt_vc_json-ld']),\n claims: v.optional(v.pipe(v.array(DcqlClaimsQuery.vW3cSdJwtVc), vNonEmptyArray())),\n })\n export type W3cVc = v.InferOutput<typeof vW3cVc>\n\n export const vModel = v.variant('format', [vMdoc, vSdJwtVc, vW3cVc])\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n\n export const validate = (credentialQuery: Output) => {\n claimSetIdsAreDefined(credentialQuery)\n }\n}\nexport type DcqlCredentialQuery = DcqlCredentialQuery.Output\n\n// --- validations --- //\n\nconst claimSetIdsAreDefined = (credentialQuery: DcqlCredentialQuery) => {\n if (!credentialQuery.claim_sets) return\n const claimIds = new Set(credentialQuery.claims?.map((claim) => claim.id))\n\n const undefinedClaims: string[] = []\n for (const claim_set of credentialQuery.claim_sets) {\n for (const claim_id of claim_set) {\n if (!claimIds.has(claim_id)) {\n undefinedClaims.push(claim_id)\n }\n }\n }\n\n if (undefinedClaims.length > 0) {\n throw new DcqlUndefinedClaimSetIdError({\n message: `Credential set contains undefined credential id${undefinedClaims.length === 0 ? '' : '`s'} '${undefinedClaims.join(', ')}'`,\n })\n }\n}\n","import * as v from 'valibot'\nimport { vIdString, vNonEmptyArray } from '../u-dcql.js'\n\n/**\n * A Credential Set Query is an object representing\n * a request for one or more credentials to satisfy a particular use case with the Verifier.\n */\nexport namespace CredentialSetQuery {\n export const vModel = v.object({\n options: v.pipe(\n v.array(v.array(vIdString)),\n vNonEmptyArray(),\n v.description(\n 'REQUIRED. A non-empty array, where each value in the array is a list of Credential Query identifiers representing one set of Credentials that satisfies the use case.'\n )\n ),\n required: v.pipe(\n v.optional(v.boolean(), true),\n v.description(\n `OPTIONAL. Boolean which indicates whether this set of Credentials is required to satisfy the particular use case at the Verifier. If omitted, the default value is 'true'.`\n )\n ),\n purpose: v.pipe(\n v.optional(v.union([v.string(), v.number(), v.record(v.string(), v.unknown())])),\n v.description('OPTIONAL. A string, number or object specifying the purpose of the query.')\n ),\n })\n\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n}\nexport type CredentialSetQuery = CredentialSetQuery.Output\n","import * as v from 'valibot'\nimport { vIdString, vJsonRecord, vStringToJson } from '../u-dcql.js'\n\nexport namespace DcqlPresentation {\n export const vModel = v.record(vIdString, v.union([v.string(), vJsonRecord]))\n\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n export const parse = (input: Input | string) => {\n if (typeof input === 'string') {\n return v.parse(v.pipe(v.string(), vStringToJson, vModel), input)\n }\n\n return v.parse(vModel, input)\n }\n\n export const encode = (input: Output) => {\n return JSON.stringify(input)\n }\n}\nexport type DcqlPresentation = DcqlPresentation.Output\n","import type * as v from 'valibot'\nimport { runCredentialQuery } from '../dcql-parser/dcql-credential-query-result.js'\nimport type { DcqlQuery } from '../dcql-query/m-dcql-query.js'\nimport type { DcqlCredential } from '../u-dcql-credential.js'\nimport type { DcqlQueryResult } from './m-dcql-query-result.js'\n\nexport const runDcqlQuery = (\n dcqlQuery: DcqlQuery.Output,\n ctx: {\n credentials: DcqlCredential[]\n presentation: boolean\n }\n): DcqlQueryResult => {\n const credentialQueriesResults = Object.fromEntries(\n dcqlQuery.credentials.map((credentialQuery) => [credentialQuery.id, runCredentialQuery(credentialQuery, ctx)])\n )\n\n const credentialMatches = Object.fromEntries(\n Object.entries(credentialQueriesResults).map(([key, credentialQueryResult]) => {\n // Find the best match for each credential query\n let bestMatch: v.InferOutput<typeof DcqlCredential.vParseSuccess> | undefined = undefined\n\n for (const credentialParseResult of credentialQueryResult) {\n const bestMatchForCredential = credentialParseResult.find((result) => result?.success === true)\n\n if (!bestMatch && bestMatchForCredential) {\n const { issues, ...matchWithoutIssues } = bestMatchForCredential\n bestMatch = matchWithoutIssues\n continue\n }\n\n // biome-ignore lint/style/noNonNullAssertion: <explanation>\n if (bestMatchForCredential && bestMatchForCredential.claim_set_index! < bestMatch?.claim_set_index!) {\n const { issues, ...matchWithoutIssues } = bestMatchForCredential\n bestMatch = matchWithoutIssues\n }\n }\n\n return [\n key,\n bestMatch ? { ...bestMatch, all: credentialQueryResult } : { success: false, all: credentialQueryResult },\n ]\n })\n ) satisfies DcqlQueryResult.CredentialMatchRecord\n\n const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {\n const matchingOptions = set.options.filter((option) =>\n option.every((credentialQueryId) => credentialMatches[credentialQueryId]?.success)\n )\n\n return {\n ...set,\n matching_options: matchingOptions.length > 0 ? (matchingOptions as [string[], ...string[][]]) : undefined,\n }\n }) as DcqlQueryResult.Output['credential_sets']\n\n const dqclQueryMatched = credentialSetResults\n ? credentialSetResults.every((set) => !set.required || set.matching_options)\n : Object.values(credentialMatches).every((query) => query.success)\n\n return {\n ...dcqlQuery,\n canBeSatisfied: dqclQueryMatched,\n credential_matches: credentialMatches as DcqlQueryResult['credential_matches'],\n credential_sets: credentialSetResults,\n }\n}\n","import * as v from 'valibot'\nimport { DcqlCredentialSetError, DcqlNonUniqueCredentialQueryIdsError } from '../dcql-error/e-dcql.js'\nimport { runDcqlQuery } from '../dcql-query-result/run-dcql-query.js'\nimport type { DcqlCredential } from '../u-dcql-credential.js'\nimport { vNonEmptyArray } from '../u-dcql.js'\nimport { DcqlCredentialQuery } from './m-dcql-credential-query.js'\nimport { CredentialSetQuery } from './m-dcql-credential-set-query.js'\n\n/**\n * The Digital Credentials Query Language (DCQL, pronounced [ˈdakl̩]) is a\n * JSON-encoded query language that allows the Verifier to request Verifiable\n * Presentations that match the query. The Verifier MAY encode constraints on the\n * combinations of credentials and claims that are requested. The Wallet evaluates\n * the query against the Verifiable Credentials it holds and returns Verifiable\n * Presentations matching the query.\n */\nexport namespace DcqlQuery {\n export const vModel = v.object({\n credentials: v.pipe(\n v.array(DcqlCredentialQuery.vModel),\n vNonEmptyArray(),\n v.description(\n 'REQUIRED. A non-empty array of Credential Queries that specify the requested Verifiable Credentials.'\n )\n ),\n credential_sets: v.pipe(\n v.optional(v.pipe(v.array(CredentialSetQuery.vModel), vNonEmptyArray())),\n v.description(\n 'OPTIONAL. A non-empty array of credential set queries that specifies additional constraints on which of the requested Verifiable Credentials to return.'\n )\n ),\n })\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n export const validate = (dcqlQuery: Output) => {\n validateUniqueCredentialQueryIds(dcqlQuery)\n validateCredentialSets(dcqlQuery)\n dcqlQuery.credentials.forEach(DcqlCredentialQuery.validate)\n }\n export const query = (dcqlQuery: Output, credentials: DcqlCredential[]) => {\n return runDcqlQuery(dcqlQuery, { credentials, presentation: false })\n }\n\n export const parse = (input: Input) => {\n return v.parse(vModel, input)\n }\n}\nexport type DcqlQuery = DcqlQuery.Output\n\n// --- validations --- //\n\nconst validateUniqueCredentialQueryIds = (query: DcqlQuery.Output) => {\n const ids = query.credentials.map((c) => c.id)\n const duplicates = ids.filter((id, index) => ids.indexOf(id) !== index)\n\n if (duplicates.length > 0) {\n throw new DcqlNonUniqueCredentialQueryIdsError({\n message: `Duplicate credential query ids found: ${duplicates.join(', ')}`,\n })\n }\n}\n\nconst validateCredentialSets = (query: DcqlQuery.Output) => {\n if (!query.credential_sets) return\n\n const credentialQueryIds = new Set(query.credentials.map((c) => c.id))\n\n const undefinedCredentialQueryIds: string[] = []\n for (const credential_set of query.credential_sets) {\n for (const credentialSetOption of credential_set.options) {\n for (const credentialQueryId of credentialSetOption) {\n if (!credentialQueryIds.has(credentialQueryId)) {\n undefinedCredentialQueryIds.push(credentialQueryId)\n }\n }\n }\n }\n\n if (undefinedCredentialQueryIds.length > 0) {\n throw new DcqlCredentialSetError({\n message: `Credential set contains undefined credential id${undefinedCredentialQueryIds.length === 1 ? '' : '`s'} '${undefinedCredentialQueryIds.join(', ')}'`,\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,SAAS,SAAS,OAAkD;AAClE,SAAO,CAAC,CAAC,SAAS,CAAC,MAAM,QAAQ,KAAK,KAAK,OAAO,UAAU;AAC9D;AAEA,IAAM,oBAAN,cAAgC,MAAM;AAEtC;AAEO,SAAS,oBAAoB,OAAmC;AACrE,MAAI,iBAAiB,OAAO;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,OAAO;AACpB,MAAI,SAAS,eAAe,SAAS,cAAc,UAAU,MAAM;AACjE,WAAO;AAAA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BAAiB;AAAA,QACpD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,MAAI,4BAA4B,SAAS,GAAG;AAC1C,UAAM,IAAI,uBAAuB;AAAA,MAC/B,SAAS,kDAAkD,4BAA4B,WAAW,IAAI,KAAK,IAAI,KAAK,4BAA4B,KAAK,IAAI,CAAC;AAAA,IAC5J,CAAC;AAAA,EACH;AACF;","names":["v","v","v","DcqlMdocCredential","DcqlSdJwtVcCredential","DcqlW3cVcCredential","DcqlCredential","DcqlMdocPresentation","DcqlSdJwtVcPresentation","DcqlW3cVcPresentation","DcqlCredentialPresentation","v","v","v","v","DcqlClaimsQuery","query","v","v","DcqlCredentialQuery","v","CredentialSetQuery","DcqlQueryResult","DcqlPresentationResult","v","DcqlPresentation","v","DcqlQuery"]}
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/dcql-error/e-base.ts","../src/dcql-error/e-dcql.ts","../src/dcql-presentation/m-dcql-credential-presentation.ts","../src/u-dcql-credential.ts","../src/u-dcql.ts","../src/u-model.ts","../src/dcql-presentation/m-dcql-presentation-result.ts","../src/dcql-parser/dcql-credential-query-result.ts","../src/dcql-parser/dcql-claims-query-result.ts","../src/dcql-query/m-dcql-claims-query.ts","../src/dcql-query-result/m-dcql-query-result.ts","../src/dcql-query/m-dcql-credential-query.ts","../src/dcql-query/m-dcql-credential-set-query.ts","../src/dcql-presentation/m-dcql-presentation.ts","../src/dcql-query-result/run-dcql-query.ts","../src/dcql-query/m-dcql-query.ts"],"sourcesContent":["export * from './dcql-error/index.js'\nexport * from './dcql-presentation/index.js'\nexport * from './dcql-query-result/index.js'\nexport * from './dcql-query/index.js'\n\nexport {\n DcqlCredential,\n DcqlMdocCredential,\n DcqlSdJwtVcCredential,\n DcqlW3cVcCredential,\n} from './u-dcql-credential.js'\n","function isObject(value: unknown): value is Record<string, unknown> {\n return !!value && !Array.isArray(value) && typeof value === 'object'\n}\n\nclass UnknownCauseError extends Error {\n [key: string]: unknown\n}\n\nexport function getCauseFromUnknown(cause: unknown): Error | undefined {\n if (cause instanceof Error) {\n return cause\n }\n\n const type = typeof cause\n if (type === 'undefined' || type === 'function' || cause === null) {\n return undefined\n }\n\n // Primitive types just get wrapped in an error\n if (type !== 'object') {\n return new Error(String(cause))\n }\n\n // If it's an object, we'll create a synthetic error\n if (isObject(cause)) {\n const err = new UnknownCauseError()\n for (const key in cause) {\n err[key] = cause[key]\n }\n return err\n }\n\n return undefined\n}\n\nexport const isDcqlError = (cause: unknown): cause is DcqlError => {\n if (cause instanceof DcqlError) {\n return true\n }\n if (cause instanceof Error && cause.name === 'DcqlError') {\n // https://github.com/trpc/trpc/pull/4848\n return true\n }\n\n return false\n}\n\nexport function getDcqlErrorFromUnknown(cause: unknown): DcqlError {\n if (isDcqlError(cause)) {\n return cause\n }\n\n const dcqlError = new DcqlError({\n code: 'INTERNAL_SERVER_ERROR',\n cause,\n })\n\n // Inherit stack from error\n if (cause instanceof Error && cause.stack) {\n dcqlError.stack = cause.stack\n }\n\n return dcqlError\n}\n\ntype DCQL_ERROR_CODE = 'PARSE_ERROR' | 'INTERNAL_SERVER_ERROR' | 'NOT_IMPLEMENTED' | 'BAD_REQUEST'\n\nexport class DcqlError extends Error {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore override doesn't work in all environments due to \"This member cannot have an 'override' modifier because it is not declared in the base class 'Error'\"\n public override readonly cause?: Error\n public readonly code\n\n constructor(opts: {\n message?: string\n code: DCQL_ERROR_CODE\n cause?: unknown\n }) {\n const cause = getCauseFromUnknown(opts.cause)\n const message = opts.message ?? cause?.message ?? opts.code\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore https://github.com/tc39/proposal-error-cause\n super(message, { cause })\n\n this.code = opts.code\n this.name = 'DcqlError'\n\n if (!this.cause) {\n // < ES2022 / < Node 16.9.0 compatability\n this.cause = cause\n }\n }\n}\n","import { DcqlError } from './e-base.js'\n\nexport class DcqlCredentialSetError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlUndefinedClaimSetIdError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlNonUniqueCredentialQueryIdsError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlParseError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'PARSE_ERROR', ...opts })\n }\n}\n\nexport class DcqlInvalidClaimsQueryIdError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlMissingClaimSetParseError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'PARSE_ERROR', ...opts })\n }\n}\n\nexport class DcqlInvalidPresentationRecordError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlPresentationResultError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n","import * as v from 'valibot'\nimport { DcqlMdocCredential, DcqlSdJwtVcCredential, DcqlW3cVcCredential } from '../u-dcql-credential'\nimport type { InferModelTypes } from '../u-model'\nimport { Model } from '../u-model'\n\nexport namespace DcqlMdocPresentation {\n export const vModel = DcqlMdocCredential.vModel\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlMdocPresentation = DcqlMdocPresentation.Model['Output']\n\nexport namespace DcqlSdJwtVcPresentation {\n export const vModel = DcqlSdJwtVcCredential.vModel\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlSdJwtVcPresentation = DcqlSdJwtVcPresentation.Model['Output']\n\nexport namespace DcqlW3cVcPresentation {\n export const vModel = DcqlW3cVcCredential.vModel\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlW3cVcPresentation = DcqlW3cVcPresentation.Model['Output']\n\nexport namespace DcqlCredentialPresentation {\n export const model = new Model({\n vModel: v.variant('credential_format', [\n DcqlMdocPresentation.vModel,\n DcqlSdJwtVcPresentation.vModel,\n DcqlW3cVcPresentation.vModel,\n ]),\n })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlCredentialPresentation = DcqlCredentialPresentation.Model['Output']\n","import * as v from 'valibot'\nimport { vJsonRecord, vNonEmptyArray } from './u-dcql.js'\nimport type { InferModelTypes } from './u-model.js'\nimport { Model } from './u-model.js'\n\nexport namespace DcqlMdocCredential {\n export const vNamespaces = v.record(v.string(), v.record(v.string(), v.unknown()))\n export const vModel = v.object({\n credential_format: v.literal('mso_mdoc'),\n doctype: v.string(),\n namespaces: vNamespaces,\n })\n\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n export type NameSpaces = v.InferOutput<typeof vNamespaces>\n}\nexport type DcqlMdocCredential = DcqlMdocCredential.Model['Output']\n\nexport namespace DcqlSdJwtVcCredential {\n export const vClaims = vJsonRecord\n export const vModel = v.object({\n credential_format: v.picklist(['vc+sd-jwt', 'dc+sd-jwt']),\n vct: v.string(),\n claims: vClaims,\n })\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n export type Claims = Model['Output']['claims']\n}\nexport type DcqlSdJwtVcCredential = DcqlSdJwtVcCredential.Model['Output']\n\nexport namespace DcqlW3cVcCredential {\n export const vClaims = vJsonRecord\n export const vModel = v.object({\n credential_format: v.picklist(['jwt_vc_json-ld', 'jwt_vc_json']),\n claims: vClaims,\n })\n\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n export type Claims = Model['Output']['claims']\n}\nexport type DcqlW3cVcCredential = DcqlW3cVcCredential.Model['Output']\n\nexport namespace DcqlCredential {\n export const vModel = v.variant('credential_format', [\n DcqlMdocCredential.vModel,\n DcqlSdJwtVcCredential.vModel,\n DcqlW3cVcCredential.vModel,\n ])\n\n export const vParseSuccess = v.object({\n success: v.literal(true),\n typed: v.literal(true),\n issues: v.optional(v.undefined()),\n input_credential_index: v.number(),\n claim_set_index: v.union([v.number(), v.undefined()]),\n output: DcqlCredential.vModel,\n })\n\n export const vParseFailure = v.object({\n success: v.literal(false),\n typed: v.boolean(),\n output: v.unknown(),\n issues: v.pipe(v.array(v.unknown()), vNonEmptyArray()),\n input_credential_index: v.number(),\n claim_set_index: v.union([v.number(), v.undefined()]),\n })\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlCredential = DcqlCredential.Model['Output']\n","import * as v from 'valibot'\nimport type { UnknownBaseSchema } from './u-model'\nexport const idRegex = /^[a-zA-Z0-9_-]+$/\n\nexport const vNonEmptyArray = <T extends unknown[]>() => {\n return v.custom<[T[number], ...T]>((input) => (input as T).length > 0)\n}\n\nexport const vIdString = v.pipe(v.string(), v.regex(idRegex), v.nonEmpty())\n\nexport type Json = string | number | boolean | null | { [key: string]: Json } | Json[]\n\ninterface HasToJson {\n toJson(): Json\n}\n\nfunction isToJsonable(value: unknown): value is HasToJson {\n if (value === null || typeof value !== 'object') return false\n\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n const toJsonFn = (value as any).toJson\n return typeof toJsonFn === 'function'\n}\n\nexport const vWithJT = <Schema extends UnknownBaseSchema>(schema: Schema) =>\n v.pipe(\n v.custom<v.InferInput<Schema>>(() => true),\n v.rawTransform<v.InferInput<Schema>, v.InferOutput<Schema>>(({ dataset, addIssue, NEVER }) => {\n const result = v.safeParse(schema, dataset.value)\n if (result.success) return dataset.value\n\n if (!isToJsonable(dataset.value)) {\n for (const safeParseIssue of result.issues) {\n addIssue({\n ...safeParseIssue,\n expected: safeParseIssue.expected ?? undefined,\n })\n }\n\n return NEVER\n }\n\n let json: Json\n\n try {\n json = dataset.value.toJson()\n } catch (error) {\n for (const safeParseIssue of result.issues) {\n addIssue({\n ...safeParseIssue,\n expected: safeParseIssue.expected ?? undefined,\n })\n }\n addIssue({ message: 'Json Transformation failed' })\n return NEVER\n }\n\n const safeParseResult: v.SafeParseResult<Schema> = v.safeParse(schema, json)\n if (safeParseResult.success) return dataset.value\n\n for (const safeParseIssue of safeParseResult.issues) {\n addIssue({\n ...safeParseIssue,\n expected: safeParseIssue.expected ?? undefined,\n })\n }\n\n return NEVER\n })\n )\n\nexport const vJsonLiteral = v.union([v.string(), v.number(), v.boolean(), v.null()])\n\nexport type JsonLiteral = v.InferOutput<typeof vJsonLiteral>\n\nexport const vJson: v.GenericSchema<Json> = v.lazy(() =>\n v.union([vJsonLiteral, v.array(vJson), v.record(v.string(), vJson)])\n)\n\nexport const vJsonWithJT: v.GenericSchema<Json> = v.lazy(() =>\n vWithJT(v.union([vJsonLiteral, v.array(vJson), v.record(v.string(), vJson)]))\n)\n\nexport const vJsonRecord = v.record(v.string(), vJson)\nexport type JsonRecord = v.InferOutput<typeof vJsonRecord>\n\nexport const vStringToJson = v.rawTransform<string, Json>(({ dataset, addIssue, NEVER }) => {\n try {\n return JSON.parse(dataset.value) as Json\n } catch (error) {\n addIssue({ message: 'Invalid JSON' })\n return NEVER\n }\n})\n","import * as v from 'valibot'\nimport { DcqlParseError } from './dcql-error/e-dcql'\n\nexport type UnknownBaseSchema = v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>\n\ntype EnsureOutputAssignableToInput<T extends UnknownBaseSchema> = v.InferOutput<T> extends v.InferInput<T> ? T : never\n\nexport class Model<T extends UnknownBaseSchema> {\n constructor(private input: { vModel: EnsureOutputAssignableToInput<T> }) {}\n\n public get v() {\n return this.input.vModel\n }\n\n public parse(input: T) {\n const result = this.safeParse(input)\n\n if (result.success) {\n return result.output\n }\n\n return new DcqlParseError({\n message: JSON.stringify(result.flattened),\n cause: result.error,\n })\n }\n\n public safeParse(\n input: unknown\n ):\n | { success: true; output: v.InferOutput<T> }\n | { success: false; flattened: v.FlatErrors<T>; error: v.ValiError<T> } {\n const res = v.safeParse(this.input.vModel, input)\n if (res.success) {\n return { success: true, output: res.output }\n }\n return {\n success: false,\n error: new v.ValiError(res.issues),\n flattened: v.flatten<T>(res.issues),\n }\n }\n\n public is(input: unknown): input is v.InferOutput<T> {\n return v.is(this.v, input)\n }\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\nexport type InferModelTypes<T extends Model<any>> = T extends Model<infer U>\n ? {\n Input: v.InferInput<U>\n Output: v.InferOutput<U>\n }\n : never\n","import * as v from 'valibot'\n\nimport { DcqlInvalidPresentationRecordError, DcqlPresentationResultError } from '../dcql-error/e-dcql.js'\nimport { runCredentialQuery } from '../dcql-parser/dcql-credential-query-result.js'\nimport { DcqlQueryResult } from '../dcql-query-result/m-dcql-query-result.js'\nimport type { DcqlQuery } from '../dcql-query/m-dcql-query.js'\nimport { DcqlCredential } from '../u-dcql-credential.js'\nimport { vIdString } from '../u-dcql.js'\nimport type { DcqlCredentialPresentation } from './m-dcql-credential-presentation.js'\n\nexport namespace DcqlPresentationResult {\n export const vModel = v.object({\n ...v.omit(DcqlQueryResult.vModel, ['credential_matches']).entries,\n\n invalid_matches: v.union([\n v.record(\n v.pipe(vIdString),\n v.object({\n ...v.omit(DcqlCredential.vParseFailure, ['input_credential_index']).entries,\n presentation_id: v.pipe(vIdString),\n })\n ),\n v.undefined(),\n ]),\n\n valid_matches: v.record(\n v.pipe(vIdString),\n v.object({\n ...v.omit(DcqlCredential.vParseSuccess, ['issues', 'input_credential_index']).entries,\n presentation_id: v.pipe(vIdString),\n })\n ),\n })\n\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n\n export const parse = (input: Input | DcqlQueryResult) => {\n return v.parse(vModel, input)\n }\n\n /**\n * Query if the presentation record can be satisfied by the provided presentations\n * considering the dcql query\n *\n * @param dcqlQuery\n * @param dcqlPresentation\n */\n export const fromDcqlPresentation = (\n dcqlPresentation: Record<string, DcqlCredentialPresentation>,\n ctx: { dcqlQuery: DcqlQuery }\n ): Output => {\n const { dcqlQuery } = ctx\n\n const presentationQueriesResults = Object.fromEntries(\n Object.entries(dcqlPresentation).map(([queryId, presentation]) => {\n const credentialQuery = dcqlQuery.credentials.find((c) => c.id === queryId)\n if (!credentialQuery) {\n throw new DcqlPresentationResultError({\n message: `Query ${queryId} not found in the dcql query. Cannot validate presentation.`,\n })\n }\n\n return [\n queryId,\n runCredentialQuery(credentialQuery, {\n presentation: true,\n credentials: [presentation],\n }),\n ]\n })\n )\n\n let invalidMatches: DcqlPresentationResult['invalid_matches'] = {}\n const validMatches: DcqlPresentationResult['valid_matches'] = {}\n\n for (const [queryId, presentationQueryResult] of Object.entries(presentationQueriesResults)) {\n for (const presentationQueryResultForClaimSet of presentationQueryResult) {\n // NOTE: result can be undefined, but this is only the case if there was a valid claim\n // set match previously and we skip other claim set matching. We don't add these to the parse\n // result.\n const result = presentationQueryResultForClaimSet[0]\n\n if (result?.success) {\n const { issues, input_credential_index, ...rest } = result\n validMatches[queryId] = { ...rest, presentation_id: queryId }\n } else if (result?.success === false) {\n const { input_credential_index, ...rest } = result\n invalidMatches[queryId] = {\n ...rest,\n presentation_id: queryId,\n }\n }\n }\n }\n\n // Only keep the invalid matches that do not have a valid match as well\n invalidMatches = Object.fromEntries(\n Object.entries(invalidMatches ?? {}).filter(([queryId, result]) => validMatches[queryId] === undefined)\n )\n\n const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {\n const matchingOptions = set.options.filter((option) =>\n option.every((credentialQueryId) => validMatches[credentialQueryId]?.success)\n )\n\n return {\n ...set,\n matching_options: matchingOptions.length > 0 ? (matchingOptions as [string[], ...string[][]]) : undefined,\n }\n }) as DcqlQueryResult.Output['credential_sets']\n\n const dqclQueryMatched = credentialSetResults\n ? credentialSetResults.every((set) => !set.required || set.matching_options)\n : Object.keys(invalidMatches).length === 0\n\n return {\n ...dcqlQuery,\n canBeSatisfied: dqclQueryMatched,\n valid_matches: validMatches,\n invalid_matches: Object.keys(invalidMatches).length === 0 ? undefined : {},\n credential_sets: credentialSetResults,\n }\n }\n\n export const validate = (dcqlQueryResult: DcqlPresentationResult) => {\n if (!dcqlQueryResult.canBeSatisfied) {\n throw new DcqlInvalidPresentationRecordError({\n message: 'Invalid Presentation record',\n cause: dcqlQueryResult,\n })\n }\n\n return dcqlQueryResult satisfies Output\n }\n}\nexport type DcqlPresentationResult = DcqlPresentationResult.Output\n","import * as v from 'valibot'\nimport type { DcqlQueryResult } from '../dcql-query-result/m-dcql-query-result.js'\nimport type { DcqlCredentialQuery } from '../dcql-query/m-dcql-credential-query.js'\nimport type { DcqlCredential } from '../u-dcql-credential.js'\nimport type {} from '../u-dcql.js'\nimport { getCredentialQueryParser } from './dcql-claims-query-result.js'\n\nexport const runCredentialQuery = (\n credentialQuery: DcqlCredentialQuery,\n ctx: {\n credentials: DcqlCredential[]\n presentation: boolean\n }\n): DcqlQueryResult.CredentialQueryResult => {\n const { credentials, presentation } = ctx\n const claimSets = credentialQuery.claim_sets ?? [undefined]\n\n const credentialQueryResult: v.InferInput<typeof DcqlQueryResult.vCredentialQueryResult> = []\n\n for (const [claimSetIndex, claim_set] of claimSets.entries()) {\n const credentialParser = getCredentialQueryParser(credentialQuery, {\n claimSet: claim_set,\n presentation,\n })\n\n const claimSetResult: (typeof credentialQueryResult)[number] = []\n\n for (const [credentialIndex, credential] of credentials.entries()) {\n if (claimSetIndex > 0) {\n // if one the credential was successfully parsed against a previous claimsset we don't need to further validate other claim sets\n const previous = credentialQueryResult[claimSetIndex - 1][credentialIndex]\n\n // if the previous credential was successfully parsed we don't need to further validate the current credential\n // we set all further parsing attempts to undefined\n if (previous?.success || !previous) {\n claimSetResult[credentialIndex] = undefined\n continue\n }\n }\n\n const parseResult = v.safeParse(credentialParser, credential)\n claimSetResult.push({\n ...parseResult,\n ...(parseResult.issues && {\n flattened: v.flatten<typeof credentialParser>(parseResult.issues),\n }),\n input_credential_index: credentialIndex,\n claim_set_index: credentialQuery.claim_sets ? claimSetIndex : undefined,\n })\n }\n\n credentialQueryResult.push(claimSetResult)\n }\n\n return credentialQueryResult as DcqlQueryResult.CredentialQueryResult\n}\n","import * as v from 'valibot'\nimport { DcqlInvalidClaimsQueryIdError, DcqlMissingClaimSetParseError } from '../dcql-error/e-dcql.js'\nimport { DcqlClaimsQuery } from '../dcql-query/m-dcql-claims-query.js'\nimport type { DcqlCredentialQuery } from '../dcql-query/m-dcql-credential-query.js'\nimport { vWithJT } from '../u-dcql.js'\nimport { vJson, vJsonRecord } from '../u-dcql.js'\n\nconst getClaimParser = (input: {\n value?: string | number | boolean\n values?: (string | number | boolean)[]\n}) => {\n const { value, values } = input\n if (value) {\n return vWithJT(v.literal(value))\n }\n\n if (values) {\n return vWithJT(v.union(values.map((val) => v.literal(val))))\n }\n\n return v.nonNullish(v.any())\n}\n\nexport const getNamespacesParser = (claimsQueries: DcqlClaimsQuery.Mdoc[]) => {\n const claimsForNamespace: Record<string, DcqlClaimsQuery.MdocPath[]> = {}\n\n for (const claimQuery of claimsQueries) {\n // Normalize the query to the latest path syntax\n const mdocPathQuery: DcqlClaimsQuery.MdocPath = v.is(DcqlClaimsQuery.vMdocNamespace, claimQuery)\n ? {\n id: claimQuery.id,\n path: [claimQuery.namespace, claimQuery.claim_name],\n values: claimQuery.values,\n }\n : claimQuery\n\n const namespace = mdocPathQuery.path[0]\n if (claimsForNamespace[namespace]) {\n claimsForNamespace[namespace]?.push({ ...mdocPathQuery })\n } else {\n claimsForNamespace[namespace] = [{ ...mdocPathQuery }]\n }\n }\n\n const parsersForNamespaces = Object.entries(claimsForNamespace).map(([namespace, claims]) => {\n const claimParsers = Object.fromEntries(claims.map((claim) => [claim.path[1], getClaimParser(claim)]))\n return [namespace, v.object(claimParsers)]\n })\n\n return v.object(Object.fromEntries(parsersForNamespaces))\n}\n\nconst getClaimQueryParser = (\n claimQuery: DcqlClaimsQuery.W3cAndSdJwtVc,\n ctx: { index: number; presentation: boolean }\n): typeof vJson => {\n const { index, presentation } = ctx\n const pathElement = claimQuery.path[index]\n const isLast = index === claimQuery.path.length - 1\n\n const vClaimParser = getClaimParser(claimQuery)\n\n if (typeof pathElement === 'number') {\n const elementParser = isLast ? vClaimParser : getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 })\n\n if (presentation) {\n // We allow both the concrete value and an array of one value\n return v.union([\n v.pipe(\n v.array(vJson),\n v.length(1),\n v.transform((input) => input[0]),\n elementParser\n ),\n elementParser,\n ])\n }\n\n return v.pipe(\n v.array(vJson),\n v.transform((input) => input[pathElement]),\n elementParser\n )\n }\n if (typeof pathElement === 'string') {\n return v.object({\n [pathElement]: isLast ? vClaimParser : getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 }),\n })\n }\n return isLast ? v.array(vClaimParser) : v.array(getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 }))\n}\n\nexport const getJsonClaimsParser = (claimsQueries: DcqlClaimsQuery.W3cAndSdJwtVc[], ctx: { presentation: boolean }) => {\n const claimParser = v.intersect(\n claimsQueries.map(\n (claimQuery) =>\n getClaimQueryParser(claimQuery, {\n ...ctx,\n index: 0,\n }) as typeof vJsonRecord\n )\n )\n\n return claimParser\n}\n\nexport const getMdocClaimsQueriesForClaimSet = (\n claimsQueries: DcqlClaimsQuery.Mdoc[],\n claimSet: string[]\n): DcqlClaimsQuery.Mdoc[] => {\n return claimSet.map((credential_id) => {\n const query = claimsQueries.find((query) => query.id === credential_id)\n if (!query) {\n throw new DcqlInvalidClaimsQueryIdError({\n message: `Claims-query with id '${credential_id}' not found.`,\n })\n }\n\n return query\n })\n}\n\nexport const getJsonClaimsQueriesForClaimSet = (\n claimsQueries: DcqlClaimsQuery.W3cAndSdJwtVc[],\n claimSet: string[]\n): DcqlClaimsQuery.W3cAndSdJwtVc[] => {\n return claimSet.map((credential_id) => {\n const query = claimsQueries.find((query) => query.id === credential_id)\n if (!query) {\n throw new DcqlInvalidClaimsQueryIdError({\n message: `Claims-query with id '${credential_id}' not found.`,\n })\n }\n return query\n })\n}\n\nconst getMdocParser = (\n credentialQuery: DcqlCredentialQuery.Mdoc,\n ctx: { claimSet?: NonNullable<DcqlCredentialQuery['claim_sets']>[number] }\n) => {\n const { claimSet } = ctx\n\n const vDoctype = credentialQuery.meta?.doctype_value ? v.literal(credentialQuery.meta.doctype_value) : v.string()\n\n const claimSetQueries =\n credentialQuery.claims && claimSet\n ? getMdocClaimsQueriesForClaimSet(credentialQuery.claims, claimSet)\n : credentialQuery.claims\n\n const credentialParser = v.object({\n credential_format: v.literal('mso_mdoc'),\n doctype: vDoctype,\n namespaces: claimSetQueries\n ? getNamespacesParser(claimSetQueries)\n : v.record(v.string(), v.record(v.string(), v.unknown())),\n })\n\n return credentialParser\n}\n\nconst getW3cVcSdJwtVcParser = (\n credentialQuery: DcqlCredentialQuery.SdJwtVc | DcqlCredentialQuery.W3cVc,\n ctx: {\n claimSet?: NonNullable<DcqlCredentialQuery['claim_sets']>[number]\n presentation: boolean\n }\n) => {\n const { claimSet } = ctx\n const claimSetQueries =\n credentialQuery.claims && claimSet\n ? getJsonClaimsQueriesForClaimSet(credentialQuery.claims, claimSet)\n : credentialQuery.claims\n\n if (credentialQuery.format === 'vc+sd-jwt' || credentialQuery.format === 'dc+sd-jwt') {\n return v.object({\n credential_format: v.literal(credentialQuery.format),\n vct: credentialQuery.meta?.vct_values ? v.picklist(credentialQuery.meta.vct_values) : v.string(),\n claims: claimSetQueries ? getJsonClaimsParser(claimSetQueries, ctx) : vJsonRecord,\n })\n }\n const credentialParser = v.object({\n credential_format: v.picklist(['jwt_vc_json', 'jwt_vc_json-ld']),\n claims: claimSetQueries ? getJsonClaimsParser(claimSetQueries, ctx) : vJsonRecord,\n })\n\n return credentialParser\n}\n\nexport const getCredentialQueryParser = (\n credentialQuery: DcqlCredentialQuery,\n ctx: {\n claimSet?: NonNullable<DcqlCredentialQuery['claim_sets']>[number]\n presentation: boolean\n }\n) => {\n if (credentialQuery.claim_sets && !ctx.claimSet) {\n throw new DcqlMissingClaimSetParseError({\n message: 'credentialQuery specifies claim_sets but no claim_set for parsing is provided.',\n })\n }\n\n if (credentialQuery.format === 'mso_mdoc') {\n return getMdocParser(credentialQuery, ctx)\n }\n return getW3cVcSdJwtVcParser(credentialQuery, ctx)\n}\n","import * as v from 'valibot'\nimport { vIdString, vNonEmptyArray } from '../u-dcql.js'\n\n/**\n * Specifies claims withing a requested Credential.\n */\nexport namespace DcqlClaimsQuery {\n export const vValue = v.union([v.string(), v.pipe(v.number(), v.integer()), v.boolean()])\n\n export const vPath = v.union([v.string(), v.pipe(v.number(), v.integer(), v.minValue(0)), v.null()])\n\n export const vW3cSdJwtVc = v.object({\n id: v.pipe(\n v.optional(vIdString),\n v.description(\n 'A string identifying the particular claim. The value MUST be a non-empty string consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular claims array, the same id MUST NOT be present more than once.'\n )\n ),\n path: v.pipe(\n v.array(vPath),\n vNonEmptyArray(),\n v.description(\n 'A non-empty array representing a claims path pointer that specifies the path to a claim within the Verifiable Credential.'\n )\n ),\n values: v.pipe(\n v.optional(v.array(vValue)),\n v.description(\n 'An array of strings, integers or boolean values that specifies the expected values of the claim. If the values property is present, the Wallet SHOULD return the claim only if the type and value of the claim both match for at least one of the elements in the array.'\n )\n ),\n })\n export type W3cAndSdJwtVc = v.InferOutput<typeof vW3cSdJwtVc>\n\n const vMdocBase = v.object({\n id: v.pipe(\n v.optional(vIdString),\n v.description(\n 'A string identifying the particular claim. The value MUST be a non-empty string consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular claims array, the same id MUST NOT be present more than once.'\n )\n ),\n values: v.pipe(\n v.optional(v.array(vValue)),\n v.description(\n 'An array of strings, integers or boolean values that specifies the expected values of the claim. If the values property is present, the Wallet SHOULD return the claim only if the type and value of the claim both match for at least one of the elements in the array.'\n )\n ),\n })\n\n // Syntax up until Draft 23 of OID4VP. Keeping due to Draft 23 having\n // reach ID-3 status and thus being targeted by several implementations\n export const vMdocNamespace = v.object({\n ...vMdocBase.entries,\n\n namespace: v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the namespace of the data element within the mdoc, e.g., org.iso.18013.5.1.'\n )\n ),\n claim_name: v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the data element identifier of the data element within the provided namespace in the mdoc, e.g., first_name.'\n )\n ),\n })\n\n // Syntax starting from Draft 24 of OID4VP\n export const vMdocPath = v.object({\n ...vMdocBase.entries,\n\n intent_to_retain: v.pipe(\n v.optional(v.boolean()),\n v.description(\n 'A boolean that is equivalent to `IntentToRetain` variable defined in Section 8.3.2.1.2.1 of [@ISO.18013-5].'\n )\n ),\n\n path: v.pipe(\n v.tuple([\n v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the namespace of the data element within the mdoc, e.g., org.iso.18013.5.1.'\n )\n ),\n v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the data element identifier of the data element within the provided namespace in the mdoc, e.g., first_name.'\n )\n ),\n ]),\n v.description(\n 'An array defining a claims path pointer into an mdoc. It must contain two elements of type string. The first element refers to a namespace and the second element refers to a data element identifier.'\n )\n ),\n })\n export const vMdoc = v.union([vMdocNamespace, vMdocPath])\n export type MdocNamespace = v.InferOutput<typeof vMdocNamespace>\n export type MdocPath = v.InferOutput<typeof vMdocPath>\n export type Mdoc = v.InferOutput<typeof vMdoc>\n\n export const vModel = v.union([vMdoc, vW3cSdJwtVc])\n export type Input = v.InferInput<typeof vModel>\n export type Out = v.InferOutput<typeof vModel>\n}\nexport type DcqlClaimsQuery = DcqlClaimsQuery.Out\n","import * as v from 'valibot'\nimport { DcqlCredentialQuery } from '../dcql-query/m-dcql-credential-query.js'\nimport { CredentialSetQuery } from '../dcql-query/m-dcql-credential-set-query.js'\nimport { DcqlCredential } from '../u-dcql-credential.js'\nimport { vIdString, vNonEmptyArray } from '../u-dcql.js'\n\nexport namespace DcqlQueryResult {\n export const vCredentialQueryResult = v.pipe(\n v.array(v.array(v.union([v.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure]))),\n vNonEmptyArray()\n )\n\n export type CredentialQueryResult = v.InferOutput<typeof vCredentialQueryResult>\n\n export const vModel = v.object({\n credentials: v.pipe(\n v.array(DcqlCredentialQuery.vModel),\n vNonEmptyArray(),\n v.description(\n 'REQUIRED. A non-empty array of Credential Queries that specify the requested Verifiable Credentials.'\n )\n ),\n\n credential_matches: v.record(\n v.pipe(vIdString),\n v.union([\n v.object({\n ...DcqlCredential.vParseSuccess.entries,\n all: v.pipe(\n v.array(\n v.pipe(\n v.array(v.union([v.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure])),\n vNonEmptyArray()\n )\n ),\n vNonEmptyArray()\n ),\n }),\n v.object({\n success: DcqlCredential.vParseFailure.entries.success,\n all: v.pipe(\n v.array(\n v.pipe(\n v.array(v.union([v.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure])),\n vNonEmptyArray()\n )\n ),\n vNonEmptyArray()\n ),\n }),\n ])\n ),\n\n credential_sets: v.optional(\n v.pipe(\n v.array(\n v.object({\n ...CredentialSetQuery.vModel.entries,\n matching_options: v.union([v.undefined(), v.pipe(v.array(v.array(v.string())), vNonEmptyArray())]),\n })\n ),\n vNonEmptyArray(),\n v.description(\n 'OPTIONAL. A non-empty array of credential set queries that specifies additional constraints on which of the requested Verifiable Credentials to return.'\n )\n )\n ),\n\n canBeSatisfied: v.boolean(),\n })\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n\n export type CredentialMatch = Input['credential_matches'][number]\n export type CredentialMatchRecord = Input['credential_matches']\n}\nexport type DcqlQueryResult = DcqlQueryResult.Output\n","import * as v from 'valibot'\nimport { DcqlUndefinedClaimSetIdError } from '../dcql-error/e-dcql.js'\nimport { idRegex, vIdString, vNonEmptyArray } from '../u-dcql.js'\nimport { DcqlClaimsQuery } from './m-dcql-claims-query.js'\n\n/**\n * A Credential Query is an object representing a request for a presentation of one Credential.\n */\nexport namespace DcqlCredentialQuery {\n const vBase = v.object({\n id: v.pipe(\n v.string(),\n v.regex(idRegex),\n v.description(\n `REQUIRED. A string identifying the Credential in the response and, if provided, the constraints in 'credential_sets'.`\n )\n ),\n claim_sets: v.pipe(\n v.optional(v.pipe(v.array(v.pipe(v.array(vIdString), vNonEmptyArray())), vNonEmptyArray())),\n v.description(\n `OPTIONAL. A non-empty array containing arrays of identifiers for elements in 'claims' that specifies which combinations of 'claims' for the Credential are requested.`\n )\n ),\n })\n\n export const vMdoc = v.object({\n ...vBase.entries,\n format: v.pipe(\n v.literal('mso_mdoc'),\n v.description('REQUIRED. A string that specifies the format of the requested Verifiable Credential.')\n ),\n claims: v.pipe(\n v.optional(v.pipe(v.array(DcqlClaimsQuery.vMdoc), vNonEmptyArray())),\n v.description('OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.')\n ),\n meta: v.pipe(\n v.optional(\n v.object({\n doctype_value: v.pipe(\n v.optional(v.string()),\n v.description(\n 'OPTIONAL. String that specifies an allowed value for the doctype of the requested Verifiable Credential.'\n )\n ),\n })\n ),\n v.description(\n 'OPTIONAL. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential.'\n )\n ),\n })\n export type Mdoc = v.InferOutput<typeof vMdoc>\n\n export const vSdJwtVc = v.object({\n ...vBase.entries,\n format: v.pipe(\n v.picklist(['vc+sd-jwt', 'dc+sd-jwt']),\n v.description('REQUIRED. A string that specifies the format of the requested Verifiable Credential.')\n ),\n claims: v.pipe(\n v.optional(v.pipe(v.array(DcqlClaimsQuery.vW3cSdJwtVc), vNonEmptyArray())),\n v.description('OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.')\n ),\n meta: v.pipe(\n v.optional(\n v.pipe(\n v.object({\n vct_values: v.optional(v.array(v.string())),\n }),\n v.description(\n 'OPTIONAL. An array of strings that specifies allowed values for the type of the requested Verifiable Credential.'\n )\n )\n ),\n v.description(\n 'OPTIONAL. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential.'\n )\n ),\n })\n export type SdJwtVc = v.InferOutput<typeof vSdJwtVc>\n\n export const vW3cVc = v.object({\n ...vBase.entries,\n format: v.picklist(['jwt_vc_json', 'jwt_vc_json-ld']),\n claims: v.optional(v.pipe(v.array(DcqlClaimsQuery.vW3cSdJwtVc), vNonEmptyArray())),\n })\n export type W3cVc = v.InferOutput<typeof vW3cVc>\n\n export const vModel = v.variant('format', [vMdoc, vSdJwtVc, vW3cVc])\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n\n export const validate = (credentialQuery: Output) => {\n claimSetIdsAreDefined(credentialQuery)\n }\n}\nexport type DcqlCredentialQuery = DcqlCredentialQuery.Output\n\n// --- validations --- //\n\nconst claimSetIdsAreDefined = (credentialQuery: DcqlCredentialQuery) => {\n if (!credentialQuery.claim_sets) return\n const claimIds = new Set(credentialQuery.claims?.map((claim) => claim.id))\n\n const undefinedClaims: string[] = []\n for (const claim_set of credentialQuery.claim_sets) {\n for (const claim_id of claim_set) {\n if (!claimIds.has(claim_id)) {\n undefinedClaims.push(claim_id)\n }\n }\n }\n\n if (undefinedClaims.length > 0) {\n throw new DcqlUndefinedClaimSetIdError({\n message: `Credential set contains undefined credential id${undefinedClaims.length === 0 ? '' : '`s'} '${undefinedClaims.join(', ')}'`,\n })\n }\n}\n","import * as v from 'valibot'\nimport { vIdString, vNonEmptyArray } from '../u-dcql.js'\n\n/**\n * A Credential Set Query is an object representing\n * a request for one or more credentials to satisfy a particular use case with the Verifier.\n */\nexport namespace CredentialSetQuery {\n export const vModel = v.object({\n options: v.pipe(\n v.array(v.array(vIdString)),\n vNonEmptyArray(),\n v.description(\n 'REQUIRED. A non-empty array, where each value in the array is a list of Credential Query identifiers representing one set of Credentials that satisfies the use case.'\n )\n ),\n required: v.pipe(\n v.optional(v.boolean(), true),\n v.description(\n `OPTIONAL. Boolean which indicates whether this set of Credentials is required to satisfy the particular use case at the Verifier. If omitted, the default value is 'true'.`\n )\n ),\n purpose: v.pipe(\n v.optional(v.union([v.string(), v.number(), v.record(v.string(), v.unknown())])),\n v.description('OPTIONAL. A string, number or object specifying the purpose of the query.')\n ),\n })\n\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n}\nexport type CredentialSetQuery = CredentialSetQuery.Output\n","import * as v from 'valibot'\nimport { vIdString, vJsonRecord, vStringToJson } from '../u-dcql.js'\n\nexport namespace DcqlPresentation {\n export const vModel = v.record(vIdString, v.union([v.string(), vJsonRecord]))\n\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n export const parse = (input: Input | string) => {\n if (typeof input === 'string') {\n return v.parse(v.pipe(v.string(), vStringToJson, vModel), input)\n }\n\n return v.parse(vModel, input)\n }\n\n export const encode = (input: Output) => {\n return JSON.stringify(input)\n }\n}\nexport type DcqlPresentation = DcqlPresentation.Output\n","import type * as v from 'valibot'\nimport { runCredentialQuery } from '../dcql-parser/dcql-credential-query-result.js'\nimport type { DcqlQuery } from '../dcql-query/m-dcql-query.js'\nimport type { DcqlCredential } from '../u-dcql-credential.js'\nimport type { DcqlQueryResult } from './m-dcql-query-result.js'\n\nexport const runDcqlQuery = (\n dcqlQuery: DcqlQuery.Output,\n ctx: {\n credentials: DcqlCredential[]\n presentation: boolean\n }\n): DcqlQueryResult => {\n const credentialQueriesResults = Object.fromEntries(\n dcqlQuery.credentials.map((credentialQuery) => [credentialQuery.id, runCredentialQuery(credentialQuery, ctx)])\n )\n\n const credentialMatches = Object.fromEntries(\n Object.entries(credentialQueriesResults).map(([key, credentialQueryResult]) => {\n // Find the best match for each credential query\n let bestMatch: v.InferOutput<typeof DcqlCredential.vParseSuccess> | undefined = undefined\n\n for (const credentialParseResult of credentialQueryResult) {\n const bestMatchForCredential = credentialParseResult.find((result) => result?.success === true)\n\n if (!bestMatch && bestMatchForCredential) {\n const { issues, ...matchWithoutIssues } = bestMatchForCredential\n bestMatch = matchWithoutIssues\n continue\n }\n\n // biome-ignore lint/style/noNonNullAssertion: <explanation>\n if (bestMatchForCredential && bestMatchForCredential.claim_set_index! < bestMatch?.claim_set_index!) {\n const { issues, ...matchWithoutIssues } = bestMatchForCredential\n bestMatch = matchWithoutIssues\n }\n }\n\n return [\n key,\n bestMatch ? { ...bestMatch, all: credentialQueryResult } : { success: false, all: credentialQueryResult },\n ]\n })\n ) satisfies DcqlQueryResult.CredentialMatchRecord\n\n const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {\n const matchingOptions = set.options.filter((option) =>\n option.every((credentialQueryId) => credentialMatches[credentialQueryId]?.success)\n )\n\n return {\n ...set,\n matching_options: matchingOptions.length > 0 ? (matchingOptions as [string[], ...string[][]]) : undefined,\n }\n }) as DcqlQueryResult.Output['credential_sets']\n\n const dqclQueryMatched = credentialSetResults\n ? credentialSetResults.every((set) => !set.required || set.matching_options)\n : Object.values(credentialMatches).every((query) => query.success)\n\n return {\n ...dcqlQuery,\n canBeSatisfied: dqclQueryMatched,\n credential_matches: credentialMatches as DcqlQueryResult['credential_matches'],\n credential_sets: credentialSetResults,\n }\n}\n","import * as v from 'valibot'\nimport { DcqlCredentialSetError, DcqlNonUniqueCredentialQueryIdsError } from '../dcql-error/e-dcql.js'\nimport { runDcqlQuery } from '../dcql-query-result/run-dcql-query.js'\nimport type { DcqlCredential } from '../u-dcql-credential.js'\nimport { vNonEmptyArray } from '../u-dcql.js'\nimport { DcqlCredentialQuery } from './m-dcql-credential-query.js'\nimport { CredentialSetQuery } from './m-dcql-credential-set-query.js'\n\n/**\n * The Digital Credentials Query Language (DCQL, pronounced [ˈdakl̩]) is a\n * JSON-encoded query language that allows the Verifier to request Verifiable\n * Presentations that match the query. The Verifier MAY encode constraints on the\n * combinations of credentials and claims that are requested. The Wallet evaluates\n * the query against the Verifiable Credentials it holds and returns Verifiable\n * Presentations matching the query.\n */\nexport namespace DcqlQuery {\n export const vModel = v.object({\n credentials: v.pipe(\n v.array(DcqlCredentialQuery.vModel),\n vNonEmptyArray(),\n v.description(\n 'REQUIRED. A non-empty array of Credential Queries that specify the requested Verifiable Credentials.'\n )\n ),\n credential_sets: v.pipe(\n v.optional(v.pipe(v.array(CredentialSetQuery.vModel), vNonEmptyArray())),\n v.description(\n 'OPTIONAL. A non-empty array of credential set queries that specifies additional constraints on which of the requested Verifiable Credentials to return.'\n )\n ),\n })\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n export const validate = (dcqlQuery: Output) => {\n validateUniqueCredentialQueryIds(dcqlQuery)\n validateCredentialSets(dcqlQuery)\n dcqlQuery.credentials.forEach(DcqlCredentialQuery.validate)\n }\n export const query = (dcqlQuery: Output, credentials: DcqlCredential[]) => {\n return runDcqlQuery(dcqlQuery, { credentials, presentation: false })\n }\n\n export const parse = (input: Input) => {\n return v.parse(vModel, input)\n }\n}\nexport type DcqlQuery = DcqlQuery.Output\n\n// --- validations --- //\n\nconst validateUniqueCredentialQueryIds = (query: DcqlQuery.Output) => {\n const ids = query.credentials.map((c) => c.id)\n const duplicates = ids.filter((id, index) => ids.indexOf(id) !== index)\n\n if (duplicates.length > 0) {\n throw new DcqlNonUniqueCredentialQueryIdsError({\n message: `Duplicate credential query ids found: ${duplicates.join(', ')}`,\n })\n }\n}\n\nconst validateCredentialSets = (query: DcqlQuery.Output) => {\n if (!query.credential_sets) return\n\n const credentialQueryIds = new Set(query.credentials.map((c) => c.id))\n\n const undefinedCredentialQueryIds: string[] = []\n for (const credential_set of query.credential_sets) {\n for (const credentialSetOption of credential_set.options) {\n for (const credentialQueryId of credentialSetOption) {\n if (!credentialQueryIds.has(credentialQueryId)) {\n undefinedCredentialQueryIds.push(credentialQueryId)\n }\n }\n }\n }\n\n if (undefinedCredentialQueryIds.length > 0) {\n throw new DcqlCredentialSetError({\n message: `Credential set contains undefined credential id${undefinedCredentialQueryIds.length === 1 ? '' : '`s'} '${undefinedCredentialQueryIds.join(', ')}'`,\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;A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mCjB,IAAM,mCAAmC,CAAC,UAA4B;AACpE,QAAM,MAAM,MAAM,YAAY,IAAI,CAAC,MAAM,EAAE,EAAE;AAC7C,QAAM,aAAa,IAAI,OAAO,CAAC,IAAI,UAAU,IAAI,QAAQ,EAAE,MAAM,KAAK;AAEtE,MAAI,WAAW,SAAS,GAAG;AACzB,UAAM,IAAI,qCAAqC;AAAA,MAC7C,SAAS,yCAAyC,WAAW,KAAK,IAAI,CAAC;AAAA,IACzE,CAAC;AAAA,EACH;AACF;AAEA,IAAM,yBAAyB,CAAC,UAA4B;AAC1D,MAAI,CAAC,MAAM,gBAAiB;AAE5B,QAAM,qBAAqB,IAAI,IAAI,MAAM,YAAY,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;AAErE,QAAM,8BAAwC,CAAC;AAC/C,aAAW,kBAAkB,MAAM,iBAAiB;AAClD,eAAW,uBAAuB,eAAe,SAAS;AACxD,iBAAW,qBAAqB,qBAAqB;AACnD,YAAI,CAAC,mBAAmB,IAAI,iBAAiB,GAAG;AAC9C,sCAA4B,KAAK,iBAAiB;AAAA,QACpD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,MAAI,4BAA4B,SAAS,GAAG;AAC1C,UAAM,IAAI,uBAAuB;AAAA,MAC/B,SAAS,kDAAkD,4BAA4B,WAAW,IAAI,KAAK,IAAI,KAAK,4BAA4B,KAAK,IAAI,CAAC;AAAA,IAC5J,CAAC;AAAA,EACH;AACF;","names":["v","v","v","DcqlMdocCredential","DcqlSdJwtVcCredential","DcqlW3cVcCredential","DcqlCredential","DcqlMdocPresentation","DcqlSdJwtVcPresentation","DcqlW3cVcPresentation","DcqlCredentialPresentation","v","v","v","v","DcqlClaimsQuery","query","v","v","DcqlCredentialQuery","v","CredentialSetQuery","DcqlQueryResult","DcqlPresentationResult","v","DcqlPresentation","v","DcqlQuery"]}
|
package/dist/index.mjs
CHANGED
@@ -528,24 +528,23 @@ var getCredentialQueryParser = (credentialQuery, ctx) => {
|
|
528
528
|
var runCredentialQuery = (credentialQuery, ctx) => {
|
529
529
|
const { credentials, presentation } = ctx;
|
530
530
|
const claimSets = credentialQuery.claim_sets ?? [void 0];
|
531
|
-
const credentialQueryResult =
|
532
|
-
claimSets.length
|
533
|
-
).fill([]);
|
531
|
+
const credentialQueryResult = [];
|
534
532
|
for (const [claimSetIndex, claim_set] of claimSets.entries()) {
|
535
533
|
const credentialParser = getCredentialQueryParser(credentialQuery, {
|
536
534
|
claimSet: claim_set,
|
537
535
|
presentation
|
538
536
|
});
|
537
|
+
const claimSetResult = [];
|
539
538
|
for (const [credentialIndex, credential] of credentials.entries()) {
|
540
539
|
if (claimSetIndex > 0) {
|
541
|
-
const previous = credentialQueryResult[claimSetIndex - 1]
|
540
|
+
const previous = credentialQueryResult[claimSetIndex - 1][credentialIndex];
|
542
541
|
if (previous?.success || !previous) {
|
543
|
-
|
542
|
+
claimSetResult[credentialIndex] = void 0;
|
544
543
|
continue;
|
545
544
|
}
|
546
545
|
}
|
547
546
|
const parseResult = v7.safeParse(credentialParser, credential);
|
548
|
-
|
547
|
+
claimSetResult.push({
|
549
548
|
...parseResult,
|
550
549
|
...parseResult.issues && {
|
551
550
|
flattened: v7.flatten(parseResult.issues)
|
@@ -554,6 +553,7 @@ var runCredentialQuery = (credentialQuery, ctx) => {
|
|
554
553
|
claim_set_index: credentialQuery.claim_sets ? claimSetIndex : void 0
|
555
554
|
});
|
556
555
|
}
|
556
|
+
credentialQueryResult.push(claimSetResult);
|
557
557
|
}
|
558
558
|
return credentialQueryResult;
|
559
559
|
};
|
@@ -792,16 +792,15 @@ var DcqlPresentationResult;
|
|
792
792
|
];
|
793
793
|
})
|
794
794
|
);
|
795
|
-
let invalidMatches =
|
795
|
+
let invalidMatches = {};
|
796
796
|
const validMatches = {};
|
797
797
|
for (const [queryId, presentationQueryResult] of Object.entries(presentationQueriesResults)) {
|
798
798
|
for (const presentationQueryResultForClaimSet of presentationQueryResult) {
|
799
799
|
const result = presentationQueryResultForClaimSet[0];
|
800
|
-
if (result
|
800
|
+
if (result?.success) {
|
801
801
|
const { issues, input_credential_index, ...rest } = result;
|
802
802
|
validMatches[queryId] = { ...rest, presentation_id: queryId };
|
803
|
-
} else {
|
804
|
-
if (!invalidMatches) invalidMatches = {};
|
803
|
+
} else if (result?.success === false) {
|
805
804
|
const { input_credential_index, ...rest } = result;
|
806
805
|
invalidMatches[queryId] = {
|
807
806
|
...rest,
|
@@ -810,6 +809,9 @@ var DcqlPresentationResult;
|
|
810
809
|
}
|
811
810
|
}
|
812
811
|
}
|
812
|
+
invalidMatches = Object.fromEntries(
|
813
|
+
Object.entries(invalidMatches ?? {}).filter(([queryId, result]) => validMatches[queryId] === void 0)
|
814
|
+
);
|
813
815
|
const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {
|
814
816
|
const matchingOptions = set.options.filter(
|
815
817
|
(option) => option.every((credentialQueryId) => validMatches[credentialQueryId]?.success)
|
@@ -819,12 +821,12 @@ var DcqlPresentationResult;
|
|
819
821
|
matching_options: matchingOptions.length > 0 ? matchingOptions : void 0
|
820
822
|
};
|
821
823
|
});
|
822
|
-
const dqclQueryMatched = credentialSetResults ? credentialSetResults.every((set) => !set.required || set.matching_options) :
|
824
|
+
const dqclQueryMatched = credentialSetResults ? credentialSetResults.every((set) => !set.required || set.matching_options) : Object.keys(invalidMatches).length === 0;
|
823
825
|
return {
|
824
826
|
...dcqlQuery,
|
825
827
|
canBeSatisfied: dqclQueryMatched,
|
826
828
|
valid_matches: validMatches,
|
827
|
-
invalid_matches: invalidMatches,
|
829
|
+
invalid_matches: Object.keys(invalidMatches).length === 0 ? void 0 : {},
|
828
830
|
credential_sets: credentialSetResults
|
829
831
|
};
|
830
832
|
};
|
package/dist/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/dcql-error/e-base.ts","../src/dcql-error/e-dcql.ts","../src/dcql-presentation/m-dcql-credential-presentation.ts","../src/u-dcql-credential.ts","../src/u-dcql.ts","../src/u-model.ts","../src/dcql-presentation/m-dcql-presentation-result.ts","../src/dcql-parser/dcql-credential-query-result.ts","../src/dcql-parser/dcql-claims-query-result.ts","../src/dcql-query/m-dcql-claims-query.ts","../src/dcql-query-result/m-dcql-query-result.ts","../src/dcql-query/m-dcql-credential-query.ts","../src/dcql-query/m-dcql-credential-set-query.ts","../src/dcql-presentation/m-dcql-presentation.ts","../src/dcql-query-result/run-dcql-query.ts","../src/dcql-query/m-dcql-query.ts"],"sourcesContent":["function isObject(value: unknown): value is Record<string, unknown> {\n return !!value && !Array.isArray(value) && typeof value === 'object'\n}\n\nclass UnknownCauseError extends Error {\n [key: string]: unknown\n}\n\nexport function getCauseFromUnknown(cause: unknown): Error | undefined {\n if (cause instanceof Error) {\n return cause\n }\n\n const type = typeof cause\n if (type === 'undefined' || type === 'function' || cause === null) {\n return undefined\n }\n\n // Primitive types just get wrapped in an error\n if (type !== 'object') {\n return new Error(String(cause))\n }\n\n // If it's an object, we'll create a synthetic error\n if (isObject(cause)) {\n const err = new UnknownCauseError()\n for (const key in cause) {\n err[key] = cause[key]\n }\n return err\n }\n\n return undefined\n}\n\nexport const isDcqlError = (cause: unknown): cause is DcqlError => {\n if (cause instanceof DcqlError) {\n return true\n }\n if (cause instanceof Error && cause.name === 'DcqlError') {\n // https://github.com/trpc/trpc/pull/4848\n return true\n }\n\n return false\n}\n\nexport function getDcqlErrorFromUnknown(cause: unknown): DcqlError {\n if (isDcqlError(cause)) {\n return cause\n }\n\n const dcqlError = new DcqlError({\n code: 'INTERNAL_SERVER_ERROR',\n cause,\n })\n\n // Inherit stack from error\n if (cause instanceof Error && cause.stack) {\n dcqlError.stack = cause.stack\n }\n\n return dcqlError\n}\n\ntype DCQL_ERROR_CODE = 'PARSE_ERROR' | 'INTERNAL_SERVER_ERROR' | 'NOT_IMPLEMENTED' | 'BAD_REQUEST'\n\nexport class DcqlError extends Error {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore override doesn't work in all environments due to \"This member cannot have an 'override' modifier because it is not declared in the base class 'Error'\"\n public override readonly cause?: Error\n public readonly code\n\n constructor(opts: {\n message?: string\n code: DCQL_ERROR_CODE\n cause?: unknown\n }) {\n const cause = getCauseFromUnknown(opts.cause)\n const message = opts.message ?? cause?.message ?? opts.code\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore https://github.com/tc39/proposal-error-cause\n super(message, { cause })\n\n this.code = opts.code\n this.name = 'DcqlError'\n\n if (!this.cause) {\n // < ES2022 / < Node 16.9.0 compatability\n this.cause = cause\n }\n }\n}\n","import { DcqlError } from './e-base.js'\n\nexport class DcqlCredentialSetError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlUndefinedClaimSetIdError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlNonUniqueCredentialQueryIdsError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlParseError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'PARSE_ERROR', ...opts })\n }\n}\n\nexport class DcqlInvalidClaimsQueryIdError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlMissingClaimSetParseError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'PARSE_ERROR', ...opts })\n }\n}\n\nexport class DcqlInvalidPresentationRecordError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlPresentationResultError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n","import * as v from 'valibot'\nimport { DcqlMdocCredential, DcqlSdJwtVcCredential, DcqlW3cVcCredential } from '../u-dcql-credential'\nimport type { InferModelTypes } from '../u-model'\nimport { Model } from '../u-model'\n\nexport namespace DcqlMdocPresentation {\n export const vModel = DcqlMdocCredential.vModel\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlMdocPresentation = DcqlMdocPresentation.Model['Output']\n\nexport namespace DcqlSdJwtVcPresentation {\n export const vModel = DcqlSdJwtVcCredential.vModel\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlSdJwtVcPresentation = DcqlSdJwtVcPresentation.Model['Output']\n\nexport namespace DcqlW3cVcPresentation {\n export const vModel = DcqlW3cVcCredential.vModel\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlW3cVcPresentation = DcqlW3cVcPresentation.Model['Output']\n\nexport namespace DcqlCredentialPresentation {\n export const model = new Model({\n vModel: v.variant('credential_format', [\n DcqlMdocPresentation.vModel,\n DcqlSdJwtVcPresentation.vModel,\n DcqlW3cVcPresentation.vModel,\n ]),\n })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlCredentialPresentation = DcqlCredentialPresentation.Model['Output']\n","import * as v from 'valibot'\nimport { vJsonRecord, vNonEmptyArray } from './u-dcql.js'\nimport type { InferModelTypes } from './u-model.js'\nimport { Model } from './u-model.js'\n\nexport namespace DcqlMdocCredential {\n export const vNamespaces = v.record(v.string(), v.record(v.string(), v.unknown()))\n export const vModel = v.object({\n credential_format: v.literal('mso_mdoc'),\n doctype: v.string(),\n namespaces: vNamespaces,\n })\n\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n export type NameSpaces = v.InferOutput<typeof vNamespaces>\n}\nexport type DcqlMdocCredential = DcqlMdocCredential.Model['Output']\n\nexport namespace DcqlSdJwtVcCredential {\n export const vClaims = vJsonRecord\n export const vModel = v.object({\n credential_format: v.picklist(['vc+sd-jwt', 'dc+sd-jwt']),\n vct: v.string(),\n claims: vClaims,\n })\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n export type Claims = Model['Output']['claims']\n}\nexport type DcqlSdJwtVcCredential = DcqlSdJwtVcCredential.Model['Output']\n\nexport namespace DcqlW3cVcCredential {\n export const vClaims = vJsonRecord\n export const vModel = v.object({\n credential_format: v.picklist(['jwt_vc_json-ld', 'jwt_vc_json']),\n claims: vClaims,\n })\n\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n export type Claims = Model['Output']['claims']\n}\nexport type DcqlW3cVcCredential = DcqlW3cVcCredential.Model['Output']\n\nexport namespace DcqlCredential {\n export const vModel = v.variant('credential_format', [\n DcqlMdocCredential.vModel,\n DcqlSdJwtVcCredential.vModel,\n DcqlW3cVcCredential.vModel,\n ])\n\n export const vParseSuccess = v.object({\n success: v.literal(true),\n typed: v.literal(true),\n issues: v.optional(v.undefined()),\n input_credential_index: v.number(),\n claim_set_index: v.union([v.number(), v.undefined()]),\n output: DcqlCredential.vModel,\n })\n\n export const vParseFailure = v.object({\n success: v.literal(false),\n typed: v.boolean(),\n output: v.unknown(),\n issues: v.pipe(v.array(v.unknown()), vNonEmptyArray()),\n input_credential_index: v.number(),\n claim_set_index: v.union([v.number(), v.undefined()]),\n })\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlCredential = DcqlCredential.Model['Output']\n","import * as v from 'valibot'\nimport type { UnknownBaseSchema } from './u-model'\nexport const idRegex = /^[a-zA-Z0-9_-]+$/\n\nexport const vNonEmptyArray = <T extends unknown[]>() => {\n return v.custom<[T[number], ...T]>((input) => (input as T).length > 0)\n}\n\nexport const vIdString = v.pipe(v.string(), v.regex(idRegex), v.nonEmpty())\n\nexport type Json = string | number | boolean | null | { [key: string]: Json } | Json[]\n\ninterface HasToJson {\n toJson(): Json\n}\n\nfunction isToJsonable(value: unknown): value is HasToJson {\n if (value === null || typeof value !== 'object') return false\n\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n const toJsonFn = (value as any).toJson\n return typeof toJsonFn === 'function'\n}\n\nexport const vWithJT = <Schema extends UnknownBaseSchema>(schema: Schema) =>\n v.pipe(\n v.custom<v.InferInput<Schema>>(() => true),\n v.rawTransform<v.InferInput<Schema>, v.InferOutput<Schema>>(({ dataset, addIssue, NEVER }) => {\n const result = v.safeParse(schema, dataset.value)\n if (result.success) return dataset.value\n\n if (!isToJsonable(dataset.value)) {\n for (const safeParseIssue of result.issues) {\n addIssue({\n ...safeParseIssue,\n expected: safeParseIssue.expected ?? undefined,\n })\n }\n\n return NEVER\n }\n\n let json: Json\n\n try {\n json = dataset.value.toJson()\n } catch (error) {\n for (const safeParseIssue of result.issues) {\n addIssue({\n ...safeParseIssue,\n expected: safeParseIssue.expected ?? undefined,\n })\n }\n addIssue({ message: 'Json Transformation failed' })\n return NEVER\n }\n\n const safeParseResult: v.SafeParseResult<Schema> = v.safeParse(schema, json)\n if (safeParseResult.success) return dataset.value\n\n for (const safeParseIssue of safeParseResult.issues) {\n addIssue({\n ...safeParseIssue,\n expected: safeParseIssue.expected ?? undefined,\n })\n }\n\n return NEVER\n })\n )\n\nexport const vJsonLiteral = v.union([v.string(), v.number(), v.boolean(), v.null()])\n\nexport type JsonLiteral = v.InferOutput<typeof vJsonLiteral>\n\nexport const vJson: v.GenericSchema<Json> = v.lazy(() =>\n v.union([vJsonLiteral, v.array(vJson), v.record(v.string(), vJson)])\n)\n\nexport const vJsonWithJT: v.GenericSchema<Json> = v.lazy(() =>\n vWithJT(v.union([vJsonLiteral, v.array(vJson), v.record(v.string(), vJson)]))\n)\n\nexport const vJsonRecord = v.record(v.string(), vJson)\nexport type JsonRecord = v.InferOutput<typeof vJsonRecord>\n\nexport const vStringToJson = v.rawTransform<string, Json>(({ dataset, addIssue, NEVER }) => {\n try {\n return JSON.parse(dataset.value) as Json\n } catch (error) {\n addIssue({ message: 'Invalid JSON' })\n return NEVER\n }\n})\n","import * as v from 'valibot'\nimport { DcqlParseError } from './dcql-error/e-dcql'\n\nexport type UnknownBaseSchema = v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>\n\ntype EnsureOutputAssignableToInput<T extends UnknownBaseSchema> = v.InferOutput<T> extends v.InferInput<T> ? T : never\n\nexport class Model<T extends UnknownBaseSchema> {\n constructor(private input: { vModel: EnsureOutputAssignableToInput<T> }) {}\n\n public get v() {\n return this.input.vModel\n }\n\n public parse(input: T) {\n const result = this.safeParse(input)\n\n if (result.success) {\n return result.output\n }\n\n return new DcqlParseError({\n message: JSON.stringify(result.flattened),\n cause: result.error,\n })\n }\n\n public safeParse(\n input: unknown\n ):\n | { success: true; output: v.InferOutput<T> }\n | { success: false; flattened: v.FlatErrors<T>; error: v.ValiError<T> } {\n const res = v.safeParse(this.input.vModel, input)\n if (res.success) {\n return { success: true, output: res.output }\n }\n return {\n success: false,\n error: new v.ValiError(res.issues),\n flattened: v.flatten<T>(res.issues),\n }\n }\n\n public is(input: unknown): input is v.InferOutput<T> {\n return v.is(this.v, input)\n }\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\nexport type InferModelTypes<T extends Model<any>> = T extends Model<infer U>\n ? {\n Input: v.InferInput<U>\n Output: v.InferOutput<U>\n }\n : never\n","import * as v from 'valibot'\n\nimport { DcqlInvalidPresentationRecordError, DcqlPresentationResultError } from '../dcql-error/e-dcql.js'\nimport { runCredentialQuery } from '../dcql-parser/dcql-credential-query-result.js'\nimport { DcqlQueryResult } from '../dcql-query-result/m-dcql-query-result.js'\nimport type { DcqlQuery } from '../dcql-query/m-dcql-query.js'\nimport { DcqlCredential } from '../u-dcql-credential.js'\nimport { vIdString } from '../u-dcql.js'\nimport type { DcqlCredentialPresentation } from './m-dcql-credential-presentation.js'\n\nexport namespace DcqlPresentationResult {\n export const vModel = v.object({\n ...v.omit(DcqlQueryResult.vModel, ['credential_matches']).entries,\n\n invalid_matches: v.union([\n v.record(\n v.pipe(vIdString),\n v.object({\n ...v.omit(DcqlCredential.vParseFailure, ['input_credential_index']).entries,\n presentation_id: v.pipe(vIdString),\n })\n ),\n v.undefined(),\n ]),\n\n valid_matches: v.record(\n v.pipe(vIdString),\n v.object({\n ...v.omit(DcqlCredential.vParseSuccess, ['issues', 'input_credential_index']).entries,\n presentation_id: v.pipe(vIdString),\n })\n ),\n })\n\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n\n export const parse = (input: Input | DcqlQueryResult) => {\n return v.parse(vModel, input)\n }\n\n /**\n * Query if the presentation record can be satisfied by the provided presentations\n * considering the dcql query\n *\n * @param dcqlQuery\n * @param dcqlPresentation\n */\n export const fromDcqlPresentation = (\n dcqlPresentation: Record<string, DcqlCredentialPresentation>,\n ctx: { dcqlQuery: DcqlQuery }\n ): Output => {\n const { dcqlQuery } = ctx\n\n const presentationQueriesResults = Object.fromEntries(\n Object.entries(dcqlPresentation).map(([queryId, presentation]) => {\n const credentialQuery = dcqlQuery.credentials.find((c) => c.id === queryId)\n if (!credentialQuery) {\n throw new DcqlPresentationResultError({\n message: `Query ${queryId} not found in the dcql query. Cannot validate presentation.`,\n })\n }\n\n return [\n queryId,\n runCredentialQuery(credentialQuery, {\n presentation: true,\n credentials: [presentation],\n }),\n ]\n })\n )\n\n let invalidMatches: DcqlPresentationResult['invalid_matches'] = undefined\n const validMatches: DcqlPresentationResult['valid_matches'] = {}\n\n for (const [queryId, presentationQueryResult] of Object.entries(presentationQueriesResults)) {\n for (const presentationQueryResultForClaimSet of presentationQueryResult) {\n // biome-ignore lint/style/noNonNullAssertion: <explanation>\n const result = presentationQueryResultForClaimSet[0]!\n if (result.success) {\n const { issues, input_credential_index, ...rest } = result\n validMatches[queryId] = { ...rest, presentation_id: queryId }\n } else {\n if (!invalidMatches) invalidMatches = {}\n const { input_credential_index, ...rest } = result\n invalidMatches[queryId] = {\n ...rest,\n presentation_id: queryId,\n }\n }\n }\n }\n\n const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {\n const matchingOptions = set.options.filter((option) =>\n option.every((credentialQueryId) => validMatches[credentialQueryId]?.success)\n )\n\n return {\n ...set,\n matching_options: matchingOptions.length > 0 ? (matchingOptions as [string[], ...string[][]]) : undefined,\n }\n }) as DcqlQueryResult.Output['credential_sets']\n\n const dqclQueryMatched = credentialSetResults\n ? credentialSetResults.every((set) => !set.required || set.matching_options)\n : !invalidMatches\n\n return {\n ...dcqlQuery,\n canBeSatisfied: dqclQueryMatched,\n valid_matches: validMatches,\n invalid_matches: invalidMatches,\n credential_sets: credentialSetResults,\n }\n }\n\n export const validate = (dcqlQueryResult: DcqlPresentationResult) => {\n if (!dcqlQueryResult.canBeSatisfied) {\n throw new DcqlInvalidPresentationRecordError({\n message: 'Invalid Presentation record',\n cause: dcqlQueryResult,\n })\n }\n\n return dcqlQueryResult satisfies Output\n }\n}\nexport type DcqlPresentationResult = DcqlPresentationResult.Output\n","import * as v from 'valibot'\nimport type { DcqlQueryResult } from '../dcql-query-result/m-dcql-query-result.js'\nimport type { DcqlCredentialQuery } from '../dcql-query/m-dcql-credential-query.js'\nimport type { DcqlCredential } from '../u-dcql-credential.js'\nimport type {} from '../u-dcql.js'\nimport { getCredentialQueryParser } from './dcql-claims-query-result.js'\n\nexport const runCredentialQuery = (\n credentialQuery: DcqlCredentialQuery,\n ctx: {\n credentials: DcqlCredential[]\n presentation: boolean\n }\n): DcqlQueryResult.CredentialQueryResult => {\n const { credentials, presentation } = ctx\n const claimSets = credentialQuery.claim_sets ?? [undefined]\n\n const credentialQueryResult: v.InferInput<typeof DcqlQueryResult.vCredentialQueryResult> = new Array(\n claimSets.length\n ).fill([])\n\n for (const [claimSetIndex, claim_set] of claimSets.entries()) {\n const credentialParser = getCredentialQueryParser(credentialQuery, {\n claimSet: claim_set,\n presentation,\n })\n\n for (const [credentialIndex, credential] of credentials.entries()) {\n if (claimSetIndex > 0) {\n // if one the credential was successfully parsed against a previous claimsset we don't need to further validate other claim sets\n const previous = credentialQueryResult[claimSetIndex - 1]?.[credentialIndex]\n\n // if the previous credential was successfully parsed we don't need to further validate the current credential\n // we set all further parsing attempts to undefined\n if (previous?.success || !previous) {\n // biome-ignore lint/style/noNonNullAssertion: <explanation>\n credentialQueryResult[claimSetIndex]![credentialIndex] = undefined\n continue\n }\n }\n\n const parseResult = v.safeParse(credentialParser, credential)\n credentialQueryResult[claimSetIndex]?.push({\n ...parseResult,\n ...(parseResult.issues && {\n flattened: v.flatten<typeof credentialParser>(parseResult.issues),\n }),\n input_credential_index: credentialIndex,\n claim_set_index: credentialQuery.claim_sets ? claimSetIndex : undefined,\n })\n }\n }\n\n return credentialQueryResult as DcqlQueryResult.CredentialQueryResult\n}\n","import * as v from 'valibot'\nimport { DcqlInvalidClaimsQueryIdError, DcqlMissingClaimSetParseError } from '../dcql-error/e-dcql.js'\nimport { DcqlClaimsQuery } from '../dcql-query/m-dcql-claims-query.js'\nimport type { DcqlCredentialQuery } from '../dcql-query/m-dcql-credential-query.js'\nimport { vWithJT } from '../u-dcql.js'\nimport { vJson, vJsonRecord } from '../u-dcql.js'\n\nconst getClaimParser = (input: {\n value?: string | number | boolean\n values?: (string | number | boolean)[]\n}) => {\n const { value, values } = input\n if (value) {\n return vWithJT(v.literal(value))\n }\n\n if (values) {\n return vWithJT(v.union(values.map((val) => v.literal(val))))\n }\n\n return v.nonNullish(v.any())\n}\n\nexport const getNamespacesParser = (claimsQueries: DcqlClaimsQuery.Mdoc[]) => {\n const claimsForNamespace: Record<string, DcqlClaimsQuery.MdocPath[]> = {}\n\n for (const claimQuery of claimsQueries) {\n // Normalize the query to the latest path syntax\n const mdocPathQuery: DcqlClaimsQuery.MdocPath = v.is(DcqlClaimsQuery.vMdocNamespace, claimQuery)\n ? {\n id: claimQuery.id,\n path: [claimQuery.namespace, claimQuery.claim_name],\n values: claimQuery.values,\n }\n : claimQuery\n\n const namespace = mdocPathQuery.path[0]\n if (claimsForNamespace[namespace]) {\n claimsForNamespace[namespace]?.push({ ...mdocPathQuery })\n } else {\n claimsForNamespace[namespace] = [{ ...mdocPathQuery }]\n }\n }\n\n const parsersForNamespaces = Object.entries(claimsForNamespace).map(([namespace, claims]) => {\n const claimParsers = Object.fromEntries(claims.map((claim) => [claim.path[1], getClaimParser(claim)]))\n return [namespace, v.object(claimParsers)]\n })\n\n return v.object(Object.fromEntries(parsersForNamespaces))\n}\n\nconst getClaimQueryParser = (\n claimQuery: DcqlClaimsQuery.W3cAndSdJwtVc,\n ctx: { index: number; presentation: boolean }\n): typeof vJson => {\n const { index, presentation } = ctx\n const pathElement = claimQuery.path[index]\n const isLast = index === claimQuery.path.length - 1\n\n const vClaimParser = getClaimParser(claimQuery)\n\n if (typeof pathElement === 'number') {\n const elementParser = isLast ? vClaimParser : getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 })\n\n if (presentation) {\n // We allow both the concrete value and an array of one value\n return v.union([\n v.pipe(\n v.array(vJson),\n v.length(1),\n v.transform((input) => input[0]),\n elementParser\n ),\n elementParser,\n ])\n }\n\n return v.pipe(\n v.array(vJson),\n v.transform((input) => input[pathElement]),\n elementParser\n )\n }\n if (typeof pathElement === 'string') {\n return v.object({\n [pathElement]: isLast ? vClaimParser : getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 }),\n })\n }\n return isLast ? v.array(vClaimParser) : v.array(getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 }))\n}\n\nexport const getJsonClaimsParser = (claimsQueries: DcqlClaimsQuery.W3cAndSdJwtVc[], ctx: { presentation: boolean }) => {\n const claimParser = v.intersect(\n claimsQueries.map(\n (claimQuery) =>\n getClaimQueryParser(claimQuery, {\n ...ctx,\n index: 0,\n }) as typeof vJsonRecord\n )\n )\n\n return claimParser\n}\n\nexport const getMdocClaimsQueriesForClaimSet = (\n claimsQueries: DcqlClaimsQuery.Mdoc[],\n claimSet: string[]\n): DcqlClaimsQuery.Mdoc[] => {\n return claimSet.map((credential_id) => {\n const query = claimsQueries.find((query) => query.id === credential_id)\n if (!query) {\n throw new DcqlInvalidClaimsQueryIdError({\n message: `Claims-query with id '${credential_id}' not found.`,\n })\n }\n\n return query\n })\n}\n\nexport const getJsonClaimsQueriesForClaimSet = (\n claimsQueries: DcqlClaimsQuery.W3cAndSdJwtVc[],\n claimSet: string[]\n): DcqlClaimsQuery.W3cAndSdJwtVc[] => {\n return claimSet.map((credential_id) => {\n const query = claimsQueries.find((query) => query.id === credential_id)\n if (!query) {\n throw new DcqlInvalidClaimsQueryIdError({\n message: `Claims-query with id '${credential_id}' not found.`,\n })\n }\n return query\n })\n}\n\nconst getMdocParser = (\n credentialQuery: DcqlCredentialQuery.Mdoc,\n ctx: { claimSet?: NonNullable<DcqlCredentialQuery['claim_sets']>[number] }\n) => {\n const { claimSet } = ctx\n\n const vDoctype = credentialQuery.meta?.doctype_value ? v.literal(credentialQuery.meta.doctype_value) : v.string()\n\n const claimSetQueries =\n credentialQuery.claims && claimSet\n ? getMdocClaimsQueriesForClaimSet(credentialQuery.claims, claimSet)\n : credentialQuery.claims\n\n const credentialParser = v.object({\n credential_format: v.literal('mso_mdoc'),\n doctype: vDoctype,\n namespaces: claimSetQueries\n ? getNamespacesParser(claimSetQueries)\n : v.record(v.string(), v.record(v.string(), v.unknown())),\n })\n\n return credentialParser\n}\n\nconst getW3cVcSdJwtVcParser = (\n credentialQuery: DcqlCredentialQuery.SdJwtVc | DcqlCredentialQuery.W3cVc,\n ctx: {\n claimSet?: NonNullable<DcqlCredentialQuery['claim_sets']>[number]\n presentation: boolean\n }\n) => {\n const { claimSet } = ctx\n const claimSetQueries =\n credentialQuery.claims && claimSet\n ? getJsonClaimsQueriesForClaimSet(credentialQuery.claims, claimSet)\n : credentialQuery.claims\n\n if (credentialQuery.format === 'vc+sd-jwt' || credentialQuery.format === 'dc+sd-jwt') {\n return v.object({\n credential_format: v.literal(credentialQuery.format),\n vct: credentialQuery.meta?.vct_values ? v.picklist(credentialQuery.meta.vct_values) : v.string(),\n claims: claimSetQueries ? getJsonClaimsParser(claimSetQueries, ctx) : vJsonRecord,\n })\n }\n const credentialParser = v.object({\n credential_format: v.picklist(['jwt_vc_json', 'jwt_vc_json-ld']),\n claims: claimSetQueries ? getJsonClaimsParser(claimSetQueries, ctx) : vJsonRecord,\n })\n\n return credentialParser\n}\n\nexport const getCredentialQueryParser = (\n credentialQuery: DcqlCredentialQuery,\n ctx: {\n claimSet?: NonNullable<DcqlCredentialQuery['claim_sets']>[number]\n presentation: boolean\n }\n) => {\n if (credentialQuery.claim_sets && !ctx.claimSet) {\n throw new DcqlMissingClaimSetParseError({\n message: 'credentialQuery specifies claim_sets but no claim_set for parsing is provided.',\n })\n }\n\n if (credentialQuery.format === 'mso_mdoc') {\n return getMdocParser(credentialQuery, ctx)\n }\n return getW3cVcSdJwtVcParser(credentialQuery, ctx)\n}\n","import * as v from 'valibot'\nimport { vIdString, vNonEmptyArray } from '../u-dcql.js'\n\n/**\n * Specifies claims withing a requested Credential.\n */\nexport namespace DcqlClaimsQuery {\n export const vValue = v.union([v.string(), v.pipe(v.number(), v.integer()), v.boolean()])\n\n export const vPath = v.union([v.string(), v.pipe(v.number(), v.integer(), v.minValue(0)), v.null()])\n\n export const vW3cSdJwtVc = v.object({\n id: v.pipe(\n v.optional(vIdString),\n v.description(\n 'A string identifying the particular claim. The value MUST be a non-empty string consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular claims array, the same id MUST NOT be present more than once.'\n )\n ),\n path: v.pipe(\n v.array(vPath),\n vNonEmptyArray(),\n v.description(\n 'A non-empty array representing a claims path pointer that specifies the path to a claim within the Verifiable Credential.'\n )\n ),\n values: v.pipe(\n v.optional(v.array(vValue)),\n v.description(\n 'An array of strings, integers or boolean values that specifies the expected values of the claim. If the values property is present, the Wallet SHOULD return the claim only if the type and value of the claim both match for at least one of the elements in the array.'\n )\n ),\n })\n export type W3cAndSdJwtVc = v.InferOutput<typeof vW3cSdJwtVc>\n\n const vMdocBase = v.object({\n id: v.pipe(\n v.optional(vIdString),\n v.description(\n 'A string identifying the particular claim. The value MUST be a non-empty string consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular claims array, the same id MUST NOT be present more than once.'\n )\n ),\n values: v.pipe(\n v.optional(v.array(vValue)),\n v.description(\n 'An array of strings, integers or boolean values that specifies the expected values of the claim. If the values property is present, the Wallet SHOULD return the claim only if the type and value of the claim both match for at least one of the elements in the array.'\n )\n ),\n })\n\n // Syntax up until Draft 23 of OID4VP. Keeping due to Draft 23 having\n // reach ID-3 status and thus being targeted by several implementations\n export const vMdocNamespace = v.object({\n ...vMdocBase.entries,\n\n namespace: v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the namespace of the data element within the mdoc, e.g., org.iso.18013.5.1.'\n )\n ),\n claim_name: v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the data element identifier of the data element within the provided namespace in the mdoc, e.g., first_name.'\n )\n ),\n })\n\n // Syntax starting from Draft 24 of OID4VP\n export const vMdocPath = v.object({\n ...vMdocBase.entries,\n\n intent_to_retain: v.pipe(\n v.optional(v.boolean()),\n v.description(\n 'A boolean that is equivalent to `IntentToRetain` variable defined in Section 8.3.2.1.2.1 of [@ISO.18013-5].'\n )\n ),\n\n path: v.pipe(\n v.tuple([\n v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the namespace of the data element within the mdoc, e.g., org.iso.18013.5.1.'\n )\n ),\n v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the data element identifier of the data element within the provided namespace in the mdoc, e.g., first_name.'\n )\n ),\n ]),\n v.description(\n 'An array defining a claims path pointer into an mdoc. It must contain two elements of type string. The first element refers to a namespace and the second element refers to a data element identifier.'\n )\n ),\n })\n export const vMdoc = v.union([vMdocNamespace, vMdocPath])\n export type MdocNamespace = v.InferOutput<typeof vMdocNamespace>\n export type MdocPath = v.InferOutput<typeof vMdocPath>\n export type Mdoc = v.InferOutput<typeof vMdoc>\n\n export const vModel = v.union([vMdoc, vW3cSdJwtVc])\n export type Input = v.InferInput<typeof vModel>\n export type Out = v.InferOutput<typeof vModel>\n}\nexport type DcqlClaimsQuery = DcqlClaimsQuery.Out\n","import * as v from 'valibot'\nimport { DcqlCredentialQuery } from '../dcql-query/m-dcql-credential-query.js'\nimport { CredentialSetQuery } from '../dcql-query/m-dcql-credential-set-query.js'\nimport { DcqlCredential } from '../u-dcql-credential.js'\nimport { vIdString, vNonEmptyArray } from '../u-dcql.js'\n\nexport namespace DcqlQueryResult {\n export const vCredentialQueryResult = v.pipe(\n v.array(v.array(v.union([v.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure]))),\n vNonEmptyArray()\n )\n\n export type CredentialQueryResult = v.InferOutput<typeof vCredentialQueryResult>\n\n export const vModel = v.object({\n credentials: v.pipe(\n v.array(DcqlCredentialQuery.vModel),\n vNonEmptyArray(),\n v.description(\n 'REQUIRED. A non-empty array of Credential Queries that specify the requested Verifiable Credentials.'\n )\n ),\n\n credential_matches: v.record(\n v.pipe(vIdString),\n v.union([\n v.object({\n ...DcqlCredential.vParseSuccess.entries,\n all: v.pipe(\n v.array(\n v.pipe(\n v.array(v.union([v.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure])),\n vNonEmptyArray()\n )\n ),\n vNonEmptyArray()\n ),\n }),\n v.object({\n success: DcqlCredential.vParseFailure.entries.success,\n all: v.pipe(\n v.array(\n v.pipe(\n v.array(v.union([v.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure])),\n vNonEmptyArray()\n )\n ),\n vNonEmptyArray()\n ),\n }),\n ])\n ),\n\n credential_sets: v.optional(\n v.pipe(\n v.array(\n v.object({\n ...CredentialSetQuery.vModel.entries,\n matching_options: v.union([v.undefined(), v.pipe(v.array(v.array(v.string())), vNonEmptyArray())]),\n })\n ),\n vNonEmptyArray(),\n v.description(\n 'OPTIONAL. A non-empty array of credential set queries that specifies additional constraints on which of the requested Verifiable Credentials to return.'\n )\n )\n ),\n\n canBeSatisfied: v.boolean(),\n })\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n\n export type CredentialMatch = Input['credential_matches'][number]\n export type CredentialMatchRecord = Input['credential_matches']\n}\nexport type DcqlQueryResult = DcqlQueryResult.Output\n","import * as v from 'valibot'\nimport { DcqlUndefinedClaimSetIdError } from '../dcql-error/e-dcql.js'\nimport { idRegex, vIdString, vNonEmptyArray } from '../u-dcql.js'\nimport { DcqlClaimsQuery } from './m-dcql-claims-query.js'\n\n/**\n * A Credential Query is an object representing a request for a presentation of one Credential.\n */\nexport namespace DcqlCredentialQuery {\n const vBase = v.object({\n id: v.pipe(\n v.string(),\n v.regex(idRegex),\n v.description(\n `REQUIRED. A string identifying the Credential in the response and, if provided, the constraints in 'credential_sets'.`\n )\n ),\n claim_sets: v.pipe(\n v.optional(v.pipe(v.array(v.pipe(v.array(vIdString), vNonEmptyArray())), vNonEmptyArray())),\n v.description(\n `OPTIONAL. A non-empty array containing arrays of identifiers for elements in 'claims' that specifies which combinations of 'claims' for the Credential are requested.`\n )\n ),\n })\n\n export const vMdoc = v.object({\n ...vBase.entries,\n format: v.pipe(\n v.literal('mso_mdoc'),\n v.description('REQUIRED. A string that specifies the format of the requested Verifiable Credential.')\n ),\n claims: v.pipe(\n v.optional(v.pipe(v.array(DcqlClaimsQuery.vMdoc), vNonEmptyArray())),\n v.description('OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.')\n ),\n meta: v.pipe(\n v.optional(\n v.object({\n doctype_value: v.pipe(\n v.optional(v.string()),\n v.description(\n 'OPTIONAL. String that specifies an allowed value for the doctype of the requested Verifiable Credential.'\n )\n ),\n })\n ),\n v.description(\n 'OPTIONAL. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential.'\n )\n ),\n })\n export type Mdoc = v.InferOutput<typeof vMdoc>\n\n export const vSdJwtVc = v.object({\n ...vBase.entries,\n format: v.pipe(\n v.picklist(['vc+sd-jwt', 'dc+sd-jwt']),\n v.description('REQUIRED. A string that specifies the format of the requested Verifiable Credential.')\n ),\n claims: v.pipe(\n v.optional(v.pipe(v.array(DcqlClaimsQuery.vW3cSdJwtVc), vNonEmptyArray())),\n v.description('OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.')\n ),\n meta: v.pipe(\n v.optional(\n v.pipe(\n v.object({\n vct_values: v.optional(v.array(v.string())),\n }),\n v.description(\n 'OPTIONAL. An array of strings that specifies allowed values for the type of the requested Verifiable Credential.'\n )\n )\n ),\n v.description(\n 'OPTIONAL. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential.'\n )\n ),\n })\n export type SdJwtVc = v.InferOutput<typeof vSdJwtVc>\n\n export const vW3cVc = v.object({\n ...vBase.entries,\n format: v.picklist(['jwt_vc_json', 'jwt_vc_json-ld']),\n claims: v.optional(v.pipe(v.array(DcqlClaimsQuery.vW3cSdJwtVc), vNonEmptyArray())),\n })\n export type W3cVc = v.InferOutput<typeof vW3cVc>\n\n export const vModel = v.variant('format', [vMdoc, vSdJwtVc, vW3cVc])\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n\n export const validate = (credentialQuery: Output) => {\n claimSetIdsAreDefined(credentialQuery)\n }\n}\nexport type DcqlCredentialQuery = DcqlCredentialQuery.Output\n\n// --- validations --- //\n\nconst claimSetIdsAreDefined = (credentialQuery: DcqlCredentialQuery) => {\n if (!credentialQuery.claim_sets) return\n const claimIds = new Set(credentialQuery.claims?.map((claim) => claim.id))\n\n const undefinedClaims: string[] = []\n for (const claim_set of credentialQuery.claim_sets) {\n for (const claim_id of claim_set) {\n if (!claimIds.has(claim_id)) {\n undefinedClaims.push(claim_id)\n }\n }\n }\n\n if (undefinedClaims.length > 0) {\n throw new DcqlUndefinedClaimSetIdError({\n message: `Credential set contains undefined credential id${undefinedClaims.length === 0 ? '' : '`s'} '${undefinedClaims.join(', ')}'`,\n })\n }\n}\n","import * as v from 'valibot'\nimport { vIdString, vNonEmptyArray } from '../u-dcql.js'\n\n/**\n * A Credential Set Query is an object representing\n * a request for one or more credentials to satisfy a particular use case with the Verifier.\n */\nexport namespace CredentialSetQuery {\n export const vModel = v.object({\n options: v.pipe(\n v.array(v.array(vIdString)),\n vNonEmptyArray(),\n v.description(\n 'REQUIRED. A non-empty array, where each value in the array is a list of Credential Query identifiers representing one set of Credentials that satisfies the use case.'\n )\n ),\n required: v.pipe(\n v.optional(v.boolean(), true),\n v.description(\n `OPTIONAL. Boolean which indicates whether this set of Credentials is required to satisfy the particular use case at the Verifier. If omitted, the default value is 'true'.`\n )\n ),\n purpose: v.pipe(\n v.optional(v.union([v.string(), v.number(), v.record(v.string(), v.unknown())])),\n v.description('OPTIONAL. A string, number or object specifying the purpose of the query.')\n ),\n })\n\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n}\nexport type CredentialSetQuery = CredentialSetQuery.Output\n","import * as v from 'valibot'\nimport { vIdString, vJsonRecord, vStringToJson } from '../u-dcql.js'\n\nexport namespace DcqlPresentation {\n export const vModel = v.record(vIdString, v.union([v.string(), vJsonRecord]))\n\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n export const parse = (input: Input | string) => {\n if (typeof input === 'string') {\n return v.parse(v.pipe(v.string(), vStringToJson, vModel), input)\n }\n\n return v.parse(vModel, input)\n }\n\n export const encode = (input: Output) => {\n return JSON.stringify(input)\n }\n}\nexport type DcqlPresentation = DcqlPresentation.Output\n","import type * as v from 'valibot'\nimport { runCredentialQuery } from '../dcql-parser/dcql-credential-query-result.js'\nimport type { DcqlQuery } from '../dcql-query/m-dcql-query.js'\nimport type { DcqlCredential } from '../u-dcql-credential.js'\nimport type { DcqlQueryResult } from './m-dcql-query-result.js'\n\nexport const runDcqlQuery = (\n dcqlQuery: DcqlQuery.Output,\n ctx: {\n credentials: DcqlCredential[]\n presentation: boolean\n }\n): DcqlQueryResult => {\n const credentialQueriesResults = Object.fromEntries(\n dcqlQuery.credentials.map((credentialQuery) => [credentialQuery.id, runCredentialQuery(credentialQuery, ctx)])\n )\n\n const credentialMatches = Object.fromEntries(\n Object.entries(credentialQueriesResults).map(([key, credentialQueryResult]) => {\n // Find the best match for each credential query\n let bestMatch: v.InferOutput<typeof DcqlCredential.vParseSuccess> | undefined = undefined\n\n for (const credentialParseResult of credentialQueryResult) {\n const bestMatchForCredential = credentialParseResult.find((result) => result?.success === true)\n\n if (!bestMatch && bestMatchForCredential) {\n const { issues, ...matchWithoutIssues } = bestMatchForCredential\n bestMatch = matchWithoutIssues\n continue\n }\n\n // biome-ignore lint/style/noNonNullAssertion: <explanation>\n if (bestMatchForCredential && bestMatchForCredential.claim_set_index! < bestMatch?.claim_set_index!) {\n const { issues, ...matchWithoutIssues } = bestMatchForCredential\n bestMatch = matchWithoutIssues\n }\n }\n\n return [\n key,\n bestMatch ? { ...bestMatch, all: credentialQueryResult } : { success: false, all: credentialQueryResult },\n ]\n })\n ) satisfies DcqlQueryResult.CredentialMatchRecord\n\n const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {\n const matchingOptions = set.options.filter((option) =>\n option.every((credentialQueryId) => credentialMatches[credentialQueryId]?.success)\n )\n\n return {\n ...set,\n matching_options: matchingOptions.length > 0 ? (matchingOptions as [string[], ...string[][]]) : undefined,\n }\n }) as DcqlQueryResult.Output['credential_sets']\n\n const dqclQueryMatched = credentialSetResults\n ? credentialSetResults.every((set) => !set.required || set.matching_options)\n : Object.values(credentialMatches).every((query) => query.success)\n\n return {\n ...dcqlQuery,\n canBeSatisfied: dqclQueryMatched,\n credential_matches: credentialMatches as DcqlQueryResult['credential_matches'],\n credential_sets: credentialSetResults,\n }\n}\n","import * as v from 'valibot'\nimport { DcqlCredentialSetError, DcqlNonUniqueCredentialQueryIdsError } from '../dcql-error/e-dcql.js'\nimport { runDcqlQuery } from '../dcql-query-result/run-dcql-query.js'\nimport type { DcqlCredential } from '../u-dcql-credential.js'\nimport { vNonEmptyArray } from '../u-dcql.js'\nimport { DcqlCredentialQuery } from './m-dcql-credential-query.js'\nimport { CredentialSetQuery } from './m-dcql-credential-set-query.js'\n\n/**\n * The Digital Credentials Query Language (DCQL, pronounced [ˈdakl̩]) is a\n * JSON-encoded query language that allows the Verifier to request Verifiable\n * Presentations that match the query. The Verifier MAY encode constraints on the\n * combinations of credentials and claims that are requested. The Wallet evaluates\n * the query against the Verifiable Credentials it holds and returns Verifiable\n * Presentations matching the query.\n */\nexport namespace DcqlQuery {\n export const vModel = v.object({\n credentials: v.pipe(\n v.array(DcqlCredentialQuery.vModel),\n vNonEmptyArray(),\n v.description(\n 'REQUIRED. A non-empty array of Credential Queries that specify the requested Verifiable Credentials.'\n )\n ),\n credential_sets: v.pipe(\n v.optional(v.pipe(v.array(CredentialSetQuery.vModel), vNonEmptyArray())),\n v.description(\n 'OPTIONAL. A non-empty array of credential set queries that specifies additional constraints on which of the requested Verifiable Credentials to return.'\n )\n ),\n })\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n export const validate = (dcqlQuery: Output) => {\n validateUniqueCredentialQueryIds(dcqlQuery)\n validateCredentialSets(dcqlQuery)\n dcqlQuery.credentials.forEach(DcqlCredentialQuery.validate)\n }\n export const query = (dcqlQuery: Output, credentials: DcqlCredential[]) => {\n return runDcqlQuery(dcqlQuery, { credentials, presentation: false })\n }\n\n export const parse = (input: Input) => {\n return v.parse(vModel, input)\n }\n}\nexport type DcqlQuery = DcqlQuery.Output\n\n// --- validations --- //\n\nconst validateUniqueCredentialQueryIds = (query: DcqlQuery.Output) => {\n const ids = query.credentials.map((c) => c.id)\n const duplicates = ids.filter((id, index) => ids.indexOf(id) !== index)\n\n if (duplicates.length > 0) {\n throw new DcqlNonUniqueCredentialQueryIdsError({\n message: `Duplicate credential query ids found: ${duplicates.join(', ')}`,\n })\n }\n}\n\nconst validateCredentialSets = (query: DcqlQuery.Output) => {\n if (!query.credential_sets) return\n\n const credentialQueryIds = new Set(query.credentials.map((c) => c.id))\n\n const undefinedCredentialQueryIds: string[] = []\n for (const credential_set of query.credential_sets) {\n for (const credentialSetOption of credential_set.options) {\n for (const credentialQueryId of credentialSetOption) {\n if (!credentialQueryIds.has(credentialQueryId)) {\n undefinedCredentialQueryIds.push(credentialQueryId)\n }\n }\n }\n }\n\n if (undefinedCredentialQueryIds.length > 0) {\n throw new DcqlCredentialSetError({\n message: `Credential set contains undefined credential id${undefinedCredentialQueryIds.length === 1 ? '' : '`s'} '${undefinedCredentialQueryIds.join(', ')}'`,\n })\n }\n}\n"],"mappings":";AAAA,SAAS,SAAS,OAAkD;AAClE,SAAO,CAAC,CAAC,SAAS,CAAC,MAAM,QAAQ,KAAK,KAAK,OAAO,UAAU;AAC9D;AAEA,IAAM,oBAAN,cAAgC,MAAM;AAEtC;AAEO,SAAS,oBAAoB,OAAmC;AACrE,MAAI,iBAAiB,OAAO;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,OAAO;AACpB,MAAI,SAAS,eAAe,SAAS,cAAc,UAAU,MAAM;AACjE,WAAO;AAAA,EACT;AAGA,MAAI,SAAS,UAAU;AACrB,WAAO,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,EAChC;AAGA,MAAI,SAAS,KAAK,GAAG;AACnB,UAAM,MAAM,IAAI,kBAAkB;AAClC,eAAW,OAAO,OAAO;AACvB,UAAI,GAAG,IAAI,MAAM,GAAG;AAAA,IACtB;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,IAAM,cAAc,CAAC,UAAuC;AACjE,MAAI,iBAAiB,WAAW;AAC9B,WAAO;AAAA,EACT;AACA,MAAI,iBAAiB,SAAS,MAAM,SAAS,aAAa;AAExD,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,SAAS,wBAAwB,OAA2B;AACjE,MAAI,YAAY,KAAK,GAAG;AACtB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,IAAI,UAAU;AAAA,IAC9B,MAAM;AAAA,IACN;AAAA,EACF,CAAC;AAGD,MAAI,iBAAiB,SAAS,MAAM,OAAO;AACzC,cAAU,QAAQ,MAAM;AAAA,EAC1B;AAEA,SAAO;AACT;AAIO,IAAM,YAAN,cAAwB,MA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U,IAAI,QAAQ,EAAE,MAAM,KAAK;AAEtE,MAAI,WAAW,SAAS,GAAG;AACzB,UAAM,IAAI,qCAAqC;AAAA,MAC7C,SAAS,yCAAyC,WAAW,KAAK,IAAI,CAAC;AAAA,IACzE,CAAC;AAAA,EACH;AACF;AAEA,IAAM,yBAAyB,CAAC,UAA4B;AAC1D,MAAI,CAAC,MAAM,gBAAiB;AAE5B,QAAM,qBAAqB,IAAI,IAAI,MAAM,YAAY,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;AAErE,QAAM,8BAAwC,CAAC;AAC/C,aAAW,kBAAkB,MAAM,iBAAiB;AAClD,eAAW,uBAAuB,eAAe,SAAS;AACxD,iBAAW,qBAAqB,qBAAqB;AACnD,YAAI,CAAC,mBAAmB,IAAI,iBAAiB,GAAG;AAC9C,sCAA4B,KAAK,iBAAiB;AAAA,QACpD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,MAAI,4BAA4B,SAAS,GAAG;AAC1C,UAAM,IAAI,uBAAuB;AAAA,MAC/B,SAAS,kDAAkD,4BAA4B,WAAW,IAAI,KAAK,IAAI,KAAK,4BAA4B,KAAK,IAAI,CAAC;AAAA,IAC5J,CAAC;AAAA,EACH;AACF;","names":["v","v","v","DcqlMdocCredential","DcqlSdJwtVcCredential","DcqlW3cVcCredential","DcqlCredential","DcqlMdocPresentation","DcqlSdJwtVcPresentation","DcqlW3cVcPresentation","DcqlCredentialPresentation","v","v","v","v","DcqlClaimsQuery","query","v","v","DcqlCredentialQuery","v","CredentialSetQuery","DcqlQueryResult","DcqlPresentationResult","v","DcqlPresentation","v","DcqlQuery"]}
|
1
|
+
{"version":3,"sources":["../src/dcql-error/e-base.ts","../src/dcql-error/e-dcql.ts","../src/dcql-presentation/m-dcql-credential-presentation.ts","../src/u-dcql-credential.ts","../src/u-dcql.ts","../src/u-model.ts","../src/dcql-presentation/m-dcql-presentation-result.ts","../src/dcql-parser/dcql-credential-query-result.ts","../src/dcql-parser/dcql-claims-query-result.ts","../src/dcql-query/m-dcql-claims-query.ts","../src/dcql-query-result/m-dcql-query-result.ts","../src/dcql-query/m-dcql-credential-query.ts","../src/dcql-query/m-dcql-credential-set-query.ts","../src/dcql-presentation/m-dcql-presentation.ts","../src/dcql-query-result/run-dcql-query.ts","../src/dcql-query/m-dcql-query.ts"],"sourcesContent":["function isObject(value: unknown): value is Record<string, unknown> {\n return !!value && !Array.isArray(value) && typeof value === 'object'\n}\n\nclass UnknownCauseError extends Error {\n [key: string]: unknown\n}\n\nexport function getCauseFromUnknown(cause: unknown): Error | undefined {\n if (cause instanceof Error) {\n return cause\n }\n\n const type = typeof cause\n if (type === 'undefined' || type === 'function' || cause === null) {\n return undefined\n }\n\n // Primitive types just get wrapped in an error\n if (type !== 'object') {\n return new Error(String(cause))\n }\n\n // If it's an object, we'll create a synthetic error\n if (isObject(cause)) {\n const err = new UnknownCauseError()\n for (const key in cause) {\n err[key] = cause[key]\n }\n return err\n }\n\n return undefined\n}\n\nexport const isDcqlError = (cause: unknown): cause is DcqlError => {\n if (cause instanceof DcqlError) {\n return true\n }\n if (cause instanceof Error && cause.name === 'DcqlError') {\n // https://github.com/trpc/trpc/pull/4848\n return true\n }\n\n return false\n}\n\nexport function getDcqlErrorFromUnknown(cause: unknown): DcqlError {\n if (isDcqlError(cause)) {\n return cause\n }\n\n const dcqlError = new DcqlError({\n code: 'INTERNAL_SERVER_ERROR',\n cause,\n })\n\n // Inherit stack from error\n if (cause instanceof Error && cause.stack) {\n dcqlError.stack = cause.stack\n }\n\n return dcqlError\n}\n\ntype DCQL_ERROR_CODE = 'PARSE_ERROR' | 'INTERNAL_SERVER_ERROR' | 'NOT_IMPLEMENTED' | 'BAD_REQUEST'\n\nexport class DcqlError extends Error {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore override doesn't work in all environments due to \"This member cannot have an 'override' modifier because it is not declared in the base class 'Error'\"\n public override readonly cause?: Error\n public readonly code\n\n constructor(opts: {\n message?: string\n code: DCQL_ERROR_CODE\n cause?: unknown\n }) {\n const cause = getCauseFromUnknown(opts.cause)\n const message = opts.message ?? cause?.message ?? opts.code\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore https://github.com/tc39/proposal-error-cause\n super(message, { cause })\n\n this.code = opts.code\n this.name = 'DcqlError'\n\n if (!this.cause) {\n // < ES2022 / < Node 16.9.0 compatability\n this.cause = cause\n }\n }\n}\n","import { DcqlError } from './e-base.js'\n\nexport class DcqlCredentialSetError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlUndefinedClaimSetIdError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlNonUniqueCredentialQueryIdsError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlParseError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'PARSE_ERROR', ...opts })\n }\n}\n\nexport class DcqlInvalidClaimsQueryIdError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlMissingClaimSetParseError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'PARSE_ERROR', ...opts })\n }\n}\n\nexport class DcqlInvalidPresentationRecordError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n\nexport class DcqlPresentationResultError extends DcqlError {\n constructor(opts: { message: string; cause?: unknown }) {\n super({ code: 'BAD_REQUEST', ...opts })\n }\n}\n","import * as v from 'valibot'\nimport { DcqlMdocCredential, DcqlSdJwtVcCredential, DcqlW3cVcCredential } from '../u-dcql-credential'\nimport type { InferModelTypes } from '../u-model'\nimport { Model } from '../u-model'\n\nexport namespace DcqlMdocPresentation {\n export const vModel = DcqlMdocCredential.vModel\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlMdocPresentation = DcqlMdocPresentation.Model['Output']\n\nexport namespace DcqlSdJwtVcPresentation {\n export const vModel = DcqlSdJwtVcCredential.vModel\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlSdJwtVcPresentation = DcqlSdJwtVcPresentation.Model['Output']\n\nexport namespace DcqlW3cVcPresentation {\n export const vModel = DcqlW3cVcCredential.vModel\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlW3cVcPresentation = DcqlW3cVcPresentation.Model['Output']\n\nexport namespace DcqlCredentialPresentation {\n export const model = new Model({\n vModel: v.variant('credential_format', [\n DcqlMdocPresentation.vModel,\n DcqlSdJwtVcPresentation.vModel,\n DcqlW3cVcPresentation.vModel,\n ]),\n })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlCredentialPresentation = DcqlCredentialPresentation.Model['Output']\n","import * as v from 'valibot'\nimport { vJsonRecord, vNonEmptyArray } from './u-dcql.js'\nimport type { InferModelTypes } from './u-model.js'\nimport { Model } from './u-model.js'\n\nexport namespace DcqlMdocCredential {\n export const vNamespaces = v.record(v.string(), v.record(v.string(), v.unknown()))\n export const vModel = v.object({\n credential_format: v.literal('mso_mdoc'),\n doctype: v.string(),\n namespaces: vNamespaces,\n })\n\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n export type NameSpaces = v.InferOutput<typeof vNamespaces>\n}\nexport type DcqlMdocCredential = DcqlMdocCredential.Model['Output']\n\nexport namespace DcqlSdJwtVcCredential {\n export const vClaims = vJsonRecord\n export const vModel = v.object({\n credential_format: v.picklist(['vc+sd-jwt', 'dc+sd-jwt']),\n vct: v.string(),\n claims: vClaims,\n })\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n export type Claims = Model['Output']['claims']\n}\nexport type DcqlSdJwtVcCredential = DcqlSdJwtVcCredential.Model['Output']\n\nexport namespace DcqlW3cVcCredential {\n export const vClaims = vJsonRecord\n export const vModel = v.object({\n credential_format: v.picklist(['jwt_vc_json-ld', 'jwt_vc_json']),\n claims: vClaims,\n })\n\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n export type Claims = Model['Output']['claims']\n}\nexport type DcqlW3cVcCredential = DcqlW3cVcCredential.Model['Output']\n\nexport namespace DcqlCredential {\n export const vModel = v.variant('credential_format', [\n DcqlMdocCredential.vModel,\n DcqlSdJwtVcCredential.vModel,\n DcqlW3cVcCredential.vModel,\n ])\n\n export const vParseSuccess = v.object({\n success: v.literal(true),\n typed: v.literal(true),\n issues: v.optional(v.undefined()),\n input_credential_index: v.number(),\n claim_set_index: v.union([v.number(), v.undefined()]),\n output: DcqlCredential.vModel,\n })\n\n export const vParseFailure = v.object({\n success: v.literal(false),\n typed: v.boolean(),\n output: v.unknown(),\n issues: v.pipe(v.array(v.unknown()), vNonEmptyArray()),\n input_credential_index: v.number(),\n claim_set_index: v.union([v.number(), v.undefined()]),\n })\n export const model = new Model({ vModel })\n export type Model = InferModelTypes<typeof model>\n}\nexport type DcqlCredential = DcqlCredential.Model['Output']\n","import * as v from 'valibot'\nimport type { UnknownBaseSchema } from './u-model'\nexport const idRegex = /^[a-zA-Z0-9_-]+$/\n\nexport const vNonEmptyArray = <T extends unknown[]>() => {\n return v.custom<[T[number], ...T]>((input) => (input as T).length > 0)\n}\n\nexport const vIdString = v.pipe(v.string(), v.regex(idRegex), v.nonEmpty())\n\nexport type Json = string | number | boolean | null | { [key: string]: Json } | Json[]\n\ninterface HasToJson {\n toJson(): Json\n}\n\nfunction isToJsonable(value: unknown): value is HasToJson {\n if (value === null || typeof value !== 'object') return false\n\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n const toJsonFn = (value as any).toJson\n return typeof toJsonFn === 'function'\n}\n\nexport const vWithJT = <Schema extends UnknownBaseSchema>(schema: Schema) =>\n v.pipe(\n v.custom<v.InferInput<Schema>>(() => true),\n v.rawTransform<v.InferInput<Schema>, v.InferOutput<Schema>>(({ dataset, addIssue, NEVER }) => {\n const result = v.safeParse(schema, dataset.value)\n if (result.success) return dataset.value\n\n if (!isToJsonable(dataset.value)) {\n for (const safeParseIssue of result.issues) {\n addIssue({\n ...safeParseIssue,\n expected: safeParseIssue.expected ?? undefined,\n })\n }\n\n return NEVER\n }\n\n let json: Json\n\n try {\n json = dataset.value.toJson()\n } catch (error) {\n for (const safeParseIssue of result.issues) {\n addIssue({\n ...safeParseIssue,\n expected: safeParseIssue.expected ?? undefined,\n })\n }\n addIssue({ message: 'Json Transformation failed' })\n return NEVER\n }\n\n const safeParseResult: v.SafeParseResult<Schema> = v.safeParse(schema, json)\n if (safeParseResult.success) return dataset.value\n\n for (const safeParseIssue of safeParseResult.issues) {\n addIssue({\n ...safeParseIssue,\n expected: safeParseIssue.expected ?? undefined,\n })\n }\n\n return NEVER\n })\n )\n\nexport const vJsonLiteral = v.union([v.string(), v.number(), v.boolean(), v.null()])\n\nexport type JsonLiteral = v.InferOutput<typeof vJsonLiteral>\n\nexport const vJson: v.GenericSchema<Json> = v.lazy(() =>\n v.union([vJsonLiteral, v.array(vJson), v.record(v.string(), vJson)])\n)\n\nexport const vJsonWithJT: v.GenericSchema<Json> = v.lazy(() =>\n vWithJT(v.union([vJsonLiteral, v.array(vJson), v.record(v.string(), vJson)]))\n)\n\nexport const vJsonRecord = v.record(v.string(), vJson)\nexport type JsonRecord = v.InferOutput<typeof vJsonRecord>\n\nexport const vStringToJson = v.rawTransform<string, Json>(({ dataset, addIssue, NEVER }) => {\n try {\n return JSON.parse(dataset.value) as Json\n } catch (error) {\n addIssue({ message: 'Invalid JSON' })\n return NEVER\n }\n})\n","import * as v from 'valibot'\nimport { DcqlParseError } from './dcql-error/e-dcql'\n\nexport type UnknownBaseSchema = v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>\n\ntype EnsureOutputAssignableToInput<T extends UnknownBaseSchema> = v.InferOutput<T> extends v.InferInput<T> ? T : never\n\nexport class Model<T extends UnknownBaseSchema> {\n constructor(private input: { vModel: EnsureOutputAssignableToInput<T> }) {}\n\n public get v() {\n return this.input.vModel\n }\n\n public parse(input: T) {\n const result = this.safeParse(input)\n\n if (result.success) {\n return result.output\n }\n\n return new DcqlParseError({\n message: JSON.stringify(result.flattened),\n cause: result.error,\n })\n }\n\n public safeParse(\n input: unknown\n ):\n | { success: true; output: v.InferOutput<T> }\n | { success: false; flattened: v.FlatErrors<T>; error: v.ValiError<T> } {\n const res = v.safeParse(this.input.vModel, input)\n if (res.success) {\n return { success: true, output: res.output }\n }\n return {\n success: false,\n error: new v.ValiError(res.issues),\n flattened: v.flatten<T>(res.issues),\n }\n }\n\n public is(input: unknown): input is v.InferOutput<T> {\n return v.is(this.v, input)\n }\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\nexport type InferModelTypes<T extends Model<any>> = T extends Model<infer U>\n ? {\n Input: v.InferInput<U>\n Output: v.InferOutput<U>\n }\n : never\n","import * as v from 'valibot'\n\nimport { DcqlInvalidPresentationRecordError, DcqlPresentationResultError } from '../dcql-error/e-dcql.js'\nimport { runCredentialQuery } from '../dcql-parser/dcql-credential-query-result.js'\nimport { DcqlQueryResult } from '../dcql-query-result/m-dcql-query-result.js'\nimport type { DcqlQuery } from '../dcql-query/m-dcql-query.js'\nimport { DcqlCredential } from '../u-dcql-credential.js'\nimport { vIdString } from '../u-dcql.js'\nimport type { DcqlCredentialPresentation } from './m-dcql-credential-presentation.js'\n\nexport namespace DcqlPresentationResult {\n export const vModel = v.object({\n ...v.omit(DcqlQueryResult.vModel, ['credential_matches']).entries,\n\n invalid_matches: v.union([\n v.record(\n v.pipe(vIdString),\n v.object({\n ...v.omit(DcqlCredential.vParseFailure, ['input_credential_index']).entries,\n presentation_id: v.pipe(vIdString),\n })\n ),\n v.undefined(),\n ]),\n\n valid_matches: v.record(\n v.pipe(vIdString),\n v.object({\n ...v.omit(DcqlCredential.vParseSuccess, ['issues', 'input_credential_index']).entries,\n presentation_id: v.pipe(vIdString),\n })\n ),\n })\n\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n\n export const parse = (input: Input | DcqlQueryResult) => {\n return v.parse(vModel, input)\n }\n\n /**\n * Query if the presentation record can be satisfied by the provided presentations\n * considering the dcql query\n *\n * @param dcqlQuery\n * @param dcqlPresentation\n */\n export const fromDcqlPresentation = (\n dcqlPresentation: Record<string, DcqlCredentialPresentation>,\n ctx: { dcqlQuery: DcqlQuery }\n ): Output => {\n const { dcqlQuery } = ctx\n\n const presentationQueriesResults = Object.fromEntries(\n Object.entries(dcqlPresentation).map(([queryId, presentation]) => {\n const credentialQuery = dcqlQuery.credentials.find((c) => c.id === queryId)\n if (!credentialQuery) {\n throw new DcqlPresentationResultError({\n message: `Query ${queryId} not found in the dcql query. Cannot validate presentation.`,\n })\n }\n\n return [\n queryId,\n runCredentialQuery(credentialQuery, {\n presentation: true,\n credentials: [presentation],\n }),\n ]\n })\n )\n\n let invalidMatches: DcqlPresentationResult['invalid_matches'] = {}\n const validMatches: DcqlPresentationResult['valid_matches'] = {}\n\n for (const [queryId, presentationQueryResult] of Object.entries(presentationQueriesResults)) {\n for (const presentationQueryResultForClaimSet of presentationQueryResult) {\n // NOTE: result can be undefined, but this is only the case if there was a valid claim\n // set match previously and we skip other claim set matching. We don't add these to the parse\n // result.\n const result = presentationQueryResultForClaimSet[0]\n\n if (result?.success) {\n const { issues, input_credential_index, ...rest } = result\n validMatches[queryId] = { ...rest, presentation_id: queryId }\n } else if (result?.success === false) {\n const { input_credential_index, ...rest } = result\n invalidMatches[queryId] = {\n ...rest,\n presentation_id: queryId,\n }\n }\n }\n }\n\n // Only keep the invalid matches that do not have a valid match as well\n invalidMatches = Object.fromEntries(\n Object.entries(invalidMatches ?? {}).filter(([queryId, result]) => validMatches[queryId] === undefined)\n )\n\n const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {\n const matchingOptions = set.options.filter((option) =>\n option.every((credentialQueryId) => validMatches[credentialQueryId]?.success)\n )\n\n return {\n ...set,\n matching_options: matchingOptions.length > 0 ? (matchingOptions as [string[], ...string[][]]) : undefined,\n }\n }) as DcqlQueryResult.Output['credential_sets']\n\n const dqclQueryMatched = credentialSetResults\n ? credentialSetResults.every((set) => !set.required || set.matching_options)\n : Object.keys(invalidMatches).length === 0\n\n return {\n ...dcqlQuery,\n canBeSatisfied: dqclQueryMatched,\n valid_matches: validMatches,\n invalid_matches: Object.keys(invalidMatches).length === 0 ? undefined : {},\n credential_sets: credentialSetResults,\n }\n }\n\n export const validate = (dcqlQueryResult: DcqlPresentationResult) => {\n if (!dcqlQueryResult.canBeSatisfied) {\n throw new DcqlInvalidPresentationRecordError({\n message: 'Invalid Presentation record',\n cause: dcqlQueryResult,\n })\n }\n\n return dcqlQueryResult satisfies Output\n }\n}\nexport type DcqlPresentationResult = DcqlPresentationResult.Output\n","import * as v from 'valibot'\nimport type { DcqlQueryResult } from '../dcql-query-result/m-dcql-query-result.js'\nimport type { DcqlCredentialQuery } from '../dcql-query/m-dcql-credential-query.js'\nimport type { DcqlCredential } from '../u-dcql-credential.js'\nimport type {} from '../u-dcql.js'\nimport { getCredentialQueryParser } from './dcql-claims-query-result.js'\n\nexport const runCredentialQuery = (\n credentialQuery: DcqlCredentialQuery,\n ctx: {\n credentials: DcqlCredential[]\n presentation: boolean\n }\n): DcqlQueryResult.CredentialQueryResult => {\n const { credentials, presentation } = ctx\n const claimSets = credentialQuery.claim_sets ?? [undefined]\n\n const credentialQueryResult: v.InferInput<typeof DcqlQueryResult.vCredentialQueryResult> = []\n\n for (const [claimSetIndex, claim_set] of claimSets.entries()) {\n const credentialParser = getCredentialQueryParser(credentialQuery, {\n claimSet: claim_set,\n presentation,\n })\n\n const claimSetResult: (typeof credentialQueryResult)[number] = []\n\n for (const [credentialIndex, credential] of credentials.entries()) {\n if (claimSetIndex > 0) {\n // if one the credential was successfully parsed against a previous claimsset we don't need to further validate other claim sets\n const previous = credentialQueryResult[claimSetIndex - 1][credentialIndex]\n\n // if the previous credential was successfully parsed we don't need to further validate the current credential\n // we set all further parsing attempts to undefined\n if (previous?.success || !previous) {\n claimSetResult[credentialIndex] = undefined\n continue\n }\n }\n\n const parseResult = v.safeParse(credentialParser, credential)\n claimSetResult.push({\n ...parseResult,\n ...(parseResult.issues && {\n flattened: v.flatten<typeof credentialParser>(parseResult.issues),\n }),\n input_credential_index: credentialIndex,\n claim_set_index: credentialQuery.claim_sets ? claimSetIndex : undefined,\n })\n }\n\n credentialQueryResult.push(claimSetResult)\n }\n\n return credentialQueryResult as DcqlQueryResult.CredentialQueryResult\n}\n","import * as v from 'valibot'\nimport { DcqlInvalidClaimsQueryIdError, DcqlMissingClaimSetParseError } from '../dcql-error/e-dcql.js'\nimport { DcqlClaimsQuery } from '../dcql-query/m-dcql-claims-query.js'\nimport type { DcqlCredentialQuery } from '../dcql-query/m-dcql-credential-query.js'\nimport { vWithJT } from '../u-dcql.js'\nimport { vJson, vJsonRecord } from '../u-dcql.js'\n\nconst getClaimParser = (input: {\n value?: string | number | boolean\n values?: (string | number | boolean)[]\n}) => {\n const { value, values } = input\n if (value) {\n return vWithJT(v.literal(value))\n }\n\n if (values) {\n return vWithJT(v.union(values.map((val) => v.literal(val))))\n }\n\n return v.nonNullish(v.any())\n}\n\nexport const getNamespacesParser = (claimsQueries: DcqlClaimsQuery.Mdoc[]) => {\n const claimsForNamespace: Record<string, DcqlClaimsQuery.MdocPath[]> = {}\n\n for (const claimQuery of claimsQueries) {\n // Normalize the query to the latest path syntax\n const mdocPathQuery: DcqlClaimsQuery.MdocPath = v.is(DcqlClaimsQuery.vMdocNamespace, claimQuery)\n ? {\n id: claimQuery.id,\n path: [claimQuery.namespace, claimQuery.claim_name],\n values: claimQuery.values,\n }\n : claimQuery\n\n const namespace = mdocPathQuery.path[0]\n if (claimsForNamespace[namespace]) {\n claimsForNamespace[namespace]?.push({ ...mdocPathQuery })\n } else {\n claimsForNamespace[namespace] = [{ ...mdocPathQuery }]\n }\n }\n\n const parsersForNamespaces = Object.entries(claimsForNamespace).map(([namespace, claims]) => {\n const claimParsers = Object.fromEntries(claims.map((claim) => [claim.path[1], getClaimParser(claim)]))\n return [namespace, v.object(claimParsers)]\n })\n\n return v.object(Object.fromEntries(parsersForNamespaces))\n}\n\nconst getClaimQueryParser = (\n claimQuery: DcqlClaimsQuery.W3cAndSdJwtVc,\n ctx: { index: number; presentation: boolean }\n): typeof vJson => {\n const { index, presentation } = ctx\n const pathElement = claimQuery.path[index]\n const isLast = index === claimQuery.path.length - 1\n\n const vClaimParser = getClaimParser(claimQuery)\n\n if (typeof pathElement === 'number') {\n const elementParser = isLast ? vClaimParser : getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 })\n\n if (presentation) {\n // We allow both the concrete value and an array of one value\n return v.union([\n v.pipe(\n v.array(vJson),\n v.length(1),\n v.transform((input) => input[0]),\n elementParser\n ),\n elementParser,\n ])\n }\n\n return v.pipe(\n v.array(vJson),\n v.transform((input) => input[pathElement]),\n elementParser\n )\n }\n if (typeof pathElement === 'string') {\n return v.object({\n [pathElement]: isLast ? vClaimParser : getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 }),\n })\n }\n return isLast ? v.array(vClaimParser) : v.array(getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 }))\n}\n\nexport const getJsonClaimsParser = (claimsQueries: DcqlClaimsQuery.W3cAndSdJwtVc[], ctx: { presentation: boolean }) => {\n const claimParser = v.intersect(\n claimsQueries.map(\n (claimQuery) =>\n getClaimQueryParser(claimQuery, {\n ...ctx,\n index: 0,\n }) as typeof vJsonRecord\n )\n )\n\n return claimParser\n}\n\nexport const getMdocClaimsQueriesForClaimSet = (\n claimsQueries: DcqlClaimsQuery.Mdoc[],\n claimSet: string[]\n): DcqlClaimsQuery.Mdoc[] => {\n return claimSet.map((credential_id) => {\n const query = claimsQueries.find((query) => query.id === credential_id)\n if (!query) {\n throw new DcqlInvalidClaimsQueryIdError({\n message: `Claims-query with id '${credential_id}' not found.`,\n })\n }\n\n return query\n })\n}\n\nexport const getJsonClaimsQueriesForClaimSet = (\n claimsQueries: DcqlClaimsQuery.W3cAndSdJwtVc[],\n claimSet: string[]\n): DcqlClaimsQuery.W3cAndSdJwtVc[] => {\n return claimSet.map((credential_id) => {\n const query = claimsQueries.find((query) => query.id === credential_id)\n if (!query) {\n throw new DcqlInvalidClaimsQueryIdError({\n message: `Claims-query with id '${credential_id}' not found.`,\n })\n }\n return query\n })\n}\n\nconst getMdocParser = (\n credentialQuery: DcqlCredentialQuery.Mdoc,\n ctx: { claimSet?: NonNullable<DcqlCredentialQuery['claim_sets']>[number] }\n) => {\n const { claimSet } = ctx\n\n const vDoctype = credentialQuery.meta?.doctype_value ? v.literal(credentialQuery.meta.doctype_value) : v.string()\n\n const claimSetQueries =\n credentialQuery.claims && claimSet\n ? getMdocClaimsQueriesForClaimSet(credentialQuery.claims, claimSet)\n : credentialQuery.claims\n\n const credentialParser = v.object({\n credential_format: v.literal('mso_mdoc'),\n doctype: vDoctype,\n namespaces: claimSetQueries\n ? getNamespacesParser(claimSetQueries)\n : v.record(v.string(), v.record(v.string(), v.unknown())),\n })\n\n return credentialParser\n}\n\nconst getW3cVcSdJwtVcParser = (\n credentialQuery: DcqlCredentialQuery.SdJwtVc | DcqlCredentialQuery.W3cVc,\n ctx: {\n claimSet?: NonNullable<DcqlCredentialQuery['claim_sets']>[number]\n presentation: boolean\n }\n) => {\n const { claimSet } = ctx\n const claimSetQueries =\n credentialQuery.claims && claimSet\n ? getJsonClaimsQueriesForClaimSet(credentialQuery.claims, claimSet)\n : credentialQuery.claims\n\n if (credentialQuery.format === 'vc+sd-jwt' || credentialQuery.format === 'dc+sd-jwt') {\n return v.object({\n credential_format: v.literal(credentialQuery.format),\n vct: credentialQuery.meta?.vct_values ? v.picklist(credentialQuery.meta.vct_values) : v.string(),\n claims: claimSetQueries ? getJsonClaimsParser(claimSetQueries, ctx) : vJsonRecord,\n })\n }\n const credentialParser = v.object({\n credential_format: v.picklist(['jwt_vc_json', 'jwt_vc_json-ld']),\n claims: claimSetQueries ? getJsonClaimsParser(claimSetQueries, ctx) : vJsonRecord,\n })\n\n return credentialParser\n}\n\nexport const getCredentialQueryParser = (\n credentialQuery: DcqlCredentialQuery,\n ctx: {\n claimSet?: NonNullable<DcqlCredentialQuery['claim_sets']>[number]\n presentation: boolean\n }\n) => {\n if (credentialQuery.claim_sets && !ctx.claimSet) {\n throw new DcqlMissingClaimSetParseError({\n message: 'credentialQuery specifies claim_sets but no claim_set for parsing is provided.',\n })\n }\n\n if (credentialQuery.format === 'mso_mdoc') {\n return getMdocParser(credentialQuery, ctx)\n }\n return getW3cVcSdJwtVcParser(credentialQuery, ctx)\n}\n","import * as v from 'valibot'\nimport { vIdString, vNonEmptyArray } from '../u-dcql.js'\n\n/**\n * Specifies claims withing a requested Credential.\n */\nexport namespace DcqlClaimsQuery {\n export const vValue = v.union([v.string(), v.pipe(v.number(), v.integer()), v.boolean()])\n\n export const vPath = v.union([v.string(), v.pipe(v.number(), v.integer(), v.minValue(0)), v.null()])\n\n export const vW3cSdJwtVc = v.object({\n id: v.pipe(\n v.optional(vIdString),\n v.description(\n 'A string identifying the particular claim. The value MUST be a non-empty string consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular claims array, the same id MUST NOT be present more than once.'\n )\n ),\n path: v.pipe(\n v.array(vPath),\n vNonEmptyArray(),\n v.description(\n 'A non-empty array representing a claims path pointer that specifies the path to a claim within the Verifiable Credential.'\n )\n ),\n values: v.pipe(\n v.optional(v.array(vValue)),\n v.description(\n 'An array of strings, integers or boolean values that specifies the expected values of the claim. If the values property is present, the Wallet SHOULD return the claim only if the type and value of the claim both match for at least one of the elements in the array.'\n )\n ),\n })\n export type W3cAndSdJwtVc = v.InferOutput<typeof vW3cSdJwtVc>\n\n const vMdocBase = v.object({\n id: v.pipe(\n v.optional(vIdString),\n v.description(\n 'A string identifying the particular claim. The value MUST be a non-empty string consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular claims array, the same id MUST NOT be present more than once.'\n )\n ),\n values: v.pipe(\n v.optional(v.array(vValue)),\n v.description(\n 'An array of strings, integers or boolean values that specifies the expected values of the claim. If the values property is present, the Wallet SHOULD return the claim only if the type and value of the claim both match for at least one of the elements in the array.'\n )\n ),\n })\n\n // Syntax up until Draft 23 of OID4VP. Keeping due to Draft 23 having\n // reach ID-3 status and thus being targeted by several implementations\n export const vMdocNamespace = v.object({\n ...vMdocBase.entries,\n\n namespace: v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the namespace of the data element within the mdoc, e.g., org.iso.18013.5.1.'\n )\n ),\n claim_name: v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the data element identifier of the data element within the provided namespace in the mdoc, e.g., first_name.'\n )\n ),\n })\n\n // Syntax starting from Draft 24 of OID4VP\n export const vMdocPath = v.object({\n ...vMdocBase.entries,\n\n intent_to_retain: v.pipe(\n v.optional(v.boolean()),\n v.description(\n 'A boolean that is equivalent to `IntentToRetain` variable defined in Section 8.3.2.1.2.1 of [@ISO.18013-5].'\n )\n ),\n\n path: v.pipe(\n v.tuple([\n v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the namespace of the data element within the mdoc, e.g., org.iso.18013.5.1.'\n )\n ),\n v.pipe(\n v.string(),\n v.description(\n 'A string that specifies the data element identifier of the data element within the provided namespace in the mdoc, e.g., first_name.'\n )\n ),\n ]),\n v.description(\n 'An array defining a claims path pointer into an mdoc. It must contain two elements of type string. The first element refers to a namespace and the second element refers to a data element identifier.'\n )\n ),\n })\n export const vMdoc = v.union([vMdocNamespace, vMdocPath])\n export type MdocNamespace = v.InferOutput<typeof vMdocNamespace>\n export type MdocPath = v.InferOutput<typeof vMdocPath>\n export type Mdoc = v.InferOutput<typeof vMdoc>\n\n export const vModel = v.union([vMdoc, vW3cSdJwtVc])\n export type Input = v.InferInput<typeof vModel>\n export type Out = v.InferOutput<typeof vModel>\n}\nexport type DcqlClaimsQuery = DcqlClaimsQuery.Out\n","import * as v from 'valibot'\nimport { DcqlCredentialQuery } from '../dcql-query/m-dcql-credential-query.js'\nimport { CredentialSetQuery } from '../dcql-query/m-dcql-credential-set-query.js'\nimport { DcqlCredential } from '../u-dcql-credential.js'\nimport { vIdString, vNonEmptyArray } from '../u-dcql.js'\n\nexport namespace DcqlQueryResult {\n export const vCredentialQueryResult = v.pipe(\n v.array(v.array(v.union([v.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure]))),\n vNonEmptyArray()\n )\n\n export type CredentialQueryResult = v.InferOutput<typeof vCredentialQueryResult>\n\n export const vModel = v.object({\n credentials: v.pipe(\n v.array(DcqlCredentialQuery.vModel),\n vNonEmptyArray(),\n v.description(\n 'REQUIRED. A non-empty array of Credential Queries that specify the requested Verifiable Credentials.'\n )\n ),\n\n credential_matches: v.record(\n v.pipe(vIdString),\n v.union([\n v.object({\n ...DcqlCredential.vParseSuccess.entries,\n all: v.pipe(\n v.array(\n v.pipe(\n v.array(v.union([v.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure])),\n vNonEmptyArray()\n )\n ),\n vNonEmptyArray()\n ),\n }),\n v.object({\n success: DcqlCredential.vParseFailure.entries.success,\n all: v.pipe(\n v.array(\n v.pipe(\n v.array(v.union([v.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure])),\n vNonEmptyArray()\n )\n ),\n vNonEmptyArray()\n ),\n }),\n ])\n ),\n\n credential_sets: v.optional(\n v.pipe(\n v.array(\n v.object({\n ...CredentialSetQuery.vModel.entries,\n matching_options: v.union([v.undefined(), v.pipe(v.array(v.array(v.string())), vNonEmptyArray())]),\n })\n ),\n vNonEmptyArray(),\n v.description(\n 'OPTIONAL. A non-empty array of credential set queries that specifies additional constraints on which of the requested Verifiable Credentials to return.'\n )\n )\n ),\n\n canBeSatisfied: v.boolean(),\n })\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n\n export type CredentialMatch = Input['credential_matches'][number]\n export type CredentialMatchRecord = Input['credential_matches']\n}\nexport type DcqlQueryResult = DcqlQueryResult.Output\n","import * as v from 'valibot'\nimport { DcqlUndefinedClaimSetIdError } from '../dcql-error/e-dcql.js'\nimport { idRegex, vIdString, vNonEmptyArray } from '../u-dcql.js'\nimport { DcqlClaimsQuery } from './m-dcql-claims-query.js'\n\n/**\n * A Credential Query is an object representing a request for a presentation of one Credential.\n */\nexport namespace DcqlCredentialQuery {\n const vBase = v.object({\n id: v.pipe(\n v.string(),\n v.regex(idRegex),\n v.description(\n `REQUIRED. A string identifying the Credential in the response and, if provided, the constraints in 'credential_sets'.`\n )\n ),\n claim_sets: v.pipe(\n v.optional(v.pipe(v.array(v.pipe(v.array(vIdString), vNonEmptyArray())), vNonEmptyArray())),\n v.description(\n `OPTIONAL. A non-empty array containing arrays of identifiers for elements in 'claims' that specifies which combinations of 'claims' for the Credential are requested.`\n )\n ),\n })\n\n export const vMdoc = v.object({\n ...vBase.entries,\n format: v.pipe(\n v.literal('mso_mdoc'),\n v.description('REQUIRED. A string that specifies the format of the requested Verifiable Credential.')\n ),\n claims: v.pipe(\n v.optional(v.pipe(v.array(DcqlClaimsQuery.vMdoc), vNonEmptyArray())),\n v.description('OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.')\n ),\n meta: v.pipe(\n v.optional(\n v.object({\n doctype_value: v.pipe(\n v.optional(v.string()),\n v.description(\n 'OPTIONAL. String that specifies an allowed value for the doctype of the requested Verifiable Credential.'\n )\n ),\n })\n ),\n v.description(\n 'OPTIONAL. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential.'\n )\n ),\n })\n export type Mdoc = v.InferOutput<typeof vMdoc>\n\n export const vSdJwtVc = v.object({\n ...vBase.entries,\n format: v.pipe(\n v.picklist(['vc+sd-jwt', 'dc+sd-jwt']),\n v.description('REQUIRED. A string that specifies the format of the requested Verifiable Credential.')\n ),\n claims: v.pipe(\n v.optional(v.pipe(v.array(DcqlClaimsQuery.vW3cSdJwtVc), vNonEmptyArray())),\n v.description('OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.')\n ),\n meta: v.pipe(\n v.optional(\n v.pipe(\n v.object({\n vct_values: v.optional(v.array(v.string())),\n }),\n v.description(\n 'OPTIONAL. An array of strings that specifies allowed values for the type of the requested Verifiable Credential.'\n )\n )\n ),\n v.description(\n 'OPTIONAL. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential.'\n )\n ),\n })\n export type SdJwtVc = v.InferOutput<typeof vSdJwtVc>\n\n export const vW3cVc = v.object({\n ...vBase.entries,\n format: v.picklist(['jwt_vc_json', 'jwt_vc_json-ld']),\n claims: v.optional(v.pipe(v.array(DcqlClaimsQuery.vW3cSdJwtVc), vNonEmptyArray())),\n })\n export type W3cVc = v.InferOutput<typeof vW3cVc>\n\n export const vModel = v.variant('format', [vMdoc, vSdJwtVc, vW3cVc])\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n\n export const validate = (credentialQuery: Output) => {\n claimSetIdsAreDefined(credentialQuery)\n }\n}\nexport type DcqlCredentialQuery = DcqlCredentialQuery.Output\n\n// --- validations --- //\n\nconst claimSetIdsAreDefined = (credentialQuery: DcqlCredentialQuery) => {\n if (!credentialQuery.claim_sets) return\n const claimIds = new Set(credentialQuery.claims?.map((claim) => claim.id))\n\n const undefinedClaims: string[] = []\n for (const claim_set of credentialQuery.claim_sets) {\n for (const claim_id of claim_set) {\n if (!claimIds.has(claim_id)) {\n undefinedClaims.push(claim_id)\n }\n }\n }\n\n if (undefinedClaims.length > 0) {\n throw new DcqlUndefinedClaimSetIdError({\n message: `Credential set contains undefined credential id${undefinedClaims.length === 0 ? '' : '`s'} '${undefinedClaims.join(', ')}'`,\n })\n }\n}\n","import * as v from 'valibot'\nimport { vIdString, vNonEmptyArray } from '../u-dcql.js'\n\n/**\n * A Credential Set Query is an object representing\n * a request for one or more credentials to satisfy a particular use case with the Verifier.\n */\nexport namespace CredentialSetQuery {\n export const vModel = v.object({\n options: v.pipe(\n v.array(v.array(vIdString)),\n vNonEmptyArray(),\n v.description(\n 'REQUIRED. A non-empty array, where each value in the array is a list of Credential Query identifiers representing one set of Credentials that satisfies the use case.'\n )\n ),\n required: v.pipe(\n v.optional(v.boolean(), true),\n v.description(\n `OPTIONAL. Boolean which indicates whether this set of Credentials is required to satisfy the particular use case at the Verifier. If omitted, the default value is 'true'.`\n )\n ),\n purpose: v.pipe(\n v.optional(v.union([v.string(), v.number(), v.record(v.string(), v.unknown())])),\n v.description('OPTIONAL. A string, number or object specifying the purpose of the query.')\n ),\n })\n\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n}\nexport type CredentialSetQuery = CredentialSetQuery.Output\n","import * as v from 'valibot'\nimport { vIdString, vJsonRecord, vStringToJson } from '../u-dcql.js'\n\nexport namespace DcqlPresentation {\n export const vModel = v.record(vIdString, v.union([v.string(), vJsonRecord]))\n\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n export const parse = (input: Input | string) => {\n if (typeof input === 'string') {\n return v.parse(v.pipe(v.string(), vStringToJson, vModel), input)\n }\n\n return v.parse(vModel, input)\n }\n\n export const encode = (input: Output) => {\n return JSON.stringify(input)\n }\n}\nexport type DcqlPresentation = DcqlPresentation.Output\n","import type * as v from 'valibot'\nimport { runCredentialQuery } from '../dcql-parser/dcql-credential-query-result.js'\nimport type { DcqlQuery } from '../dcql-query/m-dcql-query.js'\nimport type { DcqlCredential } from '../u-dcql-credential.js'\nimport type { DcqlQueryResult } from './m-dcql-query-result.js'\n\nexport const runDcqlQuery = (\n dcqlQuery: DcqlQuery.Output,\n ctx: {\n credentials: DcqlCredential[]\n presentation: boolean\n }\n): DcqlQueryResult => {\n const credentialQueriesResults = Object.fromEntries(\n dcqlQuery.credentials.map((credentialQuery) => [credentialQuery.id, runCredentialQuery(credentialQuery, ctx)])\n )\n\n const credentialMatches = Object.fromEntries(\n Object.entries(credentialQueriesResults).map(([key, credentialQueryResult]) => {\n // Find the best match for each credential query\n let bestMatch: v.InferOutput<typeof DcqlCredential.vParseSuccess> | undefined = undefined\n\n for (const credentialParseResult of credentialQueryResult) {\n const bestMatchForCredential = credentialParseResult.find((result) => result?.success === true)\n\n if (!bestMatch && bestMatchForCredential) {\n const { issues, ...matchWithoutIssues } = bestMatchForCredential\n bestMatch = matchWithoutIssues\n continue\n }\n\n // biome-ignore lint/style/noNonNullAssertion: <explanation>\n if (bestMatchForCredential && bestMatchForCredential.claim_set_index! < bestMatch?.claim_set_index!) {\n const { issues, ...matchWithoutIssues } = bestMatchForCredential\n bestMatch = matchWithoutIssues\n }\n }\n\n return [\n key,\n bestMatch ? { ...bestMatch, all: credentialQueryResult } : { success: false, all: credentialQueryResult },\n ]\n })\n ) satisfies DcqlQueryResult.CredentialMatchRecord\n\n const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {\n const matchingOptions = set.options.filter((option) =>\n option.every((credentialQueryId) => credentialMatches[credentialQueryId]?.success)\n )\n\n return {\n ...set,\n matching_options: matchingOptions.length > 0 ? (matchingOptions as [string[], ...string[][]]) : undefined,\n }\n }) as DcqlQueryResult.Output['credential_sets']\n\n const dqclQueryMatched = credentialSetResults\n ? credentialSetResults.every((set) => !set.required || set.matching_options)\n : Object.values(credentialMatches).every((query) => query.success)\n\n return {\n ...dcqlQuery,\n canBeSatisfied: dqclQueryMatched,\n credential_matches: credentialMatches as DcqlQueryResult['credential_matches'],\n credential_sets: credentialSetResults,\n }\n}\n","import * as v from 'valibot'\nimport { DcqlCredentialSetError, DcqlNonUniqueCredentialQueryIdsError } from '../dcql-error/e-dcql.js'\nimport { runDcqlQuery } from '../dcql-query-result/run-dcql-query.js'\nimport type { DcqlCredential } from '../u-dcql-credential.js'\nimport { vNonEmptyArray } from '../u-dcql.js'\nimport { DcqlCredentialQuery } from './m-dcql-credential-query.js'\nimport { CredentialSetQuery } from './m-dcql-credential-set-query.js'\n\n/**\n * The Digital Credentials Query Language (DCQL, pronounced [ˈdakl̩]) is a\n * JSON-encoded query language that allows the Verifier to request Verifiable\n * Presentations that match the query. The Verifier MAY encode constraints on the\n * combinations of credentials and claims that are requested. The Wallet evaluates\n * the query against the Verifiable Credentials it holds and returns Verifiable\n * Presentations matching the query.\n */\nexport namespace DcqlQuery {\n export const vModel = v.object({\n credentials: v.pipe(\n v.array(DcqlCredentialQuery.vModel),\n vNonEmptyArray(),\n v.description(\n 'REQUIRED. A non-empty array of Credential Queries that specify the requested Verifiable Credentials.'\n )\n ),\n credential_sets: v.pipe(\n v.optional(v.pipe(v.array(CredentialSetQuery.vModel), vNonEmptyArray())),\n v.description(\n 'OPTIONAL. A non-empty array of credential set queries that specifies additional constraints on which of the requested Verifiable Credentials to return.'\n )\n ),\n })\n export type Input = v.InferInput<typeof vModel>\n export type Output = v.InferOutput<typeof vModel>\n export const validate = (dcqlQuery: Output) => {\n validateUniqueCredentialQueryIds(dcqlQuery)\n validateCredentialSets(dcqlQuery)\n dcqlQuery.credentials.forEach(DcqlCredentialQuery.validate)\n }\n export const query = (dcqlQuery: Output, credentials: DcqlCredential[]) => {\n return runDcqlQuery(dcqlQuery, { credentials, presentation: false })\n }\n\n export const parse = (input: Input) => {\n return v.parse(vModel, input)\n }\n}\nexport type DcqlQuery = DcqlQuery.Output\n\n// --- validations --- //\n\nconst validateUniqueCredentialQueryIds = (query: DcqlQuery.Output) => {\n const ids = query.credentials.map((c) => c.id)\n const duplicates = ids.filter((id, index) => ids.indexOf(id) !== index)\n\n if (duplicates.length > 0) {\n throw new DcqlNonUniqueCredentialQueryIdsError({\n message: `Duplicate credential query ids found: ${duplicates.join(', ')}`,\n })\n }\n}\n\nconst validateCredentialSets = (query: DcqlQuery.Output) => {\n if (!query.credential_sets) return\n\n const credentialQueryIds = new Set(query.credentials.map((c) => c.id))\n\n const undefinedCredentialQueryIds: string[] = []\n for (const credential_set of query.credential_sets) {\n for (const credentialSetOption of credential_set.options) {\n for (const credentialQueryId of credentialSetOption) {\n if (!credentialQueryIds.has(credentialQueryId)) {\n undefinedCredentialQueryIds.push(credentialQueryId)\n }\n }\n }\n }\n\n if (undefinedCredentialQueryIds.length > 0) {\n throw new DcqlCredentialSetError({\n message: `Credential set contains undefined credential id${undefinedCredentialQueryIds.length === 1 ? '' : '`s'} '${undefinedCredentialQueryIds.join(', ')}'`,\n })\n }\n}\n"],"mappings":";AAAA,SAAS,SAAS,OAAkD;AAClE,SAAO,CAAC,CAAC,SAAS,CAAC,MAAM,QAAQ,KAAK,KAAK,OAAO,UAAU;AAC9D;AAEA,IAAM,oBAAN,cAAgC,MAAM;AAEtC;AAEO,SAAS,oBAAoB,OAAmC;AACrE,MAAI,iBAAiB,OAAO;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,OAAO;AACpB,MAAI,SAAS,eAAe,SAAS,cAAc,UAAU,MAAM;AACjE,WAAO;AAAA,EACT;AAGA,MAAI,SAAS,UAAU;AACrB,WAAO,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,EAChC;AAGA,MAAI,SAAS,KAAK,GAAG;AACnB,UAAM,MAAM,IAAI,kBAAkB;AAClC,eAAW,OAAO,OAAO;AACvB,UAAI,GAAG,IAAI,MAAM,GAAG;AAAA,IACtB;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,IAAM,cAAc,CAAC,UAAuC;AACjE,MAAI,iBAAiB,WAAW;AAC9B,WAAO;AAAA,EACT;AACA,MAAI,iBAAiB,SAAS,MAAM,SAAS,aAAa;AAExD,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,SAAS,wBAAwB,OAA2B;AACjE,MAAI,YAAY,KAAK,GAAG;AACtB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,IAAI,UAAU;AAAA,IAC9B,MAAM;AAAA,IACN;AAAA,EACF,CAAC;AAGD,MAAI,iBAAiB,SAAS,MAAM,OAAO;AACzC,cAAU,QAAQ,MAAM;AAAA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MA,WAAA,QAAQ,CAAC,UAAiB;AACrC,WAAS,UAAMA,WAAA,QAAQ,KAAK;AAAA,EAC9B;AAAA,GA7Be;AAmCjB,IAAM,mCAAmC,CAAC,UAA4B;AACpE,QAAM,MAAM,MAAM,YAAY,IAAI,CAAC,MAAM,EAAE,EAAE;AAC7C,QAAM,aAAa,IAAI,OAAO,CAAC,IAAI,UAAU,IAAI,QAAQ,EAAE,MAAM,KAAK;AAEtE,MAAI,WAAW,SAAS,GAAG;AACzB,UAAM,IAAI,qCAAqC;AAAA,MAC7C,SAAS,yCAAyC,WAAW,KAAK,IAAI,CAAC;AAAA,IACzE,CAAC;AAAA,EACH;AACF;AAEA,IAAM,yBAAyB,CAAC,UAA4B;AAC1D,MAAI,CAAC,MAAM,gBAAiB;AAE5B,QAAM,qBAAqB,IAAI,IAAI,MAAM,YAAY,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;AAErE,QAAM,8BAAwC,CAAC;AAC/C,aAAW,kBAAkB,MAAM,iBAAiB;AAClD,eAAW,uBAAuB,eAAe,SAAS;AACxD,iBAAW,qBAAqB,qBAAqB;AACnD,YAAI,CAAC,mBAAmB,IAAI,iBAAiB,GAAG;AAC9C,sCAA4B,KAAK,iBAAiB;AAAA,QACpD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,MAAI,4BAA4B,SAAS,GAAG;AAC1C,UAAM,IAAI,uBAAuB;AAAA,MAC/B,SAAS,kDAAkD,4BAA4B,WAAW,IAAI,KAAK,IAAI,KAAK,4BAA4B,KAAK,IAAI,CAAC;AAAA,IAC5J,CAAC;AAAA,EACH;AACF;","names":["v","v","v","DcqlMdocCredential","DcqlSdJwtVcCredential","DcqlW3cVcCredential","DcqlCredential","DcqlMdocPresentation","DcqlSdJwtVcPresentation","DcqlW3cVcPresentation","DcqlCredentialPresentation","v","v","v","v","DcqlClaimsQuery","query","v","v","DcqlCredentialQuery","v","CredentialSetQuery","DcqlQueryResult","DcqlPresentationResult","v","DcqlPresentation","v","DcqlQuery"]}
|