@verana-labs/vs-agent-sdk 2.0.0-dev.6 → 2.0.0-dev.60

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 (148) hide show
  1. package/README.md +0 -2
  2. package/build/adminApi/AdminApiError.d.ts +25 -0
  3. package/build/adminApi/AdminApiError.js +57 -0
  4. package/build/adminApi/AdminApiError.js.map +1 -0
  5. package/build/adminApi/didcommModules.d.ts +2 -0
  6. package/build/adminApi/didcommModules.js +8 -0
  7. package/build/adminApi/didcommModules.js.map +1 -0
  8. package/build/adminApi/index.d.ts +3 -0
  9. package/build/adminApi/index.js +20 -0
  10. package/build/adminApi/index.js.map +1 -0
  11. package/build/adminApi/moduleEndpoint.d.ts +8 -0
  12. package/build/adminApi/moduleEndpoint.js +28 -0
  13. package/build/adminApi/moduleEndpoint.js.map +1 -0
  14. package/build/agent/VsAgent.d.ts +15 -33
  15. package/build/agent/VsAgent.js +75 -205
  16. package/build/agent/VsAgent.js.map +1 -1
  17. package/build/agent/createVsAgent.d.ts +5 -5
  18. package/build/agent/createVsAgent.js +3 -5
  19. package/build/agent/createVsAgent.js.map +1 -1
  20. package/build/blockchain/AnonCredsTrustService.d.ts +62 -0
  21. package/build/blockchain/AnonCredsTrustService.js +256 -0
  22. package/build/blockchain/AnonCredsTrustService.js.map +1 -0
  23. package/build/blockchain/AuthorizationService.d.ts +5 -3
  24. package/build/blockchain/AuthorizationService.js +17 -29
  25. package/build/blockchain/AuthorizationService.js.map +1 -1
  26. package/build/blockchain/IndexerWebSocketService.d.ts +7 -1
  27. package/build/blockchain/IndexerWebSocketService.js +68 -36
  28. package/build/blockchain/IndexerWebSocketService.js.map +1 -1
  29. package/build/blockchain/VeranaChainService.d.ts +2 -13
  30. package/build/blockchain/VeranaChainService.js +8 -113
  31. package/build/blockchain/VeranaChainService.js.map +1 -1
  32. package/build/blockchain/VeranaIndexerService.d.ts +14 -1
  33. package/build/blockchain/VeranaIndexerService.js +122 -8
  34. package/build/blockchain/VeranaIndexerService.js.map +1 -1
  35. package/build/blockchain/handlers/authorizationHandlers.js +2 -2
  36. package/build/blockchain/handlers/authorizationHandlers.js.map +1 -1
  37. package/build/blockchain/handlers/defaultHandlers.js +2 -0
  38. package/build/blockchain/handlers/defaultHandlers.js.map +1 -1
  39. package/build/blockchain/handlers/index.d.ts +1 -0
  40. package/build/blockchain/handlers/index.js +1 -0
  41. package/build/blockchain/handlers/index.js.map +1 -1
  42. package/build/blockchain/handlers/selfIssuanceHandlers.d.ts +13 -0
  43. package/build/blockchain/handlers/selfIssuanceHandlers.js +71 -0
  44. package/build/blockchain/handlers/selfIssuanceHandlers.js.map +1 -0
  45. package/build/blockchain/handlers/stateMutations.d.ts +21 -2
  46. package/build/blockchain/handlers/stateMutations.js +280 -34
  47. package/build/blockchain/handlers/stateMutations.js.map +1 -1
  48. package/build/blockchain/index.d.ts +2 -0
  49. package/build/blockchain/index.js +2 -0
  50. package/build/blockchain/index.js.map +1 -1
  51. package/build/blockchain/indexerMappers.d.ts +3 -0
  52. package/build/blockchain/indexerMappers.js +53 -0
  53. package/build/blockchain/indexerMappers.js.map +1 -0
  54. package/build/blockchain/types.d.ts +5 -57
  55. package/build/blockchain/types.js.map +1 -1
  56. package/build/bootstrap/EcsBootstrapService.d.ts +14 -3
  57. package/build/bootstrap/EcsBootstrapService.js +155 -76
  58. package/build/bootstrap/EcsBootstrapService.js.map +1 -1
  59. package/build/credentials/FullTailsFileService.d.ts +0 -1
  60. package/build/credentials/FullTailsFileService.js +0 -49
  61. package/build/credentials/FullTailsFileService.js.map +1 -1
  62. package/build/did/CachedDocumentLoader.d.ts +3 -0
  63. package/build/did/CachedDocumentLoader.js +7 -1
  64. package/build/did/CachedDocumentLoader.js.map +1 -1
  65. package/build/did/CachedWebDidResolver.d.ts +0 -4
  66. package/build/did/CachedWebDidResolver.js +1 -5
  67. package/build/did/CachedWebDidResolver.js.map +1 -1
  68. package/build/did/artifactServices.d.ts +12 -0
  69. package/build/did/artifactServices.js +48 -0
  70. package/build/did/artifactServices.js.map +1 -0
  71. package/build/did/legacyDidWeb.d.ts +6 -4
  72. package/build/did/legacyDidWeb.js +17 -14
  73. package/build/did/legacyDidWeb.js.map +1 -1
  74. package/build/did/publicDid.d.ts +4 -0
  75. package/build/did/publicDid.js +19 -0
  76. package/build/did/publicDid.js.map +1 -0
  77. package/build/events/BaseMessageEvents.js +139 -5
  78. package/build/events/BaseMessageEvents.js.map +1 -1
  79. package/build/events/ConnectionEvents.js +110 -82
  80. package/build/events/ConnectionEvents.js.map +1 -1
  81. package/build/events/VsAgentEvents.d.ts +11 -9
  82. package/build/events/VsAgentEvents.js +8 -1
  83. package/build/events/VsAgentEvents.js.map +1 -1
  84. package/build/events/VtFlowEvents.d.ts +1 -1
  85. package/build/events/VtFlowEvents.js +2 -19
  86. package/build/events/VtFlowEvents.js.map +1 -1
  87. package/build/index.d.ts +6 -1
  88. package/build/index.js +10 -2
  89. package/build/index.js.map +1 -1
  90. package/build/plugins/setupBaseDidComm.js +6 -12
  91. package/build/plugins/setupBaseDidComm.js.map +1 -1
  92. package/build/transports/VsAgentWsInboundTransport.d.ts +1 -1
  93. package/build/transports/VsAgentWsInboundTransport.js +20 -14
  94. package/build/transports/VsAgentWsInboundTransport.js.map +1 -1
  95. package/build/types.d.ts +5 -0
  96. package/build/types.js.map +1 -1
  97. package/build/utils/agent.d.ts +27 -3
  98. package/build/utils/agent.js +83 -22
  99. package/build/utils/agent.js.map +1 -1
  100. package/build/utils/didReadiness.d.ts +9 -0
  101. package/build/utils/didReadiness.js +42 -0
  102. package/build/utils/didReadiness.js.map +1 -0
  103. package/build/utils/ecsClaims.d.ts +47 -0
  104. package/build/utils/ecsClaims.js +120 -0
  105. package/build/utils/ecsClaims.js.map +1 -0
  106. package/build/utils/ecsService.d.ts +8 -0
  107. package/build/utils/ecsService.js +23 -0
  108. package/build/utils/ecsService.js.map +1 -0
  109. package/build/utils/index.d.ts +4 -0
  110. package/build/utils/index.js +4 -0
  111. package/build/utils/index.js.map +1 -1
  112. package/build/utils/selfIssuedEcsCredential.d.ts +8 -0
  113. package/build/utils/selfIssuedEcsCredential.js +151 -0
  114. package/build/utils/selfIssuedEcsCredential.js.map +1 -0
  115. package/build/utils/setupSelfTr.d.ts +29 -66
  116. package/build/utils/setupSelfTr.js +78 -282
  117. package/build/utils/setupSelfTr.js.map +1 -1
  118. package/build/utils/trustCredentialStore.d.ts +67 -9
  119. package/build/utils/trustCredentialStore.js +296 -109
  120. package/build/utils/trustCredentialStore.js.map +1 -1
  121. package/build/utils/util.d.ts +10 -0
  122. package/build/utils/util.js +16 -0
  123. package/build/utils/util.js.map +1 -1
  124. package/build/utils/vcdm2.d.ts +34 -0
  125. package/build/utils/vcdm2.js +62 -0
  126. package/build/utils/vcdm2.js.map +1 -0
  127. package/build/utils/vtjscResolver.d.ts +18 -0
  128. package/build/utils/vtjscResolver.js +54 -0
  129. package/build/utils/vtjscResolver.js.map +1 -0
  130. package/build/vtFlow/VtFlowOrchestrator.d.ts +59 -13
  131. package/build/vtFlow/VtFlowOrchestrator.js +139 -91
  132. package/build/vtFlow/VtFlowOrchestrator.js.map +1 -1
  133. package/build/vtFlow/assertVerifiableService.d.ts +1 -0
  134. package/build/vtFlow/assertVerifiableService.js +45 -5
  135. package/build/vtFlow/assertVerifiableService.js.map +1 -1
  136. package/build/vtFlow/ecsIssuanceExemption.d.ts +12 -0
  137. package/build/vtFlow/ecsIssuanceExemption.js +84 -0
  138. package/build/vtFlow/ecsIssuanceExemption.js.map +1 -0
  139. package/build/vtFlow/index.d.ts +1 -0
  140. package/build/vtFlow/index.js +1 -0
  141. package/build/vtFlow/index.js.map +1 -1
  142. package/package.json +12 -12
  143. package/build/did/migrateWebVhLog.d.ts +0 -34
  144. package/build/did/migrateWebVhLog.js +0 -230
  145. package/build/did/migrateWebVhLog.js.map +0 -1
  146. package/build/did/migrateWebVhVersionTime.d.ts +0 -9
  147. package/build/did/migrateWebVhVersionTime.js +0 -191
  148. package/build/did/migrateWebVhVersionTime.js.map +0 -1
@@ -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":";;AA0BA,gFAyDC;AAjFD,oCAA2D;AAG3D,qDAA4G;AAE5G;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,CAAC,6BAA6B,EAAE,uBAAuB,CAAC,CAAA;AAElF,iGAAiG;AACjG,MAAM,mBAAmB,GAAG,CAAC,mBAAmB,EAAE,8BAA8B,CAAC,CAAA;AAEjF;;;;;;;;GAQG;AACH,SAAgB,kCAAkC,CAChD,QAAgC,EAChC,OAA6B,EAC7B,aAAqB,EACrB,SAAoB;IAEpB,+FAA+F;IAC/F,IAAI,KAAK,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAA;IAE5C,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAClC,QAAQ,CAAC,QAAQ,CAAC;YAChB,GAAG;YACH,MAAM,EAAE,KAAK,EAAE,QAAyB,EAAE,GAA0B,EAAE,EAAE;gBACtE,IAAI,QAAQ;oBAAE,MAAM,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;gBAElD,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAA;gBACrB,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW;oBAAE,OAAM;gBAC5C,IAAI,CAAC;oBACH,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAA;oBAC5E,IAAI,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,GAAG,MAAK,KAAK,CAAC,GAAG,IAAI,WAAW,CAAC,IAAI,KAAK,uBAAe,CAAC,MAAM;wBAAE,OAAM;gBAC3F,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAC3B,uCAAuC,QAAQ,CAAC,SAAS,KAAM,KAAe,CAAC,OAAO,EAAE,CACzF,CAAA;oBACD,OAAM;gBACR,CAAC;gBAED,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CACtB,mCAAmC,QAAQ,CAAC,SAAS,4CAA4C,CAClG,CAAA;gBACD,KAAK,GAAG,KAAK;qBACV,IAAI,CAAC,GAAG,EAAE,CAAC,IAAA,2CAA0B,EAAC,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;qBAChF,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE,CACtB,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAmC,KAAK,CAAC,OAAO,EAAE,CAAC,CAC9E,CAAA;gBACH,MAAM,KAAK,CAAA;YACb,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,mBAAmB,EAAE,CAAC;QACtC,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAClC,QAAQ,CAAC,QAAQ,CAAC;YAChB,GAAG;YACH,MAAM,EAAE,KAAK,EAAE,QAAyB,EAAE,GAA0B,EAAE,EAAE;gBACtE,IAAI,QAAQ;oBAAE,MAAM,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;gBAElD,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAA;gBACrB,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW;oBAAE,OAAM;gBAC5C,KAAK,GAAG,KAAK;qBACV,IAAI,CAAC,GAAG,EAAE,CAAC,IAAA,8DAA6C,EAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;qBAC5F,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;gBACrG,MAAM,KAAK,CAAA;YACb,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;AACH,CAAC"}
@@ -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,31 @@ 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 vcdm2_1 = require("../../utils/vcdm2");
32
+ const vtjscResolver_1 = require("../../utils/vtjscResolver");
22
33
  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;
34
+ const types_2 = require("../types");
26
35
  function applyStateMutation(state, activity) {
27
36
  var _a;
28
37
  switch (activity.msg) {
@@ -164,6 +173,25 @@ async function markVtFlowRecordsValidated(agent, participantId) {
164
173
  return 'VALIDATED';
165
174
  }, 'Failed to markValidated');
166
175
  }
176
+ /**
177
+ * Close the onboarding records of a participant that receives no credential.
178
+ *
179
+ * Only a HOLDER takes part in a credential exchange, and the exchange is what moves a record to
180
+ * COMPLETED. An ISSUER, a VERIFIER or a grantor is finished the moment the chain records
181
+ * SetParticipantOPToValidated, so without this both sides would sit at OR_SENT and VALIDATED for
182
+ * ever. The applicant reaches its own record here, because it watches the same chain event.
183
+ */
184
+ async function completeVtFlowRecordsWithoutCredential(agent, participantId) {
185
+ const participant = await agent.indexer.findParticipant(participantId).catch(() => undefined);
186
+ if (!participant || participant.role === types_1.HOLDER_PARTICIPANT_TYPE)
187
+ return;
188
+ await reconcileVtFlowRecordsForParticipant(agent, participantId, async (record, service, agentContext) => {
189
+ if (record.state === credo_ts_didcomm_vt_flow_1.VtFlowState.Completed || (0, credo_ts_didcomm_vt_flow_1.isVtFlowTerminalState)(record.state))
190
+ return null;
191
+ await service.markCompleted(agentContext, record.id);
192
+ return 'COMPLETED';
193
+ }, 'Failed to mark COMPLETED');
194
+ }
167
195
  async function setVtFlowRecordsParticipantRevoked(agent, participantId) {
168
196
  await reconcileVtFlowRecordsForParticipant(agent, participantId, async (record, service, agentContext) => {
169
197
  if (record.state === credo_ts_didcomm_vt_flow_1.VtFlowState.ParticipantRevoked ||
@@ -196,9 +224,8 @@ async function setVtFlowRecordsParticipantSlashed(agent, participantId) {
196
224
  }
197
225
  /** VSA-VTI-FLOW-OP-REVOKE: a revoked/slashed HOLDER's credential is gone; drop its linked VP and stored VTC. */
198
226
  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)
227
+ const participant = await agent.indexer.findParticipant(participantId).catch(() => undefined);
228
+ if ((participant === null || participant === void 0 ? void 0 : participant.role) !== types_1.HOLDER_PARTICIPANT_TYPE || participant.did !== agent.did)
202
229
  return;
203
230
  if (!agent.publicApiBaseUrl)
204
231
  return;
@@ -209,7 +236,7 @@ async function removeHolderTrustCredentialIfRevoked(agent, participantId) {
209
236
  if (record.role !== credo_ts_didcomm_vt_flow_1.VtFlowRole.Applicant || !record.credentialExchangeRecordId)
210
237
  continue;
211
238
  try {
212
- const credentialId = await (0, trustCredentialStore_1.removeStoredTrustCredential)(agent, agent.publicApiBaseUrl, record.credentialExchangeRecordId);
239
+ const credentialId = await (0, trustCredentialStore_1.removeStoredTrustCredential)(agent, record.credentialExchangeRecordId);
213
240
  if (credentialId) {
214
241
  agent.config.logger.info(`[IndexerWS] Removed linked VP and stored credential ${credentialId} (participant=${participantId})`);
215
242
  }
@@ -219,10 +246,29 @@ async function removeHolderTrustCredentialIfRevoked(agent, participantId) {
219
246
  }
220
247
  }
221
248
  }
249
+ /**
250
+ * VSA-VTI-FLOW-OP-REVOKE: an ECS credential anchored against a revoked ISSUER still verifies, but a
251
+ * resolver reports the Participant as REVOKED and the whole DID then fails VS-CONN-VS.
252
+ */
253
+ async function removeSelfIssuedEcsCredentialsIfIssuerRevoked(agent, participantId) {
254
+ if (!agent.publicApiBaseUrl)
255
+ return;
256
+ const participant = await agent.indexer.findParticipant(participantId).catch(() => undefined);
257
+ if ((participant === null || participant === void 0 ? void 0 : participant.role) !== types_1.ISSUER_PARTICIPANT_TYPE || participant.did !== agent.did)
258
+ return;
259
+ try {
260
+ const withdrawn = await (0, trustCredentialStore_1.withdrawSelfIssuedEcsCredentials)(agent, participant.id);
261
+ for (const jscUrl of withdrawn) {
262
+ agent.config.logger.info(`[SelfTR] Withdrew the self-issued ECS credential bound to ${jscUrl} (issuer participant ${participantId})`);
263
+ }
264
+ }
265
+ catch (e) {
266
+ agent.config.logger.error(`[SelfTR] Failed to withdraw the ECS credentials of the revoked ISSUER participant ${participantId}`, e);
267
+ }
268
+ }
222
269
  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;
270
+ const participant = await agent.indexer.findParticipant(participantId).catch(() => undefined);
271
+ const stillValidated = Number(participant === null || participant === void 0 ? void 0 : participant.opState) === types_2.ValidationState.VALIDATED;
226
272
  await reconcileVtFlowRecordsForParticipant(agent, participantId, async (record, service, agentContext) => {
227
273
  if ((0, credo_ts_didcomm_vt_flow_1.isVtFlowTerminalState)(record.state))
228
274
  return null;
@@ -236,6 +282,20 @@ async function reconcileVtFlowRecordsOnCancel(agent, participantId) {
236
282
  return 'TERMINATED_BY_APPLICANT';
237
283
  }, 'Failed to reconcile record after cancel');
238
284
  }
285
+ // [VSA-VTI-CFG-ENV-ECS]: the applicant proposes its own claims, and the validator may override
286
+ // them. The field is omitted when the operator configured none.
287
+ async function onboardingClaims(agent, schemaId) {
288
+ if (!agent.ecsClaims || !agent.did)
289
+ return undefined;
290
+ const schema = await agent.indexer.getCredentialSchema(schemaId);
291
+ const ecsKey = schema && (await (0, vs_agent_model_1.classifyEcsSchema)(schema.json_schema));
292
+ if (!ecsKey) {
293
+ agent.config.logger.warn(`[ecs-claims] schema ${schemaId} is not an ECS schema, sending no claims`);
294
+ return undefined;
295
+ }
296
+ // a digest the agent cannot compute must stop the flow, per [VSA-VTI-CFG-ENV-ECS]
297
+ return await (0, ecsClaims_1.composeEcsClaims)(agent.ecsClaims, ecsKey, agent.config.logger);
298
+ }
239
299
  async function startParticipantOPAutoFlow(agent, activity) {
240
300
  const chain = agent.veranaChain;
241
301
  if (!chain)
@@ -243,62 +303,231 @@ async function startParticipantOPAutoFlow(agent, activity) {
243
303
  const applicantParticipantId = Number(activity.entity_id);
244
304
  if (!Number.isFinite(applicantParticipantId))
245
305
  return;
246
- const holderParticipant = await chain.getParticipant(applicantParticipantId);
306
+ const holderParticipant = await agent.indexer.findParticipant(applicantParticipantId);
247
307
  if (!holderParticipant || holderParticipant.did !== agent.did)
248
308
  return;
249
309
  try {
310
+ await (0, didReadiness_1.waitUntilOwnDidIsPubliclyResolvable)(agent, agent.config.logger);
250
311
  const orchestrator = new vtFlow_1.VtFlowOrchestrator(agent);
251
- await orchestrator.startOnboardingProcess({ applicantParticipantId });
312
+ const claims = await onboardingClaims(agent, holderParticipant.schemaId);
313
+ await orchestrator.startOnboardingProcess(Object.assign({ applicantParticipantId }, (claims ? { claims } : {})));
252
314
  }
253
315
  catch (err) {
254
316
  agent.config.logger.error(`[IndexerWS] StartParticipantOP auto-flow failed: ${err.message}\n${err.stack}`);
255
317
  }
256
318
  }
257
- async function reconcileVtjscPublications(agent, indexer, corporationId, selfTrDefaults) {
319
+ async function reconcileVtjscPublications(agent, indexer, corporationId, ecsClaims) {
258
320
  var _a, _b, _c, _d;
259
321
  if (!agent.did || !agent.publicApiBaseUrl)
260
322
  return;
261
- const chainId = (_b = (_a = agent.veranaChain) === null || _a === void 0 ? void 0 : _a.getChainId) !== null && _b !== void 0 ? _b : DEFAULT_CHAIN_ID;
323
+ const chainId = (_a = agent.veranaChain) === null || _a === void 0 ? void 0 : _a.getChainId;
324
+ if (!chainId) {
325
+ agent.config.logger.warn('[VTJSC] Skipping reconciliation: the agent is not connected to a chain');
326
+ return;
327
+ }
262
328
  const ecosystems = await indexer.listEcosystems();
263
- for (const ecosystem of ecosystems.filter(entry => Number(entry.corporation_id) === corporationId)) {
329
+ const controlled = ecosystems.filter(entry => Number(entry.corporation_id) === corporationId);
330
+ const reconciled = new Set();
331
+ for (const ecosystem of controlled) {
264
332
  for (const schema of await indexer.listCredentialSchemas(ecosystem.id)) {
265
333
  const [didRecord] = await agent.dids.getCreatedDids({ did: agent.did });
266
334
  if (!didRecord)
267
335
  return;
268
336
  const schemaRef = `vpr:verana:${chainId}:cs:${schema.id}`;
337
+ reconciled.add(schemaRef);
269
338
  const expectedDigest = (0, setupSelfTr_1.generateDigestSRI)(schema.json_schema);
270
339
  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), {
340
+ 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;
341
+ let jsonSchemaCredentialId = (_d = existingJsc === null || existingJsc === void 0 ? void 0 : existingJsc.credential) === null || _d === void 0 ? void 0 : _d.id;
342
+ try {
343
+ // a VTJSC an older agent published as data model 1.1 is rebuilt as well
344
+ if (!existingJsc ||
345
+ existingDigest !== expectedDigest ||
346
+ !(0, vcdm2_1.isDataIntegrityVcdm2Credential)(existingJsc.credential)) {
347
+ const credential = await (0, trustCredentialStore_1.createJsc)(agent, agent.publicApiBaseUrl, (0, data_1.getEcsSchemas)(agent.publicApiBaseUrl), {
275
348
  schemaBaseId: String(schema.id),
276
349
  jsonSchemaRef: schemaRef,
277
350
  precomputedDigestSRI: expectedDigest,
278
351
  });
352
+ jsonSchemaCredentialId = credential.id;
279
353
  agent.config.logger.info(`[VTJSC] Reconciled VTJSC for schema ${schema.id} (ecosystem ${ecosystem.id})`);
280
354
  }
281
- catch (e) {
282
- agent.config.logger.error(`[VTJSC] Failed to reconcile VTJSC for schema ${schema.id}`, e);
283
- continue;
355
+ else if (await (0, trustCredentialStore_1.reattachVtjscPublication)(agent, schemaRef)) {
356
+ agent.config.logger.info(`[VTJSC] Re-attached the VTJSC of schema ${schema.id} (ecosystem ${ecosystem.id})`);
284
357
  }
285
358
  }
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);
359
+ catch (e) {
360
+ agent.config.logger.error(`[VTJSC] Failed to reconcile VTJSC for schema ${schema.id}`, e);
361
+ }
362
+ // an agent that published a VTJSC before [VSA-PUB-AC-5] has no AnonCreds schema for it yet
363
+ if (!jsonSchemaCredentialId)
364
+ continue;
365
+ try {
366
+ await publishAnonCredsSchemaForVtjsc(agent, schema.id, schema.json_schema, jsonSchemaCredentialId);
367
+ }
368
+ catch (e) {
369
+ agent.config.logger.error(`[VTJSC] Failed to reconcile the AnonCreds schema of ${jsonSchemaCredentialId}`, e);
370
+ }
371
+ }
372
+ }
373
+ await detachUncontrolledVtjscPublications(agent, indexer, corporationId, chainId, reconciled);
374
+ if (ecsClaims)
375
+ await reconcileSelfIssuedEcsCredentials(agent, indexer, ecsClaims);
376
+ }
377
+ /** The `_vt/jsc` key that `createJsc` writes for an on-chain `CredentialSchema`. */
378
+ const onChainSchemaRefPrefix = (chainId) => `vpr:verana:${chainId}:cs:`;
379
+ /**
380
+ * VSA-VTI-VTJSC: only the controller of an Ecosystem advertises a VTJSC for its schemas. Archival
381
+ * is not a loss of control — the agent keeps it, and [VSA-VTI-NOTIF-ES] gives it no handler.
382
+ *
383
+ * Each entry is resolved against the VPR one by one rather than diffed against `listEcosystems`:
384
+ * that endpoint is unpaginated here, and a truncated page reads like a loss of control.
385
+ */
386
+ async function detachUncontrolledVtjscPublications(agent, indexer, corporationId, chainId, reconciled) {
387
+ const [didRecord] = await agent.dids.getCreatedDids({ did: agent.did });
388
+ if (!didRecord)
389
+ return;
390
+ const metadata = didRecord.metadata.get('_vt/jsc');
391
+ if (!metadata)
392
+ return;
393
+ const prefix = onChainSchemaRefPrefix(chainId);
394
+ const ecosystemCache = new Map();
395
+ const stale = [];
396
+ for (const schemaRef of Object.keys(metadata)) {
397
+ // the agent's own schema credentials live in this bucket, keyed by public URL.
398
+ if (!schemaRef.startsWith(prefix))
399
+ continue;
400
+ if (reconciled.has(schemaRef))
401
+ continue;
402
+ const schemaId = schemaRef.slice(prefix.length);
403
+ try {
404
+ const schema = await indexer.getCredentialSchema(schemaId);
405
+ const ecosystemId = String(schema.ecosystem_id);
406
+ if (!ecosystemCache.has(ecosystemId)) {
407
+ ecosystemCache.set(ecosystemId, await indexer.getEcosystem(ecosystemId));
408
+ }
409
+ const ecosystem = ecosystemCache.get(ecosystemId);
410
+ if (!ecosystem)
411
+ continue;
412
+ if (Number(ecosystem.corporation_id) === corporationId)
413
+ continue;
414
+ agent.config.logger.info(`[VTJSC] Detaching the VTJSC of schema ${schemaId}: ecosystem ${ecosystemId} belongs to ` +
415
+ `corporation ${ecosystem.corporation_id}`);
416
+ stale.push(schemaRef);
417
+ }
418
+ catch (error) {
419
+ // A lookup the VPR cannot answer is not evidence of anything; leave the entry advertised.
420
+ agent.config.logger.debug(`[VTJSC] Keeping the VTJSC of schema ${schemaId}: ${error.message}`);
421
+ }
422
+ }
423
+ if (stale.length === 0)
424
+ return;
425
+ const detached = await (0, trustCredentialStore_1.detachVtjscPublications)(agent, stale);
426
+ if (detached.length > 0) {
427
+ agent.config.logger.info(`[VTJSC] Detached ${detached.length} VTJSC publication(s)`);
428
+ }
429
+ }
430
+ /**
431
+ * Rebinds and anchors this agent's own ECS credentials.
432
+ *
433
+ * It follows the ISSUER Participant entries the agent holds, not the Ecosystems its Corporation
434
+ * controls: an agent may issue against an Ecosystem that another Corporation owns, and an
435
+ * Ecosystem controller may hold no ISSUER entry at all. An entry is usable only when it names
436
+ * this agent's account as its vs_operator, because the chain accepts the anchoring
437
+ * CreateOrUpdateParticipantSession from no other signer.
438
+ *
439
+ * Every ECS schema qualifies, not only the Service one. The chain of Organization credentials has
440
+ * to terminate: the service holding the ISSUER entry is the only party that can issue against that
441
+ * schema, so it issues its own. Without it that service has no serviceProvider and fails VS-CONN-VS.
442
+ */
443
+ async function reconcileSelfIssuedEcsCredentials(agent, indexer, ecsClaims) {
444
+ const chain = agent.veranaChain;
445
+ if (!chain || !agent.did || !agent.publicApiBaseUrl)
446
+ return;
447
+ const chainId = chain.getChainId;
448
+ // A Participant revoked while the agent was down delivers no event it can still act on. Runs
449
+ // first, so a schema whose ISSUER entry was replaced ends up bound to the new one.
450
+ for (const participantState of [types_2.ParticipantState.Revoked, types_2.ParticipantState.Slashed]) {
451
+ try {
452
+ const stale = await indexer.listParticipants({
453
+ did: agent.did,
454
+ role: types_2.ParticipantRole.Issuer,
455
+ participantState,
456
+ });
457
+ for (const issuer of stale) {
458
+ const withdrawn = await (0, trustCredentialStore_1.withdrawSelfIssuedEcsCredentials)(agent, issuer.id);
459
+ for (const jscUrl of withdrawn) {
460
+ agent.config.logger.info(`[SelfTR] Withdrew the self-issued ECS credential bound to ${jscUrl} (${participantState} issuer participant ${issuer.id})`);
295
461
  }
296
462
  }
297
463
  }
464
+ catch (e) {
465
+ agent.config.logger.error(`[SelfTR] Failed to withdraw the ECS credentials of ${participantState} ISSUER participants`, e);
466
+ }
467
+ }
468
+ const issuers = await indexer.listParticipants({
469
+ did: agent.did,
470
+ role: types_2.ParticipantRole.Issuer,
471
+ participantState: types_2.ParticipantState.Active,
472
+ });
473
+ for (const issuer of issuers) {
474
+ if (issuer.revoked || issuer.slashed || issuer.vs_operator !== chain.address)
475
+ continue;
476
+ try {
477
+ const schema = await indexer.getCredentialSchema(issuer.schema_id);
478
+ const ecsKey = await (0, vs_agent_model_1.classifyEcsSchema)(schema.json_schema);
479
+ if (!ecsKey)
480
+ continue;
481
+ const jsonSchemaCredentialId = await (0, vtjscResolver_1.resolveJsonSchemaCredentialId)(agent, indexer, schema.id, chainId);
482
+ await (0, trustCredentialStore_1.rebindEcsCredentialSchema)(agent, agent.publicApiBaseUrl, String(schema.id), ecsKey, ecsClaims, jsonSchemaCredentialId, issuer.id, schema.json_schema);
483
+ }
484
+ catch (e) {
485
+ agent.config.logger.error(`[SelfTR] Failed to rebind the ECS credential of schema ${issuer.schema_id}`, e);
486
+ }
487
+ }
488
+ }
489
+ /**
490
+ * Publishes the one AnonCreds schema that governs every credential of a VTJSC, per [VSA-PUB-AC-5].
491
+ * Only the issuer of the VTJSC publishes it. The call is idempotent.
492
+ */
493
+ async function publishAnonCredsSchemaForVtjsc(agent, credentialSchemaId, jsonSchema, jsonSchemaCredentialId) {
494
+ if (!agent.did)
495
+ return undefined;
496
+ const [published] = await agent.modules.anoncreds.getCreatedSchemas({
497
+ relatedJsonSchemaCredentialId: jsonSchemaCredentialId,
498
+ });
499
+ if (published)
500
+ return published.schemaId;
501
+ const { name, attrNames } = (0, util_1.anonCredsSchemaFromJsonSchema)(jsonSchema);
502
+ // used for consistency when a similar schema already exists
503
+ const version = String(credentialSchemaId);
504
+ const { schemaState, registrationMetadata } = await agent.modules.anoncreds.registerSchema({
505
+ schema: { attrNames, name, version, issuerId: agent.did },
506
+ options: { extraMetadata: { relatedJsonSchemaCredentialId: jsonSchemaCredentialId } },
507
+ });
508
+ if (schemaState.state !== 'finished') {
509
+ const detail = schemaState.state === 'failed' ? schemaState.reason : schemaState.state;
510
+ throw new Error(`Failed to register the AnonCreds schema of ${jsonSchemaCredentialId}: ${detail}`);
298
511
  }
512
+ const { schemaId } = schemaState;
513
+ const schemaRepository = agent.dependencyManager.resolve(anoncreds_1.AnonCredsSchemaRepository);
514
+ const schemaRecord = await schemaRepository.findBySchemaId(agent.context, schemaId);
515
+ if (schemaRecord) {
516
+ schemaRecord.setTag('relatedJsonSchemaCredentialId', jsonSchemaCredentialId);
517
+ await schemaRepository.update(agent.context, schemaRecord);
518
+ }
519
+ // the did:web layout builds no attested resource: it serves the object from the AnonCreds record
520
+ const { attestedResource } = registrationMetadata;
521
+ if (attestedResource) {
522
+ await (0, agent_1.saveAttestedResource)(agent, attestedResource, {
523
+ resourceType: 'anonCredsSchema',
524
+ relatedJsonSchemaCredentialId: jsonSchemaCredentialId,
525
+ });
526
+ }
527
+ return schemaId;
299
528
  }
300
529
  async function publishVtjscIfOwner(state, agent, schemaEntityId, agentCorporationId) {
301
- var _a, _b;
530
+ var _a;
302
531
  const schema = state.credentialSchemas[schemaEntityId];
303
532
  if (!schema) {
304
533
  agent.config.logger.warn(`[VTJSC] Schema ${schemaEntityId} not found in state`);
@@ -313,19 +542,36 @@ async function publishVtjscIfOwner(state, agent, schemaEntityId, agentCorporatio
313
542
  agent.config.logger.debug(`[VTJSC] Skipping schema ${schema.id}: ecosystem ${ecosystem.id} belongs to corporation ${ecosystem.corporationId}`);
314
543
  return;
315
544
  }
316
- const chainId = (_b = (_a = agent.veranaChain) === null || _a === void 0 ? void 0 : _a.getChainId) !== null && _b !== void 0 ? _b : DEFAULT_CHAIN_ID;
545
+ const chainId = (_a = agent.veranaChain) === null || _a === void 0 ? void 0 : _a.getChainId;
546
+ if (!chainId) {
547
+ agent.config.logger.warn(`[VTJSC] Skipping schema ${schema.id}: the agent is not connected to a chain`);
548
+ return;
549
+ }
317
550
  const jsonSchemaRef = `vpr:verana:${chainId}:cs:${schema.id}`;
318
551
  const digestSRI = (0, setupSelfTr_1.generateDigestSRI)(schema.jsonSchema);
552
+ let jsonSchemaCredentialId;
319
553
  try {
320
- await (0, trustCredentialStore_1.createJsc)(agent, agent.publicApiBaseUrl, (0, data_1.getEcsSchemas)(agent.publicApiBaseUrl), {
554
+ const credential = await (0, trustCredentialStore_1.createJsc)(agent, agent.publicApiBaseUrl, (0, data_1.getEcsSchemas)(agent.publicApiBaseUrl), {
321
555
  schemaBaseId: String(schema.id),
322
556
  jsonSchemaRef,
323
557
  precomputedDigestSRI: digestSRI,
324
558
  });
559
+ jsonSchemaCredentialId = credential.id;
325
560
  agent.config.logger.info(`[VTJSC] Published VTJSC for schema ${schema.id} (Ecosystem ${schema.ecosystemId}) at block ${state.lastBlockHeight}`);
326
561
  }
327
562
  catch (e) {
328
563
  agent.config.logger.error(`[VTJSC] Failed to publish VTJSC for schema ${schema.id}`, e);
564
+ return;
565
+ }
566
+ // an AnonCreds failure keeps the VTJSC: the startup reconciliation retries the schema
567
+ if (!jsonSchemaCredentialId)
568
+ return;
569
+ try {
570
+ const schemaId = await publishAnonCredsSchemaForVtjsc(agent, schema.id, schema.jsonSchema, jsonSchemaCredentialId);
571
+ agent.config.logger.info(`[VTJSC] Published the AnonCreds schema ${schemaId} of ${jsonSchemaCredentialId}`);
572
+ }
573
+ catch (e) {
574
+ agent.config.logger.error(`[VTJSC] Failed to publish the AnonCreds schema of ${jsonSchemaCredentialId}`, e);
329
575
  }
330
576
  }
331
577
  //# sourceMappingURL=stateMutations.js.map