@verana-labs/vs-agent-sdk 2.0.0-dev.12 → 2.0.0-dev.120

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 (205) hide show
  1. package/README.md +0 -2
  2. package/build/adminApi/AdminApiError.d.ts +28 -0
  3. package/build/adminApi/AdminApiError.js +67 -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 +4 -0
  9. package/build/adminApi/index.js +21 -0
  10. package/build/adminApi/index.js.map +1 -0
  11. package/build/adminApi/moduleEndpoint.d.ts +7 -0
  12. package/build/adminApi/moduleEndpoint.js +21 -0
  13. package/build/adminApi/moduleEndpoint.js.map +1 -0
  14. package/build/adminApi/pagination/PageDto.d.ts +7 -0
  15. package/build/adminApi/pagination/PageDto.js +50 -0
  16. package/build/adminApi/pagination/PageDto.js.map +1 -0
  17. package/build/adminApi/pagination/PaginationQueryDto.d.ts +11 -0
  18. package/build/adminApi/pagination/PaginationQueryDto.js +46 -0
  19. package/build/adminApi/pagination/PaginationQueryDto.js.map +1 -0
  20. package/build/adminApi/pagination/cursor.d.ts +28 -0
  21. package/build/adminApi/pagination/cursor.js +64 -0
  22. package/build/adminApi/pagination/cursor.js.map +1 -0
  23. package/build/adminApi/pagination/index.d.ts +4 -0
  24. package/build/adminApi/pagination/index.js +21 -0
  25. package/build/adminApi/pagination/index.js.map +1 -0
  26. package/build/adminApi/pagination/paginate.d.ts +27 -0
  27. package/build/adminApi/pagination/paginate.js +77 -0
  28. package/build/adminApi/pagination/paginate.js.map +1 -0
  29. package/build/agent/VsAgent.d.ts +32 -36
  30. package/build/agent/VsAgent.js +179 -221
  31. package/build/agent/VsAgent.js.map +1 -1
  32. package/build/agent/createVsAgent.d.ts +9 -6
  33. package/build/agent/createVsAgent.js +5 -5
  34. package/build/agent/createVsAgent.js.map +1 -1
  35. package/build/blockchain/AnonCredsTrustService.d.ts +115 -0
  36. package/build/blockchain/AnonCredsTrustService.js +287 -0
  37. package/build/blockchain/AnonCredsTrustService.js.map +1 -0
  38. package/build/blockchain/AuthorizationService.d.ts +8 -6
  39. package/build/blockchain/AuthorizationService.js +30 -38
  40. package/build/blockchain/AuthorizationService.js.map +1 -1
  41. package/build/blockchain/IndexerWebSocketService.d.ts +5 -1
  42. package/build/blockchain/IndexerWebSocketService.js +42 -21
  43. package/build/blockchain/IndexerWebSocketService.js.map +1 -1
  44. package/build/blockchain/VeranaChainService.d.ts +38 -27
  45. package/build/blockchain/VeranaChainService.js +186 -177
  46. package/build/blockchain/VeranaChainService.js.map +1 -1
  47. package/build/blockchain/VeranaIndexerService.d.ts +14 -1
  48. package/build/blockchain/VeranaIndexerService.js +122 -8
  49. package/build/blockchain/VeranaIndexerService.js.map +1 -1
  50. package/build/blockchain/feePreflight.d.ts +34 -0
  51. package/build/blockchain/feePreflight.js +96 -0
  52. package/build/blockchain/feePreflight.js.map +1 -0
  53. package/build/blockchain/handlers/IndexerHandlerRegistry.d.ts +0 -1
  54. package/build/blockchain/handlers/IndexerHandlerRegistry.js.map +1 -1
  55. package/build/blockchain/handlers/authorizationHandlers.js +2 -2
  56. package/build/blockchain/handlers/authorizationHandlers.js.map +1 -1
  57. package/build/blockchain/handlers/defaultHandlers.js +7 -2
  58. package/build/blockchain/handlers/defaultHandlers.js.map +1 -1
  59. package/build/blockchain/handlers/index.d.ts +1 -0
  60. package/build/blockchain/handlers/index.js +1 -0
  61. package/build/blockchain/handlers/index.js.map +1 -1
  62. package/build/blockchain/handlers/selfIssuanceHandlers.d.ts +13 -0
  63. package/build/blockchain/handlers/selfIssuanceHandlers.js +76 -0
  64. package/build/blockchain/handlers/selfIssuanceHandlers.js.map +1 -0
  65. package/build/blockchain/handlers/stateMutations.d.ts +28 -4
  66. package/build/blockchain/handlers/stateMutations.js +356 -48
  67. package/build/blockchain/handlers/stateMutations.js.map +1 -1
  68. package/build/blockchain/index.d.ts +4 -0
  69. package/build/blockchain/index.js +4 -0
  70. package/build/blockchain/index.js.map +1 -1
  71. package/build/blockchain/indexerMappers.d.ts +3 -0
  72. package/build/blockchain/indexerMappers.js +57 -0
  73. package/build/blockchain/indexerMappers.js.map +1 -0
  74. package/build/blockchain/rpcRetry.d.ts +2 -0
  75. package/build/blockchain/rpcRetry.js +43 -0
  76. package/build/blockchain/rpcRetry.js.map +1 -0
  77. package/build/blockchain/triggerResolver.d.ts +26 -0
  78. package/build/blockchain/triggerResolver.js +110 -0
  79. package/build/blockchain/triggerResolver.js.map +1 -0
  80. package/build/blockchain/types.d.ts +14 -70
  81. package/build/blockchain/types.js +6 -1
  82. package/build/blockchain/types.js.map +1 -1
  83. package/build/bootstrap/EcsBootstrapService.d.ts +13 -4
  84. package/build/bootstrap/EcsBootstrapService.js +176 -124
  85. package/build/bootstrap/EcsBootstrapService.js.map +1 -1
  86. package/build/connections/InvitationRecord.d.ts +50 -0
  87. package/build/connections/InvitationRecord.js +60 -0
  88. package/build/connections/InvitationRecord.js.map +1 -0
  89. package/build/connections/ParentConnectionModule.d.ts +22 -0
  90. package/build/connections/ParentConnectionModule.js +91 -0
  91. package/build/connections/ParentConnectionModule.js.map +1 -0
  92. package/build/credentials/FullTailsFileService.d.ts +0 -1
  93. package/build/credentials/FullTailsFileService.js +0 -49
  94. package/build/credentials/FullTailsFileService.js.map +1 -1
  95. package/build/did/CachedDocumentLoader.d.ts +3 -0
  96. package/build/did/CachedDocumentLoader.js +9 -3
  97. package/build/did/CachedDocumentLoader.js.map +1 -1
  98. package/build/did/CachedWebDidResolver.d.ts +0 -4
  99. package/build/did/CachedWebDidResolver.js +1 -5
  100. package/build/did/CachedWebDidResolver.js.map +1 -1
  101. package/build/did/artifactServices.d.ts +12 -0
  102. package/build/did/artifactServices.js +48 -0
  103. package/build/did/artifactServices.js.map +1 -0
  104. package/build/did/legacyDidWeb.d.ts +6 -4
  105. package/build/did/legacyDidWeb.js +17 -14
  106. package/build/did/legacyDidWeb.js.map +1 -1
  107. package/build/did/publicDid.d.ts +4 -0
  108. package/build/did/publicDid.js +19 -0
  109. package/build/did/publicDid.js.map +1 -0
  110. package/build/did/reusedDidDocument.d.ts +37 -0
  111. package/build/did/reusedDidDocument.js +93 -0
  112. package/build/did/reusedDidDocument.js.map +1 -0
  113. package/build/events/BaseMessageEvents.d.ts +24 -0
  114. package/build/events/BaseMessageEvents.js +368 -14
  115. package/build/events/BaseMessageEvents.js.map +1 -1
  116. package/build/events/ConnectionEvents.js +149 -87
  117. package/build/events/ConnectionEvents.js.map +1 -1
  118. package/build/events/InvitationEvents.d.ts +6 -0
  119. package/build/events/InvitationEvents.js +57 -0
  120. package/build/events/InvitationEvents.js.map +1 -0
  121. package/build/events/VsAgentEvents.d.ts +40 -9
  122. package/build/events/VsAgentEvents.js +10 -1
  123. package/build/events/VsAgentEvents.js.map +1 -1
  124. package/build/events/VtFlowEvents.d.ts +1 -1
  125. package/build/events/VtFlowEvents.js +29 -17
  126. package/build/events/VtFlowEvents.js.map +1 -1
  127. package/build/events/index.d.ts +1 -0
  128. package/build/events/index.js +1 -0
  129. package/build/events/index.js.map +1 -1
  130. package/build/index.d.ts +9 -1
  131. package/build/index.js +20 -2
  132. package/build/index.js.map +1 -1
  133. package/build/plugins/setupBaseDidComm.js +24 -22
  134. package/build/plugins/setupBaseDidComm.js.map +1 -1
  135. package/build/transports/HttpInboundTransport.js +6 -1
  136. package/build/transports/HttpInboundTransport.js.map +1 -1
  137. package/build/transports/VsAgentWsInboundTransport.d.ts +1 -1
  138. package/build/transports/VsAgentWsInboundTransport.js +20 -14
  139. package/build/transports/VsAgentWsInboundTransport.js.map +1 -1
  140. package/build/types.d.ts +14 -13
  141. package/build/types.js +1 -2
  142. package/build/types.js.map +1 -1
  143. package/build/utils/agent.d.ts +42 -4
  144. package/build/utils/agent.js +126 -22
  145. package/build/utils/agent.js.map +1 -1
  146. package/build/utils/boundedFetch.d.ts +13 -0
  147. package/build/utils/boundedFetch.js +47 -0
  148. package/build/utils/boundedFetch.js.map +1 -0
  149. package/build/utils/didReadiness.js +5 -2
  150. package/build/utils/didReadiness.js.map +1 -1
  151. package/build/utils/ecsClaims.d.ts +46 -0
  152. package/build/utils/ecsClaims.js +115 -0
  153. package/build/utils/ecsClaims.js.map +1 -0
  154. package/build/utils/ecsService.d.ts +8 -0
  155. package/build/utils/ecsService.js +23 -0
  156. package/build/utils/ecsService.js.map +1 -0
  157. package/build/utils/index.d.ts +7 -0
  158. package/build/utils/index.js +7 -0
  159. package/build/utils/index.js.map +1 -1
  160. package/build/utils/publishedDidRecord.d.ts +15 -0
  161. package/build/utils/publishedDidRecord.js +83 -0
  162. package/build/utils/publishedDidRecord.js.map +1 -0
  163. package/build/utils/selfIssuedEcsCredential.d.ts +8 -0
  164. package/build/utils/selfIssuedEcsCredential.js +158 -0
  165. package/build/utils/selfIssuedEcsCredential.js.map +1 -0
  166. package/build/utils/setupSelfTr.d.ts +34 -74
  167. package/build/utils/setupSelfTr.js +79 -321
  168. package/build/utils/setupSelfTr.js.map +1 -1
  169. package/build/utils/trustCredentialStore.d.ts +86 -9
  170. package/build/utils/trustCredentialStore.js +342 -137
  171. package/build/utils/trustCredentialStore.js.map +1 -1
  172. package/build/utils/typeMetadata.d.ts +44 -0
  173. package/build/utils/typeMetadata.js +89 -0
  174. package/build/utils/typeMetadata.js.map +1 -0
  175. package/build/utils/util.d.ts +20 -0
  176. package/build/utils/util.js +32 -1
  177. package/build/utils/util.js.map +1 -1
  178. package/build/utils/vcdm2.d.ts +34 -0
  179. package/build/utils/vcdm2.js +60 -0
  180. package/build/utils/vcdm2.js.map +1 -0
  181. package/build/utils/vtjscResolver.d.ts +23 -0
  182. package/build/utils/vtjscResolver.js +53 -0
  183. package/build/utils/vtjscResolver.js.map +1 -0
  184. package/build/vtFlow/VtFlowOrchestrator.d.ts +134 -16
  185. package/build/vtFlow/VtFlowOrchestrator.js +965 -138
  186. package/build/vtFlow/VtFlowOrchestrator.js.map +1 -1
  187. package/build/vtFlow/assertVerifiableService.d.ts +31 -2
  188. package/build/vtFlow/assertVerifiableService.js +68 -10
  189. package/build/vtFlow/assertVerifiableService.js.map +1 -1
  190. package/build/vtFlow/ecsIssuanceExemption.d.ts +12 -0
  191. package/build/vtFlow/ecsIssuanceExemption.js +63 -0
  192. package/build/vtFlow/ecsIssuanceExemption.js.map +1 -0
  193. package/build/vtFlow/index.d.ts +2 -0
  194. package/build/vtFlow/index.js +2 -0
  195. package/build/vtFlow/index.js.map +1 -1
  196. package/build/vtFlow/issuanceRepair.d.ts +4 -0
  197. package/build/vtFlow/issuanceRepair.js +181 -0
  198. package/build/vtFlow/issuanceRepair.js.map +1 -0
  199. package/package.json +27 -19
  200. package/build/did/migrateWebVhLog.d.ts +0 -34
  201. package/build/did/migrateWebVhLog.js +0 -230
  202. package/build/did/migrateWebVhLog.js.map +0 -1
  203. package/build/did/migrateWebVhVersionTime.d.ts +0 -9
  204. package/build/did/migrateWebVhVersionTime.js +0 -191
  205. package/build/did/migrateWebVhVersionTime.js.map +0 -1
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateDidRecord = updateDidRecord;
4
+ exports.publicationFingerprint = publicationFingerprint;
5
+ const core_1 = require("@credo-ts/core");
6
+ const triggerResolver_1 = require("../blockchain/triggerResolver");
7
+ const adminApiService_1 = require("../did/adminApiService");
8
+ /**
9
+ * The one write point of the published Verifiable Trust material: the `_vt/vtc` and `_vt/jsc`
10
+ * metadata of the DID record and the DID Document that announces them. [VSA-VT-LVP-5] asks for a
11
+ * `TriggerResolver` after each change of a `LinkedVerifiablePresentation` entry, so the decision
12
+ * lives here rather than in each caller: the stored record is compared with the one written. The DID
13
+ * Document is published only when it changed, so a metadata-only write adds no `did:webvh` version.
14
+ */
15
+ async function updateDidRecord(agent, didRecord) {
16
+ const repo = agent.context.dependencyManager.resolve(core_1.DidRepository);
17
+ (0, adminApiService_1.applyAdminApiServiceEntry)(didRecord.didDocument, agent.adminApiServiceEndpoint);
18
+ const stored = await storedRecord(agent, repo, didRecord.id);
19
+ const publishedBefore = publicationFingerprint(stored);
20
+ const documentBefore = documentFingerprint(stored);
21
+ await repo.update(agent.context, didRecord);
22
+ if (documentFingerprint(didRecord) !== documentBefore) {
23
+ await agent.dids.update({ did: didRecord.did, didDocument: didRecord.didDocument });
24
+ }
25
+ if (publicationFingerprint(didRecord) !== publishedBefore) {
26
+ (0, triggerResolver_1.scheduleTriggerResolverForOwnDid)(agent, 'the published Verifiable Trust material changed');
27
+ }
28
+ }
29
+ async function storedRecord(agent, repo, id) {
30
+ try {
31
+ return await repo.findById(agent.context, id);
32
+ }
33
+ catch (error) {
34
+ agent.config.logger.debug(`[trust-credential] cannot read the stored DID record: ${error.message}`);
35
+ return null;
36
+ }
37
+ }
38
+ function stableStringify(value) {
39
+ var _a;
40
+ if (Array.isArray(value))
41
+ return `[${value.map(stableStringify).join(',')}]`;
42
+ if (value && typeof value === 'object') {
43
+ const entries = Object.entries(value)
44
+ .filter(([, v]) => v !== undefined)
45
+ .sort(([a], [b]) => a.localeCompare(b));
46
+ return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${stableStringify(v)}`).join(',')}}`;
47
+ }
48
+ return (_a = JSON.stringify(value)) !== null && _a !== void 0 ? _a : 'null';
49
+ }
50
+ // a document saved as a class instance reads back from storage as JSON, so both go through JSON
51
+ function asJson(value) {
52
+ return value === undefined ? undefined : JSON.parse(JSON.stringify(value));
53
+ }
54
+ /** What the agent serves as its DID Document. Two records with the same fingerprint serve the same. */
55
+ function documentFingerprint(didRecord) {
56
+ if (!(didRecord === null || didRecord === void 0 ? void 0 : didRecord.didDocument))
57
+ return '';
58
+ return stableStringify(asJson(didRecord.didDocument));
59
+ }
60
+ /**
61
+ * What a trust resolver reads of the agent: its `LinkedVerifiablePresentation` entries, and the
62
+ * presentations behind them. Two records with the same fingerprint resolve the same way.
63
+ */
64
+ function publicationFingerprint(didRecord) {
65
+ var _a, _b;
66
+ if (!didRecord)
67
+ return '';
68
+ const services = ((_b = (_a = didRecord.didDocument) === null || _a === void 0 ? void 0 : _a.service) !== null && _b !== void 0 ? _b : [])
69
+ .filter(service => service.type === 'LinkedVerifiablePresentation')
70
+ .map(service => ({ id: service.id, serviceEndpoint: service.serviceEndpoint }))
71
+ .sort((a, b) => a.id.localeCompare(b.id));
72
+ const presentations = ['_vt/vtc', '_vt/jsc'].map(key => {
73
+ var _a;
74
+ return Object.entries((_a = didRecord.metadata.get(key)) !== null && _a !== void 0 ? _a : {})
75
+ .map(([schemaId, entry]) => ({
76
+ schemaId,
77
+ presentation: entry.verifiablePresentation,
78
+ }))
79
+ .sort((a, b) => a.schemaId.localeCompare(b.schemaId));
80
+ });
81
+ return stableStringify(asJson({ services, presentations }));
82
+ }
83
+ //# sourceMappingURL=publishedDidRecord.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publishedDidRecord.js","sourceRoot":"","sources":["../../src/utils/publishedDidRecord.ts"],"names":[],"mappings":";;AAaA,0CAcC;AAuCD,wDAeC;AAjFD,yCAAyD;AAGzD,mEAAgF;AAChF,4DAAkE;AAElE;;;;;;GAMG;AACI,KAAK,UAAU,eAAe,CAAC,KAAc,EAAE,SAAoB;IACxE,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,oBAAa,CAAC,CAAA;IACnE,IAAA,2CAAyB,EAAC,SAAS,CAAC,WAAY,EAAE,KAAK,CAAC,uBAAuB,CAAC,CAAA;IAChF,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,CAAC,CAAA;IAC5D,MAAM,eAAe,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAA;IACtD,MAAM,cAAc,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAA;IAElD,MAAM,IAAI,CAAC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CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC3C,MAAM,aAAa,GAAI,CAAC,SAAS,EAAE,SAAS,CAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;;QAChE,OAAA,MAAM,CAAC,OAAO,CAAC,MAAA,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,mCAAI,EAAE,CAAC;aAC9C,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YAC3B,QAAQ;YACR,YAAY,EAAG,KAA8C,CAAC,sBAAsB;SACrF,CAAC,CAAC;aACF,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAA;KAAA,CACxD,CAAA;IACD,OAAO,eAAe,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC,CAAC,CAAA;AAC7D,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { W3cCredentialSchema } from '@credo-ts/core';
2
+ import { VsAgent } from '../agent/VsAgent';
3
+ import { EcsClaims } from './ecsClaims';
4
+ /** The linked presentation as published: VC Data Model 2.0 JSON secured with Data Integrity proofs */
5
+ export type SelfIssuedEcsPresentation = Record<string, unknown> & {
6
+ verifiableCredential: Record<string, unknown>[];
7
+ };
8
+ export declare function publishSelfIssuedEcsPresentation(agent: VsAgent, id: string, ecsSchemas: Record<string, string>, schemaKey: string, schemaId: string, type: string[], credentialSchema: W3cCredentialSchema, ecsClaims: EcsClaims, beforePublish?: (verifiablePresentation: SelfIssuedEcsPresentation) => Promise<void>, validUntil?: string): Promise<SelfIssuedEcsPresentation>;
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.publishSelfIssuedEcsPresentation = publishSelfIssuedEcsPresentation;
4
+ const core_1 = require("@credo-ts/core");
5
+ const vs_agent_model_1 = require("@verana-labs/vs-agent-model");
6
+ const setupSelfTr_1 = require("./setupSelfTr");
7
+ const publishedDidRecord_1 = require("./publishedDidRecord");
8
+ const vcdm2_1 = require("./vcdm2");
9
+ const buildIntegrityData = (data) => {
10
+ return (0, setupSelfTr_1.generateDigestSRI)(JSON.stringify((0, setupSelfTr_1.sortKeysDeep)(data)));
11
+ };
12
+ function storedCredentialIsCurrent(credential, credentialId, credentialSchemaId, did, didRecord, validUntil) {
13
+ var _a, _b, _c;
14
+ if (!credential)
15
+ return false;
16
+ // a credential published by an older agent as data model 1.1 is rebuilt on upgrade
17
+ if (!(0, vcdm2_1.isDataIntegrityVcdm2Credential)(credential))
18
+ return false;
19
+ const issuer = typeof credential.issuer === 'string' ? credential.issuer : (_a = credential.issuer) === null || _a === void 0 ? void 0 : _a.id;
20
+ if (issuer !== did)
21
+ return false;
22
+ if (credential.id !== credentialId)
23
+ return false;
24
+ const schema = Array.isArray(credential.credentialSchema)
25
+ ? credential.credentialSchema[0]
26
+ : credential.credentialSchema;
27
+ if ((schema === null || schema === void 0 ? void 0 : schema.id) !== credentialSchemaId)
28
+ return false;
29
+ if (credential.validUntil !== validUntil)
30
+ return false;
31
+ const proofs = !credential.proof
32
+ ? []
33
+ : Array.isArray(credential.proof)
34
+ ? credential.proof
35
+ : [credential.proof];
36
+ if (proofs.length === 0)
37
+ return false;
38
+ const assertionMethods = new Set(((_c = (_b = didRecord.didDocument) === null || _b === void 0 ? void 0 : _b.assertionMethod) !== null && _c !== void 0 ? _c : []).map(entry => typeof entry === 'string' ? entry : entry.id));
39
+ return proofs.every(proof => !!proof.verificationMethod && assertionMethods.has(proof.verificationMethod));
40
+ }
41
+ /**
42
+ * Issues the ECS credential to the agent itself and wraps it in the linked presentation, both
43
+ * secured with a DataIntegrityProof by the DID Document assertion key.
44
+ */
45
+ async function signSelfIssuedEcsCredential(agent, didRecord, presentationId, credentialId, type, claims, credentialSchema, validUntil) {
46
+ const unsignedCredential = (0, vcdm2_1.createW3cV2Credential)({
47
+ id: credentialId,
48
+ type,
49
+ issuer: agent.did,
50
+ credentialSubject: Object.assign(Object.assign({}, claims), { id: agent.did }),
51
+ credentialSchema: { id: credentialSchema.id, type: credentialSchema.type },
52
+ validUntil,
53
+ });
54
+ const verificationMethodId = (0, setupSelfTr_1.getVerificationMethodId)(agent.config.logger, didRecord);
55
+ const signedCredential = await (0, setupSelfTr_1.signerW3c)(agent, unsignedCredential, verificationMethodId);
56
+ const presentation = (0, setupSelfTr_1.createPresentation)({
57
+ id: presentationId,
58
+ holder: agent.did,
59
+ verifiableCredential: [signedCredential],
60
+ });
61
+ const signedPresentation = await (0, setupSelfTr_1.signerW3c)(agent, presentation, verificationMethodId);
62
+ return signedPresentation.securedPresentation;
63
+ }
64
+ async function publishSelfIssuedEcsPresentation(agent, id, ecsSchemas, schemaKey, schemaId, type, credentialSchema, ecsClaims, beforePublish, validUntil) {
65
+ var _a, _b, _c, _d, _e, _f, _g;
66
+ if (!agent.did)
67
+ throw Error('The DID must be set up');
68
+ const [didRecord] = await agent.dids.getCreatedDids({ did: agent.did });
69
+ const didDocument = didRecord.didDocument;
70
+ if (!didDocument)
71
+ throw Error('The DID Document must be set up');
72
+ const claims = await (0, setupSelfTr_1.getClaims)(agent.config.logger, ecsSchemas, { id: agent.did }, schemaKey, ecsClaims);
73
+ if (!validUntil && (0, vs_agent_model_1.schemaRequiresValidUntil)(ecsSchemas[schemaKey])) {
74
+ throw new Error(`Not issuing the ${schemaKey} credential: its schema requires validUntil and the ISSUER participant has no effective_until`);
75
+ }
76
+ const didDocumentServiceId = `${agent.did}#${(0, setupSelfTr_1.linkedVpFragment)(schemaKey)}`;
77
+ // [VT-CRED-W3C] requires a globally unique credential id. The agent builds the id from the
78
+ // CredentialSchema, which keeps it stable: a random id causes a new issuance at each start.
79
+ const credentialId = `${agent.did}#schemas-${schemaId}-vtc`;
80
+ const integrityData = buildIntegrityData({ id, type, credentialSchema, claims });
81
+ const record = (_a = didRecord.metadata.get('_vt/vtc')) !== null && _a !== void 0 ? _a : {};
82
+ const metadata = record[credentialSchema.id];
83
+ const superseded = Object.entries(record).some(([storedSchemaId, entry]) => {
84
+ var _a;
85
+ return storedSchemaId !== credentialSchema.id &&
86
+ ((_a = entry === null || entry === void 0 ? void 0 : entry.verifiablePresentation) === null || _a === void 0 ? void 0 : _a.id) === id &&
87
+ (entry === null || entry === void 0 ? void 0 : entry.attached) !== false;
88
+ });
89
+ const attached = ((_b = metadata === null || metadata === void 0 ? void 0 : metadata.attached) !== null && _b !== void 0 ? _b : true) && !superseded;
90
+ if ((metadata === null || metadata === void 0 ? void 0 : metadata.integrityData) === integrityData &&
91
+ storedCredentialIsCurrent(metadata === null || metadata === void 0 ? void 0 : metadata.credential, credentialId, credentialSchema.id, agent.did, didRecord, validUntil)) {
92
+ // the presentation is already public, so a failed beforePublish step still needs a retry here
93
+ if (attached)
94
+ await (beforePublish === null || beforePublish === void 0 ? void 0 : beforePublish(metadata.verifiablePresentation));
95
+ return metadata.verifiablePresentation;
96
+ }
97
+ const verifiablePresentation = await signSelfIssuedEcsCredential(agent, didRecord, id, credentialId, type, claims, credentialSchema, validUntil);
98
+ // nothing is persisted yet, so a failure here leaves no public presentation behind
99
+ if (attached)
100
+ await (beforePublish === null || beforePublish === void 0 ? void 0 : beforePublish(verifiablePresentation));
101
+ // Update linked VP when the presentation has changed. Match by fragment or by the file the
102
+ // endpoint ends with: a `contains` test also matches the host, so an agent at a host such as
103
+ // ecs-org-issuer.example rewrote its DIDComm endpoint and every other ECS linked VP onto this one.
104
+ const linkedVpFile = `/${schemaKey}-vtc-vp.json`;
105
+ if (attached)
106
+ didDocument.service = (_c = didDocument.service) === null || _c === void 0 ? void 0 : _c.map(s => {
107
+ if (typeof s.serviceEndpoint !== 'string')
108
+ return s;
109
+ if (s.type !== 'LinkedVerifiablePresentation' || s.id === `${agent.did}#whois`)
110
+ return s;
111
+ if (s.id !== didDocumentServiceId && !s.serviceEndpoint.endsWith(linkedVpFile))
112
+ return s;
113
+ s.id = didDocumentServiceId;
114
+ s.serviceEndpoint = id;
115
+ return s;
116
+ });
117
+ // Resolvers only discover the credential through the [VT-CRED-W3C-LINKED-VP] fragment, and
118
+ // #whois does not match it. The rename above only covers documents that already carry the
119
+ // service, so publish it here when nothing declared it yet.
120
+ if (attached && !((_d = didDocument.service) === null || _d === void 0 ? void 0 : _d.some(s => s.id === didDocumentServiceId))) {
121
+ didDocument.service = [
122
+ ...((_e = didDocument.service) !== null && _e !== void 0 ? _e : []),
123
+ new core_1.DidDocumentService({
124
+ id: didDocumentServiceId,
125
+ serviceEndpoint: id,
126
+ type: 'LinkedVerifiablePresentation',
127
+ }),
128
+ ];
129
+ }
130
+ const whoisId = `${agent.did}#whois`;
131
+ if (attached && schemaKey === 'ecs-service') {
132
+ const whois = (_f = didDocument.service) === null || _f === void 0 ? void 0 : _f.find(s => s.id === whoisId);
133
+ if (whois) {
134
+ whois.serviceEndpoint = id;
135
+ }
136
+ else {
137
+ didDocument.service = [
138
+ ...((_g = didDocument.service) !== null && _g !== void 0 ? _g : []),
139
+ new core_1.DidDocumentService({ id: whoisId, serviceEndpoint: id, type: 'LinkedVerifiablePresentation' }),
140
+ ];
141
+ }
142
+ }
143
+ const [credential] = verifiablePresentation.verifiableCredential;
144
+ record[credentialSchema.id] = {
145
+ credential,
146
+ verifiablePresentation,
147
+ didDocumentServiceId,
148
+ integrityData,
149
+ attached,
150
+ };
151
+ didRecord.metadata.set('_vt/vtc', record);
152
+ // the write point publishes the document when it changed, and triggers the resolver when the
153
+ // published material did ([VSA-VT-LVP-5]): an ECS credential re-issued under the same URL changes
154
+ // the presentation a resolver reads, without changing the entry that announces it
155
+ await (0, publishedDidRecord_1.updateDidRecord)(agent, didRecord);
156
+ return verifiablePresentation;
157
+ }
158
+ //# sourceMappingURL=selfIssuedEcsCredential.js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AAE,MAAM,CAAC,CAAA;IACzC,6FAA6F;IAC7F,kGAAkG;IAClG,kFAAkF;IAClF,MAAM,IAAA,oCAAe,EAAC,KAAK,EAAE,SAAS,CAAC,CAAA;IACvC,OAAO,sBAAsB,CAAA;AAC/B,CAAC"}
@@ -1,76 +1,42 @@
1
- import { W3cCredential, W3cPresentation, W3cCredentialSchema, W3cCredentialSubject, W3cJsonLdVerifiableCredential, W3cJsonLdVerifiablePresentation, W3cCredentialOptions, DidRecord, W3cPresentationOptions, Logger } from '@credo-ts/core';
1
+ import { DidRecord, Logger, W3cCredentialSchema, W3cCredentialSubject, W3cV2Credential, W3cV2CredentialOptions, W3cV2DataIntegrityVerifiableCredential, W3cV2DataIntegrityVerifiablePresentation, W3cV2Presentation, W3cV2PresentationOptions } from '@credo-ts/core';
2
2
  import { AnySchemaObject } from 'ajv/dist/2020';
3
- import { VsAgent } from '../agent/VsAgent';
4
- export interface SelfTrDefaults {
5
- agentLabel: string;
6
- serviceLogoUri: string;
7
- serviceLogoDigestSri?: string;
8
- serviceType: string;
9
- serviceDescription: string;
10
- serviceMinimumAgeRequired: number;
11
- serviceTermsAndConditions: string;
12
- serviceTermsAndConditionsDigestSri?: string;
13
- servicePrivacyPolicy: string;
14
- servicePrivacyPolicyDigestSri?: string;
15
- orgRegistryId: string;
16
- orgRegistryUri: string;
17
- orgAddress: string;
18
- orgOrganizationKind: string;
19
- orgCountryCode: string;
20
- }
21
- export declare const presentations: {
22
- name: string;
23
- schemaUrl: string;
24
- }[];
25
- export declare const credentials: {
26
- name: string;
27
- credUrl: string;
28
- schemaUrl: string;
29
- }[];
3
+ import type { VsAgent } from '../agent/VsAgent';
4
+ import { EcsClaims } from './ecsClaims';
30
5
  export declare const createJsonSchema: W3cCredentialSchema;
31
6
  export declare const createJsonSubjectRef: (id: string) => W3cCredentialSubject;
7
+ export declare const linkedVpSchemaId: (schemaKey: string) => string;
32
8
  export declare const linkedVpFragment: (schemaKey: string) => string;
33
- export declare const mapToSelfTr: (url: string, publicApiBaseUrl: string) => string;
34
9
  export declare const sortKeysDeep: (value: unknown) => unknown;
35
- export declare const setupSelfTr: ({ agent, publicApiBaseUrl, defaults, }: {
36
- agent: VsAgent;
37
- publicApiBaseUrl: string;
38
- defaults: SelfTrDefaults;
39
- }) => Promise<void>;
40
- export declare function createCredential(options: Partial<W3cCredentialOptions>): W3cCredential;
41
10
  /**
42
- * Signs a W3C Verifiable Credential or Presentation using the provided agent and verification method.
11
+ * Builds an unsigned credential: a VC Data Model 2.0 credential, as
12
+ * [VT-CRED-W3C] and [VT-JSON-SCHEMA-CRED-W3C] require the `https://www.w3.org/ns/credentials/v2`
13
+ * context, valid from now for ten years unless told otherwise.
14
+ */
15
+ export declare function createCredential(options: Partial<W3cV2CredentialOptions>): W3cV2Credential;
16
+ /**
17
+ * The Data Integrity cryptosuite this agent is configured with, read from the registered
18
+ * `VtFlowModuleConfig` so the self issued credentials are secured and linked VPs with the
19
+ * same suite `VtFlowApi.issueCredentialForSession` applies to the credentials it issues. Falls back
20
+ * to the module default when the vt-flow module is not registered on the agent.
21
+ */
22
+ export declare function getDataIntegrityCryptosuite(agent: Pick<VsAgent, 'context'>): string;
23
+ /**
24
+ * Secures a W3C credential or presentation with a Data Integrity proof under the cryptosuite the
25
+ * agent is configured with, using the provided verification method.
43
26
  *
44
- * The function determines whether the input object is a `W3cCredential` or a `W3cPresentation`,
45
- * and applies the appropriate signing operation using Linked Data Proofs (`Ed25519Signature2020`).
27
+ * A credential is secured for `assertionMethod` and a presentation for `authentication`, the proof
28
+ * purposes VC Data Integrity defines for each; the presentation is published from the DID Document
29
+ * rather than presented to a verifier, so it carries no challenge.
46
30
  *
47
31
  * @param agent - The agent instance.
48
32
  * @param obj - The credential or presentation object to be signed.
49
33
  * @param verificationMethod - The DID verification method used to generate the proof.
50
- * @returns A signed W3C Verifiable Credential or Presentation in JSON-LD format.
34
+ * @returns The secured credential or presentation, wrapping the JSON that gets published.
51
35
  */
52
- export declare function signerW3c(agent: VsAgent, obj: W3cCredential, verificationMethod: string): Promise<W3cJsonLdVerifiableCredential>;
53
- export declare function signerW3c(agent: VsAgent, obj: W3cPresentation, verificationMethod: string): Promise<W3cJsonLdVerifiablePresentation>;
54
- /**
55
- * Generates and signs a verifiable presentation containing a verifiable credential.
56
- * Stores the signed presentation and its integrity metadata in the DID record.
57
- *
58
- * - Retrieves and validates claims for the agent's DID.
59
- * - Computes an integrity digest for the claims.
60
- * - If a presentation with the same integrity already exists in the DID metadata, it is returned.
61
- * - Otherwise, a new presentation is created, signed, and stored in the DID metadata.
62
- *
63
- * @param agent - The VsAgent instance used for signing and DID management.
64
- * @param logger - Logger instance for logging operations.
65
- * @param ecsSchemas - Map of ECS schemas for validation.
66
- * @param schemaKey - Unique identifier for the presentation type and metadata key.
67
- * @param type - Array of credential types to include.
68
- * @param credentialSchema - Schema definition for the credential.
69
- * @param beforePublish - Step that must succeed before a linked presentation counts as published.
70
- * @returns The signed verifiable presentation, with integrity metadata.
71
- */
72
- export declare function generateVerifiablePresentation(agent: VsAgent, id: string, ecsSchemas: Record<string, string>, schemaKey: string, type: string[], credentialSchema: W3cCredentialSchema, defaults: SelfTrDefaults, beforePublish?: (verifiablePresentation: any) => Promise<void>): Promise<any>;
73
- export declare function createPresentation(options: Partial<W3cPresentationOptions>): W3cPresentation;
36
+ export declare function signerW3c(agent: VsAgent, obj: W3cV2Credential, verificationMethod: string): Promise<W3cV2DataIntegrityVerifiableCredential>;
37
+ export declare function signerW3c(agent: VsAgent, obj: W3cV2Presentation, verificationMethod: string): Promise<W3cV2DataIntegrityVerifiablePresentation>;
38
+ /** Builds an unsigned VC Data Model 2.0 presentation; the class supplies the v2 context. */
39
+ export declare function createPresentation(options: Partial<W3cV2PresentationOptions>): W3cV2Presentation;
74
40
  /**
75
41
  * Retrieves and validates claims for a credential subject.
76
42
  * If claims are not found, builds default claims based on the schemaKey.
@@ -82,7 +48,12 @@ export declare function createPresentation(options: Partial<W3cPresentationOptio
82
48
  * @returns The validated claims object.
83
49
  * @throws If claims are invalid or schema is missing.
84
50
  */
85
- export declare function getClaims(logger: Logger, ecsSchemas: Record<string, string>, { id, claims }: W3cCredentialSubject, schemaKey: string, defaults: SelfTrDefaults): Promise<Record<string, unknown>>;
51
+ export declare function getClaims(logger: Logger, ecsSchemas: Record<string, string>, { id }: W3cCredentialSubject, schemaKey: string, ecsClaims: EcsClaims): Promise<Record<string, unknown>>;
52
+ export interface SchemaViolation {
53
+ path: string;
54
+ message: string;
55
+ }
56
+ export declare function schemaViolations(ecsSchema: AnySchemaObject, credentialSubject: Record<string, any>): SchemaViolation[];
86
57
  /**
87
58
  * Validate a validateSchema object against the corresponding AJV schema.
88
59
  * Throws an Error if the schema is missing or validation fails.
@@ -102,16 +73,5 @@ export declare function validateSchema(ecsSchema: AnySchemaObject, credentialSub
102
73
  export declare function addDigestSRI<T extends object>(id?: string, data?: T, ecsSchemas?: Record<string, string>): Promise<T & {
103
74
  digestSRI: string;
104
75
  }>;
105
- /**
106
- * Generates a SRI digest string for the given content using the specified algorithm.
107
- * @param content - The content to hash.
108
- * @param algorithm - The hash algorithm to use (default: sha256).
109
- * @returns The SRI digest string.
110
- */
111
- export declare function generateDigestSRI(content: string, algorithm?: string): string;
112
- /**
113
- * Digest of the resource a credential references. Throws rather than attest content it could
114
- * not read: a wrong digestSRI is a false integrity claim in a signed credential.
115
- */
116
- export declare function urlDigestSri(url: string): Promise<string>;
76
+ export declare function generateDigestSRI(content: string): string;
117
77
  export declare function getVerificationMethodId(logger: Logger, didRecord: DidRecord): string;