crypto: add TorV3Address.encodePublicKey (pubkey -> address)#7
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ofdecodePublicKey: compute theSHA3-256(".onion checksum" || pubkey || version)[:2]checksum, base32-encodepubkey || checksum || versionin the lowercase RFC 4648 alphabet, and append.onion. Reuses the existingcomputeChecksumhelper.Tests:
Gp8y4JM7...derives todkptfyeth...onion, matching the corpus generator and the Rust reference byte for byte.Additive; version 0.3.0 -> 0.4.0. Full suite green on JDK 21 (171 tests).