UltrafastSecp256k1 3.50.0
Ultra high-performance secp256k1 elliptic curve cryptography library
Loading...
Searching...
No Matches
ethereum.hpp
Go to the documentation of this file.
1#ifndef SECP256K1_COINS_ETHEREUM_HPP
2#define SECP256K1_COINS_ETHEREUM_HPP
3#pragma once
4
5// ============================================================================
6// Ethereum Address & Utilities
7// ============================================================================
8// Ethereum-specific functionality:
9// - EIP-55 mixed-case checksummed addresses (0x...)
10// - Address derivation from public key (Keccak-256)
11// - Raw 20-byte address extraction
12//
13// Compatible with all EVM chains:
14// Ethereum, BSC, Polygon, Avalanche, Fantom, Arbitrum, Optimism, etc.
15//
16// Address derivation:
17// 1. Get uncompressed public key (65 bytes, prefix 0x04 + x + y)
18// 2. Keccak-256(pubkey[1..65]) -- skip prefix byte
19// 3. Take last 20 bytes of hash
20// 4. Apply EIP-55 checksum (mixed-case hex encoding)
21// ============================================================================
22
23#include <array>
24#include <cstdint>
25#include <string>
26#include "secp256k1/point.hpp"
27
28namespace secp256k1::coins {
29
30// -- Ethereum Address (EIP-55) ------------------------------------------------
31
32// Generate EIP-55 checksummed Ethereum address from public key
33// Returns: "0x" + 40 hex chars with mixed-case checksum
34// Example: "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"
35std::string ethereum_address(const fast::Point& pubkey);
36
37// Get raw 20-byte Ethereum address (lowercase, no "0x" prefix)
38std::string ethereum_address_raw(const fast::Point& pubkey);
39
40// Get raw 20-byte address as bytes
41std::array<std::uint8_t, 20> ethereum_address_bytes(const fast::Point& pubkey);
42
43// -- EIP-55 Checksum ----------------------------------------------------------
44
45// Apply EIP-55 checksum to a 40-char lowercase hex address
46// Input: 40 hex chars (no "0x" prefix)
47// Output: 40 hex chars with mixed-case checksum
48std::string eip55_checksum(const std::string& hex_addr);
49
50// Verify EIP-55 checksum
51bool eip55_verify(const std::string& addr);
52
53} // namespace secp256k1::coins
54
55#endif // SECP256K1_COINS_ETHEREUM_HPP
std::array< std::uint8_t, 20 > ethereum_address_bytes(const fast::Point &pubkey)
bool eip55_verify(const std::string &addr)
std::string eip55_checksum(const std::string &hex_addr)
std::string ethereum_address(const fast::Point &pubkey)
std::string ethereum_address_raw(const fast::Point &pubkey)