diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cd8d18..b585351 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ set( LIB_NAME ${PROJECT_NAME} ) set( LIB_SOURCE src/base58.cpp - src/types.cpp + src/ec.cpp src/WIF.cpp ) diff --git a/include/libeosio/WIF.hpp b/include/libeosio/WIF.hpp index 79b7147..5259e4f 100644 --- a/include/libeosio/WIF.hpp +++ b/include/libeosio/WIF.hpp @@ -25,7 +25,7 @@ #define LIBEOSIO_WIF_H #include -#include +#include namespace libeosio { diff --git a/include/libeosio/ec.hpp b/include/libeosio/ec.hpp index afd0df6..0834f9a 100644 --- a/include/libeosio/ec.hpp +++ b/include/libeosio/ec.hpp @@ -24,10 +24,39 @@ #ifndef LIBEOSIO_EC_H #define LIBEOSIO_EC_H -#include +#include +#include +#include namespace libeosio { +/** + * Elliptic curve private key size (in bytes) + */ +#define EC_PRIVKEY_SIZE 32 + +/** + * Elliptic curve public key size (in bytes) + * + * Compressed format: z||x, where byte z specifies which (of the 2) solutions + * of the quadratic equation y is. Each cordinate is 32 bytes. + */ +#define EC_PUBKEY_SIZE (32 + 1) + +/** + * Elliptic curve priv/pub key datastructures. + */ +typedef std::array ec_privkey_t; +typedef std::array ec_pubkey_t; + +/** + * Elliptic curve keypair (public + private) + */ +struct ec_keypair { + ec_privkey_t secret; + ec_pubkey_t pub; +}; + /** * Generates a keypair using the secp256k1 curve. * public key is in compressed format. @@ -36,4 +65,11 @@ int ec_generate_key(struct ec_keypair *pair); } // namespace libeosio + +// Stream operators + +std::ostream& operator<<(std::ostream& os, const libeosio::ec_privkey_t& pk); + +std::ostream& operator<<(std::ostream& os, const libeosio::ec_pubkey_t& pk); + #endif /* LIBEOSIO_EC_H */ diff --git a/include/libeosio/hash.hpp b/include/libeosio/hash.hpp index 630ef93..8fc9b02 100644 --- a/include/libeosio/hash.hpp +++ b/include/libeosio/hash.hpp @@ -25,10 +25,15 @@ #define LIBEOSIO_HASH_H #include -#include namespace libeosio { +/** + * Hashes + */ +typedef struct { unsigned char data[20]; } ripemd160_t; +typedef struct { unsigned char data[32]; } sha256_t; + /** * sha256 hashing function. * Hashes the content in `data` up to `len` bytes. The result is stored in `out`. diff --git a/src/types.cpp b/src/ec.cpp similarity index 98% rename from src/types.cpp rename to src/ec.cpp index f9a7df7..241fb15 100644 --- a/src/types.cpp +++ b/src/ec.cpp @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include +#include std::ostream& _hex(std::ostream& os, const unsigned char *b, std::size_t sz) { os << "[ " << std::hex;