2015-08-28 18:46:03 +00:00
|
|
|
/*
|
2015-10-12 17:48:40 +00:00
|
|
|
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
|
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* The MIT License
|
2015-10-12 17:48:40 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2015-10-12 17:48:40 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
2015-10-12 17:02:59 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
* THE SOFTWARE.
|
2015-08-28 18:46:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include <fc/crypto/elliptic.hpp>
|
|
|
|
|
#include <fc/io/json.hpp>
|
|
|
|
|
|
|
|
|
|
#include <graphene/chain/protocol/address.hpp>
|
|
|
|
|
#include <graphene/chain/protocol/types.hpp>
|
|
|
|
|
#include <graphene/utilities/key_conversion.hpp>
|
|
|
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
|
#include <csignal>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
int main( int argc, char** argv )
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
std::string dev_key_prefix;
|
2015-09-18 20:47:58 +00:00
|
|
|
bool need_help = false;
|
2015-08-28 18:46:03 +00:00
|
|
|
if( argc < 2 )
|
|
|
|
|
need_help = true;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dev_key_prefix = argv[1];
|
|
|
|
|
if( (dev_key_prefix == "-h")
|
|
|
|
|
|| (dev_key_prefix == "--help")
|
|
|
|
|
)
|
|
|
|
|
need_help = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( need_help )
|
|
|
|
|
{
|
2015-09-18 20:47:58 +00:00
|
|
|
std::cerr << argc << " " << argv[1] << "\n";
|
2015-08-28 18:46:03 +00:00
|
|
|
std::cerr << "get-dev-key <prefix> <suffix> ...\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"example:\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"get-dev-key wxyz- owner-5 active-7 balance-9 wit-block-signing-3 wit-owner-5 wit-active-33\n"
|
|
|
|
|
"get-dev-key wxyz- wit-block-signing-0:101\n"
|
|
|
|
|
"\n";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool comma = false;
|
|
|
|
|
|
2018-03-19 22:23:59 +00:00
|
|
|
auto show_key = [&comma]( const fc::ecc::private_key& priv_key )
|
2015-08-28 18:46:03 +00:00
|
|
|
{
|
2018-03-19 22:23:59 +00:00
|
|
|
fc::limited_mutable_variant_object mvo(5);
|
2015-08-28 18:46:03 +00:00
|
|
|
graphene::chain::public_key_type pub_key = priv_key.get_public_key();
|
|
|
|
|
mvo( "private_key", graphene::utilities::key_to_wif( priv_key ) )
|
|
|
|
|
( "public_key", std::string( pub_key ) )
|
|
|
|
|
( "address", graphene::chain::address( pub_key ) )
|
|
|
|
|
;
|
|
|
|
|
if( comma )
|
|
|
|
|
std::cout << ",\n";
|
2018-03-19 22:23:59 +00:00
|
|
|
std::cout << fc::json::to_string( fc::mutable_variant_object(mvo) );
|
2015-08-28 18:46:03 +00:00
|
|
|
comma = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::cout << "[";
|
|
|
|
|
|
|
|
|
|
for( int i=2; i<argc; i++ )
|
|
|
|
|
{
|
|
|
|
|
std::string arg = argv[i];
|
|
|
|
|
std::string prefix;
|
2018-03-19 22:23:59 +00:00
|
|
|
int lep = -1, rep = -1;
|
2015-08-28 18:46:03 +00:00
|
|
|
auto dash_pos = arg.rfind('-');
|
|
|
|
|
if( dash_pos != string::npos )
|
|
|
|
|
{
|
|
|
|
|
std::string lhs = arg.substr( 0, dash_pos+1 );
|
|
|
|
|
std::string rhs = arg.substr( dash_pos+1 );
|
|
|
|
|
auto colon_pos = rhs.find(':');
|
|
|
|
|
if( colon_pos != string::npos )
|
|
|
|
|
{
|
|
|
|
|
prefix = lhs;
|
|
|
|
|
lep = std::stoi( rhs.substr( 0, colon_pos ) );
|
|
|
|
|
rep = std::stoi( rhs.substr( colon_pos+1 ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if( lep >= 0 )
|
|
|
|
|
{
|
|
|
|
|
for( int k=lep; k<rep; k++ )
|
|
|
|
|
{
|
|
|
|
|
std::string s = dev_key_prefix + prefix + std::to_string(k);
|
|
|
|
|
show_key( fc::ecc::private_key::regenerate( fc::sha256::hash( s ) ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
show_key( fc::ecc::private_key::regenerate( fc::sha256::hash( dev_key_prefix + arg ) ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
std::cout << "]\n";
|
|
|
|
|
}
|
|
|
|
|
catch ( const fc::exception& e )
|
|
|
|
|
{
|
|
|
|
|
std::cout << e.to_detail_string() << "\n";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|