Skip to content

Div by 256 -> shift #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions src/ga_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <nlohmann/json.hpp>

#include "assertion.hpp"
Expand Down Expand Up @@ -66,20 +65,6 @@ namespace green {
static const std::array<const std::string, 4> TX_NTFY_FIELDS
= { "subaccounts", "txhash", "value", TXN_OPTIONAL };

// TODO: too slow. lacks validation.
static std::array<unsigned char, SHA256_LEN> uint256_to_base256(const std::string& input)
{
constexpr size_t base = 256;

std::array<unsigned char, SHA256_LEN> repr{};
size_t i = repr.size() - 1;
for (boost::multiprecision::checked_uint256_t num(input); num; num = num / base, --i) {
repr[i] = static_cast<unsigned char>(num % base);
}

return repr;
}

static bool ignore_tx_notification(const nlohmann::json& details)
{
for (const auto& item : details.items()) {
Expand Down Expand Up @@ -351,19 +336,6 @@ namespace green {
return m_nlocktimes;
}

std::pair<std::string, std::string> ga_session::sign_challenge(
session_impl::locker_t& locker, const std::string& challenge)
{
GDK_RUNTIME_ASSERT(locker.owns_lock());
GDK_RUNTIME_ASSERT(m_signer);

const auto path_bytes = get_random_bytes<8>();
const auto path = bytes_to_bip32_path(path_bytes);
const auto challenge_hash = uint256_to_base256(challenge);

return { sig_only_to_der_hex(m_signer->ecdsa_sign(path, challenge_hash)), b2h(path_bytes) };
}

void ga_session::set_fee_estimates(session_impl::locker_t& locker, const nlohmann::json& fee_estimates)
{
GDK_RUNTIME_ASSERT(locker.owns_lock());
Expand Down
2 changes: 0 additions & 2 deletions src/ga_session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ namespace green {
const std::string& name, const std::string& receiving_id, const std::optional<xpub_hdkey>& recovery_key,
uint32_t required_ca);

std::pair<std::string, std::string> sign_challenge(locker_t& locker, const std::string& challenge);

void set_fee_estimates(locker_t& locker, const nlohmann::json& fee_estimates);

nlohmann::json refresh_http_data(const std::string& page, const std::string& key, bool refresh);
Expand Down