@sphereon/ssi-sdk.oid4vci-holder 0.34.1-feature.FIDES.1.274 → 0.34.1-feature.IDK.11.48

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
@@ -56,16 +56,13 @@ var require_nl = __commonJS({
56
56
 
57
57
  // src/agent/OID4VCIHolder.ts
58
58
  import { CredentialOfferClient, MetadataClient, OpenID4VCIClient as OpenID4VCIClient2 } from "@sphereon/oid4vci-client";
59
- import { DefaultURISchemes, getTypesFromObject as getTypesFromObject2 } from "@sphereon/oid4vci-common";
59
+ import { DefaultURISchemes, getTypesFromAuthorizationDetails, getTypesFromCredentialOffer, getTypesFromObject as getTypesFromObject2 } from "@sphereon/oid4vci-common";
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 { ensureRawDocument } from "@sphereon/ssi-sdk.data-store-types";
65
- import { ConnectionType, CorrelationIdentifierType, CredentialCorrelationType, IdentityOrigin } from "@sphereon/ssi-sdk.data-store-types";
66
- import { CredentialMapper as CredentialMapper2, CredentialRole, JoseSignatureAlgorithm as JoseSignatureAlgorithm2, Loggers, parseDid } 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";
67
65
  import { asArray as asArray2, computeEntryHash } from "@veramo/utils";
68
- import fetch from "cross-fetch";
69
66
  import { decodeJWT } from "did-jwt";
70
67
  import { v4 as uuidv42 } from "uuid";
71
68
 
@@ -152,7 +149,6 @@ var OID4VCIMachineGuards = /* @__PURE__ */ (function(OID4VCIMachineGuards2) {
152
149
  OID4VCIMachineGuards2["requirePinGuard"] = "oid4vciRequirePinGuard";
153
150
  OID4VCIMachineGuards2["requireAuthorizationGuard"] = "oid4vciRequireAuthorizationGuard";
154
151
  OID4VCIMachineGuards2["noAuthorizationGuard"] = "oid4vciNoAuthorizationGuard";
155
- OID4VCIMachineGuards2["hasNonceEndpointGuard"] = "oid4vciHasNonceEndpointGuard ";
156
152
  OID4VCIMachineGuards2["hasAuthorizationResponse"] = "oid4vciHasAuthorizationResponse";
157
153
  OID4VCIMachineGuards2["hasNoContactIdentityGuard"] = "oid4vciHasNoContactIdentityGuard";
158
154
  OID4VCIMachineGuards2["verificationCodeGuard"] = "oid4vciVerificationCodeGuard";
@@ -980,410 +976,219 @@ var OID4VCIMachine = class {
980
976
 
981
977
  // src/services/OID4VCIHolderService.ts
982
978
  import { LOG } from "@sphereon/oid4vci-client";
983
- import { getSupportedCredentials, getTypesFromCredentialSupported, getTypesFromObject } from "@sphereon/oid4vci-common";
979
+ import { getSupportedCredentials, getTypesFromCredentialSupported, getTypesFromObject, OpenId4VCIVersion } from "@sphereon/oid4vci-common";
984
980
  import { KeyUse } from "@sphereon/ssi-sdk-ext.did-resolver-jwk";
985
981
  import { getOrCreatePrimaryIdentifier, SupportedDidMethodEnum } from "@sphereon/ssi-sdk-ext.did-utils";
986
982
  import { isIIdentifier, isManagedIdentifierDidResult, isManagedIdentifierResult, managedIdentifierToJwk } from "@sphereon/ssi-sdk-ext.identifier-resolution";
987
983
  import { keyTypeFromCryptographicSuite } from "@sphereon/ssi-sdk-ext.key-utils";
988
- import { defaultHasher } from "@sphereon/ssi-sdk.core";
989
984
  import { CredentialMapper, JoseSignatureAlgorithm, mdocDecodedCredentialToUniformCredential, sdJwtDecodedCredentialToUniformCredential } from "@sphereon/ssi-types";
990
985
  import { asArray } from "@veramo/utils";
991
986
 
992
- // src/machines/firstPartyMachine.ts
993
- import { assign as assign2, createMachine as createMachine2, interpret as interpret2 } from "xstate";
994
- import { AuthorizationChallengeError } from "@sphereon/oid4vci-common";
995
-
996
- // src/services/FirstPartyMachineServices.ts
997
- import { OpenID4VCIClient } from "@sphereon/oid4vci-client";
998
- import { v4 as uuidv4 } from "uuid";
999
- var sendAuthorizationChallengeRequest = /* @__PURE__ */ __name(async (args) => {
1000
- const { openID4VCIClientState, authSession, presentationDuringIssuanceSession } = args;
1001
- const oid4vciClient = await OpenID4VCIClient.fromState({
1002
- 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
+ }
1003
1001
  });
1004
- return oid4vciClient.acquireAuthorizationChallengeCode({
1005
- clientId: oid4vciClient.clientId ?? uuidv4(),
1006
- ...authSession && {
1007
- 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
1008
1045
  },
1009
- ...!authSession && openID4VCIClientState.credentialOffer?.preAuthorizedCode && {
1010
- issuerState: openID4VCIClientState.credentialOffer?.preAuthorizedCode
1046
+ ...credentialDisplay.locale && {
1047
+ locale: credentialDisplay.locale
1011
1048
  },
1012
- ...!authSession && openID4VCIClientState.credentialOffer?.issuerState && {
1013
- 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
+ }
1014
1058
  },
1015
- ...presentationDuringIssuanceSession && {
1016
- presentationDuringIssuanceSession
1017
- }
1018
- });
1019
- }, "sendAuthorizationChallengeRequest");
1020
- var createConfig = /* @__PURE__ */ __name(async (args, context) => {
1021
- const { presentationUri } = args;
1022
- if (!presentationUri) {
1023
- return Promise.reject(Error("Missing presentation uri in context"));
1024
- }
1025
- return context.agent.siopCreateConfig({
1026
- url: presentationUri
1027
- });
1028
- }, "createConfig");
1029
- var getSiopRequest = /* @__PURE__ */ __name(async (args, context) => {
1030
- const { didAuthConfig, presentationUri } = args;
1031
- if (presentationUri === void 0) {
1032
- return Promise.reject(Error("Missing presentation uri in context"));
1033
- }
1034
- if (didAuthConfig === void 0) {
1035
- return Promise.reject(Error("Missing did auth config in context"));
1036
- }
1037
- return context.agent.siopGetSiopRequest({
1038
- didAuthConfig,
1039
- url: presentationUri
1040
- });
1041
- }, "getSiopRequest");
1042
- var sendAuthorizationResponse = /* @__PURE__ */ __name(async (args, context) => {
1043
- const { didAuthConfig, authorizationRequestData, selectedCredentials } = args;
1044
- const responseData = await context.agent.siopSendResponse({
1045
- authorizationRequestData,
1046
- selectedCredentials,
1047
- didAuthConfig,
1048
- isFirstParty: true
1049
- });
1050
- return responseData.body.presentation_during_issuance_session;
1051
- }, "sendAuthorizationResponse");
1052
-
1053
- // src/machines/firstPartyMachine.ts
1054
- var firstPartyMachineStates = {
1055
- [FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest]: {
1056
- id: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1057
- invoke: {
1058
- src: FirstPartyMachineServices.sendAuthorizationChallengeRequest,
1059
- onDone: {
1060
- target: FirstPartyMachineStateTypes.done,
1061
- actions: assign2({
1062
- authorizationCodeResponse: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationCodeResponse")
1063
- })
1064
- },
1065
- onError: [
1066
- {
1067
- target: FirstPartyMachineStateTypes.createConfig,
1068
- cond: /* @__PURE__ */ __name((_ctx, _event) => _event.data.error === AuthorizationChallengeError.insufficient_authorization, "cond"),
1069
- actions: assign2({
1070
- authSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data.auth_session, "authSession"),
1071
- presentationUri: /* @__PURE__ */ __name((_ctx, _event) => _event.data.presentation, "presentationUri")
1072
- })
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
+ }
1073
1078
  },
1074
- {
1075
- target: FirstPartyMachineStateTypes.error,
1076
- actions: assign2({
1077
- error: /* @__PURE__ */ __name((_ctx, _event) => ({
1078
- title: translate("oid4vci_machine_send_authorization_challenge_request_error_title"),
1079
- message: _event.data.message,
1080
- stack: _event.data.stack
1081
- }), "error")
1082
- })
1079
+ ...credentialDisplay.background_color && {
1080
+ color: credentialDisplay.background_color
1083
1081
  }
1084
- ]
1085
- }
1086
- },
1087
- [FirstPartyMachineStateTypes.createConfig]: {
1088
- id: FirstPartyMachineStateTypes.createConfig,
1089
- invoke: {
1090
- src: FirstPartyMachineServices.createConfig,
1091
- onDone: {
1092
- target: FirstPartyMachineStateTypes.getSiopRequest,
1093
- actions: assign2({
1094
- didAuthConfig: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "didAuthConfig")
1095
- })
1096
- },
1097
- onError: {
1098
- target: FirstPartyMachineStateTypes.error,
1099
- actions: assign2({
1100
- error: /* @__PURE__ */ __name((_ctx, _event) => ({
1101
- title: translate("oid4vci_machine_create_config_error_title"),
1102
- message: _event.data.message,
1103
- stack: _event.data.stack
1104
- }), "error")
1105
- })
1106
1082
  }
1107
1083
  }
1108
- },
1109
- [FirstPartyMachineStateTypes.getSiopRequest]: {
1110
- id: FirstPartyMachineStateTypes.getSiopRequest,
1111
- invoke: {
1112
- src: FirstPartyMachineServices.getSiopRequest,
1113
- onDone: {
1114
- target: FirstPartyMachineStateTypes.selectCredentials,
1115
- actions: assign2({
1116
- authorizationRequestData: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationRequestData")
1117
- })
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
1118
1101
  },
1119
- onError: {
1120
- target: FirstPartyMachineStateTypes.error,
1121
- actions: assign2({
1122
- error: /* @__PURE__ */ __name((_ctx, _event) => ({
1123
- title: translate("siopV2_machine_get_request_error_title"),
1124
- message: _event.data.message,
1125
- stack: _event.data.stack
1126
- }), "error")
1127
- })
1128
- }
1129
- }
1130
- },
1131
- [FirstPartyMachineStateTypes.selectCredentials]: {
1132
- id: FirstPartyMachineStateTypes.selectCredentials,
1133
- on: {
1134
- [FirstPartyMachineEvents.SET_SELECTED_CREDENTIALS]: {
1135
- actions: assign2({
1136
- selectedCredentials: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectedCredentials")
1137
- })
1138
- },
1139
- [FirstPartyMachineEvents.NEXT]: {
1140
- target: FirstPartyMachineStateTypes.sendAuthorizationResponse
1141
- },
1142
- [FirstPartyMachineEvents.DECLINE]: {
1143
- target: FirstPartyMachineStateTypes.declined
1144
- },
1145
- [FirstPartyMachineEvents.PREVIOUS]: {
1146
- target: FirstPartyMachineStateTypes.aborted
1147
- }
1148
- }
1149
- },
1150
- [FirstPartyMachineStateTypes.sendAuthorizationResponse]: {
1151
- id: FirstPartyMachineStateTypes.sendAuthorizationResponse,
1152
- invoke: {
1153
- src: FirstPartyMachineServices.sendAuthorizationResponse,
1154
- onDone: {
1155
- target: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1156
- actions: assign2({
1157
- presentationDuringIssuanceSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "presentationDuringIssuanceSession")
1158
- })
1159
- },
1160
- onError: {
1161
- target: FirstPartyMachineStateTypes.error,
1162
- actions: assign2({
1163
- error: /* @__PURE__ */ __name((_ctx, _event) => ({
1164
- title: translate("oid4vci_machine_get_request_error_title"),
1165
- message: _event.data.message,
1166
- stack: _event.data.stack
1167
- }), "error")
1168
- })
1169
- }
1170
- }
1171
- },
1172
- [FirstPartyMachineStateTypes.aborted]: {
1173
- id: FirstPartyMachineStateTypes.aborted,
1174
- type: "final"
1175
- },
1176
- [FirstPartyMachineStateTypes.declined]: {
1177
- id: FirstPartyMachineStateTypes.declined,
1178
- type: "final"
1179
- },
1180
- [FirstPartyMachineStateTypes.error]: {
1181
- id: FirstPartyMachineStateTypes.error,
1182
- type: "final"
1183
- },
1184
- [FirstPartyMachineStateTypes.done]: {
1185
- id: FirstPartyMachineStateTypes.done,
1186
- type: "final"
1187
- }
1188
- };
1189
- var createFirstPartyActivationMachine = /* @__PURE__ */ __name((opts) => {
1190
- const initialContext = {
1191
- openID4VCIClientState: opts.openID4VCIClientState,
1192
- contact: opts.contact,
1193
- selectedCredentials: []
1194
- };
1195
- return createMachine2({
1196
- id: opts?.machineId ?? "FirstParty",
1197
- predictableActionArguments: true,
1198
- initial: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1199
- context: initialContext,
1200
- states: firstPartyMachineStates,
1201
- schema: {
1202
- events: {},
1203
- services: {}
1204
- }
1205
- });
1206
- }, "createFirstPartyActivationMachine");
1207
- var FirstPartyMachine = class _FirstPartyMachine {
1208
- static {
1209
- __name(this, "FirstPartyMachine");
1210
- }
1211
- static _instance;
1212
- static hasInstance() {
1213
- return _FirstPartyMachine._instance !== void 0;
1214
- }
1215
- static get instance() {
1216
- if (!_FirstPartyMachine._instance) {
1217
- throw Error("Please initialize ESIMActivation machine first");
1218
- }
1219
- return _FirstPartyMachine._instance;
1220
- }
1221
- static clearInstance(opts) {
1222
- const { stop } = opts;
1223
- if (_FirstPartyMachine.hasInstance()) {
1224
- if (stop) {
1225
- _FirstPartyMachine.stopInstance();
1226
- }
1227
- }
1228
- _FirstPartyMachine._instance = void 0;
1229
- }
1230
- static stopInstance() {
1231
- if (!_FirstPartyMachine.hasInstance()) {
1232
- return;
1233
- }
1234
- _FirstPartyMachine.instance.stop();
1235
- _FirstPartyMachine._instance = void 0;
1236
- }
1237
- static newInstance(opts) {
1238
- const { agentContext } = opts;
1239
- const services = {
1240
- [FirstPartyMachineServices.sendAuthorizationChallengeRequest]: sendAuthorizationChallengeRequest,
1241
- [FirstPartyMachineServices.createConfig]: (args) => createConfig(args, agentContext),
1242
- [FirstPartyMachineServices.getSiopRequest]: (args) => getSiopRequest(args, agentContext),
1243
- [FirstPartyMachineServices.sendAuthorizationResponse]: (args) => sendAuthorizationResponse(args, agentContext)
1244
- };
1245
- const newInst = interpret2(createFirstPartyActivationMachine(opts).withConfig({
1246
- services: {
1247
- ...services,
1248
- ...opts?.services
1249
- },
1250
- guards: {
1251
- ...opts?.guards
1252
- }
1253
- }));
1254
- if (typeof opts?.subscription === "function") {
1255
- newInst.onTransition(opts.subscription);
1256
- }
1257
- if (opts?.requireCustomNavigationHook !== true) {
1258
- newInst.onTransition((snapshot) => {
1259
- if (opts?.stateNavigationListener) {
1260
- void opts.stateNavigationListener(newInst, snapshot);
1261
- }
1262
- });
1263
- }
1264
- return newInst;
1265
- }
1266
- static getInstance(opts) {
1267
- if (!_FirstPartyMachine._instance) {
1268
- if (opts?.requireExisting === true) {
1269
- throw Error(`Existing FirstPartyMachine instance requested, but none was created at this point!`);
1270
- }
1271
- _FirstPartyMachine._instance = _FirstPartyMachine.newInstance(opts);
1272
- }
1273
- return _FirstPartyMachine._instance;
1274
- }
1275
- };
1276
-
1277
- // src/mappers/OIDC4VCIBrandingMapper.ts
1278
- var oid4vciGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1279
- const { credentialDisplay, issuerCredentialSubject } = args;
1280
- return oid4vciCombineDisplayLocalesFrom({
1281
- ...issuerCredentialSubject && {
1282
- issuerCredentialSubjectLocales: await oid4vciIssuerCredentialSubjectLocalesFrom({
1283
- issuerCredentialSubject
1284
- })
1285
- },
1286
- ...credentialDisplay && {
1287
- credentialDisplayLocales: await oid4vciCredentialDisplayLocalesFrom({
1288
- credentialDisplay
1289
- })
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
+ })
1290
1118
  }
1291
1119
  });
1292
- }, "oid4vciGetCredentialBrandingFrom");
1293
- var oid4vciCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1120
+ }, "sdJwtGetCredentialBrandingFrom");
1121
+ var sdJwtCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1294
1122
  const { credentialDisplay } = args;
1295
1123
  return credentialDisplay.reduce((localeDisplays, display) => {
1296
- const localeKey = display.locale || "";
1124
+ const localeKey = display.lang || "";
1297
1125
  localeDisplays.set(localeKey, display);
1298
1126
  return localeDisplays;
1299
1127
  }, /* @__PURE__ */ new Map());
1300
- }, "oid4vciCredentialDisplayLocalesFrom");
1301
- var oid4vciIssuerCredentialSubjectLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1302
- const { issuerCredentialSubject } = args;
1128
+ }, "sdJwtCredentialDisplayLocalesFrom");
1129
+ var sdJwtCredentialClaimLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1130
+ const { claimsMetadata } = args;
1303
1131
  const localeClaims = /* @__PURE__ */ new Map();
1304
- const processClaimObject = /* @__PURE__ */ __name((claim, parentKey = "") => {
1305
- Object.entries(claim).forEach(([key, value]) => {
1306
- if (key === "mandatory" || key === "value_type") {
1307
- return;
1308
- }
1309
- if (key === "display" && Array.isArray(value)) {
1310
- value.forEach(({ name, locale = "" }) => {
1311
- if (!name) {
1312
- return;
1313
- }
1314
- if (!localeClaims.has(locale)) {
1315
- localeClaims.set(locale, []);
1316
- }
1317
- localeClaims.get(locale).push({
1318
- key: parentKey,
1319
- name
1320
- });
1321
- });
1322
- } else if (typeof value === "object" && value !== null) {
1323
- 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, []);
1324
1138
  }
1139
+ localeClaims.get(lang).push({
1140
+ key,
1141
+ name: label
1142
+ });
1325
1143
  });
1326
- }, "processClaimObject");
1327
- processClaimObject(issuerCredentialSubject);
1144
+ });
1328
1145
  return localeClaims;
1329
- }, "oid4vciIssuerCredentialSubjectLocalesFrom");
1330
- var oid4vciCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1146
+ }, "sdJwtCredentialClaimLocalesFrom");
1147
+ var sdJwtCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1331
1148
  const { credentialDisplay } = args;
1332
1149
  return {
1333
1150
  ...credentialDisplay.name && {
1334
1151
  alias: credentialDisplay.name
1335
1152
  },
1336
- ...credentialDisplay.locale && {
1337
- locale: credentialDisplay.locale
1153
+ ...credentialDisplay.lang && {
1154
+ locale: credentialDisplay.lang
1338
1155
  },
1339
- ...credentialDisplay.logo && {
1156
+ ...credentialDisplay.rendering?.simple?.logo && {
1340
1157
  logo: {
1341
- ...(credentialDisplay.logo.url || credentialDisplay.logo.uri) && {
1342
- uri: credentialDisplay.logo?.url ?? credentialDisplay.logo.uri
1158
+ ...credentialDisplay.rendering.simple.logo.uri && {
1159
+ uri: credentialDisplay.rendering.simple.logo.uri
1343
1160
  },
1344
- ...credentialDisplay.logo.alt_text && {
1345
- alt: credentialDisplay.logo?.alt_text
1161
+ ...credentialDisplay.rendering.simple.logo.alt_text && {
1162
+ alt: credentialDisplay.rendering.simple.logo.alt_text
1346
1163
  }
1347
1164
  }
1348
1165
  },
1349
1166
  ...credentialDisplay.description && {
1350
1167
  description: credentialDisplay.description
1351
1168
  },
1352
- ...credentialDisplay.text_color && {
1169
+ ...credentialDisplay.rendering?.simple?.text_color && {
1353
1170
  text: {
1354
- color: credentialDisplay.text_color
1171
+ color: credentialDisplay.rendering.simple.text_color
1355
1172
  }
1356
1173
  },
1357
- ...(credentialDisplay.background_image || credentialDisplay.background_color) && {
1174
+ ...credentialDisplay.rendering?.simple?.background_color && {
1358
1175
  background: {
1359
- ...credentialDisplay.background_image && {
1360
- image: {
1361
- ...(credentialDisplay.background_image.url || credentialDisplay.background_image.uri) && {
1362
- uri: credentialDisplay.background_image?.url ?? credentialDisplay.background_image.uri
1363
- },
1364
- ...credentialDisplay.background_image.alt_text && {
1365
- alt: credentialDisplay.background_image?.alt_text
1366
- }
1367
- }
1368
- },
1369
- ...credentialDisplay.background_color && {
1370
- color: credentialDisplay.background_color
1371
- }
1176
+ color: credentialDisplay.rendering.simple.background_color
1372
1177
  }
1373
1178
  }
1374
1179
  };
1375
- }, "oid4vciCredentialLocaleBrandingFrom");
1376
- var oid4vciCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1377
- 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;
1378
1183
  const locales = Array.from(/* @__PURE__ */ new Set([
1379
- ...issuerCredentialSubjectLocales.keys(),
1184
+ ...claimsMetadata.keys(),
1380
1185
  ...credentialDisplayLocales.keys()
1381
1186
  ]));
1382
1187
  return Promise.all(locales.map(async (locale) => {
1383
1188
  const display = credentialDisplayLocales.get(locale);
1384
- const claims = issuerCredentialSubjectLocales.get(locale);
1189
+ const claims = claimsMetadata.get(locale);
1385
1190
  return {
1386
- ...display && await oid4vciCredentialLocaleBrandingFrom({
1191
+ ...display && await sdJwtCredentialLocaleBrandingFrom({
1387
1192
  credentialDisplay: display
1388
1193
  }),
1389
1194
  ...locale.length > 0 && {
@@ -1392,157 +1197,348 @@ var oid4vciCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1392
1197
  claims
1393
1198
  };
1394
1199
  }));
1395
- }, "oid4vciCombineDisplayLocalesFrom");
1396
- var sdJwtGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1397
- const { credentialDisplay, claimsMetadata } = args;
1398
- return sdJwtCombineDisplayLocalesFrom({
1399
- ...claimsMetadata && {
1400
- claimsMetadata: await sdJwtCredentialClaimLocalesFrom({
1401
- claimsMetadata
1402
- })
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
1403
1206
  },
1404
- ...credentialDisplay && {
1405
- credentialDisplayLocales: await sdJwtCredentialDisplayLocalesFrom({
1406
- credentialDisplay
1407
- })
1408
- }
1409
- });
1410
- }, "sdJwtGetCredentialBrandingFrom");
1411
- var sdJwtCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1412
- const { credentialDisplay } = args;
1413
- return credentialDisplay.reduce((localeDisplays, display) => {
1414
- const localeKey = display.lang || "";
1415
- localeDisplays.set(localeKey, display);
1416
- return localeDisplays;
1417
- }, /* @__PURE__ */ new Map());
1418
- }, "sdJwtCredentialDisplayLocalesFrom");
1419
- var sdJwtCredentialClaimLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1420
- const { claimsMetadata } = args;
1421
- const localeClaims = /* @__PURE__ */ new Map();
1422
- claimsMetadata.forEach((claim) => {
1423
- claim.display?.forEach((display) => {
1424
- const { lang = "", label } = display;
1425
- const key = claim.path.map((value) => String(value)).join(".");
1426
- if (!localeClaims.has(lang)) {
1427
- 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
+ }
1428
1224
  }
1429
- localeClaims.get(lang).push({
1430
- key,
1431
- name: label
1432
- });
1433
- });
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
1434
1260
  });
1435
- return localeClaims;
1436
- }, "sdJwtCredentialClaimLocalesFrom");
1437
- var sdJwtCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1438
- const { credentialDisplay } = args;
1439
- return {
1440
- ...credentialDisplay.name && {
1441
- alias: credentialDisplay.name
1261
+ return oid4vciClient.acquireAuthorizationChallengeCode({
1262
+ clientId: oid4vciClient.clientId ?? uuidv4(),
1263
+ ...authSession && {
1264
+ authSession
1442
1265
  },
1443
- ...credentialDisplay.lang && {
1444
- locale: credentialDisplay.lang
1266
+ ...!authSession && openID4VCIClientState.credentialOffer?.preAuthorizedCode && {
1267
+ issuerState: openID4VCIClientState.credentialOffer?.preAuthorizedCode
1445
1268
  },
1446
- ...credentialDisplay.rendering?.simple?.logo && {
1447
- logo: {
1448
- ...credentialDisplay.rendering.simple.logo.uri && {
1449
- 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
+ })
1450
1330
  },
1451
- ...credentialDisplay.rendering.simple.logo.alt_text && {
1452
- 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
+ })
1453
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
+ })
1454
1363
  }
1455
- },
1456
- ...credentialDisplay.description && {
1457
- description: credentialDisplay.description
1458
- },
1459
- ...credentialDisplay.rendering?.simple?.text_color && {
1460
- text: {
1461
- 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
+ })
1462
1385
  }
1463
- },
1464
- ...credentialDisplay.rendering?.simple?.background_color && {
1465
- background: {
1466
- 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
1467
1404
  }
1468
1405
  }
1469
- };
1470
- }, "sdJwtCredentialLocaleBrandingFrom");
1471
- var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1472
- const { credentialDisplayLocales = /* @__PURE__ */ new Map(), claimsMetadata = /* @__PURE__ */ new Map() } = args;
1473
- const locales = Array.from(/* @__PURE__ */ new Set([
1474
- ...claimsMetadata.keys(),
1475
- ...credentialDisplayLocales.keys()
1476
- ]));
1477
- return Promise.all(locales.map(async (locale) => {
1478
- const display = credentialDisplayLocales.get(locale);
1479
- const claims = claimsMetadata.get(locale);
1480
- return {
1481
- ...display && await sdJwtCredentialLocaleBrandingFrom({
1482
- credentialDisplay: display
1483
- }),
1484
- ...locale.length > 0 && {
1485
- 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
+ })
1486
1416
  },
1487
- 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)
1488
1501
  };
1489
- }));
1490
- }, "sdJwtCombineDisplayLocalesFrom");
1491
- var issuerLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1492
- const { issuerDisplay, dynamicRegistrationClientMetadata } = args;
1493
- return {
1494
- ...dynamicRegistrationClientMetadata?.client_name && {
1495
- alias: dynamicRegistrationClientMetadata.client_name
1496
- },
1497
- ...issuerDisplay.name && {
1498
- alias: issuerDisplay.name
1499
- },
1500
- ...issuerDisplay.locale && {
1501
- locale: issuerDisplay.locale
1502
- },
1503
- ...(issuerDisplay.logo || dynamicRegistrationClientMetadata?.logo_uri) && {
1504
- logo: {
1505
- ...dynamicRegistrationClientMetadata?.logo_uri && {
1506
- uri: dynamicRegistrationClientMetadata?.logo_uri
1507
- },
1508
- ...(issuerDisplay.logo?.url || issuerDisplay.logo?.uri) && {
1509
- uri: issuerDisplay.logo?.url ?? issuerDisplay.logo?.uri
1510
- },
1511
- ...issuerDisplay.logo?.alt_text && {
1512
- alt: issuerDisplay.logo?.alt_text
1513
- }
1502
+ const newInst = interpret2(createFirstPartyActivationMachine(opts).withConfig({
1503
+ services: {
1504
+ ...services,
1505
+ ...opts?.services
1506
+ },
1507
+ guards: {
1508
+ ...opts?.guards
1514
1509
  }
1515
- },
1516
- ...issuerDisplay.description && {
1517
- description: issuerDisplay.description
1518
- },
1519
- ...issuerDisplay.text_color && {
1520
- text: {
1521
- 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!`);
1522
1527
  }
1523
- },
1524
- ...dynamicRegistrationClientMetadata?.client_uri && {
1525
- clientUri: dynamicRegistrationClientMetadata.client_uri
1526
- },
1527
- ...dynamicRegistrationClientMetadata?.tos_uri && {
1528
- tosUri: dynamicRegistrationClientMetadata.tos_uri
1529
- },
1530
- ...dynamicRegistrationClientMetadata?.policy_uri && {
1531
- policyUri: dynamicRegistrationClientMetadata.policy_uri
1532
- },
1533
- ...dynamicRegistrationClientMetadata?.contacts && {
1534
- contacts: dynamicRegistrationClientMetadata.contacts
1528
+ _FirstPartyMachine._instance = _FirstPartyMachine.newInstance(opts);
1535
1529
  }
1536
- };
1537
- }, "issuerLocaleBrandingFrom");
1530
+ return _FirstPartyMachine._instance;
1531
+ }
1532
+ };
1538
1533
 
1539
1534
  // src/services/OID4VCIHolderService.ts
1535
+ import { defaultHasher } from "@sphereon/ssi-sdk.core";
1540
1536
  var getCredentialBranding = /* @__PURE__ */ __name(async (args) => {
1541
1537
  const { credentialsSupported, context } = args;
1542
1538
  const credentialBranding = {};
1543
1539
  await Promise.all(Object.entries(credentialsSupported).map(async ([configId, credentialsConfigSupported]) => {
1544
1540
  let sdJwtTypeMetadata;
1545
- if (credentialsConfigSupported.format === "dc+sd-jwt") {
1541
+ if (credentialsConfigSupported.format === "vc+sd-jwt") {
1546
1542
  const vct = credentialsConfigSupported.vct;
1547
1543
  if (vct.startsWith("http")) {
1548
1544
  try {
@@ -1608,7 +1604,10 @@ var selectCredentialLocaleBranding = /* @__PURE__ */ __name(async (args) => {
1608
1604
  }, "selectCredentialLocaleBranding");
1609
1605
  var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1610
1606
  const { mappedCredential, hasher, onVerifyEBSICredentialIssuer, schemaValidation, context } = args;
1611
- 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
+ }
1612
1611
  const wrappedVC = CredentialMapper.toWrappedVerifiableCredential(credential, {
1613
1612
  hasher: hasher ?? defaultHasher
1614
1613
  });
@@ -1660,7 +1659,11 @@ var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1660
1659
  }, "verifyCredentialToAccept");
1661
1660
  var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1662
1661
  const { credentialToAccept, hasher } = args;
1663
- 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
+ }
1664
1667
  const wrappedVerifiableCredential = CredentialMapper.toWrappedVerifiableCredential(verifiableCredential, {
1665
1668
  hasher
1666
1669
  });
@@ -1680,7 +1683,6 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1680
1683
  uniformVerifiableCredential = wrappedVerifiableCredential.credential;
1681
1684
  }
1682
1685
  const correlationId = typeof uniformVerifiableCredential.issuer === "string" ? uniformVerifiableCredential.issuer : CredentialMapper.isSdJwtDecodedCredential(uniformVerifiableCredential) ? uniformVerifiableCredential.decodedPayload.iss : uniformVerifiableCredential.issuer.id;
1683
- const credentialResponse = credentialToAccept.credentialResponse;
1684
1686
  return {
1685
1687
  correlationId,
1686
1688
  credentialToAccept,
@@ -1692,18 +1694,6 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1692
1694
  }
1693
1695
  };
1694
1696
  }, "mapCredentialToAccept");
1695
- var extractCredentialFromResponse = /* @__PURE__ */ __name((credentialResponse) => {
1696
- let credential;
1697
- if ("credential" in credentialResponse) {
1698
- credential = credentialResponse.credential;
1699
- } else if ("credentials" in credentialResponse && credentialResponse.credentials && Array.isArray(credentialResponse.credentials) && credentialResponse.credentials.length > 0) {
1700
- credential = credentialResponse.credentials[0].credential;
1701
- }
1702
- if (!credential) {
1703
- throw new Error("No credential found in credential response");
1704
- }
1705
- return credential;
1706
- }, "extractCredentialFromResponse");
1707
1697
  var getIdentifierOpts = /* @__PURE__ */ __name(async (args) => {
1708
1698
  const { issuanceOpt, context } = args;
1709
1699
  const { identifier: identifierArg } = issuanceOpt;
@@ -1812,19 +1802,24 @@ var getCredentialConfigsSupportedBySingleTypeOrId = /* @__PURE__ */ __name(async
1812
1802
  }
1813
1803
  __name(createIdFromTypes, "createIdFromTypes");
1814
1804
  if (configurationId) {
1815
- const allSupported2 = client.getCredentialsSupported(format);
1805
+ const allSupported2 = client.getCredentialsSupported(false);
1816
1806
  return Object.fromEntries(Object.entries(allSupported2).filter(([id, supported]) => id === configurationId || supported.id === configurationId || createIdFromTypes(supported) === configurationId));
1817
1807
  }
1818
- if (!client.credentialOffer) {
1819
- return Promise.reject(Error("openID4VCIClient has no credentialOffer"));
1808
+ if (!types && !client.credentialOffer) {
1809
+ return Promise.reject(Error("openID4VCIClient has no credentialOffer and no types where provided"));
1820
1810
  }
1821
- if (!types) {
1822
- return Promise.reject(Error("openID4VCIClient has no types"));
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
+ }
1823
1818
  }
1824
1819
  const offerSupported = getSupportedCredentials({
1825
- types: [
1820
+ types: types ? [
1826
1821
  types
1827
- ],
1822
+ ] : client.getCredentialOfferTypes(),
1828
1823
  format,
1829
1824
  version: client.version(),
1830
1825
  issuerMetadata: client.endpointMetadata.credentialIssuerMetadata
@@ -1999,8 +1994,7 @@ var getIssuanceCryptoSuite = /* @__PURE__ */ __name(async (opts) => {
1999
1994
  case "jwt":
2000
1995
  case "jwt_vc_json":
2001
1996
  case "jwt_vc":
2002
- //case 'vc+sd-jwt': // TODO see SSISDK-52 concerning vc+sd-jwt
2003
- case "dc+sd-jwt":
1997
+ case "vc+sd-jwt":
2004
1998
  case "mso_mdoc": {
2005
1999
  const supportedPreferences = jwtCryptographicSuitePreferences.filter((suite) => signing_algs_supported.includes(suite));
2006
2000
  if (supportedPreferences.length > 0) {
@@ -2068,6 +2062,8 @@ var startFirstPartApplicationMachine = /* @__PURE__ */ __name(async (args, conte
2068
2062
  }, "startFirstPartApplicationMachine");
2069
2063
 
2070
2064
  // src/agent/OID4VCIHolder.ts
2065
+ import "cross-fetch/polyfill";
2066
+ import { defaultHasher as defaultHasher2 } from "@sphereon/ssi-sdk.core";
2071
2067
  var oid4vciHolderContextMethods = [
2072
2068
  "cmGetContacts",
2073
2069
  "cmGetContact",
@@ -2083,7 +2079,7 @@ var oid4vciHolderContextMethods = [
2083
2079
  ];
2084
2080
  var logger = Loggers.DEFAULT.get("sphereon:oid4vci:holder");
2085
2081
  function signCallback(identifier, context, nonce) {
2086
- return async (jwt, kid, noIssPayloadUpdate) => {
2082
+ return async (jwt, kid) => {
2087
2083
  let resolution = await context.agent.identifierManagedGet(identifier);
2088
2084
  const jwk = jwt.header.jwk ?? (resolution.method === "jwk" ? resolution.jwk : void 0);
2089
2085
  if (!resolution.issuer && !jwt.payload.iss) {
@@ -2101,7 +2097,7 @@ function signCallback(identifier, context, nonce) {
2101
2097
  return (await context.agent.jwtCreateJwsCompactSignature({
2102
2098
  issuer: {
2103
2099
  ...resolution,
2104
- noIssPayloadUpdate: noIssPayloadUpdate ?? false
2100
+ noIssPayloadUpdate: false
2105
2101
  },
2106
2102
  protectedHeader: header,
2107
2103
  payload
@@ -2136,7 +2132,6 @@ var OID4VCIHolder = class _OID4VCIHolder {
2136
2132
  oid4vciHolderStoreIssuerBranding: this.oid4vciHolderStoreIssuerBranding.bind(this)
2137
2133
  };
2138
2134
  vcFormatPreferences = [
2139
- "dc+sd-jwt",
2140
2135
  "vc+sd-jwt",
2141
2136
  "mso_mdoc",
2142
2137
  "jwt_vc_json",
@@ -2288,6 +2283,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2288
2283
  formats = Array.from(new Set(authFormats));
2289
2284
  }
2290
2285
  let oid4vciClient;
2286
+ let types = void 0;
2291
2287
  let offer;
2292
2288
  if (requestData.existingClientState) {
2293
2289
  oid4vciClient = await OpenID4VCIClient2.fromState({
@@ -2323,18 +2319,17 @@ var OID4VCIHolder = class _OID4VCIHolder {
2323
2319
  });
2324
2320
  }
2325
2321
  }
2326
- let configurationIds = [];
2327
2322
  if (offer) {
2328
- configurationIds = offer.original_credential_offer.credential_configuration_ids;
2323
+ types = getTypesFromCredentialOffer(offer.original_credential_offer);
2329
2324
  } else {
2330
- configurationIds = asArray2(authorizationRequestOpts.authorizationDetails).filter((authDetails) => typeof authDetails !== "string").map((authReqOpts) => authReqOpts.credential_configuration_id).filter((id) => !!id);
2325
+ types = asArray2(authorizationRequestOpts.authorizationDetails).map((authReqOpts) => getTypesFromAuthorizationDetails(authReqOpts) ?? []).filter((inner) => inner.length > 0);
2331
2326
  }
2327
+ const serverMetadata = await oid4vciClient.retrieveServerMetadata();
2332
2328
  const credentialsSupported = await getCredentialConfigsSupportedMerged({
2333
2329
  client: oid4vciClient,
2334
2330
  vcFormatPreferences: formats,
2335
- configurationIds
2331
+ types
2336
2332
  });
2337
- const serverMetadata = await oid4vciClient.retrieveServerMetadata();
2338
2333
  const credentialBranding = await getCredentialBranding({
2339
2334
  credentialsSupported,
2340
2335
  context
@@ -2723,7 +2718,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2723
2718
  if (Array.isArray(subjectIssuance?.notification_events_supported)) {
2724
2719
  event = subjectIssuance.notification_events_supported.includes("credential_accepted_holder_signed") ? "credential_accepted_holder_signed" : "credential_deleted_holder_signed";
2725
2720
  logger.log(`Subject issuance/signing will be used, with event`, event);
2726
- const issuerVC = extractCredentialFromResponse(mappedCredentialToAccept.credentialToAccept.credentialResponse);
2721
+ const issuerVC = mappedCredentialToAccept.credentialToAccept.credentialResponse.credential;
2727
2722
  const wrappedIssuerVC = CredentialMapper2.toWrappedVerifiableCredential(issuerVC, {
2728
2723
  hasher: this.hasher ?? defaultHasher2
2729
2724
  });
@@ -3094,7 +3089,6 @@ export {
3094
3089
  RequestType,
3095
3090
  SupportedLanguage,
3096
3091
  createConfig,
3097
- extractCredentialFromResponse,
3098
3092
  getBasicIssuerLocaleBranding,
3099
3093
  getCredentialBranding,
3100
3094
  getCredentialConfigsBasedOnFormatPref,