Error message returned for an invalid HRP string for a correctly encoded bech32 addresses was incorrect. It was returning 'Not a valid Bech32 or Base58 encoding'.
but it should return “Invalid or unsupported prefix for Segwit (Bech32) address (expected …, got …).”
The check in the DecodeDestination
function that returns "Invalid or unsupported prefix for Segwit (Bech32) address (expected ..., got ...)."
was not reachable for any address, as the HRP was checked at the start of the DecodeDestination
function, and if it didn’t match, then the address was assumed to be base58 or an invalid encoding, even if it was valid bech32 but with incorrect HRP.
This fix checks if the address is a valid bech32 encoding, and then only if an invalid encoding AND incorrect HRP, then attempts to verify a base58 encoding.