-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 1. Add XRP X-address 2. Add Sourcetrail project 3. Other minor fixes * Fix codacy warning
- Loading branch information
1 parent
b48a437
commit 25ef9f8
Showing
23 changed files
with
377 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright © 2017-2019 Trust Wallet. | ||
// | ||
// This file is part of Trust. The full Trust copyright notice, including | ||
// terms governing use, modification, and redistribution, is contained in the | ||
// file LICENSE at the root of the source code distribution tree. | ||
|
||
#pragma once | ||
|
||
#include "TWBase.h" | ||
#include "TWData.h" | ||
#include "TWHRP.h" | ||
#include "TWString.h" | ||
|
||
TW_EXTERN_C_BEGIN | ||
|
||
struct TWPublicKey; | ||
|
||
/// Represents a Ripple X-address. | ||
TW_EXPORT_CLASS | ||
struct TWRippleXAddress; | ||
|
||
/// Compares two addresses for equality. | ||
TW_EXPORT_STATIC_METHOD | ||
bool TWRippleXAddressEqual(struct TWRippleXAddress *_Nonnull lhs, struct TWRippleXAddress *_Nonnull rhs); | ||
|
||
/// Determines if the string is a valid Ripple address. | ||
TW_EXPORT_STATIC_METHOD | ||
bool TWRippleXAddressIsValidString(TWString *_Nonnull string); | ||
|
||
/// Creates an address from a string representaion. | ||
TW_EXPORT_STATIC_METHOD | ||
struct TWRippleXAddress *_Nullable TWRippleXAddressCreateWithString(TWString *_Nonnull string); | ||
|
||
/// Creates an address from a public key and destination tag. | ||
TW_EXPORT_STATIC_METHOD | ||
struct TWRippleXAddress *_Nonnull TWRippleXAddressCreateWithPublicKey(struct TWPublicKey *_Nonnull publicKey, uint32_t tag); | ||
|
||
TW_EXPORT_METHOD | ||
void TWRippleXAddressDelete(struct TWRippleXAddress *_Nonnull address); | ||
|
||
/// Returns the address string representation. | ||
TW_EXPORT_PROPERTY | ||
TWString *_Nonnull TWRippleXAddressDescription(struct TWRippleXAddress *_Nonnull address); | ||
|
||
/// Returns the destination tag. | ||
TW_EXPORT_PROPERTY | ||
uint32_t TWRippleXAddressTag(struct TWRippleXAddress *_Nonnull address); | ||
|
||
TW_EXTERN_C_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright © 2017-2019 Trust Wallet. | ||
// | ||
// This file is part of Trust. The full Trust copyright notice, including | ||
// terms governing use, modification, and redistribution, is contained in the | ||
// file LICENSE at the root of the source code distribution tree. | ||
|
||
#include "XAddress.h" | ||
|
||
#include "../Base58.h" | ||
#include "../BinaryCoding.h" | ||
#include "../Data.h" | ||
#include <TrezorCrypto/ecdsa.h> | ||
|
||
using namespace TW; | ||
using namespace TW::Ripple; | ||
|
||
const Data prefixMainnet = {0x05, 0x44}; | ||
|
||
bool XAddress::isValid(const std::string& string) { | ||
const auto decoded = Base58::ripple.decodeCheck(string); | ||
if (decoded.size() != XAddress::size) { | ||
return false; | ||
} | ||
if(!std::equal(decoded.begin(), decoded.begin() + 2, prefixMainnet.begin())) { | ||
return false; | ||
} | ||
if (!(decoded[22] == byte(TagFlag::none) || decoded[22] == byte(TagFlag::classic))) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
XAddress::XAddress(const std::string& string) { | ||
if (!XAddress::isValid(string)) { | ||
throw std::invalid_argument("Invalid address string"); | ||
} | ||
const auto decoded = Base58::ripple.decodeCheck(string); | ||
std::copy(decoded.begin() + prefixMainnet.size(), decoded.begin() + prefixMainnet.size() + XAddress::keyHashSize, bytes.begin()); | ||
if (decoded[22] == byte(TagFlag::classic)) { | ||
tag = decode32LE(Data(decoded.end() - 8, decoded.end() - 4).data()); | ||
} else if (decoded[22] == byte(TagFlag::none)) { | ||
flag = TagFlag::none; | ||
} else { | ||
throw std::invalid_argument("Invalid flag"); | ||
} | ||
} | ||
|
||
XAddress::XAddress(const PublicKey& publicKey, const uint32_t destination): tag(destination) { | ||
ecdsa_get_pubkeyhash(publicKey.bytes.data(), HASHER_SHA2_RIPEMD, bytes.data()); | ||
} | ||
|
||
std::string XAddress::string() const { | ||
/// see https://github.com/ripple/ripple-address-codec/blob/master/src/index.ts | ||
/// base58check(2 bytes prefix + 20 bytes keyhash + 1 byte flag + 4 bytes + 32bit tag + 4 bytes reserved) | ||
Data result; | ||
append(result, prefixMainnet); | ||
append(result, Data{bytes.begin(), bytes.end()}); | ||
append(result, byte(flag)); | ||
encode32LE(tag, result); | ||
append(result, Data{0x00, 0x00, 0x00, 0x00}); | ||
return Base58::ripple.encodeCheck(result); | ||
} |
Oops, something went wrong.