Add keys chapter

Introduces PublicKey and SecretKey as distinct type-safe wrappers around
secp256k1, with hex and NIP-19 bech32 (npub/nsec) encoding. SecretKey has
a redacted Debug impl and no Display to reduce accidental leakage; it
exposes material only through explicit to_hex / to_nsec. FromStr on both
types auto-detects hex vs. bech32. Eight round-trip tests cover encoding,
auto-detection, prefix validation, debug redaction, and generation.
This commit is contained in:
Jon Staab
2026-04-13 15:16:32 -07:00
parent ce4dce9779
commit 5364854881
9 changed files with 1248 additions and 2 deletions
+11
View File
@@ -26,6 +26,10 @@ Also read:
Create or update the chapter markdown file in `./book/`. Follow these conventions:
- **Voice**: Write as though documenting a library, not teaching a class. Do not refer
to the book as a "teaching resource", "tutorial", "pedagogical", or similar — and
don't justify design decisions on the grounds that the reader is learning. The prose
should stand on its own merits as technical writing about the library.
- **Literate style**: The prose is the primary artifact. Code blocks are woven into the
narrative, not dumped in bulk.
- **Code blocks** that should be tangled use the annotation format:
@@ -39,6 +43,13 @@ Create or update the chapter markdown file in `./book/`. Follow these convention
seeing the implementation.
- Keep code blocks focused — one concept per block where possible.
- Ensure all `use` statements and module declarations are included in tangled blocks.
- **Tests are hand-written, not tangled, and do not appear in the chapter.** Do not put
test code in chapter markdown, do not emit `{file=crate-name/tests/…}` blocks, and do
not add a "Tests" section to the narrative. Tangle owns `src/` and overwrites it every
build, so tests must live *outside* `src/` to survive. Integration tests go in
`crate-name/tests/<topic>.rs` as normal, hand-edited Rust files alongside `src/`. Write
or update the test file directly with the Edit or Write tool as part of the same task,
and run `cargo test -p <crate>` alongside `just all` to verify.
- Update `./book/SUMMARY.md` if adding a new chapter.
- Update any `Cargo.toml` files if new dependencies are needed.