@sphereon/ssi-sdk.oid4vci-holder 0.34.1-feature.SSISDK.26.RP.58 → 0.34.1-feature.SSISDK.45.189

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.cjs CHANGED
@@ -100,6 +100,7 @@ __export(index_exports, {
100
100
  RequestType: () => RequestType,
101
101
  SupportedLanguage: () => SupportedLanguage,
102
102
  createConfig: () => createConfig,
103
+ extractCredentialFromResponse: () => extractCredentialFromResponse,
103
104
  getBasicIssuerLocaleBranding: () => getBasicIssuerLocaleBranding,
104
105
  getCredentialBranding: () => getCredentialBranding,
105
106
  getCredentialConfigsBasedOnFormatPref: () => getCredentialConfigsBasedOnFormatPref,
@@ -155,18 +156,18 @@ var import_i18n_js = __toESM(require("i18n-js"), 1);
155
156
  var import_lodash = __toESM(require("lodash.memoize"), 1);
156
157
 
157
158
  // src/types/IOID4VCIHolder.ts
158
- var OID4VCIHolderEvent = /* @__PURE__ */ function(OID4VCIHolderEvent2) {
159
+ var OID4VCIHolderEvent = /* @__PURE__ */ (function(OID4VCIHolderEvent2) {
159
160
  OID4VCIHolderEvent2["CONTACT_IDENTITY_CREATED"] = "contact_identity_created";
160
161
  OID4VCIHolderEvent2["CREDENTIAL_STORED"] = "credential_stored";
161
162
  OID4VCIHolderEvent2["IDENTIFIER_CREATED"] = "identifier_created";
162
163
  return OID4VCIHolderEvent2;
163
- }({});
164
- var SupportedLanguage = /* @__PURE__ */ function(SupportedLanguage2) {
164
+ })({});
165
+ var SupportedLanguage = /* @__PURE__ */ (function(SupportedLanguage2) {
165
166
  SupportedLanguage2["ENGLISH"] = "en";
166
167
  SupportedLanguage2["DUTCH"] = "nl";
167
168
  return SupportedLanguage2;
168
- }({});
169
- var OID4VCIMachineStates = /* @__PURE__ */ function(OID4VCIMachineStates2) {
169
+ })({});
170
+ var OID4VCIMachineStates = /* @__PURE__ */ (function(OID4VCIMachineStates2) {
170
171
  OID4VCIMachineStates2["start"] = "start";
171
172
  OID4VCIMachineStates2["createCredentialsToSelectFrom"] = "createCredentialsToSelectFrom";
172
173
  OID4VCIMachineStates2["getContact"] = "getContact";
@@ -197,18 +198,18 @@ var OID4VCIMachineStates = /* @__PURE__ */ function(OID4VCIMachineStates2) {
197
198
  OID4VCIMachineStates2["error"] = "error";
198
199
  OID4VCIMachineStates2["done"] = "done";
199
200
  return OID4VCIMachineStates2;
200
- }({});
201
- var OID4VCIMachineAddContactStates = /* @__PURE__ */ function(OID4VCIMachineAddContactStates2) {
201
+ })({});
202
+ var OID4VCIMachineAddContactStates = /* @__PURE__ */ (function(OID4VCIMachineAddContactStates2) {
202
203
  OID4VCIMachineAddContactStates2["idle"] = "idle";
203
204
  OID4VCIMachineAddContactStates2["next"] = "next";
204
205
  return OID4VCIMachineAddContactStates2;
205
- }({});
206
- var OID4VCIMachineVerifyPinStates = /* @__PURE__ */ function(OID4VCIMachineVerifyPinStates2) {
206
+ })({});
207
+ var OID4VCIMachineVerifyPinStates = /* @__PURE__ */ (function(OID4VCIMachineVerifyPinStates2) {
207
208
  OID4VCIMachineVerifyPinStates2["idle"] = "idle";
208
209
  OID4VCIMachineVerifyPinStates2["next"] = "next";
209
210
  return OID4VCIMachineVerifyPinStates2;
210
- }({});
211
- var OID4VCIMachineEvents = /* @__PURE__ */ function(OID4VCIMachineEvents2) {
211
+ })({});
212
+ var OID4VCIMachineEvents = /* @__PURE__ */ (function(OID4VCIMachineEvents2) {
212
213
  OID4VCIMachineEvents2["NEXT"] = "NEXT";
213
214
  OID4VCIMachineEvents2["PREVIOUS"] = "PREVIOUS";
214
215
  OID4VCIMachineEvents2["DECLINE"] = "DECLINE";
@@ -221,8 +222,8 @@ var OID4VCIMachineEvents = /* @__PURE__ */ function(OID4VCIMachineEvents2) {
221
222
  OID4VCIMachineEvents2["INVOKED_AUTHORIZATION_CODE_REQUEST"] = "INVOKED_AUTHORIZATION_CODE_REQUEST";
222
223
  OID4VCIMachineEvents2["PROVIDE_AUTHORIZATION_CODE_RESPONSE"] = "PROVIDE_AUTHORIZATION_CODE_RESPONSE";
223
224
  return OID4VCIMachineEvents2;
224
- }({});
225
- var OID4VCIMachineGuards = /* @__PURE__ */ function(OID4VCIMachineGuards2) {
225
+ })({});
226
+ var OID4VCIMachineGuards = /* @__PURE__ */ (function(OID4VCIMachineGuards2) {
226
227
  OID4VCIMachineGuards2["hasContactGuard"] = "oid4vciHasContactGuard";
227
228
  OID4VCIMachineGuards2["hasNoContactGuard"] = "oid4vciHasNoContactGuard";
228
229
  OID4VCIMachineGuards2["credentialsToSelectRequiredGuard"] = "oid4vciCredentialsToSelectRequiredGuard";
@@ -239,8 +240,8 @@ var OID4VCIMachineGuards = /* @__PURE__ */ function(OID4VCIMachineGuards2) {
239
240
  OID4VCIMachineGuards2["contactHasLowTrustGuard"] = "oid4vciContactHasLowTrustGuard";
240
241
  OID4VCIMachineGuards2["isFirstPartyApplication"] = "oid4vciIsFirstPartyApplication";
241
242
  return OID4VCIMachineGuards2;
242
- }({});
243
- var OID4VCIMachineServices = /* @__PURE__ */ function(OID4VCIMachineServices2) {
243
+ })({});
244
+ var OID4VCIMachineServices = /* @__PURE__ */ (function(OID4VCIMachineServices2) {
244
245
  OID4VCIMachineServices2["start"] = "start";
245
246
  OID4VCIMachineServices2["getContact"] = "getContact";
246
247
  OID4VCIMachineServices2["getFederationTrust"] = "getFederationTrust";
@@ -255,17 +256,17 @@ var OID4VCIMachineServices = /* @__PURE__ */ function(OID4VCIMachineServices2) {
255
256
  OID4VCIMachineServices2["storeCredentials"] = "storeCredentials";
256
257
  OID4VCIMachineServices2["startFirstPartApplicationFlow"] = "startFirstPartApplicationFlow";
257
258
  return OID4VCIMachineServices2;
258
- }({});
259
- var RequestType = /* @__PURE__ */ function(RequestType2) {
259
+ })({});
260
+ var RequestType = /* @__PURE__ */ (function(RequestType2) {
260
261
  RequestType2["OPENID_INITIATE_ISSUANCE"] = "openid-initiate-issuance";
261
262
  RequestType2["OPENID_CREDENTIAL_OFFER"] = "openid-credential-offer";
262
263
  RequestType2["URL"] = "URL";
263
264
  return RequestType2;
264
- }({});
265
- var IdentifierAliasEnum = /* @__PURE__ */ function(IdentifierAliasEnum2) {
265
+ })({});
266
+ var IdentifierAliasEnum = /* @__PURE__ */ (function(IdentifierAliasEnum2) {
266
267
  IdentifierAliasEnum2["PRIMARY"] = "primary";
267
268
  return IdentifierAliasEnum2;
268
- }({});
269
+ })({});
269
270
 
270
271
  // src/localization/Localization.ts
271
272
  var Localization = class Localization2 {
@@ -307,7 +308,7 @@ var Localization = class Localization2 {
307
308
  var translate = Localization.translate;
308
309
 
309
310
  // src/types/FirstPartyMachine.ts
310
- var FirstPartyMachineStateTypes = /* @__PURE__ */ function(FirstPartyMachineStateTypes2) {
311
+ var FirstPartyMachineStateTypes = /* @__PURE__ */ (function(FirstPartyMachineStateTypes2) {
311
312
  FirstPartyMachineStateTypes2["sendAuthorizationChallengeRequest"] = "sendAuthorizationChallengeRequest";
312
313
  FirstPartyMachineStateTypes2["sendAuthorizationResponse"] = "sendAuthorizationResponse";
313
314
  FirstPartyMachineStateTypes2["selectCredentials"] = "selectCredentials";
@@ -318,21 +319,21 @@ var FirstPartyMachineStateTypes = /* @__PURE__ */ function(FirstPartyMachineStat
318
319
  FirstPartyMachineStateTypes2["aborted"] = "aborted";
319
320
  FirstPartyMachineStateTypes2["declined"] = "declined";
320
321
  return FirstPartyMachineStateTypes2;
321
- }({});
322
- var FirstPartyMachineServices = /* @__PURE__ */ function(FirstPartyMachineServices2) {
322
+ })({});
323
+ var FirstPartyMachineServices = /* @__PURE__ */ (function(FirstPartyMachineServices2) {
323
324
  FirstPartyMachineServices2["sendAuthorizationChallengeRequest"] = "sendAuthorizationChallengeRequest";
324
325
  FirstPartyMachineServices2["sendAuthorizationResponse"] = "sendAuthorizationResponse";
325
326
  FirstPartyMachineServices2["createConfig"] = "createConfig";
326
327
  FirstPartyMachineServices2["getSiopRequest"] = "getSiopRequest";
327
328
  return FirstPartyMachineServices2;
328
- }({});
329
- var FirstPartyMachineEvents = /* @__PURE__ */ function(FirstPartyMachineEvents2) {
329
+ })({});
330
+ var FirstPartyMachineEvents = /* @__PURE__ */ (function(FirstPartyMachineEvents2) {
330
331
  FirstPartyMachineEvents2["NEXT"] = "NEXT";
331
332
  FirstPartyMachineEvents2["PREVIOUS"] = "PREVIOUS";
332
333
  FirstPartyMachineEvents2["DECLINE"] = "DECLINE";
333
334
  FirstPartyMachineEvents2["SET_SELECTED_CREDENTIALS"] = "SET_SELECTED_CREDENTIALS";
334
335
  return FirstPartyMachineEvents2;
335
- }({});
336
+ })({});
336
337
 
337
338
  // src/machines/oid4vciMachine.ts
338
339
  var oid4vciHasNoContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
@@ -1062,9 +1063,295 @@ var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.did-resolver-jwk");
1062
1063
  var import_ssi_sdk_ext2 = require("@sphereon/ssi-sdk-ext.did-utils");
1063
1064
  var import_ssi_sdk_ext3 = require("@sphereon/ssi-sdk-ext.identifier-resolution");
1064
1065
  var import_ssi_sdk_ext4 = require("@sphereon/ssi-sdk-ext.key-utils");
1066
+ var import_ssi_sdk = require("@sphereon/ssi-sdk.core");
1065
1067
  var import_ssi_types = require("@sphereon/ssi-types");
1066
1068
  var import_utils = require("@veramo/utils");
1067
1069
 
1070
+ // src/machines/firstPartyMachine.ts
1071
+ var import_xstate2 = require("xstate");
1072
+ var import_oid4vci_common2 = require("@sphereon/oid4vci-common");
1073
+
1074
+ // src/services/FirstPartyMachineServices.ts
1075
+ var import_oid4vci_client = require("@sphereon/oid4vci-client");
1076
+ var import_uuid = require("uuid");
1077
+ var sendAuthorizationChallengeRequest = /* @__PURE__ */ __name(async (args) => {
1078
+ const { openID4VCIClientState, authSession, presentationDuringIssuanceSession } = args;
1079
+ const oid4vciClient = await import_oid4vci_client.OpenID4VCIClient.fromState({
1080
+ state: openID4VCIClientState
1081
+ });
1082
+ return oid4vciClient.acquireAuthorizationChallengeCode({
1083
+ clientId: oid4vciClient.clientId ?? (0, import_uuid.v4)(),
1084
+ ...authSession && {
1085
+ authSession
1086
+ },
1087
+ ...!authSession && openID4VCIClientState.credentialOffer?.preAuthorizedCode && {
1088
+ issuerState: openID4VCIClientState.credentialOffer?.preAuthorizedCode
1089
+ },
1090
+ ...!authSession && openID4VCIClientState.credentialOffer?.issuerState && {
1091
+ issuerState: openID4VCIClientState.credentialOffer?.issuerState
1092
+ },
1093
+ ...presentationDuringIssuanceSession && {
1094
+ presentationDuringIssuanceSession
1095
+ }
1096
+ });
1097
+ }, "sendAuthorizationChallengeRequest");
1098
+ var createConfig = /* @__PURE__ */ __name(async (args, context) => {
1099
+ const { presentationUri } = args;
1100
+ if (!presentationUri) {
1101
+ return Promise.reject(Error("Missing presentation uri in context"));
1102
+ }
1103
+ return context.agent.siopCreateConfig({
1104
+ url: presentationUri
1105
+ });
1106
+ }, "createConfig");
1107
+ var getSiopRequest = /* @__PURE__ */ __name(async (args, context) => {
1108
+ const { didAuthConfig, presentationUri } = args;
1109
+ if (presentationUri === void 0) {
1110
+ return Promise.reject(Error("Missing presentation uri in context"));
1111
+ }
1112
+ if (didAuthConfig === void 0) {
1113
+ return Promise.reject(Error("Missing did auth config in context"));
1114
+ }
1115
+ return context.agent.siopGetSiopRequest({
1116
+ didAuthConfig,
1117
+ url: presentationUri
1118
+ });
1119
+ }, "getSiopRequest");
1120
+ var sendAuthorizationResponse = /* @__PURE__ */ __name(async (args, context) => {
1121
+ const { didAuthConfig, authorizationRequestData, selectedCredentials } = args;
1122
+ const responseData = await context.agent.siopSendResponse({
1123
+ authorizationRequestData,
1124
+ selectedCredentials,
1125
+ didAuthConfig,
1126
+ isFirstParty: true
1127
+ });
1128
+ return responseData.body.presentation_during_issuance_session;
1129
+ }, "sendAuthorizationResponse");
1130
+
1131
+ // src/machines/firstPartyMachine.ts
1132
+ var firstPartyMachineStates = {
1133
+ [FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest]: {
1134
+ id: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1135
+ invoke: {
1136
+ src: FirstPartyMachineServices.sendAuthorizationChallengeRequest,
1137
+ onDone: {
1138
+ target: FirstPartyMachineStateTypes.done,
1139
+ actions: (0, import_xstate2.assign)({
1140
+ authorizationCodeResponse: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationCodeResponse")
1141
+ })
1142
+ },
1143
+ onError: [
1144
+ {
1145
+ target: FirstPartyMachineStateTypes.createConfig,
1146
+ cond: /* @__PURE__ */ __name((_ctx, _event) => _event.data.error === import_oid4vci_common2.AuthorizationChallengeError.insufficient_authorization, "cond"),
1147
+ actions: (0, import_xstate2.assign)({
1148
+ authSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data.auth_session, "authSession"),
1149
+ presentationUri: /* @__PURE__ */ __name((_ctx, _event) => _event.data.presentation, "presentationUri")
1150
+ })
1151
+ },
1152
+ {
1153
+ target: FirstPartyMachineStateTypes.error,
1154
+ actions: (0, import_xstate2.assign)({
1155
+ error: /* @__PURE__ */ __name((_ctx, _event) => ({
1156
+ title: translate("oid4vci_machine_send_authorization_challenge_request_error_title"),
1157
+ message: _event.data.message,
1158
+ stack: _event.data.stack
1159
+ }), "error")
1160
+ })
1161
+ }
1162
+ ]
1163
+ }
1164
+ },
1165
+ [FirstPartyMachineStateTypes.createConfig]: {
1166
+ id: FirstPartyMachineStateTypes.createConfig,
1167
+ invoke: {
1168
+ src: FirstPartyMachineServices.createConfig,
1169
+ onDone: {
1170
+ target: FirstPartyMachineStateTypes.getSiopRequest,
1171
+ actions: (0, import_xstate2.assign)({
1172
+ didAuthConfig: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "didAuthConfig")
1173
+ })
1174
+ },
1175
+ onError: {
1176
+ target: FirstPartyMachineStateTypes.error,
1177
+ actions: (0, import_xstate2.assign)({
1178
+ error: /* @__PURE__ */ __name((_ctx, _event) => ({
1179
+ title: translate("oid4vci_machine_create_config_error_title"),
1180
+ message: _event.data.message,
1181
+ stack: _event.data.stack
1182
+ }), "error")
1183
+ })
1184
+ }
1185
+ }
1186
+ },
1187
+ [FirstPartyMachineStateTypes.getSiopRequest]: {
1188
+ id: FirstPartyMachineStateTypes.getSiopRequest,
1189
+ invoke: {
1190
+ src: FirstPartyMachineServices.getSiopRequest,
1191
+ onDone: {
1192
+ target: FirstPartyMachineStateTypes.selectCredentials,
1193
+ actions: (0, import_xstate2.assign)({
1194
+ authorizationRequestData: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationRequestData")
1195
+ })
1196
+ },
1197
+ onError: {
1198
+ target: FirstPartyMachineStateTypes.error,
1199
+ actions: (0, import_xstate2.assign)({
1200
+ error: /* @__PURE__ */ __name((_ctx, _event) => ({
1201
+ title: translate("siopV2_machine_get_request_error_title"),
1202
+ message: _event.data.message,
1203
+ stack: _event.data.stack
1204
+ }), "error")
1205
+ })
1206
+ }
1207
+ }
1208
+ },
1209
+ [FirstPartyMachineStateTypes.selectCredentials]: {
1210
+ id: FirstPartyMachineStateTypes.selectCredentials,
1211
+ on: {
1212
+ [FirstPartyMachineEvents.SET_SELECTED_CREDENTIALS]: {
1213
+ actions: (0, import_xstate2.assign)({
1214
+ selectedCredentials: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectedCredentials")
1215
+ })
1216
+ },
1217
+ [FirstPartyMachineEvents.NEXT]: {
1218
+ target: FirstPartyMachineStateTypes.sendAuthorizationResponse
1219
+ },
1220
+ [FirstPartyMachineEvents.DECLINE]: {
1221
+ target: FirstPartyMachineStateTypes.declined
1222
+ },
1223
+ [FirstPartyMachineEvents.PREVIOUS]: {
1224
+ target: FirstPartyMachineStateTypes.aborted
1225
+ }
1226
+ }
1227
+ },
1228
+ [FirstPartyMachineStateTypes.sendAuthorizationResponse]: {
1229
+ id: FirstPartyMachineStateTypes.sendAuthorizationResponse,
1230
+ invoke: {
1231
+ src: FirstPartyMachineServices.sendAuthorizationResponse,
1232
+ onDone: {
1233
+ target: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1234
+ actions: (0, import_xstate2.assign)({
1235
+ presentationDuringIssuanceSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "presentationDuringIssuanceSession")
1236
+ })
1237
+ },
1238
+ onError: {
1239
+ target: FirstPartyMachineStateTypes.error,
1240
+ actions: (0, import_xstate2.assign)({
1241
+ error: /* @__PURE__ */ __name((_ctx, _event) => ({
1242
+ title: translate("oid4vci_machine_get_request_error_title"),
1243
+ message: _event.data.message,
1244
+ stack: _event.data.stack
1245
+ }), "error")
1246
+ })
1247
+ }
1248
+ }
1249
+ },
1250
+ [FirstPartyMachineStateTypes.aborted]: {
1251
+ id: FirstPartyMachineStateTypes.aborted,
1252
+ type: "final"
1253
+ },
1254
+ [FirstPartyMachineStateTypes.declined]: {
1255
+ id: FirstPartyMachineStateTypes.declined,
1256
+ type: "final"
1257
+ },
1258
+ [FirstPartyMachineStateTypes.error]: {
1259
+ id: FirstPartyMachineStateTypes.error,
1260
+ type: "final"
1261
+ },
1262
+ [FirstPartyMachineStateTypes.done]: {
1263
+ id: FirstPartyMachineStateTypes.done,
1264
+ type: "final"
1265
+ }
1266
+ };
1267
+ var createFirstPartyActivationMachine = /* @__PURE__ */ __name((opts) => {
1268
+ const initialContext = {
1269
+ openID4VCIClientState: opts.openID4VCIClientState,
1270
+ contact: opts.contact,
1271
+ selectedCredentials: []
1272
+ };
1273
+ return (0, import_xstate2.createMachine)({
1274
+ id: opts?.machineId ?? "FirstParty",
1275
+ predictableActionArguments: true,
1276
+ initial: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1277
+ context: initialContext,
1278
+ states: firstPartyMachineStates,
1279
+ schema: {
1280
+ events: {},
1281
+ services: {}
1282
+ }
1283
+ });
1284
+ }, "createFirstPartyActivationMachine");
1285
+ var FirstPartyMachine = class _FirstPartyMachine {
1286
+ static {
1287
+ __name(this, "FirstPartyMachine");
1288
+ }
1289
+ static _instance;
1290
+ static hasInstance() {
1291
+ return _FirstPartyMachine._instance !== void 0;
1292
+ }
1293
+ static get instance() {
1294
+ if (!_FirstPartyMachine._instance) {
1295
+ throw Error("Please initialize ESIMActivation machine first");
1296
+ }
1297
+ return _FirstPartyMachine._instance;
1298
+ }
1299
+ static clearInstance(opts) {
1300
+ const { stop } = opts;
1301
+ if (_FirstPartyMachine.hasInstance()) {
1302
+ if (stop) {
1303
+ _FirstPartyMachine.stopInstance();
1304
+ }
1305
+ }
1306
+ _FirstPartyMachine._instance = void 0;
1307
+ }
1308
+ static stopInstance() {
1309
+ if (!_FirstPartyMachine.hasInstance()) {
1310
+ return;
1311
+ }
1312
+ _FirstPartyMachine.instance.stop();
1313
+ _FirstPartyMachine._instance = void 0;
1314
+ }
1315
+ static newInstance(opts) {
1316
+ const { agentContext } = opts;
1317
+ const services = {
1318
+ [FirstPartyMachineServices.sendAuthorizationChallengeRequest]: sendAuthorizationChallengeRequest,
1319
+ [FirstPartyMachineServices.createConfig]: (args) => createConfig(args, agentContext),
1320
+ [FirstPartyMachineServices.getSiopRequest]: (args) => getSiopRequest(args, agentContext),
1321
+ [FirstPartyMachineServices.sendAuthorizationResponse]: (args) => sendAuthorizationResponse(args, agentContext)
1322
+ };
1323
+ const newInst = (0, import_xstate2.interpret)(createFirstPartyActivationMachine(opts).withConfig({
1324
+ services: {
1325
+ ...services,
1326
+ ...opts?.services
1327
+ },
1328
+ guards: {
1329
+ ...opts?.guards
1330
+ }
1331
+ }));
1332
+ if (typeof opts?.subscription === "function") {
1333
+ newInst.onTransition(opts.subscription);
1334
+ }
1335
+ if (opts?.requireCustomNavigationHook !== true) {
1336
+ newInst.onTransition((snapshot) => {
1337
+ if (opts?.stateNavigationListener) {
1338
+ void opts.stateNavigationListener(newInst, snapshot);
1339
+ }
1340
+ });
1341
+ }
1342
+ return newInst;
1343
+ }
1344
+ static getInstance(opts) {
1345
+ if (!_FirstPartyMachine._instance) {
1346
+ if (opts?.requireExisting === true) {
1347
+ throw Error(`Existing FirstPartyMachine instance requested, but none was created at this point!`);
1348
+ }
1349
+ _FirstPartyMachine._instance = _FirstPartyMachine.newInstance(opts);
1350
+ }
1351
+ return _FirstPartyMachine._instance;
1352
+ }
1353
+ };
1354
+
1068
1355
  // src/mappers/OIDC4VCIBrandingMapper.ts
1069
1356
  var oid4vciGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1070
1357
  const { credentialDisplay, issuerCredentialSubject } = args;
@@ -1229,391 +1516,105 @@ var sdJwtCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1229
1516
  const { credentialDisplay } = args;
1230
1517
  return {
1231
1518
  ...credentialDisplay.name && {
1232
- alias: credentialDisplay.name
1233
- },
1234
- ...credentialDisplay.lang && {
1235
- locale: credentialDisplay.lang
1236
- },
1237
- ...credentialDisplay.rendering?.simple?.logo && {
1238
- logo: {
1239
- ...credentialDisplay.rendering.simple.logo.uri && {
1240
- uri: credentialDisplay.rendering.simple.logo.uri
1241
- },
1242
- ...credentialDisplay.rendering.simple.logo.alt_text && {
1243
- alt: credentialDisplay.rendering.simple.logo.alt_text
1244
- }
1245
- }
1246
- },
1247
- ...credentialDisplay.description && {
1248
- description: credentialDisplay.description
1249
- },
1250
- ...credentialDisplay.rendering?.simple?.text_color && {
1251
- text: {
1252
- color: credentialDisplay.rendering.simple.text_color
1253
- }
1254
- },
1255
- ...credentialDisplay.rendering?.simple?.background_color && {
1256
- background: {
1257
- color: credentialDisplay.rendering.simple.background_color
1258
- }
1259
- }
1260
- };
1261
- }, "sdJwtCredentialLocaleBrandingFrom");
1262
- var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1263
- const { credentialDisplayLocales = /* @__PURE__ */ new Map(), claimsMetadata = /* @__PURE__ */ new Map() } = args;
1264
- const locales = Array.from(/* @__PURE__ */ new Set([
1265
- ...claimsMetadata.keys(),
1266
- ...credentialDisplayLocales.keys()
1267
- ]));
1268
- return Promise.all(locales.map(async (locale) => {
1269
- const display = credentialDisplayLocales.get(locale);
1270
- const claims = claimsMetadata.get(locale);
1271
- return {
1272
- ...display && await sdJwtCredentialLocaleBrandingFrom({
1273
- credentialDisplay: display
1274
- }),
1275
- ...locale.length > 0 && {
1276
- locale
1277
- },
1278
- claims
1279
- };
1280
- }));
1281
- }, "sdJwtCombineDisplayLocalesFrom");
1282
- var issuerLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1283
- const { issuerDisplay, dynamicRegistrationClientMetadata } = args;
1284
- return {
1285
- ...dynamicRegistrationClientMetadata?.client_name && {
1286
- alias: dynamicRegistrationClientMetadata.client_name
1287
- },
1288
- ...issuerDisplay.name && {
1289
- alias: issuerDisplay.name
1290
- },
1291
- ...issuerDisplay.locale && {
1292
- locale: issuerDisplay.locale
1293
- },
1294
- ...(issuerDisplay.logo || dynamicRegistrationClientMetadata?.logo_uri) && {
1295
- logo: {
1296
- ...dynamicRegistrationClientMetadata?.logo_uri && {
1297
- uri: dynamicRegistrationClientMetadata?.logo_uri
1298
- },
1299
- ...(issuerDisplay.logo?.url || issuerDisplay.logo?.uri) && {
1300
- uri: issuerDisplay.logo?.url ?? issuerDisplay.logo?.uri
1301
- },
1302
- ...issuerDisplay.logo?.alt_text && {
1303
- alt: issuerDisplay.logo?.alt_text
1304
- }
1305
- }
1306
- },
1307
- ...issuerDisplay.description && {
1308
- description: issuerDisplay.description
1309
- },
1310
- ...issuerDisplay.text_color && {
1311
- text: {
1312
- color: issuerDisplay.text_color
1313
- }
1314
- },
1315
- ...dynamicRegistrationClientMetadata?.client_uri && {
1316
- clientUri: dynamicRegistrationClientMetadata.client_uri
1317
- },
1318
- ...dynamicRegistrationClientMetadata?.tos_uri && {
1319
- tosUri: dynamicRegistrationClientMetadata.tos_uri
1320
- },
1321
- ...dynamicRegistrationClientMetadata?.policy_uri && {
1322
- policyUri: dynamicRegistrationClientMetadata.policy_uri
1323
- },
1324
- ...dynamicRegistrationClientMetadata?.contacts && {
1325
- contacts: dynamicRegistrationClientMetadata.contacts
1326
- }
1327
- };
1328
- }, "issuerLocaleBrandingFrom");
1329
-
1330
- // src/machines/firstPartyMachine.ts
1331
- var import_xstate2 = require("xstate");
1332
- var import_oid4vci_common2 = require("@sphereon/oid4vci-common");
1333
-
1334
- // src/services/FirstPartyMachineServices.ts
1335
- var import_oid4vci_client = require("@sphereon/oid4vci-client");
1336
- var import_uuid = require("uuid");
1337
- var sendAuthorizationChallengeRequest = /* @__PURE__ */ __name(async (args) => {
1338
- const { openID4VCIClientState, authSession, presentationDuringIssuanceSession } = args;
1339
- const oid4vciClient = await import_oid4vci_client.OpenID4VCIClient.fromState({
1340
- state: openID4VCIClientState
1341
- });
1342
- return oid4vciClient.acquireAuthorizationChallengeCode({
1343
- clientId: oid4vciClient.clientId ?? (0, import_uuid.v4)(),
1344
- ...authSession && {
1345
- authSession
1346
- },
1347
- ...!authSession && openID4VCIClientState.credentialOffer?.preAuthorizedCode && {
1348
- issuerState: openID4VCIClientState.credentialOffer?.preAuthorizedCode
1349
- },
1350
- ...!authSession && openID4VCIClientState.credentialOffer?.issuerState && {
1351
- issuerState: openID4VCIClientState.credentialOffer?.issuerState
1352
- },
1353
- ...presentationDuringIssuanceSession && {
1354
- presentationDuringIssuanceSession
1355
- }
1356
- });
1357
- }, "sendAuthorizationChallengeRequest");
1358
- var createConfig = /* @__PURE__ */ __name(async (args, context) => {
1359
- const { presentationUri } = args;
1360
- if (!presentationUri) {
1361
- return Promise.reject(Error("Missing presentation uri in context"));
1362
- }
1363
- return context.agent.siopCreateConfig({
1364
- url: presentationUri
1365
- });
1366
- }, "createConfig");
1367
- var getSiopRequest = /* @__PURE__ */ __name(async (args, context) => {
1368
- const { didAuthConfig, presentationUri } = args;
1369
- if (presentationUri === void 0) {
1370
- return Promise.reject(Error("Missing presentation uri in context"));
1371
- }
1372
- if (didAuthConfig === void 0) {
1373
- return Promise.reject(Error("Missing did auth config in context"));
1374
- }
1375
- return context.agent.siopGetSiopRequest({
1376
- didAuthConfig,
1377
- url: presentationUri
1378
- });
1379
- }, "getSiopRequest");
1380
- var sendAuthorizationResponse = /* @__PURE__ */ __name(async (args, context) => {
1381
- const { didAuthConfig, authorizationRequestData, selectedCredentials } = args;
1382
- const responseData = await context.agent.siopSendResponse({
1383
- authorizationRequestData,
1384
- selectedCredentials,
1385
- didAuthConfig,
1386
- isFirstParty: true
1387
- });
1388
- return responseData.body.presentation_during_issuance_session;
1389
- }, "sendAuthorizationResponse");
1390
-
1391
- // src/machines/firstPartyMachine.ts
1392
- var firstPartyMachineStates = {
1393
- [FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest]: {
1394
- id: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1395
- invoke: {
1396
- src: FirstPartyMachineServices.sendAuthorizationChallengeRequest,
1397
- onDone: {
1398
- target: FirstPartyMachineStateTypes.done,
1399
- actions: (0, import_xstate2.assign)({
1400
- authorizationCodeResponse: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationCodeResponse")
1401
- })
1402
- },
1403
- onError: [
1404
- {
1405
- target: FirstPartyMachineStateTypes.createConfig,
1406
- cond: /* @__PURE__ */ __name((_ctx, _event) => _event.data.error === import_oid4vci_common2.AuthorizationChallengeError.insufficient_authorization, "cond"),
1407
- actions: (0, import_xstate2.assign)({
1408
- authSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data.auth_session, "authSession"),
1409
- presentationUri: /* @__PURE__ */ __name((_ctx, _event) => _event.data.presentation, "presentationUri")
1410
- })
1411
- },
1412
- {
1413
- target: FirstPartyMachineStateTypes.error,
1414
- actions: (0, import_xstate2.assign)({
1415
- error: /* @__PURE__ */ __name((_ctx, _event) => ({
1416
- title: translate("oid4vci_machine_send_authorization_challenge_request_error_title"),
1417
- message: _event.data.message,
1418
- stack: _event.data.stack
1419
- }), "error")
1420
- })
1421
- }
1422
- ]
1423
- }
1424
- },
1425
- [FirstPartyMachineStateTypes.createConfig]: {
1426
- id: FirstPartyMachineStateTypes.createConfig,
1427
- invoke: {
1428
- src: FirstPartyMachineServices.createConfig,
1429
- onDone: {
1430
- target: FirstPartyMachineStateTypes.getSiopRequest,
1431
- actions: (0, import_xstate2.assign)({
1432
- didAuthConfig: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "didAuthConfig")
1433
- })
1434
- },
1435
- onError: {
1436
- target: FirstPartyMachineStateTypes.error,
1437
- actions: (0, import_xstate2.assign)({
1438
- error: /* @__PURE__ */ __name((_ctx, _event) => ({
1439
- title: translate("oid4vci_machine_create_config_error_title"),
1440
- message: _event.data.message,
1441
- stack: _event.data.stack
1442
- }), "error")
1443
- })
1444
- }
1445
- }
1446
- },
1447
- [FirstPartyMachineStateTypes.getSiopRequest]: {
1448
- id: FirstPartyMachineStateTypes.getSiopRequest,
1449
- invoke: {
1450
- src: FirstPartyMachineServices.getSiopRequest,
1451
- onDone: {
1452
- target: FirstPartyMachineStateTypes.selectCredentials,
1453
- actions: (0, import_xstate2.assign)({
1454
- authorizationRequestData: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationRequestData")
1455
- })
1456
- },
1457
- onError: {
1458
- target: FirstPartyMachineStateTypes.error,
1459
- actions: (0, import_xstate2.assign)({
1460
- error: /* @__PURE__ */ __name((_ctx, _event) => ({
1461
- title: translate("siopV2_machine_get_request_error_title"),
1462
- message: _event.data.message,
1463
- stack: _event.data.stack
1464
- }), "error")
1465
- })
1519
+ alias: credentialDisplay.name
1520
+ },
1521
+ ...credentialDisplay.lang && {
1522
+ locale: credentialDisplay.lang
1523
+ },
1524
+ ...credentialDisplay.rendering?.simple?.logo && {
1525
+ logo: {
1526
+ ...credentialDisplay.rendering.simple.logo.uri && {
1527
+ uri: credentialDisplay.rendering.simple.logo.uri
1528
+ },
1529
+ ...credentialDisplay.rendering.simple.logo.alt_text && {
1530
+ alt: credentialDisplay.rendering.simple.logo.alt_text
1531
+ }
1466
1532
  }
1467
- }
1468
- },
1469
- [FirstPartyMachineStateTypes.selectCredentials]: {
1470
- id: FirstPartyMachineStateTypes.selectCredentials,
1471
- on: {
1472
- [FirstPartyMachineEvents.SET_SELECTED_CREDENTIALS]: {
1473
- actions: (0, import_xstate2.assign)({
1474
- selectedCredentials: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectedCredentials")
1475
- })
1476
- },
1477
- [FirstPartyMachineEvents.NEXT]: {
1478
- target: FirstPartyMachineStateTypes.sendAuthorizationResponse
1479
- },
1480
- [FirstPartyMachineEvents.DECLINE]: {
1481
- target: FirstPartyMachineStateTypes.declined
1482
- },
1483
- [FirstPartyMachineEvents.PREVIOUS]: {
1484
- target: FirstPartyMachineStateTypes.aborted
1533
+ },
1534
+ ...credentialDisplay.description && {
1535
+ description: credentialDisplay.description
1536
+ },
1537
+ ...credentialDisplay.rendering?.simple?.text_color && {
1538
+ text: {
1539
+ color: credentialDisplay.rendering.simple.text_color
1485
1540
  }
1486
- }
1487
- },
1488
- [FirstPartyMachineStateTypes.sendAuthorizationResponse]: {
1489
- id: FirstPartyMachineStateTypes.sendAuthorizationResponse,
1490
- invoke: {
1491
- src: FirstPartyMachineServices.sendAuthorizationResponse,
1492
- onDone: {
1493
- target: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1494
- actions: (0, import_xstate2.assign)({
1495
- presentationDuringIssuanceSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "presentationDuringIssuanceSession")
1496
- })
1497
- },
1498
- onError: {
1499
- target: FirstPartyMachineStateTypes.error,
1500
- actions: (0, import_xstate2.assign)({
1501
- error: /* @__PURE__ */ __name((_ctx, _event) => ({
1502
- title: translate("oid4vci_machine_get_request_error_title"),
1503
- message: _event.data.message,
1504
- stack: _event.data.stack
1505
- }), "error")
1506
- })
1541
+ },
1542
+ ...credentialDisplay.rendering?.simple?.background_color && {
1543
+ background: {
1544
+ color: credentialDisplay.rendering.simple.background_color
1507
1545
  }
1508
1546
  }
1509
- },
1510
- [FirstPartyMachineStateTypes.aborted]: {
1511
- id: FirstPartyMachineStateTypes.aborted,
1512
- type: "final"
1513
- },
1514
- [FirstPartyMachineStateTypes.declined]: {
1515
- id: FirstPartyMachineStateTypes.declined,
1516
- type: "final"
1517
- },
1518
- [FirstPartyMachineStateTypes.error]: {
1519
- id: FirstPartyMachineStateTypes.error,
1520
- type: "final"
1521
- },
1522
- [FirstPartyMachineStateTypes.done]: {
1523
- id: FirstPartyMachineStateTypes.done,
1524
- type: "final"
1525
- }
1526
- };
1527
- var createFirstPartyActivationMachine = /* @__PURE__ */ __name((opts) => {
1528
- const initialContext = {
1529
- openID4VCIClientState: opts.openID4VCIClientState,
1530
- contact: opts.contact,
1531
- selectedCredentials: []
1532
1547
  };
1533
- return (0, import_xstate2.createMachine)({
1534
- id: opts?.machineId ?? "FirstParty",
1535
- predictableActionArguments: true,
1536
- initial: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
1537
- context: initialContext,
1538
- states: firstPartyMachineStates,
1539
- schema: {
1540
- events: {},
1541
- services: {}
1542
- }
1543
- });
1544
- }, "createFirstPartyActivationMachine");
1545
- var FirstPartyMachine = class _FirstPartyMachine {
1546
- static {
1547
- __name(this, "FirstPartyMachine");
1548
- }
1549
- static _instance;
1550
- static hasInstance() {
1551
- return _FirstPartyMachine._instance !== void 0;
1552
- }
1553
- static get instance() {
1554
- if (!_FirstPartyMachine._instance) {
1555
- throw Error("Please initialize ESIMActivation machine first");
1556
- }
1557
- return _FirstPartyMachine._instance;
1558
- }
1559
- static clearInstance(opts) {
1560
- const { stop } = opts;
1561
- if (_FirstPartyMachine.hasInstance()) {
1562
- if (stop) {
1563
- _FirstPartyMachine.stopInstance();
1564
- }
1565
- }
1566
- _FirstPartyMachine._instance = void 0;
1567
- }
1568
- static stopInstance() {
1569
- if (!_FirstPartyMachine.hasInstance()) {
1570
- return;
1571
- }
1572
- _FirstPartyMachine.instance.stop();
1573
- _FirstPartyMachine._instance = void 0;
1574
- }
1575
- static newInstance(opts) {
1576
- const { agentContext } = opts;
1577
- const services = {
1578
- [FirstPartyMachineServices.sendAuthorizationChallengeRequest]: sendAuthorizationChallengeRequest,
1579
- [FirstPartyMachineServices.createConfig]: (args) => createConfig(args, agentContext),
1580
- [FirstPartyMachineServices.getSiopRequest]: (args) => getSiopRequest(args, agentContext),
1581
- [FirstPartyMachineServices.sendAuthorizationResponse]: (args) => sendAuthorizationResponse(args, agentContext)
1582
- };
1583
- const newInst = (0, import_xstate2.interpret)(createFirstPartyActivationMachine(opts).withConfig({
1584
- services: {
1585
- ...services,
1586
- ...opts?.services
1548
+ }, "sdJwtCredentialLocaleBrandingFrom");
1549
+ var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1550
+ const { credentialDisplayLocales = /* @__PURE__ */ new Map(), claimsMetadata = /* @__PURE__ */ new Map() } = args;
1551
+ const locales = Array.from(/* @__PURE__ */ new Set([
1552
+ ...claimsMetadata.keys(),
1553
+ ...credentialDisplayLocales.keys()
1554
+ ]));
1555
+ return Promise.all(locales.map(async (locale) => {
1556
+ const display = credentialDisplayLocales.get(locale);
1557
+ const claims = claimsMetadata.get(locale);
1558
+ return {
1559
+ ...display && await sdJwtCredentialLocaleBrandingFrom({
1560
+ credentialDisplay: display
1561
+ }),
1562
+ ...locale.length > 0 && {
1563
+ locale
1587
1564
  },
1588
- guards: {
1589
- ...opts?.guards
1590
- }
1591
- }));
1592
- if (typeof opts?.subscription === "function") {
1593
- newInst.onTransition(opts.subscription);
1594
- }
1595
- if (opts?.requireCustomNavigationHook !== true) {
1596
- newInst.onTransition((snapshot) => {
1597
- if (opts?.stateNavigationListener) {
1598
- void opts.stateNavigationListener(newInst, snapshot);
1565
+ claims
1566
+ };
1567
+ }));
1568
+ }, "sdJwtCombineDisplayLocalesFrom");
1569
+ var issuerLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1570
+ const { issuerDisplay, dynamicRegistrationClientMetadata } = args;
1571
+ return {
1572
+ ...dynamicRegistrationClientMetadata?.client_name && {
1573
+ alias: dynamicRegistrationClientMetadata.client_name
1574
+ },
1575
+ ...issuerDisplay.name && {
1576
+ alias: issuerDisplay.name
1577
+ },
1578
+ ...issuerDisplay.locale && {
1579
+ locale: issuerDisplay.locale
1580
+ },
1581
+ ...(issuerDisplay.logo || dynamicRegistrationClientMetadata?.logo_uri) && {
1582
+ logo: {
1583
+ ...dynamicRegistrationClientMetadata?.logo_uri && {
1584
+ uri: dynamicRegistrationClientMetadata?.logo_uri
1585
+ },
1586
+ ...(issuerDisplay.logo?.url || issuerDisplay.logo?.uri) && {
1587
+ uri: issuerDisplay.logo?.url ?? issuerDisplay.logo?.uri
1588
+ },
1589
+ ...issuerDisplay.logo?.alt_text && {
1590
+ alt: issuerDisplay.logo?.alt_text
1599
1591
  }
1600
- });
1601
- }
1602
- return newInst;
1603
- }
1604
- static getInstance(opts) {
1605
- if (!_FirstPartyMachine._instance) {
1606
- if (opts?.requireExisting === true) {
1607
- throw Error(`Existing FirstPartyMachine instance requested, but none was created at this point!`);
1608
1592
  }
1609
- _FirstPartyMachine._instance = _FirstPartyMachine.newInstance(opts);
1593
+ },
1594
+ ...issuerDisplay.description && {
1595
+ description: issuerDisplay.description
1596
+ },
1597
+ ...issuerDisplay.text_color && {
1598
+ text: {
1599
+ color: issuerDisplay.text_color
1600
+ }
1601
+ },
1602
+ ...dynamicRegistrationClientMetadata?.client_uri && {
1603
+ clientUri: dynamicRegistrationClientMetadata.client_uri
1604
+ },
1605
+ ...dynamicRegistrationClientMetadata?.tos_uri && {
1606
+ tosUri: dynamicRegistrationClientMetadata.tos_uri
1607
+ },
1608
+ ...dynamicRegistrationClientMetadata?.policy_uri && {
1609
+ policyUri: dynamicRegistrationClientMetadata.policy_uri
1610
+ },
1611
+ ...dynamicRegistrationClientMetadata?.contacts && {
1612
+ contacts: dynamicRegistrationClientMetadata.contacts
1610
1613
  }
1611
- return _FirstPartyMachine._instance;
1612
- }
1613
- };
1614
+ };
1615
+ }, "issuerLocaleBrandingFrom");
1614
1616
 
1615
1617
  // src/services/OID4VCIHolderService.ts
1616
- var import_ssi_sdk = require("@sphereon/ssi-sdk.core");
1617
1618
  var getCredentialBranding = /* @__PURE__ */ __name(async (args) => {
1618
1619
  const { credentialsSupported, context } = args;
1619
1620
  const credentialBranding = {};
@@ -1685,16 +1686,7 @@ var selectCredentialLocaleBranding = /* @__PURE__ */ __name(async (args) => {
1685
1686
  }, "selectCredentialLocaleBranding");
1686
1687
  var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1687
1688
  const { mappedCredential, hasher, onVerifyEBSICredentialIssuer, schemaValidation, context } = args;
1688
- const credentialResponse = mappedCredential.credentialToAccept.credentialResponse;
1689
- let credential;
1690
- if ("credential" in credentialResponse) {
1691
- credential = credentialResponse.credential;
1692
- } else if ("credentials" in credentialResponse && credentialResponse.credentials && Array.isArray(credentialResponse.credentials) && credentialResponse.credentials.length > 0) {
1693
- credential = credentialResponse.credentials[0].credential;
1694
- }
1695
- if (!credential) {
1696
- return Promise.reject(Error("No credential found in credential response"));
1697
- }
1689
+ const credential = extractCredentialFromResponse(mappedCredential.credentialToAccept.credentialResponse);
1698
1690
  const wrappedVC = import_ssi_types.CredentialMapper.toWrappedVerifiableCredential(credential, {
1699
1691
  hasher: hasher ?? import_ssi_sdk.defaultHasher
1700
1692
  });
@@ -1746,16 +1738,7 @@ var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1746
1738
  }, "verifyCredentialToAccept");
1747
1739
  var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1748
1740
  const { credentialToAccept, hasher } = args;
1749
- const credentialResponse = credentialToAccept.credentialResponse;
1750
- let verifiableCredential;
1751
- if ("credential" in credentialResponse) {
1752
- verifiableCredential = credentialResponse.credential;
1753
- } else if ("credentials" in credentialResponse && credentialResponse.credentials && Array.isArray(credentialResponse.credentials) && credentialResponse.credentials.length > 0) {
1754
- verifiableCredential = credentialResponse.credentials[0].credential;
1755
- }
1756
- if (!verifiableCredential) {
1757
- return Promise.reject(Error("No credential found in credential response"));
1758
- }
1741
+ const verifiableCredential = extractCredentialFromResponse(credentialToAccept.credentialResponse);
1759
1742
  const wrappedVerifiableCredential = import_ssi_types.CredentialMapper.toWrappedVerifiableCredential(verifiableCredential, {
1760
1743
  hasher
1761
1744
  });
@@ -1775,6 +1758,7 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1775
1758
  uniformVerifiableCredential = wrappedVerifiableCredential.credential;
1776
1759
  }
1777
1760
  const correlationId = typeof uniformVerifiableCredential.issuer === "string" ? uniformVerifiableCredential.issuer : import_ssi_types.CredentialMapper.isSdJwtDecodedCredential(uniformVerifiableCredential) ? uniformVerifiableCredential.decodedPayload.iss : uniformVerifiableCredential.issuer.id;
1761
+ const credentialResponse = credentialToAccept.credentialResponse;
1778
1762
  return {
1779
1763
  correlationId,
1780
1764
  credentialToAccept,
@@ -1786,6 +1770,18 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1786
1770
  }
1787
1771
  };
1788
1772
  }, "mapCredentialToAccept");
1773
+ var extractCredentialFromResponse = /* @__PURE__ */ __name((credentialResponse) => {
1774
+ let credential;
1775
+ if ("credential" in credentialResponse) {
1776
+ credential = credentialResponse.credential;
1777
+ } else if ("credentials" in credentialResponse && credentialResponse.credentials && Array.isArray(credentialResponse.credentials) && credentialResponse.credentials.length > 0) {
1778
+ credential = credentialResponse.credentials[0].credential;
1779
+ }
1780
+ if (!credential) {
1781
+ throw new Error("No credential found in credential response");
1782
+ }
1783
+ return credential;
1784
+ }, "extractCredentialFromResponse");
1789
1785
  var getIdentifierOpts = /* @__PURE__ */ __name(async (args) => {
1790
1786
  const { issuanceOpt, context } = args;
1791
1787
  const { identifier: identifierArg } = issuanceOpt;
@@ -1894,24 +1890,22 @@ var getCredentialConfigsSupportedBySingleTypeOrId = /* @__PURE__ */ __name(async
1894
1890
  }
1895
1891
  __name(createIdFromTypes, "createIdFromTypes");
1896
1892
  if (configurationId) {
1897
- const allSupported2 = client.getCredentialsSupported(false);
1893
+ if (!format) {
1894
+ return Promise.reject(Error("format parameter missing from input"));
1895
+ }
1896
+ const allSupported2 = client.getCredentialsSupported(format);
1898
1897
  return Object.fromEntries(Object.entries(allSupported2).filter(([id, supported]) => id === configurationId || supported.id === configurationId || createIdFromTypes(supported) === configurationId));
1899
1898
  }
1900
- if (!types && !client.credentialOffer) {
1901
- return Promise.reject(Error("openID4VCIClient has no credentialOffer and no types where provided"));
1899
+ if (!client.credentialOffer) {
1900
+ return Promise.reject(Error("openID4VCIClient has no credentialOffer"));
1902
1901
  }
1903
- if (!Array.isArray(format) && client.credentialOffer) {
1904
- if (client.version() > import_oid4vci_common3.OpenId4VCIVersion.VER_1_0_09 && typeof client.credentialOffer.credential_offer === "object" && "credentials" in client.credentialOffer.credential_offer) {
1905
- format = client.credentialOffer.credential_offer.credentials.filter((cred) => typeof cred !== "string").map((cred) => cred.format);
1906
- if (format?.length === 0) {
1907
- format = void 0;
1908
- }
1909
- }
1902
+ if (!types) {
1903
+ return Promise.reject(Error("openID4VCIClient has no types"));
1910
1904
  }
1911
1905
  const offerSupported = (0, import_oid4vci_common3.getSupportedCredentials)({
1912
- types: types ? [
1906
+ types: [
1913
1907
  types
1914
- ] : client.getCredentialOfferTypes(),
1908
+ ],
1915
1909
  format,
1916
1910
  version: client.version(),
1917
1911
  issuerMetadata: client.endpointMetadata.credentialIssuerMetadata
@@ -2086,7 +2080,7 @@ var getIssuanceCryptoSuite = /* @__PURE__ */ __name(async (opts) => {
2086
2080
  case "jwt":
2087
2081
  case "jwt_vc_json":
2088
2082
  case "jwt_vc":
2089
- case "vc+sd-jwt":
2083
+ //case 'vc+sd-jwt': // TODO see SSISDK-52 concerning vc+sd-jwt
2090
2084
  case "dc+sd-jwt":
2091
2085
  case "mso_mdoc": {
2092
2086
  const supportedPreferences = jwtCryptographicSuitePreferences.filter((suite) => signing_algs_supported.includes(suite));
@@ -2413,7 +2407,13 @@ var OID4VCIHolder = class _OID4VCIHolder {
2413
2407
  }
2414
2408
  }
2415
2409
  if (offer) {
2416
- types = (0, import_oid4vci_common4.getTypesFromCredentialOffer)(offer.original_credential_offer);
2410
+ const credentialsSupported2 = offer.original_credential_offer.credential_configuration_ids.flatMap((configId) => {
2411
+ const config = oid4vciClient.endpointMetadata.credentialIssuerMetadata?.credential_configurations_supported[configId];
2412
+ return config ? [
2413
+ config
2414
+ ] : [];
2415
+ });
2416
+ types = credentialsSupported2.map((credentialSupported) => (0, import_oid4vci_common4.getTypesFromCredentialSupported)(credentialSupported));
2417
2417
  } else {
2418
2418
  types = (0, import_utils2.asArray)(authorizationRequestOpts.authorizationDetails).map((authReqOpts) => (0, import_oid4vci_common4.getTypesFromAuthorizationDetails)(authReqOpts) ?? []).filter((inner) => inner.length > 0);
2419
2419
  }
@@ -2650,7 +2650,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2650
2650
  alias: credentialsToAccept[0].correlationId,
2651
2651
  origin: import_ssi_sdk3.IdentityOrigin.EXTERNAL,
2652
2652
  roles: [
2653
- import_ssi_sdk3.CredentialRole.ISSUER
2653
+ import_ssi_types2.CredentialRole.ISSUER
2654
2654
  ],
2655
2655
  identifier: {
2656
2656
  type: identifierType,
@@ -2685,7 +2685,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2685
2685
  }
2686
2686
  async oid4vciHolderGetIssuerBranding(args, context) {
2687
2687
  const { serverMetadata, contact } = args;
2688
- const issuerCorrelationId = contact?.identities.filter((identity) => identity.roles.includes(import_ssi_sdk3.CredentialRole.ISSUER)).map((identity) => identity.identifier.correlationId)[0];
2688
+ const issuerCorrelationId = contact?.identities.filter((identity) => identity.roles.includes(import_ssi_types2.CredentialRole.ISSUER)).map((identity) => identity.identifier.correlationId)[0];
2689
2689
  if (issuerCorrelationId) {
2690
2690
  const branding = await context.agent.ibGetIssuerBranding({
2691
2691
  filter: [
@@ -2715,7 +2715,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2715
2715
  if (!contact) {
2716
2716
  return Promise.reject(Error("Missing contact in context"));
2717
2717
  }
2718
- const issuerCorrelationId = contact?.identities.filter((identity) => identity.roles.includes(import_ssi_sdk3.CredentialRole.ISSUER)).map((identity) => identity.identifier.correlationId)[0];
2718
+ const issuerCorrelationId = contact?.identities.filter((identity) => identity.roles.includes(import_ssi_types2.CredentialRole.ISSUER)).map((identity) => identity.identifier.correlationId)[0];
2719
2719
  const branding = await context.agent.ibGetIssuerBranding({
2720
2720
  filter: [
2721
2721
  {
@@ -2811,16 +2811,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2811
2811
  if (Array.isArray(subjectIssuance?.notification_events_supported)) {
2812
2812
  event = subjectIssuance.notification_events_supported.includes("credential_accepted_holder_signed") ? "credential_accepted_holder_signed" : "credential_deleted_holder_signed";
2813
2813
  logger.log(`Subject issuance/signing will be used, with event`, event);
2814
- const credentialResponse = mappedCredentialToAccept.credentialToAccept.credentialResponse;
2815
- let issuerVC;
2816
- if ("credential" in credentialResponse) {
2817
- issuerVC = credentialResponse.credential;
2818
- } else if ("credentials" in credentialResponse && credentialResponse.credentials && Array.isArray(credentialResponse.credentials) && credentialResponse.credentials.length > 0) {
2819
- issuerVC = credentialResponse.credentials[0].credential;
2820
- }
2821
- if (!issuerVC) {
2822
- return Promise.reject(Error("No credential found in credential response"));
2823
- }
2814
+ const issuerVC = extractCredentialFromResponse(mappedCredentialToAccept.credentialToAccept.credentialResponse);
2824
2815
  const wrappedIssuerVC = import_ssi_types2.CredentialMapper.toWrappedVerifiableCredential(issuerVC, {
2825
2816
  hasher: this.hasher ?? import_ssi_sdk2.defaultHasher
2826
2817
  });
@@ -2926,7 +2917,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2926
2917
  rawDocument: (0, import_ssi_sdk3.ensureRawDocument)(persistCredential),
2927
2918
  kmsKeyRef,
2928
2919
  identifierMethod: method,
2929
- credentialRole: import_ssi_sdk3.CredentialRole.HOLDER,
2920
+ credentialRole: import_ssi_types2.CredentialRole.HOLDER,
2930
2921
  issuerCorrelationType: issuer?.startsWith("did:") ? import_ssi_sdk3.CredentialCorrelationType.DID : import_ssi_sdk3.CredentialCorrelationType.URL,
2931
2922
  issuerCorrelationId: issuer,
2932
2923
  subjectCorrelationType,