@verana-labs/vs-agent-sdk 2.0.0-dev.8 → 2.0.0-dev.80

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 (182) hide show
  1. package/README.md +0 -2
  2. package/build/adminApi/AdminApiError.d.ts +28 -0
  3. package/build/adminApi/AdminApiError.js +60 -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 +8 -0
  12. package/build/adminApi/moduleEndpoint.js +28 -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 +22 -34
  30. package/build/agent/VsAgent.js +84 -205
  31. package/build/agent/VsAgent.js.map +1 -1
  32. package/build/agent/createVsAgent.d.ts +5 -6
  33. package/build/agent/createVsAgent.js +3 -5
  34. package/build/agent/createVsAgent.js.map +1 -1
  35. package/build/blockchain/AnonCredsTrustService.d.ts +62 -0
  36. package/build/blockchain/AnonCredsTrustService.js +256 -0
  37. package/build/blockchain/AnonCredsTrustService.js.map +1 -0
  38. package/build/blockchain/AuthorizationService.d.ts +5 -3
  39. package/build/blockchain/AuthorizationService.js +17 -29
  40. package/build/blockchain/AuthorizationService.js.map +1 -1
  41. package/build/blockchain/IndexerWebSocketService.d.ts +7 -1
  42. package/build/blockchain/IndexerWebSocketService.js +68 -36
  43. package/build/blockchain/IndexerWebSocketService.js.map +1 -1
  44. package/build/blockchain/VeranaChainService.d.ts +38 -27
  45. package/build/blockchain/VeranaChainService.js +169 -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 +32 -0
  51. package/build/blockchain/feePreflight.js +89 -0
  52. package/build/blockchain/feePreflight.js.map +1 -0
  53. package/build/blockchain/handlers/authorizationHandlers.js +2 -2
  54. package/build/blockchain/handlers/authorizationHandlers.js.map +1 -1
  55. package/build/blockchain/handlers/defaultHandlers.js +6 -1
  56. package/build/blockchain/handlers/defaultHandlers.js.map +1 -1
  57. package/build/blockchain/handlers/index.d.ts +1 -0
  58. package/build/blockchain/handlers/index.js +1 -0
  59. package/build/blockchain/handlers/index.js.map +1 -1
  60. package/build/blockchain/handlers/selfIssuanceHandlers.d.ts +13 -0
  61. package/build/blockchain/handlers/selfIssuanceHandlers.js +76 -0
  62. package/build/blockchain/handlers/selfIssuanceHandlers.js.map +1 -0
  63. package/build/blockchain/handlers/stateMutations.d.ts +26 -3
  64. package/build/blockchain/handlers/stateMutations.js +317 -41
  65. package/build/blockchain/handlers/stateMutations.js.map +1 -1
  66. package/build/blockchain/index.d.ts +4 -0
  67. package/build/blockchain/index.js +4 -0
  68. package/build/blockchain/index.js.map +1 -1
  69. package/build/blockchain/indexerMappers.d.ts +3 -0
  70. package/build/blockchain/indexerMappers.js +53 -0
  71. package/build/blockchain/indexerMappers.js.map +1 -0
  72. package/build/blockchain/triggerResolver.d.ts +26 -0
  73. package/build/blockchain/triggerResolver.js +120 -0
  74. package/build/blockchain/triggerResolver.js.map +1 -0
  75. package/build/blockchain/types.d.ts +13 -70
  76. package/build/blockchain/types.js.map +1 -1
  77. package/build/bootstrap/EcsBootstrapService.d.ts +13 -3
  78. package/build/bootstrap/EcsBootstrapService.js +172 -94
  79. package/build/bootstrap/EcsBootstrapService.js.map +1 -1
  80. package/build/connections/ParentConnectionModule.d.ts +20 -0
  81. package/build/connections/ParentConnectionModule.js +56 -0
  82. package/build/connections/ParentConnectionModule.js.map +1 -0
  83. package/build/credentials/FullTailsFileService.d.ts +0 -1
  84. package/build/credentials/FullTailsFileService.js +0 -49
  85. package/build/credentials/FullTailsFileService.js.map +1 -1
  86. package/build/did/CachedDocumentLoader.d.ts +3 -0
  87. package/build/did/CachedDocumentLoader.js +7 -1
  88. package/build/did/CachedDocumentLoader.js.map +1 -1
  89. package/build/did/CachedWebDidResolver.d.ts +0 -4
  90. package/build/did/CachedWebDidResolver.js +1 -5
  91. package/build/did/CachedWebDidResolver.js.map +1 -1
  92. package/build/did/artifactServices.d.ts +12 -0
  93. package/build/did/artifactServices.js +48 -0
  94. package/build/did/artifactServices.js.map +1 -0
  95. package/build/did/legacyDidWeb.d.ts +6 -4
  96. package/build/did/legacyDidWeb.js +17 -14
  97. package/build/did/legacyDidWeb.js.map +1 -1
  98. package/build/did/publicDid.d.ts +4 -0
  99. package/build/did/publicDid.js +19 -0
  100. package/build/did/publicDid.js.map +1 -0
  101. package/build/events/BaseMessageEvents.js +139 -5
  102. package/build/events/BaseMessageEvents.js.map +1 -1
  103. package/build/events/ConnectionEvents.js +150 -86
  104. package/build/events/ConnectionEvents.js.map +1 -1
  105. package/build/events/VsAgentEvents.d.ts +11 -9
  106. package/build/events/VsAgentEvents.js +8 -1
  107. package/build/events/VsAgentEvents.js.map +1 -1
  108. package/build/events/VtFlowEvents.d.ts +1 -1
  109. package/build/events/VtFlowEvents.js +29 -17
  110. package/build/events/VtFlowEvents.js.map +1 -1
  111. package/build/index.d.ts +7 -1
  112. package/build/index.js +15 -2
  113. package/build/index.js.map +1 -1
  114. package/build/plugins/setupBaseDidComm.js +9 -12
  115. package/build/plugins/setupBaseDidComm.js.map +1 -1
  116. package/build/transports/VsAgentWsInboundTransport.d.ts +1 -1
  117. package/build/transports/VsAgentWsInboundTransport.js +20 -14
  118. package/build/transports/VsAgentWsInboundTransport.js.map +1 -1
  119. package/build/types.d.ts +14 -13
  120. package/build/types.js +1 -2
  121. package/build/types.js.map +1 -1
  122. package/build/utils/agent.d.ts +29 -4
  123. package/build/utils/agent.js +91 -22
  124. package/build/utils/agent.js.map +1 -1
  125. package/build/utils/boundedFetch.d.ts +13 -0
  126. package/build/utils/boundedFetch.js +47 -0
  127. package/build/utils/boundedFetch.js.map +1 -0
  128. package/build/utils/didReadiness.d.ts +9 -0
  129. package/build/utils/didReadiness.js +42 -0
  130. package/build/utils/didReadiness.js.map +1 -0
  131. package/build/utils/ecsClaims.d.ts +46 -0
  132. package/build/utils/ecsClaims.js +115 -0
  133. package/build/utils/ecsClaims.js.map +1 -0
  134. package/build/utils/ecsService.d.ts +8 -0
  135. package/build/utils/ecsService.js +23 -0
  136. package/build/utils/ecsService.js.map +1 -0
  137. package/build/utils/index.d.ts +7 -0
  138. package/build/utils/index.js +7 -0
  139. package/build/utils/index.js.map +1 -1
  140. package/build/utils/publishedDidRecord.d.ts +15 -0
  141. package/build/utils/publishedDidRecord.js +83 -0
  142. package/build/utils/publishedDidRecord.js.map +1 -0
  143. package/build/utils/selfIssuedEcsCredential.d.ts +8 -0
  144. package/build/utils/selfIssuedEcsCredential.js +153 -0
  145. package/build/utils/selfIssuedEcsCredential.js.map +1 -0
  146. package/build/utils/setupSelfTr.d.ts +35 -74
  147. package/build/utils/setupSelfTr.js +93 -312
  148. package/build/utils/setupSelfTr.js.map +1 -1
  149. package/build/utils/trustCredentialStore.d.ts +78 -9
  150. package/build/utils/trustCredentialStore.js +324 -136
  151. package/build/utils/trustCredentialStore.js.map +1 -1
  152. package/build/utils/typeMetadata.d.ts +43 -0
  153. package/build/utils/typeMetadata.js +77 -0
  154. package/build/utils/typeMetadata.js.map +1 -0
  155. package/build/utils/util.d.ts +19 -0
  156. package/build/utils/util.js +24 -0
  157. package/build/utils/util.js.map +1 -1
  158. package/build/utils/vcdm2.d.ts +34 -0
  159. package/build/utils/vcdm2.js +60 -0
  160. package/build/utils/vcdm2.js.map +1 -0
  161. package/build/utils/vtjscResolver.d.ts +23 -0
  162. package/build/utils/vtjscResolver.js +53 -0
  163. package/build/utils/vtjscResolver.js.map +1 -0
  164. package/build/vtFlow/VtFlowOrchestrator.d.ts +107 -15
  165. package/build/vtFlow/VtFlowOrchestrator.js +678 -116
  166. package/build/vtFlow/VtFlowOrchestrator.js.map +1 -1
  167. package/build/vtFlow/assertVerifiableService.d.ts +1 -0
  168. package/build/vtFlow/assertVerifiableService.js +45 -5
  169. package/build/vtFlow/assertVerifiableService.js.map +1 -1
  170. package/build/vtFlow/ecsIssuanceExemption.d.ts +12 -0
  171. package/build/vtFlow/ecsIssuanceExemption.js +84 -0
  172. package/build/vtFlow/ecsIssuanceExemption.js.map +1 -0
  173. package/build/vtFlow/index.d.ts +1 -0
  174. package/build/vtFlow/index.js +1 -0
  175. package/build/vtFlow/index.js.map +1 -1
  176. package/package.json +18 -12
  177. package/build/did/migrateWebVhLog.d.ts +0 -34
  178. package/build/did/migrateWebVhLog.js +0 -230
  179. package/build/did/migrateWebVhLog.js.map +0 -1
  180. package/build/did/migrateWebVhVersionTime.d.ts +0 -9
  181. package/build/did/migrateWebVhVersionTime.js +0 -191
  182. package/build/did/migrateWebVhVersionTime.js.map +0 -1
@@ -1,75 +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
- export declare const setupSelfTr: ({ agent, publicApiBaseUrl, defaults, }: {
35
- agent: VsAgent;
36
- publicApiBaseUrl: string;
37
- defaults: SelfTrDefaults;
38
- }) => Promise<void>;
39
- export declare function createCredential(options: Partial<W3cCredentialOptions>): W3cCredential;
9
+ export declare const sortKeysDeep: (value: unknown) => unknown;
10
+ /**
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;
40
23
  /**
41
- * Signs a W3C Verifiable Credential or Presentation using the provided agent and verification method.
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.
42
26
  *
43
- * The function determines whether the input object is a `W3cCredential` or a `W3cPresentation`,
44
- * 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.
45
30
  *
46
31
  * @param agent - The agent instance.
47
32
  * @param obj - The credential or presentation object to be signed.
48
33
  * @param verificationMethod - The DID verification method used to generate the proof.
49
- * @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.
50
35
  */
51
- export declare function signerW3c(agent: VsAgent, obj: W3cCredential, verificationMethod: string): Promise<W3cJsonLdVerifiableCredential>;
52
- export declare function signerW3c(agent: VsAgent, obj: W3cPresentation, verificationMethod: string): Promise<W3cJsonLdVerifiablePresentation>;
53
- /**
54
- * Generates and signs a verifiable presentation containing a verifiable credential.
55
- * Stores the signed presentation and its integrity metadata in the DID record.
56
- *
57
- * - Retrieves and validates claims for the agent's DID.
58
- * - Computes an integrity digest for the claims.
59
- * - If a presentation with the same integrity already exists in the DID metadata, it is returned.
60
- * - Otherwise, a new presentation is created, signed, and stored in the DID metadata.
61
- *
62
- * @param agent - The VsAgent instance used for signing and DID management.
63
- * @param logger - Logger instance for logging operations.
64
- * @param ecsSchemas - Map of ECS schemas for validation.
65
- * @param schemaKey - Unique identifier for the presentation type and metadata key.
66
- * @param type - Array of credential types to include.
67
- * @param credentialSchema - Schema definition for the credential.
68
- * @param beforePublish - Step that must succeed before a linked presentation counts as published.
69
- * @returns The signed verifiable presentation, with integrity metadata.
70
- */
71
- 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>;
72
- 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;
73
40
  /**
74
41
  * Retrieves and validates claims for a credential subject.
75
42
  * If claims are not found, builds default claims based on the schemaKey.
@@ -81,7 +48,12 @@ export declare function createPresentation(options: Partial<W3cPresentationOptio
81
48
  * @returns The validated claims object.
82
49
  * @throws If claims are invalid or schema is missing.
83
50
  */
84
- 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[];
85
57
  /**
86
58
  * Validate a validateSchema object against the corresponding AJV schema.
87
59
  * Throws an Error if the schema is missing or validation fails.
@@ -101,16 +73,5 @@ export declare function validateSchema(ecsSchema: AnySchemaObject, credentialSub
101
73
  export declare function addDigestSRI<T extends object>(id?: string, data?: T, ecsSchemas?: Record<string, string>): Promise<T & {
102
74
  digestSRI: string;
103
75
  }>;
104
- /**
105
- * Generates a SRI digest string for the given content using the specified algorithm.
106
- * @param content - The content to hash.
107
- * @param algorithm - The hash algorithm to use (default: sha256).
108
- * @returns The SRI digest string.
109
- */
110
- export declare function generateDigestSRI(content: string, algorithm?: string): string;
111
- /**
112
- * Digest of the resource a credential references. Throws rather than attest content it could
113
- * not read: a wrong digestSRI is a false integrity claim in a signed credential.
114
- */
115
- export declare function urlDigestSri(url: string): Promise<string>;
76
+ export declare function generateDigestSRI(content: string): string;
116
77
  export declare function getVerificationMethodId(logger: Logger, didRecord: DidRecord): string;
@@ -3,55 +3,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.setupSelfTr = exports.mapToSelfTr = exports.linkedVpFragment = exports.createJsonSubjectRef = exports.createJsonSchema = exports.credentials = exports.presentations = void 0;
6
+ exports.sortKeysDeep = exports.linkedVpFragment = exports.linkedVpSchemaId = exports.createJsonSubjectRef = exports.createJsonSchema = void 0;
7
7
  exports.createCredential = createCredential;
8
+ exports.getDataIntegrityCryptosuite = getDataIntegrityCryptosuite;
8
9
  exports.signerW3c = signerW3c;
9
- exports.generateVerifiablePresentation = generateVerifiablePresentation;
10
10
  exports.createPresentation = createPresentation;
11
11
  exports.getClaims = getClaims;
12
+ exports.schemaViolations = schemaViolations;
12
13
  exports.validateSchema = validateSchema;
13
14
  exports.addDigestSRI = addDigestSRI;
14
15
  exports.generateDigestSRI = generateDigestSRI;
15
- exports.urlDigestSri = urlDigestSri;
16
16
  exports.getVerificationMethodId = getVerificationMethodId;
17
17
  const core_1 = require("@credo-ts/core");
18
- // No type definitions available for this library
19
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
20
- //@ts-expect-error
21
- const jsonld_signatures_1 = require("@digitalcredentials/jsonld-signatures");
18
+ const credo_ts_didcomm_vt_flow_1 = require("@verana-labs/credo-ts-didcomm-vt-flow");
22
19
  const vs_agent_model_1 = require("@verana-labs/vs-agent-model");
23
20
  const _2020_1 = __importDefault(require("ajv/dist/2020"));
24
21
  const ajv_formats_1 = __importDefault(require("ajv-formats"));
25
- const axios_1 = __importDefault(require("axios"));
26
- const crypto_1 = require("crypto");
27
- const data_1 = require("./data");
28
- const ajv = new _2020_1.default({ strict: false });
22
+ const boundedFetch_1 = require("./boundedFetch");
23
+ const ecsClaims_1 = require("./ecsClaims");
24
+ const vcdm2_1 = require("./vcdm2");
25
+ const TEN_YEARS_MS = 10 * 365 * 24 * 60 * 60 * 1000;
26
+ const ajv = new _2020_1.default({ strict: false, allErrors: true });
29
27
  (0, ajv_formats_1.default)(ajv);
30
- const DIGEST_FETCH_TIMEOUT_MS = 5000;
31
- // Helpers
32
- exports.presentations = [
33
- {
34
- name: 'ecs-service',
35
- schemaUrl: `ecosystem/schemas-example-service-jsc.json`,
36
- },
37
- {
38
- name: 'ecs-org',
39
- schemaUrl: `ecosystem/schemas-example-org-jsc.json`,
40
- },
41
- ];
42
- exports.credentials = [
43
- {
44
- name: 'example-service',
45
- credUrl: `ecosystem/cs/v1/js/ecs-service`,
46
- schemaUrl: `ecosystem/schemas-example-service-jsc.json`,
47
- },
48
- {
49
- name: 'example-org',
50
- credUrl: `ecosystem/cs/v1/js/ecs-org`,
51
- schemaUrl: `ecosystem/schemas-example-org-jsc.json`,
52
- },
53
- ];
54
- // Default JSON Schema objects
55
28
  exports.createJsonSchema = {
56
29
  id: 'https://www.w3.org/ns/credentials/json-schema/v2.json',
57
30
  type: 'JsonSchema',
@@ -67,233 +40,72 @@ const createJsonSubjectRef = (id) => ({
67
40
  });
68
41
  exports.createJsonSubjectRef = createJsonSubjectRef;
69
42
  // fragment format per [VT-CRED-W3C-LINKED-VP]
70
- const linkedVpFragment = (schemaKey) => `vpr-schemas-${schemaKey.replace(/^ecs-/, '')}-vtc-vp`;
43
+ const linkedVpSchemaId = (schemaKey) => schemaKey.replace(/^ecs-/, '');
44
+ exports.linkedVpSchemaId = linkedVpSchemaId;
45
+ const linkedVpFragment = (schemaKey) => `vpr-schemas-${(0, exports.linkedVpSchemaId)(schemaKey)}-vtc-vp`;
71
46
  exports.linkedVpFragment = linkedVpFragment;
72
- const mapToSelfTr = (url, publicApiBaseUrl) => url.replace('ecosystem', `${publicApiBaseUrl}/vt`);
73
- exports.mapToSelfTr = mapToSelfTr;
74
- const buildIntegrityData = (data) => {
75
- return generateDigestSRI(JSON.stringify(data, Object.keys(data).sort()));
76
- };
77
- const setupSelfTr = async ({ agent, publicApiBaseUrl, defaults, }) => {
78
- const ecsSchemas = (0, data_1.getEcsSchemas)(publicApiBaseUrl);
79
- const logger = agent.config.logger;
80
- for (const { name, schemaUrl } of exports.presentations) {
81
- try {
82
- await generateVerifiablePresentation(agent, `${publicApiBaseUrl}/vt/${name}-vtc-vp.json`, ecsSchemas, name, ['VerifiableCredential', 'VerifiableTrustCredential'], {
83
- id: (0, exports.mapToSelfTr)(schemaUrl, publicApiBaseUrl),
84
- type: 'JsonSchemaCredential',
85
- }, defaults);
86
- }
87
- catch (error) {
88
- logger.warn(`Skipping self-issued ${name}: ${error instanceof Error ? error.message : error}`);
89
- }
90
- }
91
- for (const { name, credUrl, schemaUrl } of exports.credentials) {
92
- const id = (0, exports.mapToSelfTr)(schemaUrl, publicApiBaseUrl);
93
- const ref = (0, exports.mapToSelfTr)(credUrl, publicApiBaseUrl);
94
- try {
95
- await generateVerifiableCredential(agent, id, ecsSchemas, name, ['VerifiableCredential', 'JsonSchemaCredential'], (0, exports.createJsonSubjectRef)(ref), exports.createJsonSchema, defaults);
96
- }
97
- catch (error) {
98
- logger.warn(`Skipping self-issued ${name}: ${error instanceof Error ? error.message : error}`);
99
- }
100
- }
47
+ // A plain array replacer only allowlists property names, applied at every
48
+ // nesting level — nested objects like `claims` and `credentialSchema` would
49
+ // serialize to `{}` since none of their own keys appear in a top-level
50
+ // key list. Sort keys recursively instead, so the hash actually reflects
51
+ // nested content and changes to claims invalidate the cache correctly.
52
+ const sortKeysDeep = (value) => {
53
+ if (Array.isArray(value))
54
+ return value.map(exports.sortKeysDeep);
55
+ if (value !== null && typeof value === 'object') {
56
+ return Object.keys(value)
57
+ .sort()
58
+ .reduce((acc, key) => {
59
+ acc[key] = (0, exports.sortKeysDeep)(value[key]);
60
+ return acc;
61
+ }, {});
62
+ }
63
+ return value;
101
64
  };
102
- exports.setupSelfTr = setupSelfTr;
65
+ exports.sortKeysDeep = sortKeysDeep;
103
66
  /**
104
- * Generates and signs a verifiable credential using the agent's DID.
105
- * Stores the signed credential and its integrity metadata in the DID record.
106
- *
107
- * - If the claims for the subject are not provided, they are retrieved (default claims) and validated against the schema.
108
- * - The integrity of the claims is tracked using a Subresource Integrity (SRI) digest.
109
- * - If a credential with the same integrity already exists in the DID metadata, it is returned directly.
110
- * - Otherwise, a new credential is created, signed, and stored in the DID metadata.
111
- * - If a presentation is provided, the signed credential is embedded and a signed presentation is returned.
112
- *
113
- * @param agent - The VsAgent instance used for signing and DID management.
114
- * @param logger - Logger instance for logging operations.
115
- * @param ecsSchemas - Map of ECS schemas for validation.
116
- * @param schemaKey - Unique identifier for the credential type and metadata key.
117
- * @param type - Array of credential types (e.g., ['VerifiableCredential']).
118
- * @param subject - Subject information, including ID and optional claims.
119
- * @param credentialSchema - Schema definition for the credential.
120
- * @param presentation - Optional presentation to include the credential.
121
- * @returns The signed verifiable credential or presentation, with integrity metadata.
67
+ * Builds an unsigned credential: a VC Data Model 2.0 credential, as
68
+ * [VT-CRED-W3C] and [VT-JSON-SCHEMA-CRED-W3C] require the `https://www.w3.org/ns/credentials/v2`
69
+ * context, valid from now for ten years unless told otherwise.
122
70
  */
123
- async function generateVerifiableCredential(agent, id, ecsSchemas, schemaKey, type, subject, credentialSchema, defaults, presentation) {
71
+ function createCredential(options) {
124
72
  var _a;
125
- const logger = agent.config.logger;
126
- const [didRecord] = await agent.dids.getCreatedDids({ did: agent.did });
127
- const { id: subjectId } = subject;
128
- let claims = subject.claims;
129
- if (!claims) {
130
- claims = await getClaims(logger, ecsSchemas, { id: subjectId }, schemaKey, defaults);
131
- }
132
- const integrityData = buildIntegrityData({ id, type, credentialSchema, claims });
133
- const record = (_a = didRecord.metadata.get('_vt/jsc')) !== null && _a !== void 0 ? _a : {};
134
- const metadata = record[subjectId];
135
- if ((metadata === null || metadata === void 0 ? void 0 : metadata.integrityData) === integrityData)
136
- return metadata.credential;
137
- const unsignedCredential = createCredential({
138
- id,
139
- type,
140
- issuer: agent.did,
141
- credentialSubject: {
142
- id: subjectId,
143
- claims: presentation ? claims : await addDigestSRI(subjectId, claims, ecsSchemas),
144
- },
145
- });
146
- unsignedCredential.credentialSchema = presentation
147
- ? credentialSchema
148
- : await addDigestSRI(credentialSchema.id, credentialSchema, ecsSchemas);
149
- // Note: this is dependant on DIDComm invitation keys. Not sure if it is fine or we should use a dedicated
150
- // key for this feature
151
- const verificationMethodId = getVerificationMethodId(logger, didRecord);
152
- const signedCredential = await signerW3c(agent, unsignedCredential, verificationMethodId);
153
- if (presentation) {
154
- presentation.verifiableCredential = [signedCredential];
155
- return await signerW3c(agent, presentation, verificationMethodId);
156
- }
157
- else {
158
- record[subjectId] = {
159
- credential: signedCredential.jsonCredential,
160
- verifiablePresentation: {},
161
- didDocumentServiceId: '',
162
- integrityData,
163
- };
164
- didRecord.metadata.set('_vt/jsc', record);
165
- await agent.context.dependencyManager.resolve(core_1.DidRepository).update(agent.context, didRecord);
166
- return signedCredential.jsonCredential;
167
- }
73
+ return (0, vcdm2_1.createW3cV2Credential)(Object.assign(Object.assign({}, options), { validUntil: (_a = options.validUntil) !== null && _a !== void 0 ? _a : new Date(Date.now() + TEN_YEARS_MS).toISOString() }));
168
74
  }
169
- function createCredential(options) {
170
- var _a, _b, _c;
171
- (_a = options.context) !== null && _a !== void 0 ? _a : (options.context = [
172
- 'https://www.w3.org/2018/credentials/v1',
173
- 'https://www.w3.org/ns/credentials/examples/v2',
174
- ]);
175
- (_b = options.issuanceDate) !== null && _b !== void 0 ? _b : (options.issuanceDate = new Date().toISOString());
176
- (_c = options.expirationDate) !== null && _c !== void 0 ? _c : (options.expirationDate = new Date(Date.now() + 10 * 365 * 24 * 60 * 60 * 1000).toISOString());
177
- return new core_1.W3cCredential(options);
75
+ /**
76
+ * The Data Integrity cryptosuite this agent is configured with, read from the registered
77
+ * `VtFlowModuleConfig` so the self issued credentials are secured and linked VPs with the
78
+ * same suite `VtFlowApi.issueCredentialForSession` applies to the credentials it issues. Falls back
79
+ * to the module default when the vt-flow module is not registered on the agent.
80
+ */
81
+ function getDataIntegrityCryptosuite(agent) {
82
+ const { dependencyManager } = agent.context;
83
+ return dependencyManager.isRegistered(credo_ts_didcomm_vt_flow_1.VtFlowModuleConfig)
84
+ ? dependencyManager.resolve(credo_ts_didcomm_vt_flow_1.VtFlowModuleConfig).dataIntegrityCryptosuite
85
+ : credo_ts_didcomm_vt_flow_1.DEFAULT_DATA_INTEGRITY_CRYPTOSUITE;
178
86
  }
179
87
  async function signerW3c(agent, obj, verificationMethod) {
180
- const proofPurpose = new jsonld_signatures_1.purposes.AssertionProofPurpose();
181
- if (obj instanceof core_1.W3cCredential) {
182
- return await agent.w3cCredentials.signCredential({
183
- format: core_1.ClaimFormat.LdpVc,
88
+ const cryptosuite = getDataIntegrityCryptosuite(agent);
89
+ if (obj instanceof core_1.W3cV2Credential) {
90
+ return await agent.w3cV2Credentials.signCredential({
91
+ format: core_1.ClaimFormat.DiVc,
184
92
  credential: obj,
185
- proofType: 'Ed25519Signature2020',
186
- verificationMethod,
187
- proofPurpose,
188
- });
189
- }
190
- if (obj instanceof core_1.W3cPresentation) {
191
- return await agent.w3cCredentials.signPresentation({
192
- format: core_1.ClaimFormat.LdpVp,
193
- presentation: obj,
194
- proofType: 'Ed25519Signature2020',
93
+ cryptosuite,
195
94
  verificationMethod,
196
- proofPurpose,
197
95
  });
198
96
  }
199
- }
200
- /**
201
- * Generates and signs a verifiable presentation containing a verifiable credential.
202
- * Stores the signed presentation and its integrity metadata in the DID record.
203
- *
204
- * - Retrieves and validates claims for the agent's DID.
205
- * - Computes an integrity digest for the claims.
206
- * - If a presentation with the same integrity already exists in the DID metadata, it is returned.
207
- * - Otherwise, a new presentation is created, signed, and stored in the DID metadata.
208
- *
209
- * @param agent - The VsAgent instance used for signing and DID management.
210
- * @param logger - Logger instance for logging operations.
211
- * @param ecsSchemas - Map of ECS schemas for validation.
212
- * @param schemaKey - Unique identifier for the presentation type and metadata key.
213
- * @param type - Array of credential types to include.
214
- * @param credentialSchema - Schema definition for the credential.
215
- * @param beforePublish - Step that must succeed before a linked presentation counts as published.
216
- * @returns The signed verifiable presentation, with integrity metadata.
217
- */
218
- async function generateVerifiablePresentation(agent, id, ecsSchemas, schemaKey, type, credentialSchema, defaults, beforePublish) {
219
- var _a, _b, _c, _d, _e;
220
- if (!agent.did)
221
- throw Error('The DID must be set up');
222
- const [didRecord] = await agent.dids.getCreatedDids({ did: agent.did });
223
- const didDocument = didRecord.didDocument;
224
- if (!didDocument)
225
- throw Error('The DID Document be set up');
226
- const claims = await getClaims(agent.config.logger, ecsSchemas, { id: agent.did }, schemaKey, defaults);
227
- // Use full input for integrityData to ensure update detection
228
- const didDocumentServiceId = `${agent.did}#${(0, exports.linkedVpFragment)(schemaKey)}`;
229
- const integrityData = buildIntegrityData({ id, type, credentialSchema, claims });
230
- const record = (_a = didRecord.metadata.get('_vt/vtc')) !== null && _a !== void 0 ? _a : {};
231
- const metadata = record[credentialSchema.id];
232
- const attached = (_b = metadata === null || metadata === void 0 ? void 0 : metadata.attached) !== null && _b !== void 0 ? _b : true;
233
- if ((metadata === null || metadata === void 0 ? void 0 : metadata.integrityData) === integrityData) {
234
- // the presentation is already public, so a failed beforePublish step still needs a retry here
235
- if (attached)
236
- await (beforePublish === null || beforePublish === void 0 ? void 0 : beforePublish(metadata.verifiablePresentation));
237
- return metadata.verifiablePresentation;
238
- }
239
- const presentation = createPresentation({
240
- id,
241
- holder: agent.did,
242
- verifiableCredential: [],
97
+ // The options type requires a challenge for every presentation format, while a Data Integrity
98
+ // proof only carries one when it is given
99
+ return await agent.w3cV2Credentials.signPresentation({
100
+ format: core_1.ClaimFormat.DiVp,
101
+ presentation: obj,
102
+ cryptosuite,
103
+ verificationMethod,
243
104
  });
244
- const verifiablePresentation = await generateVerifiableCredential(agent, agent.did, ecsSchemas, schemaKey, type, { id: agent.did }, credentialSchema, defaults, presentation);
245
- // nothing is persisted yet, so a failure here leaves no public presentation behind
246
- if (attached)
247
- await (beforePublish === null || beforePublish === void 0 ? void 0 : beforePublish(verifiablePresentation));
248
- // Update linked VP when the presentation has changed
249
- if (attached)
250
- didDocument.service = (_c = didDocument.service) === null || _c === void 0 ? void 0 : _c.map(s => {
251
- if (typeof s.serviceEndpoint !== 'string')
252
- return s;
253
- if (s.serviceEndpoint.includes(schemaKey) && s.id !== `${agent.did}#whois`) {
254
- s.id = didDocumentServiceId;
255
- s.serviceEndpoint = id;
256
- }
257
- return s;
258
- });
259
- // Resolvers only discover the credential through the [VT-CRED-W3C-LINKED-VP] fragment, and
260
- // #whois does not match it. The rename above only covers documents that already carry the
261
- // service, so publish it here when nothing declared it yet.
262
- let didDocumentChanged = false;
263
- if (attached && !((_d = didDocument.service) === null || _d === void 0 ? void 0 : _d.some(s => s.id === didDocumentServiceId))) {
264
- didDocument.service = [
265
- ...((_e = didDocument.service) !== null && _e !== void 0 ? _e : []),
266
- new core_1.DidDocumentService({
267
- id: didDocumentServiceId,
268
- serviceEndpoint: id,
269
- type: 'LinkedVerifiablePresentation',
270
- }),
271
- ];
272
- didDocumentChanged = true;
273
- }
274
- const credential = verifiablePresentation.verifiableCredential[0];
275
- record[credentialSchema.id] = {
276
- credential,
277
- verifiablePresentation,
278
- didDocumentServiceId,
279
- integrityData,
280
- attached,
281
- };
282
- didRecord.metadata.set('_vt/vtc', record);
283
- await agent.context.dependencyManager.resolve(core_1.DidRepository).update(agent.context, didRecord);
284
- if (didDocumentChanged) {
285
- await agent.dids.update({ did: didRecord.did, didDocument });
286
- }
287
- return verifiablePresentation;
288
105
  }
106
+ /** Builds an unsigned VC Data Model 2.0 presentation; the class supplies the v2 context. */
289
107
  function createPresentation(options) {
290
- var _a, _b;
291
- (_a = options.context) !== null && _a !== void 0 ? _a : (options.context = [
292
- 'https://www.w3.org/2018/credentials/v1',
293
- 'https://www.w3.org/ns/credentials/examples/v2',
294
- ]);
295
- (_b = options.type) !== null && _b !== void 0 ? _b : (options.type = ['VerifiablePresentation']);
296
- return new core_1.W3cPresentation(options);
108
+ return new core_1.W3cV2Presentation(Object.assign({ type: ['VerifiablePresentation'] }, options));
297
109
  }
298
110
  /**
299
111
  * Retrieves and validates claims for a credential subject.
@@ -306,60 +118,43 @@ function createPresentation(options) {
306
118
  * @returns The validated claims object.
307
119
  * @throws If claims are invalid or schema is missing.
308
120
  */
309
- async function getClaims(logger, ecsSchemas, { id, claims }, schemaKey, defaults) {
310
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
311
- // Default claims fallback
312
- const logoUri = (_a = claims === null || claims === void 0 ? void 0 : claims.logoUri) !== null && _a !== void 0 ? _a : defaults.serviceLogoUri;
313
- const termsAndConditionsUri = (_b = claims === null || claims === void 0 ? void 0 : claims.termsAndConditionsUri) !== null && _b !== void 0 ? _b : defaults.serviceTermsAndConditions;
314
- const privacyPolicyUri = (_c = claims === null || claims === void 0 ? void 0 : claims.privacyPolicyUri) !== null && _c !== void 0 ? _c : defaults.servicePrivacyPolicy;
315
- claims =
316
- schemaKey === 'ecs-service'
317
- ? {
318
- name: (_d = claims === null || claims === void 0 ? void 0 : claims.name) !== null && _d !== void 0 ? _d : defaults.agentLabel,
319
- type: (_e = claims === null || claims === void 0 ? void 0 : claims.type) !== null && _e !== void 0 ? _e : defaults.serviceType,
320
- description: (_f = claims === null || claims === void 0 ? void 0 : claims.description) !== null && _f !== void 0 ? _f : defaults.serviceDescription,
321
- logoUri,
322
- logoDigestSri: (_h = (_g = claims === null || claims === void 0 ? void 0 : claims.logoDigestSri) !== null && _g !== void 0 ? _g : defaults.serviceLogoDigestSri) !== null && _h !== void 0 ? _h : (await urlDigestSri(logoUri)),
323
- minimumAgeRequired: (_j = claims === null || claims === void 0 ? void 0 : claims.minimumAgeRequired) !== null && _j !== void 0 ? _j : defaults.serviceMinimumAgeRequired,
324
- termsAndConditionsUri,
325
- termsAndConditionsDigestSri: (_l = (_k = claims === null || claims === void 0 ? void 0 : claims.termsAndConditionsDigestSri) !== null && _k !== void 0 ? _k : defaults.serviceTermsAndConditionsDigestSri) !== null && _l !== void 0 ? _l : (await urlDigestSri(termsAndConditionsUri)),
326
- privacyPolicyUri,
327
- privacyPolicyDigestSri: (_o = (_m = claims === null || claims === void 0 ? void 0 : claims.privacyPolicyDigestSri) !== null && _m !== void 0 ? _m : defaults.servicePrivacyPolicyDigestSri) !== null && _o !== void 0 ? _o : (await urlDigestSri(privacyPolicyUri)),
328
- }
329
- : {
330
- name: (_p = claims === null || claims === void 0 ? void 0 : claims.name) !== null && _p !== void 0 ? _p : defaults.agentLabel,
331
- logoUri,
332
- logoDigestSri: (_r = (_q = claims === null || claims === void 0 ? void 0 : claims.logoDigestSri) !== null && _q !== void 0 ? _q : defaults.serviceLogoDigestSri) !== null && _r !== void 0 ? _r : (await urlDigestSri(logoUri)),
333
- registryId: (_s = claims === null || claims === void 0 ? void 0 : claims.registryId) !== null && _s !== void 0 ? _s : defaults.orgRegistryId,
334
- registryUri: (_t = claims === null || claims === void 0 ? void 0 : claims.registryUri) !== null && _t !== void 0 ? _t : defaults.orgRegistryUri,
335
- address: (_u = claims === null || claims === void 0 ? void 0 : claims.address) !== null && _u !== void 0 ? _u : defaults.orgAddress,
336
- organizationKind: (_v = claims === null || claims === void 0 ? void 0 : claims.organizationKind) !== null && _v !== void 0 ? _v : defaults.orgOrganizationKind,
337
- countryCode: (_w = claims === null || claims === void 0 ? void 0 : claims.countryCode) !== null && _w !== void 0 ? _w : defaults.orgCountryCode,
338
- };
121
+ async function getClaims(logger, ecsSchemas, { id }, schemaKey, ecsClaims) {
122
+ const claims = await (0, ecsClaims_1.composeEcsClaims)(ecsClaims, schemaKey, logger);
123
+ if (!claims)
124
+ throw new Error(`No ECS_CLAIMS_* variable is set for ${schemaKey}`);
339
125
  const ecsSchema = ecsSchemas[schemaKey];
340
126
  if (!ecsSchema) {
341
127
  throw new Error(`Schema not defined in data schemas for schemaKey: ${schemaKey}`);
342
128
  }
343
- const credentialSubject = Object.assign({ id }, claims);
344
- validateSchema(JSON.parse(ecsSchema), credentialSubject);
129
+ validateSchema(JSON.parse(ecsSchema), Object.assign({ id }, claims));
345
130
  return claims;
346
131
  }
132
+ function schemaViolations(ecsSchema, credentialSubject) {
133
+ var _a, _b;
134
+ const validate = ajv.compile((_a = ecsSchema.properties) === null || _a === void 0 ? void 0 : _a.credentialSubject);
135
+ if (validate(credentialSubject))
136
+ return [];
137
+ return ((_b = validate.errors) !== null && _b !== void 0 ? _b : []).map(e => { var _a; return ({ path: e.instancePath, message: (_a = e.message) !== null && _a !== void 0 ? _a : e.keyword }); });
138
+ }
347
139
  /**
348
140
  * Validate a validateSchema object against the corresponding AJV schema.
349
141
  * Throws an Error if the schema is missing or validation fails.
350
142
  */
351
143
  function validateSchema(ecsSchema, credentialSubject) {
352
- var _a, _b;
353
- const validate = ajv.compile((_a = ecsSchema.properties) === null || _a === void 0 ? void 0 : _a.credentialSubject);
354
- const isValid = validate(credentialSubject);
355
- if (!isValid) {
356
- const errorDetails = (_b = validate.errors) === null || _b === void 0 ? void 0 : _b.map(e => ({
357
- message: e.message,
358
- path: e.instancePath,
359
- keyword: e.keyword,
360
- params: e.params,
361
- }));
362
- throw new Error(`Invalid claims for ${ecsSchema.$id}: ${JSON.stringify(errorDetails, null, 2)}`);
144
+ const violations = schemaViolations(ecsSchema, credentialSubject);
145
+ if (violations.length > 0) {
146
+ throw new Error(`Invalid claims for ${ecsSchema.$id}: ${JSON.stringify(violations, null, 2)}`);
147
+ }
148
+ }
149
+ async function fetchSchemaContent(id) {
150
+ try {
151
+ const response = await fetch((0, vs_agent_model_1.mapToEcosystem)(id));
152
+ if (!response.ok)
153
+ return { error: `${response.status} ${response.statusText}` };
154
+ return { content: await response.text() };
155
+ }
156
+ catch (error) {
157
+ return { error: error instanceof Error ? error.message : String(error) };
363
158
  }
364
159
  }
365
160
  /**
@@ -374,15 +169,16 @@ function validateSchema(ecsSchema, credentialSubject) {
374
169
  * @throws Error if both the fetch and local fallback fail.
375
170
  */
376
171
  async function addDigestSRI(id, data, ecsSchemas) {
172
+ var _a;
377
173
  if (!id || !data) {
378
174
  throw new Error(`id and data has requiered`);
379
175
  }
380
- const response = await fetch((0, vs_agent_model_1.mapToEcosystem)(id));
176
+ const fetched = await fetchSchemaContent(id);
381
177
  const key = id.split('/').pop();
382
178
  const fallbackSchema = key && (ecsSchemas === null || ecsSchemas === void 0 ? void 0 : ecsSchemas[key]);
383
- const schemaContent = response.ok ? await response.text() : fallbackSchema;
179
+ const schemaContent = (_a = fetched.content) !== null && _a !== void 0 ? _a : fallbackSchema;
384
180
  if (!schemaContent) {
385
- throw new Error(`Failed to fetch schema from ${id}: ${response.status} ${response.statusText}, and no local fallback found.`);
181
+ throw new Error(`Failed to fetch schema from ${id}: ${fetched.error}, and no local fallback found.`);
386
182
  }
387
183
  assertValidSchema(schemaContent, id);
388
184
  return Object.assign(Object.assign({}, data), { digestSRI: generateDigestSRI(schemaContent) });
@@ -404,23 +200,8 @@ function assertValidSchema(schemaContent, id) {
404
200
  throw new Error(`Schema from ${id} is not valid: ${message}`);
405
201
  }
406
202
  }
407
- /**
408
- * Generates a SRI digest string for the given content using the specified algorithm.
409
- * @param content - The content to hash.
410
- * @param algorithm - The hash algorithm to use (default: sha256).
411
- * @returns The SRI digest string.
412
- */
413
- function generateDigestSRI(content, algorithm = 'sha384') {
414
- const hash = (0, crypto_1.createHash)(algorithm).update(content).digest('base64');
415
- return `${algorithm}-${hash}`;
416
- }
417
- /**
418
- * Digest of the resource a credential references. Throws rather than attest content it could
419
- * not read: a wrong digestSRI is a false integrity claim in a signed credential.
420
- */
421
- async function urlDigestSri(url) {
422
- const response = await axios_1.default.get(url, { responseType: 'arraybuffer', timeout: DIGEST_FETCH_TIMEOUT_MS });
423
- return `sha384-${(0, crypto_1.createHash)('sha384').update(Buffer.from(response.data)).digest('base64')}`;
203
+ function generateDigestSRI(content) {
204
+ return (0, boundedFetch_1.digestOfBytes)(content);
424
205
  }
425
206
  function getVerificationMethodId(logger, didRecord) {
426
207
  var _a, _b;
@@ -431,7 +212,7 @@ function getVerificationMethodId(logger, didRecord) {
431
212
  method.id === ((_b = (_a = didRecord.didDocument) === null || _a === void 0 ? void 0 : _a.assertionMethod) === null || _b === void 0 ? void 0 : _b[0]);
432
213
  });
433
214
  if (!verificationMethod) {
434
- throw new Error('Cannot find a suitable Ed25519Signature2020 verification method in DID Document');
215
+ throw new Error('Cannot find a suitable Ed25519 verification method in DID Document');
435
216
  }
436
217
  return verificationMethod.id;
437
218
  }