1
// Copyright © 2017-2020 Trust Wallet.
2
//
3
// This file is part of Trust. The full Trust copyright notice, including
4
// terms governing use, modification, and redistribution, is contained in the
5
// file LICENSE at the root of the source code distribution tree.
6

7
#include "Address.h"
8
#include "../Base58.h"
9
#include <TrezorCrypto/ecdsa.h>
10

11
using namespace TW::Ripple;
12

13 1
bool Address::isValid(const std::string& string) {
14 1
    const auto decoded = Base58::ripple.decodeCheck(string);
15 1
    if (decoded.size() != Address::size) {
16 1
        return false;
17
    }
18 1
    return true;
19
}
20

21 1
Address::Address(const std::string& string) {
22 1
    const auto decoded = Base58::ripple.decodeCheck(string);
23 1
    if (decoded.size() != Address::size) {
24 1
        throw std::invalid_argument("Invalid address string");
25
    }
26 1
    std::copy(decoded.begin(), decoded.end(), bytes.begin());
27
}
28

29 1
Address::Address(const PublicKey& publicKey) {
30
    /// see type prefix: https://developers.ripple.com/base58-encodings.html
31 1
    bytes[0] = 0x00;
32 1
    ecdsa_get_pubkeyhash(publicKey.bytes.data(), HASHER_SHA2_RIPEMD, bytes.data() + 1);
33
}
34

35 1
std::string Address::string() const {
36 1
    return Base58::ripple.encodeCheck(bytes);
37
}

Read our documentation on viewing source code .

Loading