@sphereon/ssi-sdk.oid4vci-holder 0.34.1-feature.merge.crypto.extensions.modules.39 → 0.34.1-fix.79

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 CHANGED
@@ -60,6 +60,7 @@ import { DefaultURISchemes, getTypesFromAuthorizationDetails, getTypesFromCreden
60
60
  import { SupportedDidMethodEnum as SupportedDidMethodEnum2 } from "@sphereon/ssi-sdk-ext.did-utils";
61
61
  import { isManagedIdentifierDidOpts, isManagedIdentifierDidResult as isManagedIdentifierDidResult2, isManagedIdentifierJwkResult, isManagedIdentifierKidResult, isManagedIdentifierResult as isManagedIdentifierResult2, isManagedIdentifierX5cOpts, isManagedIdentifierX5cResult } from "@sphereon/ssi-sdk-ext.identifier-resolution";
62
62
  import { signatureAlgorithmFromKey } from "@sphereon/ssi-sdk-ext.key-utils";
63
+ import { defaultHasher as defaultHasher2 } from "@sphereon/ssi-sdk.core";
63
64
  import { ConnectionType, CorrelationIdentifierType, CredentialCorrelationType, CredentialRole, ensureRawDocument, IdentityOrigin } from "@sphereon/ssi-sdk.data-store";
64
65
  import { CredentialMapper as CredentialMapper2, JoseSignatureAlgorithm as JoseSignatureAlgorithm2, Loggers, parseDid } from "@sphereon/ssi-types";
65
66
  import { asArray as asArray2, computeEntryHash } from "@veramo/utils";
@@ -75,18 +76,18 @@ import i18n from "i18n-js";
75
76
  import memoize from "lodash.memoize";
76
77
 
77
78
  // src/types/IOID4VCIHolder.ts
78
- var OID4VCIHolderEvent = /* @__PURE__ */ (function(OID4VCIHolderEvent2) {
79
+ var OID4VCIHolderEvent = /* @__PURE__ */ function(OID4VCIHolderEvent2) {
79
80
  OID4VCIHolderEvent2["CONTACT_IDENTITY_CREATED"] = "contact_identity_created";
80
81
  OID4VCIHolderEvent2["CREDENTIAL_STORED"] = "credential_stored";
81
82
  OID4VCIHolderEvent2["IDENTIFIER_CREATED"] = "identifier_created";
82
83
  return OID4VCIHolderEvent2;
83
- })({});
84
- var SupportedLanguage = /* @__PURE__ */ (function(SupportedLanguage2) {
84
+ }({});
85
+ var SupportedLanguage = /* @__PURE__ */ function(SupportedLanguage2) {
85
86
  SupportedLanguage2["ENGLISH"] = "en";
86
87
  SupportedLanguage2["DUTCH"] = "nl";
87
88
  return SupportedLanguage2;
88
- })({});
89
- var OID4VCIMachineStates = /* @__PURE__ */ (function(OID4VCIMachineStates2) {
89
+ }({});
90
+ var OID4VCIMachineStates = /* @__PURE__ */ function(OID4VCIMachineStates2) {
90
91
  OID4VCIMachineStates2["start"] = "start";
91
92
  OID4VCIMachineStates2["createCredentialsToSelectFrom"] = "createCredentialsToSelectFrom";
92
93
  OID4VCIMachineStates2["getContact"] = "getContact";
@@ -117,18 +118,18 @@ var OID4VCIMachineStates = /* @__PURE__ */ (function(OID4VCIMachineStates2) {
117
118
  OID4VCIMachineStates2["error"] = "error";
118
119
  OID4VCIMachineStates2["done"] = "done";
119
120
  return OID4VCIMachineStates2;
120
- })({});
121
- var OID4VCIMachineAddContactStates = /* @__PURE__ */ (function(OID4VCIMachineAddContactStates2) {
121
+ }({});
122
+ var OID4VCIMachineAddContactStates = /* @__PURE__ */ function(OID4VCIMachineAddContactStates2) {
122
123
  OID4VCIMachineAddContactStates2["idle"] = "idle";
123
124
  OID4VCIMachineAddContactStates2["next"] = "next";
124
125
  return OID4VCIMachineAddContactStates2;
125
- })({});
126
- var OID4VCIMachineVerifyPinStates = /* @__PURE__ */ (function(OID4VCIMachineVerifyPinStates2) {
126
+ }({});
127
+ var OID4VCIMachineVerifyPinStates = /* @__PURE__ */ function(OID4VCIMachineVerifyPinStates2) {
127
128
  OID4VCIMachineVerifyPinStates2["idle"] = "idle";
128
129
  OID4VCIMachineVerifyPinStates2["next"] = "next";
129
130
  return OID4VCIMachineVerifyPinStates2;
130
- })({});
131
- var OID4VCIMachineEvents = /* @__PURE__ */ (function(OID4VCIMachineEvents2) {
131
+ }({});
132
+ var OID4VCIMachineEvents = /* @__PURE__ */ function(OID4VCIMachineEvents2) {
132
133
  OID4VCIMachineEvents2["NEXT"] = "NEXT";
133
134
  OID4VCIMachineEvents2["PREVIOUS"] = "PREVIOUS";
134
135
  OID4VCIMachineEvents2["DECLINE"] = "DECLINE";
@@ -141,14 +142,15 @@ var OID4VCIMachineEvents = /* @__PURE__ */ (function(OID4VCIMachineEvents2) {
141
142
  OID4VCIMachineEvents2["INVOKED_AUTHORIZATION_CODE_REQUEST"] = "INVOKED_AUTHORIZATION_CODE_REQUEST";
142
143
  OID4VCIMachineEvents2["PROVIDE_AUTHORIZATION_CODE_RESPONSE"] = "PROVIDE_AUTHORIZATION_CODE_RESPONSE";
143
144
  return OID4VCIMachineEvents2;
144
- })({});
145
- var OID4VCIMachineGuards = /* @__PURE__ */ (function(OID4VCIMachineGuards2) {
145
+ }({});
146
+ var OID4VCIMachineGuards = /* @__PURE__ */ function(OID4VCIMachineGuards2) {
146
147
  OID4VCIMachineGuards2["hasContactGuard"] = "oid4vciHasContactGuard";
147
148
  OID4VCIMachineGuards2["hasNoContactGuard"] = "oid4vciHasNoContactGuard";
148
149
  OID4VCIMachineGuards2["credentialsToSelectRequiredGuard"] = "oid4vciCredentialsToSelectRequiredGuard";
149
150
  OID4VCIMachineGuards2["requirePinGuard"] = "oid4vciRequirePinGuard";
150
151
  OID4VCIMachineGuards2["requireAuthorizationGuard"] = "oid4vciRequireAuthorizationGuard";
151
152
  OID4VCIMachineGuards2["noAuthorizationGuard"] = "oid4vciNoAuthorizationGuard";
153
+ OID4VCIMachineGuards2["hasNonceEndpointGuard"] = "oid4vciHasNonceEndpointGuard ";
152
154
  OID4VCIMachineGuards2["hasAuthorizationResponse"] = "oid4vciHasAuthorizationResponse";
153
155
  OID4VCIMachineGuards2["hasNoContactIdentityGuard"] = "oid4vciHasNoContactIdentityGuard";
154
156
  OID4VCIMachineGuards2["verificationCodeGuard"] = "oid4vciVerificationCodeGuard";
@@ -158,8 +160,8 @@ var OID4VCIMachineGuards = /* @__PURE__ */ (function(OID4VCIMachineGuards2) {
158
160
  OID4VCIMachineGuards2["contactHasLowTrustGuard"] = "oid4vciContactHasLowTrustGuard";
159
161
  OID4VCIMachineGuards2["isFirstPartyApplication"] = "oid4vciIsFirstPartyApplication";
160
162
  return OID4VCIMachineGuards2;
161
- })({});
162
- var OID4VCIMachineServices = /* @__PURE__ */ (function(OID4VCIMachineServices2) {
163
+ }({});
164
+ var OID4VCIMachineServices = /* @__PURE__ */ function(OID4VCIMachineServices2) {
163
165
  OID4VCIMachineServices2["start"] = "start";
164
166
  OID4VCIMachineServices2["getContact"] = "getContact";
165
167
  OID4VCIMachineServices2["getFederationTrust"] = "getFederationTrust";
@@ -174,17 +176,17 @@ var OID4VCIMachineServices = /* @__PURE__ */ (function(OID4VCIMachineServices2)
174
176
  OID4VCIMachineServices2["storeCredentials"] = "storeCredentials";
175
177
  OID4VCIMachineServices2["startFirstPartApplicationFlow"] = "startFirstPartApplicationFlow";
176
178
  return OID4VCIMachineServices2;
177
- })({});
178
- var RequestType = /* @__PURE__ */ (function(RequestType2) {
179
+ }({});
180
+ var RequestType = /* @__PURE__ */ function(RequestType2) {
179
181
  RequestType2["OPENID_INITIATE_ISSUANCE"] = "openid-initiate-issuance";
180
182
  RequestType2["OPENID_CREDENTIAL_OFFER"] = "openid-credential-offer";
181
183
  RequestType2["URL"] = "URL";
182
184
  return RequestType2;
183
- })({});
184
- var IdentifierAliasEnum = /* @__PURE__ */ (function(IdentifierAliasEnum2) {
185
+ }({});
186
+ var IdentifierAliasEnum = /* @__PURE__ */ function(IdentifierAliasEnum2) {
185
187
  IdentifierAliasEnum2["PRIMARY"] = "primary";
186
188
  return IdentifierAliasEnum2;
187
- })({});
189
+ }({});
188
190
 
189
191
  // src/localization/Localization.ts
190
192
  var Localization = class Localization2 {
@@ -226,7 +228,7 @@ var Localization = class Localization2 {
226
228
  var translate = Localization.translate;
227
229
 
228
230
  // src/types/FirstPartyMachine.ts
229
- var FirstPartyMachineStateTypes = /* @__PURE__ */ (function(FirstPartyMachineStateTypes2) {
231
+ var FirstPartyMachineStateTypes = /* @__PURE__ */ function(FirstPartyMachineStateTypes2) {
230
232
  FirstPartyMachineStateTypes2["sendAuthorizationChallengeRequest"] = "sendAuthorizationChallengeRequest";
231
233
  FirstPartyMachineStateTypes2["sendAuthorizationResponse"] = "sendAuthorizationResponse";
232
234
  FirstPartyMachineStateTypes2["selectCredentials"] = "selectCredentials";
@@ -237,21 +239,21 @@ var FirstPartyMachineStateTypes = /* @__PURE__ */ (function(FirstPartyMachineSta
237
239
  FirstPartyMachineStateTypes2["aborted"] = "aborted";
238
240
  FirstPartyMachineStateTypes2["declined"] = "declined";
239
241
  return FirstPartyMachineStateTypes2;
240
- })({});
241
- var FirstPartyMachineServices = /* @__PURE__ */ (function(FirstPartyMachineServices2) {
242
+ }({});
243
+ var FirstPartyMachineServices = /* @__PURE__ */ function(FirstPartyMachineServices2) {
242
244
  FirstPartyMachineServices2["sendAuthorizationChallengeRequest"] = "sendAuthorizationChallengeRequest";
243
245
  FirstPartyMachineServices2["sendAuthorizationResponse"] = "sendAuthorizationResponse";
244
246
  FirstPartyMachineServices2["createConfig"] = "createConfig";
245
247
  FirstPartyMachineServices2["getSiopRequest"] = "getSiopRequest";
246
248
  return FirstPartyMachineServices2;
247
- })({});
248
- var FirstPartyMachineEvents = /* @__PURE__ */ (function(FirstPartyMachineEvents2) {
249
+ }({});
250
+ var FirstPartyMachineEvents = /* @__PURE__ */ function(FirstPartyMachineEvents2) {
249
251
  FirstPartyMachineEvents2["NEXT"] = "NEXT";
250
252
  FirstPartyMachineEvents2["PREVIOUS"] = "PREVIOUS";
251
253
  FirstPartyMachineEvents2["DECLINE"] = "DECLINE";
252
254
  FirstPartyMachineEvents2["SET_SELECTED_CREDENTIALS"] = "SET_SELECTED_CREDENTIALS";
253
255
  return FirstPartyMachineEvents2;
254
- })({});
256
+ }({});
255
257
 
256
258
  // src/machines/oid4vciMachine.ts
257
259
  var oid4vciHasNoContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
@@ -976,413 +978,152 @@ var OID4VCIMachine = class {
976
978
 
977
979
  // src/services/OID4VCIHolderService.ts
978
980
  import { LOG } from "@sphereon/oid4vci-client";
979
- import { getSupportedCredentials, getTypesFromCredentialSupported, getTypesFromObject, OpenId4VCIVersion } from "@sphereon/oid4vci-common";
981
+ import { getSupportedCredentials, getTypesFromCredentialSupported, getTypesFromObject } from "@sphereon/oid4vci-common";
980
982
  import { KeyUse } from "@sphereon/ssi-sdk-ext.did-resolver-jwk";
981
983
  import { getOrCreatePrimaryIdentifier, SupportedDidMethodEnum } from "@sphereon/ssi-sdk-ext.did-utils";
982
984
  import { isIIdentifier, isManagedIdentifierDidResult, isManagedIdentifierResult, managedIdentifierToJwk } from "@sphereon/ssi-sdk-ext.identifier-resolution";
983
985
  import { keyTypeFromCryptographicSuite } from "@sphereon/ssi-sdk-ext.key-utils";
986
+ import { defaultHasher } from "@sphereon/ssi-sdk.core";
984
987
  import { CredentialMapper, JoseSignatureAlgorithm, mdocDecodedCredentialToUniformCredential, sdJwtDecodedCredentialToUniformCredential } from "@sphereon/ssi-types";
985
988
  import { asArray } from "@veramo/utils";
986
989
 
987
- // src/mappers/OIDC4VCIBrandingMapper.ts
988
- var oid4vciGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
989
- const { credentialDisplay, issuerCredentialSubject } = args;
990
- return oid4vciCombineDisplayLocalesFrom({
991
- ...issuerCredentialSubject && {
992
- issuerCredentialSubjectLocales: await oid4vciIssuerCredentialSubjectLocalesFrom({
993
- issuerCredentialSubject
994
- })
995
- },
996
- ...credentialDisplay && {
997
- credentialDisplayLocales: await oid4vciCredentialDisplayLocalesFrom({
998
- credentialDisplay
999
- })
1000
- }
990
+ // src/machines/firstPartyMachine.ts
991
+ import { assign as assign2, createMachine as createMachine2, interpret as interpret2 } from "xstate";
992
+ import { AuthorizationChallengeError } from "@sphereon/oid4vci-common";
993
+
994
+ // src/services/FirstPartyMachineServices.ts
995
+ import { OpenID4VCIClient } from "@sphereon/oid4vci-client";
996
+ import { v4 as uuidv4 } from "uuid";
997
+ var sendAuthorizationChallengeRequest = /* @__PURE__ */ __name(async (args) => {
998
+ const { openID4VCIClientState, authSession, presentationDuringIssuanceSession } = args;
999
+ const oid4vciClient = await OpenID4VCIClient.fromState({
1000
+ state: openID4VCIClientState
1001
1001
  });
1002
- }, "oid4vciGetCredentialBrandingFrom");
1003
- var oid4vciCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1004
- const { credentialDisplay } = args;
1005
- return credentialDisplay.reduce((localeDisplays, display) => {
1006
- const localeKey = display.locale || "";
1007
- localeDisplays.set(localeKey, display);
1008
- return localeDisplays;
1009
- }, /* @__PURE__ */ new Map());
1010
- }, "oid4vciCredentialDisplayLocalesFrom");
1011
- var oid4vciIssuerCredentialSubjectLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1012
- const { issuerCredentialSubject } = args;
1013
- const localeClaims = /* @__PURE__ */ new Map();
1014
- const processClaimObject = /* @__PURE__ */ __name((claim, parentKey = "") => {
1015
- Object.entries(claim).forEach(([key, value]) => {
1016
- if (key === "mandatory" || key === "value_type") {
1017
- return;
1018
- }
1019
- if (key === "display" && Array.isArray(value)) {
1020
- value.forEach(({ name, locale = "" }) => {
1021
- if (!name) {
1022
- return;
1023
- }
1024
- if (!localeClaims.has(locale)) {
1025
- localeClaims.set(locale, []);
1026
- }
1027
- localeClaims.get(locale).push({
1028
- key: parentKey,
1029
- name
1030
- });
1031
- });
1032
- } else if (typeof value === "object" && value !== null) {
1033
- processClaimObject(value, parentKey ? `${parentKey}.${key}` : key);
1034
- }
1035
- });
1036
- }, "processClaimObject");
1037
- processClaimObject(issuerCredentialSubject);
1038
- return localeClaims;
1039
- }, "oid4vciIssuerCredentialSubjectLocalesFrom");
1040
- var oid4vciCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1041
- const { credentialDisplay } = args;
1042
- return {
1043
- ...credentialDisplay.name && {
1044
- alias: credentialDisplay.name
1045
- },
1046
- ...credentialDisplay.locale && {
1047
- locale: credentialDisplay.locale
1048
- },
1049
- ...credentialDisplay.logo && {
1050
- logo: {
1051
- ...(credentialDisplay.logo.url || credentialDisplay.logo.uri) && {
1052
- uri: credentialDisplay.logo?.url ?? credentialDisplay.logo.uri
1053
- },
1054
- ...credentialDisplay.logo.alt_text && {
1055
- alt: credentialDisplay.logo?.alt_text
1056
- }
1057
- }
1002
+ return oid4vciClient.acquireAuthorizationChallengeCode({
1003
+ clientId: oid4vciClient.clientId ?? uuidv4(),
1004
+ ...authSession && {
1005
+ authSession
1058
1006
  },
1059
- ...credentialDisplay.description && {
1060
- description: credentialDisplay.description
1007
+ ...!authSession && openID4VCIClientState.credentialOffer?.preAuthorizedCode && {
1008
+ issuerState: openID4VCIClientState.credentialOffer?.preAuthorizedCode
1061
1009
  },
1062
- ...credentialDisplay.text_color && {
1063
- text: {
1064
- color: credentialDisplay.text_color
1065
- }
1010
+ ...!authSession && openID4VCIClientState.credentialOffer?.issuerState && {
1011
+ issuerState: openID4VCIClientState.credentialOffer?.issuerState
1066
1012
  },
1067
- ...(credentialDisplay.background_image || credentialDisplay.background_color) && {
1068
- background: {
1069
- ...credentialDisplay.background_image && {
1070
- image: {
1071
- ...(credentialDisplay.background_image.url || credentialDisplay.background_image.uri) && {
1072
- uri: credentialDisplay.background_image?.url ?? credentialDisplay.background_image.uri
1073
- },
1074
- ...credentialDisplay.background_image.alt_text && {
1075
- alt: credentialDisplay.background_image?.alt_text
1076
- }
1077
- }
1013
+ ...presentationDuringIssuanceSession && {
1014
+ presentationDuringIssuanceSession
1015
+ }
1016
+ });
1017
+ }, "sendAuthorizationChallengeRequest");
1018
+ var createConfig = /* @__PURE__ */ __name(async (args, context) => {
1019
+ const { presentationUri } = args;
1020
+ if (!presentationUri) {
1021
+ return Promise.reject(Error("Missing presentation uri in context"));
1022
+ }
1023
+ return context.agent.siopCreateConfig({
1024
+ url: presentationUri
1025
+ });
1026
+ }, "createConfig");
1027
+ var getSiopRequest = /* @__PURE__ */ __name(async (args, context) => {
1028
+ const { didAuthConfig, presentationUri } = args;
1029
+ if (presentationUri === void 0) {
1030
+ return Promise.reject(Error("Missing presentation uri in context"));
1031
+ }
1032
+ if (didAuthConfig === void 0) {
1033
+ return Promise.reject(Error("Missing did auth config in context"));
1034
+ }
1035
+ return context.agent.siopGetSiopRequest({
1036
+ didAuthConfig,
1037
+ url: presentationUri
1038
+ });
1039
+ }, "getSiopRequest");
1040
+ var sendAuthorizationResponse = /* @__PURE__ */ __name(async (args, context) => {
1041
+ const { didAuthConfig, authorizationRequestData, selectedCredentials } = args;
1042
+ const responseData = await context.agent.siopSendResponse({
1043
+ authorizationRequestData,
1044
+ selectedCredentials,
1045
+ didAuthConfig,
1046
+ isFirstParty: true
1047
+ });
1048
+ return responseData.body.presentation_during_issuance_session;
1049
+ }, "sendAuthorizationResponse");
1050
+
1051
+ // src/machines/firstPartyMachine.ts
1052
+ var firstPartyMachineStates = {
1053
+ [FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest]: {
1054
+ id: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1055
+ invoke: {
1056
+ src: FirstPartyMachineServices.sendAuthorizationChallengeRequest,
1057
+ onDone: {
1058
+ target: FirstPartyMachineStateTypes.done,
1059
+ actions: assign2({
1060
+ authorizationCodeResponse: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationCodeResponse")
1061
+ })
1062
+ },
1063
+ onError: [
1064
+ {
1065
+ target: FirstPartyMachineStateTypes.createConfig,
1066
+ cond: /* @__PURE__ */ __name((_ctx, _event) => _event.data.error === AuthorizationChallengeError.insufficient_authorization, "cond"),
1067
+ actions: assign2({
1068
+ authSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data.auth_session, "authSession"),
1069
+ presentationUri: /* @__PURE__ */ __name((_ctx, _event) => _event.data.presentation, "presentationUri")
1070
+ })
1078
1071
  },
1079
- ...credentialDisplay.background_color && {
1080
- color: credentialDisplay.background_color
1072
+ {
1073
+ target: FirstPartyMachineStateTypes.error,
1074
+ actions: assign2({
1075
+ error: /* @__PURE__ */ __name((_ctx, _event) => ({
1076
+ title: translate("oid4vci_machine_send_authorization_challenge_request_error_title"),
1077
+ message: _event.data.message,
1078
+ stack: _event.data.stack
1079
+ }), "error")
1080
+ })
1081
1081
  }
1082
+ ]
1083
+ }
1084
+ },
1085
+ [FirstPartyMachineStateTypes.createConfig]: {
1086
+ id: FirstPartyMachineStateTypes.createConfig,
1087
+ invoke: {
1088
+ src: FirstPartyMachineServices.createConfig,
1089
+ onDone: {
1090
+ target: FirstPartyMachineStateTypes.getSiopRequest,
1091
+ actions: assign2({
1092
+ didAuthConfig: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "didAuthConfig")
1093
+ })
1094
+ },
1095
+ onError: {
1096
+ target: FirstPartyMachineStateTypes.error,
1097
+ actions: assign2({
1098
+ error: /* @__PURE__ */ __name((_ctx, _event) => ({
1099
+ title: translate("oid4vci_machine_create_config_error_title"),
1100
+ message: _event.data.message,
1101
+ stack: _event.data.stack
1102
+ }), "error")
1103
+ })
1082
1104
  }
1083
1105
  }
1084
- };
1085
- }, "oid4vciCredentialLocaleBrandingFrom");
1086
- var oid4vciCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1087
- const { credentialDisplayLocales = /* @__PURE__ */ new Map(), issuerCredentialSubjectLocales = /* @__PURE__ */ new Map() } = args;
1088
- const locales = Array.from(/* @__PURE__ */ new Set([
1089
- ...issuerCredentialSubjectLocales.keys(),
1090
- ...credentialDisplayLocales.keys()
1091
- ]));
1092
- return Promise.all(locales.map(async (locale) => {
1093
- const display = credentialDisplayLocales.get(locale);
1094
- const claims = issuerCredentialSubjectLocales.get(locale);
1095
- return {
1096
- ...display && await oid4vciCredentialLocaleBrandingFrom({
1097
- credentialDisplay: display
1098
- }),
1099
- ...locale.length > 0 && {
1100
- locale
1106
+ },
1107
+ [FirstPartyMachineStateTypes.getSiopRequest]: {
1108
+ id: FirstPartyMachineStateTypes.getSiopRequest,
1109
+ invoke: {
1110
+ src: FirstPartyMachineServices.getSiopRequest,
1111
+ onDone: {
1112
+ target: FirstPartyMachineStateTypes.selectCredentials,
1113
+ actions: assign2({
1114
+ authorizationRequestData: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationRequestData")
1115
+ })
1101
1116
  },
1102
- claims
1103
- };
1104
- }));
1105
- }, "oid4vciCombineDisplayLocalesFrom");
1106
- var sdJwtGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1107
- const { credentialDisplay, claimsMetadata } = args;
1108
- return sdJwtCombineDisplayLocalesFrom({
1109
- ...claimsMetadata && {
1110
- claimsMetadata: await sdJwtCredentialClaimLocalesFrom({
1111
- claimsMetadata
1112
- })
1113
- },
1114
- ...credentialDisplay && {
1115
- credentialDisplayLocales: await sdJwtCredentialDisplayLocalesFrom({
1116
- credentialDisplay
1117
- })
1118
- }
1119
- });
1120
- }, "sdJwtGetCredentialBrandingFrom");
1121
- var sdJwtCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1122
- const { credentialDisplay } = args;
1123
- return credentialDisplay.reduce((localeDisplays, display) => {
1124
- const localeKey = display.lang || "";
1125
- localeDisplays.set(localeKey, display);
1126
- return localeDisplays;
1127
- }, /* @__PURE__ */ new Map());
1128
- }, "sdJwtCredentialDisplayLocalesFrom");
1129
- var sdJwtCredentialClaimLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1130
- const { claimsMetadata } = args;
1131
- const localeClaims = /* @__PURE__ */ new Map();
1132
- claimsMetadata.forEach((claim) => {
1133
- claim.display?.forEach((display) => {
1134
- const { lang = "", label } = display;
1135
- const key = claim.path.map((value) => String(value)).join(".");
1136
- if (!localeClaims.has(lang)) {
1137
- localeClaims.set(lang, []);
1138
- }
1139
- localeClaims.get(lang).push({
1140
- key,
1141
- name: label
1142
- });
1143
- });
1144
- });
1145
- return localeClaims;
1146
- }, "sdJwtCredentialClaimLocalesFrom");
1147
- var sdJwtCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1148
- const { credentialDisplay } = args;
1149
- return {
1150
- ...credentialDisplay.name && {
1151
- alias: credentialDisplay.name
1152
- },
1153
- ...credentialDisplay.lang && {
1154
- locale: credentialDisplay.lang
1155
- },
1156
- ...credentialDisplay.rendering?.simple?.logo && {
1157
- logo: {
1158
- ...credentialDisplay.rendering.simple.logo.uri && {
1159
- uri: credentialDisplay.rendering.simple.logo.uri
1160
- },
1161
- ...credentialDisplay.rendering.simple.logo.alt_text && {
1162
- alt: credentialDisplay.rendering.simple.logo.alt_text
1163
- }
1164
- }
1165
- },
1166
- ...credentialDisplay.description && {
1167
- description: credentialDisplay.description
1168
- },
1169
- ...credentialDisplay.rendering?.simple?.text_color && {
1170
- text: {
1171
- color: credentialDisplay.rendering.simple.text_color
1172
- }
1173
- },
1174
- ...credentialDisplay.rendering?.simple?.background_color && {
1175
- background: {
1176
- color: credentialDisplay.rendering.simple.background_color
1177
- }
1178
- }
1179
- };
1180
- }, "sdJwtCredentialLocaleBrandingFrom");
1181
- var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1182
- const { credentialDisplayLocales = /* @__PURE__ */ new Map(), claimsMetadata = /* @__PURE__ */ new Map() } = args;
1183
- const locales = Array.from(/* @__PURE__ */ new Set([
1184
- ...claimsMetadata.keys(),
1185
- ...credentialDisplayLocales.keys()
1186
- ]));
1187
- return Promise.all(locales.map(async (locale) => {
1188
- const display = credentialDisplayLocales.get(locale);
1189
- const claims = claimsMetadata.get(locale);
1190
- return {
1191
- ...display && await sdJwtCredentialLocaleBrandingFrom({
1192
- credentialDisplay: display
1193
- }),
1194
- ...locale.length > 0 && {
1195
- locale
1196
- },
1197
- claims
1198
- };
1199
- }));
1200
- }, "sdJwtCombineDisplayLocalesFrom");
1201
- var issuerLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1202
- const { issuerDisplay, dynamicRegistrationClientMetadata } = args;
1203
- return {
1204
- ...dynamicRegistrationClientMetadata?.client_name && {
1205
- alias: dynamicRegistrationClientMetadata.client_name
1206
- },
1207
- ...issuerDisplay.name && {
1208
- alias: issuerDisplay.name
1209
- },
1210
- ...issuerDisplay.locale && {
1211
- locale: issuerDisplay.locale
1212
- },
1213
- ...(issuerDisplay.logo || dynamicRegistrationClientMetadata?.logo_uri) && {
1214
- logo: {
1215
- ...dynamicRegistrationClientMetadata?.logo_uri && {
1216
- uri: dynamicRegistrationClientMetadata?.logo_uri
1217
- },
1218
- ...(issuerDisplay.logo?.url || issuerDisplay.logo?.uri) && {
1219
- uri: issuerDisplay.logo?.url ?? issuerDisplay.logo?.uri
1220
- },
1221
- ...issuerDisplay.logo?.alt_text && {
1222
- alt: issuerDisplay.logo?.alt_text
1223
- }
1224
- }
1225
- },
1226
- ...issuerDisplay.description && {
1227
- description: issuerDisplay.description
1228
- },
1229
- ...issuerDisplay.text_color && {
1230
- text: {
1231
- color: issuerDisplay.text_color
1232
- }
1233
- },
1234
- ...dynamicRegistrationClientMetadata?.client_uri && {
1235
- clientUri: dynamicRegistrationClientMetadata.client_uri
1236
- },
1237
- ...dynamicRegistrationClientMetadata?.tos_uri && {
1238
- tosUri: dynamicRegistrationClientMetadata.tos_uri
1239
- },
1240
- ...dynamicRegistrationClientMetadata?.policy_uri && {
1241
- policyUri: dynamicRegistrationClientMetadata.policy_uri
1242
- },
1243
- ...dynamicRegistrationClientMetadata?.contacts && {
1244
- contacts: dynamicRegistrationClientMetadata.contacts
1245
- }
1246
- };
1247
- }, "issuerLocaleBrandingFrom");
1248
-
1249
- // src/machines/firstPartyMachine.ts
1250
- import { assign as assign2, createMachine as createMachine2, interpret as interpret2 } from "xstate";
1251
- import { AuthorizationChallengeError } from "@sphereon/oid4vci-common";
1252
-
1253
- // src/services/FirstPartyMachineServices.ts
1254
- import { OpenID4VCIClient } from "@sphereon/oid4vci-client";
1255
- import { v4 as uuidv4 } from "uuid";
1256
- var sendAuthorizationChallengeRequest = /* @__PURE__ */ __name(async (args) => {
1257
- const { openID4VCIClientState, authSession, presentationDuringIssuanceSession } = args;
1258
- const oid4vciClient = await OpenID4VCIClient.fromState({
1259
- state: openID4VCIClientState
1260
- });
1261
- return oid4vciClient.acquireAuthorizationChallengeCode({
1262
- clientId: oid4vciClient.clientId ?? uuidv4(),
1263
- ...authSession && {
1264
- authSession
1265
- },
1266
- ...!authSession && openID4VCIClientState.credentialOffer?.preAuthorizedCode && {
1267
- issuerState: openID4VCIClientState.credentialOffer?.preAuthorizedCode
1268
- },
1269
- ...!authSession && openID4VCIClientState.credentialOffer?.issuerState && {
1270
- issuerState: openID4VCIClientState.credentialOffer?.issuerState
1271
- },
1272
- ...presentationDuringIssuanceSession && {
1273
- presentationDuringIssuanceSession
1274
- }
1275
- });
1276
- }, "sendAuthorizationChallengeRequest");
1277
- var createConfig = /* @__PURE__ */ __name(async (args, context) => {
1278
- const { presentationUri } = args;
1279
- if (!presentationUri) {
1280
- return Promise.reject(Error("Missing presentation uri in context"));
1281
- }
1282
- return context.agent.siopCreateConfig({
1283
- url: presentationUri
1284
- });
1285
- }, "createConfig");
1286
- var getSiopRequest = /* @__PURE__ */ __name(async (args, context) => {
1287
- const { didAuthConfig, presentationUri } = args;
1288
- if (presentationUri === void 0) {
1289
- return Promise.reject(Error("Missing presentation uri in context"));
1290
- }
1291
- if (didAuthConfig === void 0) {
1292
- return Promise.reject(Error("Missing did auth config in context"));
1293
- }
1294
- return context.agent.siopGetSiopRequest({
1295
- didAuthConfig,
1296
- url: presentationUri
1297
- });
1298
- }, "getSiopRequest");
1299
- var sendAuthorizationResponse = /* @__PURE__ */ __name(async (args, context) => {
1300
- const { didAuthConfig, authorizationRequestData, selectedCredentials } = args;
1301
- const responseData = await context.agent.siopSendResponse({
1302
- authorizationRequestData,
1303
- selectedCredentials,
1304
- didAuthConfig,
1305
- isFirstParty: true
1306
- });
1307
- return responseData.body.presentation_during_issuance_session;
1308
- }, "sendAuthorizationResponse");
1309
-
1310
- // src/machines/firstPartyMachine.ts
1311
- var firstPartyMachineStates = {
1312
- [FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest]: {
1313
- id: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1314
- invoke: {
1315
- src: FirstPartyMachineServices.sendAuthorizationChallengeRequest,
1316
- onDone: {
1317
- target: FirstPartyMachineStateTypes.done,
1318
- actions: assign2({
1319
- authorizationCodeResponse: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationCodeResponse")
1320
- })
1321
- },
1322
- onError: [
1323
- {
1324
- target: FirstPartyMachineStateTypes.createConfig,
1325
- cond: /* @__PURE__ */ __name((_ctx, _event) => _event.data.error === AuthorizationChallengeError.insufficient_authorization, "cond"),
1326
- actions: assign2({
1327
- authSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data.auth_session, "authSession"),
1328
- presentationUri: /* @__PURE__ */ __name((_ctx, _event) => _event.data.presentation, "presentationUri")
1329
- })
1330
- },
1331
- {
1332
- target: FirstPartyMachineStateTypes.error,
1333
- actions: assign2({
1334
- error: /* @__PURE__ */ __name((_ctx, _event) => ({
1335
- title: translate("oid4vci_machine_send_authorization_challenge_request_error_title"),
1336
- message: _event.data.message,
1337
- stack: _event.data.stack
1338
- }), "error")
1339
- })
1340
- }
1341
- ]
1342
- }
1343
- },
1344
- [FirstPartyMachineStateTypes.createConfig]: {
1345
- id: FirstPartyMachineStateTypes.createConfig,
1346
- invoke: {
1347
- src: FirstPartyMachineServices.createConfig,
1348
- onDone: {
1349
- target: FirstPartyMachineStateTypes.getSiopRequest,
1350
- actions: assign2({
1351
- didAuthConfig: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "didAuthConfig")
1352
- })
1353
- },
1354
- onError: {
1355
- target: FirstPartyMachineStateTypes.error,
1356
- actions: assign2({
1357
- error: /* @__PURE__ */ __name((_ctx, _event) => ({
1358
- title: translate("oid4vci_machine_create_config_error_title"),
1359
- message: _event.data.message,
1360
- stack: _event.data.stack
1361
- }), "error")
1362
- })
1363
- }
1364
- }
1365
- },
1366
- [FirstPartyMachineStateTypes.getSiopRequest]: {
1367
- id: FirstPartyMachineStateTypes.getSiopRequest,
1368
- invoke: {
1369
- src: FirstPartyMachineServices.getSiopRequest,
1370
- onDone: {
1371
- target: FirstPartyMachineStateTypes.selectCredentials,
1372
- actions: assign2({
1373
- authorizationRequestData: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationRequestData")
1374
- })
1375
- },
1376
- onError: {
1377
- target: FirstPartyMachineStateTypes.error,
1378
- actions: assign2({
1379
- error: /* @__PURE__ */ __name((_ctx, _event) => ({
1380
- title: translate("siopV2_machine_get_request_error_title"),
1381
- message: _event.data.message,
1382
- stack: _event.data.stack
1383
- }), "error")
1384
- })
1385
- }
1117
+ onError: {
1118
+ target: FirstPartyMachineStateTypes.error,
1119
+ actions: assign2({
1120
+ error: /* @__PURE__ */ __name((_ctx, _event) => ({
1121
+ title: translate("siopV2_machine_get_request_error_title"),
1122
+ message: _event.data.message,
1123
+ stack: _event.data.stack
1124
+ }), "error")
1125
+ })
1126
+ }
1386
1127
  }
1387
1128
  },
1388
1129
  [FirstPartyMachineStateTypes.selectCredentials]: {
@@ -1449,96 +1190,357 @@ var createFirstPartyActivationMachine = /* @__PURE__ */ __name((opts) => {
1449
1190
  contact: opts.contact,
1450
1191
  selectedCredentials: []
1451
1192
  };
1452
- return createMachine2({
1453
- id: opts?.machineId ?? "FirstParty",
1454
- predictableActionArguments: true,
1455
- initial: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1456
- context: initialContext,
1457
- states: firstPartyMachineStates,
1458
- schema: {
1459
- events: {},
1460
- services: {}
1193
+ return createMachine2({
1194
+ id: opts?.machineId ?? "FirstParty",
1195
+ predictableActionArguments: true,
1196
+ initial: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1197
+ context: initialContext,
1198
+ states: firstPartyMachineStates,
1199
+ schema: {
1200
+ events: {},
1201
+ services: {}
1202
+ }
1203
+ });
1204
+ }, "createFirstPartyActivationMachine");
1205
+ var FirstPartyMachine = class _FirstPartyMachine {
1206
+ static {
1207
+ __name(this, "FirstPartyMachine");
1208
+ }
1209
+ static _instance;
1210
+ static hasInstance() {
1211
+ return _FirstPartyMachine._instance !== void 0;
1212
+ }
1213
+ static get instance() {
1214
+ if (!_FirstPartyMachine._instance) {
1215
+ throw Error("Please initialize ESIMActivation machine first");
1216
+ }
1217
+ return _FirstPartyMachine._instance;
1218
+ }
1219
+ static clearInstance(opts) {
1220
+ const { stop } = opts;
1221
+ if (_FirstPartyMachine.hasInstance()) {
1222
+ if (stop) {
1223
+ _FirstPartyMachine.stopInstance();
1224
+ }
1225
+ }
1226
+ _FirstPartyMachine._instance = void 0;
1227
+ }
1228
+ static stopInstance() {
1229
+ if (!_FirstPartyMachine.hasInstance()) {
1230
+ return;
1231
+ }
1232
+ _FirstPartyMachine.instance.stop();
1233
+ _FirstPartyMachine._instance = void 0;
1234
+ }
1235
+ static newInstance(opts) {
1236
+ const { agentContext } = opts;
1237
+ const services = {
1238
+ [FirstPartyMachineServices.sendAuthorizationChallengeRequest]: sendAuthorizationChallengeRequest,
1239
+ [FirstPartyMachineServices.createConfig]: (args) => createConfig(args, agentContext),
1240
+ [FirstPartyMachineServices.getSiopRequest]: (args) => getSiopRequest(args, agentContext),
1241
+ [FirstPartyMachineServices.sendAuthorizationResponse]: (args) => sendAuthorizationResponse(args, agentContext)
1242
+ };
1243
+ const newInst = interpret2(createFirstPartyActivationMachine(opts).withConfig({
1244
+ services: {
1245
+ ...services,
1246
+ ...opts?.services
1247
+ },
1248
+ guards: {
1249
+ ...opts?.guards
1250
+ }
1251
+ }));
1252
+ if (typeof opts?.subscription === "function") {
1253
+ newInst.onTransition(opts.subscription);
1254
+ }
1255
+ if (opts?.requireCustomNavigationHook !== true) {
1256
+ newInst.onTransition((snapshot) => {
1257
+ if (opts?.stateNavigationListener) {
1258
+ void opts.stateNavigationListener(newInst, snapshot);
1259
+ }
1260
+ });
1261
+ }
1262
+ return newInst;
1263
+ }
1264
+ static getInstance(opts) {
1265
+ if (!_FirstPartyMachine._instance) {
1266
+ if (opts?.requireExisting === true) {
1267
+ throw Error(`Existing FirstPartyMachine instance requested, but none was created at this point!`);
1268
+ }
1269
+ _FirstPartyMachine._instance = _FirstPartyMachine.newInstance(opts);
1270
+ }
1271
+ return _FirstPartyMachine._instance;
1272
+ }
1273
+ };
1274
+
1275
+ // src/mappers/OIDC4VCIBrandingMapper.ts
1276
+ var oid4vciGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1277
+ const { credentialDisplay, issuerCredentialSubject } = args;
1278
+ return oid4vciCombineDisplayLocalesFrom({
1279
+ ...issuerCredentialSubject && {
1280
+ issuerCredentialSubjectLocales: await oid4vciIssuerCredentialSubjectLocalesFrom({
1281
+ issuerCredentialSubject
1282
+ })
1283
+ },
1284
+ ...credentialDisplay && {
1285
+ credentialDisplayLocales: await oid4vciCredentialDisplayLocalesFrom({
1286
+ credentialDisplay
1287
+ })
1288
+ }
1289
+ });
1290
+ }, "oid4vciGetCredentialBrandingFrom");
1291
+ var oid4vciCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1292
+ const { credentialDisplay } = args;
1293
+ return credentialDisplay.reduce((localeDisplays, display) => {
1294
+ const localeKey = display.locale || "";
1295
+ localeDisplays.set(localeKey, display);
1296
+ return localeDisplays;
1297
+ }, /* @__PURE__ */ new Map());
1298
+ }, "oid4vciCredentialDisplayLocalesFrom");
1299
+ var oid4vciIssuerCredentialSubjectLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1300
+ const { issuerCredentialSubject } = args;
1301
+ const localeClaims = /* @__PURE__ */ new Map();
1302
+ const processClaimObject = /* @__PURE__ */ __name((claim, parentKey = "") => {
1303
+ Object.entries(claim).forEach(([key, value]) => {
1304
+ if (key === "mandatory" || key === "value_type") {
1305
+ return;
1306
+ }
1307
+ if (key === "display" && Array.isArray(value)) {
1308
+ value.forEach(({ name, locale = "" }) => {
1309
+ if (!name) {
1310
+ return;
1311
+ }
1312
+ if (!localeClaims.has(locale)) {
1313
+ localeClaims.set(locale, []);
1314
+ }
1315
+ localeClaims.get(locale).push({
1316
+ key: parentKey,
1317
+ name
1318
+ });
1319
+ });
1320
+ } else if (typeof value === "object" && value !== null) {
1321
+ processClaimObject(value, parentKey ? `${parentKey}.${key}` : key);
1322
+ }
1323
+ });
1324
+ }, "processClaimObject");
1325
+ processClaimObject(issuerCredentialSubject);
1326
+ return localeClaims;
1327
+ }, "oid4vciIssuerCredentialSubjectLocalesFrom");
1328
+ var oid4vciCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1329
+ const { credentialDisplay } = args;
1330
+ return {
1331
+ ...credentialDisplay.name && {
1332
+ alias: credentialDisplay.name
1333
+ },
1334
+ ...credentialDisplay.locale && {
1335
+ locale: credentialDisplay.locale
1336
+ },
1337
+ ...credentialDisplay.logo && {
1338
+ logo: {
1339
+ ...(credentialDisplay.logo.url || credentialDisplay.logo.uri) && {
1340
+ uri: credentialDisplay.logo?.url ?? credentialDisplay.logo.uri
1341
+ },
1342
+ ...credentialDisplay.logo.alt_text && {
1343
+ alt: credentialDisplay.logo?.alt_text
1344
+ }
1345
+ }
1346
+ },
1347
+ ...credentialDisplay.description && {
1348
+ description: credentialDisplay.description
1349
+ },
1350
+ ...credentialDisplay.text_color && {
1351
+ text: {
1352
+ color: credentialDisplay.text_color
1353
+ }
1354
+ },
1355
+ ...(credentialDisplay.background_image || credentialDisplay.background_color) && {
1356
+ background: {
1357
+ ...credentialDisplay.background_image && {
1358
+ image: {
1359
+ ...(credentialDisplay.background_image.url || credentialDisplay.background_image.uri) && {
1360
+ uri: credentialDisplay.background_image?.url ?? credentialDisplay.background_image.uri
1361
+ },
1362
+ ...credentialDisplay.background_image.alt_text && {
1363
+ alt: credentialDisplay.background_image?.alt_text
1364
+ }
1365
+ }
1366
+ },
1367
+ ...credentialDisplay.background_color && {
1368
+ color: credentialDisplay.background_color
1369
+ }
1370
+ }
1371
+ }
1372
+ };
1373
+ }, "oid4vciCredentialLocaleBrandingFrom");
1374
+ var oid4vciCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1375
+ const { credentialDisplayLocales = /* @__PURE__ */ new Map(), issuerCredentialSubjectLocales = /* @__PURE__ */ new Map() } = args;
1376
+ const locales = Array.from(/* @__PURE__ */ new Set([
1377
+ ...issuerCredentialSubjectLocales.keys(),
1378
+ ...credentialDisplayLocales.keys()
1379
+ ]));
1380
+ return Promise.all(locales.map(async (locale) => {
1381
+ const display = credentialDisplayLocales.get(locale);
1382
+ const claims = issuerCredentialSubjectLocales.get(locale);
1383
+ return {
1384
+ ...display && await oid4vciCredentialLocaleBrandingFrom({
1385
+ credentialDisplay: display
1386
+ }),
1387
+ ...locale.length > 0 && {
1388
+ locale
1389
+ },
1390
+ claims
1391
+ };
1392
+ }));
1393
+ }, "oid4vciCombineDisplayLocalesFrom");
1394
+ var sdJwtGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1395
+ const { credentialDisplay, claimsMetadata } = args;
1396
+ return sdJwtCombineDisplayLocalesFrom({
1397
+ ...claimsMetadata && {
1398
+ claimsMetadata: await sdJwtCredentialClaimLocalesFrom({
1399
+ claimsMetadata
1400
+ })
1401
+ },
1402
+ ...credentialDisplay && {
1403
+ credentialDisplayLocales: await sdJwtCredentialDisplayLocalesFrom({
1404
+ credentialDisplay
1405
+ })
1461
1406
  }
1462
1407
  });
1463
- }, "createFirstPartyActivationMachine");
1464
- var FirstPartyMachine = class _FirstPartyMachine {
1465
- static {
1466
- __name(this, "FirstPartyMachine");
1467
- }
1468
- static _instance;
1469
- static hasInstance() {
1470
- return _FirstPartyMachine._instance !== void 0;
1471
- }
1472
- static get instance() {
1473
- if (!_FirstPartyMachine._instance) {
1474
- throw Error("Please initialize ESIMActivation machine first");
1475
- }
1476
- return _FirstPartyMachine._instance;
1477
- }
1478
- static clearInstance(opts) {
1479
- const { stop } = opts;
1480
- if (_FirstPartyMachine.hasInstance()) {
1481
- if (stop) {
1482
- _FirstPartyMachine.stopInstance();
1408
+ }, "sdJwtGetCredentialBrandingFrom");
1409
+ var sdJwtCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1410
+ const { credentialDisplay } = args;
1411
+ return credentialDisplay.reduce((localeDisplays, display) => {
1412
+ const localeKey = display.lang || "";
1413
+ localeDisplays.set(localeKey, display);
1414
+ return localeDisplays;
1415
+ }, /* @__PURE__ */ new Map());
1416
+ }, "sdJwtCredentialDisplayLocalesFrom");
1417
+ var sdJwtCredentialClaimLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1418
+ const { claimsMetadata } = args;
1419
+ const localeClaims = /* @__PURE__ */ new Map();
1420
+ claimsMetadata.forEach((claim) => {
1421
+ claim.display?.forEach((display) => {
1422
+ const { lang = "", label } = display;
1423
+ const key = claim.path.map((value) => String(value)).join(".");
1424
+ if (!localeClaims.has(lang)) {
1425
+ localeClaims.set(lang, []);
1483
1426
  }
1484
- }
1485
- _FirstPartyMachine._instance = void 0;
1486
- }
1487
- static stopInstance() {
1488
- if (!_FirstPartyMachine.hasInstance()) {
1489
- return;
1490
- }
1491
- _FirstPartyMachine.instance.stop();
1492
- _FirstPartyMachine._instance = void 0;
1493
- }
1494
- static newInstance(opts) {
1495
- const { agentContext } = opts;
1496
- const services = {
1497
- [FirstPartyMachineServices.sendAuthorizationChallengeRequest]: sendAuthorizationChallengeRequest,
1498
- [FirstPartyMachineServices.createConfig]: (args) => createConfig(args, agentContext),
1499
- [FirstPartyMachineServices.getSiopRequest]: (args) => getSiopRequest(args, agentContext),
1500
- [FirstPartyMachineServices.sendAuthorizationResponse]: (args) => sendAuthorizationResponse(args, agentContext)
1501
- };
1502
- const newInst = interpret2(createFirstPartyActivationMachine(opts).withConfig({
1503
- services: {
1504
- ...services,
1505
- ...opts?.services
1506
- },
1507
- guards: {
1508
- ...opts?.guards
1427
+ localeClaims.get(lang).push({
1428
+ key,
1429
+ name: label
1430
+ });
1431
+ });
1432
+ });
1433
+ return localeClaims;
1434
+ }, "sdJwtCredentialClaimLocalesFrom");
1435
+ var sdJwtCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1436
+ const { credentialDisplay } = args;
1437
+ return {
1438
+ ...credentialDisplay.name && {
1439
+ alias: credentialDisplay.name
1440
+ },
1441
+ ...credentialDisplay.lang && {
1442
+ locale: credentialDisplay.lang
1443
+ },
1444
+ ...credentialDisplay.rendering?.simple?.logo && {
1445
+ logo: {
1446
+ ...credentialDisplay.rendering.simple.logo.uri && {
1447
+ uri: credentialDisplay.rendering.simple.logo.uri
1448
+ },
1449
+ ...credentialDisplay.rendering.simple.logo.alt_text && {
1450
+ alt: credentialDisplay.rendering.simple.logo.alt_text
1451
+ }
1452
+ }
1453
+ },
1454
+ ...credentialDisplay.description && {
1455
+ description: credentialDisplay.description
1456
+ },
1457
+ ...credentialDisplay.rendering?.simple?.text_color && {
1458
+ text: {
1459
+ color: credentialDisplay.rendering.simple.text_color
1460
+ }
1461
+ },
1462
+ ...credentialDisplay.rendering?.simple?.background_color && {
1463
+ background: {
1464
+ color: credentialDisplay.rendering.simple.background_color
1509
1465
  }
1510
- }));
1511
- if (typeof opts?.subscription === "function") {
1512
- newInst.onTransition(opts.subscription);
1513
1466
  }
1514
- if (opts?.requireCustomNavigationHook !== true) {
1515
- newInst.onTransition((snapshot) => {
1516
- if (opts?.stateNavigationListener) {
1517
- void opts.stateNavigationListener(newInst, snapshot);
1467
+ };
1468
+ }, "sdJwtCredentialLocaleBrandingFrom");
1469
+ var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1470
+ const { credentialDisplayLocales = /* @__PURE__ */ new Map(), claimsMetadata = /* @__PURE__ */ new Map() } = args;
1471
+ const locales = Array.from(/* @__PURE__ */ new Set([
1472
+ ...claimsMetadata.keys(),
1473
+ ...credentialDisplayLocales.keys()
1474
+ ]));
1475
+ return Promise.all(locales.map(async (locale) => {
1476
+ const display = credentialDisplayLocales.get(locale);
1477
+ const claims = claimsMetadata.get(locale);
1478
+ return {
1479
+ ...display && await sdJwtCredentialLocaleBrandingFrom({
1480
+ credentialDisplay: display
1481
+ }),
1482
+ ...locale.length > 0 && {
1483
+ locale
1484
+ },
1485
+ claims
1486
+ };
1487
+ }));
1488
+ }, "sdJwtCombineDisplayLocalesFrom");
1489
+ var issuerLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1490
+ const { issuerDisplay, dynamicRegistrationClientMetadata } = args;
1491
+ return {
1492
+ ...dynamicRegistrationClientMetadata?.client_name && {
1493
+ alias: dynamicRegistrationClientMetadata.client_name
1494
+ },
1495
+ ...issuerDisplay.name && {
1496
+ alias: issuerDisplay.name
1497
+ },
1498
+ ...issuerDisplay.locale && {
1499
+ locale: issuerDisplay.locale
1500
+ },
1501
+ ...(issuerDisplay.logo || dynamicRegistrationClientMetadata?.logo_uri) && {
1502
+ logo: {
1503
+ ...dynamicRegistrationClientMetadata?.logo_uri && {
1504
+ uri: dynamicRegistrationClientMetadata?.logo_uri
1505
+ },
1506
+ ...(issuerDisplay.logo?.url || issuerDisplay.logo?.uri) && {
1507
+ uri: issuerDisplay.logo?.url ?? issuerDisplay.logo?.uri
1508
+ },
1509
+ ...issuerDisplay.logo?.alt_text && {
1510
+ alt: issuerDisplay.logo?.alt_text
1518
1511
  }
1519
- });
1520
- }
1521
- return newInst;
1522
- }
1523
- static getInstance(opts) {
1524
- if (!_FirstPartyMachine._instance) {
1525
- if (opts?.requireExisting === true) {
1526
- throw Error(`Existing FirstPartyMachine instance requested, but none was created at this point!`);
1527
1512
  }
1528
- _FirstPartyMachine._instance = _FirstPartyMachine.newInstance(opts);
1513
+ },
1514
+ ...issuerDisplay.description && {
1515
+ description: issuerDisplay.description
1516
+ },
1517
+ ...issuerDisplay.text_color && {
1518
+ text: {
1519
+ color: issuerDisplay.text_color
1520
+ }
1521
+ },
1522
+ ...dynamicRegistrationClientMetadata?.client_uri && {
1523
+ clientUri: dynamicRegistrationClientMetadata.client_uri
1524
+ },
1525
+ ...dynamicRegistrationClientMetadata?.tos_uri && {
1526
+ tosUri: dynamicRegistrationClientMetadata.tos_uri
1527
+ },
1528
+ ...dynamicRegistrationClientMetadata?.policy_uri && {
1529
+ policyUri: dynamicRegistrationClientMetadata.policy_uri
1530
+ },
1531
+ ...dynamicRegistrationClientMetadata?.contacts && {
1532
+ contacts: dynamicRegistrationClientMetadata.contacts
1529
1533
  }
1530
- return _FirstPartyMachine._instance;
1531
- }
1532
- };
1534
+ };
1535
+ }, "issuerLocaleBrandingFrom");
1533
1536
 
1534
1537
  // src/services/OID4VCIHolderService.ts
1535
- import { defaultHasher } from "@sphereon/ssi-sdk.core";
1536
1538
  var getCredentialBranding = /* @__PURE__ */ __name(async (args) => {
1537
1539
  const { credentialsSupported, context } = args;
1538
1540
  const credentialBranding = {};
1539
1541
  await Promise.all(Object.entries(credentialsSupported).map(async ([configId, credentialsConfigSupported]) => {
1540
1542
  let sdJwtTypeMetadata;
1541
- if (credentialsConfigSupported.format === "vc+sd-jwt") {
1543
+ if (credentialsConfigSupported.format === "dc+sd-jwt") {
1542
1544
  const vct = credentialsConfigSupported.vct;
1543
1545
  if (vct.startsWith("http")) {
1544
1546
  try {
@@ -1604,10 +1606,7 @@ var selectCredentialLocaleBranding = /* @__PURE__ */ __name(async (args) => {
1604
1606
  }, "selectCredentialLocaleBranding");
1605
1607
  var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1606
1608
  const { mappedCredential, hasher, onVerifyEBSICredentialIssuer, schemaValidation, context } = args;
1607
- const credential = mappedCredential.credentialToAccept.credentialResponse.credential;
1608
- if (!credential) {
1609
- return Promise.reject(Error("No credential found in credential response"));
1610
- }
1609
+ const credential = extractCredentialFromResponse(mappedCredential.credentialToAccept.credentialResponse);
1611
1610
  const wrappedVC = CredentialMapper.toWrappedVerifiableCredential(credential, {
1612
1611
  hasher: hasher ?? defaultHasher
1613
1612
  });
@@ -1659,11 +1658,7 @@ var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1659
1658
  }, "verifyCredentialToAccept");
1660
1659
  var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1661
1660
  const { credentialToAccept, hasher } = args;
1662
- const credentialResponse = credentialToAccept.credentialResponse;
1663
- const verifiableCredential = credentialResponse.credential;
1664
- if (!verifiableCredential) {
1665
- return Promise.reject(Error("No credential found in credential response"));
1666
- }
1661
+ const verifiableCredential = extractCredentialFromResponse(credentialToAccept.credentialResponse);
1667
1662
  const wrappedVerifiableCredential = CredentialMapper.toWrappedVerifiableCredential(verifiableCredential, {
1668
1663
  hasher
1669
1664
  });
@@ -1683,6 +1678,7 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1683
1678
  uniformVerifiableCredential = wrappedVerifiableCredential.credential;
1684
1679
  }
1685
1680
  const correlationId = typeof uniformVerifiableCredential.issuer === "string" ? uniformVerifiableCredential.issuer : CredentialMapper.isSdJwtDecodedCredential(uniformVerifiableCredential) ? uniformVerifiableCredential.decodedPayload.iss : uniformVerifiableCredential.issuer.id;
1681
+ const credentialResponse = credentialToAccept.credentialResponse;
1686
1682
  return {
1687
1683
  correlationId,
1688
1684
  credentialToAccept,
@@ -1694,6 +1690,18 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1694
1690
  }
1695
1691
  };
1696
1692
  }, "mapCredentialToAccept");
1693
+ var extractCredentialFromResponse = /* @__PURE__ */ __name((credentialResponse) => {
1694
+ let credential;
1695
+ if ("credential" in credentialResponse) {
1696
+ credential = credentialResponse.credential;
1697
+ } else if ("credentials" in credentialResponse && credentialResponse.credentials && Array.isArray(credentialResponse.credentials) && credentialResponse.credentials.length > 0) {
1698
+ credential = credentialResponse.credentials[0].credential;
1699
+ }
1700
+ if (!credential) {
1701
+ throw new Error("No credential found in credential response");
1702
+ }
1703
+ return credential;
1704
+ }, "extractCredentialFromResponse");
1697
1705
  var getIdentifierOpts = /* @__PURE__ */ __name(async (args) => {
1698
1706
  const { issuanceOpt, context } = args;
1699
1707
  const { identifier: identifierArg } = issuanceOpt;
@@ -1802,24 +1810,19 @@ var getCredentialConfigsSupportedBySingleTypeOrId = /* @__PURE__ */ __name(async
1802
1810
  }
1803
1811
  __name(createIdFromTypes, "createIdFromTypes");
1804
1812
  if (configurationId) {
1805
- const allSupported2 = client.getCredentialsSupported(false);
1813
+ const allSupported2 = client.getCredentialsSupported(format);
1806
1814
  return Object.fromEntries(Object.entries(allSupported2).filter(([id, supported]) => id === configurationId || supported.id === configurationId || createIdFromTypes(supported) === configurationId));
1807
1815
  }
1808
- if (!types && !client.credentialOffer) {
1809
- return Promise.reject(Error("openID4VCIClient has no credentialOffer and no types where provided"));
1816
+ if (!client.credentialOffer) {
1817
+ return Promise.reject(Error("openID4VCIClient has no credentialOffer"));
1810
1818
  }
1811
- if (!Array.isArray(format) && client.credentialOffer) {
1812
- if (client.version() > OpenId4VCIVersion.VER_1_0_09 && typeof client.credentialOffer.credential_offer === "object" && "credentials" in client.credentialOffer.credential_offer) {
1813
- format = client.credentialOffer.credential_offer.credentials.filter((cred) => typeof cred !== "string").map((cred) => cred.format);
1814
- if (format?.length === 0) {
1815
- format = void 0;
1816
- }
1817
- }
1819
+ if (!types) {
1820
+ return Promise.reject(Error("openID4VCIClient has no types"));
1818
1821
  }
1819
1822
  const offerSupported = getSupportedCredentials({
1820
- types: types ? [
1823
+ types: [
1821
1824
  types
1822
- ] : client.getCredentialOfferTypes(),
1825
+ ],
1823
1826
  format,
1824
1827
  version: client.version(),
1825
1828
  issuerMetadata: client.endpointMetadata.credentialIssuerMetadata
@@ -1994,7 +1997,8 @@ var getIssuanceCryptoSuite = /* @__PURE__ */ __name(async (opts) => {
1994
1997
  case "jwt":
1995
1998
  case "jwt_vc_json":
1996
1999
  case "jwt_vc":
1997
- case "vc+sd-jwt":
2000
+ //case 'vc+sd-jwt': FIXME re-enable for vcdm2
2001
+ case "dc+sd-jwt":
1998
2002
  case "mso_mdoc": {
1999
2003
  const supportedPreferences = jwtCryptographicSuitePreferences.filter((suite) => signing_algs_supported.includes(suite));
2000
2004
  if (supportedPreferences.length > 0) {
@@ -2063,7 +2067,6 @@ var startFirstPartApplicationMachine = /* @__PURE__ */ __name(async (args, conte
2063
2067
 
2064
2068
  // src/agent/OID4VCIHolder.ts
2065
2069
  import "cross-fetch/polyfill";
2066
- import { defaultHasher as defaultHasher2 } from "@sphereon/ssi-sdk.core";
2067
2070
  var oid4vciHolderContextMethods = [
2068
2071
  "cmGetContacts",
2069
2072
  "cmGetContact",
@@ -2079,7 +2082,7 @@ var oid4vciHolderContextMethods = [
2079
2082
  ];
2080
2083
  var logger = Loggers.DEFAULT.get("sphereon:oid4vci:holder");
2081
2084
  function signCallback(identifier, context, nonce) {
2082
- return async (jwt, kid) => {
2085
+ return async (jwt, kid, noIssPayloadUpdate) => {
2083
2086
  let resolution = await context.agent.identifierManagedGet(identifier);
2084
2087
  const jwk = jwt.header.jwk ?? (resolution.method === "jwk" ? resolution.jwk : void 0);
2085
2088
  if (!resolution.issuer && !jwt.payload.iss) {
@@ -2097,7 +2100,7 @@ function signCallback(identifier, context, nonce) {
2097
2100
  return (await context.agent.jwtCreateJwsCompactSignature({
2098
2101
  issuer: {
2099
2102
  ...resolution,
2100
- noIssPayloadUpdate: false
2103
+ noIssPayloadUpdate: noIssPayloadUpdate ?? false
2101
2104
  },
2102
2105
  protectedHeader: header,
2103
2106
  payload
@@ -2132,6 +2135,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2132
2135
  oid4vciHolderStoreIssuerBranding: this.oid4vciHolderStoreIssuerBranding.bind(this)
2133
2136
  };
2134
2137
  vcFormatPreferences = [
2138
+ "dc+sd-jwt",
2135
2139
  "vc+sd-jwt",
2136
2140
  "mso_mdoc",
2137
2141
  "jwt_vc_json",
@@ -2718,7 +2722,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2718
2722
  if (Array.isArray(subjectIssuance?.notification_events_supported)) {
2719
2723
  event = subjectIssuance.notification_events_supported.includes("credential_accepted_holder_signed") ? "credential_accepted_holder_signed" : "credential_deleted_holder_signed";
2720
2724
  logger.log(`Subject issuance/signing will be used, with event`, event);
2721
- const issuerVC = mappedCredentialToAccept.credentialToAccept.credentialResponse.credential;
2725
+ const issuerVC = extractCredentialFromResponse(mappedCredentialToAccept.credentialToAccept.credentialResponse);
2722
2726
  const wrappedIssuerVC = CredentialMapper2.toWrappedVerifiableCredential(issuerVC, {
2723
2727
  hasher: this.hasher ?? defaultHasher2
2724
2728
  });
@@ -3089,6 +3093,7 @@ export {
3089
3093
  RequestType,
3090
3094
  SupportedLanguage,
3091
3095
  createConfig,
3096
+ extractCredentialFromResponse,
3092
3097
  getBasicIssuerLocaleBranding,
3093
3098
  getCredentialBranding,
3094
3099
  getCredentialConfigsBasedOnFormatPref,