Skip to content

Conversation

@tcheeric
Copy link
Owner

Summary

  • Optional accessors
    • Added Optional getters for optional fields and adopted them in serializers/builders.
    • Examples:
      • EventTag: getRecommendedRelayUrlOptional(), getMarkerOptional()
        Files: nostr-java-event/src/main/java/nostr/event/tag/EventTag.java
      • PubKeyTag: getMainRelayUrlOptional(), getPetNameOptional()
        Files: nostr-java-event/src/main/java/nostr/event/tag/PubKeyTag.java
      • PriceTag: getFrequencyOptional()
        Files: nostr-java-event/src/main/java/nostr/event/tag/PriceTag.java
      • AddressTag: getRelayOptional(), getIdentifierTagOptional()
        Files: nostr-java-event/src/main/java/nostr/event/tag/AddressTag.java
      • SubjectTag: getSubjectOptional()
        Files: nostr-java-event/src/main/java/nostr/event/tag/SubjectTag.java
      • ReferenceTag: getMarkerOptional()
        Files: nostr-java-event/src/main/java/nostr/event/tag/ReferenceTag.java
    • Adopted usage:
      • ClassifiedListingEvent.getPrice uses getFrequencyOptional()
        Files: nostr-java-event/src/main/java/nostr/event/impl/ClassifiedListingEvent.java
      • ReferenceTagSerializer, AddressTagSerializer use Optional instead of null checks
        Files: nostr-java-event/src/main/java/nostr/event/json/serializer/ReferenceTagSerializer.java, AddressTagSerializer.java
      • ChannelMessageEvent, ChannelMetadataEvent use Optional for marker/relay filters
        Files: nostr-java-event/src/main/java/nostr/event/impl/ChannelMessageEvent.java, ChannelMetadataEvent.java
  • Unchecked warning reductions
    • Converted tag deserializers to concrete return types (removed unsafe generic casts).
    • Localized @SuppressWarnings("unchecked") to exact cast sites in message codecs and deserializer.
    • Files: nostr-java-event/src/main/java/nostr/event/tag/.java, event/message/.java, event/json/deserializer/TagDeserializer.java
  • JSON serialization consistency
    • Applied @JsonInclude(JsonInclude.Include.NON_NULL) to optional fields (frequency, subject, marker, relay).
    • Introduced @JsonPropertyOrder on tags for stable field ordering.
    • Files: PriceTag.java, SubjectTag.java, ReferenceTag.java, AddressTag.java, HashtagTag.java, UrlTag.java, LabelTag.java, EmojiTag.java, IdentifierTag.java, GeohashTag.java,
      LabelNamespaceTag.java
  • Micro-inlines and small efficiency tweaks
    • Inlined transient locals in tag update methods and builders where clearer.
    • Reused a parsed JSON tree in ReqMessage for filter list extraction.
    • Files: multiple tag classes in nostr-java-event/src/main/java/nostr/event/tag/, event/message/ReqMessage.java
  • Javadoc improvements
    • Normalized first-sentence summaries with NIP references.
    • Added NIP-01 anchors to core API points (NIP01TagFactory, NostrEventDispatcher, NostrRequestDispatcher).
    • Files: tag classes in nostr-java-event/src/main/java/nostr/event/tag/, nostr-java-api/src/main/java/nostr/api/*

Testing

  • Event module:
    • mvn -q -DskipITs -pl nostr-java-event -am test
    • Result: Passed
  • API module (ran earlier during refactor):
    • mvn -q -DskipITs -pl nostr-java-api -am test
    • Result: Passed; expected retry/timeout logs remain from tests

@tcheeric tcheeric changed the base branch from main to develop October 12, 2025 01:09
@chatgpt-codex-connector
Copy link

💡 Codex Review

* <li>Validates the event is kind 4 (encrypted DM)</li>
* <li>Extracts the 'p' tag to identify the recipient</li>
* <li>Determines if the identity is the sender or recipient</li>
* <li>Uses the appropriate keys for ECDH decryption</li>
* <li>Returns the plaintext content</li>
* </ol>
*
* <p><strong>Example (as recipient):</strong>
* <pre>{@code
* Identity myIdentity = new Identity("nsec1...");
* GenericEvent dmEvent = ... // received from relay
*
* String message = NIP04.decrypt(myIdentity, dmEvent);
* System.out.println("Received: " + message);
* }</pre>
*
* <p><strong>Example (as sender, reading your own DM):</strong>
* <pre>{@code
* Identity myIdentity = new Identity("nsec1...");
* GenericEvent myDmEvent = ... // a DM I sent
*
* String message = NIP04.decrypt(myIdentity, myDmEvent);
* System.out.println("I sent: " + message);

P1 Badge Decrypting DMs fails when p tag is a GenericTag

The new implementation of decrypt(Identity, GenericEvent) fetches the recipient tag via Filterable.getTypeSpecificTags(PubKeyTag.class, event). That helper only returns tags already instantiated as PubKeyTag. Prior to this commit the method iterated all tags and converted a GenericTag to PubKeyTag via PubKeyTag.updateFields, so it worked even when the tag list contained plain GenericTag instances (e.g., events constructed or deserialized without the registry). With the current change, any encrypted DM whose p tag is represented as a GenericTag will now throw NoSuchElementException("No matching p-tag found.") even though the tag is present. This breaks backwards compatibility for callers that build tags generically and previously could decrypt messages. Consider falling back to generic tags before failing.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

@tcheeric
Copy link
Owner Author

@codex address the comment

@tcheeric tcheeric requested a review from Copilot October 12, 2025 01:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refines code quality across multiple areas: Optional accessors for nullable tag fields, serializer cleanup eliminating @SuppressWarnings("unchecked") where possible, JSON serialization consistency with @JsonInclude and @JsonPropertyOrder, import reordering to follow static-last convention, Javadoc improvements with NIP references, and small efficiency tweaks inlining transient locals. Additionally, it removes deprecated code (legacy relay loader) and adds missing unit tests (PointTest, AddressableEventTest, etc.).

Reviewed Changes

Copilot reviewed 300 out of 362 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Event tag classes (EventTag, PubKeyTag, ReferenceTag, etc.) Added Optional accessors; adopted @JsonInclude/@JsonPropertyOrder; removed unchecked casts; updated Javadoc
Message codecs (ReqMessage, OkMessage, etc.) Localized @SuppressWarnings("unchecked") to exact cast sites; reordered imports
Serializers (ReferenceTagSerializer, AddressTagSerializer) Replaced null checks with Optional-based patterns
Event implementations (ChannelMessageEvent, ChannelMetadataEvent, ClassifiedListingEvent) Adopted Optional accessors for filtering/building
Test files (unit and integration) Reordered imports; added new test classes for AddressableEvent, EphemeralEvent, ClassifiedListingEvent, Point, RelayUri
Config & API support files Removed deprecated legacyRelays() method; updated Javadoc with NIP-01 anchors; reordered imports
POMs Version bumped to 1.0.1-SNAPSHOT

@chatgpt-codex-connector
Copy link

Summary

Testing

  • ⚠️ mvn -q verify (fails: missing xyz.tcheeric:nostr-java-bom:pom:1.1.1)

View task →

@tcheeric tcheeric merged commit b85dd49 into develop Oct 12, 2025
1 check passed
@tcheeric tcheeric deleted the chore/bump-version-1.0.1-SNAPSHOT branch October 12, 2025 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants