@mattrglobal/verifier-sdk-web 1.1.1-unstable.145 → 1.1.1-unstable.153
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/lib/verifier-js-no-deps.cjs.js +263 -91
- package/dist/lib/verifier-js-no-deps.cjs.js.map +1 -1
- package/dist/lib/verifier-js.cjs.js +314 -90
- package/dist/lib/verifier-js.cjs.js.map +1 -1
- package/dist/typings/common/safeFetch.d.ts +3 -3
- package/dist/typings/index.d.ts +4 -4
- package/dist/typings/verifier/index.d.ts +1 -0
- package/dist/typings/verifier/requestCredentialsCrossDevice.d.ts +1 -1
- package/dist/typings/verifier/requestCredentialsDigitalCredentialsApi.d.ts +16 -0
- package/dist/typings/verifier/types/credential-presentation.d.ts +45 -7
- package/dist/typings/verifier/types/verifier-web-sdk.d.ts +77 -128
- package/dist/typings/verifier/utils.d.ts +6 -6
- package/dist/verifier-js.development.js +297 -87
- package/dist/verifier-js.development.js.map +1 -1
- package/dist/verifier-js.production.esm.js +2 -2
- package/dist/verifier-js.production.esm.js.map +1 -1
- package/dist/verifier-js.production.js +2 -2
- package/dist/verifier-js.production.js.map +1 -1
- package/package.json +2 -2
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Do Not Translate or Localize
|
|
8
8
|
*
|
|
9
9
|
* Bundle of @mattrglobal/verifier-sdk-web
|
|
10
|
-
* Generated: 2025-05-
|
|
10
|
+
* Generated: 2025-05-16
|
|
11
11
|
* Version: 1.1.0
|
|
12
12
|
* Dependencies:
|
|
13
13
|
*
|
|
@@ -697,6 +697,20 @@ function getDefault(schema, dataset, config2) {
|
|
|
697
697
|
return typeof schema["default"] === "function" ? schema["default"](dataset, config2) : schema["default"];
|
|
698
698
|
}
|
|
699
699
|
|
|
700
|
+
function any() {
|
|
701
|
+
return {
|
|
702
|
+
kind: "schema",
|
|
703
|
+
type: "any",
|
|
704
|
+
reference: any,
|
|
705
|
+
expects: "any",
|
|
706
|
+
async: false,
|
|
707
|
+
_run: function _run(dataset) {
|
|
708
|
+
dataset.typed = true;
|
|
709
|
+
return dataset;
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
|
|
700
714
|
function array(item, message) {
|
|
701
715
|
return {
|
|
702
716
|
kind: "schema",
|
|
@@ -782,6 +796,45 @@ function _boolean(message) {
|
|
|
782
796
|
};
|
|
783
797
|
}
|
|
784
798
|
|
|
799
|
+
function literal(literal_, message) {
|
|
800
|
+
return {
|
|
801
|
+
kind: "schema",
|
|
802
|
+
type: "literal",
|
|
803
|
+
reference: literal,
|
|
804
|
+
expects: _stringify(literal_),
|
|
805
|
+
async: false,
|
|
806
|
+
literal: literal_,
|
|
807
|
+
message: message,
|
|
808
|
+
_run: function _run(dataset, config2) {
|
|
809
|
+
if (dataset.value === this.literal) {
|
|
810
|
+
dataset.typed = true;
|
|
811
|
+
} else {
|
|
812
|
+
_addIssue(this, "type", dataset, config2);
|
|
813
|
+
}
|
|
814
|
+
return dataset;
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
function number(message) {
|
|
820
|
+
return {
|
|
821
|
+
kind: "schema",
|
|
822
|
+
type: "number",
|
|
823
|
+
reference: number,
|
|
824
|
+
expects: "number",
|
|
825
|
+
async: false,
|
|
826
|
+
message: message,
|
|
827
|
+
_run: function _run(dataset, config2) {
|
|
828
|
+
if (typeof dataset.value === "number" && !isNaN(dataset.value)) {
|
|
829
|
+
dataset.typed = true;
|
|
830
|
+
} else {
|
|
831
|
+
_addIssue(this, "type", dataset, config2);
|
|
832
|
+
}
|
|
833
|
+
return dataset;
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
|
|
785
838
|
function object(entries, message) {
|
|
786
839
|
return {
|
|
787
840
|
kind: "schema",
|
|
@@ -1362,19 +1415,45 @@ const PresentationResultRelaxValidator = object({
|
|
|
1362
1415
|
error: optional(unknown())
|
|
1363
1416
|
});
|
|
1364
1417
|
|
|
1418
|
+
exports.Mode = void 0;
|
|
1419
|
+
|
|
1420
|
+
(function(Mode) {
|
|
1421
|
+
Mode["SameDevice"] = "sameDevice";
|
|
1422
|
+
Mode["CrossDevice"] = "crossDevice";
|
|
1423
|
+
})(exports.Mode || (exports.Mode = {}));
|
|
1424
|
+
|
|
1425
|
+
var SessionType;
|
|
1426
|
+
|
|
1427
|
+
(function(SessionType) {
|
|
1428
|
+
SessionType["DigitalCredentialsApi"] = "digital-credentials-api";
|
|
1429
|
+
SessionType["Openid4vp"] = "openid4vp";
|
|
1430
|
+
})(SessionType || (SessionType = {}));
|
|
1431
|
+
|
|
1365
1432
|
object({
|
|
1366
1433
|
credentialQuery: array(CredentialQueryValidator),
|
|
1367
1434
|
challenge: string(),
|
|
1368
1435
|
redirectUri: optional(string()),
|
|
1369
|
-
walletProviderId: optional(string())
|
|
1436
|
+
walletProviderId: optional(string()),
|
|
1437
|
+
dcApiSupported: optional(_boolean())
|
|
1438
|
+
});
|
|
1439
|
+
|
|
1440
|
+
const CreateSessionDigitalCredentialsValidator = object({
|
|
1441
|
+
type: literal(SessionType.DigitalCredentialsApi),
|
|
1442
|
+
sessionId: string(),
|
|
1443
|
+
sessionKey: string(),
|
|
1444
|
+
sessionTtl: number(),
|
|
1445
|
+
request: record(string(), any())
|
|
1370
1446
|
});
|
|
1371
1447
|
|
|
1372
|
-
const
|
|
1448
|
+
const CreateSessionOpenId4vpResponseValidator = object({
|
|
1449
|
+
type: optional(literal(SessionType.Openid4vp)),
|
|
1373
1450
|
sessionId: string(),
|
|
1374
1451
|
sessionKey: string(),
|
|
1375
1452
|
sessionUrl: string()
|
|
1376
1453
|
});
|
|
1377
1454
|
|
|
1455
|
+
const CreateSessionResponseValidator = union([ CreateSessionDigitalCredentialsValidator, CreateSessionOpenId4vpResponseValidator ]);
|
|
1456
|
+
|
|
1378
1457
|
const GetSessionStatusResponseValidator = union([ object({
|
|
1379
1458
|
status: picklist([ PresentationStatusCode.ResultReady ]),
|
|
1380
1459
|
responseCode: optional(string())
|
|
@@ -1393,13 +1472,6 @@ const MATTR_SDK_VERSION_HEADER = "x-mattr-sdk-version";
|
|
|
1393
1472
|
|
|
1394
1473
|
const MATTR_SDK_VERSION_VALUE = "2.0.0";
|
|
1395
1474
|
|
|
1396
|
-
exports.Mode = void 0;
|
|
1397
|
-
|
|
1398
|
-
(function(Mode) {
|
|
1399
|
-
Mode["sameDevice"] = "sameDevice";
|
|
1400
|
-
Mode["crossDevice"] = "crossDevice";
|
|
1401
|
-
})(exports.Mode || (exports.Mode = {}));
|
|
1402
|
-
|
|
1403
1475
|
var MessageEventDataType;
|
|
1404
1476
|
|
|
1405
1477
|
(function(MessageEventDataType) {
|
|
@@ -1408,30 +1480,28 @@ var MessageEventDataType;
|
|
|
1408
1480
|
MessageEventDataType["PresentationAbort"] = "PresentationAbort";
|
|
1409
1481
|
})(MessageEventDataType || (MessageEventDataType = {}));
|
|
1410
1482
|
|
|
1411
|
-
const
|
|
1412
|
-
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1413
|
-
redirectUri: string(),
|
|
1414
|
-
challenge: optional(string()),
|
|
1483
|
+
const OpenId4vpConfigSameDeviceOptionsValidator = object({
|
|
1415
1484
|
walletProviderId: optional(string()),
|
|
1416
|
-
mode:
|
|
1485
|
+
mode: literal(exports.Mode.SameDevice),
|
|
1486
|
+
redirectUri: string()
|
|
1417
1487
|
});
|
|
1418
1488
|
|
|
1419
|
-
const
|
|
1420
|
-
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1421
|
-
challenge: optional(string()),
|
|
1489
|
+
const OpenId4vpConfigCrossDeviceOptionsValidator = object({
|
|
1422
1490
|
walletProviderId: optional(string()),
|
|
1423
|
-
mode:
|
|
1491
|
+
mode: literal(exports.Mode.CrossDevice)
|
|
1424
1492
|
});
|
|
1425
1493
|
|
|
1426
|
-
const
|
|
1427
|
-
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1428
|
-
redirectUri: string(),
|
|
1429
|
-
challenge: optional(string()),
|
|
1494
|
+
const OpenId4vpConfigAutoDetectOptionsValidator = object({
|
|
1430
1495
|
walletProviderId: optional(string()),
|
|
1431
|
-
|
|
1496
|
+
redirectUri: string(),
|
|
1497
|
+
mode: optional(picklist([ exports.Mode.CrossDevice, exports.Mode.SameDevice ]))
|
|
1432
1498
|
});
|
|
1433
1499
|
|
|
1434
|
-
const RequestCredentialsOptionsValidator =
|
|
1500
|
+
const RequestCredentialsOptionsValidator = object({
|
|
1501
|
+
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1502
|
+
challenge: optional(string()),
|
|
1503
|
+
openid4vpConfiguration: optional(union([ OpenId4vpConfigSameDeviceOptionsValidator, OpenId4vpConfigCrossDeviceOptionsValidator, OpenId4vpConfigAutoDetectOptionsValidator ]))
|
|
1504
|
+
});
|
|
1435
1505
|
|
|
1436
1506
|
exports.RequestCredentialsErrorType = void 0;
|
|
1437
1507
|
|
|
@@ -1447,6 +1517,10 @@ var RequestCredentialsErrorMessage;
|
|
|
1447
1517
|
RequestCredentialsErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
|
|
1448
1518
|
RequestCredentialsErrorMessage["FailedToGetSessionStatus"] = "Failed to get session status";
|
|
1449
1519
|
RequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
|
|
1520
|
+
RequestCredentialsErrorMessage["FailedToVerifyCredentialResponse"] = "Failed to verify credential response";
|
|
1521
|
+
RequestCredentialsErrorMessage["MissingOpenId4vpConfig"] = "Identified openid4vp session, but missing openId4vpConfiguration on `requestCredentials`";
|
|
1522
|
+
RequestCredentialsErrorMessage["DcApiError"] = "Failed to request credentials with Digital Credentials API";
|
|
1523
|
+
RequestCredentialsErrorMessage["DcApiResponseParseError"] = "Failed to parse response from Digital Credentials API";
|
|
1450
1524
|
RequestCredentialsErrorMessage["Abort"] = "User aborted the session";
|
|
1451
1525
|
RequestCredentialsErrorMessage["Timeout"] = "User session timeout";
|
|
1452
1526
|
})(RequestCredentialsErrorMessage || (RequestCredentialsErrorMessage = {}));
|
|
@@ -1468,11 +1542,11 @@ const InitialiseOptionsValidator = object({
|
|
|
1468
1542
|
applicationId: pipe(string(), nonEmpty("Must not be empty"))
|
|
1469
1543
|
});
|
|
1470
1544
|
|
|
1471
|
-
var
|
|
1545
|
+
var SafeFetchCommonResponseErrorType;
|
|
1472
1546
|
|
|
1473
|
-
(function(
|
|
1474
|
-
|
|
1475
|
-
})(
|
|
1547
|
+
(function(SafeFetchCommonResponseErrorType) {
|
|
1548
|
+
SafeFetchCommonResponseErrorType["UnexpectedResponse"] = "UnexpectedResponse";
|
|
1549
|
+
})(SafeFetchCommonResponseErrorType || (SafeFetchCommonResponseErrorType = {}));
|
|
1476
1550
|
|
|
1477
1551
|
var SafeFetchErrorType;
|
|
1478
1552
|
|
|
@@ -1636,16 +1710,15 @@ const getHashParamValue = (hash, param) => {
|
|
|
1636
1710
|
return urlParams.get(param);
|
|
1637
1711
|
};
|
|
1638
1712
|
|
|
1639
|
-
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl,
|
|
1640
|
-
const postData =
|
|
1713
|
+
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl, walletProviderId: walletProviderId, dcApiSupported: dcApiSupported, applicationId: applicationId}) => {
|
|
1714
|
+
const postData = {
|
|
1641
1715
|
credentialQuery: credentialQuery,
|
|
1642
1716
|
challenge: challenge,
|
|
1643
|
-
applicationId: applicationId
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
} : {});
|
|
1717
|
+
applicationId: applicationId,
|
|
1718
|
+
redirectUri: redirectUri,
|
|
1719
|
+
walletProviderId: walletProviderId,
|
|
1720
|
+
dcApiSupported: dcApiSupported
|
|
1721
|
+
};
|
|
1649
1722
|
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions`, {
|
|
1650
1723
|
method: "POST",
|
|
1651
1724
|
headers: {
|
|
@@ -1659,8 +1732,8 @@ const createSession = async ({credentialQuery: credentialQuery, challenge: chall
|
|
|
1659
1732
|
const data = await responseResult.value.json();
|
|
1660
1733
|
if (!isType(CreateSessionResponseValidator)(data)) {
|
|
1661
1734
|
return err({
|
|
1662
|
-
type:
|
|
1663
|
-
message: "Create session
|
|
1735
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1736
|
+
message: "Create session returned unsupported response"
|
|
1664
1737
|
});
|
|
1665
1738
|
}
|
|
1666
1739
|
return ok(data);
|
|
@@ -1693,7 +1766,7 @@ const getSessionStatus = async ({apiBaseUrl: apiBaseUrl, sessionId: sessionId, s
|
|
|
1693
1766
|
const data = await responseResult.value.json();
|
|
1694
1767
|
if (!isType(GetSessionStatusResponseValidator)(data)) {
|
|
1695
1768
|
return err({
|
|
1696
|
-
type:
|
|
1769
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1697
1770
|
message: "Get session status return unsupported response"
|
|
1698
1771
|
});
|
|
1699
1772
|
}
|
|
@@ -1722,7 +1795,7 @@ const exchangeSessionResult = async ({challenge: challenge, responseCode: respon
|
|
|
1722
1795
|
const data = await responseResult.value.json();
|
|
1723
1796
|
if (!isType(PresentationResultRelaxValidator)(data)) {
|
|
1724
1797
|
return err({
|
|
1725
|
-
type:
|
|
1798
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1726
1799
|
message: "Exchange session result return unsupported response",
|
|
1727
1800
|
details: {
|
|
1728
1801
|
data: data
|
|
@@ -1833,24 +1906,8 @@ const openCrossDeviceModal = options => {
|
|
|
1833
1906
|
return modalContainer;
|
|
1834
1907
|
};
|
|
1835
1908
|
|
|
1836
|
-
const
|
|
1837
|
-
const {challenge: challenge,
|
|
1838
|
-
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
|
|
1839
|
-
const createSessionResult = await createSession({
|
|
1840
|
-
credentialQuery: credentialQuery,
|
|
1841
|
-
challenge: challenge,
|
|
1842
|
-
apiBaseUrl: apiBaseUrl,
|
|
1843
|
-
applicationId: applicationId,
|
|
1844
|
-
walletProviderId: walletProviderId
|
|
1845
|
-
});
|
|
1846
|
-
if (createSessionResult.isErr()) {
|
|
1847
|
-
return err({
|
|
1848
|
-
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1849
|
-
message: RequestCredentialsErrorMessage.FailedToCreateSession,
|
|
1850
|
-
cause: createSessionResult.error
|
|
1851
|
-
});
|
|
1852
|
-
}
|
|
1853
|
-
const {sessionUrl: sessionUrl, sessionId: sessionId, sessionKey: sessionKey} = createSessionResult.value;
|
|
1909
|
+
const requestCredentialsWithCrossDevice = async options => {
|
|
1910
|
+
const {challenge: challenge, apiBaseUrl: apiBaseUrl, sessionUrl: sessionUrl, sessionId: sessionId, sessionKey: sessionKey} = options;
|
|
1854
1911
|
const container = openCrossDeviceModal({
|
|
1855
1912
|
sessionUrl: sessionUrl
|
|
1856
1913
|
});
|
|
@@ -1881,6 +1938,131 @@ const requestCredentialsCrossDevice = async options => {
|
|
|
1881
1938
|
}));
|
|
1882
1939
|
};
|
|
1883
1940
|
|
|
1941
|
+
const requestCredentialsWithDigitalCredentialsApi = async options => {
|
|
1942
|
+
const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, request: request} = options;
|
|
1943
|
+
const credentialResponseResult = await getCredentials(request);
|
|
1944
|
+
if (credentialResponseResult.isErr()) {
|
|
1945
|
+
await abortSession({
|
|
1946
|
+
apiBaseUrl: apiBaseUrl,
|
|
1947
|
+
sessionId: sessionId,
|
|
1948
|
+
sessionKey: sessionKey
|
|
1949
|
+
});
|
|
1950
|
+
return err(credentialResponseResult.error);
|
|
1951
|
+
}
|
|
1952
|
+
const credentialResponse = credentialResponseResult.value;
|
|
1953
|
+
const parsedCredentialResponseResult = parseCredentialResponse(credentialResponse);
|
|
1954
|
+
if (parsedCredentialResponseResult.isErr()) {
|
|
1955
|
+
await abortSession({
|
|
1956
|
+
apiBaseUrl: apiBaseUrl,
|
|
1957
|
+
sessionId: sessionId,
|
|
1958
|
+
sessionKey: sessionKey
|
|
1959
|
+
});
|
|
1960
|
+
return err(parsedCredentialResponseResult.error);
|
|
1961
|
+
}
|
|
1962
|
+
const parsedCredentialResponse = parsedCredentialResponseResult.value;
|
|
1963
|
+
const credentialVerificationResult = await verifyCredentialResponse({
|
|
1964
|
+
apiBaseUrl: apiBaseUrl,
|
|
1965
|
+
sessionId: sessionId,
|
|
1966
|
+
sessionKey: sessionKey,
|
|
1967
|
+
challenge: challenge,
|
|
1968
|
+
protocol: parsedCredentialResponse.protocol,
|
|
1969
|
+
data: parsedCredentialResponse.data
|
|
1970
|
+
});
|
|
1971
|
+
if (credentialVerificationResult.isErr()) {
|
|
1972
|
+
return err({
|
|
1973
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1974
|
+
message: RequestCredentialsErrorMessage.FailedToVerifyCredentialResponse,
|
|
1975
|
+
cause: credentialVerificationResult.error
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
return ok(credentialVerificationResult.value);
|
|
1979
|
+
};
|
|
1980
|
+
|
|
1981
|
+
const getCredentials = async request => {
|
|
1982
|
+
try {
|
|
1983
|
+
const credentialResponse = await navigator.credentials.get(request);
|
|
1984
|
+
return ok(credentialResponse);
|
|
1985
|
+
} catch (exception) {
|
|
1986
|
+
return err({
|
|
1987
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1988
|
+
message: RequestCredentialsErrorMessage.DcApiError,
|
|
1989
|
+
cause: exception
|
|
1990
|
+
});
|
|
1991
|
+
}
|
|
1992
|
+
};
|
|
1993
|
+
|
|
1994
|
+
const parseCredentialResponse = credentialResponse => {
|
|
1995
|
+
if (!credentialResponse) {
|
|
1996
|
+
return err({
|
|
1997
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1998
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
1999
|
+
details: {
|
|
2000
|
+
response: credentialResponse
|
|
2001
|
+
}
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
if (typeof credentialResponse === "object") {
|
|
2005
|
+
return ok(credentialResponse);
|
|
2006
|
+
}
|
|
2007
|
+
if (typeof credentialResponse === "string") {
|
|
2008
|
+
try {
|
|
2009
|
+
const parsed = JSON.parse(credentialResponse);
|
|
2010
|
+
return ok(parsed);
|
|
2011
|
+
} catch (_a) {
|
|
2012
|
+
return err({
|
|
2013
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2014
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
2015
|
+
details: {
|
|
2016
|
+
response: credentialResponse
|
|
2017
|
+
}
|
|
2018
|
+
});
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
return err({
|
|
2022
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2023
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
2024
|
+
details: {
|
|
2025
|
+
response: credentialResponse
|
|
2026
|
+
}
|
|
2027
|
+
});
|
|
2028
|
+
};
|
|
2029
|
+
|
|
2030
|
+
const verifyCredentialResponse = async options => {
|
|
2031
|
+
const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, protocol: protocol, data: data} = options;
|
|
2032
|
+
const requestBody = {
|
|
2033
|
+
protocol: protocol,
|
|
2034
|
+
data: data,
|
|
2035
|
+
challenge: challenge
|
|
2036
|
+
};
|
|
2037
|
+
const credentialVerificationResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/dc-api/response`, {
|
|
2038
|
+
method: "POST",
|
|
2039
|
+
headers: {
|
|
2040
|
+
"Content-Type": "application/json",
|
|
2041
|
+
Authorization: `Bearer ${sessionKey}`
|
|
2042
|
+
},
|
|
2043
|
+
body: JSON.stringify(requestBody)
|
|
2044
|
+
});
|
|
2045
|
+
if (credentialVerificationResult.isErr()) {
|
|
2046
|
+
return err(credentialVerificationResult.error);
|
|
2047
|
+
}
|
|
2048
|
+
const credentialVerificationResponse = await credentialVerificationResult.value.json();
|
|
2049
|
+
if (!isType(PresentationResultRelaxValidator)(credentialVerificationResponse)) {
|
|
2050
|
+
return err({
|
|
2051
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
2052
|
+
message: "Verify credential returned unsupported response",
|
|
2053
|
+
details: {
|
|
2054
|
+
response: credentialVerificationResponse
|
|
2055
|
+
}
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
return ok(credentialVerificationResponse);
|
|
2059
|
+
};
|
|
2060
|
+
|
|
2061
|
+
const isDigitalCredentialsApiSupported = () => {
|
|
2062
|
+
var _a;
|
|
2063
|
+
return "DigitalCredential" in window && typeof window.DigitalCredential === "function" && typeof ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.credentials) === null || _a === void 0 ? void 0 : _a.get) === "function";
|
|
2064
|
+
};
|
|
2065
|
+
|
|
1884
2066
|
const sleep = ms => new Promise((resolve => setTimeout(resolve, ms)));
|
|
1885
2067
|
|
|
1886
2068
|
const SESSION_STATUS_POLLING_MAX_RETRY = 1e3;
|
|
@@ -1897,24 +2079,7 @@ var SameDeviceRequestCredentialsErrorMessage;
|
|
|
1897
2079
|
})(SameDeviceRequestCredentialsErrorMessage || (SameDeviceRequestCredentialsErrorMessage = {}));
|
|
1898
2080
|
|
|
1899
2081
|
const requestCredentialsSameDevice = async options => {
|
|
1900
|
-
const {challenge: challenge,
|
|
1901
|
-
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
|
|
1902
|
-
const createSessionResult = await createSession({
|
|
1903
|
-
credentialQuery: credentialQuery,
|
|
1904
|
-
challenge: challenge,
|
|
1905
|
-
redirectUri: redirectUri,
|
|
1906
|
-
apiBaseUrl: apiBaseUrl,
|
|
1907
|
-
applicationId: applicationId,
|
|
1908
|
-
walletProviderId: walletProviderId
|
|
1909
|
-
});
|
|
1910
|
-
if (createSessionResult.isErr()) {
|
|
1911
|
-
return err({
|
|
1912
|
-
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1913
|
-
message: SameDeviceRequestCredentialsErrorMessage.FailedToCreateSession,
|
|
1914
|
-
cause: createSessionResult.error
|
|
1915
|
-
});
|
|
1916
|
-
}
|
|
1917
|
-
const {sessionUrl: sessionUrl, sessionKey: sessionKey, sessionId: sessionId} = createSessionResult.value;
|
|
2082
|
+
const {challenge: challenge, apiBaseUrl: apiBaseUrl, applicationId: applicationId, sessionUrl: sessionUrl, sessionKey: sessionKey, sessionId: sessionId} = options;
|
|
1918
2083
|
const abortController = setActiveSession({
|
|
1919
2084
|
sessionId: sessionId,
|
|
1920
2085
|
sessionKey: sessionKey
|
|
@@ -1970,20 +2135,78 @@ const requestCredentials = async options => {
|
|
|
1970
2135
|
throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
|
|
1971
2136
|
}
|
|
1972
2137
|
assertType(RequestCredentialsOptionsValidator, "Invalid request credential options")(options);
|
|
1973
|
-
const {
|
|
1974
|
-
const
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
2138
|
+
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
|
|
2139
|
+
const {challenge: challenge = generateChallenge(), credentialQuery: credentialQuery, openid4vpConfiguration: openid4vpConfiguration} = options;
|
|
2140
|
+
const dcApiSupported = isDigitalCredentialsApiSupported();
|
|
2141
|
+
const openId4VpRedirectUri = deriveOpenId4vpRedirectUri(openid4vpConfiguration);
|
|
2142
|
+
const createSessionResult = await createSession({
|
|
2143
|
+
credentialQuery: credentialQuery,
|
|
2144
|
+
challenge: challenge,
|
|
2145
|
+
redirectUri: openId4VpRedirectUri,
|
|
2146
|
+
walletProviderId: (_a = openid4vpConfiguration === null || openid4vpConfiguration === void 0 ? void 0 : openid4vpConfiguration.walletProviderId) !== null && _a !== void 0 ? _a : undefined,
|
|
2147
|
+
apiBaseUrl: apiBaseUrl,
|
|
2148
|
+
applicationId: applicationId,
|
|
2149
|
+
dcApiSupported: dcApiSupported
|
|
2150
|
+
});
|
|
2151
|
+
if (createSessionResult.isErr()) {
|
|
2152
|
+
return err({
|
|
2153
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2154
|
+
message: RequestCredentialsErrorMessage.FailedToCreateSession,
|
|
2155
|
+
cause: createSessionResult.error
|
|
2156
|
+
});
|
|
2157
|
+
}
|
|
2158
|
+
const session = createSessionResult.value;
|
|
2159
|
+
const {sessionKey: sessionKey, sessionId: sessionId} = session;
|
|
2160
|
+
if (session.type === SessionType.DigitalCredentialsApi) {
|
|
2161
|
+
const {request: request} = session;
|
|
2162
|
+
return await requestCredentialsWithDigitalCredentialsApi({
|
|
2163
|
+
apiBaseUrl: apiBaseUrl,
|
|
2164
|
+
request: request,
|
|
2165
|
+
sessionId: sessionId,
|
|
2166
|
+
sessionKey: sessionKey,
|
|
2167
|
+
challenge: challenge
|
|
2168
|
+
});
|
|
2169
|
+
}
|
|
2170
|
+
if (!openid4vpConfiguration) {
|
|
2171
|
+
return err({
|
|
2172
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2173
|
+
message: RequestCredentialsErrorMessage.MissingOpenId4vpConfig
|
|
2174
|
+
});
|
|
2175
|
+
}
|
|
2176
|
+
const {sessionUrl: sessionUrl} = session;
|
|
2177
|
+
if (openId4VpRedirectUri) {
|
|
2178
|
+
return await requestCredentialsSameDevice({
|
|
1978
2179
|
challenge: challenge,
|
|
1979
|
-
|
|
1980
|
-
|
|
2180
|
+
apiBaseUrl: apiBaseUrl,
|
|
2181
|
+
applicationId: applicationId,
|
|
2182
|
+
sessionUrl: sessionUrl,
|
|
2183
|
+
sessionKey: sessionKey,
|
|
2184
|
+
sessionId: sessionId
|
|
2185
|
+
});
|
|
1981
2186
|
}
|
|
1982
|
-
return await
|
|
1983
|
-
initialiseOptions: initialiseOptions,
|
|
2187
|
+
return await requestCredentialsWithCrossDevice({
|
|
1984
2188
|
challenge: challenge,
|
|
1985
|
-
|
|
1986
|
-
|
|
2189
|
+
apiBaseUrl: apiBaseUrl,
|
|
2190
|
+
sessionUrl: sessionUrl,
|
|
2191
|
+
sessionKey: sessionKey,
|
|
2192
|
+
sessionId: sessionId
|
|
2193
|
+
});
|
|
2194
|
+
};
|
|
2195
|
+
|
|
2196
|
+
const deriveOpenId4vpRedirectUri = openid4vpConfiguration => {
|
|
2197
|
+
if (!openid4vpConfiguration) {
|
|
2198
|
+
return undefined;
|
|
2199
|
+
}
|
|
2200
|
+
let detectedMode;
|
|
2201
|
+
if (openid4vpConfiguration && openid4vpConfiguration.mode) {
|
|
2202
|
+
detectedMode = openid4vpConfiguration.mode;
|
|
2203
|
+
} else {
|
|
2204
|
+
detectedMode = isMobileDetect(navigator.userAgent) ? exports.Mode.SameDevice : exports.Mode.CrossDevice;
|
|
2205
|
+
}
|
|
2206
|
+
if (detectedMode === exports.Mode.SameDevice && !isType(OpenId4vpConfigCrossDeviceOptionsValidator)(openid4vpConfiguration) && openid4vpConfiguration.redirectUri) {
|
|
2207
|
+
return openid4vpConfiguration.redirectUri;
|
|
2208
|
+
}
|
|
2209
|
+
return undefined;
|
|
1987
2210
|
};
|
|
1988
2211
|
|
|
1989
2212
|
exports.HandleRedirectCallbackErrorType = void 0;
|
|
@@ -2046,7 +2269,7 @@ const abortCredentialRequest = async () => {
|
|
|
2046
2269
|
if (!initialiseOptions) {
|
|
2047
2270
|
throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
|
|
2048
2271
|
}
|
|
2049
|
-
const {apiBaseUrl: apiBaseUrl
|
|
2272
|
+
const {apiBaseUrl: apiBaseUrl} = initialiseOptions;
|
|
2050
2273
|
const session = getActiveSession();
|
|
2051
2274
|
if (!session || !session.sessionKey) {
|
|
2052
2275
|
return ok(undefined);
|
|
@@ -2055,7 +2278,6 @@ const abortCredentialRequest = async () => {
|
|
|
2055
2278
|
removeActiveSession();
|
|
2056
2279
|
const abortSessionResult = await abortSession({
|
|
2057
2280
|
apiBaseUrl: apiBaseUrl,
|
|
2058
|
-
applicationId: applicationId,
|
|
2059
2281
|
sessionId: sessionId,
|
|
2060
2282
|
sessionKey: sessionKey
|
|
2061
2283
|
});
|
|
@@ -2081,6 +2303,8 @@ exports.handleRedirectCallback = handleRedirectCallback;
|
|
|
2081
2303
|
|
|
2082
2304
|
exports.initialise = initialise;
|
|
2083
2305
|
|
|
2306
|
+
exports.isDigitalCredentialsApiSupported = isDigitalCredentialsApiSupported;
|
|
2307
|
+
|
|
2084
2308
|
exports.requestCredentials = requestCredentials;
|
|
2085
2309
|
|
|
2086
2310
|
exports.utils = utils;
|