@verana-labs/vs-agent-sdk 2.0.0-dev.5 → 2.0.0-dev.51

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 (123) hide show
  1. package/build/agent/VsAgent.d.ts +11 -16
  2. package/build/agent/VsAgent.js +82 -172
  3. package/build/agent/VsAgent.js.map +1 -1
  4. package/build/agent/createVsAgent.d.ts +5 -0
  5. package/build/agent/createVsAgent.js +3 -0
  6. package/build/agent/createVsAgent.js.map +1 -1
  7. package/build/blockchain/AnonCredsTrustService.d.ts +53 -0
  8. package/build/blockchain/AnonCredsTrustService.js +238 -0
  9. package/build/blockchain/AnonCredsTrustService.js.map +1 -0
  10. package/build/blockchain/AuthorizationService.d.ts +5 -3
  11. package/build/blockchain/AuthorizationService.js +17 -29
  12. package/build/blockchain/AuthorizationService.js.map +1 -1
  13. package/build/blockchain/IndexerWebSocketService.d.ts +7 -1
  14. package/build/blockchain/IndexerWebSocketService.js +68 -36
  15. package/build/blockchain/IndexerWebSocketService.js.map +1 -1
  16. package/build/blockchain/VeranaChainService.d.ts +2 -13
  17. package/build/blockchain/VeranaChainService.js +8 -113
  18. package/build/blockchain/VeranaChainService.js.map +1 -1
  19. package/build/blockchain/VeranaIndexerService.d.ts +14 -1
  20. package/build/blockchain/VeranaIndexerService.js +122 -8
  21. package/build/blockchain/VeranaIndexerService.js.map +1 -1
  22. package/build/blockchain/handlers/authorizationHandlers.js +2 -2
  23. package/build/blockchain/handlers/authorizationHandlers.js.map +1 -1
  24. package/build/blockchain/handlers/defaultHandlers.js +2 -0
  25. package/build/blockchain/handlers/defaultHandlers.js.map +1 -1
  26. package/build/blockchain/handlers/index.d.ts +1 -0
  27. package/build/blockchain/handlers/index.js +1 -0
  28. package/build/blockchain/handlers/index.js.map +1 -1
  29. package/build/blockchain/handlers/selfIssuanceHandlers.d.ts +13 -0
  30. package/build/blockchain/handlers/selfIssuanceHandlers.js +71 -0
  31. package/build/blockchain/handlers/selfIssuanceHandlers.js.map +1 -0
  32. package/build/blockchain/handlers/stateMutations.d.ts +21 -2
  33. package/build/blockchain/handlers/stateMutations.js +272 -34
  34. package/build/blockchain/handlers/stateMutations.js.map +1 -1
  35. package/build/blockchain/index.d.ts +2 -0
  36. package/build/blockchain/index.js +2 -0
  37. package/build/blockchain/index.js.map +1 -1
  38. package/build/blockchain/indexerMappers.d.ts +3 -0
  39. package/build/blockchain/indexerMappers.js +53 -0
  40. package/build/blockchain/indexerMappers.js.map +1 -0
  41. package/build/blockchain/types.d.ts +5 -57
  42. package/build/blockchain/types.js.map +1 -1
  43. package/build/bootstrap/EcsBootstrapService.d.ts +16 -3
  44. package/build/bootstrap/EcsBootstrapService.js +202 -77
  45. package/build/bootstrap/EcsBootstrapService.js.map +1 -1
  46. package/build/did/CachedWebDidResolver.d.ts +0 -4
  47. package/build/did/CachedWebDidResolver.js +1 -5
  48. package/build/did/CachedWebDidResolver.js.map +1 -1
  49. package/build/did/artifactServices.d.ts +11 -0
  50. package/build/did/artifactServices.js +48 -0
  51. package/build/did/artifactServices.js.map +1 -0
  52. package/build/did/legacyDidWeb.d.ts +6 -4
  53. package/build/did/legacyDidWeb.js +17 -14
  54. package/build/did/legacyDidWeb.js.map +1 -1
  55. package/build/did/migrations/index.d.ts +22 -0
  56. package/build/did/migrations/index.js +103 -0
  57. package/build/did/migrations/index.js.map +1 -0
  58. package/build/did/migrations/migrateWebVhLog.js.map +1 -0
  59. package/build/did/migrations/migrateWebVhVersionTime.js.map +1 -0
  60. package/build/events/BaseMessageEvents.js +109 -0
  61. package/build/events/BaseMessageEvents.js.map +1 -1
  62. package/build/events/ConnectionEvents.js +110 -82
  63. package/build/events/ConnectionEvents.js.map +1 -1
  64. package/build/events/VsAgentEvents.d.ts +1 -8
  65. package/build/events/VsAgentEvents.js +0 -1
  66. package/build/events/VsAgentEvents.js.map +1 -1
  67. package/build/events/VtFlowEvents.d.ts +1 -1
  68. package/build/events/VtFlowEvents.js +2 -19
  69. package/build/events/VtFlowEvents.js.map +1 -1
  70. package/build/index.d.ts +2 -0
  71. package/build/index.js +5 -1
  72. package/build/index.js.map +1 -1
  73. package/build/plugins/setupBaseDidComm.js +4 -6
  74. package/build/plugins/setupBaseDidComm.js.map +1 -1
  75. package/build/transports/VsAgentWsInboundTransport.d.ts +1 -1
  76. package/build/transports/VsAgentWsInboundTransport.js +20 -14
  77. package/build/transports/VsAgentWsInboundTransport.js.map +1 -1
  78. package/build/utils/agent.d.ts +27 -3
  79. package/build/utils/agent.js +78 -19
  80. package/build/utils/agent.js.map +1 -1
  81. package/build/utils/didReadiness.d.ts +9 -0
  82. package/build/utils/didReadiness.js +42 -0
  83. package/build/utils/didReadiness.js.map +1 -0
  84. package/build/utils/ecsClaims.d.ts +47 -0
  85. package/build/utils/ecsClaims.js +120 -0
  86. package/build/utils/ecsClaims.js.map +1 -0
  87. package/build/utils/index.d.ts +2 -0
  88. package/build/utils/index.js +2 -0
  89. package/build/utils/index.js.map +1 -1
  90. package/build/utils/selfIssuedEcsCredential.d.ts +4 -0
  91. package/build/utils/selfIssuedEcsCredential.js +140 -0
  92. package/build/utils/selfIssuedEcsCredential.js.map +1 -0
  93. package/build/utils/setupSelfTr.d.ts +3 -56
  94. package/build/utils/setupSelfTr.js +41 -249
  95. package/build/utils/setupSelfTr.js.map +1 -1
  96. package/build/utils/trustCredentialStore.d.ts +32 -6
  97. package/build/utils/trustCredentialStore.js +183 -82
  98. package/build/utils/trustCredentialStore.js.map +1 -1
  99. package/build/utils/util.d.ts +10 -0
  100. package/build/utils/util.js +16 -0
  101. package/build/utils/util.js.map +1 -1
  102. package/build/utils/vtjscResolver.d.ts +18 -0
  103. package/build/utils/vtjscResolver.js +54 -0
  104. package/build/utils/vtjscResolver.js.map +1 -0
  105. package/build/vtFlow/VtFlowOrchestrator.d.ts +47 -9
  106. package/build/vtFlow/VtFlowOrchestrator.js +99 -58
  107. package/build/vtFlow/VtFlowOrchestrator.js.map +1 -1
  108. package/build/vtFlow/assertVerifiableService.d.ts +1 -0
  109. package/build/vtFlow/assertVerifiableService.js +45 -5
  110. package/build/vtFlow/assertVerifiableService.js.map +1 -1
  111. package/build/vtFlow/ecsIssuanceExemption.d.ts +12 -0
  112. package/build/vtFlow/ecsIssuanceExemption.js +84 -0
  113. package/build/vtFlow/ecsIssuanceExemption.js.map +1 -0
  114. package/build/vtFlow/index.d.ts +1 -0
  115. package/build/vtFlow/index.js +1 -0
  116. package/build/vtFlow/index.js.map +1 -1
  117. package/package.json +11 -11
  118. package/build/did/migrateWebVhLog.js.map +0 -1
  119. package/build/did/migrateWebVhVersionTime.js.map +0 -1
  120. /package/build/did/{migrateWebVhLog.d.ts → migrations/migrateWebVhLog.d.ts} +0 -0
  121. /package/build/did/{migrateWebVhLog.js → migrations/migrateWebVhLog.js} +0 -0
  122. /package/build/did/{migrateWebVhVersionTime.d.ts → migrations/migrateWebVhVersionTime.d.ts} +0 -0
  123. /package/build/did/{migrateWebVhVersionTime.js → migrations/migrateWebVhVersionTime.js} +0 -0
@@ -17,5 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./authorizationHandlers"), exports);
18
18
  __exportStar(require("./defaultHandlers"), exports);
19
19
  __exportStar(require("./IndexerHandlerRegistry"), exports);
20
+ __exportStar(require("./selfIssuanceHandlers"), exports);
20
21
  __exportStar(require("./stateMutations"), exports);
21
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/blockchain/handlers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAuC;AACvC,oDAAiC;AACjC,2DAAwC;AACxC,mDAAgC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/blockchain/handlers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAuC;AACvC,oDAAiC;AACjC,2DAAwC;AACxC,yDAAsC;AACtC,mDAAgC"}
@@ -0,0 +1,13 @@
1
+ import { EcsClaims } from '../../utils/ecsClaims';
2
+ import { VeranaIndexerService } from '../VeranaIndexerService';
3
+ import { IndexerHandlerRegistry } from './IndexerHandlerRegistry';
4
+ /**
5
+ * Keeps this agent's self-issued ECS credentials in step with its own ISSUER participant.
6
+ *
7
+ * The Corporation operator provisions that participant out of band, and a third party revokes it
8
+ * just as asynchronously — both usually while the agent is already running. Until it exists the
9
+ * agent cannot anchor the digest of its ECS credentials, because the chain accepts a
10
+ * CreateOrUpdateParticipantSession only against an active ISSUER entry; once it is revoked the
11
+ * credential that anchors against it makes the whole DID fail VS-CONN-VS.
12
+ */
13
+ export declare function registerSelfIssuanceAnchorHandlers(registry: IndexerHandlerRegistry, indexer: VeranaIndexerService, corporationId: number, ecsClaims: EcsClaims): void;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerSelfIssuanceAnchorHandlers = registerSelfIssuanceAnchorHandlers;
4
+ const types_1 = require("../types");
5
+ const stateMutations_1 = require("./stateMutations");
6
+ /**
7
+ * Messages that can give this agent the ISSUER participant its own ECS credentials anchor
8
+ * against: an ECOSYSTEM-mode entry becomes usable when the validator validates it, an OPEN-mode
9
+ * entry as soon as its owner creates it.
10
+ */
11
+ const ISSUER_READY_MSGS = ['SetParticipantOPToValidated', 'SelfCreateParticipant'];
12
+ /** Messages that make an ISSUER participant permanently unusable, per VSA-VTI-FLOW-OP-REVOKE. */
13
+ const ISSUER_REVOKED_MSGS = ['RevokeParticipant', 'SlashParticipantTrustDeposit'];
14
+ /**
15
+ * Keeps this agent's self-issued ECS credentials in step with its own ISSUER participant.
16
+ *
17
+ * The Corporation operator provisions that participant out of band, and a third party revokes it
18
+ * just as asynchronously — both usually while the agent is already running. Until it exists the
19
+ * agent cannot anchor the digest of its ECS credentials, because the chain accepts a
20
+ * CreateOrUpdateParticipantSession only against an active ISSUER entry; once it is revoked the
21
+ * credential that anchors against it makes the whole DID fail VS-CONN-VS.
22
+ */
23
+ function registerSelfIssuanceAnchorHandlers(registry, indexer, corporationId, ecsClaims) {
24
+ // Events arrive in bursts, and each reconciliation writes the DID record, so they run in turn.
25
+ let queue = Promise.resolve();
26
+ for (const msg of ISSUER_READY_MSGS) {
27
+ const original = registry.get(msg);
28
+ registry.register({
29
+ msg,
30
+ handle: async (activity, ctx) => {
31
+ if (original)
32
+ await original.handle(activity, ctx);
33
+ const { agent } = ctx;
34
+ if (!agent.did || !agent.veranaChain)
35
+ return;
36
+ try {
37
+ const participant = await indexer.getParticipant(String(activity.entity_id));
38
+ if ((participant === null || participant === void 0 ? void 0 : participant.did) !== agent.did || participant.role !== types_1.ParticipantRole.Issuer)
39
+ return;
40
+ }
41
+ catch (error) {
42
+ ctx.agent.config.logger.debug(`[SelfTR] could not read participant ${activity.entity_id}: ${error.message}`);
43
+ return;
44
+ }
45
+ agent.config.logger.info(`[SelfTR] own ISSUER participant ${activity.entity_id} is ready; reconciling the ECS credentials`);
46
+ queue = queue
47
+ .then(() => (0, stateMutations_1.reconcileVtjscPublications)(agent, indexer, corporationId, ecsClaims))
48
+ .catch((error) => agent.config.logger.error(`[SelfTR] reconciliation failed: ${error.message}`));
49
+ await queue;
50
+ },
51
+ });
52
+ }
53
+ for (const msg of ISSUER_REVOKED_MSGS) {
54
+ const original = registry.get(msg);
55
+ registry.register({
56
+ msg,
57
+ handle: async (activity, ctx) => {
58
+ if (original)
59
+ await original.handle(activity, ctx);
60
+ const { agent } = ctx;
61
+ if (!agent.did || !agent.veranaChain)
62
+ return;
63
+ queue = queue
64
+ .then(() => (0, stateMutations_1.removeSelfIssuedEcsCredentialsIfIssuerRevoked)(agent, String(activity.entity_id)))
65
+ .catch((error) => agent.config.logger.error(`[SelfTR] withdrawal failed: ${error.message}`));
66
+ await queue;
67
+ },
68
+ });
69
+ }
70
+ }
71
+ //# sourceMappingURL=selfIssuanceHandlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selfIssuanceHandlers.js","sourceRoot":"","sources":["../../../src/blockchain/handlers/selfIssuanceHandlers.ts"],"names":[],"mappings":"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"}
@@ -1,7 +1,7 @@
1
1
  import { AgentContext } from '@credo-ts/core';
2
2
  import { VtFlowRecord, VtFlowService } from '@verana-labs/credo-ts-didcomm-vt-flow';
3
3
  import { VsAgent } from '../../agent/VsAgent';
4
- import { SelfTrDefaults } from '../../utils/setupSelfTr';
4
+ import { EcsClaims } from '../../utils/ecsClaims';
5
5
  import { VeranaIndexerService } from '../VeranaIndexerService';
6
6
  import { IndexerActivity, VeranaSyncState } from '../types';
7
7
  export declare function applyStateMutation(state: VeranaSyncState, activity: IndexerActivity): void;
@@ -16,11 +16,30 @@ export declare function upsertParticipant(state: VeranaSyncState, activity: Inde
16
16
  }): void;
17
17
  export declare function reconcileVtFlowRecordsForParticipant(agent: VsAgent, participantId: string, reconcile: (record: VtFlowRecord, service: VtFlowService, agentContext: AgentContext) => Promise<string | null>, errorLabel: string): Promise<void>;
18
18
  export declare function markVtFlowRecordsValidated(agent: VsAgent, participantId: string): Promise<void>;
19
+ /**
20
+ * Close the onboarding records of a participant that receives no credential.
21
+ *
22
+ * Only a HOLDER takes part in a credential exchange, and the exchange is what moves a record to
23
+ * COMPLETED. An ISSUER, a VERIFIER or a grantor is finished the moment the chain records
24
+ * SetParticipantOPToValidated, so without this both sides would sit at OR_SENT and VALIDATED for
25
+ * ever. The applicant reaches its own record here, because it watches the same chain event.
26
+ */
27
+ export declare function completeVtFlowRecordsWithoutCredential(agent: VsAgent, participantId: string): Promise<void>;
19
28
  export declare function setVtFlowRecordsParticipantRevoked(agent: VsAgent, participantId: string): Promise<void>;
20
29
  export declare function setVtFlowRecordsParticipantSlashed(agent: VsAgent, participantId: string): Promise<void>;
21
30
  /** VSA-VTI-FLOW-OP-REVOKE: a revoked/slashed HOLDER's credential is gone; drop its linked VP and stored VTC. */
22
31
  export declare function removeHolderTrustCredentialIfRevoked(agent: VsAgent, participantId: string): Promise<void>;
32
+ /**
33
+ * VSA-VTI-FLOW-OP-REVOKE: an ECS credential anchored against a revoked ISSUER still verifies, but a
34
+ * resolver reports the Participant as REVOKED and the whole DID then fails VS-CONN-VS.
35
+ */
36
+ export declare function removeSelfIssuedEcsCredentialsIfIssuerRevoked(agent: VsAgent, participantId: string): Promise<void>;
23
37
  export declare function reconcileVtFlowRecordsOnCancel(agent: VsAgent, participantId: string): Promise<void>;
24
38
  export declare function startParticipantOPAutoFlow(agent: VsAgent, activity: IndexerActivity): Promise<void>;
25
- export declare function reconcileVtjscPublications(agent: VsAgent, indexer: VeranaIndexerService, corporationId: number, selfTrDefaults?: SelfTrDefaults): Promise<void>;
39
+ export declare function reconcileVtjscPublications(agent: VsAgent, indexer: VeranaIndexerService, corporationId: number, ecsClaims?: EcsClaims): Promise<void>;
40
+ /**
41
+ * Publishes the one AnonCreds schema that governs every credential of a VTJSC, per [VSA-PUB-AC-5].
42
+ * Only the issuer of the VTJSC publishes it. The call is idempotent.
43
+ */
44
+ export declare function publishAnonCredsSchemaForVtjsc(agent: VsAgent, credentialSchemaId: string | number, jsonSchema: string | object, jsonSchemaCredentialId: string): Promise<string | undefined>;
26
45
  export declare function publishVtjscIfOwner(state: VeranaSyncState, agent: VsAgent, schemaEntityId: string, agentCorporationId?: number): Promise<void>;
@@ -7,22 +7,30 @@ exports.upsertCredentialSchema = upsertCredentialSchema;
7
7
  exports.upsertParticipant = upsertParticipant;
8
8
  exports.reconcileVtFlowRecordsForParticipant = reconcileVtFlowRecordsForParticipant;
9
9
  exports.markVtFlowRecordsValidated = markVtFlowRecordsValidated;
10
+ exports.completeVtFlowRecordsWithoutCredential = completeVtFlowRecordsWithoutCredential;
10
11
  exports.setVtFlowRecordsParticipantRevoked = setVtFlowRecordsParticipantRevoked;
11
12
  exports.setVtFlowRecordsParticipantSlashed = setVtFlowRecordsParticipantSlashed;
12
13
  exports.removeHolderTrustCredentialIfRevoked = removeHolderTrustCredentialIfRevoked;
14
+ exports.removeSelfIssuedEcsCredentialsIfIssuerRevoked = removeSelfIssuedEcsCredentialsIfIssuerRevoked;
13
15
  exports.reconcileVtFlowRecordsOnCancel = reconcileVtFlowRecordsOnCancel;
14
16
  exports.startParticipantOPAutoFlow = startParticipantOPAutoFlow;
15
17
  exports.reconcileVtjscPublications = reconcileVtjscPublications;
18
+ exports.publishAnonCredsSchemaForVtjsc = publishAnonCredsSchemaForVtjsc;
16
19
  exports.publishVtjscIfOwner = publishVtjscIfOwner;
20
+ const anoncreds_1 = require("@credo-ts/anoncreds");
17
21
  const credo_ts_didcomm_vt_flow_1 = require("@verana-labs/credo-ts-didcomm-vt-flow");
18
22
  const vs_agent_model_1 = require("@verana-labs/vs-agent-model");
23
+ const types_1 = require("../../types");
24
+ const agent_1 = require("../../utils/agent");
19
25
  const data_1 = require("../../utils/data");
26
+ const didReadiness_1 = require("../../utils/didReadiness");
20
27
  const setupSelfTr_1 = require("../../utils/setupSelfTr");
28
+ const ecsClaims_1 = require("../../utils/ecsClaims");
21
29
  const trustCredentialStore_1 = require("../../utils/trustCredentialStore");
30
+ const util_1 = require("../../utils/util");
31
+ const vtjscResolver_1 = require("../../utils/vtjscResolver");
22
32
  const vtFlow_1 = require("../../vtFlow");
23
- const types_1 = require("../types");
24
- const DEFAULT_CHAIN_ID = 'vna-testnet-1';
25
- const PARTICIPANT_ROLE_HOLDER = 6;
33
+ const types_2 = require("../types");
26
34
  function applyStateMutation(state, activity) {
27
35
  var _a;
28
36
  switch (activity.msg) {
@@ -164,6 +172,25 @@ async function markVtFlowRecordsValidated(agent, participantId) {
164
172
  return 'VALIDATED';
165
173
  }, 'Failed to markValidated');
166
174
  }
175
+ /**
176
+ * Close the onboarding records of a participant that receives no credential.
177
+ *
178
+ * Only a HOLDER takes part in a credential exchange, and the exchange is what moves a record to
179
+ * COMPLETED. An ISSUER, a VERIFIER or a grantor is finished the moment the chain records
180
+ * SetParticipantOPToValidated, so without this both sides would sit at OR_SENT and VALIDATED for
181
+ * ever. The applicant reaches its own record here, because it watches the same chain event.
182
+ */
183
+ async function completeVtFlowRecordsWithoutCredential(agent, participantId) {
184
+ const participant = await agent.indexer.findParticipant(participantId).catch(() => undefined);
185
+ if (!participant || participant.role === types_1.HOLDER_PARTICIPANT_TYPE)
186
+ return;
187
+ await reconcileVtFlowRecordsForParticipant(agent, participantId, async (record, service, agentContext) => {
188
+ if (record.state === credo_ts_didcomm_vt_flow_1.VtFlowState.Completed || (0, credo_ts_didcomm_vt_flow_1.isVtFlowTerminalState)(record.state))
189
+ return null;
190
+ await service.markCompleted(agentContext, record.id);
191
+ return 'COMPLETED';
192
+ }, 'Failed to mark COMPLETED');
193
+ }
167
194
  async function setVtFlowRecordsParticipantRevoked(agent, participantId) {
168
195
  await reconcileVtFlowRecordsForParticipant(agent, participantId, async (record, service, agentContext) => {
169
196
  if (record.state === credo_ts_didcomm_vt_flow_1.VtFlowState.ParticipantRevoked ||
@@ -196,9 +223,8 @@ async function setVtFlowRecordsParticipantSlashed(agent, participantId) {
196
223
  }
197
224
  /** VSA-VTI-FLOW-OP-REVOKE: a revoked/slashed HOLDER's credential is gone; drop its linked VP and stored VTC. */
198
225
  async function removeHolderTrustCredentialIfRevoked(agent, participantId) {
199
- var _a;
200
- const participant = await ((_a = agent.veranaChain) === null || _a === void 0 ? void 0 : _a.getParticipant(Number(participantId)).catch(() => undefined));
201
- if ((participant === null || participant === void 0 ? void 0 : participant.role) !== PARTICIPANT_ROLE_HOLDER || participant.did !== agent.did)
226
+ const participant = await agent.indexer.findParticipant(participantId).catch(() => undefined);
227
+ if ((participant === null || participant === void 0 ? void 0 : participant.role) !== types_1.HOLDER_PARTICIPANT_TYPE || participant.did !== agent.did)
202
228
  return;
203
229
  if (!agent.publicApiBaseUrl)
204
230
  return;
@@ -209,7 +235,7 @@ async function removeHolderTrustCredentialIfRevoked(agent, participantId) {
209
235
  if (record.role !== credo_ts_didcomm_vt_flow_1.VtFlowRole.Applicant || !record.credentialExchangeRecordId)
210
236
  continue;
211
237
  try {
212
- const credentialId = await (0, trustCredentialStore_1.removeStoredTrustCredential)(agent, agent.publicApiBaseUrl, record.credentialExchangeRecordId);
238
+ const credentialId = await (0, trustCredentialStore_1.removeStoredTrustCredential)(agent, record.credentialExchangeRecordId);
213
239
  if (credentialId) {
214
240
  agent.config.logger.info(`[IndexerWS] Removed linked VP and stored credential ${credentialId} (participant=${participantId})`);
215
241
  }
@@ -219,10 +245,29 @@ async function removeHolderTrustCredentialIfRevoked(agent, participantId) {
219
245
  }
220
246
  }
221
247
  }
248
+ /**
249
+ * VSA-VTI-FLOW-OP-REVOKE: an ECS credential anchored against a revoked ISSUER still verifies, but a
250
+ * resolver reports the Participant as REVOKED and the whole DID then fails VS-CONN-VS.
251
+ */
252
+ async function removeSelfIssuedEcsCredentialsIfIssuerRevoked(agent, participantId) {
253
+ if (!agent.publicApiBaseUrl)
254
+ return;
255
+ const participant = await agent.indexer.findParticipant(participantId).catch(() => undefined);
256
+ if ((participant === null || participant === void 0 ? void 0 : participant.role) !== types_1.ISSUER_PARTICIPANT_TYPE || participant.did !== agent.did)
257
+ return;
258
+ try {
259
+ const withdrawn = await (0, trustCredentialStore_1.withdrawSelfIssuedEcsCredentials)(agent, participant.id);
260
+ for (const jscUrl of withdrawn) {
261
+ agent.config.logger.info(`[SelfTR] Withdrew the self-issued ECS credential bound to ${jscUrl} (issuer participant ${participantId})`);
262
+ }
263
+ }
264
+ catch (e) {
265
+ agent.config.logger.error(`[SelfTR] Failed to withdraw the ECS credentials of the revoked ISSUER participant ${participantId}`, e);
266
+ }
267
+ }
222
268
  async function reconcileVtFlowRecordsOnCancel(agent, participantId) {
223
- var _a;
224
- const participant = await ((_a = agent.veranaChain) === null || _a === void 0 ? void 0 : _a.getParticipant(Number(participantId)).catch(() => undefined));
225
- const stillValidated = Number(participant === null || participant === void 0 ? void 0 : participant.opState) === types_1.ValidationState.VALIDATED;
269
+ const participant = await agent.indexer.findParticipant(participantId).catch(() => undefined);
270
+ const stillValidated = Number(participant === null || participant === void 0 ? void 0 : participant.opState) === types_2.ValidationState.VALIDATED;
226
271
  await reconcileVtFlowRecordsForParticipant(agent, participantId, async (record, service, agentContext) => {
227
272
  if ((0, credo_ts_didcomm_vt_flow_1.isVtFlowTerminalState)(record.state))
228
273
  return null;
@@ -236,6 +281,20 @@ async function reconcileVtFlowRecordsOnCancel(agent, participantId) {
236
281
  return 'TERMINATED_BY_APPLICANT';
237
282
  }, 'Failed to reconcile record after cancel');
238
283
  }
284
+ // [VSA-VTI-CFG-ENV-ECS]: the applicant proposes its own claims, and the validator may override
285
+ // them. The field is omitted when the operator configured none.
286
+ async function onboardingClaims(agent, schemaId) {
287
+ if (!agent.ecsClaims || !agent.did)
288
+ return undefined;
289
+ const schema = await agent.indexer.getCredentialSchema(schemaId);
290
+ const ecsKey = schema && (await (0, vs_agent_model_1.classifyEcsSchema)(schema.json_schema));
291
+ if (!ecsKey) {
292
+ agent.config.logger.warn(`[ecs-claims] schema ${schemaId} is not an ECS schema, sending no claims`);
293
+ return undefined;
294
+ }
295
+ // a digest the agent cannot compute must stop the flow, per [VSA-VTI-CFG-ENV-ECS]
296
+ return await (0, ecsClaims_1.composeEcsClaims)(agent.ecsClaims, ecsKey, agent.config.logger);
297
+ }
239
298
  async function startParticipantOPAutoFlow(agent, activity) {
240
299
  const chain = agent.veranaChain;
241
300
  if (!chain)
@@ -243,62 +302,224 @@ async function startParticipantOPAutoFlow(agent, activity) {
243
302
  const applicantParticipantId = Number(activity.entity_id);
244
303
  if (!Number.isFinite(applicantParticipantId))
245
304
  return;
246
- const holderParticipant = await chain.getParticipant(applicantParticipantId);
305
+ const holderParticipant = await agent.indexer.findParticipant(applicantParticipantId);
247
306
  if (!holderParticipant || holderParticipant.did !== agent.did)
248
307
  return;
249
308
  try {
309
+ await (0, didReadiness_1.waitUntilOwnDidIsPubliclyResolvable)(agent, agent.config.logger);
250
310
  const orchestrator = new vtFlow_1.VtFlowOrchestrator(agent);
251
- await orchestrator.startOnboardingProcess({ applicantParticipantId });
311
+ const claims = await onboardingClaims(agent, holderParticipant.schemaId);
312
+ await orchestrator.startOnboardingProcess(Object.assign({ applicantParticipantId }, (claims ? { claims } : {})));
252
313
  }
253
314
  catch (err) {
254
315
  agent.config.logger.error(`[IndexerWS] StartParticipantOP auto-flow failed: ${err.message}\n${err.stack}`);
255
316
  }
256
317
  }
257
- async function reconcileVtjscPublications(agent, indexer, corporationId, selfTrDefaults) {
318
+ async function reconcileVtjscPublications(agent, indexer, corporationId, ecsClaims) {
258
319
  var _a, _b, _c, _d;
259
320
  if (!agent.did || !agent.publicApiBaseUrl)
260
321
  return;
261
- const chainId = (_b = (_a = agent.veranaChain) === null || _a === void 0 ? void 0 : _a.getChainId) !== null && _b !== void 0 ? _b : DEFAULT_CHAIN_ID;
322
+ const chainId = (_a = agent.veranaChain) === null || _a === void 0 ? void 0 : _a.getChainId;
323
+ if (!chainId) {
324
+ agent.config.logger.warn('[VTJSC] Skipping reconciliation: the agent is not connected to a chain');
325
+ return;
326
+ }
262
327
  const ecosystems = await indexer.listEcosystems();
263
- for (const ecosystem of ecosystems.filter(entry => Number(entry.corporation_id) === corporationId)) {
328
+ const controlled = ecosystems.filter(entry => Number(entry.corporation_id) === corporationId);
329
+ const reconciled = new Set();
330
+ for (const ecosystem of controlled) {
264
331
  for (const schema of await indexer.listCredentialSchemas(ecosystem.id)) {
265
332
  const [didRecord] = await agent.dids.getCreatedDids({ did: agent.did });
266
333
  if (!didRecord)
267
334
  return;
268
335
  const schemaRef = `vpr:verana:${chainId}:cs:${schema.id}`;
336
+ reconciled.add(schemaRef);
269
337
  const expectedDigest = (0, setupSelfTr_1.generateDigestSRI)(schema.json_schema);
270
338
  const existingJsc = (0, trustCredentialStore_1.findMetadataEntry)(didRecord, '_vt/jsc', '', schemaRef);
271
- const existingDigest = (_d = (_c = existingJsc === null || existingJsc === void 0 ? void 0 : existingJsc.credential) === null || _c === void 0 ? void 0 : _c.credentialSubject) === null || _d === void 0 ? void 0 : _d.digestSRI;
272
- if (!existingJsc || existingDigest !== expectedDigest) {
273
- try {
274
- await (0, trustCredentialStore_1.createJsc)(agent, agent.publicApiBaseUrl, (0, data_1.getEcsSchemas)(agent.publicApiBaseUrl), {
339
+ const existingDigest = (_c = (_b = existingJsc === null || existingJsc === void 0 ? void 0 : existingJsc.credential) === null || _b === void 0 ? void 0 : _b.credentialSubject) === null || _c === void 0 ? void 0 : _c.digestSRI;
340
+ let jsonSchemaCredentialId = (_d = existingJsc === null || existingJsc === void 0 ? void 0 : existingJsc.credential) === null || _d === void 0 ? void 0 : _d.id;
341
+ try {
342
+ if (!existingJsc || existingDigest !== expectedDigest) {
343
+ const credential = await (0, trustCredentialStore_1.createJsc)(agent, agent.publicApiBaseUrl, (0, data_1.getEcsSchemas)(agent.publicApiBaseUrl), {
275
344
  schemaBaseId: String(schema.id),
276
345
  jsonSchemaRef: schemaRef,
277
346
  precomputedDigestSRI: expectedDigest,
278
347
  });
348
+ jsonSchemaCredentialId = credential.id;
279
349
  agent.config.logger.info(`[VTJSC] Reconciled VTJSC for schema ${schema.id} (ecosystem ${ecosystem.id})`);
280
350
  }
281
- catch (e) {
282
- agent.config.logger.error(`[VTJSC] Failed to reconcile VTJSC for schema ${schema.id}`, e);
283
- continue;
351
+ else if (await (0, trustCredentialStore_1.reattachVtjscPublication)(agent, schemaRef)) {
352
+ agent.config.logger.info(`[VTJSC] Re-attached the VTJSC of schema ${schema.id} (ecosystem ${ecosystem.id})`);
284
353
  }
285
354
  }
286
- if (selfTrDefaults) {
287
- try {
288
- const ecsKey = await (0, vs_agent_model_1.identifySchema)(JSON.parse(schema.json_schema));
289
- if (!ecsKey)
290
- continue;
291
- await (0, trustCredentialStore_1.rebindEcsCredentialSchema)(agent, agent.publicApiBaseUrl, String(schema.id), ecsKey, selfTrDefaults);
292
- }
293
- catch (e) {
294
- agent.config.logger.error(`[VTJSC] Failed to rebind ECS credential for schema ${schema.id}`, e);
355
+ catch (e) {
356
+ agent.config.logger.error(`[VTJSC] Failed to reconcile VTJSC for schema ${schema.id}`, e);
357
+ }
358
+ // an agent that published a VTJSC before [VSA-PUB-AC-5] has no AnonCreds schema for it yet
359
+ if (!jsonSchemaCredentialId)
360
+ continue;
361
+ try {
362
+ await publishAnonCredsSchemaForVtjsc(agent, schema.id, schema.json_schema, jsonSchemaCredentialId);
363
+ }
364
+ catch (e) {
365
+ agent.config.logger.error(`[VTJSC] Failed to reconcile the AnonCreds schema of ${jsonSchemaCredentialId}`, e);
366
+ }
367
+ }
368
+ }
369
+ await detachUncontrolledVtjscPublications(agent, indexer, corporationId, chainId, reconciled);
370
+ if (ecsClaims)
371
+ await reconcileSelfIssuedEcsCredentials(agent, indexer, ecsClaims);
372
+ }
373
+ /** The `_vt/jsc` key that `createJsc` writes for an on-chain `CredentialSchema`. */
374
+ const onChainSchemaRefPrefix = (chainId) => `vpr:verana:${chainId}:cs:`;
375
+ /**
376
+ * VSA-VTI-VTJSC: only the controller of an Ecosystem advertises a VTJSC for its schemas. Archival
377
+ * is not a loss of control — the agent keeps it, and [VSA-VTI-NOTIF-ES] gives it no handler.
378
+ *
379
+ * Each entry is resolved against the VPR one by one rather than diffed against `listEcosystems`:
380
+ * that endpoint is unpaginated here, and a truncated page reads like a loss of control.
381
+ */
382
+ async function detachUncontrolledVtjscPublications(agent, indexer, corporationId, chainId, reconciled) {
383
+ const [didRecord] = await agent.dids.getCreatedDids({ did: agent.did });
384
+ if (!didRecord)
385
+ return;
386
+ const metadata = didRecord.metadata.get('_vt/jsc');
387
+ if (!metadata)
388
+ return;
389
+ const prefix = onChainSchemaRefPrefix(chainId);
390
+ const ecosystemCache = new Map();
391
+ const stale = [];
392
+ for (const schemaRef of Object.keys(metadata)) {
393
+ // the agent's own schema credentials live in this bucket, keyed by public URL.
394
+ if (!schemaRef.startsWith(prefix))
395
+ continue;
396
+ if (reconciled.has(schemaRef))
397
+ continue;
398
+ const schemaId = schemaRef.slice(prefix.length);
399
+ try {
400
+ const schema = await indexer.getCredentialSchema(schemaId);
401
+ const ecosystemId = String(schema.ecosystem_id);
402
+ if (!ecosystemCache.has(ecosystemId)) {
403
+ ecosystemCache.set(ecosystemId, await indexer.getEcosystem(ecosystemId));
404
+ }
405
+ const ecosystem = ecosystemCache.get(ecosystemId);
406
+ if (!ecosystem)
407
+ continue;
408
+ if (Number(ecosystem.corporation_id) === corporationId)
409
+ continue;
410
+ agent.config.logger.info(`[VTJSC] Detaching the VTJSC of schema ${schemaId}: ecosystem ${ecosystemId} belongs to ` +
411
+ `corporation ${ecosystem.corporation_id}`);
412
+ stale.push(schemaRef);
413
+ }
414
+ catch (error) {
415
+ // A lookup the VPR cannot answer is not evidence of anything; leave the entry advertised.
416
+ agent.config.logger.debug(`[VTJSC] Keeping the VTJSC of schema ${schemaId}: ${error.message}`);
417
+ }
418
+ }
419
+ if (stale.length === 0)
420
+ return;
421
+ const detached = await (0, trustCredentialStore_1.detachVtjscPublications)(agent, stale);
422
+ if (detached.length > 0) {
423
+ agent.config.logger.info(`[VTJSC] Detached ${detached.length} VTJSC publication(s)`);
424
+ }
425
+ }
426
+ /**
427
+ * Rebinds and anchors this agent's own ECS credentials.
428
+ *
429
+ * It follows the ISSUER Participant entries the agent holds, not the Ecosystems its Corporation
430
+ * controls: an agent may issue against an Ecosystem that another Corporation owns, and an
431
+ * Ecosystem controller may hold no ISSUER entry at all. An entry is usable only when it names
432
+ * this agent's account as its vs_operator, because the chain accepts the anchoring
433
+ * CreateOrUpdateParticipantSession from no other signer.
434
+ */
435
+ async function reconcileSelfIssuedEcsCredentials(agent, indexer, ecsClaims) {
436
+ const chain = agent.veranaChain;
437
+ if (!chain || !agent.did || !agent.publicApiBaseUrl)
438
+ return;
439
+ const chainId = chain.getChainId;
440
+ // A Participant revoked while the agent was down delivers no event it can still act on. Runs
441
+ // first, so a schema whose ISSUER entry was replaced ends up bound to the new one.
442
+ for (const participantState of [types_2.ParticipantState.Revoked, types_2.ParticipantState.Slashed]) {
443
+ try {
444
+ const stale = await indexer.listParticipants({
445
+ did: agent.did,
446
+ role: types_2.ParticipantRole.Issuer,
447
+ participantState,
448
+ });
449
+ for (const issuer of stale) {
450
+ const withdrawn = await (0, trustCredentialStore_1.withdrawSelfIssuedEcsCredentials)(agent, issuer.id);
451
+ for (const jscUrl of withdrawn) {
452
+ agent.config.logger.info(`[SelfTR] Withdrew the self-issued ECS credential bound to ${jscUrl} (${participantState} issuer participant ${issuer.id})`);
295
453
  }
296
454
  }
297
455
  }
456
+ catch (e) {
457
+ agent.config.logger.error(`[SelfTR] Failed to withdraw the ECS credentials of ${participantState} ISSUER participants`, e);
458
+ }
459
+ }
460
+ const issuers = await indexer.listParticipants({
461
+ did: agent.did,
462
+ role: types_2.ParticipantRole.Issuer,
463
+ participantState: types_2.ParticipantState.Active,
464
+ });
465
+ for (const issuer of issuers) {
466
+ if (issuer.revoked || issuer.slashed || issuer.vs_operator !== chain.address)
467
+ continue;
468
+ try {
469
+ const schema = await indexer.getCredentialSchema(issuer.schema_id);
470
+ const ecsKey = await (0, vs_agent_model_1.classifyEcsSchema)(schema.json_schema);
471
+ if (ecsKey !== 'ecs-service')
472
+ continue;
473
+ const jsonSchemaCredentialId = await (0, vtjscResolver_1.resolveJsonSchemaCredentialId)(agent, indexer, schema.id, chainId);
474
+ await (0, trustCredentialStore_1.rebindEcsCredentialSchema)(agent, agent.publicApiBaseUrl, String(schema.id), ecsKey, ecsClaims, jsonSchemaCredentialId, issuer.id, schema.json_schema);
475
+ }
476
+ catch (e) {
477
+ agent.config.logger.error(`[SelfTR] Failed to rebind the ECS credential of schema ${issuer.schema_id}`, e);
478
+ }
479
+ }
480
+ }
481
+ /**
482
+ * Publishes the one AnonCreds schema that governs every credential of a VTJSC, per [VSA-PUB-AC-5].
483
+ * Only the issuer of the VTJSC publishes it. The call is idempotent.
484
+ */
485
+ async function publishAnonCredsSchemaForVtjsc(agent, credentialSchemaId, jsonSchema, jsonSchemaCredentialId) {
486
+ if (!agent.did)
487
+ return undefined;
488
+ const [published] = await agent.modules.anoncreds.getCreatedSchemas({
489
+ relatedJsonSchemaCredentialId: jsonSchemaCredentialId,
490
+ });
491
+ if (published)
492
+ return published.schemaId;
493
+ const { name, attrNames } = (0, util_1.anonCredsSchemaFromJsonSchema)(jsonSchema);
494
+ // used for consistency when a similar schema already exists
495
+ const version = String(credentialSchemaId);
496
+ const { schemaState, registrationMetadata } = await agent.modules.anoncreds.registerSchema({
497
+ schema: { attrNames, name, version, issuerId: agent.did },
498
+ options: { extraMetadata: { relatedJsonSchemaCredentialId: jsonSchemaCredentialId } },
499
+ });
500
+ if (schemaState.state !== 'finished') {
501
+ const detail = schemaState.state === 'failed' ? schemaState.reason : schemaState.state;
502
+ throw new Error(`Failed to register the AnonCreds schema of ${jsonSchemaCredentialId}: ${detail}`);
298
503
  }
504
+ const { schemaId } = schemaState;
505
+ const schemaRepository = agent.dependencyManager.resolve(anoncreds_1.AnonCredsSchemaRepository);
506
+ const schemaRecord = await schemaRepository.findBySchemaId(agent.context, schemaId);
507
+ if (schemaRecord) {
508
+ schemaRecord.setTag('relatedJsonSchemaCredentialId', jsonSchemaCredentialId);
509
+ await schemaRepository.update(agent.context, schemaRecord);
510
+ }
511
+ // the did:web layout builds no attested resource: it serves the object from the AnonCreds record
512
+ const { attestedResource } = registrationMetadata;
513
+ if (attestedResource) {
514
+ await (0, agent_1.saveAttestedResource)(agent, attestedResource, {
515
+ resourceType: 'anonCredsSchema',
516
+ relatedJsonSchemaCredentialId: jsonSchemaCredentialId,
517
+ });
518
+ }
519
+ return schemaId;
299
520
  }
300
521
  async function publishVtjscIfOwner(state, agent, schemaEntityId, agentCorporationId) {
301
- var _a, _b;
522
+ var _a;
302
523
  const schema = state.credentialSchemas[schemaEntityId];
303
524
  if (!schema) {
304
525
  agent.config.logger.warn(`[VTJSC] Schema ${schemaEntityId} not found in state`);
@@ -313,19 +534,36 @@ async function publishVtjscIfOwner(state, agent, schemaEntityId, agentCorporatio
313
534
  agent.config.logger.debug(`[VTJSC] Skipping schema ${schema.id}: ecosystem ${ecosystem.id} belongs to corporation ${ecosystem.corporationId}`);
314
535
  return;
315
536
  }
316
- const chainId = (_b = (_a = agent.veranaChain) === null || _a === void 0 ? void 0 : _a.getChainId) !== null && _b !== void 0 ? _b : DEFAULT_CHAIN_ID;
537
+ const chainId = (_a = agent.veranaChain) === null || _a === void 0 ? void 0 : _a.getChainId;
538
+ if (!chainId) {
539
+ agent.config.logger.warn(`[VTJSC] Skipping schema ${schema.id}: the agent is not connected to a chain`);
540
+ return;
541
+ }
317
542
  const jsonSchemaRef = `vpr:verana:${chainId}:cs:${schema.id}`;
318
543
  const digestSRI = (0, setupSelfTr_1.generateDigestSRI)(schema.jsonSchema);
544
+ let jsonSchemaCredentialId;
319
545
  try {
320
- await (0, trustCredentialStore_1.createJsc)(agent, agent.publicApiBaseUrl, (0, data_1.getEcsSchemas)(agent.publicApiBaseUrl), {
546
+ const credential = await (0, trustCredentialStore_1.createJsc)(agent, agent.publicApiBaseUrl, (0, data_1.getEcsSchemas)(agent.publicApiBaseUrl), {
321
547
  schemaBaseId: String(schema.id),
322
548
  jsonSchemaRef,
323
549
  precomputedDigestSRI: digestSRI,
324
550
  });
551
+ jsonSchemaCredentialId = credential.id;
325
552
  agent.config.logger.info(`[VTJSC] Published VTJSC for schema ${schema.id} (Ecosystem ${schema.ecosystemId}) at block ${state.lastBlockHeight}`);
326
553
  }
327
554
  catch (e) {
328
555
  agent.config.logger.error(`[VTJSC] Failed to publish VTJSC for schema ${schema.id}`, e);
556
+ return;
557
+ }
558
+ // an AnonCreds failure keeps the VTJSC: the startup reconciliation retries the schema
559
+ if (!jsonSchemaCredentialId)
560
+ return;
561
+ try {
562
+ const schemaId = await publishAnonCredsSchemaForVtjsc(agent, schema.id, schema.jsonSchema, jsonSchemaCredentialId);
563
+ agent.config.logger.info(`[VTJSC] Published the AnonCreds schema ${schemaId} of ${jsonSchemaCredentialId}`);
564
+ }
565
+ catch (e) {
566
+ agent.config.logger.error(`[VTJSC] Failed to publish the AnonCreds schema of ${jsonSchemaCredentialId}`, e);
329
567
  }
330
568
  }
331
569
  //# sourceMappingURL=stateMutations.js.map