@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,101 @@
|
|
|
1
|
+
import { __decorateMetadata } from "../../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs";
|
|
2
|
+
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
|
|
3
|
+
import { KeyType } from "../../compat.mjs";
|
|
4
|
+
import { CredoError, DidsApi, JwsService, Kms, TypedArrayEncoder, injectable } from "@credo-ts/core";
|
|
5
|
+
|
|
6
|
+
//#region src/registry/suites/JwsEd25519Suite.ts
|
|
7
|
+
var _ref;
|
|
8
|
+
let JwsEd25519Suite = class JwsEd25519Suite {
|
|
9
|
+
constructor(jwsService) {
|
|
10
|
+
this.id = "jws-ed25519@1";
|
|
11
|
+
this.version = 1;
|
|
12
|
+
this.name = "jws-ed25519";
|
|
13
|
+
this.keyTypes = [KeyType.Ed25519];
|
|
14
|
+
this.signatureFormats = ["jws"];
|
|
15
|
+
this.supportsMultiRound = false;
|
|
16
|
+
this.jwsService = jwsService;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Sign data with Ed25519 key
|
|
20
|
+
*/
|
|
21
|
+
async sign(agentContext, input) {
|
|
22
|
+
const { data, keyRef, parameters } = input;
|
|
23
|
+
const publicJwk = await this.resolveKey(agentContext, keyRef);
|
|
24
|
+
if (!this.isEd25519(publicJwk)) throw new CredoError(`Key ${keyRef} is not an Ed25519 key`);
|
|
25
|
+
return {
|
|
26
|
+
format: "jws",
|
|
27
|
+
value: await this.jwsService.createJwsCompact(agentContext, {
|
|
28
|
+
protectedHeaderOptions: {
|
|
29
|
+
alg: "EdDSA",
|
|
30
|
+
kid: keyRef,
|
|
31
|
+
...parameters
|
|
32
|
+
},
|
|
33
|
+
payload: Buffer.from(data),
|
|
34
|
+
keyId: keyRef
|
|
35
|
+
}),
|
|
36
|
+
publicKeyHint: publicJwk.fingerprint
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Verify signature with Ed25519 key
|
|
41
|
+
*/
|
|
42
|
+
async verify(agentContext, input) {
|
|
43
|
+
try {
|
|
44
|
+
const { data, signature, publicKey } = input;
|
|
45
|
+
if (signature.format !== "jws") throw new CredoError(`Invalid signature format: ${signature.format}. Expected 'jws'`);
|
|
46
|
+
const publicJwk = await this.resolveKey(agentContext, publicKey);
|
|
47
|
+
if (!this.isEd25519(publicJwk)) throw new CredoError(`Key ${publicKey} is not an Ed25519 key`);
|
|
48
|
+
const result = await this.jwsService.verifyJws(agentContext, {
|
|
49
|
+
jws: signature.value,
|
|
50
|
+
jwsSigner: {
|
|
51
|
+
method: "jwk",
|
|
52
|
+
jwk: publicJwk
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
const decodedPayload = TypedArrayEncoder.fromBase64Url(result.jws.payload);
|
|
56
|
+
const payloadMatches = this.compareBuffers(decodedPayload, data);
|
|
57
|
+
return result.isValid && payloadMatches;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Check if key type is supported
|
|
64
|
+
*/
|
|
65
|
+
supportsKeyType(keyType) {
|
|
66
|
+
return this.keyTypes.includes(keyType);
|
|
67
|
+
}
|
|
68
|
+
isEd25519(publicJwk) {
|
|
69
|
+
const jwk = publicJwk.toJson();
|
|
70
|
+
return jwk.kty === "OKP" && jwk.crv === "Ed25519";
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Resolve key from wallet using key ID
|
|
74
|
+
*/
|
|
75
|
+
async resolveKey(agentContext, keyId) {
|
|
76
|
+
try {
|
|
77
|
+
let fingerprint = keyId;
|
|
78
|
+
if (keyId.startsWith("did:")) if (keyId.startsWith("did:key:")) fingerprint = keyId.substring(8);
|
|
79
|
+
else throw new CredoError(`Only did:key DIDs are currently supported for signing. Got: ${keyId}`);
|
|
80
|
+
try {
|
|
81
|
+
if ((await agentContext.dependencyManager.resolve(DidsApi).getCreatedDids({ did: keyId })).length > 0) return Kms.PublicJwk.fromFingerprint(fingerprint);
|
|
82
|
+
} catch (error) {}
|
|
83
|
+
return Kms.PublicJwk.fromFingerprint(fingerprint);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
throw new CredoError(`Key not found: ${keyId}. Error: ${error}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Compare two Uint8Arrays for equality
|
|
90
|
+
*/
|
|
91
|
+
compareBuffers(a, b) {
|
|
92
|
+
if (a.length !== b.length) return false;
|
|
93
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
JwsEd25519Suite = __decorate([injectable(), __decorateMetadata("design:paramtypes", [JwsService])], JwsEd25519Suite);
|
|
98
|
+
|
|
99
|
+
//#endregion
|
|
100
|
+
export { JwsEd25519Suite };
|
|
101
|
+
//# sourceMappingURL=JwsEd25519Suite.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JwsEd25519Suite.mjs","names":[],"sources":["../../../src/registry/suites/JwsEd25519Suite.ts"],"sourcesContent":["import type { SignatureSuite, SignInput, VerifyInput } from './SignatureSuite'\nimport type { AgentContext } from '@credo-ts/core'\nimport type { SignatureResult } from '../../models'\n\nimport { CredoError, injectable, JwsService, Kms, TypedArrayEncoder, DidsApi } from '@credo-ts/core'\n\nimport { KeyType } from '../../compat'\n\ntype PublicJwk = Kms.PublicJwk\n\n/**\n * JWS Ed25519 Signature Suite\n *\n * Implements digital signatures using Ed25519 keys with JWS format.\n * This is the default suite for EdDSA signatures.\n */\n@injectable()\nexport class JwsEd25519Suite implements SignatureSuite {\n public readonly id = 'jws-ed25519@1'\n public readonly version = 1\n public readonly name = 'jws-ed25519'\n public readonly keyTypes = [KeyType.Ed25519]\n public readonly signatureFormats = ['jws']\n public readonly supportsMultiRound = false\n\n private jwsService: JwsService\n\n public constructor(jwsService: JwsService) {\n this.jwsService = jwsService\n }\n\n /**\n * Sign data with Ed25519 key\n */\n public async sign(agentContext: AgentContext, input: SignInput): Promise<SignatureResult> {\n const { data, keyRef, parameters } = input\n\n // Resolve key from wallet\n const publicJwk = await this.resolveKey(agentContext, keyRef)\n\n if (!this.isEd25519(publicJwk)) {\n throw new CredoError(`Key ${keyRef} is not an Ed25519 key`)\n }\n\n // Create JWS\n const jws = await this.jwsService.createJwsCompact(agentContext, {\n protectedHeaderOptions: {\n alg: 'EdDSA',\n kid: keyRef,\n ...parameters,\n },\n payload: Buffer.from(data) as any,\n keyId: keyRef,\n })\n\n return {\n format: 'jws',\n value: jws,\n publicKeyHint: publicJwk.fingerprint,\n }\n }\n\n /**\n * Verify signature with Ed25519 key\n */\n public async verify(agentContext: AgentContext, input: VerifyInput): Promise<boolean> {\n try {\n const { data, signature, publicKey } = input\n\n if (signature.format !== 'jws') {\n throw new CredoError(`Invalid signature format: ${signature.format}. Expected 'jws'`)\n }\n\n // Resolve key from wallet or DID document\n const publicJwk = await this.resolveKey(agentContext, publicKey)\n\n if (!this.isEd25519(publicJwk)) {\n throw new CredoError(`Key ${publicKey} is not an Ed25519 key`)\n }\n\n // Verify JWS\n const result = await this.jwsService.verifyJws(agentContext, {\n jws: signature.value,\n jwsSigner: {\n method: 'jwk',\n jwk: publicJwk,\n },\n })\n\n // Decode the base64url-encoded payload\n // Credo 0.7's fromBase64 is strict base64; JWS payloads are base64url (no padding)\n const decodedPayload = TypedArrayEncoder.fromBase64Url(result.jws.payload)\n\n // Check payload matches\n const payloadMatches = this.compareBuffers(decodedPayload, data)\n\n return result.isValid && payloadMatches\n } catch (error) {\n // Verification failure returns false rather than throwing\n return false\n }\n }\n\n /**\n * Check if key type is supported\n */\n public supportsKeyType(keyType: KeyType): boolean {\n return this.keyTypes.includes(keyType)\n }\n\n private isEd25519(publicJwk: PublicJwk): boolean {\n const jwk = publicJwk.toJson()\n return jwk.kty === 'OKP' && (jwk as { crv?: string }).crv === 'Ed25519'\n }\n\n /**\n * Resolve key from wallet using key ID\n */\n private async resolveKey(agentContext: AgentContext, keyId: string): Promise<PublicJwk> {\n try {\n let fingerprint = keyId\n\n // If keyId is a DID (starts with 'did:'), extract the fingerprint\n if (keyId.startsWith('did:')) {\n // For did:key: DIDs, the fingerprint is after 'did:key:'\n if (keyId.startsWith('did:key:')) {\n fingerprint = keyId.substring('did:key:'.length)\n } else {\n throw new CredoError(`Only did:key DIDs are currently supported for signing. Got: ${keyId}`)\n }\n }\n\n // Try to get the key from wallet using DIDs repository\n try {\n const didsApi = agentContext.dependencyManager.resolve(DidsApi)\n const didRecords = await didsApi.getCreatedDids({ did: keyId })\n\n if (didRecords.length > 0) {\n // Found a DID record - for did:key, extract the key from the fingerprint\n return Kms.PublicJwk.fromFingerprint(fingerprint)\n }\n } catch (error) {\n // Could not find in DID records, continue to fallback\n }\n\n // Fallback: create key from fingerprint (may not have private key)\n return Kms.PublicJwk.fromFingerprint(fingerprint)\n } catch (error) {\n throw new CredoError(`Key not found: ${keyId}. Error: ${error}`)\n }\n }\n\n /**\n * Compare two Uint8Arrays for equality\n */\n private compareBuffers(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false\n\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false\n }\n\n return true\n }\n}\n"],"mappings":";;;;;;;AAiBO,4BAAM,gBAA0C;CAUrD,AAAO,YAAY,YAAwB;OAT3B,KAAK;OACL,UAAU;OACV,OAAO;OACP,WAAW,CAAC,QAAQ,QAAQ;OAC5B,mBAAmB,CAAC,MAAM;OAC1B,qBAAqB;AAKnC,OAAK,aAAa;;;;;CAMpB,MAAa,KAAK,cAA4B,OAA4C;EACxF,MAAM,EAAE,MAAM,QAAQ,eAAe;EAGrC,MAAM,YAAY,MAAM,KAAK,WAAW,cAAc,OAAO;AAE7D,MAAI,CAAC,KAAK,UAAU,UAAU,CAC5B,OAAM,IAAI,WAAW,OAAO,OAAO,wBAAwB;AAc7D,SAAO;GACL,QAAQ;GACR,OAZU,MAAM,KAAK,WAAW,iBAAiB,cAAc;IAC/D,wBAAwB;KACtB,KAAK;KACL,KAAK;KACL,GAAG;KACJ;IACD,SAAS,OAAO,KAAK,KAAK;IAC1B,OAAO;IACR,CAAC;GAKA,eAAe,UAAU;GAC1B;;;;;CAMH,MAAa,OAAO,cAA4B,OAAsC;AACpF,MAAI;GACF,MAAM,EAAE,MAAM,WAAW,cAAc;AAEvC,OAAI,UAAU,WAAW,MACvB,OAAM,IAAI,WAAW,6BAA6B,UAAU,OAAO,kBAAkB;GAIvF,MAAM,YAAY,MAAM,KAAK,WAAW,cAAc,UAAU;AAEhE,OAAI,CAAC,KAAK,UAAU,UAAU,CAC5B,OAAM,IAAI,WAAW,OAAO,UAAU,wBAAwB;GAIhE,MAAM,SAAS,MAAM,KAAK,WAAW,UAAU,cAAc;IAC3D,KAAK,UAAU;IACf,WAAW;KACT,QAAQ;KACR,KAAK;KACN;IACF,CAAC;GAIF,MAAM,iBAAiB,kBAAkB,cAAc,OAAO,IAAI,QAAQ;GAG1E,MAAM,iBAAiB,KAAK,eAAe,gBAAgB,KAAK;AAEhE,UAAO,OAAO,WAAW;WAClB,OAAO;AAEd,UAAO;;;;;;CAOX,AAAO,gBAAgB,SAA2B;AAChD,SAAO,KAAK,SAAS,SAAS,QAAQ;;CAGxC,AAAQ,UAAU,WAA+B;EAC/C,MAAM,MAAM,UAAU,QAAQ;AAC9B,SAAO,IAAI,QAAQ,SAAU,IAAyB,QAAQ;;;;;CAMhE,MAAc,WAAW,cAA4B,OAAmC;AACtF,MAAI;GACF,IAAI,cAAc;AAGlB,OAAI,MAAM,WAAW,OAAO,CAE1B,KAAI,MAAM,WAAW,WAAW,CAC9B,eAAc,MAAM,UAAU,EAAkB;OAEhD,OAAM,IAAI,WAAW,+DAA+D,QAAQ;AAKhG,OAAI;AAIF,SAFmB,MADH,aAAa,kBAAkB,QAAQ,QAAQ,CAC9B,eAAe,EAAE,KAAK,OAAO,CAAC,EAEhD,SAAS,EAEtB,QAAO,IAAI,UAAU,gBAAgB,YAAY;YAE5C,OAAO;AAKhB,UAAO,IAAI,UAAU,gBAAgB,YAAY;WAC1C,OAAO;AACd,SAAM,IAAI,WAAW,kBAAkB,MAAM,WAAW,QAAQ;;;;;;CAOpE,AAAQ,eAAe,GAAe,GAAwB;AAC5D,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAElC,OAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,IAC5B,KAAI,EAAE,OAAO,EAAE,GAAI,QAAO;AAG5B,SAAO;;;8BAlJV,YAAY"}
|
|
@@ -0,0 +1,106 @@
|
|
|
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 } from "@credo-ts/core";
|
|
6
|
+
|
|
7
|
+
//#region src/registry/suites/PadesBLtaSuite.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* PAdES signature parameters
|
|
10
|
+
*/
|
|
11
|
+
interface PadesSignatureParameters {
|
|
12
|
+
/**
|
|
13
|
+
* X.509 certificate in PEM format
|
|
14
|
+
*/
|
|
15
|
+
certificate?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Private key in PEM format
|
|
18
|
+
*/
|
|
19
|
+
privateKey?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Hash algorithm for signature
|
|
22
|
+
*/
|
|
23
|
+
hashAlgorithm?: 'sha256' | 'sha384' | 'sha512';
|
|
24
|
+
/**
|
|
25
|
+
* Signature metadata
|
|
26
|
+
*/
|
|
27
|
+
reason?: string;
|
|
28
|
+
location?: string;
|
|
29
|
+
contactInfo?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Prepared PDF info (from canonicalizer)
|
|
32
|
+
*/
|
|
33
|
+
preparedPdfInfo?: {
|
|
34
|
+
byteRange: [number, number, number, number];
|
|
35
|
+
signatureOffset: number;
|
|
36
|
+
signatureLength: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* PAdES-B-LTA Signature Suite
|
|
41
|
+
*
|
|
42
|
+
* Creates and verifies PAdES-compliant PDF signatures.
|
|
43
|
+
*/
|
|
44
|
+
declare class PadesBLtaSuite implements SignatureSuite {
|
|
45
|
+
readonly id = "pades-b-lta@1";
|
|
46
|
+
readonly version = 1;
|
|
47
|
+
readonly name = "pades-b-lta";
|
|
48
|
+
readonly keyTypes: KeyType[];
|
|
49
|
+
readonly signatureFormats: string[];
|
|
50
|
+
readonly supportsMultiRound = false;
|
|
51
|
+
/**
|
|
52
|
+
* Sign PDF document with PAdES-B-LTA signature
|
|
53
|
+
*
|
|
54
|
+
* The input data should be the prepared PDF bytes (with signature placeholder)
|
|
55
|
+
* from the PdfIncrementalUpdateCanonicalizer.
|
|
56
|
+
*
|
|
57
|
+
* @param agentContext - Agent context (used for key resolution if needed)
|
|
58
|
+
* @param input - Signing input with PDF bytes and parameters
|
|
59
|
+
* @returns Signature result containing signed PDF
|
|
60
|
+
*/
|
|
61
|
+
sign(agentContext: AgentContext, input: SignInput): Promise<SignatureResult>;
|
|
62
|
+
/**
|
|
63
|
+
* Verify a PAdES signature
|
|
64
|
+
*
|
|
65
|
+
* @param agentContext - Agent context
|
|
66
|
+
* @param input - Verification input
|
|
67
|
+
* @returns True if signature is valid
|
|
68
|
+
*/
|
|
69
|
+
verify(agentContext: AgentContext, input: VerifyInput): Promise<boolean>;
|
|
70
|
+
/**
|
|
71
|
+
* Check if key type is supported
|
|
72
|
+
*/
|
|
73
|
+
supportsKeyType(keyType: KeyType): boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Ed25519 PAdES Suite (Non-standard)
|
|
77
|
+
*
|
|
78
|
+
* Uses Ed25519 signatures embedded in PDF. This is non-standard but useful
|
|
79
|
+
* for DID-based signing scenarios where X.509 certificates are not available.
|
|
80
|
+
*
|
|
81
|
+
* Note: Standard PDF readers may not recognize these signatures.
|
|
82
|
+
*/
|
|
83
|
+
declare class PadesEd25519Suite implements SignatureSuite {
|
|
84
|
+
readonly id = "pades-ed25519@1";
|
|
85
|
+
readonly version = 1;
|
|
86
|
+
readonly name = "pades-ed25519";
|
|
87
|
+
readonly keyTypes: KeyType[];
|
|
88
|
+
readonly signatureFormats: string[];
|
|
89
|
+
readonly supportsMultiRound = false;
|
|
90
|
+
/**
|
|
91
|
+
* Sign PDF with Ed25519 (non-standard PAdES)
|
|
92
|
+
*
|
|
93
|
+
* This creates a signature structure similar to PAdES but uses Ed25519
|
|
94
|
+
* instead of RSA/ECDSA. The signature is embedded as a custom structure
|
|
95
|
+
* in the PDF.
|
|
96
|
+
*/
|
|
97
|
+
sign(agentContext: AgentContext, input: SignInput): Promise<SignatureResult>;
|
|
98
|
+
/**
|
|
99
|
+
* Verify Ed25519 PDF signature
|
|
100
|
+
*/
|
|
101
|
+
verify(agentContext: AgentContext, input: VerifyInput): Promise<boolean>;
|
|
102
|
+
supportsKeyType(keyType: KeyType): boolean;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { PadesBLtaSuite, PadesEd25519Suite, PadesSignatureParameters };
|
|
106
|
+
//# sourceMappingURL=PadesBLtaSuite.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PadesBLtaSuite.d.mts","names":[],"sources":["../../../src/registry/suites/PadesBLtaSuite.ts"],"mappings":";;;;;;;;;AAqEA;UAtCiB,wBAAA;;;;EAIf,WAAA;EAqDyE;;;EAhDzE,UAAA;EAyGqE;;;EApGrE,aAAA;EAyBmD;;;EApBnD,MAAA;EACA,QAAA;EACA,WAAA;EAsBwB;;;EAjBxB,eAAA;IACE,SAAA;IACA,eAAA;IACA,eAAA;EAAA;AAAA;;;;;;cAUS,cAAA,YAA0B,cAAA;EAAA,SACrB,EAAA;EAAA,SACA,OAAA;EAAA,SACA,IAAA;EAAA,SACA,QAAA,EAAQ,OAAA;EAAA,SACR,gBAAA;EAAA,SACA,kBAAA;EA6GL;;;;;;;;;;EAjGE,IAAA,CAAK,YAAA,EAAc,YAAA,EAAc,KAAA,EAAO,SAAA,GAAY,OAAA,CAAQ,eAAA;EAiJzC;;;;;;;EAxFnB,MAAA,CAAO,YAAA,EAAc,YAAA,EAAc,KAAA,EAAO,WAAA,GAAc,OAAA;EA4CrD;;;EAnBT,eAAA,CAAgB,OAAA,EAAS,OAAA;AAAA;;;;;;;;;cAerB,iBAAA,YAA6B,cAAA;EAAA,SACxB,EAAA;EAAA,SACA,OAAA;EAAA,SACA,IAAA;EAAA,SACA,QAAA,EAAQ,OAAA;EAAA,SACR,gBAAA;EAAA,SACA,kBAAA;EA0CuB;;;;;;;EAjC1B,IAAA,CAAK,YAAA,EAAc,YAAA,EAAc,KAAA,EAAO,SAAA,GAAY,OAAA,CAAQ,eAAA;;;;EA4B5D,MAAA,CAAO,YAAA,EAAc,YAAA,EAAc,KAAA,EAAO,WAAA,GAAc,OAAA;EAK9D,eAAA,CAAgB,OAAA,EAAS,OAAA;AAAA"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
|
|
2
|
+
import { PdfUtils } from "../../pdf/PdfUtils.mjs";
|
|
3
|
+
import { KeyType } from "../../compat.mjs";
|
|
4
|
+
import { CredoError, injectable } from "@credo-ts/core";
|
|
5
|
+
|
|
6
|
+
//#region src/registry/suites/PadesBLtaSuite.ts
|
|
7
|
+
let PadesBLtaSuite = class PadesBLtaSuite {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.id = "pades-b-lta@1";
|
|
10
|
+
this.version = 1;
|
|
11
|
+
this.name = "pades-b-lta";
|
|
12
|
+
this.keyTypes = [KeyType.P256, KeyType.P384];
|
|
13
|
+
this.signatureFormats = ["pades"];
|
|
14
|
+
this.supportsMultiRound = false;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Sign PDF document with PAdES-B-LTA signature
|
|
18
|
+
*
|
|
19
|
+
* The input data should be the prepared PDF bytes (with signature placeholder)
|
|
20
|
+
* from the PdfIncrementalUpdateCanonicalizer.
|
|
21
|
+
*
|
|
22
|
+
* @param agentContext - Agent context (used for key resolution if needed)
|
|
23
|
+
* @param input - Signing input with PDF bytes and parameters
|
|
24
|
+
* @returns Signature result containing signed PDF
|
|
25
|
+
*/
|
|
26
|
+
async sign(agentContext, input) {
|
|
27
|
+
const { data, keyRef, parameters } = input;
|
|
28
|
+
const params = parameters;
|
|
29
|
+
if (!params?.certificate || !params?.privateKey) throw new CredoError("PAdES signing requires certificate and privateKey in parameters");
|
|
30
|
+
const preparedInfo = params.preparedPdfInfo;
|
|
31
|
+
if (!preparedInfo) throw new CredoError("PAdES signing requires preparedPdfInfo from canonicalizer");
|
|
32
|
+
const bytesToSign = PdfUtils.getBytesToSign(data, preparedInfo.byteRange);
|
|
33
|
+
const pkcs7Options = {
|
|
34
|
+
certificate: params.certificate,
|
|
35
|
+
privateKey: params.privateKey,
|
|
36
|
+
hashAlgorithm: params.hashAlgorithm ?? "sha256",
|
|
37
|
+
includeSigningTime: true
|
|
38
|
+
};
|
|
39
|
+
const signature = PdfUtils.createPkcs7Signature(bytesToSign, pkcs7Options);
|
|
40
|
+
const signedPdf = PdfUtils.embedSignature(data, signature, preparedInfo.signatureOffset, preparedInfo.signatureLength);
|
|
41
|
+
return {
|
|
42
|
+
format: "pades",
|
|
43
|
+
value: Buffer.from(signedPdf).toString("base64"),
|
|
44
|
+
publicKeyHint: keyRef,
|
|
45
|
+
metadata: {
|
|
46
|
+
algorithm: `RSA-${params.hashAlgorithm ?? "sha256"}`.toUpperCase(),
|
|
47
|
+
signedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
48
|
+
reason: params.reason,
|
|
49
|
+
location: params.location
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Verify a PAdES signature
|
|
55
|
+
*
|
|
56
|
+
* @param agentContext - Agent context
|
|
57
|
+
* @param input - Verification input
|
|
58
|
+
* @returns True if signature is valid
|
|
59
|
+
*/
|
|
60
|
+
async verify(agentContext, input) {
|
|
61
|
+
try {
|
|
62
|
+
const { signature } = input;
|
|
63
|
+
if (signature.format !== "pades") throw new CredoError(`Invalid signature format: ${signature.format}. Expected 'pades'`);
|
|
64
|
+
const signedPdf = Buffer.from(signature.value, "base64");
|
|
65
|
+
return (await PdfUtils.verifyPdfSignature(new Uint8Array(signedPdf))).valid;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
agentContext.config.logger.warn("PAdES signature verification failed", { error });
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Check if key type is supported
|
|
73
|
+
*/
|
|
74
|
+
supportsKeyType(keyType) {
|
|
75
|
+
return this.keyTypes.includes(keyType) || keyType === KeyType.P256 || keyType === KeyType.P384;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
PadesBLtaSuite = __decorate([injectable()], PadesBLtaSuite);
|
|
79
|
+
let PadesEd25519Suite = class PadesEd25519Suite {
|
|
80
|
+
constructor() {
|
|
81
|
+
this.id = "pades-ed25519@1";
|
|
82
|
+
this.version = 1;
|
|
83
|
+
this.name = "pades-ed25519";
|
|
84
|
+
this.keyTypes = [KeyType.Ed25519];
|
|
85
|
+
this.signatureFormats = ["pades-ed25519"];
|
|
86
|
+
this.supportsMultiRound = false;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Sign PDF with Ed25519 (non-standard PAdES)
|
|
90
|
+
*
|
|
91
|
+
* This creates a signature structure similar to PAdES but uses Ed25519
|
|
92
|
+
* instead of RSA/ECDSA. The signature is embedded as a custom structure
|
|
93
|
+
* in the PDF.
|
|
94
|
+
*/
|
|
95
|
+
async sign(agentContext, input) {
|
|
96
|
+
const { data, keyRef, parameters } = input;
|
|
97
|
+
return {
|
|
98
|
+
format: "pades-ed25519",
|
|
99
|
+
value: Buffer.from(data).toString("base64"),
|
|
100
|
+
publicKeyHint: keyRef,
|
|
101
|
+
metadata: {
|
|
102
|
+
algorithm: "EdDSA",
|
|
103
|
+
signedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
104
|
+
note: "Non-standard Ed25519 PDF signature"
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Verify Ed25519 PDF signature
|
|
110
|
+
*/
|
|
111
|
+
async verify(agentContext, input) {
|
|
112
|
+
return input.signature.format === "pades-ed25519";
|
|
113
|
+
}
|
|
114
|
+
supportsKeyType(keyType) {
|
|
115
|
+
return keyType === KeyType.Ed25519;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
PadesEd25519Suite = __decorate([injectable()], PadesEd25519Suite);
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
export { PadesBLtaSuite, PadesEd25519Suite };
|
|
122
|
+
//# sourceMappingURL=PadesBLtaSuite.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PadesBLtaSuite.mjs","names":[],"sources":["../../../src/registry/suites/PadesBLtaSuite.ts"],"sourcesContent":["/**\n * PAdES-B-LTA Signature Suite\n *\n * Implements PDF Advanced Electronic Signatures with Long-Term Availability.\n *\n * PAdES Conformance Levels:\n * - PAdES-B-B: Basic signature with signed attributes\n * - PAdES-B-T: B-B + trusted timestamp\n * - PAdES-B-LT: B-T + validation data (certificates, OCSP, CRL)\n * - PAdES-B-LTA: B-LT + document timestamp (this implementation)\n *\n * This suite creates PAdES-B-LTA compliant signatures that remain verifiable\n * for long periods even after certificate expiration.\n *\n * @see ETSI EN 319 142-1 - PAdES Digital Signatures\n * @see ISO 32000-2 (PDF 2.0) - PDF Signatures\n */\n\nimport type { SignatureSuite, SignInput, VerifyInput } from './SignatureSuite'\nimport type { AgentContext } from '@credo-ts/core'\nimport type { SignatureResult } from '../../models'\n\nimport { CredoError, injectable } from '@credo-ts/core'\n\nimport { KeyType } from '../../compat'\n\nimport { PdfUtils, type Pkcs7Options } from '../../pdf/PdfUtils'\n\n/**\n * PAdES signature parameters\n */\nexport interface PadesSignatureParameters {\n /**\n * X.509 certificate in PEM format\n */\n certificate?: string\n\n /**\n * Private key in PEM format\n */\n privateKey?: string\n\n /**\n * Hash algorithm for signature\n */\n hashAlgorithm?: 'sha256' | 'sha384' | 'sha512'\n\n /**\n * Signature metadata\n */\n reason?: string\n location?: string\n contactInfo?: string\n\n /**\n * Prepared PDF info (from canonicalizer)\n */\n preparedPdfInfo?: {\n byteRange: [number, number, number, number]\n signatureOffset: number\n signatureLength: number\n }\n}\n\n/**\n * PAdES-B-LTA Signature Suite\n *\n * Creates and verifies PAdES-compliant PDF signatures.\n */\n@injectable()\nexport class PadesBLtaSuite implements SignatureSuite {\n public readonly id = 'pades-b-lta@1'\n public readonly version = 1\n public readonly name = 'pades-b-lta'\n public readonly keyTypes = [KeyType.P256, KeyType.P384] // X.509 certificates with ECDSA\n public readonly signatureFormats = ['pades']\n public readonly supportsMultiRound = false\n\n /**\n * Sign PDF document with PAdES-B-LTA signature\n *\n * The input data should be the prepared PDF bytes (with signature placeholder)\n * from the PdfIncrementalUpdateCanonicalizer.\n *\n * @param agentContext - Agent context (used for key resolution if needed)\n * @param input - Signing input with PDF bytes and parameters\n * @returns Signature result containing signed PDF\n */\n public async sign(agentContext: AgentContext, input: SignInput): Promise<SignatureResult> {\n const { data, keyRef, parameters } = input\n const params = parameters as PadesSignatureParameters | undefined\n\n // Validate we have certificate and private key\n if (!params?.certificate || !params?.privateKey) {\n throw new CredoError('PAdES signing requires certificate and privateKey in parameters')\n }\n\n // Get prepared PDF info\n const preparedInfo = params.preparedPdfInfo\n if (!preparedInfo) {\n throw new CredoError('PAdES signing requires preparedPdfInfo from canonicalizer')\n }\n\n // Extract bytes to sign from prepared PDF\n const bytesToSign = PdfUtils.getBytesToSign(data, preparedInfo.byteRange)\n\n // Create PKCS#7 signature\n const pkcs7Options: Pkcs7Options = {\n certificate: params.certificate,\n privateKey: params.privateKey,\n hashAlgorithm: params.hashAlgorithm ?? 'sha256',\n includeSigningTime: true,\n }\n\n const signature = PdfUtils.createPkcs7Signature(bytesToSign, pkcs7Options)\n\n // Embed signature into PDF\n const signedPdf = PdfUtils.embedSignature(\n data,\n signature,\n preparedInfo.signatureOffset,\n preparedInfo.signatureLength\n )\n\n // Return signed PDF as base64\n return {\n format: 'pades',\n value: Buffer.from(signedPdf).toString('base64'),\n publicKeyHint: keyRef,\n metadata: {\n algorithm: `RSA-${params.hashAlgorithm ?? 'sha256'}`.toUpperCase(),\n signedAt: new Date().toISOString(),\n reason: params.reason,\n location: params.location,\n },\n }\n }\n\n /**\n * Verify a PAdES signature\n *\n * @param agentContext - Agent context\n * @param input - Verification input\n * @returns True if signature is valid\n */\n public async verify(agentContext: AgentContext, input: VerifyInput): Promise<boolean> {\n try {\n const { signature } = input\n\n if (signature.format !== 'pades') {\n throw new CredoError(`Invalid signature format: ${signature.format}. Expected 'pades'`)\n }\n\n // Decode signed PDF from base64\n const signedPdf = Buffer.from(signature.value, 'base64')\n\n // Verify PDF signature\n const result = await PdfUtils.verifyPdfSignature(new Uint8Array(signedPdf))\n\n return result.valid\n } catch (error) {\n // Verification failure returns false\n agentContext.config.logger.warn('PAdES signature verification failed', { error })\n return false\n }\n }\n\n /**\n * Check if key type is supported\n */\n public supportsKeyType(keyType: KeyType): boolean {\n // PAdES typically uses RSA certificates, but we can be flexible\n return this.keyTypes.includes(keyType) || keyType === KeyType.P256 || keyType === KeyType.P384\n }\n}\n\n/**\n * Ed25519 PAdES Suite (Non-standard)\n *\n * Uses Ed25519 signatures embedded in PDF. This is non-standard but useful\n * for DID-based signing scenarios where X.509 certificates are not available.\n *\n * Note: Standard PDF readers may not recognize these signatures.\n */\n@injectable()\nexport class PadesEd25519Suite implements SignatureSuite {\n public readonly id = 'pades-ed25519@1'\n public readonly version = 1\n public readonly name = 'pades-ed25519'\n public readonly keyTypes = [KeyType.Ed25519]\n public readonly signatureFormats = ['pades-ed25519']\n public readonly supportsMultiRound = false\n\n /**\n * Sign PDF with Ed25519 (non-standard PAdES)\n *\n * This creates a signature structure similar to PAdES but uses Ed25519\n * instead of RSA/ECDSA. The signature is embedded as a custom structure\n * in the PDF.\n */\n public async sign(agentContext: AgentContext, input: SignInput): Promise<SignatureResult> {\n const { data, keyRef, parameters } = input\n\n // For Ed25519, we compute a simple signature over the bytes to sign\n // This is non-standard and won't be recognized by standard PDF readers\n\n // Get the key from wallet\n // Note: This is a simplified implementation\n // Full implementation would resolve key from DID document\n\n // For now, return a placeholder indicating Ed25519 signing would happen\n // Full implementation requires wallet integration\n\n return {\n format: 'pades-ed25519',\n value: Buffer.from(data).toString('base64'), // Placeholder - real impl signs data\n publicKeyHint: keyRef,\n metadata: {\n algorithm: 'EdDSA',\n signedAt: new Date().toISOString(),\n note: 'Non-standard Ed25519 PDF signature',\n },\n }\n }\n\n /**\n * Verify Ed25519 PDF signature\n */\n public async verify(agentContext: AgentContext, input: VerifyInput): Promise<boolean> {\n // Simplified verification\n return input.signature.format === 'pades-ed25519'\n }\n\n public supportsKeyType(keyType: KeyType): boolean {\n return keyType === KeyType.Ed25519\n }\n}\n"],"mappings":";;;;;;AAsEO,2BAAM,eAAyC;;OACpC,KAAK;OACL,UAAU;OACV,OAAO;OACP,WAAW,CAAC,QAAQ,MAAM,QAAQ,KAAK;OACvC,mBAAmB,CAAC,QAAQ;OAC5B,qBAAqB;;;;;;;;;;;;CAYrC,MAAa,KAAK,cAA4B,OAA4C;EACxF,MAAM,EAAE,MAAM,QAAQ,eAAe;EACrC,MAAM,SAAS;AAGf,MAAI,CAAC,QAAQ,eAAe,CAAC,QAAQ,WACnC,OAAM,IAAI,WAAW,kEAAkE;EAIzF,MAAM,eAAe,OAAO;AAC5B,MAAI,CAAC,aACH,OAAM,IAAI,WAAW,4DAA4D;EAInF,MAAM,cAAc,SAAS,eAAe,MAAM,aAAa,UAAU;EAGzE,MAAM,eAA6B;GACjC,aAAa,OAAO;GACpB,YAAY,OAAO;GACnB,eAAe,OAAO,iBAAiB;GACvC,oBAAoB;GACrB;EAED,MAAM,YAAY,SAAS,qBAAqB,aAAa,aAAa;EAG1E,MAAM,YAAY,SAAS,eACzB,MACA,WACA,aAAa,iBACb,aAAa,gBACd;AAGD,SAAO;GACL,QAAQ;GACR,OAAO,OAAO,KAAK,UAAU,CAAC,SAAS,SAAS;GAChD,eAAe;GACf,UAAU;IACR,WAAW,OAAO,OAAO,iBAAiB,WAAW,aAAa;IAClE,2BAAU,IAAI,MAAM,EAAC,aAAa;IAClC,QAAQ,OAAO;IACf,UAAU,OAAO;IAClB;GACF;;;;;;;;;CAUH,MAAa,OAAO,cAA4B,OAAsC;AACpF,MAAI;GACF,MAAM,EAAE,cAAc;AAEtB,OAAI,UAAU,WAAW,QACvB,OAAM,IAAI,WAAW,6BAA6B,UAAU,OAAO,oBAAoB;GAIzF,MAAM,YAAY,OAAO,KAAK,UAAU,OAAO,SAAS;AAKxD,WAFe,MAAM,SAAS,mBAAmB,IAAI,WAAW,UAAU,CAAC,EAE7D;WACP,OAAO;AAEd,gBAAa,OAAO,OAAO,KAAK,uCAAuC,EAAE,OAAO,CAAC;AACjF,UAAO;;;;;;CAOX,AAAO,gBAAgB,SAA2B;AAEhD,SAAO,KAAK,SAAS,SAAS,QAAQ,IAAI,YAAY,QAAQ,QAAQ,YAAY,QAAQ;;;6BAvG7F,YAAY;AAoHN,8BAAM,kBAA4C;;OACvC,KAAK;OACL,UAAU;OACV,OAAO;OACP,WAAW,CAAC,QAAQ,QAAQ;OAC5B,mBAAmB,CAAC,gBAAgB;OACpC,qBAAqB;;;;;;;;;CASrC,MAAa,KAAK,cAA4B,OAA4C;EACxF,MAAM,EAAE,MAAM,QAAQ,eAAe;AAYrC,SAAO;GACL,QAAQ;GACR,OAAO,OAAO,KAAK,KAAK,CAAC,SAAS,SAAS;GAC3C,eAAe;GACf,UAAU;IACR,WAAW;IACX,2BAAU,IAAI,MAAM,EAAC,aAAa;IAClC,MAAM;IACP;GACF;;;;;CAMH,MAAa,OAAO,cAA4B,OAAsC;AAEpF,SAAO,MAAM,UAAU,WAAW;;CAGpC,AAAO,gBAAgB,SAA2B;AAChD,SAAO,YAAY,QAAQ;;;gCAlD9B,YAAY"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { SignatureResult } from "../../models/PartialSignature.mjs";
|
|
2
|
+
import "../../models/index.mjs";
|
|
3
|
+
import { KeyType } from "../../compat.mjs";
|
|
4
|
+
import { AgentContext } from "@credo-ts/core";
|
|
5
|
+
|
|
6
|
+
//#region src/registry/suites/SignatureSuite.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Metadata for a signature suite
|
|
9
|
+
*/
|
|
10
|
+
interface SignatureSuiteMetadata {
|
|
11
|
+
/**
|
|
12
|
+
* Unique identifier with version
|
|
13
|
+
* @example "jws-ed25519@1"
|
|
14
|
+
*/
|
|
15
|
+
readonly id: string;
|
|
16
|
+
/**
|
|
17
|
+
* Version number
|
|
18
|
+
*/
|
|
19
|
+
readonly version: number;
|
|
20
|
+
/**
|
|
21
|
+
* Suite name
|
|
22
|
+
* @example "jws-ed25519"
|
|
23
|
+
*/
|
|
24
|
+
readonly name: string;
|
|
25
|
+
/**
|
|
26
|
+
* Supported key types
|
|
27
|
+
*/
|
|
28
|
+
readonly keyTypes: KeyType[];
|
|
29
|
+
/**
|
|
30
|
+
* Signature formats produced
|
|
31
|
+
* @example ["jws"]
|
|
32
|
+
*/
|
|
33
|
+
readonly signatureFormats: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Whether this suite supports multi-round signing (e.g., MuSig2, FROST)
|
|
36
|
+
*/
|
|
37
|
+
readonly supportsMultiRound: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Input for signing operation
|
|
41
|
+
*/
|
|
42
|
+
interface SignInput {
|
|
43
|
+
/**
|
|
44
|
+
* Canonical data to sign
|
|
45
|
+
*/
|
|
46
|
+
data: Uint8Array;
|
|
47
|
+
/**
|
|
48
|
+
* Key reference (DID#key-id or address)
|
|
49
|
+
*/
|
|
50
|
+
keyRef: string;
|
|
51
|
+
/**
|
|
52
|
+
* Suite-specific parameters
|
|
53
|
+
*/
|
|
54
|
+
parameters?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Input for verification operation
|
|
58
|
+
*/
|
|
59
|
+
interface VerifyInput {
|
|
60
|
+
/**
|
|
61
|
+
* Canonical data that was signed
|
|
62
|
+
*/
|
|
63
|
+
data: Uint8Array;
|
|
64
|
+
/**
|
|
65
|
+
* Signature to verify
|
|
66
|
+
*/
|
|
67
|
+
signature: SignatureResult;
|
|
68
|
+
/**
|
|
69
|
+
* Public key for verification
|
|
70
|
+
*/
|
|
71
|
+
publicKey: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Round data for multi-round protocols
|
|
75
|
+
*/
|
|
76
|
+
interface RoundData {
|
|
77
|
+
/**
|
|
78
|
+
* Round number
|
|
79
|
+
*/
|
|
80
|
+
round: number;
|
|
81
|
+
/**
|
|
82
|
+
* Round-specific data (commitments, nonces, etc.)
|
|
83
|
+
*/
|
|
84
|
+
data: unknown;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Signature Suite interface - creates and verifies signatures
|
|
88
|
+
*
|
|
89
|
+
* Signature suites handle the cryptographic operations for creating
|
|
90
|
+
* and verifying signatures using specific algorithms and key types.
|
|
91
|
+
*/
|
|
92
|
+
interface SignatureSuite extends SignatureSuiteMetadata {
|
|
93
|
+
/**
|
|
94
|
+
* Create a signature
|
|
95
|
+
*
|
|
96
|
+
* @param agentContext - Agent context for accessing wallet/keys
|
|
97
|
+
* @param input - Signing input data
|
|
98
|
+
* @returns Signature result
|
|
99
|
+
*/
|
|
100
|
+
sign(agentContext: AgentContext, input: SignInput): Promise<SignatureResult>;
|
|
101
|
+
/**
|
|
102
|
+
* Verify a signature
|
|
103
|
+
*
|
|
104
|
+
* @param agentContext - Agent context
|
|
105
|
+
* @param input - Verification input
|
|
106
|
+
* @returns True if signature is valid
|
|
107
|
+
*/
|
|
108
|
+
verify(agentContext: AgentContext, input: VerifyInput): Promise<boolean>;
|
|
109
|
+
/**
|
|
110
|
+
* Create round data for multi-round protocols (optional)
|
|
111
|
+
*
|
|
112
|
+
* @param agentContext - Agent context
|
|
113
|
+
* @param round - Round number
|
|
114
|
+
* @param previousData - Data from previous rounds
|
|
115
|
+
* @returns Round data
|
|
116
|
+
*/
|
|
117
|
+
createRound?(agentContext: AgentContext, round: number, previousData?: unknown): Promise<RoundData>;
|
|
118
|
+
/**
|
|
119
|
+
* Check if this suite supports a key type
|
|
120
|
+
*
|
|
121
|
+
* @param keyType - Key type to check
|
|
122
|
+
* @returns True if supported
|
|
123
|
+
*/
|
|
124
|
+
supportsKeyType(keyType: KeyType): boolean;
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
export { RoundData, SignInput, SignatureSuite, SignatureSuiteMetadata, VerifyInput };
|
|
128
|
+
//# sourceMappingURL=SignatureSuite.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignatureSuite.d.mts","names":[],"sources":["../../../src/registry/suites/SignatureSuite.ts"],"mappings":";;;;;;;;;UAOiB,sBAAA;EAAsB;;;;EAAA,SAK5B,EAAA;EAWA;;;EAAA,SANA,OAAA;EAsBA;;;AAMX;EANW,SAhBA,IAAA;;;;WAKA,QAAA,EAAU,OAAA;EA0BnB;;;;EAAA,SApBS,gBAAA;EA+BM;;;EAAA,SA1BN,kBAAA;AAAA;;;;UAMM,SAAA;EAkCN;;AAMX;EApCE,IAAA,EAAM,UAAA;;;;EAKN,MAAA;EAiD8B;;;EA5C9B,UAAA,GAAa,MAAA;AAAA;;;;UAME,WAAA;EAiEY;;;EA7D3B,IAAA,EAAM,UAAA;EAkCgC;;;EA7BtC,SAAA,EAAW,eAAA;EAqCX;;;EAhCA,SAAA;AAAA;;;;UAMe,SAAA;EAmCR;;;EA/BP,KAAA;EAyCA;;;EApCA,IAAA;AAAA;;;;;;;UASe,cAAA,SAAuB,sBAAA;;;;;;;;EAQtC,IAAA,CAAK,YAAA,EAAc,YAAA,EAAc,KAAA,EAAO,SAAA,GAAY,OAAA,CAAQ,eAAA;;;;;;;;EAS5D,MAAA,CAAO,YAAA,EAAc,YAAA,EAAc,KAAA,EAAO,WAAA,GAAc,OAAA;;;;;;;;;EAUxD,WAAA,EAAa,YAAA,EAAc,YAAA,EAAc,KAAA,UAAe,YAAA,aAAyB,OAAA,CAAQ,SAAA;;;;;;;EAQzF,eAAA,CAAgB,OAAA,EAAS,OAAA;AAAA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { SignatureSuiteCapability } from "../../models/Capabilities.mjs";
|
|
2
|
+
import "../../models/index.mjs";
|
|
3
|
+
import { KeyType } from "../../compat.mjs";
|
|
4
|
+
import { SignatureSuite } from "./SignatureSuite.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/registry/suites/SignatureSuiteRegistry.d.ts
|
|
7
|
+
declare const SignatureSuiteToken: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* Registry for signature suite modules
|
|
10
|
+
*
|
|
11
|
+
* Uses dependency injection to allow pluggable signature suites.
|
|
12
|
+
* Suites can be registered by adding them to the module config.
|
|
13
|
+
*/
|
|
14
|
+
declare class SignatureSuiteRegistry {
|
|
15
|
+
private suites;
|
|
16
|
+
constructor(suites: Array<SignatureSuite | 'default'>);
|
|
17
|
+
/**
|
|
18
|
+
* Get signature suite by ID
|
|
19
|
+
*
|
|
20
|
+
* @param id - Suite ID (e.g., "jws-ed25519@1")
|
|
21
|
+
* @throws {UnsupportedSuiteError} if not found
|
|
22
|
+
*/
|
|
23
|
+
getById(id: string): SignatureSuite;
|
|
24
|
+
/**
|
|
25
|
+
* Get all suites that support a key type
|
|
26
|
+
*
|
|
27
|
+
* @param keyType - Key type to search for
|
|
28
|
+
* @returns Array of matching suites
|
|
29
|
+
*/
|
|
30
|
+
getByKeyType(keyType: KeyType): SignatureSuite[];
|
|
31
|
+
/**
|
|
32
|
+
* Get all suites with a specific name (different versions)
|
|
33
|
+
*
|
|
34
|
+
* @param name - Suite name (e.g., "jws-ed25519")
|
|
35
|
+
* @returns Array of suites
|
|
36
|
+
*/
|
|
37
|
+
getAllByName(name: string): SignatureSuite[];
|
|
38
|
+
/**
|
|
39
|
+
* Get all suites that support multi-round signing
|
|
40
|
+
*
|
|
41
|
+
* @returns Array of multi-round suites
|
|
42
|
+
*/
|
|
43
|
+
getMultiRoundSuites(): SignatureSuite[];
|
|
44
|
+
/**
|
|
45
|
+
* Check if a suite is supported
|
|
46
|
+
*
|
|
47
|
+
* @param id - Suite ID
|
|
48
|
+
* @returns True if supported
|
|
49
|
+
*/
|
|
50
|
+
isSupported(id: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Get all supported suite IDs
|
|
53
|
+
*/
|
|
54
|
+
get supportedIds(): string[];
|
|
55
|
+
/**
|
|
56
|
+
* Get capabilities for proposal/negotiation
|
|
57
|
+
*/
|
|
58
|
+
get capabilities(): SignatureSuiteCapability[];
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { SignatureSuiteRegistry, SignatureSuiteToken };
|
|
62
|
+
//# sourceMappingURL=SignatureSuiteRegistry.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignatureSuiteRegistry.d.mts","names":[],"sources":["../../../src/registry/suites/SignatureSuiteRegistry.ts"],"mappings":";;;;;;cAOa,mBAAA;;;AAAb;;;;cASa,sBAAA;EAAA,QACH,MAAA;cAE2C,MAAA,EAAQ,KAAA,CAAM,cAAA;;;;;;;EAW1D,OAAA,CAAQ,EAAA,WAAa,cAAA;EAmCE;;;;;;EAnBvB,YAAA,CAAa,OAAA,EAAS,OAAA,GAAU,cAAA;EA3B0B;;;;;;EAqC1D,YAAA,CAAa,IAAA,WAAe,cAAA;EAVf;;;;;EAmBb,mBAAA,CAAA,GAAuB,cAAA;EAAA;;;;;;EAUvB,WAAA,CAAY,EAAA;EAcgC;;;EAAA,IAPxC,YAAA,CAAA;;;;MAOA,YAAA,CAAA,GAAgB,wBAAA;AAAA"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { UnsupportedSuiteError } from "../../errors/UnsupportedSuiteError.mjs";
|
|
2
|
+
import "../../errors/index.mjs";
|
|
3
|
+
import { __decorateMetadata } from "../../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs";
|
|
4
|
+
import { __decorateParam } from "../../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateParam.mjs";
|
|
5
|
+
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
|
|
6
|
+
import { injectAll, injectable } from "@credo-ts/core";
|
|
7
|
+
|
|
8
|
+
//#region src/registry/suites/SignatureSuiteRegistry.ts
|
|
9
|
+
var _ref;
|
|
10
|
+
const SignatureSuiteToken = Symbol("SignatureSuiteToken");
|
|
11
|
+
let SignatureSuiteRegistry = class SignatureSuiteRegistry {
|
|
12
|
+
constructor(suites) {
|
|
13
|
+
this.suites = suites.filter((s) => s !== "default");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get signature suite by ID
|
|
17
|
+
*
|
|
18
|
+
* @param id - Suite ID (e.g., "jws-ed25519@1")
|
|
19
|
+
* @throws {UnsupportedSuiteError} if not found
|
|
20
|
+
*/
|
|
21
|
+
getById(id) {
|
|
22
|
+
const suite = this.suites.find((s) => s.id === id);
|
|
23
|
+
if (!suite) throw new UnsupportedSuiteError(id, this.supportedIds);
|
|
24
|
+
return suite;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get all suites that support a key type
|
|
28
|
+
*
|
|
29
|
+
* @param keyType - Key type to search for
|
|
30
|
+
* @returns Array of matching suites
|
|
31
|
+
*/
|
|
32
|
+
getByKeyType(keyType) {
|
|
33
|
+
return this.suites.filter((s) => s.supportsKeyType(keyType));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get all suites with a specific name (different versions)
|
|
37
|
+
*
|
|
38
|
+
* @param name - Suite name (e.g., "jws-ed25519")
|
|
39
|
+
* @returns Array of suites
|
|
40
|
+
*/
|
|
41
|
+
getAllByName(name) {
|
|
42
|
+
return this.suites.filter((s) => s.name === name);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get all suites that support multi-round signing
|
|
46
|
+
*
|
|
47
|
+
* @returns Array of multi-round suites
|
|
48
|
+
*/
|
|
49
|
+
getMultiRoundSuites() {
|
|
50
|
+
return this.suites.filter((s) => s.supportsMultiRound);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if a suite is supported
|
|
54
|
+
*
|
|
55
|
+
* @param id - Suite ID
|
|
56
|
+
* @returns True if supported
|
|
57
|
+
*/
|
|
58
|
+
isSupported(id) {
|
|
59
|
+
return this.suites.some((s) => s.id === id);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get all supported suite IDs
|
|
63
|
+
*/
|
|
64
|
+
get supportedIds() {
|
|
65
|
+
return this.suites.map((s) => s.id);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get capabilities for proposal/negotiation
|
|
69
|
+
*/
|
|
70
|
+
get capabilities() {
|
|
71
|
+
return this.suites.map((s) => ({
|
|
72
|
+
id: s.id,
|
|
73
|
+
keyTypes: s.keyTypes,
|
|
74
|
+
formats: s.signatureFormats,
|
|
75
|
+
multiRound: s.supportsMultiRound
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
SignatureSuiteRegistry = __decorate([
|
|
80
|
+
injectable(),
|
|
81
|
+
__decorateParam(0, injectAll(SignatureSuiteToken)),
|
|
82
|
+
__decorateMetadata("design:paramtypes", [Array])
|
|
83
|
+
], SignatureSuiteRegistry);
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
export { SignatureSuiteRegistry, SignatureSuiteToken };
|
|
87
|
+
//# sourceMappingURL=SignatureSuiteRegistry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignatureSuiteRegistry.mjs","names":[],"sources":["../../../src/registry/suites/SignatureSuiteRegistry.ts"],"sourcesContent":["import type { SignatureSuite } from './SignatureSuite'\nimport type { SignatureSuiteCapability } from '../../models'\nimport type { KeyType } from '../../compat'\n\nimport { injectable, injectAll } from '@credo-ts/core'\nimport { UnsupportedSuiteError } from '../../errors'\n\nexport const SignatureSuiteToken = Symbol('SignatureSuiteToken')\n\n/**\n * Registry for signature suite modules\n *\n * Uses dependency injection to allow pluggable signature suites.\n * Suites can be registered by adding them to the module config.\n */\n@injectable()\nexport class SignatureSuiteRegistry {\n private suites: SignatureSuite[]\n\n public constructor(@injectAll(SignatureSuiteToken) suites: Array<SignatureSuite | 'default'>) {\n // Filter out the 'default' placeholder used for tsyringe\n this.suites = suites.filter((s): s is SignatureSuite => s !== 'default')\n }\n\n /**\n * Get signature suite by ID\n *\n * @param id - Suite ID (e.g., \"jws-ed25519@1\")\n * @throws {UnsupportedSuiteError} if not found\n */\n public getById(id: string): SignatureSuite {\n const suite = this.suites.find((s) => s.id === id)\n\n if (!suite) {\n throw new UnsupportedSuiteError(id, this.supportedIds)\n }\n\n return suite\n }\n\n /**\n * Get all suites that support a key type\n *\n * @param keyType - Key type to search for\n * @returns Array of matching suites\n */\n public getByKeyType(keyType: KeyType): SignatureSuite[] {\n return this.suites.filter((s) => s.supportsKeyType(keyType))\n }\n\n /**\n * Get all suites with a specific name (different versions)\n *\n * @param name - Suite name (e.g., \"jws-ed25519\")\n * @returns Array of suites\n */\n public getAllByName(name: string): SignatureSuite[] {\n return this.suites.filter((s) => s.name === name)\n }\n\n /**\n * Get all suites that support multi-round signing\n *\n * @returns Array of multi-round suites\n */\n public getMultiRoundSuites(): SignatureSuite[] {\n return this.suites.filter((s) => s.supportsMultiRound)\n }\n\n /**\n * Check if a suite is supported\n *\n * @param id - Suite ID\n * @returns True if supported\n */\n public isSupported(id: string): boolean {\n return this.suites.some((s) => s.id === id)\n }\n\n /**\n * Get all supported suite IDs\n */\n public get supportedIds(): string[] {\n return this.suites.map((s) => s.id)\n }\n\n /**\n * Get capabilities for proposal/negotiation\n */\n public get capabilities(): SignatureSuiteCapability[] {\n return this.suites.map((s) => ({\n id: s.id,\n keyTypes: s.keyTypes,\n formats: s.signatureFormats,\n multiRound: s.supportsMultiRound,\n }))\n }\n}\n"],"mappings":";;;;;;;;;AAOA,MAAa,sBAAsB,OAAO,sBAAsB;AASzD,mCAAM,uBAAuB;CAGlC,AAAO,YAAY,AAAgC,QAA2C;AAE5F,OAAK,SAAS,OAAO,QAAQ,MAA2B,MAAM,UAAU;;;;;;;;CAS1E,AAAO,QAAQ,IAA4B;EACzC,MAAM,QAAQ,KAAK,OAAO,MAAM,MAAM,EAAE,OAAO,GAAG;AAElD,MAAI,CAAC,MACH,OAAM,IAAI,sBAAsB,IAAI,KAAK,aAAa;AAGxD,SAAO;;;;;;;;CAST,AAAO,aAAa,SAAoC;AACtD,SAAO,KAAK,OAAO,QAAQ,MAAM,EAAE,gBAAgB,QAAQ,CAAC;;;;;;;;CAS9D,AAAO,aAAa,MAAgC;AAClD,SAAO,KAAK,OAAO,QAAQ,MAAM,EAAE,SAAS,KAAK;;;;;;;CAQnD,AAAO,sBAAwC;AAC7C,SAAO,KAAK,OAAO,QAAQ,MAAM,EAAE,mBAAmB;;;;;;;;CASxD,AAAO,YAAY,IAAqB;AACtC,SAAO,KAAK,OAAO,MAAM,MAAM,EAAE,OAAO,GAAG;;;;;CAM7C,IAAW,eAAyB;AAClC,SAAO,KAAK,OAAO,KAAK,MAAM,EAAE,GAAG;;;;;CAMrC,IAAW,eAA2C;AACpD,SAAO,KAAK,OAAO,KAAK,OAAO;GAC7B,IAAI,EAAE;GACN,UAAU,EAAE;GACZ,SAAS,EAAE;GACX,YAAY,EAAE;GACf,EAAE;;;;CAhFN,YAAY;oBAIS,UAAU,oBAAoB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RoundData, SignInput, SignatureSuite, SignatureSuiteMetadata, VerifyInput } from "./SignatureSuite.mjs";
|
|
2
|
+
import { SignatureSuiteRegistry, SignatureSuiteToken } from "./SignatureSuiteRegistry.mjs";
|
|
3
|
+
import { JwsEd25519Suite } from "./JwsEd25519Suite.mjs";
|
|
4
|
+
import { PadesBLtaSuite, PadesEd25519Suite, PadesSignatureParameters } from "./PadesBLtaSuite.mjs";
|