various updates to support bitshares

This commit is contained in:
Daniel Larimer 2013-06-06 19:20:51 -04:00
parent 639a0c795a
commit 0fd0574c05
3 changed files with 97 additions and 48 deletions

View file

@ -5,58 +5,95 @@
#include <fc/fwd.hpp> #include <fc/fwd.hpp>
#include <fc/array.hpp> #include <fc/array.hpp>
#include <vector> #include <vector>
#include <fc/io/raw_fwd.hpp>
namespace fc { namespace ecc { namespace fc
{
namespace ecc
{
namespace detail namespace detail
{ {
class public_key_impl; class public_key_impl;
class private_key_impl; class private_key_impl;
}
typedef fc::array<char,72> signature;
typedef fc::array<unsigned char,65> compact_signature;
class public_key
{
public:
public_key();
~public_key();
bool verify( const fc::sha256& digest, const signature& sig );
std::vector<char> serialize()const;
public_key( const std::vector<char>& v );
public_key( const compact_signature& c, const fc::sha256& digest );
private:
friend class private_key;
fc::fwd<detail::public_key_impl,8> my;
};
class private_key
{
public:
private_key();
private_key( std::vector<char> k );
~private_key();
static private_key generate();
static private_key regenerate( const fc::sha256& secret );
fc::sha256 get_secret()const; // get the private key secret
/**
* Given a public key, calculatse a 512 bit shared secret between that
* key and this private key.
*/
fc::sha512 get_shared_secret( const public_key& pub );
signature sign( const fc::sha256& digest );
compact_signature sign_compact( const fc::sha256& digest );
bool verify( const fc::sha256& digest, const signature& sig );
public_key get_public_key()const;
private:
fc::fwd<detail::private_key_impl,8> my;
};
} // namespace ecc
namespace raw
{
template<typename Stream>
inline void pack( Stream& s, const fc::ecc::public_key& v )
{
pack( s, v.serialize() );
}
template<typename Stream>
inline void unpack( Stream& s, fc::ecc::public_key& v )
{
std::vector<char> d;
unpack( s, d );
v = fc::ecc::public_key( fc::move(d) );
} }
typedef fc::array<char,72> signature; template<typename Stream>
typedef fc::array<unsigned char,65> compact_signature; inline void pack( Stream& s, const fc::ecc::private_key& v )
class public_key
{ {
public: pack( s, v.get_secret() );
public_key(); }
~public_key();
bool verify( const fc::sha256& digest, const signature& sig );
std::vector<char> serialize()const; template<typename Stream>
public_key( const std::vector<char>& v ); inline void unpack( Stream& s, fc::ecc::private_key& v )
public_key( const compact_signature& c, const fc::sha256& digest );
private:
friend class private_key;
fc::fwd<detail::public_key_impl,8> my;
};
class private_key
{ {
public: fc::sha256 secret;
private_key(); unpack( s, secret );
private_key( std::vector<char> k ); v = fc::ecc::private_key::regenerate( secret );
~private_key(); }
static private_key generate(); } // namespace raw
static private_key regenerate( const fc::sha256& secret );
fc::sha256 get_secret()const; // get the private key secret } // fc
/**
* Given a public key, calculatse a 512 bit shared secret between that
* key and this private key.
*/
fc::sha512 get_shared_secret( const public_key& pub );
signature sign( const fc::sha256& digest );
compact_signature sign_compact( const fc::sha256& digest );
bool verify( const fc::sha256& digest, const signature& sig );
public_key get_public_key()const;
private:
fc::fwd<detail::private_key_impl,8> my;
};
} } // fc::ecc

View file

@ -127,7 +127,9 @@ namespace fc {
template<typename Stream> inline void unpack( Stream& s, fc::string& v ) { template<typename Stream> inline void unpack( Stream& s, fc::string& v ) {
std::vector<char> tmp; unpack(s,tmp); std::vector<char> tmp; unpack(s,tmp);
v = fc::string(tmp.begin(),tmp.end()); if( tmp.size() )
v = fc::string(tmp.data(),tmp.data()+tmp.size());
else v = fc::string();
} }
// bool // bool

View file

@ -1,13 +1,23 @@
#pragma once #pragma once
#include <fc/io/varint.hpp> #include <fc/io/varint.hpp>
#include <fc/array.hpp> #include <fc/array.hpp>
#include <vector>
#include <string>
namespace fc { namespace raw { namespace fc {
namespace ecc { class public_key; class private_key; }
namespace raw {
template<typename Stream, typename T> void unpack( Stream& s, fc::optional<T>& v ); template<typename Stream, typename T> void unpack( Stream& s, fc::optional<T>& v );
template<typename Stream, typename T> void pack( Stream& s, const fc::optional<T>& v ); template<typename Stream, typename T> void pack( Stream& s, const fc::optional<T>& v );
template<typename Stream> void unpack( Stream& s, fc::string& ); template<typename Stream> void unpack( Stream& s, fc::string& );
template<typename Stream> void pack( Stream& s, const fc::string& ); template<typename Stream> void pack( Stream& s, const fc::string& );
template<typename Stream> void unpack( Stream& s, std::string& );
template<typename Stream> void pack( Stream& s, const std::string& );
template<typename Stream> void unpack( Stream& s, fc::ecc::public_key& );
template<typename Stream> void pack( Stream& s, const fc::ecc::public_key& );
template<typename Stream> void unpack( Stream& s, fc::ecc::private_key& );
template<typename Stream> void pack( Stream& s, const fc::ecc::private_key& );
template<typename Stream, typename T> inline void pack( Stream& s, const T& v ); template<typename Stream, typename T> inline void pack( Stream& s, const T& v );
template<typename Stream, typename T> inline void unpack( Stream& s, T& v ); template<typename Stream, typename T> inline void unpack( Stream& s, T& v );