@veridid/signing 0.0.0-stage → 1.0.0
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/LICENSE +202 -0
- package/README.md +39 -2
- package/build/SigningApi.d.mts +368 -0
- package/build/SigningApi.d.mts.map +1 -0
- package/build/SigningApi.mjs +516 -0
- package/build/SigningApi.mjs.map +1 -0
- package/build/SigningEvents.d.mts +71 -0
- package/build/SigningEvents.d.mts.map +1 -0
- package/build/SigningEvents.mjs +16 -0
- package/build/SigningEvents.mjs.map +1 -0
- package/build/SigningModule.d.mts +42 -0
- package/build/SigningModule.d.mts.map +1 -0
- package/build/SigningModule.mjs +91 -0
- package/build/SigningModule.mjs.map +1 -0
- package/build/SigningRole.d.mts +25 -0
- package/build/SigningRole.d.mts.map +1 -0
- package/build/SigningRole.mjs +27 -0
- package/build/SigningRole.mjs.map +1 -0
- package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs +10 -0
- package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs +7 -0
- package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateParam.mjs +9 -0
- package/build/compat.d.mts +24 -0
- package/build/compat.d.mts.map +1 -0
- package/build/compat.mjs +26 -0
- package/build/compat.mjs.map +1 -0
- package/build/delivery/ArtifactDeliveryStrategy.d.mts +74 -0
- package/build/delivery/ArtifactDeliveryStrategy.d.mts.map +1 -0
- package/build/delivery/InlineBase64Strategy.d.mts +50 -0
- package/build/delivery/InlineBase64Strategy.d.mts.map +1 -0
- package/build/delivery/InlineBase64Strategy.mjs +80 -0
- package/build/delivery/InlineBase64Strategy.mjs.map +1 -0
- package/build/delivery/index.mjs +1 -0
- package/build/errors/ArtifactTooLargeError.d.mts +12 -0
- package/build/errors/ArtifactTooLargeError.d.mts.map +1 -0
- package/build/errors/ArtifactTooLargeError.mjs +15 -0
- package/build/errors/ArtifactTooLargeError.mjs.map +1 -0
- package/build/errors/DigestMismatchError.d.mts +12 -0
- package/build/errors/DigestMismatchError.d.mts.map +1 -0
- package/build/errors/DigestMismatchError.mjs +15 -0
- package/build/errors/DigestMismatchError.mjs.map +1 -0
- package/build/errors/IdempotencyConflictError.d.mts +12 -0
- package/build/errors/IdempotencyConflictError.d.mts.map +1 -0
- package/build/errors/IdempotencyConflictError.mjs +15 -0
- package/build/errors/IdempotencyConflictError.mjs.map +1 -0
- package/build/errors/InvalidStateError.d.mts +14 -0
- package/build/errors/InvalidStateError.d.mts.map +1 -0
- package/build/errors/InvalidStateError.mjs +16 -0
- package/build/errors/InvalidStateError.mjs.map +1 -0
- package/build/errors/PolicyEnforcementError.d.mts +12 -0
- package/build/errors/PolicyEnforcementError.d.mts.map +1 -0
- package/build/errors/PolicyEnforcementError.mjs +15 -0
- package/build/errors/PolicyEnforcementError.mjs.map +1 -0
- package/build/errors/SigningError.d.mts +16 -0
- package/build/errors/SigningError.d.mts.map +1 -0
- package/build/errors/SigningError.mjs +16 -0
- package/build/errors/SigningError.mjs.map +1 -0
- package/build/errors/ThresholdNotMetError.d.mts +12 -0
- package/build/errors/ThresholdNotMetError.d.mts.map +1 -0
- package/build/errors/ThresholdNotMetError.mjs +15 -0
- package/build/errors/ThresholdNotMetError.mjs.map +1 -0
- package/build/errors/UnsupportedCanonicalizerError.d.mts +12 -0
- package/build/errors/UnsupportedCanonicalizerError.d.mts.map +1 -0
- package/build/errors/UnsupportedCanonicalizerError.mjs +16 -0
- package/build/errors/UnsupportedCanonicalizerError.mjs.map +1 -0
- package/build/errors/UnsupportedSuiteError.d.mts +12 -0
- package/build/errors/UnsupportedSuiteError.d.mts.map +1 -0
- package/build/errors/UnsupportedSuiteError.mjs +16 -0
- package/build/errors/UnsupportedSuiteError.mjs.map +1 -0
- package/build/errors/index.d.mts +9 -0
- package/build/errors/index.mjs +9 -0
- package/build/handlers/CombineMessageHandler.d.mts +22 -0
- package/build/handlers/CombineMessageHandler.d.mts.map +1 -0
- package/build/handlers/CombineMessageHandler.mjs +25 -0
- package/build/handlers/CombineMessageHandler.mjs.map +1 -0
- package/build/handlers/ConsentMessageHandler.d.mts +19 -0
- package/build/handlers/ConsentMessageHandler.d.mts.map +1 -0
- package/build/handlers/ConsentMessageHandler.mjs +21 -0
- package/build/handlers/ConsentMessageHandler.mjs.map +1 -0
- package/build/handlers/DeclineMessageHandler.d.mts +19 -0
- package/build/handlers/DeclineMessageHandler.d.mts.map +1 -0
- package/build/handlers/DeclineMessageHandler.mjs +21 -0
- package/build/handlers/DeclineMessageHandler.mjs.map +1 -0
- package/build/handlers/PartialSignatureMessageHandler.d.mts +19 -0
- package/build/handlers/PartialSignatureMessageHandler.d.mts.map +1 -0
- package/build/handlers/PartialSignatureMessageHandler.mjs +21 -0
- package/build/handlers/PartialSignatureMessageHandler.mjs.map +1 -0
- package/build/handlers/ProposeSigningMessageHandler.d.mts +19 -0
- package/build/handlers/ProposeSigningMessageHandler.d.mts.map +1 -0
- package/build/handlers/ProposeSigningMessageHandler.mjs +21 -0
- package/build/handlers/ProposeSigningMessageHandler.mjs.map +1 -0
- package/build/handlers/ProvideArtifactsMessageHandler.d.mts +19 -0
- package/build/handlers/ProvideArtifactsMessageHandler.d.mts.map +1 -0
- package/build/handlers/ProvideArtifactsMessageHandler.mjs +21 -0
- package/build/handlers/ProvideArtifactsMessageHandler.mjs.map +1 -0
- package/build/handlers/RequestSigningMessageHandler.d.mts +19 -0
- package/build/handlers/RequestSigningMessageHandler.d.mts.map +1 -0
- package/build/handlers/RequestSigningMessageHandler.mjs +21 -0
- package/build/handlers/RequestSigningMessageHandler.mjs.map +1 -0
- package/build/handlers/SigningAckMessageHandler.d.mts +22 -0
- package/build/handlers/SigningAckMessageHandler.d.mts.map +1 -0
- package/build/handlers/SigningAckMessageHandler.mjs +25 -0
- package/build/handlers/SigningAckMessageHandler.mjs.map +1 -0
- package/build/handlers/SigningProblemReportMessageHandler.d.mts +19 -0
- package/build/handlers/SigningProblemReportMessageHandler.d.mts.map +1 -0
- package/build/handlers/SigningProblemReportMessageHandler.mjs +21 -0
- package/build/handlers/SigningProblemReportMessageHandler.mjs.map +1 -0
- package/build/handlers/index.d.mts +9 -0
- package/build/handlers/index.mjs +9 -0
- package/build/index.d.mts +75 -0
- package/build/index.mjs +63 -0
- package/build/messages/CombineMessage.d.mts +32 -0
- package/build/messages/CombineMessage.d.mts.map +1 -0
- package/build/messages/CombineMessage.mjs +47 -0
- package/build/messages/CombineMessage.mjs.map +1 -0
- package/build/messages/ConsentMessage.d.mts +32 -0
- package/build/messages/ConsentMessage.d.mts.map +1 -0
- package/build/messages/ConsentMessage.mjs +46 -0
- package/build/messages/ConsentMessage.mjs.map +1 -0
- package/build/messages/DeclineMessage.d.mts +26 -0
- package/build/messages/DeclineMessage.d.mts.map +1 -0
- package/build/messages/DeclineMessage.mjs +47 -0
- package/build/messages/DeclineMessage.mjs.map +1 -0
- package/build/messages/PartialSignatureMessage.d.mts +36 -0
- package/build/messages/PartialSignatureMessage.d.mts.map +1 -0
- package/build/messages/PartialSignatureMessage.mjs +72 -0
- package/build/messages/PartialSignatureMessage.mjs.map +1 -0
- package/build/messages/ProposeSigningMessage.d.mts +27 -0
- package/build/messages/ProposeSigningMessage.d.mts.map +1 -0
- package/build/messages/ProposeSigningMessage.mjs +41 -0
- package/build/messages/ProposeSigningMessage.mjs.map +1 -0
- package/build/messages/ProvideArtifactsMessage.d.mts +62 -0
- package/build/messages/ProvideArtifactsMessage.d.mts.map +1 -0
- package/build/messages/ProvideArtifactsMessage.mjs +40 -0
- package/build/messages/ProvideArtifactsMessage.mjs.map +1 -0
- package/build/messages/RequestSigningMessage.d.mts +38 -0
- package/build/messages/RequestSigningMessage.d.mts.map +1 -0
- package/build/messages/RequestSigningMessage.mjs +62 -0
- package/build/messages/RequestSigningMessage.mjs.map +1 -0
- package/build/messages/SigningAckMessage.d.mts +26 -0
- package/build/messages/SigningAckMessage.d.mts.map +1 -0
- package/build/messages/SigningAckMessage.mjs +46 -0
- package/build/messages/SigningAckMessage.mjs.map +1 -0
- package/build/messages/SigningProblemReportMessage.d.mts +44 -0
- package/build/messages/SigningProblemReportMessage.d.mts.map +1 -0
- package/build/messages/SigningProblemReportMessage.mjs +65 -0
- package/build/messages/SigningProblemReportMessage.mjs.map +1 -0
- package/build/messages/index.d.mts +9 -0
- package/build/messages/index.mjs +9 -0
- package/build/models/AggregationResult.d.mts +85 -0
- package/build/models/AggregationResult.d.mts.map +1 -0
- package/build/models/ArtifactMetadata.d.mts +37 -0
- package/build/models/ArtifactMetadata.d.mts.map +1 -0
- package/build/models/AuthzArtifact.d.mts +178 -0
- package/build/models/AuthzArtifact.d.mts.map +1 -0
- package/build/models/Capabilities.d.mts +109 -0
- package/build/models/Capabilities.d.mts.map +1 -0
- package/build/models/JoinToken.d.mts +344 -0
- package/build/models/JoinToken.d.mts.map +1 -0
- package/build/models/JoinToken.mjs +14 -0
- package/build/models/JoinToken.mjs.map +1 -0
- package/build/models/PartialSignature.d.mts +82 -0
- package/build/models/PartialSignature.d.mts.map +1 -0
- package/build/models/PolicyContext.d.mts +55 -0
- package/build/models/PolicyContext.d.mts.map +1 -0
- package/build/models/RouterAttestation.d.mts +186 -0
- package/build/models/RouterAttestation.d.mts.map +1 -0
- package/build/models/Session.d.mts +62 -0
- package/build/models/Session.d.mts.map +1 -0
- package/build/models/Session.mjs +19 -0
- package/build/models/Session.mjs.map +1 -0
- package/build/models/SignableObject.d.mts +71 -0
- package/build/models/SignableObject.d.mts.map +1 -0
- package/build/models/SigningState.d.mts +21 -0
- package/build/models/SigningState.d.mts.map +1 -0
- package/build/models/SigningState.mjs +23 -0
- package/build/models/SigningState.mjs.map +1 -0
- package/build/models/Suite.d.mts +59 -0
- package/build/models/Suite.d.mts.map +1 -0
- package/build/models/index.d.mts +12 -0
- package/build/pdf/PdfUtils.d.mts +160 -0
- package/build/pdf/PdfUtils.d.mts.map +1 -0
- package/build/pdf/PdfUtils.mjs +283 -0
- package/build/pdf/PdfUtils.mjs.map +1 -0
- package/build/pdf/index.mjs +1 -0
- package/build/registry/aggregators/Aggregator.d.mts +85 -0
- package/build/registry/aggregators/Aggregator.d.mts.map +1 -0
- package/build/registry/aggregators/AggregatorRegistry.d.mts +55 -0
- package/build/registry/aggregators/AggregatorRegistry.d.mts.map +1 -0
- package/build/registry/aggregators/AggregatorRegistry.mjs +76 -0
- package/build/registry/aggregators/AggregatorRegistry.mjs.map +1 -0
- package/build/registry/aggregators/BundleNoneAggregator.d.mts +43 -0
- package/build/registry/aggregators/BundleNoneAggregator.d.mts.map +1 -0
- package/build/registry/aggregators/BundleNoneAggregator.mjs +65 -0
- package/build/registry/aggregators/BundleNoneAggregator.mjs.map +1 -0
- package/build/registry/aggregators/index.d.mts +3 -0
- package/build/registry/aggregators/index.mjs +2 -0
- package/build/registry/canonicalizers/Canonicalizer.d.mts +67 -0
- package/build/registry/canonicalizers/Canonicalizer.d.mts.map +1 -0
- package/build/registry/canonicalizers/CanonicalizerRegistry.d.mts +55 -0
- package/build/registry/canonicalizers/CanonicalizerRegistry.d.mts.map +1 -0
- package/build/registry/canonicalizers/CanonicalizerRegistry.mjs +78 -0
- package/build/registry/canonicalizers/CanonicalizerRegistry.mjs.map +1 -0
- package/build/registry/canonicalizers/PdfIncrementalUpdateCanonicalizer.d.mts +126 -0
- package/build/registry/canonicalizers/PdfIncrementalUpdateCanonicalizer.d.mts.map +1 -0
- package/build/registry/canonicalizers/PdfIncrementalUpdateCanonicalizer.mjs +143 -0
- package/build/registry/canonicalizers/PdfIncrementalUpdateCanonicalizer.mjs.map +1 -0
- package/build/registry/canonicalizers/RawBytesCanonicalizer.d.mts +34 -0
- package/build/registry/canonicalizers/RawBytesCanonicalizer.d.mts.map +1 -0
- package/build/registry/canonicalizers/RawBytesCanonicalizer.mjs +55 -0
- package/build/registry/canonicalizers/RawBytesCanonicalizer.mjs.map +1 -0
- package/build/registry/canonicalizers/index.d.mts +4 -0
- package/build/registry/canonicalizers/index.mjs +3 -0
- package/build/registry/index.d.mts +18 -0
- package/build/registry/index.mjs +14 -0
- package/build/registry/policies/Policy.d.mts +62 -0
- package/build/registry/policies/Policy.d.mts.map +1 -0
- package/build/registry/policies/PolicyRegistry.d.mts +54 -0
- package/build/registry/policies/PolicyRegistry.d.mts.map +1 -0
- package/build/registry/policies/PolicyRegistry.mjs +73 -0
- package/build/registry/policies/PolicyRegistry.mjs.map +1 -0
- package/build/registry/policies/TimeWindowPolicy.d.mts +85 -0
- package/build/registry/policies/TimeWindowPolicy.d.mts.map +1 -0
- package/build/registry/policies/TimeWindowPolicy.mjs +111 -0
- package/build/registry/policies/TimeWindowPolicy.mjs.map +1 -0
- package/build/registry/policies/index.d.mts +3 -0
- package/build/registry/policies/index.mjs +2 -0
- package/build/registry/suites/JwsEd25519Suite.d.mts +47 -0
- package/build/registry/suites/JwsEd25519Suite.d.mts.map +1 -0
- package/build/registry/suites/JwsEd25519Suite.mjs +101 -0
- package/build/registry/suites/JwsEd25519Suite.mjs.map +1 -0
- package/build/registry/suites/PadesBLtaSuite.d.mts +106 -0
- package/build/registry/suites/PadesBLtaSuite.d.mts.map +1 -0
- package/build/registry/suites/PadesBLtaSuite.mjs +122 -0
- package/build/registry/suites/PadesBLtaSuite.mjs.map +1 -0
- package/build/registry/suites/SignatureSuite.d.mts +128 -0
- package/build/registry/suites/SignatureSuite.d.mts.map +1 -0
- package/build/registry/suites/SignatureSuiteRegistry.d.mts +62 -0
- package/build/registry/suites/SignatureSuiteRegistry.d.mts.map +1 -0
- package/build/registry/suites/SignatureSuiteRegistry.mjs +87 -0
- package/build/registry/suites/SignatureSuiteRegistry.mjs.map +1 -0
- package/build/registry/suites/index.d.mts +4 -0
- package/build/registry/suites/index.mjs +3 -0
- package/build/repository/CounterRecord.d.mts +84 -0
- package/build/repository/CounterRecord.d.mts.map +1 -0
- package/build/repository/CounterRecord.mjs +82 -0
- package/build/repository/CounterRecord.mjs.map +1 -0
- package/build/repository/CounterRepository.d.mts +22 -0
- package/build/repository/CounterRepository.d.mts.map +1 -0
- package/build/repository/CounterRepository.mjs +51 -0
- package/build/repository/CounterRepository.mjs.map +1 -0
- package/build/repository/SigningSessionRecord.d.mts +102 -0
- package/build/repository/SigningSessionRecord.d.mts.map +1 -0
- package/build/repository/SigningSessionRecord.mjs +96 -0
- package/build/repository/SigningSessionRecord.mjs.map +1 -0
- package/build/repository/SigningSessionRepository.d.mts +30 -0
- package/build/repository/SigningSessionRepository.d.mts.map +1 -0
- package/build/repository/SigningSessionRepository.mjs +52 -0
- package/build/repository/SigningSessionRepository.mjs.map +1 -0
- package/build/repository/index.d.mts +4 -0
- package/build/repository/index.mjs +4 -0
- package/build/services/CounterService.d.mts +121 -0
- package/build/services/CounterService.d.mts.map +1 -0
- package/build/services/CounterService.mjs +176 -0
- package/build/services/CounterService.mjs.map +1 -0
- package/build/services/HPKEService.d.mts +174 -0
- package/build/services/HPKEService.d.mts.map +1 -0
- package/build/services/HPKEService.mjs +195 -0
- package/build/services/HPKEService.mjs.map +1 -0
- package/build/services/SigningService.d.mts +387 -0
- package/build/services/SigningService.d.mts.map +1 -0
- package/build/services/SigningService.mjs +1104 -0
- package/build/services/SigningService.mjs.map +1 -0
- package/build/services/index.d.mts +3 -0
- package/build/services/index.mjs +3 -0
- package/package.json +44 -3
|
@@ -0,0 +1,1104 @@
|
|
|
1
|
+
import { SigningState } from "../models/SigningState.mjs";
|
|
2
|
+
import { SessionMode } from "../models/Session.mjs";
|
|
3
|
+
import { SigningRole } from "../SigningRole.mjs";
|
|
4
|
+
import { SigningError } from "../errors/SigningError.mjs";
|
|
5
|
+
import { ThresholdNotMetError } from "../errors/ThresholdNotMetError.mjs";
|
|
6
|
+
import { DigestMismatchError } from "../errors/DigestMismatchError.mjs";
|
|
7
|
+
import "../errors/index.mjs";
|
|
8
|
+
import { SigningSessionRecord } from "../repository/SigningSessionRecord.mjs";
|
|
9
|
+
import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs";
|
|
10
|
+
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
|
|
11
|
+
import { SigningSessionRepository } from "../repository/SigningSessionRepository.mjs";
|
|
12
|
+
import { CanonicalizerRegistry } from "../registry/canonicalizers/CanonicalizerRegistry.mjs";
|
|
13
|
+
import "../registry/canonicalizers/index.mjs";
|
|
14
|
+
import { SignatureSuiteRegistry } from "../registry/suites/SignatureSuiteRegistry.mjs";
|
|
15
|
+
import "../registry/suites/index.mjs";
|
|
16
|
+
import { AggregatorRegistry } from "../registry/aggregators/AggregatorRegistry.mjs";
|
|
17
|
+
import "../registry/aggregators/index.mjs";
|
|
18
|
+
import { PolicyRegistry } from "../registry/policies/PolicyRegistry.mjs";
|
|
19
|
+
import "../registry/policies/index.mjs";
|
|
20
|
+
import { InlineBase64Strategy } from "../delivery/InlineBase64Strategy.mjs";
|
|
21
|
+
import { HPKEService } from "./HPKEService.mjs";
|
|
22
|
+
import { CounterService } from "./CounterService.mjs";
|
|
23
|
+
import { ProposeSigningMessage } from "../messages/ProposeSigningMessage.mjs";
|
|
24
|
+
import { RequestSigningMessage } from "../messages/RequestSigningMessage.mjs";
|
|
25
|
+
import { ConsentMessage } from "../messages/ConsentMessage.mjs";
|
|
26
|
+
import { PartialSignatureMessage } from "../messages/PartialSignatureMessage.mjs";
|
|
27
|
+
import { ProvideArtifactsMessage } from "../messages/ProvideArtifactsMessage.mjs";
|
|
28
|
+
import { DeclineMessage } from "../messages/DeclineMessage.mjs";
|
|
29
|
+
import { SigningProblemReportMessage } from "../messages/SigningProblemReportMessage.mjs";
|
|
30
|
+
import "../messages/index.mjs";
|
|
31
|
+
import { SigningEventTypes } from "../SigningEvents.mjs";
|
|
32
|
+
import { CredoError, EventEmitter, injectable, utils } from "@credo-ts/core";
|
|
33
|
+
import { DidCommMessageRepository, DidCommMessageSender } from "@credo-ts/didcomm";
|
|
34
|
+
|
|
35
|
+
//#region src/services/SigningService.ts
|
|
36
|
+
var _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _ref10, _ref11;
|
|
37
|
+
let SigningService = class SigningService {
|
|
38
|
+
constructor(sessionRepository, messageSender, didCommMessageRepository, canonicalizerRegistry, suiteRegistry, aggregatorRegistry, policyRegistry, artifactDelivery, eventEmitter, hpkeService, counterService) {
|
|
39
|
+
this.sessionRepository = sessionRepository;
|
|
40
|
+
this.messageSender = messageSender;
|
|
41
|
+
this.didCommMessageRepository = didCommMessageRepository;
|
|
42
|
+
this.canonicalizerRegistry = canonicalizerRegistry;
|
|
43
|
+
this.suiteRegistry = suiteRegistry;
|
|
44
|
+
this.aggregatorRegistry = aggregatorRegistry;
|
|
45
|
+
this.policyRegistry = policyRegistry;
|
|
46
|
+
this.artifactDelivery = artifactDelivery;
|
|
47
|
+
this.eventEmitter = eventEmitter;
|
|
48
|
+
this.hpkeService = hpkeService;
|
|
49
|
+
this.counterService = counterService;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Emit a state changed event
|
|
53
|
+
*/
|
|
54
|
+
emitStateChangedEvent(agentContext, sessionRecord, previousState) {
|
|
55
|
+
this.eventEmitter.emit(agentContext, {
|
|
56
|
+
type: SigningEventTypes.SigningStateChanged,
|
|
57
|
+
payload: {
|
|
58
|
+
sessionRecord,
|
|
59
|
+
previousState
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create and send a signing proposal
|
|
65
|
+
* Role: Requester → Signer
|
|
66
|
+
*/
|
|
67
|
+
async createProposal(agentContext, options) {
|
|
68
|
+
const { connectionId, session } = options;
|
|
69
|
+
const sessionRecord = new SigningSessionRecord({
|
|
70
|
+
id: utils.uuid(),
|
|
71
|
+
sessionId: session?.sessionId || utils.uuid(),
|
|
72
|
+
state: SigningState.ProposalSent,
|
|
73
|
+
role: SigningRole.Requester,
|
|
74
|
+
connectionId,
|
|
75
|
+
threadId: utils.uuid(),
|
|
76
|
+
mode: session?.mode,
|
|
77
|
+
threshold: session?.threshold
|
|
78
|
+
});
|
|
79
|
+
const capabilities = {
|
|
80
|
+
canonicalizers: this.canonicalizerRegistry.capabilities,
|
|
81
|
+
suites: this.suiteRegistry.capabilities,
|
|
82
|
+
aggregators: this.aggregatorRegistry.capabilities,
|
|
83
|
+
policies: this.policyRegistry.capabilities
|
|
84
|
+
};
|
|
85
|
+
const message = new ProposeSigningMessage({
|
|
86
|
+
id: utils.uuid(),
|
|
87
|
+
session: session || {
|
|
88
|
+
sessionId: sessionRecord.sessionId,
|
|
89
|
+
mode: SessionMode.Single
|
|
90
|
+
},
|
|
91
|
+
capabilities
|
|
92
|
+
});
|
|
93
|
+
await this.sessionRepository.save(agentContext, sessionRecord);
|
|
94
|
+
this.emitStateChangedEvent(agentContext, sessionRecord, null);
|
|
95
|
+
return {
|
|
96
|
+
record: sessionRecord,
|
|
97
|
+
message
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Process received proposal
|
|
102
|
+
* Role: Signer receives from Requester
|
|
103
|
+
*/
|
|
104
|
+
async processProposal(messageContext) {
|
|
105
|
+
const { message, agentContext, connection } = messageContext;
|
|
106
|
+
if (!connection) throw new CredoError("No connection associated with proposal");
|
|
107
|
+
const sessionRecord = new SigningSessionRecord({
|
|
108
|
+
id: utils.uuid(),
|
|
109
|
+
sessionId: message.session.sessionId,
|
|
110
|
+
state: SigningState.ProposalReceived,
|
|
111
|
+
role: SigningRole.Signer,
|
|
112
|
+
connectionId: connection.id,
|
|
113
|
+
threadId: message.id,
|
|
114
|
+
mode: message.session.mode,
|
|
115
|
+
threshold: message.session.threshold
|
|
116
|
+
});
|
|
117
|
+
sessionRecord.metadata.set("remoteCapabilities", message.capabilities);
|
|
118
|
+
await this.sessionRepository.save(agentContext, sessionRecord);
|
|
119
|
+
this.emitStateChangedEvent(agentContext, sessionRecord, null);
|
|
120
|
+
return sessionRecord;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Create and send a signing request
|
|
124
|
+
* Role: Requester → Signer(s)
|
|
125
|
+
*/
|
|
126
|
+
async createRequest(agentContext, options) {
|
|
127
|
+
const { connectionId, object, suite, session, idempotencyKey } = options;
|
|
128
|
+
if (!this.canonicalizerRegistry.getById(object.canonicalization.method)) throw new CredoError(`Canonicalizer not found: ${object.canonicalization.method}`);
|
|
129
|
+
if (!this.suiteRegistry.getById(suite.suite)) throw new CredoError(`Signature suite not found: ${suite.suite}`);
|
|
130
|
+
const sessionRecord = new SigningSessionRecord({
|
|
131
|
+
id: utils.uuid(),
|
|
132
|
+
sessionId: session?.sessionId || utils.uuid(),
|
|
133
|
+
state: SigningState.RequestSent,
|
|
134
|
+
role: SigningRole.Requester,
|
|
135
|
+
connectionId,
|
|
136
|
+
threadId: utils.uuid(),
|
|
137
|
+
mode: session?.mode || SessionMode.Single,
|
|
138
|
+
object,
|
|
139
|
+
suite,
|
|
140
|
+
threshold: session?.threshold
|
|
141
|
+
});
|
|
142
|
+
const message = new RequestSigningMessage({
|
|
143
|
+
id: utils.uuid(),
|
|
144
|
+
session: session || {
|
|
145
|
+
sessionId: sessionRecord.sessionId,
|
|
146
|
+
mode: SessionMode.Single
|
|
147
|
+
},
|
|
148
|
+
object,
|
|
149
|
+
suite,
|
|
150
|
+
idempotencyKey
|
|
151
|
+
});
|
|
152
|
+
await this.sessionRepository.save(agentContext, sessionRecord);
|
|
153
|
+
this.emitStateChangedEvent(agentContext, sessionRecord, null);
|
|
154
|
+
return {
|
|
155
|
+
record: sessionRecord,
|
|
156
|
+
message
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Process received signing request
|
|
161
|
+
* Role: Signer receives from Requester
|
|
162
|
+
*/
|
|
163
|
+
async processRequest(messageContext) {
|
|
164
|
+
const { message, agentContext, connection } = messageContext;
|
|
165
|
+
if (!connection) throw new CredoError("No connection associated with request");
|
|
166
|
+
if (message.idempotencyKey) {
|
|
167
|
+
const existing = await this.sessionRepository.findByQuery(agentContext, {
|
|
168
|
+
connectionId: connection.id,
|
|
169
|
+
"session.sessionId": message.session.sessionId
|
|
170
|
+
});
|
|
171
|
+
if (existing.length > 0) return existing[0];
|
|
172
|
+
}
|
|
173
|
+
const sessionRecord = new SigningSessionRecord({
|
|
174
|
+
id: utils.uuid(),
|
|
175
|
+
sessionId: message.session.sessionId,
|
|
176
|
+
state: SigningState.RequestReceived,
|
|
177
|
+
role: SigningRole.Signer,
|
|
178
|
+
connectionId: connection.id,
|
|
179
|
+
threadId: message.threadId,
|
|
180
|
+
mode: message.session.mode || "single",
|
|
181
|
+
object: message.object,
|
|
182
|
+
suite: message.suite,
|
|
183
|
+
threshold: message.session.threshold
|
|
184
|
+
});
|
|
185
|
+
await this.sessionRepository.save(agentContext, sessionRecord);
|
|
186
|
+
this.emitStateChangedEvent(agentContext, sessionRecord, null);
|
|
187
|
+
return sessionRecord;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Create and send consent to sign
|
|
191
|
+
* Role: Signer → Requester
|
|
192
|
+
*/
|
|
193
|
+
async createConsent(agentContext, options) {
|
|
194
|
+
const { sessionId, objectId, keyId, keyBindingPayload } = options;
|
|
195
|
+
const sessionRecord = await this.getSessionById(agentContext, sessionId);
|
|
196
|
+
sessionRecord.assertRole(SigningRole.Signer);
|
|
197
|
+
sessionRecord.assertState(SigningState.RequestReceived);
|
|
198
|
+
const keyBindingProof = {
|
|
199
|
+
type: "jws",
|
|
200
|
+
kid: keyId,
|
|
201
|
+
payload: keyBindingPayload || JSON.stringify({
|
|
202
|
+
sessionId,
|
|
203
|
+
objectId,
|
|
204
|
+
keyId
|
|
205
|
+
}),
|
|
206
|
+
signature: "mock-signature"
|
|
207
|
+
};
|
|
208
|
+
const previousState = sessionRecord.state;
|
|
209
|
+
sessionRecord.state = SigningState.ConsentSent;
|
|
210
|
+
const message = new ConsentMessage({
|
|
211
|
+
id: utils.uuid(),
|
|
212
|
+
sessionId: sessionRecord.sessionId,
|
|
213
|
+
objectId,
|
|
214
|
+
keyBindingProof
|
|
215
|
+
});
|
|
216
|
+
await this.sessionRepository.update(agentContext, sessionRecord);
|
|
217
|
+
this.emitStateChangedEvent(agentContext, sessionRecord, previousState);
|
|
218
|
+
return {
|
|
219
|
+
record: sessionRecord,
|
|
220
|
+
message
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Process received consent
|
|
225
|
+
* Role: Requester receives from Signer
|
|
226
|
+
*/
|
|
227
|
+
async processConsent(messageContext) {
|
|
228
|
+
const { message, agentContext } = messageContext;
|
|
229
|
+
const sessionRecord = await this.getSessionBySessionId(agentContext, message.sessionId);
|
|
230
|
+
sessionRecord.assertRole(SigningRole.Requester);
|
|
231
|
+
if (!sessionRecord.consentMessages) sessionRecord.consentMessages = [];
|
|
232
|
+
sessionRecord.consentMessages.push({
|
|
233
|
+
signer: message.keyBindingProof.kid,
|
|
234
|
+
objectId: message.objectId,
|
|
235
|
+
keyBindingProof: message.keyBindingProof,
|
|
236
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
237
|
+
});
|
|
238
|
+
const previousState = sessionRecord.state;
|
|
239
|
+
sessionRecord.state = SigningState.ConsentReceived;
|
|
240
|
+
await this.sessionRepository.update(agentContext, sessionRecord);
|
|
241
|
+
this.emitStateChangedEvent(agentContext, sessionRecord, previousState);
|
|
242
|
+
return sessionRecord;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Create and send signature
|
|
246
|
+
* Role: Signer → Requester/Coordinator
|
|
247
|
+
*/
|
|
248
|
+
async createSignature(agentContext, options) {
|
|
249
|
+
const { sessionId, objectId, keyId, round } = options;
|
|
250
|
+
const sessionRecord = await this.getSessionById(agentContext, sessionId);
|
|
251
|
+
sessionRecord.assertRole(SigningRole.Signer);
|
|
252
|
+
const canonicalizer = this.canonicalizerRegistry.getById(sessionRecord.object.canonicalization.method);
|
|
253
|
+
const dataToSign = sessionRecord.object.canonicalization.parameters?.data || sessionRecord.object.data || sessionRecord.object.id;
|
|
254
|
+
const canonical = await canonicalizer.canonicalize(dataToSign, sessionRecord.object.canonicalization.parameters);
|
|
255
|
+
if ((await canonicalizer.computeDigest(canonical, sessionRecord.object.digest.alg)).value !== sessionRecord.object.digest.value) throw new DigestMismatchError("Digest mismatch: computed digest does not match expected digest");
|
|
256
|
+
const signatureResult = await this.suiteRegistry.getById(sessionRecord.suite.suite).sign(agentContext, {
|
|
257
|
+
data: canonical,
|
|
258
|
+
keyRef: keyId,
|
|
259
|
+
parameters: sessionRecord.suite.constraints
|
|
260
|
+
});
|
|
261
|
+
const message = new PartialSignatureMessage({
|
|
262
|
+
id: utils.uuid(),
|
|
263
|
+
sessionId: sessionRecord.sessionId,
|
|
264
|
+
objectId,
|
|
265
|
+
signer: keyId,
|
|
266
|
+
suite: sessionRecord.suite.suite,
|
|
267
|
+
round,
|
|
268
|
+
signature: signatureResult
|
|
269
|
+
});
|
|
270
|
+
if (!sessionRecord.partialSignatures) sessionRecord.partialSignatures = [];
|
|
271
|
+
sessionRecord.partialSignatures.push({
|
|
272
|
+
signer: keyId,
|
|
273
|
+
suite: sessionRecord.suite.suite,
|
|
274
|
+
round,
|
|
275
|
+
signature: signatureResult,
|
|
276
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
277
|
+
});
|
|
278
|
+
const previousState = sessionRecord.state;
|
|
279
|
+
sessionRecord.state = SigningState.PartialSignatureReceived;
|
|
280
|
+
await this.sessionRepository.update(agentContext, sessionRecord);
|
|
281
|
+
this.emitStateChangedEvent(agentContext, sessionRecord, previousState);
|
|
282
|
+
return {
|
|
283
|
+
record: sessionRecord,
|
|
284
|
+
message
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Process received signature
|
|
289
|
+
* Role: Requester/Coordinator receives from Signer
|
|
290
|
+
*/
|
|
291
|
+
async processSignature(messageContext) {
|
|
292
|
+
const { message, agentContext } = messageContext;
|
|
293
|
+
const sessionRecord = await this.getSessionBySessionId(agentContext, message.sessionId);
|
|
294
|
+
if (!sessionRecord.partialSignatures) sessionRecord.partialSignatures = [];
|
|
295
|
+
sessionRecord.partialSignatures.push({
|
|
296
|
+
signer: message.signer,
|
|
297
|
+
suite: message.suite,
|
|
298
|
+
round: message.round,
|
|
299
|
+
signature: message.signature,
|
|
300
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
301
|
+
});
|
|
302
|
+
const previousState = sessionRecord.state;
|
|
303
|
+
sessionRecord.state = SigningState.PartialSignatureReceived;
|
|
304
|
+
await this.sessionRepository.update(agentContext, sessionRecord);
|
|
305
|
+
this.emitStateChangedEvent(agentContext, sessionRecord, previousState);
|
|
306
|
+
return sessionRecord;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Combine signatures and complete signing
|
|
310
|
+
* Role: Requester/Coordinator
|
|
311
|
+
*/
|
|
312
|
+
async completeSession(agentContext, options) {
|
|
313
|
+
const { sessionId, artifactData, artifactMimeType } = options;
|
|
314
|
+
const sessionRecord = await this.getSessionById(agentContext, sessionId);
|
|
315
|
+
if (!sessionRecord.isThresholdMet) throw new ThresholdNotMetError(sessionRecord.threshold?.n || 1, sessionRecord.partialSignatures.length);
|
|
316
|
+
await this.verifySignatures(agentContext, sessionRecord);
|
|
317
|
+
if (sessionRecord.threshold?.aggregation && sessionRecord.mode && sessionRecord.object) (await this.aggregatorRegistry.getById(sessionRecord.threshold.aggregation).aggregate(agentContext, {
|
|
318
|
+
partialSignatures: sessionRecord.partialSignatures,
|
|
319
|
+
session: {
|
|
320
|
+
sessionId: sessionRecord.sessionId,
|
|
321
|
+
mode: sessionRecord.mode,
|
|
322
|
+
threshold: sessionRecord.threshold
|
|
323
|
+
},
|
|
324
|
+
object: sessionRecord.object
|
|
325
|
+
})).finalSignature;
|
|
326
|
+
else sessionRecord.partialSignatures[0].signature?.value;
|
|
327
|
+
const artifacts = [];
|
|
328
|
+
if (artifactData) {
|
|
329
|
+
const artifact = await this.artifactDelivery.prepare(artifactData, artifactMimeType);
|
|
330
|
+
artifacts.push({
|
|
331
|
+
id: utils.uuid(),
|
|
332
|
+
mimeType: artifact.mimeType,
|
|
333
|
+
data: artifact.data,
|
|
334
|
+
hash: artifact.hash,
|
|
335
|
+
size: artifact.size
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
const message = new ProvideArtifactsMessage({
|
|
339
|
+
id: utils.uuid(),
|
|
340
|
+
sessionId: sessionRecord.sessionId,
|
|
341
|
+
artifacts
|
|
342
|
+
});
|
|
343
|
+
const previousState = sessionRecord.state;
|
|
344
|
+
sessionRecord.state = SigningState.Completed;
|
|
345
|
+
sessionRecord.artifacts = artifacts;
|
|
346
|
+
await this.sessionRepository.update(agentContext, sessionRecord);
|
|
347
|
+
this.emitStateChangedEvent(agentContext, sessionRecord, previousState);
|
|
348
|
+
return {
|
|
349
|
+
record: sessionRecord,
|
|
350
|
+
message
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Process signing completion
|
|
355
|
+
* Role: Signer receives completion from Requester
|
|
356
|
+
*/
|
|
357
|
+
async processComplete(messageContext) {
|
|
358
|
+
const { message, agentContext } = messageContext;
|
|
359
|
+
const sessionRecord = await this.getSessionBySessionId(agentContext, message.sessionId);
|
|
360
|
+
const previousState = sessionRecord.state;
|
|
361
|
+
sessionRecord.state = SigningState.Completed;
|
|
362
|
+
sessionRecord.artifacts = message.artifacts || [];
|
|
363
|
+
await this.sessionRepository.update(agentContext, sessionRecord);
|
|
364
|
+
this.emitStateChangedEvent(agentContext, sessionRecord, previousState);
|
|
365
|
+
return sessionRecord;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Decline signing request
|
|
369
|
+
* Role: Signer → Requester
|
|
370
|
+
*/
|
|
371
|
+
async createDecline(agentContext, options) {
|
|
372
|
+
const { sessionId, reason } = options;
|
|
373
|
+
const sessionRecord = await this.getSessionById(agentContext, sessionId);
|
|
374
|
+
sessionRecord.assertRole(SigningRole.Signer);
|
|
375
|
+
const message = new DeclineMessage({
|
|
376
|
+
id: utils.uuid(),
|
|
377
|
+
sessionId: sessionRecord.sessionId,
|
|
378
|
+
reason
|
|
379
|
+
});
|
|
380
|
+
const previousState = sessionRecord.state;
|
|
381
|
+
sessionRecord.state = SigningState.Declined;
|
|
382
|
+
await this.sessionRepository.update(agentContext, sessionRecord);
|
|
383
|
+
this.emitStateChangedEvent(agentContext, sessionRecord, previousState);
|
|
384
|
+
return {
|
|
385
|
+
record: sessionRecord,
|
|
386
|
+
message
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Process decline message
|
|
391
|
+
*/
|
|
392
|
+
async processDecline(messageContext) {
|
|
393
|
+
const { message, agentContext } = messageContext;
|
|
394
|
+
const sessionRecord = await this.getSessionBySessionId(agentContext, message.sessionId);
|
|
395
|
+
const previousState = sessionRecord.state;
|
|
396
|
+
sessionRecord.state = SigningState.Declined;
|
|
397
|
+
await this.sessionRepository.update(agentContext, sessionRecord);
|
|
398
|
+
this.emitStateChangedEvent(agentContext, sessionRecord, previousState);
|
|
399
|
+
return sessionRecord;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Abandon signing session
|
|
403
|
+
* Role: Any participant
|
|
404
|
+
*/
|
|
405
|
+
async createAbandon(agentContext, options) {
|
|
406
|
+
const { sessionId, code, explain } = options;
|
|
407
|
+
const sessionRecord = await this.getSessionById(agentContext, sessionId);
|
|
408
|
+
const message = new SigningProblemReportMessage({
|
|
409
|
+
id: utils.uuid(),
|
|
410
|
+
sessionId: sessionRecord.sessionId,
|
|
411
|
+
code,
|
|
412
|
+
explain
|
|
413
|
+
});
|
|
414
|
+
const previousState = sessionRecord.state;
|
|
415
|
+
sessionRecord.state = SigningState.Abandoned;
|
|
416
|
+
await this.sessionRepository.update(agentContext, sessionRecord);
|
|
417
|
+
this.emitStateChangedEvent(agentContext, sessionRecord, previousState);
|
|
418
|
+
return {
|
|
419
|
+
record: sessionRecord,
|
|
420
|
+
message
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Process abandon message
|
|
425
|
+
*/
|
|
426
|
+
async processAbandon(messageContext) {
|
|
427
|
+
const { message, agentContext } = messageContext;
|
|
428
|
+
const sessionRecord = await this.getSessionBySessionId(agentContext, message.sessionId);
|
|
429
|
+
const previousState = sessionRecord.state;
|
|
430
|
+
sessionRecord.state = SigningState.Abandoned;
|
|
431
|
+
await this.sessionRepository.update(agentContext, sessionRecord);
|
|
432
|
+
this.emitStateChangedEvent(agentContext, sessionRecord, previousState);
|
|
433
|
+
return sessionRecord;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Verify all collected signatures
|
|
437
|
+
*/
|
|
438
|
+
async verifySignatures(agentContext, sessionRecord) {
|
|
439
|
+
const canonicalizer = this.canonicalizerRegistry.getById(sessionRecord.object.canonicalization.method);
|
|
440
|
+
const dataToVerify = sessionRecord.object.canonicalization.parameters?.data || sessionRecord.object.data || sessionRecord.object.id;
|
|
441
|
+
const canonical = await canonicalizer.canonicalize(dataToVerify, sessionRecord.object.canonicalization.parameters);
|
|
442
|
+
const suite = this.suiteRegistry.getById(sessionRecord.suite.suite);
|
|
443
|
+
for (const sig of sessionRecord.partialSignatures) {
|
|
444
|
+
if (!sig.signature) continue;
|
|
445
|
+
if (!await suite.verify(agentContext, {
|
|
446
|
+
data: canonical,
|
|
447
|
+
signature: sig.signature,
|
|
448
|
+
publicKey: sig.signer
|
|
449
|
+
})) throw new DigestMismatchError(`Signature verification failed for signer: ${sig.signer}`);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Find a session by record ID
|
|
454
|
+
*/
|
|
455
|
+
async findById(agentContext, id) {
|
|
456
|
+
return this.sessionRepository.findById(agentContext, id);
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Get all signing sessions
|
|
460
|
+
*/
|
|
461
|
+
async getAll(agentContext) {
|
|
462
|
+
return this.sessionRepository.getAll(agentContext);
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Find sessions by query
|
|
466
|
+
*/
|
|
467
|
+
async findAllByQuery(agentContext, query, queryOptions) {
|
|
468
|
+
return this.sessionRepository.findByQuery(agentContext, query, queryOptions);
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Get session by record ID (throws if not found)
|
|
472
|
+
*/
|
|
473
|
+
async getSessionById(agentContext, id) {
|
|
474
|
+
const record = await this.sessionRepository.findById(agentContext, id);
|
|
475
|
+
if (!record) throw new SigningError(`Session not found: ${id}`);
|
|
476
|
+
return record;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Get session by session ID (throws if not found)
|
|
480
|
+
*/
|
|
481
|
+
async getSessionBySessionId(agentContext, sessionId) {
|
|
482
|
+
const records = await this.sessionRepository.findByQuery(agentContext, { sessionId });
|
|
483
|
+
if (records.length === 0) throw new SigningError(`Session not found: ${sessionId}`);
|
|
484
|
+
return records[0];
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Create an authorization artifact for Group Messaging Protocol
|
|
488
|
+
*
|
|
489
|
+
* Creates a signed authorization artifact that proves admin approval for
|
|
490
|
+
* privileged operations (invite, moderate, update). Supports both single
|
|
491
|
+
* admin and threshold (n-of-m) approval modes.
|
|
492
|
+
*
|
|
493
|
+
* Used by Group Messaging Protocol for:
|
|
494
|
+
* - Admin authorization (invite, moderate operations)
|
|
495
|
+
* - Room policy updates
|
|
496
|
+
* - Threshold admin approval (2-of-3, etc.)
|
|
497
|
+
*
|
|
498
|
+
* @param agentContext - Agent context
|
|
499
|
+
* @param options - Authorization artifact options
|
|
500
|
+
* @returns Authorization artifact with signatures
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```typescript
|
|
504
|
+
* const authz = await signingService.createAuthzArtifact(agentContext, {
|
|
505
|
+
* action: 'invite',
|
|
506
|
+
* roomDid: 'did:peer:room123',
|
|
507
|
+
* targetDid: 'did:ex:alice',
|
|
508
|
+
* adminDids: ['did:ex:admin1', 'did:ex:admin2'],
|
|
509
|
+
* threshold: 2,
|
|
510
|
+
* payload: { room: 'did:peer:room123', invitee: 'did:ex:alice' }
|
|
511
|
+
* })
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
async createAuthzArtifact(agentContext, options) {
|
|
515
|
+
const { action, roomDid, targetDid, adminDids, threshold, payload, expiresIn, nonce } = options;
|
|
516
|
+
const mode = !threshold || threshold === 1 || adminDids.length === 1 ? "single" : "threshold";
|
|
517
|
+
const objectId = `authz_${action}_${utils.uuid()}`;
|
|
518
|
+
const canonicalizer = this.canonicalizerRegistry.getById("raw-bytes@1");
|
|
519
|
+
if (!canonicalizer) throw new CredoError("Raw bytes canonicalizer not found");
|
|
520
|
+
const payloadBytes = Buffer.from(JSON.stringify(payload), "utf-8");
|
|
521
|
+
const canonical = await canonicalizer.canonicalize(payloadBytes, {});
|
|
522
|
+
const digest = await canonicalizer.computeDigest(canonical, "sha-256");
|
|
523
|
+
const signableObject = {
|
|
524
|
+
id: objectId,
|
|
525
|
+
mediaType: "application/json",
|
|
526
|
+
canonicalization: {
|
|
527
|
+
method: "raw-bytes@1",
|
|
528
|
+
parameters: { data: payloadBytes }
|
|
529
|
+
},
|
|
530
|
+
digest: {
|
|
531
|
+
alg: "sha-256",
|
|
532
|
+
value: digest.value
|
|
533
|
+
},
|
|
534
|
+
displayHints: {
|
|
535
|
+
title: `Authorization: ${action}`,
|
|
536
|
+
summary: `Admin authorization for ${action} on ${roomDid}`
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
const sessionId = `authz_sess_${utils.uuid()}`;
|
|
540
|
+
const sessionRecord = new SigningSessionRecord({
|
|
541
|
+
id: utils.uuid(),
|
|
542
|
+
sessionId,
|
|
543
|
+
state: SigningState.RequestSent,
|
|
544
|
+
role: SigningRole.Requester,
|
|
545
|
+
connectionId: "",
|
|
546
|
+
threadId: utils.uuid(),
|
|
547
|
+
mode: mode === "single" ? SessionMode.Single : SessionMode.Threshold,
|
|
548
|
+
object: signableObject,
|
|
549
|
+
suite: {
|
|
550
|
+
suite: "jws-ed25519@1",
|
|
551
|
+
keyBinding: {
|
|
552
|
+
controller: adminDids[0],
|
|
553
|
+
proofPurpose: "authorization"
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
threshold: threshold ? {
|
|
557
|
+
scheme: "n-of-m",
|
|
558
|
+
n: threshold,
|
|
559
|
+
m: adminDids.length,
|
|
560
|
+
signers: adminDids,
|
|
561
|
+
aggregation: "bundle-none@1"
|
|
562
|
+
} : void 0
|
|
563
|
+
});
|
|
564
|
+
await this.sessionRepository.save(agentContext, sessionRecord);
|
|
565
|
+
const signatures = [];
|
|
566
|
+
const suite = this.suiteRegistry.getById("jws-ed25519@1");
|
|
567
|
+
if (!suite) throw new CredoError("JWS Ed25519 suite not found");
|
|
568
|
+
const numSignatures = threshold || 1;
|
|
569
|
+
for (let i = 0; i < Math.min(numSignatures, adminDids.length); i++) try {
|
|
570
|
+
const signResult = await suite.sign(agentContext, {
|
|
571
|
+
data: canonical,
|
|
572
|
+
keyRef: adminDids[i],
|
|
573
|
+
parameters: {}
|
|
574
|
+
});
|
|
575
|
+
signatures.push(signResult.value || "");
|
|
576
|
+
} catch (error) {
|
|
577
|
+
console.warn(`Could not sign with admin ${adminDids[i]}:`, error);
|
|
578
|
+
}
|
|
579
|
+
if (signatures.length === 0) throw new CredoError("No signatures could be created for authorization artifact");
|
|
580
|
+
return {
|
|
581
|
+
type: mode,
|
|
582
|
+
session_id: sessionId,
|
|
583
|
+
artifacts: [{
|
|
584
|
+
object_id: objectId,
|
|
585
|
+
suite: "jws-ed25519@1",
|
|
586
|
+
digest: `sha-256:${digest.value}`
|
|
587
|
+
}],
|
|
588
|
+
signatures,
|
|
589
|
+
metadata: {
|
|
590
|
+
admin_dids: adminDids.slice(0, signatures.length),
|
|
591
|
+
room_did: roomDid,
|
|
592
|
+
action,
|
|
593
|
+
threshold: threshold ? {
|
|
594
|
+
n: threshold,
|
|
595
|
+
m: adminDids.length
|
|
596
|
+
} : void 0,
|
|
597
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
598
|
+
nonce
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Verify an authorization artifact
|
|
604
|
+
*
|
|
605
|
+
* Verifies that an authorization artifact has valid signatures from
|
|
606
|
+
* authorized admins and meets threshold requirements.
|
|
607
|
+
*
|
|
608
|
+
* @param agentContext - Agent context
|
|
609
|
+
* @param authz - Authorization artifact to verify
|
|
610
|
+
* @param options - Verification options
|
|
611
|
+
* @returns Verification result with validity and details
|
|
612
|
+
*
|
|
613
|
+
* @example
|
|
614
|
+
* ```typescript
|
|
615
|
+
* const result = await signingService.verifyAuthzArtifact(agentContext, authz, {
|
|
616
|
+
* roomDid: 'did:peer:room123',
|
|
617
|
+
* requiredAction: 'invite',
|
|
618
|
+
* allowedAdmins: ['did:ex:admin1', 'did:ex:admin2'],
|
|
619
|
+
* threshold: 2
|
|
620
|
+
* })
|
|
621
|
+
* ```
|
|
622
|
+
*/
|
|
623
|
+
async verifyAuthzArtifact(agentContext, authz, options) {
|
|
624
|
+
const { roomDid, requiredAction, allowedAdmins, threshold, enforceExpiry = true } = options;
|
|
625
|
+
if (authz.metadata?.room_did !== roomDid) return {
|
|
626
|
+
valid: false,
|
|
627
|
+
reason: `Room DID mismatch: expected ${roomDid}, got ${authz.metadata?.room_did}`
|
|
628
|
+
};
|
|
629
|
+
if (authz.metadata?.action !== requiredAction) return {
|
|
630
|
+
valid: false,
|
|
631
|
+
reason: `Action mismatch: expected ${requiredAction}, got ${authz.metadata?.action}`
|
|
632
|
+
};
|
|
633
|
+
if (enforceExpiry && authz.metadata?.timestamp) {
|
|
634
|
+
const timestamp = new Date(authz.metadata.timestamp);
|
|
635
|
+
if ((/* @__PURE__ */ new Date()).getTime() - timestamp.getTime() > 36e5) return {
|
|
636
|
+
valid: false,
|
|
637
|
+
reason: "Authorization artifact has expired"
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
const suite = this.suiteRegistry.getById("jws-ed25519@1");
|
|
641
|
+
if (!suite) return {
|
|
642
|
+
valid: false,
|
|
643
|
+
reason: "JWS Ed25519 suite not available for verification"
|
|
644
|
+
};
|
|
645
|
+
const validSigners = [];
|
|
646
|
+
const signerDids = authz.metadata?.admin_dids || [];
|
|
647
|
+
if (authz.artifacts.length === 0) return {
|
|
648
|
+
valid: false,
|
|
649
|
+
reason: "No artifacts in authorization"
|
|
650
|
+
};
|
|
651
|
+
authz.artifacts[0];
|
|
652
|
+
for (let i = 0; i < authz.signatures.length; i++) {
|
|
653
|
+
const signature = authz.signatures[i];
|
|
654
|
+
const signerDid = signerDids[i];
|
|
655
|
+
if (!allowedAdmins.includes(signerDid)) continue;
|
|
656
|
+
try {
|
|
657
|
+
if (await suite.verify(agentContext, {
|
|
658
|
+
data: Buffer.from(""),
|
|
659
|
+
signature: {
|
|
660
|
+
value: signature,
|
|
661
|
+
format: "jws"
|
|
662
|
+
},
|
|
663
|
+
publicKey: signerDid
|
|
664
|
+
})) validSigners.push(signerDid);
|
|
665
|
+
} catch (error) {
|
|
666
|
+
console.warn(`Signature verification failed for ${signerDid}:`, error);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
const requiredThreshold = threshold || authz.metadata?.threshold?.n || 1;
|
|
670
|
+
if (!(validSigners.length >= requiredThreshold)) return {
|
|
671
|
+
valid: false,
|
|
672
|
+
reason: `Threshold not met: ${validSigners.length}/${requiredThreshold} valid signatures`,
|
|
673
|
+
validSigners,
|
|
674
|
+
thresholdMet: false
|
|
675
|
+
};
|
|
676
|
+
return {
|
|
677
|
+
valid: true,
|
|
678
|
+
validSigners,
|
|
679
|
+
thresholdMet: true
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Create a join token with HPKE envelope
|
|
684
|
+
*
|
|
685
|
+
* Creates a replay-proof join token that encapsulates:
|
|
686
|
+
* - Signed authorization ticket with monotonic counter
|
|
687
|
+
* - HPKE-encrypted payload (e.g., MLS Welcome message)
|
|
688
|
+
* - AAD binding to prevent envelope transplant attacks
|
|
689
|
+
*
|
|
690
|
+
* Used by Group Messaging Protocol for:
|
|
691
|
+
* - Secure room invitations with encrypted Welcome messages
|
|
692
|
+
* - Device-bound, single-use credentials
|
|
693
|
+
* - Replay-protected authorization
|
|
694
|
+
*
|
|
695
|
+
* Security Properties:
|
|
696
|
+
* - Replay protection via monotonic counter
|
|
697
|
+
* - Device binding via HPKE encryption to device public key
|
|
698
|
+
* - Transplant resistance via AAD binding (ticket_digest)
|
|
699
|
+
* - Short-lived tokens (default 2 minutes)
|
|
700
|
+
* - Single-use enforcement (cap = 1)
|
|
701
|
+
*
|
|
702
|
+
* @param agentContext - Agent context
|
|
703
|
+
* @param options - Join token creation options
|
|
704
|
+
* @returns Complete join token ready for transmission
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
707
|
+
* ```typescript
|
|
708
|
+
* const joinToken = await signingService.createJoinToken(agentContext, {
|
|
709
|
+
* sessionId: 'session_abc123',
|
|
710
|
+
* deviceDid: 'did:ex:alice#device1',
|
|
711
|
+
* devicePublicKey: aliceX25519PublicKey,
|
|
712
|
+
* payload: { welcome: mlsWelcomeMessage, groupInfo: ... },
|
|
713
|
+
* expiresIn: 120,
|
|
714
|
+
* capacity: 1,
|
|
715
|
+
* scope: 'join'
|
|
716
|
+
* })
|
|
717
|
+
* ```
|
|
718
|
+
*/
|
|
719
|
+
async createJoinToken(agentContext, options) {
|
|
720
|
+
const { sessionId, deviceDid, devicePublicKey, payload, expiresIn = 120, capacity = 1, scope = "join", audience, policyHash, nonce } = options;
|
|
721
|
+
const ticket = {
|
|
722
|
+
typ: "signing-ticket",
|
|
723
|
+
session_id: sessionId,
|
|
724
|
+
scope,
|
|
725
|
+
device: deviceDid,
|
|
726
|
+
ctr: await this.counterService.incrementCounter(agentContext, deviceDid),
|
|
727
|
+
exp: new Date(Date.now() + expiresIn * 1e3).toISOString(),
|
|
728
|
+
cap: capacity,
|
|
729
|
+
aud: audience,
|
|
730
|
+
policy_hash: policyHash,
|
|
731
|
+
nonce
|
|
732
|
+
};
|
|
733
|
+
const suite = this.suiteRegistry.getById("jws-ed25519@1");
|
|
734
|
+
if (!suite) throw new CredoError("JWS Ed25519 suite not found");
|
|
735
|
+
const ticketBytes = Buffer.from(JSON.stringify(ticket), "utf-8");
|
|
736
|
+
const signature = {
|
|
737
|
+
suite: "jws-ed25519@1",
|
|
738
|
+
kid: deviceDid,
|
|
739
|
+
value: (await suite.sign(agentContext, {
|
|
740
|
+
data: ticketBytes,
|
|
741
|
+
keyRef: deviceDid,
|
|
742
|
+
parameters: {}
|
|
743
|
+
})).value || ""
|
|
744
|
+
};
|
|
745
|
+
const ticketDigest = this.hpkeService.computeTicketDigest(ticketBytes);
|
|
746
|
+
const payloadBytes = Buffer.from(JSON.stringify(payload), "utf-8");
|
|
747
|
+
const encryptResult = await this.hpkeService.encrypt(devicePublicKey, payloadBytes, {
|
|
748
|
+
ticket_digest: ticketDigest,
|
|
749
|
+
session_id: sessionId,
|
|
750
|
+
device: deviceDid
|
|
751
|
+
});
|
|
752
|
+
return {
|
|
753
|
+
token: ticket,
|
|
754
|
+
sig: signature,
|
|
755
|
+
envelope: {
|
|
756
|
+
suite: "envelope-hpke@1",
|
|
757
|
+
aad: {
|
|
758
|
+
ticket_digest: ticketDigest,
|
|
759
|
+
session_id: sessionId,
|
|
760
|
+
device: deviceDid
|
|
761
|
+
},
|
|
762
|
+
ciphertext: Buffer.from(encryptResult.ciphertext).toString("base64"),
|
|
763
|
+
enc: {
|
|
764
|
+
kem: encryptResult.metadata.kem,
|
|
765
|
+
kdf: encryptResult.metadata.kdf,
|
|
766
|
+
aead: encryptResult.metadata.aead,
|
|
767
|
+
ek_pub: Buffer.from(encryptResult.ephemeralPublicKey).toString("base64")
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Verify and decrypt a join token
|
|
774
|
+
*
|
|
775
|
+
* Verifies a join token by:
|
|
776
|
+
* 1. Verifying the ticket signature
|
|
777
|
+
* 2. Checking counter for replay attacks
|
|
778
|
+
* 3. Verifying expiry
|
|
779
|
+
* 4. Checking AAD binding
|
|
780
|
+
* 5. Decrypting the envelope with device private key
|
|
781
|
+
*
|
|
782
|
+
* CRITICAL: Counter is persisted BEFORE token consumption to prevent
|
|
783
|
+
* replay attacks even if consumption fails.
|
|
784
|
+
*
|
|
785
|
+
* @param agentContext - Agent context
|
|
786
|
+
* @param joinToken - Join token to verify
|
|
787
|
+
* @param options - Verification options
|
|
788
|
+
* @returns Verification result with decrypted payload
|
|
789
|
+
*
|
|
790
|
+
* @example
|
|
791
|
+
* ```typescript
|
|
792
|
+
* const result = await signingService.verifyJoinToken(agentContext, joinToken, {
|
|
793
|
+
* devicePrivateKey: aliceX25519PrivateKey,
|
|
794
|
+
* enforceExpiry: true,
|
|
795
|
+
* enforceCounter: true,
|
|
796
|
+
* expectedCoordinator: 'did:ex:coordinator'
|
|
797
|
+
* })
|
|
798
|
+
*
|
|
799
|
+
* if (result.valid) {
|
|
800
|
+
* const { welcome, groupInfo } = result.payload
|
|
801
|
+
* // Process MLS Welcome message...
|
|
802
|
+
* }
|
|
803
|
+
* ```
|
|
804
|
+
*/
|
|
805
|
+
async verifyJoinToken(agentContext, joinToken, options) {
|
|
806
|
+
const { devicePrivateKey, enforceExpiry = true, enforceCounter = true, expectedCoordinator } = options;
|
|
807
|
+
const { token, sig, envelope } = joinToken;
|
|
808
|
+
const suite = this.suiteRegistry.getById(sig.suite);
|
|
809
|
+
if (!suite) return {
|
|
810
|
+
valid: false,
|
|
811
|
+
reason: `Signature suite not found: ${sig.suite}`
|
|
812
|
+
};
|
|
813
|
+
const ticketBytes = Buffer.from(JSON.stringify(token), "utf-8");
|
|
814
|
+
try {
|
|
815
|
+
if (!await suite.verify(agentContext, {
|
|
816
|
+
data: ticketBytes,
|
|
817
|
+
signature: {
|
|
818
|
+
value: sig.value,
|
|
819
|
+
format: "jws"
|
|
820
|
+
},
|
|
821
|
+
publicKey: sig.kid || expectedCoordinator || ""
|
|
822
|
+
})) return {
|
|
823
|
+
valid: false,
|
|
824
|
+
reason: "Invalid ticket signature"
|
|
825
|
+
};
|
|
826
|
+
} catch (error) {
|
|
827
|
+
return {
|
|
828
|
+
valid: false,
|
|
829
|
+
reason: `Signature verification failed: ${error instanceof Error ? error.message : "unknown error"}`
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
if (expectedCoordinator && sig.kid !== expectedCoordinator) return {
|
|
833
|
+
valid: false,
|
|
834
|
+
reason: `Coordinator mismatch: expected ${expectedCoordinator}, got ${sig.kid}`
|
|
835
|
+
};
|
|
836
|
+
const expired = /* @__PURE__ */ new Date() > new Date(token.exp);
|
|
837
|
+
if (enforceExpiry && expired) return {
|
|
838
|
+
valid: false,
|
|
839
|
+
reason: `Token expired at ${token.exp}`,
|
|
840
|
+
metadata: {
|
|
841
|
+
counter: token.ctr,
|
|
842
|
+
device: token.device,
|
|
843
|
+
expiry: token.exp,
|
|
844
|
+
expired: true
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
if (enforceCounter) {
|
|
848
|
+
const counterResult = await this.counterService.verifyAndUpdateCounter(agentContext, token.device, token.ctr);
|
|
849
|
+
if (!counterResult.valid) return {
|
|
850
|
+
valid: false,
|
|
851
|
+
reason: counterResult.reason || "Counter verification failed",
|
|
852
|
+
metadata: {
|
|
853
|
+
counter: token.ctr,
|
|
854
|
+
device: token.device,
|
|
855
|
+
expiry: token.exp,
|
|
856
|
+
expired
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
const expectedDigest = this.hpkeService.computeTicketDigest(ticketBytes);
|
|
861
|
+
if (envelope.aad.ticket_digest !== expectedDigest) return {
|
|
862
|
+
valid: false,
|
|
863
|
+
reason: "AAD binding verification failed: ticket_digest mismatch",
|
|
864
|
+
metadata: {
|
|
865
|
+
counter: token.ctr,
|
|
866
|
+
device: token.device,
|
|
867
|
+
expiry: token.exp,
|
|
868
|
+
expired
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
try {
|
|
872
|
+
const ciphertext = Buffer.from(envelope.ciphertext, "base64");
|
|
873
|
+
const ephemeralPublicKey = Buffer.from(envelope.enc.ek_pub, "base64");
|
|
874
|
+
const decryptResult = await this.hpkeService.decrypt(devicePrivateKey, ciphertext, ephemeralPublicKey, {
|
|
875
|
+
ticket_digest: envelope.aad.ticket_digest,
|
|
876
|
+
session_id: envelope.aad.session_id,
|
|
877
|
+
device: envelope.aad.device
|
|
878
|
+
});
|
|
879
|
+
const payloadString = Buffer.from(decryptResult.plaintext).toString("utf-8");
|
|
880
|
+
return {
|
|
881
|
+
valid: true,
|
|
882
|
+
payload: JSON.parse(payloadString),
|
|
883
|
+
metadata: {
|
|
884
|
+
counter: token.ctr,
|
|
885
|
+
device: token.device,
|
|
886
|
+
expiry: token.exp,
|
|
887
|
+
expired
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
} catch (error) {
|
|
891
|
+
return {
|
|
892
|
+
valid: false,
|
|
893
|
+
reason: `Decryption failed: ${error instanceof Error ? error.message : "unknown error"}`,
|
|
894
|
+
metadata: {
|
|
895
|
+
counter: token.ctr,
|
|
896
|
+
device: token.device,
|
|
897
|
+
expiry: token.exp,
|
|
898
|
+
expired
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Create a router attestation for Group Messaging Protocol
|
|
905
|
+
*
|
|
906
|
+
* Creates a signed attestation that proves a router is authorized to relay
|
|
907
|
+
* messages for a room to a specific reach set of DIDs.
|
|
908
|
+
*
|
|
909
|
+
* Used by Group Messaging Protocol for:
|
|
910
|
+
* - Router registration with Host
|
|
911
|
+
* - Mesh relay authorization
|
|
912
|
+
* - Reach set advertisement
|
|
913
|
+
*
|
|
914
|
+
* Security Properties:
|
|
915
|
+
* - Router identity binding via DID signature
|
|
916
|
+
* - Room-specific authorization
|
|
917
|
+
* - Time-bounded validity (expiry)
|
|
918
|
+
* - Optional admin co-signature for additional trust
|
|
919
|
+
*
|
|
920
|
+
* @param agentContext - Agent context
|
|
921
|
+
* @param options - Router attestation options
|
|
922
|
+
* @returns Router attestation with signature(s)
|
|
923
|
+
*
|
|
924
|
+
* @example
|
|
925
|
+
* ```typescript
|
|
926
|
+
* const attestation = await signingService.createRouterAttestation(agentContext, {
|
|
927
|
+
* routerDid: 'did:ex:router1',
|
|
928
|
+
* roomDid: 'did:peer:room123',
|
|
929
|
+
* reach: ['did:ex:alice', 'did:ex:bob', 'did:ex:charlie'],
|
|
930
|
+
* expiresIn: 86400, // 24 hours
|
|
931
|
+
* policyHash: 'sha-256:abc123...',
|
|
932
|
+
* adminDids: ['did:ex:admin1'], // Optional co-signature
|
|
933
|
+
* })
|
|
934
|
+
* ```
|
|
935
|
+
*/
|
|
936
|
+
async createRouterAttestation(agentContext, options) {
|
|
937
|
+
const { routerDid, roomDid, reach, expiresIn = 86400, policyHash, nonce, adminDids, adminThreshold } = options;
|
|
938
|
+
if (!reach || reach.length === 0) throw new CredoError("Reach set must contain at least one DID");
|
|
939
|
+
const claim = {
|
|
940
|
+
router: routerDid,
|
|
941
|
+
room_did: roomDid,
|
|
942
|
+
reach,
|
|
943
|
+
exp: new Date(Date.now() + expiresIn * 1e3).toISOString(),
|
|
944
|
+
policy_hash: policyHash,
|
|
945
|
+
nonce
|
|
946
|
+
};
|
|
947
|
+
const suite = this.suiteRegistry.getById("jws-ed25519@1");
|
|
948
|
+
if (!suite) throw new CredoError("JWS Ed25519 suite not found");
|
|
949
|
+
const claimBytes = Buffer.from(JSON.stringify(claim), "utf-8");
|
|
950
|
+
const attestation = {
|
|
951
|
+
signed: claim,
|
|
952
|
+
sig: (await suite.sign(agentContext, {
|
|
953
|
+
data: claimBytes,
|
|
954
|
+
keyRef: routerDid,
|
|
955
|
+
parameters: {}
|
|
956
|
+
})).value || ""
|
|
957
|
+
};
|
|
958
|
+
if (adminDids && adminDids.length > 0) try {
|
|
959
|
+
attestation.admin_sig = (await suite.sign(agentContext, {
|
|
960
|
+
data: claimBytes,
|
|
961
|
+
keyRef: adminDids[0],
|
|
962
|
+
parameters: {}
|
|
963
|
+
})).value || "";
|
|
964
|
+
} catch (error) {
|
|
965
|
+
console.warn(`Could not create admin co-signature:`, error);
|
|
966
|
+
}
|
|
967
|
+
return attestation;
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Verify a router attestation
|
|
971
|
+
*
|
|
972
|
+
* Verifies that a router attestation has:
|
|
973
|
+
* - Valid signature from router DID
|
|
974
|
+
* - Correct room DID
|
|
975
|
+
* - Not expired
|
|
976
|
+
* - Optional admin co-signature validation
|
|
977
|
+
*
|
|
978
|
+
* @param agentContext - Agent context
|
|
979
|
+
* @param attestation - Router attestation to verify
|
|
980
|
+
* @param options - Verification options
|
|
981
|
+
* @returns Verification result with validity and details
|
|
982
|
+
*
|
|
983
|
+
* @example
|
|
984
|
+
* ```typescript
|
|
985
|
+
* const result = await signingService.verifyRouterAttestation(agentContext, attestation, {
|
|
986
|
+
* roomDid: 'did:peer:room123',
|
|
987
|
+
* expectedRouter: 'did:ex:router1',
|
|
988
|
+
* enforceExpiry: true,
|
|
989
|
+
* allowedRouters: ['did:ex:router1', 'did:ex:router2'],
|
|
990
|
+
* authorizedAdmins: ['did:ex:admin1'],
|
|
991
|
+
* requireAdminSignature: false,
|
|
992
|
+
* })
|
|
993
|
+
* ```
|
|
994
|
+
*/
|
|
995
|
+
async verifyRouterAttestation(agentContext, attestation, options) {
|
|
996
|
+
const { roomDid, expectedRouter, enforceExpiry = true, allowedRouters, authorizedAdmins, requireAdminSignature = false } = options;
|
|
997
|
+
const { signed, sig, admin_sig } = attestation;
|
|
998
|
+
if (signed.room_did !== roomDid) return {
|
|
999
|
+
valid: false,
|
|
1000
|
+
reason: `Room DID mismatch: expected ${roomDid}, got ${signed.room_did}`
|
|
1001
|
+
};
|
|
1002
|
+
if (expectedRouter && signed.router !== expectedRouter) return {
|
|
1003
|
+
valid: false,
|
|
1004
|
+
reason: `Router DID mismatch: expected ${expectedRouter}, got ${signed.router}`
|
|
1005
|
+
};
|
|
1006
|
+
if (allowedRouters && !allowedRouters.includes(signed.router)) return {
|
|
1007
|
+
valid: false,
|
|
1008
|
+
reason: `Router ${signed.router} is not in allowed routers list`
|
|
1009
|
+
};
|
|
1010
|
+
const expired = /* @__PURE__ */ new Date() > new Date(signed.exp);
|
|
1011
|
+
if (enforceExpiry && expired) return {
|
|
1012
|
+
valid: false,
|
|
1013
|
+
reason: `Attestation expired at ${signed.exp}`,
|
|
1014
|
+
metadata: {
|
|
1015
|
+
expired: true,
|
|
1016
|
+
expiryDate: signed.exp,
|
|
1017
|
+
policyHash: signed.policy_hash
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
const suite = this.suiteRegistry.getById("jws-ed25519@1");
|
|
1021
|
+
if (!suite) return {
|
|
1022
|
+
valid: false,
|
|
1023
|
+
reason: "JWS Ed25519 suite not available for verification"
|
|
1024
|
+
};
|
|
1025
|
+
const claimBytes = Buffer.from(JSON.stringify(signed), "utf-8");
|
|
1026
|
+
try {
|
|
1027
|
+
if (!await suite.verify(agentContext, {
|
|
1028
|
+
data: claimBytes,
|
|
1029
|
+
signature: {
|
|
1030
|
+
value: sig,
|
|
1031
|
+
format: "jws"
|
|
1032
|
+
},
|
|
1033
|
+
publicKey: signed.router
|
|
1034
|
+
})) return {
|
|
1035
|
+
valid: false,
|
|
1036
|
+
reason: "Invalid router signature"
|
|
1037
|
+
};
|
|
1038
|
+
} catch (error) {
|
|
1039
|
+
return {
|
|
1040
|
+
valid: false,
|
|
1041
|
+
reason: `Router signature verification failed: ${error instanceof Error ? error.message : "unknown error"}`
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
let adminSignatureValid = false;
|
|
1045
|
+
if (admin_sig) {
|
|
1046
|
+
if (!authorizedAdmins || authorizedAdmins.length === 0) return {
|
|
1047
|
+
valid: false,
|
|
1048
|
+
reason: "Admin signature present but no authorized admins provided for verification"
|
|
1049
|
+
};
|
|
1050
|
+
for (const adminDid of authorizedAdmins) try {
|
|
1051
|
+
if (await suite.verify(agentContext, {
|
|
1052
|
+
data: claimBytes,
|
|
1053
|
+
signature: {
|
|
1054
|
+
value: admin_sig,
|
|
1055
|
+
format: "jws"
|
|
1056
|
+
},
|
|
1057
|
+
publicKey: adminDid
|
|
1058
|
+
})) {
|
|
1059
|
+
adminSignatureValid = true;
|
|
1060
|
+
break;
|
|
1061
|
+
}
|
|
1062
|
+
} catch (error) {
|
|
1063
|
+
continue;
|
|
1064
|
+
}
|
|
1065
|
+
if (!adminSignatureValid) return {
|
|
1066
|
+
valid: false,
|
|
1067
|
+
reason: "Invalid admin co-signature",
|
|
1068
|
+
adminSignatureValid: false
|
|
1069
|
+
};
|
|
1070
|
+
} else if (requireAdminSignature) return {
|
|
1071
|
+
valid: false,
|
|
1072
|
+
reason: "Admin co-signature required but not present",
|
|
1073
|
+
adminSignatureValid: false
|
|
1074
|
+
};
|
|
1075
|
+
return {
|
|
1076
|
+
valid: true,
|
|
1077
|
+
routerDid: signed.router,
|
|
1078
|
+
reach: signed.reach,
|
|
1079
|
+
adminSignatureValid: admin_sig ? adminSignatureValid : void 0,
|
|
1080
|
+
metadata: {
|
|
1081
|
+
expired,
|
|
1082
|
+
expiryDate: signed.exp,
|
|
1083
|
+
policyHash: signed.policy_hash
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
SigningService = __decorate([injectable(), __decorateMetadata("design:paramtypes", [
|
|
1089
|
+
SigningSessionRepository,
|
|
1090
|
+
DidCommMessageSender,
|
|
1091
|
+
DidCommMessageRepository,
|
|
1092
|
+
CanonicalizerRegistry,
|
|
1093
|
+
SignatureSuiteRegistry,
|
|
1094
|
+
AggregatorRegistry,
|
|
1095
|
+
PolicyRegistry,
|
|
1096
|
+
InlineBase64Strategy,
|
|
1097
|
+
EventEmitter,
|
|
1098
|
+
HPKEService,
|
|
1099
|
+
CounterService
|
|
1100
|
+
])], SigningService);
|
|
1101
|
+
|
|
1102
|
+
//#endregion
|
|
1103
|
+
export { SigningService };
|
|
1104
|
+
//# sourceMappingURL=SigningService.mjs.map
|