Skip to content

docs: add AUTHENTICATION.md - v1 reference spec - #19

Merged
grunch merged 3 commits into
mainfrom
docs/authentication-spec
Mar 24, 2026
Merged

docs: add AUTHENTICATION.md - v1 reference spec#19
grunch merged 3 commits into
mainfrom
docs/authentication-spec

Conversation

@mostronatorcoder

@mostronatorcoder mostronatorcoder Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Detailed documentation of mostro-mobile v1 authentication system based on actual code analysis.

Contents

Authentication Flow

  • First run flow: walkthrough \u2192 master key generation \u2192 home
  • Key generation: BIP-39 (24 words) + BIP-32 HD derivation
  • Privacy modes: Reputation mode vs Full Privacy mode

Key Management Screen

  • View/export mnemonic (with masking: first 2 + last 2 words)
  • Privacy mode toggle
  • Generate new user (WARNING: deletes all data)
  • Import user via mnemonic
  • Refresh user (re-fetch data without changing keys)

Session Management

  • Per-order sessions with derived trade keys
  • Shared key computation via ECDH with peer
  • Session expiration (24 hours default)
  • Role tracking (buyer/seller)

Restore Flow

  1. Import mnemonic and validate
  2. Clear all existing data
  3. Subscribe to Nostr with temp trade key (index 1)
  4. Request restore data from Mostro
  5. Request order details
  6. Request last trade index
  7. Restore sessions and subscribe to chats
  8. Rebuild state from Mostro data

Key Derivation

  • Path: m/44/1237/0 (NIP-06 compliant)
  • Index 0: Master identity key
  • Index 1: Temp key (restore only)
  • Index N: Trade key for order N

Security Model

  • Master key never leaves device (secure storage)
  • Each order uses different derived key
  • Shared key computed per session (ECDH)
  • Full privacy mode hides master key from Mostro

Protocol References

This spec relates to the following Mostro protocol documentation:

  • Restore Flow: restore.md - Action::restore, fetching order data from Mostro
  • NIP-59 Gift Wrap: gift-wrap.md - Encrypted messaging using NIP-59
  • NIP-06: BIP-39 key derivation for Nostr identity
  • NIP-33: nip33.md - Replaceable events for orders
  • mostro-core: order.rs - Order status enum definitions

Files Analyzed

  • lib/features/key_manager/key_manager.dart
  • lib/features/key_manager/key_derivator.dart
  • lib/features/key_manager/key_storage.dart
  • lib/features/key_manager/key_management_screen.dart
  • lib/features/walkthrough/screens/walkthrough_screen.dart
  • lib/features/restore/restore_manager.dart
  • lib/shared/notifiers/session_notifier.dart
  • lib/data/models/session.dart

Related Specs

  • .specify/v1-reference/NYM_IDENTITY.md - Anonymous identity concept
  • .specify/v1-reference/SESSION_AND_KEY_MANAGEMENT.md - Existing session docs

Summary by CodeRabbit

Documentation

  • Enhanced account screen specification documentation with a new "Related Documentation" section linking to comprehensive authentication implementation guides and external protocol references for identity management systems
  • Added complete authentication and identity system documentation covering key generation, account restore workflows, privacy mode selection, key derivation semantics, session management, and user-facing authentication screens

MostronatorCoder[bot] added 2 commits March 24, 2026 13:00
Detailed documentation of mostro-mobile v1 authentication system:

- Hierarchical deterministic key system (BIP-39, BIP-32, NIP-06)
- Authentication flow (first run, walkthrough, master key generation)
- Key management screen (view mnemonic, privacy modes, import/export)
- Session management (per-order sessions, shared keys, expiration)
- Restore flow (import mnemonic, fetch orders from Mostro, rebuild state)
- Key derivation paths and privacy mode considerations
- Security model and comparison v1 vs v2

Based on actual code analysis of:
- lib/features/key_manager/
- lib/features/walkthrough/
- lib/features/restore/
- lib/shared/notifiers/session_notifier.dart
- lib/data/models/session.dart
…ON.md

ACCOUNT_SCREEN.md:
- Added 'Related Documentation' section pointing to AUTHENTICATION.md for technical details
- Added protocol references (restore flow, gift wrap, NIP-06)

AUTHENTICATION.md:
- Added 'Related Documentation' section pointing to ACCOUNT_SCREEN.md for UI specs
@grunch

grunch commented Mar 24, 2026

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9385eac7-9d08-46ab-a866-eb132915dc31

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Documentation expansion for Mostro Mobile v1 authentication system. ACCOUNT_SCREEN.md now references a new AUTHENTICATION.md file that comprehensively documents HD key derivation (BIP-39/BIP-32), first-run and restore flows, key management screens, and security architecture. No code modifications.

Changes

Cohort / File(s) Summary
Authentication Documentation
.specify/v1-reference/ACCOUNT_SCREEN.md, .specify/v1-reference/AUTHENTICATION.md
Added comprehensive authentication reference documentation. ACCOUNT_SCREEN.md links to new AUTHENTICATION.md file with protocol references (BIP-39/BIP-32, NIP-06, Gift Wrap). AUTHENTICATION.md details HD key generation, BIP-39 mnemonics, restore/import flows, key derivation paths, user-facing screens, key management components, and data storage strategy.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Poem

🐰 A warren of secrets, now plainly told,
BIP-39 seeds in digital gold,
Keys nested deep in paths so grand,
HD wallets bloom across the land! 🌿✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding AUTHENTICATION.md as a v1 reference specification for the mostro-mobile project.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/authentication-spec

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.specify/v1-reference/ACCOUNT_SCREEN.md:
- Line 204: Update the restore action label in the documentation: replace the
incorrect reference `Action::restore` with the correct protocol label
`Action::restore-session` so it matches the protocol naming (see the existing
reference line that currently reads "**[Restore Flow](...)** —
`Action::restore`" and change the symbol to `Action::restore-session`).

In @.specify/v1-reference/AUTHENTICATION.md:
- Line 52: The document defines index 1 twice (once as "first trade key" and
again as a "restore-only temp key"), causing a role conflict; update the
AUTHENTICATION.md entries so each key role uses a unique index—e.g., keep "first
trade key = index 1" in the trade key section and change the restore-only temp
key's index in the restore/session derivation section (lines referencing index 1
in the restore-only temp key paragraph) to a distinct index (such as index 2),
and update any wording to clearly state the intended role for the renamed index.
- Around line 68-69: Replace the non-canonical action name "restore" with the
protocol-defined canonical action "restore-session" wherever the Mostro protocol
action is referenced in the document (e.g., the Nostr/send-restore example and
any other protocol examples), ensuring examples, diagrams, and any JSON/Nostr
action fields use "restore-session" instead of "restore"; leave CLI-specific
mentions of the shorthand "restore" only in CLI usage sections if present and
update any surrounding explanatory text to note that the protocol action name is
"restore-session" while the CLI uses the shorthand.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4d326fbb-b31d-4b2a-aa20-51cbb86d4067

📥 Commits

Reviewing files that changed from the base of the PR and between 1e9d1e5 and 91be911.

📒 Files selected for processing (2)
  • .specify/v1-reference/ACCOUNT_SCREEN.md
  • .specify/v1-reference/AUTHENTICATION.md

Comment thread .specify/v1-reference/ACCOUNT_SCREEN.md Outdated
Comment thread .specify/v1-reference/AUTHENTICATION.md Outdated
Comment thread .specify/v1-reference/AUTHENTICATION.md Outdated
…nflict

- ACCOUNT_SCREEN.md: Action::restore → Action::restore-session (protocol canonical name)
- AUTHENTICATION.md:
  - KEY GENERATION: first trade key index 1 → 2 (index 1 reserved for temp restore key)
  - Restore flow: 'Restore request' → 'restore-session request' (protocol action)
  - KEY DERIVATION: clarify index 1 is ephemeral (restore temp), indices 2+ for orders
  - Stage 1: Action::restore → Action::restore-session
  - Note: explain first trade = index 2 after init, lastTradeIndex+1 after restore

Fixes CodeRabbit inline comments on PR #19
@grunch
grunch merged commit 6f91fdf into main Mar 24, 2026
1 check passed
@grunch
grunch deleted the docs/authentication-spec branch March 24, 2026 14:02
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.

1 participant