Skip to content

tor: add OnionAddress::from_origin_pubkey (pubkey -> address)#13

Merged
samjanny merged 2 commits into
mainfrom
feat/onion-encode
Jun 3, 2026
Merged

tor: add OnionAddress::from_origin_pubkey (pubkey -> address)#13
samjanny merged 2 commits into
mainfrom
feat/onion-encode

Conversation

@samjanny
Copy link
Copy Markdown
Owner

@samjanny samjanny commented Jun 3, 2026

The crate could decode and strictly verify a Tor v3 onion address (OnionAddress::decode / verify_strict) but had no public way to derive an address from an origin public key. A publisher building a manifest origin needs that direction; without it, callers must reimplement the Tor v3 base32+checksum encoding themselves.

Add OnionAddress::from_origin_pubkey, the exact inverse of verify_strict: it computes the SHA3-256(".onion checksum" || pubkey || version)[:2] checksum, encodes pubkey || checksum || version as lowercase base32 per rend-spec-v3, and appends .onion.

Tests:

  • round trip: encode a pubkey, then verify_strict returns the same pubkey, a valid checksum, and version 0x03.
  • canonical fixture: the corpus origin key Gp8y4JM7... derives to dkptfyeth...onion, matching the corpus generator's independent encoder byte for byte.

Additive public API; crate version 0.8.0 -> 0.9.0. Spec revision unchanged (rc.48). fmt, clippy -D warnings, doc -D warnings, and the full test suite are green.

samjanny added 2 commits June 3, 2026 11:59
…0.9.0

The crate could decode and strictly verify a Tor v3 onion address but had
no public way to derive an address from an origin public key. A publisher
building a manifest origin needs that direction. Add
OnionAddress::from_origin_pubkey, the exact inverse of verify_strict: it
computes the SHA3-256 checksum, encodes pubkey||checksum||version as
lowercase base32 per rend-spec-v3, and appends .onion.

Tests cover the encode/verify_strict round trip and the canonical corpus
origin fixture (Gp8y4JM7... -> dkptfyeth...onion), confirming the output
matches an independent encoder byte for byte.

Additive public API; bump the crate 0.8.0 -> 0.9.0. Spec revision is
unchanged (rc.48).
CI builds with --locked, which rejects a Cargo.lock that disagrees with
Cargo.toml. The 0.8.0 -> 0.9.0 bump updated the manifest but not the lock,
so every --locked job failed. Sync the lock.
@samjanny samjanny merged commit 0b68886 into main Jun 3, 2026
11 checks passed
@samjanny samjanny deleted the feat/onion-encode branch June 3, 2026 10:07
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