@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.
- package/README.md +0 -2
- package/build/adminApi/AdminApiError.d.ts +28 -0
- package/build/adminApi/AdminApiError.js +60 -0
- package/build/adminApi/AdminApiError.js.map +1 -0
- package/build/adminApi/didcommModules.d.ts +2 -0
- package/build/adminApi/didcommModules.js +8 -0
- package/build/adminApi/didcommModules.js.map +1 -0
- package/build/adminApi/index.d.ts +4 -0
- package/build/adminApi/index.js +21 -0
- package/build/adminApi/index.js.map +1 -0
- package/build/adminApi/moduleEndpoint.d.ts +8 -0
- package/build/adminApi/moduleEndpoint.js +28 -0
- package/build/adminApi/moduleEndpoint.js.map +1 -0
- package/build/adminApi/pagination/PageDto.d.ts +7 -0
- package/build/adminApi/pagination/PageDto.js +50 -0
- package/build/adminApi/pagination/PageDto.js.map +1 -0
- package/build/adminApi/pagination/PaginationQueryDto.d.ts +11 -0
- package/build/adminApi/pagination/PaginationQueryDto.js +46 -0
- package/build/adminApi/pagination/PaginationQueryDto.js.map +1 -0
- package/build/adminApi/pagination/cursor.d.ts +28 -0
- package/build/adminApi/pagination/cursor.js +64 -0
- package/build/adminApi/pagination/cursor.js.map +1 -0
- package/build/adminApi/pagination/index.d.ts +4 -0
- package/build/adminApi/pagination/index.js +21 -0
- package/build/adminApi/pagination/index.js.map +1 -0
- package/build/adminApi/pagination/paginate.d.ts +27 -0
- package/build/adminApi/pagination/paginate.js +77 -0
- package/build/adminApi/pagination/paginate.js.map +1 -0
- package/build/agent/VsAgent.d.ts +22 -34
- package/build/agent/VsAgent.js +84 -205
- package/build/agent/VsAgent.js.map +1 -1
- package/build/agent/createVsAgent.d.ts +5 -6
- package/build/agent/createVsAgent.js +3 -5
- package/build/agent/createVsAgent.js.map +1 -1
- package/build/blockchain/AnonCredsTrustService.d.ts +62 -0
- package/build/blockchain/AnonCredsTrustService.js +256 -0
- package/build/blockchain/AnonCredsTrustService.js.map +1 -0
- package/build/blockchain/AuthorizationService.d.ts +5 -3
- package/build/blockchain/AuthorizationService.js +17 -29
- package/build/blockchain/AuthorizationService.js.map +1 -1
- package/build/blockchain/IndexerWebSocketService.d.ts +7 -1
- package/build/blockchain/IndexerWebSocketService.js +68 -36
- package/build/blockchain/IndexerWebSocketService.js.map +1 -1
- package/build/blockchain/VeranaChainService.d.ts +38 -27
- package/build/blockchain/VeranaChainService.js +169 -177
- package/build/blockchain/VeranaChainService.js.map +1 -1
- package/build/blockchain/VeranaIndexerService.d.ts +14 -1
- package/build/blockchain/VeranaIndexerService.js +122 -8
- package/build/blockchain/VeranaIndexerService.js.map +1 -1
- package/build/blockchain/feePreflight.d.ts +32 -0
- package/build/blockchain/feePreflight.js +89 -0
- package/build/blockchain/feePreflight.js.map +1 -0
- package/build/blockchain/handlers/authorizationHandlers.js +2 -2
- package/build/blockchain/handlers/authorizationHandlers.js.map +1 -1
- package/build/blockchain/handlers/defaultHandlers.js +6 -1
- package/build/blockchain/handlers/defaultHandlers.js.map +1 -1
- package/build/blockchain/handlers/index.d.ts +1 -0
- package/build/blockchain/handlers/index.js +1 -0
- package/build/blockchain/handlers/index.js.map +1 -1
- package/build/blockchain/handlers/selfIssuanceHandlers.d.ts +13 -0
- package/build/blockchain/handlers/selfIssuanceHandlers.js +76 -0
- package/build/blockchain/handlers/selfIssuanceHandlers.js.map +1 -0
- package/build/blockchain/handlers/stateMutations.d.ts +26 -3
- package/build/blockchain/handlers/stateMutations.js +317 -41
- package/build/blockchain/handlers/stateMutations.js.map +1 -1
- package/build/blockchain/index.d.ts +4 -0
- package/build/blockchain/index.js +4 -0
- package/build/blockchain/index.js.map +1 -1
- package/build/blockchain/indexerMappers.d.ts +3 -0
- package/build/blockchain/indexerMappers.js +53 -0
- package/build/blockchain/indexerMappers.js.map +1 -0
- package/build/blockchain/triggerResolver.d.ts +26 -0
- package/build/blockchain/triggerResolver.js +120 -0
- package/build/blockchain/triggerResolver.js.map +1 -0
- package/build/blockchain/types.d.ts +13 -70
- package/build/blockchain/types.js.map +1 -1
- package/build/bootstrap/EcsBootstrapService.d.ts +13 -3
- package/build/bootstrap/EcsBootstrapService.js +172 -94
- package/build/bootstrap/EcsBootstrapService.js.map +1 -1
- package/build/connections/ParentConnectionModule.d.ts +20 -0
- package/build/connections/ParentConnectionModule.js +56 -0
- package/build/connections/ParentConnectionModule.js.map +1 -0
- package/build/credentials/FullTailsFileService.d.ts +0 -1
- package/build/credentials/FullTailsFileService.js +0 -49
- package/build/credentials/FullTailsFileService.js.map +1 -1
- package/build/did/CachedDocumentLoader.d.ts +3 -0
- package/build/did/CachedDocumentLoader.js +7 -1
- package/build/did/CachedDocumentLoader.js.map +1 -1
- package/build/did/CachedWebDidResolver.d.ts +0 -4
- package/build/did/CachedWebDidResolver.js +1 -5
- package/build/did/CachedWebDidResolver.js.map +1 -1
- package/build/did/artifactServices.d.ts +12 -0
- package/build/did/artifactServices.js +48 -0
- package/build/did/artifactServices.js.map +1 -0
- package/build/did/legacyDidWeb.d.ts +6 -4
- package/build/did/legacyDidWeb.js +17 -14
- package/build/did/legacyDidWeb.js.map +1 -1
- package/build/did/publicDid.d.ts +4 -0
- package/build/did/publicDid.js +19 -0
- package/build/did/publicDid.js.map +1 -0
- package/build/events/BaseMessageEvents.js +139 -5
- package/build/events/BaseMessageEvents.js.map +1 -1
- package/build/events/ConnectionEvents.js +150 -86
- package/build/events/ConnectionEvents.js.map +1 -1
- package/build/events/VsAgentEvents.d.ts +11 -9
- package/build/events/VsAgentEvents.js +8 -1
- package/build/events/VsAgentEvents.js.map +1 -1
- package/build/events/VtFlowEvents.d.ts +1 -1
- package/build/events/VtFlowEvents.js +29 -17
- package/build/events/VtFlowEvents.js.map +1 -1
- package/build/index.d.ts +7 -1
- package/build/index.js +15 -2
- package/build/index.js.map +1 -1
- package/build/plugins/setupBaseDidComm.js +9 -12
- package/build/plugins/setupBaseDidComm.js.map +1 -1
- package/build/transports/VsAgentWsInboundTransport.d.ts +1 -1
- package/build/transports/VsAgentWsInboundTransport.js +20 -14
- package/build/transports/VsAgentWsInboundTransport.js.map +1 -1
- package/build/types.d.ts +14 -13
- package/build/types.js +1 -2
- package/build/types.js.map +1 -1
- package/build/utils/agent.d.ts +29 -4
- package/build/utils/agent.js +91 -22
- package/build/utils/agent.js.map +1 -1
- package/build/utils/boundedFetch.d.ts +13 -0
- package/build/utils/boundedFetch.js +47 -0
- package/build/utils/boundedFetch.js.map +1 -0
- package/build/utils/didReadiness.d.ts +9 -0
- package/build/utils/didReadiness.js +42 -0
- package/build/utils/didReadiness.js.map +1 -0
- package/build/utils/ecsClaims.d.ts +46 -0
- package/build/utils/ecsClaims.js +115 -0
- package/build/utils/ecsClaims.js.map +1 -0
- package/build/utils/ecsService.d.ts +8 -0
- package/build/utils/ecsService.js +23 -0
- package/build/utils/ecsService.js.map +1 -0
- package/build/utils/index.d.ts +7 -0
- package/build/utils/index.js +7 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/publishedDidRecord.d.ts +15 -0
- package/build/utils/publishedDidRecord.js +83 -0
- package/build/utils/publishedDidRecord.js.map +1 -0
- package/build/utils/selfIssuedEcsCredential.d.ts +8 -0
- package/build/utils/selfIssuedEcsCredential.js +153 -0
- package/build/utils/selfIssuedEcsCredential.js.map +1 -0
- package/build/utils/setupSelfTr.d.ts +35 -74
- package/build/utils/setupSelfTr.js +93 -312
- package/build/utils/setupSelfTr.js.map +1 -1
- package/build/utils/trustCredentialStore.d.ts +78 -9
- package/build/utils/trustCredentialStore.js +324 -136
- package/build/utils/trustCredentialStore.js.map +1 -1
- package/build/utils/typeMetadata.d.ts +43 -0
- package/build/utils/typeMetadata.js +77 -0
- package/build/utils/typeMetadata.js.map +1 -0
- package/build/utils/util.d.ts +19 -0
- package/build/utils/util.js +24 -0
- package/build/utils/util.js.map +1 -1
- package/build/utils/vcdm2.d.ts +34 -0
- package/build/utils/vcdm2.js +60 -0
- package/build/utils/vcdm2.js.map +1 -0
- package/build/utils/vtjscResolver.d.ts +23 -0
- package/build/utils/vtjscResolver.js +53 -0
- package/build/utils/vtjscResolver.js.map +1 -0
- package/build/vtFlow/VtFlowOrchestrator.d.ts +107 -15
- package/build/vtFlow/VtFlowOrchestrator.js +678 -116
- package/build/vtFlow/VtFlowOrchestrator.js.map +1 -1
- package/build/vtFlow/assertVerifiableService.d.ts +1 -0
- package/build/vtFlow/assertVerifiableService.js +45 -5
- package/build/vtFlow/assertVerifiableService.js.map +1 -1
- package/build/vtFlow/ecsIssuanceExemption.d.ts +12 -0
- package/build/vtFlow/ecsIssuanceExemption.js +84 -0
- package/build/vtFlow/ecsIssuanceExemption.js.map +1 -0
- package/build/vtFlow/index.d.ts +1 -0
- package/build/vtFlow/index.js +1 -0
- package/build/vtFlow/index.js.map +1 -1
- package/package.json +18 -12
- package/build/did/migrateWebVhLog.d.ts +0 -34
- package/build/did/migrateWebVhLog.js +0 -230
- package/build/did/migrateWebVhLog.js.map +0 -1
- package/build/did/migrateWebVhVersionTime.d.ts +0 -9
- package/build/did/migrateWebVhVersionTime.js +0 -191
- package/build/did/migrateWebVhVersionTime.js.map +0 -1
|
@@ -1,75 +1,42 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export declare function createCredential(options: Partial<
|
|
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
|
-
*
|
|
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
|
-
*
|
|
44
|
-
*
|
|
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
|
|
34
|
+
* @returns The secured credential or presentation, wrapping the JSON that gets published.
|
|
50
35
|
*/
|
|
51
|
-
export declare function signerW3c(agent: VsAgent, obj:
|
|
52
|
-
export declare function signerW3c(agent: VsAgent, obj:
|
|
53
|
-
/**
|
|
54
|
-
|
|
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
|
|
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.
|
|
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
|
-
|
|
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
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
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
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
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.
|
|
65
|
+
exports.sortKeysDeep = sortKeysDeep;
|
|
103
66
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
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
|
-
|
|
71
|
+
function createCredential(options) {
|
|
124
72
|
var _a;
|
|
125
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return
|
|
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
|
|
181
|
-
if (obj instanceof core_1.
|
|
182
|
-
return await agent.
|
|
183
|
-
format: core_1.ClaimFormat.
|
|
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
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
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
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
-
|
|
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
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
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
|
|
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 =
|
|
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}: ${
|
|
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
|
-
|
|
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
|
|
215
|
+
throw new Error('Cannot find a suitable Ed25519 verification method in DID Document');
|
|
435
216
|
}
|
|
436
217
|
return verificationMethod.id;
|
|
437
218
|
}
|