@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
|
*/
|
|
@@ -174,22 +174,49 @@ const PresentationResultRelaxValidator = v__namespace.object({
|
|
|
174
174
|
error: v__namespace.optional(v__namespace.unknown())
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
+
exports.Mode = void 0;
|
|
178
|
+
|
|
179
|
+
(function(Mode) {
|
|
180
|
+
Mode["SameDevice"] = "sameDevice";
|
|
181
|
+
Mode["CrossDevice"] = "crossDevice";
|
|
182
|
+
})(exports.Mode || (exports.Mode = {}));
|
|
183
|
+
|
|
184
|
+
var SessionType;
|
|
185
|
+
|
|
186
|
+
(function(SessionType) {
|
|
187
|
+
SessionType["DigitalCredentialsApi"] = "digital-credentials-api";
|
|
188
|
+
SessionType["Openid4vp"] = "openid4vp";
|
|
189
|
+
})(SessionType || (SessionType = {}));
|
|
190
|
+
|
|
177
191
|
v__namespace.object({
|
|
178
192
|
credentialQuery: v__namespace.array(CredentialQueryValidator),
|
|
179
193
|
challenge: v__namespace.string(),
|
|
180
194
|
redirectUri: v__namespace.optional(v__namespace.string()),
|
|
181
|
-
walletProviderId: v__namespace.optional(v__namespace.string())
|
|
195
|
+
walletProviderId: v__namespace.optional(v__namespace.string()),
|
|
196
|
+
dcApiSupported: v__namespace.optional(v__namespace.boolean())
|
|
182
197
|
});
|
|
183
198
|
|
|
184
|
-
const
|
|
199
|
+
const CreateSessionDigitalCredentialsValidator = v__namespace.object({
|
|
200
|
+
type: v__namespace.literal(SessionType.DigitalCredentialsApi),
|
|
201
|
+
sessionId: v__namespace.string(),
|
|
202
|
+
sessionKey: v__namespace.string(),
|
|
203
|
+
sessionTtl: v__namespace.number(),
|
|
204
|
+
request: v__namespace.record(v__namespace.string(), v__namespace.any())
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const CreateSessionOpenId4vpResponseValidator = v__namespace.object({
|
|
208
|
+
type: v__namespace.optional(v__namespace.literal(SessionType.Openid4vp)),
|
|
185
209
|
sessionId: v__namespace.string(),
|
|
186
210
|
sessionKey: v__namespace.string(),
|
|
187
211
|
sessionUrl: v__namespace.string()
|
|
188
212
|
});
|
|
189
213
|
|
|
214
|
+
const CreateSessionResponseValidator = v__namespace.union([ CreateSessionDigitalCredentialsValidator, CreateSessionOpenId4vpResponseValidator ]);
|
|
215
|
+
|
|
190
216
|
v__namespace.object({
|
|
191
217
|
sessionId: v__namespace.string(),
|
|
192
|
-
sessionKey: v__namespace.string()
|
|
218
|
+
sessionKey: v__namespace.string(),
|
|
219
|
+
apiBaseUrl: v__namespace.string()
|
|
193
220
|
});
|
|
194
221
|
|
|
195
222
|
v__namespace.object({
|
|
@@ -215,13 +242,6 @@ const MATTR_SDK_VERSION_HEADER = "x-mattr-sdk-version";
|
|
|
215
242
|
|
|
216
243
|
const MATTR_SDK_VERSION_VALUE = "2.0.0";
|
|
217
244
|
|
|
218
|
-
exports.Mode = void 0;
|
|
219
|
-
|
|
220
|
-
(function(Mode) {
|
|
221
|
-
Mode["sameDevice"] = "sameDevice";
|
|
222
|
-
Mode["crossDevice"] = "crossDevice";
|
|
223
|
-
})(exports.Mode || (exports.Mode = {}));
|
|
224
|
-
|
|
225
245
|
var MessageEventDataType;
|
|
226
246
|
|
|
227
247
|
(function(MessageEventDataType) {
|
|
@@ -230,30 +250,28 @@ var MessageEventDataType;
|
|
|
230
250
|
MessageEventDataType["PresentationAbort"] = "PresentationAbort";
|
|
231
251
|
})(MessageEventDataType || (MessageEventDataType = {}));
|
|
232
252
|
|
|
233
|
-
const
|
|
234
|
-
credentialQuery: v__namespace.pipe(v__namespace.array(CredentialQueryValidator), v__namespace.nonEmpty()),
|
|
235
|
-
redirectUri: v__namespace.string(),
|
|
236
|
-
challenge: v__namespace.optional(v__namespace.string()),
|
|
253
|
+
const OpenId4vpConfigSameDeviceOptionsValidator = v__namespace.object({
|
|
237
254
|
walletProviderId: v__namespace.optional(v__namespace.string()),
|
|
238
|
-
mode: v__namespace.
|
|
255
|
+
mode: v__namespace.literal(exports.Mode.SameDevice),
|
|
256
|
+
redirectUri: v__namespace.string()
|
|
239
257
|
});
|
|
240
258
|
|
|
241
|
-
const
|
|
242
|
-
credentialQuery: v__namespace.pipe(v__namespace.array(CredentialQueryValidator), v__namespace.nonEmpty()),
|
|
243
|
-
challenge: v__namespace.optional(v__namespace.string()),
|
|
259
|
+
const OpenId4vpConfigCrossDeviceOptionsValidator = v__namespace.object({
|
|
244
260
|
walletProviderId: v__namespace.optional(v__namespace.string()),
|
|
245
|
-
mode: v__namespace.
|
|
261
|
+
mode: v__namespace.literal(exports.Mode.CrossDevice)
|
|
246
262
|
});
|
|
247
263
|
|
|
248
|
-
const
|
|
249
|
-
credentialQuery: v__namespace.pipe(v__namespace.array(CredentialQueryValidator), v__namespace.nonEmpty()),
|
|
250
|
-
redirectUri: v__namespace.string(),
|
|
251
|
-
challenge: v__namespace.optional(v__namespace.string()),
|
|
264
|
+
const OpenId4vpConfigAutoDetectOptionsValidator = v__namespace.object({
|
|
252
265
|
walletProviderId: v__namespace.optional(v__namespace.string()),
|
|
253
|
-
|
|
266
|
+
redirectUri: v__namespace.string(),
|
|
267
|
+
mode: v__namespace.optional(v__namespace.picklist([ exports.Mode.CrossDevice, exports.Mode.SameDevice ]))
|
|
254
268
|
});
|
|
255
269
|
|
|
256
|
-
const RequestCredentialsOptionsValidator = v__namespace.
|
|
270
|
+
const RequestCredentialsOptionsValidator = v__namespace.object({
|
|
271
|
+
credentialQuery: v__namespace.pipe(v__namespace.array(CredentialQueryValidator), v__namespace.nonEmpty()),
|
|
272
|
+
challenge: v__namespace.optional(v__namespace.string()),
|
|
273
|
+
openid4vpConfiguration: v__namespace.optional(v__namespace.union([ OpenId4vpConfigSameDeviceOptionsValidator, OpenId4vpConfigCrossDeviceOptionsValidator, OpenId4vpConfigAutoDetectOptionsValidator ]))
|
|
274
|
+
});
|
|
257
275
|
|
|
258
276
|
exports.RequestCredentialsErrorType = void 0;
|
|
259
277
|
|
|
@@ -269,6 +287,10 @@ var RequestCredentialsErrorMessage;
|
|
|
269
287
|
RequestCredentialsErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
|
|
270
288
|
RequestCredentialsErrorMessage["FailedToGetSessionStatus"] = "Failed to get session status";
|
|
271
289
|
RequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
|
|
290
|
+
RequestCredentialsErrorMessage["FailedToVerifyCredentialResponse"] = "Failed to verify credential response";
|
|
291
|
+
RequestCredentialsErrorMessage["MissingOpenId4vpConfig"] = "Identified openid4vp session, but missing openId4vpConfiguration on `requestCredentials`";
|
|
292
|
+
RequestCredentialsErrorMessage["DcApiError"] = "Failed to request credentials with Digital Credentials API";
|
|
293
|
+
RequestCredentialsErrorMessage["DcApiResponseParseError"] = "Failed to parse response from Digital Credentials API";
|
|
272
294
|
RequestCredentialsErrorMessage["Abort"] = "User aborted the session";
|
|
273
295
|
RequestCredentialsErrorMessage["Timeout"] = "User session timeout";
|
|
274
296
|
})(RequestCredentialsErrorMessage || (RequestCredentialsErrorMessage = {}));
|
|
@@ -290,11 +312,11 @@ const InitialiseOptionsValidator = v__namespace.object({
|
|
|
290
312
|
applicationId: v__namespace.pipe(v__namespace.string(), v__namespace.nonEmpty("Must not be empty"))
|
|
291
313
|
});
|
|
292
314
|
|
|
293
|
-
var
|
|
315
|
+
var SafeFetchCommonResponseErrorType;
|
|
294
316
|
|
|
295
|
-
(function(
|
|
296
|
-
|
|
297
|
-
})(
|
|
317
|
+
(function(SafeFetchCommonResponseErrorType) {
|
|
318
|
+
SafeFetchCommonResponseErrorType["UnexpectedResponse"] = "UnexpectedResponse";
|
|
319
|
+
})(SafeFetchCommonResponseErrorType || (SafeFetchCommonResponseErrorType = {}));
|
|
298
320
|
|
|
299
321
|
var SafeFetchErrorType;
|
|
300
322
|
|
|
@@ -427,16 +449,15 @@ const getHashParamValue = (hash, param) => {
|
|
|
427
449
|
return urlParams.get(param);
|
|
428
450
|
};
|
|
429
451
|
|
|
430
|
-
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl,
|
|
431
|
-
const postData =
|
|
452
|
+
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl, walletProviderId: walletProviderId, dcApiSupported: dcApiSupported, applicationId: applicationId}) => {
|
|
453
|
+
const postData = {
|
|
432
454
|
credentialQuery: credentialQuery,
|
|
433
455
|
challenge: challenge,
|
|
434
|
-
applicationId: applicationId
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
} : {});
|
|
456
|
+
applicationId: applicationId,
|
|
457
|
+
redirectUri: redirectUri,
|
|
458
|
+
walletProviderId: walletProviderId,
|
|
459
|
+
dcApiSupported: dcApiSupported
|
|
460
|
+
};
|
|
440
461
|
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions`, {
|
|
441
462
|
method: "POST",
|
|
442
463
|
headers: {
|
|
@@ -450,8 +471,8 @@ const createSession = async ({credentialQuery: credentialQuery, challenge: chall
|
|
|
450
471
|
const data = await responseResult.value.json();
|
|
451
472
|
if (!isType(CreateSessionResponseValidator)(data)) {
|
|
452
473
|
return neverthrow.err({
|
|
453
|
-
type:
|
|
454
|
-
message: "Create session
|
|
474
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
475
|
+
message: "Create session returned unsupported response"
|
|
455
476
|
});
|
|
456
477
|
}
|
|
457
478
|
return neverthrow.ok(data);
|
|
@@ -484,7 +505,7 @@ const getSessionStatus = async ({apiBaseUrl: apiBaseUrl, sessionId: sessionId, s
|
|
|
484
505
|
const data = await responseResult.value.json();
|
|
485
506
|
if (!isType(GetSessionStatusResponseValidator)(data)) {
|
|
486
507
|
return neverthrow.err({
|
|
487
|
-
type:
|
|
508
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
488
509
|
message: "Get session status return unsupported response"
|
|
489
510
|
});
|
|
490
511
|
}
|
|
@@ -513,7 +534,7 @@ const exchangeSessionResult = async ({challenge: challenge, responseCode: respon
|
|
|
513
534
|
const data = await responseResult.value.json();
|
|
514
535
|
if (!isType(PresentationResultRelaxValidator)(data)) {
|
|
515
536
|
return neverthrow.err({
|
|
516
|
-
type:
|
|
537
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
517
538
|
message: "Exchange session result return unsupported response",
|
|
518
539
|
details: {
|
|
519
540
|
data: data
|
|
@@ -624,24 +645,8 @@ const openCrossDeviceModal = options => {
|
|
|
624
645
|
return modalContainer;
|
|
625
646
|
};
|
|
626
647
|
|
|
627
|
-
const
|
|
628
|
-
const {challenge: challenge,
|
|
629
|
-
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
|
|
630
|
-
const createSessionResult = await createSession({
|
|
631
|
-
credentialQuery: credentialQuery,
|
|
632
|
-
challenge: challenge,
|
|
633
|
-
apiBaseUrl: apiBaseUrl,
|
|
634
|
-
applicationId: applicationId,
|
|
635
|
-
walletProviderId: walletProviderId
|
|
636
|
-
});
|
|
637
|
-
if (createSessionResult.isErr()) {
|
|
638
|
-
return neverthrow.err({
|
|
639
|
-
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
640
|
-
message: RequestCredentialsErrorMessage.FailedToCreateSession,
|
|
641
|
-
cause: createSessionResult.error
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
const {sessionUrl: sessionUrl, sessionId: sessionId, sessionKey: sessionKey} = createSessionResult.value;
|
|
648
|
+
const requestCredentialsWithCrossDevice = async options => {
|
|
649
|
+
const {challenge: challenge, apiBaseUrl: apiBaseUrl, sessionUrl: sessionUrl, sessionId: sessionId, sessionKey: sessionKey} = options;
|
|
645
650
|
const container = openCrossDeviceModal({
|
|
646
651
|
sessionUrl: sessionUrl
|
|
647
652
|
});
|
|
@@ -672,6 +677,131 @@ const requestCredentialsCrossDevice = async options => {
|
|
|
672
677
|
}));
|
|
673
678
|
};
|
|
674
679
|
|
|
680
|
+
const requestCredentialsWithDigitalCredentialsApi = async options => {
|
|
681
|
+
const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, request: request} = options;
|
|
682
|
+
const credentialResponseResult = await getCredentials(request);
|
|
683
|
+
if (credentialResponseResult.isErr()) {
|
|
684
|
+
await abortSession({
|
|
685
|
+
apiBaseUrl: apiBaseUrl,
|
|
686
|
+
sessionId: sessionId,
|
|
687
|
+
sessionKey: sessionKey
|
|
688
|
+
});
|
|
689
|
+
return neverthrow.err(credentialResponseResult.error);
|
|
690
|
+
}
|
|
691
|
+
const credentialResponse = credentialResponseResult.value;
|
|
692
|
+
const parsedCredentialResponseResult = parseCredentialResponse(credentialResponse);
|
|
693
|
+
if (parsedCredentialResponseResult.isErr()) {
|
|
694
|
+
await abortSession({
|
|
695
|
+
apiBaseUrl: apiBaseUrl,
|
|
696
|
+
sessionId: sessionId,
|
|
697
|
+
sessionKey: sessionKey
|
|
698
|
+
});
|
|
699
|
+
return neverthrow.err(parsedCredentialResponseResult.error);
|
|
700
|
+
}
|
|
701
|
+
const parsedCredentialResponse = parsedCredentialResponseResult.value;
|
|
702
|
+
const credentialVerificationResult = await verifyCredentialResponse({
|
|
703
|
+
apiBaseUrl: apiBaseUrl,
|
|
704
|
+
sessionId: sessionId,
|
|
705
|
+
sessionKey: sessionKey,
|
|
706
|
+
challenge: challenge,
|
|
707
|
+
protocol: parsedCredentialResponse.protocol,
|
|
708
|
+
data: parsedCredentialResponse.data
|
|
709
|
+
});
|
|
710
|
+
if (credentialVerificationResult.isErr()) {
|
|
711
|
+
return neverthrow.err({
|
|
712
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
713
|
+
message: RequestCredentialsErrorMessage.FailedToVerifyCredentialResponse,
|
|
714
|
+
cause: credentialVerificationResult.error
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
return neverthrow.ok(credentialVerificationResult.value);
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
const getCredentials = async request => {
|
|
721
|
+
try {
|
|
722
|
+
const credentialResponse = await navigator.credentials.get(request);
|
|
723
|
+
return neverthrow.ok(credentialResponse);
|
|
724
|
+
} catch (exception) {
|
|
725
|
+
return neverthrow.err({
|
|
726
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
727
|
+
message: RequestCredentialsErrorMessage.DcApiError,
|
|
728
|
+
cause: exception
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
const parseCredentialResponse = credentialResponse => {
|
|
734
|
+
if (!credentialResponse) {
|
|
735
|
+
return neverthrow.err({
|
|
736
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
737
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
738
|
+
details: {
|
|
739
|
+
response: credentialResponse
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
if (typeof credentialResponse === "object") {
|
|
744
|
+
return neverthrow.ok(credentialResponse);
|
|
745
|
+
}
|
|
746
|
+
if (typeof credentialResponse === "string") {
|
|
747
|
+
try {
|
|
748
|
+
const parsed = JSON.parse(credentialResponse);
|
|
749
|
+
return neverthrow.ok(parsed);
|
|
750
|
+
} catch (_a) {
|
|
751
|
+
return neverthrow.err({
|
|
752
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
753
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
754
|
+
details: {
|
|
755
|
+
response: credentialResponse
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return neverthrow.err({
|
|
761
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
762
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
763
|
+
details: {
|
|
764
|
+
response: credentialResponse
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
const verifyCredentialResponse = async options => {
|
|
770
|
+
const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, protocol: protocol, data: data} = options;
|
|
771
|
+
const requestBody = {
|
|
772
|
+
protocol: protocol,
|
|
773
|
+
data: data,
|
|
774
|
+
challenge: challenge
|
|
775
|
+
};
|
|
776
|
+
const credentialVerificationResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/dc-api/response`, {
|
|
777
|
+
method: "POST",
|
|
778
|
+
headers: {
|
|
779
|
+
"Content-Type": "application/json",
|
|
780
|
+
Authorization: `Bearer ${sessionKey}`
|
|
781
|
+
},
|
|
782
|
+
body: JSON.stringify(requestBody)
|
|
783
|
+
});
|
|
784
|
+
if (credentialVerificationResult.isErr()) {
|
|
785
|
+
return neverthrow.err(credentialVerificationResult.error);
|
|
786
|
+
}
|
|
787
|
+
const credentialVerificationResponse = await credentialVerificationResult.value.json();
|
|
788
|
+
if (!isType(PresentationResultRelaxValidator)(credentialVerificationResponse)) {
|
|
789
|
+
return neverthrow.err({
|
|
790
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
791
|
+
message: "Verify credential returned unsupported response",
|
|
792
|
+
details: {
|
|
793
|
+
response: credentialVerificationResponse
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
return neverthrow.ok(credentialVerificationResponse);
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
const isDigitalCredentialsApiSupported = () => {
|
|
801
|
+
var _a;
|
|
802
|
+
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";
|
|
803
|
+
};
|
|
804
|
+
|
|
675
805
|
const sleep = ms => new Promise((resolve => setTimeout(resolve, ms)));
|
|
676
806
|
|
|
677
807
|
const SESSION_STATUS_POLLING_MAX_RETRY = 1e3;
|
|
@@ -688,24 +818,7 @@ var SameDeviceRequestCredentialsErrorMessage;
|
|
|
688
818
|
})(SameDeviceRequestCredentialsErrorMessage || (SameDeviceRequestCredentialsErrorMessage = {}));
|
|
689
819
|
|
|
690
820
|
const requestCredentialsSameDevice = async options => {
|
|
691
|
-
const {challenge: challenge,
|
|
692
|
-
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
|
|
693
|
-
const createSessionResult = await createSession({
|
|
694
|
-
credentialQuery: credentialQuery,
|
|
695
|
-
challenge: challenge,
|
|
696
|
-
redirectUri: redirectUri,
|
|
697
|
-
apiBaseUrl: apiBaseUrl,
|
|
698
|
-
applicationId: applicationId,
|
|
699
|
-
walletProviderId: walletProviderId
|
|
700
|
-
});
|
|
701
|
-
if (createSessionResult.isErr()) {
|
|
702
|
-
return neverthrow.err({
|
|
703
|
-
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
704
|
-
message: SameDeviceRequestCredentialsErrorMessage.FailedToCreateSession,
|
|
705
|
-
cause: createSessionResult.error
|
|
706
|
-
});
|
|
707
|
-
}
|
|
708
|
-
const {sessionUrl: sessionUrl, sessionKey: sessionKey, sessionId: sessionId} = createSessionResult.value;
|
|
821
|
+
const {challenge: challenge, apiBaseUrl: apiBaseUrl, applicationId: applicationId, sessionUrl: sessionUrl, sessionKey: sessionKey, sessionId: sessionId} = options;
|
|
709
822
|
const abortController = setActiveSession({
|
|
710
823
|
sessionId: sessionId,
|
|
711
824
|
sessionKey: sessionKey
|
|
@@ -761,20 +874,78 @@ const requestCredentials = async options => {
|
|
|
761
874
|
throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
|
|
762
875
|
}
|
|
763
876
|
assertType(RequestCredentialsOptionsValidator, "Invalid request credential options")(options);
|
|
764
|
-
const {
|
|
765
|
-
const
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
877
|
+
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
|
|
878
|
+
const {challenge: challenge = generateChallenge(), credentialQuery: credentialQuery, openid4vpConfiguration: openid4vpConfiguration} = options;
|
|
879
|
+
const dcApiSupported = isDigitalCredentialsApiSupported();
|
|
880
|
+
const openId4VpRedirectUri = deriveOpenId4vpRedirectUri(openid4vpConfiguration);
|
|
881
|
+
const createSessionResult = await createSession({
|
|
882
|
+
credentialQuery: credentialQuery,
|
|
883
|
+
challenge: challenge,
|
|
884
|
+
redirectUri: openId4VpRedirectUri,
|
|
885
|
+
walletProviderId: (_a = openid4vpConfiguration === null || openid4vpConfiguration === void 0 ? void 0 : openid4vpConfiguration.walletProviderId) !== null && _a !== void 0 ? _a : undefined,
|
|
886
|
+
apiBaseUrl: apiBaseUrl,
|
|
887
|
+
applicationId: applicationId,
|
|
888
|
+
dcApiSupported: dcApiSupported
|
|
889
|
+
});
|
|
890
|
+
if (createSessionResult.isErr()) {
|
|
891
|
+
return neverthrow.err({
|
|
892
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
893
|
+
message: RequestCredentialsErrorMessage.FailedToCreateSession,
|
|
894
|
+
cause: createSessionResult.error
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
const session = createSessionResult.value;
|
|
898
|
+
const {sessionKey: sessionKey, sessionId: sessionId} = session;
|
|
899
|
+
if (session.type === SessionType.DigitalCredentialsApi) {
|
|
900
|
+
const {request: request} = session;
|
|
901
|
+
return await requestCredentialsWithDigitalCredentialsApi({
|
|
902
|
+
apiBaseUrl: apiBaseUrl,
|
|
903
|
+
request: request,
|
|
904
|
+
sessionId: sessionId,
|
|
905
|
+
sessionKey: sessionKey,
|
|
906
|
+
challenge: challenge
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
if (!openid4vpConfiguration) {
|
|
910
|
+
return neverthrow.err({
|
|
911
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
912
|
+
message: RequestCredentialsErrorMessage.MissingOpenId4vpConfig
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
const {sessionUrl: sessionUrl} = session;
|
|
916
|
+
if (openId4VpRedirectUri) {
|
|
917
|
+
return await requestCredentialsSameDevice({
|
|
769
918
|
challenge: challenge,
|
|
770
|
-
|
|
771
|
-
|
|
919
|
+
apiBaseUrl: apiBaseUrl,
|
|
920
|
+
applicationId: applicationId,
|
|
921
|
+
sessionUrl: sessionUrl,
|
|
922
|
+
sessionKey: sessionKey,
|
|
923
|
+
sessionId: sessionId
|
|
924
|
+
});
|
|
772
925
|
}
|
|
773
|
-
return await
|
|
774
|
-
initialiseOptions: initialiseOptions,
|
|
926
|
+
return await requestCredentialsWithCrossDevice({
|
|
775
927
|
challenge: challenge,
|
|
776
|
-
|
|
777
|
-
|
|
928
|
+
apiBaseUrl: apiBaseUrl,
|
|
929
|
+
sessionUrl: sessionUrl,
|
|
930
|
+
sessionKey: sessionKey,
|
|
931
|
+
sessionId: sessionId
|
|
932
|
+
});
|
|
933
|
+
};
|
|
934
|
+
|
|
935
|
+
const deriveOpenId4vpRedirectUri = openid4vpConfiguration => {
|
|
936
|
+
if (!openid4vpConfiguration) {
|
|
937
|
+
return undefined;
|
|
938
|
+
}
|
|
939
|
+
let detectedMode;
|
|
940
|
+
if (openid4vpConfiguration && openid4vpConfiguration.mode) {
|
|
941
|
+
detectedMode = openid4vpConfiguration.mode;
|
|
942
|
+
} else {
|
|
943
|
+
detectedMode = isMobileDetect(navigator.userAgent) ? exports.Mode.SameDevice : exports.Mode.CrossDevice;
|
|
944
|
+
}
|
|
945
|
+
if (detectedMode === exports.Mode.SameDevice && !isType(OpenId4vpConfigCrossDeviceOptionsValidator)(openid4vpConfiguration) && openid4vpConfiguration.redirectUri) {
|
|
946
|
+
return openid4vpConfiguration.redirectUri;
|
|
947
|
+
}
|
|
948
|
+
return undefined;
|
|
778
949
|
};
|
|
779
950
|
|
|
780
951
|
exports.HandleRedirectCallbackErrorType = void 0;
|
|
@@ -837,7 +1008,7 @@ const abortCredentialRequest = async () => {
|
|
|
837
1008
|
if (!initialiseOptions) {
|
|
838
1009
|
throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
|
|
839
1010
|
}
|
|
840
|
-
const {apiBaseUrl: apiBaseUrl
|
|
1011
|
+
const {apiBaseUrl: apiBaseUrl} = initialiseOptions;
|
|
841
1012
|
const session = getActiveSession();
|
|
842
1013
|
if (!session || !session.sessionKey) {
|
|
843
1014
|
return neverthrow.ok(undefined);
|
|
@@ -846,7 +1017,6 @@ const abortCredentialRequest = async () => {
|
|
|
846
1017
|
removeActiveSession();
|
|
847
1018
|
const abortSessionResult = await abortSession({
|
|
848
1019
|
apiBaseUrl: apiBaseUrl,
|
|
849
|
-
applicationId: applicationId,
|
|
850
1020
|
sessionId: sessionId,
|
|
851
1021
|
sessionKey: sessionKey
|
|
852
1022
|
});
|
|
@@ -872,6 +1042,8 @@ exports.handleRedirectCallback = handleRedirectCallback;
|
|
|
872
1042
|
|
|
873
1043
|
exports.initialise = initialise;
|
|
874
1044
|
|
|
1045
|
+
exports.isDigitalCredentialsApiSupported = isDigitalCredentialsApiSupported;
|
|
1046
|
+
|
|
875
1047
|
exports.requestCredentials = requestCredentials;
|
|
876
1048
|
|
|
877
1049
|
exports.utils = utils;
|