Convert addresses

Within this document, we'll outline some examples on how to convert addresses between different formats in Titan Chain.

Convert Hex <> Bech32 address

Titan Chain addresses are compatible with both Ethereum addresses (hex format) and Cosmos addresses (bech32 format). You can convert between the two formats easily using the same private key.

Key Classes Overview

PrivKeySecp256k1 Class

The PrivKeySecp256k1 class handles private key operations:

export class PrivKeySecp256k1 {
  // Generate a random private key
  static generateRandomKey(): PrivKeySecp256k1;

  // Create from Uint8Array
  constructor(protected readonly privKey: Uint8Array);

  // Convert to bytes
  toBytes(): Uint8Array;

  // Get corresponding public key
  getPubKey(): PubKeySecp256k1;

  // Sign a 32-byte digest
  signDigest32(digest: Uint8Array): {
    readonly r: Uint8Array;
    readonly s: Uint8Array;
    readonly v: number | null;
  };
}

PubKeySecp256k1 Class

The PubKeySecp256k1 class handles public key operations and address generation:

Using TypeScript

You can easily convert between a Titan address and Ethereum address by using our utility functions:

Convert ETH Address to Titan Bech32

For chains using ETH-style addressing with bech32 encoding (slip44 = 60):

Generate Random Key and Addresses

Create a new random private key and generate all address formats:

Multi-chain Address Generation

Generate addresses for multiple chains using the same private key:

Signing and Verification

Sign and verify messages using the secp256k1 curve:

Key Differences

  • ETH addressing: Uses uncompressed public key + keccak256 hash

  • Cosmos addressing: Uses compressed public key + sha256 + ripemd160 hash

  • Chain-specific logic: Some chains use ETH addressing even with bech32 format (slip44 = 60)

  • Key generation: Uses secp256k1 curve for both private and public keys

  • Signing: Implements deterministic ECDSA with lowS for compatibility

The same private key generates different address formats, allowing users to interact with multiple chains in the Titan ecosystem.