@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.js CHANGED
@@ -55,15 +55,16 @@ var require_nl = __commonJS({
55
55
  });
56
56
 
57
57
  // src/agent/OID4VCIHolder.ts
58
- import { CredentialOfferClient, MetadataClient, OpenID4VCIClient as OpenID4VCIClient2 } from "@sphereon/oid4vci-client";
59
- import { DefaultURISchemes, getTypesFromAuthorizationDetails, getTypesFromCredentialOffer, getTypesFromObject as getTypesFromObject2 } from "@sphereon/oid4vci-common";
58
+ import { CredentialOfferClient, MetadataClient, OpenID4VCIClient as OpenID4VCIClient2, OpenID4VCIClientV1_0_15 } from "@sphereon/oid4vci-client";
59
+ import { DefaultURISchemes, getTypesFromObject as getTypesFromObject2 } from "@sphereon/oid4vci-common";
60
60
  import { SupportedDidMethodEnum as SupportedDidMethodEnum2 } from "@sphereon/ssi-sdk-ext.did-utils";
61
61
  import { isManagedIdentifierDidOpts, isManagedIdentifierDidResult as isManagedIdentifierDidResult2, isManagedIdentifierJwkResult, isManagedIdentifierKidResult, isManagedIdentifierResult as isManagedIdentifierResult2, isManagedIdentifierX5cOpts, isManagedIdentifierX5cResult } from "@sphereon/ssi-sdk-ext.identifier-resolution";
62
62
  import { signatureAlgorithmFromKey } from "@sphereon/ssi-sdk-ext.key-utils";
63
63
  import { defaultHasher as defaultHasher2 } from "@sphereon/ssi-sdk.core";
64
- import { ConnectionType, CorrelationIdentifierType, CredentialCorrelationType, CredentialRole, ensureRawDocument, IdentityOrigin } from "@sphereon/ssi-sdk.data-store";
65
- import { CredentialMapper as CredentialMapper2, JoseSignatureAlgorithm as JoseSignatureAlgorithm2, Loggers, parseDid } from "@sphereon/ssi-types";
64
+ import { ConnectionType, CorrelationIdentifierType, CredentialCorrelationType, ensureRawDocument, IdentityOrigin } from "@sphereon/ssi-sdk.data-store-types";
65
+ import { CredentialMapper as CredentialMapper2, CredentialRole, JoseSignatureAlgorithm as JoseSignatureAlgorithm2, Loggers, parseDid } from "@sphereon/ssi-types";
66
66
  import { asArray as asArray2, computeEntryHash } from "@veramo/utils";
67
+ import fetch from "cross-fetch";
67
68
  import { decodeJWT } from "did-jwt";
68
69
  import { v4 as uuidv42 } from "uuid";
69
70
 
@@ -103,6 +104,7 @@ var OID4VCIMachineStates = /* @__PURE__ */ (function(OID4VCIMachineStates2) {
103
104
  OID4VCIMachineStates2["selectCredentials"] = "selectCredentials";
104
105
  OID4VCIMachineStates2["transitionFromSelectingCredentials"] = "transitionFromSelectingCredentials";
105
106
  OID4VCIMachineStates2["verifyPin"] = "verifyPin";
107
+ OID4VCIMachineStates2["prepareAuthorizationRequest"] = "prepareAuthorizationRequest";
106
108
  OID4VCIMachineStates2["initiateAuthorizationRequest"] = "initiateAuthorizationRequest";
107
109
  OID4VCIMachineStates2["waitForAuthorizationResponse"] = "waitForAuthorizationResponse";
108
110
  OID4VCIMachineStates2["getCredentials"] = "getCredentials";
@@ -167,6 +169,7 @@ var OID4VCIMachineServices = /* @__PURE__ */ (function(OID4VCIMachineServices2)
167
169
  OID4VCIMachineServices2["getFederationTrust"] = "getFederationTrust";
168
170
  OID4VCIMachineServices2["addContactIdentity"] = "addContactIdentity";
169
171
  OID4VCIMachineServices2["createCredentialsToSelectFrom"] = "createCredentialsToSelectFrom";
172
+ OID4VCIMachineServices2["prepareAuthorizationRequest"] = "prepareAuthorizationRequest";
170
173
  OID4VCIMachineServices2["getIssuerBranding"] = "getIssuerBranding";
171
174
  OID4VCIMachineServices2["storeIssuerBranding"] = "storeIssuerBranding";
172
175
  OID4VCIMachineServices2["getCredentials"] = "getCredentials";
@@ -308,9 +311,7 @@ var oid4vciRequireAuthorizationGuard = /* @__PURE__ */ __name((ctx, _event) => {
308
311
  if (!openID4VCIClientState) {
309
312
  throw Error("Missing openID4VCI client state in context");
310
313
  }
311
- if (!openID4VCIClientState.authorizationURL) {
312
- return false;
313
- } else if (openID4VCIClientState.authorizationRequestOpts) {
314
+ if (openID4VCIClientState.authorizationURL && openID4VCIClientState.authorizationRequestOpts) {
314
315
  return !ctx.openID4VCIClientState?.authorizationCodeResponse;
315
316
  } else if (openID4VCIClientState.credentialOffer?.supportedFlows?.includes(AuthzFlowType.AUTHORIZATION_CODE_FLOW)) {
316
317
  return !ctx.openID4VCIClientState?.authorizationCodeResponse;
@@ -361,7 +362,6 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
361
362
  onDone: {
362
363
  target: OID4VCIMachineStates.createCredentialsToSelectFrom,
363
364
  actions: assign({
364
- authorizationCodeURL: /* @__PURE__ */ __name((_ctx, _event) => _event.data.authorizationCodeURL, "authorizationCodeURL"),
365
365
  credentialBranding: /* @__PURE__ */ __name((_ctx, _event) => _event.data.credentialBranding ?? {}, "credentialBranding"),
366
366
  credentialsSupported: /* @__PURE__ */ __name((_ctx, _event) => _event.data.credentialsSupported, "credentialsSupported"),
367
367
  serverMetadata: /* @__PURE__ */ __name((_ctx, _event) => _event.data.serverMetadata, "serverMetadata"),
@@ -598,6 +598,10 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
598
598
  target: OID4VCIMachineStates.startFirstPartApplicationFlow,
599
599
  cond: OID4VCIMachineGuards.isFirstPartyApplication
600
600
  },
601
+ {
602
+ target: OID4VCIMachineStates.prepareAuthorizationRequest,
603
+ cond: OID4VCIMachineGuards.requireAuthorizationGuard
604
+ },
601
605
  {
602
606
  target: OID4VCIMachineStates.initiateAuthorizationRequest,
603
607
  cond: OID4VCIMachineGuards.requireAuthorizationGuard
@@ -673,12 +677,16 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
673
677
  target: OID4VCIMachineStates.startFirstPartApplicationFlow,
674
678
  cond: OID4VCIMachineGuards.isFirstPartyApplication
675
679
  },
680
+ {
681
+ target: OID4VCIMachineStates.prepareAuthorizationRequest,
682
+ cond: OID4VCIMachineGuards.requireAuthorizationGuard
683
+ },
676
684
  {
677
685
  target: OID4VCIMachineStates.verifyPin,
678
686
  cond: OID4VCIMachineGuards.requirePinGuard
679
687
  },
680
688
  {
681
- target: OID4VCIMachineStates.initiateAuthorizationRequest,
689
+ target: OID4VCIMachineStates.prepareAuthorizationRequest,
682
690
  cond: OID4VCIMachineGuards.requireAuthorizationGuard
683
691
  },
684
692
  {
@@ -686,6 +694,29 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
686
694
  }
687
695
  ]
688
696
  },
697
+ [OID4VCIMachineStates.prepareAuthorizationRequest]: {
698
+ id: OID4VCIMachineStates.prepareAuthorizationRequest,
699
+ invoke: {
700
+ src: OID4VCIMachineServices.prepareAuthorizationRequest,
701
+ onDone: {
702
+ target: OID4VCIMachineStates.initiateAuthorizationRequest,
703
+ actions: assign({
704
+ authorizationCodeURL: /* @__PURE__ */ __name((_ctx, _event) => _event.data.authorizationCodeURL, "authorizationCodeURL"),
705
+ openID4VCIClientState: /* @__PURE__ */ __name((_ctx, _event) => _event.data.oid4vciClientState, "openID4VCIClientState")
706
+ })
707
+ },
708
+ onError: {
709
+ target: OID4VCIMachineStates.handleError,
710
+ actions: assign({
711
+ error: /* @__PURE__ */ __name((_ctx, _event) => ({
712
+ title: translate("oid4vci_machine_prepare_authorization_error_title"),
713
+ message: _event.data.message,
714
+ stack: _event.data.stack
715
+ }), "error")
716
+ })
717
+ }
718
+ }
719
+ },
689
720
  [OID4VCIMachineStates.initiateAuthorizationRequest]: {
690
721
  id: OID4VCIMachineStates.initiateAuthorizationRequest,
691
722
  on: {
@@ -978,276 +1009,15 @@ var OID4VCIMachine = class {
978
1009
 
979
1010
  // src/services/OID4VCIHolderService.ts
980
1011
  import { LOG } from "@sphereon/oid4vci-client";
981
- import { getSupportedCredentials, getTypesFromCredentialSupported, getTypesFromObject, OpenId4VCIVersion } from "@sphereon/oid4vci-common";
1012
+ import { getSupportedCredentials, getTypesFromCredentialSupported, getTypesFromObject } from "@sphereon/oid4vci-common";
982
1013
  import { KeyUse } from "@sphereon/ssi-sdk-ext.did-resolver-jwk";
983
1014
  import { getOrCreatePrimaryIdentifier, SupportedDidMethodEnum } from "@sphereon/ssi-sdk-ext.did-utils";
984
1015
  import { isIIdentifier, isManagedIdentifierDidResult, isManagedIdentifierResult, managedIdentifierToJwk } from "@sphereon/ssi-sdk-ext.identifier-resolution";
985
1016
  import { keyTypeFromCryptographicSuite } from "@sphereon/ssi-sdk-ext.key-utils";
1017
+ import { defaultHasher } from "@sphereon/ssi-sdk.core";
986
1018
  import { CredentialMapper, JoseSignatureAlgorithm, mdocDecodedCredentialToUniformCredential, sdJwtDecodedCredentialToUniformCredential } from "@sphereon/ssi-types";
987
1019
  import { asArray } from "@veramo/utils";
988
1020
 
989
- // src/mappers/OIDC4VCIBrandingMapper.ts
990
- var oid4vciGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
991
- const { credentialDisplay, issuerCredentialSubject } = args;
992
- return oid4vciCombineDisplayLocalesFrom({
993
- ...issuerCredentialSubject && {
994
- issuerCredentialSubjectLocales: await oid4vciIssuerCredentialSubjectLocalesFrom({
995
- issuerCredentialSubject
996
- })
997
- },
998
- ...credentialDisplay && {
999
- credentialDisplayLocales: await oid4vciCredentialDisplayLocalesFrom({
1000
- credentialDisplay
1001
- })
1002
- }
1003
- });
1004
- }, "oid4vciGetCredentialBrandingFrom");
1005
- var oid4vciCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1006
- const { credentialDisplay } = args;
1007
- return credentialDisplay.reduce((localeDisplays, display) => {
1008
- const localeKey = display.locale || "";
1009
- localeDisplays.set(localeKey, display);
1010
- return localeDisplays;
1011
- }, /* @__PURE__ */ new Map());
1012
- }, "oid4vciCredentialDisplayLocalesFrom");
1013
- var oid4vciIssuerCredentialSubjectLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1014
- const { issuerCredentialSubject } = args;
1015
- const localeClaims = /* @__PURE__ */ new Map();
1016
- const processClaimObject = /* @__PURE__ */ __name((claim, parentKey = "") => {
1017
- Object.entries(claim).forEach(([key, value]) => {
1018
- if (key === "mandatory" || key === "value_type") {
1019
- return;
1020
- }
1021
- if (key === "display" && Array.isArray(value)) {
1022
- value.forEach(({ name, locale = "" }) => {
1023
- if (!name) {
1024
- return;
1025
- }
1026
- if (!localeClaims.has(locale)) {
1027
- localeClaims.set(locale, []);
1028
- }
1029
- localeClaims.get(locale).push({
1030
- key: parentKey,
1031
- name
1032
- });
1033
- });
1034
- } else if (typeof value === "object" && value !== null) {
1035
- processClaimObject(value, parentKey ? `${parentKey}.${key}` : key);
1036
- }
1037
- });
1038
- }, "processClaimObject");
1039
- processClaimObject(issuerCredentialSubject);
1040
- return localeClaims;
1041
- }, "oid4vciIssuerCredentialSubjectLocalesFrom");
1042
- var oid4vciCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1043
- const { credentialDisplay } = args;
1044
- return {
1045
- ...credentialDisplay.name && {
1046
- alias: credentialDisplay.name
1047
- },
1048
- ...credentialDisplay.locale && {
1049
- locale: credentialDisplay.locale
1050
- },
1051
- ...credentialDisplay.logo && {
1052
- logo: {
1053
- ...(credentialDisplay.logo.url || credentialDisplay.logo.uri) && {
1054
- uri: credentialDisplay.logo?.url ?? credentialDisplay.logo.uri
1055
- },
1056
- ...credentialDisplay.logo.alt_text && {
1057
- alt: credentialDisplay.logo?.alt_text
1058
- }
1059
- }
1060
- },
1061
- ...credentialDisplay.description && {
1062
- description: credentialDisplay.description
1063
- },
1064
- ...credentialDisplay.text_color && {
1065
- text: {
1066
- color: credentialDisplay.text_color
1067
- }
1068
- },
1069
- ...(credentialDisplay.background_image || credentialDisplay.background_color) && {
1070
- background: {
1071
- ...credentialDisplay.background_image && {
1072
- image: {
1073
- ...(credentialDisplay.background_image.url || credentialDisplay.background_image.uri) && {
1074
- uri: credentialDisplay.background_image?.url ?? credentialDisplay.background_image.uri
1075
- },
1076
- ...credentialDisplay.background_image.alt_text && {
1077
- alt: credentialDisplay.background_image?.alt_text
1078
- }
1079
- }
1080
- },
1081
- ...credentialDisplay.background_color && {
1082
- color: credentialDisplay.background_color
1083
- }
1084
- }
1085
- }
1086
- };
1087
- }, "oid4vciCredentialLocaleBrandingFrom");
1088
- var oid4vciCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1089
- const { credentialDisplayLocales = /* @__PURE__ */ new Map(), issuerCredentialSubjectLocales = /* @__PURE__ */ new Map() } = args;
1090
- const locales = Array.from(/* @__PURE__ */ new Set([
1091
- ...issuerCredentialSubjectLocales.keys(),
1092
- ...credentialDisplayLocales.keys()
1093
- ]));
1094
- return Promise.all(locales.map(async (locale) => {
1095
- const display = credentialDisplayLocales.get(locale);
1096
- const claims = issuerCredentialSubjectLocales.get(locale);
1097
- return {
1098
- ...display && await oid4vciCredentialLocaleBrandingFrom({
1099
- credentialDisplay: display
1100
- }),
1101
- ...locale.length > 0 && {
1102
- locale
1103
- },
1104
- claims
1105
- };
1106
- }));
1107
- }, "oid4vciCombineDisplayLocalesFrom");
1108
- var sdJwtGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1109
- const { credentialDisplay, claimsMetadata } = args;
1110
- return sdJwtCombineDisplayLocalesFrom({
1111
- ...claimsMetadata && {
1112
- claimsMetadata: await sdJwtCredentialClaimLocalesFrom({
1113
- claimsMetadata
1114
- })
1115
- },
1116
- ...credentialDisplay && {
1117
- credentialDisplayLocales: await sdJwtCredentialDisplayLocalesFrom({
1118
- credentialDisplay
1119
- })
1120
- }
1121
- });
1122
- }, "sdJwtGetCredentialBrandingFrom");
1123
- var sdJwtCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1124
- const { credentialDisplay } = args;
1125
- return credentialDisplay.reduce((localeDisplays, display) => {
1126
- const localeKey = display.lang || "";
1127
- localeDisplays.set(localeKey, display);
1128
- return localeDisplays;
1129
- }, /* @__PURE__ */ new Map());
1130
- }, "sdJwtCredentialDisplayLocalesFrom");
1131
- var sdJwtCredentialClaimLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1132
- const { claimsMetadata } = args;
1133
- const localeClaims = /* @__PURE__ */ new Map();
1134
- claimsMetadata.forEach((claim) => {
1135
- claim.display?.forEach((display) => {
1136
- const { lang = "", label } = display;
1137
- const key = claim.path.map((value) => String(value)).join(".");
1138
- if (!localeClaims.has(lang)) {
1139
- localeClaims.set(lang, []);
1140
- }
1141
- localeClaims.get(lang).push({
1142
- key,
1143
- name: label
1144
- });
1145
- });
1146
- });
1147
- return localeClaims;
1148
- }, "sdJwtCredentialClaimLocalesFrom");
1149
- var sdJwtCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1150
- const { credentialDisplay } = args;
1151
- return {
1152
- ...credentialDisplay.name && {
1153
- alias: credentialDisplay.name
1154
- },
1155
- ...credentialDisplay.lang && {
1156
- locale: credentialDisplay.lang
1157
- },
1158
- ...credentialDisplay.rendering?.simple?.logo && {
1159
- logo: {
1160
- ...credentialDisplay.rendering.simple.logo.uri && {
1161
- uri: credentialDisplay.rendering.simple.logo.uri
1162
- },
1163
- ...credentialDisplay.rendering.simple.logo.alt_text && {
1164
- alt: credentialDisplay.rendering.simple.logo.alt_text
1165
- }
1166
- }
1167
- },
1168
- ...credentialDisplay.description && {
1169
- description: credentialDisplay.description
1170
- },
1171
- ...credentialDisplay.rendering?.simple?.text_color && {
1172
- text: {
1173
- color: credentialDisplay.rendering.simple.text_color
1174
- }
1175
- },
1176
- ...credentialDisplay.rendering?.simple?.background_color && {
1177
- background: {
1178
- color: credentialDisplay.rendering.simple.background_color
1179
- }
1180
- }
1181
- };
1182
- }, "sdJwtCredentialLocaleBrandingFrom");
1183
- var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1184
- const { credentialDisplayLocales = /* @__PURE__ */ new Map(), claimsMetadata = /* @__PURE__ */ new Map() } = args;
1185
- const locales = Array.from(/* @__PURE__ */ new Set([
1186
- ...claimsMetadata.keys(),
1187
- ...credentialDisplayLocales.keys()
1188
- ]));
1189
- return Promise.all(locales.map(async (locale) => {
1190
- const display = credentialDisplayLocales.get(locale);
1191
- const claims = claimsMetadata.get(locale);
1192
- return {
1193
- ...display && await sdJwtCredentialLocaleBrandingFrom({
1194
- credentialDisplay: display
1195
- }),
1196
- ...locale.length > 0 && {
1197
- locale
1198
- },
1199
- claims
1200
- };
1201
- }));
1202
- }, "sdJwtCombineDisplayLocalesFrom");
1203
- var issuerLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1204
- const { issuerDisplay, dynamicRegistrationClientMetadata } = args;
1205
- return {
1206
- ...dynamicRegistrationClientMetadata?.client_name && {
1207
- alias: dynamicRegistrationClientMetadata.client_name
1208
- },
1209
- ...issuerDisplay.name && {
1210
- alias: issuerDisplay.name
1211
- },
1212
- ...issuerDisplay.locale && {
1213
- locale: issuerDisplay.locale
1214
- },
1215
- ...(issuerDisplay.logo || dynamicRegistrationClientMetadata?.logo_uri) && {
1216
- logo: {
1217
- ...dynamicRegistrationClientMetadata?.logo_uri && {
1218
- uri: dynamicRegistrationClientMetadata?.logo_uri
1219
- },
1220
- ...(issuerDisplay.logo?.url || issuerDisplay.logo?.uri) && {
1221
- uri: issuerDisplay.logo?.url ?? issuerDisplay.logo?.uri
1222
- },
1223
- ...issuerDisplay.logo?.alt_text && {
1224
- alt: issuerDisplay.logo?.alt_text
1225
- }
1226
- }
1227
- },
1228
- ...issuerDisplay.description && {
1229
- description: issuerDisplay.description
1230
- },
1231
- ...issuerDisplay.text_color && {
1232
- text: {
1233
- color: issuerDisplay.text_color
1234
- }
1235
- },
1236
- ...dynamicRegistrationClientMetadata?.client_uri && {
1237
- clientUri: dynamicRegistrationClientMetadata.client_uri
1238
- },
1239
- ...dynamicRegistrationClientMetadata?.tos_uri && {
1240
- tosUri: dynamicRegistrationClientMetadata.tos_uri
1241
- },
1242
- ...dynamicRegistrationClientMetadata?.policy_uri && {
1243
- policyUri: dynamicRegistrationClientMetadata.policy_uri
1244
- },
1245
- ...dynamicRegistrationClientMetadata?.contacts && {
1246
- contacts: dynamicRegistrationClientMetadata.contacts
1247
- }
1248
- };
1249
- }, "issuerLocaleBrandingFrom");
1250
-
1251
1021
  // src/machines/firstPartyMachine.ts
1252
1022
  import { assign as assign2, createMachine as createMachine2, interpret as interpret2 } from "xstate";
1253
1023
  import { AuthorizationChallengeError } from "@sphereon/oid4vci-common";
@@ -1484,57 +1254,318 @@ var FirstPartyMachine = class _FirstPartyMachine {
1484
1254
  _FirstPartyMachine.stopInstance();
1485
1255
  }
1486
1256
  }
1487
- _FirstPartyMachine._instance = void 0;
1488
- }
1489
- static stopInstance() {
1490
- if (!_FirstPartyMachine.hasInstance()) {
1491
- return;
1492
- }
1493
- _FirstPartyMachine.instance.stop();
1494
- _FirstPartyMachine._instance = void 0;
1495
- }
1496
- static newInstance(opts) {
1497
- const { agentContext } = opts;
1498
- const services = {
1499
- [FirstPartyMachineServices.sendAuthorizationChallengeRequest]: sendAuthorizationChallengeRequest,
1500
- [FirstPartyMachineServices.createConfig]: (args) => createConfig(args, agentContext),
1501
- [FirstPartyMachineServices.getSiopRequest]: (args) => getSiopRequest(args, agentContext),
1502
- [FirstPartyMachineServices.sendAuthorizationResponse]: (args) => sendAuthorizationResponse(args, agentContext)
1503
- };
1504
- const newInst = interpret2(createFirstPartyActivationMachine(opts).withConfig({
1505
- services: {
1506
- ...services,
1507
- ...opts?.services
1257
+ _FirstPartyMachine._instance = void 0;
1258
+ }
1259
+ static stopInstance() {
1260
+ if (!_FirstPartyMachine.hasInstance()) {
1261
+ return;
1262
+ }
1263
+ _FirstPartyMachine.instance.stop();
1264
+ _FirstPartyMachine._instance = void 0;
1265
+ }
1266
+ static newInstance(opts) {
1267
+ const { agentContext } = opts;
1268
+ const services = {
1269
+ [FirstPartyMachineServices.sendAuthorizationChallengeRequest]: sendAuthorizationChallengeRequest,
1270
+ [FirstPartyMachineServices.createConfig]: (args) => createConfig(args, agentContext),
1271
+ [FirstPartyMachineServices.getSiopRequest]: (args) => getSiopRequest(args, agentContext),
1272
+ [FirstPartyMachineServices.sendAuthorizationResponse]: (args) => sendAuthorizationResponse(args, agentContext)
1273
+ };
1274
+ const newInst = interpret2(createFirstPartyActivationMachine(opts).withConfig({
1275
+ services: {
1276
+ ...services,
1277
+ ...opts?.services
1278
+ },
1279
+ guards: {
1280
+ ...opts?.guards
1281
+ }
1282
+ }));
1283
+ if (typeof opts?.subscription === "function") {
1284
+ newInst.onTransition(opts.subscription);
1285
+ }
1286
+ if (opts?.requireCustomNavigationHook !== true) {
1287
+ newInst.onTransition((snapshot) => {
1288
+ if (opts?.stateNavigationListener) {
1289
+ void opts.stateNavigationListener(newInst, snapshot);
1290
+ }
1291
+ });
1292
+ }
1293
+ return newInst;
1294
+ }
1295
+ static getInstance(opts) {
1296
+ if (!_FirstPartyMachine._instance) {
1297
+ if (opts?.requireExisting === true) {
1298
+ throw Error(`Existing FirstPartyMachine instance requested, but none was created at this point!`);
1299
+ }
1300
+ _FirstPartyMachine._instance = _FirstPartyMachine.newInstance(opts);
1301
+ }
1302
+ return _FirstPartyMachine._instance;
1303
+ }
1304
+ };
1305
+
1306
+ // src/mappers/OIDC4VCIBrandingMapper.ts
1307
+ var oid4vciGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1308
+ const { credentialDisplay, issuerCredentialSubject } = args;
1309
+ return oid4vciCombineDisplayLocalesFrom({
1310
+ ...issuerCredentialSubject && {
1311
+ issuerCredentialSubjectLocales: await oid4vciIssuerCredentialSubjectLocalesFrom({
1312
+ issuerCredentialSubject
1313
+ })
1314
+ },
1315
+ ...credentialDisplay && {
1316
+ credentialDisplayLocales: await oid4vciCredentialDisplayLocalesFrom({
1317
+ credentialDisplay
1318
+ })
1319
+ }
1320
+ });
1321
+ }, "oid4vciGetCredentialBrandingFrom");
1322
+ var oid4vciCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1323
+ const { credentialDisplay } = args;
1324
+ return credentialDisplay.reduce((localeDisplays, display) => {
1325
+ const localeKey = display.locale || "";
1326
+ localeDisplays.set(localeKey, display);
1327
+ return localeDisplays;
1328
+ }, /* @__PURE__ */ new Map());
1329
+ }, "oid4vciCredentialDisplayLocalesFrom");
1330
+ var oid4vciIssuerCredentialSubjectLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1331
+ const { issuerCredentialSubject } = args;
1332
+ const localeClaims = /* @__PURE__ */ new Map();
1333
+ const processClaimObject = /* @__PURE__ */ __name((claim, parentKey = "") => {
1334
+ Object.entries(claim).forEach(([key, value]) => {
1335
+ if (key === "mandatory" || key === "value_type") {
1336
+ return;
1337
+ }
1338
+ if (key === "display" && Array.isArray(value)) {
1339
+ value.forEach(({ name, locale = "" }) => {
1340
+ if (!name) {
1341
+ return;
1342
+ }
1343
+ if (!localeClaims.has(locale)) {
1344
+ localeClaims.set(locale, []);
1345
+ }
1346
+ localeClaims.get(locale).push({
1347
+ key: parentKey,
1348
+ name
1349
+ });
1350
+ });
1351
+ } else if (typeof value === "object" && value !== null) {
1352
+ processClaimObject(value, parentKey ? `${parentKey}.${key}` : key);
1353
+ }
1354
+ });
1355
+ }, "processClaimObject");
1356
+ processClaimObject(issuerCredentialSubject);
1357
+ return localeClaims;
1358
+ }, "oid4vciIssuerCredentialSubjectLocalesFrom");
1359
+ var oid4vciCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1360
+ const { credentialDisplay } = args;
1361
+ return {
1362
+ ...credentialDisplay.name && {
1363
+ alias: credentialDisplay.name
1364
+ },
1365
+ ...credentialDisplay.locale && {
1366
+ locale: credentialDisplay.locale
1367
+ },
1368
+ ...credentialDisplay.logo && {
1369
+ logo: {
1370
+ ...(credentialDisplay.logo.url || credentialDisplay.logo.uri) && {
1371
+ uri: credentialDisplay.logo?.url ?? credentialDisplay.logo.uri
1372
+ },
1373
+ ...credentialDisplay.logo.alt_text && {
1374
+ alt: credentialDisplay.logo?.alt_text
1375
+ }
1376
+ }
1377
+ },
1378
+ ...credentialDisplay.description && {
1379
+ description: credentialDisplay.description
1380
+ },
1381
+ ...credentialDisplay.text_color && {
1382
+ text: {
1383
+ color: credentialDisplay.text_color
1384
+ }
1385
+ },
1386
+ ...(credentialDisplay.background_image || credentialDisplay.background_color) && {
1387
+ background: {
1388
+ ...credentialDisplay.background_image && {
1389
+ image: {
1390
+ ...(credentialDisplay.background_image.url || credentialDisplay.background_image.uri) && {
1391
+ uri: credentialDisplay.background_image?.url ?? credentialDisplay.background_image.uri
1392
+ },
1393
+ ...credentialDisplay.background_image.alt_text && {
1394
+ alt: credentialDisplay.background_image?.alt_text
1395
+ }
1396
+ }
1397
+ },
1398
+ ...credentialDisplay.background_color && {
1399
+ color: credentialDisplay.background_color
1400
+ }
1401
+ }
1402
+ }
1403
+ };
1404
+ }, "oid4vciCredentialLocaleBrandingFrom");
1405
+ var oid4vciCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1406
+ const { credentialDisplayLocales = /* @__PURE__ */ new Map(), issuerCredentialSubjectLocales = /* @__PURE__ */ new Map() } = args;
1407
+ const locales = Array.from(/* @__PURE__ */ new Set([
1408
+ ...issuerCredentialSubjectLocales.keys(),
1409
+ ...credentialDisplayLocales.keys()
1410
+ ]));
1411
+ return Promise.all(locales.map(async (locale) => {
1412
+ const display = credentialDisplayLocales.get(locale);
1413
+ const claims = issuerCredentialSubjectLocales.get(locale);
1414
+ return {
1415
+ ...display && await oid4vciCredentialLocaleBrandingFrom({
1416
+ credentialDisplay: display
1417
+ }),
1418
+ ...locale.length > 0 && {
1419
+ locale
1508
1420
  },
1509
- guards: {
1510
- ...opts?.guards
1511
- }
1512
- }));
1513
- if (typeof opts?.subscription === "function") {
1514
- newInst.onTransition(opts.subscription);
1421
+ claims
1422
+ };
1423
+ }));
1424
+ }, "oid4vciCombineDisplayLocalesFrom");
1425
+ var sdJwtGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1426
+ const { credentialDisplay, claimsMetadata } = args;
1427
+ return sdJwtCombineDisplayLocalesFrom({
1428
+ ...claimsMetadata && {
1429
+ claimsMetadata: await sdJwtCredentialClaimLocalesFrom({
1430
+ claimsMetadata
1431
+ })
1432
+ },
1433
+ ...credentialDisplay && {
1434
+ credentialDisplayLocales: await sdJwtCredentialDisplayLocalesFrom({
1435
+ credentialDisplay
1436
+ })
1515
1437
  }
1516
- if (opts?.requireCustomNavigationHook !== true) {
1517
- newInst.onTransition((snapshot) => {
1518
- if (opts?.stateNavigationListener) {
1519
- void opts.stateNavigationListener(newInst, snapshot);
1520
- }
1438
+ });
1439
+ }, "sdJwtGetCredentialBrandingFrom");
1440
+ var sdJwtCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1441
+ const { credentialDisplay } = args;
1442
+ return credentialDisplay.reduce((localeDisplays, display) => {
1443
+ const localeKey = display.lang || "";
1444
+ localeDisplays.set(localeKey, display);
1445
+ return localeDisplays;
1446
+ }, /* @__PURE__ */ new Map());
1447
+ }, "sdJwtCredentialDisplayLocalesFrom");
1448
+ var sdJwtCredentialClaimLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1449
+ const { claimsMetadata } = args;
1450
+ const localeClaims = /* @__PURE__ */ new Map();
1451
+ claimsMetadata.forEach((claim) => {
1452
+ claim.display?.forEach((display) => {
1453
+ const { lang = "", label } = display;
1454
+ const key = claim.path.map((value) => String(value)).join(".");
1455
+ if (!localeClaims.has(lang)) {
1456
+ localeClaims.set(lang, []);
1457
+ }
1458
+ localeClaims.get(lang).push({
1459
+ key,
1460
+ name: label
1521
1461
  });
1462
+ });
1463
+ });
1464
+ return localeClaims;
1465
+ }, "sdJwtCredentialClaimLocalesFrom");
1466
+ var sdJwtCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1467
+ const { credentialDisplay } = args;
1468
+ return {
1469
+ ...credentialDisplay.name && {
1470
+ alias: credentialDisplay.name
1471
+ },
1472
+ ...credentialDisplay.lang && {
1473
+ locale: credentialDisplay.lang
1474
+ },
1475
+ ...credentialDisplay.rendering?.simple?.logo && {
1476
+ logo: {
1477
+ ...credentialDisplay.rendering.simple.logo.uri && {
1478
+ uri: credentialDisplay.rendering.simple.logo.uri
1479
+ },
1480
+ ...credentialDisplay.rendering.simple.logo.alt_text && {
1481
+ alt: credentialDisplay.rendering.simple.logo.alt_text
1482
+ }
1483
+ }
1484
+ },
1485
+ ...credentialDisplay.description && {
1486
+ description: credentialDisplay.description
1487
+ },
1488
+ ...credentialDisplay.rendering?.simple?.text_color && {
1489
+ text: {
1490
+ color: credentialDisplay.rendering.simple.text_color
1491
+ }
1492
+ },
1493
+ ...credentialDisplay.rendering?.simple?.background_color && {
1494
+ background: {
1495
+ color: credentialDisplay.rendering.simple.background_color
1496
+ }
1522
1497
  }
1523
- return newInst;
1524
- }
1525
- static getInstance(opts) {
1526
- if (!_FirstPartyMachine._instance) {
1527
- if (opts?.requireExisting === true) {
1528
- throw Error(`Existing FirstPartyMachine instance requested, but none was created at this point!`);
1498
+ };
1499
+ }, "sdJwtCredentialLocaleBrandingFrom");
1500
+ var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
1501
+ const { credentialDisplayLocales = /* @__PURE__ */ new Map(), claimsMetadata = /* @__PURE__ */ new Map() } = args;
1502
+ const locales = Array.from(/* @__PURE__ */ new Set([
1503
+ ...claimsMetadata.keys(),
1504
+ ...credentialDisplayLocales.keys()
1505
+ ]));
1506
+ return Promise.all(locales.map(async (locale) => {
1507
+ const display = credentialDisplayLocales.get(locale);
1508
+ const claims = claimsMetadata.get(locale);
1509
+ return {
1510
+ ...display && await sdJwtCredentialLocaleBrandingFrom({
1511
+ credentialDisplay: display
1512
+ }),
1513
+ ...locale.length > 0 && {
1514
+ locale
1515
+ },
1516
+ claims
1517
+ };
1518
+ }));
1519
+ }, "sdJwtCombineDisplayLocalesFrom");
1520
+ var issuerLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
1521
+ const { issuerDisplay, dynamicRegistrationClientMetadata } = args;
1522
+ return {
1523
+ ...dynamicRegistrationClientMetadata?.client_name && {
1524
+ alias: dynamicRegistrationClientMetadata.client_name
1525
+ },
1526
+ ...issuerDisplay.name && {
1527
+ alias: issuerDisplay.name
1528
+ },
1529
+ ...issuerDisplay.locale && {
1530
+ locale: issuerDisplay.locale
1531
+ },
1532
+ ...(issuerDisplay.logo || dynamicRegistrationClientMetadata?.logo_uri) && {
1533
+ logo: {
1534
+ ...dynamicRegistrationClientMetadata?.logo_uri && {
1535
+ uri: dynamicRegistrationClientMetadata?.logo_uri
1536
+ },
1537
+ ...(issuerDisplay.logo?.url || issuerDisplay.logo?.uri) && {
1538
+ uri: issuerDisplay.logo?.url ?? issuerDisplay.logo?.uri
1539
+ },
1540
+ ...issuerDisplay.logo?.alt_text && {
1541
+ alt: issuerDisplay.logo?.alt_text
1542
+ }
1529
1543
  }
1530
- _FirstPartyMachine._instance = _FirstPartyMachine.newInstance(opts);
1544
+ },
1545
+ ...issuerDisplay.description && {
1546
+ description: issuerDisplay.description
1547
+ },
1548
+ ...issuerDisplay.text_color && {
1549
+ text: {
1550
+ color: issuerDisplay.text_color
1551
+ }
1552
+ },
1553
+ ...dynamicRegistrationClientMetadata?.client_uri && {
1554
+ clientUri: dynamicRegistrationClientMetadata.client_uri
1555
+ },
1556
+ ...dynamicRegistrationClientMetadata?.tos_uri && {
1557
+ tosUri: dynamicRegistrationClientMetadata.tos_uri
1558
+ },
1559
+ ...dynamicRegistrationClientMetadata?.policy_uri && {
1560
+ policyUri: dynamicRegistrationClientMetadata.policy_uri
1561
+ },
1562
+ ...dynamicRegistrationClientMetadata?.contacts && {
1563
+ contacts: dynamicRegistrationClientMetadata.contacts
1531
1564
  }
1532
- return _FirstPartyMachine._instance;
1533
- }
1534
- };
1565
+ };
1566
+ }, "issuerLocaleBrandingFrom");
1535
1567
 
1536
1568
  // src/services/OID4VCIHolderService.ts
1537
- import { defaultHasher } from "@sphereon/ssi-sdk.core";
1538
1569
  var getCredentialBranding = /* @__PURE__ */ __name(async (args) => {
1539
1570
  const { credentialsSupported, context } = args;
1540
1571
  const credentialBranding = {};
@@ -1606,16 +1637,7 @@ var selectCredentialLocaleBranding = /* @__PURE__ */ __name(async (args) => {
1606
1637
  }, "selectCredentialLocaleBranding");
1607
1638
  var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1608
1639
  const { mappedCredential, hasher, onVerifyEBSICredentialIssuer, schemaValidation, context } = args;
1609
- const credentialResponse = mappedCredential.credentialToAccept.credentialResponse;
1610
- let credential;
1611
- if ("credential" in credentialResponse) {
1612
- credential = credentialResponse.credential;
1613
- } else if ("credentials" in credentialResponse && credentialResponse.credentials && Array.isArray(credentialResponse.credentials) && credentialResponse.credentials.length > 0) {
1614
- credential = credentialResponse.credentials[0].credential;
1615
- }
1616
- if (!credential) {
1617
- return Promise.reject(Error("No credential found in credential response"));
1618
- }
1640
+ const credential = extractCredentialFromResponse(mappedCredential.credentialToAccept.credentialResponse);
1619
1641
  const wrappedVC = CredentialMapper.toWrappedVerifiableCredential(credential, {
1620
1642
  hasher: hasher ?? defaultHasher
1621
1643
  });
@@ -1667,22 +1689,13 @@ var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1667
1689
  }, "verifyCredentialToAccept");
1668
1690
  var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1669
1691
  const { credentialToAccept, hasher } = args;
1670
- const credentialResponse = credentialToAccept.credentialResponse;
1671
- let verifiableCredential;
1672
- if ("credential" in credentialResponse) {
1673
- verifiableCredential = credentialResponse.credential;
1674
- } else if ("credentials" in credentialResponse && credentialResponse.credentials && Array.isArray(credentialResponse.credentials) && credentialResponse.credentials.length > 0) {
1675
- verifiableCredential = credentialResponse.credentials[0].credential;
1676
- }
1677
- if (!verifiableCredential) {
1678
- return Promise.reject(Error("No credential found in credential response"));
1679
- }
1692
+ const verifiableCredential = extractCredentialFromResponse(credentialToAccept.credentialResponse);
1680
1693
  const wrappedVerifiableCredential = CredentialMapper.toWrappedVerifiableCredential(verifiableCredential, {
1681
1694
  hasher
1682
1695
  });
1683
1696
  let uniformVerifiableCredential;
1684
1697
  if (CredentialMapper.isSdJwtDecodedCredential(wrappedVerifiableCredential.credential)) {
1685
- uniformVerifiableCredential = await sdJwtDecodedCredentialToUniformCredential(wrappedVerifiableCredential.credential);
1698
+ uniformVerifiableCredential = sdJwtDecodedCredentialToUniformCredential(wrappedVerifiableCredential.credential);
1686
1699
  } else if (CredentialMapper.isSdJwtEncoded(wrappedVerifiableCredential.credential)) {
1687
1700
  if (!hasher) {
1688
1701
  return Promise.reject("a hasher is required for encoded SD-JWT credentials");
@@ -1696,6 +1709,7 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1696
1709
  uniformVerifiableCredential = wrappedVerifiableCredential.credential;
1697
1710
  }
1698
1711
  const correlationId = typeof uniformVerifiableCredential.issuer === "string" ? uniformVerifiableCredential.issuer : CredentialMapper.isSdJwtDecodedCredential(uniformVerifiableCredential) ? uniformVerifiableCredential.decodedPayload.iss : uniformVerifiableCredential.issuer.id;
1712
+ const credentialResponse = credentialToAccept.credentialResponse;
1699
1713
  return {
1700
1714
  correlationId,
1701
1715
  credentialToAccept,
@@ -1707,6 +1721,18 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
1707
1721
  }
1708
1722
  };
1709
1723
  }, "mapCredentialToAccept");
1724
+ var extractCredentialFromResponse = /* @__PURE__ */ __name((credentialResponse) => {
1725
+ let credential;
1726
+ if ("credential" in credentialResponse) {
1727
+ credential = credentialResponse.credential;
1728
+ } else if ("credentials" in credentialResponse && credentialResponse.credentials && Array.isArray(credentialResponse.credentials) && credentialResponse.credentials.length > 0) {
1729
+ credential = credentialResponse.credentials[0].credential;
1730
+ }
1731
+ if (!credential) {
1732
+ throw new Error("No credential found in credential response");
1733
+ }
1734
+ return credential;
1735
+ }, "extractCredentialFromResponse");
1710
1736
  var getIdentifierOpts = /* @__PURE__ */ __name(async (args) => {
1711
1737
  const { issuanceOpt, context } = args;
1712
1738
  const { identifier: identifierArg } = issuanceOpt;
@@ -1815,24 +1841,19 @@ var getCredentialConfigsSupportedBySingleTypeOrId = /* @__PURE__ */ __name(async
1815
1841
  }
1816
1842
  __name(createIdFromTypes, "createIdFromTypes");
1817
1843
  if (configurationId) {
1818
- const allSupported2 = client.getCredentialsSupported(false);
1844
+ const allSupported2 = client.getCredentialsSupported(void 0, format);
1819
1845
  return Object.fromEntries(Object.entries(allSupported2).filter(([id, supported]) => id === configurationId || supported.id === configurationId || createIdFromTypes(supported) === configurationId));
1820
1846
  }
1821
- if (!types && !client.credentialOffer) {
1822
- return Promise.reject(Error("openID4VCIClient has no credentialOffer and no types where provided"));
1847
+ if (!client.credentialOffer) {
1848
+ return Promise.reject(Error("openID4VCIClient has no credentialOffer"));
1823
1849
  }
1824
- if (!Array.isArray(format) && client.credentialOffer) {
1825
- if (client.version() > OpenId4VCIVersion.VER_1_0_09 && typeof client.credentialOffer.credential_offer === "object" && "credentials" in client.credentialOffer.credential_offer) {
1826
- format = client.credentialOffer.credential_offer.credentials.filter((cred) => typeof cred !== "string").map((cred) => cred.format);
1827
- if (format?.length === 0) {
1828
- format = void 0;
1829
- }
1830
- }
1850
+ if (!types) {
1851
+ return Promise.reject(Error("openID4VCIClient has no types"));
1831
1852
  }
1832
1853
  const offerSupported = getSupportedCredentials({
1833
- types: types ? [
1854
+ types: [
1834
1855
  types
1835
- ] : client.getCredentialOfferTypes(),
1856
+ ],
1836
1857
  format,
1837
1858
  version: client.version(),
1838
1859
  issuerMetadata: client.endpointMetadata.credentialIssuerMetadata
@@ -2076,7 +2097,6 @@ var startFirstPartApplicationMachine = /* @__PURE__ */ __name(async (args, conte
2076
2097
  }, "startFirstPartApplicationMachine");
2077
2098
 
2078
2099
  // src/agent/OID4VCIHolder.ts
2079
- import "cross-fetch/polyfill";
2080
2100
  var oid4vciHolderContextMethods = [
2081
2101
  "cmGetContacts",
2082
2102
  "cmGetContact",
@@ -2132,6 +2152,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2132
2152
  oid4vciHolderStart: this.oid4vciHolderStart.bind(this),
2133
2153
  oid4vciHolderGetIssuerMetadata: this.oid4vciHolderGetIssuerMetadata.bind(this),
2134
2154
  oid4vciHolderGetMachineInterpreter: this.oid4vciHolderGetMachineInterpreter.bind(this),
2155
+ oid4vciHolderPrepareAuthorizationRequest: this.oid4vciHolderPrepareAuthorizationRequest.bind(this),
2135
2156
  oid4vciHolderCreateCredentialsToSelectFrom: this.oid4vciHolderCreateCredentialsToSelectFrom.bind(this),
2136
2157
  oid4vciHolderGetContact: this.oid4vciHolderGetContact.bind(this),
2137
2158
  oid4vciHolderGetCredentials: this.oid4vciHolderGetCredentials.bind(this),
@@ -2236,6 +2257,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2236
2257
  stateNavigationListener: opts.firstPartyStateNavigationListener
2237
2258
  }, context),
2238
2259
  [OID4VCIMachineServices.createCredentialsToSelectFrom]: (args) => this.oid4vciHolderCreateCredentialsToSelectFrom(args, context),
2260
+ [OID4VCIMachineServices.prepareAuthorizationRequest]: (args) => this.oid4vciHolderPrepareAuthorizationRequest(args, context),
2239
2261
  [OID4VCIMachineServices.getContact]: (args) => this.oid4vciHolderGetContact(args, context),
2240
2262
  [OID4VCIMachineServices.getCredentials]: (args) => this.oid4vciHolderGetCredentials({
2241
2263
  accessTokenOpts: args.accessTokenOpts ?? opts.accessTokenOpts,
@@ -2284,7 +2306,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2284
2306
  ...this.defaultAuthorizationRequestOpts,
2285
2307
  ...args.authorizationRequestOpts
2286
2308
  };
2287
- authorizationRequestOpts.authorizationDetails = authorizationRequestOpts?.authorizationDetails ? asArray2(authorizationRequestOpts.authorizationDetails).filter((detail) => typeof detail === "string" || this.vcFormatPreferences.includes(detail.format)) : void 0;
2309
+ authorizationRequestOpts.authorizationDetails = authorizationRequestOpts?.authorizationDetails ? asArray2(authorizationRequestOpts.authorizationDetails) : void 0;
2288
2310
  if (!authorizationRequestOpts.redirectUri) {
2289
2311
  authorizationRequestOpts.redirectUri = _OID4VCIHolder.DEFAULT_MOBILE_REDIRECT_URI;
2290
2312
  }
@@ -2297,10 +2319,9 @@ var OID4VCIHolder = class _OID4VCIHolder {
2297
2319
  formats = Array.from(new Set(authFormats));
2298
2320
  }
2299
2321
  let oid4vciClient;
2300
- let types = void 0;
2301
2322
  let offer;
2302
2323
  if (requestData.existingClientState) {
2303
- oid4vciClient = await OpenID4VCIClient2.fromState({
2324
+ oid4vciClient = await OpenID4VCIClientV1_0_15.fromState({
2304
2325
  state: requestData.existingClientState
2305
2326
  });
2306
2327
  offer = oid4vciClient.credentialOffer;
@@ -2317,50 +2338,78 @@ var OID4VCIHolder = class _OID4VCIHolder {
2317
2338
  }
2318
2339
  if (!offer) {
2319
2340
  logger.log(`Issuer url received (no credential offer): ${uri}`);
2320
- oid4vciClient = await OpenID4VCIClient2.fromCredentialIssuer({
2341
+ oid4vciClient = await OpenID4VCIClientV1_0_15.fromCredentialIssuer({
2321
2342
  credentialIssuer: uri,
2322
2343
  authorizationRequest: authorizationRequestOpts,
2323
2344
  clientId: authorizationRequestOpts.clientId,
2324
- createAuthorizationRequestURL: requestData.createAuthorizationRequestURL ?? true
2345
+ createAuthorizationRequestURL: false
2325
2346
  });
2326
2347
  } else {
2327
2348
  logger.log(`Credential offer received: ${uri}`);
2328
- oid4vciClient = await OpenID4VCIClient2.fromURI({
2349
+ oid4vciClient = await OpenID4VCIClientV1_0_15.fromURI({
2329
2350
  uri,
2330
2351
  authorizationRequest: authorizationRequestOpts,
2331
2352
  clientId: authorizationRequestOpts.clientId,
2332
- createAuthorizationRequestURL: requestData.createAuthorizationRequestURL ?? true
2353
+ createAuthorizationRequestURL: false
2333
2354
  });
2334
2355
  }
2335
2356
  }
2357
+ let configurationIds = [];
2336
2358
  if (offer) {
2337
- types = getTypesFromCredentialOffer(offer.original_credential_offer);
2359
+ configurationIds = offer.original_credential_offer.credential_configuration_ids;
2338
2360
  } else {
2339
- types = asArray2(authorizationRequestOpts.authorizationDetails).map((authReqOpts) => getTypesFromAuthorizationDetails(authReqOpts) ?? []).filter((inner) => inner.length > 0);
2361
+ configurationIds = asArray2(authorizationRequestOpts.authorizationDetails).map((authReqOpts) => authReqOpts.credential_configuration_id).filter((id) => !!id);
2340
2362
  }
2341
- const serverMetadata = await oid4vciClient.retrieveServerMetadata();
2342
2363
  const credentialsSupported = await getCredentialConfigsSupportedMerged({
2343
2364
  client: oid4vciClient,
2344
2365
  vcFormatPreferences: formats,
2345
- types
2366
+ configurationIds
2346
2367
  });
2368
+ const serverMetadata = await oid4vciClient.retrieveServerMetadata();
2347
2369
  const credentialBranding = await getCredentialBranding({
2348
2370
  credentialsSupported,
2349
2371
  context
2350
2372
  });
2351
- const authorizationCodeURL = oid4vciClient.authorizationURL;
2352
- if (authorizationCodeURL) {
2353
- logger.log(`authorization code URL ${authorizationCodeURL}`);
2354
- }
2355
2373
  const oid4vciClientState = JSON.parse(await oid4vciClient.exportState());
2356
2374
  return {
2357
- authorizationCodeURL,
2358
2375
  credentialBranding,
2359
2376
  credentialsSupported,
2360
2377
  serverMetadata,
2361
2378
  oid4vciClientState
2362
2379
  };
2363
2380
  }
2381
+ async oid4vciHolderPrepareAuthorizationRequest(args, context) {
2382
+ const { openID4VCIClientState, contact } = args;
2383
+ if (!openID4VCIClientState) {
2384
+ return Promise.reject(Error("Missing openID4VCI client state in context"));
2385
+ }
2386
+ const clientId = contact?.identities.map((identity) => {
2387
+ const connectionConfig = identity.connection?.config;
2388
+ if (connectionConfig && "clientId" in connectionConfig) {
2389
+ return connectionConfig.clientId;
2390
+ }
2391
+ return void 0;
2392
+ }).find((clientId2) => clientId2);
2393
+ if (!clientId) {
2394
+ return Promise.reject(Error(`Missing client id in contact's connectionConfig`));
2395
+ }
2396
+ const client = await OpenID4VCIClient2.fromState({
2397
+ state: openID4VCIClientState
2398
+ });
2399
+ const authorizationCodeURL = await client.createAuthorizationRequestUrl({
2400
+ authorizationRequest: {
2401
+ clientId
2402
+ }
2403
+ });
2404
+ if (authorizationCodeURL) {
2405
+ logger.log(`authorization code URL ${authorizationCodeURL}`);
2406
+ }
2407
+ return {
2408
+ authorizationCodeURL,
2409
+ // Needed, because the above createAuthorizationRequestUrl manipulates the state, adding pkce opts to the state
2410
+ oid4vciClientState: JSON.parse(await client.exportState())
2411
+ };
2412
+ }
2364
2413
  async oid4vciHolderCreateCredentialsToSelectFrom(args, context) {
2365
2414
  const { credentialBranding, locale, selectedCredentials, credentialsSupported } = args;
2366
2415
  logger.info(`Credentials supported ${Object.keys(credentialsSupported).join(", ")}`);
@@ -2432,7 +2481,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2432
2481
  if (!openID4VCIClientState) {
2433
2482
  return Promise.reject(Error("Missing openID4VCI client state in context"));
2434
2483
  }
2435
- const client = await OpenID4VCIClient2.fromState({
2484
+ const client = await OpenID4VCIClientV1_0_15.fromState({
2436
2485
  state: openID4VCIClientState
2437
2486
  });
2438
2487
  const credentialsSupported = await getCredentialConfigsSupportedMerged({
@@ -2732,16 +2781,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
2732
2781
  if (Array.isArray(subjectIssuance?.notification_events_supported)) {
2733
2782
  event = subjectIssuance.notification_events_supported.includes("credential_accepted_holder_signed") ? "credential_accepted_holder_signed" : "credential_deleted_holder_signed";
2734
2783
  logger.log(`Subject issuance/signing will be used, with event`, event);
2735
- const credentialResponse = mappedCredentialToAccept.credentialToAccept.credentialResponse;
2736
- let issuerVC;
2737
- if ("credential" in credentialResponse) {
2738
- issuerVC = credentialResponse.credential;
2739
- } else if ("credentials" in credentialResponse && credentialResponse.credentials && Array.isArray(credentialResponse.credentials) && credentialResponse.credentials.length > 0) {
2740
- issuerVC = credentialResponse.credentials[0].credential;
2741
- }
2742
- if (!issuerVC) {
2743
- return Promise.reject(Error("No credential found in credential response"));
2744
- }
2784
+ const issuerVC = extractCredentialFromResponse(mappedCredentialToAccept.credentialToAccept.credentialResponse);
2745
2785
  const wrappedIssuerVC = CredentialMapper2.toWrappedVerifiableCredential(issuerVC, {
2746
2786
  hasher: this.hasher ?? defaultHasher2
2747
2787
  });
@@ -3112,6 +3152,7 @@ export {
3112
3152
  RequestType,
3113
3153
  SupportedLanguage,
3114
3154
  createConfig,
3155
+ extractCredentialFromResponse,
3115
3156
  getBasicIssuerLocaleBranding,
3116
3157
  getCredentialBranding,
3117
3158
  getCredentialConfigsBasedOnFormatPref,