@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,55 @@
|
|
|
1
|
+
import { CredoError } from "@credo-ts/core";
|
|
2
|
+
import { webcrypto } from "node:crypto";
|
|
3
|
+
|
|
4
|
+
//#region src/registry/canonicalizers/RawBytesCanonicalizer.ts
|
|
5
|
+
/**
|
|
6
|
+
* Raw bytes canonicalizer - identity canonicalization
|
|
7
|
+
*
|
|
8
|
+
* This is the simplest canonicalizer that just converts input to bytes
|
|
9
|
+
* without any transformation. Useful for data that's already canonical.
|
|
10
|
+
*/
|
|
11
|
+
var RawBytesCanonicalizer = class {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.id = "raw-bytes@1";
|
|
14
|
+
this.version = 1;
|
|
15
|
+
this.name = "raw-bytes";
|
|
16
|
+
this.mediaTypes = ["*/*"];
|
|
17
|
+
this.supportedAlgorithms = ["sha-256", "sha-512"];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Convert input to bytes (identity transformation)
|
|
21
|
+
*/
|
|
22
|
+
async canonicalize(input, _parameters) {
|
|
23
|
+
if (input instanceof Uint8Array) return input;
|
|
24
|
+
if (Buffer.isBuffer(input)) return Uint8Array.from(input);
|
|
25
|
+
if (typeof input === "string") return new TextEncoder().encode(input);
|
|
26
|
+
if (typeof input === "object" && input !== null) {
|
|
27
|
+
const json = JSON.stringify(input);
|
|
28
|
+
return new TextEncoder().encode(json);
|
|
29
|
+
}
|
|
30
|
+
throw new CredoError(`Cannot canonicalize input of type ${typeof input}`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Compute cryptographic digest
|
|
34
|
+
*/
|
|
35
|
+
async computeDigest(canonical, algorithm) {
|
|
36
|
+
if (!this.supportedAlgorithms.includes(algorithm)) throw new CredoError(`Unsupported hash algorithm: ${algorithm}. Supported: ${this.supportedAlgorithms.join(", ")}`);
|
|
37
|
+
const cryptoAlg = algorithm === "sha-256" ? "SHA-256" : "SHA-512";
|
|
38
|
+
const hashBuffer = await webcrypto.subtle.digest(cryptoAlg, canonical);
|
|
39
|
+
const hashArray = new Uint8Array(hashBuffer);
|
|
40
|
+
return {
|
|
41
|
+
alg: algorithm,
|
|
42
|
+
value: Buffer.from(hashArray).toString("base64")
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if media type is supported (supports all)
|
|
47
|
+
*/
|
|
48
|
+
supportsMediaType(_mediaType) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { RawBytesCanonicalizer };
|
|
55
|
+
//# sourceMappingURL=RawBytesCanonicalizer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RawBytesCanonicalizer.mjs","names":[],"sources":["../../../src/registry/canonicalizers/RawBytesCanonicalizer.ts"],"sourcesContent":["import type { Canonicalizer } from './Canonicalizer'\n\nimport { CredoError } from '@credo-ts/core'\nimport { webcrypto } from 'node:crypto'\n\n/**\n * Raw bytes canonicalizer - identity canonicalization\n *\n * This is the simplest canonicalizer that just converts input to bytes\n * without any transformation. Useful for data that's already canonical.\n */\nexport class RawBytesCanonicalizer implements Canonicalizer {\n public readonly id = 'raw-bytes@1'\n public readonly version = 1\n public readonly name = 'raw-bytes'\n public readonly mediaTypes = ['*/*'] // Accepts any media type\n public readonly supportedAlgorithms = ['sha-256', 'sha-512']\n\n /**\n * Convert input to bytes (identity transformation)\n */\n public async canonicalize(input: unknown, _parameters?: Record<string, unknown>): Promise<Uint8Array> {\n // If already Uint8Array, return as-is\n if (input instanceof Uint8Array) {\n return input\n }\n\n // If Buffer, convert to Uint8Array\n if (Buffer.isBuffer(input)) {\n return Uint8Array.from(input)\n }\n\n // If string, encode as UTF-8\n if (typeof input === 'string') {\n return new TextEncoder().encode(input)\n }\n\n // If object, JSON stringify\n if (typeof input === 'object' && input !== null) {\n const json = JSON.stringify(input)\n return new TextEncoder().encode(json)\n }\n\n throw new CredoError(`Cannot canonicalize input of type ${typeof input}`)\n }\n\n /**\n * Compute cryptographic digest\n */\n public async computeDigest(\n canonical: Uint8Array,\n algorithm: string\n ): Promise<{ alg: string; value: string }> {\n if (!this.supportedAlgorithms.includes(algorithm)) {\n throw new CredoError(\n `Unsupported hash algorithm: ${algorithm}. Supported: ${this.supportedAlgorithms.join(', ')}`\n )\n }\n\n // Map to WebCrypto algorithm names\n const cryptoAlg = algorithm === 'sha-256' ? 'SHA-256' : 'SHA-512'\n\n // Compute hash using WebCrypto API\n const hashBuffer = await webcrypto.subtle.digest(cryptoAlg, canonical)\n\n // Convert to base64\n const hashArray = new Uint8Array(hashBuffer)\n const base64 = Buffer.from(hashArray).toString('base64')\n\n return {\n alg: algorithm,\n value: base64,\n }\n }\n\n /**\n * Check if media type is supported (supports all)\n */\n public supportsMediaType(_mediaType: string): boolean {\n return true // Accept any media type\n }\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAa,wBAAb,MAA4D;;OAC1C,KAAK;OACL,UAAU;OACV,OAAO;OACP,aAAa,CAAC,MAAM;OACpB,sBAAsB,CAAC,WAAW,UAAU;;;;;CAK5D,MAAa,aAAa,OAAgB,aAA4D;AAEpG,MAAI,iBAAiB,WACnB,QAAO;AAIT,MAAI,OAAO,SAAS,MAAM,CACxB,QAAO,WAAW,KAAK,MAAM;AAI/B,MAAI,OAAO,UAAU,SACnB,QAAO,IAAI,aAAa,CAAC,OAAO,MAAM;AAIxC,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;GAC/C,MAAM,OAAO,KAAK,UAAU,MAAM;AAClC,UAAO,IAAI,aAAa,CAAC,OAAO,KAAK;;AAGvC,QAAM,IAAI,WAAW,qCAAqC,OAAO,QAAQ;;;;;CAM3E,MAAa,cACX,WACA,WACyC;AACzC,MAAI,CAAC,KAAK,oBAAoB,SAAS,UAAU,CAC/C,OAAM,IAAI,WACR,+BAA+B,UAAU,eAAe,KAAK,oBAAoB,KAAK,KAAK,GAC5F;EAIH,MAAM,YAAY,cAAc,YAAY,YAAY;EAGxD,MAAM,aAAa,MAAM,UAAU,OAAO,OAAO,WAAW,UAAU;EAGtE,MAAM,YAAY,IAAI,WAAW,WAAW;AAG5C,SAAO;GACL,KAAK;GACL,OAJa,OAAO,KAAK,UAAU,CAAC,SAAS,SAAS;GAKvD;;;;;CAMH,AAAO,kBAAkB,YAA6B;AACpD,SAAO"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Canonicalizer, CanonicalizerMetadata } from "./Canonicalizer.mjs";
|
|
2
|
+
import { CanonicalizerRegistry, CanonicalizerToken } from "./CanonicalizerRegistry.mjs";
|
|
3
|
+
import { RawBytesCanonicalizer } from "./RawBytesCanonicalizer.mjs";
|
|
4
|
+
import { PdfCanonicalizationParameters, PdfIncrementalUpdateCanonicalizer, PreparedPdfCanonicalization } from "./PdfIncrementalUpdateCanonicalizer.mjs";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Canonicalizer, CanonicalizerMetadata } from "./canonicalizers/Canonicalizer.mjs";
|
|
2
|
+
import { CanonicalizerRegistry, CanonicalizerToken } from "./canonicalizers/CanonicalizerRegistry.mjs";
|
|
3
|
+
import { RawBytesCanonicalizer } from "./canonicalizers/RawBytesCanonicalizer.mjs";
|
|
4
|
+
import { PdfCanonicalizationParameters, PdfIncrementalUpdateCanonicalizer, PreparedPdfCanonicalization } from "./canonicalizers/PdfIncrementalUpdateCanonicalizer.mjs";
|
|
5
|
+
import "./canonicalizers/index.mjs";
|
|
6
|
+
import { RoundData, SignInput, SignatureSuite, SignatureSuiteMetadata, VerifyInput } from "./suites/SignatureSuite.mjs";
|
|
7
|
+
import { SignatureSuiteRegistry, SignatureSuiteToken } from "./suites/SignatureSuiteRegistry.mjs";
|
|
8
|
+
import { JwsEd25519Suite } from "./suites/JwsEd25519Suite.mjs";
|
|
9
|
+
import { PadesBLtaSuite, PadesEd25519Suite, PadesSignatureParameters } from "./suites/PadesBLtaSuite.mjs";
|
|
10
|
+
import "./suites/index.mjs";
|
|
11
|
+
import { AggregateInput, AggregationType, Aggregator, AggregatorMetadata } from "./aggregators/Aggregator.mjs";
|
|
12
|
+
import { AggregatorRegistry, AggregatorToken } from "./aggregators/AggregatorRegistry.mjs";
|
|
13
|
+
import { BundleNoneAggregator } from "./aggregators/BundleNoneAggregator.mjs";
|
|
14
|
+
import "./aggregators/index.mjs";
|
|
15
|
+
import { Policy, PolicyEnforcementPhase, PolicyMetadata } from "./policies/Policy.mjs";
|
|
16
|
+
import { PolicyRegistry, PolicyToken } from "./policies/PolicyRegistry.mjs";
|
|
17
|
+
import { TimeWindowPolicy, TimeWindowPolicyParameters } from "./policies/TimeWindowPolicy.mjs";
|
|
18
|
+
import "./policies/index.mjs";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CanonicalizerRegistry, CanonicalizerToken } from "./canonicalizers/CanonicalizerRegistry.mjs";
|
|
2
|
+
import { RawBytesCanonicalizer } from "./canonicalizers/RawBytesCanonicalizer.mjs";
|
|
3
|
+
import { PdfIncrementalUpdateCanonicalizer } from "./canonicalizers/PdfIncrementalUpdateCanonicalizer.mjs";
|
|
4
|
+
import "./canonicalizers/index.mjs";
|
|
5
|
+
import { SignatureSuiteRegistry, SignatureSuiteToken } from "./suites/SignatureSuiteRegistry.mjs";
|
|
6
|
+
import { JwsEd25519Suite } from "./suites/JwsEd25519Suite.mjs";
|
|
7
|
+
import { PadesBLtaSuite, PadesEd25519Suite } from "./suites/PadesBLtaSuite.mjs";
|
|
8
|
+
import "./suites/index.mjs";
|
|
9
|
+
import { AggregatorRegistry, AggregatorToken } from "./aggregators/AggregatorRegistry.mjs";
|
|
10
|
+
import { BundleNoneAggregator } from "./aggregators/BundleNoneAggregator.mjs";
|
|
11
|
+
import "./aggregators/index.mjs";
|
|
12
|
+
import { PolicyRegistry, PolicyToken } from "./policies/PolicyRegistry.mjs";
|
|
13
|
+
import { TimeWindowPolicy } from "./policies/TimeWindowPolicy.mjs";
|
|
14
|
+
import "./policies/index.mjs";
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { PolicyContext, PolicyResult } from "../../models/PolicyContext.mjs";
|
|
2
|
+
import "../../models/index.mjs";
|
|
3
|
+
import { AgentContext } from "@credo-ts/core";
|
|
4
|
+
|
|
5
|
+
//#region src/registry/policies/Policy.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Policy enforcement phase
|
|
8
|
+
*/
|
|
9
|
+
type PolicyEnforcementPhase = 'pre-request' | 'pre-sign' | 'post-sign';
|
|
10
|
+
/**
|
|
11
|
+
* Metadata for a policy
|
|
12
|
+
*/
|
|
13
|
+
interface PolicyMetadata {
|
|
14
|
+
/**
|
|
15
|
+
* Unique identifier with version
|
|
16
|
+
* @example "time-window@1"
|
|
17
|
+
*/
|
|
18
|
+
readonly id: string;
|
|
19
|
+
/**
|
|
20
|
+
* Version number
|
|
21
|
+
*/
|
|
22
|
+
readonly version: number;
|
|
23
|
+
/**
|
|
24
|
+
* Policy name
|
|
25
|
+
* @example "time-window"
|
|
26
|
+
*/
|
|
27
|
+
readonly name: string;
|
|
28
|
+
/**
|
|
29
|
+
* When this policy is enforced
|
|
30
|
+
*/
|
|
31
|
+
readonly enforcementPhase: PolicyEnforcementPhase;
|
|
32
|
+
/**
|
|
33
|
+
* Whether this policy accepts configuration
|
|
34
|
+
*/
|
|
35
|
+
readonly configurable: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Policy interface - enforces business rules and constraints
|
|
39
|
+
*
|
|
40
|
+
* Policies check constraints and business rules before or after
|
|
41
|
+
* signing operations (e.g., time windows, audience, usage limits).
|
|
42
|
+
*/
|
|
43
|
+
interface Policy extends PolicyMetadata {
|
|
44
|
+
/**
|
|
45
|
+
* Enforce policy constraints
|
|
46
|
+
*
|
|
47
|
+
* @param agentContext - Agent context
|
|
48
|
+
* @param context - Policy enforcement context
|
|
49
|
+
* @returns Policy result (allowed/denied with reason)
|
|
50
|
+
*/
|
|
51
|
+
enforce(agentContext: AgentContext, context: PolicyContext): Promise<PolicyResult>;
|
|
52
|
+
/**
|
|
53
|
+
* Validate policy configuration (if configurable)
|
|
54
|
+
*
|
|
55
|
+
* @param config - Configuration to validate
|
|
56
|
+
* @returns True if valid
|
|
57
|
+
*/
|
|
58
|
+
validate(config: unknown): boolean;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { Policy, PolicyEnforcementPhase, PolicyMetadata };
|
|
62
|
+
//# sourceMappingURL=Policy.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Policy.d.mts","names":[],"sources":["../../../src/registry/policies/Policy.ts"],"mappings":";;;;;;;;KAMY,sBAAA;;;;UAKK,cAAA;EAAA;;;;EAAA,SAKN,EAAA;EAKA;;;EAAA,SAAA,OAAA;EAgBA;;;AASX;EATW,SAVA,IAAA;;;;WAKA,gBAAA,EAAkB,sBAAA;EAsBkC;;;EAAA,SAjBpD,YAAA;AAAA;;;;;;;UASM,MAAA,SAAe,cAAA;EAgB9B;;;;;;;EARA,OAAA,CAAQ,YAAA,EAAc,YAAA,EAAc,OAAA,EAAS,aAAA,GAAgB,OAAA,CAAQ,YAAA;;;;;;;EAQrE,QAAA,CAAS,MAAA;AAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { PolicyCapability } from "../../models/Capabilities.mjs";
|
|
2
|
+
import "../../models/index.mjs";
|
|
3
|
+
import { Policy, PolicyEnforcementPhase } from "./Policy.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/registry/policies/PolicyRegistry.d.ts
|
|
6
|
+
declare const PolicyToken: unique symbol;
|
|
7
|
+
/**
|
|
8
|
+
* Registry for policy modules
|
|
9
|
+
*
|
|
10
|
+
* Uses dependency injection to allow pluggable policies.
|
|
11
|
+
* Policies can be registered by adding them to the module config.
|
|
12
|
+
*/
|
|
13
|
+
declare class PolicyRegistry {
|
|
14
|
+
private policies;
|
|
15
|
+
constructor(policies: Array<Policy | 'default'>);
|
|
16
|
+
/**
|
|
17
|
+
* Get policy by ID
|
|
18
|
+
*
|
|
19
|
+
* @param id - Policy ID (e.g., "time-window@1")
|
|
20
|
+
* @returns Policy or undefined if not found
|
|
21
|
+
*/
|
|
22
|
+
getById(id: string): Policy | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Get all policies for a specific enforcement phase
|
|
25
|
+
*
|
|
26
|
+
* @param phase - Enforcement phase
|
|
27
|
+
* @returns Array of policies
|
|
28
|
+
*/
|
|
29
|
+
getByPhase(phase: PolicyEnforcementPhase): Policy[];
|
|
30
|
+
/**
|
|
31
|
+
* Get all active policies
|
|
32
|
+
*
|
|
33
|
+
* @returns All registered policies
|
|
34
|
+
*/
|
|
35
|
+
getAll(): Policy[];
|
|
36
|
+
/**
|
|
37
|
+
* Check if a policy is registered
|
|
38
|
+
*
|
|
39
|
+
* @param id - Policy ID
|
|
40
|
+
* @returns True if registered
|
|
41
|
+
*/
|
|
42
|
+
isRegistered(id: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Get all registered policy IDs
|
|
45
|
+
*/
|
|
46
|
+
get registeredIds(): string[];
|
|
47
|
+
/**
|
|
48
|
+
* Get capabilities for proposal/negotiation
|
|
49
|
+
*/
|
|
50
|
+
get capabilities(): PolicyCapability[];
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { PolicyRegistry, PolicyToken };
|
|
54
|
+
//# sourceMappingURL=PolicyRegistry.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PolicyRegistry.d.mts","names":[],"sources":["../../../src/registry/policies/PolicyRegistry.ts"],"mappings":";;;;;cAKa,WAAA;;;AAAb;;;;cASa,cAAA;EAAA,QACH,QAAA;cAEmC,QAAA,EAAU,KAAA,CAAM,MAAA;;;;;;;EAWpD,OAAA,CAAQ,EAAA,WAAa,MAAA;EA2CD;;;;;;EAjCpB,UAAA,CAAW,KAAA,EAAO,sBAAA,GAAyB,MAAA;EArBP;;;;;EA8BpC,MAAA,CAAA,GAAU,MAAA;EATC;;;;;;EAmBX,YAAA,CAAa,EAAA;EAcT;;;EAAA,IAPA,aAAA,CAAA;;;;MAOA,YAAA,CAAA,GAAgB,gBAAA;AAAA"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { __decorateMetadata } from "../../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs";
|
|
2
|
+
import { __decorateParam } from "../../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateParam.mjs";
|
|
3
|
+
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
|
|
4
|
+
import { injectAll, injectable } from "@credo-ts/core";
|
|
5
|
+
|
|
6
|
+
//#region src/registry/policies/PolicyRegistry.ts
|
|
7
|
+
var _ref;
|
|
8
|
+
const PolicyToken = Symbol("PolicyToken");
|
|
9
|
+
let PolicyRegistry = class PolicyRegistry {
|
|
10
|
+
constructor(policies) {
|
|
11
|
+
this.policies = policies.filter((p) => p !== "default");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get policy by ID
|
|
15
|
+
*
|
|
16
|
+
* @param id - Policy ID (e.g., "time-window@1")
|
|
17
|
+
* @returns Policy or undefined if not found
|
|
18
|
+
*/
|
|
19
|
+
getById(id) {
|
|
20
|
+
return this.policies.find((p) => p.id === id);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get all policies for a specific enforcement phase
|
|
24
|
+
*
|
|
25
|
+
* @param phase - Enforcement phase
|
|
26
|
+
* @returns Array of policies
|
|
27
|
+
*/
|
|
28
|
+
getByPhase(phase) {
|
|
29
|
+
return this.policies.filter((p) => p.enforcementPhase === phase);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get all active policies
|
|
33
|
+
*
|
|
34
|
+
* @returns All registered policies
|
|
35
|
+
*/
|
|
36
|
+
getAll() {
|
|
37
|
+
return [...this.policies];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check if a policy is registered
|
|
41
|
+
*
|
|
42
|
+
* @param id - Policy ID
|
|
43
|
+
* @returns True if registered
|
|
44
|
+
*/
|
|
45
|
+
isRegistered(id) {
|
|
46
|
+
return this.policies.some((p) => p.id === id);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get all registered policy IDs
|
|
50
|
+
*/
|
|
51
|
+
get registeredIds() {
|
|
52
|
+
return this.policies.map((p) => p.id);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get capabilities for proposal/negotiation
|
|
56
|
+
*/
|
|
57
|
+
get capabilities() {
|
|
58
|
+
return this.policies.map((p) => ({
|
|
59
|
+
id: p.id,
|
|
60
|
+
enforcementPhase: p.enforcementPhase,
|
|
61
|
+
configurable: p.configurable
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
PolicyRegistry = __decorate([
|
|
66
|
+
injectable(),
|
|
67
|
+
__decorateParam(0, injectAll(PolicyToken)),
|
|
68
|
+
__decorateMetadata("design:paramtypes", [Array])
|
|
69
|
+
], PolicyRegistry);
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { PolicyRegistry, PolicyToken };
|
|
73
|
+
//# sourceMappingURL=PolicyRegistry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PolicyRegistry.mjs","names":[],"sources":["../../../src/registry/policies/PolicyRegistry.ts"],"sourcesContent":["import type { Policy, PolicyEnforcementPhase } from './Policy'\nimport type { PolicyCapability } from '../../models'\n\nimport { injectable, injectAll } from '@credo-ts/core'\n\nexport const PolicyToken = Symbol('PolicyToken')\n\n/**\n * Registry for policy modules\n *\n * Uses dependency injection to allow pluggable policies.\n * Policies can be registered by adding them to the module config.\n */\n@injectable()\nexport class PolicyRegistry {\n private policies: Policy[]\n\n public constructor(@injectAll(PolicyToken) policies: Array<Policy | 'default'>) {\n // Filter out the 'default' placeholder used for tsyringe\n this.policies = policies.filter((p): p is Policy => p !== 'default')\n }\n\n /**\n * Get policy by ID\n *\n * @param id - Policy ID (e.g., \"time-window@1\")\n * @returns Policy or undefined if not found\n */\n public getById(id: string): Policy | undefined {\n return this.policies.find((p) => p.id === id)\n }\n\n /**\n * Get all policies for a specific enforcement phase\n *\n * @param phase - Enforcement phase\n * @returns Array of policies\n */\n public getByPhase(phase: PolicyEnforcementPhase): Policy[] {\n return this.policies.filter((p) => p.enforcementPhase === phase)\n }\n\n /**\n * Get all active policies\n *\n * @returns All registered policies\n */\n public getAll(): Policy[] {\n return [...this.policies]\n }\n\n /**\n * Check if a policy is registered\n *\n * @param id - Policy ID\n * @returns True if registered\n */\n public isRegistered(id: string): boolean {\n return this.policies.some((p) => p.id === id)\n }\n\n /**\n * Get all registered policy IDs\n */\n public get registeredIds(): string[] {\n return this.policies.map((p) => p.id)\n }\n\n /**\n * Get capabilities for proposal/negotiation\n */\n public get capabilities(): PolicyCapability[] {\n return this.policies.map((p) => ({\n id: p.id,\n enforcementPhase: p.enforcementPhase,\n configurable: p.configurable,\n }))\n }\n}\n"],"mappings":";;;;;;;AAKA,MAAa,cAAc,OAAO,cAAc;AASzC,2BAAM,eAAe;CAG1B,AAAO,YAAY,AAAwB,UAAqC;AAE9E,OAAK,WAAW,SAAS,QAAQ,MAAmB,MAAM,UAAU;;;;;;;;CAStE,AAAO,QAAQ,IAAgC;AAC7C,SAAO,KAAK,SAAS,MAAM,MAAM,EAAE,OAAO,GAAG;;;;;;;;CAS/C,AAAO,WAAW,OAAyC;AACzD,SAAO,KAAK,SAAS,QAAQ,MAAM,EAAE,qBAAqB,MAAM;;;;;;;CAQlE,AAAO,SAAmB;AACxB,SAAO,CAAC,GAAG,KAAK,SAAS;;;;;;;;CAS3B,AAAO,aAAa,IAAqB;AACvC,SAAO,KAAK,SAAS,MAAM,MAAM,EAAE,OAAO,GAAG;;;;;CAM/C,IAAW,gBAA0B;AACnC,SAAO,KAAK,SAAS,KAAK,MAAM,EAAE,GAAG;;;;;CAMvC,IAAW,eAAmC;AAC5C,SAAO,KAAK,SAAS,KAAK,OAAO;GAC/B,IAAI,EAAE;GACN,kBAAkB,EAAE;GACpB,cAAc,EAAE;GACjB,EAAE;;;;CA/DN,YAAY;oBAIS,UAAU,YAAY"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { PolicyContext, PolicyResult } from "../../models/PolicyContext.mjs";
|
|
2
|
+
import "../../models/index.mjs";
|
|
3
|
+
import { SigningSessionRecord } from "../../repository/SigningSessionRecord.mjs";
|
|
4
|
+
import { Policy } from "./Policy.mjs";
|
|
5
|
+
import { AgentContext } from "@credo-ts/core";
|
|
6
|
+
|
|
7
|
+
//#region src/registry/policies/TimeWindowPolicy.d.ts
|
|
8
|
+
interface TimeWindowPolicyParameters {
|
|
9
|
+
/**
|
|
10
|
+
* Maximum time window for signing (in milliseconds)
|
|
11
|
+
* Default: 24 hours
|
|
12
|
+
*/
|
|
13
|
+
maxDuration?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Grace period after expiration (in milliseconds)
|
|
16
|
+
* Default: 5 minutes
|
|
17
|
+
*/
|
|
18
|
+
gracePeriod?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Require all signatures within time window
|
|
21
|
+
* Default: true
|
|
22
|
+
*/
|
|
23
|
+
strictTiming?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Time Window Policy
|
|
27
|
+
*
|
|
28
|
+
* Enforces time-based constraints on signing sessions:
|
|
29
|
+
* - Sessions must complete within a maximum duration
|
|
30
|
+
* - Optional grace period for clock skew
|
|
31
|
+
* - Can enforce strict timing requirements
|
|
32
|
+
*
|
|
33
|
+
* Use cases:
|
|
34
|
+
* - Time-sensitive documents
|
|
35
|
+
* - Compliance requirements
|
|
36
|
+
* - Prevent stale signatures
|
|
37
|
+
*/
|
|
38
|
+
declare class TimeWindowPolicy implements Policy {
|
|
39
|
+
readonly id = "time-window@1";
|
|
40
|
+
readonly version = 1;
|
|
41
|
+
readonly name = "time-window";
|
|
42
|
+
readonly enforcementPhase: "post-sign";
|
|
43
|
+
readonly configurable = true;
|
|
44
|
+
private readonly DEFAULT_MAX_DURATION;
|
|
45
|
+
private readonly DEFAULT_GRACE_PERIOD;
|
|
46
|
+
/**
|
|
47
|
+
* Evaluate if session meets time window policy
|
|
48
|
+
*/
|
|
49
|
+
evaluate(session: SigningSessionRecord, parameters?: TimeWindowPolicyParameters): Promise<{
|
|
50
|
+
allowed: boolean;
|
|
51
|
+
reason?: string;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Enforce policy by checking evaluation result
|
|
55
|
+
*/
|
|
56
|
+
enforce(_agentContext: AgentContext, context: PolicyContext): Promise<PolicyResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Validate policy configuration
|
|
59
|
+
*/
|
|
60
|
+
validate(config: unknown): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Get policy metadata including default parameters
|
|
63
|
+
*/
|
|
64
|
+
getMetadata(): {
|
|
65
|
+
id: string;
|
|
66
|
+
version: number;
|
|
67
|
+
name: string;
|
|
68
|
+
defaultParameters: TimeWindowPolicyParameters;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Format milliseconds into human-readable duration
|
|
72
|
+
*/
|
|
73
|
+
private formatDuration;
|
|
74
|
+
/**
|
|
75
|
+
* Calculate time remaining in session
|
|
76
|
+
*/
|
|
77
|
+
timeRemaining(session: SigningSessionRecord, parameters?: TimeWindowPolicyParameters): number;
|
|
78
|
+
/**
|
|
79
|
+
* Check if session has expired
|
|
80
|
+
*/
|
|
81
|
+
isExpired(session: SigningSessionRecord, parameters?: TimeWindowPolicyParameters): boolean;
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
export { TimeWindowPolicy, TimeWindowPolicyParameters };
|
|
85
|
+
//# sourceMappingURL=TimeWindowPolicy.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimeWindowPolicy.d.mts","names":[],"sources":["../../../src/registry/policies/TimeWindowPolicy.ts"],"mappings":";;;;;;;UAOiB,0BAAA;;;AAAjB;;EAKE,WAAA;EALyC;;;;EAWzC,WAAA;EAMY;AAgBd;;;EAhBE,YAAA;AAAA;;;;;;;;;;;;;;cAiBW,gBAAA,YAA4B,MAAA;EAAA,SACvB,EAAA;EAAA,SACA,OAAA;EAAA,SACA,IAAA;EAAA,SACA,gBAAA;EAAA,SACA,YAAA;EAAA,iBAEC,oBAAA;EAAA,iBACA,oBAAA;EAKJ;;;EAAA,QAAA,CACX,OAAA,EAAS,oBAAA,EACT,UAAA,GAAa,0BAAA,GACZ,OAAA;IAAU,OAAA;IAAkB,MAAA;EAAA;EAAA;;;EAoDlB,OAAA,CAAQ,aAAA,EAAe,YAAA,EAAc,OAAA,EAAS,aAAA,GAAgB,OAAA,CAAQ,YAAA;EAAxB;;;EAUpD,QAAA,CAAS,MAAA;EAAT;;;EAeA,WAAA,CAAA;IACL,EAAA;IACA,OAAA;IACA,IAAA;IACA,iBAAA,EAAmB,0BAAA;EAAA;EAsCd;;;EAAA,QArBC,cAAA;EAqB4C;;;EAA7C,aAAA,CAAc,OAAA,EAAS,oBAAA,EAAsB,UAAA,GAAa,0BAAA;EAiBJ;;;EAAtD,SAAA,CAAU,OAAA,EAAS,oBAAA,EAAsB,UAAA,GAAa,0BAAA;AAAA"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
|
|
2
|
+
import { CredoError, injectable } from "@credo-ts/core";
|
|
3
|
+
|
|
4
|
+
//#region src/registry/policies/TimeWindowPolicy.ts
|
|
5
|
+
let TimeWindowPolicy = class TimeWindowPolicy {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.id = "time-window@1";
|
|
8
|
+
this.version = 1;
|
|
9
|
+
this.name = "time-window";
|
|
10
|
+
this.enforcementPhase = "post-sign";
|
|
11
|
+
this.configurable = true;
|
|
12
|
+
this.DEFAULT_MAX_DURATION = 1440 * 60 * 1e3;
|
|
13
|
+
this.DEFAULT_GRACE_PERIOD = 300 * 1e3;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Evaluate if session meets time window policy
|
|
17
|
+
*/
|
|
18
|
+
async evaluate(session, parameters) {
|
|
19
|
+
const maxDuration = parameters?.maxDuration ?? this.DEFAULT_MAX_DURATION;
|
|
20
|
+
const gracePeriod = parameters?.gracePeriod ?? this.DEFAULT_GRACE_PERIOD;
|
|
21
|
+
const strictTiming = parameters?.strictTiming ?? true;
|
|
22
|
+
const now = Date.now();
|
|
23
|
+
const sessionStart = session.createdAt.getTime();
|
|
24
|
+
const elapsed = now - sessionStart;
|
|
25
|
+
if (strictTiming && session.partialSignatures.length > 0) for (const sig of session.partialSignatures) {
|
|
26
|
+
if (!sig.timestamp) continue;
|
|
27
|
+
if (new Date(sig.timestamp).getTime() - sessionStart > maxDuration + gracePeriod) return {
|
|
28
|
+
allowed: false,
|
|
29
|
+
reason: `Signature from ${sig.signer} is outside time window`
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (elapsed > maxDuration + gracePeriod) return {
|
|
33
|
+
allowed: false,
|
|
34
|
+
reason: `Session expired. Maximum duration: ${this.formatDuration(maxDuration)}, elapsed: ${this.formatDuration(elapsed)}`
|
|
35
|
+
};
|
|
36
|
+
if (elapsed > maxDuration && elapsed <= maxDuration + gracePeriod) return {
|
|
37
|
+
allowed: true,
|
|
38
|
+
reason: `Session within grace period. Duration: ${this.formatDuration(elapsed)}`
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
allowed: true,
|
|
42
|
+
reason: `Session within time window. Duration: ${this.formatDuration(elapsed)}`
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Enforce policy by checking evaluation result
|
|
47
|
+
*/
|
|
48
|
+
async enforce(_agentContext, context) {
|
|
49
|
+
const parameters = context.metadata;
|
|
50
|
+
return await this.evaluate(context.session, parameters);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Validate policy configuration
|
|
54
|
+
*/
|
|
55
|
+
validate(config) {
|
|
56
|
+
if (typeof config !== "object" || config === null) return false;
|
|
57
|
+
const params = config;
|
|
58
|
+
if (params.maxDuration !== void 0 && (typeof params.maxDuration !== "number" || params.maxDuration <= 0)) return false;
|
|
59
|
+
if (params.gracePeriod !== void 0 && (typeof params.gracePeriod !== "number" || params.gracePeriod < 0)) return false;
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get policy metadata including default parameters
|
|
64
|
+
*/
|
|
65
|
+
getMetadata() {
|
|
66
|
+
return {
|
|
67
|
+
id: this.id,
|
|
68
|
+
version: this.version,
|
|
69
|
+
name: this.name,
|
|
70
|
+
defaultParameters: {
|
|
71
|
+
maxDuration: this.DEFAULT_MAX_DURATION,
|
|
72
|
+
gracePeriod: this.DEFAULT_GRACE_PERIOD,
|
|
73
|
+
strictTiming: true
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Format milliseconds into human-readable duration
|
|
79
|
+
*/
|
|
80
|
+
formatDuration(ms) {
|
|
81
|
+
const seconds = Math.floor(ms / 1e3);
|
|
82
|
+
const minutes = Math.floor(seconds / 60);
|
|
83
|
+
const hours = Math.floor(minutes / 60);
|
|
84
|
+
const days = Math.floor(hours / 24);
|
|
85
|
+
if (days > 0) return `${days}d ${hours % 24}h`;
|
|
86
|
+
if (hours > 0) return `${hours}h ${minutes % 60}m`;
|
|
87
|
+
if (minutes > 0) return `${minutes}m ${seconds % 60}s`;
|
|
88
|
+
return `${seconds}s`;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Calculate time remaining in session
|
|
92
|
+
*/
|
|
93
|
+
timeRemaining(session, parameters) {
|
|
94
|
+
const maxDuration = parameters?.maxDuration ?? this.DEFAULT_MAX_DURATION;
|
|
95
|
+
const gracePeriod = parameters?.gracePeriod ?? this.DEFAULT_GRACE_PERIOD;
|
|
96
|
+
const elapsed = Date.now() - session.createdAt.getTime();
|
|
97
|
+
const remaining = maxDuration + gracePeriod - elapsed;
|
|
98
|
+
return Math.max(0, remaining);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Check if session has expired
|
|
102
|
+
*/
|
|
103
|
+
isExpired(session, parameters) {
|
|
104
|
+
return this.timeRemaining(session, parameters) === 0;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
TimeWindowPolicy = __decorate([injectable()], TimeWindowPolicy);
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
export { TimeWindowPolicy };
|
|
111
|
+
//# sourceMappingURL=TimeWindowPolicy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimeWindowPolicy.mjs","names":[],"sources":["../../../src/registry/policies/TimeWindowPolicy.ts"],"sourcesContent":["import type { Policy } from './Policy'\nimport type { SigningSessionRecord } from '../../repository/SigningSessionRecord'\nimport type { AgentContext } from '@credo-ts/core'\nimport type { PolicyContext, PolicyResult } from '../../models'\n\nimport { CredoError, injectable } from '@credo-ts/core'\n\nexport interface TimeWindowPolicyParameters {\n /**\n * Maximum time window for signing (in milliseconds)\n * Default: 24 hours\n */\n maxDuration?: number\n\n /**\n * Grace period after expiration (in milliseconds)\n * Default: 5 minutes\n */\n gracePeriod?: number\n\n /**\n * Require all signatures within time window\n * Default: true\n */\n strictTiming?: boolean\n}\n\n/**\n * Time Window Policy\n *\n * Enforces time-based constraints on signing sessions:\n * - Sessions must complete within a maximum duration\n * - Optional grace period for clock skew\n * - Can enforce strict timing requirements\n *\n * Use cases:\n * - Time-sensitive documents\n * - Compliance requirements\n * - Prevent stale signatures\n */\n@injectable()\nexport class TimeWindowPolicy implements Policy {\n public readonly id = 'time-window@1'\n public readonly version = 1\n public readonly name = 'time-window'\n public readonly enforcementPhase = 'post-sign' as const\n public readonly configurable = true\n\n private readonly DEFAULT_MAX_DURATION = 24 * 60 * 60 * 1000 // 24 hours\n private readonly DEFAULT_GRACE_PERIOD = 5 * 60 * 1000 // 5 minutes\n\n /**\n * Evaluate if session meets time window policy\n */\n public async evaluate(\n session: SigningSessionRecord,\n parameters?: TimeWindowPolicyParameters\n ): Promise<{ allowed: boolean; reason?: string }> {\n const maxDuration = parameters?.maxDuration ?? this.DEFAULT_MAX_DURATION\n const gracePeriod = parameters?.gracePeriod ?? this.DEFAULT_GRACE_PERIOD\n const strictTiming = parameters?.strictTiming ?? true\n\n const now = Date.now()\n const sessionStart = session.createdAt.getTime()\n const elapsed = now - sessionStart\n\n // If strict timing is enabled, check individual signature timestamps first\n if (strictTiming && session.partialSignatures.length > 0) {\n for (const sig of session.partialSignatures) {\n if (!sig.timestamp) continue\n\n const sigTime = new Date(sig.timestamp).getTime()\n const sigElapsed = sigTime - sessionStart\n\n if (sigElapsed > maxDuration + gracePeriod) {\n return {\n allowed: false,\n reason: `Signature from ${sig.signer} is outside time window`,\n }\n }\n }\n }\n\n // Check if session has exceeded max duration\n if (elapsed > maxDuration + gracePeriod) {\n return {\n allowed: false,\n reason: `Session expired. Maximum duration: ${this.formatDuration(maxDuration)}, elapsed: ${this.formatDuration(elapsed)}`,\n }\n }\n\n // Warning if within grace period\n if (elapsed > maxDuration && elapsed <= maxDuration + gracePeriod) {\n // Still allowed but log warning\n return {\n allowed: true,\n reason: `Session within grace period. Duration: ${this.formatDuration(elapsed)}`,\n }\n }\n\n return {\n allowed: true,\n reason: `Session within time window. Duration: ${this.formatDuration(elapsed)}`,\n }\n }\n\n /**\n * Enforce policy by checking evaluation result\n */\n public async enforce(_agentContext: AgentContext, context: PolicyContext): Promise<PolicyResult> {\n const parameters = context.metadata as TimeWindowPolicyParameters | undefined\n const evaluation = await this.evaluate(context.session, parameters)\n\n return evaluation\n }\n\n /**\n * Validate policy configuration\n */\n public validate(config: unknown): boolean {\n if (typeof config !== 'object' || config === null) return false\n const params = config as any\n if (params.maxDuration !== undefined && (typeof params.maxDuration !== 'number' || params.maxDuration <= 0)) {\n return false\n }\n if (params.gracePeriod !== undefined && (typeof params.gracePeriod !== 'number' || params.gracePeriod < 0)) {\n return false\n }\n return true\n }\n\n /**\n * Get policy metadata including default parameters\n */\n public getMetadata(): {\n id: string\n version: number\n name: string\n defaultParameters: TimeWindowPolicyParameters\n } {\n return {\n id: this.id,\n version: this.version,\n name: this.name,\n defaultParameters: {\n maxDuration: this.DEFAULT_MAX_DURATION,\n gracePeriod: this.DEFAULT_GRACE_PERIOD,\n strictTiming: true,\n },\n }\n }\n\n /**\n * Format milliseconds into human-readable duration\n */\n private formatDuration(ms: number): string {\n const seconds = Math.floor(ms / 1000)\n const minutes = Math.floor(seconds / 60)\n const hours = Math.floor(minutes / 60)\n const days = Math.floor(hours / 24)\n\n if (days > 0) {\n return `${days}d ${hours % 24}h`\n }\n if (hours > 0) {\n return `${hours}h ${minutes % 60}m`\n }\n if (minutes > 0) {\n return `${minutes}m ${seconds % 60}s`\n }\n return `${seconds}s`\n }\n\n /**\n * Calculate time remaining in session\n */\n public timeRemaining(session: SigningSessionRecord, parameters?: TimeWindowPolicyParameters): number {\n const maxDuration = parameters?.maxDuration ?? this.DEFAULT_MAX_DURATION\n const gracePeriod = parameters?.gracePeriod ?? this.DEFAULT_GRACE_PERIOD\n\n const now = Date.now()\n const sessionStart = session.createdAt.getTime()\n const elapsed = now - sessionStart\n\n const totalAllowed = maxDuration + gracePeriod\n const remaining = totalAllowed - elapsed\n\n return Math.max(0, remaining)\n }\n\n /**\n * Check if session has expired\n */\n public isExpired(session: SigningSessionRecord, parameters?: TimeWindowPolicyParameters): boolean {\n return this.timeRemaining(session, parameters) === 0\n }\n}\n"],"mappings":";;;;AAyCO,6BAAM,iBAAmC;;OAC9B,KAAK;OACL,UAAU;OACV,OAAO;OACP,mBAAmB;OACnB,eAAe;OAEd,uBAAuB,OAAU,KAAK;OACtC,uBAAuB,MAAS;;;;;CAKjD,MAAa,SACX,SACA,YACgD;EAChD,MAAM,cAAc,YAAY,eAAe,KAAK;EACpD,MAAM,cAAc,YAAY,eAAe,KAAK;EACpD,MAAM,eAAe,YAAY,gBAAgB;EAEjD,MAAM,MAAM,KAAK,KAAK;EACtB,MAAM,eAAe,QAAQ,UAAU,SAAS;EAChD,MAAM,UAAU,MAAM;AAGtB,MAAI,gBAAgB,QAAQ,kBAAkB,SAAS,EACrD,MAAK,MAAM,OAAO,QAAQ,mBAAmB;AAC3C,OAAI,CAAC,IAAI,UAAW;AAKpB,OAHgB,IAAI,KAAK,IAAI,UAAU,CAAC,SAAS,GACpB,eAEZ,cAAc,YAC7B,QAAO;IACL,SAAS;IACT,QAAQ,kBAAkB,IAAI,OAAO;IACtC;;AAMP,MAAI,UAAU,cAAc,YAC1B,QAAO;GACL,SAAS;GACT,QAAQ,sCAAsC,KAAK,eAAe,YAAY,CAAC,aAAa,KAAK,eAAe,QAAQ;GACzH;AAIH,MAAI,UAAU,eAAe,WAAW,cAAc,YAEpD,QAAO;GACL,SAAS;GACT,QAAQ,0CAA0C,KAAK,eAAe,QAAQ;GAC/E;AAGH,SAAO;GACL,SAAS;GACT,QAAQ,yCAAyC,KAAK,eAAe,QAAQ;GAC9E;;;;;CAMH,MAAa,QAAQ,eAA6B,SAA+C;EAC/F,MAAM,aAAa,QAAQ;AAG3B,SAFmB,MAAM,KAAK,SAAS,QAAQ,SAAS,WAAW;;;;;CAQrE,AAAO,SAAS,QAA0B;AACxC,MAAI,OAAO,WAAW,YAAY,WAAW,KAAM,QAAO;EAC1D,MAAM,SAAS;AACf,MAAI,OAAO,gBAAgB,WAAc,OAAO,OAAO,gBAAgB,YAAY,OAAO,eAAe,GACvG,QAAO;AAET,MAAI,OAAO,gBAAgB,WAAc,OAAO,OAAO,gBAAgB,YAAY,OAAO,cAAc,GACtG,QAAO;AAET,SAAO;;;;;CAMT,AAAO,cAKL;AACA,SAAO;GACL,IAAI,KAAK;GACT,SAAS,KAAK;GACd,MAAM,KAAK;GACX,mBAAmB;IACjB,aAAa,KAAK;IAClB,aAAa,KAAK;IAClB,cAAc;IACf;GACF;;;;;CAMH,AAAQ,eAAe,IAAoB;EACzC,MAAM,UAAU,KAAK,MAAM,KAAK,IAAK;EACrC,MAAM,UAAU,KAAK,MAAM,UAAU,GAAG;EACxC,MAAM,QAAQ,KAAK,MAAM,UAAU,GAAG;EACtC,MAAM,OAAO,KAAK,MAAM,QAAQ,GAAG;AAEnC,MAAI,OAAO,EACT,QAAO,GAAG,KAAK,IAAI,QAAQ,GAAG;AAEhC,MAAI,QAAQ,EACV,QAAO,GAAG,MAAM,IAAI,UAAU,GAAG;AAEnC,MAAI,UAAU,EACZ,QAAO,GAAG,QAAQ,IAAI,UAAU,GAAG;AAErC,SAAO,GAAG,QAAQ;;;;;CAMpB,AAAO,cAAc,SAA+B,YAAiD;EACnG,MAAM,cAAc,YAAY,eAAe,KAAK;EACpD,MAAM,cAAc,YAAY,eAAe,KAAK;EAIpD,MAAM,UAFM,KAAK,KAAK,GACD,QAAQ,UAAU,SAAS;EAIhD,MAAM,YADe,cAAc,cACF;AAEjC,SAAO,KAAK,IAAI,GAAG,UAAU;;;;;CAM/B,AAAO,UAAU,SAA+B,YAAkD;AAChG,SAAO,KAAK,cAAc,SAAS,WAAW,KAAK;;;+BA1JtD,YAAY"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SignatureResult } from "../../models/PartialSignature.mjs";
|
|
2
|
+
import "../../models/index.mjs";
|
|
3
|
+
import { KeyType } from "../../compat.mjs";
|
|
4
|
+
import { SignInput, SignatureSuite, VerifyInput } from "./SignatureSuite.mjs";
|
|
5
|
+
import { AgentContext, JwsService } from "@credo-ts/core";
|
|
6
|
+
|
|
7
|
+
//#region src/registry/suites/JwsEd25519Suite.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* JWS Ed25519 Signature Suite
|
|
10
|
+
*
|
|
11
|
+
* Implements digital signatures using Ed25519 keys with JWS format.
|
|
12
|
+
* This is the default suite for EdDSA signatures.
|
|
13
|
+
*/
|
|
14
|
+
declare class JwsEd25519Suite implements SignatureSuite {
|
|
15
|
+
readonly id = "jws-ed25519@1";
|
|
16
|
+
readonly version = 1;
|
|
17
|
+
readonly name = "jws-ed25519";
|
|
18
|
+
readonly keyTypes: KeyType[];
|
|
19
|
+
readonly signatureFormats: string[];
|
|
20
|
+
readonly supportsMultiRound = false;
|
|
21
|
+
private jwsService;
|
|
22
|
+
constructor(jwsService: JwsService);
|
|
23
|
+
/**
|
|
24
|
+
* Sign data with Ed25519 key
|
|
25
|
+
*/
|
|
26
|
+
sign(agentContext: AgentContext, input: SignInput): Promise<SignatureResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Verify signature with Ed25519 key
|
|
29
|
+
*/
|
|
30
|
+
verify(agentContext: AgentContext, input: VerifyInput): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Check if key type is supported
|
|
33
|
+
*/
|
|
34
|
+
supportsKeyType(keyType: KeyType): boolean;
|
|
35
|
+
private isEd25519;
|
|
36
|
+
/**
|
|
37
|
+
* Resolve key from wallet using key ID
|
|
38
|
+
*/
|
|
39
|
+
private resolveKey;
|
|
40
|
+
/**
|
|
41
|
+
* Compare two Uint8Arrays for equality
|
|
42
|
+
*/
|
|
43
|
+
private compareBuffers;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { JwsEd25519Suite };
|
|
47
|
+
//# sourceMappingURL=JwsEd25519Suite.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JwsEd25519Suite.d.mts","names":[],"sources":["../../../src/registry/suites/JwsEd25519Suite.ts"],"mappings":";;;;;;;;;AAgBA;;;;cACa,eAAA,YAA2B,cAAA;EAAA,SACtB,EAAA;EAAA,SACA,OAAA;EAAA,SACA,IAAA;EAAA,SACA,QAAA,EAAQ,OAAA;EAAA,SACR,gBAAA;EAAA,SACA,kBAAA;EAAA,QAER,UAAA;cAEW,UAAA,EAAY,UAAA;EAVO;;;EAiBzB,IAAA,CAAK,YAAA,EAAc,YAAA,EAAc,KAAA,EAAO,SAAA,GAAY,OAAA,CAAQ,eAAA;EAhBzD;;;EA+CH,MAAA,CAAO,YAAA,EAAc,YAAA,EAAc,KAAA,EAAO,WAAA,GAAc,OAAA;EA5C7C;;;EAqFjB,eAAA,CAAgB,OAAA,EAAS,OAAA;EAAA,QAIxB,SAAA;EAnFuB;;;EAAA,QA2FjB,UAAA;EApFI;;;EAAA,QAyHV,cAAA;AAAA"}
|