summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmir Taaki <genjix@riseup.net>2014-05-09 11:28:58 (GMT)
committer Amir Taaki <genjix@riseup.net>2014-05-09 11:28:58 (GMT)
commit121ad026c1ffc9d43945e26d301feadbe94ce570 (patch)
tree486ead59c36dafcd2b006980218bf83501e5150d
parent8b7b605a3dff442bfbfc70419743a6a09fca0f59 (diff)
added sha256 and ec-add-modp commands.
-rw-r--r--src/ec-add-modp.cpp29
-rw-r--r--src/sha256.cpp24
-rwxr-xr-xsrc/sx.py37
3 files changed, 83 insertions, 7 deletions
diff --git a/src/ec-add-modp.cpp b/src/ec-add-modp.cpp
new file mode 100644
index 0000000..0677729
--- /dev/null
+++ b/src/ec-add-modp.cpp
@@ -0,0 +1,29 @@
+#include "ec_util.hpp"
+
+int main(int argc, char** argv)
+{
+ if (argc != 3)
+ {
+ std::cerr << "Usage: sx ec-add-modp INTEGER INTEGER" << std::endl;
+ return -1;
+ }
+ ec_secret secret_a, secret_b;
+ if (!set_ec_secret(secret_a, argv[1]))
+ {
+ std::cerr << "sx: Invalid secret " << argv[1] << std::endl;
+ return -1;
+ }
+ if (!set_ec_secret(secret_b, argv[2]))
+ {
+ std::cerr << "sx: Invalid secret " << argv[2] << std::endl;
+ return -1;
+ }
+ if (!ec_add(secret_a, secret_b))
+ {
+ std::cerr << "sx: Error adding numbers." << std::endl;
+ return -1;
+ }
+ std::cout << secret_a << std::endl;
+ return 0;
+}
+
diff --git a/src/sha256.cpp b/src/sha256.cpp
new file mode 100644
index 0000000..6627715
--- /dev/null
+++ b/src/sha256.cpp
@@ -0,0 +1,24 @@
+#include "util.hpp"
+
+int main(int argc, char** argv)
+{
+ if (argc > 2)
+ {
+ std::cerr << "Usage: sx sha256 DATA" << std::endl;
+ return -1;
+ }
+ std::string arg;
+ if (argc == 2)
+ arg = argv[1];
+ else
+ arg = read_stdin();
+ data_chunk data = decode_hex(arg);
+ if (data.empty())
+ {
+ std::cerr << "sx: Non-hex input data." << std::endl;
+ return -1;
+ }
+ std::cout << sha256_hash(data) << std::endl;
+ return 0;
+}
+
diff --git a/src/sx.py b/src/sx.py
index d323f43..db5b042 100755
--- a/src/sx.py
+++ b/src/sx.py
@@ -531,6 +531,17 @@ Usage: echo SECRET | sx secret-to-wif
"""
),
+"sha256": (
+"MISC",
+"Perform SHA256 hash of data.",
+
+"""\
+Usage: sx sha256 DATA
+
+Perform SHA256 hash of data.\
+"""
+),
+
"mpk": (
"DETERMINISTIC KEYS AND ADDRESSES",
"Extract a master public key from a deterministic wallet seed.",
@@ -808,12 +819,12 @@ Watch transactions from the network searching for a certain hash.\
"stealth-initiate": (
"STEALTH",
-"Initiate a new stealth address.",
+"Initiate a new stealth payment.",
"""\
Usage: sx stealth-initiate EPHEM_SECRET SCAN_PUBKEY SPEND_PUBKEY
-Initiate a new stealth address.\
+Initiate a new stealth payment.\
"""
),
@@ -841,25 +852,26 @@ Uncover a stealth secret.\
"stealth-newkey": (
"STEALTH",
-"Generate a new stealth keys and an address.",
+"Generate new stealth keys and an address.",
"""\
Usage: sx stealth-newkey
-Generate a new stealth keys and an address.\
+Generate new stealth keys and an address.\
"""
),
"stealth-addr": (
"STEALTH",
-"Generate a new stealth address.",
+"See a stealth address from given input.",
"""\
-Usage: sx stealth-addr [--reuse-key|-r] SCAN_PUBKEY SPEND_PUBKEY1 ... SPEND_PUBKEYN
+Usage: sx stealth-addr [--reuse-key|-r] [--signatures|-s NSIGS] SCAN_PUBKEY SPEND_PUBKEY1 ... SPEND_PUBKEYN
-Generate a new stealth address.
+See a stealth address from given input.
--reuse-key -r Reuse SCAN_PUBKEY for SPEND_PUBKEY
+ --signatures -s Specify NUMBER_SIGNATURES needed.
"""
),
@@ -951,6 +963,17 @@ Calculate the result of POINT + INTEGER * G.\
"""
),
+"ec-add-modp": (
+"EC MATH",
+"Calculate the result of INTEGER + INTEGER.",
+
+"""\
+Usage: sx ec-add-modp INTEGER INTEGER
+
+Calculate the result of INTEGER + INTEGER.\
+"""
+),
+
}
def display_usage():