@verana-labs/credo-ts-didcomm-vt-flow 2.0.0-dev.11 → 2.0.0-dev.110
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/VtFlowApi.d.ts +22 -3
- package/build/VtFlowApi.js +129 -14
- package/build/VtFlowApi.js.map +1 -1
- package/build/VtFlowModule.js +27 -18
- package/build/VtFlowModule.js.map +1 -1
- package/build/VtFlowModuleConfig.d.ts +45 -3
- package/build/VtFlowModuleConfig.js +16 -1
- package/build/VtFlowModuleConfig.js.map +1 -1
- package/build/errors/VtFlowErrorCode.d.ts +13 -3
- package/build/errors/VtFlowErrorCode.js +62 -18
- package/build/errors/VtFlowErrorCode.js.map +1 -1
- package/build/errors/buildVtFlowProblemReport.d.ts +5 -2
- package/build/errors/buildVtFlowProblemReport.js +8 -3
- package/build/errors/buildVtFlowProblemReport.js.map +1 -1
- package/build/errors/index.d.ts +3 -3
- package/build/errors/index.js +4 -1
- package/build/errors/index.js.map +1 -1
- package/build/handlers/IssuanceRequestHandler.d.ts +2 -1
- package/build/handlers/IssuanceRequestHandler.js +11 -2
- package/build/handlers/IssuanceRequestHandler.js.map +1 -1
- package/build/handlers/OnboardingRequestHandler.d.ts +2 -1
- package/build/handlers/OnboardingRequestHandler.js +11 -2
- package/build/handlers/OnboardingRequestHandler.js.map +1 -1
- package/build/handlers/ProblemReportHandler.d.ts +10 -0
- package/build/handlers/ProblemReportHandler.js +17 -0
- package/build/handlers/ProblemReportHandler.js.map +1 -0
- package/build/handlers/index.d.ts +1 -0
- package/build/handlers/index.js +3 -1
- package/build/handlers/index.js.map +1 -1
- package/build/index.d.ts +5 -4
- package/build/index.js +12 -1
- package/build/index.js.map +1 -1
- package/build/messages/ValidatingMessage.d.ts +1 -1
- package/build/messages/ValidatingMessage.js +1 -1
- package/build/messages/ValidatingMessage.js.map +1 -1
- package/build/messages/VtFlowProblemReportMessage.d.ts +13 -0
- package/build/messages/VtFlowProblemReportMessage.js +53 -0
- package/build/messages/VtFlowProblemReportMessage.js.map +1 -0
- package/build/messages/VtFlowProtocol.d.ts +3 -1
- package/build/messages/VtFlowProtocol.js +4 -2
- package/build/messages/VtFlowProtocol.js.map +1 -1
- package/build/messages/index.d.ts +2 -1
- package/build/messages/index.js +4 -1
- package/build/messages/index.js.map +1 -1
- package/build/repository/VtFlowRecord.d.ts +25 -7
- package/build/repository/VtFlowRecord.js +10 -3
- package/build/repository/VtFlowRecord.js.map +1 -1
- package/build/services/VtFlowService.d.ts +73 -17
- package/build/services/VtFlowService.js +466 -89
- package/build/services/VtFlowService.js.map +1 -1
- package/build/types.d.ts +100 -5
- package/build/types.js +66 -2
- package/build/types.js.map +1 -1
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.js +6 -0
- package/build/utils/index.js.map +1 -0
- package/build/utils/peerAnchorDid.d.ts +2 -0
- package/build/utils/peerAnchorDid.js +12 -0
- package/build/utils/peerAnchorDid.js.map +1 -0
- package/package.json +5 -5
|
@@ -19,6 +19,7 @@ const VtFlowModuleConfig_1 = require("../VtFlowModuleConfig");
|
|
|
19
19
|
const errors_1 = require("../errors");
|
|
20
20
|
const messages_1 = require("../messages");
|
|
21
21
|
const repository_1 = require("../repository");
|
|
22
|
+
const utils_1 = require("../utils");
|
|
22
23
|
const types_1 = require("../types");
|
|
23
24
|
/** Core state machine for vt-flow; each method performs one transition and returns the wire message without dispatching (dispatch lives in `VtFlowApi`). */
|
|
24
25
|
let VtFlowService = class VtFlowService {
|
|
@@ -31,7 +32,7 @@ let VtFlowService = class VtFlowService {
|
|
|
31
32
|
/** Applicant-side OnboardingProcess: build the outbound `onboarding-request` and persist a record in `OR_SENT`. */
|
|
32
33
|
async createOnboardingProcessRecord(agentContext, params) {
|
|
33
34
|
const message = new messages_1.OnboardingRequestMessage({
|
|
34
|
-
participantId: params.
|
|
35
|
+
participantId: params.applicantParticipantId,
|
|
35
36
|
participantSessionId: params.participantSessionId,
|
|
36
37
|
agentParticipantId: params.agentParticipantId,
|
|
37
38
|
walletAgentParticipantId: params.walletAgentParticipantId,
|
|
@@ -40,7 +41,7 @@ let VtFlowService = class VtFlowService {
|
|
|
40
41
|
message.setThread({ threadId: message.id });
|
|
41
42
|
const existing = await this.repository.findByParticipantSessionId(agentContext, params.participantSessionId, types_1.VtFlowRole.Applicant);
|
|
42
43
|
if (existing) {
|
|
43
|
-
if (
|
|
44
|
+
if (!(0, types_1.isVtFlowRenewable)(existing)) {
|
|
44
45
|
throw new core_1.CredoError(`vt-flow: participant_session_id '${params.participantSessionId}' already belongs to a flow in state ${existing.state}; use a new session id`);
|
|
45
46
|
}
|
|
46
47
|
existing.connectionId = params.connectionId;
|
|
@@ -59,7 +60,10 @@ let VtFlowService = class VtFlowService {
|
|
|
59
60
|
variant: types_1.VtFlowVariant.OnboardingProcess,
|
|
60
61
|
agentParticipantId: params.agentParticipantId,
|
|
61
62
|
walletAgentParticipantId: params.walletAgentParticipantId,
|
|
62
|
-
|
|
63
|
+
applicantParticipantId: params.applicantParticipantId,
|
|
64
|
+
applicantParticipantRole: params.applicantParticipantRole,
|
|
65
|
+
validatorParticipantId: params.validatorParticipantId,
|
|
66
|
+
schemaId: params.schemaId,
|
|
63
67
|
claims: params.claims,
|
|
64
68
|
});
|
|
65
69
|
await this.repository.save(agentContext, record);
|
|
@@ -92,34 +96,55 @@ let VtFlowService = class VtFlowService {
|
|
|
92
96
|
this.emitStateChanged(agentContext, record, null);
|
|
93
97
|
return { message, record };
|
|
94
98
|
}
|
|
99
|
+
async reattachOnboardingProcessRecord(agentContext, params) {
|
|
100
|
+
const record = await this.repository.getById(agentContext, params.vtFlowRecordId);
|
|
101
|
+
record.assertRole(types_1.VtFlowRole.Applicant);
|
|
102
|
+
record.assertVariant(types_1.VtFlowVariant.OnboardingProcess);
|
|
103
|
+
if ((0, types_1.isVtFlowTerminalState)(record.state) ||
|
|
104
|
+
record.state === types_1.VtFlowState.Completed ||
|
|
105
|
+
record.state === types_1.VtFlowState.CredRevoked) {
|
|
106
|
+
throw new core_1.CredoError(`vt-flow: flow '${record.id}' in state ${record.state} cannot be re-attached`);
|
|
107
|
+
}
|
|
108
|
+
if (!record.applicantParticipantId)
|
|
109
|
+
throw new core_1.CredoError(`vt-flow: flow '${record.id}' has no participant_id`);
|
|
110
|
+
const message = new messages_1.OnboardingRequestMessage({
|
|
111
|
+
participantId: record.applicantParticipantId,
|
|
112
|
+
participantSessionId: record.participantSessionId,
|
|
113
|
+
agentParticipantId: record.agentParticipantId,
|
|
114
|
+
walletAgentParticipantId: record.walletAgentParticipantId,
|
|
115
|
+
claims: record.claims,
|
|
116
|
+
proofsAttach: record.proofsAttach,
|
|
117
|
+
});
|
|
118
|
+
message.setThread({ threadId: record.threadId });
|
|
119
|
+
record.connectionId = params.connectionId;
|
|
120
|
+
if (record.state === types_1.VtFlowState.CredOffered) {
|
|
121
|
+
await this.releaseCredentialExchange(agentContext, record);
|
|
122
|
+
await this.updateState(agentContext, record, types_1.VtFlowState.Validating);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
await this.repository.update(agentContext, record);
|
|
126
|
+
}
|
|
127
|
+
return { message, record };
|
|
128
|
+
}
|
|
129
|
+
async releaseCredentialExchange(agentContext, record) {
|
|
130
|
+
if (record.credentialExchangeRecordId) {
|
|
131
|
+
const exchanges = agentContext.dependencyManager.resolve(didcomm_1.DidCommCredentialExchangeRepository);
|
|
132
|
+
const stale = await exchanges.findById(agentContext, record.credentialExchangeRecordId);
|
|
133
|
+
if (stale) {
|
|
134
|
+
stale.parentThreadId = undefined;
|
|
135
|
+
await exchanges.update(agentContext, stale);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
record.credentialExchangeRecordId = undefined;
|
|
139
|
+
record.subprotocolThid = undefined;
|
|
140
|
+
record.issuance = undefined;
|
|
141
|
+
}
|
|
95
142
|
/** Validator-side OnboardingProcess: create or re-attach (by `participant_session_id`) a record in `AWAITING_OR` from an inbound `onboarding-request`. */
|
|
96
143
|
async processReceiveOnboardingRequest(messageContext) {
|
|
97
144
|
const { message, agentContext } = messageContext;
|
|
98
145
|
const connection = messageContext.assertReadyConnection();
|
|
99
|
-
await this.checkIsVerifiableService(agentContext, connection);
|
|
100
146
|
const existing = await this.repository.findByParticipantSessionId(agentContext, message.participantSessionId, types_1.VtFlowRole.Validator);
|
|
101
|
-
|
|
102
|
-
if ((0, types_1.isVtFlowTerminalState)(existing.state)) {
|
|
103
|
-
throw new core_1.CredoError(`vt-flow: participant_session_id '${message.participantSessionId}' collides with a terminated flow`);
|
|
104
|
-
}
|
|
105
|
-
await this.assertSamePeer(agentContext, existing, connection);
|
|
106
|
-
existing.connectionId = connection.id;
|
|
107
|
-
existing.threadId = message.threadId;
|
|
108
|
-
if (message.claims)
|
|
109
|
-
existing.claims = message.claims;
|
|
110
|
-
if (message.proofsAttach)
|
|
111
|
-
existing.proofsAttach = message.proofsAttach;
|
|
112
|
-
if (existing.state === types_1.VtFlowState.Completed || existing.state === types_1.VtFlowState.CredRevoked) {
|
|
113
|
-
// A finished flow re-entered with a new OR is a renewal (VSA-VTI-FLOW-OP-RENEW): re-run it.
|
|
114
|
-
existing.oobLinkUrl = undefined;
|
|
115
|
-
await this.updateState(agentContext, existing, types_1.VtFlowState.AwaitingOr);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
await this.repository.update(agentContext, existing);
|
|
119
|
-
}
|
|
120
|
-
return existing;
|
|
121
|
-
}
|
|
122
|
-
const record = new repository_1.VtFlowRecord({
|
|
147
|
+
const record = existing !== null && existing !== void 0 ? existing : new repository_1.VtFlowRecord({
|
|
123
148
|
threadId: message.threadId,
|
|
124
149
|
participantSessionId: message.participantSessionId,
|
|
125
150
|
connectionId: connection.id,
|
|
@@ -128,10 +153,55 @@ let VtFlowService = class VtFlowService {
|
|
|
128
153
|
variant: types_1.VtFlowVariant.OnboardingProcess,
|
|
129
154
|
agentParticipantId: message.agentParticipantId,
|
|
130
155
|
walletAgentParticipantId: message.walletAgentParticipantId,
|
|
131
|
-
|
|
156
|
+
applicantParticipantId: message.participantId,
|
|
132
157
|
claims: message.claims,
|
|
133
158
|
proofsAttach: message.proofsAttach,
|
|
134
159
|
});
|
|
160
|
+
await this.checkRequestFromVerifiableService(agentContext, connection, record, !existing, {
|
|
161
|
+
participantId: message.participantId,
|
|
162
|
+
});
|
|
163
|
+
if (existing) {
|
|
164
|
+
this.assertNotTerminated(existing);
|
|
165
|
+
if (existing.applicantParticipantId !== message.participantId) {
|
|
166
|
+
throw new errors_1.VtFlowError(errors_1.VtFlowErrorCode.InvalidParticipantSessionId, `vt-flow: participant_id '${message.participantId}' does not match the flow of participant_session_id '${message.participantSessionId}'`);
|
|
167
|
+
}
|
|
168
|
+
await this.assertSamePeer(agentContext, existing, connection);
|
|
169
|
+
// the checks above await, and a chain notification can move the flow meanwhile
|
|
170
|
+
const fresh = await this.repository.getById(agentContext, existing.id);
|
|
171
|
+
this.assertNotTerminated(fresh);
|
|
172
|
+
const reconnected = fresh.connectionTerminated;
|
|
173
|
+
fresh.connectionId = connection.id;
|
|
174
|
+
fresh.connectionTerminated = undefined;
|
|
175
|
+
if (fresh.threadId !== message.threadId) {
|
|
176
|
+
fresh.threadId = message.threadId;
|
|
177
|
+
if (fresh.state === types_1.VtFlowState.AwaitingOr || (0, types_1.isVtFlowRenewable)(fresh)) {
|
|
178
|
+
if (message.claims)
|
|
179
|
+
fresh.claims = message.claims;
|
|
180
|
+
if (message.proofsAttach)
|
|
181
|
+
fresh.proofsAttach = message.proofsAttach;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if ((0, types_1.isVtFlowRenewable)(fresh)) {
|
|
185
|
+
// A finished flow re-entered with a new OR is a renewal (VSA-VTI-FLOW-OP-RENEW): re-run it.
|
|
186
|
+
fresh.oobLink = undefined;
|
|
187
|
+
fresh.validation = undefined;
|
|
188
|
+
fresh.issuance = undefined;
|
|
189
|
+
await this.updateState(agentContext, fresh, types_1.VtFlowState.AwaitingOr);
|
|
190
|
+
}
|
|
191
|
+
else if (fresh.state === types_1.VtFlowState.CredOffered) {
|
|
192
|
+
await this.releaseCredentialExchange(agentContext, fresh);
|
|
193
|
+
await this.updateState(agentContext, fresh, types_1.VtFlowState.Validated);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
await this.repository.update(agentContext, fresh);
|
|
197
|
+
// [VSA-VTI-FLOW-OP-OR] checks every request, and [VSA-ADM-VT-FL-REJECT-2] issuance waits for this reconnection
|
|
198
|
+
if (fresh.state === types_1.VtFlowState.AwaitingOr ||
|
|
199
|
+
(reconnected && fresh.state === types_1.VtFlowState.Validated)) {
|
|
200
|
+
this.emitStateChanged(agentContext, fresh, fresh.state);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return fresh;
|
|
204
|
+
}
|
|
135
205
|
await this.repository.save(agentContext, record);
|
|
136
206
|
this.emitStateChanged(agentContext, record, null);
|
|
137
207
|
return record;
|
|
@@ -140,19 +210,8 @@ let VtFlowService = class VtFlowService {
|
|
|
140
210
|
async processReceiveIssuanceRequest(messageContext) {
|
|
141
211
|
const { message, agentContext } = messageContext;
|
|
142
212
|
const connection = messageContext.assertReadyConnection();
|
|
143
|
-
await this.checkIsVerifiableService(agentContext, connection);
|
|
144
213
|
const existing = await this.repository.findByParticipantSessionId(agentContext, message.participantSessionId, types_1.VtFlowRole.Validator);
|
|
145
|
-
|
|
146
|
-
if ((0, types_1.isVtFlowTerminalState)(existing.state)) {
|
|
147
|
-
throw new core_1.CredoError(`vt-flow: participant_session_id '${message.participantSessionId}' collides with a terminated flow`);
|
|
148
|
-
}
|
|
149
|
-
await this.assertSamePeer(agentContext, existing, connection);
|
|
150
|
-
existing.connectionId = connection.id;
|
|
151
|
-
existing.threadId = message.threadId;
|
|
152
|
-
await this.repository.update(agentContext, existing);
|
|
153
|
-
return existing;
|
|
154
|
-
}
|
|
155
|
-
const record = new repository_1.VtFlowRecord({
|
|
214
|
+
const record = existing !== null && existing !== void 0 ? existing : new repository_1.VtFlowRecord({
|
|
156
215
|
threadId: message.threadId,
|
|
157
216
|
participantSessionId: message.participantSessionId,
|
|
158
217
|
connectionId: connection.id,
|
|
@@ -164,20 +223,62 @@ let VtFlowService = class VtFlowService {
|
|
|
164
223
|
schemaId: message.schemaId,
|
|
165
224
|
claims: message.claims,
|
|
166
225
|
});
|
|
226
|
+
await this.checkRequestFromVerifiableService(agentContext, connection, record, !existing, {
|
|
227
|
+
schemaId: message.schemaId,
|
|
228
|
+
});
|
|
229
|
+
if (existing) {
|
|
230
|
+
this.assertNotTerminated(existing);
|
|
231
|
+
if (existing.variant !== types_1.VtFlowVariant.DirectIssuance || existing.schemaId !== message.schemaId) {
|
|
232
|
+
throw new errors_1.VtFlowError(errors_1.VtFlowErrorCode.InvalidParticipantSessionId, `vt-flow: schema_id '${message.schemaId}' does not match the flow of participant_session_id '${message.participantSessionId}'`);
|
|
233
|
+
}
|
|
234
|
+
await this.assertSamePeer(agentContext, existing, connection);
|
|
235
|
+
// the checks above await, and an auto accept can move the flow meanwhile
|
|
236
|
+
const fresh = await this.repository.getById(agentContext, existing.id);
|
|
237
|
+
this.assertNotTerminated(fresh);
|
|
238
|
+
fresh.connectionId = connection.id;
|
|
239
|
+
fresh.threadId = message.threadId;
|
|
240
|
+
if (fresh.state === types_1.VtFlowState.CredOffered) {
|
|
241
|
+
await this.releaseCredentialExchange(agentContext, fresh);
|
|
242
|
+
await this.updateState(agentContext, fresh, types_1.VtFlowState.Validating);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
await this.repository.update(agentContext, fresh);
|
|
246
|
+
}
|
|
247
|
+
return fresh;
|
|
248
|
+
}
|
|
167
249
|
await this.repository.save(agentContext, record);
|
|
168
250
|
this.emitStateChanged(agentContext, record, null);
|
|
169
251
|
return record;
|
|
170
252
|
}
|
|
171
|
-
/** Applicant-side inbound `oob-link`;
|
|
253
|
+
/** Applicant-side inbound `oob-link`; `OR_SENT`, `IR_SENT`, `VALIDATING` or `OOB_PENDING` => `OOB_PENDING`. */
|
|
172
254
|
async processReceiveOobLink(messageContext) {
|
|
255
|
+
var _a;
|
|
173
256
|
const { message, agentContext } = messageContext;
|
|
174
257
|
messageContext.assertReadyConnection();
|
|
175
258
|
const record = await this.getByThreadId(agentContext, message.threadId);
|
|
176
259
|
record.assertRole(types_1.VtFlowRole.Applicant);
|
|
260
|
+
record.assertState([
|
|
261
|
+
types_1.VtFlowState.OrSent,
|
|
262
|
+
types_1.VtFlowState.IrSent,
|
|
263
|
+
types_1.VtFlowState.Validating,
|
|
264
|
+
types_1.VtFlowState.OobPending,
|
|
265
|
+
]);
|
|
266
|
+
record.oobLink = {
|
|
267
|
+
url: message.url,
|
|
268
|
+
description: message.description,
|
|
269
|
+
expiresAt: (_a = message.expiresTime) === null || _a === void 0 ? void 0 : _a.toISOString(),
|
|
270
|
+
at: new Date().toISOString(),
|
|
271
|
+
};
|
|
272
|
+
this.appendMessage(record, {
|
|
273
|
+
type: types_1.VtFlowMessageType.OobLink,
|
|
274
|
+
text: message.description,
|
|
275
|
+
at: record.oobLink.at,
|
|
276
|
+
url: message.url,
|
|
277
|
+
});
|
|
177
278
|
await this.updateState(agentContext, record, types_1.VtFlowState.OobPending);
|
|
178
279
|
return record;
|
|
179
280
|
}
|
|
180
|
-
/** Applicant-side inbound `validating`;
|
|
281
|
+
/** Applicant-side inbound `validating`; `OR_SENT`, `IR_SENT` or `OOB_PENDING` => `VALIDATING`. */
|
|
181
282
|
async processReceiveValidating(messageContext) {
|
|
182
283
|
var _a;
|
|
183
284
|
const { message, agentContext } = messageContext;
|
|
@@ -185,8 +286,16 @@ let VtFlowService = class VtFlowService {
|
|
|
185
286
|
const record = await this.getByThreadId(agentContext, message.threadId);
|
|
186
287
|
this.logger.debug(`[vt-flow] validating received for session ${record.threadId}: ${(_a = message.comment) !== null && _a !== void 0 ? _a : '(no comment)'}`);
|
|
187
288
|
if (record.role === types_1.VtFlowRole.Applicant &&
|
|
188
|
-
record.
|
|
189
|
-
record
|
|
289
|
+
(message.comment || record.state === types_1.VtFlowState.OobPending)) {
|
|
290
|
+
this.appendMessage(record, {
|
|
291
|
+
type: types_1.VtFlowMessageType.Validating,
|
|
292
|
+
text: message.comment,
|
|
293
|
+
at: new Date().toISOString(),
|
|
294
|
+
});
|
|
295
|
+
await this.updateRecord(agentContext, record);
|
|
296
|
+
}
|
|
297
|
+
if (record.role === types_1.VtFlowRole.Applicant &&
|
|
298
|
+
[types_1.VtFlowState.OrSent, types_1.VtFlowState.IrSent, types_1.VtFlowState.OobPending].includes(record.state)) {
|
|
190
299
|
await this.updateState(agentContext, record, types_1.VtFlowState.Validating);
|
|
191
300
|
}
|
|
192
301
|
return record;
|
|
@@ -208,14 +317,26 @@ let VtFlowService = class VtFlowService {
|
|
|
208
317
|
}
|
|
209
318
|
return record;
|
|
210
319
|
}
|
|
211
|
-
/** `AWAITING_OR => VALIDATING
|
|
320
|
+
/** `AWAITING_OR => VALIDATING` once the `checkParticipantId` hook accepts the `participant_id`, with no transition and no message once it reports the request settled by a `VALIDATED` entry; caller is expected to have verified agent/wallet IDs on-chain. */
|
|
212
321
|
async acceptOnboardingRequest(agentContext, recordId) {
|
|
213
|
-
|
|
322
|
+
let record = await this.repository.getById(agentContext, recordId);
|
|
214
323
|
record.assertRole(types_1.VtFlowRole.Validator);
|
|
215
324
|
record.assertState(types_1.VtFlowState.AwaitingOr);
|
|
216
325
|
record.assertVariant(types_1.VtFlowVariant.OnboardingProcess);
|
|
326
|
+
const { checkParticipantId } = this.config;
|
|
327
|
+
if (checkParticipantId) {
|
|
328
|
+
const checked = await checkParticipantId({ agentContext, record });
|
|
329
|
+
if (!checked) {
|
|
330
|
+
throw new errors_1.VtFlowError(errors_1.VtFlowErrorCode.InvalidParticipantId, `vt-flow: participant_id '${record.applicantParticipantId}' is not a PENDING entry that names this agent as its validator`);
|
|
331
|
+
}
|
|
332
|
+
// the check can wait for the indexer while the flow moves on
|
|
333
|
+
record = await this.repository.getById(agentContext, recordId);
|
|
334
|
+
if (checked === 'validated')
|
|
335
|
+
return { record };
|
|
336
|
+
record.assertState(types_1.VtFlowState.AwaitingOr);
|
|
337
|
+
}
|
|
217
338
|
await this.updateState(agentContext, record, types_1.VtFlowState.Validating);
|
|
218
|
-
return record;
|
|
339
|
+
return { record, message: new messages_1.ValidatingMessage({ threadId: record.threadId }) };
|
|
219
340
|
}
|
|
220
341
|
/** DirectIssuance: `AWAITING_IR => VALIDATING`; transient before `CRED_OFFERED`. */
|
|
221
342
|
async acceptIssuanceRequest(agentContext, recordId) {
|
|
@@ -224,23 +345,44 @@ let VtFlowService = class VtFlowService {
|
|
|
224
345
|
record.assertState(types_1.VtFlowState.AwaitingIr);
|
|
225
346
|
record.assertVariant(types_1.VtFlowVariant.DirectIssuance);
|
|
226
347
|
await this.updateState(agentContext, record, types_1.VtFlowState.Validating);
|
|
227
|
-
return record;
|
|
348
|
+
return { record, message: new messages_1.ValidatingMessage({ threadId: record.threadId }) };
|
|
228
349
|
}
|
|
229
|
-
/** Reject with a problem-report;
|
|
350
|
+
/** Reject with a problem-report; a fatal code moves the sender to the Error Codes state, a retryable one returns a validator to `AWAITING_OR` or `AWAITING_IR`. */
|
|
230
351
|
async rejectRequest(agentContext, recordId, params) {
|
|
231
352
|
var _a;
|
|
232
353
|
const record = await this.repository.getById(agentContext, recordId);
|
|
354
|
+
if ((0, types_1.isVtFlowTerminalState)(record.state)) {
|
|
355
|
+
throw new core_1.CredoError(`vt-flow: flow '${record.id}' in state ${record.state} cannot be rejected`);
|
|
356
|
+
}
|
|
233
357
|
const problemReport = (0, errors_1.buildVtFlowProblemReport)({
|
|
234
358
|
code: params.code,
|
|
235
359
|
threadId: record.threadId,
|
|
236
360
|
enDescription: params.enDescription,
|
|
237
361
|
fixHintEn: params.fixHintEn,
|
|
238
362
|
});
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
363
|
+
const info = errors_1.VT_FLOW_ERROR_INFO[params.code];
|
|
364
|
+
const receiverRole = record.role === types_1.VtFlowRole.Validator ? types_1.VtFlowRole.Applicant : types_1.VtFlowRole.Validator;
|
|
365
|
+
// a fatal code lands both parties in the state the table gives the receiver
|
|
366
|
+
const fatalState = this.resolveErrorFlowState(info.flowState, receiverRole, errors_1.whoRetriesMap[info.whoRetries]);
|
|
367
|
+
const retryState = record.variant === types_1.VtFlowVariant.OnboardingProcess ? types_1.VtFlowState.AwaitingOr : types_1.VtFlowState.AwaitingIr;
|
|
368
|
+
if (!fatalState && record.role === types_1.VtFlowRole.Validator) {
|
|
369
|
+
record.assertState([
|
|
370
|
+
types_1.VtFlowState.AwaitingOr,
|
|
371
|
+
types_1.VtFlowState.AwaitingIr,
|
|
372
|
+
types_1.VtFlowState.Validating,
|
|
373
|
+
types_1.VtFlowState.OobPending,
|
|
374
|
+
]);
|
|
375
|
+
}
|
|
376
|
+
if (record.role === types_1.VtFlowRole.Validator) {
|
|
377
|
+
this.appendMessage(record, {
|
|
378
|
+
type: types_1.VtFlowMessageType.ProblemReport,
|
|
379
|
+
text: problemReport.description.en,
|
|
380
|
+
at: new Date().toISOString(),
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
if (fatalState)
|
|
384
|
+
record.errorMessage = (_a = params.enDescription) !== null && _a !== void 0 ? _a : params.code;
|
|
385
|
+
await this.updateState(agentContext, record, fatalState !== null && fatalState !== void 0 ? fatalState : (record.role === types_1.VtFlowRole.Validator ? retryState : record.state));
|
|
244
386
|
return { record, problemReport };
|
|
245
387
|
}
|
|
246
388
|
/** Applicant-side termination producing a problem-report and landing in `TERMINATED_BY_APPLICANT`. */
|
|
@@ -264,6 +406,17 @@ let VtFlowService = class VtFlowService {
|
|
|
264
406
|
var _a, _b;
|
|
265
407
|
const record = await this.repository.getById(agentContext, recordId);
|
|
266
408
|
record.assertRole(types_1.VtFlowRole.Validator);
|
|
409
|
+
record.assertState([
|
|
410
|
+
types_1.VtFlowState.AwaitingOr,
|
|
411
|
+
types_1.VtFlowState.AwaitingIr,
|
|
412
|
+
types_1.VtFlowState.Validating,
|
|
413
|
+
types_1.VtFlowState.OobPending,
|
|
414
|
+
types_1.VtFlowState.AwaitingValidationTx,
|
|
415
|
+
types_1.VtFlowState.ValidationTxFailed,
|
|
416
|
+
// VtFlowModule ends the flow here when auto-issue throws. A failed anchoring stays in CRED_OFFERED instead
|
|
417
|
+
types_1.VtFlowState.CredOffered,
|
|
418
|
+
types_1.VtFlowState.Completed,
|
|
419
|
+
]);
|
|
267
420
|
const code = (_a = params.code) !== null && _a !== void 0 ? _a : errors_1.VtFlowErrorCode.SessionTerminated;
|
|
268
421
|
const problemReport = (0, errors_1.buildVtFlowProblemReport)({
|
|
269
422
|
code,
|
|
@@ -272,6 +425,12 @@ let VtFlowService = class VtFlowService {
|
|
|
272
425
|
fixHintEn: params.fixHintEn,
|
|
273
426
|
});
|
|
274
427
|
record.errorMessage = (_b = params.enDescription) !== null && _b !== void 0 ? _b : code;
|
|
428
|
+
this.appendMessage(record, {
|
|
429
|
+
type: types_1.VtFlowMessageType.ProblemReport,
|
|
430
|
+
text: problemReport.description.en,
|
|
431
|
+
at: new Date().toISOString(),
|
|
432
|
+
});
|
|
433
|
+
record.connectionTerminated = true;
|
|
275
434
|
await this.updateState(agentContext, record, types_1.VtFlowState.TerminatedByValidator);
|
|
276
435
|
return { record, problemReport };
|
|
277
436
|
}
|
|
@@ -288,62 +447,120 @@ let VtFlowService = class VtFlowService {
|
|
|
288
447
|
await this.updateState(agentContext, record, params.state);
|
|
289
448
|
return { record, problemReport };
|
|
290
449
|
}
|
|
291
|
-
/** Build an `oob-link`;
|
|
450
|
+
/** Build an `oob-link` from `VALIDATING` or `OOB_PENDING`; the flow moves to or stays in `OOB_PENDING`. */
|
|
292
451
|
async sendOobLinkForSession(agentContext, recordId, params) {
|
|
452
|
+
var _a;
|
|
293
453
|
const record = await this.repository.getById(agentContext, recordId);
|
|
294
454
|
record.assertRole(types_1.VtFlowRole.Validator);
|
|
295
|
-
record.assertState([
|
|
296
|
-
types_1.VtFlowState.AwaitingOr,
|
|
297
|
-
types_1.VtFlowState.AwaitingIr,
|
|
298
|
-
types_1.VtFlowState.Validating,
|
|
299
|
-
types_1.VtFlowState.OobPending,
|
|
300
|
-
types_1.VtFlowState.Completed,
|
|
301
|
-
]);
|
|
455
|
+
record.assertState([types_1.VtFlowState.Validating, types_1.VtFlowState.OobPending]);
|
|
302
456
|
const message = new messages_1.OobLinkMessage({
|
|
303
457
|
threadId: record.threadId,
|
|
304
458
|
url: params.url,
|
|
305
459
|
description: params.description,
|
|
306
460
|
expiresTime: params.expiresTime,
|
|
307
461
|
});
|
|
308
|
-
record.
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
462
|
+
record.oobLink = {
|
|
463
|
+
url: params.url,
|
|
464
|
+
description: params.description,
|
|
465
|
+
expiresAt: (_a = params.expiresTime) === null || _a === void 0 ? void 0 : _a.toISOString(),
|
|
466
|
+
at: new Date().toISOString(),
|
|
467
|
+
};
|
|
468
|
+
this.appendMessage(record, {
|
|
469
|
+
type: types_1.VtFlowMessageType.OobLink,
|
|
470
|
+
text: params.description,
|
|
471
|
+
at: record.oobLink.at,
|
|
472
|
+
url: params.url,
|
|
473
|
+
});
|
|
474
|
+
await this.updateState(agentContext, record, types_1.VtFlowState.OobPending);
|
|
315
475
|
return { record, message };
|
|
316
476
|
}
|
|
317
|
-
/**
|
|
477
|
+
/** `OOB_PENDING` => `VALIDATING`, with the `validating` that tells the applicant its out-of-band step is done. */
|
|
318
478
|
async sendValidatingForSession(agentContext, recordId, params = {}) {
|
|
319
479
|
const record = await this.repository.getById(agentContext, recordId);
|
|
320
480
|
record.assertRole(types_1.VtFlowRole.Validator);
|
|
481
|
+
record.assertState(types_1.VtFlowState.OobPending);
|
|
321
482
|
const message = new messages_1.ValidatingMessage({
|
|
322
483
|
threadId: record.threadId,
|
|
323
484
|
comment: params.comment,
|
|
324
485
|
});
|
|
486
|
+
this.appendMessage(record, {
|
|
487
|
+
type: types_1.VtFlowMessageType.Validating,
|
|
488
|
+
text: params.comment,
|
|
489
|
+
at: new Date().toISOString(),
|
|
490
|
+
});
|
|
491
|
+
await this.updateState(agentContext, record, types_1.VtFlowState.Validating);
|
|
325
492
|
return { record, message };
|
|
326
493
|
}
|
|
327
|
-
/**
|
|
494
|
+
/** Record the validation decision or its transaction outcome, moving the flow when `state` is given. */
|
|
495
|
+
async recordValidation(agentContext, recordId, validation, state) {
|
|
496
|
+
const record = await this.repository.getById(agentContext, recordId);
|
|
497
|
+
record.assertRole(types_1.VtFlowRole.Validator);
|
|
498
|
+
record.validation = validation;
|
|
499
|
+
if (state)
|
|
500
|
+
await this.updateState(agentContext, record, state);
|
|
501
|
+
else
|
|
502
|
+
await this.updateRecord(agentContext, record);
|
|
503
|
+
return record;
|
|
504
|
+
}
|
|
505
|
+
/** Record the outcome of the `CreateOrUpdateParticipantSession` transaction that anchors the issued credential. */
|
|
506
|
+
async recordIssuance(agentContext, recordId, issuance) {
|
|
507
|
+
const record = await this.repository.getById(agentContext, recordId);
|
|
508
|
+
record.assertRole(types_1.VtFlowRole.Validator);
|
|
509
|
+
record.issuance = issuance;
|
|
510
|
+
await this.updateRecord(agentContext, record);
|
|
511
|
+
return record;
|
|
512
|
+
}
|
|
513
|
+
/** `VALIDATED` => `VALIDATED_PENDING_CLAIMS`, when the claims fail the schema at offer time ([VSA-VTI-FLOW-OP-ISSUE-4]). */
|
|
514
|
+
async markPendingClaims(agentContext, recordId) {
|
|
515
|
+
const record = await this.repository.getById(agentContext, recordId);
|
|
516
|
+
record.assertRole(types_1.VtFlowRole.Validator);
|
|
517
|
+
record.assertState(types_1.VtFlowState.Validated);
|
|
518
|
+
await this.updateState(agentContext, record, types_1.VtFlowState.ValidatedPendingClaims);
|
|
519
|
+
return record;
|
|
520
|
+
}
|
|
521
|
+
/** Validator-side states preceding `VALIDATED` => `VALIDATED`; call after `SetParticipantOPtoValidated` lands on-chain. */
|
|
328
522
|
async markValidated(agentContext, recordId) {
|
|
329
523
|
const record = await this.repository.getById(agentContext, recordId);
|
|
330
524
|
record.assertRole(types_1.VtFlowRole.Validator);
|
|
331
|
-
record.assertState([types_1.
|
|
525
|
+
record.assertState([...types_1.VtFlowValidatedFromStates]);
|
|
332
526
|
record.assertVariant(types_1.VtFlowVariant.OnboardingProcess);
|
|
333
527
|
await this.updateState(agentContext, record, types_1.VtFlowState.Validated);
|
|
334
528
|
return record;
|
|
335
529
|
}
|
|
336
|
-
/**
|
|
337
|
-
|
|
530
|
+
/**
|
|
531
|
+
* Close an onboarding process that carries no credential exchange. Only a HOLDER receives a
|
|
532
|
+
* credential; for every other role the chain records the outcome with
|
|
533
|
+
* SetParticipantOPToValidated, and nothing else follows. Both sides use this, so it asserts no
|
|
534
|
+
* role: the validator calls it after it validates, and the applicant reaches it from the chain
|
|
535
|
+
* event.
|
|
536
|
+
*/
|
|
537
|
+
async markCompleted(agentContext, recordId) {
|
|
338
538
|
const record = await this.repository.getById(agentContext, recordId);
|
|
539
|
+
record.assertVariant(types_1.VtFlowVariant.OnboardingProcess);
|
|
540
|
+
if (record.state === types_1.VtFlowState.Completed)
|
|
541
|
+
return record;
|
|
542
|
+
if ((0, types_1.isVtFlowTerminalState)(record.state)) {
|
|
543
|
+
throw new core_1.CredoError(`VtFlow record is in terminal state '${record.state}'; cannot complete it.`);
|
|
544
|
+
}
|
|
545
|
+
await this.updateState(agentContext, record, types_1.VtFlowState.Completed);
|
|
546
|
+
return record;
|
|
547
|
+
}
|
|
548
|
+
/** Validator states that an `offer-credential` moves to `CRED_OFFERED`; from `COMPLETED` it starts a new subprotocol run. */
|
|
549
|
+
assertCanOfferCredential(record) {
|
|
339
550
|
record.assertRole(types_1.VtFlowRole.Validator);
|
|
340
551
|
record.assertState([
|
|
341
552
|
types_1.VtFlowState.Validated,
|
|
342
|
-
types_1.VtFlowState.
|
|
343
|
-
types_1.VtFlowState.OobPending,
|
|
553
|
+
types_1.VtFlowState.ValidatedPendingClaims,
|
|
344
554
|
types_1.VtFlowState.Completed,
|
|
555
|
+
...(record.variant === types_1.VtFlowVariant.DirectIssuance ? [types_1.VtFlowState.Validating] : []),
|
|
345
556
|
]);
|
|
557
|
+
}
|
|
558
|
+
/** Link a Credo exchange record to the session and transition to `CRED_OFFERED`. */
|
|
559
|
+
async attachCredentialExchangeRecord(agentContext, recordId, credentialExchangeRecord, credentialDigest, issuerParticipantId, credentialId) {
|
|
560
|
+
const record = await this.repository.getById(agentContext, recordId);
|
|
561
|
+
this.assertCanOfferCredential(record);
|
|
346
562
|
record.credentialExchangeRecordId = credentialExchangeRecord.id;
|
|
563
|
+
record.credentialId = credentialId;
|
|
347
564
|
if (credentialDigest)
|
|
348
565
|
record.credentialDigest = credentialDigest;
|
|
349
566
|
if (issuerParticipantId !== undefined)
|
|
@@ -352,6 +569,34 @@ let VtFlowService = class VtFlowService {
|
|
|
352
569
|
await this.updateState(agentContext, record, types_1.VtFlowState.CredOffered);
|
|
353
570
|
return record;
|
|
354
571
|
}
|
|
572
|
+
async setEcsSchemaKey(agentContext, recordId, ecsSchemaKey) {
|
|
573
|
+
const record = await this.repository.getById(agentContext, recordId);
|
|
574
|
+
record.assertRole(types_1.VtFlowRole.Applicant);
|
|
575
|
+
record.ecsSchemaKey = ecsSchemaKey;
|
|
576
|
+
await this.repository.update(agentContext, record);
|
|
577
|
+
return record;
|
|
578
|
+
}
|
|
579
|
+
/** The applicant keeps the id of the credential that the flow delivered. A renewal replaces it. */
|
|
580
|
+
async setCredentialId(agentContext, recordId, credentialId) {
|
|
581
|
+
const record = await this.repository.getById(agentContext, recordId);
|
|
582
|
+
record.assertRole(types_1.VtFlowRole.Applicant);
|
|
583
|
+
record.credentialId = credentialId;
|
|
584
|
+
await this.repository.update(agentContext, record);
|
|
585
|
+
return record;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* The applicant keeps the credential id and releases the exchange.
|
|
589
|
+
* The caller then deletes that exchange.
|
|
590
|
+
*/
|
|
591
|
+
async detachCredentialExchange(agentContext, recordId, credentialId) {
|
|
592
|
+
const record = await this.repository.getById(agentContext, recordId);
|
|
593
|
+
record.assertRole(types_1.VtFlowRole.Applicant);
|
|
594
|
+
if (credentialId)
|
|
595
|
+
record.credentialId = credentialId;
|
|
596
|
+
record.credentialExchangeRecordId = undefined;
|
|
597
|
+
await this.repository.update(agentContext, record);
|
|
598
|
+
return record;
|
|
599
|
+
}
|
|
355
600
|
async setCredentialDigest(agentContext, recordId, credentialDigest) {
|
|
356
601
|
const record = await this.repository.getById(agentContext, recordId);
|
|
357
602
|
record.assertRole(types_1.VtFlowRole.Validator);
|
|
@@ -380,7 +625,16 @@ let VtFlowService = class VtFlowService {
|
|
|
380
625
|
async updateClaims(agentContext, recordId, claims) {
|
|
381
626
|
const record = await this.repository.getById(agentContext, recordId);
|
|
382
627
|
record.assertRole(types_1.VtFlowRole.Validator);
|
|
383
|
-
record.assertState([
|
|
628
|
+
record.assertState([
|
|
629
|
+
types_1.VtFlowState.AwaitingOr,
|
|
630
|
+
types_1.VtFlowState.OobPending,
|
|
631
|
+
types_1.VtFlowState.Validating,
|
|
632
|
+
types_1.VtFlowState.AwaitingValidationTx,
|
|
633
|
+
types_1.VtFlowState.ValidationTxSubmitted,
|
|
634
|
+
types_1.VtFlowState.ValidationTxFailed,
|
|
635
|
+
types_1.VtFlowState.ValidatedPendingClaims,
|
|
636
|
+
types_1.VtFlowState.CredRevoked,
|
|
637
|
+
]);
|
|
384
638
|
record.claims = claims;
|
|
385
639
|
await this.updateRecord(agentContext, record);
|
|
386
640
|
return record;
|
|
@@ -401,6 +655,11 @@ let VtFlowService = class VtFlowService {
|
|
|
401
655
|
}
|
|
402
656
|
break;
|
|
403
657
|
case didcomm_1.DidCommCredentialState.OfferReceived:
|
|
658
|
+
// the offer can beat the chain notification, and an Onboarding Process offers only from VALIDATED
|
|
659
|
+
if (record.variant === types_1.VtFlowVariant.OnboardingProcess &&
|
|
660
|
+
[types_1.VtFlowState.OrSent, types_1.VtFlowState.Validating, types_1.VtFlowState.OobPending].includes(record.state)) {
|
|
661
|
+
await this.updateState(agentContext, record, types_1.VtFlowState.Validated);
|
|
662
|
+
}
|
|
404
663
|
if (record.state !== types_1.VtFlowState.CredOffered) {
|
|
405
664
|
await this.updateState(agentContext, record, types_1.VtFlowState.CredOffered);
|
|
406
665
|
}
|
|
@@ -414,6 +673,7 @@ let VtFlowService = class VtFlowService {
|
|
|
414
673
|
}
|
|
415
674
|
break;
|
|
416
675
|
case didcomm_1.DidCommCredentialState.Abandoned:
|
|
676
|
+
case didcomm_1.DidCommCredentialState.Declined:
|
|
417
677
|
if (record.state !== types_1.VtFlowState.Error) {
|
|
418
678
|
record.errorMessage = (_a = record.errorMessage) !== null && _a !== void 0 ? _a : 'Subprotocol abandoned';
|
|
419
679
|
await this.updateState(agentContext, record, types_1.VtFlowState.Error);
|
|
@@ -448,24 +708,119 @@ let VtFlowService = class VtFlowService {
|
|
|
448
708
|
/** Transition the record, persist it, and emit `VtFlowStateChanged`. */
|
|
449
709
|
async updateState(agentContext, record, newState) {
|
|
450
710
|
const previousState = record.state;
|
|
451
|
-
if (previousState === newState)
|
|
711
|
+
if (previousState === newState) {
|
|
712
|
+
await this.repository.update(agentContext, record);
|
|
452
713
|
return;
|
|
714
|
+
}
|
|
715
|
+
if (previousState === types_1.VtFlowState.OobPending)
|
|
716
|
+
record.oobLink = undefined;
|
|
453
717
|
record.state = newState;
|
|
454
718
|
await this.repository.update(agentContext, record);
|
|
455
719
|
this.emitStateChanged(agentContext, record, previousState);
|
|
456
720
|
}
|
|
721
|
+
/**
|
|
722
|
+
* Inbound adopted `problem-report`. The Error Codes table gives the state the receiving party
|
|
723
|
+
* moves to, so both sides run this same mapping. A retryable code records the message and leaves
|
|
724
|
+
* the flow where it is.
|
|
725
|
+
*/
|
|
726
|
+
async processReceiveProblemReport(messageContext) {
|
|
727
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
728
|
+
const { message, agentContext } = messageContext;
|
|
729
|
+
const record = await this.repository.findByThreadId(agentContext, message.threadId);
|
|
730
|
+
if (!record)
|
|
731
|
+
return undefined;
|
|
732
|
+
if ((0, types_1.isVtFlowTerminalState)(record.state))
|
|
733
|
+
return record;
|
|
734
|
+
const code = (_a = message.description) === null || _a === void 0 ? void 0 : _a.code;
|
|
735
|
+
const info = code && (0, errors_1.isVtFlowErrorCode)(code) ? errors_1.VT_FLOW_ERROR_INFO[code] : undefined;
|
|
736
|
+
if (record.role === types_1.VtFlowRole.Applicant) {
|
|
737
|
+
this.appendMessage(record, {
|
|
738
|
+
type: types_1.VtFlowMessageType.ProblemReport,
|
|
739
|
+
text: (_d = (_c = (_b = message.description) === null || _b === void 0 ? void 0 : _b.en) !== null && _c !== void 0 ? _c : code) !== null && _d !== void 0 ? _d : 'problem-report',
|
|
740
|
+
at: new Date().toISOString(),
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
const target = info &&
|
|
744
|
+
this.resolveErrorFlowState(info.flowState, record.role, (_e = message.whoRetries) !== null && _e !== void 0 ? _e : errors_1.whoRetriesMap[info.whoRetries]);
|
|
745
|
+
if (!target) {
|
|
746
|
+
await this.updateRecord(agentContext, record);
|
|
747
|
+
return record;
|
|
748
|
+
}
|
|
749
|
+
record.errorMessage = (_g = (_f = message.description) === null || _f === void 0 ? void 0 : _f.en) !== null && _g !== void 0 ? _g : code;
|
|
750
|
+
await this.updateState(agentContext, record, target);
|
|
751
|
+
return record;
|
|
752
|
+
}
|
|
753
|
+
/** `terminated-by-sender` is the peer's termination, so the receiver lands in the state named after the sender. */
|
|
754
|
+
resolveErrorFlowState(flowState, receiverRole, whoRetries) {
|
|
755
|
+
if (flowState === 'unchanged')
|
|
756
|
+
return undefined;
|
|
757
|
+
if (flowState === 'unchanged-when-you') {
|
|
758
|
+
return whoRetries === didcomm_1.WhoRetriesStatus.You ? undefined : types_1.VtFlowState.Error;
|
|
759
|
+
}
|
|
760
|
+
if (flowState === 'error-when-fatal') {
|
|
761
|
+
return whoRetries === didcomm_1.WhoRetriesStatus.None ? types_1.VtFlowState.Error : undefined;
|
|
762
|
+
}
|
|
763
|
+
if (flowState !== 'terminated-by-sender')
|
|
764
|
+
return flowState;
|
|
765
|
+
return receiverRole === types_1.VtFlowRole.Applicant
|
|
766
|
+
? types_1.VtFlowState.TerminatedByValidator
|
|
767
|
+
: types_1.VtFlowState.TerminatedByApplicant;
|
|
768
|
+
}
|
|
769
|
+
/** Append to `messages[]`, which a validator fills with what it sent and an applicant with what it received. */
|
|
770
|
+
appendMessage(record, message) {
|
|
771
|
+
var _a;
|
|
772
|
+
record.messages = [...((_a = record.messages) !== null && _a !== void 0 ? _a : []), message];
|
|
773
|
+
}
|
|
457
774
|
/** Persist record changes without state-transition semantics (no event emitted). */
|
|
458
775
|
async updateRecord(agentContext, record) {
|
|
459
776
|
await this.repository.update(agentContext, record);
|
|
460
777
|
}
|
|
461
778
|
/** participant_session_ids are public on-chain, so only the original peer may re-attach a flow with one. */
|
|
462
|
-
async
|
|
779
|
+
async isSamePeer(agentContext, record, connection) {
|
|
463
780
|
if (record.connectionId === connection.id)
|
|
464
|
-
return;
|
|
781
|
+
return true;
|
|
465
782
|
const connectionRepository = agentContext.dependencyManager.resolve(didcomm_1.DidCommConnectionRepository);
|
|
466
783
|
const previous = await connectionRepository.findById(agentContext, record.connectionId);
|
|
467
|
-
|
|
468
|
-
|
|
784
|
+
return !((previous === null || previous === void 0 ? void 0 : previous.theirDid) && connection.theirDid && previous.theirDid !== connection.theirDid);
|
|
785
|
+
}
|
|
786
|
+
assertNotTerminated(record) {
|
|
787
|
+
if ((0, types_1.isVtFlowTerminalState)(record.state)) {
|
|
788
|
+
throw new errors_1.VtFlowError(errors_1.VtFlowErrorCode.InvalidParticipantSessionId, `vt-flow: participant_session_id '${record.participantSessionId}' collides with a terminated flow`);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
async assertSamePeer(agentContext, record, connection) {
|
|
792
|
+
if (!(await this.isSamePeer(agentContext, record, connection))) {
|
|
793
|
+
throw new errors_1.VtFlowError(errors_1.VtFlowErrorCode.InvalidParticipantSessionId, `vt-flow: connection '${connection.id}' peer does not match the original connection of participant_session_id '${record.participantSessionId}'`);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
/** VS-CONN-VS failure is fatal, so it ends the flow of the request in ERROR unless that flow has ended or belongs to another peer. */
|
|
797
|
+
async checkRequestFromVerifiableService(agentContext, connection, record, isNew, purpose) {
|
|
798
|
+
try {
|
|
799
|
+
await this.checkIsVerifiableService(agentContext, connection, purpose);
|
|
800
|
+
}
|
|
801
|
+
catch (error) {
|
|
802
|
+
if (!(error instanceof errors_1.VtFlowError))
|
|
803
|
+
throw error;
|
|
804
|
+
// the check above awaits, and a chain notification can move the flow meanwhile
|
|
805
|
+
const latest = isNew ? record : await this.repository.getById(agentContext, record.id);
|
|
806
|
+
if (isNew ||
|
|
807
|
+
(!(0, types_1.isVtFlowTerminalState)(latest.state) && (await this.isSamePeer(agentContext, latest, connection)))) {
|
|
808
|
+
latest.errorMessage = error.message;
|
|
809
|
+
this.appendMessage(latest, {
|
|
810
|
+
type: types_1.VtFlowMessageType.ProblemReport,
|
|
811
|
+
text: (0, errors_1.defaultEnglishDescription)(error.code),
|
|
812
|
+
at: new Date().toISOString(),
|
|
813
|
+
});
|
|
814
|
+
if (isNew) {
|
|
815
|
+
latest.state = types_1.VtFlowState.Error;
|
|
816
|
+
await this.repository.save(agentContext, latest);
|
|
817
|
+
this.emitStateChanged(agentContext, latest, null);
|
|
818
|
+
}
|
|
819
|
+
else {
|
|
820
|
+
await this.updateState(agentContext, latest, types_1.VtFlowState.Error);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
throw error;
|
|
469
824
|
}
|
|
470
825
|
}
|
|
471
826
|
emitStateChanged(agentContext, record, previousState) {
|
|
@@ -489,25 +844,47 @@ let VtFlowService = class VtFlowService {
|
|
|
489
844
|
buildProblemReport(options) {
|
|
490
845
|
return (0, errors_1.buildVtFlowProblemReport)(options);
|
|
491
846
|
}
|
|
492
|
-
/** Spec Verifiable Service Identity Check: invokes the caller-provided VS-CONN-VS hook. Throws `vt-flow.not-a-verifiable-service` when the peer fails the check. When no hook is configured, logs a warning and permits. */
|
|
493
|
-
async checkIsVerifiableService(agentContext, connection) {
|
|
494
|
-
const peerDid = connection
|
|
495
|
-
if (!peerDid)
|
|
847
|
+
/** Spec Verifiable Service Identity Check: invokes the caller-provided VS-CONN-VS hook. Throws `vt-flow.not-a-verifiable-service` when the peer fails the check. When no hook is configured, logs a warning and permits. A `purpose` is passed on the Validator side only, and lets a rejected peer through the ECS issuance exemption. */
|
|
848
|
+
async checkIsVerifiableService(agentContext, connection, purpose) {
|
|
849
|
+
const peerDid = (0, utils_1.peerAnchorDid)(connection);
|
|
850
|
+
if (!connection.theirDid || !peerDid) {
|
|
496
851
|
throw new core_1.CredoError(`vt-flow: ready connection '${connection.id}' has no theirDid`);
|
|
852
|
+
}
|
|
497
853
|
const hook = this.config.assertVerifiableService;
|
|
498
854
|
if (!hook) {
|
|
499
855
|
this.logger.warn(`[vt-flow] assertVerifiableService hook not configured; skipping VS-CONN-VS check for peer '${peerDid}'. Configure VtFlowModuleConfig.assertVerifiableService for spec-conformant trust resolution.`);
|
|
500
856
|
return;
|
|
501
857
|
}
|
|
502
858
|
let permitted = false;
|
|
859
|
+
let failure;
|
|
503
860
|
try {
|
|
504
|
-
permitted = await hook({
|
|
861
|
+
permitted = await hook({
|
|
862
|
+
agentContext,
|
|
863
|
+
peerDid,
|
|
864
|
+
connectionId: connection.id,
|
|
865
|
+
});
|
|
505
866
|
}
|
|
506
867
|
catch (error) {
|
|
507
|
-
|
|
868
|
+
failure = error.message;
|
|
508
869
|
}
|
|
509
|
-
if (
|
|
510
|
-
|
|
870
|
+
if (permitted)
|
|
871
|
+
return;
|
|
872
|
+
if (purpose && (await this.isExemptFromVsConnVs(agentContext, connection, peerDid, purpose))) {
|
|
873
|
+
this.logger.info(`[vt-flow] peer '${peerDid}' is not (yet) a Verifiable Service, but the request qualifies for the VS-CONN-VS ECS issuance exemption`);
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
throw new errors_1.VtFlowError(errors_1.VtFlowErrorCode.NotAVerifiableService, `vt-flow.not-a-verifiable-service: peer '${peerDid}' failed VS-CONN-VS check${failure ? ` (${failure})` : ''}`);
|
|
877
|
+
}
|
|
878
|
+
async isExemptFromVsConnVs(agentContext, connection, peerDid, purpose) {
|
|
879
|
+
const exemption = this.config.checkEcsIssuanceExemption;
|
|
880
|
+
if (!exemption)
|
|
881
|
+
return false;
|
|
882
|
+
try {
|
|
883
|
+
return await exemption({ agentContext, peerDid, connectionId: connection.id, purpose });
|
|
884
|
+
}
|
|
885
|
+
catch (error) {
|
|
886
|
+
this.logger.warn(`[vt-flow] VS-CONN-VS exemption check failed for peer '${peerDid}': ${error.message}`);
|
|
887
|
+
return false;
|
|
511
888
|
}
|
|
512
889
|
}
|
|
513
890
|
};
|