Skip to content

Feat/oversized payloads#35

Merged
ContextVM-org merged 13 commits intomasterfrom
feat/oversized-payloads
Apr 4, 2026
Merged

Feat/oversized payloads#35
ContextVM-org merged 13 commits intomasterfrom
feat/oversized-payloads

Conversation

@ContextVM-org
Copy link
Copy Markdown
Contributor

No description provided.

kushagra0902 and others added 6 commits April 2, 2026 07:42
Add @noble/hashes dependency for SHA256 digest operations in oversized transfers.
Refactor oversized transfer logic into a dedicated sender-session module for better
separation of concerns. Add hasSingleTag and hasEventTag utilities to utils.ts.
Update session store to track client oversized transfer support. Add E2E tests for
oversized request/response transfers and unit tests for the sender session.
- Use nullish coalescing operator instead of non-null assertion in receiver
- Replace void with undefined for explicit return types in sender session
@ContextVM-org ContextVM-org force-pushed the feat/oversized-payloads branch from eaba5ea to 9d0da30 Compare April 2, 2026 12:14
…hunk handling

Add sequence validation to enforce proper ordering of transfer frames (start, accept, chunks, end), including:
- Progress value validation for all frame types
- Accept frame must advance past start progress
- First chunk cannot skip beyond reserved accept slot
- End frame must advance past all prior frames
- Detect and reject conflicting duplicate chunks

Add out-of-order chunk buffering with configurable limits:
- maxOutOfOrderWindow: maximum forward gap allowed
- maxOutOfOrderChunks: maximum buffered out-of-order chunks
- maxConcurrentTransfers: limit active parallel transfers

Add OversizedTransferSequenceError for sequencing violations and new test coverage.
…plitting

Refactors the oversized transfer sender to correctly split UTF-8 strings by byte size without breaking multibyte characters. Adds utf8ByteLength and sha256Digest helper functions, adds validation for chunkSizeBytes parameter, and improves error handling for characters exceeding chunk size. Also adds acceptTimeoutMs option to NostrClientTransport for configuring handshake timeout. Includes test coverage for UTF-8 multibyte character handling.
This prerelease documents the new oversized payload transfer protocol for the Nostr transport layer, including sender/receiver flows, sequencing, out-of-order chunk handling, and UTF-8-safe chunk splitting.
@1amKhush
Copy link
Copy Markdown
Contributor

1amKhush commented Apr 2, 2026

@ContextVM-org I re-reviewed this PR against the CEP-22 oversized payload constraints. The recent commit fixed the earlier sequencing and UTF-8 splitting gaps. I think there are some issues still remaining (have listed them below, also i have tried to keep in mind the constraints for the implementation)

  • Preserve support_oversized_transfer advertisement when custom announcement tags are set.
    Corresponding Gap: setAnnouncementExtraTags can still replace the common tag set and drop support_oversized_transfer.
  • Gate proactive oversized server response framing by learned peer support.
    Corresponding Gap: proactive response fragmentation still triggers on progressToken without requiring known peer support.
  • Make accept handshake race-safe for early accept arrival.
    Corresponding Gap: waitForAccept path still relies on waiter registration timing; accept can arrive first and be lost.
  • Keep conservative chunk-size headroom below threshold for nested envelope/escaping overhead.
    Corresponding Gap: defaults still use threshold and chunk size at the same level, which reduces practical margin.

Let me know what you think!

@ContextVM-org
Copy link
Copy Markdown
Contributor Author

Hey! @1amKhush great comments. I'll think about them and review the implementation

… add client capability advertisement

Extract discovery tag parsing and merging logic into a new `discovery-tags.ts` module. Add client-side capability advertisement so clients can proactively advertise support for encryption, ephemeral gift wraps, and oversized transfers without waiting for server discovery. Also fix a race condition in the oversized transfer receiver where accept could arrive before waiter registration.

BREAKING CHANGE: The `hasKnownDiscoveryTag` function has been removed from `nostr-client-transport.ts` in favor of the new `hasDiscoveryTags` and `parseDiscoveredPeerCapabilities` functions.
@ContextVM-org
Copy link
Copy Markdown
Contributor Author

@1amKhush attached your comments in my last commit, also centralized discovery and capability learn and created some test around that. I'm thinking about creating a new informational cep describing stateless mode and how this capability learning works since currently it is not clear in cep 6. Also after this pr get's merged we can work in a refactor since there are some modules that are becoming pretty large

@1amKhush
Copy link
Copy Markdown
Contributor

1amKhush commented Apr 3, 2026

Great call @ContextVM-org ! Let me know how i can help. If helpful, I can open a follow-up issue right after merge with a proposed refactor breakdown and a draft outline for the informational CEP.

Extract the logic for composing outbound Nostr tags into a reusable
`composeOutboundTags` method in BaseNostrTransport. This standardizes
tag ordering across client and server transports (base tags first,
then discovery tags, then negotiation tags).

Refactor NostrClientTransport and NostrServerTransport to use the
shared composition method, and add `chooseServerOutboundGiftWrapKind`
for consistent gift wrap kind selection based on session capabilities
and configuration.

Also update `hasDiscoveryTags` to use a more efficient set-based check
and add a test for ephemeral gift wrap kind selection when client
advertises support.
@ContextVM-org
Copy link
Copy Markdown
Contributor Author

That sounds great @1amKhush a follow up pr refactoring the code to keep it tidy would be pretty helpful. Im going to be mergin this shortly so we can start with that. Thanks

This release adds oversized payload transfer support for the Nostr transport layer, including sender and receiver flows, sequencing and out-of-order chunk handling, and UTF-8-safe chunk splitting. Also includes refactoring to extract outbound tag composition into base class and discovery tags into a dedicated module with client capability advertisement.
@1amKhush
Copy link
Copy Markdown
Contributor

1amKhush commented Apr 4, 2026

That sounds great @1amKhush a follow up pr refactoring the code to keep it tidy would be pretty helpful. Im going to be mergin this shortly so we can start with that. Thanks

Sure, I'll keep an eye out for the merge

@ContextVM-org ContextVM-org merged commit 812b5bc into master Apr 4, 2026
3 checks passed
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.

3 participants