@verana-labs/vs-agent-sdk 2.0.0-dev.7 → 2.0.0-dev.70
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 +27 -0
- package/build/adminApi/AdminApiError.js +59 -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 +17 -34
- package/build/agent/VsAgent.js +75 -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 +25 -14
- package/build/blockchain/VeranaChainService.js +123 -113
- 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/handlers/authorizationHandlers.js +2 -2
- package/build/blockchain/handlers/authorizationHandlers.js.map +1 -1
- package/build/blockchain/handlers/defaultHandlers.js +2 -0
- 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 +71 -0
- package/build/blockchain/handlers/selfIssuanceHandlers.js.map +1 -0
- package/build/blockchain/handlers/stateMutations.d.ts +21 -2
- package/build/blockchain/handlers/stateMutations.js +285 -37
- package/build/blockchain/handlers/stateMutations.js.map +1 -1
- package/build/blockchain/index.d.ts +2 -0
- package/build/blockchain/index.js +2 -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/types.d.ts +13 -58
- package/build/blockchain/types.js.map +1 -1
- package/build/bootstrap/EcsBootstrapService.d.ts +14 -3
- package/build/bootstrap/EcsBootstrapService.js +166 -76
- 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 +129 -82
- 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 +27 -18
- 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 +7 -0
- 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/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 +47 -0
- package/build/utils/ecsClaims.js +120 -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 +4 -0
- package/build/utils/index.js +4 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/selfIssuedEcsCredential.d.ts +8 -0
- package/build/utils/selfIssuedEcsCredential.js +151 -0
- package/build/utils/selfIssuedEcsCredential.js.map +1 -0
- package/build/utils/setupSelfTr.d.ts +34 -66
- package/build/utils/setupSelfTr.js +89 -295
- package/build/utils/setupSelfTr.js.map +1 -1
- package/build/utils/trustCredentialStore.d.ts +67 -9
- package/build/utils/trustCredentialStore.js +296 -111
- package/build/utils/trustCredentialStore.js.map +1 -1
- package/build/utils/util.d.ts +10 -0
- package/build/utils/util.js +16 -0
- package/build/utils/util.js.map +1 -1
- package/build/utils/vcdm2.d.ts +34 -0
- package/build/utils/vcdm2.js +62 -0
- package/build/utils/vcdm2.js.map +1 -0
- package/build/utils/vtjscResolver.d.ts +18 -0
- package/build/utils/vtjscResolver.js +54 -0
- package/build/utils/vtjscResolver.js.map +1 -0
- package/build/vtFlow/VtFlowOrchestrator.d.ts +84 -13
- package/build/vtFlow/VtFlowOrchestrator.js +505 -107
- 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 +17 -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
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitUntilOwnDidIsPubliclyResolvable = waitUntilOwnDidIsPubliclyResolvable;
|
|
4
|
+
// On a fresh deployment, the ingress route to this agent's own public endpoint
|
|
5
|
+
// can lag a few seconds behind the process becoming ready (e.g. a k8s Service
|
|
6
|
+
// has not finished propagating the new pod IP yet). A peer resolves our DID as
|
|
7
|
+
// part of processing any message we send it, so we wait for our own DID
|
|
8
|
+
// document to be publicly fetchable before reaching out to one.
|
|
9
|
+
const OWN_DID_READY_TIMEOUT_MS = 60000;
|
|
10
|
+
const OWN_DID_READY_POLL_INTERVAL_MS = 2000;
|
|
11
|
+
/**
|
|
12
|
+
* Waits until this agent's own DID document is fetchable at its public endpoint, so a peer
|
|
13
|
+
* can resolve it as soon as we reach out. Checks the same file a peer's resolver would fetch:
|
|
14
|
+
* did.jsonl for did:webvh, did.json for did:web. Logs and returns if the deadline passes,
|
|
15
|
+
* rather than blocking the caller forever on a misconfigured deployment.
|
|
16
|
+
*/
|
|
17
|
+
async function waitUntilOwnDidIsPubliclyResolvable(agent, logger) {
|
|
18
|
+
const did = agent.did;
|
|
19
|
+
if (!did || !agent.publicApiBaseUrl)
|
|
20
|
+
return;
|
|
21
|
+
const documentFile = did.startsWith('did:web:') ? 'did.json' : 'did.jsonl';
|
|
22
|
+
const baseUrl = agent.publicApiBaseUrl.replace(/\/+$/, '');
|
|
23
|
+
// A path-based DID location serves its document at <base>/did.json(l), not under /.well-known
|
|
24
|
+
const hasPath = new URL(baseUrl).pathname !== '/';
|
|
25
|
+
const url = hasPath ? `${baseUrl}/${documentFile}` : `${baseUrl}/.well-known/${documentFile}`;
|
|
26
|
+
const deadline = Date.now() + OWN_DID_READY_TIMEOUT_MS;
|
|
27
|
+
let lastStatus = 'unreachable';
|
|
28
|
+
while (Date.now() < deadline) {
|
|
29
|
+
try {
|
|
30
|
+
const response = await fetch(url);
|
|
31
|
+
if (response.ok)
|
|
32
|
+
return;
|
|
33
|
+
lastStatus = response.status;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
lastStatus = error.message;
|
|
37
|
+
}
|
|
38
|
+
await new Promise(resolve => setTimeout(resolve, OWN_DID_READY_POLL_INTERVAL_MS));
|
|
39
|
+
}
|
|
40
|
+
logger.warn(`[DidReadiness] own DID document at ${url} was not publicly resolvable after ${OWN_DID_READY_TIMEOUT_MS}ms (last: ${lastStatus}); proceeding anyway`);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=didReadiness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"didReadiness.js","sourceRoot":"","sources":["../../src/utils/didReadiness.ts"],"names":[],"mappings":";;AAkBA,kFAyBC;AAvCD,+EAA+E;AAC/E,8EAA8E;AAC9E,+EAA+E;AAC/E,wEAAwE;AACxE,gEAAgE;AAChE,MAAM,wBAAwB,GAAG,KAAM,CAAA;AACvC,MAAM,8BAA8B,GAAG,IAAK,CAAA;AAE5C;;;;;GAKG;AACI,KAAK,UAAU,mCAAmC,CAAC,KAAc,EAAE,MAAc;IACtF,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAA;IACrB,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB;QAAE,OAAM;IAE3C,MAAM,YAAY,GAAG,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAA;IAC1E,MAAM,OAAO,GAAG,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAC1D,8FAA8F;IAC9F,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,QAAQ,KAAK,GAAG,CAAA;IACjD,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,IAAI,YAAY,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,gBAAgB,YAAY,EAAE,CAAA;IAE7F,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,wBAAwB,CAAA;IACtD,IAAI,UAAU,GAAoB,aAAa,CAAA;IAC/C,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAA;YACjC,IAAI,QAAQ,CAAC,EAAE;gBAAE,OAAM;YACvB,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAA;QAC9B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,UAAU,GAAI,KAAe,CAAC,OAAO,CAAA;QACvC,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,8BAA8B,CAAC,CAAC,CAAA;IACnF,CAAC;IACD,MAAM,CAAC,IAAI,CACT,sCAAsC,GAAG,sCAAsC,wBAAwB,aAAa,UAAU,sBAAsB,CACrJ,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Logger } from '@credo-ts/core';
|
|
2
|
+
export interface EcsClaims {
|
|
3
|
+
localResources?: Record<string, string>;
|
|
4
|
+
org?: Record<string, string | undefined>;
|
|
5
|
+
persona?: Record<string, string | undefined>;
|
|
6
|
+
service?: Record<string, string | undefined>;
|
|
7
|
+
}
|
|
8
|
+
export declare const ECS_CLAIMS_VARIABLES: {
|
|
9
|
+
readonly org: {
|
|
10
|
+
readonly name: "ECS_CLAIMS_ORG_NAME";
|
|
11
|
+
readonly logoUri: "ECS_CLAIMS_ORG_LOGO_URI";
|
|
12
|
+
readonly registryId: "ECS_CLAIMS_ORG_REGISTRY_ID";
|
|
13
|
+
readonly registryUri: "ECS_CLAIMS_ORG_REGISTRY_URI";
|
|
14
|
+
readonly address: "ECS_CLAIMS_ORG_ADDRESS";
|
|
15
|
+
readonly countryCode: "ECS_CLAIMS_ORG_COUNTRY_CODE";
|
|
16
|
+
readonly legalJurisdiction: "ECS_CLAIMS_ORG_LEGAL_JURISDICTION";
|
|
17
|
+
readonly organizationKind: "ECS_CLAIMS_ORG_ORGANIZATION_KIND";
|
|
18
|
+
readonly lei: "ECS_CLAIMS_ORG_LEI";
|
|
19
|
+
};
|
|
20
|
+
readonly persona: {
|
|
21
|
+
readonly name: "ECS_CLAIMS_PERSONA_NAME";
|
|
22
|
+
readonly description: "ECS_CLAIMS_PERSONA_DESCRIPTION";
|
|
23
|
+
readonly descriptionFormat: "ECS_CLAIMS_PERSONA_DESCRIPTION_FORMAT";
|
|
24
|
+
readonly avatarUri: "ECS_CLAIMS_PERSONA_AVATAR_URI";
|
|
25
|
+
readonly controllerCountryCode: "ECS_CLAIMS_PERSONA_CONTROLLER_COUNTRY_CODE";
|
|
26
|
+
readonly controllerJurisdiction: "ECS_CLAIMS_PERSONA_CONTROLLER_JURISDICTION";
|
|
27
|
+
};
|
|
28
|
+
readonly service: {
|
|
29
|
+
readonly name: "ECS_CLAIMS_SERVICE_NAME";
|
|
30
|
+
readonly type: "ECS_CLAIMS_SERVICE_TYPE";
|
|
31
|
+
readonly description: "ECS_CLAIMS_SERVICE_DESCRIPTION";
|
|
32
|
+
readonly descriptionFormat: "ECS_CLAIMS_SERVICE_DESCRIPTION_FORMAT";
|
|
33
|
+
readonly logoUri: "ECS_CLAIMS_SERVICE_LOGO_URI";
|
|
34
|
+
readonly minimumAgeRequired: "ECS_CLAIMS_SERVICE_MINIMUM_AGE_REQUIRED";
|
|
35
|
+
readonly termsAndConditionsUri: "ECS_CLAIMS_SERVICE_TERMS_AND_CONDITIONS_URI";
|
|
36
|
+
readonly privacyPolicyUri: "ECS_CLAIMS_SERVICE_PRIVACY_POLICY_URI";
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export declare function readEcsClaimsFromEnv(): Required<Pick<EcsClaims, 'org' | 'persona' | 'service'>>;
|
|
40
|
+
export declare function digestOf(content: string): string;
|
|
41
|
+
export declare function digestOfUri(uri: string, variable: string, logger?: Logger): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Compose the claims of one ECS credential from the configured variables, deriving `id` and
|
|
44
|
+
* every paired `*DigestSri`. Returns undefined when the operator configured no claim, so the
|
|
45
|
+
* caller can omit the `claims` field entirely.
|
|
46
|
+
*/
|
|
47
|
+
export declare function composeEcsClaims(claims: EcsClaims, schemaKey: string, logger?: Logger): Promise<Record<string, unknown> | undefined>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ECS_CLAIMS_VARIABLES = void 0;
|
|
7
|
+
exports.readEcsClaimsFromEnv = readEcsClaimsFromEnv;
|
|
8
|
+
exports.digestOf = digestOf;
|
|
9
|
+
exports.digestOfUri = digestOfUri;
|
|
10
|
+
exports.composeEcsClaims = composeEcsClaims;
|
|
11
|
+
const crypto_1 = require("crypto");
|
|
12
|
+
const axios_1 = __importDefault(require("axios"));
|
|
13
|
+
// the URI claim each derived digest claim is computed from
|
|
14
|
+
const DIGEST_OF = {
|
|
15
|
+
logoDigestSri: 'logoUri',
|
|
16
|
+
avatarDigestSri: 'avatarUri',
|
|
17
|
+
termsAndConditionsDigestSri: 'termsAndConditionsUri',
|
|
18
|
+
privacyPolicyDigestSri: 'privacyPolicyUri',
|
|
19
|
+
};
|
|
20
|
+
// [VSA-VTI-CFG-ENV-ECS] variable of each claim the agent reads
|
|
21
|
+
exports.ECS_CLAIMS_VARIABLES = {
|
|
22
|
+
org: {
|
|
23
|
+
name: 'ECS_CLAIMS_ORG_NAME',
|
|
24
|
+
logoUri: 'ECS_CLAIMS_ORG_LOGO_URI',
|
|
25
|
+
registryId: 'ECS_CLAIMS_ORG_REGISTRY_ID',
|
|
26
|
+
registryUri: 'ECS_CLAIMS_ORG_REGISTRY_URI',
|
|
27
|
+
address: 'ECS_CLAIMS_ORG_ADDRESS',
|
|
28
|
+
countryCode: 'ECS_CLAIMS_ORG_COUNTRY_CODE',
|
|
29
|
+
legalJurisdiction: 'ECS_CLAIMS_ORG_LEGAL_JURISDICTION',
|
|
30
|
+
organizationKind: 'ECS_CLAIMS_ORG_ORGANIZATION_KIND',
|
|
31
|
+
lei: 'ECS_CLAIMS_ORG_LEI',
|
|
32
|
+
},
|
|
33
|
+
persona: {
|
|
34
|
+
name: 'ECS_CLAIMS_PERSONA_NAME',
|
|
35
|
+
description: 'ECS_CLAIMS_PERSONA_DESCRIPTION',
|
|
36
|
+
descriptionFormat: 'ECS_CLAIMS_PERSONA_DESCRIPTION_FORMAT',
|
|
37
|
+
avatarUri: 'ECS_CLAIMS_PERSONA_AVATAR_URI',
|
|
38
|
+
controllerCountryCode: 'ECS_CLAIMS_PERSONA_CONTROLLER_COUNTRY_CODE',
|
|
39
|
+
controllerJurisdiction: 'ECS_CLAIMS_PERSONA_CONTROLLER_JURISDICTION',
|
|
40
|
+
},
|
|
41
|
+
service: {
|
|
42
|
+
name: 'ECS_CLAIMS_SERVICE_NAME',
|
|
43
|
+
type: 'ECS_CLAIMS_SERVICE_TYPE',
|
|
44
|
+
description: 'ECS_CLAIMS_SERVICE_DESCRIPTION',
|
|
45
|
+
descriptionFormat: 'ECS_CLAIMS_SERVICE_DESCRIPTION_FORMAT',
|
|
46
|
+
logoUri: 'ECS_CLAIMS_SERVICE_LOGO_URI',
|
|
47
|
+
minimumAgeRequired: 'ECS_CLAIMS_SERVICE_MINIMUM_AGE_REQUIRED',
|
|
48
|
+
termsAndConditionsUri: 'ECS_CLAIMS_SERVICE_TERMS_AND_CONDITIONS_URI',
|
|
49
|
+
privacyPolicyUri: 'ECS_CLAIMS_SERVICE_PRIVACY_POLICY_URI',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
function readEcsClaimsFromEnv() {
|
|
53
|
+
const read = (variables) => Object.fromEntries(Object.entries(variables).map(([claim, name]) => { var _a; return [claim, ((_a = process.env[name]) === null || _a === void 0 ? void 0 : _a.trim()) || undefined]; }));
|
|
54
|
+
return {
|
|
55
|
+
org: read(exports.ECS_CLAIMS_VARIABLES.org),
|
|
56
|
+
persona: read(exports.ECS_CLAIMS_VARIABLES.persona),
|
|
57
|
+
service: read(exports.ECS_CLAIMS_VARIABLES.service),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const DIGEST_TIMEOUT_MS = 5000;
|
|
61
|
+
const DIGEST_ATTEMPTS = 4;
|
|
62
|
+
const DIGEST_BASE_DELAY_MS = 500;
|
|
63
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
64
|
+
// Generate a SHA-384 digest for the given content
|
|
65
|
+
function digestOf(content) {
|
|
66
|
+
return `sha384-${(0, crypto_1.createHash)('sha384').update(content).digest('base64')}`;
|
|
67
|
+
}
|
|
68
|
+
async function digestOfUri(uri, variable, logger) {
|
|
69
|
+
let lastError;
|
|
70
|
+
for (let attempt = 1; attempt <= DIGEST_ATTEMPTS; attempt++) {
|
|
71
|
+
try {
|
|
72
|
+
const response = await axios_1.default.get(uri, { responseType: 'arraybuffer', timeout: DIGEST_TIMEOUT_MS });
|
|
73
|
+
return `sha384-${(0, crypto_1.createHash)('sha384').update(Buffer.from(response.data)).digest('base64')}`;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
lastError = error;
|
|
77
|
+
if (attempt < DIGEST_ATTEMPTS)
|
|
78
|
+
await sleep(DIGEST_BASE_DELAY_MS * 2 ** (attempt - 1));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const message = `cannot compute the digest of ${variable} (${uri}): ${lastError === null || lastError === void 0 ? void 0 : lastError.message}`;
|
|
82
|
+
logger === null || logger === void 0 ? void 0 : logger.error(`[ecs-claims] ${message}`);
|
|
83
|
+
throw new Error(message);
|
|
84
|
+
}
|
|
85
|
+
const GROUP_OF = {
|
|
86
|
+
'ecs-service': 'service',
|
|
87
|
+
'ecs-persona': 'persona',
|
|
88
|
+
'ecs-org': 'org',
|
|
89
|
+
};
|
|
90
|
+
const groupOf = (claims, schemaKey) => {
|
|
91
|
+
const group = GROUP_OF[schemaKey];
|
|
92
|
+
return group ? claims[group] : undefined;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Compose the claims of one ECS credential from the configured variables, deriving `id` and
|
|
96
|
+
* every paired `*DigestSri`. Returns undefined when the operator configured no claim, so the
|
|
97
|
+
* caller can omit the `claims` field entirely.
|
|
98
|
+
*/
|
|
99
|
+
async function composeEcsClaims(claims, schemaKey, logger) {
|
|
100
|
+
var _a;
|
|
101
|
+
const configured = groupOf(claims, schemaKey);
|
|
102
|
+
const set = Object.entries(configured !== null && configured !== void 0 ? configured : {}).filter(([, v]) => v !== undefined && v !== '');
|
|
103
|
+
if (set.length === 0)
|
|
104
|
+
return undefined;
|
|
105
|
+
const composed = {};
|
|
106
|
+
for (const [claim, value] of set) {
|
|
107
|
+
composed[claim] = claim === 'minimumAgeRequired' ? Number(value) : value;
|
|
108
|
+
}
|
|
109
|
+
for (const [digestClaim, uriClaim] of Object.entries(DIGEST_OF)) {
|
|
110
|
+
const uri = composed[uriClaim];
|
|
111
|
+
if (typeof uri !== 'string')
|
|
112
|
+
continue;
|
|
113
|
+
const group = GROUP_OF[schemaKey];
|
|
114
|
+
const variable = (group && exports.ECS_CLAIMS_VARIABLES[group][uriClaim]) || uriClaim;
|
|
115
|
+
const local = (_a = claims.localResources) === null || _a === void 0 ? void 0 : _a[uri];
|
|
116
|
+
composed[digestClaim] = local ? digestOf(local) : await digestOfUri(uri, variable, logger);
|
|
117
|
+
}
|
|
118
|
+
return composed;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=ecsClaims.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecsClaims.js","sourceRoot":"","sources":["../../src/utils/ecsClaims.ts"],"names":[],"mappings":";;;;;;AAyDA,oDAUC;AASD,4BAEC;AAED,kCAcC;AAkBD,4CAsBC;AApID,mCAAmC;AAEnC,kDAAyB;AAYzB,2DAA2D;AAC3D,MAAM,SAAS,GAA2B;IACxC,aAAa,EAAE,SAAS;IACxB,eAAe,EAAE,WAAW;IAC5B,2BAA2B,EAAE,uBAAuB;IACpD,sBAAsB,EAAE,kBAAkB;CAC3C,CAAA;AAED,+DAA+D;AAClD,QAAA,oBAAoB,GAAG;IAClC,GAAG,EAAE;QACH,IAAI,EAAE,qBAAqB;QAC3B,OAAO,EAAE,yBAAyB;QAClC,UAAU,EAAE,4BAA4B;QACxC,WAAW,EAAE,6BAA6B;QAC1C,OAAO,EAAE,wBAAwB;QACjC,WAAW,EAAE,6BAA6B;QAC1C,iBAAiB,EAAE,mCAAmC;QACtD,gBAAgB,EAAE,kCAAkC;QACpD,GAAG,EAAE,oBAAoB;KAC1B;IACD,OAAO,EAAE;QACP,IAAI,EAAE,yBAAyB;QAC/B,WAAW,EAAE,gCAAgC;QAC7C,iBAAiB,EAAE,uCAAuC;QAC1D,SAAS,EAAE,+BAA+B;QAC1C,qBAAqB,EAAE,4CAA4C;QACnE,sBAAsB,EAAE,4CAA4C;KACrE;IACD,OAAO,EAAE;QACP,IAAI,EAAE,yBAAyB;QAC/B,IAAI,EAAE,yBAAyB;QAC/B,WAAW,EAAE,gCAAgC;QAC7C,iB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AAC,CAAC,CAAC,CAAC,MAAM,WAAW,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;IAC5F,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { VsAgent } from '../agent/VsAgent';
|
|
2
|
+
export interface EcsServiceClaims {
|
|
3
|
+
name?: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
logoUri?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function ecsServiceClaims(agent: VsAgent): Promise<EcsServiceClaims | undefined>;
|
|
8
|
+
export declare function agentDisplayName(agent: VsAgent): Promise<string>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ecsServiceClaims = ecsServiceClaims;
|
|
4
|
+
exports.agentDisplayName = agentDisplayName;
|
|
5
|
+
const vs_agent_model_1 = require("@verana-labs/vs-agent-model");
|
|
6
|
+
const setupSelfTr_1 = require("./setupSelfTr");
|
|
7
|
+
// Read at call time, not at startup: the credential is published asynchronously after boot
|
|
8
|
+
async function ecsServiceClaims(agent) {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
if (!agent.did)
|
|
11
|
+
return undefined;
|
|
12
|
+
const [didRecord] = await agent.dids.getCreatedDids({ did: agent.did });
|
|
13
|
+
const metadata = didRecord === null || didRecord === void 0 ? void 0 : didRecord.metadata.get('_vt/vtc');
|
|
14
|
+
if (!metadata)
|
|
15
|
+
return undefined;
|
|
16
|
+
const serviceId = `${agent.did}#${(0, setupSelfTr_1.linkedVpFragment)(vs_agent_model_1.ECS.SERVICE)}`;
|
|
17
|
+
return (_b = (_a = Object.values(metadata).find(entry => entry.didDocumentServiceId === serviceId)) === null || _a === void 0 ? void 0 : _a.credential) === null || _b === void 0 ? void 0 : _b.credentialSubject;
|
|
18
|
+
}
|
|
19
|
+
async function agentDisplayName(agent) {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
return (_b = (_a = (await ecsServiceClaims(agent))) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : new URL(agent.publicApiBaseUrl).host;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=ecsService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecsService.js","sourceRoot":"","sources":["../../src/utils/ecsService.ts"],"names":[],"mappings":";;AAkBA,4CAUC;AAED,4CAEC;AA9BD,gEAAiD;AAEjD,+CAAgD;AAahD,2FAA2F;AACpF,KAAK,UAAU,gBAAgB,CAAC,KAAc;;IACnD,IAAI,CAAC,KAAK,CAAC,GAAG;QAAE,OAAO,SAAS,CAAA;IAEhC,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAA;IACvE,MAAM,QAAQ,GAAG,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAyC,CAAA;IAC3F,IAAI,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAA;IAE/B,MAAM,SAAS,GAAG,GAAG,KAAK,CAAC,GAAG,IAAI,IAAA,8BAAgB,EAAC,oBAAG,CAAC,OAAO,CAAC,EAAE,CAAA;IACjE,OAAO,MAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,oBAAoB,KAAK,SAAS,CAAC,0CAAE,UAAU,0CAC9F,iBAAiD,CAAA;AACvD,CAAC;AAEM,KAAK,UAAU,gBAAgB,CAAC,KAAc;;IACnD,OAAO,MAAA,MAAA,CAAC,MAAM,gBAAgB,CAAC,KAAK,CAAC,CAAC,0CAAE,IAAI,mCAAI,IAAI,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAA;AACtF,CAAC"}
|
package/build/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export * from './agent';
|
|
2
2
|
export * from './data';
|
|
3
|
+
export * from './ecsClaims';
|
|
4
|
+
export * from './ecsService';
|
|
3
5
|
export * from './setupSelfTr';
|
|
4
6
|
export * from './trustCredentialStore';
|
|
5
7
|
export * from './util';
|
|
8
|
+
export * from './vcdm2';
|
|
9
|
+
export * from './vtjscResolver';
|
package/build/utils/index.js
CHANGED
|
@@ -16,7 +16,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./agent"), exports);
|
|
18
18
|
__exportStar(require("./data"), exports);
|
|
19
|
+
__exportStar(require("./ecsClaims"), exports);
|
|
20
|
+
__exportStar(require("./ecsService"), exports);
|
|
19
21
|
__exportStar(require("./setupSelfTr"), exports);
|
|
20
22
|
__exportStar(require("./trustCredentialStore"), exports);
|
|
21
23
|
__exportStar(require("./util"), exports);
|
|
24
|
+
__exportStar(require("./vcdm2"), exports);
|
|
25
|
+
__exportStar(require("./vtjscResolver"), exports);
|
|
22
26
|
//# sourceMappingURL=index.js.map
|
package/build/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,yCAAsB;AACtB,gDAA6B;AAC7B,yDAAsC;AACtC,yCAAsB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,yCAAsB;AACtB,8CAA2B;AAC3B,+CAA4B;AAC5B,gDAA6B;AAC7B,yDAAsC;AACtC,yCAAsB;AACtB,0CAAuB;AACvB,kDAA+B"}
|
|
@@ -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, type: string[], credentialSchema: W3cCredentialSchema, ecsClaims: EcsClaims, beforePublish?: (verifiablePresentation: SelfIssuedEcsPresentation) => Promise<void>): Promise<SelfIssuedEcsPresentation>;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.publishSelfIssuedEcsPresentation = publishSelfIssuedEcsPresentation;
|
|
4
|
+
const core_1 = require("@credo-ts/core");
|
|
5
|
+
const setupSelfTr_1 = require("./setupSelfTr");
|
|
6
|
+
const vcdm2_1 = require("./vcdm2");
|
|
7
|
+
const buildIntegrityData = (data) => {
|
|
8
|
+
return (0, setupSelfTr_1.generateDigestSRI)(JSON.stringify((0, setupSelfTr_1.sortKeysDeep)(data)));
|
|
9
|
+
};
|
|
10
|
+
function storedCredentialIsCurrent(credential, credentialSchemaId, did, didRecord) {
|
|
11
|
+
var _a, _b, _c;
|
|
12
|
+
if (!credential)
|
|
13
|
+
return false;
|
|
14
|
+
// a credential published by an older agent as data model 1.1 is rebuilt on upgrade
|
|
15
|
+
if (!(0, vcdm2_1.isDataIntegrityVcdm2Credential)(credential))
|
|
16
|
+
return false;
|
|
17
|
+
const issuer = typeof credential.issuer === 'string' ? credential.issuer : (_a = credential.issuer) === null || _a === void 0 ? void 0 : _a.id;
|
|
18
|
+
if (issuer !== did)
|
|
19
|
+
return false;
|
|
20
|
+
const schema = Array.isArray(credential.credentialSchema)
|
|
21
|
+
? credential.credentialSchema[0]
|
|
22
|
+
: credential.credentialSchema;
|
|
23
|
+
if ((schema === null || schema === void 0 ? void 0 : schema.id) !== credentialSchemaId)
|
|
24
|
+
return false;
|
|
25
|
+
const proofs = !credential.proof
|
|
26
|
+
? []
|
|
27
|
+
: Array.isArray(credential.proof)
|
|
28
|
+
? credential.proof
|
|
29
|
+
: [credential.proof];
|
|
30
|
+
if (proofs.length === 0)
|
|
31
|
+
return false;
|
|
32
|
+
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));
|
|
33
|
+
return proofs.every(proof => !!proof.verificationMethod && assertionMethods.has(proof.verificationMethod));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Issues the ECS credential to the agent itself and wraps it in the linked presentation, both
|
|
37
|
+
* secured with a DataIntegrityProof by the DID Document assertion key.
|
|
38
|
+
*/
|
|
39
|
+
async function signSelfIssuedEcsCredential(agent, didRecord, presentationId, type, claims, credentialSchema) {
|
|
40
|
+
const unsignedCredential = (0, setupSelfTr_1.createCredential)({
|
|
41
|
+
id: agent.did,
|
|
42
|
+
type,
|
|
43
|
+
issuer: agent.did,
|
|
44
|
+
credentialSubject: Object.assign(Object.assign({}, claims), { id: agent.did }),
|
|
45
|
+
credentialSchema: { id: credentialSchema.id, type: credentialSchema.type },
|
|
46
|
+
});
|
|
47
|
+
const verificationMethodId = (0, setupSelfTr_1.getVerificationMethodId)(agent.config.logger, didRecord);
|
|
48
|
+
const signedCredential = await (0, setupSelfTr_1.signerW3c)(agent, unsignedCredential, verificationMethodId);
|
|
49
|
+
const presentation = (0, setupSelfTr_1.createPresentation)({
|
|
50
|
+
id: presentationId,
|
|
51
|
+
holder: agent.did,
|
|
52
|
+
verifiableCredential: [signedCredential],
|
|
53
|
+
});
|
|
54
|
+
const signedPresentation = await (0, setupSelfTr_1.signerW3c)(agent, presentation, verificationMethodId);
|
|
55
|
+
return signedPresentation.securedPresentation;
|
|
56
|
+
}
|
|
57
|
+
async function publishSelfIssuedEcsPresentation(agent, id, ecsSchemas, schemaKey, type, credentialSchema, ecsClaims, beforePublish) {
|
|
58
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
59
|
+
if (!agent.did)
|
|
60
|
+
throw Error('The DID must be set up');
|
|
61
|
+
const [didRecord] = await agent.dids.getCreatedDids({ did: agent.did });
|
|
62
|
+
const didDocument = didRecord.didDocument;
|
|
63
|
+
if (!didDocument)
|
|
64
|
+
throw Error('The DID Document must be set up');
|
|
65
|
+
const claims = await (0, setupSelfTr_1.getClaims)(agent.config.logger, ecsSchemas, { id: agent.did }, schemaKey, ecsClaims);
|
|
66
|
+
const didDocumentServiceId = `${agent.did}#${(0, setupSelfTr_1.linkedVpFragment)(schemaKey)}`;
|
|
67
|
+
const integrityData = buildIntegrityData({ id, type, credentialSchema, claims });
|
|
68
|
+
const record = (_a = didRecord.metadata.get('_vt/vtc')) !== null && _a !== void 0 ? _a : {};
|
|
69
|
+
const metadata = record[credentialSchema.id];
|
|
70
|
+
const superseded = Object.entries(record).some(([storedSchemaId, entry]) => {
|
|
71
|
+
var _a;
|
|
72
|
+
return storedSchemaId !== credentialSchema.id &&
|
|
73
|
+
((_a = entry === null || entry === void 0 ? void 0 : entry.verifiablePresentation) === null || _a === void 0 ? void 0 : _a.id) === id &&
|
|
74
|
+
(entry === null || entry === void 0 ? void 0 : entry.attached) !== false;
|
|
75
|
+
});
|
|
76
|
+
const attached = ((_b = metadata === null || metadata === void 0 ? void 0 : metadata.attached) !== null && _b !== void 0 ? _b : true) && !superseded;
|
|
77
|
+
if ((metadata === null || metadata === void 0 ? void 0 : metadata.integrityData) === integrityData &&
|
|
78
|
+
storedCredentialIsCurrent(metadata === null || metadata === void 0 ? void 0 : metadata.credential, credentialSchema.id, agent.did, didRecord)) {
|
|
79
|
+
// the presentation is already public, so a failed beforePublish step still needs a retry here
|
|
80
|
+
if (attached)
|
|
81
|
+
await (beforePublish === null || beforePublish === void 0 ? void 0 : beforePublish(metadata.verifiablePresentation));
|
|
82
|
+
return metadata.verifiablePresentation;
|
|
83
|
+
}
|
|
84
|
+
const verifiablePresentation = await signSelfIssuedEcsCredential(agent, didRecord, id, type, claims, credentialSchema);
|
|
85
|
+
// nothing is persisted yet, so a failure here leaves no public presentation behind
|
|
86
|
+
if (attached)
|
|
87
|
+
await (beforePublish === null || beforePublish === void 0 ? void 0 : beforePublish(verifiablePresentation));
|
|
88
|
+
// Update linked VP when the presentation has changed. Match by fragment or by the file the
|
|
89
|
+
// endpoint ends with: a `contains` test also matches the host, so an agent at a host such as
|
|
90
|
+
// ecs-org-issuer.example rewrote its DIDComm endpoint and every other ECS linked VP onto this one.
|
|
91
|
+
const linkedVpFile = `/${schemaKey}-vtc-vp.json`;
|
|
92
|
+
if (attached)
|
|
93
|
+
didDocument.service = (_c = didDocument.service) === null || _c === void 0 ? void 0 : _c.map(s => {
|
|
94
|
+
if (typeof s.serviceEndpoint !== 'string')
|
|
95
|
+
return s;
|
|
96
|
+
if (s.type !== 'LinkedVerifiablePresentation' || s.id === `${agent.did}#whois`)
|
|
97
|
+
return s;
|
|
98
|
+
if (s.id !== didDocumentServiceId && !s.serviceEndpoint.endsWith(linkedVpFile))
|
|
99
|
+
return s;
|
|
100
|
+
s.id = didDocumentServiceId;
|
|
101
|
+
s.serviceEndpoint = id;
|
|
102
|
+
return s;
|
|
103
|
+
});
|
|
104
|
+
// Resolvers only discover the credential through the [VT-CRED-W3C-LINKED-VP] fragment, and
|
|
105
|
+
// #whois does not match it. The rename above only covers documents that already carry the
|
|
106
|
+
// service, so publish it here when nothing declared it yet.
|
|
107
|
+
let didDocumentChanged = false;
|
|
108
|
+
if (attached && !((_d = didDocument.service) === null || _d === void 0 ? void 0 : _d.some(s => s.id === didDocumentServiceId))) {
|
|
109
|
+
didDocument.service = [
|
|
110
|
+
...((_e = didDocument.service) !== null && _e !== void 0 ? _e : []),
|
|
111
|
+
new core_1.DidDocumentService({
|
|
112
|
+
id: didDocumentServiceId,
|
|
113
|
+
serviceEndpoint: id,
|
|
114
|
+
type: 'LinkedVerifiablePresentation',
|
|
115
|
+
}),
|
|
116
|
+
];
|
|
117
|
+
didDocumentChanged = true;
|
|
118
|
+
}
|
|
119
|
+
const whoisId = `${agent.did}#whois`;
|
|
120
|
+
if (attached && schemaKey === 'ecs-service') {
|
|
121
|
+
const whois = (_f = didDocument.service) === null || _f === void 0 ? void 0 : _f.find(s => s.id === whoisId);
|
|
122
|
+
if (whois) {
|
|
123
|
+
if (whois.serviceEndpoint !== id) {
|
|
124
|
+
whois.serviceEndpoint = id;
|
|
125
|
+
didDocumentChanged = true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
didDocument.service = [
|
|
130
|
+
...((_g = didDocument.service) !== null && _g !== void 0 ? _g : []),
|
|
131
|
+
new core_1.DidDocumentService({ id: whoisId, serviceEndpoint: id, type: 'LinkedVerifiablePresentation' }),
|
|
132
|
+
];
|
|
133
|
+
didDocumentChanged = true;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const [credential] = verifiablePresentation.verifiableCredential;
|
|
137
|
+
record[credentialSchema.id] = {
|
|
138
|
+
credential,
|
|
139
|
+
verifiablePresentation,
|
|
140
|
+
didDocumentServiceId,
|
|
141
|
+
integrityData,
|
|
142
|
+
attached,
|
|
143
|
+
};
|
|
144
|
+
didRecord.metadata.set('_vt/vtc', record);
|
|
145
|
+
await agent.context.dependencyManager.resolve(core_1.DidRepository).update(agent.context, didRecord);
|
|
146
|
+
if (didDocumentChanged) {
|
|
147
|
+
await agent.dids.update({ did: didRecord.did, didDocument });
|
|
148
|
+
}
|
|
149
|
+
return verifiablePresentation;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=selfIssuedEcsCredential.js.map
|
|
@@ -0,0 +1 @@
|
|
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@@ -1,74 +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;
|
|
40
16
|
/**
|
|
41
|
-
*
|
|
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.
|
|
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
|
-
* @returns The signed verifiable presentation, with integrity metadata.
|
|
69
|
-
*/
|
|
70
|
-
export declare function generateVerifiablePresentation(agent: VsAgent, id: string, ecsSchemas: Record<string, string>, schemaKey: string, type: string[], credentialSchema: W3cCredentialSchema, defaults: SelfTrDefaults): Promise<any>;
|
|
71
|
-
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;
|
|
72
40
|
/**
|
|
73
41
|
* Retrieves and validates claims for a credential subject.
|
|
74
42
|
* If claims are not found, builds default claims based on the schemaKey.
|
|
@@ -80,7 +48,12 @@ export declare function createPresentation(options: Partial<W3cPresentationOptio
|
|
|
80
48
|
* @returns The validated claims object.
|
|
81
49
|
* @throws If claims are invalid or schema is missing.
|
|
82
50
|
*/
|
|
83
|
-
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[];
|
|
84
57
|
/**
|
|
85
58
|
* Validate a validateSchema object against the corresponding AJV schema.
|
|
86
59
|
* Throws an Error if the schema is missing or validation fails.
|
|
@@ -107,9 +80,4 @@ export declare function addDigestSRI<T extends object>(id?: string, data?: T, ec
|
|
|
107
80
|
* @returns The SRI digest string.
|
|
108
81
|
*/
|
|
109
82
|
export declare function generateDigestSRI(content: string, algorithm?: string): string;
|
|
110
|
-
/**
|
|
111
|
-
* Digest of the resource a credential references. Throws rather than attest content it could
|
|
112
|
-
* not read: a wrong digestSRI is a false integrity claim in a signed credential.
|
|
113
|
-
*/
|
|
114
|
-
export declare function urlDigestSri(url: string): Promise<string>;
|
|
115
83
|
export declare function getVerificationMethodId(logger: Logger, didRecord: DidRecord): string;
|