10

Handling a user's input in which I want to make sure that he used a valid monero address.

Bitcoin has all these rules found here and I found something similar for ethereum as well.

I was wondering if Monero has some general rules I can be checking the user's input to check the address' validity.

2 Answers2

7

I believe that you will find an answer here, although the question was asked in a different way.

Practically, you'd verify the network byte, length, address encoding and checksum. For implementation details, I suppose you could inspect source of this page (javascript), or go to the monero github repo.

JollyMort
  • 20,004
  • 3
  • 49
  • 105
1
public function verify_checksum($address)
    {
        $decoded = $this->base58->decode($address);
        $checksum = substr($decoded, -8);
        $test = substr($decoded, 0, 130);
        $checksum_hash = $this->keccak_256(substr($decoded, 0, 130));
        $calculated = substr($checksum_hash, 0, 8);
        if($checksum == $calculated){
            return true;
        }
        else
        return false;
    }
Jeff Bezos
  • 11
  • 1