|
| 1 | +# INSTRUCTIONS.md |
| 2 | + |
| 3 | +This document defines the execution contract for an implementation agent working on a Nostr-only firmware fork derived from Krux. |
| 4 | + |
| 5 | +## 1) North-star objective |
| 6 | + |
| 7 | +The most important outcome is: |
| 8 | + |
| 9 | +- given an unsigned Nostr event, the device returns a correctly signed Nostr event. |
| 10 | + |
| 11 | +Everything else is secondary until this works reliably. |
| 12 | + |
| 13 | +## 2) Product boundaries |
| 14 | + |
| 15 | +The firmware scope is Nostr signing only. |
| 16 | + |
| 17 | +- Remove Bitcoin-specific UX and flows (wallet, receive address, PSBT signing). |
| 18 | +- Keep user-critical transport and interaction paths: |
| 19 | + - QR scan/import and QR export |
| 20 | + - SD card import/export |
| 21 | + - key onboarding |
| 22 | + - event review and explicit sign confirmation |
| 23 | + |
| 24 | +Do not reintroduce Bitcoin abstractions as compatibility layers. |
| 25 | + |
| 26 | +## 3) Mandatory signer-first module layout |
| 27 | + |
| 28 | +Implement and keep responsibilities strict in the following modules: |
| 29 | + |
| 30 | +- `src/krux/nostr/event_parser.py` |
| 31 | +- `src/krux/nostr/canonicalizer.py` |
| 32 | +- `src/krux/nostr/schnorr_backend.py` |
| 33 | +- `src/krux/nostr/approval_ui.py` |
| 34 | +- `src/krux/nostr/exporter.py` |
| 35 | + |
| 36 | +Rules: |
| 37 | + |
| 38 | +- parsing/validation only in `event_parser` |
| 39 | +- canonical NIP-01 serialization and ID calculation only in `canonicalizer` |
| 40 | +- cryptographic sign/verify only in `schnorr_backend` |
| 41 | +- user confirmation rendering/logic only in `approval_ui` |
| 42 | +- output/transport formatting only in `exporter` |
| 43 | + |
| 44 | +## 4) Crypto dependency policy |
| 45 | + |
| 46 | +If `embit` is required for Schnorr during migration: |
| 47 | + |
| 48 | +- isolate all `embit` usage to `schnorr_backend.py` |
| 49 | +- do not import `embit` in UI, parser, exporter, or app orchestration code |
| 50 | +- keep adapter surface minimal (`sign_hash`, `verify_hash`, `derive_pubkey`) |
| 51 | + |
| 52 | +Prefer eventual replacement with a narrower backend when feasible. |
| 53 | + |
| 54 | +## 5) Nostr protocol rules (must enforce) |
| 55 | + |
| 56 | +- NIP-01 event ID must be computed from canonical serialized event fields. |
| 57 | +- Signature must be Schnorr over secp256k1 for the computed event hash. |
| 58 | +- Verify signatures before export; fail closed on mismatch. |
| 59 | +- NIP-19 bech32 forms (`nsec`, `npub`, etc.) are UI I/O formats; convert to internal form for protocol operations. |
| 60 | +- NIP-06 mnemonic derivation is optional and should be treated as advanced flow, not default onboarding. |
| 61 | + |
| 62 | +## 6) Test taxonomy and placement |
| 63 | + |
| 64 | +Use this exact structure: |
| 65 | + |
| 66 | +- `tests/unit/` for deterministic logic checks |
| 67 | +- `tests/functional/` for end-to-end app behavior checks |
| 68 | +- `tests/integration/` for external-system tests (nostr regtest-like node + JSON-RPC client) |
| 69 | +- `tests/common/` for shared fixtures/helpers |
| 70 | + |
| 71 | +Each test belongs to one tier only. |
| 72 | + |
| 73 | +## 7) Documentation requirements |
| 74 | + |
| 75 | +The implementation must include documentation updates: |
| 76 | + |
| 77 | +- update `CONTRIBUTING.md` with: |
| 78 | + - Nostr-only scope and architecture policy |
| 79 | + - module ownership boundaries |
| 80 | + - dependency and testing policy |
| 81 | + - pre-merge verification commands |
| 82 | +- create or update `SECURITY.md` with: |
| 83 | + - threat model |
| 84 | + - secret handling policy |
| 85 | + - disclosure policy |
| 86 | + - signing safety guarantees and explicit non-goals |
| 87 | + |
| 88 | +## 8) Tooling migration requirement |
| 89 | + |
| 90 | +Replace Poetry-based workflows with uv-based workflows: |
| 91 | + |
| 92 | +- remove Poetry-first instructions from docs and scripts |
| 93 | +- add uv setup/install/run/test/lint commands |
| 94 | +- update CI or local automation references accordingly |
| 95 | +- include old-command to new-command mapping in migration notes |
| 96 | + |
| 97 | +## 9) Execution checklist |
| 98 | + |
| 99 | +Before declaring completion, verify all items: |
| 100 | + |
| 101 | +1. signer path works end-to-end: parse -> canonicalize -> review -> sign -> verify -> export |
| 102 | +2. no direct `embit` imports outside `schnorr_backend.py` |
| 103 | +3. tests exist in the correct tiered structure |
| 104 | +4. `CONTRIBUTING.md` and `SECURITY.md` updated |
| 105 | +5. Poetry to uv migration applied and documented |
| 106 | +6. no secret leakage in logs, errors, or artifacts |
| 107 | + |
| 108 | +## 10) Reporting format |
| 109 | + |
| 110 | +Final implementation report must include: |
| 111 | + |
| 112 | +- summary of changed files and rationale |
| 113 | +- test evidence grouped by unit/functional/integration |
| 114 | +- blockers and exact remediation steps (if any) |
| 115 | +- explicit "verified" vs "assumed" statements |
0 commit comments