The send screen labelled any prefix+length match as a "Valid" address, so a mistyped address that still matched the pattern passed the gate. Add pure, offline checksum validation — Base58Check (transparent R-addresses) and Bech32 (Sapling zs-addresses) — and require it in the validity check. Both verifiers are version-byte/HRP agnostic (the HRP is taken from the string, the Base58 checksum is chain-independent), so a correct implementation never rejects a genuine address while catching transcription errors. Works for both build variants (no daemon round-trip), unit-tested against standard BIP173 / Base58Check vectors. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
29 lines
1.1 KiB
C++
29 lines
1.1 KiB
C++
// DragonX Wallet - ImGui Edition
|
|
// Copyright 2024-2026 The Hush Developers
|
|
// Released under the GPLv3
|
|
//
|
|
// address_validation.h — pure, offline checksum validation for wallet addresses.
|
|
// These verify the *encoding checksum* (Base58Check / Bech32), which is independent
|
|
// of the chain's version bytes / HRP, so a correct implementation never rejects a
|
|
// genuinely-valid address while still catching transcription errors. Used to make
|
|
// the send screen's "Valid address" label/gate reflect reality instead of a bare
|
|
// prefix+length heuristic. No network, no daemon — safe for both build variants.
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
namespace dragonx {
|
|
namespace util {
|
|
|
|
// True if `s` decodes as Base58Check with a valid 4-byte double-SHA256 checksum
|
|
// (transparent R-addresses). Version-byte agnostic by design.
|
|
bool isValidBase58Check(const std::string& s);
|
|
|
|
// True if `s` is a valid Bech32 string (Sapling zs-addresses). The HRP is taken
|
|
// from the string itself and folded into the checksum, so no HRP is hardcoded.
|
|
bool isValidBech32(const std::string& s);
|
|
|
|
} // namespace util
|
|
} // namespace dragonx
|