@eudiplo/sdk-core 4.4.0 → 4.5.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.mjs CHANGED
@@ -25,10 +25,7 @@ var formDataBodySerializer = {
25
25
  }
26
26
  };
27
27
  var jsonBodySerializer = {
28
- bodySerializer: (body) => JSON.stringify(
29
- body,
30
- (_key, value) => typeof value === "bigint" ? value.toString() : value
31
- )
28
+ bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
32
29
  };
33
30
 
34
31
  // src/api/core/serverSentEvents.gen.ts
@@ -72,10 +69,7 @@ function createSseClient({
72
69
  }
73
70
  const _fetch = options.fetch ?? globalThis.fetch;
74
71
  const response = await _fetch(request);
75
- if (!response.ok)
76
- throw new Error(
77
- `SSE failed: ${response.status} ${response.statusText}`
78
- );
72
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
79
73
  if (!response.body) throw new Error("No body in SSE response");
80
74
  const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
81
75
  let buffer = "";
@@ -106,10 +100,7 @@ function createSseClient({
106
100
  } else if (line.startsWith("id:")) {
107
101
  lastEventId = line.replace(/^id:\s*/, "");
108
102
  } else if (line.startsWith("retry:")) {
109
- const parsed = Number.parseInt(
110
- line.replace(/^retry:\s*/, ""),
111
- 10
112
- );
103
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
113
104
  if (!Number.isNaN(parsed)) {
114
105
  retryDelay = parsed;
115
106
  }
@@ -155,10 +146,7 @@ function createSseClient({
155
146
  if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
156
147
  break;
157
148
  }
158
- const backoff = Math.min(
159
- retryDelay * 2 ** (attempt - 1),
160
- sseMaxRetryDelay ?? 3e4
161
- );
149
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
162
150
  await sleep(backoff);
163
151
  }
164
152
  }
@@ -266,11 +254,7 @@ var serializeObjectParam = ({
266
254
  if (style !== "deepObject" && !explode) {
267
255
  let values = [];
268
256
  Object.entries(value).forEach(([key, v]) => {
269
- values = [
270
- ...values,
271
- key,
272
- allowReserved ? v : encodeURIComponent(v)
273
- ];
257
+ values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
274
258
  });
275
259
  const joinedValues2 = values.join(",");
276
260
  switch (style) {
@@ -321,10 +305,7 @@ var defaultPathSerializer = ({ path, url: _url }) => {
321
305
  continue;
322
306
  }
323
307
  if (Array.isArray(value)) {
324
- url = url.replace(
325
- match,
326
- serializeArrayParam({ explode, name, style, value })
327
- );
308
+ url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
328
309
  continue;
329
310
  }
330
311
  if (typeof value === "object") {
@@ -472,9 +453,7 @@ var getParseAs = (contentType) => {
472
453
  if (cleanContent === "multipart/form-data") {
473
454
  return "formData";
474
455
  }
475
- if (["application/", "audio/", "image/", "video/"].some(
476
- (type) => cleanContent.startsWith(type)
477
- )) {
456
+ if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
478
457
  return "blob";
479
458
  }
480
459
  if (cleanContent.startsWith("text/")) {
@@ -491,11 +470,8 @@ var checkForExistence = (options, name) => {
491
470
  }
492
471
  return false;
493
472
  };
494
- var setAuthParams = async ({
495
- security,
496
- ...options
497
- }) => {
498
- for (const auth of security) {
473
+ async function setAuthParams(options) {
474
+ for (const auth of options.security ?? []) {
499
475
  if (checkForExistence(options, auth.name)) {
500
476
  continue;
501
477
  }
@@ -520,7 +496,7 @@ var setAuthParams = async ({
520
496
  break;
521
497
  }
522
498
  }
523
- };
499
+ }
524
500
  var buildUrl = (options) => getUrl({
525
501
  baseUrl: options.baseUrl,
526
502
  path: options.path,
@@ -646,10 +622,7 @@ var createClient = (config = {}) => {
646
622
  serializedBody: void 0
647
623
  };
648
624
  if (opts.security) {
649
- await setAuthParams({
650
- ...opts,
651
- security: opts.security
652
- });
625
+ await setAuthParams(opts);
653
626
  }
654
627
  if (opts.requestValidator) {
655
628
  await opts.requestValidator(opts);
@@ -762,12 +735,7 @@ var createClient = (config = {}) => {
762
735
  let finalError = error;
763
736
  for (const fn of interceptors.error.fns) {
764
737
  if (fn) {
765
- finalError = await fn(
766
- finalError,
767
- response,
768
- request2,
769
- options
770
- );
738
+ finalError = await fn(finalError, response, request2, options);
771
739
  }
772
740
  }
773
741
  finalError = finalError || {};
@@ -832,9 +800,7 @@ var createClient = (config = {}) => {
832
800
  };
833
801
 
834
802
  // src/api/client.gen.ts
835
- var client = createClient(
836
- createConfig({ throwOnError: true })
837
- );
803
+ var client = createClient(createConfig({ throwOnError: true }));
838
804
 
839
805
  // src/api/sdk.gen.ts
840
806
  var appControllerGetVersion = (options) => (options?.client ?? client).get({
@@ -1117,18 +1083,81 @@ var credentialConfigControllerUpdateCredentialConfiguration = (options) => (opti
1117
1083
  ...options.headers
1118
1084
  }
1119
1085
  });
1120
- var credentialConfigControllerSignSchemaMetaConfig = (options) => (options.client ?? client).post({
1086
+ var schemaMetadataControllerSignSchemaMetaConfig = (options) => (options.client ?? client).post({
1087
+ security: [{ scheme: "bearer", type: "http" }],
1088
+ url: "/api/schema-metadata/sign",
1089
+ ...options,
1090
+ headers: {
1091
+ "Content-Type": "application/json",
1092
+ ...options.headers
1093
+ }
1094
+ });
1095
+ var schemaMetadataControllerSignVersionSchemaMetaConfig = (options) => (options.client ?? client).post({
1096
+ security: [{ scheme: "bearer", type: "http" }],
1097
+ url: "/api/schema-metadata/sign-version",
1098
+ ...options,
1099
+ headers: {
1100
+ "Content-Type": "application/json",
1101
+ ...options.headers
1102
+ }
1103
+ });
1104
+ var schemaMetadataControllerGetVocabularies = (options) => (options?.client ?? client).get({
1105
+ security: [{ scheme: "bearer", type: "http" }],
1106
+ url: "/api/schema-metadata/vocabularies",
1107
+ ...options
1108
+ });
1109
+ var schemaMetadataControllerFindAll = (options) => (options?.client ?? client).get({
1110
+ security: [{ scheme: "bearer", type: "http" }],
1111
+ url: "/api/schema-metadata",
1112
+ ...options
1113
+ });
1114
+ var schemaMetadataControllerFindOne = (options) => (options.client ?? client).get({
1115
+ security: [{ scheme: "bearer", type: "http" }],
1116
+ url: "/api/schema-metadata/{id}",
1117
+ ...options
1118
+ });
1119
+ var schemaMetadataControllerRemove = (options) => (options.client ?? client).delete({
1120
+ security: [{ scheme: "bearer", type: "http" }],
1121
+ url: "/api/schema-metadata/{id}/versions/{version}",
1122
+ ...options
1123
+ });
1124
+ var schemaMetadataControllerUpdate = (options) => (options.client ?? client).patch({
1121
1125
  security: [{ scheme: "bearer", type: "http" }],
1122
- url: "/api/issuer/credentials/schema-metadata/sign",
1126
+ url: "/api/schema-metadata/{id}/versions/{version}",
1123
1127
  ...options,
1124
1128
  headers: {
1125
1129
  "Content-Type": "application/json",
1126
1130
  ...options.headers
1127
1131
  }
1128
1132
  });
1129
- var credentialConfigControllerSignVersionSchemaMetaConfig = (options) => (options.client ?? client).post({
1133
+ var schemaMetadataControllerGetLatest = (options) => (options.client ?? client).get({
1134
+ security: [{ scheme: "bearer", type: "http" }],
1135
+ url: "/api/schema-metadata/{id}/latest",
1136
+ ...options
1137
+ });
1138
+ var schemaMetadataControllerGetVersions = (options) => (options.client ?? client).get({
1139
+ security: [{ scheme: "bearer", type: "http" }],
1140
+ url: "/api/schema-metadata/{id}/versions",
1141
+ ...options
1142
+ });
1143
+ var schemaMetadataControllerGetJwt = (options) => (options.client ?? client).get({
1144
+ security: [{ scheme: "bearer", type: "http" }],
1145
+ url: "/api/schema-metadata/{id}/versions/{version}/jwt",
1146
+ ...options
1147
+ });
1148
+ var schemaMetadataControllerExport = (options) => (options.client ?? client).get({
1149
+ security: [{ scheme: "bearer", type: "http" }],
1150
+ url: "/api/schema-metadata/{id}/versions/{version}/export",
1151
+ ...options
1152
+ });
1153
+ var schemaMetadataControllerGetSchema = (options) => (options.client ?? client).get({
1154
+ security: [{ scheme: "bearer", type: "http" }],
1155
+ url: "/api/schema-metadata/{id}/versions/{version}/schemas/{format}",
1156
+ ...options
1157
+ });
1158
+ var schemaMetadataControllerDeprecateVersion = (options) => (options.client ?? client).patch({
1130
1159
  security: [{ scheme: "bearer", type: "http" }],
1131
- url: "/api/issuer/credentials/schema-metadata/sign-version",
1160
+ url: "/api/schema-metadata/{id}/versions/{version}/deprecation",
1132
1161
  ...options,
1133
1162
  headers: {
1134
1163
  "Content-Type": "application/json",
@@ -1249,6 +1278,26 @@ var trustListControllerGetTrustListVersion = (options) => (options.client ?? cli
1249
1278
  url: "/api/trust-list/{id}/versions/{versionId}",
1250
1279
  ...options
1251
1280
  });
1281
+ var cacheControllerGetStats = (options) => (options?.client ?? client).get({
1282
+ security: [{ scheme: "bearer", type: "http" }],
1283
+ url: "/api/cache/stats",
1284
+ ...options
1285
+ });
1286
+ var cacheControllerClearAllCaches = (options) => (options?.client ?? client).delete({
1287
+ security: [{ scheme: "bearer", type: "http" }],
1288
+ url: "/api/cache",
1289
+ ...options
1290
+ });
1291
+ var cacheControllerClearTrustListCache = (options) => (options?.client ?? client).delete({
1292
+ security: [{ scheme: "bearer", type: "http" }],
1293
+ url: "/api/cache/trust-list",
1294
+ ...options
1295
+ });
1296
+ var cacheControllerClearStatusListCache = (options) => (options?.client ?? client).delete({
1297
+ security: [{ scheme: "bearer", type: "http" }],
1298
+ url: "/api/cache/status-list",
1299
+ ...options
1300
+ });
1252
1301
  var presentationManagementControllerConfiguration = (options) => (options?.client ?? client).get({
1253
1302
  security: [{ scheme: "bearer", type: "http" }],
1254
1303
  url: "/api/verifier/config",
@@ -1310,26 +1359,6 @@ var presentationManagementControllerReissueRegistrationCertificate = (options) =
1310
1359
  url: "/api/verifier/config/{id}/registration-cert/reissue",
1311
1360
  ...options
1312
1361
  });
1313
- var cacheControllerGetStats = (options) => (options?.client ?? client).get({
1314
- security: [{ scheme: "bearer", type: "http" }],
1315
- url: "/api/cache/stats",
1316
- ...options
1317
- });
1318
- var cacheControllerClearAllCaches = (options) => (options?.client ?? client).delete({
1319
- security: [{ scheme: "bearer", type: "http" }],
1320
- url: "/api/cache",
1321
- ...options
1322
- });
1323
- var cacheControllerClearTrustListCache = (options) => (options?.client ?? client).delete({
1324
- security: [{ scheme: "bearer", type: "http" }],
1325
- url: "/api/cache/trust-list",
1326
- ...options
1327
- });
1328
- var cacheControllerClearStatusListCache = (options) => (options?.client ?? client).delete({
1329
- security: [{ scheme: "bearer", type: "http" }],
1330
- url: "/api/cache/status-list",
1331
- ...options
1332
- });
1333
1362
  var registrarControllerDeleteConfig = (options) => (options?.client ?? client).delete({
1334
1363
  security: [{ scheme: "bearer", type: "http" }],
1335
1364
  url: "/api/registrar/config",
@@ -1367,69 +1396,6 @@ var registrarControllerCreateAccessCertificate = (options) => (options.client ??
1367
1396
  ...options.headers
1368
1397
  }
1369
1398
  });
1370
- var schemaMetadataControllerGetVocabularies = (options) => (options?.client ?? client).get({
1371
- security: [{ scheme: "bearer", type: "http" }],
1372
- url: "/api/schema-metadata/vocabularies",
1373
- ...options
1374
- });
1375
- var schemaMetadataControllerFindAll = (options) => (options?.client ?? client).get({
1376
- security: [{ scheme: "bearer", type: "http" }],
1377
- url: "/api/schema-metadata",
1378
- ...options
1379
- });
1380
- var schemaMetadataControllerFindOne = (options) => (options.client ?? client).get({
1381
- security: [{ scheme: "bearer", type: "http" }],
1382
- url: "/api/schema-metadata/{id}",
1383
- ...options
1384
- });
1385
- var schemaMetadataControllerRemove = (options) => (options.client ?? client).delete({
1386
- security: [{ scheme: "bearer", type: "http" }],
1387
- url: "/api/schema-metadata/{id}/versions/{version}",
1388
- ...options
1389
- });
1390
- var schemaMetadataControllerUpdate = (options) => (options.client ?? client).patch({
1391
- security: [{ scheme: "bearer", type: "http" }],
1392
- url: "/api/schema-metadata/{id}/versions/{version}",
1393
- ...options,
1394
- headers: {
1395
- "Content-Type": "application/json",
1396
- ...options.headers
1397
- }
1398
- });
1399
- var schemaMetadataControllerGetLatest = (options) => (options.client ?? client).get({
1400
- security: [{ scheme: "bearer", type: "http" }],
1401
- url: "/api/schema-metadata/{id}/latest",
1402
- ...options
1403
- });
1404
- var schemaMetadataControllerGetVersions = (options) => (options.client ?? client).get({
1405
- security: [{ scheme: "bearer", type: "http" }],
1406
- url: "/api/schema-metadata/{id}/versions",
1407
- ...options
1408
- });
1409
- var schemaMetadataControllerGetJwt = (options) => (options.client ?? client).get({
1410
- security: [{ scheme: "bearer", type: "http" }],
1411
- url: "/api/schema-metadata/{id}/versions/{version}/jwt",
1412
- ...options
1413
- });
1414
- var schemaMetadataControllerExport = (options) => (options.client ?? client).get({
1415
- security: [{ scheme: "bearer", type: "http" }],
1416
- url: "/api/schema-metadata/{id}/versions/{version}/export",
1417
- ...options
1418
- });
1419
- var schemaMetadataControllerGetSchema = (options) => (options.client ?? client).get({
1420
- security: [{ scheme: "bearer", type: "http" }],
1421
- url: "/api/schema-metadata/{id}/versions/{version}/schemas/{format}",
1422
- ...options
1423
- });
1424
- var schemaMetadataControllerDeprecateVersion = (options) => (options.client ?? client).patch({
1425
- security: [{ scheme: "bearer", type: "http" }],
1426
- url: "/api/schema-metadata/{id}/versions/{version}/deprecation",
1427
- ...options,
1428
- headers: {
1429
- "Content-Type": "application/json",
1430
- ...options.headers
1431
- }
1432
- });
1433
1399
  var credentialOfferControllerGetOffer = (options) => (options.client ?? client).post({
1434
1400
  security: [{ scheme: "bearer", type: "http" }],
1435
1401
  url: "/api/issuer/offer",
@@ -1462,6 +1428,11 @@ var keyChainControllerGetProviders = (options) => (options?.client ?? client).ge
1462
1428
  url: "/api/key-chain/providers",
1463
1429
  ...options
1464
1430
  });
1431
+ var keyChainControllerGetProvidersHealth = (options) => (options?.client ?? client).get({
1432
+ security: [{ scheme: "bearer", type: "http" }],
1433
+ url: "/api/key-chain/providers/health",
1434
+ ...options
1435
+ });
1465
1436
  var keyChainControllerGetAll = (options) => (options?.client ?? client).get({
1466
1437
  security: [{ scheme: "bearer", type: "http" }],
1467
1438
  url: "/api/key-chain",
@@ -1548,6 +1519,26 @@ function decodeJwtPayload(jwt) {
1548
1519
  const jsonPayload = atob(base64);
1549
1520
  return JSON.parse(jsonPayload);
1550
1521
  }
1522
+ function extractResponseUriFromRequestObject(requestObject) {
1523
+ const requestPayload = decodeJwtPayload(requestObject);
1524
+ if (!requestPayload.response_uri) {
1525
+ throw new Error("No response_uri found in request object");
1526
+ }
1527
+ return requestPayload.response_uri;
1528
+ }
1529
+ function mapDcApiPresentationResult(result) {
1530
+ let resolvedCredentials;
1531
+ if (Array.isArray(result)) {
1532
+ resolvedCredentials = result;
1533
+ } else if (Array.isArray(result?.credentials)) {
1534
+ resolvedCredentials = result.credentials;
1535
+ }
1536
+ return {
1537
+ credentials: resolvedCredentials,
1538
+ response: result,
1539
+ redirectUri: result?.redirect_uri
1540
+ };
1541
+ }
1551
1542
  var EudiploClient = class {
1552
1543
  config;
1553
1544
  accessToken;
@@ -1639,15 +1630,14 @@ var EudiploClient = class {
1639
1630
  tx_code: options.txCode
1640
1631
  };
1641
1632
  if (options.claims) {
1642
- body.credentialClaims = {
1643
- additionalProperties: void 0
1644
- };
1633
+ const credentialClaims = {};
1645
1634
  for (const [configId, claims] of Object.entries(options.claims)) {
1646
- body.credentialClaims[configId] = {
1635
+ credentialClaims[configId] = {
1647
1636
  type: "inline",
1648
1637
  claims
1649
1638
  };
1650
1639
  }
1640
+ body.credentialClaims = credentialClaims;
1651
1641
  }
1652
1642
  const response = await credentialOfferControllerGetOffer({
1653
1643
  body
@@ -1688,10 +1678,12 @@ var EudiploClient = class {
1688
1678
  */
1689
1679
  async createPresentationRequest(options) {
1690
1680
  await this.ensureAuthenticated();
1681
+ const inferredOrigin = options.origin ?? (typeof globalThis.location === "object" ? globalThis.location.origin : void 0);
1691
1682
  const body = {
1692
1683
  response_type: options.responseType ?? "uri",
1693
1684
  requestId: options.configId,
1694
- redirectUri: options.redirectUri
1685
+ redirectUri: options.redirectUri,
1686
+ expected_origin: options.responseType === "dc-api" ? inferredOrigin : void 0
1695
1687
  };
1696
1688
  const response = await verifierOfferControllerGetOffer({
1697
1689
  body
@@ -1909,10 +1901,12 @@ var EudiploClient = class {
1909
1901
  */
1910
1902
  async createDcApiPresentationRequest(options) {
1911
1903
  await this.ensureAuthenticated();
1904
+ const inferredOrigin = options.origin ?? (typeof globalThis.location === "object" ? globalThis.location.origin : void 0);
1912
1905
  const body = {
1913
1906
  response_type: "dc-api",
1914
1907
  requestId: options.configId,
1915
- redirectUri: options.redirectUri
1908
+ redirectUri: options.redirectUri,
1909
+ expected_origin: inferredOrigin
1916
1910
  };
1917
1911
  const response = await verifierOfferControllerGetOffer({
1918
1912
  body
@@ -1920,7 +1914,34 @@ var EudiploClient = class {
1920
1914
  if (!response.data) {
1921
1915
  throw new Error("Failed to create DC API presentation request");
1922
1916
  }
1923
- return this.getSession(response.data.session);
1917
+ const session = await this.getSession(response.data.session);
1918
+ if (session.requestObject) {
1919
+ return session;
1920
+ }
1921
+ const nonceOrId = session.walletNonce ?? session.id;
1922
+ const requestObjectUrl = `${this.config.baseUrl}/api/presentations/${encodeURIComponent(nonceOrId)}/oid4vp/request`;
1923
+ const fetchImpl = this.config.fetch ?? fetch;
1924
+ const requestObjectResponse = await fetchImpl(requestObjectUrl, {
1925
+ method: "GET",
1926
+ headers: {
1927
+ Accept: "application/oauth-authz-req+jwt",
1928
+ ...inferredOrigin ? { Origin: inferredOrigin } : {}
1929
+ }
1930
+ });
1931
+ if (!requestObjectResponse.ok) {
1932
+ const errorText = await requestObjectResponse.text();
1933
+ throw new Error(
1934
+ `Failed to fetch DC API request object: ${requestObjectResponse.status} ${errorText}`
1935
+ );
1936
+ }
1937
+ const requestObject = (await requestObjectResponse.text()).trim();
1938
+ if (!requestObject) {
1939
+ throw new Error("DC API request endpoint returned an empty requestObject");
1940
+ }
1941
+ return {
1942
+ ...session,
1943
+ requestObject
1944
+ };
1924
1945
  }
1925
1946
  /**
1926
1947
  * Submit a presentation using the Digital Credentials API.
@@ -1952,54 +1973,13 @@ var EudiploClient = class {
1952
1973
  'Session does not contain a requestObject. Make sure to create the session with response_type: "dc-api"'
1953
1974
  );
1954
1975
  }
1955
- const dcResponse = await navigator.credentials.get({
1956
- mediation: "required",
1957
- digital: {
1958
- requests: [
1959
- {
1960
- protocol: "openid4vp-v1-signed",
1961
- data: { request: session.requestObject }
1962
- }
1963
- ]
1964
- }
1965
- });
1966
- if (!dcResponse) {
1967
- throw new Error("No response from Digital Credentials API");
1968
- }
1969
- if (dcResponse.data?.error) {
1970
- throw new Error(
1971
- `Wallet error: ${dcResponse.data.error}${dcResponse.data.error_description ? ` - ${dcResponse.data.error_description}` : ""}`
1972
- );
1973
- }
1974
- const requestPayload = decodeJwtPayload(
1975
- session.requestObject
1976
- );
1977
- if (!requestPayload.response_uri) {
1978
- throw new Error("No response_uri found in request object");
1979
- }
1980
- const fetchImpl = this.config.fetch ?? fetch;
1981
- const submitResponse = await fetchImpl(requestPayload.response_uri, {
1982
- method: "POST",
1983
- headers: {
1984
- "Content-Type": "application/json"
1985
- },
1986
- body: JSON.stringify({
1987
- ...dcResponse.data,
1988
- sendResponse: options.sendResponse ?? true
1989
- })
1976
+ const walletResponse = await invokeDcApi(session.requestObject);
1977
+ return submitDcApiResponse({
1978
+ responseUri: extractResponseUriFromRequestObject(session.requestObject),
1979
+ walletResponse,
1980
+ sendResponse: options.sendResponse,
1981
+ fetch: this.config.fetch
1990
1982
  });
1991
- if (!submitResponse.ok) {
1992
- const errorText = await submitResponse.text();
1993
- throw new Error(
1994
- `Failed to submit presentation: ${submitResponse.status} ${errorText}`
1995
- );
1996
- }
1997
- const result = await submitResponse.json();
1998
- return {
1999
- credentials: result.credentials ?? result,
2000
- response: result,
2001
- redirectUri: result.redirect_uri
2002
- };
2003
1983
  }
2004
1984
  /**
2005
1985
  * Convenience method to create a presentation request and immediately
@@ -2018,111 +1998,7 @@ var EudiploClient = class {
2018
1998
  return this.submitDcApiPresentation(session, dcOptions);
2019
1999
  }
2020
2000
  };
2021
- async function verify(options) {
2022
- const client2 = new EudiploClient({
2023
- baseUrl: options.baseUrl,
2024
- clientId: options.clientId,
2025
- clientSecret: options.clientSecret
2026
- });
2027
- const { uri, sessionId } = await client2.createPresentationRequest({
2028
- configId: options.configId,
2029
- redirectUri: options.redirectUri
2030
- });
2031
- return {
2032
- uri,
2033
- sessionId,
2034
- waitForCompletion: (pollingOptions) => client2.waitForSession(sessionId, { ...options.polling, ...pollingOptions }),
2035
- getStatus: () => client2.getSession(sessionId)
2036
- };
2037
- }
2038
- async function issue(options) {
2039
- const client2 = new EudiploClient({
2040
- baseUrl: options.baseUrl,
2041
- clientId: options.clientId,
2042
- clientSecret: options.clientSecret
2043
- });
2044
- const { uri, sessionId } = await client2.createIssuanceOffer({
2045
- credentialConfigurationIds: options.credentialConfigurationIds,
2046
- claims: options.claims,
2047
- txCode: options.txCode
2048
- });
2049
- return {
2050
- uri,
2051
- sessionId,
2052
- waitForCompletion: (pollingOptions) => client2.waitForSession(sessionId, { ...options.polling, ...pollingOptions }),
2053
- getStatus: () => client2.getSession(sessionId)
2054
- };
2055
- }
2056
- async function verifyAndWait(options) {
2057
- const { uri, waitForCompletion } = await verify(options);
2058
- options.onUri(uri);
2059
- return waitForCompletion(options.polling);
2060
- }
2061
- async function issueAndWait(options) {
2062
- const { uri, waitForCompletion } = await issue(options);
2063
- options.onUri(uri);
2064
- return waitForCompletion(options.polling);
2065
- }
2066
- async function verifyWithDcApi(options) {
2067
- const eudiploClient = new EudiploClient({
2068
- baseUrl: options.baseUrl,
2069
- clientId: options.clientId,
2070
- clientSecret: options.clientSecret
2071
- });
2072
- return eudiploClient.verifyWithDcApi(
2073
- {
2074
- configId: options.configId,
2075
- redirectUri: options.redirectUri
2076
- },
2077
- {
2078
- sendResponse: options.sendResponse
2079
- }
2080
- );
2081
- }
2082
- async function createDcApiRequest(options) {
2083
- const eudiploClient = new EudiploClient({
2084
- baseUrl: options.baseUrl,
2085
- clientId: options.clientId,
2086
- clientSecret: options.clientSecret
2087
- });
2088
- const session = await eudiploClient.createDcApiPresentationRequest({
2089
- configId: options.configId,
2090
- redirectUri: options.redirectUri
2091
- });
2092
- return {
2093
- session,
2094
- submit: (dcOptions) => eudiploClient.submitDcApiPresentation(session, {
2095
- sendResponse: options.sendResponse,
2096
- ...dcOptions
2097
- })
2098
- };
2099
- }
2100
- async function createDcApiRequestForBrowser(options) {
2101
- const eudiploClient = new EudiploClient({
2102
- baseUrl: options.baseUrl,
2103
- clientId: options.clientId,
2104
- clientSecret: options.clientSecret
2105
- });
2106
- const session = await eudiploClient.createDcApiPresentationRequest({
2107
- configId: options.configId,
2108
- redirectUri: options.redirectUri
2109
- });
2110
- if (!session.requestObject) {
2111
- throw new Error("Session does not contain a requestObject");
2112
- }
2113
- const requestPayload = decodeJwtPayload(
2114
- session.requestObject
2115
- );
2116
- if (!requestPayload.response_uri) {
2117
- throw new Error("No response_uri found in request object");
2118
- }
2119
- return {
2120
- requestObject: session.requestObject,
2121
- sessionId: session.id,
2122
- responseUri: requestPayload.response_uri
2123
- };
2124
- }
2125
- async function callDcApi(requestObject) {
2001
+ async function invokeDcApi(requestObject) {
2126
2002
  if (!isDcApiAvailable()) {
2127
2003
  throw new Error(
2128
2004
  "Digital Credentials API is not available in this browser. Please use a supported browser or fall back to QR code flow."
@@ -2149,7 +2025,7 @@ async function callDcApi(requestObject) {
2149
2025
  }
2150
2026
  return dcResponse.data;
2151
2027
  }
2152
- async function submitDcApiWalletResponse(options) {
2028
+ async function submitDcApiResponse(options) {
2153
2029
  const fetchImpl = options.fetch ?? fetch;
2154
2030
  const submitResponse = await fetchImpl(options.responseUri, {
2155
2031
  method: "POST",
@@ -2168,13 +2044,220 @@ async function submitDcApiWalletResponse(options) {
2168
2044
  );
2169
2045
  }
2170
2046
  const result = await submitResponse.json();
2047
+ return mapDcApiPresentationResult(result);
2048
+ }
2049
+
2050
+ // src/config/derive.ts
2051
+ var JSON_SCHEMA_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema";
2052
+ function segmentToKey(segment) {
2053
+ if (segment === null) {
2054
+ return "*";
2055
+ }
2056
+ return String(segment);
2057
+ }
2058
+ function getOrCreateChild(target, key, nextIsArray) {
2059
+ const current = target[key];
2060
+ if (current !== void 0) {
2061
+ if (Array.isArray(current)) {
2062
+ return current;
2063
+ }
2064
+ if (typeof current === "object" && current !== null) {
2065
+ return current;
2066
+ }
2067
+ }
2068
+ const created = nextIsArray ? [] : {};
2069
+ target[key] = created;
2070
+ return created;
2071
+ }
2072
+ function setValueAtPath(target, path, value) {
2073
+ if (path.length === 0) {
2074
+ return;
2075
+ }
2076
+ let cursor = target;
2077
+ for (let index = 0; index < path.length; index += 1) {
2078
+ const segment = path[index];
2079
+ const isLast = index === path.length - 1;
2080
+ const next = path[index + 1];
2081
+ if (Array.isArray(cursor)) {
2082
+ const arrayIndex = typeof segment === "number" ? segment : Number(segmentToKey(segment));
2083
+ if (!Number.isFinite(arrayIndex) || arrayIndex < 0) {
2084
+ return;
2085
+ }
2086
+ if (isLast) {
2087
+ cursor[arrayIndex] = value;
2088
+ return;
2089
+ }
2090
+ const current = cursor[arrayIndex];
2091
+ if (typeof current !== "object" || current === null) {
2092
+ cursor[arrayIndex] = typeof next === "number" ? [] : {};
2093
+ }
2094
+ cursor = cursor[arrayIndex];
2095
+ continue;
2096
+ }
2097
+ const key = segmentToKey(segment);
2098
+ if (isLast) {
2099
+ cursor[key] = value;
2100
+ return;
2101
+ }
2102
+ cursor = getOrCreateChild(cursor, key, typeof next === "number");
2103
+ }
2104
+ }
2105
+ function getDisplayTitle(display) {
2106
+ if (!display || display.length === 0) {
2107
+ return void 0;
2108
+ }
2109
+ const en = display.find((entry) => entry.locale.toLowerCase().startsWith("en"));
2110
+ return en?.name ?? display[0]?.name;
2111
+ }
2112
+ function mergeLeafSchema(existing, next) {
2113
+ const merged = { ...next };
2114
+ if (existing.properties && Object.keys(existing.properties).length > 0) {
2115
+ merged.properties = existing.properties;
2116
+ }
2117
+ if (Array.isArray(existing.required) && existing.required.length > 0) {
2118
+ merged.required = existing.required;
2119
+ }
2120
+ return merged;
2121
+ }
2122
+ function ensureSchemaNode(root, path) {
2123
+ let cursor = root;
2124
+ for (const segment of path) {
2125
+ const key = segmentToKey(segment);
2126
+ cursor.properties ??= {};
2127
+ if (!cursor.properties[key]) {
2128
+ cursor.properties[key] = {
2129
+ type: "object",
2130
+ properties: {}
2131
+ };
2132
+ }
2133
+ cursor = cursor.properties[key];
2134
+ }
2135
+ return cursor;
2136
+ }
2137
+ function ensureFrameNode(root, path) {
2138
+ let cursor = root;
2139
+ for (const segment of path) {
2140
+ const key = segmentToKey(segment);
2141
+ const current = cursor[key];
2142
+ if (!current || typeof current !== "object" || Array.isArray(current)) {
2143
+ cursor[key] = {};
2144
+ }
2145
+ cursor = cursor[key];
2146
+ }
2147
+ return cursor;
2148
+ }
2149
+ function buildClaims(fields) {
2150
+ const claims = {};
2151
+ for (const field of fields) {
2152
+ if (!Object.prototype.hasOwnProperty.call(field, "defaultValue")) {
2153
+ continue;
2154
+ }
2155
+ setValueAtPath(claims, field.path, field.defaultValue);
2156
+ }
2157
+ return claims;
2158
+ }
2159
+ function buildDisclosureFrame(fields) {
2160
+ const frame = {};
2161
+ let hasDisclosure = false;
2162
+ for (const field of fields) {
2163
+ if (!field.disclosable || field.path.length === 0) {
2164
+ continue;
2165
+ }
2166
+ const parentPath = field.path.slice(0, -1);
2167
+ const leaf = segmentToKey(field.path.at(-1) ?? "");
2168
+ const node = ensureFrameNode(frame, parentPath);
2169
+ const existing = Array.isArray(node._sd) ? node._sd : [];
2170
+ if (!existing.includes(leaf)) {
2171
+ existing.push(leaf);
2172
+ node._sd = existing;
2173
+ }
2174
+ hasDisclosure = true;
2175
+ }
2176
+ return hasDisclosure ? frame : void 0;
2177
+ }
2178
+ function buildClaimsMetadata(fields) {
2179
+ return fields.filter((field) => field.path.length > 0).map((field) => {
2180
+ const metadata = {
2181
+ path: field.path
2182
+ };
2183
+ if (typeof field.mandatory === "boolean") {
2184
+ metadata.mandatory = field.mandatory;
2185
+ }
2186
+ if (field.display && field.display.length > 0) {
2187
+ metadata.display = field.display;
2188
+ }
2189
+ return metadata;
2190
+ });
2191
+ }
2192
+ function buildLeafSchema(field) {
2193
+ const schema = {
2194
+ ...field.constraints,
2195
+ type: field.type === "date" ? "string" : field.type
2196
+ };
2197
+ if (field.type === "date" && !schema.format) {
2198
+ schema.format = "date";
2199
+ }
2200
+ const title = getDisplayTitle(field.display);
2201
+ if (title) {
2202
+ schema.title = title;
2203
+ }
2204
+ return schema;
2205
+ }
2206
+ function addRequired(parent, key) {
2207
+ if (!Array.isArray(parent.required)) {
2208
+ parent.required = [];
2209
+ }
2210
+ if (!parent.required.includes(key)) {
2211
+ parent.required.push(key);
2212
+ }
2213
+ }
2214
+ function buildJsonSchema(fields) {
2215
+ const root = {
2216
+ $schema: JSON_SCHEMA_DRAFT_2020_12,
2217
+ type: "object",
2218
+ properties: {}
2219
+ };
2220
+ for (const field of fields) {
2221
+ if (field.path.length === 0) {
2222
+ continue;
2223
+ }
2224
+ const parent = ensureSchemaNode(root, field.path.slice(0, -1));
2225
+ const leafKey = segmentToKey(field.path.at(-1) ?? "");
2226
+ parent.properties ??= {};
2227
+ const leafSchema = buildLeafSchema(field);
2228
+ const existing = parent.properties[leafKey];
2229
+ parent.properties[leafKey] = existing && typeof existing === "object" && !Array.isArray(existing) ? mergeLeafSchema(existing, leafSchema) : leafSchema;
2230
+ if (field.mandatory) {
2231
+ addRequired(parent, leafKey);
2232
+ }
2233
+ }
2234
+ return root;
2235
+ }
2236
+ function buildClaimsByNamespace(fields) {
2237
+ const byNamespace = {};
2238
+ for (const field of fields) {
2239
+ if (!field.namespace || !Object.prototype.hasOwnProperty.call(field, "defaultValue")) {
2240
+ continue;
2241
+ }
2242
+ if (!byNamespace[field.namespace]) {
2243
+ byNamespace[field.namespace] = {};
2244
+ }
2245
+ const namespaceTarget = byNamespace[field.namespace];
2246
+ const normalizedPath = field.path.length > 0 && segmentToKey(field.path[0] ?? "") === field.namespace ? field.path.slice(1) : field.path;
2247
+ setValueAtPath(namespaceTarget, normalizedPath, field.defaultValue);
2248
+ }
2249
+ return byNamespace;
2250
+ }
2251
+ function deriveRuntimeArtifacts(fields) {
2171
2252
  return {
2172
- credentials: result.credentials ?? result,
2173
- response: result,
2174
- redirectUri: result.redirect_uri
2253
+ claims: buildClaims(fields),
2254
+ disclosureFrame: buildDisclosureFrame(fields),
2255
+ claimsMetadata: buildClaimsMetadata(fields),
2256
+ schema: buildJsonSchema(fields),
2257
+ claimsByNamespace: buildClaimsByNamespace(fields)
2175
2258
  };
2176
2259
  }
2177
2260
 
2178
- export { EudiploClient, appControllerGetFrontendConfig, appControllerGetVersion, attributeProviderControllerCreate, attributeProviderControllerDelete, attributeProviderControllerGetAll, attributeProviderControllerGetById, attributeProviderControllerUpdate, auditLogControllerGetAuditLogs, authControllerGetOAuth2Token, cacheControllerClearAllCaches, cacheControllerClearStatusListCache, cacheControllerClearTrustListCache, cacheControllerGetStats, callDcApi, client, clientControllerCreateClient, clientControllerDeleteClient, clientControllerGetClient, clientControllerGetClientSecret, clientControllerGetClients, clientControllerRotateClientSecret, clientControllerUpdateClient, createDcApiRequest, createDcApiRequestForBrowser, credentialConfigControllerDeleteIssuanceConfiguration, credentialConfigControllerGetConfigById, credentialConfigControllerGetConfigs, credentialConfigControllerSignSchemaMetaConfig, credentialConfigControllerSignVersionSchemaMetaConfig, credentialConfigControllerStoreCredentialConfiguration, credentialConfigControllerUpdateCredentialConfiguration, credentialOfferControllerGetOffer, deferredControllerCompleteDeferred, deferredControllerFailDeferred, isDcApiAvailable, issuanceConfigControllerGetIssuanceConfigurations, issuanceConfigControllerStoreIssuanceConfiguration, issue, issueAndWait, keyChainControllerCreate, keyChainControllerDelete, keyChainControllerExport, keyChainControllerGetAll, keyChainControllerGetById, keyChainControllerGetProviders, keyChainControllerImport, keyChainControllerRotate, keyChainControllerUpdate, presentationManagementControllerConfiguration, presentationManagementControllerDeleteConfiguration, presentationManagementControllerGetConfiguration, presentationManagementControllerListSchemaMetadataCatalog, presentationManagementControllerReissueRegistrationCertificate, presentationManagementControllerResolveIssuerMetadata, presentationManagementControllerResolveSchemaMetadata, presentationManagementControllerStorePresentationConfig, presentationManagementControllerUpdateConfiguration, registrarControllerCreateAccessCertificate, registrarControllerCreateConfig, registrarControllerDeleteConfig, registrarControllerGetConfig, registrarControllerUpdateConfig, schemaMetadataControllerDeprecateVersion, schemaMetadataControllerExport, schemaMetadataControllerFindAll, schemaMetadataControllerFindOne, schemaMetadataControllerGetJwt, schemaMetadataControllerGetLatest, schemaMetadataControllerGetSchema, schemaMetadataControllerGetVersions, schemaMetadataControllerGetVocabularies, schemaMetadataControllerRemove, schemaMetadataControllerUpdate, sessionConfigControllerGetConfig, sessionConfigControllerResetConfig, sessionConfigControllerUpdateConfig, sessionControllerDeleteSession, sessionControllerGetAllSessions, sessionControllerGetSession, sessionControllerGetSessionLogs, sessionControllerRevokeAll, sessionEventsControllerSubscribeToSessionEvents, statusListConfigControllerGetConfig, statusListConfigControllerResetConfig, statusListConfigControllerUpdateConfig, statusListManagementControllerCreateList, statusListManagementControllerDeleteList, statusListManagementControllerGetList, statusListManagementControllerGetLists, statusListManagementControllerUpdateList, storageControllerUpload, submitDcApiWalletResponse, tenantControllerDeleteTenant, tenantControllerGetTenant, tenantControllerGetTenants, tenantControllerInitTenant, tenantControllerUpdateTenant, trustListControllerCreateTrustList, trustListControllerDeleteTrustList, trustListControllerExportTrustList, trustListControllerGetAllTrustLists, trustListControllerGetTrustList, trustListControllerGetTrustListVersion, trustListControllerGetTrustListVersions, trustListControllerUpdateTrustList, userControllerCreateUser, userControllerDeleteUser, userControllerGetUser, userControllerGetUsers, userControllerUpdateUser, verifierOfferControllerGetOffer, verify, verifyAndWait, verifyWithDcApi, webhookEndpointControllerCreate, webhookEndpointControllerDelete, webhookEndpointControllerGetAll, webhookEndpointControllerGetById, webhookEndpointControllerUpdate };
2261
+ export { EudiploClient, appControllerGetFrontendConfig, appControllerGetVersion, attributeProviderControllerCreate, attributeProviderControllerDelete, attributeProviderControllerGetAll, attributeProviderControllerGetById, attributeProviderControllerUpdate, auditLogControllerGetAuditLogs, authControllerGetOAuth2Token, buildClaims, buildClaimsByNamespace, buildClaimsMetadata, buildDisclosureFrame, buildJsonSchema, cacheControllerClearAllCaches, cacheControllerClearStatusListCache, cacheControllerClearTrustListCache, cacheControllerGetStats, client, clientControllerCreateClient, clientControllerDeleteClient, clientControllerGetClient, clientControllerGetClientSecret, clientControllerGetClients, clientControllerRotateClientSecret, clientControllerUpdateClient, credentialConfigControllerDeleteIssuanceConfiguration, credentialConfigControllerGetConfigById, credentialConfigControllerGetConfigs, credentialConfigControllerStoreCredentialConfiguration, credentialConfigControllerUpdateCredentialConfiguration, credentialOfferControllerGetOffer, deferredControllerCompleteDeferred, deferredControllerFailDeferred, deriveRuntimeArtifacts, isDcApiAvailable, issuanceConfigControllerGetIssuanceConfigurations, issuanceConfigControllerStoreIssuanceConfiguration, keyChainControllerCreate, keyChainControllerDelete, keyChainControllerExport, keyChainControllerGetAll, keyChainControllerGetById, keyChainControllerGetProviders, keyChainControllerGetProvidersHealth, keyChainControllerImport, keyChainControllerRotate, keyChainControllerUpdate, presentationManagementControllerConfiguration, presentationManagementControllerDeleteConfiguration, presentationManagementControllerGetConfiguration, presentationManagementControllerListSchemaMetadataCatalog, presentationManagementControllerReissueRegistrationCertificate, presentationManagementControllerResolveIssuerMetadata, presentationManagementControllerResolveSchemaMetadata, presentationManagementControllerStorePresentationConfig, presentationManagementControllerUpdateConfiguration, registrarControllerCreateAccessCertificate, registrarControllerCreateConfig, registrarControllerDeleteConfig, registrarControllerGetConfig, registrarControllerUpdateConfig, schemaMetadataControllerDeprecateVersion, schemaMetadataControllerExport, schemaMetadataControllerFindAll, schemaMetadataControllerFindOne, schemaMetadataControllerGetJwt, schemaMetadataControllerGetLatest, schemaMetadataControllerGetSchema, schemaMetadataControllerGetVersions, schemaMetadataControllerGetVocabularies, schemaMetadataControllerRemove, schemaMetadataControllerSignSchemaMetaConfig, schemaMetadataControllerSignVersionSchemaMetaConfig, schemaMetadataControllerUpdate, sessionConfigControllerGetConfig, sessionConfigControllerResetConfig, sessionConfigControllerUpdateConfig, sessionControllerDeleteSession, sessionControllerGetAllSessions, sessionControllerGetSession, sessionControllerGetSessionLogs, sessionControllerRevokeAll, sessionEventsControllerSubscribeToSessionEvents, statusListConfigControllerGetConfig, statusListConfigControllerResetConfig, statusListConfigControllerUpdateConfig, statusListManagementControllerCreateList, statusListManagementControllerDeleteList, statusListManagementControllerGetList, statusListManagementControllerGetLists, statusListManagementControllerUpdateList, storageControllerUpload, tenantControllerDeleteTenant, tenantControllerGetTenant, tenantControllerGetTenants, tenantControllerInitTenant, tenantControllerUpdateTenant, trustListControllerCreateTrustList, trustListControllerDeleteTrustList, trustListControllerExportTrustList, trustListControllerGetAllTrustLists, trustListControllerGetTrustList, trustListControllerGetTrustListVersion, trustListControllerGetTrustListVersions, trustListControllerUpdateTrustList, userControllerCreateUser, userControllerDeleteUser, userControllerGetUser, userControllerGetUsers, userControllerUpdateUser, verifierOfferControllerGetOffer, webhookEndpointControllerCreate, webhookEndpointControllerDelete, webhookEndpointControllerGetAll, webhookEndpointControllerGetById, webhookEndpointControllerUpdate };
2179
2262
  //# sourceMappingURL=index.mjs.map
2180
2263
  //# sourceMappingURL=index.mjs.map