Skip to content

fix: author account-scoped requests with an ephemeral key, not the identity key - #173

Merged
arkanoider merged 1 commit into
MostroP2P:mainfrom
Forte11Cuba:fix/account-scoped-ephemeral-author
Sep 12, 2026
Merged

fix: author account-scoped requests with an ephemeral key, not the identity key#173
arkanoider merged 1 commit into
MostroP2P:mainfrom
Forte11Cuba:fix/account-scoped-ephemeral-author

Conversation

@Forte11Cuba

@Forte11Cuba Forte11Cuba commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Close #172

The three account-scoped requests (Action::LastTradeIndex, Action::RestoreSession, and the restore stage-2 Action::Orders fetch) passed identity_keys as both the identity and the trade-key argument of send_dm, so the outer kind-14 was authored by the permanent identity pubkey and the identity proof was silently dropped (mostro-core only includes it when the keys differ)

Each call site now generates a fresh Keys::generate() that authors the event, and the whole trio switches together send_dm, wait_for_dm and parse_dm_events all use the same ephemeral key, since the daemon replies NIP-44-encrypted to event.sender. identity_keys stay where the protocol wants them: inside the encrypted proof, which is what the daemon resolves the account from (event.identity).

No daemon or dependency changes, no public signature changes, and no wallet index burned (check_trade_index only covers NewOrder | TakeBuy | TakeSell). The sender != mostro_pubkey checks are untouched.

Bonus hardening on restore (the only flow with no request_id): a stale restore reply replayed by a relay used to be decryptable by the identity key and could seed outdated RestoreData; a per-run ephemeral key cannot decrypt replies addressed to earlier runs, so they can never be consumed

Two notes, neither a behavior regression:

  • Each ephemeral key adds a relay subscription that lives until listener rebuild — same lifecycle per-order trade keys already follow. A future improvement could unsubscribe in prune_closed_pending_waiters.
  • The restore log now prints the ephemeral key instead of the identity pubkey, aligning with the daemon's convention of keeping the persistent identity out of logs.

Verified with cargo fmt --check, cargo clippy --all-targets (clean) and the full cargo test suite (all green)

Summary by CodeRabbit

  • Security & Privacy

    • Session restoration, order-detail retrieval, and trade-index synchronization now use fresh, temporary keys for requests.
    • Account identity remains securely included as encrypted proof while avoiding persistent identity-to-service links.
    • Fresh keys help prevent replies from previous restore attempts from being reused.
  • Documentation

    • Added guidance explaining key usage, privacy modes, and safe handling of long-lived identity keys.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 22a63a93-b06e-4899-9d4c-6e961ca2d6c0

📥 Commits

Reviewing files that changed from the base of the PR and between 8ec3bfa and 484eb6f.

📒 Files selected for processing (3)
  • src/util/dm_utils/mod.rs
  • src/util/order_utils/execute_restore.rs
  • src/util/sync_trade_index.rs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

Restore and last-trade-index requests now use fresh ephemeral keys for outer DM authorship and response handling. Long-lived identity keys remain encrypted identity proofs. Documentation describes the key separation and privacy rules.

Changes

Account-scoped DM privacy

Layer / File(s) Summary
Restore ephemeral-key flow
src/util/dm_utils/mod.rs, src/util/order_utils/execute_restore.rs
Restore requests and order-detail requests use fresh ephemeral keys for authorship, reply addressing, and response decryption. Identity keys remain encrypted proofs. Documentation describes the key roles and replay protection.
Trade-index ephemeral-key flow
src/util/sync_trade_index.rs
Last-trade-index requests use a fresh ephemeral key for sending, waiting, and parsing responses. Identity keys remain in the encrypted proof.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 484eb

Restore and trade-index requests now use fresh ephemeral authors and reply keys while preserving encrypted identity proofs, preventing permanent identity exposure in relay-visible events and isolating restore replies between runs. No current merge-blocking risk remains.

Suggested reviewers: arkanoider

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: using ephemeral keys to author account-scoped requests instead of identity keys.
Linked Issues check ✅ Passed The changes satisfy issue #172. The three specified requests now use fresh ephemeral keys for sending, waiting, and parsing, while identity keys remain in the encrypted proof. Restore flows also gain …
Out of Scope Changes check ✅ Passed All code and documentation changes support the linked issue and PR objectives. No unrelated functional, dependency, daemon, or public API changes are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit sends a fleeting key,
While identity sleeps unseen.
Replies hop back through moonlit air,
Old echoes find no doorway there.
Privacy blooms with every pair.

Comment @coderabbitai help to get the list of available commands.

@Catrya Catrya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK

@arkanoider

Copy link
Copy Markdown
Collaborator

Good pick! Well scoped, safely mergeable. LGTM!

@arkanoider
arkanoider merged commit 59912bd into MostroP2P:main Sep 12, 2026
8 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.

Restore and last-trade-index requests are authored by the identity key, leaking it to relays

3 participants