Skip to content

Conversation

@ihsraham
Copy link
Collaborator

@ihsraham ihsraham commented Nov 8, 2025

YNU-354: Protocol Documentation (Parts 1, 2 & 3)

Part 1 – Delivered 8 Nov 2025

Scope (Part 1)

  • New Protocol section rooted at docs/protocol/, covering: introduction, terminology, architecture, and the on-chain suite (overview, data-structures, channel-lifecycle, security).

  • Sidebar (protocolSidebar) now reflects this structure automatically:

    Introduction → Terminology → Architecture → On-Chain Protocol (Overview → Data Structures → Channel Lifecycle → Security).

  • Navbar updated with a Protocol button (left-aligned) linking to docs/protocol/introduction.

Presentation Enhancements

  • Custom tooltip system (@tippyjs/react, Tooltip.tsx) exposing Terminology definitions on hover across all Part 1 pages.

  • Contextual highlight boxes (info, tip, caution, warning, success, note) used where required.

  • Mermaid diagrams created for architectural, lifecycle, and flow visuals.


Part 2 – Delivered 12 Nov 2025

Scope (Part 2)

  • Complete off-chain protocol documentation suite covering all RPC methods and communication patterns.

  • Seven comprehensive modules added under docs/protocol/off-chain/:

    • overview – Off-chain layer architecture and WebSocket communication
    • message-format – JSON-RPC 2.0 structure, request/response patterns, error codes
    • authentication – Three-step session key flow (auth_request, auth_challenge, auth_verify)
    • channel-methods – Lifecycle operations (create_channel, close_channel, resize_channel)
    • transfers – Off-chain transfer mechanics between unified balances
    • app-sessions – Virtual ledger channels (app.create, app.submit, app.close) with intent system
    • queries – Ten query methods (get_config, get_assets, get_channels, get_app_sessions, get_balance, get_ledger_entries, get_ledger_transactions, get_user_tag, get_session_keys, ping)
  • Sidebar structure expanded:

    Introduction → Terminology → Architecture → On-Chain Protocol → Off-Chain Protocol (Overview → Message Format → Authentication → Channel Methods → Transfers → App Sessions → Queries).

Parameter Documentation Transformation

  • Deeply nested structures refactored using separate sub-tables (Stripe/GitHub/AWS pattern):

    • AppDefinition structure with Quick Reference anchors
    • Channel and State structures with cross-references
    • AppSessionInfo with 13 fields cleanly separated
    • SessionKeyInfo with Allowance sub-structure
    • BrokerSignatures for atomic operations
  • Enhanced scannability:

    • Uniform table structure (Parameter | Type | Required | Description | Default | Example | Notes)
    • Clear visual hierarchy with anchor links
    • "See Also" columns for structure references
    • Quick Reference tip boxes for complex methods

Presentation Enhancements (Part 2)

  • Mermaid diagrams for:
    • Authentication flow (3-step process with state transitions)
    • Channel lifecycle (creation, active, closure paths)
    • App session intent system (operate, deposit, withdraw)
    • Transaction type flows (transfer, deposit, withdrawal, app operations)
  • Contextual admonitions:
    • Security requirements (authentication, signature verification)
    • Balance tracking (double-entry bookkeeping principles)
    • Intent validation rules (NitroRPC/0.4)
    • Best practices (pagination, error handling, session management)
  • Code examples:
    • Implementation snippets for WebSocket connection
    • Authentication flow step-by-step
    • Request/response patterns with actual payloads
    • Error handling strategies

Part 3 – Delivered 14 Nov 2025

Scope (Part 3)

  • Four reference and integration modules added to complete the protocol documentation:
    • communication-flows – End-to-end sequence diagrams showing how on-chain and off-chain layers interact for major operations (channel creation, transfers, app sessions, cooperative closure, disputes)
    • protocol-reference – Quick reference guide with all critical protocol constants, magic numbers, state intents, participant indices, error codes, hash computations, and signature requirements in one place
    • glossary – A-Z terminology reference with detailed definitions for all protocol concepts (75+ terms)
    • implementation-checklist – Comprehensive checklist for building compliant Nitrolite implementations covering identifier computation, signature handling, blockchain integration, off-chain RPC, state management, security, and testing

Cross-Layer Communication Flows

  • Detailed sequence diagrams for:
    • Channel creation (off-chain preparation → on-chain execution → event monitoring)
    • Off-chain transfers (ledger updates, balance management, double-entry bookkeeping)
    • App session lifecycle (creation, state updates with intents, closure)
    • Cooperative closure (final state agreement → on-chain settlement)
    • Dispute resolution (challenge → response/timeout → resolution)

Protocol Reference

  • Organized into quick-lookup sections:
    • Constants (magic numbers, participant indices, state count)
    • State intents (INITIALIZE, OPERATE, RESIZE, FINALIZE)
    • Error codes (authentication, validation, balance, channel state)
    • Hash computations (channelId, stateHash with exact formulas)
    • Signature requirements (per method, per role)
  • Designed for developers to quickly find protocol values without reading full method docs

Implementation Support

  • Glossary provides standalone definitions with cross-references, useful for:

    • Onboarding new developers
    • Quick lookups during implementation
    • Understanding relationships between concepts
  • Implementation Checklist organized by concern:

    • Core protocol (identifiers, signatures, magic numbers)
    • On-chain integration (blockchain connection, contract calls, event monitoring)
    • Off-chain RPC (WebSocket, authentication, method implementation)
    • State management (channel state, app sessions, version tracking)
    • Security (challenge periods, signature verification, replay protection)
    • Testing (unit tests, integration tests, scenario coverage)

Reviews

Anton's Review Integration

  • Addressed technical review comments from Anton on Part 1 files:
    • Corrected channel opening flow (client submits with both signatures, no separate join)
    • Fixed State structure to include intent and version fields
    • Updated stateHash computation to include all required fields
    • Changed challenge response method from challenge to checkpoint()
    • Updated participant index constants (CLIENT_IDX, SERVER_IDX, PART_NUM)
    • Clarified EVM chain support list
    • Enhanced Creator term definition for clarity
  • Applied ripple effects across all affected documentation (Parts 1, 2, and 3)

Protocol Specification Approach

  • Per Alessio's guidance from PBR: documentation should be fact-based, not conversational
  • Abstracted all implementation-specific code examples to maintain language-agnostic approach
  • Focused on describing WHAT the protocol does rather than HOW to implement it in specific languages

Final Documentation Structure

docs/protocol/
├── introduction.mdx
├── terminology.mdx
├── architecture.mdx
├── on-chain/
│   ├── overview.mdx
│   ├── data-structures.mdx
│   ├── channel-lifecycle.mdx
│   └── security.mdx
├── off-chain/
│   ├── overview.mdx
│   ├── message-format.mdx
│   ├── authentication.mdx
│   ├── channel-methods.mdx
│   ├── transfers.mdx
│   ├── app-sessions.mdx
│   └── queries.mdx
├── communication-flows.mdx
├── protocol-reference.mdx
├── glossary.mdx
└── implementation-checklist.mdx

Total: 18 comprehensive documentation pages covering the complete Nitrolite protocol

- Added Protocol section in the docs
- Added Intro and Architecture pages
- Added On-chain section and contents
@ihsraham ihsraham added the documentation Improvements or additions to documentation label Nov 8, 2025
@ihsraham ihsraham changed the title Added protocol section, intro, on-chain Protocol Docs Nov 8, 2025
@ihsraham ihsraham changed the title Protocol Docs Adding Protocol Docs Nov 8, 2025
@ihsraham ihsraham changed the title Adding Protocol Docs YNU354: Protocol Docs Nov 10, 2025
@ihsraham ihsraham changed the title YNU354: Protocol Docs YNU-354: Protocol Docs Nov 12, 2025
Copy link
Collaborator

@philanton philanton left a comment

Choose a reason for hiding this comment

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

Great Work!

| `application` | string | Application name for this session | `"clearnode"` ||
| `allowances` | array\<Allowance\> | Spending limits and usage || See [Allowance](#allowance-structure) below |
| `scope` | string | Permission scope || Future feature, not fully enforced yet |
| `expire` | string (timestamp) | Session expiration time |||
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a bit outdated. Now expires_at is used - please check current docs/API.md

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

:::success Cryptographic Security
State validity is enforced through ECDSA signatures on the secp256k1 curve, the same cryptographic foundation as Ethereum itself.
:::

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be good to mention why using EIP-712 sigs is more superior than 191 in terms of security and user experience (as this is one of the minor but important features that differentiate our protocol)

Copy link
Collaborator Author

@ihsraham ihsraham Nov 17, 2025

Choose a reason for hiding this comment

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

@dimast-x
image
I am adding this new section, is it fine?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Great work! Just one minor suggestion - no need to say this loudly with the green highlight about this being a differentiating feature XD Yes, it is differentiating, but its not the main feature that we need to highlight this much. Maybe try to shorten it - one small sentence should be enough

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dimast-x
Copy link
Collaborator

dimast-x commented Nov 21, 2025

@ihsraham Some change broke the sidebar UI, now the arrows are shown on both sides of the title (It must be only on the left). It was good before
image

Copy link
Contributor

@nksazonov nksazonov left a comment

Choose a reason for hiding this comment

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

Generally LGTM!
Some comments are still left to address, but nothing critical.
GREAT WORK!

Comment on lines 33 to 45
assetSymbol: "A lowercase string identifier for a supported asset.",
sessionThreshold:
"Minimum total weight of signatures required to approve app session state updates.",
creatorRole:
"Most often a light client willing to fund a ledger account with a clearnode (the Broker).",
stateIntent:
"An enum defining the purpose of a state: INITIALIZE (0), OPERATE (1), RESIZE (2), FINALIZE (3).",
creatorParticipant:
"The participant at index 0 in a channel who initiates channel creation.",
appSessionId:
"A unique identifier for an app session, formatted as a 0x-prefixed hex string (32 bytes).",
packedState:
"A specific encoding of a channelId, state.intent, state.version, state.data, state.allocations, used for signing and signature verification.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move these definitions closer to others, that are relevant, so that they form groups. I.e., move "packedState" to right after "channel state", "appSessionId" to right after "appSession" etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment on lines +15 to +16
appChannel:
"Off-chain channels built on top of payment channels, intended to be used by app developers to enable application-specific interactions and transactions without touching the blockchain.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should rename this to "appSession" and avoid using "channels" in the "off-chain" definition, so that the difference between on-chain state channels is bigger? @dimast-x @philanton , WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did not address it, we can have this as a part of an enhancement story if decide upon to be done

Comment on lines 134 to 135
4. If a newer valid state is submitted during the challenge period, it replaces the current state
5. After the challenge period expires, any participant calls `close()` to finalize with the latest submitted state
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's clarify what happens if a newer state is submitted during challenge period

Suggested change
4. If a newer valid state is submitted during the challenge period, it replaces the current state
5. After the challenge period expires, any participant calls `close()` to finalize with the latest submitted state
4. If participants decides to cooperate again, they may produce a newer valid state, and any of them can submit it via `checkpoint()`, thus stopping the challenge period and moving the channel from DISPUTE back to ACTIVE status
5. If not, after the challenge period expires, any participant calls `close()` to finalize with the latest submitted state

Copy link
Collaborator Author

Choose a reason for hiding this comment

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


### Usage

Transfer funds from the authenticated user's <Tooltip content={tooltipDefinitions.unifiedBalance}>unified balance</Tooltip> to another user's <Tooltip content={tooltipDefinitions.unifiedBalance}>unified balance</Tooltip> within the Yellow Network. This is a purely off-chain operation executed as a database transaction on <Tooltip content={tooltipDefinitions.clearnode}>the clearnode</Tooltip>, resulting in instant settlement. The transfer updates internal ledger entries using double-entry bookkeeping principles and creates a transaction record for both parties. The security guarantee comes from the underlying on-chain channels that back the <Tooltip content={tooltipDefinitions.unifiedBalance}>unified balance</Tooltip>.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Replace "This is a purely off-chain operation executed as a database transaction on the clearnode, resulting in instant settlement.'
with "This is a purely off-chain operation executed as a database transaction on the clearnode, resulting in instant settlement."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed it to: Transfer funds from the authenticated user's unified balance to another user's unified balance within the Yellow Network. This is a purely off-chain operation, which results in instant settlement. The transfer updates internal ledger entries using double-entry bookkeeping principles and creates a transaction record for both parties. The security guarantee comes from the underlying on-chain channels that back the unified balance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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


### When to Use

When sending funds to another Yellow Network user. Common use cases include peer-to-peer payments, merchant payments, tipping, and rapid fund redistribution between users.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove "rapid fund redistribution between users", its a feature of app sessions, not transfers

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

- Recipient must be identified by valid <Tooltip content={tooltipDefinitions.participant}>wallet address</Tooltip> or user tag

:::info Recipient Requirements
The recipient does not need to have an existing balance or account on the clearnode. Transfers can be sent to any valid wallet address, and the recipient's account will be created automatically if it doesn't exist.
Copy link
Collaborator

Choose a reason for hiding this comment

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

created automatically on the first login.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Clearnode->>Bob: tr (transfer) notification
Clearnode->>Bob: bu (balance update) notification
Note over Bob: 5. Balance Updated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Client A also receives tr (transfer) notification.
also move "Clearnode->>Alice: {ledger_transactions}" to be the last step, and instead of ledger_transactions, simply say that this is "response"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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


#### 4. Sends Notifications

- **Sender** receives response with transaction details
Copy link
Collaborator

Choose a reason for hiding this comment

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

move "Sender receives response with transaction details" into section 5. Response

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

B[Create App Session<br/>Alice locks 100 USDC]
C[Alice's Unified Balance<br/>Total: 200 USDC<br/>Available: 100 USDC<br/>Locked: 100 USDC]
Copy link
Collaborator

Choose a reason for hiding this comment

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

We dont have Locked acccount.
There is User's Unified Account and an App Session Account. In this example, the funds are transferred from user's Unified Account to the App Session Account

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Locked: 100 USDC (in app session 0x98765...)
```

:::warning Locked Funds
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this warning completely as funds can be withdrawn without closing an app session

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alice's Unified Balance:
Total: 200 USDC
Available: 100 USDC
Locked: 100 USDC (in app session 0x98765...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove Locked terminology from here and other parts. The funds are no longer on the unified balance account, they are no locked on unified balance, they are on a separate app session account. please check it in all places where you mention that funds are locked in the unified balance

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

---

## Error Cases

Copy link
Collaborator

Choose a reason for hiding this comment

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

Lots of these errors do not follow the real errors. Every error can be checked by copying it and searching for it in the Clearnode codebase. Please remove the errors that don't exist, and you can create a user story to address errors properly in the documentation so that we don't forget

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ihsraham ihsraham marked this pull request as ready for review November 21, 2025 16:00
@ihsraham ihsraham requested a review from dpatsora as a code owner November 21, 2025 16:00
@ihsraham ihsraham merged commit 48d19fc into master Nov 21, 2025
7 checks passed
@ihsraham ihsraham deleted the YNU354_protocol_docs branch November 21, 2025 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants