-
Notifications
You must be signed in to change notification settings - Fork 14
/
handler.ts
707 lines (636 loc) · 22.8 KB
/
handler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
import type {
ConnectionRecord,
CredentialStateChangedEvent,
DifPresentationExchangeDefinitionV2,
OutOfBandInvitation,
OutOfBandRecord,
P256Jwk,
ProofStateChangedEvent,
} from '@credo-ts/core'
import type { PlaintextMessage } from '@credo-ts/core/build/types'
import type {
OpenId4VciCredentialConfigurationSupportedWithFormats,
OpenId4VciDpopRequestOptions,
OpenId4VciRequestTokenResponse,
OpenId4VciResolvedAuthorizationRequest,
OpenId4VciResolvedCredentialOffer,
} from '@credo-ts/openid4vc'
import { getOid4vciCallbacks } from '@credo-ts/openid4vc/build/shared/callbacks'
import { Linking } from 'react-native'
import type { EitherAgent, FullAppAgent } from '../agent'
import { V1OfferCredentialMessage, V1RequestPresentationMessage } from '@credo-ts/anoncreds'
import {
CredentialEventTypes,
CredentialState,
JwaSignatureAlgorithm,
Jwt,
OutOfBandRepository,
ProofEventTypes,
ProofState,
V2OfferCredentialMessage,
V2RequestPresentationMessage,
X509ModuleConfig,
parseMessageType,
} from '@credo-ts/core'
import { supportsIncomingMessageType } from '@credo-ts/core/build/utils/messageType'
import {
getOfferedCredentials,
getScopesFromCredentialConfigurationsSupported,
preAuthorizedCodeGrantIdentifier,
} from '@credo-ts/openid4vc'
import { getHostNameFromUrl } from '@package/utils'
import { filter, first, firstValueFrom, merge, timeout } from 'rxjs'
import { Oauth2Client, getAuthorizationServerMetadataFromList } from '@animo-id/oauth2'
import q from 'query-string'
import { credentialRecordFromCredential, encodeCredential } from '../format/credentialEncoding'
import {
type FormattedSubmission,
formatDcqlCredentialsForRequest,
formatDifPexCredentialsForRequest,
} from '../format/formatPresentation'
import { setBatchCredentialMetadata } from '../openid4vc/batchMetadata'
import { getCredentialBindingResolver } from '../openid4vc/credentialBindingResolver'
import { extractOpenId4VcCredentialMetadata, setOpenId4VcCredentialMetadata } from '../openid4vc/displayMetadata'
import { BiometricAuthenticationError } from './error'
import { fetchInvitationDataUrl } from './fetchInvitation'
import { TRUSTED_ENTITIES } from './trustedEntities'
import type { TrustedEntity } from './trustedEntities'
export async function resolveOpenId4VciOffer({
agent,
offer,
authorization,
customHeaders,
fetchAuthorization = true,
}: {
agent: EitherAgent
offer: { data?: string; uri?: string }
authorization?: { clientId: string; redirectUri: string }
customHeaders?: Record<string, unknown>
fetchAuthorization?: boolean
}) {
let offerUri = offer.uri
if (!offerUri && offer.data) {
// FIXME: Credo only support credential offer string, but we already parsed it before. So we construct an offer here
// but in the future we need to support the parsed offer in Credo directly
offerUri = `openid-credential-offer://credential_offer=${encodeURIComponent(JSON.stringify(offer.data))}`
} else if (!offerUri) {
throw new Error('either data or uri must be provided')
}
agent.config.logger.info(`Receiving openid uri ${offerUri}`, {
offerUri,
data: offer.data,
uri: offer.uri,
})
const resolvedCredentialOffer = await agent.modules.openId4VcHolder.resolveCredentialOffer(offerUri)
let resolvedAuthorizationRequest: OpenId4VciResolvedAuthorizationRequest | undefined = undefined
// NOTE: we always assume scopes are used at the moment
if (fetchAuthorization && resolvedCredentialOffer.credentialOfferPayload.grants?.authorization_code) {
// If only authorization_code grant is valid and user didn't provide authorization details we can't continue
if (!resolvedCredentialOffer.credentialOfferPayload.grants[preAuthorizedCodeGrantIdentifier] && !authorization) {
throw new Error(
"Missing 'authorization' parameter with 'clientId' and 'redirectUri' and authorization code flow is only allowed grant type on offer."
)
}
// TODO: authorization should only be initiated after we know which credentials we're going to request
if (authorization) {
resolvedAuthorizationRequest = await agent.modules.openId4VcHolder.resolveIssuanceAuthorizationRequest(
resolvedCredentialOffer,
{
redirectUri: authorization.redirectUri,
clientId: authorization.clientId,
scope: getScopesFromCredentialConfigurationsSupported(
resolvedCredentialOffer.offeredCredentialConfigurations
),
// Added in patch but not in types
// @ts-ignore
customHeaders,
}
)
}
}
return {
resolvedCredentialOffer,
resolvedAuthorizationRequest,
}
}
export async function acquirePreAuthorizedAccessToken({
agent,
resolvedCredentialOffer,
txCode,
}: {
agent: EitherAgent
resolvedCredentialOffer: OpenId4VciResolvedCredentialOffer
txCode?: string
}) {
return await agent.modules.openId4VcHolder.requestToken({
resolvedCredentialOffer,
txCode,
})
}
export async function acquireAuthorizationCodeUsingPresentation({
resolvedCredentialOffer,
agent,
authSession,
presentationDuringIssuanceSession,
dPopKeyJwk,
}: {
agent: EitherAgent
resolvedCredentialOffer: OpenId4VciResolvedCredentialOffer
dPopKeyJwk?: P256Jwk
authSession: string
presentationDuringIssuanceSession?: string
}) {
return await agent.modules.openId4VcHolder.retrieveAuthorizationCodeUsingPresentation({
authSession,
dpop: dPopKeyJwk
? {
alg: dPopKeyJwk.supportedSignatureAlgorithms[0],
jwk: dPopKeyJwk,
}
: undefined,
resolvedCredentialOffer,
presentationDuringIssuanceSession,
})
}
export async function acquireRefreshTokenAccessToken({
authorizationServer,
resolvedCredentialOffer,
agent,
clientId,
refreshToken,
dpop,
}: {
agent: EitherAgent
resolvedCredentialOffer: OpenId4VciResolvedCredentialOffer
authorizationServer: string
clientId: string
refreshToken: string
dpop?: OpenId4VciDpopRequestOptions
}): Promise<OpenId4VciRequestTokenResponse> {
const oauth2Client = new Oauth2Client({ callbacks: getOid4vciCallbacks(agent.context) })
// TODO: dpop retry also for this method
const accessTokenResponse = await oauth2Client.retrieveRefreshTokenAccessToken({
refreshToken,
resource: resolvedCredentialOffer.credentialOfferPayload.credential_issuer,
authorizationServerMetadata: getAuthorizationServerMetadataFromList(
resolvedCredentialOffer.metadata.authorizationServers,
authorizationServer
),
additionalRequestPayload: {
client_id: clientId,
},
dpop: dpop
? {
nonce: dpop.nonce,
signer: {
method: 'jwk',
alg: dpop.alg,
publicJwk: dpop.jwk.toJson(),
},
}
: undefined,
})
return {
accessToken: accessTokenResponse.accessTokenResponse.access_token,
cNonce: accessTokenResponse.accessTokenResponse.c_nonce,
dpop: dpop ? { ...dpop, nonce: accessTokenResponse.dpop?.nonce } : undefined,
accessTokenResponse: accessTokenResponse.accessTokenResponse,
}
}
export async function acquireAuthorizationCodeAccessToken({
resolvedCredentialOffer,
agent,
codeVerifier,
authorizationCode,
clientId,
redirectUri,
}: {
agent: EitherAgent
resolvedCredentialOffer: OpenId4VciResolvedCredentialOffer
codeVerifier?: string
authorizationCode: string
clientId: string
redirectUri?: string
}) {
return await agent.modules.openId4VcHolder.requestToken({
resolvedCredentialOffer,
code: authorizationCode,
codeVerifier,
redirectUri,
clientId,
})
}
export const receiveCredentialFromOpenId4VciOffer = async ({
agent,
resolvedCredentialOffer,
credentialConfigurationIdsToRequest,
accessToken,
clientId,
pidSchemes,
requestBatch,
}: {
agent: EitherAgent
resolvedCredentialOffer: OpenId4VciResolvedCredentialOffer
credentialConfigurationIdsToRequest?: string[]
clientId?: string
pidSchemes?: { sdJwtVcVcts: Array<string>; msoMdocDoctypes: Array<string> }
requestBatch?: boolean | number
// TODO: cNonce should maybe be provided separately (multiple calls can have different c_nonce values)
accessToken: OpenId4VciRequestTokenResponse
}) => {
const offeredCredentialsToRequest = getOfferedCredentials(
credentialConfigurationIdsToRequest ?? [
resolvedCredentialOffer.credentialOfferPayload.credential_configuration_ids[0],
],
resolvedCredentialOffer.offeredCredentialConfigurations
) as OpenId4VciCredentialConfigurationSupportedWithFormats
if (Object.keys(offeredCredentialsToRequest).length === 0) {
throw new Error(
`Parameter 'credentialConfigurationIdsToRequest' with values ${credentialConfigurationIdsToRequest} is not a credential_configuration_id in the credential offer.`
)
}
try {
const credentials = await agent.modules.openId4VcHolder.requestCredentials({
resolvedCredentialOffer,
...accessToken,
clientId,
credentialConfigurationIds: Object.keys(offeredCredentialsToRequest),
verifyCredentialStatus: false,
requestBatch,
allowedProofOfPossessionSignatureAlgorithms: [
// NOTE: MATTR launchpad for JFF MUST use EdDSA. So it is important that the default (first allowed one)
// is EdDSA. The list is ordered by preference, so if no suites are defined by the issuer, the first one
// will be used
JwaSignatureAlgorithm.EdDSA,
JwaSignatureAlgorithm.ES256,
],
credentialBindingResolver: getCredentialBindingResolver({
pidSchemes,
resolvedCredentialOffer,
}),
})
return credentials.credentials.map(({ credentials, ...credentialResponse }) => {
const configuration = resolvedCredentialOffer.offeredCredentialConfigurations[
credentialResponse.credentialConfigurationId
] as OpenId4VciCredentialConfigurationSupportedWithFormats
const firstCredential = credentials[0]
const record = credentialRecordFromCredential(firstCredential)
// OpenID4VC metadata
const openId4VcMetadata = extractOpenId4VcCredentialMetadata(configuration, {
id: resolvedCredentialOffer.metadata.credentialIssuer.credential_issuer,
display: resolvedCredentialOffer.metadata.credentialIssuer.display,
})
setOpenId4VcCredentialMetadata(record, openId4VcMetadata)
// Match metadata
if (credentials.length > 1) {
setBatchCredentialMetadata(record, {
additionalCredentials: credentials.slice(1).map(encodeCredential) as
| Array<string>
| Array<Record<string, unknown>>,
})
}
return {
...credentialResponse,
configuration,
credential: record,
}
})
} catch (error) {
// TODO: if one biometric operation fails it will fail the whole credential receiving. We should have more control so we
// can retry e.g. the second credential
// Handle biometric authentication errors
throw BiometricAuthenticationError.tryParseFromError(error) ?? error
}
}
const extractEntityIdFromJwt = (jwt: string): string | null => {
const jwtPayload = Jwt.fromSerializedJwt(jwt).payload
if (jwtPayload?.additionalClaims?.client_id_scheme !== 'entity_id') return null
const clientId = jwtPayload?.additionalClaims?.client_id
if (!clientId || typeof clientId !== 'string') return null
return clientId
}
/**
* This is a temp method to allow for untrusted certificates to still work with the wallet.
*/
export const extractEntityIdFromAuthorizationRequest = async ({
data,
uri,
}: { data?: string; uri?: string }): Promise<{ data: string | null; entityId: string | null }> => {
try {
if (data) {
return {
data,
entityId: extractEntityIdFromJwt(data),
}
}
if (uri) {
const query = q.parseUrl(uri).query
if (query.request_uri && typeof query.request_uri === 'string') {
const result = await fetchInvitationDataUrl(query.request_uri)
if (
result.success &&
result.result.type === 'openid-authorization-request' &&
typeof result.result.data === 'string'
) {
return {
data: result.result.data,
entityId: extractEntityIdFromJwt(result.result.data),
}
}
} else if (query.request && typeof query.request === 'string') {
return {
data: query.request,
entityId: extractEntityIdFromJwt(query.request),
}
}
}
} catch (error) {
console.error(error)
}
return { data: null, entityId: null }
}
const extractCertificateFromJwt = (jwt: string) => {
const jwtHeader = Jwt.fromSerializedJwt(jwt).header
return Array.isArray(jwtHeader.x5c) && typeof jwtHeader.x5c[0] === 'string' ? jwtHeader.x5c[0] : null
}
/**
* This is a temp method to allow for untrusted certificates to still work with the wallet.
*/
export const extractCertificateFromAuthorizationRequest = async ({
data,
uri,
}: { data?: string; uri?: string }): Promise<{ data: string | null; certificate: string | null }> => {
try {
if (data) {
return {
data,
certificate: extractCertificateFromJwt(data),
}
}
if (uri) {
const query = q.parseUrl(uri).query
if (query.request_uri && typeof query.request_uri === 'string') {
const result = await fetchInvitationDataUrl(query.request_uri)
if (
result.success &&
result.result.type === 'openid-authorization-request' &&
typeof result.result.data === 'string'
) {
return {
data: result.result.data,
certificate: extractCertificateFromJwt(result.result.data),
}
}
} else if (query.request && typeof query.request === 'string') {
return {
data: query.request,
certificate: extractCertificateFromJwt(query.request),
}
}
}
return { data: null, certificate: null }
} catch (error) {
return { data: null, certificate: null }
}
}
export async function withTrustedCertificate<T>(
agent: EitherAgent,
certificate: string | null,
method: () => Promise<T> | T
): Promise<T> {
const x509ModuleConfig = agent.dependencyManager.resolve(X509ModuleConfig)
const currentTrustedCertificates = x509ModuleConfig.trustedCertificates
? [...x509ModuleConfig.trustedCertificates]
: []
try {
if (certificate) agent.x509.addTrustedCertificate(certificate)
return await method()
} finally {
if (certificate) x509ModuleConfig.setTrustedCertificates(currentTrustedCertificates as [string])
}
}
export type CredentialsForProofRequest = Awaited<ReturnType<typeof getCredentialsForProofRequest>>
export type GetCredentialsForProofRequestOptions = {
agent: EitherAgent
data?: string
uri?: string
allowUntrustedFederation?: boolean
}
export const getCredentialsForProofRequest = async ({
agent,
data,
uri,
allowUntrustedFederation = true,
}: GetCredentialsForProofRequestOptions) => {
let requestUri: string
let requestData = data
const { entityId = undefined, data: fromFederationData = null } = allowUntrustedFederation
? await extractEntityIdFromAuthorizationRequest({ data: requestData, uri })
: {}
requestData = fromFederationData ?? requestData
if (requestData) {
// FIXME: Credo only support request string, but we already parsed it before. So we construct an request here
// but in the future we need to support the parsed request in Credo directly
requestUri = `openid://?request=${encodeURIComponent(requestData)}`
} else if (uri) {
requestUri = uri
} else {
throw new Error('Either data or uri must be provided')
}
agent.config.logger.info(`Receiving openid uri ${requestUri}`, {
data,
uri,
requestUri,
})
const resolved = await agent.modules.openId4VcHolder.resolveSiopAuthorizationRequest(requestUri, {
...(entityId ? { federation: { trustedEntityIds: [entityId] } } : {}),
})
let trustedEntities: Array<TrustedEntity> = []
if (entityId) {
// TODO: Remove me when the new credo-ts version is used
if (resolved.authorizationRequest.payload) {
resolved.authorizationRequest.payload.client_metadata =
resolved.authorizationRequest.authorizationRequestPayload.client_metadata
}
const resolvedChains = await agent.modules.openId4VcHolder.resolveOpenIdFederationChains({
entityId: entityId,
trustAnchorEntityIds: TRUSTED_ENTITIES,
})
trustedEntities = resolvedChains
.map((chain) => ({
entity_id: chain.trustAnchorEntityConfiguration.sub,
organization_name:
chain.trustAnchorEntityConfiguration.metadata?.federation_entity?.organization_name ?? 'Unknown entity',
logo_uri: chain.trustAnchorEntityConfiguration.metadata?.federation_entity?.logo_uri,
}))
.filter((entity, index, self) => self.findIndex((e) => e.entity_id === entity.entity_id) === index)
}
let formattedSubmission: FormattedSubmission
if (resolved.presentationExchange) {
formattedSubmission = formatDifPexCredentialsForRequest(
resolved.presentationExchange.credentialsForRequest,
resolved.presentationExchange.definition as DifPresentationExchangeDefinitionV2
)
} else if (resolved.dcql) {
formattedSubmission = formatDcqlCredentialsForRequest(resolved.dcql.queryResult)
} else {
throw new Error('No presentation exchange or dcql found in authorization request.')
}
const clientMetadata = resolved.authorizationRequest.payload?.client_metadata as
| {
client_name?: string
logo_uri?: string
}
| undefined
return {
...resolved.presentationExchange,
...resolved.dcql,
authorizationRequest: resolved.authorizationRequest,
verifier: {
hostName: resolved.authorizationRequest.responseURI
? getHostNameFromUrl(resolved.authorizationRequest.responseURI)
: undefined,
entityId: entityId ?? (resolved.authorizationRequest.payload?.iss as string),
logo: clientMetadata?.logo_uri
? {
url: clientMetadata?.logo_uri,
}
: undefined,
name: clientMetadata?.client_name,
trustedEntities,
},
formattedSubmission,
} as const
}
/**
* @todo we probably need a way to cancel this method, if the qr scanner is .e.g dismissed.
*/
export async function receiveOutOfBandInvitation(
agent: FullAppAgent,
invitation: OutOfBandInvitation
): Promise<
| { success: true; id: string; type: 'credentialExchange' }
| { success: true; id: string; type: 'proofExchange' }
| { success: false; error: string }
> {
const requestMessages = invitation.getRequests() ?? []
if (requestMessages.length > 1) {
const message = 'Message contains multiple requests. Invitation should only contain a single request.'
agent.config.logger.error(message)
return {
success: false,
error: message,
}
}
// In this case we probably need to create a connection first. We will do this here, as we don't allow to just
// create a connection
if (requestMessages.length === 0) {
if (!invitation.handshakeProtocols || invitation.handshakeProtocols.length === 0) {
agent.config.logger.error('No requests and no handshake protocols found in invitation.')
return {
success: false,
error: 'Invalid invitation.',
}
}
}
// Validate the type of the request message
else {
const requestMessage = requestMessages[0] as PlaintextMessage
const parsedMessageType = parseMessageType(requestMessage['@type'])
const isValidRequestMessage =
supportsIncomingMessageType(parsedMessageType, V1OfferCredentialMessage.type) ||
supportsIncomingMessageType(parsedMessageType, V2OfferCredentialMessage.type) ||
supportsIncomingMessageType(parsedMessageType, V1RequestPresentationMessage.type) ||
supportsIncomingMessageType(parsedMessageType, V2RequestPresentationMessage.type)
if (!isValidRequestMessage) {
agent.config.logger.error('Message request is not from supported protocol.')
return {
success: false,
error: 'Invalid invitation.',
}
}
}
// The value is reassigned, but eslint doesn't know this.
// eslint-disable-next-line prefer-const
let connectionId: string | undefined
const credentialOffer = agent.events
.observable<CredentialStateChangedEvent>(CredentialEventTypes.CredentialStateChanged)
.pipe(
filter((event) => event.payload.credentialRecord.state === CredentialState.OfferReceived),
filter((event) => event.payload.credentialRecord.connectionId === connectionId)
)
const proofRequest = agent.events.observable<ProofStateChangedEvent>(ProofEventTypes.ProofStateChanged).pipe(
filter((event) => event.payload.proofRecord.state === ProofState.RequestReceived),
filter((event) => event.payload.proofRecord.connectionId === connectionId)
)
const eventPromise = firstValueFrom(
merge(credentialOffer, proofRequest).pipe(
first(),
// We allow 15 seconds to receive a credential offer or proof request
timeout(15 * 1000)
)
)
let connectionRecord: ConnectionRecord | undefined
let outOfBandRecord: OutOfBandRecord
try {
// Check if invitation already exists
const receivedInvite = await agent.oob.findByReceivedInvitationId(invitation.id)
if (receivedInvite) {
return {
success: false,
error: 'Invitation has already been scanned.',
}
}
const receiveInvitationResult = await agent.oob.receiveInvitation(invitation, {
reuseConnection: true,
})
connectionRecord = receiveInvitationResult.connectionRecord
outOfBandRecord = receiveInvitationResult.outOfBandRecord
// Assign connectionId so it can be used in the observables.
connectionId = connectionRecord?.id
} catch (error) {
agent.config.logger.error(`Error while receiving invitation: ${error as string}`)
return {
success: false,
error: 'Invalid invitation.',
}
}
try {
const event = await eventPromise
agent.config.logger.debug(`Received event ${event.type}`)
if (event.type === CredentialEventTypes.CredentialStateChanged) {
return {
success: true,
id: event.payload.credentialRecord.id,
type: 'credentialExchange',
}
}
if (event.type === ProofEventTypes.ProofStateChanged) {
return {
success: true,
id: event.payload.proofRecord.id,
type: 'proofExchange',
}
}
} catch (error) {
agent.config.logger.error(
'Error while waiting for credential offer or proof request. Deleting connection and records'
)
// Delete OOB record
const outOfBandRepository = agent.dependencyManager.resolve(OutOfBandRepository)
await outOfBandRepository.deleteById(agent.context, outOfBandRecord.id)
// Delete connection record
// TODO: delete did and mediation stuff
if (connectionRecord) {
await agent.connections.deleteById(connectionRecord.id)
}
return {
success: false,
error: 'Invalid invitation.',
}
}
return {
success: false,
error: 'Invalid invitation.',
}
}