Class AddressUtil

java.lang.Object
com.privatechain.crypto.AddressUtil

public final class AddressUtil extends Object
Utility class for deriving a blockchain address from an EC public key.

The derivation pipeline follows the Bitcoin / Web3 convention (FR-CRYPTO-09):

  1. SHA-256 of the DER-encoded public key bytes
  2. RIPEMD-160 of the SHA-256 result (reduces size from 32 → 20 bytes)
  3. 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 Details

    • deriveAddress

      public static String deriveAddress(PublicKey publicKey)
      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 null
      IllegalStateException - if the BouncyCastle provider is missing
    • deriveAddress

      public static String deriveAddress(byte[] publicKeyBytes, byte versionByte)
      Derives a Base58Check-encoded address from raw public-key bytes with a custom version byte.

      Pass a custom version byte (e.g., 0x6f for 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 null
      IllegalArgumentException - if publicKeyBytes is empty
      IllegalStateException - if the BouncyCastle provider is missing
    • isAddressValid

      public static boolean isAddressValid(String address)
      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:
      true if the embedded checksum is valid; false otherwise
      Throws:
      NullPointerException - if address is null
      IllegalArgumentException - if address is blank