@openid4vc/openid4vci 0.3.0-alpha-20251017122507 → 0.3.0-alpha-20251021081452
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.d.mts +24 -14
- package/dist/index.d.ts +36 -26
- package/dist/index.js +35 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import z from "zod";
|
|
|
4
4
|
|
|
5
5
|
//#region src/version.ts
|
|
6
6
|
let Openid4vciDraftVersion = /* @__PURE__ */ function(Openid4vciDraftVersion$1) {
|
|
7
|
-
Openid4vciDraftVersion$1["
|
|
7
|
+
Openid4vciDraftVersion$1["V1"] = "V1";
|
|
8
8
|
Openid4vciDraftVersion$1["Draft15"] = "Draft15";
|
|
9
9
|
Openid4vciDraftVersion$1["Draft14"] = "Draft14";
|
|
10
10
|
Openid4vciDraftVersion$1["Draft11"] = "Draft11";
|
|
@@ -304,7 +304,7 @@ const zLegacySdJwtVcFormatIdentifier = z.literal("vc+sd-jwt");
|
|
|
304
304
|
* of the OpenID for Verifiable Presentations specification. Please update your
|
|
305
305
|
* implementations accordingly.
|
|
306
306
|
*/
|
|
307
|
-
const
|
|
307
|
+
const zLegacySdJwtVcCredentialIssuerMetadataV1 = zCredentialConfigurationSupportedCommon.extend({
|
|
308
308
|
vct: z.string(),
|
|
309
309
|
format: zLegacySdJwtVcFormatIdentifier,
|
|
310
310
|
order: z.optional(z.array(z.string())),
|
|
@@ -581,7 +581,7 @@ const allCredentialIssuerMetadataFormats = [
|
|
|
581
581
|
zJwtVcJsonCredentialIssuerMetadata,
|
|
582
582
|
zSdJwtW3VcCredentialIssuerMetadata,
|
|
583
583
|
zSdJwtW3VcCredentialIssuerMetadataDraft15,
|
|
584
|
-
|
|
584
|
+
zLegacySdJwtVcCredentialIssuerMetadataV1,
|
|
585
585
|
zSdJwtDcCredentialIssuerMetadataDraft15,
|
|
586
586
|
zMsoMdocCredentialIssuerMetadataDraft15,
|
|
587
587
|
zJwtVcJsonLdCredentialIssuerMetadataDraft15,
|
|
@@ -613,7 +613,7 @@ const zCredentialIssuerMetadataDisplayEntry = z.object({
|
|
|
613
613
|
alt_text: z.string().optional()
|
|
614
614
|
}).loose().optional()
|
|
615
615
|
}).loose();
|
|
616
|
-
const
|
|
616
|
+
const zCredentialIssuerMetadataDraft14Draft15V1 = z.object({
|
|
617
617
|
credential_issuer: zHttpsUrl,
|
|
618
618
|
authorization_servers: z.array(zHttpsUrl).optional(),
|
|
619
619
|
credential_endpoint: zHttpsUrl,
|
|
@@ -626,7 +626,6 @@ const zCredentialIssuerMetadataDraft14Draft15Draft16 = z.object({
|
|
|
626
626
|
encryption_required: z.boolean()
|
|
627
627
|
}).loose().optional(),
|
|
628
628
|
batch_credential_issuance: z.object({ batch_size: z.number().positive() }).loose().optional(),
|
|
629
|
-
signed_metadata: zCompactJwt.optional(),
|
|
630
629
|
display: z.array(zCredentialIssuerMetadataDisplayEntry).optional(),
|
|
631
630
|
credential_configurations_supported: z.record(z.string(), zCredentialConfigurationSupportedWithFormats)
|
|
632
631
|
}).loose();
|
|
@@ -665,7 +664,7 @@ const zCredentialConfigurationSupportedDraft11To16 = z.object({
|
|
|
665
664
|
});
|
|
666
665
|
return z.NEVER;
|
|
667
666
|
}).pipe(zCredentialConfigurationSupportedWithFormats);
|
|
668
|
-
const
|
|
667
|
+
const zCredentialConfigurationSupportedV1ToDraft11 = zCredentialConfigurationSupportedWithFormats.transform(({ credential_metadata,...rest }) => ({
|
|
669
668
|
...credential_metadata,
|
|
670
669
|
...rest
|
|
671
670
|
})).and(z.object({ id: z.string() }).loose()).transform(({ id, credential_signing_alg_values_supported, display, proof_types_supported, scope,...rest }) => ({
|
|
@@ -706,17 +705,17 @@ const zCredentialIssuerMetadataDraft11To16 = z.object({
|
|
|
706
705
|
...authorization_server ? { authorization_servers: [authorization_server] } : {},
|
|
707
706
|
credential_configurations_supported: Object.fromEntries(credentials_supported.map((supported) => supported.id ? [supported.id, supported] : void 0).filter((i) => i !== void 0))
|
|
708
707
|
};
|
|
709
|
-
}).pipe(z.object({ credential_configurations_supported: z.record(z.string(), zCredentialConfigurationSupportedDraft11To16) }).loose()).pipe(
|
|
710
|
-
const zCredentialIssuerMetadataWithDraft11 =
|
|
708
|
+
}).pipe(z.object({ credential_configurations_supported: z.record(z.string(), zCredentialConfigurationSupportedDraft11To16) }).loose()).pipe(zCredentialIssuerMetadataDraft14Draft15V1);
|
|
709
|
+
const zCredentialIssuerMetadataWithDraft11 = zCredentialIssuerMetadataDraft14Draft15V1.transform((issuerMetadata) => ({
|
|
711
710
|
...issuerMetadata,
|
|
712
711
|
...issuerMetadata.authorization_servers ? { authorization_server: issuerMetadata.authorization_servers[0] } : {},
|
|
713
712
|
credentials_supported: Object.entries(issuerMetadata.credential_configurations_supported).map(([id, value]) => ({
|
|
714
713
|
...value,
|
|
715
714
|
id
|
|
716
715
|
}))
|
|
717
|
-
})).pipe(
|
|
718
|
-
const zCredentialIssuerMetadata = z.union([
|
|
719
|
-
const zCredentialIssuerMetadataWithDraftVersion = z.union([
|
|
716
|
+
})).pipe(zCredentialIssuerMetadataDraft14Draft15V1.extend({ credentials_supported: z.array(zCredentialConfigurationSupportedV1ToDraft11) }));
|
|
717
|
+
const zCredentialIssuerMetadata = z.union([zCredentialIssuerMetadataDraft14Draft15V1, zCredentialIssuerMetadataDraft11To16]);
|
|
718
|
+
const zCredentialIssuerMetadataWithDraftVersion = z.union([zCredentialIssuerMetadataDraft14Draft15V1.transform((credentialIssuerMetadata) => {
|
|
720
719
|
const credentialConfigurations = Object.values(credentialIssuerMetadata.credential_configurations_supported);
|
|
721
720
|
const isDraft15 = credentialConfigurations.some((configuration) => {
|
|
722
721
|
const knownConfiguration = configuration;
|
|
@@ -727,9 +726,7 @@ const zCredentialIssuerMetadataWithDraftVersion = z.union([zCredentialIssuerMeta
|
|
|
727
726
|
});
|
|
728
727
|
return {
|
|
729
728
|
credentialIssuerMetadata,
|
|
730
|
-
originalDraftVersion: credentialConfigurations.some((configuration) =>
|
|
731
|
-
return configuration.credential_metadata;
|
|
732
|
-
}) ? Openid4vciDraftVersion.Draft16 : isDraft15 ? Openid4vciDraftVersion.Draft15 : Openid4vciDraftVersion.Draft14
|
|
729
|
+
originalDraftVersion: credentialConfigurations.some((configuration) => configuration.credential_metadata) ? Openid4vciDraftVersion.V1 : isDraft15 ? Openid4vciDraftVersion.Draft15 : Openid4vciDraftVersion.Draft14
|
|
733
730
|
};
|
|
734
731
|
}), zCredentialIssuerMetadataDraft11To16.transform((credentialIssuerMetadata) => ({
|
|
735
732
|
credentialIssuerMetadata,
|
|
@@ -908,7 +905,7 @@ function credentialsSupportedToCredentialConfigurationsSupported(credentialsSupp
|
|
|
908
905
|
//#region src/credential-request/format-payload.ts
|
|
909
906
|
function getCredentialRequestFormatPayloadForCredentialConfigurationId(options) {
|
|
910
907
|
const credentialConfiguration = getCredentialConfigurationSupportedById(options.issuerMetadata.credentialIssuer.credential_configurations_supported, options.credentialConfigurationId);
|
|
911
|
-
if (zIs(
|
|
908
|
+
if (zIs(zLegacySdJwtVcCredentialIssuerMetadataV1, credentialConfiguration) || zIs(zLegacySdJwtVcCredentialIssuerMetadataDraft14, credentialConfiguration)) return {
|
|
912
909
|
format: credentialConfiguration.format,
|
|
913
910
|
vct: credentialConfiguration.vct
|
|
914
911
|
};
|
|
@@ -1133,12 +1130,12 @@ const zOauth2ErrorResponse = z.object({
|
|
|
1133
1130
|
const zCredentialEncoding = z.union([z.string(), z.record(z.string(), z.any())]);
|
|
1134
1131
|
const zBaseCredentialResponse = z.object({
|
|
1135
1132
|
credentials: z.union([z.array(z.object({ credential: zCredentialEncoding })), z.array(zCredentialEncoding)]).optional(),
|
|
1136
|
-
|
|
1137
|
-
|
|
1133
|
+
notification_id: z.string().optional(),
|
|
1134
|
+
transaction_id: z.string().optional(),
|
|
1135
|
+
interval: z.number().int().positive().optional()
|
|
1138
1136
|
}).loose();
|
|
1139
1137
|
const zCredentialResponse = zBaseCredentialResponse.extend({
|
|
1140
1138
|
credential: z.optional(zCredentialEncoding),
|
|
1141
|
-
transaction_id: z.string().optional(),
|
|
1142
1139
|
c_nonce: z.string().optional(),
|
|
1143
1140
|
c_nonce_expires_in: z.number().int().optional()
|
|
1144
1141
|
}).loose().superRefine((value, ctx) => {
|
|
@@ -1165,15 +1162,26 @@ const zCredentialErrorResponse = z.object({
|
|
|
1165
1162
|
c_nonce: z.string().optional(),
|
|
1166
1163
|
c_nonce_expires_in: z.number().int().optional()
|
|
1167
1164
|
}).loose();
|
|
1168
|
-
const zDeferredCredentialResponse = zBaseCredentialResponse.
|
|
1169
|
-
const { credentials, interval } = value;
|
|
1170
|
-
|
|
1171
|
-
|
|
1165
|
+
const zDeferredCredentialResponse = zBaseCredentialResponse.superRefine((value, ctx) => {
|
|
1166
|
+
const { credentials, transaction_id, interval, notification_id } = value;
|
|
1167
|
+
if ([credentials, transaction_id].filter((i) => i !== void 0).length !== 1) ctx.addIssue({
|
|
1168
|
+
code: "custom",
|
|
1169
|
+
message: `Exactly one of 'credentials', or 'transaction_id' MUST be defined.`
|
|
1170
|
+
});
|
|
1171
|
+
if (transaction_id && !interval) ctx.addIssue({
|
|
1172
|
+
code: "custom",
|
|
1173
|
+
message: `'interval' MUST be defined when 'transaction_id' is defined.`
|
|
1174
|
+
});
|
|
1175
|
+
if (notification_id && credentials) ctx.addIssue({
|
|
1176
|
+
code: "custom",
|
|
1177
|
+
message: `'notification_id' MUST NOT be defined when 'credentials' is not defined.`
|
|
1178
|
+
});
|
|
1179
|
+
});
|
|
1172
1180
|
|
|
1173
1181
|
//#endregion
|
|
1174
1182
|
//#region src/credential-request/retrieve-credentials.ts
|
|
1175
1183
|
async function retrieveCredentialsWithCredentialConfigurationId(options) {
|
|
1176
|
-
if (options.issuerMetadata.originalDraftVersion !== Openid4vciDraftVersion.Draft15 && options.issuerMetadata.originalDraftVersion !== Openid4vciDraftVersion.
|
|
1184
|
+
if (options.issuerMetadata.originalDraftVersion !== Openid4vciDraftVersion.Draft15 && options.issuerMetadata.originalDraftVersion !== Openid4vciDraftVersion.V1) throw new Openid4vciError("Requesting credentials based on credential configuration ID is not supported in OpenID4VCI below draft 15. Make sure to provide the format and format specific claims in the request.");
|
|
1177
1185
|
getCredentialConfigurationSupportedById(options.issuerMetadata.credentialIssuer.credential_configurations_supported, options.credentialConfigurationId);
|
|
1178
1186
|
const credentialRequest = {
|
|
1179
1187
|
...options.additionalRequestPayload,
|
|
@@ -1190,7 +1198,7 @@ async function retrieveCredentialsWithCredentialConfigurationId(options) {
|
|
|
1190
1198
|
});
|
|
1191
1199
|
}
|
|
1192
1200
|
async function retrieveCredentialsWithFormat(options) {
|
|
1193
|
-
if (options.issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.Draft15 || options.issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.
|
|
1201
|
+
if (options.issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.Draft15 || options.issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.V1) throw new Openid4vciError("Requesting credentials based on format is not supported on OpenID4VCI above draft 15. Provide the credential configuration id directly in the request.");
|
|
1194
1202
|
const credentialRequest = {
|
|
1195
1203
|
...options.formatPayload,
|
|
1196
1204
|
...options.additionalRequestPayload,
|
|
@@ -1272,7 +1280,7 @@ async function retrieveDeferredCredentials(options) {
|
|
|
1272
1280
|
deferredCredentialErrorResponseResult
|
|
1273
1281
|
};
|
|
1274
1282
|
}
|
|
1275
|
-
const deferredCredentialResponseResult = isResponseContentType(ContentType.Json, resourceResponse.response) ? zDeferredCredentialResponse.safeParse(await resourceResponse.response.clone().json()) : void 0;
|
|
1283
|
+
const deferredCredentialResponseResult = isResponseContentType(ContentType.Json, resourceResponse.response) ? zDeferredCredentialResponse.refine((response) => response.credentials || response.transaction_id === options.transactionId, { error: `Transaction id in deferred credential response does not match transaction id in deferred credential request '${options.transactionId}'` }).safeParse(await resourceResponse.response.clone().json()) : void 0;
|
|
1276
1284
|
if (!deferredCredentialResponseResult?.success) return {
|
|
1277
1285
|
...resourceResponse,
|
|
1278
1286
|
ok: false,
|
|
@@ -1690,7 +1698,7 @@ var Openid4vciClient = class {
|
|
|
1690
1698
|
*/
|
|
1691
1699
|
async retrieveCredentials({ issuerMetadata, proof, proofs, credentialConfigurationId, additionalRequestPayload, accessToken, dpop }) {
|
|
1692
1700
|
let credentialResponse;
|
|
1693
|
-
if (issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.Draft15 || issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.
|
|
1701
|
+
if (issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.Draft15 || issuerMetadata.originalDraftVersion === Openid4vciDraftVersion.V1) credentialResponse = await retrieveCredentialsWithCredentialConfigurationId({
|
|
1694
1702
|
accessToken,
|
|
1695
1703
|
credentialConfigurationId,
|
|
1696
1704
|
issuerMetadata,
|
|
@@ -1765,6 +1773,7 @@ function createDeferredCredentialResponse(options) {
|
|
|
1765
1773
|
return parseWithErrorHandling(zDeferredCredentialResponse, {
|
|
1766
1774
|
credentials: options.credentials,
|
|
1767
1775
|
notification_id: options.notificationId,
|
|
1776
|
+
transaction_id: options.transactionId,
|
|
1768
1777
|
interval: options.interval,
|
|
1769
1778
|
...options.additionalPayload
|
|
1770
1779
|
});
|