Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return Eth addresses with EIP-55 checksum applied #2024

Merged
merged 3 commits into from
Jun 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/key_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,22 @@ class DestinationEncoder

std::string operator()(const WitnessV16EthHash& id) const
{
prasannavl marked this conversation as resolved.
Show resolved Hide resolved
return ETH_ADDR_PREFIX + HexStr(id);
// Raw addr = ETH_ADDR_PREFIX + HexStr(id);
// Produce ETH checksum address: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md
const auto address = id.ToString();
std::vector<unsigned char> input(address.begin(), address.end());
std::vector<unsigned char> output;
sha3(input, output);
const auto hashedAddress = HexStr(output);
std::string result;
for (size_t i{}; i < address.size(); ++i) {
if (std::isdigit(address[i]) || hashedAddress[i] < '8') {
result += address[i];
} else {
result += std::toupper(address[i]);
}
}
return ETH_ADDR_PREFIX + result;
}

std::string operator()(const CNoDestination& no) const { return {}; }
Expand Down