Skip to content

crypto: add TorV3Address.encodePublicKey (pubkey -> address)#7

Merged
samjanny merged 1 commit into
mainfrom
feat/onion-encode
Jun 3, 2026
Merged

crypto: add TorV3Address.encodePublicKey (pubkey -> address)#7
samjanny merged 1 commit into
mainfrom
feat/onion-encode

Conversation

@samjanny
Copy link
Copy Markdown
Owner

@samjanny samjanny commented Jun 3, 2026

The Java library could decode and verify a Tor v3 onion address (TorV3Address.decodePublicKey) but had no way to derive an address from an origin public key, the direction a publisher needs when building a manifest origin. This mirrors the same gap just closed in the Rust reference (OnionAddress::from_origin_pubkey).

Add TorV3Address.encodePublicKey, the exact inverse of decodePublicKey: compute the SHA3-256(".onion checksum" || pubkey || version)[:2] checksum, base32-encode pubkey || checksum || version in the lowercase RFC 4648 alphabet, and append .onion. Reuses the existing computeChecksum helper.

Tests:

  • round trip: encode a pubkey, then decode the result returns the same pubkey.
  • canonical fixture: the corpus origin key Gp8y4JM7... derives to dkptfyeth...onion, matching the corpus generator and the Rust reference byte for byte.
  • rejects a non-32-byte key.

Additive; version 0.3.0 -> 0.4.0. Full suite green on JDK 21 (171 tests).

… 0.4.0

The Java library could decode and verify a Tor v3 onion address but had no
way to derive an address from an origin public key, the direction a
publisher needs when building a manifest origin. Add
TorV3Address.encodePublicKey, the exact inverse of decodePublicKey: it
computes the SHA3-256 checksum, base32-encodes pubkey||checksum||version
in the lowercase RFC 4648 alphabet, and appends .onion, reusing the
existing computeChecksum helper.

Tests cover the encode/decode round trip and the canonical corpus origin
fixture (Gp8y4JM7... -> dkptfyeth...onion), confirming the output matches
the corpus generator and the Rust reference byte for byte.

Additive; bump version 0.3.0 -> 0.4.0.
@samjanny samjanny merged commit 93391ed into main Jun 3, 2026
2 checks passed
@samjanny samjanny deleted the feat/onion-encode branch June 3, 2026 10:13
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