summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmir Taaki <genjix@riseup.net>2014-05-07 09:57:38 (GMT)
committer Amir Taaki <genjix@riseup.net>2014-05-07 09:58:06 (GMT)
commit3d49d0e6092c6f4a16a267ea55d8aa24cd12fa27 (patch)
tree77fea40946c62abff58afd0254739d530109ae29
parent708aaa433d82ee913edce21352f8cf6cd3ba9c14 (diff)
EC MATH commands (ec-add and ec-multiply)
-rw-r--r--src/Makefile.am9
-rw-r--r--src/ec-add.cpp30
-rw-r--r--src/ec-multiply.cpp34
-rw-r--r--src/ec_util.hpp20
-rw-r--r--src/mktx.cpp3
-rwxr-xr-xsrc/sx.py22
6 files changed, 116 insertions, 2 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 9faa78a..a474911 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,7 +9,8 @@ corebin_PROGRAMS = \
sx-validaddr sx-base58-encode sx-base58-decode sx-wrap sx-unwrap \
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-addr sx-stealth-show-addr \
+ sx-ec-multiply sx-ec-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 \
sx-base58check-decode sx-embed-addr sx-blke-fetch-transaction \
@@ -47,6 +48,12 @@ corebin_PROGRAMS += \
AM_CPPFLAGS += ${libobelisk_CFLAGS} -DSYSCONFDIR=\"${sysconfdir}\"
endif
+sx_ec_add_SOURCES = ec-add.cpp
+sx_ec_add_LDADD = ${libbitcoin_LIBS} ${libwallet_LIBS}
+
+sx_ec_multiply_SOURCES = ec-multiply.cpp
+sx_ec_multiply_LDADD = ${libbitcoin_LIBS} ${libwallet_LIBS}
+
sx_stealth_show_addr_SOURCES = stealth-show-addr.cpp
sx_stealth_show_addr_LDADD = ${libbitcoin_LIBS} ${libwallet_LIBS}
diff --git a/src/ec-add.cpp b/src/ec-add.cpp
new file mode 100644
index 0000000..9884f4e
--- /dev/null
+++ b/src/ec-add.cpp
@@ -0,0 +1,30 @@
+#include "ec_util.hpp"
+
+int main(int argc, char** argv)
+{
+ if (argc != 3)
+ {
+ std::cerr << "Usage: sx ec-add POINT POINT" << std::endl;
+ return -1;
+ }
+ ec_point point_a, point_b;
+ if (!set_ec_point(point_a, argv[1]))
+ {
+ std::cerr << "sx: Invalid point " << argv[1] << std::endl;
+ return -1;
+ }
+ if (!set_ec_point(point_b, argv[2]))
+ {
+ std::cerr << "sx: Invalid point " << argv[2] << std::endl;
+ return -1;
+ }
+ bool success = (point_a += point_b);
+ if (!success)
+ {
+ std::cerr << "sx: Out of range." << std::endl;
+ return -1;
+ }
+ std::cout << point_a << std::endl;
+ return 0;
+}
+
diff --git a/src/ec-multiply.cpp b/src/ec-multiply.cpp
new file mode 100644
index 0000000..0ce63da
--- /dev/null
+++ b/src/ec-multiply.cpp
@@ -0,0 +1,34 @@
+#include "ec_util.hpp"
+
+int main(int argc, char** argv)
+{
+ if (argc != 3)
+ {
+ std::cerr << "Usage: sx ec-multiply INTEGER POINT" << std::endl;
+ return -1;
+ }
+ ec_secret int_part = null_hash;
+ ec_point point_part;
+ for (size_t i = 1; i < argc; ++i)
+ {
+ const auto arg = argv[i];
+ if (set_ec_secret(int_part, arg))
+ continue;
+ if (set_ec_point(point_part, arg))
+ continue;
+ }
+ if (int_part == null_hash || point_part.empty())
+ {
+ std::cerr << "sx: Unable to read input values." << std::endl;
+ return -1;
+ }
+ bool success = (point_part *= int_part);
+ if (!success)
+ {
+ std::cerr << "sx: Out of range." << std::endl;
+ return -1;
+ }
+ std::cout << point_part << std::endl;
+ return 0;
+}
+
diff --git a/src/ec_util.hpp b/src/ec_util.hpp
new file mode 100644
index 0000000..7a6bc67
--- /dev/null
+++ b/src/ec_util.hpp
@@ -0,0 +1,20 @@
+#include <bitcoin/bitcoin.hpp>
+using namespace bc;
+
+bool set_ec_secret(ec_secret& secret, const std::string& arg)
+{
+ secret = decode_hex_digest<ec_secret>(arg);
+ return secret != null_hash;
+}
+bool set_ec_point(ec_point& point, const std::string& arg)
+{
+ //if (arg == "G")
+ ec_point result = decode_hex(arg);
+ if (result.size() != ec_compressed_size)
+ return false;
+ if (result[0] != 0x02 && result[0] != 0x03)
+ return false;
+ point = result;
+ return true;
+}
+
diff --git a/src/mktx.cpp b/src/mktx.cpp
index c7a1c22..75b2660 100644
--- a/src/mktx.cpp
+++ b/src/mktx.cpp
@@ -3,6 +3,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <bitcoin/bitcoin.hpp>
+#include <wallet/wallet.hpp>
using namespace bc;
@@ -135,7 +136,7 @@ bool add_output(transaction_type& tx, const std::string& parameter)
}
const std::string& output_str = strs[0];
payment_address addr;
- stealth_address stealth;
+ libwallet::stealth_address stealth;
script_type rawscript;
std::string payto;
diff --git a/src/sx.py b/src/sx.py
index a291979..017beb1 100755
--- a/src/sx.py
+++ b/src/sx.py
@@ -885,6 +885,28 @@ Convert an HD private key to a WIF private key.\
"""
),
+"ec-multiply": (
+"EC MATH",
+"Multiply an integer and a point together.",
+
+"""\
+Usage: sx ec-multiply INTEGER POINT
+
+Multiply an integer and a point together.\
+"""
+),
+
+"ec-add": (
+"EC MATH",
+"Add two points together.",
+
+"""\
+Usage: sx ec-add POINT POINT
+
+Add two points together.\
+"""
+),
+
}
def display_usage():