@mattrglobal/verifier-sdk-web 2.0.0-preview-digital-credential-api.4 → 2.0.0-preview-digital-credential-api.6

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.
@@ -7,8 +7,8 @@
7
7
  * Do Not Translate or Localize
8
8
  *
9
9
  * Bundle of @mattrglobal/verifier-sdk-web
10
- * Generated: 2025-03-25
11
- * Version: 2.0.0-preview-digital-credential-api.4
10
+ * Generated: 2025-06-13
11
+ * Version: 2.0.0-preview-digital-credential-api.6
12
12
  * Dependencies:
13
13
  *
14
14
  * neverthrow -- 4.3.0
@@ -1379,6 +1379,22 @@ const CredentialQueryValidator = object({
1379
1379
  })))
1380
1380
  });
1381
1381
 
1382
+ const DcqlCredentialQueryValidator = object({
1383
+ credentials: array(object({
1384
+ id: string(),
1385
+ format: string(),
1386
+ meta: optional(unknown()),
1387
+ claims: array(object({
1388
+ path: array(string())
1389
+ }))
1390
+ })),
1391
+ credential_sets: optional(array(object({
1392
+ options: array(array(string())),
1393
+ required: optional(_boolean()),
1394
+ purpose: optional(unknown())
1395
+ })))
1396
+ });
1397
+
1382
1398
  var PresentationErrorType;
1383
1399
 
1384
1400
  (function(PresentationErrorType) {
@@ -1399,7 +1415,7 @@ const PresentationResultRelaxValidator = object({
1399
1415
  });
1400
1416
 
1401
1417
  object({
1402
- credentialQuery: array(CredentialQueryValidator),
1418
+ credentialQuery: union([ array(CredentialQueryValidator), DcqlCredentialQueryValidator ]),
1403
1419
  challenge: string(),
1404
1420
  redirectUri: optional(string()),
1405
1421
  walletProviderId: optional(string())
@@ -1438,7 +1454,7 @@ var MessageEventDataType;
1438
1454
  })(MessageEventDataType || (MessageEventDataType = {}));
1439
1455
 
1440
1456
  const RequestCredentialsSameDeviceOptionsValidator = object({
1441
- credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
1457
+ credentialQuery: union([ pipe(array(CredentialQueryValidator), nonEmpty()), DcqlCredentialQueryValidator ]),
1442
1458
  redirectUri: string(),
1443
1459
  challenge: optional(string()),
1444
1460
  walletProviderId: optional(string()),
@@ -1446,7 +1462,7 @@ const RequestCredentialsSameDeviceOptionsValidator = object({
1446
1462
  });
1447
1463
 
1448
1464
  const RequestCredentialsCrossDeviceOptionsValidator = object({
1449
- credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
1465
+ credentialQuery: union([ pipe(array(CredentialQueryValidator), nonEmpty()), DcqlCredentialQueryValidator ]),
1450
1466
  crossDeviceCallback: object({
1451
1467
  onComplete: function_(),
1452
1468
  onFailure: function_()
@@ -1457,7 +1473,7 @@ const RequestCredentialsCrossDeviceOptionsValidator = object({
1457
1473
  });
1458
1474
 
1459
1475
  const RequestCredentialsAutoDetectDeviceOptionsValidator = object({
1460
- credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
1476
+ credentialQuery: union([ pipe(array(CredentialQueryValidator), nonEmpty()), DcqlCredentialQueryValidator ]),
1461
1477
  crossDeviceCallback: object({
1462
1478
  onComplete: function_(),
1463
1479
  onFailure: function_()
@@ -1629,15 +1645,6 @@ const isMobileDetect = userAgent => isMobile_2({
1629
1645
  tablet: false
1630
1646
  });
1631
1647
 
1632
- const isDigitalCredentialsApiSupported = () => {
1633
- var _a;
1634
- try {
1635
- return typeof ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.identity) === null || _a === void 0 ? void 0 : _a.get) === "function";
1636
- } catch (error) {
1637
- return false;
1638
- }
1639
- };
1640
-
1641
1648
  const createDigitalCredentialsApiSession = async ({credentialQuery: credentialQuery, challenge: challenge, apiBaseUrl: apiBaseUrl, protocol: protocol}) => {
1642
1649
  const postData = Object.assign({
1643
1650
  credentialQuery: credentialQuery,
@@ -1907,21 +1914,41 @@ const requestCredentialsDigitalCredentialsApi = async options => {
1907
1914
  }
1908
1915
  const {request: request, sessionId: sessionId} = createSessionResult.value;
1909
1916
  window.localStorage.setItem(LocalStorageKey.sessionId, sessionId);
1910
- let rawResponse;
1917
+ let response;
1911
1918
  try {
1912
- rawResponse = await navigator.identity.get(request);
1919
+ if ("providers" in request.digital) {
1920
+ let requestData;
1921
+ const providerRequest = request.digital.providers[0];
1922
+ if (providerRequest.protocol === "preview") {
1923
+ console.log(`DC API Preview Request: ${JSON.stringify(request)}`);
1924
+ const rawResponse = await navigator.identity.get(request);
1925
+ response = rawResponse.data;
1926
+ } else {
1927
+ requestData = {
1928
+ protocol: providerRequest.protocol,
1929
+ data: JSON.parse(providerRequest.request)
1930
+ };
1931
+ const modernRequest = Object.assign(Object.assign({}, requestData.protocol === "org-iso-mdoc" && {
1932
+ mediation: "required"
1933
+ }), {
1934
+ digital: {
1935
+ requests: [ requestData ]
1936
+ }
1937
+ });
1938
+ console.log(`DC API Request: ${JSON.stringify(modernRequest)}`);
1939
+ const rawResponse = await navigator.credentials.get(modernRequest);
1940
+ response = rawResponse.data;
1941
+ }
1942
+ } else {
1943
+ const rawResponse = await navigator.credentials.get(request);
1944
+ response = rawResponse.data;
1945
+ }
1913
1946
  } catch (_a) {
1914
1947
  return err({
1915
1948
  type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
1916
1949
  message: "Failed call to digital credentials api"
1917
1950
  });
1918
1951
  }
1919
- let response;
1920
- try {
1921
- response = JSON.parse(rawResponse.data);
1922
- } catch (_b) {
1923
- response = rawResponse.data;
1924
- }
1925
1952
  const result = await getDigitalCredentialsApiSessionResult({
1926
1953
  challenge: challenge,
1927
1954
  sessionId: sessionId,
@@ -1950,7 +1977,7 @@ const requestCredentials = async options => {
1950
1977
  assertType(RequestCredentialsOptionsValidator, "Invalid request credential options")(options);
1951
1978
  const {challenge: challenge = generateChallenge()} = options;
1952
1979
  const mode = (_a = options.mode) !== null && _a !== void 0 ? _a : isMobileDetect(navigator.userAgent) ? exports.Mode.sameDevice : exports.Mode.crossDevice;
1953
- if (initialiseOptions.enableDigitalCredentialsApiCrossDeviceFlow && isDigitalCredentialsApiSupported() && mode === exports.Mode.crossDevice) {
1980
+ if (initialiseOptions.enableDigitalCredentialsApiCrossDeviceFlow && mode === exports.Mode.crossDevice) {
1954
1981
  console.log("Digital Credentials API support found, proceeding with request using API in cross device flow");
1955
1982
  return await requestCredentialsDigitalCredentialsApi(Object.assign(Object.assign({}, options), {
1956
1983
  initialiseOptions: initialiseOptions,
@@ -1959,7 +1986,7 @@ const requestCredentials = async options => {
1959
1986
  } else if (initialiseOptions.enableDigitalCredentialsApiCrossDeviceFlow) {
1960
1987
  console.log("Digital Credentials API support not found, falling back to OpenID4VP");
1961
1988
  }
1962
- if (initialiseOptions.enableDigitalCredentialsApiSameDeviceFlow && isDigitalCredentialsApiSupported() && mode === exports.Mode.sameDevice) {
1989
+ if (initialiseOptions.enableDigitalCredentialsApiSameDeviceFlow && mode === exports.Mode.sameDevice) {
1963
1990
  console.log("Digital Credentials API support found, proceeding with request using API in same device flow");
1964
1991
  return await requestCredentialsDigitalCredentialsApi(Object.assign(Object.assign({}, options), {
1965
1992
  initialiseOptions: initialiseOptions,
@@ -2050,8 +2077,7 @@ const handleRedirectCallback = async () => {
2050
2077
 
2051
2078
  const utils = {
2052
2079
  generateChallenge: generateChallenge,
2053
- unwrap: unwrap,
2054
- isDigitalCredentialsApiSupported: isDigitalCredentialsApiSupported
2080
+ unwrap: unwrap
2055
2081
  };
2056
2082
 
2057
2083
  exports.handleRedirectCallback = handleRedirectCallback;