feat(nip44): add cross-implementation test vectors and fix ChaCha20 cipher initialization #503
+281
−3
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
NIP-44 implementation lacked test vectors to verify cross-implementation compatibility with nostr-tools (JavaScript) and contained a critical bug where
IvParameterSpecwas incorrectly used for ChaCha20 cipher initialization on Java 21+.Type of change
fix- Bug fix (non-breaking)feat- New feature (non-breaking)test- Adding or updating testsWhat changed?
Cross-Implementation Test Vectors
Added official NIP-44 test vectors from
paulmillr/nip44repository:Conversation Key Tests (
Nip44ConversationKeyTest.java)sec1 = n-2,sec1 = 2,sec1 == pub2(G point)Decryption Compatibility Tests (
Nip44EncryptDecryptTest.java)Critical Bug Fix
Problem:
EncryptedPayloadsusedIvParameterSpecfor ChaCha20, which fails on Java 21:Fix: Use
ChaCha20ParameterSpecas required by JCA:Applied to both encrypt and decrypt paths in
EncryptedPayloads.java.Breaking changes
None. Existing functionality preserved; bug was preventing correct operation on Java 21.
Testing
mvn testmvn verifyReview focus
Verify test vectors match official NIP-44 specification at https://github.com/paulmillr/nip44/blob/main/nip44.vectors.json
Checklist
type(scope): description✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.