@sphereon/ssi-sdk.oid4vci-holder 0.34.1-feature.SSISDK.45.93 → 0.34.1-feature.SSISDK.46.40

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,9 +60,8 @@ 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";
64
- import { ConnectionType, CorrelationIdentifierType, CredentialCorrelationType, ensureRawDocument, IdentityOrigin } from "@sphereon/ssi-sdk.data-store";
65
- import { CredentialMapper as CredentialMapper2, JoseSignatureAlgorithm as JoseSignatureAlgorithm2, Loggers, parseDid, CredentialRole } from "@sphereon/ssi-types";
63
+ import { ConnectionType, CorrelationIdentifierType, CredentialCorrelationType, CredentialRole, ensureRawDocument, IdentityOrigin } from "@sphereon/ssi-sdk.data-store";
64
+ import { CredentialMapper as CredentialMapper2, JoseSignatureAlgorithm as JoseSignatureAlgorithm2, Loggers, parseDid } from "@sphereon/ssi-types";
66
65
  import { asArray as asArray2, computeEntryHash } from "@veramo/utils";
67
66
  import { decodeJWT } from "did-jwt";
68
67
  import { v4 as uuidv42 } from "uuid";
@@ -76,18 +75,18 @@ import i18n from "i18n-js";
76
75
  import memoize from "lodash.memoize";
77
76
 
78
77
  // src/types/IOID4VCIHolder.ts
79
- var OID4VCIHolderEvent = /* @__PURE__ */ function(OID4VCIHolderEvent2) {
78
+ var OID4VCIHolderEvent = /* @__PURE__ */ (function(OID4VCIHolderEvent2) {
80
79
  OID4VCIHolderEvent2["CONTACT_IDENTITY_CREATED"] = "contact_identity_created";
81
80
  OID4VCIHolderEvent2["CREDENTIAL_STORED"] = "credential_stored";
82
81
  OID4VCIHolderEvent2["IDENTIFIER_CREATED"] = "identifier_created";
83
82
  return OID4VCIHolderEvent2;
84
- }({});
85
- var SupportedLanguage = /* @__PURE__ */ function(SupportedLanguage2) {
83
+ })({});
84
+ var SupportedLanguage = /* @__PURE__ */ (function(SupportedLanguage2) {
86
85
  SupportedLanguage2["ENGLISH"] = "en";
87
86
  SupportedLanguage2["DUTCH"] = "nl";
88
87
  return SupportedLanguage2;
89
- }({});
90
- var OID4VCIMachineStates = /* @__PURE__ */ function(OID4VCIMachineStates2) {
88
+ })({});
89
+ var OID4VCIMachineStates = /* @__PURE__ */ (function(OID4VCIMachineStates2) {
91
90
  OID4VCIMachineStates2["start"] = "start";
92
91
  OID4VCIMachineStates2["createCredentialsToSelectFrom"] = "createCredentialsToSelectFrom";
93
92
  OID4VCIMachineStates2["getContact"] = "getContact";
@@ -118,18 +117,18 @@ var OID4VCIMachineStates = /* @__PURE__ */ function(OID4VCIMachineStates2) {
118
117
  OID4VCIMachineStates2["error"] = "error";
119
118
  OID4VCIMachineStates2["done"] = "done";
120
119
  return OID4VCIMachineStates2;
121
- }({});
122
- var OID4VCIMachineAddContactStates = /* @__PURE__ */ function(OID4VCIMachineAddContactStates2) {
120
+ })({});
121
+ var OID4VCIMachineAddContactStates = /* @__PURE__ */ (function(OID4VCIMachineAddContactStates2) {
123
122
  OID4VCIMachineAddContactStates2["idle"] = "idle";
124
123
  OID4VCIMachineAddContactStates2["next"] = "next";
125
124
  return OID4VCIMachineAddContactStates2;
126
- }({});
127
- var OID4VCIMachineVerifyPinStates = /* @__PURE__ */ function(OID4VCIMachineVerifyPinStates2) {
125
+ })({});
126
+ var OID4VCIMachineVerifyPinStates = /* @__PURE__ */ (function(OID4VCIMachineVerifyPinStates2) {
128
127
  OID4VCIMachineVerifyPinStates2["idle"] = "idle";
129
128
  OID4VCIMachineVerifyPinStates2["next"] = "next";
130
129
  return OID4VCIMachineVerifyPinStates2;
131
- }({});
132
- var OID4VCIMachineEvents = /* @__PURE__ */ function(OID4VCIMachineEvents2) {
130
+ })({});
131
+ var OID4VCIMachineEvents = /* @__PURE__ */ (function(OID4VCIMachineEvents2) {
133
132
  OID4VCIMachineEvents2["NEXT"] = "NEXT";
134
133
  OID4VCIMachineEvents2["PREVIOUS"] = "PREVIOUS";
135
134
  OID4VCIMachineEvents2["DECLINE"] = "DECLINE";
@@ -142,15 +141,14 @@ var OID4VCIMachineEvents = /* @__PURE__ */ function(OID4VCIMachineEvents2) {
142
141
  OID4VCIMachineEvents2["INVOKED_AUTHORIZATION_CODE_REQUEST"] = "INVOKED_AUTHORIZATION_CODE_REQUEST";
143
142
  OID4VCIMachineEvents2["PROVIDE_AUTHORIZATION_CODE_RESPONSE"] = "PROVIDE_AUTHORIZATION_CODE_RESPONSE";
144
143
  return OID4VCIMachineEvents2;
145
- }({});
146
- var OID4VCIMachineGuards = /* @__PURE__ */ function(OID4VCIMachineGuards2) {
144
+ })({});
145
+ var OID4VCIMachineGuards = /* @__PURE__ */ (function(OID4VCIMachineGuards2) {
147
146
  OID4VCIMachineGuards2["hasContactGuard"] = "oid4vciHasContactGuard";
148
147
  OID4VCIMachineGuards2["hasNoContactGuard"] = "oid4vciHasNoContactGuard";
149
148
  OID4VCIMachineGuards2["credentialsToSelectRequiredGuard"] = "oid4vciCredentialsToSelectRequiredGuard";
150
149
  OID4VCIMachineGuards2["requirePinGuard"] = "oid4vciRequirePinGuard";
151
150
  OID4VCIMachineGuards2["requireAuthorizationGuard"] = "oid4vciRequireAuthorizationGuard";
152
151
  OID4VCIMachineGuards2["noAuthorizationGuard"] = "oid4vciNoAuthorizationGuard";
153
- OID4VCIMachineGuards2["hasNonceEndpointGuard"] = "oid4vciHasNonceEndpointGuard ";
154
152
  OID4VCIMachineGuards2["hasAuthorizationResponse"] = "oid4vciHasAuthorizationResponse";
155
153
  OID4VCIMachineGuards2["hasNoContactIdentityGuard"] = "oid4vciHasNoContactIdentityGuard";
156
154
  OID4VCIMachineGuards2["verificationCodeGuard"] = "oid4vciVerificationCodeGuard";
@@ -160,8 +158,8 @@ var OID4VCIMachineGuards = /* @__PURE__ */ function(OID4VCIMachineGuards2) {
160
158
  OID4VCIMachineGuards2["contactHasLowTrustGuard"] = "oid4vciContactHasLowTrustGuard";
161
159
  OID4VCIMachineGuards2["isFirstPartyApplication"] = "oid4vciIsFirstPartyApplication";
162
160
  return OID4VCIMachineGuards2;
163
- }({});
164
- var OID4VCIMachineServices = /* @__PURE__ */ function(OID4VCIMachineServices2) {
161
+ })({});
162
+ var OID4VCIMachineServices = /* @__PURE__ */ (function(OID4VCIMachineServices2) {
165
163
  OID4VCIMachineServices2["start"] = "start";
166
164
  OID4VCIMachineServices2["getContact"] = "getContact";
167
165
  OID4VCIMachineServices2["getFederationTrust"] = "getFederationTrust";
@@ -176,17 +174,17 @@ var OID4VCIMachineServices = /* @__PURE__ */ function(OID4VCIMachineServices2) {
176
174
  OID4VCIMachineServices2["storeCredentials"] = "storeCredentials";
177
175
  OID4VCIMachineServices2["startFirstPartApplicationFlow"] = "startFirstPartApplicationFlow";
178
176
  return OID4VCIMachineServices2;
179
- }({});
180
- var RequestType = /* @__PURE__ */ function(RequestType2) {
177
+ })({});
178
+ var RequestType = /* @__PURE__ */ (function(RequestType2) {
181
179
  RequestType2["OPENID_INITIATE_ISSUANCE"] = "openid-initiate-issuance";
182
180
  RequestType2["OPENID_CREDENTIAL_OFFER"] = "openid-credential-offer";
183
181
  RequestType2["URL"] = "URL";
184
182
  return RequestType2;
185
- }({});
186
- var IdentifierAliasEnum = /* @__PURE__ */ function(IdentifierAliasEnum2) {
183
+ })({});
184
+ var IdentifierAliasEnum = /* @__PURE__ */ (function(IdentifierAliasEnum2) {
187
185
  IdentifierAliasEnum2["PRIMARY"] = "primary";
188
186
  return IdentifierAliasEnum2;
189
- }({});
187
+ })({});
190
188
 
191
189
  // src/localization/Localization.ts
192
190
  var Localization = class Localization2 {
@@ -228,7 +226,7 @@ var Localization = class Localization2 {
228
226
  var translate = Localization.translate;
229
227
 
230
228
  // src/types/FirstPartyMachine.ts
231
- var FirstPartyMachineStateTypes = /* @__PURE__ */ function(FirstPartyMachineStateTypes2) {
229
+ var FirstPartyMachineStateTypes = /* @__PURE__ */ (function(FirstPartyMachineStateTypes2) {
232
230
  FirstPartyMachineStateTypes2["sendAuthorizationChallengeRequest"] = "sendAuthorizationChallengeRequest";
233
231
  FirstPartyMachineStateTypes2["sendAuthorizationResponse"] = "sendAuthorizationResponse";
234
232
  FirstPartyMachineStateTypes2["selectCredentials"] = "selectCredentials";
@@ -239,21 +237,21 @@ var FirstPartyMachineStateTypes = /* @__PURE__ */ function(FirstPartyMachineStat
239
237
  FirstPartyMachineStateTypes2["aborted"] = "aborted";
240
238
  FirstPartyMachineStateTypes2["declined"] = "declined";
241
239
  return FirstPartyMachineStateTypes2;
242
- }({});
243
- var FirstPartyMachineServices = /* @__PURE__ */ function(FirstPartyMachineServices2) {
240
+ })({});
241
+ var FirstPartyMachineServices = /* @__PURE__ */ (function(FirstPartyMachineServices2) {
244
242
  FirstPartyMachineServices2["sendAuthorizationChallengeRequest"] = "sendAuthorizationChallengeRequest";
245
243
  FirstPartyMachineServices2["sendAuthorizationResponse"] = "sendAuthorizationResponse";
246
244
  FirstPartyMachineServices2["createConfig"] = "createConfig";
247
245
  FirstPartyMachineServices2["getSiopRequest"] = "getSiopRequest";
248
246
  return FirstPartyMachineServices2;
249
- }({});
250
- var FirstPartyMachineEvents = /* @__PURE__ */ function(FirstPartyMachineEvents2) {
247
+ })({});
248
+ var FirstPartyMachineEvents = /* @__PURE__ */ (function(FirstPartyMachineEvents2) {
251
249
  FirstPartyMachineEvents2["NEXT"] = "NEXT";
252
250
  FirstPartyMachineEvents2["PREVIOUS"] = "PREVIOUS";
253
251
  FirstPartyMachineEvents2["DECLINE"] = "DECLINE";
254
252
  FirstPartyMachineEvents2["SET_SELECTED_CREDENTIALS"] = "SET_SELECTED_CREDENTIALS";
255
253
  return FirstPartyMachineEvents2;
256
- }({});
254
+ })({});
257
255
 
258
256
  // src/machines/oid4vciMachine.ts
259
257
  var oid4vciHasNoContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
@@ -983,405 +981,214 @@ import { KeyUse } from "@sphereon/ssi-sdk-ext.did-resolver-jwk";
983
981
  import { getOrCreatePrimaryIdentifier, SupportedDidMethodEnum } from "@sphereon/ssi-sdk-ext.did-utils";
984
982
  import { isIIdentifier, isManagedIdentifierDidResult, isManagedIdentifierResult, managedIdentifierToJwk } from "@sphereon/ssi-sdk-ext.identifier-resolution";
985
983
  import { keyTypeFromCryptographicSuite } from "@sphereon/ssi-sdk-ext.key-utils";
986
- import { defaultHasher } from "@sphereon/ssi-sdk.core";
987
984
  import { CredentialMapper, JoseSignatureAlgorithm, mdocDecodedCredentialToUniformCredential, sdJwtDecodedCredentialToUniformCredential } from "@sphereon/ssi-types";
988
985
  import { asArray } from "@veramo/utils";
989
986
 
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
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
+ }
1001
1001
  });
1002
- return oid4vciClient.acquireAuthorizationChallengeCode({
1003
- clientId: oid4vciClient.clientId ?? uuidv4(),
1004
- ...authSession && {
1005
- authSession
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
1006
1045
  },
1007
- ...!authSession && openID4VCIClientState.credentialOffer?.preAuthorizedCode && {
1008
- issuerState: openID4VCIClientState.credentialOffer?.preAuthorizedCode
1046
+ ...credentialDisplay.locale && {
1047
+ locale: credentialDisplay.locale
1009
1048
  },
1010
- ...!authSession && openID4VCIClientState.credentialOffer?.issuerState && {
1011
- issuerState: openID4VCIClientState.credentialOffer?.issuerState
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
+ }
1012
1058
  },
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
- })
1059
+ ...credentialDisplay.description && {
1060
+ description: credentialDisplay.description
1061
+ },
1062
+ ...credentialDisplay.text_color && {
1063
+ text: {
1064
+ color: credentialDisplay.text_color
1065
+ }
1066
+ },
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
+ }
1071
1078
  },
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
- })
1079
+ ...credentialDisplay.background_color && {
1080
+ color: credentialDisplay.background_color
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
- })
1104
1082
  }
1105
1083
  }
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
- })
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
1116
1101
  },
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
- }
1127
- }
1128
- },
1129
- [FirstPartyMachineStateTypes.selectCredentials]: {
1130
- id: FirstPartyMachineStateTypes.selectCredentials,
1131
- on: {
1132
- [FirstPartyMachineEvents.SET_SELECTED_CREDENTIALS]: {
1133
- actions: assign2({
1134
- selectedCredentials: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectedCredentials")
1135
- })
1136
- },
1137
- [FirstPartyMachineEvents.NEXT]: {
1138
- target: FirstPartyMachineStateTypes.sendAuthorizationResponse
1139
- },
1140
- [FirstPartyMachineEvents.DECLINE]: {
1141
- target: FirstPartyMachineStateTypes.declined
1142
- },
1143
- [FirstPartyMachineEvents.PREVIOUS]: {
1144
- target: FirstPartyMachineStateTypes.aborted
1145
- }
1146
- }
1147
- },
1148
- [FirstPartyMachineStateTypes.sendAuthorizationResponse]: {
1149
- id: FirstPartyMachineStateTypes.sendAuthorizationResponse,
1150
- invoke: {
1151
- src: FirstPartyMachineServices.sendAuthorizationResponse,
1152
- onDone: {
1153
- target: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1154
- actions: assign2({
1155
- presentationDuringIssuanceSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "presentationDuringIssuanceSession")
1156
- })
1157
- },
1158
- onError: {
1159
- target: FirstPartyMachineStateTypes.error,
1160
- actions: assign2({
1161
- error: /* @__PURE__ */ __name((_ctx, _event) => ({
1162
- title: translate("oid4vci_machine_get_request_error_title"),
1163
- message: _event.data.message,
1164
- stack: _event.data.stack
1165
- }), "error")
1166
- })
1167
- }
1168
- }
1169
- },
1170
- [FirstPartyMachineStateTypes.aborted]: {
1171
- id: FirstPartyMachineStateTypes.aborted,
1172
- type: "final"
1173
- },
1174
- [FirstPartyMachineStateTypes.declined]: {
1175
- id: FirstPartyMachineStateTypes.declined,
1176
- type: "final"
1177
- },
1178
- [FirstPartyMachineStateTypes.error]: {
1179
- id: FirstPartyMachineStateTypes.error,
1180
- type: "final"
1181
- },
1182
- [FirstPartyMachineStateTypes.done]: {
1183
- id: FirstPartyMachineStateTypes.done,
1184
- type: "final"
1185
- }
1186
- };
1187
- var createFirstPartyActivationMachine = /* @__PURE__ */ __name((opts) => {
1188
- const initialContext = {
1189
- openID4VCIClientState: opts.openID4VCIClientState,
1190
- contact: opts.contact,
1191
- selectedCredentials: []
1192
- };
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: {}
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
+ })
1202
1118
  }
1203
1119
  });
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) => {
1120
+ }, "sdJwtGetCredentialBrandingFrom");
1121
+ var sdJwtCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1292
1122
  const { credentialDisplay } = args;
1293
1123
  return credentialDisplay.reduce((localeDisplays, display) => {
1294
- const localeKey = display.locale || "";
1124
+ const localeKey = display.lang || "";
1295
1125
  localeDisplays.set(localeKey, display);
1296
1126
  return localeDisplays;
1297
1127
  }, /* @__PURE__ */ new Map());
1298
- }, "oid4vciCredentialDisplayLocalesFrom");
1299
- var oid4vciIssuerCredentialSubjectLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1300
- const { issuerCredentialSubject } = args;
1128
+ }, "sdJwtCredentialDisplayLocalesFrom");
1129
+ var sdJwtCredentialClaimLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1130
+ const { claimsMetadata } = args;
1301
1131
  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);
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, []);
1322
1138
  }
1139
+ localeClaims.get(lang).push({
1140
+ key,
1141
+ name: label
1142
+ });
1323
1143
  });
1324
- }, "processClaimObject");
1325
- processClaimObject(issuerCredentialSubject);
1144
+ });
1326
1145
  return localeClaims;
1327
- }, "oid4vciIssuerCredentialSubjectLocalesFrom");
1328
- var oid4vciCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1146
+ }, "sdJwtCredentialClaimLocalesFrom");
1147
+ var sdJwtCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1329
1148
  const { credentialDisplay } = args;
1330
1149
  return {
1331
1150
  ...credentialDisplay.name && {
1332
1151
  alias: credentialDisplay.name
1333
1152
  },
1334
- ...credentialDisplay.locale && {
1335
- locale: credentialDisplay.locale
1153
+ ...credentialDisplay.lang && {
1154
+ locale: credentialDisplay.lang
1336
1155
  },
1337
- ...credentialDisplay.logo && {
1156
+ ...credentialDisplay.rendering?.simple?.logo && {
1338
1157
  logo: {
1339
- ...(credentialDisplay.logo.url || credentialDisplay.logo.uri) && {
1340
- uri: credentialDisplay.logo?.url ?? credentialDisplay.logo.uri
1158
+ ...credentialDisplay.rendering.simple.logo.uri && {
1159
+ uri: credentialDisplay.rendering.simple.logo.uri
1341
1160
  },
1342
- ...credentialDisplay.logo.alt_text && {
1343
- alt: credentialDisplay.logo?.alt_text
1161
+ ...credentialDisplay.rendering.simple.logo.alt_text && {
1162
+ alt: credentialDisplay.rendering.simple.logo.alt_text
1344
1163
  }
1345
1164
  }
1346
1165
  },
1347
1166
  ...credentialDisplay.description && {
1348
1167
  description: credentialDisplay.description
1349
1168
  },
1350
- ...credentialDisplay.text_color && {
1169
+ ...credentialDisplay.rendering?.simple?.text_color && {
1351
1170
  text: {
1352
- color: credentialDisplay.text_color
1171
+ color: credentialDisplay.rendering.simple.text_color
1353
1172
  }
1354
1173
  },
1355
- ...(credentialDisplay.background_image || credentialDisplay.background_color) && {
1174
+ ...credentialDisplay.rendering?.simple?.background_color && {
1356
1175
  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
- }
1176
+ color: credentialDisplay.rendering.simple.background_color
1370
1177
  }
1371
1178
  }
1372
1179
  };
1373
- }, "oid4vciCredentialLocaleBrandingFrom");
1374
- var oid4vciCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1375
- const { credentialDisplayLocales = /* @__PURE__ */ new Map(), issuerCredentialSubjectLocales = /* @__PURE__ */ new Map() } = args;
1180
+ }, "sdJwtCredentialLocaleBrandingFrom");
1181
+ var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1182
+ const { credentialDisplayLocales = /* @__PURE__ */ new Map(), claimsMetadata = /* @__PURE__ */ new Map() } = args;
1376
1183
  const locales = Array.from(/* @__PURE__ */ new Set([
1377
- ...issuerCredentialSubjectLocales.keys(),
1184
+ ...claimsMetadata.keys(),
1378
1185
  ...credentialDisplayLocales.keys()
1379
1186
  ]));
1380
1187
  return Promise.all(locales.map(async (locale) => {
1381
1188
  const display = credentialDisplayLocales.get(locale);
1382
- const claims = issuerCredentialSubjectLocales.get(locale);
1189
+ const claims = claimsMetadata.get(locale);
1383
1190
  return {
1384
- ...display && await oid4vciCredentialLocaleBrandingFrom({
1191
+ ...display && await sdJwtCredentialLocaleBrandingFrom({
1385
1192
  credentialDisplay: display
1386
1193
  }),
1387
1194
  ...locale.length > 0 && {
@@ -1390,157 +1197,348 @@ var oid4vciCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1390
1197
  claims
1391
1198
  };
1392
1199
  }));
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
- })
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
1401
1206
  },
1402
- ...credentialDisplay && {
1403
- credentialDisplayLocales: await sdJwtCredentialDisplayLocalesFrom({
1404
- credentialDisplay
1405
- })
1406
- }
1407
- });
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, []);
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
+ }
1426
1224
  }
1427
- localeClaims.get(lang).push({
1428
- key,
1429
- name: label
1430
- });
1431
- });
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
1432
1260
  });
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
1261
+ return oid4vciClient.acquireAuthorizationChallengeCode({
1262
+ clientId: oid4vciClient.clientId ?? uuidv4(),
1263
+ ...authSession && {
1264
+ authSession
1440
1265
  },
1441
- ...credentialDisplay.lang && {
1442
- locale: credentialDisplay.lang
1266
+ ...!authSession && openID4VCIClientState.credentialOffer?.preAuthorizedCode && {
1267
+ issuerState: openID4VCIClientState.credentialOffer?.preAuthorizedCode
1443
1268
  },
1444
- ...credentialDisplay.rendering?.simple?.logo && {
1445
- logo: {
1446
- ...credentialDisplay.rendering.simple.logo.uri && {
1447
- uri: credentialDisplay.rendering.simple.logo.uri
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
+ })
1448
1330
  },
1449
- ...credentialDisplay.rendering.simple.logo.alt_text && {
1450
- alt: credentialDisplay.rendering.simple.logo.alt_text
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
+ })
1451
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
+ })
1452
1363
  }
1453
- },
1454
- ...credentialDisplay.description && {
1455
- description: credentialDisplay.description
1456
- },
1457
- ...credentialDisplay.rendering?.simple?.text_color && {
1458
- text: {
1459
- color: credentialDisplay.rendering.simple.text_color
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
+ })
1460
1385
  }
1461
- },
1462
- ...credentialDisplay.rendering?.simple?.background_color && {
1463
- background: {
1464
- color: credentialDisplay.rendering.simple.background_color
1386
+ }
1387
+ },
1388
+ [FirstPartyMachineStateTypes.selectCredentials]: {
1389
+ id: FirstPartyMachineStateTypes.selectCredentials,
1390
+ on: {
1391
+ [FirstPartyMachineEvents.SET_SELECTED_CREDENTIALS]: {
1392
+ actions: assign2({
1393
+ selectedCredentials: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectedCredentials")
1394
+ })
1395
+ },
1396
+ [FirstPartyMachineEvents.NEXT]: {
1397
+ target: FirstPartyMachineStateTypes.sendAuthorizationResponse
1398
+ },
1399
+ [FirstPartyMachineEvents.DECLINE]: {
1400
+ target: FirstPartyMachineStateTypes.declined
1401
+ },
1402
+ [FirstPartyMachineEvents.PREVIOUS]: {
1403
+ target: FirstPartyMachineStateTypes.aborted
1465
1404
  }
1466
1405
  }
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
1406
+ },
1407
+ [FirstPartyMachineStateTypes.sendAuthorizationResponse]: {
1408
+ id: FirstPartyMachineStateTypes.sendAuthorizationResponse,
1409
+ invoke: {
1410
+ src: FirstPartyMachineServices.sendAuthorizationResponse,
1411
+ onDone: {
1412
+ target: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1413
+ actions: assign2({
1414
+ presentationDuringIssuanceSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "presentationDuringIssuanceSession")
1415
+ })
1484
1416
  },
1485
- claims
1417
+ onError: {
1418
+ target: FirstPartyMachineStateTypes.error,
1419
+ actions: assign2({
1420
+ error: /* @__PURE__ */ __name((_ctx, _event) => ({
1421
+ title: translate("oid4vci_machine_get_request_error_title"),
1422
+ message: _event.data.message,
1423
+ stack: _event.data.stack
1424
+ }), "error")
1425
+ })
1426
+ }
1427
+ }
1428
+ },
1429
+ [FirstPartyMachineStateTypes.aborted]: {
1430
+ id: FirstPartyMachineStateTypes.aborted,
1431
+ type: "final"
1432
+ },
1433
+ [FirstPartyMachineStateTypes.declined]: {
1434
+ id: FirstPartyMachineStateTypes.declined,
1435
+ type: "final"
1436
+ },
1437
+ [FirstPartyMachineStateTypes.error]: {
1438
+ id: FirstPartyMachineStateTypes.error,
1439
+ type: "final"
1440
+ },
1441
+ [FirstPartyMachineStateTypes.done]: {
1442
+ id: FirstPartyMachineStateTypes.done,
1443
+ type: "final"
1444
+ }
1445
+ };
1446
+ var createFirstPartyActivationMachine = /* @__PURE__ */ __name((opts) => {
1447
+ const initialContext = {
1448
+ openID4VCIClientState: opts.openID4VCIClientState,
1449
+ contact: opts.contact,
1450
+ selectedCredentials: []
1451
+ };
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: {}
1461
+ }
1462
+ });
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();
1483
+ }
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)
1486
1501
  };
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
1511
- }
1502
+ const newInst = interpret2(createFirstPartyActivationMachine(opts).withConfig({
1503
+ services: {
1504
+ ...services,
1505
+ ...opts?.services
1506
+ },
1507
+ guards: {
1508
+ ...opts?.guards
1512
1509
  }
1513
- },
1514
- ...issuerDisplay.description && {
1515
- description: issuerDisplay.description
1516
- },
1517
- ...issuerDisplay.text_color && {
1518
- text: {
1519
- color: issuerDisplay.text_color
1510
+ }));
1511
+ if (typeof opts?.subscription === "function") {
1512
+ newInst.onTransition(opts.subscription);
1513
+ }
1514
+ if (opts?.requireCustomNavigationHook !== true) {
1515
+ newInst.onTransition((snapshot) => {
1516
+ if (opts?.stateNavigationListener) {
1517
+ void opts.stateNavigationListener(newInst, snapshot);
1518
+ }
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!`);
1520
1527
  }
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
1528
+ _FirstPartyMachine._instance = _FirstPartyMachine.newInstance(opts);
1533
1529
  }
1534
- };
1535
- }, "issuerLocaleBrandingFrom");
1530
+ return _FirstPartyMachine._instance;
1531
+ }
1532
+ };
1536
1533
 
1537
1534
  // src/services/OID4VCIHolderService.ts
1535
+ import { defaultHasher } from "@sphereon/ssi-sdk.core";
1538
1536
  var getCredentialBranding = /* @__PURE__ */ __name(async (args) => {
1539
1537
  const { credentialsSupported, context } = args;
1540
1538
  const credentialBranding = {};
1541
1539
  await Promise.all(Object.entries(credentialsSupported).map(async ([configId, credentialsConfigSupported]) => {
1542
1540
  let sdJwtTypeMetadata;
1543
- if (credentialsConfigSupported.format === "dc+sd-jwt") {
1541
+ if (credentialsConfigSupported.format === "vc+sd-jwt") {
1544
1542
  const vct = credentialsConfigSupported.vct;
1545
1543
  if (vct.startsWith("http")) {
1546
1544
  try {
@@ -1606,7 +1604,10 @@ var selectCredentialLocaleBranding = /* @__PURE__ */ __name(async (args) => {
1606
1604
  }, "selectCredentialLocaleBranding");
1607
1605
  var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1608
1606
  const { mappedCredential, hasher, onVerifyEBSICredentialIssuer, schemaValidation, context } = args;
1609
- const credential = extractCredentialFromResponse(mappedCredential.credentialToAccept.credentialResponse);
1607
+ const credential = mappedCredential.credentialToAccept.credentialResponse.credential;
1608
+ if (!credential) {
1609
+ return Promise.reject(Error("No credential found in credential response"));
1610
+ }
1610
1611
  const wrappedVC = CredentialMapper.toWrappedVerifiableCredential(credential, {
1611
1612
  hasher: hasher ?? defaultHasher
1612
1613
  });
@@ -1658,7 +1659,11 @@ var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1658
1659
  }, "verifyCredentialToAccept");
1659
1660
  var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1660
1661
  const { credentialToAccept, hasher } = args;
1661
- const verifiableCredential = extractCredentialFromResponse(credentialToAccept.credentialResponse);
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
+ }
1662
1667
  const wrappedVerifiableCredential = CredentialMapper.toWrappedVerifiableCredential(verifiableCredential, {
1663
1668
  hasher
1664
1669
  });
@@ -1678,7 +1683,6 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1678
1683
  uniformVerifiableCredential = wrappedVerifiableCredential.credential;
1679
1684
  }
1680
1685
  const correlationId = typeof uniformVerifiableCredential.issuer === "string" ? uniformVerifiableCredential.issuer : CredentialMapper.isSdJwtDecodedCredential(uniformVerifiableCredential) ? uniformVerifiableCredential.decodedPayload.iss : uniformVerifiableCredential.issuer.id;
1681
- const credentialResponse = credentialToAccept.credentialResponse;
1682
1686
  return {
1683
1687
  correlationId,
1684
1688
  credentialToAccept,
@@ -1690,18 +1694,6 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1690
1694
  }
1691
1695
  };
1692
1696
  }, "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");
1705
1697
  var getIdentifierOpts = /* @__PURE__ */ __name(async (args) => {
1706
1698
  const { issuanceOpt, context } = args;
1707
1699
  const { identifier: identifierArg } = issuanceOpt;
@@ -2003,7 +1995,6 @@ var getIssuanceCryptoSuite = /* @__PURE__ */ __name(async (opts) => {
2003
1995
  case "jwt_vc_json":
2004
1996
  case "jwt_vc":
2005
1997
  case "vc+sd-jwt":
2006
- case "dc+sd-jwt":
2007
1998
  case "mso_mdoc": {
2008
1999
  const supportedPreferences = jwtCryptographicSuitePreferences.filter((suite) => signing_algs_supported.includes(suite));
2009
2000
  if (supportedPreferences.length > 0) {
@@ -2072,6 +2063,7 @@ var startFirstPartApplicationMachine = /* @__PURE__ */ __name(async (args, conte
2072
2063
 
2073
2064
  // src/agent/OID4VCIHolder.ts
2074
2065
  import "cross-fetch/polyfill";
2066
+ import { defaultHasher as defaultHasher2 } from "@sphereon/ssi-sdk.core";
2075
2067
  var oid4vciHolderContextMethods = [
2076
2068
  "cmGetContacts",
2077
2069
  "cmGetContact",
@@ -2087,7 +2079,7 @@ var oid4vciHolderContextMethods = [
2087
2079
  ];
2088
2080
  var logger = Loggers.DEFAULT.get("sphereon:oid4vci:holder");
2089
2081
  function signCallback(identifier, context, nonce) {
2090
- return async (jwt, kid, noIssPayloadUpdate) => {
2082
+ return async (jwt, kid) => {
2091
2083
  let resolution = await context.agent.identifierManagedGet(identifier);
2092
2084
  const jwk = jwt.header.jwk ?? (resolution.method === "jwk" ? resolution.jwk : void 0);
2093
2085
  if (!resolution.issuer && !jwt.payload.iss) {
@@ -2105,7 +2097,7 @@ function signCallback(identifier, context, nonce) {
2105
2097
  return (await context.agent.jwtCreateJwsCompactSignature({
2106
2098
  issuer: {
2107
2099
  ...resolution,
2108
- noIssPayloadUpdate: noIssPayloadUpdate ?? false
2100
+ noIssPayloadUpdate: false
2109
2101
  },
2110
2102
  protectedHeader: header,
2111
2103
  payload
@@ -2140,7 +2132,6 @@ var OID4VCIHolder = class _OID4VCIHolder {
2140
2132
  oid4vciHolderStoreIssuerBranding: this.oid4vciHolderStoreIssuerBranding.bind(this)
2141
2133
  };
2142
2134
  vcFormatPreferences = [
2143
- "dc+sd-jwt",
2144
2135
  "vc+sd-jwt",
2145
2136
  "mso_mdoc",
2146
2137
  "jwt_vc_json",
@@ -2727,7 +2718,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2727
2718
  if (Array.isArray(subjectIssuance?.notification_events_supported)) {
2728
2719
  event = subjectIssuance.notification_events_supported.includes("credential_accepted_holder_signed") ? "credential_accepted_holder_signed" : "credential_deleted_holder_signed";
2729
2720
  logger.log(`Subject issuance/signing will be used, with event`, event);
2730
- const issuerVC = extractCredentialFromResponse(mappedCredentialToAccept.credentialToAccept.credentialResponse);
2721
+ const issuerVC = mappedCredentialToAccept.credentialToAccept.credentialResponse.credential;
2731
2722
  const wrappedIssuerVC = CredentialMapper2.toWrappedVerifiableCredential(issuerVC, {
2732
2723
  hasher: this.hasher ?? defaultHasher2
2733
2724
  });
@@ -3098,7 +3089,6 @@ export {
3098
3089
  RequestType,
3099
3090
  SupportedLanguage,
3100
3091
  createConfig,
3101
- extractCredentialFromResponse,
3102
3092
  getBasicIssuerLocaleBranding,
3103
3093
  getCredentialBranding,
3104
3094
  getCredentialConfigsBasedOnFormatPref,