Use SecretKey, PublicKey

This commit is contained in:
Vinnie Falco
2015-07-10 19:55:39 -07:00
committed by Nik Bougalis
parent 6fccd07479
commit 163e8eb8fc
34 changed files with 202 additions and 693 deletions

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_TEST_JTX_ACCOUNT_H_INCLUDED
#define RIPPLE_TEST_JTX_ACCOUNT_H_INCLUDED
#include <ripple/protocol/RippleAddress.h>
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/UintTypes.h>
#include <ripple/crypto/KeyType.h>
#include <beast/utility/noexcept.h>
@@ -37,10 +37,8 @@ class Account
{
private:
std::string name_;
// VFALCO TODO use AnyPublicKey, AnySecretKey
// instead of RippleAddress
RippleAddress pk_;
RippleAddress sk_;
PublicKey pk_;
SecretKey sk_;
AccountID id_;
std::string human_; // base58 public key string
@@ -58,12 +56,14 @@ public:
#endif
/** Create an account from a key pair. */
Account (std::string name, KeyPair&& keys);
Account (std::string name,
std::pair<PublicKey, SecretKey> const& keys);
/** Create an account from a simple string name. */
/** @{ */
Account (std::string name,
KeyType type = KeyType::secp256k1);
Account (char const* name,
KeyType type = KeyType::secp256k1)
: Account(std::string(name), type)
@@ -79,14 +79,14 @@ public:
}
/** Return the public key. */
RippleAddress const&
PublicKey const&
pk() const
{
return pk_;
}
/** Return the secret key. */
RippleAddress const&
SecretKey const&
sk() const
{
return sk_;

View File

@@ -34,7 +34,6 @@
#include <ripple/ledger/CachedSLEs.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/protocol/Issue.h>
#include <ripple/protocol/RippleAddress.h>
#include <ripple/protocol/STAmount.h>
#include <ripple/protocol/STObject.h>
#include <ripple/protocol/STTx.h>
@@ -154,7 +153,7 @@ public:
as a public member for interested callers.
*/
static
std::shared_ptr<Ledger const>
std::shared_ptr<Ledger>
genesis();
/** Returns the open ledger.

View File

@@ -48,14 +48,14 @@ Account::operator= (Account&& rhs)
}
#endif
Account::Account(
std::string name, KeyPair&& keys)
Account::Account(std::string name,
std::pair<PublicKey, SecretKey> const& keys)
: name_(std::move(name))
, pk_ (keys.first)
, sk_ (keys.second)
, id_ (calcAccountID(pk_))
, human_ (toBase58(id_))
{
pk_ = std::move(keys.publicKey);
sk_ = std::move(keys.secretKey);
id_ = calcAccountID(pk_);
human_ = toBase58(id_);
}
Account::Account (std::string name,
@@ -66,9 +66,7 @@ Account::Account (std::string name,
// Fails on Clang and possibly gcc
: Account(std::move(name),
#endif
generateKeysFromSeed(type,
RippleAddress::createSeedGeneric(
name)))
generateKeyPair(type, generateSeed(name)))
{
}

View File

@@ -44,22 +44,21 @@
#include <ripple/protocol/TxFlags.h>
#include <ripple/protocol/types.h>
#include <memory>
// VFALCO TODO Use AnyPublicKey, AnySecretKey, AccountID
namespace ripple {
namespace test {
namespace jtx {
std::shared_ptr<Ledger const>
std::shared_ptr<Ledger>
Env::genesis()
{
Account master("master", generateKeysFromSeed(
KeyType::secp256k1, RippleAddress::createSeedGeneric(
"masterpassphrase")));
Account const master("master",
generateKeyPair(KeyType::secp256k1,
generateSeed("masterpassphrase")));
auto const ledger =
std::make_shared<Ledger>(master.pk(),
SYSTEM_CURRENCY_START);
std::make_shared<Ledger>(
master.id(), SYSTEM_CURRENCY_START);
ledger->setClosed();
return ledger;
}
@@ -67,9 +66,9 @@ Env::genesis()
// VFALCO Could wrap the log in a Journal here
Env::Env (beast::unit_test::suite& test_)
: test(test_)
, master("master", generateKeysFromSeed(
KeyType::secp256k1, RippleAddress::createSeedGeneric(
"masterpassphrase")))
, master("master", generateKeyPair(
KeyType::secp256k1,
generateSeed("masterpassphrase")))
, closed_ (genesis())
, cachedSLEs_ (std::chrono::seconds(5), clock)
, openLedger (closed_, config, cachedSLEs_, journal)

View File

@@ -102,17 +102,18 @@ msig::operator()(Env const& env, JTx& jt) const
auto const& e = accounts[i];
auto& jo = js[i]["SigningAccount"];
jo[jss::Account] = e.human();
jo[jss::SigningPubKey] = strHex(makeSlice(
e.pk().getAccountPublic()));
jo[jss::SigningPubKey] = strHex(e.pk().slice());
Serializer ss;
ss.add32 (HashPrefix::txMultiSign);
st->addWithoutSigningFields(ss);
ss.add160(*signFor);
ss.add160(e.id());
jo["MultiSignature"] = strHex(makeSlice(
e.sk().accountPrivateSign(ss.getData())));
auto const sig = ripple::sign(
*publicKeyType(e.pk().slice()),
e.sk(), ss.slice());
jo["MultiSignature"] =
strHex(Slice{ sig.data(), sig.size() });
}
};
}
@@ -165,17 +166,19 @@ msig2_t::operator()(Env const& env, JTx& jt) const
{
auto& jj = js[j.first]["SigningAccount"];
jj[jss::Account] = j.second->human();
jj[jss::SigningPubKey] = strHex(makeSlice(
j.second->pk().getAccountPublic()));
jj[jss::SigningPubKey] = strHex(
j.second->pk().slice());
Serializer ss;
ss.add32 (HashPrefix::txMultiSign);
st->addWithoutSigningFields(ss);
ss.add160(sign_for.id());
ss.add160(j.second->id());
jj["MultiSignature"] = strHex(makeSlice(
j.second->sk().accountPrivateSign(
ss.getData())));
auto const sig = ripple::sign(
*publicKeyType(j.second->pk().slice()),
j.second->sk(), ss.slice());
jj["MultiSignature"] =
strHex(Slice{ sig.data(), sig.size() });
}
}
};

View File

@@ -46,14 +46,15 @@ sign (Json::Value& jv,
Account const& account)
{
jv[jss::SigningPubKey] =
strHex(makeSlice(
account.pk().getAccountPublic()));
strHex(account.pk().slice());
Serializer ss;
ss.add32 (HashPrefix::txSign);
parse(jv).add(ss);
jv[jss::TxnSignature] = strHex(makeSlice(
account.sk().accountPrivateSign(
ss.getData())));
auto const sig = ripple::sign(
*publicKeyType(account.pk().slice()),
account.sk(), ss.slice());
jv[jss::TxnSignature] =
strHex(Slice{ sig.data(), sig.size() });
}
void