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

2 Answers 2

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.

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;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.