You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Converts a range of bytes to a hexadecimal string representation.
template
inline std::string hex(const Iter begin, const Iter end) {
static constexpr std::array<char, 16> hexmap = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
std::string result;
result.reserve((end - begin) * 2);
for (auto it = begin; it < end; ++it) {
auto val = static_cast<uint8_t>(*it);
result.push_back(hexmap[val >> 4]);
result.push_back(hexmap[val & 0x0f]);
}
return result;
}
/// Converts a collection of bytes to a hexadecimal string representation.
template
inline std::string hex(const T& collection) {
return hex(std::begin(collection), std::end(collection));
}
/// same as hex, with 0x prefix
template
inline std::string hexEncoded(const T& collection) {
return hex(std::begin(collection), std::end(collection)).insert(0, "0x");
}
/// Converts a uint64_t value to a hexadecimal string.
inline std::string hex(uint64_t value) {
auto bytes = reinterpret_cast<const uint8_t*>(&value);
return hex(std::reverse_iterator<const uint8_t*>(bytes + sizeof(value)),
std::reverse_iterator<const uint8_t*>(bytes));
}
/// Parses a string of hexadecimal values.
///
/// \returns the array or parsed bytes or an empty array if the string is not
/// valid hexadecimal.
template
inline TW::Data parse_hex(const Iter begin, const Iter end) {
auto it = begin;
/// Parses a string of hexadecimal values.
///
/// \returns the array or parsed bytes or an empty array if the string is not
/// valid hexadecimal.
inline TW::Data parse_hex(const std::string& string) {
return parse_hex( string.begin(), string.end() );
}
void privateKeyToResult( TWPrivateKey* priKey, string& res_out)
{
// take the key, but may need to take extension as well
res_out = hex(priKey->impl.bytes);
if (priKey->impl.extensionBytes.size() > 0) {
res_out += hex(priKey->impl.extensionBytes);
res_out += hex(priKey->impl.chainCodeBytes);
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
#include "Bitcoin/Address.h"
#include "Bitcoin/OutPoint.h"
#include "Bitcoin/Script.h"
#include "Bitcoin/Transaction.h"
#include "Bitcoin/TransactionBuilder.h"
#include "Bitcoin/TransactionSigner.h"
#include "Bitcoin/SigHashType.h"
#include <TrustWalletCore/TWCoinType.h>
#include <TrustWalletCore/TWAnySigner.h>
#include <TrustWalletCore/TWCoinTypeConfiguration.h>
#include <TrustWalletCore/TWHDWallet.h>
#include <TrustWalletCore/TWPrivateKey.h>
#include <TrustWalletCore/TWPublicKey.h>
#include <TrustWalletCore/TWBitcoinScript.h>
#include <TrustWalletCore/TWString.h>
#include <TrustWalletCore/TWData.h>
#include <gtest/gtest.h>
// #include <google/protobuf/util/json_util.h>
#include
#include
#include "HexCoding.h"
#include "PrivateKey.h"
#include "PublicKey.h"
#include "Coin.h"
#include "uint256.h"
// #include "Ethereum/Transaction.h"
// #include "Ethereum/Signer.h"
#include <boost/lexical_cast.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std ;
/// Converts a range of bytes to a hexadecimal string representation.
template
inline std::string hex(const Iter begin, const Iter end) {
static constexpr std::array<char, 16> hexmap = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
}
/// Converts a collection of bytes to a hexadecimal string representation.
template
inline std::string hex(const T& collection) {
return hex(std::begin(collection), std::end(collection));
}
/// same as hex, with 0x prefix
template
inline std::string hexEncoded(const T& collection) {
return hex(std::begin(collection), std::end(collection)).insert(0, "0x");
}
/// Converts a
uint64_t
value to a hexadecimal string.inline std::string hex(uint64_t value) {
auto bytes = reinterpret_cast<const uint8_t*>(&value);
return hex(std::reverse_iterator<const uint8_t*>(bytes + sizeof(value)),
std::reverse_iterator<const uint8_t*>(bytes));
}
/// Parses a string of hexadecimal values.
///
/// \returns the array or parsed bytes or an empty array if the string is not
/// valid hexadecimal.
template
inline TW::Data parse_hex(const Iter begin, const Iter end) {
auto it = begin;
}
/// Parses a string of hexadecimal values.
///
/// \returns the array or parsed bytes or an empty array if the string is not
/// valid hexadecimal.
inline TW::Data parse_hex(const std::string& string) {
return parse_hex( string.begin(), string.end() );
}
void privateKeyToResult( TWPrivateKey* priKey, string& res_out)
{
// take the key, but may need to take extension as well
res_out = hex(priKey->impl.bytes);
if (priKey->impl.extensionBytes.size() > 0) {
res_out += hex(priKey->impl.extensionBytes);
res_out += hex(priKey->impl.chainCodeBytes);
}
}
void pubPri(const TWCoinType coinType, const string& PrivateKey, string& PublicKey)
{
TW::Data privDat;
try {
privDat = parse_hex(PrivateKey) ;
auto priv = TW::PrivateKey(privDat) ;
auto pub = priv.getPublicKey((TWPublicKeyType)TW::publicKeyType( coinType ));
PublicKey = hex(pub.bytes);
}
int main() {
}
Beta Was this translation helpful? Give feedback.
All reactions