@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
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { DidDocument } from '@credo-ts/core';
|
|
2
|
+
/**
|
|
3
|
+
* The verification method the agent signs its credentials and presentations with: the first
|
|
4
|
+
* `assertionMethod` entry, when it is an Ed25519 key. A did:webvh document written by v1 also types
|
|
5
|
+
* the update key as `Ed25519VerificationKey2020`, so the type alone does not identify it.
|
|
6
|
+
*/
|
|
7
|
+
export declare function findSigningVerificationMethodId(didDocument: DidDocument): string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Makes sure the signing key is under `authentication` and `assertionMethod`, and removes the
|
|
10
|
+
* did:webvh update keys from both. A document written by v1 has the update key, and not the
|
|
11
|
+
* signing key, under `authentication`, so no resolver accepts a presentation whose proof purpose
|
|
12
|
+
* is `authentication`. Every other key stays: the OpenID4VC keys live under these relations too.
|
|
13
|
+
* `updateKeys` are the `updateKeys` of the did:webvh log, as multibase public keys.
|
|
14
|
+
* Returns whether the document changed.
|
|
15
|
+
*/
|
|
16
|
+
export declare function alignSigningKeyRelations(didDocument: DidDocument, updateKeys?: string[]): boolean;
|
|
17
|
+
/** Every key a did:webvh log has authorized to update the DID, as multibase public keys. */
|
|
18
|
+
export declare function didWebvhUpdateKeys(log: unknown): string[];
|
|
19
|
+
type PresentationEntries = Record<string, {
|
|
20
|
+
verifiablePresentation?: {
|
|
21
|
+
id?: string;
|
|
22
|
+
};
|
|
23
|
+
} | undefined>;
|
|
24
|
+
export interface ServedLinkedVpOptions {
|
|
25
|
+
publicApiBaseUrl: string;
|
|
26
|
+
/** The `_vt/vtc` metadata of the DID record */
|
|
27
|
+
vtc?: PresentationEntries;
|
|
28
|
+
/** The `_vt/jsc` metadata of the DID record */
|
|
29
|
+
jsc?: PresentationEntries;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Removes the `LinkedVerifiablePresentation` services whose endpoint the agent does not serve, such
|
|
33
|
+
* as the `/vt/schemas-*-c-vp.json` ones a v1 document carries: a resolver reports each of them as a
|
|
34
|
+
* failed presentation. Returns the ids of the removed services.
|
|
35
|
+
*/
|
|
36
|
+
export declare function removeUnservedLinkedVpServices(didDocument: DidDocument, options: ServedLinkedVpOptions): string[];
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findSigningVerificationMethodId = findSigningVerificationMethodId;
|
|
4
|
+
exports.alignSigningKeyRelations = alignSigningKeyRelations;
|
|
5
|
+
exports.didWebvhUpdateKeys = didWebvhUpdateKeys;
|
|
6
|
+
exports.removeUnservedLinkedVpServices = removeUnservedLinkedVpServices;
|
|
7
|
+
const LINKED_VP_SERVICE_TYPE = 'LinkedVerifiablePresentation';
|
|
8
|
+
const SIGNING_VERIFICATION_METHOD_TYPES = [
|
|
9
|
+
'Ed25519VerificationKey2020',
|
|
10
|
+
'Ed25519VerificationKey2018',
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* The verification method the agent signs its credentials and presentations with: the first
|
|
14
|
+
* `assertionMethod` entry, when it is an Ed25519 key. A did:webvh document written by v1 also types
|
|
15
|
+
* the update key as `Ed25519VerificationKey2020`, so the type alone does not identify it.
|
|
16
|
+
*/
|
|
17
|
+
function findSigningVerificationMethodId(didDocument) {
|
|
18
|
+
var _a, _b, _c;
|
|
19
|
+
const [first] = (_a = didDocument.assertionMethod) !== null && _a !== void 0 ? _a : [];
|
|
20
|
+
if (typeof first !== 'string')
|
|
21
|
+
return undefined;
|
|
22
|
+
return (_c = (_b = didDocument.verificationMethod) === null || _b === void 0 ? void 0 : _b.find(method => method.id === first && SIGNING_VERIFICATION_METHOD_TYPES.includes(method.type))) === null || _c === void 0 ? void 0 : _c.id;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Makes sure the signing key is under `authentication` and `assertionMethod`, and removes the
|
|
26
|
+
* did:webvh update keys from both. A document written by v1 has the update key, and not the
|
|
27
|
+
* signing key, under `authentication`, so no resolver accepts a presentation whose proof purpose
|
|
28
|
+
* is `authentication`. Every other key stays: the OpenID4VC keys live under these relations too.
|
|
29
|
+
* `updateKeys` are the `updateKeys` of the did:webvh log, as multibase public keys.
|
|
30
|
+
* Returns whether the document changed.
|
|
31
|
+
*/
|
|
32
|
+
function alignSigningKeyRelations(didDocument, updateKeys = []) {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
const signingKeyId = findSigningVerificationMethodId(didDocument);
|
|
35
|
+
if (!signingKeyId)
|
|
36
|
+
return false;
|
|
37
|
+
const updateKeyIds = ((_a = didDocument.verificationMethod) !== null && _a !== void 0 ? _a : [])
|
|
38
|
+
.filter(method => method.id !== signingKeyId &&
|
|
39
|
+
typeof method.publicKeyMultibase === 'string' &&
|
|
40
|
+
updateKeys.includes(method.publicKeyMultibase))
|
|
41
|
+
.map(method => method.id);
|
|
42
|
+
let changed = false;
|
|
43
|
+
for (const relation of ['authentication', 'assertionMethod']) {
|
|
44
|
+
const current = (_b = didDocument[relation]) !== null && _b !== void 0 ? _b : [];
|
|
45
|
+
const kept = current.filter(entry => typeof entry !== 'string' || !updateKeyIds.includes(entry));
|
|
46
|
+
const aligned = kept.includes(signingKeyId) ? kept : [signingKeyId, ...kept];
|
|
47
|
+
if (aligned.length === current.length && aligned.every((entry, index) => entry === current[index]))
|
|
48
|
+
continue;
|
|
49
|
+
didDocument[relation] = aligned;
|
|
50
|
+
changed = true;
|
|
51
|
+
}
|
|
52
|
+
return changed;
|
|
53
|
+
}
|
|
54
|
+
/** Every key a did:webvh log has authorized to update the DID, as multibase public keys. */
|
|
55
|
+
function didWebvhUpdateKeys(log) {
|
|
56
|
+
if (!Array.isArray(log))
|
|
57
|
+
return [];
|
|
58
|
+
const updateKeys = log.flatMap(entry => { var _a, _b; return (_b = (_a = entry === null || entry === void 0 ? void 0 : entry.parameters) === null || _a === void 0 ? void 0 : _a.updateKeys) !== null && _b !== void 0 ? _b : []; });
|
|
59
|
+
return [...new Set(updateKeys.filter((key) => typeof key === 'string'))];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Whether `GET /vt/:file` of the public API answers this endpoint with a presentation: the file
|
|
63
|
+
* name has a suffix the route accepts, and the DID record stores a presentation under that URL.
|
|
64
|
+
*/
|
|
65
|
+
function isServedLinkedVp(endpoint, { publicApiBaseUrl, vtc, jsc }) {
|
|
66
|
+
if (!endpoint.startsWith(`${publicApiBaseUrl}/vt/`))
|
|
67
|
+
return false;
|
|
68
|
+
const entries = endpoint.endsWith('-vtc-vp.json')
|
|
69
|
+
? vtc
|
|
70
|
+
: endpoint.endsWith('-vtjsc-vp.json')
|
|
71
|
+
? jsc
|
|
72
|
+
: undefined;
|
|
73
|
+
return Object.values(entries !== null && entries !== void 0 ? entries : {}).some(entry => { var _a; return ((_a = entry === null || entry === void 0 ? void 0 : entry.verifiablePresentation) === null || _a === void 0 ? void 0 : _a.id) === endpoint; });
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Removes the `LinkedVerifiablePresentation` services whose endpoint the agent does not serve, such
|
|
77
|
+
* as the `/vt/schemas-*-c-vp.json` ones a v1 document carries: a resolver reports each of them as a
|
|
78
|
+
* failed presentation. Returns the ids of the removed services.
|
|
79
|
+
*/
|
|
80
|
+
function removeUnservedLinkedVpServices(didDocument, options) {
|
|
81
|
+
var _a;
|
|
82
|
+
const removed = [];
|
|
83
|
+
didDocument.service = ((_a = didDocument.service) !== null && _a !== void 0 ? _a : []).filter(service => {
|
|
84
|
+
if (service.type !== LINKED_VP_SERVICE_TYPE || typeof service.serviceEndpoint !== 'string')
|
|
85
|
+
return true;
|
|
86
|
+
if (isServedLinkedVp(service.serviceEndpoint, options))
|
|
87
|
+
return true;
|
|
88
|
+
removed.push(service.id);
|
|
89
|
+
return false;
|
|
90
|
+
});
|
|
91
|
+
return removed;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=reusedDidDocument.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reusedDidDocument.js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|
|
2
|
+
import type { DidCommProofExchangeRecord } from '@credo-ts/didcomm';
|
|
2
3
|
import { BaseLogger } from '@credo-ts/core';
|
|
3
4
|
export declare const baseMessageEvents: (agent: VsAgent<BaseAgentModules>, logger: BaseLogger) => Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Credo sets `presentation-received` before the trust decision of [VSA-VTI-FLOW-VERIFY-AC-7] runs.
|
|
7
|
+
* The decision records the presented credentials when it succeeds. Before that, the record is not
|
|
8
|
+
* `verified`. The caller cannot acknowledge the presentation, and cannot decline it.
|
|
9
|
+
*/
|
|
10
|
+
export declare function awaitsTrustDecision(record: DidCommProofExchangeRecord): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* This function completes the trust decision of each received presentation that has none.
|
|
13
|
+
*
|
|
14
|
+
* - A stop of the agent before the decision leaves such a record. An earlier version of the agent
|
|
15
|
+
* leaves such a record also. The caller cannot acknowledge that record, and cannot decline it.
|
|
16
|
+
* - Call this function at each start, after the event listeners are registered. The decision emits
|
|
17
|
+
* the event of `presentation-received`.
|
|
18
|
+
* - The decision uses the state of the ledger at the time of the call, not at the time of the
|
|
19
|
+
* presentation.
|
|
20
|
+
* - A decision that cannot complete ends the exchange in `abandoned`, per
|
|
21
|
+
* [VSA-VTI-FLOW-VERIFY-AC-8].
|
|
22
|
+
* - The function does not decide a record that is younger than `minAgeMs`. Another process can
|
|
23
|
+
* decide that record at this moment. The function examines that record again later.
|
|
24
|
+
*/
|
|
25
|
+
export declare function completePendingTrustDecisions(agent: VsAgent<BaseAgentModules>, logger: BaseLogger, { minAgeMs }?: {
|
|
26
|
+
minAgeMs?: number;
|
|
27
|
+
}): Promise<void>;
|
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.baseMessageEvents = void 0;
|
|
4
|
-
|
|
15
|
+
exports.awaitsTrustDecision = awaitsTrustDecision;
|
|
16
|
+
exports.completePendingTrustDecisions = completePendingTrustDecisions;
|
|
17
|
+
const core_1 = require("@credo-ts/core");
|
|
5
18
|
const didcomm_1 = require("@credo-ts/didcomm");
|
|
6
19
|
const vs_agent_model_1 = require("@verana-labs/vs-agent-model");
|
|
20
|
+
const AnonCredsTrustService_1 = require("../blockchain/AnonCredsTrustService");
|
|
21
|
+
const types_1 = require("../blockchain/types");
|
|
7
22
|
const agent_1 = require("../utils/agent");
|
|
8
23
|
const VsAgentEvents_1 = require("./VsAgentEvents");
|
|
9
24
|
const baseMessageEvents = async (agent, logger) => {
|
|
25
|
+
registerAnonCredsTrustDecision(agent, logger);
|
|
10
26
|
// Proofs protocol messages (proof presentation and problem reports)
|
|
11
27
|
agent.events.on(didcomm_1.DidCommEventTypes.DidCommMessageProcessed, async ({ payload }) => {
|
|
12
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
28
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
13
29
|
const { message, connection } = payload;
|
|
14
30
|
if (!connection)
|
|
15
31
|
return;
|
|
16
|
-
if (
|
|
17
|
-
didcomm_1.DidCommPresentationV2ProblemReportMessage.type.messageTypeUri,
|
|
18
|
-
anoncreds_1.DidCommPresentationV1ProblemReportMessage.type.messageTypeUri,
|
|
19
|
-
].includes(message.type)) {
|
|
32
|
+
if (message.type === didcomm_1.DidCommPresentationV2ProblemReportMessage.type.messageTypeUri) {
|
|
20
33
|
logger.info('Presentation problem report received');
|
|
21
34
|
try {
|
|
22
35
|
const record = await agent.didcomm.proofs.getByThreadAndConnectionId(message.threadId, connection.id);
|
|
@@ -53,16 +66,13 @@ const baseMessageEvents = async (agent, logger) => {
|
|
|
53
66
|
logger.error(`Error processing presentation problem report: ${error}`);
|
|
54
67
|
}
|
|
55
68
|
}
|
|
56
|
-
if (
|
|
57
|
-
anoncreds_1.DidCommPresentationV1Message.type.messageTypeUri,
|
|
58
|
-
didcomm_1.DidCommPresentationV2Message.type.messageTypeUri,
|
|
59
|
-
].includes(message.type)) {
|
|
69
|
+
if (message.type === didcomm_1.DidCommPresentationV2Message.type.messageTypeUri) {
|
|
60
70
|
logger.info('Presentation received');
|
|
61
71
|
try {
|
|
62
72
|
const record = await agent.didcomm.proofs.getByThreadAndConnectionId(message.threadId, connection.id);
|
|
63
73
|
const formatData = await agent.didcomm.proofs.getFormatData(record.id);
|
|
64
|
-
const revealedAttributes = (
|
|
65
|
-
const revealedAttributeGroups = (
|
|
74
|
+
const revealedAttributes = (_d = (_c = formatData.presentation) === null || _c === void 0 ? void 0 : _c.anoncreds) === null || _d === void 0 ? void 0 : _d.requested_proof.revealed_attrs;
|
|
75
|
+
const revealedAttributeGroups = (_f = (_e = formatData.presentation) === null || _e === void 0 ? void 0 : _e.anoncreds) === null || _f === void 0 ? void 0 : _f.requested_proof.revealed_attr_groups;
|
|
66
76
|
const claims = [];
|
|
67
77
|
if (revealedAttributes) {
|
|
68
78
|
for (const [name, value] of Object.entries(revealedAttributes)) {
|
|
@@ -83,7 +93,7 @@ const baseMessageEvents = async (agent, logger) => {
|
|
|
83
93
|
callbackUrl: callbackParameters.callbackUrl,
|
|
84
94
|
claims,
|
|
85
95
|
state: record.isVerified ? vs_agent_model_1.PresentationState.OK : vs_agent_model_1.PresentationState.VERIFICATION_ERROR,
|
|
86
|
-
verified: (
|
|
96
|
+
verified: (_g = record.isVerified) !== null && _g !== void 0 ? _g : false,
|
|
87
97
|
ref: callbackParameters.ref,
|
|
88
98
|
}));
|
|
89
99
|
}
|
|
@@ -93,7 +103,7 @@ const baseMessageEvents = async (agent, logger) => {
|
|
|
93
103
|
id: record.threadId,
|
|
94
104
|
proofExchangeId: record.id,
|
|
95
105
|
claims,
|
|
96
|
-
verified: (
|
|
106
|
+
verified: (_h = record.isVerified) !== null && _h !== void 0 ? _h : false,
|
|
97
107
|
}),
|
|
98
108
|
],
|
|
99
109
|
connectionId: record.connectionId,
|
|
@@ -145,4 +155,348 @@ const baseMessageEvents = async (agent, logger) => {
|
|
|
145
155
|
});
|
|
146
156
|
};
|
|
147
157
|
exports.baseMessageEvents = baseMessageEvents;
|
|
158
|
+
/**
|
|
159
|
+
* A trust decision in flight completes in less than this time. The function
|
|
160
|
+
* `completePendingTrustDecisions` does not decide a record that is younger: the message handler of
|
|
161
|
+
* this process, or of another process on the same wallet, can decide it at that moment.
|
|
162
|
+
*/
|
|
163
|
+
const PENDING_TRUST_DECISION_MIN_AGE_MS = 60000;
|
|
164
|
+
const trustDecisionStates = new WeakMap();
|
|
165
|
+
function trustDecisionStateOf(agent) {
|
|
166
|
+
let state = trustDecisionStates.get(agent);
|
|
167
|
+
if (!state) {
|
|
168
|
+
state = { deciding: new Set() };
|
|
169
|
+
trustDecisionStates.set(agent, state);
|
|
170
|
+
}
|
|
171
|
+
return state;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Credo sets `presentation-received` before the trust decision of [VSA-VTI-FLOW-VERIFY-AC-7] runs.
|
|
175
|
+
* The decision records the presented credentials when it succeeds. Before that, the record is not
|
|
176
|
+
* `verified`. The caller cannot acknowledge the presentation, and cannot decline it.
|
|
177
|
+
*/
|
|
178
|
+
function awaitsTrustDecision(record) {
|
|
179
|
+
return (record.role === didcomm_1.DidCommProofRole.Verifier &&
|
|
180
|
+
record.state === didcomm_1.DidCommProofState.PresentationReceived &&
|
|
181
|
+
!record.metadata.get(AnonCredsTrustService_1.PRESENTED_CREDENTIALS_METADATA));
|
|
182
|
+
}
|
|
183
|
+
function registerAnonCredsTrustDecision(agent, logger) {
|
|
184
|
+
const { deciding } = trustDecisionStateOf(agent);
|
|
185
|
+
agent.didcomm.registerMessageHandlerMiddleware(async (messageContext, next) => {
|
|
186
|
+
var _a;
|
|
187
|
+
const { message } = messageContext;
|
|
188
|
+
if (message.type !== didcomm_1.DidCommPresentationV2Message.type.messageTypeUri)
|
|
189
|
+
return next();
|
|
190
|
+
deciding.add(message.threadId);
|
|
191
|
+
try {
|
|
192
|
+
await next();
|
|
193
|
+
// A presentation with no connection answers a request of an invitation. The trust decision
|
|
194
|
+
// applies to it also.
|
|
195
|
+
const { connection } = messageContext;
|
|
196
|
+
let record;
|
|
197
|
+
try {
|
|
198
|
+
record = connection
|
|
199
|
+
? await agent.didcomm.proofs.getByThreadAndConnectionId(message.threadId, connection.id)
|
|
200
|
+
: ((_a = (await agent.didcomm.proofs.findAllByQuery({
|
|
201
|
+
threadId: message.threadId,
|
|
202
|
+
role: didcomm_1.DidCommProofRole.Verifier,
|
|
203
|
+
}))[0]) !== null && _a !== void 0 ? _a : null);
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
logger.error(`The agent cannot read the presentation of ${message.threadId}: ${error}`);
|
|
207
|
+
messageContext.responseMessage = undefined;
|
|
208
|
+
// The agent has no record to abandon. It examines the pending trust decisions again later:
|
|
209
|
+
// that examination completes the decision, or it ends the exchange in `abandoned`.
|
|
210
|
+
completePendingTrustDecisionsLater(agent, logger, PENDING_TRUST_DECISION_MIN_AGE_MS);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (!record)
|
|
214
|
+
return;
|
|
215
|
+
if (await completeTrustDecision(agent, record, connection, logger)) {
|
|
216
|
+
messageContext.responseMessage = undefined;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
deciding.delete(message.threadId);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* This function runs the trust decision of [VSA-VTI-FLOW-VERIFY-AC-7] on a received presentation.
|
|
226
|
+
* It acknowledges the presentation when the exchange asks for it. It returns `true` when the
|
|
227
|
+
* decision failed. The exchange is then in `abandoned`.
|
|
228
|
+
*/
|
|
229
|
+
async function completeTrustDecision(agent, record, connection, logger) {
|
|
230
|
+
var _a;
|
|
231
|
+
let presentation;
|
|
232
|
+
try {
|
|
233
|
+
const formatData = await agent.didcomm.proofs.getFormatData(record.id);
|
|
234
|
+
presentation = (_a = formatData.presentation) === null || _a === void 0 ? void 0 : _a.anoncreds;
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
logger.error(`The agent cannot read the presentation ${record.id}: ${error}`);
|
|
238
|
+
// The check did not run, so the exchange ends here, per [VSA-VTI-FLOW-VERIFY-AC-8]
|
|
239
|
+
if (record.role === didcomm_1.DidCommProofRole.Verifier) {
|
|
240
|
+
await abandonPresentation(agent, record, connection, AnonCredsTrustService_1.AnonCredsTrustProblemCode.TrustResolutionUnavailable, `the agent cannot read the presentation: ${error}`, logger);
|
|
241
|
+
}
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
if (await applyAnonCredsTrustDecision(agent, record, connection, presentation, logger))
|
|
245
|
+
return true;
|
|
246
|
+
// The proof and the trust decision both succeeded, so the agent acknowledges the presentation.
|
|
247
|
+
const policy = record.metadata.get(AnonCredsTrustService_1.AUTO_ACCEPT_PRESENTATION_METADATA);
|
|
248
|
+
if (!(policy === null || policy === void 0 ? void 0 : policy.autoAccept) || record.state !== didcomm_1.DidCommProofState.PresentationReceived)
|
|
249
|
+
return false;
|
|
250
|
+
try {
|
|
251
|
+
await agent.didcomm.proofs.acceptPresentation({ proofExchangeRecordId: record.id });
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
logger.error(`The agent cannot acknowledge the presentation ${record.id}: ${error}`);
|
|
255
|
+
}
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* This function completes the trust decision of each received presentation that has none.
|
|
260
|
+
*
|
|
261
|
+
* - A stop of the agent before the decision leaves such a record. An earlier version of the agent
|
|
262
|
+
* leaves such a record also. The caller cannot acknowledge that record, and cannot decline it.
|
|
263
|
+
* - Call this function at each start, after the event listeners are registered. The decision emits
|
|
264
|
+
* the event of `presentation-received`.
|
|
265
|
+
* - The decision uses the state of the ledger at the time of the call, not at the time of the
|
|
266
|
+
* presentation.
|
|
267
|
+
* - A decision that cannot complete ends the exchange in `abandoned`, per
|
|
268
|
+
* [VSA-VTI-FLOW-VERIFY-AC-8].
|
|
269
|
+
* - The function does not decide a record that is younger than `minAgeMs`. Another process can
|
|
270
|
+
* decide that record at this moment. The function examines that record again later.
|
|
271
|
+
*/
|
|
272
|
+
async function completePendingTrustDecisions(agent, logger, { minAgeMs = PENDING_TRUST_DECISION_MIN_AGE_MS } = {}) {
|
|
273
|
+
var _a, _b;
|
|
274
|
+
// A timer can start this function after the agent stopped
|
|
275
|
+
if (!agent.isInitialized)
|
|
276
|
+
return;
|
|
277
|
+
const { deciding } = trustDecisionStateOf(agent);
|
|
278
|
+
let pending;
|
|
279
|
+
try {
|
|
280
|
+
pending = await agent.didcomm.proofs.findAllByQuery({
|
|
281
|
+
role: didcomm_1.DidCommProofRole.Verifier,
|
|
282
|
+
state: didcomm_1.DidCommProofState.PresentationReceived,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
logger.error(`The agent cannot read the presentations that wait for the trust decision: ${error}`);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
let examineAgainInMs = 0;
|
|
290
|
+
// A record with a decision waits for the caller, so the agent does not read it again
|
|
291
|
+
for (const { id, threadId } of pending.filter(awaitsTrustDecision)) {
|
|
292
|
+
// The message handler of this process decides this presentation at this moment
|
|
293
|
+
if (deciding.has(threadId))
|
|
294
|
+
continue;
|
|
295
|
+
deciding.add(threadId);
|
|
296
|
+
try {
|
|
297
|
+
// The record can change after the query, so the agent reads it again
|
|
298
|
+
const record = await agent.didcomm.proofs.findById(id);
|
|
299
|
+
if (!record || !awaitsTrustDecision(record))
|
|
300
|
+
continue;
|
|
301
|
+
const ageMs = Date.now() - ((_a = record.updatedAt) !== null && _a !== void 0 ? _a : record.createdAt).getTime();
|
|
302
|
+
if (ageMs < minAgeMs) {
|
|
303
|
+
examineAgainInMs = Math.max(examineAgainInMs, minAgeMs - ageMs);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
const connection = record.connectionId
|
|
307
|
+
? ((_b = (await agent.didcomm.connections.findById(record.connectionId))) !== null && _b !== void 0 ? _b : undefined)
|
|
308
|
+
: undefined;
|
|
309
|
+
logger.info(`The agent completes the trust decision of the presentation ${id}`);
|
|
310
|
+
await completeTrustDecision(agent, record, connection, logger);
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
logger.error(`The agent cannot complete the trust decision of the presentation ${id}: ${error}`);
|
|
314
|
+
}
|
|
315
|
+
finally {
|
|
316
|
+
deciding.delete(threadId);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (examineAgainInMs > 0)
|
|
320
|
+
completePendingTrustDecisionsLater(agent, logger, examineAgainInMs, minAgeMs);
|
|
321
|
+
}
|
|
322
|
+
/** This function starts one later examination of the pending trust decisions of an agent. */
|
|
323
|
+
function completePendingTrustDecisionsLater(agent, logger, delayMs, minAgeMs) {
|
|
324
|
+
const state = trustDecisionStateOf(agent);
|
|
325
|
+
// One examination decides every pending record, so the agent keeps one timer only
|
|
326
|
+
if (state.nextExamination)
|
|
327
|
+
return;
|
|
328
|
+
state.nextExamination = setTimeout(() => {
|
|
329
|
+
state.nextExamination = undefined;
|
|
330
|
+
void completePendingTrustDecisions(agent, logger, { minAgeMs });
|
|
331
|
+
}, delayMs);
|
|
332
|
+
// The timer does not keep the process alive
|
|
333
|
+
state.nextExamination.unref();
|
|
334
|
+
}
|
|
335
|
+
async function applyAnonCredsTrustDecision(agent, record, connection, presentation, logger) {
|
|
336
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
337
|
+
if (record.role !== didcomm_1.DidCommProofRole.Verifier)
|
|
338
|
+
return false;
|
|
339
|
+
// The agent can check an AnonCreds presentation only. A presentation with no decision can be
|
|
340
|
+
// neither acknowledged nor declined, so the exchange ends here, per [VSA-VTI-FLOW-VERIFY-AC-8].
|
|
341
|
+
if (!presentation) {
|
|
342
|
+
await abandonPresentation(agent, record, connection, AnonCredsTrustService_1.AnonCredsTrustProblemCode.TrustResolutionUnavailable, 'the presentation has no AnonCreds proof', logger);
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
const identifiers = (_a = presentation.identifiers) !== null && _a !== void 0 ? _a : [];
|
|
346
|
+
const stored = record.metadata.get(AnonCredsTrustService_1.REQUESTED_CREDENTIAL_SCHEMAS_METADATA);
|
|
347
|
+
const requestedCredentialSchemas = Object.entries(Array.isArray(stored) ? {} : (stored !== null && stored !== void 0 ? stored : {}));
|
|
348
|
+
// A request whose creator recorded no CredentialSchema cannot be checked against what it asked
|
|
349
|
+
// for, so it abandons rather than accepting any schema.
|
|
350
|
+
if (requestedCredentialSchemas.length === 0) {
|
|
351
|
+
await abandonPresentation(agent, record, connection, AnonCredsTrustService_1.AnonCredsTrustProblemCode.TrustResolutionUnavailable, 'the exchange records no CredentialSchema of its requested credentials', logger);
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
const answered = Object.assign(Object.assign(Object.assign(Object.assign({}, (_b = presentation.requested_proof) === null || _b === void 0 ? void 0 : _b.revealed_attrs), (_c = presentation.requested_proof) === null || _c === void 0 ? void 0 : _c.revealed_attr_groups), (_d = presentation.requested_proof) === null || _d === void 0 ? void 0 : _d.unrevealed_attrs), (_e = presentation.requested_proof) === null || _e === void 0 ? void 0 : _e.predicates);
|
|
355
|
+
const candidates = [];
|
|
356
|
+
const rejected = [];
|
|
357
|
+
const reject = (index, code, note, known = {}) => rejected.push(Object.assign({ index, code, note }, known));
|
|
358
|
+
for (const [index, [group, requested]] of requestedCredentialSchemas.entries()) {
|
|
359
|
+
const subProofIndex = (_f = answered[group]) === null || _f === void 0 ? void 0 : _f.sub_proof_index;
|
|
360
|
+
const credentialDefinitionId = subProofIndex === undefined ? undefined : (_g = identifiers[subProofIndex]) === null || _g === void 0 ? void 0 : _g.cred_def_id;
|
|
361
|
+
if (!credentialDefinitionId) {
|
|
362
|
+
reject(index, AnonCredsTrustService_1.AnonCredsTrustProblemCode.IssuerNotAuthorized, `no sub-proof answers the requested group "${group}"`);
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
try {
|
|
366
|
+
const derived = await agent.anonCredsTrust.deriveCredentialSchema({ credentialDefinitionId });
|
|
367
|
+
const known = {
|
|
368
|
+
credentialDefinitionId,
|
|
369
|
+
issuerDid: derived.issuerId,
|
|
370
|
+
credentialSchemaId: derived.credentialSchemaId,
|
|
371
|
+
};
|
|
372
|
+
if (derived.credentialSchemaId !== requested.credentialSchemaId) {
|
|
373
|
+
reject(index, AnonCredsTrustService_1.AnonCredsTrustProblemCode.IssuerNotAuthorized, `${credentialDefinitionId} presents the CredentialSchema ${derived.credentialSchemaId} for the group "${group}", which asks for the CredentialSchema ${requested.credentialSchemaId}`, known);
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
if (!derived.issuerId) {
|
|
377
|
+
reject(index, AnonCredsTrustService_1.AnonCredsTrustProblemCode.IssuerNotAuthorized, `${credentialDefinitionId} names no issuer`, known);
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
candidates.push({
|
|
381
|
+
index,
|
|
382
|
+
group,
|
|
383
|
+
credentialDefinitionId,
|
|
384
|
+
issuerDid: derived.issuerId,
|
|
385
|
+
credentialSchemaId: derived.credentialSchemaId,
|
|
386
|
+
ecosystemDid: derived.ecosystemDid,
|
|
387
|
+
jsonSchemaCredentialId: derived.jsonSchemaCredentialId,
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
catch (error) {
|
|
391
|
+
const cannotCheck = !(error instanceof AnonCredsTrustService_1.AnonCredsTrustError) || error.reason === AnonCredsTrustService_1.AnonCredsTrustErrorReason.Unavailable;
|
|
392
|
+
reject(index, cannotCheck
|
|
393
|
+
? AnonCredsTrustService_1.AnonCredsTrustProblemCode.TrustResolutionUnavailable
|
|
394
|
+
: AnonCredsTrustService_1.AnonCredsTrustProblemCode.IssuerNotAuthorized, `${error}`, { credentialDefinitionId });
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
// One read answers every credential of an issuer on a CredentialSchema
|
|
398
|
+
const issuersByCredentialSchema = new Map();
|
|
399
|
+
for (const { credentialSchemaId, issuerDid } of candidates) {
|
|
400
|
+
issuersByCredentialSchema.set(credentialSchemaId, [
|
|
401
|
+
...((_h = issuersByCredentialSchema.get(credentialSchemaId)) !== null && _h !== void 0 ? _h : []),
|
|
402
|
+
issuerDid,
|
|
403
|
+
]);
|
|
404
|
+
}
|
|
405
|
+
for (const [credentialSchemaId, issuers] of issuersByCredentialSchema) {
|
|
406
|
+
// A read that fails leaves every issuer of the CredentialSchema unchecked, per
|
|
407
|
+
// [VSA-VTI-FLOW-VERIFY-AC-8]
|
|
408
|
+
let result;
|
|
409
|
+
try {
|
|
410
|
+
result = await agent.anonCredsTrust.findUnaccreditedDids(issuers, types_1.ParticipantRole.Issuer, credentialSchemaId);
|
|
411
|
+
}
|
|
412
|
+
catch (error) {
|
|
413
|
+
logger.error(`The agent cannot read the ISSUER Participants of ${credentialSchemaId}: ${error}`);
|
|
414
|
+
result = { unaccredited: [], unchecked: issuers };
|
|
415
|
+
}
|
|
416
|
+
for (const candidate of candidates) {
|
|
417
|
+
if (candidate.credentialSchemaId !== credentialSchemaId)
|
|
418
|
+
continue;
|
|
419
|
+
const { index, credentialDefinitionId, issuerDid } = candidate;
|
|
420
|
+
const known = { credentialDefinitionId, issuerDid, credentialSchemaId };
|
|
421
|
+
if (result.unaccredited.includes(issuerDid)) {
|
|
422
|
+
reject(index, AnonCredsTrustService_1.AnonCredsTrustProblemCode.IssuerNotAuthorized, `${issuerDid} holds no active ISSUER Participant for the CredentialSchema ${credentialSchemaId}`, known);
|
|
423
|
+
}
|
|
424
|
+
else if (result.unchecked.includes(issuerDid)) {
|
|
425
|
+
reject(index, AnonCredsTrustService_1.AnonCredsTrustProblemCode.TrustResolutionUnavailable, `the agent cannot check the ISSUER Participant of ${issuerDid} for the CredentialSchema ${credentialSchemaId}`, known);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (rejected.length === 0) {
|
|
430
|
+
// The record keeps the values that the agent verified, so a later read resolves nothing
|
|
431
|
+
record.metadata.set(AnonCredsTrustService_1.PRESENTED_CREDENTIALS_METADATA, candidates.map((_a) => {
|
|
432
|
+
var { index: _index } = _a, presented = __rest(_a, ["index"]);
|
|
433
|
+
return presented;
|
|
434
|
+
}));
|
|
435
|
+
await agent.didcomm.proofs.update(record);
|
|
436
|
+
emitTrustDecided(agent, record);
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
rejected.sort((a, b) => a.index - b.index);
|
|
440
|
+
record.metadata.set(AnonCredsTrustService_1.REJECTED_CREDENTIALS_METADATA, rejected);
|
|
441
|
+
// A credential that is not authorized decides the code. Its cause comes first in the report.
|
|
442
|
+
const notAuthorized = rejected.filter(({ code }) => code === AnonCredsTrustService_1.AnonCredsTrustProblemCode.IssuerNotAuthorized);
|
|
443
|
+
const unavailable = rejected.filter(({ code }) => code === AnonCredsTrustService_1.AnonCredsTrustProblemCode.TrustResolutionUnavailable);
|
|
444
|
+
await abandonPresentation(agent, record, connection, notAuthorized.length > 0
|
|
445
|
+
? AnonCredsTrustService_1.AnonCredsTrustProblemCode.IssuerNotAuthorized
|
|
446
|
+
: AnonCredsTrustService_1.AnonCredsTrustProblemCode.TrustResolutionUnavailable, [...new Set([...notAuthorized, ...unavailable].map(({ note }) => note))].join('; '), logger);
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Credo emits the change to `presentation-received` before the trust decision runs. The Events API
|
|
451
|
+
* reports that change on this event, per [VSA-VTI-FLOW-VERIFY-AC-7]. The event carries the result
|
|
452
|
+
* of the decision. The function emits nothing for a record that is not in `presentation-received`:
|
|
453
|
+
* Credo reported the state of that record already.
|
|
454
|
+
*/
|
|
455
|
+
function emitTrustDecided(agent, record) {
|
|
456
|
+
if (record.state !== didcomm_1.DidCommProofState.PresentationReceived)
|
|
457
|
+
return;
|
|
458
|
+
agent.events.emit(agent.context, {
|
|
459
|
+
type: VsAgentEvents_1.VsAgentEventTypes.PresentationTrustDecided,
|
|
460
|
+
payload: { proofRecord: record.clone(), previousState: didcomm_1.DidCommProofState.RequestSent },
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
async function abandonPresentation(agent, record, connection, code, description, logger) {
|
|
464
|
+
var _a, _b;
|
|
465
|
+
logger.warn(`The presentation ${record.id} fails the AnonCreds trust decision (${code}): ${description}`);
|
|
466
|
+
record.isVerified = false;
|
|
467
|
+
record.errorMessage = `${code}: ${description}`;
|
|
468
|
+
// The Events API reports the change to `presentation-received` with the cause of the failure.
|
|
469
|
+
// It reports the change to `abandoned` after that.
|
|
470
|
+
emitTrustDecided(agent, record);
|
|
471
|
+
// `updateState` emits the state change with `previousState`, per [VSA-VTI-FLOW-VERIFY-AC-7]
|
|
472
|
+
const protocol = agent.dependencyManager
|
|
473
|
+
.resolve(didcomm_1.DidCommProofsModuleConfig)
|
|
474
|
+
.proofProtocols.find(candidate => candidate.version === record.protocolVersion);
|
|
475
|
+
if (!protocol) {
|
|
476
|
+
throw new core_1.CredoError(`No proof protocol registered for protocol version ${record.protocolVersion}, so the presentation ${record.id} cannot end in abandoned`);
|
|
477
|
+
}
|
|
478
|
+
const problemReport = new didcomm_1.DidCommPresentationV2ProblemReportMessage({
|
|
479
|
+
description: { code, en: description },
|
|
480
|
+
});
|
|
481
|
+
problemReport.setThread({ threadId: record.threadId, parentThreadId: record.parentThreadId });
|
|
482
|
+
try {
|
|
483
|
+
// An exchange with no connection has no route. Its last two messages give the services.
|
|
484
|
+
const outboundMessageContext = await (0, didcomm_1.getOutboundDidCommMessageContext)(agent.context, {
|
|
485
|
+
message: problemReport,
|
|
486
|
+
associatedRecord: record,
|
|
487
|
+
connectionRecord: connection,
|
|
488
|
+
lastReceivedMessage: connection
|
|
489
|
+
? undefined
|
|
490
|
+
: ((_a = (await protocol.findPresentationMessage(agent.context, record.id))) !== null && _a !== void 0 ? _a : undefined),
|
|
491
|
+
lastSentMessage: connection
|
|
492
|
+
? undefined
|
|
493
|
+
: ((_b = (await protocol.findRequestMessage(agent.context, record.id))) !== null && _b !== void 0 ? _b : undefined),
|
|
494
|
+
});
|
|
495
|
+
await agent.dependencyManager.resolve(didcomm_1.DidCommMessageSender).sendMessage(outboundMessageContext);
|
|
496
|
+
}
|
|
497
|
+
catch (error) {
|
|
498
|
+
logger.error(`The agent cannot send the problem report of presentation ${record.id}: ${error}`);
|
|
499
|
+
}
|
|
500
|
+
await protocol.updateState(agent.context, record, didcomm_1.DidCommProofState.Abandoned);
|
|
501
|
+
}
|
|
148
502
|
//# sourceMappingURL=BaseMessageEvents.js.map
|