@sphereon/ssi-sdk.oid4vci-holder 0.34.1-next.88 → 0.36.0

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,
@@ -140,9 +141,10 @@ var import_ssi_sdk_ext5 = require("@sphereon/ssi-sdk-ext.did-utils");
140
141
  var import_ssi_sdk_ext6 = require("@sphereon/ssi-sdk-ext.identifier-resolution");
141
142
  var import_ssi_sdk_ext7 = require("@sphereon/ssi-sdk-ext.key-utils");
142
143
  var import_ssi_sdk2 = require("@sphereon/ssi-sdk.core");
143
- var import_ssi_sdk3 = require("@sphereon/ssi-sdk.data-store");
144
+ var import_ssi_sdk3 = require("@sphereon/ssi-sdk.data-store-types");
144
145
  var import_ssi_types2 = require("@sphereon/ssi-types");
145
146
  var import_utils2 = require("@veramo/utils");
147
+ var import_cross_fetch = __toESM(require("cross-fetch"), 1);
146
148
  var import_did_jwt = require("did-jwt");
147
149
  var import_uuid2 = require("uuid");
148
150
 
@@ -182,6 +184,7 @@ var OID4VCIMachineStates = /* @__PURE__ */ (function(OID4VCIMachineStates2) {
182
184
  OID4VCIMachineStates2["selectCredentials"] = "selectCredentials";
183
185
  OID4VCIMachineStates2["transitionFromSelectingCredentials"] = "transitionFromSelectingCredentials";
184
186
  OID4VCIMachineStates2["verifyPin"] = "verifyPin";
187
+ OID4VCIMachineStates2["prepareAuthorizationRequest"] = "prepareAuthorizationRequest";
185
188
  OID4VCIMachineStates2["initiateAuthorizationRequest"] = "initiateAuthorizationRequest";
186
189
  OID4VCIMachineStates2["waitForAuthorizationResponse"] = "waitForAuthorizationResponse";
187
190
  OID4VCIMachineStates2["getCredentials"] = "getCredentials";
@@ -246,6 +249,7 @@ var OID4VCIMachineServices = /* @__PURE__ */ (function(OID4VCIMachineServices2)
246
249
  OID4VCIMachineServices2["getFederationTrust"] = "getFederationTrust";
247
250
  OID4VCIMachineServices2["addContactIdentity"] = "addContactIdentity";
248
251
  OID4VCIMachineServices2["createCredentialsToSelectFrom"] = "createCredentialsToSelectFrom";
252
+ OID4VCIMachineServices2["prepareAuthorizationRequest"] = "prepareAuthorizationRequest";
249
253
  OID4VCIMachineServices2["getIssuerBranding"] = "getIssuerBranding";
250
254
  OID4VCIMachineServices2["storeIssuerBranding"] = "storeIssuerBranding";
251
255
  OID4VCIMachineServices2["getCredentials"] = "getCredentials";
@@ -387,9 +391,7 @@ var oid4vciRequireAuthorizationGuard = /* @__PURE__ */ __name((ctx, _event) => {
387
391
  if (!openID4VCIClientState) {
388
392
  throw Error("Missing openID4VCI client state in context");
389
393
  }
390
- if (!openID4VCIClientState.authorizationURL) {
391
- return false;
392
- } else if (openID4VCIClientState.authorizationRequestOpts) {
394
+ if (openID4VCIClientState.authorizationURL && openID4VCIClientState.authorizationRequestOpts) {
393
395
  return !ctx.openID4VCIClientState?.authorizationCodeResponse;
394
396
  } else if (openID4VCIClientState.credentialOffer?.supportedFlows?.includes(import_oid4vci_common.AuthzFlowType.AUTHORIZATION_CODE_FLOW)) {
395
397
  return !ctx.openID4VCIClientState?.authorizationCodeResponse;
@@ -440,7 +442,6 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
440
442
  onDone: {
441
443
  target: OID4VCIMachineStates.createCredentialsToSelectFrom,
442
444
  actions: (0, import_xstate.assign)({
443
- authorizationCodeURL: /* @__PURE__ */ __name((_ctx, _event) => _event.data.authorizationCodeURL, "authorizationCodeURL"),
444
445
  credentialBranding: /* @__PURE__ */ __name((_ctx, _event) => _event.data.credentialBranding ?? {}, "credentialBranding"),
445
446
  credentialsSupported: /* @__PURE__ */ __name((_ctx, _event) => _event.data.credentialsSupported, "credentialsSupported"),
446
447
  serverMetadata: /* @__PURE__ */ __name((_ctx, _event) => _event.data.serverMetadata, "serverMetadata"),
@@ -677,6 +678,10 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
677
678
  target: OID4VCIMachineStates.startFirstPartApplicationFlow,
678
679
  cond: OID4VCIMachineGuards.isFirstPartyApplication
679
680
  },
681
+ {
682
+ target: OID4VCIMachineStates.prepareAuthorizationRequest,
683
+ cond: OID4VCIMachineGuards.requireAuthorizationGuard
684
+ },
680
685
  {
681
686
  target: OID4VCIMachineStates.initiateAuthorizationRequest,
682
687
  cond: OID4VCIMachineGuards.requireAuthorizationGuard
@@ -752,12 +757,16 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
752
757
  target: OID4VCIMachineStates.startFirstPartApplicationFlow,
753
758
  cond: OID4VCIMachineGuards.isFirstPartyApplication
754
759
  },
760
+ {
761
+ target: OID4VCIMachineStates.prepareAuthorizationRequest,
762
+ cond: OID4VCIMachineGuards.requireAuthorizationGuard
763
+ },
755
764
  {
756
765
  target: OID4VCIMachineStates.verifyPin,
757
766
  cond: OID4VCIMachineGuards.requirePinGuard
758
767
  },
759
768
  {
760
- target: OID4VCIMachineStates.initiateAuthorizationRequest,
769
+ target: OID4VCIMachineStates.prepareAuthorizationRequest,
761
770
  cond: OID4VCIMachineGuards.requireAuthorizationGuard
762
771
  },
763
772
  {
@@ -765,6 +774,29 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
765
774
  }
766
775
  ]
767
776
  },
777
+ [OID4VCIMachineStates.prepareAuthorizationRequest]: {
778
+ id: OID4VCIMachineStates.prepareAuthorizationRequest,
779
+ invoke: {
780
+ src: OID4VCIMachineServices.prepareAuthorizationRequest,
781
+ onDone: {
782
+ target: OID4VCIMachineStates.initiateAuthorizationRequest,
783
+ actions: (0, import_xstate.assign)({
784
+ authorizationCodeURL: /* @__PURE__ */ __name((_ctx, _event) => _event.data.authorizationCodeURL, "authorizationCodeURL"),
785
+ openID4VCIClientState: /* @__PURE__ */ __name((_ctx, _event) => _event.data.oid4vciClientState, "openID4VCIClientState")
786
+ })
787
+ },
788
+ onError: {
789
+ target: OID4VCIMachineStates.handleError,
790
+ actions: (0, import_xstate.assign)({
791
+ error: /* @__PURE__ */ __name((_ctx, _event) => ({
792
+ title: translate("oid4vci_machine_prepare_authorization_error_title"),
793
+ message: _event.data.message,
794
+ stack: _event.data.stack
795
+ }), "error")
796
+ })
797
+ }
798
+ }
799
+ },
768
800
  [OID4VCIMachineStates.initiateAuthorizationRequest]: {
769
801
  id: OID4VCIMachineStates.initiateAuthorizationRequest,
770
802
  on: {
@@ -1062,271 +1094,10 @@ var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.did-resolver-jwk");
1062
1094
  var import_ssi_sdk_ext2 = require("@sphereon/ssi-sdk-ext.did-utils");
1063
1095
  var import_ssi_sdk_ext3 = require("@sphereon/ssi-sdk-ext.identifier-resolution");
1064
1096
  var import_ssi_sdk_ext4 = require("@sphereon/ssi-sdk-ext.key-utils");
1097
+ var import_ssi_sdk = require("@sphereon/ssi-sdk.core");
1065
1098
  var import_ssi_types = require("@sphereon/ssi-types");
1066
1099
  var import_utils = require("@veramo/utils");
1067
1100
 
1068
- // src/mappers/OIDC4VCIBrandingMapper.ts
1069
- var oid4vciGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1070
- const { credentialDisplay, issuerCredentialSubject } = args;
1071
- return oid4vciCombineDisplayLocalesFrom({
1072
- ...issuerCredentialSubject && {
1073
- issuerCredentialSubjectLocales: await oid4vciIssuerCredentialSubjectLocalesFrom({
1074
- issuerCredentialSubject
1075
- })
1076
- },
1077
- ...credentialDisplay && {
1078
- credentialDisplayLocales: await oid4vciCredentialDisplayLocalesFrom({
1079
- credentialDisplay
1080
- })
1081
- }
1082
- });
1083
- }, "oid4vciGetCredentialBrandingFrom");
1084
- var oid4vciCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1085
- const { credentialDisplay } = args;
1086
- return credentialDisplay.reduce((localeDisplays, display) => {
1087
- const localeKey = display.locale || "";
1088
- localeDisplays.set(localeKey, display);
1089
- return localeDisplays;
1090
- }, /* @__PURE__ */ new Map());
1091
- }, "oid4vciCredentialDisplayLocalesFrom");
1092
- var oid4vciIssuerCredentialSubjectLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1093
- const { issuerCredentialSubject } = args;
1094
- const localeClaims = /* @__PURE__ */ new Map();
1095
- const processClaimObject = /* @__PURE__ */ __name((claim, parentKey = "") => {
1096
- Object.entries(claim).forEach(([key, value]) => {
1097
- if (key === "mandatory" || key === "value_type") {
1098
- return;
1099
- }
1100
- if (key === "display" && Array.isArray(value)) {
1101
- value.forEach(({ name, locale = "" }) => {
1102
- if (!name) {
1103
- return;
1104
- }
1105
- if (!localeClaims.has(locale)) {
1106
- localeClaims.set(locale, []);
1107
- }
1108
- localeClaims.get(locale).push({
1109
- key: parentKey,
1110
- name
1111
- });
1112
- });
1113
- } else if (typeof value === "object" && value !== null) {
1114
- processClaimObject(value, parentKey ? `${parentKey}.${key}` : key);
1115
- }
1116
- });
1117
- }, "processClaimObject");
1118
- processClaimObject(issuerCredentialSubject);
1119
- return localeClaims;
1120
- }, "oid4vciIssuerCredentialSubjectLocalesFrom");
1121
- var oid4vciCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1122
- const { credentialDisplay } = args;
1123
- return {
1124
- ...credentialDisplay.name && {
1125
- alias: credentialDisplay.name
1126
- },
1127
- ...credentialDisplay.locale && {
1128
- locale: credentialDisplay.locale
1129
- },
1130
- ...credentialDisplay.logo && {
1131
- logo: {
1132
- ...(credentialDisplay.logo.url || credentialDisplay.logo.uri) && {
1133
- uri: credentialDisplay.logo?.url ?? credentialDisplay.logo.uri
1134
- },
1135
- ...credentialDisplay.logo.alt_text && {
1136
- alt: credentialDisplay.logo?.alt_text
1137
- }
1138
- }
1139
- },
1140
- ...credentialDisplay.description && {
1141
- description: credentialDisplay.description
1142
- },
1143
- ...credentialDisplay.text_color && {
1144
- text: {
1145
- color: credentialDisplay.text_color
1146
- }
1147
- },
1148
- ...(credentialDisplay.background_image || credentialDisplay.background_color) && {
1149
- background: {
1150
- ...credentialDisplay.background_image && {
1151
- image: {
1152
- ...(credentialDisplay.background_image.url || credentialDisplay.background_image.uri) && {
1153
- uri: credentialDisplay.background_image?.url ?? credentialDisplay.background_image.uri
1154
- },
1155
- ...credentialDisplay.background_image.alt_text && {
1156
- alt: credentialDisplay.background_image?.alt_text
1157
- }
1158
- }
1159
- },
1160
- ...credentialDisplay.background_color && {
1161
- color: credentialDisplay.background_color
1162
- }
1163
- }
1164
- }
1165
- };
1166
- }, "oid4vciCredentialLocaleBrandingFrom");
1167
- var oid4vciCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1168
- const { credentialDisplayLocales = /* @__PURE__ */ new Map(), issuerCredentialSubjectLocales = /* @__PURE__ */ new Map() } = args;
1169
- const locales = Array.from(/* @__PURE__ */ new Set([
1170
- ...issuerCredentialSubjectLocales.keys(),
1171
- ...credentialDisplayLocales.keys()
1172
- ]));
1173
- return Promise.all(locales.map(async (locale) => {
1174
- const display = credentialDisplayLocales.get(locale);
1175
- const claims = issuerCredentialSubjectLocales.get(locale);
1176
- return {
1177
- ...display && await oid4vciCredentialLocaleBrandingFrom({
1178
- credentialDisplay: display
1179
- }),
1180
- ...locale.length > 0 && {
1181
- locale
1182
- },
1183
- claims
1184
- };
1185
- }));
1186
- }, "oid4vciCombineDisplayLocalesFrom");
1187
- var sdJwtGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1188
- const { credentialDisplay, claimsMetadata } = args;
1189
- return sdJwtCombineDisplayLocalesFrom({
1190
- ...claimsMetadata && {
1191
- claimsMetadata: await sdJwtCredentialClaimLocalesFrom({
1192
- claimsMetadata
1193
- })
1194
- },
1195
- ...credentialDisplay && {
1196
- credentialDisplayLocales: await sdJwtCredentialDisplayLocalesFrom({
1197
- credentialDisplay
1198
- })
1199
- }
1200
- });
1201
- }, "sdJwtGetCredentialBrandingFrom");
1202
- var sdJwtCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1203
- const { credentialDisplay } = args;
1204
- return credentialDisplay.reduce((localeDisplays, display) => {
1205
- const localeKey = display.lang || "";
1206
- localeDisplays.set(localeKey, display);
1207
- return localeDisplays;
1208
- }, /* @__PURE__ */ new Map());
1209
- }, "sdJwtCredentialDisplayLocalesFrom");
1210
- var sdJwtCredentialClaimLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1211
- const { claimsMetadata } = args;
1212
- const localeClaims = /* @__PURE__ */ new Map();
1213
- claimsMetadata.forEach((claim) => {
1214
- claim.display?.forEach((display) => {
1215
- const { lang = "", label } = display;
1216
- const key = claim.path.map((value) => String(value)).join(".");
1217
- if (!localeClaims.has(lang)) {
1218
- localeClaims.set(lang, []);
1219
- }
1220
- localeClaims.get(lang).push({
1221
- key,
1222
- name: label
1223
- });
1224
- });
1225
- });
1226
- return localeClaims;
1227
- }, "sdJwtCredentialClaimLocalesFrom");
1228
- var sdJwtCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1229
- const { credentialDisplay } = args;
1230
- return {
1231
- ...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
1101
  // src/machines/firstPartyMachine.ts
1331
1102
  var import_xstate2 = require("xstate");
1332
1103
  var import_oid4vci_common2 = require("@sphereon/oid4vci-common");
@@ -1563,57 +1334,318 @@ var FirstPartyMachine = class _FirstPartyMachine {
1563
1334
  _FirstPartyMachine.stopInstance();
1564
1335
  }
1565
1336
  }
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
1337
+ _FirstPartyMachine._instance = void 0;
1338
+ }
1339
+ static stopInstance() {
1340
+ if (!_FirstPartyMachine.hasInstance()) {
1341
+ return;
1342
+ }
1343
+ _FirstPartyMachine.instance.stop();
1344
+ _FirstPartyMachine._instance = void 0;
1345
+ }
1346
+ static newInstance(opts) {
1347
+ const { agentContext } = opts;
1348
+ const services = {
1349
+ [FirstPartyMachineServices.sendAuthorizationChallengeRequest]: sendAuthorizationChallengeRequest,
1350
+ [FirstPartyMachineServices.createConfig]: (args) => createConfig(args, agentContext),
1351
+ [FirstPartyMachineServices.getSiopRequest]: (args) => getSiopRequest(args, agentContext),
1352
+ [FirstPartyMachineServices.sendAuthorizationResponse]: (args) => sendAuthorizationResponse(args, agentContext)
1353
+ };
1354
+ const newInst = (0, import_xstate2.interpret)(createFirstPartyActivationMachine(opts).withConfig({
1355
+ services: {
1356
+ ...services,
1357
+ ...opts?.services
1358
+ },
1359
+ guards: {
1360
+ ...opts?.guards
1361
+ }
1362
+ }));
1363
+ if (typeof opts?.subscription === "function") {
1364
+ newInst.onTransition(opts.subscription);
1365
+ }
1366
+ if (opts?.requireCustomNavigationHook !== true) {
1367
+ newInst.onTransition((snapshot) => {
1368
+ if (opts?.stateNavigationListener) {
1369
+ void opts.stateNavigationListener(newInst, snapshot);
1370
+ }
1371
+ });
1372
+ }
1373
+ return newInst;
1374
+ }
1375
+ static getInstance(opts) {
1376
+ if (!_FirstPartyMachine._instance) {
1377
+ if (opts?.requireExisting === true) {
1378
+ throw Error(`Existing FirstPartyMachine instance requested, but none was created at this point!`);
1379
+ }
1380
+ _FirstPartyMachine._instance = _FirstPartyMachine.newInstance(opts);
1381
+ }
1382
+ return _FirstPartyMachine._instance;
1383
+ }
1384
+ };
1385
+
1386
+ // src/mappers/OIDC4VCIBrandingMapper.ts
1387
+ var oid4vciGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1388
+ const { credentialDisplay, issuerCredentialSubject } = args;
1389
+ return oid4vciCombineDisplayLocalesFrom({
1390
+ ...issuerCredentialSubject && {
1391
+ issuerCredentialSubjectLocales: await oid4vciIssuerCredentialSubjectLocalesFrom({
1392
+ issuerCredentialSubject
1393
+ })
1394
+ },
1395
+ ...credentialDisplay && {
1396
+ credentialDisplayLocales: await oid4vciCredentialDisplayLocalesFrom({
1397
+ credentialDisplay
1398
+ })
1399
+ }
1400
+ });
1401
+ }, "oid4vciGetCredentialBrandingFrom");
1402
+ var oid4vciCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1403
+ const { credentialDisplay } = args;
1404
+ return credentialDisplay.reduce((localeDisplays, display) => {
1405
+ const localeKey = display.locale || "";
1406
+ localeDisplays.set(localeKey, display);
1407
+ return localeDisplays;
1408
+ }, /* @__PURE__ */ new Map());
1409
+ }, "oid4vciCredentialDisplayLocalesFrom");
1410
+ var oid4vciIssuerCredentialSubjectLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1411
+ const { issuerCredentialSubject } = args;
1412
+ const localeClaims = /* @__PURE__ */ new Map();
1413
+ const processClaimObject = /* @__PURE__ */ __name((claim, parentKey = "") => {
1414
+ Object.entries(claim).forEach(([key, value]) => {
1415
+ if (key === "mandatory" || key === "value_type") {
1416
+ return;
1417
+ }
1418
+ if (key === "display" && Array.isArray(value)) {
1419
+ value.forEach(({ name, locale = "" }) => {
1420
+ if (!name) {
1421
+ return;
1422
+ }
1423
+ if (!localeClaims.has(locale)) {
1424
+ localeClaims.set(locale, []);
1425
+ }
1426
+ localeClaims.get(locale).push({
1427
+ key: parentKey,
1428
+ name
1429
+ });
1430
+ });
1431
+ } else if (typeof value === "object" && value !== null) {
1432
+ processClaimObject(value, parentKey ? `${parentKey}.${key}` : key);
1433
+ }
1434
+ });
1435
+ }, "processClaimObject");
1436
+ processClaimObject(issuerCredentialSubject);
1437
+ return localeClaims;
1438
+ }, "oid4vciIssuerCredentialSubjectLocalesFrom");
1439
+ var oid4vciCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1440
+ const { credentialDisplay } = args;
1441
+ return {
1442
+ ...credentialDisplay.name && {
1443
+ alias: credentialDisplay.name
1444
+ },
1445
+ ...credentialDisplay.locale && {
1446
+ locale: credentialDisplay.locale
1447
+ },
1448
+ ...credentialDisplay.logo && {
1449
+ logo: {
1450
+ ...(credentialDisplay.logo.url || credentialDisplay.logo.uri) && {
1451
+ uri: credentialDisplay.logo?.url ?? credentialDisplay.logo.uri
1452
+ },
1453
+ ...credentialDisplay.logo.alt_text && {
1454
+ alt: credentialDisplay.logo?.alt_text
1455
+ }
1456
+ }
1457
+ },
1458
+ ...credentialDisplay.description && {
1459
+ description: credentialDisplay.description
1460
+ },
1461
+ ...credentialDisplay.text_color && {
1462
+ text: {
1463
+ color: credentialDisplay.text_color
1464
+ }
1465
+ },
1466
+ ...(credentialDisplay.background_image || credentialDisplay.background_color) && {
1467
+ background: {
1468
+ ...credentialDisplay.background_image && {
1469
+ image: {
1470
+ ...(credentialDisplay.background_image.url || credentialDisplay.background_image.uri) && {
1471
+ uri: credentialDisplay.background_image?.url ?? credentialDisplay.background_image.uri
1472
+ },
1473
+ ...credentialDisplay.background_image.alt_text && {
1474
+ alt: credentialDisplay.background_image?.alt_text
1475
+ }
1476
+ }
1477
+ },
1478
+ ...credentialDisplay.background_color && {
1479
+ color: credentialDisplay.background_color
1480
+ }
1481
+ }
1482
+ }
1483
+ };
1484
+ }, "oid4vciCredentialLocaleBrandingFrom");
1485
+ var oid4vciCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1486
+ const { credentialDisplayLocales = /* @__PURE__ */ new Map(), issuerCredentialSubjectLocales = /* @__PURE__ */ new Map() } = args;
1487
+ const locales = Array.from(/* @__PURE__ */ new Set([
1488
+ ...issuerCredentialSubjectLocales.keys(),
1489
+ ...credentialDisplayLocales.keys()
1490
+ ]));
1491
+ return Promise.all(locales.map(async (locale) => {
1492
+ const display = credentialDisplayLocales.get(locale);
1493
+ const claims = issuerCredentialSubjectLocales.get(locale);
1494
+ return {
1495
+ ...display && await oid4vciCredentialLocaleBrandingFrom({
1496
+ credentialDisplay: display
1497
+ }),
1498
+ ...locale.length > 0 && {
1499
+ locale
1587
1500
  },
1588
- guards: {
1589
- ...opts?.guards
1590
- }
1591
- }));
1592
- if (typeof opts?.subscription === "function") {
1593
- newInst.onTransition(opts.subscription);
1501
+ claims
1502
+ };
1503
+ }));
1504
+ }, "oid4vciCombineDisplayLocalesFrom");
1505
+ var sdJwtGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1506
+ const { credentialDisplay, claimsMetadata } = args;
1507
+ return sdJwtCombineDisplayLocalesFrom({
1508
+ ...claimsMetadata && {
1509
+ claimsMetadata: await sdJwtCredentialClaimLocalesFrom({
1510
+ claimsMetadata
1511
+ })
1512
+ },
1513
+ ...credentialDisplay && {
1514
+ credentialDisplayLocales: await sdJwtCredentialDisplayLocalesFrom({
1515
+ credentialDisplay
1516
+ })
1594
1517
  }
1595
- if (opts?.requireCustomNavigationHook !== true) {
1596
- newInst.onTransition((snapshot) => {
1597
- if (opts?.stateNavigationListener) {
1598
- void opts.stateNavigationListener(newInst, snapshot);
1599
- }
1518
+ });
1519
+ }, "sdJwtGetCredentialBrandingFrom");
1520
+ var sdJwtCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1521
+ const { credentialDisplay } = args;
1522
+ return credentialDisplay.reduce((localeDisplays, display) => {
1523
+ const localeKey = display.lang || "";
1524
+ localeDisplays.set(localeKey, display);
1525
+ return localeDisplays;
1526
+ }, /* @__PURE__ */ new Map());
1527
+ }, "sdJwtCredentialDisplayLocalesFrom");
1528
+ var sdJwtCredentialClaimLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1529
+ const { claimsMetadata } = args;
1530
+ const localeClaims = /* @__PURE__ */ new Map();
1531
+ claimsMetadata.forEach((claim) => {
1532
+ claim.display?.forEach((display) => {
1533
+ const { lang = "", label } = display;
1534
+ const key = claim.path.map((value) => String(value)).join(".");
1535
+ if (!localeClaims.has(lang)) {
1536
+ localeClaims.set(lang, []);
1537
+ }
1538
+ localeClaims.get(lang).push({
1539
+ key,
1540
+ name: label
1600
1541
  });
1542
+ });
1543
+ });
1544
+ return localeClaims;
1545
+ }, "sdJwtCredentialClaimLocalesFrom");
1546
+ var sdJwtCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1547
+ const { credentialDisplay } = args;
1548
+ return {
1549
+ ...credentialDisplay.name && {
1550
+ alias: credentialDisplay.name
1551
+ },
1552
+ ...credentialDisplay.lang && {
1553
+ locale: credentialDisplay.lang
1554
+ },
1555
+ ...credentialDisplay.rendering?.simple?.logo && {
1556
+ logo: {
1557
+ ...credentialDisplay.rendering.simple.logo.uri && {
1558
+ uri: credentialDisplay.rendering.simple.logo.uri
1559
+ },
1560
+ ...credentialDisplay.rendering.simple.logo.alt_text && {
1561
+ alt: credentialDisplay.rendering.simple.logo.alt_text
1562
+ }
1563
+ }
1564
+ },
1565
+ ...credentialDisplay.description && {
1566
+ description: credentialDisplay.description
1567
+ },
1568
+ ...credentialDisplay.rendering?.simple?.text_color && {
1569
+ text: {
1570
+ color: credentialDisplay.rendering.simple.text_color
1571
+ }
1572
+ },
1573
+ ...credentialDisplay.rendering?.simple?.background_color && {
1574
+ background: {
1575
+ color: credentialDisplay.rendering.simple.background_color
1576
+ }
1601
1577
  }
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!`);
1578
+ };
1579
+ }, "sdJwtCredentialLocaleBrandingFrom");
1580
+ var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1581
+ const { credentialDisplayLocales = /* @__PURE__ */ new Map(), claimsMetadata = /* @__PURE__ */ new Map() } = args;
1582
+ const locales = Array.from(/* @__PURE__ */ new Set([
1583
+ ...claimsMetadata.keys(),
1584
+ ...credentialDisplayLocales.keys()
1585
+ ]));
1586
+ return Promise.all(locales.map(async (locale) => {
1587
+ const display = credentialDisplayLocales.get(locale);
1588
+ const claims = claimsMetadata.get(locale);
1589
+ return {
1590
+ ...display && await sdJwtCredentialLocaleBrandingFrom({
1591
+ credentialDisplay: display
1592
+ }),
1593
+ ...locale.length > 0 && {
1594
+ locale
1595
+ },
1596
+ claims
1597
+ };
1598
+ }));
1599
+ }, "sdJwtCombineDisplayLocalesFrom");
1600
+ var issuerLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1601
+ const { issuerDisplay, dynamicRegistrationClientMetadata } = args;
1602
+ return {
1603
+ ...dynamicRegistrationClientMetadata?.client_name && {
1604
+ alias: dynamicRegistrationClientMetadata.client_name
1605
+ },
1606
+ ...issuerDisplay.name && {
1607
+ alias: issuerDisplay.name
1608
+ },
1609
+ ...issuerDisplay.locale && {
1610
+ locale: issuerDisplay.locale
1611
+ },
1612
+ ...(issuerDisplay.logo || dynamicRegistrationClientMetadata?.logo_uri) && {
1613
+ logo: {
1614
+ ...dynamicRegistrationClientMetadata?.logo_uri && {
1615
+ uri: dynamicRegistrationClientMetadata?.logo_uri
1616
+ },
1617
+ ...(issuerDisplay.logo?.url || issuerDisplay.logo?.uri) && {
1618
+ uri: issuerDisplay.logo?.url ?? issuerDisplay.logo?.uri
1619
+ },
1620
+ ...issuerDisplay.logo?.alt_text && {
1621
+ alt: issuerDisplay.logo?.alt_text
1622
+ }
1608
1623
  }
1609
- _FirstPartyMachine._instance = _FirstPartyMachine.newInstance(opts);
1624
+ },
1625
+ ...issuerDisplay.description && {
1626
+ description: issuerDisplay.description
1627
+ },
1628
+ ...issuerDisplay.text_color && {
1629
+ text: {
1630
+ color: issuerDisplay.text_color
1631
+ }
1632
+ },
1633
+ ...dynamicRegistrationClientMetadata?.client_uri && {
1634
+ clientUri: dynamicRegistrationClientMetadata.client_uri
1635
+ },
1636
+ ...dynamicRegistrationClientMetadata?.tos_uri && {
1637
+ tosUri: dynamicRegistrationClientMetadata.tos_uri
1638
+ },
1639
+ ...dynamicRegistrationClientMetadata?.policy_uri && {
1640
+ policyUri: dynamicRegistrationClientMetadata.policy_uri
1641
+ },
1642
+ ...dynamicRegistrationClientMetadata?.contacts && {
1643
+ contacts: dynamicRegistrationClientMetadata.contacts
1610
1644
  }
1611
- return _FirstPartyMachine._instance;
1612
- }
1613
- };
1645
+ };
1646
+ }, "issuerLocaleBrandingFrom");
1614
1647
 
1615
1648
  // src/services/OID4VCIHolderService.ts
1616
- var import_ssi_sdk = require("@sphereon/ssi-sdk.core");
1617
1649
  var getCredentialBranding = /* @__PURE__ */ __name(async (args) => {
1618
1650
  const { credentialsSupported, context } = args;
1619
1651
  const credentialBranding = {};
@@ -1685,16 +1717,7 @@ var selectCredentialLocaleBranding = /* @__PURE__ */ __name(async (args) => {
1685
1717
  }, "selectCredentialLocaleBranding");
1686
1718
  var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1687
1719
  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
- }
1720
+ const credential = extractCredentialFromResponse(mappedCredential.credentialToAccept.credentialResponse);
1698
1721
  const wrappedVC = import_ssi_types.CredentialMapper.toWrappedVerifiableCredential(credential, {
1699
1722
  hasher: hasher ?? import_ssi_sdk.defaultHasher
1700
1723
  });
@@ -1746,22 +1769,13 @@ var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1746
1769
  }, "verifyCredentialToAccept");
1747
1770
  var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1748
1771
  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
- }
1772
+ const verifiableCredential = extractCredentialFromResponse(credentialToAccept.credentialResponse);
1759
1773
  const wrappedVerifiableCredential = import_ssi_types.CredentialMapper.toWrappedVerifiableCredential(verifiableCredential, {
1760
1774
  hasher
1761
1775
  });
1762
1776
  let uniformVerifiableCredential;
1763
1777
  if (import_ssi_types.CredentialMapper.isSdJwtDecodedCredential(wrappedVerifiableCredential.credential)) {
1764
- uniformVerifiableCredential = await (0, import_ssi_types.sdJwtDecodedCredentialToUniformCredential)(wrappedVerifiableCredential.credential);
1778
+ uniformVerifiableCredential = (0, import_ssi_types.sdJwtDecodedCredentialToUniformCredential)(wrappedVerifiableCredential.credential);
1765
1779
  } else if (import_ssi_types.CredentialMapper.isSdJwtEncoded(wrappedVerifiableCredential.credential)) {
1766
1780
  if (!hasher) {
1767
1781
  return Promise.reject("a hasher is required for encoded SD-JWT credentials");
@@ -1775,6 +1789,7 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1775
1789
  uniformVerifiableCredential = wrappedVerifiableCredential.credential;
1776
1790
  }
1777
1791
  const correlationId = typeof uniformVerifiableCredential.issuer === "string" ? uniformVerifiableCredential.issuer : import_ssi_types.CredentialMapper.isSdJwtDecodedCredential(uniformVerifiableCredential) ? uniformVerifiableCredential.decodedPayload.iss : uniformVerifiableCredential.issuer.id;
1792
+ const credentialResponse = credentialToAccept.credentialResponse;
1778
1793
  return {
1779
1794
  correlationId,
1780
1795
  credentialToAccept,
@@ -1786,6 +1801,18 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1786
1801
  }
1787
1802
  };
1788
1803
  }, "mapCredentialToAccept");
1804
+ var extractCredentialFromResponse = /* @__PURE__ */ __name((credentialResponse) => {
1805
+ let credential;
1806
+ if ("credential" in credentialResponse) {
1807
+ credential = credentialResponse.credential;
1808
+ } else if ("credentials" in credentialResponse && credentialResponse.credentials && Array.isArray(credentialResponse.credentials) && credentialResponse.credentials.length > 0) {
1809
+ credential = credentialResponse.credentials[0].credential;
1810
+ }
1811
+ if (!credential) {
1812
+ throw new Error("No credential found in credential response");
1813
+ }
1814
+ return credential;
1815
+ }, "extractCredentialFromResponse");
1789
1816
  var getIdentifierOpts = /* @__PURE__ */ __name(async (args) => {
1790
1817
  const { issuanceOpt, context } = args;
1791
1818
  const { identifier: identifierArg } = issuanceOpt;
@@ -1894,24 +1921,19 @@ var getCredentialConfigsSupportedBySingleTypeOrId = /* @__PURE__ */ __name(async
1894
1921
  }
1895
1922
  __name(createIdFromTypes, "createIdFromTypes");
1896
1923
  if (configurationId) {
1897
- const allSupported2 = client.getCredentialsSupported(false);
1924
+ const allSupported2 = client.getCredentialsSupported(void 0, format);
1898
1925
  return Object.fromEntries(Object.entries(allSupported2).filter(([id, supported]) => id === configurationId || supported.id === configurationId || createIdFromTypes(supported) === configurationId));
1899
1926
  }
1900
- if (!types && !client.credentialOffer) {
1901
- return Promise.reject(Error("openID4VCIClient has no credentialOffer and no types where provided"));
1927
+ if (!client.credentialOffer) {
1928
+ return Promise.reject(Error("openID4VCIClient has no credentialOffer"));
1902
1929
  }
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
- }
1930
+ if (!types) {
1931
+ return Promise.reject(Error("openID4VCIClient has no types"));
1910
1932
  }
1911
1933
  const offerSupported = (0, import_oid4vci_common3.getSupportedCredentials)({
1912
- types: types ? [
1934
+ types: [
1913
1935
  types
1914
- ] : client.getCredentialOfferTypes(),
1936
+ ],
1915
1937
  format,
1916
1938
  version: client.version(),
1917
1939
  issuerMetadata: client.endpointMetadata.credentialIssuerMetadata
@@ -2155,7 +2177,6 @@ var startFirstPartApplicationMachine = /* @__PURE__ */ __name(async (args, conte
2155
2177
  }, "startFirstPartApplicationMachine");
2156
2178
 
2157
2179
  // src/agent/OID4VCIHolder.ts
2158
- var import_polyfill = require("cross-fetch/polyfill");
2159
2180
  var oid4vciHolderContextMethods = [
2160
2181
  "cmGetContacts",
2161
2182
  "cmGetContact",
@@ -2211,6 +2232,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2211
2232
  oid4vciHolderStart: this.oid4vciHolderStart.bind(this),
2212
2233
  oid4vciHolderGetIssuerMetadata: this.oid4vciHolderGetIssuerMetadata.bind(this),
2213
2234
  oid4vciHolderGetMachineInterpreter: this.oid4vciHolderGetMachineInterpreter.bind(this),
2235
+ oid4vciHolderPrepareAuthorizationRequest: this.oid4vciHolderPrepareAuthorizationRequest.bind(this),
2214
2236
  oid4vciHolderCreateCredentialsToSelectFrom: this.oid4vciHolderCreateCredentialsToSelectFrom.bind(this),
2215
2237
  oid4vciHolderGetContact: this.oid4vciHolderGetContact.bind(this),
2216
2238
  oid4vciHolderGetCredentials: this.oid4vciHolderGetCredentials.bind(this),
@@ -2315,6 +2337,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2315
2337
  stateNavigationListener: opts.firstPartyStateNavigationListener
2316
2338
  }, context),
2317
2339
  [OID4VCIMachineServices.createCredentialsToSelectFrom]: (args) => this.oid4vciHolderCreateCredentialsToSelectFrom(args, context),
2340
+ [OID4VCIMachineServices.prepareAuthorizationRequest]: (args) => this.oid4vciHolderPrepareAuthorizationRequest(args, context),
2318
2341
  [OID4VCIMachineServices.getContact]: (args) => this.oid4vciHolderGetContact(args, context),
2319
2342
  [OID4VCIMachineServices.getCredentials]: (args) => this.oid4vciHolderGetCredentials({
2320
2343
  accessTokenOpts: args.accessTokenOpts ?? opts.accessTokenOpts,
@@ -2363,7 +2386,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2363
2386
  ...this.defaultAuthorizationRequestOpts,
2364
2387
  ...args.authorizationRequestOpts
2365
2388
  };
2366
- authorizationRequestOpts.authorizationDetails = authorizationRequestOpts?.authorizationDetails ? (0, import_utils2.asArray)(authorizationRequestOpts.authorizationDetails).filter((detail) => typeof detail === "string" || this.vcFormatPreferences.includes(detail.format)) : void 0;
2389
+ authorizationRequestOpts.authorizationDetails = authorizationRequestOpts?.authorizationDetails ? (0, import_utils2.asArray)(authorizationRequestOpts.authorizationDetails) : void 0;
2367
2390
  if (!authorizationRequestOpts.redirectUri) {
2368
2391
  authorizationRequestOpts.redirectUri = _OID4VCIHolder.DEFAULT_MOBILE_REDIRECT_URI;
2369
2392
  }
@@ -2376,10 +2399,9 @@ var OID4VCIHolder = class _OID4VCIHolder {
2376
2399
  formats = Array.from(new Set(authFormats));
2377
2400
  }
2378
2401
  let oid4vciClient;
2379
- let types = void 0;
2380
2402
  let offer;
2381
2403
  if (requestData.existingClientState) {
2382
- oid4vciClient = await import_oid4vci_client3.OpenID4VCIClient.fromState({
2404
+ oid4vciClient = await import_oid4vci_client3.OpenID4VCIClientV1_0_15.fromState({
2383
2405
  state: requestData.existingClientState
2384
2406
  });
2385
2407
  offer = oid4vciClient.credentialOffer;
@@ -2396,50 +2418,78 @@ var OID4VCIHolder = class _OID4VCIHolder {
2396
2418
  }
2397
2419
  if (!offer) {
2398
2420
  logger.log(`Issuer url received (no credential offer): ${uri}`);
2399
- oid4vciClient = await import_oid4vci_client3.OpenID4VCIClient.fromCredentialIssuer({
2421
+ oid4vciClient = await import_oid4vci_client3.OpenID4VCIClientV1_0_15.fromCredentialIssuer({
2400
2422
  credentialIssuer: uri,
2401
2423
  authorizationRequest: authorizationRequestOpts,
2402
2424
  clientId: authorizationRequestOpts.clientId,
2403
- createAuthorizationRequestURL: requestData.createAuthorizationRequestURL ?? true
2425
+ createAuthorizationRequestURL: false
2404
2426
  });
2405
2427
  } else {
2406
2428
  logger.log(`Credential offer received: ${uri}`);
2407
- oid4vciClient = await import_oid4vci_client3.OpenID4VCIClient.fromURI({
2429
+ oid4vciClient = await import_oid4vci_client3.OpenID4VCIClientV1_0_15.fromURI({
2408
2430
  uri,
2409
2431
  authorizationRequest: authorizationRequestOpts,
2410
2432
  clientId: authorizationRequestOpts.clientId,
2411
- createAuthorizationRequestURL: requestData.createAuthorizationRequestURL ?? true
2433
+ createAuthorizationRequestURL: false
2412
2434
  });
2413
2435
  }
2414
2436
  }
2437
+ let configurationIds = [];
2415
2438
  if (offer) {
2416
- types = (0, import_oid4vci_common4.getTypesFromCredentialOffer)(offer.original_credential_offer);
2439
+ configurationIds = offer.original_credential_offer.credential_configuration_ids;
2417
2440
  } else {
2418
- types = (0, import_utils2.asArray)(authorizationRequestOpts.authorizationDetails).map((authReqOpts) => (0, import_oid4vci_common4.getTypesFromAuthorizationDetails)(authReqOpts) ?? []).filter((inner) => inner.length > 0);
2441
+ configurationIds = (0, import_utils2.asArray)(authorizationRequestOpts.authorizationDetails).map((authReqOpts) => authReqOpts.credential_configuration_id).filter((id) => !!id);
2419
2442
  }
2420
- const serverMetadata = await oid4vciClient.retrieveServerMetadata();
2421
2443
  const credentialsSupported = await getCredentialConfigsSupportedMerged({
2422
2444
  client: oid4vciClient,
2423
2445
  vcFormatPreferences: formats,
2424
- types
2446
+ configurationIds
2425
2447
  });
2448
+ const serverMetadata = await oid4vciClient.retrieveServerMetadata();
2426
2449
  const credentialBranding = await getCredentialBranding({
2427
2450
  credentialsSupported,
2428
2451
  context
2429
2452
  });
2430
- const authorizationCodeURL = oid4vciClient.authorizationURL;
2431
- if (authorizationCodeURL) {
2432
- logger.log(`authorization code URL ${authorizationCodeURL}`);
2433
- }
2434
2453
  const oid4vciClientState = JSON.parse(await oid4vciClient.exportState());
2435
2454
  return {
2436
- authorizationCodeURL,
2437
2455
  credentialBranding,
2438
2456
  credentialsSupported,
2439
2457
  serverMetadata,
2440
2458
  oid4vciClientState
2441
2459
  };
2442
2460
  }
2461
+ async oid4vciHolderPrepareAuthorizationRequest(args, context) {
2462
+ const { openID4VCIClientState, contact } = args;
2463
+ if (!openID4VCIClientState) {
2464
+ return Promise.reject(Error("Missing openID4VCI client state in context"));
2465
+ }
2466
+ const clientId = contact?.identities.map((identity) => {
2467
+ const connectionConfig = identity.connection?.config;
2468
+ if (connectionConfig && "clientId" in connectionConfig) {
2469
+ return connectionConfig.clientId;
2470
+ }
2471
+ return void 0;
2472
+ }).find((clientId2) => clientId2);
2473
+ if (!clientId) {
2474
+ return Promise.reject(Error(`Missing client id in contact's connectionConfig`));
2475
+ }
2476
+ const client = await import_oid4vci_client3.OpenID4VCIClient.fromState({
2477
+ state: openID4VCIClientState
2478
+ });
2479
+ const authorizationCodeURL = await client.createAuthorizationRequestUrl({
2480
+ authorizationRequest: {
2481
+ clientId
2482
+ }
2483
+ });
2484
+ if (authorizationCodeURL) {
2485
+ logger.log(`authorization code URL ${authorizationCodeURL}`);
2486
+ }
2487
+ return {
2488
+ authorizationCodeURL,
2489
+ // Needed, because the above createAuthorizationRequestUrl manipulates the state, adding pkce opts to the state
2490
+ oid4vciClientState: JSON.parse(await client.exportState())
2491
+ };
2492
+ }
2443
2493
  async oid4vciHolderCreateCredentialsToSelectFrom(args, context) {
2444
2494
  const { credentialBranding, locale, selectedCredentials, credentialsSupported } = args;
2445
2495
  logger.info(`Credentials supported ${Object.keys(credentialsSupported).join(", ")}`);
@@ -2511,7 +2561,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2511
2561
  if (!openID4VCIClientState) {
2512
2562
  return Promise.reject(Error("Missing openID4VCI client state in context"));
2513
2563
  }
2514
- const client = await import_oid4vci_client3.OpenID4VCIClient.fromState({
2564
+ const client = await import_oid4vci_client3.OpenID4VCIClientV1_0_15.fromState({
2515
2565
  state: openID4VCIClientState
2516
2566
  });
2517
2567
  const credentialsSupported = await getCredentialConfigsSupportedMerged({
@@ -2650,7 +2700,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2650
2700
  alias: credentialsToAccept[0].correlationId,
2651
2701
  origin: import_ssi_sdk3.IdentityOrigin.EXTERNAL,
2652
2702
  roles: [
2653
- import_ssi_sdk3.CredentialRole.ISSUER
2703
+ import_ssi_types2.CredentialRole.ISSUER
2654
2704
  ],
2655
2705
  identifier: {
2656
2706
  type: identifierType,
@@ -2685,7 +2735,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2685
2735
  }
2686
2736
  async oid4vciHolderGetIssuerBranding(args, context) {
2687
2737
  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];
2738
+ const issuerCorrelationId = contact?.identities.filter((identity) => identity.roles.includes(import_ssi_types2.CredentialRole.ISSUER)).map((identity) => identity.identifier.correlationId)[0];
2689
2739
  if (issuerCorrelationId) {
2690
2740
  const branding = await context.agent.ibGetIssuerBranding({
2691
2741
  filter: [
@@ -2715,7 +2765,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2715
2765
  if (!contact) {
2716
2766
  return Promise.reject(Error("Missing contact in context"));
2717
2767
  }
2718
- const issuerCorrelationId = contact?.identities.filter((identity) => identity.roles.includes(import_ssi_sdk3.CredentialRole.ISSUER)).map((identity) => identity.identifier.correlationId)[0];
2768
+ const issuerCorrelationId = contact?.identities.filter((identity) => identity.roles.includes(import_ssi_types2.CredentialRole.ISSUER)).map((identity) => identity.identifier.correlationId)[0];
2719
2769
  const branding = await context.agent.ibGetIssuerBranding({
2720
2770
  filter: [
2721
2771
  {
@@ -2811,16 +2861,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2811
2861
  if (Array.isArray(subjectIssuance?.notification_events_supported)) {
2812
2862
  event = subjectIssuance.notification_events_supported.includes("credential_accepted_holder_signed") ? "credential_accepted_holder_signed" : "credential_deleted_holder_signed";
2813
2863
  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
- }
2864
+ const issuerVC = extractCredentialFromResponse(mappedCredentialToAccept.credentialToAccept.credentialResponse);
2824
2865
  const wrappedIssuerVC = import_ssi_types2.CredentialMapper.toWrappedVerifiableCredential(issuerVC, {
2825
2866
  hasher: this.hasher ?? import_ssi_sdk2.defaultHasher
2826
2867
  });
@@ -2926,7 +2967,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2926
2967
  rawDocument: (0, import_ssi_sdk3.ensureRawDocument)(persistCredential),
2927
2968
  kmsKeyRef,
2928
2969
  identifierMethod: method,
2929
- credentialRole: import_ssi_sdk3.CredentialRole.HOLDER,
2970
+ credentialRole: import_ssi_types2.CredentialRole.HOLDER,
2930
2971
  issuerCorrelationType: issuer?.startsWith("did:") ? import_ssi_sdk3.CredentialCorrelationType.DID : import_ssi_sdk3.CredentialCorrelationType.URL,
2931
2972
  issuerCorrelationId: issuer,
2932
2973
  subjectCorrelationType,