feat: JCS canonicalization + post-quantum dual-signature (Ed25519 + ML-DSA-65)#7
Open
HaraldeRoessler wants to merge 1 commit intoMoltyCel:mainfrom
Open
Conversation
…L-DSA-65) Two related changes combined to avoid merge conflicts: 1. RFC 8785 JCS canonicalization for VC signing Replace json.dumps(sort_keys=True) with jcs.canonicalize() for deterministic serialization. Verification supports both JCS (new) and sort_keys (legacy) via canonicalizationAlgorithm field in proof. 2. Post-quantum dual-signature with ML-DSA-65 (Dilithium3) Every credential is signed with both Ed25519 and ML-DSA-65 when Dilithium keys are configured. Falls back to Ed25519-only if not. New files: - app/crypto/dilithium.py: ML-DSA-65 key management, sign, verify - app/crypto/hybrid.py: dual_sign() and verify_proof() - scripts/generate_dilithium_keys.py: keypair generation utility Modified files: - app/credentials.py: uses dual_sign(), verify_proof() handles all formats - app/swarm/endorsement.py: endorsement VCs use dual_sign() - app/main.py: DID document dynamically includes Dilithium key, proof list handling for DB inserts Tested locally with docker-compose: - Ed25519-only mode (no Dilithium keys): works, backward compatible - Dual-signature mode: Ed25519 (64B) + Dilithium (3,309B) both verified - DID document shows both keys when Dilithium configured - Legacy single-proof credentials still verify correctly Migration path: Phase 1 (this PR): dual-signature, Ed25519 + ML-DSA-65 Phase 2 (future): ML-DSA-65 first, Ed25519 deprecated Phase 3 (future): Ed25519 sunset Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Apr 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two tightly related changes combined into one PR to avoid merge conflicts:
1. RFC 8785 JCS canonicalization — replaces
json.dumps(sort_keys=True)with properjcs.canonicalize()for deterministic VC serialization2. Post-quantum dual-signature — every credential signed with both Ed25519 (64 bytes) and ML-DSA-65/Dilithium3 (3,309 bytes) when configured
Zero-risk deployment
If
DILITHIUM_PRIVATE_KEY_HEXis not set, the system behaves exactly as before (Ed25519-only). Enable PQC by generating keys:Credential format
Without Dilithium (backward compatible):
{"proof": {"type": "Ed25519Signature2020", "canonicalizationAlgorithm": "JCS", ...}}With Dilithium (dual-signature):
{"proof": [ {"type": "Ed25519Signature2020", "verificationMethod": "...#key-ed25519", ...}, {"type": "DilithiumSignature2026", "verificationMethod": "...#key-dilithium", ...} ]}New files
app/crypto/dilithium.pyapp/crypto/hybrid.pydual_sign()andverify_proof()for all proof formatsscripts/generate_dilithium_keys.pyModified files
app/credentials.pydual_sign(),verify_proof()handles legacy + dual + future formatsapp/swarm/endorsement.pydual_sign()app/main.pyLocally tested
Ed25519: valid,Dilithium: valid)#key-ed25519,#key-1legacy,#key-dilithium)Supersedes PRs #5 and #6
Replaces #5 (JCS only) and #6 (PQC only) which would have caused merge conflicts.
Merge order
This PR is independent but recommended to merge after #1 (which adds
jcsto requirements.txt).Generated with Claude Code