summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmir Taaki <genjix@riseup.net>2014-05-08 19:50:14 (GMT)
committer Amir Taaki <genjix@riseup.net>2014-05-08 19:50:14 (GMT)
commitd7cc8d408379e70fc01e57f4f5d53eda410a181f (patch)
treebc2c223657eb19fe0fbc93dc639c48691ee56e60
parent24eb32df703f41bf6c6c8b238f11347161606b37 (diff)
added stealth-newkey command.
-rw-r--r--src/Makefile.am5
-rw-r--r--src/mktx.cpp13
-rw-r--r--src/stealth-newkey.cpp22
-rwxr-xr-xsrc/sx.py11
-rw-r--r--src/util.hpp10
5 files changed, 49 insertions, 12 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index e9f890f..c423aa3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,7 +10,7 @@ corebin_PROGRAMS = \
sx-ripemd-hash sx-initchain sx-secret-to-wif sx-wif-to-secret \
sx-hd-seed sx-hd-priv sx-hd-pub sx-hd-to-address sx-hd-to-wif \
sx-stealth-addr sx-stealth-show-addr sx-stealth-initiate \
- sx-stealth-uncover sx-stealth-uncover-secret \
+ sx-stealth-uncover sx-stealth-uncover-secret sx-stealth-newkey \
sx-ec-multiply sx-ec-tweak-add
corebin_SCRIPTS = sx-qrcode sx-watchtx sx-btc sx-satoshi sx-bci-history \
sx-get-utxo sx-bci-fetch-last-height sx-sendtx-bci sx-base58check-encode \
@@ -67,6 +67,9 @@ sx_stealth_uncover_LDADD = ${libbitcoin_LIBS} ${libwallet_LIBS}
sx_stealth_uncover_secret_SOURCES = stealth-uncover-secret.cpp
sx_stealth_uncover_secret_LDADD = ${libbitcoin_LIBS} ${libwallet_LIBS}
+sx_stealth_newkey_SOURCES = stealth-newkey.cpp
+sx_stealth_newkey_LDADD = ${libbitcoin_LIBS} ${libwallet_LIBS}
+
sx_stealth_addr_SOURCES = stealth-addr.cpp
sx_stealth_addr_LDADD = ${libbitcoin_LIBS} ${libwallet_LIBS}
diff --git a/src/mktx.cpp b/src/mktx.cpp
index 0852256..7ac3fc6 100644
--- a/src/mktx.cpp
+++ b/src/mktx.cpp
@@ -4,6 +4,7 @@
#include <boost/lexical_cast.hpp>
#include <bitcoin/bitcoin.hpp>
#include <wallet/wallet.hpp>
+#include "util.hpp"
using namespace bc;
using namespace libwallet;
@@ -117,16 +118,6 @@ bool build_output_script(
return false;
}
-ec_secret generate_random_ephemkey()
-{
- std::random_device random;
- std::default_random_engine engine(random());
- ec_secret secret;
- for (uint8_t& byte: secret)
- byte = engine() % std::numeric_limits<uint8_t>::max();
- return secret;
-}
-
bool add_output(transaction_type& tx, const std::string& parameter)
{
transaction_output_type output;
@@ -175,7 +166,7 @@ bool add_output(transaction_type& tx, const std::string& parameter)
if (!reuse_key)
spend_pubkey = stealth.spend_pubkeys.front();
// Do stealth stuff.
- ec_secret ephem_secret = generate_random_ephemkey();
+ ec_secret ephem_secret = generate_random_secret();
ec_point addr_pubkey = initiate_stealth(
ephem_secret, scan_pubkey, spend_pubkey);
// stealth_metadata
diff --git a/src/stealth-newkey.cpp b/src/stealth-newkey.cpp
new file mode 100644
index 0000000..d34f13a
--- /dev/null
+++ b/src/stealth-newkey.cpp
@@ -0,0 +1,22 @@
+#include <wallet/wallet.hpp>
+#include "util.hpp"
+using namespace libwallet;
+
+int main()
+{
+ ec_secret scan_secret = generate_random_secret();
+ ec_secret spend_secret = generate_random_secret();
+ ec_point spend_pubkey = secret_to_public_key(spend_secret);
+
+ stealth_address addr;
+ addr.options |= stealth_address::reuse_key_option;
+ addr.scan_pubkey = secret_to_public_key(scan_secret);
+ addr.spend_pubkeys.push_back(spend_pubkey);
+ addr.number_signatures = 1;
+
+ std::cout << "Stealth address: " << addr.encoded() << std::endl;
+ std::cout << "Scan secret: " << scan_secret << std::endl;
+ std::cout << "Spend secret: " << spend_secret << std::endl;
+ return 0;
+}
+
diff --git a/src/sx.py b/src/sx.py
index c285716..d323f43 100755
--- a/src/sx.py
+++ b/src/sx.py
@@ -839,6 +839,17 @@ Uncover a stealth secret.\
"""
),
+"stealth-newkey": (
+"STEALTH",
+"Generate a new stealth keys and an address.",
+
+"""\
+Usage: sx stealth-newkey
+
+Generate a new stealth keys and an address.\
+"""
+),
+
"stealth-addr": (
"STEALTH",
"Generate a new stealth address.",
diff --git a/src/util.hpp b/src/util.hpp
index 2b35458..be2c603 100644
--- a/src/util.hpp
+++ b/src/util.hpp
@@ -116,5 +116,15 @@ bool read_hd_command_args(int argc, char** argv,
return true;
}
+ec_secret generate_random_secret()
+{
+ std::random_device random;
+ std::default_random_engine engine(random());
+ ec_secret secret;
+ for (uint8_t& byte: secret)
+ byte = engine() % std::numeric_limits<uint8_t>::max();
+ return secret;
+}
+
#endif