@credo-ts/openid4vc 0.6.0-pr-2209-20250321171013 → 0.6.0-pr-2195-20250321182650
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/build/openid4vc-holder/OpenId4VcHolderApi.d.ts +126 -21
- package/build/openid4vc-holder/OpenId4VcHolderApi.js +36 -21
- package/build/openid4vc-holder/OpenId4VcHolderApi.js.map +1 -1
- package/build/openid4vc-holder/OpenId4VcHolderModule.js +3 -3
- package/build/openid4vc-holder/OpenId4VcHolderModule.js.map +1 -1
- package/build/openid4vc-holder/OpenId4VciHolderService.d.ts +5 -6
- package/build/openid4vc-holder/OpenId4VciHolderService.js +13 -15
- package/build/openid4vc-holder/OpenId4VciHolderService.js.map +1 -1
- package/build/openid4vc-holder/OpenId4VciHolderServiceOptions.d.ts +3 -3
- package/build/openid4vc-holder/OpenId4VciHolderServiceOptions.js +2 -2
- package/build/openid4vc-holder/OpenId4VciHolderServiceOptions.js.map +1 -1
- package/build/openid4vc-holder/OpenId4vpHolderService.d.ts +132 -0
- package/build/openid4vc-holder/OpenId4vpHolderService.js +317 -0
- package/build/openid4vc-holder/OpenId4vpHolderService.js.map +1 -0
- package/build/openid4vc-holder/OpenId4vpHolderServiceOptions.d.ts +81 -0
- package/build/openid4vc-holder/{OpenId4vcSiopHolderServiceOptions.js → OpenId4vpHolderServiceOptions.js} +1 -1
- package/build/openid4vc-holder/OpenId4vpHolderServiceOptions.js.map +1 -0
- package/build/openid4vc-holder/index.d.ts +2 -2
- package/build/openid4vc-holder/index.js +2 -2
- package/build/openid4vc-holder/index.js.map +1 -1
- package/build/openid4vc-issuer/OpenId4VcIssuerApi.d.ts +194 -44
- package/build/openid4vc-issuer/OpenId4VcIssuerModule.js +1 -1
- package/build/openid4vc-issuer/OpenId4VcIssuerModule.js.map +1 -1
- package/build/openid4vc-issuer/OpenId4VcIssuerModuleConfig.d.ts +7 -7
- package/build/openid4vc-issuer/OpenId4VcIssuerModuleConfig.js +2 -10
- package/build/openid4vc-issuer/OpenId4VcIssuerModuleConfig.js.map +1 -1
- package/build/openid4vc-issuer/OpenId4VcIssuerService.d.ts +197 -48
- package/build/openid4vc-issuer/OpenId4VcIssuerService.js +28 -19
- package/build/openid4vc-issuer/OpenId4VcIssuerService.js.map +1 -1
- package/build/openid4vc-issuer/OpenId4VcIssuerServiceOptions.d.ts +11 -6
- package/build/openid4vc-issuer/repository/OpenId4VcIssuanceSessionRecord.d.ts +11 -1
- package/build/openid4vc-issuer/repository/OpenId4VcIssuanceSessionRecord.js +2 -0
- package/build/openid4vc-issuer/repository/OpenId4VcIssuanceSessionRecord.js.map +1 -1
- package/build/openid4vc-issuer/repository/OpenId4VcIssuerRecord.js +2 -2
- package/build/openid4vc-issuer/repository/OpenId4VcIssuerRecord.js.map +1 -1
- package/build/openid4vc-issuer/router/accessTokenEndpoint.js +1 -1
- package/build/openid4vc-issuer/router/accessTokenEndpoint.js.map +1 -1
- package/build/openid4vc-issuer/router/authorizationChallengeEndpoint.js +1 -1
- package/build/openid4vc-issuer/router/authorizationChallengeEndpoint.js.map +1 -1
- package/build/openid4vc-issuer/router/authorizationServerMetadataEndpoint.js +1 -1
- package/build/openid4vc-issuer/router/authorizationServerMetadataEndpoint.js.map +1 -1
- package/build/openid4vc-issuer/router/credentialEndpoint.js +4 -3
- package/build/openid4vc-issuer/router/credentialEndpoint.js.map +1 -1
- package/build/openid4vc-issuer/router/credentialOfferEndpoint.js +15 -0
- package/build/openid4vc-issuer/router/credentialOfferEndpoint.js.map +1 -1
- package/build/openid4vc-issuer/router/issuerMetadataEndpoint.js +1 -1
- package/build/openid4vc-issuer/router/issuerMetadataEndpoint.js.map +1 -1
- package/build/openid4vc-verifier/OpenId4VcVerifierApi.d.ts +12 -25
- package/build/openid4vc-verifier/OpenId4VcVerifierApi.js +16 -25
- package/build/openid4vc-verifier/OpenId4VcVerifierApi.js.map +1 -1
- package/build/openid4vc-verifier/OpenId4VcVerifierModule.js +5 -8
- package/build/openid4vc-verifier/OpenId4VcVerifierModule.js.map +1 -1
- package/build/openid4vc-verifier/OpenId4VcVerifierModuleConfig.d.ts +30 -7
- package/build/openid4vc-verifier/OpenId4VcVerifierModuleConfig.js +16 -12
- package/build/openid4vc-verifier/OpenId4VcVerifierModuleConfig.js.map +1 -1
- package/build/openid4vc-verifier/OpenId4VpVerifierService.d.ts +51 -0
- package/build/openid4vc-verifier/OpenId4VpVerifierService.js +765 -0
- package/build/openid4vc-verifier/OpenId4VpVerifierService.js.map +1 -0
- package/build/openid4vc-verifier/OpenId4VpVerifierServiceOptions.d.ts +146 -0
- package/build/openid4vc-verifier/{OpenId4VcSiopVerifierServiceOptions.js → OpenId4VpVerifierServiceOptions.js} +1 -1
- package/build/openid4vc-verifier/OpenId4VpVerifierServiceOptions.js.map +1 -0
- package/build/openid4vc-verifier/index.d.ts +2 -2
- package/build/openid4vc-verifier/index.js +2 -2
- package/build/openid4vc-verifier/index.js.map +1 -1
- package/build/openid4vc-verifier/repository/OpenId4VcVerificationSessionRecord.d.ts +39 -14
- package/build/openid4vc-verifier/repository/OpenId4VcVerificationSessionRecord.js +38 -8
- package/build/openid4vc-verifier/repository/OpenId4VcVerificationSessionRecord.js.map +1 -1
- package/build/openid4vc-verifier/repository/OpenId4VcVerifierRecord.d.ts +3 -3
- package/build/openid4vc-verifier/router/authorizationEndpoint.d.ts +2 -10
- package/build/openid4vc-verifier/router/authorizationEndpoint.js +94 -105
- package/build/openid4vc-verifier/router/authorizationEndpoint.js.map +1 -1
- package/build/openid4vc-verifier/router/authorizationRequestEndpoint.d.ts +2 -10
- package/build/openid4vc-verifier/router/authorizationRequestEndpoint.js +21 -22
- package/build/openid4vc-verifier/router/authorizationRequestEndpoint.js.map +1 -1
- package/build/shared/callbacks.d.ts +13 -5
- package/build/shared/callbacks.js +104 -13
- package/build/shared/callbacks.js.map +1 -1
- package/build/shared/issuerMetadataUtils.d.ts +102 -144
- package/build/shared/models/OpenId4VcJwtIssuer.d.ts +2 -3
- package/build/shared/models/index.d.ts +10 -10
- package/build/shared/models/index.js +5 -5
- package/build/shared/models/index.js.map +1 -1
- package/build/shared/router/context.d.ts +3 -3
- package/build/shared/router/context.js +7 -3
- package/build/shared/router/context.js.map +1 -1
- package/build/shared/transactionData.d.ts +5 -0
- package/build/shared/transactionData.js +22 -0
- package/build/shared/transactionData.js.map +1 -0
- package/build/shared/utils.d.ts +6 -8
- package/build/shared/utils.js +34 -105
- package/build/shared/utils.js.map +1 -1
- package/package.json +7 -8
- package/build/openid4vc-holder/OpenId4vcSiopHolderService.d.ts +0 -32
- package/build/openid4vc-holder/OpenId4vcSiopHolderService.js +0 -300
- package/build/openid4vc-holder/OpenId4vcSiopHolderService.js.map +0 -1
- package/build/openid4vc-holder/OpenId4vcSiopHolderServiceOptions.d.ts +0 -38
- package/build/openid4vc-holder/OpenId4vcSiopHolderServiceOptions.js.map +0 -1
- package/build/openid4vc-verifier/OpenId4VcSiopVerifierService.d.ts +0 -55
- package/build/openid4vc-verifier/OpenId4VcSiopVerifierService.js +0 -553
- package/build/openid4vc-verifier/OpenId4VcSiopVerifierService.js.map +0 -1
- package/build/openid4vc-verifier/OpenId4VcSiopVerifierServiceOptions.d.ts +0 -77
- package/build/openid4vc-verifier/OpenId4VcSiopVerifierServiceOptions.js.map +0 -1
- package/build/openid4vc-verifier/repository/OpenId4VcRelyingPartyEventEmitter.d.ts +0 -49
- package/build/openid4vc-verifier/repository/OpenId4VcRelyingPartyEventEmitter.js +0 -230
- package/build/openid4vc-verifier/repository/OpenId4VcRelyingPartyEventEmitter.js.map +0 -1
- package/build/openid4vc-verifier/repository/OpenId4VcRelyingPartySessionManager.d.ts +0 -19
- package/build/openid4vc-verifier/repository/OpenId4VcRelyingPartySessionManager.js +0 -144
- package/build/openid4vc-verifier/repository/OpenId4VcRelyingPartySessionManager.js.map +0 -1
- package/build/shared/transform.d.ts +0 -5
- package/build/shared/transform.js +0 -69
- package/build/shared/transform.js.map +0 -1
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { DifPexCredentialsForRequest, DifPexInputDescriptorToCredentials, DifPresentationExchangeDefinition } from '@credo-ts/core';
|
|
2
|
-
import type { OpenId4VcJwtIssuer, OpenId4VcSiopVerifiedAuthorizationRequest } from '../shared';
|
|
3
|
-
export interface OpenId4VcSiopResolvedAuthorizationRequest {
|
|
4
|
-
/**
|
|
5
|
-
* Parameters related to DIF Presentation Exchange. Only defined when
|
|
6
|
-
* the request included
|
|
7
|
-
*/
|
|
8
|
-
presentationExchange?: {
|
|
9
|
-
definition: DifPresentationExchangeDefinition;
|
|
10
|
-
credentialsForRequest: DifPexCredentialsForRequest;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* The verified authorization request.
|
|
14
|
-
*/
|
|
15
|
-
authorizationRequest: OpenId4VcSiopVerifiedAuthorizationRequest;
|
|
16
|
-
}
|
|
17
|
-
export interface OpenId4VcSiopAcceptAuthorizationRequestOptions {
|
|
18
|
-
/**
|
|
19
|
-
* Parameters related to DIF Presentation Exchange. MUST be present when the resolved
|
|
20
|
-
* authorization request included a `presentationExchange` parameter.
|
|
21
|
-
*/
|
|
22
|
-
presentationExchange?: {
|
|
23
|
-
credentials: DifPexInputDescriptorToCredentials;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* The issuer of the ID Token.
|
|
27
|
-
*
|
|
28
|
-
* REQUIRED when presentation exchange is not used.
|
|
29
|
-
*
|
|
30
|
-
* In case presentation exchange is used, and `openIdTokenIssuer` is not provided, the issuer of the ID Token
|
|
31
|
-
* will be extracted from the signer of the first verifiable presentation.
|
|
32
|
-
*/
|
|
33
|
-
openIdTokenIssuer?: OpenId4VcJwtIssuer;
|
|
34
|
-
/**
|
|
35
|
-
* The verified authorization request.
|
|
36
|
-
*/
|
|
37
|
-
authorizationRequest: OpenId4VcSiopVerifiedAuthorizationRequest;
|
|
38
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OpenId4vcSiopHolderServiceOptions.js","sourceRoot":"","sources":["../../src/openid4vc-holder/OpenId4vcSiopHolderServiceOptions.ts"],"names":[],"mappings":""}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { AgentContext, Query, QueryOptions } from '@credo-ts/core';
|
|
2
|
-
import type { OpenId4VcSiopAuthorizationResponsePayload } from '../shared';
|
|
3
|
-
import type { OpenId4VcSiopCreateAuthorizationRequestOptions, OpenId4VcSiopCreateAuthorizationRequestReturn, OpenId4VcSiopCreateVerifierOptions, OpenId4VcSiopVerifiedAuthorizationResponse, OpenId4VcSiopVerifyAuthorizationResponseOptions } from './OpenId4VcSiopVerifierServiceOptions';
|
|
4
|
-
import type { OpenId4VcVerificationSessionRecord } from './repository';
|
|
5
|
-
import { Logger, W3cCredentialService } from '@credo-ts/core';
|
|
6
|
-
import { OpenId4VcVerifierModuleConfig } from './OpenId4VcVerifierModuleConfig';
|
|
7
|
-
import { OpenId4VcVerificationSessionRepository, OpenId4VcVerifierRecord, OpenId4VcVerifierRepository } from './repository';
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export declare class OpenId4VcSiopVerifierService {
|
|
12
|
-
private logger;
|
|
13
|
-
private w3cCredentialService;
|
|
14
|
-
private openId4VcVerifierRepository;
|
|
15
|
-
private config;
|
|
16
|
-
private openId4VcVerificationSessionRepository;
|
|
17
|
-
constructor(logger: Logger, w3cCredentialService: W3cCredentialService, openId4VcVerifierRepository: OpenId4VcVerifierRepository, config: OpenId4VcVerifierModuleConfig, openId4VcVerificationSessionRepository: OpenId4VcVerificationSessionRepository);
|
|
18
|
-
createAuthorizationRequest(agentContext: AgentContext, options: OpenId4VcSiopCreateAuthorizationRequestOptions & {
|
|
19
|
-
verifier: OpenId4VcVerifierRecord;
|
|
20
|
-
}): Promise<OpenId4VcSiopCreateAuthorizationRequestReturn>;
|
|
21
|
-
verifyAuthorizationResponse(agentContext: AgentContext, options: OpenId4VcSiopVerifyAuthorizationResponseOptions & {
|
|
22
|
-
verificationSession: OpenId4VcVerificationSessionRecord;
|
|
23
|
-
jarmHeader?: {
|
|
24
|
-
apu?: string;
|
|
25
|
-
apv?: string;
|
|
26
|
-
};
|
|
27
|
-
}): Promise<OpenId4VcSiopVerifiedAuthorizationResponse & {
|
|
28
|
-
verificationSession: OpenId4VcVerificationSessionRecord;
|
|
29
|
-
}>;
|
|
30
|
-
getVerifiedAuthorizationResponse(verificationSession: OpenId4VcVerificationSessionRecord): Promise<OpenId4VcSiopVerifiedAuthorizationResponse>;
|
|
31
|
-
/**
|
|
32
|
-
* Find the verification session associated with an authorization response. You can optionally provide a verifier id
|
|
33
|
-
* if the verifier that the response is associated with is already known.
|
|
34
|
-
*/
|
|
35
|
-
findVerificationSessionForAuthorizationResponse(agentContext: AgentContext, { authorizationResponse, authorizationResponseParams, verifierId, }: {
|
|
36
|
-
authorizationResponse?: never;
|
|
37
|
-
authorizationResponseParams: {
|
|
38
|
-
state?: string;
|
|
39
|
-
nonce?: string;
|
|
40
|
-
};
|
|
41
|
-
verifierId?: string;
|
|
42
|
-
} | {
|
|
43
|
-
authorizationResponse: OpenId4VcSiopAuthorizationResponsePayload;
|
|
44
|
-
authorizationResponseParams?: never;
|
|
45
|
-
verifierId?: string;
|
|
46
|
-
}): Promise<OpenId4VcVerificationSessionRecord | null>;
|
|
47
|
-
getAllVerifiers(agentContext: AgentContext): Promise<OpenId4VcVerifierRecord[]>;
|
|
48
|
-
getVerifierByVerifierId(agentContext: AgentContext, verifierId: string): Promise<OpenId4VcVerifierRecord>;
|
|
49
|
-
updateVerifier(agentContext: AgentContext, verifier: OpenId4VcVerifierRecord): Promise<void>;
|
|
50
|
-
createVerifier(agentContext: AgentContext, options?: OpenId4VcSiopCreateVerifierOptions): Promise<OpenId4VcVerifierRecord>;
|
|
51
|
-
findVerificationSessionsByQuery(agentContext: AgentContext, query: Query<OpenId4VcVerificationSessionRecord>, queryOptions?: QueryOptions): Promise<OpenId4VcVerificationSessionRecord[]>;
|
|
52
|
-
getVerificationSessionById(agentContext: AgentContext, verificationSessionId: string): Promise<OpenId4VcVerificationSessionRecord>;
|
|
53
|
-
private getRelyingParty;
|
|
54
|
-
private getPresentationVerificationCallback;
|
|
55
|
-
}
|
|
@@ -1,553 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.OpenId4VcSiopVerifierService = void 0;
|
|
16
|
-
const core_1 = require("@credo-ts/core");
|
|
17
|
-
const did_auth_siop_1 = require("@sphereon/did-auth-siop");
|
|
18
|
-
const OpenID4VP_1 = require("@sphereon/did-auth-siop/dist/authorization-response/OpenID4VP");
|
|
19
|
-
const rxjs_1 = require("rxjs");
|
|
20
|
-
const router_1 = require("../shared/router");
|
|
21
|
-
const transform_1 = require("../shared/transform");
|
|
22
|
-
const utils_1 = require("../shared/utils");
|
|
23
|
-
const OpenId4VcVerificationSessionState_1 = require("./OpenId4VcVerificationSessionState");
|
|
24
|
-
const OpenId4VcVerifierModuleConfig_1 = require("./OpenId4VcVerifierModuleConfig");
|
|
25
|
-
const repository_1 = require("./repository");
|
|
26
|
-
const OpenId4VcRelyingPartyEventEmitter_1 = require("./repository/OpenId4VcRelyingPartyEventEmitter");
|
|
27
|
-
const OpenId4VcRelyingPartySessionManager_1 = require("./repository/OpenId4VcRelyingPartySessionManager");
|
|
28
|
-
/**
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
let OpenId4VcSiopVerifierService = class OpenId4VcSiopVerifierService {
|
|
32
|
-
constructor(logger, w3cCredentialService, openId4VcVerifierRepository, config, openId4VcVerificationSessionRepository) {
|
|
33
|
-
this.logger = logger;
|
|
34
|
-
this.w3cCredentialService = w3cCredentialService;
|
|
35
|
-
this.openId4VcVerifierRepository = openId4VcVerifierRepository;
|
|
36
|
-
this.config = config;
|
|
37
|
-
this.openId4VcVerificationSessionRepository = openId4VcVerificationSessionRepository;
|
|
38
|
-
}
|
|
39
|
-
async createAuthorizationRequest(agentContext, options) {
|
|
40
|
-
const nonce = await agentContext.wallet.generateNonce();
|
|
41
|
-
const state = await agentContext.wallet.generateNonce();
|
|
42
|
-
// Correlation id will be the id of the verification session record
|
|
43
|
-
const correlationId = core_1.utils.uuid();
|
|
44
|
-
let authorizationResponseUrl = (0, core_1.joinUriParts)(this.config.baseUrl, [
|
|
45
|
-
options.verifier.verifierId,
|
|
46
|
-
this.config.authorizationEndpoint.endpointPath,
|
|
47
|
-
]);
|
|
48
|
-
const jwtIssuer = options.requestSigner.method === 'x5c'
|
|
49
|
-
? await (0, utils_1.openIdTokenIssuerToJwtIssuer)(agentContext, {
|
|
50
|
-
...options.requestSigner,
|
|
51
|
-
issuer: authorizationResponseUrl,
|
|
52
|
-
})
|
|
53
|
-
: await (0, utils_1.openIdTokenIssuerToJwtIssuer)(agentContext, options.requestSigner);
|
|
54
|
-
let clientIdScheme;
|
|
55
|
-
let clientId;
|
|
56
|
-
if (jwtIssuer.method === 'x5c') {
|
|
57
|
-
if (jwtIssuer.issuer !== authorizationResponseUrl) {
|
|
58
|
-
throw new core_1.CredoError(`The jwtIssuer's issuer field must match the verifier's authorizationResponseUrl '${authorizationResponseUrl}'.`);
|
|
59
|
-
}
|
|
60
|
-
const leafCertificate = core_1.X509Service.getLeafCertificate(agentContext, { certificateChain: jwtIssuer.x5c });
|
|
61
|
-
if (leafCertificate.sanDnsNames.includes((0, core_1.getDomainFromUrl)(jwtIssuer.issuer))) {
|
|
62
|
-
clientIdScheme = 'x509_san_dns';
|
|
63
|
-
clientId = (0, core_1.getDomainFromUrl)(jwtIssuer.issuer);
|
|
64
|
-
authorizationResponseUrl = jwtIssuer.issuer;
|
|
65
|
-
}
|
|
66
|
-
else if (leafCertificate.sanUriNames.includes(jwtIssuer.issuer)) {
|
|
67
|
-
clientIdScheme = 'x509_san_uri';
|
|
68
|
-
clientId = jwtIssuer.issuer;
|
|
69
|
-
authorizationResponseUrl = clientId;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
throw new core_1.CredoError(`With jwtIssuer 'method' 'x5c' the jwtIssuer's 'issuer' field must either match the match a sanDnsName (FQDN) or sanUriName in the leaf x509 chain's leaf certificate.`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else if (jwtIssuer.method === 'did') {
|
|
76
|
-
clientId = jwtIssuer.didUrl.split('#')[0];
|
|
77
|
-
clientIdScheme = 'did';
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
throw new core_1.CredoError(`Unsupported jwt issuer method '${options.requestSigner.method}'. Only 'did' and 'x5c' are supported.`);
|
|
81
|
-
}
|
|
82
|
-
const relyingParty = await this.getRelyingParty(agentContext, options.verifier, {
|
|
83
|
-
presentationDefinition: options.presentationExchange?.definition,
|
|
84
|
-
authorizationResponseUrl,
|
|
85
|
-
clientId,
|
|
86
|
-
clientIdScheme,
|
|
87
|
-
responseMode: options.responseMode,
|
|
88
|
-
});
|
|
89
|
-
// We always use shortened URIs currently
|
|
90
|
-
const hostedAuthorizationRequestUri = (0, core_1.joinUriParts)(this.config.baseUrl, [
|
|
91
|
-
options.verifier.verifierId,
|
|
92
|
-
this.config.authorizationRequestEndpoint.endpointPath,
|
|
93
|
-
// It doesn't really matter what the url is, as long as it's unique
|
|
94
|
-
core_1.utils.uuid(),
|
|
95
|
-
]);
|
|
96
|
-
// This is very unfortunate, but storing state in sphereon's SiOP-OID4VP library
|
|
97
|
-
// is done async, so we can't be certain yet that the verification session record
|
|
98
|
-
// is created already when we have created the authorization request. So we need to
|
|
99
|
-
// wait for a short while before we can be certain that the verification session record
|
|
100
|
-
// is created. To not use arbitrary timeouts, we wait for the specific RecordSavedEvent
|
|
101
|
-
// that is emitted when the verification session record is created.
|
|
102
|
-
const eventEmitter = agentContext.dependencyManager.resolve(core_1.EventEmitter);
|
|
103
|
-
const verificationSessionCreatedPromise = (0, rxjs_1.firstValueFrom)(eventEmitter
|
|
104
|
-
.observable(core_1.RepositoryEventTypes.RecordSaved)
|
|
105
|
-
.pipe((0, rxjs_1.filter)((e) => e.metadata.contextCorrelationId === agentContext.contextCorrelationId), (0, rxjs_1.filter)((e) => e.payload.record.id === correlationId && e.payload.record.verifierId === options.verifier.verifierId), (0, rxjs_1.first)(), (0, rxjs_1.timeout)({
|
|
106
|
-
first: 10000,
|
|
107
|
-
meta: 'OpenId4VcSiopVerifierService.createAuthorizationRequest',
|
|
108
|
-
}), (0, rxjs_1.map)((e) => e.payload.record)));
|
|
109
|
-
const authorizationRequest = await relyingParty.createAuthorizationRequest({
|
|
110
|
-
correlationId,
|
|
111
|
-
nonce,
|
|
112
|
-
state,
|
|
113
|
-
requestByReferenceURI: hostedAuthorizationRequestUri,
|
|
114
|
-
jwtIssuer,
|
|
115
|
-
});
|
|
116
|
-
// NOTE: it's not possible to set the uri scheme when using the RP to create an auth request, only lower level
|
|
117
|
-
// functions allow this. So we need to replace the uri scheme manually.
|
|
118
|
-
let authorizationRequestUri = (await authorizationRequest.uri()).encodedUri;
|
|
119
|
-
if (options.presentationExchange && !options.idToken) {
|
|
120
|
-
authorizationRequestUri = authorizationRequestUri.replace('openid://', 'openid4vp://');
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
authorizationRequestUri = authorizationRequestUri.replace('openid4vp://', 'openid://');
|
|
124
|
-
}
|
|
125
|
-
const verificationSession = await verificationSessionCreatedPromise;
|
|
126
|
-
return {
|
|
127
|
-
authorizationRequest: authorizationRequestUri,
|
|
128
|
-
verificationSession,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
async verifyAuthorizationResponse(agentContext, options) {
|
|
132
|
-
// Assert state
|
|
133
|
-
options.verificationSession.assertState([
|
|
134
|
-
OpenId4VcVerificationSessionState_1.OpenId4VcVerificationSessionState.RequestUriRetrieved,
|
|
135
|
-
OpenId4VcVerificationSessionState_1.OpenId4VcVerificationSessionState.RequestCreated,
|
|
136
|
-
]);
|
|
137
|
-
const authorizationRequest = await did_auth_siop_1.AuthorizationRequest.fromUriOrJwt(options.verificationSession.authorizationRequestJwt);
|
|
138
|
-
const verifier = await this.getVerifierByVerifierId(agentContext, options.verificationSession.verifierId);
|
|
139
|
-
const requestClientId = await authorizationRequest.getMergedProperty('client_id');
|
|
140
|
-
const requestNonce = await authorizationRequest.getMergedProperty('nonce');
|
|
141
|
-
const requestState = await authorizationRequest.getMergedProperty('state');
|
|
142
|
-
const responseUri = await authorizationRequest.getMergedProperty('response_uri');
|
|
143
|
-
const presentationDefinitionsWithLocation = await authorizationRequest.getPresentationDefinitions();
|
|
144
|
-
if (!requestNonce || !requestClientId || !requestState) {
|
|
145
|
-
throw new core_1.CredoError(`Unable to find nonce, state, or client_id in authorization request for verification session '${options.verificationSession.id}'`);
|
|
146
|
-
}
|
|
147
|
-
const authorizationResponseUrl = (0, core_1.joinUriParts)(this.config.baseUrl, [
|
|
148
|
-
options.verificationSession.verifierId,
|
|
149
|
-
this.config.authorizationEndpoint.endpointPath,
|
|
150
|
-
]);
|
|
151
|
-
const relyingParty = await this.getRelyingParty(agentContext, verifier, {
|
|
152
|
-
presentationDefinition: presentationDefinitionsWithLocation?.[0]?.definition,
|
|
153
|
-
authorizationResponseUrl,
|
|
154
|
-
clientId: requestClientId,
|
|
155
|
-
});
|
|
156
|
-
// This is very unfortunate, but storing state in sphereon's SiOP-OID4VP library
|
|
157
|
-
// is done async, so we can't be certain yet that the verification session record
|
|
158
|
-
// is updated already when we have verified the authorization response. So we need to
|
|
159
|
-
// wait for a short while before we can be certain that the verification session record
|
|
160
|
-
// is updated. To not use arbitrary timeouts, we wait for the specific RecordUpdatedEvent
|
|
161
|
-
// that is emitted when the verification session record is updated.
|
|
162
|
-
const eventEmitter = agentContext.dependencyManager.resolve(core_1.EventEmitter);
|
|
163
|
-
const verificationSessionUpdatedPromise = (0, rxjs_1.firstValueFrom)(eventEmitter
|
|
164
|
-
.observable(core_1.RepositoryEventTypes.RecordUpdated)
|
|
165
|
-
.pipe((0, rxjs_1.filter)((e) => e.metadata.contextCorrelationId === agentContext.contextCorrelationId), (0, rxjs_1.filter)((e) => e.payload.record.id === options.verificationSession.id &&
|
|
166
|
-
e.payload.record.verifierId === options.verificationSession.verifierId &&
|
|
167
|
-
(e.payload.record.state === OpenId4VcVerificationSessionState_1.OpenId4VcVerificationSessionState.ResponseVerified ||
|
|
168
|
-
e.payload.record.state === OpenId4VcVerificationSessionState_1.OpenId4VcVerificationSessionState.Error)), (0, rxjs_1.first)(), (0, rxjs_1.timeout)({
|
|
169
|
-
first: 10000,
|
|
170
|
-
meta: 'OpenId4VcSiopVerifierService.verifyAuthorizationResponse',
|
|
171
|
-
}), (0, rxjs_1.map)((e) => e.payload.record)));
|
|
172
|
-
await relyingParty.verifyAuthorizationResponse(options.authorizationResponse, {
|
|
173
|
-
audience: requestClientId,
|
|
174
|
-
correlationId: options.verificationSession.id,
|
|
175
|
-
state: requestState,
|
|
176
|
-
presentationDefinitions: presentationDefinitionsWithLocation,
|
|
177
|
-
verification: {
|
|
178
|
-
presentationVerificationCallback: this.getPresentationVerificationCallback(agentContext, {
|
|
179
|
-
correlationId: options.verificationSession.id,
|
|
180
|
-
nonce: requestNonce,
|
|
181
|
-
audience: requestClientId,
|
|
182
|
-
responseUri,
|
|
183
|
-
mdocGeneratedNonce: options.jarmHeader?.apu
|
|
184
|
-
? core_1.TypedArrayEncoder.toUtf8String(core_1.TypedArrayEncoder.fromBase64(options.jarmHeader.apu))
|
|
185
|
-
: undefined,
|
|
186
|
-
verificationSessionRecordId: options.verificationSession.id,
|
|
187
|
-
}),
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
const verificationSession = await verificationSessionUpdatedPromise;
|
|
191
|
-
const verifiedAuthorizationResponse = await this.getVerifiedAuthorizationResponse(verificationSession);
|
|
192
|
-
return {
|
|
193
|
-
...verifiedAuthorizationResponse,
|
|
194
|
-
verificationSession: await verificationSessionUpdatedPromise,
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
async getVerifiedAuthorizationResponse(verificationSession) {
|
|
198
|
-
verificationSession.assertState(OpenId4VcVerificationSessionState_1.OpenId4VcVerificationSessionState.ResponseVerified);
|
|
199
|
-
if (!verificationSession.authorizationResponsePayload) {
|
|
200
|
-
throw new core_1.CredoError('No authorization response payload found in the verification session.');
|
|
201
|
-
}
|
|
202
|
-
const authorizationResponse = await did_auth_siop_1.AuthorizationResponse.fromPayload(verificationSession.authorizationResponsePayload);
|
|
203
|
-
const authorizationRequest = await did_auth_siop_1.AuthorizationRequest.fromUriOrJwt(verificationSession.authorizationRequestJwt);
|
|
204
|
-
const idToken = authorizationResponse.idToken
|
|
205
|
-
? { payload: await authorizationResponse.idToken?.payload() }
|
|
206
|
-
: undefined;
|
|
207
|
-
let presentationExchange = undefined;
|
|
208
|
-
const presentationDefinitions = await authorizationRequest.getPresentationDefinitions();
|
|
209
|
-
if (presentationDefinitions && presentationDefinitions.length > 0) {
|
|
210
|
-
const rawPresentations = authorizationResponse.payload.vp_token
|
|
211
|
-
? await (0, OpenID4VP_1.extractPresentationsFromVpToken)(authorizationResponse.payload.vp_token, {
|
|
212
|
-
hasher: core_1.Hasher.hash,
|
|
213
|
-
})
|
|
214
|
-
: [];
|
|
215
|
-
// TODO: Probably wise to check against request for the location of the submission_data
|
|
216
|
-
const submission = idToken?.payload?._vp_token?.presentation_submission ?? authorizationResponse.payload.presentation_submission;
|
|
217
|
-
if (!submission) {
|
|
218
|
-
throw new core_1.CredoError('Unable to extract submission from the response.');
|
|
219
|
-
}
|
|
220
|
-
// FIXME: should return type be an array? As now it doesn't always match the submission
|
|
221
|
-
const verifiablePresentations = Array.isArray(rawPresentations)
|
|
222
|
-
? rawPresentations.map(transform_1.getVerifiablePresentationFromSphereonWrapped)
|
|
223
|
-
: (0, transform_1.getVerifiablePresentationFromSphereonWrapped)(rawPresentations);
|
|
224
|
-
const definition = presentationDefinitions[0].definition;
|
|
225
|
-
presentationExchange = {
|
|
226
|
-
definition,
|
|
227
|
-
submission,
|
|
228
|
-
// We always return this as an array
|
|
229
|
-
presentations: Array.isArray(verifiablePresentations) ? verifiablePresentations : [verifiablePresentations],
|
|
230
|
-
descriptors: (0, core_1.extractPresentationsWithDescriptorsFromSubmission)(verifiablePresentations, submission, definition),
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
if (!idToken && !presentationExchange) {
|
|
234
|
-
throw new core_1.CredoError('No idToken or presentationExchange found in the response.');
|
|
235
|
-
}
|
|
236
|
-
return {
|
|
237
|
-
idToken,
|
|
238
|
-
presentationExchange,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Find the verification session associated with an authorization response. You can optionally provide a verifier id
|
|
243
|
-
* if the verifier that the response is associated with is already known.
|
|
244
|
-
*/
|
|
245
|
-
async findVerificationSessionForAuthorizationResponse(agentContext, { authorizationResponse, authorizationResponseParams, verifierId, }) {
|
|
246
|
-
let nonce;
|
|
247
|
-
let state;
|
|
248
|
-
if (authorizationResponse) {
|
|
249
|
-
const authorizationResponseInstance = await did_auth_siop_1.AuthorizationResponse.fromPayload(authorizationResponse).catch(() => {
|
|
250
|
-
throw new core_1.CredoError(`Unable to parse authorization response payload. ${JSON.stringify(authorizationResponse)}`);
|
|
251
|
-
});
|
|
252
|
-
nonce = await authorizationResponseInstance.getMergedProperty('nonce', {
|
|
253
|
-
hasher: core_1.Hasher.hash,
|
|
254
|
-
});
|
|
255
|
-
state = await authorizationResponseInstance.getMergedProperty('state', {
|
|
256
|
-
hasher: core_1.Hasher.hash,
|
|
257
|
-
});
|
|
258
|
-
if (!nonce && !state) {
|
|
259
|
-
throw new core_1.CredoError('Could not extract nonce or state from authorization response. Unable to find OpenId4VcVerificationSession.');
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
if (authorizationResponseParams?.nonce && !authorizationResponseParams?.state) {
|
|
264
|
-
throw new core_1.CredoError('Either nonce or state must be provided if no authorization response is provided. Unable to find OpenId4VcVerificationSession.');
|
|
265
|
-
}
|
|
266
|
-
nonce = authorizationResponseParams?.nonce;
|
|
267
|
-
state = authorizationResponseParams?.state;
|
|
268
|
-
}
|
|
269
|
-
const verificationSession = await this.openId4VcVerificationSessionRepository.findSingleByQuery(agentContext, {
|
|
270
|
-
nonce,
|
|
271
|
-
payloadState: state,
|
|
272
|
-
verifierId,
|
|
273
|
-
});
|
|
274
|
-
return verificationSession;
|
|
275
|
-
}
|
|
276
|
-
async getAllVerifiers(agentContext) {
|
|
277
|
-
return this.openId4VcVerifierRepository.getAll(agentContext);
|
|
278
|
-
}
|
|
279
|
-
async getVerifierByVerifierId(agentContext, verifierId) {
|
|
280
|
-
return this.openId4VcVerifierRepository.getByVerifierId(agentContext, verifierId);
|
|
281
|
-
}
|
|
282
|
-
async updateVerifier(agentContext, verifier) {
|
|
283
|
-
return this.openId4VcVerifierRepository.update(agentContext, verifier);
|
|
284
|
-
}
|
|
285
|
-
async createVerifier(agentContext, options) {
|
|
286
|
-
const openId4VcVerifier = new repository_1.OpenId4VcVerifierRecord({
|
|
287
|
-
verifierId: options?.verifierId ?? core_1.utils.uuid(),
|
|
288
|
-
clientMetadata: options?.clientMetadata,
|
|
289
|
-
});
|
|
290
|
-
await this.openId4VcVerifierRepository.save(agentContext, openId4VcVerifier);
|
|
291
|
-
await (0, router_1.storeActorIdForContextCorrelationId)(agentContext, openId4VcVerifier.verifierId);
|
|
292
|
-
return openId4VcVerifier;
|
|
293
|
-
}
|
|
294
|
-
async findVerificationSessionsByQuery(agentContext, query, queryOptions) {
|
|
295
|
-
return this.openId4VcVerificationSessionRepository.findByQuery(agentContext, query, queryOptions);
|
|
296
|
-
}
|
|
297
|
-
async getVerificationSessionById(agentContext, verificationSessionId) {
|
|
298
|
-
return this.openId4VcVerificationSessionRepository.getById(agentContext, verificationSessionId);
|
|
299
|
-
}
|
|
300
|
-
async getRelyingParty(agentContext, verifier, { idToken, presentationDefinition, clientId, clientIdScheme, authorizationResponseUrl, responseMode, }) {
|
|
301
|
-
const signatureSuiteRegistry = agentContext.dependencyManager.resolve(core_1.SignatureSuiteRegistry);
|
|
302
|
-
const supportedAlgs = (0, utils_1.getSupportedJwaSignatureAlgorithms)(agentContext);
|
|
303
|
-
const supportedMdocAlgs = supportedAlgs.filter(core_1.isMdocSupportedSignatureAlgorithm);
|
|
304
|
-
const supportedProofTypes = signatureSuiteRegistry.supportedProofTypes;
|
|
305
|
-
// Check: audience must be set to the issuer with dynamic disc otherwise self-issued.me/v2.
|
|
306
|
-
const builder = did_auth_siop_1.RP.builder();
|
|
307
|
-
const responseTypes = [];
|
|
308
|
-
if (!presentationDefinition && idToken === false) {
|
|
309
|
-
throw new core_1.CredoError('Either `presentationExchange` or `idToken` must be enabled');
|
|
310
|
-
}
|
|
311
|
-
if (presentationDefinition) {
|
|
312
|
-
responseTypes.push(did_auth_siop_1.ResponseType.VP_TOKEN);
|
|
313
|
-
}
|
|
314
|
-
if (idToken === true || !presentationDefinition) {
|
|
315
|
-
responseTypes.push(did_auth_siop_1.ResponseType.ID_TOKEN);
|
|
316
|
-
}
|
|
317
|
-
// FIXME: we now manually remove did:peer, we should probably allow the user to configure this
|
|
318
|
-
const supportedDidMethods = agentContext.dependencyManager
|
|
319
|
-
.resolve(core_1.DidsApi)
|
|
320
|
-
.supportedResolverMethods.filter((m) => m !== 'peer');
|
|
321
|
-
// The OpenId4VcRelyingPartyEventHandler is a global event handler that makes sure that
|
|
322
|
-
// all the events are handled, and that the correct context is used for the events.
|
|
323
|
-
const sphereonEventEmitter = agentContext.dependencyManager
|
|
324
|
-
.resolve(OpenId4VcRelyingPartyEventEmitter_1.OpenId4VcRelyingPartyEventHandler)
|
|
325
|
-
.getEventEmitterForVerifier(agentContext.contextCorrelationId, verifier.verifierId);
|
|
326
|
-
const mode = !responseMode || responseMode === 'direct_post'
|
|
327
|
-
? did_auth_siop_1.ResponseMode.DIRECT_POST
|
|
328
|
-
: did_auth_siop_1.ResponseMode.DIRECT_POST_JWT;
|
|
329
|
-
let jarmEncryptionJwk;
|
|
330
|
-
if (mode === did_auth_siop_1.ResponseMode.DIRECT_POST_JWT) {
|
|
331
|
-
const key = await agentContext.wallet.createKey({ keyType: core_1.KeyType.P256 });
|
|
332
|
-
jarmEncryptionJwk = { ...(0, core_1.getJwkFromKey)(key).toJson(), kid: key.fingerprint, use: 'enc' };
|
|
333
|
-
}
|
|
334
|
-
const jarmClientMetadata = jarmEncryptionJwk
|
|
335
|
-
? {
|
|
336
|
-
jwks: { keys: [jarmEncryptionJwk] },
|
|
337
|
-
authorization_encrypted_response_alg: 'ECDH-ES',
|
|
338
|
-
authorization_encrypted_response_enc: 'A256GCM',
|
|
339
|
-
}
|
|
340
|
-
: undefined;
|
|
341
|
-
builder
|
|
342
|
-
.withClientId(clientId)
|
|
343
|
-
.withResponseUri(authorizationResponseUrl)
|
|
344
|
-
.withIssuer(did_auth_siop_1.ResponseIss.SELF_ISSUED_V2)
|
|
345
|
-
.withAudience(did_auth_siop_1.RequestAud.SELF_ISSUED_V2)
|
|
346
|
-
.withIssuer(did_auth_siop_1.ResponseIss.SELF_ISSUED_V2)
|
|
347
|
-
.withSupportedVersions([
|
|
348
|
-
did_auth_siop_1.SupportedVersion.SIOPv2_D11,
|
|
349
|
-
did_auth_siop_1.SupportedVersion.SIOPv2_D12_OID4VP_D18,
|
|
350
|
-
did_auth_siop_1.SupportedVersion.SIOPv2_D12_OID4VP_D20,
|
|
351
|
-
])
|
|
352
|
-
.withResponseMode(mode)
|
|
353
|
-
.withHasher(core_1.Hasher.hash)
|
|
354
|
-
// FIXME: should allow verification of revocation
|
|
355
|
-
// .withRevocationVerificationCallback()
|
|
356
|
-
.withRevocationVerification(did_auth_siop_1.RevocationVerification.NEVER)
|
|
357
|
-
.withSessionManager(new OpenId4VcRelyingPartySessionManager_1.OpenId4VcRelyingPartySessionManager(agentContext, verifier.verifierId))
|
|
358
|
-
.withEventEmitter(sphereonEventEmitter)
|
|
359
|
-
.withResponseType(responseTypes)
|
|
360
|
-
.withCreateJwtCallback((0, utils_1.getCreateJwtCallback)(agentContext))
|
|
361
|
-
.withVerifyJwtCallback((0, utils_1.getVerifyJwtCallback)(agentContext))
|
|
362
|
-
// TODO: we should probably allow some dynamic values here
|
|
363
|
-
.withClientMetadata({
|
|
364
|
-
...jarmClientMetadata,
|
|
365
|
-
...verifier.clientMetadata,
|
|
366
|
-
// FIXME: not passing client_id here means it will not be added
|
|
367
|
-
// to the authorization request url (not the signed payload). Need
|
|
368
|
-
// to fix that in Sphereon lib
|
|
369
|
-
client_id: clientId,
|
|
370
|
-
passBy: did_auth_siop_1.PassBy.VALUE,
|
|
371
|
-
response_types_supported: [did_auth_siop_1.ResponseType.VP_TOKEN],
|
|
372
|
-
subject_syntax_types_supported: [
|
|
373
|
-
'urn:ietf:params:oauth:jwk-thumbprint',
|
|
374
|
-
...supportedDidMethods.map((m) => `did:${m}`),
|
|
375
|
-
],
|
|
376
|
-
vp_formats: {
|
|
377
|
-
mso_mdoc: {
|
|
378
|
-
alg: supportedMdocAlgs,
|
|
379
|
-
},
|
|
380
|
-
jwt_vc: {
|
|
381
|
-
alg: supportedAlgs,
|
|
382
|
-
},
|
|
383
|
-
jwt_vc_json: {
|
|
384
|
-
alg: supportedAlgs,
|
|
385
|
-
},
|
|
386
|
-
jwt_vp_json: {
|
|
387
|
-
alg: supportedAlgs,
|
|
388
|
-
},
|
|
389
|
-
jwt_vp: {
|
|
390
|
-
alg: supportedAlgs,
|
|
391
|
-
},
|
|
392
|
-
ldp_vc: {
|
|
393
|
-
proof_type: supportedProofTypes,
|
|
394
|
-
},
|
|
395
|
-
ldp_vp: {
|
|
396
|
-
proof_type: supportedProofTypes,
|
|
397
|
-
},
|
|
398
|
-
'vc+sd-jwt': {
|
|
399
|
-
'kb-jwt_alg_values': supportedAlgs,
|
|
400
|
-
'sd-jwt_alg_values': supportedAlgs,
|
|
401
|
-
},
|
|
402
|
-
},
|
|
403
|
-
});
|
|
404
|
-
if (clientIdScheme) {
|
|
405
|
-
builder.withClientIdScheme(clientIdScheme);
|
|
406
|
-
}
|
|
407
|
-
if (presentationDefinition) {
|
|
408
|
-
builder.withPresentationDefinition({ definition: presentationDefinition }, [did_auth_siop_1.PropertyTarget.REQUEST_OBJECT]);
|
|
409
|
-
}
|
|
410
|
-
if (responseTypes.includes(did_auth_siop_1.ResponseType.ID_TOKEN)) {
|
|
411
|
-
builder.withScope('openid');
|
|
412
|
-
}
|
|
413
|
-
return builder.build();
|
|
414
|
-
}
|
|
415
|
-
getPresentationVerificationCallback(agentContext, options) {
|
|
416
|
-
return async (encodedPresentation, presentationSubmission) => {
|
|
417
|
-
try {
|
|
418
|
-
this.logger.debug('Presentation response', core_1.JsonTransformer.toJSON(encodedPresentation));
|
|
419
|
-
this.logger.debug('Presentation submission', presentationSubmission);
|
|
420
|
-
if (!encodedPresentation)
|
|
421
|
-
throw new core_1.CredoError('Did not receive a presentation for verification.');
|
|
422
|
-
const x509Config = agentContext.dependencyManager.resolve(core_1.X509ModuleConfig);
|
|
423
|
-
let isValid;
|
|
424
|
-
let reason = undefined;
|
|
425
|
-
if (typeof encodedPresentation === 'string' && encodedPresentation.includes('~')) {
|
|
426
|
-
// TODO: it might be better here to look at the presentation submission to know
|
|
427
|
-
// If presentation includes a ~, we assume it's an SD-JWT-VC
|
|
428
|
-
const sdJwtVcApi = agentContext.dependencyManager.resolve(core_1.SdJwtVcApi);
|
|
429
|
-
const jwt = core_1.Jwt.fromSerializedJwt(encodedPresentation.split('~')[0]);
|
|
430
|
-
const sdJwtVc = sdJwtVcApi.fromCompact(encodedPresentation);
|
|
431
|
-
const certificateChain = (0, core_1.extractX509CertificatesFromJwt)(jwt);
|
|
432
|
-
let trustedCertificates = undefined;
|
|
433
|
-
if (certificateChain && x509Config.getTrustedCertificatesForVerification) {
|
|
434
|
-
trustedCertificates = await x509Config.getTrustedCertificatesForVerification(agentContext, {
|
|
435
|
-
certificateChain,
|
|
436
|
-
verification: {
|
|
437
|
-
type: 'credential',
|
|
438
|
-
credential: sdJwtVc,
|
|
439
|
-
openId4VcVerificationSessionId: options.verificationSessionRecordId,
|
|
440
|
-
},
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
if (!trustedCertificates) {
|
|
444
|
-
// We also take from the config here to avoid the callback being called again
|
|
445
|
-
trustedCertificates = x509Config.trustedCertificates ?? [];
|
|
446
|
-
}
|
|
447
|
-
const verificationResult = await sdJwtVcApi.verify({
|
|
448
|
-
compactSdJwtVc: encodedPresentation,
|
|
449
|
-
keyBinding: {
|
|
450
|
-
audience: options.audience,
|
|
451
|
-
nonce: options.nonce,
|
|
452
|
-
},
|
|
453
|
-
trustedCertificates,
|
|
454
|
-
});
|
|
455
|
-
isValid = verificationResult.verification.isValid;
|
|
456
|
-
reason = verificationResult.isValid ? undefined : verificationResult.error.message;
|
|
457
|
-
}
|
|
458
|
-
else if (typeof encodedPresentation === 'string' && !core_1.Jwt.format.test(encodedPresentation)) {
|
|
459
|
-
if (!options.responseUri || !options.mdocGeneratedNonce) {
|
|
460
|
-
isValid = false;
|
|
461
|
-
reason = 'Mdoc device response verification failed. Response uri and the mdocGeneratedNonce are not set';
|
|
462
|
-
}
|
|
463
|
-
else {
|
|
464
|
-
const mdocDeviceResponse = core_1.MdocDeviceResponse.fromBase64Url(encodedPresentation);
|
|
465
|
-
if (mdocDeviceResponse.documents.length !== 1) {
|
|
466
|
-
throw new core_1.CredoError('Only a single mdoc is supported per device response for OpenID4VP verification');
|
|
467
|
-
}
|
|
468
|
-
const document = mdocDeviceResponse.documents[0];
|
|
469
|
-
const certificateChain = document.issuerSignedCertificateChain.map((cert) => core_1.X509Certificate.fromRawCertificate(cert));
|
|
470
|
-
const trustedCertificates = await x509Config.getTrustedCertificatesForVerification?.(agentContext, {
|
|
471
|
-
certificateChain,
|
|
472
|
-
verification: {
|
|
473
|
-
type: 'credential',
|
|
474
|
-
credential: document,
|
|
475
|
-
openId4VcVerificationSessionId: options.verificationSessionRecordId,
|
|
476
|
-
},
|
|
477
|
-
});
|
|
478
|
-
await mdocDeviceResponse.verify(agentContext, {
|
|
479
|
-
sessionTranscriptOptions: {
|
|
480
|
-
clientId: options.audience,
|
|
481
|
-
mdocGeneratedNonce: options.mdocGeneratedNonce,
|
|
482
|
-
responseUri: options.responseUri,
|
|
483
|
-
verifierGeneratedNonce: options.nonce,
|
|
484
|
-
},
|
|
485
|
-
trustedCertificates,
|
|
486
|
-
});
|
|
487
|
-
isValid = true;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
else if (typeof encodedPresentation === 'string' && core_1.Jwt.format.test(encodedPresentation)) {
|
|
491
|
-
const presentation = core_1.W3cJwtVerifiablePresentation.fromSerializedJwt(encodedPresentation);
|
|
492
|
-
const certificateChain = (0, core_1.extractX509CertificatesFromJwt)(presentation.jwt);
|
|
493
|
-
let trustedCertificates = undefined;
|
|
494
|
-
if (certificateChain && x509Config.getTrustedCertificatesForVerification) {
|
|
495
|
-
trustedCertificates = await x509Config.getTrustedCertificatesForVerification?.(agentContext, {
|
|
496
|
-
certificateChain,
|
|
497
|
-
verification: {
|
|
498
|
-
type: 'credential',
|
|
499
|
-
credential: presentation,
|
|
500
|
-
openId4VcVerificationSessionId: options.verificationSessionRecordId,
|
|
501
|
-
},
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
if (!trustedCertificates) {
|
|
505
|
-
trustedCertificates = x509Config.trustedCertificates ?? [];
|
|
506
|
-
}
|
|
507
|
-
const verificationResult = await this.w3cCredentialService.verifyPresentation(agentContext, {
|
|
508
|
-
presentation: encodedPresentation,
|
|
509
|
-
challenge: options.nonce,
|
|
510
|
-
domain: options.audience,
|
|
511
|
-
trustedCertificates,
|
|
512
|
-
});
|
|
513
|
-
isValid = verificationResult.isValid;
|
|
514
|
-
reason = verificationResult.error?.message;
|
|
515
|
-
}
|
|
516
|
-
else {
|
|
517
|
-
const verificationResult = await this.w3cCredentialService.verifyPresentation(agentContext, {
|
|
518
|
-
presentation: core_1.JsonTransformer.fromJSON(encodedPresentation, core_1.W3cJsonLdVerifiablePresentation),
|
|
519
|
-
challenge: options.nonce,
|
|
520
|
-
domain: options.audience,
|
|
521
|
-
});
|
|
522
|
-
isValid = verificationResult.isValid;
|
|
523
|
-
reason = verificationResult.error?.message;
|
|
524
|
-
}
|
|
525
|
-
if (!isValid) {
|
|
526
|
-
throw new Error(reason);
|
|
527
|
-
}
|
|
528
|
-
return {
|
|
529
|
-
verified: true,
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
catch (error) {
|
|
533
|
-
agentContext.config.logger.warn('Error occurred during verification of presentation', {
|
|
534
|
-
error,
|
|
535
|
-
});
|
|
536
|
-
return {
|
|
537
|
-
verified: false,
|
|
538
|
-
reason: error.message,
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
exports.OpenId4VcSiopVerifierService = OpenId4VcSiopVerifierService;
|
|
545
|
-
exports.OpenId4VcSiopVerifierService = OpenId4VcSiopVerifierService = __decorate([
|
|
546
|
-
(0, core_1.injectable)(),
|
|
547
|
-
__param(0, (0, core_1.inject)(core_1.InjectionSymbols.Logger)),
|
|
548
|
-
__metadata("design:paramtypes", [Object, core_1.W3cCredentialService,
|
|
549
|
-
repository_1.OpenId4VcVerifierRepository,
|
|
550
|
-
OpenId4VcVerifierModuleConfig_1.OpenId4VcVerifierModuleConfig,
|
|
551
|
-
repository_1.OpenId4VcVerificationSessionRepository])
|
|
552
|
-
], OpenId4VcSiopVerifierService);
|
|
553
|
-
//# sourceMappingURL=OpenId4VcSiopVerifierService.js.map
|