@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
|
*
|
|
@@ -650,6 +650,19 @@
|
|
|
650
650
|
function getDefault(schema, dataset, config2) {
|
|
651
651
|
return typeof schema["default"] === "function" ? schema["default"](dataset, config2) : schema["default"];
|
|
652
652
|
}
|
|
653
|
+
function any() {
|
|
654
|
+
return {
|
|
655
|
+
kind: "schema",
|
|
656
|
+
type: "any",
|
|
657
|
+
reference: any,
|
|
658
|
+
expects: "any",
|
|
659
|
+
async: false,
|
|
660
|
+
_run: function _run(dataset) {
|
|
661
|
+
dataset.typed = true;
|
|
662
|
+
return dataset;
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
}
|
|
653
666
|
function array(item, message) {
|
|
654
667
|
return {
|
|
655
668
|
kind: "schema",
|
|
@@ -733,6 +746,43 @@
|
|
|
733
746
|
}
|
|
734
747
|
};
|
|
735
748
|
}
|
|
749
|
+
function literal(literal_, message) {
|
|
750
|
+
return {
|
|
751
|
+
kind: "schema",
|
|
752
|
+
type: "literal",
|
|
753
|
+
reference: literal,
|
|
754
|
+
expects: _stringify(literal_),
|
|
755
|
+
async: false,
|
|
756
|
+
literal: literal_,
|
|
757
|
+
message: message,
|
|
758
|
+
_run: function _run(dataset, config2) {
|
|
759
|
+
if (dataset.value === this.literal) {
|
|
760
|
+
dataset.typed = true;
|
|
761
|
+
} else {
|
|
762
|
+
_addIssue(this, "type", dataset, config2);
|
|
763
|
+
}
|
|
764
|
+
return dataset;
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
function number(message) {
|
|
769
|
+
return {
|
|
770
|
+
kind: "schema",
|
|
771
|
+
type: "number",
|
|
772
|
+
reference: number,
|
|
773
|
+
expects: "number",
|
|
774
|
+
async: false,
|
|
775
|
+
message: message,
|
|
776
|
+
_run: function _run(dataset, config2) {
|
|
777
|
+
if (typeof dataset.value === "number" && !isNaN(dataset.value)) {
|
|
778
|
+
dataset.typed = true;
|
|
779
|
+
} else {
|
|
780
|
+
_addIssue(this, "type", dataset, config2);
|
|
781
|
+
}
|
|
782
|
+
return dataset;
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
}
|
|
736
786
|
function object(entries, message) {
|
|
737
787
|
return {
|
|
738
788
|
kind: "schema",
|
|
@@ -1282,17 +1332,37 @@
|
|
|
1282
1332
|
credentialErrors: optional(unknown()),
|
|
1283
1333
|
error: optional(unknown())
|
|
1284
1334
|
});
|
|
1335
|
+
exports.Mode = void 0;
|
|
1336
|
+
(function(Mode) {
|
|
1337
|
+
Mode["SameDevice"] = "sameDevice";
|
|
1338
|
+
Mode["CrossDevice"] = "crossDevice";
|
|
1339
|
+
})(exports.Mode || (exports.Mode = {}));
|
|
1340
|
+
var SessionType;
|
|
1341
|
+
(function(SessionType) {
|
|
1342
|
+
SessionType["DigitalCredentialsApi"] = "digital-credentials-api";
|
|
1343
|
+
SessionType["Openid4vp"] = "openid4vp";
|
|
1344
|
+
})(SessionType || (SessionType = {}));
|
|
1285
1345
|
object({
|
|
1286
1346
|
credentialQuery: array(CredentialQueryValidator),
|
|
1287
1347
|
challenge: string(),
|
|
1288
1348
|
redirectUri: optional(string()),
|
|
1289
|
-
walletProviderId: optional(string())
|
|
1349
|
+
walletProviderId: optional(string()),
|
|
1350
|
+
dcApiSupported: optional(_boolean())
|
|
1290
1351
|
});
|
|
1291
|
-
const
|
|
1352
|
+
const CreateSessionDigitalCredentialsValidator = object({
|
|
1353
|
+
type: literal(SessionType.DigitalCredentialsApi),
|
|
1354
|
+
sessionId: string(),
|
|
1355
|
+
sessionKey: string(),
|
|
1356
|
+
sessionTtl: number(),
|
|
1357
|
+
request: record(string(), any())
|
|
1358
|
+
});
|
|
1359
|
+
const CreateSessionOpenId4vpResponseValidator = object({
|
|
1360
|
+
type: optional(literal(SessionType.Openid4vp)),
|
|
1292
1361
|
sessionId: string(),
|
|
1293
1362
|
sessionKey: string(),
|
|
1294
1363
|
sessionUrl: string()
|
|
1295
1364
|
});
|
|
1365
|
+
const CreateSessionResponseValidator = union([ CreateSessionDigitalCredentialsValidator, CreateSessionOpenId4vpResponseValidator ]);
|
|
1296
1366
|
const GetSessionStatusResponseValidator = union([ object({
|
|
1297
1367
|
status: picklist([ PresentationStatusCode.ResultReady ]),
|
|
1298
1368
|
responseCode: optional(string())
|
|
@@ -1306,38 +1376,31 @@
|
|
|
1306
1376
|
})(LocalStorageKey || (LocalStorageKey = {}));
|
|
1307
1377
|
const MATTR_SDK_VERSION_HEADER = "x-mattr-sdk-version";
|
|
1308
1378
|
const MATTR_SDK_VERSION_VALUE = "2.0.0";
|
|
1309
|
-
exports.Mode = void 0;
|
|
1310
|
-
(function(Mode) {
|
|
1311
|
-
Mode["sameDevice"] = "sameDevice";
|
|
1312
|
-
Mode["crossDevice"] = "crossDevice";
|
|
1313
|
-
})(exports.Mode || (exports.Mode = {}));
|
|
1314
1379
|
var MessageEventDataType;
|
|
1315
1380
|
(function(MessageEventDataType) {
|
|
1316
1381
|
MessageEventDataType["PresentationCompleted"] = "PresentationCompleted";
|
|
1317
1382
|
MessageEventDataType["PresentationTimeout"] = "PresentationTimeout";
|
|
1318
1383
|
MessageEventDataType["PresentationAbort"] = "PresentationAbort";
|
|
1319
1384
|
})(MessageEventDataType || (MessageEventDataType = {}));
|
|
1320
|
-
const
|
|
1321
|
-
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1322
|
-
redirectUri: string(),
|
|
1323
|
-
challenge: optional(string()),
|
|
1385
|
+
const OpenId4vpConfigSameDeviceOptionsValidator = object({
|
|
1324
1386
|
walletProviderId: optional(string()),
|
|
1325
|
-
mode:
|
|
1387
|
+
mode: literal(exports.Mode.SameDevice),
|
|
1388
|
+
redirectUri: string()
|
|
1326
1389
|
});
|
|
1327
|
-
const
|
|
1328
|
-
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1329
|
-
challenge: optional(string()),
|
|
1390
|
+
const OpenId4vpConfigCrossDeviceOptionsValidator = object({
|
|
1330
1391
|
walletProviderId: optional(string()),
|
|
1331
|
-
mode:
|
|
1392
|
+
mode: literal(exports.Mode.CrossDevice)
|
|
1332
1393
|
});
|
|
1333
|
-
const
|
|
1334
|
-
|
|
1394
|
+
const OpenId4vpConfigAutoDetectOptionsValidator = object({
|
|
1395
|
+
walletProviderId: optional(string()),
|
|
1335
1396
|
redirectUri: string(),
|
|
1397
|
+
mode: optional(picklist([ exports.Mode.CrossDevice, exports.Mode.SameDevice ]))
|
|
1398
|
+
});
|
|
1399
|
+
const RequestCredentialsOptionsValidator = object({
|
|
1400
|
+
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1336
1401
|
challenge: optional(string()),
|
|
1337
|
-
|
|
1338
|
-
mode: optional(picklist([ exports.Mode.crossDevice, exports.Mode.sameDevice ]))
|
|
1402
|
+
openid4vpConfiguration: optional(union([ OpenId4vpConfigSameDeviceOptionsValidator, OpenId4vpConfigCrossDeviceOptionsValidator, OpenId4vpConfigAutoDetectOptionsValidator ]))
|
|
1339
1403
|
});
|
|
1340
|
-
const RequestCredentialsOptionsValidator = union([ RequestCredentialsSameDeviceOptionsValidator, RequestCredentialsCrossDeviceOptionsValidator, RequestCredentialsAutoDetectDeviceOptionsValidator ]);
|
|
1341
1404
|
exports.RequestCredentialsErrorType = void 0;
|
|
1342
1405
|
(function(RequestCredentialsErrorType) {
|
|
1343
1406
|
RequestCredentialsErrorType["RequestCredentialsFailed"] = "RequestCredentialsFailed";
|
|
@@ -1349,6 +1412,10 @@
|
|
|
1349
1412
|
RequestCredentialsErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
|
|
1350
1413
|
RequestCredentialsErrorMessage["FailedToGetSessionStatus"] = "Failed to get session status";
|
|
1351
1414
|
RequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
|
|
1415
|
+
RequestCredentialsErrorMessage["FailedToVerifyCredentialResponse"] = "Failed to verify credential response";
|
|
1416
|
+
RequestCredentialsErrorMessage["MissingOpenId4vpConfig"] = "Identified openid4vp session, but missing openId4vpConfiguration on `requestCredentials`";
|
|
1417
|
+
RequestCredentialsErrorMessage["DcApiError"] = "Failed to request credentials with Digital Credentials API";
|
|
1418
|
+
RequestCredentialsErrorMessage["DcApiResponseParseError"] = "Failed to parse response from Digital Credentials API";
|
|
1352
1419
|
RequestCredentialsErrorMessage["Abort"] = "User aborted the session";
|
|
1353
1420
|
RequestCredentialsErrorMessage["Timeout"] = "User session timeout";
|
|
1354
1421
|
})(RequestCredentialsErrorMessage || (RequestCredentialsErrorMessage = {}));
|
|
@@ -1364,10 +1431,10 @@
|
|
|
1364
1431
|
apiBaseUrl: pipe(string(), nonEmpty("Must not be empty")),
|
|
1365
1432
|
applicationId: pipe(string(), nonEmpty("Must not be empty"))
|
|
1366
1433
|
});
|
|
1367
|
-
var
|
|
1368
|
-
(function(
|
|
1369
|
-
|
|
1370
|
-
})(
|
|
1434
|
+
var SafeFetchCommonResponseErrorType;
|
|
1435
|
+
(function(SafeFetchCommonResponseErrorType) {
|
|
1436
|
+
SafeFetchCommonResponseErrorType["UnexpectedResponse"] = "UnexpectedResponse";
|
|
1437
|
+
})(SafeFetchCommonResponseErrorType || (SafeFetchCommonResponseErrorType = {}));
|
|
1371
1438
|
var SafeFetchErrorType;
|
|
1372
1439
|
(function(SafeFetchErrorType) {
|
|
1373
1440
|
SafeFetchErrorType["HttpError"] = "HttpError";
|
|
@@ -1501,16 +1568,15 @@
|
|
|
1501
1568
|
const urlParams = new URLSearchParams(hash.split("#")[1]);
|
|
1502
1569
|
return urlParams.get(param);
|
|
1503
1570
|
};
|
|
1504
|
-
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl,
|
|
1505
|
-
const postData =
|
|
1571
|
+
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl, walletProviderId: walletProviderId, dcApiSupported: dcApiSupported, applicationId: applicationId}) => {
|
|
1572
|
+
const postData = {
|
|
1506
1573
|
credentialQuery: credentialQuery,
|
|
1507
1574
|
challenge: challenge,
|
|
1508
|
-
applicationId: applicationId
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
} : {});
|
|
1575
|
+
applicationId: applicationId,
|
|
1576
|
+
redirectUri: redirectUri,
|
|
1577
|
+
walletProviderId: walletProviderId,
|
|
1578
|
+
dcApiSupported: dcApiSupported
|
|
1579
|
+
};
|
|
1514
1580
|
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions`, {
|
|
1515
1581
|
method: "POST",
|
|
1516
1582
|
headers: {
|
|
@@ -1524,8 +1590,8 @@
|
|
|
1524
1590
|
const data = await responseResult.value.json();
|
|
1525
1591
|
if (!isType(CreateSessionResponseValidator)(data)) {
|
|
1526
1592
|
return err({
|
|
1527
|
-
type:
|
|
1528
|
-
message: "Create session
|
|
1593
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1594
|
+
message: "Create session returned unsupported response"
|
|
1529
1595
|
});
|
|
1530
1596
|
}
|
|
1531
1597
|
return ok(data);
|
|
@@ -1556,7 +1622,7 @@
|
|
|
1556
1622
|
const data = await responseResult.value.json();
|
|
1557
1623
|
if (!isType(GetSessionStatusResponseValidator)(data)) {
|
|
1558
1624
|
return err({
|
|
1559
|
-
type:
|
|
1625
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1560
1626
|
message: "Get session status return unsupported response"
|
|
1561
1627
|
});
|
|
1562
1628
|
}
|
|
@@ -1584,7 +1650,7 @@
|
|
|
1584
1650
|
const data = await responseResult.value.json();
|
|
1585
1651
|
if (!isType(PresentationResultRelaxValidator)(data)) {
|
|
1586
1652
|
return err({
|
|
1587
|
-
type:
|
|
1653
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1588
1654
|
message: "Exchange session result return unsupported response",
|
|
1589
1655
|
details: {
|
|
1590
1656
|
data: data
|
|
@@ -1685,24 +1751,8 @@
|
|
|
1685
1751
|
modalContainer.setAttribute("class", "mattr-verifier-modal-container");
|
|
1686
1752
|
return modalContainer;
|
|
1687
1753
|
};
|
|
1688
|
-
const
|
|
1689
|
-
const {challenge: challenge,
|
|
1690
|
-
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
|
|
1691
|
-
const createSessionResult = await createSession({
|
|
1692
|
-
credentialQuery: credentialQuery,
|
|
1693
|
-
challenge: challenge,
|
|
1694
|
-
apiBaseUrl: apiBaseUrl,
|
|
1695
|
-
applicationId: applicationId,
|
|
1696
|
-
walletProviderId: walletProviderId
|
|
1697
|
-
});
|
|
1698
|
-
if (createSessionResult.isErr()) {
|
|
1699
|
-
return err({
|
|
1700
|
-
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1701
|
-
message: RequestCredentialsErrorMessage.FailedToCreateSession,
|
|
1702
|
-
cause: createSessionResult.error
|
|
1703
|
-
});
|
|
1704
|
-
}
|
|
1705
|
-
const {sessionUrl: sessionUrl, sessionId: sessionId, sessionKey: sessionKey} = createSessionResult.value;
|
|
1754
|
+
const requestCredentialsWithCrossDevice = async options => {
|
|
1755
|
+
const {challenge: challenge, apiBaseUrl: apiBaseUrl, sessionUrl: sessionUrl, sessionId: sessionId, sessionKey: sessionKey} = options;
|
|
1706
1756
|
const container = openCrossDeviceModal({
|
|
1707
1757
|
sessionUrl: sessionUrl
|
|
1708
1758
|
});
|
|
@@ -1732,6 +1782,126 @@
|
|
|
1732
1782
|
window.addEventListener(WindowEventListenerType.message, listener, false);
|
|
1733
1783
|
}));
|
|
1734
1784
|
};
|
|
1785
|
+
const requestCredentialsWithDigitalCredentialsApi = async options => {
|
|
1786
|
+
const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, request: request} = options;
|
|
1787
|
+
const credentialResponseResult = await getCredentials(request);
|
|
1788
|
+
if (credentialResponseResult.isErr()) {
|
|
1789
|
+
await abortSession({
|
|
1790
|
+
apiBaseUrl: apiBaseUrl,
|
|
1791
|
+
sessionId: sessionId,
|
|
1792
|
+
sessionKey: sessionKey
|
|
1793
|
+
});
|
|
1794
|
+
return err(credentialResponseResult.error);
|
|
1795
|
+
}
|
|
1796
|
+
const credentialResponse = credentialResponseResult.value;
|
|
1797
|
+
const parsedCredentialResponseResult = parseCredentialResponse(credentialResponse);
|
|
1798
|
+
if (parsedCredentialResponseResult.isErr()) {
|
|
1799
|
+
await abortSession({
|
|
1800
|
+
apiBaseUrl: apiBaseUrl,
|
|
1801
|
+
sessionId: sessionId,
|
|
1802
|
+
sessionKey: sessionKey
|
|
1803
|
+
});
|
|
1804
|
+
return err(parsedCredentialResponseResult.error);
|
|
1805
|
+
}
|
|
1806
|
+
const parsedCredentialResponse = parsedCredentialResponseResult.value;
|
|
1807
|
+
const credentialVerificationResult = await verifyCredentialResponse({
|
|
1808
|
+
apiBaseUrl: apiBaseUrl,
|
|
1809
|
+
sessionId: sessionId,
|
|
1810
|
+
sessionKey: sessionKey,
|
|
1811
|
+
challenge: challenge,
|
|
1812
|
+
protocol: parsedCredentialResponse.protocol,
|
|
1813
|
+
data: parsedCredentialResponse.data
|
|
1814
|
+
});
|
|
1815
|
+
if (credentialVerificationResult.isErr()) {
|
|
1816
|
+
return err({
|
|
1817
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1818
|
+
message: RequestCredentialsErrorMessage.FailedToVerifyCredentialResponse,
|
|
1819
|
+
cause: credentialVerificationResult.error
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
return ok(credentialVerificationResult.value);
|
|
1823
|
+
};
|
|
1824
|
+
const getCredentials = async request => {
|
|
1825
|
+
try {
|
|
1826
|
+
const credentialResponse = await navigator.credentials.get(request);
|
|
1827
|
+
return ok(credentialResponse);
|
|
1828
|
+
} catch (exception) {
|
|
1829
|
+
return err({
|
|
1830
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1831
|
+
message: RequestCredentialsErrorMessage.DcApiError,
|
|
1832
|
+
cause: exception
|
|
1833
|
+
});
|
|
1834
|
+
}
|
|
1835
|
+
};
|
|
1836
|
+
const parseCredentialResponse = credentialResponse => {
|
|
1837
|
+
if (!credentialResponse) {
|
|
1838
|
+
return err({
|
|
1839
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1840
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
1841
|
+
details: {
|
|
1842
|
+
response: credentialResponse
|
|
1843
|
+
}
|
|
1844
|
+
});
|
|
1845
|
+
}
|
|
1846
|
+
if (typeof credentialResponse === "object") {
|
|
1847
|
+
return ok(credentialResponse);
|
|
1848
|
+
}
|
|
1849
|
+
if (typeof credentialResponse === "string") {
|
|
1850
|
+
try {
|
|
1851
|
+
const parsed = JSON.parse(credentialResponse);
|
|
1852
|
+
return ok(parsed);
|
|
1853
|
+
} catch (_a) {
|
|
1854
|
+
return err({
|
|
1855
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1856
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
1857
|
+
details: {
|
|
1858
|
+
response: credentialResponse
|
|
1859
|
+
}
|
|
1860
|
+
});
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
return err({
|
|
1864
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1865
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
1866
|
+
details: {
|
|
1867
|
+
response: credentialResponse
|
|
1868
|
+
}
|
|
1869
|
+
});
|
|
1870
|
+
};
|
|
1871
|
+
const verifyCredentialResponse = async options => {
|
|
1872
|
+
const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, protocol: protocol, data: data} = options;
|
|
1873
|
+
const requestBody = {
|
|
1874
|
+
protocol: protocol,
|
|
1875
|
+
data: data,
|
|
1876
|
+
challenge: challenge
|
|
1877
|
+
};
|
|
1878
|
+
const credentialVerificationResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/dc-api/response`, {
|
|
1879
|
+
method: "POST",
|
|
1880
|
+
headers: {
|
|
1881
|
+
"Content-Type": "application/json",
|
|
1882
|
+
Authorization: `Bearer ${sessionKey}`
|
|
1883
|
+
},
|
|
1884
|
+
body: JSON.stringify(requestBody)
|
|
1885
|
+
});
|
|
1886
|
+
if (credentialVerificationResult.isErr()) {
|
|
1887
|
+
return err(credentialVerificationResult.error);
|
|
1888
|
+
}
|
|
1889
|
+
const credentialVerificationResponse = await credentialVerificationResult.value.json();
|
|
1890
|
+
if (!isType(PresentationResultRelaxValidator)(credentialVerificationResponse)) {
|
|
1891
|
+
return err({
|
|
1892
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1893
|
+
message: "Verify credential returned unsupported response",
|
|
1894
|
+
details: {
|
|
1895
|
+
response: credentialVerificationResponse
|
|
1896
|
+
}
|
|
1897
|
+
});
|
|
1898
|
+
}
|
|
1899
|
+
return ok(credentialVerificationResponse);
|
|
1900
|
+
};
|
|
1901
|
+
const isDigitalCredentialsApiSupported = () => {
|
|
1902
|
+
var _a;
|
|
1903
|
+
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";
|
|
1904
|
+
};
|
|
1735
1905
|
const sleep = ms => new Promise((resolve => setTimeout(resolve, ms)));
|
|
1736
1906
|
const SESSION_STATUS_POLLING_MAX_RETRY = 1e3;
|
|
1737
1907
|
const SESSION_STATUS_POLLING_INTERVAL_MS = 3e3;
|
|
@@ -1742,24 +1912,7 @@
|
|
|
1742
1912
|
SameDeviceRequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
|
|
1743
1913
|
})(SameDeviceRequestCredentialsErrorMessage || (SameDeviceRequestCredentialsErrorMessage = {}));
|
|
1744
1914
|
const requestCredentialsSameDevice = async options => {
|
|
1745
|
-
const {challenge: challenge,
|
|
1746
|
-
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
|
|
1747
|
-
const createSessionResult = await createSession({
|
|
1748
|
-
credentialQuery: credentialQuery,
|
|
1749
|
-
challenge: challenge,
|
|
1750
|
-
redirectUri: redirectUri,
|
|
1751
|
-
apiBaseUrl: apiBaseUrl,
|
|
1752
|
-
applicationId: applicationId,
|
|
1753
|
-
walletProviderId: walletProviderId
|
|
1754
|
-
});
|
|
1755
|
-
if (createSessionResult.isErr()) {
|
|
1756
|
-
return err({
|
|
1757
|
-
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1758
|
-
message: SameDeviceRequestCredentialsErrorMessage.FailedToCreateSession,
|
|
1759
|
-
cause: createSessionResult.error
|
|
1760
|
-
});
|
|
1761
|
-
}
|
|
1762
|
-
const {sessionUrl: sessionUrl, sessionKey: sessionKey, sessionId: sessionId} = createSessionResult.value;
|
|
1915
|
+
const {challenge: challenge, apiBaseUrl: apiBaseUrl, applicationId: applicationId, sessionUrl: sessionUrl, sessionKey: sessionKey, sessionId: sessionId} = options;
|
|
1763
1916
|
const abortController = setActiveSession({
|
|
1764
1917
|
sessionId: sessionId,
|
|
1765
1918
|
sessionKey: sessionKey
|
|
@@ -1814,20 +1967,77 @@
|
|
|
1814
1967
|
throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
|
|
1815
1968
|
}
|
|
1816
1969
|
assertType(RequestCredentialsOptionsValidator, "Invalid request credential options")(options);
|
|
1817
|
-
const {
|
|
1818
|
-
const
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1970
|
+
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
|
|
1971
|
+
const {challenge: challenge = generateChallenge(), credentialQuery: credentialQuery, openid4vpConfiguration: openid4vpConfiguration} = options;
|
|
1972
|
+
const dcApiSupported = isDigitalCredentialsApiSupported();
|
|
1973
|
+
const openId4VpRedirectUri = deriveOpenId4vpRedirectUri(openid4vpConfiguration);
|
|
1974
|
+
const createSessionResult = await createSession({
|
|
1975
|
+
credentialQuery: credentialQuery,
|
|
1976
|
+
challenge: challenge,
|
|
1977
|
+
redirectUri: openId4VpRedirectUri,
|
|
1978
|
+
walletProviderId: (_a = openid4vpConfiguration === null || openid4vpConfiguration === void 0 ? void 0 : openid4vpConfiguration.walletProviderId) !== null && _a !== void 0 ? _a : undefined,
|
|
1979
|
+
apiBaseUrl: apiBaseUrl,
|
|
1980
|
+
applicationId: applicationId,
|
|
1981
|
+
dcApiSupported: dcApiSupported
|
|
1982
|
+
});
|
|
1983
|
+
if (createSessionResult.isErr()) {
|
|
1984
|
+
return err({
|
|
1985
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1986
|
+
message: RequestCredentialsErrorMessage.FailedToCreateSession,
|
|
1987
|
+
cause: createSessionResult.error
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
const session = createSessionResult.value;
|
|
1991
|
+
const {sessionKey: sessionKey, sessionId: sessionId} = session;
|
|
1992
|
+
if (session.type === SessionType.DigitalCredentialsApi) {
|
|
1993
|
+
const {request: request} = session;
|
|
1994
|
+
return await requestCredentialsWithDigitalCredentialsApi({
|
|
1995
|
+
apiBaseUrl: apiBaseUrl,
|
|
1996
|
+
request: request,
|
|
1997
|
+
sessionId: sessionId,
|
|
1998
|
+
sessionKey: sessionKey,
|
|
1999
|
+
challenge: challenge
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
2002
|
+
if (!openid4vpConfiguration) {
|
|
2003
|
+
return err({
|
|
2004
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2005
|
+
message: RequestCredentialsErrorMessage.MissingOpenId4vpConfig
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
const {sessionUrl: sessionUrl} = session;
|
|
2009
|
+
if (openId4VpRedirectUri) {
|
|
2010
|
+
return await requestCredentialsSameDevice({
|
|
1822
2011
|
challenge: challenge,
|
|
1823
|
-
|
|
1824
|
-
|
|
2012
|
+
apiBaseUrl: apiBaseUrl,
|
|
2013
|
+
applicationId: applicationId,
|
|
2014
|
+
sessionUrl: sessionUrl,
|
|
2015
|
+
sessionKey: sessionKey,
|
|
2016
|
+
sessionId: sessionId
|
|
2017
|
+
});
|
|
1825
2018
|
}
|
|
1826
|
-
return await
|
|
1827
|
-
initialiseOptions: initialiseOptions,
|
|
2019
|
+
return await requestCredentialsWithCrossDevice({
|
|
1828
2020
|
challenge: challenge,
|
|
1829
|
-
|
|
1830
|
-
|
|
2021
|
+
apiBaseUrl: apiBaseUrl,
|
|
2022
|
+
sessionUrl: sessionUrl,
|
|
2023
|
+
sessionKey: sessionKey,
|
|
2024
|
+
sessionId: sessionId
|
|
2025
|
+
});
|
|
2026
|
+
};
|
|
2027
|
+
const deriveOpenId4vpRedirectUri = openid4vpConfiguration => {
|
|
2028
|
+
if (!openid4vpConfiguration) {
|
|
2029
|
+
return undefined;
|
|
2030
|
+
}
|
|
2031
|
+
let detectedMode;
|
|
2032
|
+
if (openid4vpConfiguration && openid4vpConfiguration.mode) {
|
|
2033
|
+
detectedMode = openid4vpConfiguration.mode;
|
|
2034
|
+
} else {
|
|
2035
|
+
detectedMode = isMobileDetect(navigator.userAgent) ? exports.Mode.SameDevice : exports.Mode.CrossDevice;
|
|
2036
|
+
}
|
|
2037
|
+
if (detectedMode === exports.Mode.SameDevice && !isType(OpenId4vpConfigCrossDeviceOptionsValidator)(openid4vpConfiguration) && openid4vpConfiguration.redirectUri) {
|
|
2038
|
+
return openid4vpConfiguration.redirectUri;
|
|
2039
|
+
}
|
|
2040
|
+
return undefined;
|
|
1831
2041
|
};
|
|
1832
2042
|
exports.HandleRedirectCallbackErrorType = void 0;
|
|
1833
2043
|
(function(HandleRedirectCallbackErrorType) {
|
|
@@ -1884,7 +2094,7 @@
|
|
|
1884
2094
|
if (!initialiseOptions) {
|
|
1885
2095
|
throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
|
|
1886
2096
|
}
|
|
1887
|
-
const {apiBaseUrl: apiBaseUrl
|
|
2097
|
+
const {apiBaseUrl: apiBaseUrl} = initialiseOptions;
|
|
1888
2098
|
const session = getActiveSession();
|
|
1889
2099
|
if (!session || !session.sessionKey) {
|
|
1890
2100
|
return ok(undefined);
|
|
@@ -1893,7 +2103,6 @@
|
|
|
1893
2103
|
removeActiveSession();
|
|
1894
2104
|
const abortSessionResult = await abortSession({
|
|
1895
2105
|
apiBaseUrl: apiBaseUrl,
|
|
1896
|
-
applicationId: applicationId,
|
|
1897
2106
|
sessionId: sessionId,
|
|
1898
2107
|
sessionKey: sessionKey
|
|
1899
2108
|
});
|
|
@@ -1914,6 +2123,7 @@
|
|
|
1914
2123
|
exports.abortCredentialRequest = abortCredentialRequest;
|
|
1915
2124
|
exports.handleRedirectCallback = handleRedirectCallback;
|
|
1916
2125
|
exports.initialise = initialise;
|
|
2126
|
+
exports.isDigitalCredentialsApiSupported = isDigitalCredentialsApiSupported;
|
|
1917
2127
|
exports.requestCredentials = requestCredentials;
|
|
1918
2128
|
exports.utils = utils;
|
|
1919
2129
|
Object.defineProperty(exports, "__esModule", {
|