Skip to content
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

RPC "sign" (hash, block) #1241

Merged
merged 35 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cca3394
RPC sign
SergiySW Sep 27, 2018
b6ae670
Typo
SergiySW Sep 27, 2018
204579e
Add test for RPC sign
SergiySW Sep 27, 2018
4aa6925
block_impl
SergiySW Sep 27, 2018
5e0c37e
Add required header
SergiySW Sep 27, 2018
71a36d2
Split sign_hash & sign_block
SergiySW Sep 27, 2018
81d5160
Headers order
SergiySW Sep 27, 2018
8191ef8
Allow blocks w/o signature & hash in RPC block_hash
SergiySW Sep 27, 2018
0cf2471
Merge remote-tracking branch 'upstream/master' into rpc_sign
SergiySW Oct 6, 2018
7d2624b
Prepare for master merge
SergiySW Nov 30, 2018
f16137f
Merge remote-tracking branch 'upstream/master' into rpc_sign
SergiySW Nov 30, 2018
fd0c087
Test for RPC sign
SergiySW Nov 30, 2018
48652b8
Merge remote-tracking branch 'upstream/master' into rpc_sign
SergiySW Dec 27, 2018
f2cf376
Formatting
SergiySW Dec 28, 2018
de0e686
system.io_ctx
SergiySW Dec 28, 2018
4f5e5c3
merge upstream/master
SergiySW Dec 28, 2018
5c6fbc2
Merge remote-tracking branch 'upstream/master' into rpc_sign
SergiySW Dec 29, 2018
6eccccb
Update test_response
SergiySW Dec 29, 2018
32114af
merge upstream/master
SergiySW Jan 16, 2019
5db35e7
Unified RPC "sign"
SergiySW Jan 16, 2019
4217762
Merge remote-tracking branch 'upstream/master' into rpc_sign
SergiySW Jan 17, 2019
defa165
Merge remote-tracking branch 'upstream/master' into rpc_sign
SergiySW Jan 17, 2019
33f315d
Config option enable_sign_hash
SergiySW Jan 17, 2019
7d5bb88
Fix
SergiySW Jan 17, 2019
63ffc86
Formatting
SergiySW Jan 18, 2019
b7c7896
Merge remote-tracking branch 'upstream/master' into rpc_sign
SergiySW Jan 20, 2019
181e178
Merge remote-tracking branch 'upstream/master' into rpc_sign
SergiySW Jan 23, 2019
22cedf6
Merge remote-tracking branch 'upstream/master' into rpc_sign
SergiySW Jan 23, 2019
3531d86
Merge remote-tracking branch 'upstream/master' into rpc_sign
SergiySW Jan 24, 2019
897fab1
Fix rpc_config
SergiySW Jan 24, 2019
704fa66
explicitly set signature_work_required value for block_impl ()
SergiySW Jan 24, 2019
91ead95
Merge remote-tracking branch 'upstream/master' into rpc_sign
SergiySW Jan 26, 2019
95519a0
Merge remote-tracking branch 'upstream/master' into rpc_sign
SergiySW Jan 27, 2019
68ea895
Fix transactions
SergiySW Jan 27, 2019
a9d9b30
Merge remote-tracking branch 'upstream/master' into rpc_sign
SergiySW Jan 28, 2019
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
67 changes: 67 additions & 0 deletions nano/core_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4135,3 +4135,70 @@ TEST (rpc, node_id_delete)
nano::keypair node_id (system.nodes[0]->store.get_node_id (transaction));
ASSERT_NE (node_id.pub.to_string (), system.nodes[0]->node_id.pub.to_string ());
}

TEST (rpc, sign_hash)
{
nano::system system (24000, 1);
nano::keypair key;
auto & node1 (*system.nodes[0]);
nano::state_block send (nano::genesis_account, node1.latest (nano::test_genesis_key.pub), nano::genesis_account, nano::genesis_amount - nano::Gxrb_ratio, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::rpc rpc (system.io_ctx, node1, nano::rpc_config (true));
rpc.start ();
boost::property_tree::ptree request;
request.put ("action", "sign");
request.put ("hash", send.hash ().to_string ());
request.put ("key", key.prv.data.to_string ());
test_response response (request, rpc, system.io_ctx);
while (response.status == 0)
{
system.poll ();
}
ASSERT_EQ (200, response.status);
std::error_code ec (nano::error_rpc::sign_hash_disabled);
ASSERT_EQ (response.json.get<std::string> ("error"), ec.message ());
rpc.config.enable_sign_hash = true;
test_response response2 (request, rpc, system.io_ctx);
while (response2.status == 0)
{
system.poll ();
}
ASSERT_EQ (200, response2.status);
nano::signature signature;
std::string signature_text (response2.json.get<std::string> ("signature"));
ASSERT_FALSE (signature.decode_hex (signature_text));
ASSERT_FALSE (nano::validate_message (key.pub, send.hash (), signature));
}

TEST (rpc, sign_block)
{
nano::system system (24000, 1);
nano::keypair key;
auto & node1 (*system.nodes[0]);
nano::state_block send (nano::genesis_account, node1.latest (nano::test_genesis_key.pub), nano::genesis_account, nano::genesis_amount - nano::Gxrb_ratio, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::rpc rpc (system.io_ctx, node1, nano::rpc_config (true));
rpc.start ();
boost::property_tree::ptree request;
request.put ("action", "sign");
system.wallet (0)->insert_adhoc (key.prv);
std::string wallet;
system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet);
request.put ("wallet", wallet);
request.put ("account", key.pub.to_account ());
std::string json;
send.serialize_json (json);
request.put ("block", json);
test_response response (request, rpc, system.io_ctx);
while (response.status == 0)
{
system.poll ();
}
ASSERT_EQ (200, response.status);
auto contents (response.json.get<std::string> ("block"));
boost::property_tree::ptree block_l;
std::stringstream block_stream (contents);
boost::property_tree::read_json (block_stream, block_l);
auto block (nano::deserialize_block_json (block_l));
ASSERT_FALSE (nano::validate_message (key.pub, send.hash (), block->block_signature ()));
ASSERT_NE (block->block_signature (), send.block_signature ());
ASSERT_EQ (block->hash (), send.hash ());
}
2 changes: 2 additions & 0 deletions nano/lib/errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ std::string nano::error_rpc_messages::message (int ev) const
return "Unable to create transaction account";
case nano::error_rpc::rpc_control_disabled:
return "RPC control is disabled";
case nano::error_rpc::sign_hash_disabled:
return "Signing by block hash is disabled";
case nano::error_rpc::source_not_found:
return "Source not found";
}
Expand Down
1 change: 1 addition & 0 deletions nano/lib/errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ enum class error_rpc
payment_account_balance,
payment_unable_create_account,
rpc_control_disabled,
sign_hash_disabled,
source_not_found
};

Expand Down
Loading