-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement zilliqa bech32 address (#445)
* implement zilliqa bech32 address * improve code coverage * make cocodacy happy * Fix tests * test keyhash * Add a test case from zil js lib
- Loading branch information
1 parent
32310c0
commit bdfb93b
Showing
23 changed files
with
126 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
exclude_paths: | ||
- 'codegen/**' | ||
- 'tools/**' | ||
- 'trezor-crypto/**' |
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 |
---|---|---|
@@ -1,42 +1,7 @@ | ||
#include "Address.h" | ||
#include "AddressChecksum.h" | ||
#include "stdint.h" | ||
#include "../HexCoding.h" | ||
|
||
using namespace TW::Zilliqa; | ||
|
||
bool Address::isValid(const std::string& string) { | ||
if (string.size() != 42 || string[0] != '0' || string[1] != 'x') { | ||
return false; | ||
} | ||
const auto data = parse_hex(string); | ||
return Address::isValid(data); | ||
} | ||
|
||
Address::Address(const std::string& string) { | ||
if (!isValid(string)) { | ||
throw std::invalid_argument("Invalid address data"); | ||
} | ||
const auto data = parse_hex(string); | ||
std::copy(data.begin(), data.end(), bytes.begin()); | ||
} | ||
// Copyright © 2017-2019 Trust. | ||
// | ||
// 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. | ||
|
||
Address::Address(const PublicKey& publicKey) { | ||
if (publicKey.type != TWPublicKeyTypeSECP256k1) { | ||
throw std::invalid_argument("Ziliqa::Address needs SECP256k1 public key"); | ||
} | ||
const auto data = | ||
publicKey.hash({}, static_cast<Data (*)(const byte*, const byte*)>(Hash::sha256), false); | ||
std::copy(data.end() - Address::size, data.end(), bytes.begin()); | ||
} | ||
|
||
Address::Address(const Data& data) { | ||
if (!isValid(data)) { | ||
throw std::invalid_argument("Invalid address data"); | ||
} | ||
std::copy(data.begin(), data.end(), bytes.begin()); | ||
} | ||
|
||
std::string Address::string() const { | ||
return checksumed(*this); | ||
} | ||
#include "Address.h" |
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
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
Oops, something went wrong.