@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.34.1-feature.SSISDK.26.74 → 0.34.1-feature.SSISDK.26.75
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.cjs +833 -831
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1006 -1004
- package/dist/index.js.map +1 -1
- package/package.json +19 -19
- package/src/agent/DidAuthSiopOpAuthenticator.ts +14 -24
package/dist/index.js
CHANGED
|
@@ -371,650 +371,221 @@ import { ConnectionType as ConnectionType2, CorrelationIdentifierType, Credentia
|
|
|
371
371
|
import { Loggers as Loggers4 } from "@sphereon/ssi-types";
|
|
372
372
|
import { v4 as uuidv4 } from "uuid";
|
|
373
373
|
|
|
374
|
-
// src/
|
|
375
|
-
import {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
import
|
|
379
|
-
import
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
374
|
+
// src/machine/Siopv2Machine.ts
|
|
375
|
+
import { assign, createMachine, interpret } from "xstate";
|
|
376
|
+
|
|
377
|
+
// src/localization/Localization.ts
|
|
378
|
+
import i18n from "i18n-js";
|
|
379
|
+
import memoize from "lodash.memoize";
|
|
380
|
+
|
|
381
|
+
// src/types/IDidAuthSiopOpAuthenticator.ts
|
|
382
|
+
var LOGGER_NAMESPACE = "sphereon:siopv2-oid4vp:op-auth";
|
|
383
|
+
var DEFAULT_JWT_PROOF_TYPE = "JwtProof2020";
|
|
384
|
+
|
|
385
|
+
// src/types/siop-service/index.ts
|
|
386
|
+
var Siopv2HolderEvent = /* @__PURE__ */ function(Siopv2HolderEvent2) {
|
|
387
|
+
Siopv2HolderEvent2["CONTACT_IDENTITY_CREATED"] = "contact_identity_created";
|
|
388
|
+
Siopv2HolderEvent2["IDENTIFIER_CREATED"] = "identifier_created";
|
|
389
|
+
return Siopv2HolderEvent2;
|
|
390
|
+
}({});
|
|
391
|
+
var SupportedLanguage = /* @__PURE__ */ function(SupportedLanguage2) {
|
|
392
|
+
SupportedLanguage2["ENGLISH"] = "en";
|
|
393
|
+
SupportedLanguage2["DUTCH"] = "nl";
|
|
394
|
+
return SupportedLanguage2;
|
|
395
|
+
}({});
|
|
396
|
+
|
|
397
|
+
// src/types/machine/index.ts
|
|
398
|
+
var Siopv2MachineStates = /* @__PURE__ */ function(Siopv2MachineStates2) {
|
|
399
|
+
Siopv2MachineStates2["createConfig"] = "createConfig";
|
|
400
|
+
Siopv2MachineStates2["getSiopRequest"] = "getSiopRequest";
|
|
401
|
+
Siopv2MachineStates2["getSelectableCredentials"] = "getSelectableCredentials";
|
|
402
|
+
Siopv2MachineStates2["retrieveContact"] = "retrieveContact";
|
|
403
|
+
Siopv2MachineStates2["transitionFromSetup"] = "transitionFromSetup";
|
|
404
|
+
Siopv2MachineStates2["addContact"] = "addContact";
|
|
405
|
+
Siopv2MachineStates2["addContactIdentity"] = "addContactIdentity";
|
|
406
|
+
Siopv2MachineStates2["selectCredentials"] = "selectCredentials";
|
|
407
|
+
Siopv2MachineStates2["sendResponse"] = "sendResponse";
|
|
408
|
+
Siopv2MachineStates2["handleError"] = "handleError";
|
|
409
|
+
Siopv2MachineStates2["aborted"] = "aborted";
|
|
410
|
+
Siopv2MachineStates2["declined"] = "declined";
|
|
411
|
+
Siopv2MachineStates2["error"] = "error";
|
|
412
|
+
Siopv2MachineStates2["done"] = "done";
|
|
413
|
+
return Siopv2MachineStates2;
|
|
414
|
+
}({});
|
|
415
|
+
var Siopv2MachineAddContactStates = /* @__PURE__ */ function(Siopv2MachineAddContactStates2) {
|
|
416
|
+
Siopv2MachineAddContactStates2["idle"] = "idle";
|
|
417
|
+
Siopv2MachineAddContactStates2["executing"] = "executing";
|
|
418
|
+
Siopv2MachineAddContactStates2["next"] = "next";
|
|
419
|
+
return Siopv2MachineAddContactStates2;
|
|
420
|
+
}({});
|
|
421
|
+
var Siopv2MachineEvents = /* @__PURE__ */ function(Siopv2MachineEvents2) {
|
|
422
|
+
Siopv2MachineEvents2["NEXT"] = "NEXT";
|
|
423
|
+
Siopv2MachineEvents2["PREVIOUS"] = "PREVIOUS";
|
|
424
|
+
Siopv2MachineEvents2["DECLINE"] = "DECLINE";
|
|
425
|
+
Siopv2MachineEvents2["SET_CONTACT_ALIAS"] = "SET_CONTACT_ALIAS";
|
|
426
|
+
Siopv2MachineEvents2["SET_CONTACT_CONSENT"] = "SET_CONTACT_CONSENT";
|
|
427
|
+
Siopv2MachineEvents2["CREATE_CONTACT"] = "CREATE_CONTACT";
|
|
428
|
+
Siopv2MachineEvents2["SET_SELECTED_CREDENTIALS"] = "SET_SELECTED_CREDENTIALS";
|
|
429
|
+
return Siopv2MachineEvents2;
|
|
430
|
+
}({});
|
|
431
|
+
var Siopv2MachineGuards = /* @__PURE__ */ function(Siopv2MachineGuards2) {
|
|
432
|
+
Siopv2MachineGuards2["hasNoContactGuard"] = "Siopv2HasNoContactGuard";
|
|
433
|
+
Siopv2MachineGuards2["createContactGuard"] = "Siopv2CreateContactGuard";
|
|
434
|
+
Siopv2MachineGuards2["hasContactGuard"] = "Siopv2HasContactGuard";
|
|
435
|
+
Siopv2MachineGuards2["hasAuthorizationRequestGuard"] = "Siopv2HasAuthorizationRequestGuard";
|
|
436
|
+
Siopv2MachineGuards2["hasSelectableCredentialsAndContactGuard"] = "Siopv2HasSelectableCredentialsAndContactGuard";
|
|
437
|
+
Siopv2MachineGuards2["hasSelectedRequiredCredentialsGuard"] = "Siopv2HasSelectedRequiredCredentialsGuard";
|
|
438
|
+
Siopv2MachineGuards2["siopOnlyGuard"] = "Siopv2IsSiopOnlyGuard";
|
|
439
|
+
Siopv2MachineGuards2["siopWithOID4VPGuard"] = "Siopv2IsSiopWithOID4VPGuard";
|
|
440
|
+
return Siopv2MachineGuards2;
|
|
441
|
+
}({});
|
|
442
|
+
var Siopv2MachineServices = /* @__PURE__ */ function(Siopv2MachineServices2) {
|
|
443
|
+
Siopv2MachineServices2["getSiopRequest"] = "getSiopRequest";
|
|
444
|
+
Siopv2MachineServices2["getSelectableCredentials"] = "getSelectableCredentials";
|
|
445
|
+
Siopv2MachineServices2["retrieveContact"] = "retrieveContact";
|
|
446
|
+
Siopv2MachineServices2["addContactIdentity"] = "addContactIdentity";
|
|
447
|
+
Siopv2MachineServices2["sendResponse"] = "sendResponse";
|
|
448
|
+
Siopv2MachineServices2["createConfig"] = "createConfig";
|
|
449
|
+
return Siopv2MachineServices2;
|
|
450
|
+
}({});
|
|
451
|
+
|
|
452
|
+
// src/types/identifier/index.ts
|
|
453
|
+
var DID_PREFIX = "did";
|
|
454
|
+
|
|
455
|
+
// src/localization/Localization.ts
|
|
456
|
+
var Localization = class Localization2 {
|
|
457
|
+
static {
|
|
458
|
+
__name(this, "Localization");
|
|
383
459
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
domain,
|
|
388
|
-
challenge,
|
|
389
|
-
format,
|
|
390
|
-
skipDidResolution
|
|
391
|
-
}, context);
|
|
392
|
-
}
|
|
393
|
-
__name(createOID4VPPresentationSignCallback, "createOID4VPPresentationSignCallback");
|
|
394
|
-
async function createOPBuilder({ opOptions, idOpts: idOpts1, context }) {
|
|
395
|
-
const eventEmitter = opOptions.eventEmitter ?? new EventEmitter();
|
|
396
|
-
const builder = OP.builder().withResponseMode(opOptions.responseMode ?? ResponseMode.DIRECT_POST).withSupportedVersions(opOptions.supportedVersions ?? [
|
|
397
|
-
SupportedVersion.SIOPv2_ID1,
|
|
398
|
-
SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1,
|
|
399
|
-
SupportedVersion.SIOPv2_D11,
|
|
400
|
-
SupportedVersion.SIOPv2_D12_OID4VP_D18
|
|
401
|
-
]).withExpiresIn(opOptions.expiresIn ?? 300).withEventEmitter(eventEmitter).withRegistration({
|
|
402
|
-
passBy: PassBy.VALUE
|
|
403
|
-
});
|
|
404
|
-
const wellknownDIDVerifyCallback = opOptions.wellknownDIDVerifyCallback ? opOptions.wellknownDIDVerifyCallback : async (args) => {
|
|
405
|
-
const result = await context.agent.cvVerifyCredential({
|
|
406
|
-
credential: args.credential,
|
|
407
|
-
fetchRemoteContexts: true
|
|
408
|
-
});
|
|
409
|
-
return {
|
|
410
|
-
verified: result.result
|
|
411
|
-
};
|
|
460
|
+
static translationGetters = {
|
|
461
|
+
[SupportedLanguage.ENGLISH]: () => require_en(),
|
|
462
|
+
[SupportedLanguage.DUTCH]: () => require_nl()
|
|
412
463
|
};
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
}, context));
|
|
419
|
-
if (idOpts1) {
|
|
420
|
-
if (opOptions.skipDidResolution && isManagedIdentifierDidOpts(idOpts1)) {
|
|
421
|
-
idOpts1.offlineWhenNoDIDRegistered = true;
|
|
422
|
-
}
|
|
423
|
-
const createJwtCallback = createJwtCallbackWithIdOpts(idOpts1, context);
|
|
424
|
-
builder.withCreateJwtCallback(createJwtCallback);
|
|
425
|
-
builder.withPresentationSignCallback(await createOID4VPPresentationSignCallback({
|
|
426
|
-
presentationSignCallback: opOptions.presentationSignCallback,
|
|
427
|
-
skipDidResolution: opOptions.skipDidResolution ?? false,
|
|
428
|
-
idOpts: idOpts1,
|
|
429
|
-
context
|
|
430
|
-
}));
|
|
431
|
-
} else {
|
|
432
|
-
const createJwtCallback = createJwtCallbackWithOpOpts(opOptions, context);
|
|
433
|
-
builder.withCreateJwtCallback(createJwtCallback);
|
|
434
|
-
}
|
|
435
|
-
return builder;
|
|
436
|
-
}
|
|
437
|
-
__name(createOPBuilder, "createOPBuilder");
|
|
438
|
-
function createJwtCallbackWithIdOpts(idOpts1, context) {
|
|
439
|
-
return async (jwtIssuer, jwt) => {
|
|
440
|
-
let issuer;
|
|
441
|
-
if (isManagedIdentifierDidOpts(idOpts1)) {
|
|
442
|
-
issuer = {
|
|
443
|
-
...idOpts1,
|
|
444
|
-
method: idOpts1.method,
|
|
445
|
-
noIdentifierInHeader: false
|
|
446
|
-
};
|
|
447
|
-
} else if (isManagedIdentifierX5cOpts(idOpts1)) {
|
|
448
|
-
issuer = {
|
|
449
|
-
...idOpts1,
|
|
450
|
-
method: idOpts1.method,
|
|
451
|
-
noIdentifierInHeader: false
|
|
464
|
+
static translate = memoize((key, config) => {
|
|
465
|
+
if (Object.keys(i18n.translations).length === 0) {
|
|
466
|
+
i18n.translations = {
|
|
467
|
+
[SupportedLanguage.ENGLISH]: Localization2.translationGetters[SupportedLanguage.ENGLISH]()
|
|
452
468
|
};
|
|
469
|
+
i18n.locale = SupportedLanguage.ENGLISH;
|
|
453
470
|
} else {
|
|
454
|
-
|
|
471
|
+
i18n.translations = {
|
|
472
|
+
[i18n.locale]: {
|
|
473
|
+
...i18n.translations[i18n.locale],
|
|
474
|
+
...Localization2.translationGetters[this.findSupportedLanguage(i18n.locale) || SupportedLanguage.ENGLISH]()
|
|
475
|
+
}
|
|
476
|
+
};
|
|
455
477
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
__name(createJwtCallbackWithIdOpts, "createJwtCallbackWithIdOpts");
|
|
465
|
-
function createJwtCallbackWithOpOpts(opOpts, context) {
|
|
466
|
-
return async (jwtIssuer, jwt) => {
|
|
467
|
-
let identifier;
|
|
468
|
-
if (jwtIssuer.method == "did") {
|
|
469
|
-
identifier = jwtIssuer.didUrl;
|
|
470
|
-
} else if (jwtIssuer.method == "x5c") {
|
|
471
|
-
identifier = jwtIssuer.x5c;
|
|
472
|
-
} else {
|
|
473
|
-
return Promise.reject(Error(`JWT issuer method ${jwtIssuer.method} not yet supported`));
|
|
478
|
+
return i18n.t(key, config);
|
|
479
|
+
}, (key, config) => config ? key + JSON.stringify(config) : key);
|
|
480
|
+
static findSupportedLanguage = /* @__PURE__ */ __name((locale) => {
|
|
481
|
+
for (const language of Object.values(SupportedLanguage)) {
|
|
482
|
+
if (language === locale) {
|
|
483
|
+
return language;
|
|
484
|
+
}
|
|
474
485
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
},
|
|
483
|
-
// FIXME fix JWK key_ops
|
|
484
|
-
// @ts-ignore
|
|
485
|
-
protectedHeader: jwt.header,
|
|
486
|
-
payload: jwt.payload
|
|
487
|
-
});
|
|
488
|
-
return result.jwt;
|
|
489
|
-
};
|
|
490
|
-
}
|
|
491
|
-
__name(createJwtCallbackWithOpOpts, "createJwtCallbackWithOpOpts");
|
|
492
|
-
function getVerifyJwtCallback(_opts, context) {
|
|
493
|
-
return async (_jwtVerifier, jwt) => {
|
|
494
|
-
const result = await context.agent.jwtVerifyJwsSignature({
|
|
495
|
-
jws: jwt.raw
|
|
496
|
-
});
|
|
497
|
-
console.log(result.message);
|
|
498
|
-
return !result.error;
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
__name(getVerifyJwtCallback, "getVerifyJwtCallback");
|
|
502
|
-
async function createOP({ opOptions, idOpts: idOpts1, context }) {
|
|
503
|
-
return (await createOPBuilder({
|
|
504
|
-
opOptions,
|
|
505
|
-
idOpts: idOpts1,
|
|
506
|
-
context
|
|
507
|
-
})).build();
|
|
508
|
-
}
|
|
509
|
-
__name(createOP, "createOP");
|
|
510
|
-
function getSigningAlgo(type) {
|
|
511
|
-
switch (type) {
|
|
512
|
-
case "Ed25519":
|
|
513
|
-
return SigningAlgo.EDDSA;
|
|
514
|
-
case "Secp256k1":
|
|
515
|
-
return SigningAlgo.ES256K;
|
|
516
|
-
case "Secp256r1":
|
|
517
|
-
return SigningAlgo.ES256;
|
|
518
|
-
// @ts-ignore
|
|
519
|
-
case "RSA":
|
|
520
|
-
return SigningAlgo.RS256;
|
|
521
|
-
default:
|
|
522
|
-
throw Error("Key type not yet supported");
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
__name(getSigningAlgo, "getSigningAlgo");
|
|
486
|
+
return void 0;
|
|
487
|
+
}, "findSupportedLanguage");
|
|
488
|
+
static getLocale = /* @__PURE__ */ __name(() => {
|
|
489
|
+
return i18n.locale || SupportedLanguage.ENGLISH;
|
|
490
|
+
}, "getLocale");
|
|
491
|
+
};
|
|
492
|
+
var translate = Localization.translate;
|
|
526
493
|
|
|
527
|
-
// src/
|
|
528
|
-
var OID4VP = class _OID4VP {
|
|
529
|
-
static {
|
|
530
|
-
__name(this, "OID4VP");
|
|
531
|
-
}
|
|
532
|
-
//private readonly session: OpSession
|
|
533
|
-
// private readonly allIdentifiers: string[]
|
|
534
|
-
// private readonly hasher?: HasherSync
|
|
535
|
-
constructor(args) {
|
|
536
|
-
}
|
|
537
|
-
static async init(session, allIdentifiers, hasher) {
|
|
538
|
-
return new _OID4VP({
|
|
539
|
-
session,
|
|
540
|
-
allIdentifiers: allIdentifiers ?? await session.getSupportedDIDs(),
|
|
541
|
-
hasher
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
// src/session/OpSession.ts
|
|
547
|
-
import { OP as OP2, URI } from "@sphereon/did-auth-siop";
|
|
548
|
-
import { getAgentDIDMethods, getAgentResolver } from "@sphereon/ssi-sdk-ext.did-utils";
|
|
549
|
-
import { encodeBase64url } from "@sphereon/ssi-sdk.core";
|
|
550
|
-
import { parseDid } from "@sphereon/ssi-types";
|
|
551
|
-
import { v4 } from "uuid";
|
|
494
|
+
// src/machine/Siopv2Machine.ts
|
|
552
495
|
import { Loggers } from "@sphereon/ssi-types";
|
|
553
|
-
var logger = Loggers.DEFAULT.get(
|
|
554
|
-
var
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
this.requestJwtOrUri = options.requestJwtOrUri;
|
|
571
|
-
}
|
|
572
|
-
static async init(options) {
|
|
573
|
-
return new _OpSession(options);
|
|
574
|
-
}
|
|
575
|
-
async getAuthorizationRequest() {
|
|
576
|
-
if (!this.verifiedAuthorizationRequest) {
|
|
577
|
-
const op = await createOP({
|
|
578
|
-
opOptions: this.options,
|
|
579
|
-
context: this.context
|
|
580
|
-
});
|
|
581
|
-
this.verifiedAuthorizationRequest = await op.verifyAuthorizationRequest(this.requestJwtOrUri);
|
|
582
|
-
this._nonce = await this.verifiedAuthorizationRequest.authorizationRequest.getMergedProperty("nonce");
|
|
583
|
-
this._state = await this.verifiedAuthorizationRequest.authorizationRequest.getMergedProperty("state");
|
|
584
|
-
await this.getSupportedDIDMethods();
|
|
585
|
-
}
|
|
586
|
-
return this.verifiedAuthorizationRequest;
|
|
587
|
-
}
|
|
588
|
-
async getAuthorizationRequestURI() {
|
|
589
|
-
return await URI.fromAuthorizationRequest((await this.getAuthorizationRequest()).authorizationRequest);
|
|
590
|
-
}
|
|
591
|
-
get nonce() {
|
|
592
|
-
if (!this._nonce) {
|
|
593
|
-
throw Error("No nonce available. Please get authorization request first");
|
|
594
|
-
}
|
|
595
|
-
return this._nonce;
|
|
496
|
+
var logger = Loggers.DEFAULT.get(LOGGER_NAMESPACE);
|
|
497
|
+
var Siopv2HasNoContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
498
|
+
const { contact } = _ctx;
|
|
499
|
+
return contact === void 0;
|
|
500
|
+
}, "Siopv2HasNoContactGuard");
|
|
501
|
+
var Siopv2HasContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
502
|
+
const { contact } = _ctx;
|
|
503
|
+
return contact !== void 0;
|
|
504
|
+
}, "Siopv2HasContactGuard");
|
|
505
|
+
var Siopv2HasAuthorizationRequestGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
506
|
+
const { authorizationRequestData } = _ctx;
|
|
507
|
+
return authorizationRequestData !== void 0;
|
|
508
|
+
}, "Siopv2HasAuthorizationRequestGuard");
|
|
509
|
+
var Siopv2HasSelectableCredentialsAndContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
510
|
+
const { authorizationRequestData, contact } = _ctx;
|
|
511
|
+
if (!authorizationRequestData) {
|
|
512
|
+
throw new Error("Missing authorization request data in context");
|
|
596
513
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
throw Error("No state available. Please get authorization request first");
|
|
600
|
-
}
|
|
601
|
-
return this._state;
|
|
514
|
+
if (!contact) {
|
|
515
|
+
throw new Error("Missing contact request data in context");
|
|
602
516
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
517
|
+
return authorizationRequestData.dcqlQuery !== void 0;
|
|
518
|
+
}, "Siopv2HasSelectableCredentialsAndContactGuard");
|
|
519
|
+
var Siopv2CreateContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
520
|
+
const { contactAlias, hasContactConsent } = _ctx;
|
|
521
|
+
return hasContactConsent && contactAlias !== void 0 && contactAlias.length > 0;
|
|
522
|
+
}, "Siopv2CreateContactGuard");
|
|
523
|
+
var Siopv2HasSelectedRequiredCredentialsGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
524
|
+
const { authorizationRequestData } = _ctx;
|
|
525
|
+
if (authorizationRequestData === void 0) {
|
|
526
|
+
throw new Error("Missing authorization request data in context");
|
|
608
527
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
didPrefix
|
|
612
|
-
});
|
|
613
|
-
let rpMethods = await this.getRPDIDMethodsSupported({
|
|
614
|
-
didPrefix,
|
|
615
|
-
agentMethods
|
|
616
|
-
});
|
|
617
|
-
logger.debug(`RP supports subject syntax types: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`);
|
|
618
|
-
if (rpMethods.dids.length === 0) {
|
|
619
|
-
logger.debug(`RP does not support DIDs. Supported: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`);
|
|
620
|
-
return [];
|
|
621
|
-
}
|
|
622
|
-
let intersection;
|
|
623
|
-
if (rpMethods.dids.includes("did")) {
|
|
624
|
-
intersection = agentMethods && agentMethods.length > 0 ? agentMethods : (await getAgentDIDMethods(this.context)).map((method) => convertDidMethod(method, didPrefix));
|
|
625
|
-
} else if (!agentMethods || agentMethods.length === 0) {
|
|
626
|
-
intersection = rpMethods.dids?.map((method) => convertDidMethod(method, didPrefix));
|
|
627
|
-
} else {
|
|
628
|
-
intersection = agentMethods.filter((value) => rpMethods.dids.includes(value));
|
|
629
|
-
}
|
|
630
|
-
if (intersection.length === 0) {
|
|
631
|
-
throw Error("No matching DID methods between agent and relying party");
|
|
632
|
-
}
|
|
633
|
-
return intersection.map((value) => convertDidMethod(value, didPrefix));
|
|
528
|
+
if (authorizationRequestData.dcqlQuery === void 0) {
|
|
529
|
+
throw Error("No presentation definitions present");
|
|
634
530
|
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
531
|
+
return _ctx.selectedCredentials.length > 0;
|
|
532
|
+
}, "Siopv2HasSelectedRequiredCredentialsGuard");
|
|
533
|
+
var Siopv2IsSiopOnlyGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
534
|
+
const { authorizationRequestData } = _ctx;
|
|
535
|
+
if (authorizationRequestData === void 0) {
|
|
536
|
+
throw new Error("Missing authorization request data in context");
|
|
639
537
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
538
|
+
return authorizationRequestData.dcqlQuery === void 0;
|
|
539
|
+
}, "Siopv2IsSiopOnlyGuard");
|
|
540
|
+
var Siopv2IsSiopWithOID4VPGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
541
|
+
const { authorizationRequestData, selectableCredentialsMap } = _ctx;
|
|
542
|
+
if (!authorizationRequestData) {
|
|
543
|
+
throw new Error("Missing authorization request data in context");
|
|
644
544
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
const agentMethods = (opts.agentMethods ?? this.getAgentDIDMethodsSupported(opts))?.map((method) => convertDidMethod(method, opts.didPrefix)) ?? [];
|
|
648
|
-
logger.debug(`agent methods supported: ${JSON.stringify(agentMethods)}`);
|
|
649
|
-
const authReq = await this.getAuthorizationRequest();
|
|
650
|
-
const subjectSyntaxTypesSupported = authReq.registrationMetadataPayload?.subject_syntax_types_supported?.map((method) => convertDidMethod(method, opts.didPrefix)).filter((val) => !val.startsWith("did"));
|
|
651
|
-
logger.debug(`subject syntax types supported in rp method supported: ${JSON.stringify(subjectSyntaxTypesSupported)}`);
|
|
652
|
-
const aud = await authReq.authorizationRequest.getMergedProperty("aud");
|
|
653
|
-
let rpMethods = [];
|
|
654
|
-
if (aud && aud.startsWith("did:")) {
|
|
655
|
-
const didMethod = convertDidMethod(parseDid(aud).method, opts.didPrefix);
|
|
656
|
-
logger.debug(`aud did method: ${didMethod}`);
|
|
657
|
-
if (subjectSyntaxTypesSupported && subjectSyntaxTypesSupported.length > 0 && !subjectSyntaxTypesSupported.includes("did") && !subjectSyntaxTypesSupported.includes(didMethod)) {
|
|
658
|
-
throw Error(`The aud DID method ${didMethod} is not in the supported types ${subjectSyntaxTypesSupported}`);
|
|
659
|
-
}
|
|
660
|
-
rpMethods = [
|
|
661
|
-
didMethod
|
|
662
|
-
];
|
|
663
|
-
} else if (subjectSyntaxTypesSupported) {
|
|
664
|
-
rpMethods = (Array.isArray(subjectSyntaxTypesSupported) ? subjectSyntaxTypesSupported : [
|
|
665
|
-
subjectSyntaxTypesSupported
|
|
666
|
-
]).map((method) => convertDidMethod(method, opts.didPrefix));
|
|
667
|
-
}
|
|
668
|
-
const isEBSI = rpMethods.length === 0 && (authReq.issuer?.includes(".ebsi.eu") || authReq.authorizationRequest.getMergedProperty("client_id")?.includes(".ebsi.eu"));
|
|
669
|
-
let codecName = void 0;
|
|
670
|
-
if (isEBSI && (!aud || !aud.startsWith("http"))) {
|
|
671
|
-
logger.debug(`EBSI detected, adding did:key to supported DID methods for RP`);
|
|
672
|
-
const didKeyMethod = convertDidMethod("did:key", opts.didPrefix);
|
|
673
|
-
if (!agentMethods?.includes(didKeyMethod)) {
|
|
674
|
-
throw Error(`EBSI detected, but agent did not support did:key. Please reconfigure agent`);
|
|
675
|
-
}
|
|
676
|
-
rpMethods = [
|
|
677
|
-
didKeyMethod
|
|
678
|
-
];
|
|
679
|
-
keyType = "Secp256r1";
|
|
680
|
-
codecName = "jwk_jcs-pub";
|
|
681
|
-
}
|
|
682
|
-
return {
|
|
683
|
-
dids: rpMethods,
|
|
684
|
-
codecName,
|
|
685
|
-
keyType
|
|
686
|
-
};
|
|
545
|
+
if (!selectableCredentialsMap) {
|
|
546
|
+
throw new Error("Missing selectableCredentialsMap in context");
|
|
687
547
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
const { clientMetadata, requestObjectPayload, authorizationResponsePayload: authResponse } = opts;
|
|
730
|
-
const jwk = await OP2.extractEncJwksFromClientMetadata(clientMetadata);
|
|
731
|
-
const recipientKey = await agent.identifierExternalResolveByJwk({
|
|
732
|
-
identifier: jwk
|
|
733
|
-
});
|
|
734
|
-
return await agent.jwtEncryptJweCompactJwt({
|
|
735
|
-
recipientKey,
|
|
736
|
-
protectedHeader: {},
|
|
737
|
-
alg: requestObjectPayload.client_metadata.authorization_encrypted_response_alg ?? "ECDH-ES",
|
|
738
|
-
enc: requestObjectPayload.client_metadata.authorization_encrypted_response_enc ?? "A256GCM",
|
|
739
|
-
apv: encodeBase64url(opts.requestObjectPayload.nonce),
|
|
740
|
-
apu: encodeBase64url(v4()),
|
|
741
|
-
payload: authResponse,
|
|
742
|
-
issuer: responseOpts.issuer,
|
|
743
|
-
audience: responseOpts.audience
|
|
744
|
-
}).then((result) => {
|
|
745
|
-
return {
|
|
746
|
-
response: result.jwt
|
|
747
|
-
};
|
|
748
|
-
});
|
|
749
|
-
}, "jarmResponse");
|
|
750
|
-
}
|
|
751
|
-
async sendAuthorizationResponse(args) {
|
|
752
|
-
const { responseSignerOpts, dcqlResponse, isFirstParty } = args;
|
|
753
|
-
const resolveOpts = this.options.resolveOpts ?? {
|
|
754
|
-
resolver: getAgentResolver(this.context, {
|
|
755
|
-
uniresolverResolution: true,
|
|
756
|
-
localResolution: true,
|
|
757
|
-
resolverResolution: true
|
|
758
|
-
})
|
|
759
|
-
};
|
|
760
|
-
if (!resolveOpts.subjectSyntaxTypesSupported || resolveOpts.subjectSyntaxTypesSupported.length === 0) {
|
|
761
|
-
resolveOpts.subjectSyntaxTypesSupported = await this.getSupportedDIDMethods(true);
|
|
762
|
-
}
|
|
763
|
-
const request = await this.getAuthorizationRequest();
|
|
764
|
-
const op = await createOP({
|
|
765
|
-
opOptions: {
|
|
766
|
-
...this.options,
|
|
767
|
-
resolveOpts: {
|
|
768
|
-
...this.options.resolveOpts
|
|
769
|
-
},
|
|
770
|
-
eventEmitter: this.options.eventEmitter,
|
|
771
|
-
presentationSignCallback: this.options.presentationSignCallback,
|
|
772
|
-
wellknownDIDVerifyCallback: this.options.wellknownDIDVerifyCallback,
|
|
773
|
-
supportedVersions: request.versions
|
|
774
|
-
},
|
|
775
|
-
idOpts: responseSignerOpts,
|
|
776
|
-
context: this.context
|
|
777
|
-
});
|
|
778
|
-
let issuer = responseSignerOpts.issuer;
|
|
779
|
-
const responseOpts = {
|
|
780
|
-
issuer,
|
|
781
|
-
...isFirstParty && {
|
|
782
|
-
isFirstParty
|
|
783
|
-
},
|
|
784
|
-
dcqlResponse
|
|
785
|
-
};
|
|
786
|
-
const authResponse = await op.createAuthorizationResponse(request, responseOpts);
|
|
787
|
-
const response = await op.submitAuthorizationResponse(authResponse, await this.createJarmResponseCallback({
|
|
788
|
-
responseOpts
|
|
789
|
-
}));
|
|
790
|
-
if (response.status >= 400) {
|
|
791
|
-
throw Error(`Error ${response.status}: ${response.statusText || await response.text()}`);
|
|
792
|
-
} else {
|
|
793
|
-
return response;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
};
|
|
797
|
-
function convertDidMethod(didMethod, didPrefix) {
|
|
798
|
-
if (didPrefix === false) {
|
|
799
|
-
return didMethod.startsWith("did:") ? didMethod.toLowerCase().replace("did:", "") : didMethod.toLowerCase();
|
|
800
|
-
}
|
|
801
|
-
return didMethod.startsWith("did:") ? didMethod.toLowerCase() : `did:${didMethod.toLowerCase().replace("did:", "")}`;
|
|
802
|
-
}
|
|
803
|
-
__name(convertDidMethod, "convertDidMethod");
|
|
804
|
-
|
|
805
|
-
// src/types/IDidAuthSiopOpAuthenticator.ts
|
|
806
|
-
var LOGGER_NAMESPACE = "sphereon:siopv2-oid4vp:op-auth";
|
|
807
|
-
var DEFAULT_JWT_PROOF_TYPE = "JwtProof2020";
|
|
808
|
-
|
|
809
|
-
// src/types/siop-service/index.ts
|
|
810
|
-
var Siopv2HolderEvent = /* @__PURE__ */ function(Siopv2HolderEvent2) {
|
|
811
|
-
Siopv2HolderEvent2["CONTACT_IDENTITY_CREATED"] = "contact_identity_created";
|
|
812
|
-
Siopv2HolderEvent2["IDENTIFIER_CREATED"] = "identifier_created";
|
|
813
|
-
return Siopv2HolderEvent2;
|
|
814
|
-
}({});
|
|
815
|
-
var SupportedLanguage = /* @__PURE__ */ function(SupportedLanguage2) {
|
|
816
|
-
SupportedLanguage2["ENGLISH"] = "en";
|
|
817
|
-
SupportedLanguage2["DUTCH"] = "nl";
|
|
818
|
-
return SupportedLanguage2;
|
|
819
|
-
}({});
|
|
820
|
-
|
|
821
|
-
// src/types/machine/index.ts
|
|
822
|
-
var Siopv2MachineStates = /* @__PURE__ */ function(Siopv2MachineStates2) {
|
|
823
|
-
Siopv2MachineStates2["createConfig"] = "createConfig";
|
|
824
|
-
Siopv2MachineStates2["getSiopRequest"] = "getSiopRequest";
|
|
825
|
-
Siopv2MachineStates2["getSelectableCredentials"] = "getSelectableCredentials";
|
|
826
|
-
Siopv2MachineStates2["retrieveContact"] = "retrieveContact";
|
|
827
|
-
Siopv2MachineStates2["transitionFromSetup"] = "transitionFromSetup";
|
|
828
|
-
Siopv2MachineStates2["addContact"] = "addContact";
|
|
829
|
-
Siopv2MachineStates2["addContactIdentity"] = "addContactIdentity";
|
|
830
|
-
Siopv2MachineStates2["selectCredentials"] = "selectCredentials";
|
|
831
|
-
Siopv2MachineStates2["sendResponse"] = "sendResponse";
|
|
832
|
-
Siopv2MachineStates2["handleError"] = "handleError";
|
|
833
|
-
Siopv2MachineStates2["aborted"] = "aborted";
|
|
834
|
-
Siopv2MachineStates2["declined"] = "declined";
|
|
835
|
-
Siopv2MachineStates2["error"] = "error";
|
|
836
|
-
Siopv2MachineStates2["done"] = "done";
|
|
837
|
-
return Siopv2MachineStates2;
|
|
838
|
-
}({});
|
|
839
|
-
var Siopv2MachineAddContactStates = /* @__PURE__ */ function(Siopv2MachineAddContactStates2) {
|
|
840
|
-
Siopv2MachineAddContactStates2["idle"] = "idle";
|
|
841
|
-
Siopv2MachineAddContactStates2["executing"] = "executing";
|
|
842
|
-
Siopv2MachineAddContactStates2["next"] = "next";
|
|
843
|
-
return Siopv2MachineAddContactStates2;
|
|
844
|
-
}({});
|
|
845
|
-
var Siopv2MachineEvents = /* @__PURE__ */ function(Siopv2MachineEvents2) {
|
|
846
|
-
Siopv2MachineEvents2["NEXT"] = "NEXT";
|
|
847
|
-
Siopv2MachineEvents2["PREVIOUS"] = "PREVIOUS";
|
|
848
|
-
Siopv2MachineEvents2["DECLINE"] = "DECLINE";
|
|
849
|
-
Siopv2MachineEvents2["SET_CONTACT_ALIAS"] = "SET_CONTACT_ALIAS";
|
|
850
|
-
Siopv2MachineEvents2["SET_CONTACT_CONSENT"] = "SET_CONTACT_CONSENT";
|
|
851
|
-
Siopv2MachineEvents2["CREATE_CONTACT"] = "CREATE_CONTACT";
|
|
852
|
-
Siopv2MachineEvents2["SET_SELECTED_CREDENTIALS"] = "SET_SELECTED_CREDENTIALS";
|
|
853
|
-
return Siopv2MachineEvents2;
|
|
854
|
-
}({});
|
|
855
|
-
var Siopv2MachineGuards = /* @__PURE__ */ function(Siopv2MachineGuards2) {
|
|
856
|
-
Siopv2MachineGuards2["hasNoContactGuard"] = "Siopv2HasNoContactGuard";
|
|
857
|
-
Siopv2MachineGuards2["createContactGuard"] = "Siopv2CreateContactGuard";
|
|
858
|
-
Siopv2MachineGuards2["hasContactGuard"] = "Siopv2HasContactGuard";
|
|
859
|
-
Siopv2MachineGuards2["hasAuthorizationRequestGuard"] = "Siopv2HasAuthorizationRequestGuard";
|
|
860
|
-
Siopv2MachineGuards2["hasSelectableCredentialsAndContactGuard"] = "Siopv2HasSelectableCredentialsAndContactGuard";
|
|
861
|
-
Siopv2MachineGuards2["hasSelectedRequiredCredentialsGuard"] = "Siopv2HasSelectedRequiredCredentialsGuard";
|
|
862
|
-
Siopv2MachineGuards2["siopOnlyGuard"] = "Siopv2IsSiopOnlyGuard";
|
|
863
|
-
Siopv2MachineGuards2["siopWithOID4VPGuard"] = "Siopv2IsSiopWithOID4VPGuard";
|
|
864
|
-
return Siopv2MachineGuards2;
|
|
865
|
-
}({});
|
|
866
|
-
var Siopv2MachineServices = /* @__PURE__ */ function(Siopv2MachineServices2) {
|
|
867
|
-
Siopv2MachineServices2["getSiopRequest"] = "getSiopRequest";
|
|
868
|
-
Siopv2MachineServices2["getSelectableCredentials"] = "getSelectableCredentials";
|
|
869
|
-
Siopv2MachineServices2["retrieveContact"] = "retrieveContact";
|
|
870
|
-
Siopv2MachineServices2["addContactIdentity"] = "addContactIdentity";
|
|
871
|
-
Siopv2MachineServices2["sendResponse"] = "sendResponse";
|
|
872
|
-
Siopv2MachineServices2["createConfig"] = "createConfig";
|
|
873
|
-
return Siopv2MachineServices2;
|
|
874
|
-
}({});
|
|
875
|
-
|
|
876
|
-
// src/types/identifier/index.ts
|
|
877
|
-
var DID_PREFIX = "did";
|
|
878
|
-
|
|
879
|
-
// src/machine/Siopv2Machine.ts
|
|
880
|
-
import { assign, createMachine, interpret } from "xstate";
|
|
881
|
-
|
|
882
|
-
// src/localization/Localization.ts
|
|
883
|
-
import i18n from "i18n-js";
|
|
884
|
-
import memoize from "lodash.memoize";
|
|
885
|
-
var Localization = class Localization2 {
|
|
886
|
-
static {
|
|
887
|
-
__name(this, "Localization");
|
|
888
|
-
}
|
|
889
|
-
static translationGetters = {
|
|
890
|
-
[SupportedLanguage.ENGLISH]: () => require_en(),
|
|
891
|
-
[SupportedLanguage.DUTCH]: () => require_nl()
|
|
892
|
-
};
|
|
893
|
-
static translate = memoize((key, config) => {
|
|
894
|
-
if (Object.keys(i18n.translations).length === 0) {
|
|
895
|
-
i18n.translations = {
|
|
896
|
-
[SupportedLanguage.ENGLISH]: Localization2.translationGetters[SupportedLanguage.ENGLISH]()
|
|
897
|
-
};
|
|
898
|
-
i18n.locale = SupportedLanguage.ENGLISH;
|
|
899
|
-
} else {
|
|
900
|
-
i18n.translations = {
|
|
901
|
-
[i18n.locale]: {
|
|
902
|
-
...i18n.translations[i18n.locale],
|
|
903
|
-
...Localization2.translationGetters[this.findSupportedLanguage(i18n.locale) || SupportedLanguage.ENGLISH]()
|
|
904
|
-
}
|
|
905
|
-
};
|
|
906
|
-
}
|
|
907
|
-
return i18n.t(key, config);
|
|
908
|
-
}, (key, config) => config ? key + JSON.stringify(config) : key);
|
|
909
|
-
static findSupportedLanguage = /* @__PURE__ */ __name((locale) => {
|
|
910
|
-
for (const language of Object.values(SupportedLanguage)) {
|
|
911
|
-
if (language === locale) {
|
|
912
|
-
return language;
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
return void 0;
|
|
916
|
-
}, "findSupportedLanguage");
|
|
917
|
-
static getLocale = /* @__PURE__ */ __name(() => {
|
|
918
|
-
return i18n.locale || SupportedLanguage.ENGLISH;
|
|
919
|
-
}, "getLocale");
|
|
920
|
-
};
|
|
921
|
-
var translate = Localization.translate;
|
|
922
|
-
|
|
923
|
-
// src/machine/Siopv2Machine.ts
|
|
924
|
-
import { Loggers as Loggers2 } from "@sphereon/ssi-types";
|
|
925
|
-
var logger2 = Loggers2.DEFAULT.get(LOGGER_NAMESPACE);
|
|
926
|
-
var Siopv2HasNoContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
927
|
-
const { contact } = _ctx;
|
|
928
|
-
return contact === void 0;
|
|
929
|
-
}, "Siopv2HasNoContactGuard");
|
|
930
|
-
var Siopv2HasContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
931
|
-
const { contact } = _ctx;
|
|
932
|
-
return contact !== void 0;
|
|
933
|
-
}, "Siopv2HasContactGuard");
|
|
934
|
-
var Siopv2HasAuthorizationRequestGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
935
|
-
const { authorizationRequestData } = _ctx;
|
|
936
|
-
return authorizationRequestData !== void 0;
|
|
937
|
-
}, "Siopv2HasAuthorizationRequestGuard");
|
|
938
|
-
var Siopv2HasSelectableCredentialsAndContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
939
|
-
const { authorizationRequestData, contact } = _ctx;
|
|
940
|
-
if (!authorizationRequestData) {
|
|
941
|
-
throw new Error("Missing authorization request data in context");
|
|
942
|
-
}
|
|
943
|
-
if (!contact) {
|
|
944
|
-
throw new Error("Missing contact request data in context");
|
|
945
|
-
}
|
|
946
|
-
return authorizationRequestData.dcqlQuery !== void 0;
|
|
947
|
-
}, "Siopv2HasSelectableCredentialsAndContactGuard");
|
|
948
|
-
var Siopv2CreateContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
949
|
-
const { contactAlias, hasContactConsent } = _ctx;
|
|
950
|
-
return hasContactConsent && contactAlias !== void 0 && contactAlias.length > 0;
|
|
951
|
-
}, "Siopv2CreateContactGuard");
|
|
952
|
-
var Siopv2HasSelectedRequiredCredentialsGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
953
|
-
const { authorizationRequestData } = _ctx;
|
|
954
|
-
if (authorizationRequestData === void 0) {
|
|
955
|
-
throw new Error("Missing authorization request data in context");
|
|
956
|
-
}
|
|
957
|
-
if (authorizationRequestData.dcqlQuery === void 0) {
|
|
958
|
-
throw Error("No presentation definitions present");
|
|
959
|
-
}
|
|
960
|
-
return _ctx.selectedCredentials.length > 0;
|
|
961
|
-
}, "Siopv2HasSelectedRequiredCredentialsGuard");
|
|
962
|
-
var Siopv2IsSiopOnlyGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
963
|
-
const { authorizationRequestData } = _ctx;
|
|
964
|
-
if (authorizationRequestData === void 0) {
|
|
965
|
-
throw new Error("Missing authorization request data in context");
|
|
966
|
-
}
|
|
967
|
-
return authorizationRequestData.dcqlQuery === void 0;
|
|
968
|
-
}, "Siopv2IsSiopOnlyGuard");
|
|
969
|
-
var Siopv2IsSiopWithOID4VPGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
970
|
-
const { authorizationRequestData, selectableCredentialsMap } = _ctx;
|
|
971
|
-
if (!authorizationRequestData) {
|
|
972
|
-
throw new Error("Missing authorization request data in context");
|
|
973
|
-
}
|
|
974
|
-
if (!selectableCredentialsMap) {
|
|
975
|
-
throw new Error("Missing selectableCredentialsMap in context");
|
|
976
|
-
}
|
|
977
|
-
return authorizationRequestData.dcqlQuery !== void 0;
|
|
978
|
-
}, "Siopv2IsSiopWithOID4VPGuard");
|
|
979
|
-
var createSiopv2Machine = /* @__PURE__ */ __name((opts) => {
|
|
980
|
-
const { url, idOpts: idOpts2 } = opts;
|
|
981
|
-
const initialContext = {
|
|
982
|
-
url: new URL(url).toString(),
|
|
983
|
-
hasContactConsent: true,
|
|
984
|
-
contactAlias: "",
|
|
985
|
-
selectedCredentials: [],
|
|
986
|
-
idOpts: idOpts2
|
|
987
|
-
};
|
|
988
|
-
return createMachine({
|
|
989
|
-
id: opts?.machineId ?? "Siopv2",
|
|
990
|
-
predictableActionArguments: true,
|
|
991
|
-
initial: Siopv2MachineStates.createConfig,
|
|
992
|
-
schema: {
|
|
993
|
-
events: {},
|
|
994
|
-
guards: {},
|
|
995
|
-
services: {}
|
|
996
|
-
},
|
|
997
|
-
context: initialContext,
|
|
998
|
-
states: {
|
|
999
|
-
[Siopv2MachineStates.createConfig]: {
|
|
1000
|
-
id: Siopv2MachineStates.createConfig,
|
|
1001
|
-
invoke: {
|
|
1002
|
-
src: Siopv2MachineServices.createConfig,
|
|
1003
|
-
onDone: {
|
|
1004
|
-
target: Siopv2MachineStates.getSiopRequest,
|
|
1005
|
-
actions: assign({
|
|
1006
|
-
didAuthConfig: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "didAuthConfig")
|
|
1007
|
-
})
|
|
1008
|
-
},
|
|
1009
|
-
onError: {
|
|
1010
|
-
target: Siopv2MachineStates.handleError,
|
|
1011
|
-
actions: assign({
|
|
1012
|
-
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1013
|
-
title: translate("siopv2_machine_create_config_error_title"),
|
|
1014
|
-
message: _event.data.message,
|
|
1015
|
-
stack: _event.data.stack
|
|
1016
|
-
}), "error")
|
|
1017
|
-
})
|
|
548
|
+
return authorizationRequestData.dcqlQuery !== void 0;
|
|
549
|
+
}, "Siopv2IsSiopWithOID4VPGuard");
|
|
550
|
+
var createSiopv2Machine = /* @__PURE__ */ __name((opts) => {
|
|
551
|
+
const { url, idOpts: idOpts2 } = opts;
|
|
552
|
+
const initialContext = {
|
|
553
|
+
url: new URL(url).toString(),
|
|
554
|
+
hasContactConsent: true,
|
|
555
|
+
contactAlias: "",
|
|
556
|
+
selectedCredentials: [],
|
|
557
|
+
idOpts: idOpts2
|
|
558
|
+
};
|
|
559
|
+
return createMachine({
|
|
560
|
+
id: opts?.machineId ?? "Siopv2",
|
|
561
|
+
predictableActionArguments: true,
|
|
562
|
+
initial: Siopv2MachineStates.createConfig,
|
|
563
|
+
schema: {
|
|
564
|
+
events: {},
|
|
565
|
+
guards: {},
|
|
566
|
+
services: {}
|
|
567
|
+
},
|
|
568
|
+
context: initialContext,
|
|
569
|
+
states: {
|
|
570
|
+
[Siopv2MachineStates.createConfig]: {
|
|
571
|
+
id: Siopv2MachineStates.createConfig,
|
|
572
|
+
invoke: {
|
|
573
|
+
src: Siopv2MachineServices.createConfig,
|
|
574
|
+
onDone: {
|
|
575
|
+
target: Siopv2MachineStates.getSiopRequest,
|
|
576
|
+
actions: assign({
|
|
577
|
+
didAuthConfig: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "didAuthConfig")
|
|
578
|
+
})
|
|
579
|
+
},
|
|
580
|
+
onError: {
|
|
581
|
+
target: Siopv2MachineStates.handleError,
|
|
582
|
+
actions: assign({
|
|
583
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
584
|
+
title: translate("siopv2_machine_create_config_error_title"),
|
|
585
|
+
message: _event.data.message,
|
|
586
|
+
stack: _event.data.stack
|
|
587
|
+
}), "error")
|
|
588
|
+
})
|
|
1018
589
|
}
|
|
1019
590
|
}
|
|
1020
591
|
},
|
|
@@ -1096,420 +667,851 @@ var createSiopv2Machine = /* @__PURE__ */ __name((opts) => {
|
|
|
1096
667
|
actions: assign({
|
|
1097
668
|
contactAlias: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "contactAlias")
|
|
1098
669
|
})
|
|
1099
|
-
},
|
|
1100
|
-
[Siopv2MachineEvents.CREATE_CONTACT]: {
|
|
1101
|
-
target: `.${Siopv2MachineAddContactStates.next}`,
|
|
1102
|
-
actions: assign({
|
|
1103
|
-
contact: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "contact")
|
|
1104
|
-
}),
|
|
1105
|
-
cond: Siopv2MachineGuards.createContactGuard
|
|
1106
|
-
},
|
|
1107
|
-
[Siopv2MachineEvents.DECLINE]: {
|
|
1108
|
-
target: Siopv2MachineStates.declined
|
|
670
|
+
},
|
|
671
|
+
[Siopv2MachineEvents.CREATE_CONTACT]: {
|
|
672
|
+
target: `.${Siopv2MachineAddContactStates.next}`,
|
|
673
|
+
actions: assign({
|
|
674
|
+
contact: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "contact")
|
|
675
|
+
}),
|
|
676
|
+
cond: Siopv2MachineGuards.createContactGuard
|
|
677
|
+
},
|
|
678
|
+
[Siopv2MachineEvents.DECLINE]: {
|
|
679
|
+
target: Siopv2MachineStates.declined
|
|
680
|
+
},
|
|
681
|
+
[Siopv2MachineEvents.PREVIOUS]: {
|
|
682
|
+
target: Siopv2MachineStates.aborted
|
|
683
|
+
}
|
|
684
|
+
},
|
|
685
|
+
states: {
|
|
686
|
+
[Siopv2MachineAddContactStates.idle]: {},
|
|
687
|
+
[Siopv2MachineAddContactStates.next]: {
|
|
688
|
+
always: {
|
|
689
|
+
target: `#${Siopv2MachineStates.transitionFromSetup}`,
|
|
690
|
+
cond: Siopv2MachineGuards.hasContactGuard
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
},
|
|
695
|
+
[Siopv2MachineStates.addContactIdentity]: {
|
|
696
|
+
id: Siopv2MachineStates.addContactIdentity,
|
|
697
|
+
invoke: {
|
|
698
|
+
src: Siopv2MachineServices.addContactIdentity,
|
|
699
|
+
onDone: [
|
|
700
|
+
{
|
|
701
|
+
target: Siopv2MachineStates.getSelectableCredentials,
|
|
702
|
+
actions: /* @__PURE__ */ __name((_ctx, _event) => {
|
|
703
|
+
_ctx.contact?.identities.push(_event.data);
|
|
704
|
+
}, "actions"),
|
|
705
|
+
cond: Siopv2MachineGuards.hasSelectableCredentialsAndContactGuard
|
|
706
|
+
},
|
|
707
|
+
{
|
|
708
|
+
target: Siopv2MachineStates.sendResponse,
|
|
709
|
+
actions: /* @__PURE__ */ __name((_ctx, _event) => {
|
|
710
|
+
_ctx.contact?.identities.push(_event.data);
|
|
711
|
+
}, "actions"),
|
|
712
|
+
cond: Siopv2MachineGuards.siopOnlyGuard
|
|
713
|
+
}
|
|
714
|
+
],
|
|
715
|
+
onError: {
|
|
716
|
+
target: Siopv2MachineStates.handleError,
|
|
717
|
+
actions: assign({
|
|
718
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
719
|
+
title: translate("siopv2_machine_add_contact_identity_error_title"),
|
|
720
|
+
message: _event.data.message,
|
|
721
|
+
stack: _event.data.stack
|
|
722
|
+
}), "error")
|
|
723
|
+
})
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
},
|
|
727
|
+
[Siopv2MachineStates.getSelectableCredentials]: {
|
|
728
|
+
id: Siopv2MachineStates.getSelectableCredentials,
|
|
729
|
+
invoke: {
|
|
730
|
+
src: Siopv2MachineServices.getSelectableCredentials,
|
|
731
|
+
onDone: {
|
|
732
|
+
target: Siopv2MachineStates.selectCredentials,
|
|
733
|
+
actions: assign({
|
|
734
|
+
selectableCredentialsMap: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectableCredentialsMap")
|
|
735
|
+
})
|
|
736
|
+
},
|
|
737
|
+
onError: {
|
|
738
|
+
target: Siopv2MachineStates.handleError,
|
|
739
|
+
actions: assign({
|
|
740
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
741
|
+
title: translate("siopv2_machine_get_selectable_credentials_error_title"),
|
|
742
|
+
message: _event.data.message,
|
|
743
|
+
stack: _event.data.stack
|
|
744
|
+
}), "error")
|
|
745
|
+
})
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
},
|
|
749
|
+
[Siopv2MachineStates.selectCredentials]: {
|
|
750
|
+
id: Siopv2MachineStates.selectCredentials,
|
|
751
|
+
on: {
|
|
752
|
+
[Siopv2MachineEvents.SET_SELECTED_CREDENTIALS]: {
|
|
753
|
+
actions: assign({
|
|
754
|
+
selectedCredentials: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectedCredentials")
|
|
755
|
+
})
|
|
756
|
+
},
|
|
757
|
+
[Siopv2MachineEvents.NEXT]: {
|
|
758
|
+
target: Siopv2MachineStates.sendResponse,
|
|
759
|
+
cond: Siopv2MachineGuards.hasSelectedRequiredCredentialsGuard
|
|
760
|
+
},
|
|
761
|
+
[Siopv2MachineEvents.DECLINE]: {
|
|
762
|
+
target: Siopv2MachineStates.declined
|
|
763
|
+
},
|
|
764
|
+
[Siopv2MachineEvents.PREVIOUS]: {
|
|
765
|
+
target: Siopv2MachineStates.aborted
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
},
|
|
769
|
+
[Siopv2MachineStates.sendResponse]: {
|
|
770
|
+
id: Siopv2MachineStates.sendResponse,
|
|
771
|
+
invoke: {
|
|
772
|
+
src: Siopv2MachineServices.sendResponse,
|
|
773
|
+
onDone: {
|
|
774
|
+
target: Siopv2MachineStates.done,
|
|
775
|
+
actions: assign({
|
|
776
|
+
authorizationResponseData: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationResponseData")
|
|
777
|
+
})
|
|
778
|
+
},
|
|
779
|
+
onError: {
|
|
780
|
+
target: Siopv2MachineStates.handleError,
|
|
781
|
+
actions: assign({
|
|
782
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
783
|
+
title: translate("siopv2_machine_send_response_error_title"),
|
|
784
|
+
message: _event.data.message,
|
|
785
|
+
stack: _event.data.stack
|
|
786
|
+
}), "error")
|
|
787
|
+
})
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
},
|
|
791
|
+
[Siopv2MachineStates.handleError]: {
|
|
792
|
+
id: Siopv2MachineStates.handleError,
|
|
793
|
+
on: {
|
|
794
|
+
[Siopv2MachineEvents.NEXT]: {
|
|
795
|
+
target: Siopv2MachineStates.error
|
|
1109
796
|
},
|
|
1110
797
|
[Siopv2MachineEvents.PREVIOUS]: {
|
|
1111
|
-
target: Siopv2MachineStates.
|
|
1112
|
-
}
|
|
1113
|
-
},
|
|
1114
|
-
states: {
|
|
1115
|
-
[Siopv2MachineAddContactStates.idle]: {},
|
|
1116
|
-
[Siopv2MachineAddContactStates.next]: {
|
|
1117
|
-
always: {
|
|
1118
|
-
target: `#${Siopv2MachineStates.transitionFromSetup}`,
|
|
1119
|
-
cond: Siopv2MachineGuards.hasContactGuard
|
|
1120
|
-
}
|
|
798
|
+
target: Siopv2MachineStates.error
|
|
1121
799
|
}
|
|
1122
800
|
}
|
|
1123
801
|
},
|
|
1124
|
-
[Siopv2MachineStates.
|
|
1125
|
-
id: Siopv2MachineStates.
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
802
|
+
[Siopv2MachineStates.aborted]: {
|
|
803
|
+
id: Siopv2MachineStates.aborted,
|
|
804
|
+
type: "final"
|
|
805
|
+
},
|
|
806
|
+
[Siopv2MachineStates.declined]: {
|
|
807
|
+
id: Siopv2MachineStates.declined,
|
|
808
|
+
type: "final"
|
|
809
|
+
},
|
|
810
|
+
[Siopv2MachineStates.error]: {
|
|
811
|
+
id: Siopv2MachineStates.error,
|
|
812
|
+
type: "final"
|
|
813
|
+
},
|
|
814
|
+
[Siopv2MachineStates.done]: {
|
|
815
|
+
id: Siopv2MachineStates.done,
|
|
816
|
+
type: "final"
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
}, "createSiopv2Machine");
|
|
821
|
+
var Siopv2Machine = class {
|
|
822
|
+
static {
|
|
823
|
+
__name(this, "Siopv2Machine");
|
|
824
|
+
}
|
|
825
|
+
static newInstance(opts) {
|
|
826
|
+
logger.info("New Siopv2Machine instance");
|
|
827
|
+
const interpreter = interpret(createSiopv2Machine(opts).withConfig({
|
|
828
|
+
services: {
|
|
829
|
+
...opts?.services
|
|
830
|
+
},
|
|
831
|
+
guards: {
|
|
832
|
+
Siopv2HasNoContactGuard,
|
|
833
|
+
Siopv2HasContactGuard,
|
|
834
|
+
Siopv2HasAuthorizationRequestGuard,
|
|
835
|
+
Siopv2HasSelectableCredentialsAndContactGuard,
|
|
836
|
+
Siopv2HasSelectedRequiredCredentialsGuard,
|
|
837
|
+
Siopv2IsSiopOnlyGuard,
|
|
838
|
+
Siopv2IsSiopWithOID4VPGuard,
|
|
839
|
+
Siopv2CreateContactGuard,
|
|
840
|
+
...opts?.guards
|
|
841
|
+
}
|
|
842
|
+
}));
|
|
843
|
+
if (typeof opts?.subscription === "function") {
|
|
844
|
+
interpreter.onTransition(opts.subscription);
|
|
845
|
+
}
|
|
846
|
+
if (opts?.requireCustomNavigationHook !== true) {
|
|
847
|
+
interpreter.onTransition((snapshot) => {
|
|
848
|
+
if (opts.stateNavigationListener !== void 0) {
|
|
849
|
+
void opts.stateNavigationListener(interpreter, snapshot);
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
interpreter.onTransition((snapshot) => {
|
|
854
|
+
logger.info("onTransition to new state", snapshot.value);
|
|
855
|
+
});
|
|
856
|
+
return {
|
|
857
|
+
interpreter
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
|
|
862
|
+
// src/services/Siopv2MachineService.ts
|
|
863
|
+
import { SupportedVersion } from "@sphereon/did-auth-siop";
|
|
864
|
+
import { isOID4VCIssuerIdentifier } from "@sphereon/ssi-sdk-ext.identifier-resolution";
|
|
865
|
+
import { verifiableCredentialForRoleFilter } from "@sphereon/ssi-sdk.credential-store";
|
|
866
|
+
import { ConnectionType, CredentialRole } from "@sphereon/ssi-sdk.data-store";
|
|
867
|
+
import { CredentialMapper as CredentialMapper3, Loggers as Loggers2 } from "@sphereon/ssi-types";
|
|
868
|
+
import { encodeJoseBlob } from "@sphereon/ssi-sdk.core";
|
|
869
|
+
import { DcqlPresentation, DcqlQuery } from "dcql";
|
|
870
|
+
|
|
871
|
+
// src/utils/dcql.ts
|
|
872
|
+
import { CredentialMapper as CredentialMapper2 } from "@sphereon/ssi-types";
|
|
873
|
+
import { Dcql } from "@sphereon/did-auth-siop";
|
|
874
|
+
|
|
875
|
+
// src/utils/CredentialUtils.ts
|
|
876
|
+
import { CredentialMapper } from "@sphereon/ssi-types";
|
|
877
|
+
var isUniqueDigitalCredential = /* @__PURE__ */ __name((credential) => {
|
|
878
|
+
return credential.digitalCredential !== void 0;
|
|
879
|
+
}, "isUniqueDigitalCredential");
|
|
880
|
+
|
|
881
|
+
// src/utils/dcql.ts
|
|
882
|
+
function convertToDcqlCredentials(credential, hasher) {
|
|
883
|
+
let originalVerifiableCredential;
|
|
884
|
+
if (isUniqueDigitalCredential(credential)) {
|
|
885
|
+
if (!credential.originalVerifiableCredential) {
|
|
886
|
+
throw new Error("originalVerifiableCredential is not defined in UniqueDigitalCredential");
|
|
887
|
+
}
|
|
888
|
+
originalVerifiableCredential = CredentialMapper2.decodeVerifiableCredential(credential.originalVerifiableCredential, hasher);
|
|
889
|
+
} else {
|
|
890
|
+
originalVerifiableCredential = CredentialMapper2.decodeVerifiableCredential(credential, hasher);
|
|
891
|
+
}
|
|
892
|
+
if (!originalVerifiableCredential) {
|
|
893
|
+
throw new Error("No payload found");
|
|
894
|
+
}
|
|
895
|
+
if (CredentialMapper2.isJwtDecodedCredential(originalVerifiableCredential)) {
|
|
896
|
+
return Dcql.toDcqlJwtCredential(CredentialMapper2.toWrappedVerifiableCredential(originalVerifiableCredential));
|
|
897
|
+
} else if (CredentialMapper2.isSdJwtDecodedCredential(originalVerifiableCredential)) {
|
|
898
|
+
return Dcql.toDcqlSdJwtCredential(CredentialMapper2.toWrappedVerifiableCredential(originalVerifiableCredential));
|
|
899
|
+
} else if (CredentialMapper2.isMsoMdocDecodedCredential(originalVerifiableCredential)) {
|
|
900
|
+
return Dcql.toDcqlMdocCredential(CredentialMapper2.toWrappedVerifiableCredential(originalVerifiableCredential));
|
|
901
|
+
} else if (CredentialMapper2.isW3cCredential(originalVerifiableCredential)) {
|
|
902
|
+
return Dcql.toDcqlJsonLdCredential(CredentialMapper2.toWrappedVerifiableCredential(originalVerifiableCredential));
|
|
903
|
+
}
|
|
904
|
+
throw Error(`Unable to map credential to DCQL credential. Credential: ${JSON.stringify(originalVerifiableCredential)}`);
|
|
905
|
+
}
|
|
906
|
+
__name(convertToDcqlCredentials, "convertToDcqlCredentials");
|
|
907
|
+
|
|
908
|
+
// src/services/Siopv2MachineService.ts
|
|
909
|
+
import { getOrCreatePrimaryIdentifier, SupportedDidMethodEnum } from "@sphereon/ssi-sdk-ext.did-utils";
|
|
910
|
+
var logger2 = Loggers2.DEFAULT.get(LOGGER_NAMESPACE);
|
|
911
|
+
var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType, args, context) => {
|
|
912
|
+
const { agent } = context;
|
|
913
|
+
const { credentials } = args;
|
|
914
|
+
if (connectionType !== ConnectionType.SIOPv2_OpenID4VP) {
|
|
915
|
+
return Promise.reject(Error(`No supported authentication provider for type: ${connectionType}`));
|
|
916
|
+
}
|
|
917
|
+
const session = await agent.siopGetOPSession({
|
|
918
|
+
sessionId: args.sessionId
|
|
919
|
+
});
|
|
920
|
+
const request = await session.getAuthorizationRequest();
|
|
921
|
+
const aud = request.authorizationRequest.getMergedProperty("aud");
|
|
922
|
+
logger2.debug(`AUD: ${aud}`);
|
|
923
|
+
logger2.debug(JSON.stringify(request.authorizationRequest));
|
|
924
|
+
const domain = await request.authorizationRequest.getMergedProperty("client_id") ?? request.issuer ?? (request.versions.includes(SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1) ? "https://self-issued.me/v2/openid-vc" : "https://self-issued.me/v2");
|
|
925
|
+
logger2.debug(`NONCE: ${session.nonce}, domain: ${domain}`);
|
|
926
|
+
const firstUniqueDC = credentials[0];
|
|
927
|
+
if (typeof firstUniqueDC !== "object" || !("digitalCredential" in firstUniqueDC)) {
|
|
928
|
+
return Promise.reject(Error("SiopMachine only supports UniqueDigitalCredentials for now"));
|
|
929
|
+
}
|
|
930
|
+
let identifier;
|
|
931
|
+
const digitalCredential = firstUniqueDC.digitalCredential;
|
|
932
|
+
const firstVC = firstUniqueDC.uniformVerifiableCredential;
|
|
933
|
+
const holder = CredentialMapper3.isSdJwtDecodedCredential(firstVC) ? firstVC.decodedPayload.cnf?.jwk ? (
|
|
934
|
+
//doesn't apply to did:jwk only, as you can represent any DID key as a JWK. So whenever you encounter a JWK it doesn't mean it had to come from a did:jwk in the system. It just can always be represented as a did:jwk
|
|
935
|
+
`did:jwk:${encodeJoseBlob(firstVC.decodedPayload.cnf?.jwk)}#0`
|
|
936
|
+
) : firstVC.decodedPayload.sub : Array.isArray(firstVC.credentialSubject) ? firstVC.credentialSubject[0].id : firstVC.credentialSubject.id;
|
|
937
|
+
if (!digitalCredential.kmsKeyRef) {
|
|
938
|
+
if (!holder) {
|
|
939
|
+
return Promise.reject(`No holder found and no kmsKeyRef in DB. Cannot determine identifier to use`);
|
|
940
|
+
}
|
|
941
|
+
try {
|
|
942
|
+
identifier = await session.context.agent.identifierManagedGet({
|
|
943
|
+
identifier: holder
|
|
944
|
+
});
|
|
945
|
+
} catch (e) {
|
|
946
|
+
logger2.debug(`Holder DID not found: ${holder}`);
|
|
947
|
+
throw e;
|
|
948
|
+
}
|
|
949
|
+
} else if (isOID4VCIssuerIdentifier(digitalCredential.kmsKeyRef)) {
|
|
950
|
+
identifier = await session.context.agent.identifierManagedGetByOID4VCIssuer({
|
|
951
|
+
identifier: firstUniqueDC.digitalCredential.kmsKeyRef
|
|
952
|
+
});
|
|
953
|
+
} else {
|
|
954
|
+
switch (digitalCredential.subjectCorrelationType) {
|
|
955
|
+
case "DID":
|
|
956
|
+
identifier = await session.context.agent.identifierManagedGetByDid({
|
|
957
|
+
identifier: digitalCredential.subjectCorrelationId ?? holder,
|
|
958
|
+
kmsKeyRef: digitalCredential.kmsKeyRef
|
|
959
|
+
});
|
|
960
|
+
break;
|
|
961
|
+
// TODO other implementations?
|
|
962
|
+
default:
|
|
963
|
+
identifier = await session.context.agent.identifierManagedGetByKid({
|
|
964
|
+
identifier: digitalCredential.subjectCorrelationId ?? holder ?? digitalCredential.kmsKeyRef,
|
|
965
|
+
kmsKeyRef: digitalCredential.kmsKeyRef
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
const dcqlCredentialsWithCredentials = new Map(credentials.map((vc) => [
|
|
970
|
+
convertToDcqlCredentials(vc),
|
|
971
|
+
vc
|
|
972
|
+
]));
|
|
973
|
+
const queryResult = DcqlQuery.query(request.dcqlQuery, Array.from(dcqlCredentialsWithCredentials.keys()));
|
|
974
|
+
if (!queryResult.can_be_satisfied) {
|
|
975
|
+
return Promise.reject(Error("Credentials do not match required query request"));
|
|
976
|
+
}
|
|
977
|
+
const presentation = {};
|
|
978
|
+
const uniqueCredentials = Array.from(dcqlCredentialsWithCredentials.values());
|
|
979
|
+
for (const [key, value] of Object.entries(queryResult.credential_matches)) {
|
|
980
|
+
if (value.success) {
|
|
981
|
+
const matchedCredentials = value.valid_credentials.map((cred) => uniqueCredentials[cred.input_credential_index]);
|
|
982
|
+
const vc = matchedCredentials[0];
|
|
983
|
+
if (!vc) {
|
|
984
|
+
continue;
|
|
985
|
+
}
|
|
986
|
+
const originalVc = retrieveEncodedCredential(vc);
|
|
987
|
+
if (!originalVc) {
|
|
988
|
+
continue;
|
|
989
|
+
}
|
|
990
|
+
if (originalVc) {
|
|
991
|
+
presentation[key] = originalVc;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
const dcqlPresentation = DcqlPresentation.parse(presentation);
|
|
996
|
+
const response = session.sendAuthorizationResponse({
|
|
997
|
+
responseSignerOpts: identifier,
|
|
998
|
+
dcqlResponse: {
|
|
999
|
+
dcqlPresentation
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
logger2.debug(`Response: `, response);
|
|
1003
|
+
return response;
|
|
1004
|
+
}, "siopSendAuthorizationResponse");
|
|
1005
|
+
var retrieveEncodedCredential = /* @__PURE__ */ __name((credential) => {
|
|
1006
|
+
return credential.originalVerifiableCredential !== void 0 && credential.originalVerifiableCredential !== null && credential?.originalVerifiableCredential?.compactSdJwtVc !== void 0 && credential?.originalVerifiableCredential?.compactSdJwtVc !== null ? credential.originalVerifiableCredential.compactSdJwtVc : credential.originalVerifiableCredential;
|
|
1007
|
+
}, "retrieveEncodedCredential");
|
|
1008
|
+
var getSelectableCredentials = /* @__PURE__ */ __name(async (dcqlQuery, context) => {
|
|
1009
|
+
const agentContext = {
|
|
1010
|
+
...context,
|
|
1011
|
+
agent: context.agent
|
|
1012
|
+
};
|
|
1013
|
+
const { agent } = agentContext;
|
|
1014
|
+
const uniqueVerifiableCredentials = await agent.crsGetUniqueCredentials({
|
|
1015
|
+
filter: verifiableCredentialForRoleFilter(CredentialRole.HOLDER)
|
|
1016
|
+
});
|
|
1017
|
+
const branding = await agent.ibGetCredentialBranding();
|
|
1018
|
+
const dcqlCredentialsWithCredentials = new Map(uniqueVerifiableCredentials.map((vc) => [
|
|
1019
|
+
convertToDcqlCredentials(vc),
|
|
1020
|
+
vc
|
|
1021
|
+
]));
|
|
1022
|
+
const queryResult = DcqlQuery.query(dcqlQuery, Array.from(dcqlCredentialsWithCredentials.keys()));
|
|
1023
|
+
const uniqueCredentials = Array.from(dcqlCredentialsWithCredentials.values());
|
|
1024
|
+
const selectableCredentialsMap = /* @__PURE__ */ new Map();
|
|
1025
|
+
for (const [key, value] of Object.entries(queryResult.credential_matches)) {
|
|
1026
|
+
if (!value.valid_credentials) {
|
|
1027
|
+
continue;
|
|
1028
|
+
}
|
|
1029
|
+
const mapSelectableCredentialPromises = value.valid_credentials.map(async (cred) => {
|
|
1030
|
+
const matchedCredential = uniqueCredentials[cred.input_credential_index];
|
|
1031
|
+
const credentialBranding = branding.filter((cb) => cb.vcHash === matchedCredential.hash);
|
|
1032
|
+
const issuerPartyIdentity = await agent.cmGetContacts({
|
|
1033
|
+
filter: [
|
|
1034
|
+
{
|
|
1035
|
+
identities: {
|
|
1036
|
+
identifier: {
|
|
1037
|
+
correlationId: matchedCredential.uniformVerifiableCredential.issuerDid
|
|
1038
|
+
}
|
|
1142
1039
|
}
|
|
1143
|
-
],
|
|
1144
|
-
onError: {
|
|
1145
|
-
target: Siopv2MachineStates.handleError,
|
|
1146
|
-
actions: assign({
|
|
1147
|
-
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1148
|
-
title: translate("siopv2_machine_add_contact_identity_error_title"),
|
|
1149
|
-
message: _event.data.message,
|
|
1150
|
-
stack: _event.data.stack
|
|
1151
|
-
}), "error")
|
|
1152
|
-
})
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
},
|
|
1156
|
-
[Siopv2MachineStates.getSelectableCredentials]: {
|
|
1157
|
-
id: Siopv2MachineStates.getSelectableCredentials,
|
|
1158
|
-
invoke: {
|
|
1159
|
-
src: Siopv2MachineServices.getSelectableCredentials,
|
|
1160
|
-
onDone: {
|
|
1161
|
-
target: Siopv2MachineStates.selectCredentials,
|
|
1162
|
-
actions: assign({
|
|
1163
|
-
selectableCredentialsMap: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectableCredentialsMap")
|
|
1164
|
-
})
|
|
1165
|
-
},
|
|
1166
|
-
onError: {
|
|
1167
|
-
target: Siopv2MachineStates.handleError,
|
|
1168
|
-
actions: assign({
|
|
1169
|
-
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1170
|
-
title: translate("siopv2_machine_get_selectable_credentials_error_title"),
|
|
1171
|
-
message: _event.data.message,
|
|
1172
|
-
stack: _event.data.stack
|
|
1173
|
-
}), "error")
|
|
1174
|
-
})
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
},
|
|
1178
|
-
[Siopv2MachineStates.selectCredentials]: {
|
|
1179
|
-
id: Siopv2MachineStates.selectCredentials,
|
|
1180
|
-
on: {
|
|
1181
|
-
[Siopv2MachineEvents.SET_SELECTED_CREDENTIALS]: {
|
|
1182
|
-
actions: assign({
|
|
1183
|
-
selectedCredentials: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectedCredentials")
|
|
1184
|
-
})
|
|
1185
|
-
},
|
|
1186
|
-
[Siopv2MachineEvents.NEXT]: {
|
|
1187
|
-
target: Siopv2MachineStates.sendResponse,
|
|
1188
|
-
cond: Siopv2MachineGuards.hasSelectedRequiredCredentialsGuard
|
|
1189
|
-
},
|
|
1190
|
-
[Siopv2MachineEvents.DECLINE]: {
|
|
1191
|
-
target: Siopv2MachineStates.declined
|
|
1192
|
-
},
|
|
1193
|
-
[Siopv2MachineEvents.PREVIOUS]: {
|
|
1194
|
-
target: Siopv2MachineStates.aborted
|
|
1195
1040
|
}
|
|
1196
|
-
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
})
|
|
1207
|
-
},
|
|
1208
|
-
onError: {
|
|
1209
|
-
target: Siopv2MachineStates.handleError,
|
|
1210
|
-
actions: assign({
|
|
1211
|
-
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1212
|
-
title: translate("siopv2_machine_send_response_error_title"),
|
|
1213
|
-
message: _event.data.message,
|
|
1214
|
-
stack: _event.data.stack
|
|
1215
|
-
}), "error")
|
|
1216
|
-
})
|
|
1041
|
+
]
|
|
1042
|
+
});
|
|
1043
|
+
const subjectPartyIdentity = await agent.cmGetContacts({
|
|
1044
|
+
filter: [
|
|
1045
|
+
{
|
|
1046
|
+
identities: {
|
|
1047
|
+
identifier: {
|
|
1048
|
+
correlationId: matchedCredential.uniformVerifiableCredential.subjectDid
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1217
1051
|
}
|
|
1218
|
-
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1052
|
+
]
|
|
1053
|
+
});
|
|
1054
|
+
return {
|
|
1055
|
+
credential: matchedCredential,
|
|
1056
|
+
credentialBranding: credentialBranding[0]?.localeBranding,
|
|
1057
|
+
issuerParty: issuerPartyIdentity?.[0],
|
|
1058
|
+
subjectParty: subjectPartyIdentity?.[0]
|
|
1059
|
+
};
|
|
1060
|
+
});
|
|
1061
|
+
const selectableCredentials = await Promise.all(mapSelectableCredentialPromises);
|
|
1062
|
+
selectableCredentialsMap.set(key, selectableCredentials);
|
|
1063
|
+
}
|
|
1064
|
+
return selectableCredentialsMap;
|
|
1065
|
+
}, "getSelectableCredentials");
|
|
1066
|
+
var translateCorrelationIdToName = /* @__PURE__ */ __name(async (correlationId, context) => {
|
|
1067
|
+
const { agent } = context;
|
|
1068
|
+
const contacts = await agent.cmGetContacts({
|
|
1069
|
+
filter: [
|
|
1070
|
+
{
|
|
1071
|
+
identities: {
|
|
1072
|
+
identifier: {
|
|
1073
|
+
correlationId
|
|
1228
1074
|
}
|
|
1229
1075
|
}
|
|
1076
|
+
}
|
|
1077
|
+
]
|
|
1078
|
+
});
|
|
1079
|
+
if (contacts.length === 0) {
|
|
1080
|
+
return void 0;
|
|
1081
|
+
}
|
|
1082
|
+
return contacts[0].contact.displayName;
|
|
1083
|
+
}, "translateCorrelationIdToName");
|
|
1084
|
+
|
|
1085
|
+
// src/session/functions.ts
|
|
1086
|
+
import { OP, PassBy, ResponseMode, SupportedVersion as SupportedVersion2 } from "@sphereon/did-auth-siop";
|
|
1087
|
+
import { SigningAlgo } from "@sphereon/oid4vc-common";
|
|
1088
|
+
import { isManagedIdentifierDidOpts, isManagedIdentifierX5cOpts } from "@sphereon/ssi-sdk-ext.identifier-resolution";
|
|
1089
|
+
import { createPEXPresentationSignCallback } from "@sphereon/ssi-sdk.presentation-exchange";
|
|
1090
|
+
import { EventEmitter } from "events";
|
|
1091
|
+
async function createOID4VPPresentationSignCallback({ presentationSignCallback, idOpts: idOpts1, domain, fetchRemoteContexts, challenge, format, context, skipDidResolution }) {
|
|
1092
|
+
if (typeof presentationSignCallback === "function") {
|
|
1093
|
+
return presentationSignCallback;
|
|
1094
|
+
}
|
|
1095
|
+
return createPEXPresentationSignCallback({
|
|
1096
|
+
idOpts: idOpts1,
|
|
1097
|
+
fetchRemoteContexts,
|
|
1098
|
+
domain,
|
|
1099
|
+
challenge,
|
|
1100
|
+
format,
|
|
1101
|
+
skipDidResolution
|
|
1102
|
+
}, context);
|
|
1103
|
+
}
|
|
1104
|
+
__name(createOID4VPPresentationSignCallback, "createOID4VPPresentationSignCallback");
|
|
1105
|
+
async function createOPBuilder({ opOptions, idOpts: idOpts1, context }) {
|
|
1106
|
+
const eventEmitter = opOptions.eventEmitter ?? new EventEmitter();
|
|
1107
|
+
const builder = OP.builder().withResponseMode(opOptions.responseMode ?? ResponseMode.DIRECT_POST).withSupportedVersions(opOptions.supportedVersions ?? [
|
|
1108
|
+
SupportedVersion2.SIOPv2_ID1,
|
|
1109
|
+
SupportedVersion2.JWT_VC_PRESENTATION_PROFILE_v1,
|
|
1110
|
+
SupportedVersion2.SIOPv2_D11,
|
|
1111
|
+
SupportedVersion2.SIOPv2_D12_OID4VP_D18
|
|
1112
|
+
]).withExpiresIn(opOptions.expiresIn ?? 300).withEventEmitter(eventEmitter).withRegistration({
|
|
1113
|
+
passBy: PassBy.VALUE
|
|
1114
|
+
});
|
|
1115
|
+
const wellknownDIDVerifyCallback = opOptions.wellknownDIDVerifyCallback ? opOptions.wellknownDIDVerifyCallback : async (args) => {
|
|
1116
|
+
const result = await context.agent.cvVerifyCredential({
|
|
1117
|
+
credential: args.credential,
|
|
1118
|
+
fetchRemoteContexts: true
|
|
1119
|
+
});
|
|
1120
|
+
return {
|
|
1121
|
+
verified: result.result
|
|
1122
|
+
};
|
|
1123
|
+
};
|
|
1124
|
+
builder.withVerifyJwtCallback(opOptions.verifyJwtCallback ? opOptions.verifyJwtCallback : getVerifyJwtCallback({
|
|
1125
|
+
verifyOpts: {
|
|
1126
|
+
wellknownDIDVerifyCallback,
|
|
1127
|
+
checkLinkedDomain: "if_present"
|
|
1128
|
+
}
|
|
1129
|
+
}, context));
|
|
1130
|
+
if (idOpts1) {
|
|
1131
|
+
if (opOptions.skipDidResolution && isManagedIdentifierDidOpts(idOpts1)) {
|
|
1132
|
+
idOpts1.offlineWhenNoDIDRegistered = true;
|
|
1133
|
+
}
|
|
1134
|
+
const createJwtCallback = createJwtCallbackWithIdOpts(idOpts1, context);
|
|
1135
|
+
builder.withCreateJwtCallback(createJwtCallback);
|
|
1136
|
+
builder.withPresentationSignCallback(await createOID4VPPresentationSignCallback({
|
|
1137
|
+
presentationSignCallback: opOptions.presentationSignCallback,
|
|
1138
|
+
skipDidResolution: opOptions.skipDidResolution ?? false,
|
|
1139
|
+
idOpts: idOpts1,
|
|
1140
|
+
context
|
|
1141
|
+
}));
|
|
1142
|
+
} else {
|
|
1143
|
+
const createJwtCallback = createJwtCallbackWithOpOpts(opOptions, context);
|
|
1144
|
+
builder.withCreateJwtCallback(createJwtCallback);
|
|
1145
|
+
}
|
|
1146
|
+
return builder;
|
|
1147
|
+
}
|
|
1148
|
+
__name(createOPBuilder, "createOPBuilder");
|
|
1149
|
+
function createJwtCallbackWithIdOpts(idOpts1, context) {
|
|
1150
|
+
return async (jwtIssuer, jwt) => {
|
|
1151
|
+
let issuer;
|
|
1152
|
+
if (isManagedIdentifierDidOpts(idOpts1)) {
|
|
1153
|
+
issuer = {
|
|
1154
|
+
...idOpts1,
|
|
1155
|
+
method: idOpts1.method,
|
|
1156
|
+
noIdentifierInHeader: false
|
|
1157
|
+
};
|
|
1158
|
+
} else if (isManagedIdentifierX5cOpts(idOpts1)) {
|
|
1159
|
+
issuer = {
|
|
1160
|
+
...idOpts1,
|
|
1161
|
+
method: idOpts1.method,
|
|
1162
|
+
noIdentifierInHeader: false
|
|
1163
|
+
};
|
|
1164
|
+
} else {
|
|
1165
|
+
return Promise.reject(Error(`JWT issuer method ${jwtIssuer.method} not yet supported`));
|
|
1166
|
+
}
|
|
1167
|
+
const result = await context.agent.jwtCreateJwsCompactSignature({
|
|
1168
|
+
issuer,
|
|
1169
|
+
protectedHeader: jwt.header,
|
|
1170
|
+
payload: jwt.payload
|
|
1171
|
+
});
|
|
1172
|
+
return result.jwt;
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
__name(createJwtCallbackWithIdOpts, "createJwtCallbackWithIdOpts");
|
|
1176
|
+
function createJwtCallbackWithOpOpts(opOpts, context) {
|
|
1177
|
+
return async (jwtIssuer, jwt) => {
|
|
1178
|
+
let identifier;
|
|
1179
|
+
if (jwtIssuer.method == "did") {
|
|
1180
|
+
identifier = jwtIssuer.didUrl;
|
|
1181
|
+
} else if (jwtIssuer.method == "x5c") {
|
|
1182
|
+
identifier = jwtIssuer.x5c;
|
|
1183
|
+
} else {
|
|
1184
|
+
return Promise.reject(Error(`JWT issuer method ${jwtIssuer.method} not yet supported`));
|
|
1185
|
+
}
|
|
1186
|
+
const result = await context.agent.jwtCreateJwsCompactSignature({
|
|
1187
|
+
// FIXME fix cose-key inference
|
|
1188
|
+
// @ts-ignore
|
|
1189
|
+
issuer: {
|
|
1190
|
+
identifier,
|
|
1191
|
+
kmsKeyRef: idOpts.kmsKeyRef,
|
|
1192
|
+
noIdentifierInHeader: false
|
|
1230
1193
|
},
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1194
|
+
// FIXME fix JWK key_ops
|
|
1195
|
+
// @ts-ignore
|
|
1196
|
+
protectedHeader: jwt.header,
|
|
1197
|
+
payload: jwt.payload
|
|
1198
|
+
});
|
|
1199
|
+
return result.jwt;
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
__name(createJwtCallbackWithOpOpts, "createJwtCallbackWithOpOpts");
|
|
1203
|
+
function getVerifyJwtCallback(_opts, context) {
|
|
1204
|
+
return async (_jwtVerifier, jwt) => {
|
|
1205
|
+
const result = await context.agent.jwtVerifyJwsSignature({
|
|
1206
|
+
jws: jwt.raw
|
|
1207
|
+
});
|
|
1208
|
+
console.log(result.message);
|
|
1209
|
+
return !result.error;
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
__name(getVerifyJwtCallback, "getVerifyJwtCallback");
|
|
1213
|
+
async function createOP({ opOptions, idOpts: idOpts1, context }) {
|
|
1214
|
+
return (await createOPBuilder({
|
|
1215
|
+
opOptions,
|
|
1216
|
+
idOpts: idOpts1,
|
|
1217
|
+
context
|
|
1218
|
+
})).build();
|
|
1219
|
+
}
|
|
1220
|
+
__name(createOP, "createOP");
|
|
1221
|
+
function getSigningAlgo(type) {
|
|
1222
|
+
switch (type) {
|
|
1223
|
+
case "Ed25519":
|
|
1224
|
+
return SigningAlgo.EDDSA;
|
|
1225
|
+
case "Secp256k1":
|
|
1226
|
+
return SigningAlgo.ES256K;
|
|
1227
|
+
case "Secp256r1":
|
|
1228
|
+
return SigningAlgo.ES256;
|
|
1229
|
+
// @ts-ignore
|
|
1230
|
+
case "RSA":
|
|
1231
|
+
return SigningAlgo.RS256;
|
|
1232
|
+
default:
|
|
1233
|
+
throw Error("Key type not yet supported");
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
__name(getSigningAlgo, "getSigningAlgo");
|
|
1237
|
+
|
|
1238
|
+
// src/session/OID4VP.ts
|
|
1239
|
+
var OID4VP = class _OID4VP {
|
|
1251
1240
|
static {
|
|
1252
|
-
__name(this, "
|
|
1241
|
+
__name(this, "OID4VP");
|
|
1253
1242
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
Siopv2HasSelectableCredentialsAndContactGuard,
|
|
1265
|
-
Siopv2HasSelectedRequiredCredentialsGuard,
|
|
1266
|
-
Siopv2IsSiopOnlyGuard,
|
|
1267
|
-
Siopv2IsSiopWithOID4VPGuard,
|
|
1268
|
-
Siopv2CreateContactGuard,
|
|
1269
|
-
...opts?.guards
|
|
1270
|
-
}
|
|
1271
|
-
}));
|
|
1272
|
-
if (typeof opts?.subscription === "function") {
|
|
1273
|
-
interpreter.onTransition(opts.subscription);
|
|
1274
|
-
}
|
|
1275
|
-
if (opts?.requireCustomNavigationHook !== true) {
|
|
1276
|
-
interpreter.onTransition((snapshot) => {
|
|
1277
|
-
if (opts.stateNavigationListener !== void 0) {
|
|
1278
|
-
void opts.stateNavigationListener(interpreter, snapshot);
|
|
1279
|
-
}
|
|
1280
|
-
});
|
|
1281
|
-
}
|
|
1282
|
-
interpreter.onTransition((snapshot) => {
|
|
1283
|
-
logger2.info("onTransition to new state", snapshot.value);
|
|
1243
|
+
//private readonly session: OpSession
|
|
1244
|
+
// private readonly allIdentifiers: string[]
|
|
1245
|
+
// private readonly hasher?: HasherSync
|
|
1246
|
+
constructor(args) {
|
|
1247
|
+
}
|
|
1248
|
+
static async init(session, allIdentifiers, hasher) {
|
|
1249
|
+
return new _OID4VP({
|
|
1250
|
+
session,
|
|
1251
|
+
allIdentifiers: allIdentifiers ?? await session.getSupportedDIDs(),
|
|
1252
|
+
hasher
|
|
1284
1253
|
});
|
|
1285
|
-
return {
|
|
1286
|
-
interpreter
|
|
1287
|
-
};
|
|
1288
1254
|
}
|
|
1289
1255
|
};
|
|
1290
1256
|
|
|
1291
|
-
// src/
|
|
1292
|
-
import {
|
|
1293
|
-
import {
|
|
1294
|
-
import {
|
|
1295
|
-
import {
|
|
1296
|
-
import {
|
|
1297
|
-
import {
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
import { Dcql } from "@sphereon/did-auth-siop";
|
|
1303
|
-
|
|
1304
|
-
// src/utils/CredentialUtils.ts
|
|
1305
|
-
import { CredentialMapper } from "@sphereon/ssi-types";
|
|
1306
|
-
var isUniqueDigitalCredential = /* @__PURE__ */ __name((credential) => {
|
|
1307
|
-
return credential.digitalCredential !== void 0;
|
|
1308
|
-
}, "isUniqueDigitalCredential");
|
|
1309
|
-
|
|
1310
|
-
// src/utils/dcql.ts
|
|
1311
|
-
function convertToDcqlCredentials(credential, hasher) {
|
|
1312
|
-
let originalVerifiableCredential;
|
|
1313
|
-
if (isUniqueDigitalCredential(credential)) {
|
|
1314
|
-
if (!credential.originalVerifiableCredential) {
|
|
1315
|
-
throw new Error("originalVerifiableCredential is not defined in UniqueDigitalCredential");
|
|
1316
|
-
}
|
|
1317
|
-
originalVerifiableCredential = CredentialMapper2.decodeVerifiableCredential(credential.originalVerifiableCredential, hasher);
|
|
1318
|
-
} else {
|
|
1319
|
-
originalVerifiableCredential = CredentialMapper2.decodeVerifiableCredential(credential, hasher);
|
|
1257
|
+
// src/session/OpSession.ts
|
|
1258
|
+
import { OP as OP2, URI } from "@sphereon/did-auth-siop";
|
|
1259
|
+
import { getAgentDIDMethods, getAgentResolver } from "@sphereon/ssi-sdk-ext.did-utils";
|
|
1260
|
+
import { encodeBase64url } from "@sphereon/ssi-sdk.core";
|
|
1261
|
+
import { parseDid } from "@sphereon/ssi-types";
|
|
1262
|
+
import { v4 } from "uuid";
|
|
1263
|
+
import { Loggers as Loggers3 } from "@sphereon/ssi-types";
|
|
1264
|
+
var logger3 = Loggers3.DEFAULT.get("sphereon:oid4vp:OpSession");
|
|
1265
|
+
var OpSession = class _OpSession {
|
|
1266
|
+
static {
|
|
1267
|
+
__name(this, "OpSession");
|
|
1320
1268
|
}
|
|
1321
|
-
|
|
1322
|
-
|
|
1269
|
+
ts = (/* @__PURE__ */ new Date()).getDate();
|
|
1270
|
+
id;
|
|
1271
|
+
options;
|
|
1272
|
+
context;
|
|
1273
|
+
requestJwtOrUri;
|
|
1274
|
+
verifiedAuthorizationRequest;
|
|
1275
|
+
_nonce;
|
|
1276
|
+
_state;
|
|
1277
|
+
constructor(options) {
|
|
1278
|
+
this.id = options.sessionId;
|
|
1279
|
+
this.options = options.op;
|
|
1280
|
+
this.context = options.context;
|
|
1281
|
+
this.requestJwtOrUri = options.requestJwtOrUri;
|
|
1323
1282
|
}
|
|
1324
|
-
|
|
1325
|
-
return
|
|
1326
|
-
} else if (CredentialMapper2.isSdJwtDecodedCredential(originalVerifiableCredential)) {
|
|
1327
|
-
return Dcql.toDcqlSdJwtCredential(CredentialMapper2.toWrappedVerifiableCredential(originalVerifiableCredential));
|
|
1328
|
-
} else if (CredentialMapper2.isMsoMdocDecodedCredential(originalVerifiableCredential)) {
|
|
1329
|
-
return Dcql.toDcqlMdocCredential(CredentialMapper2.toWrappedVerifiableCredential(originalVerifiableCredential));
|
|
1330
|
-
} else if (CredentialMapper2.isW3cCredential(originalVerifiableCredential)) {
|
|
1331
|
-
return Dcql.toDcqlJsonLdCredential(CredentialMapper2.toWrappedVerifiableCredential(originalVerifiableCredential));
|
|
1283
|
+
static async init(options) {
|
|
1284
|
+
return new _OpSession(options);
|
|
1332
1285
|
}
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
return
|
|
1286
|
+
async getAuthorizationRequest() {
|
|
1287
|
+
if (!this.verifiedAuthorizationRequest) {
|
|
1288
|
+
const op = await createOP({
|
|
1289
|
+
opOptions: this.options,
|
|
1290
|
+
context: this.context
|
|
1291
|
+
});
|
|
1292
|
+
this.verifiedAuthorizationRequest = await op.verifyAuthorizationRequest(this.requestJwtOrUri);
|
|
1293
|
+
this._nonce = await this.verifiedAuthorizationRequest.authorizationRequest.getMergedProperty("nonce");
|
|
1294
|
+
this._state = await this.verifiedAuthorizationRequest.authorizationRequest.getMergedProperty("state");
|
|
1295
|
+
await this.getSupportedDIDMethods();
|
|
1296
|
+
}
|
|
1297
|
+
return this.verifiedAuthorizationRequest;
|
|
1345
1298
|
}
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
});
|
|
1349
|
-
const request = await session.getAuthorizationRequest();
|
|
1350
|
-
const aud = request.authorizationRequest.getMergedProperty("aud");
|
|
1351
|
-
logger3.debug(`AUD: ${aud}`);
|
|
1352
|
-
logger3.debug(JSON.stringify(request.authorizationRequest));
|
|
1353
|
-
const domain = await request.authorizationRequest.getMergedProperty("client_id") ?? request.issuer ?? (request.versions.includes(SupportedVersion2.JWT_VC_PRESENTATION_PROFILE_v1) ? "https://self-issued.me/v2/openid-vc" : "https://self-issued.me/v2");
|
|
1354
|
-
logger3.debug(`NONCE: ${session.nonce}, domain: ${domain}`);
|
|
1355
|
-
const firstUniqueDC = credentials[0];
|
|
1356
|
-
if (typeof firstUniqueDC !== "object" || !("digitalCredential" in firstUniqueDC)) {
|
|
1357
|
-
return Promise.reject(Error("SiopMachine only supports UniqueDigitalCredentials for now"));
|
|
1299
|
+
async getAuthorizationRequestURI() {
|
|
1300
|
+
return await URI.fromAuthorizationRequest((await this.getAuthorizationRequest()).authorizationRequest);
|
|
1358
1301
|
}
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
const holder = CredentialMapper3.isSdJwtDecodedCredential(firstVC) ? firstVC.decodedPayload.cnf?.jwk ? (
|
|
1363
|
-
//doesn't apply to did:jwk only, as you can represent any DID key as a JWK. So whenever you encounter a JWK it doesn't mean it had to come from a did:jwk in the system. It just can always be represented as a did:jwk
|
|
1364
|
-
`did:jwk:${encodeJoseBlob(firstVC.decodedPayload.cnf?.jwk)}#0`
|
|
1365
|
-
) : firstVC.decodedPayload.sub : Array.isArray(firstVC.credentialSubject) ? firstVC.credentialSubject[0].id : firstVC.credentialSubject.id;
|
|
1366
|
-
if (!digitalCredential.kmsKeyRef) {
|
|
1367
|
-
if (!holder) {
|
|
1368
|
-
return Promise.reject(`No holder found and no kmsKeyRef in DB. Cannot determine identifier to use`);
|
|
1302
|
+
get nonce() {
|
|
1303
|
+
if (!this._nonce) {
|
|
1304
|
+
throw Error("No nonce available. Please get authorization request first");
|
|
1369
1305
|
}
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
logger3.debug(`Holder DID not found: ${holder}`);
|
|
1376
|
-
throw e;
|
|
1306
|
+
return this._nonce;
|
|
1307
|
+
}
|
|
1308
|
+
get state() {
|
|
1309
|
+
if (!this._state) {
|
|
1310
|
+
throw Error("No state available. Please get authorization request first");
|
|
1377
1311
|
}
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1312
|
+
return this._state;
|
|
1313
|
+
}
|
|
1314
|
+
clear() {
|
|
1315
|
+
this._nonce = void 0;
|
|
1316
|
+
this._state = void 0;
|
|
1317
|
+
this.verifiedAuthorizationRequest = void 0;
|
|
1318
|
+
return this;
|
|
1319
|
+
}
|
|
1320
|
+
async getSupportedDIDMethods(didPrefix) {
|
|
1321
|
+
const agentMethods = this.getAgentDIDMethodsSupported({
|
|
1322
|
+
didPrefix
|
|
1381
1323
|
});
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1324
|
+
let rpMethods = await this.getRPDIDMethodsSupported({
|
|
1325
|
+
didPrefix,
|
|
1326
|
+
agentMethods
|
|
1327
|
+
});
|
|
1328
|
+
logger3.debug(`RP supports subject syntax types: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`);
|
|
1329
|
+
if (rpMethods.dids.length === 0) {
|
|
1330
|
+
logger3.debug(`RP does not support DIDs. Supported: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`);
|
|
1331
|
+
return [];
|
|
1332
|
+
}
|
|
1333
|
+
let intersection;
|
|
1334
|
+
if (rpMethods.dids.includes("did")) {
|
|
1335
|
+
intersection = agentMethods && agentMethods.length > 0 ? agentMethods : (await getAgentDIDMethods(this.context)).map((method) => convertDidMethod(method, didPrefix));
|
|
1336
|
+
} else if (!agentMethods || agentMethods.length === 0) {
|
|
1337
|
+
intersection = rpMethods.dids?.map((method) => convertDidMethod(method, didPrefix));
|
|
1338
|
+
} else {
|
|
1339
|
+
intersection = agentMethods.filter((value) => rpMethods.dids.includes(value));
|
|
1340
|
+
}
|
|
1341
|
+
if (intersection.length === 0) {
|
|
1342
|
+
throw Error("No matching DID methods between agent and relying party");
|
|
1396
1343
|
}
|
|
1344
|
+
return intersection.map((value) => convertDidMethod(value, didPrefix));
|
|
1397
1345
|
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
const queryResult = DcqlQuery.query(request.dcqlQuery, Array.from(dcqlCredentialsWithCredentials.keys()));
|
|
1403
|
-
if (!queryResult.can_be_satisfied) {
|
|
1404
|
-
return Promise.reject(Error("Credentials do not match required query request"));
|
|
1346
|
+
getAgentDIDMethodsSupported(opts) {
|
|
1347
|
+
const agentMethods = this.options.supportedDIDMethods?.map((method) => convertDidMethod(method, opts.didPrefix));
|
|
1348
|
+
logger3.debug(`agent methods: ${JSON.stringify(agentMethods)}`);
|
|
1349
|
+
return agentMethods;
|
|
1405
1350
|
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1351
|
+
async getSubjectSyntaxTypesSupported() {
|
|
1352
|
+
const authReq = await this.getAuthorizationRequest();
|
|
1353
|
+
const subjectSyntaxTypesSupported = authReq.registrationMetadataPayload?.subject_syntax_types_supported;
|
|
1354
|
+
return subjectSyntaxTypesSupported ?? [];
|
|
1355
|
+
}
|
|
1356
|
+
async getRPDIDMethodsSupported(opts) {
|
|
1357
|
+
let keyType;
|
|
1358
|
+
const agentMethods = (opts.agentMethods ?? this.getAgentDIDMethodsSupported(opts))?.map((method) => convertDidMethod(method, opts.didPrefix)) ?? [];
|
|
1359
|
+
logger3.debug(`agent methods supported: ${JSON.stringify(agentMethods)}`);
|
|
1360
|
+
const authReq = await this.getAuthorizationRequest();
|
|
1361
|
+
const subjectSyntaxTypesSupported = authReq.registrationMetadataPayload?.subject_syntax_types_supported?.map((method) => convertDidMethod(method, opts.didPrefix)).filter((val) => !val.startsWith("did"));
|
|
1362
|
+
logger3.debug(`subject syntax types supported in rp method supported: ${JSON.stringify(subjectSyntaxTypesSupported)}`);
|
|
1363
|
+
const aud = await authReq.authorizationRequest.getMergedProperty("aud");
|
|
1364
|
+
let rpMethods = [];
|
|
1365
|
+
if (aud && aud.startsWith("did:")) {
|
|
1366
|
+
const didMethod = convertDidMethod(parseDid(aud).method, opts.didPrefix);
|
|
1367
|
+
logger3.debug(`aud did method: ${didMethod}`);
|
|
1368
|
+
if (subjectSyntaxTypesSupported && subjectSyntaxTypesSupported.length > 0 && !subjectSyntaxTypesSupported.includes("did") && !subjectSyntaxTypesSupported.includes(didMethod)) {
|
|
1369
|
+
throw Error(`The aud DID method ${didMethod} is not in the supported types ${subjectSyntaxTypesSupported}`);
|
|
1418
1370
|
}
|
|
1419
|
-
|
|
1420
|
-
|
|
1371
|
+
rpMethods = [
|
|
1372
|
+
didMethod
|
|
1373
|
+
];
|
|
1374
|
+
} else if (subjectSyntaxTypesSupported) {
|
|
1375
|
+
rpMethods = (Array.isArray(subjectSyntaxTypesSupported) ? subjectSyntaxTypesSupported : [
|
|
1376
|
+
subjectSyntaxTypesSupported
|
|
1377
|
+
]).map((method) => convertDidMethod(method, opts.didPrefix));
|
|
1378
|
+
}
|
|
1379
|
+
const isEBSI = rpMethods.length === 0 && (authReq.issuer?.includes(".ebsi.eu") || authReq.authorizationRequest.getMergedProperty("client_id")?.includes(".ebsi.eu"));
|
|
1380
|
+
let codecName = void 0;
|
|
1381
|
+
if (isEBSI && (!aud || !aud.startsWith("http"))) {
|
|
1382
|
+
logger3.debug(`EBSI detected, adding did:key to supported DID methods for RP`);
|
|
1383
|
+
const didKeyMethod = convertDidMethod("did:key", opts.didPrefix);
|
|
1384
|
+
if (!agentMethods?.includes(didKeyMethod)) {
|
|
1385
|
+
throw Error(`EBSI detected, but agent did not support did:key. Please reconfigure agent`);
|
|
1421
1386
|
}
|
|
1387
|
+
rpMethods = [
|
|
1388
|
+
didKeyMethod
|
|
1389
|
+
];
|
|
1390
|
+
keyType = "Secp256r1";
|
|
1391
|
+
codecName = "jwk_jcs-pub";
|
|
1422
1392
|
}
|
|
1393
|
+
return {
|
|
1394
|
+
dids: rpMethods,
|
|
1395
|
+
codecName,
|
|
1396
|
+
keyType
|
|
1397
|
+
};
|
|
1423
1398
|
}
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
}
|
|
1430
|
-
});
|
|
1431
|
-
logger3.debug(`Response: `, response);
|
|
1432
|
-
return response;
|
|
1433
|
-
}, "siopSendAuthorizationResponse");
|
|
1434
|
-
var retrieveEncodedCredential = /* @__PURE__ */ __name((credential) => {
|
|
1435
|
-
return credential.originalVerifiableCredential !== void 0 && credential.originalVerifiableCredential !== null && credential?.originalVerifiableCredential?.compactSdJwtVc !== void 0 && credential?.originalVerifiableCredential?.compactSdJwtVc !== null ? credential.originalVerifiableCredential.compactSdJwtVc : credential.originalVerifiableCredential;
|
|
1436
|
-
}, "retrieveEncodedCredential");
|
|
1437
|
-
var getSelectableCredentials = /* @__PURE__ */ __name(async (dcqlQuery, context) => {
|
|
1438
|
-
const agentContext = {
|
|
1439
|
-
...context,
|
|
1440
|
-
agent: context.agent
|
|
1441
|
-
};
|
|
1442
|
-
const { agent } = agentContext;
|
|
1443
|
-
const uniqueVerifiableCredentials = await agent.crsGetUniqueCredentials({
|
|
1444
|
-
filter: verifiableCredentialForRoleFilter(CredentialRole.HOLDER)
|
|
1445
|
-
});
|
|
1446
|
-
const branding = await agent.ibGetCredentialBranding();
|
|
1447
|
-
const dcqlCredentialsWithCredentials = new Map(uniqueVerifiableCredentials.map((vc) => [
|
|
1448
|
-
convertToDcqlCredentials(vc),
|
|
1449
|
-
vc
|
|
1450
|
-
]));
|
|
1451
|
-
const queryResult = DcqlQuery.query(dcqlQuery, Array.from(dcqlCredentialsWithCredentials.keys()));
|
|
1452
|
-
const uniqueCredentials = Array.from(dcqlCredentialsWithCredentials.values());
|
|
1453
|
-
const selectableCredentialsMap = /* @__PURE__ */ new Map();
|
|
1454
|
-
for (const [key, value] of Object.entries(queryResult.credential_matches)) {
|
|
1455
|
-
if (!value.valid_credentials) {
|
|
1456
|
-
continue;
|
|
1399
|
+
async getSupportedIdentifiers(opts) {
|
|
1400
|
+
const methods = await this.getSupportedDIDMethods(true);
|
|
1401
|
+
logger3.debug(`supported DID methods (did: prefix = true): ${JSON.stringify(methods)}`);
|
|
1402
|
+
if (methods.length === 0) {
|
|
1403
|
+
throw Error(`No DID methods are supported`);
|
|
1457
1404
|
}
|
|
1458
|
-
const
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1405
|
+
const identifiers = await this.context.agent.didManagerFind().then((ids) => ids.filter((id) => methods.includes(id.provider)));
|
|
1406
|
+
if (identifiers.length === 0) {
|
|
1407
|
+
logger3.debug(`No identifiers available in agent supporting methods ${JSON.stringify(methods)}`);
|
|
1408
|
+
if (opts?.createInCaseNoDIDFound !== false) {
|
|
1409
|
+
const { codecName, keyType } = await this.getRPDIDMethodsSupported({
|
|
1410
|
+
didPrefix: true,
|
|
1411
|
+
agentMethods: methods
|
|
1412
|
+
});
|
|
1413
|
+
const identifier = await this.context.agent.didManagerCreate({
|
|
1414
|
+
provider: methods[0],
|
|
1415
|
+
options: {
|
|
1416
|
+
codecName,
|
|
1417
|
+
keyType,
|
|
1418
|
+
type: keyType
|
|
1469
1419
|
}
|
|
1470
|
-
|
|
1420
|
+
});
|
|
1421
|
+
logger3.debug(`Created a new identifier for the SIOP interaction: ${identifier.did}`);
|
|
1422
|
+
identifiers.push(identifier);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
logger3.debug(`supported identifiers: ${JSON.stringify(identifiers.map((id) => id.did))}`);
|
|
1426
|
+
return identifiers;
|
|
1427
|
+
}
|
|
1428
|
+
async getSupportedDIDs() {
|
|
1429
|
+
return (await this.getSupportedIdentifiers()).map((id) => id.did);
|
|
1430
|
+
}
|
|
1431
|
+
async getRedirectUri() {
|
|
1432
|
+
return Promise.resolve(this.verifiedAuthorizationRequest.responseURI);
|
|
1433
|
+
}
|
|
1434
|
+
async getOID4VP(args) {
|
|
1435
|
+
return await OID4VP.init(this, args.allIdentifiers ?? [], args.hasher);
|
|
1436
|
+
}
|
|
1437
|
+
async createJarmResponseCallback({ responseOpts }) {
|
|
1438
|
+
const agent = this.context.agent;
|
|
1439
|
+
return /* @__PURE__ */ __name(async function jarmResponse(opts) {
|
|
1440
|
+
const { clientMetadata, requestObjectPayload, authorizationResponsePayload: authResponse } = opts;
|
|
1441
|
+
const jwk = await OP2.extractEncJwksFromClientMetadata(clientMetadata);
|
|
1442
|
+
const recipientKey = await agent.identifierExternalResolveByJwk({
|
|
1443
|
+
identifier: jwk
|
|
1471
1444
|
});
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1445
|
+
return await agent.jwtEncryptJweCompactJwt({
|
|
1446
|
+
recipientKey,
|
|
1447
|
+
protectedHeader: {},
|
|
1448
|
+
alg: requestObjectPayload.client_metadata.authorization_encrypted_response_alg ?? "ECDH-ES",
|
|
1449
|
+
enc: requestObjectPayload.client_metadata.authorization_encrypted_response_enc ?? "A256GCM",
|
|
1450
|
+
apv: encodeBase64url(opts.requestObjectPayload.nonce),
|
|
1451
|
+
apu: encodeBase64url(v4()),
|
|
1452
|
+
payload: authResponse,
|
|
1453
|
+
issuer: responseOpts.issuer,
|
|
1454
|
+
audience: responseOpts.audience
|
|
1455
|
+
}).then((result) => {
|
|
1456
|
+
return {
|
|
1457
|
+
response: result.jwt
|
|
1458
|
+
};
|
|
1482
1459
|
});
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1460
|
+
}, "jarmResponse");
|
|
1461
|
+
}
|
|
1462
|
+
async sendAuthorizationResponse(args) {
|
|
1463
|
+
const { responseSignerOpts, dcqlResponse, isFirstParty } = args;
|
|
1464
|
+
const resolveOpts = this.options.resolveOpts ?? {
|
|
1465
|
+
resolver: getAgentResolver(this.context, {
|
|
1466
|
+
uniresolverResolution: true,
|
|
1467
|
+
localResolution: true,
|
|
1468
|
+
resolverResolution: true
|
|
1469
|
+
})
|
|
1470
|
+
};
|
|
1471
|
+
if (!resolveOpts.subjectSyntaxTypesSupported || resolveOpts.subjectSyntaxTypesSupported.length === 0) {
|
|
1472
|
+
resolveOpts.subjectSyntaxTypesSupported = await this.getSupportedDIDMethods(true);
|
|
1473
|
+
}
|
|
1474
|
+
const request = await this.getAuthorizationRequest();
|
|
1475
|
+
const op = await createOP({
|
|
1476
|
+
opOptions: {
|
|
1477
|
+
...this.options,
|
|
1478
|
+
resolveOpts: {
|
|
1479
|
+
...this.options.resolveOpts
|
|
1480
|
+
},
|
|
1481
|
+
eventEmitter: this.options.eventEmitter,
|
|
1482
|
+
presentationSignCallback: this.options.presentationSignCallback,
|
|
1483
|
+
wellknownDIDVerifyCallback: this.options.wellknownDIDVerifyCallback,
|
|
1484
|
+
supportedVersions: request.versions
|
|
1485
|
+
},
|
|
1486
|
+
idOpts: responseSignerOpts,
|
|
1487
|
+
context: this.context
|
|
1489
1488
|
});
|
|
1490
|
-
|
|
1491
|
-
|
|
1489
|
+
let issuer = responseSignerOpts.issuer;
|
|
1490
|
+
const responseOpts = {
|
|
1491
|
+
issuer,
|
|
1492
|
+
...isFirstParty && {
|
|
1493
|
+
isFirstParty
|
|
1494
|
+
},
|
|
1495
|
+
dcqlResponse
|
|
1496
|
+
};
|
|
1497
|
+
const authResponse = await op.createAuthorizationResponse(request, responseOpts);
|
|
1498
|
+
const response = await op.submitAuthorizationResponse(authResponse, await this.createJarmResponseCallback({
|
|
1499
|
+
responseOpts
|
|
1500
|
+
}));
|
|
1501
|
+
if (response.status >= 400) {
|
|
1502
|
+
throw Error(`Error ${response.status}: ${response.statusText || await response.text()}`);
|
|
1503
|
+
} else {
|
|
1504
|
+
return response;
|
|
1505
|
+
}
|
|
1492
1506
|
}
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
const contacts = await agent.cmGetContacts({
|
|
1498
|
-
filter: [
|
|
1499
|
-
{
|
|
1500
|
-
identities: {
|
|
1501
|
-
identifier: {
|
|
1502
|
-
correlationId
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
]
|
|
1507
|
-
});
|
|
1508
|
-
if (contacts.length === 0) {
|
|
1509
|
-
return void 0;
|
|
1507
|
+
};
|
|
1508
|
+
function convertDidMethod(didMethod, didPrefix) {
|
|
1509
|
+
if (didPrefix === false) {
|
|
1510
|
+
return didMethod.startsWith("did:") ? didMethod.toLowerCase().replace("did:", "") : didMethod.toLowerCase();
|
|
1510
1511
|
}
|
|
1511
|
-
return
|
|
1512
|
-
}
|
|
1512
|
+
return didMethod.startsWith("did:") ? didMethod.toLowerCase() : `did:${didMethod.toLowerCase().replace("did:", "")}`;
|
|
1513
|
+
}
|
|
1514
|
+
__name(convertDidMethod, "convertDidMethod");
|
|
1513
1515
|
|
|
1514
1516
|
// src/agent/DidAuthSiopOpAuthenticator.ts
|
|
1515
1517
|
var logger4 = Loggers4.DEFAULT.options(LOGGER_NAMESPACE, {}).get(LOGGER_NAMESPACE);
|