@verana-labs/vs-agent-sdk 2.0.0-dev.11 → 2.0.0-dev.111
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 +67 -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 +7 -0
- package/build/adminApi/moduleEndpoint.js +21 -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 +30 -34
- package/build/agent/VsAgent.js +176 -221
- package/build/agent/VsAgent.js.map +1 -1
- package/build/agent/createVsAgent.d.ts +9 -6
- package/build/agent/createVsAgent.js +5 -5
- package/build/agent/createVsAgent.js.map +1 -1
- package/build/blockchain/AnonCredsTrustService.d.ts +115 -0
- package/build/blockchain/AnonCredsTrustService.js +287 -0
- package/build/blockchain/AnonCredsTrustService.js.map +1 -0
- package/build/blockchain/AuthorizationService.d.ts +8 -6
- package/build/blockchain/AuthorizationService.js +30 -38
- package/build/blockchain/AuthorizationService.js.map +1 -1
- package/build/blockchain/IndexerWebSocketService.d.ts +7 -2
- package/build/blockchain/IndexerWebSocketService.js +67 -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/IndexerHandlerRegistry.d.ts +0 -1
- package/build/blockchain/handlers/IndexerHandlerRegistry.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 +7 -2
- 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 +27 -4
- package/build/blockchain/handlers/stateMutations.js +331 -45
- 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 +110 -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 -4
- package/build/bootstrap/EcsBootstrapService.js +170 -124
- package/build/bootstrap/EcsBootstrapService.js.map +1 -1
- package/build/connections/InvitationRecord.d.ts +50 -0
- package/build/connections/InvitationRecord.js +60 -0
- package/build/connections/InvitationRecord.js.map +1 -0
- package/build/connections/ParentConnectionModule.d.ts +22 -0
- package/build/connections/ParentConnectionModule.js +91 -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 +9 -3
- 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/did/reusedDidDocument.d.ts +37 -0
- package/build/did/reusedDidDocument.js +93 -0
- package/build/did/reusedDidDocument.js.map +1 -0
- package/build/events/BaseMessageEvents.d.ts +24 -0
- package/build/events/BaseMessageEvents.js +368 -14
- package/build/events/BaseMessageEvents.js.map +1 -1
- package/build/events/ConnectionEvents.js +149 -87
- package/build/events/ConnectionEvents.js.map +1 -1
- package/build/events/InvitationEvents.d.ts +6 -0
- package/build/events/InvitationEvents.js +57 -0
- package/build/events/InvitationEvents.js.map +1 -0
- package/build/events/VsAgentEvents.d.ts +40 -9
- package/build/events/VsAgentEvents.js +10 -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/events/index.d.ts +1 -0
- package/build/events/index.js +1 -0
- package/build/events/index.js.map +1 -1
- package/build/index.d.ts +9 -1
- package/build/index.js +20 -2
- package/build/index.js.map +1 -1
- package/build/plugins/setupBaseDidComm.js +20 -21
- package/build/plugins/setupBaseDidComm.js.map +1 -1
- package/build/transports/HttpInboundTransport.js +6 -1
- package/build/transports/HttpInboundTransport.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 +42 -4
- package/build/utils/agent.js +126 -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.js +5 -2
- package/build/utils/didReadiness.js.map +1 -1
- 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 +158 -0
- package/build/utils/selfIssuedEcsCredential.js.map +1 -0
- package/build/utils/setupSelfTr.d.ts +34 -74
- package/build/utils/setupSelfTr.js +79 -321
- package/build/utils/setupSelfTr.js.map +1 -1
- package/build/utils/trustCredentialStore.d.ts +87 -9
- package/build/utils/trustCredentialStore.js +343 -137
- package/build/utils/trustCredentialStore.js.map +1 -1
- package/build/utils/typeMetadata.d.ts +44 -0
- package/build/utils/typeMetadata.js +89 -0
- package/build/utils/typeMetadata.js.map +1 -0
- package/build/utils/util.d.ts +20 -0
- package/build/utils/util.js +29 -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 +108 -15
- package/build/vtFlow/VtFlowOrchestrator.js +692 -118
- package/build/vtFlow/VtFlowOrchestrator.js.map +1 -1
- package/build/vtFlow/assertVerifiableService.d.ts +31 -2
- package/build/vtFlow/assertVerifiableService.js +68 -10
- 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 +27 -19
- 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,29 +1,101 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signLinkedDataIntegrityPresentation = signLinkedDataIntegrityPresentation;
|
|
3
4
|
exports.findMetadataEntry = findMetadataEntry;
|
|
4
5
|
exports.saveMetadataEntry = saveMetadataEntry;
|
|
5
6
|
exports.deleteMetadataEntry = deleteMetadataEntry;
|
|
6
7
|
exports.createVtc = createVtc;
|
|
7
8
|
exports.createJsc = createJsc;
|
|
8
9
|
exports.removeTrustCredential = removeTrustCredential;
|
|
10
|
+
exports.findExchangeCredentialId = findExchangeCredentialId;
|
|
9
11
|
exports.removeStoredTrustCredential = removeStoredTrustCredential;
|
|
10
12
|
exports.migrateVtjscServiceIds = migrateVtjscServiceIds;
|
|
13
|
+
exports.detachVtjscPublications = detachVtjscPublications;
|
|
14
|
+
exports.reattachVtjscPublication = reattachVtjscPublication;
|
|
11
15
|
exports.getTrustMetadata = getTrustMetadata;
|
|
16
|
+
exports.saveVtjscTypeMetadata = saveVtjscTypeMetadata;
|
|
17
|
+
exports.findVtjscTypeMetadata = findVtjscTypeMetadata;
|
|
12
18
|
exports.rebindEcsCredentialSchema = rebindEcsCredentialSchema;
|
|
19
|
+
exports.withdrawSelfIssuedEcsCredentials = withdrawSelfIssuedEcsCredentials;
|
|
13
20
|
const core_1 = require("@credo-ts/core");
|
|
21
|
+
// No type definitions available for this library
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
23
|
+
//@ts-expect-error
|
|
24
|
+
const jsonld_signatures_1 = require("jsonld-signatures");
|
|
14
25
|
const verre_1 = require("@verana-labs/verre");
|
|
15
|
-
const
|
|
26
|
+
const feePreflight_1 = require("../blockchain/feePreflight");
|
|
16
27
|
const setupSelfTr_1 = require("./setupSelfTr");
|
|
28
|
+
const selfIssuedEcsCredential_1 = require("./selfIssuedEcsCredential");
|
|
29
|
+
const publishedDidRecord_1 = require("./publishedDidRecord");
|
|
17
30
|
const data_1 = require("./data");
|
|
18
31
|
async function getDidRecord(agent) {
|
|
19
32
|
const [didRecord] = await agent.dids.getCreatedDids({ did: agent.did });
|
|
20
33
|
return didRecord;
|
|
21
34
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
/** The credential fields shared by both data models: id, credentialSchema and credentialSubject */
|
|
36
|
+
function trustCredentialFields(credential) {
|
|
37
|
+
return credential instanceof core_1.W3cV2DataIntegrityVerifiableCredential
|
|
38
|
+
? credential.resolvedCredential
|
|
39
|
+
: credential;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* What the metadata entry stores and the DID Document service endpoint serves. A data model 1.1
|
|
43
|
+
* presentation is kept as its class instance, which serializes to JSON-LD when the DID record is
|
|
44
|
+
* saved; a Data Integrity one wraps the secured JSON, so that is what gets stored.
|
|
45
|
+
*/
|
|
46
|
+
function trustCredentialEntry(credential) {
|
|
47
|
+
return credential instanceof core_1.W3cV2DataIntegrityVerifiableCredential
|
|
48
|
+
? credential.securedCredential
|
|
49
|
+
: credential.jsonCredential;
|
|
50
|
+
}
|
|
51
|
+
function trustPresentationEntry(presentation) {
|
|
52
|
+
return presentation instanceof core_1.W3cV2DataIntegrityVerifiablePresentation
|
|
53
|
+
? presentation.securedPresentation
|
|
54
|
+
: presentation;
|
|
55
|
+
}
|
|
56
|
+
function trustPresentationId(presentation) {
|
|
57
|
+
return presentation instanceof core_1.W3cV2DataIntegrityVerifiablePresentation
|
|
58
|
+
? presentation.securedPresentation.id
|
|
59
|
+
: presentation.id;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Wraps a VC Data Model 2.0 credential in a data model 2.0 presentation secured with a
|
|
63
|
+
* DataIntegrityProof under the cryptosuite the agent is configured with, the counterpart of the
|
|
64
|
+
* linked data proof a data model 1.1 linked VP carries. The presentation is published from the DID
|
|
65
|
+
* Document rather than presented to a verifier, so there is no challenge to bind; its proof purpose
|
|
66
|
+
* is `authentication`, as Data Integrity defines for presentations.
|
|
67
|
+
*/
|
|
68
|
+
async function signLinkedDataIntegrityPresentation(agent, options) {
|
|
69
|
+
const presentation = new core_1.W3cV2Presentation({
|
|
70
|
+
id: options.id,
|
|
71
|
+
holder: options.holder,
|
|
72
|
+
verifiableCredential: [options.credential],
|
|
73
|
+
});
|
|
74
|
+
// The options type requires a challenge for every presentation format, while a Data Integrity
|
|
75
|
+
// proof only carries one when it is given
|
|
76
|
+
return await agent.w3cV2Credentials.signPresentation({
|
|
77
|
+
format: core_1.ClaimFormat.DiVp,
|
|
78
|
+
presentation,
|
|
79
|
+
cryptosuite: (0, setupSelfTr_1.getDataIntegrityCryptosuite)(agent),
|
|
80
|
+
verificationMethod: options.verificationMethodId,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Wraps a VC Data Model 1.1 credential in a data model 1.1 presentation carrying an
|
|
85
|
+
* Ed25519Signature2020 linked data proof, for credentials received from issuers that still use it.
|
|
86
|
+
*/
|
|
87
|
+
async function signLinkedDataProofPresentation(agent, options) {
|
|
88
|
+
return await agent.w3cCredentials.signPresentation({
|
|
89
|
+
format: core_1.ClaimFormat.LdpVp,
|
|
90
|
+
presentation: new core_1.W3cPresentation({
|
|
91
|
+
id: options.id,
|
|
92
|
+
holder: options.holder,
|
|
93
|
+
verifiableCredential: [options.credential],
|
|
94
|
+
}),
|
|
95
|
+
proofType: 'Ed25519Signature2020',
|
|
96
|
+
verificationMethod: options.verificationMethodId,
|
|
97
|
+
proofPurpose: new jsonld_signatures_1.purposes.AssertionProofPurpose(),
|
|
98
|
+
});
|
|
27
99
|
}
|
|
28
100
|
function findMetadataEntry(didRecord, key, id, jsonSchemaRef) {
|
|
29
101
|
var _a, _b;
|
|
@@ -32,59 +104,53 @@ function findMetadataEntry(didRecord, key, id, jsonSchemaRef) {
|
|
|
32
104
|
return null;
|
|
33
105
|
if (!id && !jsonSchemaRef)
|
|
34
106
|
return { schemaId: '', data: metadata, didDocumentServiceId: '' };
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
107
|
+
const entries = Object.entries(metadata);
|
|
108
|
+
// the metadata key identifies one entry, so it answers before any preference between entries
|
|
109
|
+
const exact = jsonSchemaRef ? entries.find(([schemaId]) => schemaId === jsonSchemaRef) : undefined;
|
|
110
|
+
if (exact)
|
|
111
|
+
return Object.assign(Object.assign({ schemaId: exact[0] }, exact[1]), { data: exact[1].verifiablePresentation });
|
|
112
|
+
const match = ([schemaId, entry]) => {
|
|
113
|
+
var _a, _b;
|
|
114
|
+
if (((_a = entry.credential) === null || _a === void 0 ? void 0 : _a.id) === id)
|
|
42
115
|
return Object.assign(Object.assign({ schemaId }, entry), { data: entry.credential });
|
|
43
|
-
|
|
44
|
-
if (presId === id) {
|
|
116
|
+
if (((_b = entry.verifiablePresentation) === null || _b === void 0 ? void 0 : _b.id) === id)
|
|
45
117
|
return Object.assign(Object.assign({ schemaId }, entry), { data: entry.verifiablePresentation });
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
118
|
+
return null;
|
|
119
|
+
};
|
|
120
|
+
// several entries can carry the same presentation URL while a binding is replaced, so the entry
|
|
121
|
+
// the DID Document announces wins over a detached leftover
|
|
122
|
+
const matched = entries.map(match).filter(entry => entry !== null);
|
|
123
|
+
return (_b = (_a = matched.find(entry => entry.attached !== false)) !== null && _a !== void 0 ? _a : matched[0]) !== null && _b !== void 0 ? _b : null;
|
|
49
124
|
}
|
|
50
|
-
async function saveMetadataEntry(agent, didRecord, credential, verifiablePresentation, didDocumentServiceId, key
|
|
51
|
-
var _a, _b, _c, _d, _e, _f
|
|
52
|
-
const
|
|
125
|
+
async function saveMetadataEntry(agent, didRecord, credential, verifiablePresentation, didDocumentServiceId, key) {
|
|
126
|
+
var _a, _b, _c, _d, _e, _f;
|
|
127
|
+
const fields = trustCredentialFields(credential);
|
|
128
|
+
const schema = key === '_vt/vtc' ? fields.credentialSchema : fields.credentialSubject;
|
|
53
129
|
const ref = Array.isArray(schema) ? (_a = schema[0]) === null || _a === void 0 ? void 0 : _a.id : schema === null || schema === void 0 ? void 0 : schema.id;
|
|
54
130
|
if (!ref) {
|
|
55
131
|
throw new Error('No ID was found in credentialSubject');
|
|
56
132
|
}
|
|
57
133
|
const record = (_b = didRecord.metadata.get(key)) !== null && _b !== void 0 ? _b : {};
|
|
58
134
|
// Remove previous entry for this credential ID (if exists)
|
|
59
|
-
const found = findMetadataEntry(didRecord, key,
|
|
135
|
+
const found = findMetadataEntry(didRecord, key, fields.id, ref);
|
|
136
|
+
// [VSA-PUB-VT-5]: the Type Metadata of a schema outlives every re-issue of its VTJSC
|
|
137
|
+
const typeMetadata = (found === null || found === void 0 ? void 0 : found.schemaId) === ref ? (_c = record[ref]) === null || _c === void 0 ? void 0 : _c.typeMetadata : undefined;
|
|
60
138
|
if (found) {
|
|
61
|
-
if ((
|
|
139
|
+
if ((_d = didRecord.didDocument) === null || _d === void 0 ? void 0 : _d.service) {
|
|
62
140
|
didRecord.didDocument.service = didRecord.didDocument.service.filter(s => s.id !== found.didDocumentServiceId);
|
|
63
141
|
}
|
|
64
142
|
delete record[found.schemaId];
|
|
65
143
|
}
|
|
66
|
-
record[ref] = {
|
|
67
|
-
|
|
68
|
-
verifiablePresentation,
|
|
69
|
-
didDocumentServiceId,
|
|
70
|
-
};
|
|
71
|
-
(_e = (_d = didRecord.didDocument) === null || _d === void 0 ? void 0 : _d.service) === null || _e === void 0 ? void 0 : _e.push(new core_1.DidDocumentService({
|
|
144
|
+
record[ref] = Object.assign(Object.assign({}, (typeof typeMetadata === 'string' ? { typeMetadata } : {})), { credential: trustCredentialEntry(credential), verifiablePresentation: trustPresentationEntry(verifiablePresentation), didDocumentServiceId });
|
|
145
|
+
(_f = (_e = didRecord.didDocument) === null || _e === void 0 ? void 0 : _e.service) === null || _f === void 0 ? void 0 : _f.push(new core_1.DidDocumentService({
|
|
72
146
|
id: didDocumentServiceId,
|
|
73
|
-
serviceEndpoint: verifiablePresentation
|
|
147
|
+
serviceEndpoint: trustPresentationId(verifiablePresentation),
|
|
74
148
|
type: 'LinkedVerifiablePresentation',
|
|
75
149
|
}));
|
|
76
150
|
didRecord.metadata.set(key, record);
|
|
77
|
-
|
|
78
|
-
const service = (_g = (_f = didRecord.didDocument) === null || _f === void 0 ? void 0 : _f.service) === null || _g === void 0 ? void 0 : _g.find(s => s.id === `${agent.did}#whois`);
|
|
79
|
-
if (service && ((_h = verifiablePresentation.id) === null || _h === void 0 ? void 0 : _h.includes('service')))
|
|
80
|
-
service.serviceEndpoint = verifiablePresentation.id;
|
|
81
|
-
// A JSON schema credential says nothing about this agent's own ECS identity, so only a real
|
|
82
|
-
// trust credential replaces the self-issued ones.
|
|
83
|
-
if (key === '_vt/vtc')
|
|
84
|
-
updateVtcEntries(didRecord, false, publicApiBaseUrl);
|
|
85
|
-
await updateDidRecord(agent, didRecord);
|
|
151
|
+
await (0, publishedDidRecord_1.updateDidRecord)(agent, didRecord);
|
|
86
152
|
}
|
|
87
|
-
async function deleteMetadataEntry(agent, id, didRecord, key
|
|
153
|
+
async function deleteMetadataEntry(agent, id, didRecord, key) {
|
|
88
154
|
const found = findMetadataEntry(didRecord, key, id, id);
|
|
89
155
|
if (!found)
|
|
90
156
|
return null;
|
|
@@ -93,66 +159,22 @@ async function deleteMetadataEntry(agent, id, didRecord, key, publicApiBaseUrl)
|
|
|
93
159
|
return null;
|
|
94
160
|
delete metadata[found.schemaId];
|
|
95
161
|
didRecord.metadata.set(key, metadata);
|
|
96
|
-
|
|
97
|
-
restoreDefaultVtcEntries(didRecord, publicApiBaseUrl);
|
|
98
|
-
await updateDidRecord(agent, didRecord);
|
|
162
|
+
await (0, publishedDidRecord_1.updateDidRecord)(agent, didRecord);
|
|
99
163
|
return { schemaId: found.schemaId };
|
|
100
164
|
}
|
|
101
|
-
function restoreDefaultVtcEntries(didRecord, publicApiBaseUrl) {
|
|
102
|
-
var _a, _b;
|
|
103
|
-
const vtc = (_a = didRecord.metadata.get('_vt/vtc')) !== null && _a !== void 0 ? _a : {};
|
|
104
|
-
const jsc = (_b = didRecord.metadata.get('_vt/jsc')) !== null && _b !== void 0 ? _b : {};
|
|
105
|
-
// By default we have 2 Self-trusted VTCs
|
|
106
|
-
if (Object.keys(vtc).length < 3 && Object.keys(jsc).length < 3) {
|
|
107
|
-
updateVtcEntries(didRecord, true, publicApiBaseUrl);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function updateVtcEntries(didRecord, attach, publicApiBaseUrl) {
|
|
111
|
-
var _a;
|
|
112
|
-
const record = (_a = didRecord.metadata.get('_vt/vtc')) !== null && _a !== void 0 ? _a : {};
|
|
113
|
-
setupSelfTr_1.presentations.forEach(p => {
|
|
114
|
-
var _a, _b, _c, _d;
|
|
115
|
-
const schemaId = (0, setupSelfTr_1.mapToSelfTr)(p.schemaUrl, publicApiBaseUrl);
|
|
116
|
-
const current = record[schemaId];
|
|
117
|
-
if ((current === null || current === void 0 ? void 0 : current.attached) === attach)
|
|
118
|
-
return;
|
|
119
|
-
record[schemaId] = Object.assign(Object.assign({}, current), { attached: attach });
|
|
120
|
-
const serviceId = current === null || current === void 0 ? void 0 : current.didDocumentServiceId;
|
|
121
|
-
const serviceEndpoint = (_a = current === null || current === void 0 ? void 0 : current.verifiablePresentation) === null || _a === void 0 ? void 0 : _a.id;
|
|
122
|
-
if (!((_b = didRecord.didDocument) === null || _b === void 0 ? void 0 : _b.service))
|
|
123
|
-
return;
|
|
124
|
-
if (attach) {
|
|
125
|
-
const alreadyExists = didRecord.didDocument.service.some(s => s.id === serviceId);
|
|
126
|
-
if (!alreadyExists && serviceId && serviceEndpoint) {
|
|
127
|
-
didRecord.didDocument.service.push(new core_1.DidDocumentService({
|
|
128
|
-
id: serviceId,
|
|
129
|
-
serviceEndpoint,
|
|
130
|
-
type: 'LinkedVerifiablePresentation',
|
|
131
|
-
}));
|
|
132
|
-
}
|
|
133
|
-
// Return to self-trusted VTC in #whois endpoint
|
|
134
|
-
const service = (_d = (_c = didRecord.didDocument) === null || _c === void 0 ? void 0 : _c.service) === null || _d === void 0 ? void 0 : _d.find(s => s.id === `${didRecord.did}#whois`);
|
|
135
|
-
if (service && (serviceEndpoint === null || serviceEndpoint === void 0 ? void 0 : serviceEndpoint.includes('service')))
|
|
136
|
-
service.serviceEndpoint = serviceEndpoint;
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
didRecord.didDocument.service = didRecord.didDocument.service.filter(s => s.id !== serviceId);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
didRecord.metadata.set('_vt/vtc', record);
|
|
143
|
-
}
|
|
144
165
|
async function createVtc(agent, publicApiBaseUrl, id, credential) {
|
|
145
166
|
const didRecord = await getDidRecord(agent);
|
|
146
167
|
const schemaId = `schemas-${id}-vtc-vp.json`;
|
|
147
168
|
const didDocumentServiceId = `${agent.did}#vpr-${schemaId.replace('.json', '')}`;
|
|
148
169
|
const serviceEndpoint = `${publicApiBaseUrl}/vt/${schemaId}`;
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
170
|
+
const verificationMethodId = (0, setupSelfTr_1.getVerificationMethodId)(agent.config.logger, didRecord);
|
|
171
|
+
// The linked VP takes the data model of the credential it carries: a Data Integrity credential
|
|
172
|
+
// cannot be embedded in a data model 1.1 presentation, nor the other way round
|
|
173
|
+
const linkedVp = { id: serviceEndpoint, holder: agent.did, verificationMethodId };
|
|
174
|
+
const verifiablePresentation = credential instanceof core_1.W3cV2DataIntegrityVerifiableCredential
|
|
175
|
+
? await signLinkedDataIntegrityPresentation(agent, Object.assign(Object.assign({}, linkedVp), { credential }))
|
|
176
|
+
: await signLinkedDataProofPresentation(agent, Object.assign(Object.assign({}, linkedVp), { credential }));
|
|
177
|
+
await saveMetadataEntry(agent, didRecord, credential, verifiablePresentation, didDocumentServiceId, '_vt/vtc');
|
|
156
178
|
return verifiablePresentation;
|
|
157
179
|
}
|
|
158
180
|
async function createJsc(agent, publicApiBaseUrl, ecsSchemas, options) {
|
|
@@ -161,53 +183,86 @@ async function createJsc(agent, publicApiBaseUrl, ecsSchemas, options) {
|
|
|
161
183
|
const { id: subjectId, claims } = (0, setupSelfTr_1.createJsonSubjectRef)(jsonSchemaRef);
|
|
162
184
|
const subjectClaims = precomputedDigestSRI
|
|
163
185
|
? Object.assign(Object.assign({}, claims), { digestSRI: precomputedDigestSRI }) : await (0, setupSelfTr_1.addDigestSRI)(subjectId, claims, ecsSchemas);
|
|
164
|
-
const credentialSubject = {
|
|
165
|
-
id: subjectId,
|
|
166
|
-
claims: subjectClaims,
|
|
167
|
-
};
|
|
186
|
+
const credentialSubject = Object.assign(Object.assign({}, subjectClaims), { id: subjectId });
|
|
168
187
|
const schemaPresentation = `schemas-${schemaBaseId}-vtjsc-vp.json`;
|
|
169
188
|
const schemaCredential = `schemas-${schemaBaseId}-jsc.json`;
|
|
170
189
|
const serviceEndpoint = `${publicApiBaseUrl}/vt/${schemaPresentation}`;
|
|
171
190
|
const didDocumentServiceId = `${agent.did}#vpr-schemas-${schemaBaseId}-vtjsc-vp`;
|
|
191
|
+
const credentialId = `${publicApiBaseUrl}/vt/${schemaCredential}`;
|
|
172
192
|
const unsignedCredential = (0, setupSelfTr_1.createCredential)({
|
|
173
|
-
id:
|
|
193
|
+
id: credentialId,
|
|
174
194
|
type: ['VerifiableCredential', 'JsonSchemaCredential'],
|
|
175
195
|
issuer: agent.did,
|
|
176
196
|
credentialSubject,
|
|
197
|
+
credentialSchema: await (0, setupSelfTr_1.addDigestSRI)(setupSelfTr_1.createJsonSchema.id, { id: setupSelfTr_1.createJsonSchema.id, type: setupSelfTr_1.createJsonSchema.type }, ecsSchemas),
|
|
177
198
|
});
|
|
178
|
-
unsignedCredential.credentialSchema = await (0, setupSelfTr_1.addDigestSRI)(setupSelfTr_1.createJsonSchema.id, setupSelfTr_1.createJsonSchema, ecsSchemas);
|
|
179
199
|
const verificationMethodId = (0, setupSelfTr_1.getVerificationMethodId)(agent.config.logger, didRecord);
|
|
180
|
-
const credential = await (0, setupSelfTr_1.signerW3c)(agent,
|
|
181
|
-
const
|
|
200
|
+
const credential = await (0, setupSelfTr_1.signerW3c)(agent, unsignedCredential, verificationMethodId);
|
|
201
|
+
const verifiablePresentation = await signLinkedDataIntegrityPresentation(agent, {
|
|
182
202
|
id: serviceEndpoint,
|
|
183
203
|
holder: agent.did,
|
|
184
|
-
|
|
204
|
+
credential,
|
|
205
|
+
verificationMethodId,
|
|
185
206
|
});
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return credential.
|
|
207
|
+
await saveMetadataEntry(agent, didRecord, credential, verifiablePresentation, didDocumentServiceId, '_vt/jsc');
|
|
208
|
+
// the credential as published; its id is the one assigned above
|
|
209
|
+
return credential.securedCredential;
|
|
189
210
|
}
|
|
190
|
-
async function removeTrustCredential(agent,
|
|
211
|
+
async function removeTrustCredential(agent, schemaId, key) {
|
|
191
212
|
var _a;
|
|
192
213
|
const didRecord = await getDidRecord(agent);
|
|
193
|
-
const record = findMetadataEntry(didRecord, key, schemaId);
|
|
214
|
+
const record = findMetadataEntry(didRecord, key, schemaId, schemaId);
|
|
194
215
|
// Currently, we only use one serviceEndpoint per ID.
|
|
195
216
|
// In the future, if multiple serviceEndpoints exist for the same ID,
|
|
196
217
|
// we should review the serviceEndpoint content and remove only the specific one.
|
|
197
218
|
if ((record === null || record === void 0 ? void 0 : record.didDocumentServiceId) && ((_a = didRecord.didDocument) === null || _a === void 0 ? void 0 : _a.service)) {
|
|
198
219
|
didRecord.didDocument.service = didRecord.didDocument.service.filter(s => s.id !== record.didDocumentServiceId);
|
|
199
220
|
}
|
|
200
|
-
return await deleteMetadataEntry(agent, schemaId, didRecord, key
|
|
221
|
+
return await deleteMetadataEntry(agent, schemaId, didRecord, key);
|
|
201
222
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Reads the id of the credential from the RFC 0809 format data of an exchange.
|
|
225
|
+
* Returns `undefined` when the exchange is deleted. Returns `undefined` also when the exchange
|
|
226
|
+
* used a different format.
|
|
227
|
+
*/
|
|
228
|
+
async function findExchangeCredentialId(agent, credentialExchangeRecordId) {
|
|
229
|
+
var _a, _b, _c;
|
|
230
|
+
const formatData = await agent.didcomm.credentials
|
|
231
|
+
.getFormatData(credentialExchangeRecordId)
|
|
232
|
+
.catch(error => {
|
|
233
|
+
if (error instanceof core_1.RecordNotFoundError)
|
|
234
|
+
return undefined;
|
|
235
|
+
throw error;
|
|
236
|
+
});
|
|
237
|
+
const credentialId = (_c = (_b = (_a = formatData === null || formatData === void 0 ? void 0 : formatData.credential) === null || _a === void 0 ? void 0 : _a.dataIntegrity) === null || _b === void 0 ? void 0 : _b.credential) === null || _c === void 0 ? void 0 : _c.id;
|
|
238
|
+
return typeof credentialId === 'string' ? credentialId : undefined;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Removes the linked VP and the stored credential of the applicant, as
|
|
242
|
+
* [VSA-VTI-FLOW-OP-REVOKE] requires. The caller supplies the credential id from the flow record.
|
|
243
|
+
* An older record has no credential id. Then this function reads the id from the RFC 0809 format
|
|
244
|
+
* data of the exchange. Returns the credential id. Returns `undefined` when no id is available,
|
|
245
|
+
* and removes nothing.
|
|
246
|
+
*/
|
|
247
|
+
async function removeStoredTrustCredential(agent, options) {
|
|
248
|
+
var _a;
|
|
249
|
+
const { credentialExchangeRecordId } = options;
|
|
250
|
+
const credentialId = (_a = options.credentialId) !== null && _a !== void 0 ? _a : (credentialExchangeRecordId
|
|
251
|
+
? await findExchangeCredentialId(agent, credentialExchangeRecordId)
|
|
252
|
+
: undefined);
|
|
253
|
+
if (!credentialId) {
|
|
254
|
+
agent.config.logger.warn(`[trust-credential] Credential exchange ${credentialExchangeRecordId} carries no RFC 0809 credential id; its linked VP and stored credential are left in place`);
|
|
207
255
|
return undefined;
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
256
|
+
}
|
|
257
|
+
await removeTrustCredential(agent, credentialId, '_vt/vtc');
|
|
258
|
+
// The RFC 0809 format holds a data model 2.0 credential in a W3cV2CredentialRecord and a data
|
|
259
|
+
// model 1.1 one in a W3cCredentialRecord; the credential id is tagged on both
|
|
260
|
+
for (const storedRecord of await agent.w3cV2Credentials.getAll()) {
|
|
261
|
+
if (storedRecord.getTags().givenId === credentialId) {
|
|
262
|
+
await agent.w3cV2Credentials.deleteById(storedRecord.id);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
for (const storedRecord of await agent.w3cCredentials.getAll()) {
|
|
211
266
|
if (storedRecord.getTags().givenId === credentialId) {
|
|
212
267
|
await agent.w3cCredentials.deleteById(storedRecord.id);
|
|
213
268
|
}
|
|
@@ -239,69 +294,220 @@ async function migrateVtjscServiceIds(agent) {
|
|
|
239
294
|
if (!changed)
|
|
240
295
|
return;
|
|
241
296
|
didRecord.metadata.set('_vt/jsc', metadata);
|
|
242
|
-
await updateDidRecord(agent, didRecord);
|
|
297
|
+
await (0, publishedDidRecord_1.updateDidRecord)(agent, didRecord);
|
|
243
298
|
agent.config.logger.info('[VTJSC] migrated stored service ids to the -vtjsc-vp naming');
|
|
244
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* Takes the linked VPs of the given `_vt/jsc` entries out of the DID Document, publishing it once.
|
|
302
|
+
*
|
|
303
|
+
* The entries stay: `SelfTrController` serves them, and issued credentials name that URL in
|
|
304
|
+
* `credentialSchema.id`. Dropping one would 404 it and leave those credentials unverifiable.
|
|
305
|
+
*/
|
|
306
|
+
async function detachVtjscPublications(agent, schemaRefs) {
|
|
307
|
+
var _a, _b;
|
|
308
|
+
if (schemaRefs.length === 0)
|
|
309
|
+
return [];
|
|
310
|
+
const didRecord = await getDidRecord(agent);
|
|
311
|
+
if (!((_a = didRecord === null || didRecord === void 0 ? void 0 : didRecord.didDocument) === null || _a === void 0 ? void 0 : _a.service))
|
|
312
|
+
return [];
|
|
313
|
+
const metadata = didRecord.metadata.get('_vt/jsc');
|
|
314
|
+
if (!metadata)
|
|
315
|
+
return [];
|
|
316
|
+
const detached = [];
|
|
317
|
+
for (const schemaRef of schemaRefs) {
|
|
318
|
+
const serviceId = (_b = metadata[schemaRef]) === null || _b === void 0 ? void 0 : _b.didDocumentServiceId;
|
|
319
|
+
if (!serviceId || !didRecord.didDocument.service.some(s => s.id === serviceId))
|
|
320
|
+
continue;
|
|
321
|
+
didRecord.didDocument.service = didRecord.didDocument.service.filter(s => s.id !== serviceId);
|
|
322
|
+
detached.push(schemaRef);
|
|
323
|
+
}
|
|
324
|
+
if (detached.length === 0)
|
|
325
|
+
return [];
|
|
326
|
+
await (0, publishedDidRecord_1.updateDidRecord)(agent, didRecord);
|
|
327
|
+
return detached;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Puts a detached `_vt/jsc` entry back in the DID Document.
|
|
331
|
+
*
|
|
332
|
+
* The publication pass skips an entry whose digest still matches, so without this the agent would
|
|
333
|
+
* keep serving a VTJSC it never announces again.
|
|
334
|
+
*/
|
|
335
|
+
async function reattachVtjscPublication(agent, schemaRef) {
|
|
336
|
+
var _a, _b, _c;
|
|
337
|
+
const didRecord = await getDidRecord(agent);
|
|
338
|
+
if (!(didRecord === null || didRecord === void 0 ? void 0 : didRecord.didDocument))
|
|
339
|
+
return false;
|
|
340
|
+
const entry = (_a = didRecord.metadata.get('_vt/jsc')) === null || _a === void 0 ? void 0 : _a[schemaRef];
|
|
341
|
+
const serviceId = entry === null || entry === void 0 ? void 0 : entry.didDocumentServiceId;
|
|
342
|
+
const serviceEndpoint = (_b = entry === null || entry === void 0 ? void 0 : entry.verifiablePresentation) === null || _b === void 0 ? void 0 : _b.id;
|
|
343
|
+
if (!serviceId || !serviceEndpoint)
|
|
344
|
+
return false;
|
|
345
|
+
const services = (_c = didRecord.didDocument.service) !== null && _c !== void 0 ? _c : [];
|
|
346
|
+
if (services.some(s => s.id === serviceId))
|
|
347
|
+
return false;
|
|
348
|
+
didRecord.didDocument.service = [
|
|
349
|
+
...services,
|
|
350
|
+
new core_1.DidDocumentService({ id: serviceId, serviceEndpoint, type: 'LinkedVerifiablePresentation' }),
|
|
351
|
+
];
|
|
352
|
+
await (0, publishedDidRecord_1.updateDidRecord)(agent, didRecord);
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
245
355
|
function getTrustMetadata(didRecord, key, schemaId) {
|
|
246
356
|
return findMetadataEntry(didRecord, key, schemaId);
|
|
247
357
|
}
|
|
248
|
-
|
|
249
|
-
|
|
358
|
+
/**
|
|
359
|
+
* Stores the serialized SD-JWT VC Type Metadata of a VTJSC with its `_vt/jsc` entry, once. A
|
|
360
|
+
* stored document is never replaced: [VSA-PUB-VT-5] serves identical bytes while the schema exists.
|
|
361
|
+
* Returns false when the entry does not exist or already carries a document.
|
|
362
|
+
*/
|
|
363
|
+
async function saveVtjscTypeMetadata(agent, schemaRef, typeMetadata) {
|
|
364
|
+
const didRecord = await getDidRecord(agent);
|
|
365
|
+
const metadata = didRecord === null || didRecord === void 0 ? void 0 : didRecord.metadata.get('_vt/jsc');
|
|
366
|
+
const entry = metadata === null || metadata === void 0 ? void 0 : metadata[schemaRef];
|
|
367
|
+
if (!entry || typeof entry.typeMetadata === 'string')
|
|
368
|
+
return false;
|
|
369
|
+
entry.typeMetadata = typeMetadata;
|
|
370
|
+
didRecord.metadata.set('_vt/jsc', metadata);
|
|
371
|
+
// the DID Document does not change, so the record is saved without a DID update
|
|
372
|
+
const repo = agent.context.dependencyManager.resolve(core_1.DidRepository);
|
|
373
|
+
await repo.update(agent.context, didRecord);
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* The stored Type Metadata of the `CredentialSchema` with the given on-chain id, as serialized.
|
|
378
|
+
* The `_vt/jsc` key of such a schema is `vpr:verana:{chainId}:cs:{id}`.
|
|
379
|
+
*/
|
|
380
|
+
function findVtjscTypeMetadata(didRecord, chainId, credentialSchemaId) {
|
|
381
|
+
var _a;
|
|
382
|
+
const entry = (_a = didRecord.metadata.get('_vt/jsc')) === null || _a === void 0 ? void 0 : _a[`vpr:verana:${chainId}:cs:${credentialSchemaId}`];
|
|
383
|
+
return typeof (entry === null || entry === void 0 ? void 0 : entry.typeMetadata) === 'string' ? entry.typeMetadata : undefined;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Anchors a self-issued ECS credential, the same way as any other issuance: through
|
|
387
|
+
* CreateOrUpdateParticipantSession, which stores the digest in the `di` module keeper-to-keeper.
|
|
388
|
+
*
|
|
389
|
+
* `issuerParticipantId` must name an active ISSUER participant of this agent for the schema, whose
|
|
390
|
+
* vs_operator is this agent's account — the chain accepts the session from no other signer. The
|
|
391
|
+
* caller resolves it, because it already lists the agent's participants to decide what to rebind.
|
|
392
|
+
*/
|
|
393
|
+
async function anchorCredentialDigest(agent, schemaId, credential, issuerParticipantId) {
|
|
394
|
+
const chain = agent.veranaChain;
|
|
395
|
+
if (!chain)
|
|
250
396
|
return;
|
|
251
397
|
if (!credential)
|
|
252
398
|
throw new Error(`[DigestAnchor] The presentation for schema ${schemaId} has no credential`);
|
|
253
|
-
|
|
399
|
+
if (!agent.did)
|
|
400
|
+
throw new Error('[DigestAnchor] The agent has no public DID');
|
|
401
|
+
const schema = await agent.indexer.getCredentialSchema(schemaId).catch(() => undefined);
|
|
254
402
|
if (!schema)
|
|
255
403
|
throw new Error(`[DigestAnchor] Credential schema ${schemaId} is not on chain`);
|
|
256
|
-
|
|
404
|
+
// the credential as published, which is what a verifier digests
|
|
405
|
+
const digest = (0, verre_1.computeCredentialDigestJCS)(credential, schema.digest_algorithm);
|
|
257
406
|
// the same credential gives the same digest on each run, so an anchored digest needs no second transaction
|
|
258
|
-
if (await agent.
|
|
407
|
+
if (await agent.indexer.getDigest(digest))
|
|
259
408
|
return;
|
|
260
|
-
|
|
261
|
-
|
|
409
|
+
// A self-issued credential has no counterparty, so the session names only the issuer.
|
|
410
|
+
const { txHash } = await chain.createOrUpdateParticipantSession({
|
|
411
|
+
id: core_1.utils.uuid(),
|
|
412
|
+
issuerParticipantId,
|
|
413
|
+
agentParticipantId: 0,
|
|
414
|
+
walletAgentParticipantId: 0,
|
|
415
|
+
digest,
|
|
416
|
+
}, { granter: (0, feePreflight_1.feeGranterFor)(agent, issuerParticipantId) });
|
|
417
|
+
agent.config.logger.info(`[DigestAnchor] Anchored digest ${digest} for schema ${schemaId} against issuer participant ${issuerParticipantId} (tx ${txHash})`);
|
|
418
|
+
await agent.indexer.waitForDigest(digest);
|
|
262
419
|
}
|
|
263
420
|
// replaces the self-TR example JSC binding with the on-chain VTJSC so resolvers can link the credential to the VPR
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
421
|
+
/**
|
|
422
|
+
* @param jsonSchemaCredentialId the VTJSC the Ecosystem published for this schema. Only the
|
|
423
|
+
* Ecosystem publishes it, so an agent that issues against another Corporation's Ecosystem must
|
|
424
|
+
* resolve it there — see resolveJsonSchemaCredentialId.
|
|
425
|
+
* @param issuerParticipantId this agent's ISSUER participant for the schema, which anchors the
|
|
426
|
+
* credential digest.
|
|
427
|
+
* @param schemaKey the ECS schema this agent issues against. Every ECS key is accepted; the caller
|
|
428
|
+
* reaches this function only for a schema the agent holds an active ISSUER entry on.
|
|
429
|
+
*/
|
|
430
|
+
async function rebindEcsCredentialSchema(agent, publicApiBaseUrl, schemaId, schemaKey, ecsClaims, jsonSchemaCredentialId, issuerParticipantId, onChainJsonSchema, effectiveUntil) {
|
|
431
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
432
|
+
if (!agent.did)
|
|
267
433
|
return;
|
|
268
434
|
const vpUrl = `${publicApiBaseUrl}/vt/${schemaKey}-vtc-vp.json`;
|
|
269
|
-
const jscUrl =
|
|
435
|
+
const jscUrl = jsonSchemaCredentialId;
|
|
270
436
|
const didRecord = await getDidRecord(agent);
|
|
271
437
|
const record = (_a = didRecord.metadata.get('_vt/vtc')) !== null && _a !== void 0 ? _a : {};
|
|
438
|
+
const stored = record[jscUrl];
|
|
439
|
+
const storedIssuer = typeof ((_b = stored === null || stored === void 0 ? void 0 : stored.credential) === null || _b === void 0 ? void 0 : _b.issuer) === 'string' ? stored.credential.issuer : (_d = (_c = stored === null || stored === void 0 ? void 0 : stored.credential) === null || _c === void 0 ? void 0 : _c.issuer) === null || _d === void 0 ? void 0 : _d.id;
|
|
440
|
+
if ((stored === null || stored === void 0 ? void 0 : stored.credential) && !stored.integrityData && storedIssuer !== agent.did) {
|
|
441
|
+
agent.config.logger.debug(`[SelfTR] Keeping the ${schemaKey} credential issued by ${storedIssuer} instead of rebinding a self-issued one`);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
272
444
|
let removedStale = false;
|
|
273
445
|
for (const [key, entry] of Object.entries(record)) {
|
|
274
446
|
// findMetadataEntry serves the first entry matching the VP url, so stale bindings must go
|
|
275
447
|
if (key !== jscUrl &&
|
|
276
|
-
((
|
|
448
|
+
((_e = entry.verifiablePresentation) === null || _e === void 0 ? void 0 : _e.id) === vpUrl) {
|
|
277
449
|
delete record[key];
|
|
278
450
|
removedStale = true;
|
|
279
451
|
}
|
|
280
452
|
}
|
|
281
453
|
if (removedStale) {
|
|
282
454
|
didRecord.metadata.set('_vt/vtc', record);
|
|
283
|
-
await updateDidRecord(agent, didRecord);
|
|
455
|
+
await (0, publishedDidRecord_1.updateDidRecord)(agent, didRecord);
|
|
284
456
|
}
|
|
285
|
-
await (0,
|
|
286
|
-
var _a;
|
|
287
|
-
return await anchorCredentialDigest(agent, Number(schemaId), (_a = verifiablePresentation === null || verifiablePresentation === void 0 ? void 0 : verifiablePresentation.verifiableCredential) === null || _a === void 0 ? void 0 : _a[0]);
|
|
288
|
-
});
|
|
457
|
+
await (0, selfIssuedEcsCredential_1.publishSelfIssuedEcsPresentation)(agent, vpUrl, Object.assign(Object.assign({}, (0, data_1.getEcsSchemas)(publicApiBaseUrl)), (onChainJsonSchema ? { [schemaKey]: onChainJsonSchema } : {})), schemaKey, schemaId, ['VerifiableCredential', 'VerifiableTrustCredential'], { id: jscUrl, type: 'JsonSchemaCredential' }, ecsClaims, async (verifiablePresentation) => await anchorCredentialDigest(agent, Number(schemaId), verifiablePresentation.verifiableCredential[0], issuerParticipantId), effectiveUntil);
|
|
289
458
|
const freshRecord = await getDidRecord(agent);
|
|
459
|
+
let recordChanged = false;
|
|
460
|
+
const vtc = (_f = freshRecord.metadata.get('_vt/vtc')) !== null && _f !== void 0 ? _f : {};
|
|
461
|
+
const entry = vtc[jscUrl];
|
|
462
|
+
if (entry && (entry.issuerParticipantId !== issuerParticipantId || entry.schemaKey !== schemaKey)) {
|
|
463
|
+
vtc[jscUrl] = Object.assign(Object.assign({}, entry), { issuerParticipantId, schemaKey });
|
|
464
|
+
freshRecord.metadata.set('_vt/vtc', vtc);
|
|
465
|
+
recordChanged = true;
|
|
466
|
+
}
|
|
290
467
|
const doc = freshRecord.didDocument;
|
|
291
468
|
if (doc) {
|
|
292
469
|
// resolvers match the [VT-CRED-W3C-LINKED-VP] fragment; #whois alone is not enough
|
|
293
470
|
const expectedServiceId = `${agent.did}#${(0, setupSelfTr_1.linkedVpFragment)(schemaKey)}`;
|
|
294
|
-
const linked = (
|
|
471
|
+
const linked = (_g = doc.service) === null || _g === void 0 ? void 0 : _g.some(s => s.id === expectedServiceId);
|
|
295
472
|
if (!linked) {
|
|
296
|
-
doc.service = (
|
|
473
|
+
doc.service = (_h = doc.service) !== null && _h !== void 0 ? _h : [];
|
|
297
474
|
doc.service.push(new core_1.DidDocumentService({
|
|
298
475
|
id: expectedServiceId,
|
|
299
476
|
serviceEndpoint: vpUrl,
|
|
300
477
|
type: 'LinkedVerifiablePresentation',
|
|
301
478
|
}));
|
|
302
|
-
|
|
479
|
+
recordChanged = true;
|
|
303
480
|
}
|
|
481
|
+
if (recordChanged)
|
|
482
|
+
await (0, publishedDidRecord_1.updateDidRecord)(agent, freshRecord);
|
|
304
483
|
}
|
|
305
484
|
agent.config.logger.info(`[SelfTR] Rebound ${schemaKey} credential to VTJSC ${jscUrl}`);
|
|
306
485
|
}
|
|
486
|
+
/**
|
|
487
|
+
* Withdraws the ECS credentials anchored against `issuerParticipantId`, and the #whois entry
|
|
488
|
+
* when the Service credential is among them.
|
|
489
|
+
*/
|
|
490
|
+
async function withdrawSelfIssuedEcsCredentials(agent, issuerParticipantId) {
|
|
491
|
+
var _a, _b;
|
|
492
|
+
const didRecord = await getDidRecord(agent);
|
|
493
|
+
const withdrawn = [];
|
|
494
|
+
let whoisWithdrawn = false;
|
|
495
|
+
for (const [jscUrl, value] of Object.entries((_a = didRecord.metadata.get('_vt/vtc')) !== null && _a !== void 0 ? _a : {})) {
|
|
496
|
+
const entry = value;
|
|
497
|
+
if (entry.issuerParticipantId !== issuerParticipantId)
|
|
498
|
+
continue;
|
|
499
|
+
await removeTrustCredential(agent, jscUrl, '_vt/vtc');
|
|
500
|
+
withdrawn.push(jscUrl);
|
|
501
|
+
if (entry.schemaKey === 'ecs-service')
|
|
502
|
+
whoisWithdrawn = true;
|
|
503
|
+
}
|
|
504
|
+
if (whoisWithdrawn) {
|
|
505
|
+
const record = await getDidRecord(agent);
|
|
506
|
+
if ((_b = record.didDocument) === null || _b === void 0 ? void 0 : _b.service) {
|
|
507
|
+
record.didDocument.service = record.didDocument.service.filter(s => s.id !== `${agent.did}#whois`);
|
|
508
|
+
await (0, publishedDidRecord_1.updateDidRecord)(agent, record);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return withdrawn;
|
|
512
|
+
}
|
|
307
513
|
//# sourceMappingURL=trustCredentialStore.js.map
|