Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools for working with deterministic wallets.
- Loading branch information
Showing
9 changed files
with
247 additions
and
0 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
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,11 @@ | ||
CXXFLAGS=$(shell pkg-config --cflags libbitcoin) | ||
LIBS=$(shell pkg-config --libs libbitcoin) | ||
|
||
default: genpriv | ||
|
||
main.o: main.cpp | ||
g++ -c main.cpp -o main.o $(CXXFLAGS) | ||
|
||
genpriv: main.o | ||
g++ -o genpriv main.o $(LIBS) | ||
|
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,57 @@ | ||
#include <boost/lexical_cast.hpp> | ||
#include <boost/algorithm/string.hpp> | ||
#include <bitcoin/bitcoin.hpp> | ||
using namespace bc; | ||
|
||
std::string dump_file(std::istream& in_file) | ||
{ | ||
std::istreambuf_iterator<char> it(in_file); | ||
std::istreambuf_iterator<char> end; | ||
return std::string(it, end); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
if (argc != 2 && argc != 3) | ||
{ | ||
std::cerr << "Usage: genpriv N [CHANGE]" << std::endl; | ||
return -1; | ||
} | ||
size_t n; | ||
try | ||
{ | ||
n = boost::lexical_cast<size_t>(argv[1]); | ||
} | ||
catch (const boost::bad_lexical_cast&) | ||
{ | ||
std::cerr << "genpriv: Bad N provided" << std::endl; | ||
return -1; | ||
} | ||
bool for_change = false; | ||
if (argc == 3) | ||
{ | ||
std::string change_str = argv[2]; | ||
boost::algorithm::to_lower(change_str); | ||
if (change_str == "true" || change_str == "1") | ||
for_change = true; | ||
} | ||
std::string seed = dump_file(std::cin); | ||
boost::algorithm::trim(seed); | ||
deterministic_wallet wallet; | ||
if (!wallet.set_seed(seed)) | ||
{ | ||
std::cerr << "genpriv: Error setting seed" << std::endl; | ||
return -1; | ||
} | ||
secret_parameter secret = wallet.generate_secret(n, for_change); | ||
elliptic_curve_key key; | ||
if (!key.set_secret(secret)) | ||
{ | ||
std::cerr << "genpriv: Internal error setting secret" << std::endl; | ||
return -1; | ||
} | ||
private_data raw_private_key = key.private_key(); | ||
std::cout << std::string(raw_private_key.begin(), raw_private_key.end()); | ||
return 0; | ||
} | ||
|
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,11 @@ | ||
CXXFLAGS=$(shell pkg-config --cflags libbitcoin) | ||
LIBS=$(shell pkg-config --libs libbitcoin) | ||
|
||
default: genpub | ||
|
||
main.o: main.cpp | ||
g++ -c main.cpp -o main.o $(CXXFLAGS) | ||
|
||
genpub: main.o | ||
g++ -o genpub main.o $(LIBS) | ||
|
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,66 @@ | ||
#include <boost/lexical_cast.hpp> | ||
#include <boost/algorithm/string.hpp> | ||
#include <bitcoin/bitcoin.hpp> | ||
using namespace bc; | ||
|
||
std::string dump_file(std::istream& in_file) | ||
{ | ||
std::istreambuf_iterator<char> it(in_file); | ||
std::istreambuf_iterator<char> end; | ||
return std::string(it, end); | ||
} | ||
|
||
data_chunk read_mpk_data() | ||
{ | ||
std::string raw_mpk = dump_file(std::cin); | ||
return data_chunk(raw_mpk.begin(), raw_mpk.end()); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
if (argc != 2 && argc != 3) | ||
{ | ||
std::cerr << "Usage: genpub N [CHANGE]" << std::endl; | ||
return -1; | ||
} | ||
size_t n; | ||
try | ||
{ | ||
n = boost::lexical_cast<size_t>(argv[1]); | ||
} | ||
catch (const boost::bad_lexical_cast&) | ||
{ | ||
std::cerr << "genpub: Bad N provided" << std::endl; | ||
return -1; | ||
} | ||
bool for_change = false; | ||
if (argc == 3) | ||
{ | ||
std::string change_str = argv[2]; | ||
boost::algorithm::to_lower(change_str); | ||
if (change_str == "true" || change_str == "1") | ||
for_change = true; | ||
} | ||
const data_chunk mpk = read_mpk_data(); | ||
if (mpk.empty()) | ||
{ | ||
std::cerr << "genpub: Empty master public key" << std::endl; | ||
return -1; | ||
} | ||
deterministic_wallet wallet; | ||
if (!wallet.set_master_public_key(mpk)) | ||
{ | ||
std::cerr << "genpub: Error setting master public key" << std::endl; | ||
return -1; | ||
} | ||
data_chunk pubkey = wallet.generate_public_key(n, for_change); | ||
payment_address addr; | ||
if (!set_public_key(addr, pubkey)) | ||
{ | ||
std::cerr << "genpub: Internal error setting pubkey" << std::endl; | ||
return -1; | ||
} | ||
std::cout << addr.encoded() << std::endl; | ||
return 0; | ||
} | ||
|
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,11 @@ | ||
CXXFLAGS=$(shell pkg-config --cflags libbitcoin) | ||
LIBS=$(shell pkg-config --libs libbitcoin) | ||
|
||
default: mpk | ||
|
||
main.o: main.cpp | ||
g++ -c main.cpp -o main.o $(CXXFLAGS) | ||
|
||
mpk: main.o | ||
g++ -o mpk main.o $(LIBS) | ||
|
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,26 @@ | ||
#include <boost/algorithm/string.hpp> | ||
#include <bitcoin/bitcoin.hpp> | ||
using namespace bc; | ||
|
||
std::string dump_file(std::istream& in_file) | ||
{ | ||
std::istreambuf_iterator<char> it(in_file); | ||
std::istreambuf_iterator<char> end; | ||
return std::string(it, end); | ||
} | ||
|
||
int main() | ||
{ | ||
std::string seed = dump_file(std::cin); | ||
boost::algorithm::trim(seed); | ||
deterministic_wallet wallet; | ||
if (!wallet.set_seed(seed)) | ||
{ | ||
std::cerr << "mpk: Error setting seed" << std::endl; | ||
return -1; | ||
} | ||
const data_chunk mpk = wallet.master_public_key(); | ||
std::cout << std::string(mpk.begin(), mpk.end()) << std::endl; | ||
return 0; | ||
} | ||
|
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,11 @@ | ||
CXXFLAGS=$(shell pkg-config --cflags libbitcoin) | ||
LIBS=$(shell pkg-config --libs libbitcoin) | ||
|
||
default: newseed | ||
|
||
main.o: main.cpp | ||
g++ -c main.cpp -o main.o $(CXXFLAGS) | ||
|
||
newseed: main.o | ||
g++ -o newseed main.o $(LIBS) | ||
|
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,11 @@ | ||
#include <bitcoin/bitcoin.hpp> | ||
using namespace bc; | ||
|
||
int main() | ||
{ | ||
deterministic_wallet wallet; | ||
wallet.new_seed(); | ||
std::cout << wallet.seed() << std::endl; | ||
return 0; | ||
} | ||
|