Package com.privatechain.crypto
Class AddressUtil
java.lang.Object
com.privatechain.crypto.AddressUtil
Utility class for deriving a blockchain address from an EC public key.
The derivation pipeline follows the Bitcoin / Web3 convention (FR-CRYPTO-09):
- SHA-256 of the DER-encoded public key bytes
- RIPEMD-160 of the SHA-256 result (reduces size from 32 → 20 bytes)
- Base58Check encoding with a configurable version byte
(default
0x00— main net Pay-to-Public-Key-Hash)
The result is a 25–34 character, human-readable, typo-resistant address that can be verified for internal checksum consistency.
Usage
ECKeyPair keyPair = KeyPairGenerator.generateECKeyPair();
String address = AddressUtil.deriveAddress(keyPair.getPublicKey());
// e.g., "1A1zP1eP5QGefi2DMPTfTL5SLmv7Divf..."
- Since:
- 1.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringderiveAddress(byte[] publicKeyBytes, byte versionByte) Derives a Base58Check-encoded address from raw public-key bytes with a custom version byte.static StringderiveAddress(PublicKey publicKey) Derives a Base58Check-encoded blockchain address from a secp256k1 public key.static booleanisAddressValid(String address) Verifies that a Base58Check-encoded address has a valid internal checksum.
-
Method Details
-
deriveAddress
Derives a Base58Check-encoded blockchain address from a secp256k1 public key.The pipeline is: SHA-256 → RIPEMD-160 → version byte prefix → Base58Check.
- Parameters:
publicKey- the EC public key to derive an address from (non-null)- Returns:
- a Base58Check address string (25–34 characters, main net version byte)
- Throws:
NullPointerException- if publicKey is nullIllegalStateException- if the BouncyCastle provider is missing
-
deriveAddress
Derives a Base58Check-encoded address from raw public-key bytes with a custom version byte.Pass a custom version byte (e.g.,
0x6ffor Bitcoin testnet) to produce network-specific addresses.- Parameters:
publicKeyBytes- DER-encoded public key bytes (non-null, non-empty)versionByte- single-byte network identifier prepended to the hash- Returns:
- a Base58Check address string
- Throws:
NullPointerException- if publicKeyBytes is nullIllegalArgumentException- if publicKeyBytes is emptyIllegalStateException- if the BouncyCastle provider is missing
-
isAddressValid
Verifies that a Base58Check-encoded address has a valid internal checksum.This check does not verify that the address belongs to a known public key; it only confirms that the address string was not corrupted in transit.
- Parameters:
address- the Base58Check-encoded address to verify (non-null, non-blank)- Returns:
trueif the embedded checksum is valid;falseotherwise- Throws:
NullPointerException- if address is nullIllegalArgumentException- if address is blank
-