@credo-ts/openid4vc 0.6.0-pr-2195-20250226100854 → 0.6.0-pr-2195-20250321180923

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.
Files changed (100) hide show
  1. package/build/openid4vc-holder/OpenId4VcHolderApi.d.ts +29 -29
  2. package/build/openid4vc-holder/OpenId4VcHolderApi.js +16 -16
  3. package/build/openid4vc-holder/OpenId4VcHolderApi.js.map +1 -1
  4. package/build/openid4vc-holder/OpenId4VcHolderModule.js +2 -2
  5. package/build/openid4vc-holder/OpenId4VcHolderModule.js.map +1 -1
  6. package/build/openid4vc-holder/OpenId4VciHolderService.d.ts +2 -2
  7. package/build/openid4vc-holder/OpenId4VciHolderService.js +6 -6
  8. package/build/openid4vc-holder/OpenId4VciHolderService.js.map +1 -1
  9. package/build/openid4vc-holder/OpenId4VciHolderServiceOptions.d.ts +1 -1
  10. package/build/openid4vc-holder/{OpenId4vcSiopHolderService.d.ts → OpenId4vpHolderService.d.ts} +21 -22
  11. package/build/openid4vc-holder/OpenId4vpHolderService.js +317 -0
  12. package/build/openid4vc-holder/OpenId4vpHolderService.js.map +1 -0
  13. package/build/openid4vc-holder/OpenId4vpHolderServiceOptions.d.ts +81 -0
  14. package/build/openid4vc-holder/{OpenId4vcSiopHolderServiceOptions.js → OpenId4vpHolderServiceOptions.js} +1 -1
  15. package/build/openid4vc-holder/OpenId4vpHolderServiceOptions.js.map +1 -0
  16. package/build/openid4vc-holder/index.d.ts +2 -2
  17. package/build/openid4vc-holder/index.js +2 -2
  18. package/build/openid4vc-holder/index.js.map +1 -1
  19. package/build/openid4vc-issuer/OpenId4VcIssuerEvents.d.ts +1 -1
  20. package/build/openid4vc-issuer/OpenId4VcIssuerModule.d.ts +1 -1
  21. package/build/openid4vc-issuer/OpenId4VcIssuerModuleConfig.d.ts +1 -1
  22. package/build/openid4vc-issuer/OpenId4VcIssuerService.d.ts +2 -3
  23. package/build/openid4vc-issuer/OpenId4VcIssuerService.js +13 -16
  24. package/build/openid4vc-issuer/OpenId4VcIssuerService.js.map +1 -1
  25. package/build/openid4vc-issuer/OpenId4VcIssuerServiceOptions.d.ts +8 -8
  26. package/build/openid4vc-issuer/repository/OpenId4VcIssuanceSessionRecord.d.ts +11 -1
  27. package/build/openid4vc-issuer/repository/OpenId4VcIssuanceSessionRecord.js +3 -0
  28. package/build/openid4vc-issuer/repository/OpenId4VcIssuanceSessionRecord.js.map +1 -1
  29. package/build/openid4vc-issuer/repository/OpenId4VcIssuanceSessionRepository.d.ts +1 -1
  30. package/build/openid4vc-issuer/repository/OpenId4VcIssuerRecord.d.ts +1 -1
  31. package/build/openid4vc-issuer/repository/OpenId4VcIssuerRecord.js +1 -1
  32. package/build/openid4vc-issuer/repository/OpenId4VcIssuerRecord.js.map +1 -1
  33. package/build/openid4vc-issuer/repository/OpenId4VcIssuerRepository.d.ts +1 -1
  34. package/build/openid4vc-issuer/router/accessTokenEndpoint.d.ts +2 -2
  35. package/build/openid4vc-issuer/router/authorizationChallengeEndpoint.js.map +1 -1
  36. package/build/openid4vc-issuer/router/credentialEndpoint.d.ts +1 -1
  37. package/build/openid4vc-issuer/router/credentialEndpoint.js +1 -0
  38. package/build/openid4vc-issuer/router/credentialEndpoint.js.map +1 -1
  39. package/build/openid4vc-issuer/router/credentialOfferEndpoint.d.ts +1 -1
  40. package/build/openid4vc-issuer/router/credentialOfferEndpoint.js +15 -0
  41. package/build/openid4vc-issuer/router/credentialOfferEndpoint.js.map +1 -1
  42. package/build/openid4vc-issuer/router/jwksEndpoint.d.ts +1 -1
  43. package/build/openid4vc-issuer/router/nonceEndpoint.d.ts +1 -1
  44. package/build/openid4vc-issuer/util/txCode.d.ts +1 -1
  45. package/build/openid4vc-verifier/OpenId4VcVerifierApi.d.ts +13 -26
  46. package/build/openid4vc-verifier/OpenId4VcVerifierApi.js +16 -25
  47. package/build/openid4vc-verifier/OpenId4VcVerifierApi.js.map +1 -1
  48. package/build/openid4vc-verifier/OpenId4VcVerifierEvents.d.ts +1 -1
  49. package/build/openid4vc-verifier/OpenId4VcVerifierModule.d.ts +1 -1
  50. package/build/openid4vc-verifier/OpenId4VcVerifierModule.js +4 -4
  51. package/build/openid4vc-verifier/OpenId4VcVerifierModule.js.map +1 -1
  52. package/build/openid4vc-verifier/OpenId4VcVerifierModuleConfig.d.ts +30 -7
  53. package/build/openid4vc-verifier/OpenId4VcVerifierModuleConfig.js +16 -12
  54. package/build/openid4vc-verifier/OpenId4VcVerifierModuleConfig.js.map +1 -1
  55. package/build/openid4vc-verifier/{OpenId4VcSiopVerifierService.d.ts → OpenId4VpVerifierService.d.ts} +17 -33
  56. package/build/openid4vc-verifier/OpenId4VpVerifierService.js +765 -0
  57. package/build/openid4vc-verifier/OpenId4VpVerifierService.js.map +1 -0
  58. package/build/openid4vc-verifier/OpenId4VpVerifierServiceOptions.d.ts +146 -0
  59. package/build/openid4vc-verifier/{OpenId4VcSiopVerifierServiceOptions.js → OpenId4VpVerifierServiceOptions.js} +1 -1
  60. package/build/openid4vc-verifier/OpenId4VpVerifierServiceOptions.js.map +1 -0
  61. package/build/openid4vc-verifier/index.d.ts +2 -2
  62. package/build/openid4vc-verifier/index.js +2 -2
  63. package/build/openid4vc-verifier/index.js.map +1 -1
  64. package/build/openid4vc-verifier/repository/OpenId4VcVerificationSessionRecord.d.ts +25 -9
  65. package/build/openid4vc-verifier/repository/OpenId4VcVerificationSessionRecord.js +21 -2
  66. package/build/openid4vc-verifier/repository/OpenId4VcVerificationSessionRecord.js.map +1 -1
  67. package/build/openid4vc-verifier/repository/OpenId4VcVerificationSessionRepository.d.ts +1 -1
  68. package/build/openid4vc-verifier/repository/OpenId4VcVerifierRecord.d.ts +3 -3
  69. package/build/openid4vc-verifier/repository/OpenId4VcVerifierRepository.d.ts +1 -1
  70. package/build/openid4vc-verifier/router/authorizationEndpoint.d.ts +2 -10
  71. package/build/openid4vc-verifier/router/authorizationEndpoint.js +94 -7
  72. package/build/openid4vc-verifier/router/authorizationEndpoint.js.map +1 -1
  73. package/build/openid4vc-verifier/router/authorizationRequestEndpoint.d.ts +2 -10
  74. package/build/openid4vc-verifier/router/authorizationRequestEndpoint.js +18 -6
  75. package/build/openid4vc-verifier/router/authorizationRequestEndpoint.js.map +1 -1
  76. package/build/shared/callbacks.d.ts +2 -2
  77. package/build/shared/callbacks.js +10 -7
  78. package/build/shared/callbacks.js.map +1 -1
  79. package/build/shared/models/index.d.ts +4 -4
  80. package/build/shared/models/index.js.map +1 -1
  81. package/build/shared/router/context.d.ts +2 -2
  82. package/build/shared/router/context.js +9 -5
  83. package/build/shared/router/context.js.map +1 -1
  84. package/build/shared/router/express.js +1 -2
  85. package/build/shared/router/express.js.map +1 -1
  86. package/build/shared/transactionData.d.ts +5 -0
  87. package/build/shared/transactionData.js +22 -0
  88. package/build/shared/transactionData.js.map +1 -0
  89. package/build/shared/utils.d.ts +1 -1
  90. package/build/shared/utils.js +3 -3
  91. package/build/shared/utils.js.map +1 -1
  92. package/package.json +7 -6
  93. package/build/openid4vc-holder/OpenId4vcSiopHolderService.js +0 -306
  94. package/build/openid4vc-holder/OpenId4vcSiopHolderService.js.map +0 -1
  95. package/build/openid4vc-holder/OpenId4vcSiopHolderServiceOptions.d.ts +0 -54
  96. package/build/openid4vc-holder/OpenId4vcSiopHolderServiceOptions.js.map +0 -1
  97. package/build/openid4vc-verifier/OpenId4VcSiopVerifierService.js +0 -806
  98. package/build/openid4vc-verifier/OpenId4VcSiopVerifierService.js.map +0 -1
  99. package/build/openid4vc-verifier/OpenId4VcSiopVerifierServiceOptions.d.ts +0 -93
  100. package/build/openid4vc-verifier/OpenId4VcSiopVerifierServiceOptions.js.map +0 -1
@@ -1,806 +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 oauth2_1 = require("@openid4vc/oauth2");
18
- const openid4vp_1 = require("@openid4vc/openid4vp");
19
- const callbacks_1 = require("../shared/callbacks");
20
- const router_1 = require("../shared/router");
21
- const utils_1 = require("../shared/utils");
22
- const OpenId4VcVerificationSessionState_1 = require("./OpenId4VcVerificationSessionState");
23
- const OpenId4VcVerifierEvents_1 = require("./OpenId4VcVerifierEvents");
24
- const OpenId4VcVerifierModuleConfig_1 = require("./OpenId4VcVerifierModuleConfig");
25
- const repository_1 = require("./repository");
26
- /**
27
- * @internal
28
- */
29
- let OpenId4VcSiopVerifierService = class OpenId4VcSiopVerifierService {
30
- constructor(logger, w3cCredentialService, openId4VcVerifierRepository, config, openId4VcVerificationSessionRepository) {
31
- this.logger = logger;
32
- this.w3cCredentialService = w3cCredentialService;
33
- this.openId4VcVerifierRepository = openId4VcVerifierRepository;
34
- this.config = config;
35
- this.openId4VcVerificationSessionRepository = openId4VcVerificationSessionRepository;
36
- }
37
- getOpenid4vpVerifier(agentContext) {
38
- const callbacks = (0, callbacks_1.getOid4vcCallbacks)(agentContext);
39
- const openid4vpClient = new openid4vp_1.Openid4vpVerifier({ callbacks });
40
- return openid4vpClient;
41
- }
42
- async createAuthorizationRequest(agentContext, options) {
43
- const nonce = await agentContext.wallet.generateNonce();
44
- const state = await agentContext.wallet.generateNonce();
45
- const isDcApiRequest = options.responseMode === 'dc_api' || options.responseMode === 'dc_api.jwt';
46
- const responseMode = options.responseMode ?? 'direct_post.jwt';
47
- // No response url for DC API
48
- let authorizationResponseUrl = (0, core_1.joinUriParts)(this.config.baseUrl, [
49
- options.verifier.verifierId,
50
- this.config.authorizationEndpoint.endpointPath,
51
- ]);
52
- const jwtIssuer = options.requestSigner.method === 'none'
53
- ? undefined
54
- : options.requestSigner.method === 'x5c'
55
- ? await (0, utils_1.requestSignerToJwtIssuer)(agentContext, {
56
- ...options.requestSigner,
57
- issuer: authorizationResponseUrl,
58
- })
59
- : await (0, utils_1.requestSignerToJwtIssuer)(agentContext, options.requestSigner);
60
- let clientIdScheme;
61
- let clientId;
62
- if (!jwtIssuer) {
63
- if (!isDcApiRequest) {
64
- throw new Error("requestSigner method 'none' is only supported for response mode 'dc_api' and 'dc_api.jwt'");
65
- }
66
- clientIdScheme = 'web-origin';
67
- clientId = undefined;
68
- }
69
- else if (jwtIssuer?.method === 'x5c') {
70
- const leafCertificate = core_1.X509Service.getLeafCertificate(agentContext, { certificateChain: jwtIssuer.x5c });
71
- if (leafCertificate.sanDnsNames.includes((0, core_1.getDomainFromUrl)(jwtIssuer.issuer))) {
72
- clientIdScheme = 'x509_san_dns';
73
- clientId = (0, core_1.getDomainFromUrl)(jwtIssuer.issuer);
74
- authorizationResponseUrl = jwtIssuer.issuer;
75
- }
76
- else if (leafCertificate.sanUriNames.includes(jwtIssuer.issuer)) {
77
- clientIdScheme = 'x509_san_uri';
78
- clientId = jwtIssuer.issuer;
79
- authorizationResponseUrl = clientId;
80
- }
81
- else {
82
- 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.`);
83
- }
84
- }
85
- else if (jwtIssuer?.method === 'did') {
86
- clientId = jwtIssuer.didUrl.split('#')[0];
87
- clientIdScheme = 'did';
88
- }
89
- else {
90
- throw new core_1.CredoError(`Unsupported jwt issuer method '${options.requestSigner.method}'. Only 'did' and 'x5c' are supported.`);
91
- }
92
- // We always use shortened URIs currently
93
- const hostedAuthorizationRequestUri = !isDcApiRequest
94
- ? (0, core_1.joinUriParts)(this.config.baseUrl, [
95
- options.verifier.verifierId,
96
- this.config.authorizationRequestEndpoint.endpointPath,
97
- // It doesn't really matter what the url is, as long as it's unique
98
- core_1.utils.uuid(),
99
- ])
100
- : // No hosted request needed when using DC API
101
- undefined;
102
- const client_id = clientIdScheme === 'did' || clientIdScheme === 'https' ? clientId : `${clientIdScheme}:${clientId}`;
103
- const client_metadata = await this.getClientMetadata(agentContext, {
104
- responseMode,
105
- verifier: options.verifier,
106
- authorizationResponseUrl,
107
- });
108
- const requestParamsBase = {
109
- nonce,
110
- presentation_definition: options.presentationExchange?.definition,
111
- dcql_query: options.dcql?.query,
112
- transaction_data: options.transactionData?.map((entry) => core_1.JsonEncoder.toBase64URL(entry)),
113
- response_mode: responseMode,
114
- response_type: 'vp_token',
115
- client_metadata,
116
- };
117
- const authorizationRequestPayload = requestParamsBase.response_mode === 'dc_api.jwt' || requestParamsBase.response_mode === 'dc_api'
118
- ? {
119
- ...requestParamsBase,
120
- // No client_id for unsigned requests
121
- client_id: jwtIssuer ? client_id : undefined,
122
- response_mode: requestParamsBase.response_mode,
123
- expected_origins: options.expectedOrigins,
124
- }
125
- : {
126
- ...requestParamsBase,
127
- client_id: client_id,
128
- state,
129
- response_uri: authorizationResponseUrl,
130
- };
131
- const openid4vpVerifier = this.getOpenid4vpVerifier(agentContext);
132
- const authorizationRequest = await openid4vpVerifier.createOpenId4vpAuthorizationRequest({
133
- jar: jwtIssuer
134
- ? {
135
- jwtSigner: jwtIssuer,
136
- // FIXME: cast can be removed when PR 41 is merged in oid4vc-ts
137
- requestUri: hostedAuthorizationRequestUri,
138
- }
139
- : undefined,
140
- requestParams: authorizationRequestPayload,
141
- });
142
- const verificationSession = new repository_1.OpenId4VcVerificationSessionRecord({
143
- // Only store payload for unsiged requests
144
- authorizationRequestPayload: authorizationRequest.jar ? undefined : authorizationRequestPayload,
145
- authorizationRequestJwt: authorizationRequest.jar?.requestObjectJwt,
146
- authorizationRequestUri: authorizationRequest.jar?.requestUri,
147
- state: OpenId4VcVerificationSessionState_1.OpenId4VcVerificationSessionState.RequestCreated,
148
- verifierId: options.verifier.verifierId,
149
- });
150
- await this.openId4VcVerificationSessionRepository.save(agentContext, verificationSession);
151
- this.emitStateChangedEvent(agentContext, verificationSession, null);
152
- return {
153
- authorizationRequest: authorizationRequest.authRequest,
154
- verificationSession,
155
- authorizationRequestObject: authorizationRequest.authRequestObject,
156
- };
157
- }
158
- getDcqlVerifiedResponse(agentContext, _dcqlQuery, presentation) {
159
- const dcqlService = agentContext.dependencyManager.resolve(core_1.DcqlService);
160
- const dcqlQuery = dcqlService.validateDcqlQuery(_dcqlQuery);
161
- const dcqlPresentationEntries = Object.entries(presentation);
162
- const dcqlPresentation = Object.fromEntries(dcqlPresentationEntries.map((presentation) => {
163
- const [credentialId, vpTokenPresentationParseResult] = presentation;
164
- return [credentialId, this.decodePresentation(agentContext, { vpTokenPresentationParseResult })];
165
- }));
166
- const dcqlPresentationResult = dcqlService.assertValidDcqlPresentation(dcqlPresentation, dcqlQuery);
167
- return {
168
- query: dcqlQuery,
169
- presentation: dcqlPresentation,
170
- presentationResult: dcqlPresentationResult,
171
- };
172
- }
173
- async parseAuthorizationResponse(agentContext, options) {
174
- const { verifierId, responsePayload } = options;
175
- if (!options.verificationSession && !options.verifierId) {
176
- throw new core_1.CredoError('Either verificationSession or verifierId needs to be provided');
177
- }
178
- let verificationSession = options.verificationSession;
179
- let parsedAuthResponse;
180
- let rawResponsePayload = responsePayload;
181
- try {
182
- parsedAuthResponse = await (0, openid4vp_1.parseOpenid4vpAuthorizationResponse)({
183
- responsePayload,
184
- callbacks: {
185
- ...(0, callbacks_1.getOid4vcCallbacks)(agentContext),
186
- getOpenid4vpAuthorizationRequest: async (responsePayload) => {
187
- if (!verificationSession) {
188
- const { state, nonce } = responsePayload;
189
- rawResponsePayload = responsePayload;
190
- const session = await this.findVerificationSessionForAuthorizationResponse(agentContext, {
191
- authorizationResponseParams: { state, nonce },
192
- verifierId,
193
- });
194
- if (!session) {
195
- agentContext.config.logger.warn(`No verification session found for incoming authorization response for verifier ${verifierId}`);
196
- throw new core_1.CredoError(`No state or nonce provided in authorization response for verifier ${verifierId}`);
197
- }
198
- verificationSession = session;
199
- }
200
- const authorizationRequest = (0, openid4vp_1.parseOpenid4vpAuthorizationRequestPayload)({
201
- authorizationRequest: verificationSession.request,
202
- });
203
- if (authorizationRequest.type !== 'openid4vp' && authorizationRequest.type !== 'openid4vp_dc_api') {
204
- throw new core_1.CredoError(`Invalid authorization request jwt. Expected 'openid4vp' or 'openid4vp_dc_api' request, received '${authorizationRequest.type}'.`);
205
- }
206
- if (authorizationRequest.params.client_id) {
207
- return {
208
- authorizationRequest: {
209
- ...authorizationRequest.params,
210
- client_id: authorizationRequest.params.client_id,
211
- },
212
- };
213
- }
214
- if (!options.origin) {
215
- throw new core_1.CredoError('Origin must be provided when client id is not set.');
216
- }
217
- return {
218
- authorizationRequest: {
219
- ...authorizationRequest.params,
220
- client_id: authorizationRequest.params.client_id ?? `web-origin:${options.origin}`,
221
- },
222
- };
223
- },
224
- },
225
- });
226
- }
227
- catch (error) {
228
- if (verificationSession?.state === OpenId4VcVerificationSessionState_1.OpenId4VcVerificationSessionState.RequestUriRetrieved ||
229
- verificationSession?.state === OpenId4VcVerificationSessionState_1.OpenId4VcVerificationSessionState.RequestCreated) {
230
- const parsed = openid4vp_1.zOpenid4vpAuthorizationResponse.safeParse(rawResponsePayload);
231
- verificationSession.authorizationResponsePayload = parsed.success ? parsed.data : undefined;
232
- verificationSession.errorMessage = error.message;
233
- await this.updateState(agentContext, verificationSession, OpenId4VcVerificationSessionState_1.OpenId4VcVerificationSessionState.Error);
234
- }
235
- throw error;
236
- }
237
- if (parsedAuthResponse.authResponsePayload.presentation_submission &&
238
- typeof parsedAuthResponse.authResponsePayload.presentation_submission === 'string') {
239
- const decoded = decodeURIComponent(parsedAuthResponse.authResponsePayload.presentation_submission);
240
- const parsed = JSON.parse(decoded);
241
- parsedAuthResponse.authResponsePayload.presentation_submission = parsed;
242
- if (parsedAuthResponse.type === 'pex') {
243
- parsedAuthResponse.pex.presentationSubmission = parsed;
244
- }
245
- }
246
- if (!verificationSession) {
247
- throw new core_1.CredoError('Missing verification session, cannot verify authorization response.');
248
- }
249
- // FIXME: export JarmMode from openid4vp
250
- if (parsedAuthResponse.jarm && `${parsedAuthResponse.jarm.type}` !== 'Encrypted') {
251
- throw new oauth2_1.Oauth2ServerErrorResponseError({
252
- error: oauth2_1.Oauth2ErrorCodes.InvalidRequest,
253
- error_description: `Only encrypted JARM responses are supported, received '${parsedAuthResponse.jarm.type}'.`,
254
- });
255
- }
256
- return {
257
- ...parsedAuthResponse,
258
- verificationSession,
259
- };
260
- }
261
- async verifyAuthorizationResponse(agentContext, options) {
262
- const openid4vpVerifier = this.getOpenid4vpVerifier(agentContext);
263
- const result = await this.parseAuthorizationResponse(agentContext, {
264
- verifierId: options.verifierId,
265
- verificationSession: options.verificationSession,
266
- responsePayload: options.authorizationResponse,
267
- origin: options.origin,
268
- });
269
- result.verificationSession.assertState([
270
- OpenId4VcVerificationSessionState_1.OpenId4VcVerificationSessionState.RequestUriRetrieved,
271
- OpenId4VcVerificationSessionState_1.OpenId4VcVerificationSessionState.RequestCreated,
272
- ]);
273
- const authorizationRequest = result.authRequestPayload;
274
- let requestClientId = authorizationRequest.client_id;
275
- const responseUri = 'response_uri' in authorizationRequest ? authorizationRequest.response_uri : undefined;
276
- const transactionData = authorizationRequest.transaction_data
277
- ? openid4vpVerifier.parseTransactionData({ transactionData: authorizationRequest.transaction_data })
278
- : undefined;
279
- const isDcApiRequest = authorizationRequest.response_mode === 'dc_api' || authorizationRequest.response_mode === 'dc_api.jwt';
280
- if (isDcApiRequest) {
281
- if (!options.origin)
282
- throw new core_1.CredoError('origin is required for Digital Credentials API');
283
- if (!requestClientId)
284
- requestClientId = `web-origin:${options.origin}`;
285
- }
286
- else if (!requestClientId) {
287
- throw new core_1.CredoError('Missing required client_id');
288
- }
289
- // validating the id token
290
- // verifying the presentations
291
- // validating the presentations against the presentation definition
292
- // checking the revocation status of the presentations
293
- // checking the nonce of the presentations matches the nonce of the request
294
- let presentationVerificationResults = [];
295
- if (result.type === 'dcql') {
296
- const dcqlPresentationEntries = Object.entries(result.dcql.presentation);
297
- const presentationVerificationPromises = dcqlPresentationEntries.map(async (presentation) => {
298
- const [credentialId, vpTokenPresentationParseResult] = presentation;
299
- return await this.verifyPresentations(agentContext, {
300
- correlationId: result.verificationSession.id,
301
- transactionData,
302
- nonce: authorizationRequest.nonce,
303
- audience: requestClientId,
304
- origin: options.origin,
305
- responseUri,
306
- mdocGeneratedNonce: result.jarm?.mdocGeneratedNonce,
307
- verificationSessionRecordId: result.verificationSession.id,
308
- vpTokenPresentationParseResult,
309
- credentialId,
310
- });
311
- });
312
- presentationVerificationResults = await Promise.all(presentationVerificationPromises);
313
- }
314
- if (result.type === 'pex') {
315
- const presentations = result.pex.presentations;
316
- const pex = agentContext.dependencyManager.resolve(core_1.DifPresentationExchangeService);
317
- pex.validatePresentationDefinition(result.pex.presentationDefinition);
318
- pex.validatePresentationSubmission(result.pex.presentationSubmission);
319
- const presentationsArray = Array.isArray(presentations) ? presentations : [presentations];
320
- const presentationVerificationPromises = presentationsArray.map((presentation) => {
321
- const inputDescriptor = result.pex.presentationSubmission.descriptor_map.find((descriptorMapEntry) => descriptorMapEntry.path === presentation.path);
322
- if (!inputDescriptor) {
323
- throw new core_1.CredoError(`Could not map transaction data entry to input descriptor.`);
324
- }
325
- return this.verifyPresentations(agentContext, {
326
- correlationId: result.verificationSession.id,
327
- transactionData,
328
- nonce: authorizationRequest.nonce,
329
- audience: requestClientId,
330
- responseUri,
331
- mdocGeneratedNonce: result.jarm?.mdocGeneratedNonce,
332
- verificationSessionRecordId: result.verificationSession.id,
333
- vpTokenPresentationParseResult: presentation,
334
- credentialId: inputDescriptor.id,
335
- });
336
- });
337
- presentationVerificationResults = await Promise.all(presentationVerificationPromises);
338
- }
339
- try {
340
- const errorMessages = presentationVerificationResults
341
- .map((result, index) => (!result.verified ? `\t- [${index}]: ${result.reason}` : undefined))
342
- .filter((i) => i !== undefined);
343
- if (errorMessages.length > 0) {
344
- throw new core_1.CredoError(`One or more presentations failed verification. \n\t${errorMessages.join('\n')}`);
345
- }
346
- // Validate the presentations against the query
347
- if (result.type === 'pex') {
348
- const pex = agentContext.dependencyManager.resolve(core_1.DifPresentationExchangeService);
349
- const presentations = presentationVerificationResults
350
- .map((p) => (p.verified ? p.presentation : undefined))
351
- .filter((p) => p !== undefined);
352
- pex.validatePresentation(
353
- // FIXME: type. it should always be an object as we created it
354
- result.pex.presentationDefinition, presentations, result.pex.presentationSubmission);
355
- }
356
- else {
357
- const dcql = agentContext.dependencyManager.resolve(core_1.DcqlService);
358
- const presentations = presentationVerificationResults.reduce((all, p) => (p.verified ? { ...all, [p.credentialId]: p.presentation } : all), {});
359
- // FIXME: type for this parameter
360
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
361
- dcql.assertValidDcqlPresentation(presentations, result.dcql.query);
362
- }
363
- const transactionDataMeta = [];
364
- for (const result of presentationVerificationResults) {
365
- if (result.verified && result.transactionDataMeta) {
366
- transactionDataMeta.push([result.transactionDataMeta.credentialId, result.transactionDataMeta]);
367
- }
368
- }
369
- if (transactionData) {
370
- const inputDescriptorToTransactionDataMeta = Object.fromEntries(transactionDataMeta);
371
- if (!transactionData.every((tdEntry) => {
372
- return tdEntry.credential_ids.some((credentialId) => inputDescriptorToTransactionDataMeta[credentialId]);
373
- })) {
374
- throw new core_1.CredoError('One ore more required transaction data entries were not found in the signed transaction data.');
375
- }
376
- }
377
- }
378
- catch (error) {
379
- result.verificationSession.errorMessage = error.message;
380
- await this.updateState(agentContext, result.verificationSession, OpenId4VcVerificationSessionState_1.OpenId4VcVerificationSessionState.Error);
381
- throw error;
382
- }
383
- result.verificationSession.authorizationResponsePayload = result.authResponsePayload;
384
- await this.updateState(agentContext, result.verificationSession, OpenId4VcVerificationSessionState_1.OpenId4VcVerificationSessionState.ResponseVerified);
385
- const verifiedAuthorizationResponse = await this.getVerifiedAuthorizationResponse(agentContext, result.verificationSession);
386
- return { ...verifiedAuthorizationResponse, verificationSession: result.verificationSession };
387
- }
388
- async getVerifiedAuthorizationResponse(agentContext, verificationSession) {
389
- verificationSession.assertState(OpenId4VcVerificationSessionState_1.OpenId4VcVerificationSessionState.ResponseVerified);
390
- if (!verificationSession.authorizationResponsePayload) {
391
- throw new core_1.CredoError('No authorization response payload found in the verification session.');
392
- }
393
- const openid4vpAuthorizationResponsePayload = verificationSession.authorizationResponsePayload;
394
- const openid4vpVerifier = this.getOpenid4vpVerifier(agentContext);
395
- const authorizationRequest = openid4vpVerifier.parseOpenid4vpAuthorizationRequestPayload({
396
- authorizationRequest: verificationSession.request,
397
- });
398
- if ((authorizationRequest.provided !== 'jwt' && authorizationRequest.provided !== 'params') ||
399
- authorizationRequest.type === 'jar') {
400
- throw new core_1.CredoError('Invalid authorization request');
401
- }
402
- const result = openid4vpVerifier.validateOpenid4vpAuthorizationResponse({
403
- authorizationRequest: authorizationRequest.params,
404
- authorizationResponse: openid4vpAuthorizationResponsePayload,
405
- });
406
- const transactionData = authorizationRequest.params.transaction_data
407
- ? openid4vpVerifier.parseTransactionData({ transactionData: authorizationRequest.params.transaction_data })
408
- : undefined;
409
- let presentationExchange = undefined;
410
- const dcql = result.type === 'dcql'
411
- ? this.getDcqlVerifiedResponse(agentContext, authorizationRequest.params.dcql_query, result.dcql.presentation)
412
- : undefined;
413
- const vpToken = (0, utils_1.parseIfJson)(openid4vpAuthorizationResponsePayload.vp_token);
414
- const presentationDefinition = authorizationRequest.params
415
- .presentation_definition;
416
- if (presentationDefinition) {
417
- if (!vpToken) {
418
- throw new core_1.CredoError('Missing vp_token in the openid4vp authorization response.');
419
- }
420
- const rawPresentations = openid4vpVerifier.parsePresentationsFromVpToken({ vpToken });
421
- const submission = openid4vpAuthorizationResponsePayload.presentation_submission;
422
- if (!submission) {
423
- throw new core_1.CredoError('Unable to extract submission from the response.');
424
- }
425
- const verifiablePresentations = rawPresentations.map((presentation) => this.getPresentationFromVpTokenParseResult(agentContext, presentation));
426
- presentationExchange = {
427
- definition: presentationDefinition,
428
- submission,
429
- presentations: verifiablePresentations,
430
- descriptors: (0, core_1.extractPresentationsWithDescriptorsFromSubmission)(verifiablePresentations, submission, presentationDefinition),
431
- };
432
- }
433
- if (!presentationExchange && !dcql) {
434
- throw new core_1.CredoError('No presentationExchange or dcql found in the response.');
435
- }
436
- return {
437
- presentationExchange,
438
- dcql,
439
- transactionData,
440
- };
441
- }
442
- /**
443
- * Find the verification session associated with an authorization response. You can optionally provide a verifier id
444
- * if the verifier that the response is associated with is already known.
445
- */
446
- async findVerificationSessionForAuthorizationResponse(agentContext, { authorizationResponse, authorizationResponseParams, verifierId, }) {
447
- let nonce;
448
- let state;
449
- if (authorizationResponse) {
450
- const state = authorizationResponse.state;
451
- if (!state) {
452
- throw new core_1.CredoError('Could not extract nonce or state from authorization response. Unable to find OpenId4VcVerificationSession.');
453
- }
454
- }
455
- else {
456
- if (!authorizationResponseParams?.nonce && !authorizationResponseParams?.state) {
457
- throw new core_1.CredoError('Either nonce or state must be provided if no authorization response is provided. Unable to find OpenId4VcVerificationSession.');
458
- }
459
- nonce = authorizationResponseParams?.nonce;
460
- state = authorizationResponseParams?.state;
461
- }
462
- const verificationSession = await this.openId4VcVerificationSessionRepository.findSingleByQuery(agentContext, {
463
- nonce,
464
- payloadState: state,
465
- verifierId,
466
- });
467
- return verificationSession;
468
- }
469
- async getAllVerifiers(agentContext) {
470
- return this.openId4VcVerifierRepository.getAll(agentContext);
471
- }
472
- async getVerifierByVerifierId(agentContext, verifierId) {
473
- return this.openId4VcVerifierRepository.getByVerifierId(agentContext, verifierId);
474
- }
475
- async updateVerifier(agentContext, verifier) {
476
- return this.openId4VcVerifierRepository.update(agentContext, verifier);
477
- }
478
- async createVerifier(agentContext, options) {
479
- const openId4VcVerifier = new repository_1.OpenId4VcVerifierRecord({
480
- verifierId: options?.verifierId ?? core_1.utils.uuid(),
481
- clientMetadata: options?.clientMetadata,
482
- });
483
- await this.openId4VcVerifierRepository.save(agentContext, openId4VcVerifier);
484
- await (0, router_1.storeActorIdForContextCorrelationId)(agentContext, openId4VcVerifier.verifierId);
485
- return openId4VcVerifier;
486
- }
487
- async findVerificationSessionsByQuery(agentContext, query, queryOptions) {
488
- return this.openId4VcVerificationSessionRepository.findByQuery(agentContext, query, queryOptions);
489
- }
490
- async getVerificationSessionById(agentContext, verificationSessionId) {
491
- return this.openId4VcVerificationSessionRepository.getById(agentContext, verificationSessionId);
492
- }
493
- async getClientMetadata(agentContext, options) {
494
- const { responseMode, verifier } = options;
495
- const signatureSuiteRegistry = agentContext.dependencyManager.resolve(core_1.SignatureSuiteRegistry);
496
- const supportedAlgs = (0, utils_1.getSupportedJwaSignatureAlgorithms)(agentContext);
497
- const supportedMdocAlgs = supportedAlgs.filter(core_1.isMdocSupportedSignatureAlgorithm);
498
- const supportedProofTypes = signatureSuiteRegistry.supportedProofTypes;
499
- // FIXME: we now manually remove did:peer, we should probably allow the user to configure this
500
- const supportedDidMethods = agentContext.dependencyManager
501
- .resolve(core_1.DidsApi)
502
- .supportedResolverMethods.filter((m) => m !== 'peer');
503
- let jarmEncryptionJwk;
504
- if ((0, openid4vp_1.isJarmResponseMode)(responseMode)) {
505
- const key = await agentContext.wallet.createKey({ keyType: core_1.KeyType.P256 });
506
- jarmEncryptionJwk = { ...(0, core_1.getJwkFromKey)(key).toJson(), kid: key.fingerprint, use: 'enc' };
507
- }
508
- const jarmClientMetadata = jarmEncryptionJwk
509
- ? {
510
- jwks: { keys: [jarmEncryptionJwk] },
511
- authorization_encrypted_response_alg: 'ECDH-ES',
512
- // FIXME: we need to allow setting this, but also to fetch it based on the `request_uri` and
513
- // `request_uri_method`
514
- authorization_encrypted_response_enc: 'A128GCM',
515
- }
516
- : undefined;
517
- return {
518
- ...jarmClientMetadata,
519
- ...verifier.clientMetadata,
520
- response_types_supported: ['vp_token'],
521
- subject_syntax_types_supported: [
522
- 'urn:ietf:params:oauth:jwk-thumbprint',
523
- ...supportedDidMethods.map((m) => `did:${m}`),
524
- ],
525
- authorization_signed_response_alg: 'RS256',
526
- vp_formats: {
527
- mso_mdoc: {
528
- alg: supportedMdocAlgs,
529
- },
530
- jwt_vc: {
531
- alg: supportedAlgs,
532
- },
533
- jwt_vc_json: {
534
- alg: supportedAlgs,
535
- },
536
- jwt_vp_json: {
537
- alg: supportedAlgs,
538
- },
539
- jwt_vp: {
540
- alg: supportedAlgs,
541
- },
542
- ldp_vc: {
543
- proof_type: supportedProofTypes,
544
- },
545
- ldp_vp: {
546
- proof_type: supportedProofTypes,
547
- },
548
- 'vc+sd-jwt': {
549
- 'kb-jwt_alg_values': supportedAlgs,
550
- 'sd-jwt_alg_values': supportedAlgs,
551
- },
552
- 'dc+sd-jwt': {
553
- 'kb-jwt_alg_values': supportedAlgs,
554
- 'sd-jwt_alg_values': supportedAlgs,
555
- },
556
- },
557
- };
558
- }
559
- getPresentationFromVpTokenParseResult(agentContext, vpTokenPresentationParseResult) {
560
- if (vpTokenPresentationParseResult.format === 'dc+sd-jwt') {
561
- const sdJwtVcApi = agentContext.dependencyManager.resolve(core_1.SdJwtVcApi);
562
- return sdJwtVcApi.fromCompact(vpTokenPresentationParseResult.presentation);
563
- }
564
- else if (vpTokenPresentationParseResult.format === 'mso_mdoc') {
565
- return core_1.MdocDeviceResponse.fromBase64Url(vpTokenPresentationParseResult.presentation);
566
- }
567
- else if (vpTokenPresentationParseResult.format === 'jwt_vp_json') {
568
- return core_1.W3cJwtVerifiablePresentation.fromSerializedJwt(vpTokenPresentationParseResult.presentation);
569
- }
570
- else if (vpTokenPresentationParseResult.format === 'ldp_vp') {
571
- return core_1.JsonTransformer.fromJSON(vpTokenPresentationParseResult.presentation, core_1.W3cJsonLdVerifiablePresentation);
572
- }
573
- throw new core_1.CredoError(`Unsupported presentation format. ${vpTokenPresentationParseResult.format}`);
574
- }
575
- getTransactionDataMeta(options) {
576
- const { vpTokenPresentationParseResult, transactionData, transactionDataResult, credentialId } = options;
577
- if (!transactionData) {
578
- throw new core_1.CredoError('Could not map transaction data result to the request');
579
- }
580
- const hashName = transactionDataResult.hashes_alg ?? 'sha-256';
581
- const presentationHashes = transactionDataResult.hashes;
582
- const transactionDataEntriesWithHash = transactionData.map((tdEntry) => {
583
- const hash = core_1.TypedArrayEncoder.toBase64URL(core_1.Hasher.hash(core_1.JsonEncoder.toBase64URL(tdEntry), hashName));
584
- return hash;
585
- });
586
- for (const [idx, hash] of transactionDataEntriesWithHash.entries()) {
587
- if (presentationHashes[idx] !== hash) {
588
- throw new core_1.CredoError(`Transaction data entry ${idx} does not match hash ${hash}`);
589
- }
590
- }
591
- return {
592
- credentialId,
593
- transactionData,
594
- transactionDataResult,
595
- path: vpTokenPresentationParseResult.path,
596
- };
597
- }
598
- decodePresentation(agentContext, options) {
599
- const { vpTokenPresentationParseResult } = options;
600
- if (vpTokenPresentationParseResult.format === 'dc+sd-jwt') {
601
- // TODO: it might be better here to look at the presentation submission to know
602
- // If presentation includes a ~, we assume it's an SD-JWT-VC
603
- const sdJwtVcApi = agentContext.dependencyManager.resolve(core_1.SdJwtVcApi);
604
- const sdJwtVc = sdJwtVcApi.fromCompact(vpTokenPresentationParseResult.presentation);
605
- return sdJwtVc;
606
- }
607
- else if (vpTokenPresentationParseResult.format === 'mso_mdoc') {
608
- const mdocDeviceResponse = core_1.MdocDeviceResponse.fromBase64Url(vpTokenPresentationParseResult.presentation);
609
- return mdocDeviceResponse;
610
- }
611
- else if (vpTokenPresentationParseResult.format === 'jwt_vp_json') {
612
- return core_1.W3cJwtVerifiablePresentation.fromSerializedJwt(vpTokenPresentationParseResult.presentation);
613
- }
614
- else {
615
- return core_1.JsonTransformer.fromJSON(vpTokenPresentationParseResult.presentation, core_1.W3cJsonLdVerifiablePresentation);
616
- }
617
- }
618
- async verifyPresentations(agentContext, options) {
619
- const { vpTokenPresentationParseResult, transactionData } = options;
620
- let transactionDataMeta = undefined;
621
- try {
622
- this.logger.debug(`Presentation response`, core_1.JsonTransformer.toJSON(vpTokenPresentationParseResult.presentation));
623
- if (!vpTokenPresentationParseResult)
624
- throw new core_1.CredoError('Did not receive a presentation for verification.');
625
- const x509Config = agentContext.dependencyManager.resolve(core_1.X509ModuleConfig);
626
- let isValid;
627
- let reason = undefined;
628
- let verifiablePresentation;
629
- if (vpTokenPresentationParseResult.format === 'dc+sd-jwt') {
630
- // TODO: it might be better here to look at the presentation submission to know
631
- // If presentation includes a ~, we assume it's an SD-JWT-VC
632
- const sdJwtVcApi = agentContext.dependencyManager.resolve(core_1.SdJwtVcApi);
633
- const jwt = core_1.Jwt.fromSerializedJwt(vpTokenPresentationParseResult.presentation.split('~')[0]);
634
- const sdJwtVc = sdJwtVcApi.fromCompact(vpTokenPresentationParseResult.presentation);
635
- const certificateChain = (0, core_1.extractX509CertificatesFromJwt)(jwt);
636
- let trustedCertificates = undefined;
637
- if (certificateChain && x509Config.getTrustedCertificatesForVerification) {
638
- trustedCertificates = await x509Config.getTrustedCertificatesForVerification(agentContext, {
639
- certificateChain,
640
- verification: {
641
- type: 'credential',
642
- credential: sdJwtVc,
643
- openId4VcVerificationSessionId: options.verificationSessionRecordId,
644
- },
645
- });
646
- }
647
- if (!trustedCertificates) {
648
- // We also take from the config here to avoid the callback being called again
649
- trustedCertificates = x509Config.trustedCertificates ?? [];
650
- }
651
- const verificationResult = await sdJwtVcApi.verify({
652
- compactSdJwtVc: vpTokenPresentationParseResult.presentation,
653
- keyBinding: {
654
- audience: options.audience,
655
- nonce: options.nonce,
656
- },
657
- trustedCertificates,
658
- });
659
- if (verificationResult.sdJwtVc?.transactionData) {
660
- transactionDataMeta = this.getTransactionDataMeta({
661
- vpTokenPresentationParseResult,
662
- transactionData,
663
- transactionDataResult: verificationResult.sdJwtVc.transactionData,
664
- credentialId: options.credentialId,
665
- });
666
- }
667
- isValid = verificationResult.verification.isValid;
668
- reason = verificationResult.isValid ? undefined : verificationResult.error.message;
669
- verifiablePresentation = sdJwtVc;
670
- }
671
- else if (vpTokenPresentationParseResult.format === 'mso_mdoc') {
672
- const mdocDeviceResponse = core_1.MdocDeviceResponse.fromBase64Url(vpTokenPresentationParseResult.presentation);
673
- const trustedCertificates = (await Promise.all(mdocDeviceResponse.documents.map(async (mdoc) => {
674
- const certificateChain = mdoc.issuerSignedCertificateChain.map((cert) => core_1.X509Certificate.fromRawCertificate(cert));
675
- const trustedCertificates = await x509Config.getTrustedCertificatesForVerification?.(agentContext, {
676
- certificateChain,
677
- verification: {
678
- type: 'credential',
679
- credential: mdoc,
680
- openId4VcVerificationSessionId: options.verificationSessionRecordId,
681
- },
682
- });
683
- // TODO: could have some duplication but not a big issue
684
- return trustedCertificates ?? x509Config.trustedCertificates;
685
- })))
686
- .filter((c) => c !== undefined)
687
- .flatMap((c) => c);
688
- let sessionTranscriptOptions;
689
- if (options.origin) {
690
- sessionTranscriptOptions = {
691
- type: 'openId4VpDcApi',
692
- clientId: options.audience,
693
- verifierGeneratedNonce: options.nonce,
694
- origin: options.origin,
695
- };
696
- }
697
- else {
698
- if (!options.mdocGeneratedNonce || !options.responseUri) {
699
- throw new core_1.CredoError('mdocGeneratedNonce and responseUri are required for mdoc openid4vp session transcript calculation');
700
- }
701
- sessionTranscriptOptions = {
702
- type: 'openId4Vp',
703
- clientId: options.audience,
704
- mdocGeneratedNonce: options.mdocGeneratedNonce,
705
- responseUri: options.responseUri,
706
- verifierGeneratedNonce: options.nonce,
707
- };
708
- }
709
- await mdocDeviceResponse.verify(agentContext, {
710
- sessionTranscriptOptions,
711
- trustedCertificates,
712
- });
713
- isValid = true;
714
- verifiablePresentation = mdocDeviceResponse;
715
- }
716
- else if (vpTokenPresentationParseResult.format === 'jwt_vp_json') {
717
- const sdJwtPresentation = core_1.W3cJwtVerifiablePresentation.fromSerializedJwt(vpTokenPresentationParseResult.presentation);
718
- const certificateChain = (0, core_1.extractX509CertificatesFromJwt)(sdJwtPresentation.jwt);
719
- let trustedCertificates = undefined;
720
- if (certificateChain && x509Config.getTrustedCertificatesForVerification) {
721
- trustedCertificates = await x509Config.getTrustedCertificatesForVerification?.(agentContext, {
722
- certificateChain,
723
- verification: {
724
- type: 'credential',
725
- credential: sdJwtPresentation,
726
- openId4VcVerificationSessionId: options.verificationSessionRecordId,
727
- },
728
- });
729
- }
730
- if (!trustedCertificates) {
731
- trustedCertificates = x509Config.trustedCertificates ?? [];
732
- }
733
- const verificationResult = await this.w3cCredentialService.verifyPresentation(agentContext, {
734
- presentation: vpTokenPresentationParseResult.presentation,
735
- challenge: options.nonce,
736
- domain: options.audience,
737
- trustedCertificates,
738
- });
739
- isValid = verificationResult.isValid;
740
- reason = verificationResult.error?.message;
741
- verifiablePresentation = core_1.W3cJwtVerifiablePresentation.fromSerializedJwt(vpTokenPresentationParseResult.presentation);
742
- }
743
- else {
744
- const w3cJsonLdVerifiablePresentation = core_1.JsonTransformer.fromJSON(vpTokenPresentationParseResult.presentation, core_1.W3cJsonLdVerifiablePresentation);
745
- const verificationResult = await this.w3cCredentialService.verifyPresentation(agentContext, {
746
- presentation: w3cJsonLdVerifiablePresentation,
747
- challenge: options.nonce,
748
- domain: options.audience,
749
- });
750
- isValid = verificationResult.isValid;
751
- reason = verificationResult.error?.message;
752
- verifiablePresentation = w3cJsonLdVerifiablePresentation;
753
- }
754
- if (!isValid) {
755
- throw new Error(reason);
756
- }
757
- return {
758
- verified: true,
759
- transactionDataMeta,
760
- presentation: verifiablePresentation,
761
- credentialId: options.credentialId,
762
- };
763
- }
764
- catch (error) {
765
- agentContext.config.logger.warn('Error occurred during verification of presentation', {
766
- error,
767
- });
768
- return {
769
- verified: false,
770
- reason: error.message,
771
- credentialId: options.credentialId,
772
- };
773
- }
774
- }
775
- /**
776
- * Update the record to a new state and emit an state changed event. Also updates the record
777
- * in storage.
778
- */
779
- async updateState(agentContext, verificationSession, newState) {
780
- agentContext.config.logger.debug(`Updating openid4vc verification session record ${verificationSession.id} to state ${newState} (previous=${verificationSession.state})`);
781
- const previousState = verificationSession.state;
782
- verificationSession.state = newState;
783
- await this.openId4VcVerificationSessionRepository.update(agentContext, verificationSession);
784
- this.emitStateChangedEvent(agentContext, verificationSession, previousState);
785
- }
786
- emitStateChangedEvent(agentContext, verificationSession, previousState) {
787
- const eventEmitter = agentContext.dependencyManager.resolve(core_1.EventEmitter);
788
- eventEmitter.emit(agentContext, {
789
- type: OpenId4VcVerifierEvents_1.OpenId4VcVerifierEvents.VerificationSessionStateChanged,
790
- payload: {
791
- verificationSession: verificationSession.clone(),
792
- previousState,
793
- },
794
- });
795
- }
796
- };
797
- exports.OpenId4VcSiopVerifierService = OpenId4VcSiopVerifierService;
798
- exports.OpenId4VcSiopVerifierService = OpenId4VcSiopVerifierService = __decorate([
799
- (0, core_1.injectable)(),
800
- __param(0, (0, core_1.inject)(core_1.InjectionSymbols.Logger)),
801
- __metadata("design:paramtypes", [Object, core_1.W3cCredentialService,
802
- repository_1.OpenId4VcVerifierRepository,
803
- OpenId4VcVerifierModuleConfig_1.OpenId4VcVerifierModuleConfig,
804
- repository_1.OpenId4VcVerificationSessionRepository])
805
- ], OpenId4VcSiopVerifierService);
806
- //# sourceMappingURL=OpenId4VcSiopVerifierService.js.map