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

@@ -2711,10 +2711,6 @@
</ClCompile>
<ClInclude Include="..\..\src\ripple\protocol\AccountID.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\AnyPublicKey.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\AnySecretKey.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\Book.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\BuildInfo.h">
@@ -2729,14 +2725,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\AnyPublicKey.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\AnySecretKey.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\BuildInfo.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>

View File

@@ -3435,12 +3435,6 @@
<ClInclude Include="..\..\src\ripple\protocol\AccountID.h">
<Filter>ripple\protocol</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\AnyPublicKey.h">
<Filter>ripple\protocol</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\AnySecretKey.h">
<Filter>ripple\protocol</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\Book.h">
<Filter>ripple\protocol</Filter>
</ClInclude>
@@ -3459,12 +3453,6 @@
<ClCompile Include="..\..\src\ripple\protocol\impl\AccountID.cpp">
<Filter>ripple\protocol\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\AnyPublicKey.cpp">
<Filter>ripple\protocol\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\AnySecretKey.cpp">
<Filter>ripple\protocol\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\BuildInfo.cpp">
<Filter>ripple\protocol\impl</Filter>
</ClCompile>

View File

@@ -38,6 +38,7 @@
#include <ripple/core/SociDB.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/protocol/JsonFields.h>
#include <ripple/protocol/PublicKey.h>
#include <ripple/core/Config.h>
#include <ripple/core/JobQueue.h>
#include <ripple/core/LoadFeeTrack.h>
@@ -134,8 +135,7 @@ makeGenesisAccount (AccountID const& id,
// other constructor with appropriate parameters, and
// then create the master account / flush dirty.
//
// VFALCO Use `AnyPublicKey masterPublicKey`
Ledger::Ledger (RippleAddress const& masterPublicKey,
Ledger::Ledger (AccountID const& masterAccountID,
std::uint64_t balanceInDrops)
: mTotCoins (balanceInDrops)
, mCloseResolution (ledgerDefaultTimeResolution)
@@ -151,8 +151,7 @@ Ledger::Ledger (RippleAddress const& masterPublicKey,
// first ledger
info_.seq = 1;
auto const sle = makeGenesisAccount(
calcAccountID(masterPublicKey),
balanceInDrops);
masterAccountID, balanceInDrops);
WriteLog (lsTRACE, Ledger)
<< "root account: " << sle->getJson(0);
rawInsert(sle);

View File

@@ -82,10 +82,10 @@ public:
/** Construct the genesis ledger.
@param masterPublicKey The public of the account that
will hold `startAmount` XRP in drops.
@param masterAccountID The public of the account that
will hold `balanceInDrops` XRP in drops.
*/
Ledger (RippleAddress const& masterPublicKey,
Ledger (AccountID const& masterAccountID,
std::uint64_t balanceInDrops);
// Used for ledgers loaded from JSON files

View File

@@ -33,6 +33,7 @@ LedgerProposal::LedgerProposal (
uint256 const& tx,
std::uint32_t closeTime,
RippleAddress const& publicKey,
PublicKey const& pk,
uint256 const& suppression)
: mPreviousLedger (pLgr)
, mCurrentHash (tx)
@@ -40,6 +41,7 @@ LedgerProposal::LedgerProposal (
, mCloseTime (closeTime)
, mProposeSeq (seq)
, mPublicKey (publicKey)
, publicKey_ (pk)
{
mPeerID = mPublicKey.getNodeID ();
mTime = std::chrono::steady_clock::now ();
@@ -72,12 +74,47 @@ uint256 LedgerProposal::getSigningHash () const
mCurrentHash);
}
struct HashStream
{
static beast::endian const endian =
beast::endian::big;
std::vector<std::uint8_t> v;
std::uint8_t const*
data() const
{
return v.data();
}
std::size_t
size() const
{
return v.size();
}
void
operator()(void const* data,
std::size_t size) noexcept
{
auto const p = reinterpret_cast<
std::uint8_t const*>(data);
v.insert(v.end(), p, p + size);
}
};
bool LedgerProposal::checkSign (std::string const& signature) const
{
return mPublicKey.verifyNodePublic (
getSigningHash (),
signature,
ECDSA::not_strict);
auto const valid = mPublicKey.verifyNodePublic(
getSigningHash(), signature, ECDSA::not_strict);
HashStream h;
hash_append(h);
assert(valid == (publicKey_.verify(
Slice(h.data(), h.size()),
makeSlice(signature), false)));
return valid;
}
bool LedgerProposal::changePosition (

View File

@@ -23,7 +23,10 @@
#include <ripple/basics/CountedObject.h>
#include <ripple/basics/base_uint.h>
#include <ripple/json/json_value.h>
#include <ripple/protocol/HashPrefix.h>
#include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/RippleAddress.h>
#include <beast/hash/hash_append.h>
#include <chrono>
#include <cstdint>
#include <string>
@@ -53,6 +56,7 @@ public:
uint256 const& propose,
std::uint32_t closeTime,
RippleAddress const& publicKey,
PublicKey const& pk,
uint256 const& suppress);
// Our own proposal: the publicKey, if set, indicates we are a validating
@@ -116,11 +120,24 @@ public:
Json::Value getJson () const;
private:
template <class Hasher>
void
hash_append (Hasher& h) const
{
using beast::hash_append;
hash_append(h, HashPrefix::proposal);
hash_append(h, std::uint32_t(mProposeSeq));
hash_append(h, std::uint32_t(mCloseTime));
hash_append(h, mPreviousLedger);
hash_append(h, mCurrentHash);
}
uint256 mPreviousLedger, mCurrentHash, mSuppression;
std::uint32_t mCloseTime, mProposeSeq;
NodeID mPeerID;
RippleAddress mPublicKey;
PublicKey publicKey_;
std::chrono::steady_clock::time_point mTime;
};

View File

@@ -59,6 +59,7 @@
#include <ripple/nodestore/Manager.h>
#include <ripple/overlay/make_Overlay.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/STParsedJSON.h>
#include <ripple/protocol/types.h>
#include <ripple/server/make_ServerHandler.h>
@@ -1048,7 +1049,13 @@ void ApplicationImp::startNewLedger ()
m_journal.info << "Root account: " << toBase58(calcAccountID(rootAddress));
{
Ledger::pointer firstLedger = std::make_shared<Ledger> (rootAddress, SYSTEM_CURRENCY_START);
auto const masterAccountID =
calcAccountID(generateKeyPair(
KeyType::secp256k1,
generateSeed("masterpassphrase")).first);
auto firstLedger = std::make_shared<Ledger>(
masterAccountID, SYSTEM_CURRENCY_START);
assert (firstLedger->exists(keylet::account(
calcAccountID(rootAddress))));
// TODO(david): Add any default amendments

View File

@@ -93,18 +93,6 @@ strJoin (Iterator first, Iterator last, std::string strSeparator)
return ossValues.str ();
}
static
std::string
encodeCredential (AnyPublicKey const& pk, unsigned char type)
{
Blob buffer;
buffer.reserve(1 + pk.size());
buffer.push_back (type);
auto const data = pk.data();
buffer.insert (buffer.end(), data, data + pk.size());
return Base58::encodeWithCheck (buffer);
}
template <size_t I, class String>
void selectBlobsIntoStrings (
soci::session& s,
@@ -229,7 +217,7 @@ private:
// XXX Make this faster, make this the contents vector unsigned char or raw public key.
// XXX Contents needs to based on score.
hash_set<std::string> mUNL;
hash_map<AnyPublicKey, std::string> ephemeralValidatorKeys_;
hash_map<PublicKey, std::string> ephemeralValidatorKeys_;
boost::posix_time::ptime mtpScoreNext; // When to start scoring.
boost::posix_time::ptime mtpScoreStart; // Time currently started scoring.
@@ -260,8 +248,8 @@ public:
// Get update times and start fetching and scoring as needed.
void start();
void insertEphemeralKey (AnyPublicKey pk, std::string comment);
void deleteEphemeralKey (AnyPublicKey const& pk);
void insertEphemeralKey (PublicKey pk, std::string comment);
void deleteEphemeralKey (PublicKey const& pk);
// Add a trusted node. Called by RPC or other source.
void nodeAddPublic (RippleAddress const& naNodePublic, ValidatorSource vsWhy, std::string const& strComment);
@@ -487,14 +475,14 @@ void UniqueNodeListImp::start()
//--------------------------------------------------------------------------
void UniqueNodeListImp::insertEphemeralKey (AnyPublicKey pk, std::string comment)
void UniqueNodeListImp::insertEphemeralKey (PublicKey pk, std::string comment)
{
ScopedUNLLockType sl (mUNLLock);
ephemeralValidatorKeys_.insert (std::make_pair(std::move(pk), std::move(comment)));
}
void UniqueNodeListImp::deleteEphemeralKey (AnyPublicKey const& pk)
void UniqueNodeListImp::deleteEphemeralKey (PublicKey const& pk)
{
ScopedUNLLockType sl (mUNLLock);
@@ -648,7 +636,7 @@ void UniqueNodeListImp::nodeScore()
bool UniqueNodeListImp::nodeInUNL (RippleAddress const& naNodePublic)
{
auto const& blob = naNodePublic.getNodePublic();
AnyPublicKey const pk (blob.data(), blob.size());
PublicKey const pk (Slice(blob.data(), blob.size()));
ScopedUNLLockType sl (mUNLLock);
@@ -932,7 +920,7 @@ Json::Value UniqueNodeListImp::getUnlJson()
{
Json::Value node (Json::objectValue);
node["publicKey"] = encodeCredential (key.first, TOKEN_NODE_PUBLIC);
node["publicKey"] = toBase58(TokenType::TOKEN_NODE_PUBLIC, key.first);
node["comment"] = key.second;
ret.append (node);

View File

@@ -21,7 +21,7 @@
#define RIPPLE_APP_PEERS_UNIQUENODELIST_H_INCLUDED
#include <ripple/overlay/ClusterNodeStatus.h>
#include <ripple/protocol/AnyPublicKey.h>
#include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/RippleAddress.h>
#include <beast/cxx14/memory.h> // <memory>
#include <beast/threads/Stoppable.h>
@@ -55,8 +55,8 @@ public:
// VFALCO TODO Roll this into the constructor so there is one less state.
virtual void start () = 0;
virtual void insertEphemeralKey (AnyPublicKey pk, std::string comment) = 0;
virtual void deleteEphemeralKey (AnyPublicKey const& pk) = 0;
virtual void insertEphemeralKey (PublicKey pk, std::string comment) = 0;
virtual void deleteEphemeralKey (PublicKey const& pk) = 0;
// VFALCO TODO rename all these, the "node" prefix is redundant (lol)
virtual void nodeAddPublic (RippleAddress const& naNodePublic, ValidatorSource vsWhy, std::string const& strComment) = 0;

View File

@@ -147,10 +147,7 @@ class View_test
testLedger()
{
using namespace jtx;
Account const master("master");
auto const ledger =
std::make_shared<Ledger>(
master.pk(), 1000000000);
auto const ledger = Env::genesis();
wipe(*ledger);
ReadView& v = *ledger;
succ(v, 0, boost::none);
@@ -391,10 +388,7 @@ class View_test
// ApplyView on that, then another ApplyView,
// erase the item, apply.
{
Account const master("master");
auto const ledger =
std::make_shared<Ledger>(
master.pk(), 1000000000);
auto const ledger = Env::genesis();
wipe(*ledger);
ledger->rawInsert(sle(1));
ReadView& v0 = *ledger;

View File

@@ -36,8 +36,8 @@ make_Manifest (std::string s)
STObject st (sfGeneric);
SerialIter sit (s.data (), s.size ());
st.set (sit);
auto const opt_pk = get<AnyPublicKey>(st, sfPublicKey);
auto const opt_spk = get<AnyPublicKey>(st, sfSigningPubKey);
auto const opt_pk = get<PublicKey>(st, sfPublicKey);
auto const opt_spk = get<PublicKey>(st, sfSigningPubKey);
auto const opt_seq = get (st, sfSequence);
auto const opt_sig = get (st, sfSignature);
if (!opt_pk || !opt_spk || !opt_seq || !opt_sig)
@@ -57,11 +57,11 @@ Stream&
logMftAct (
Stream& s,
std::string const& action,
AnyPublicKey const& pk,
PublicKey const& pk,
std::uint32_t seq)
{
s << "Manifest: " << action <<
";Pk: " << toString (pk) <<
";Pk: " << toBase58 (TokenType::TOKEN_NODE_PUBLIC, pk) <<
";Seq: " << seq << ";";
return s;
}
@@ -70,20 +70,20 @@ template<class Stream>
Stream& logMftAct (
Stream& s,
std::string const& action,
AnyPublicKey const& pk,
PublicKey const& pk,
std::uint32_t seq,
std::uint32_t oldSeq)
{
s << "Manifest: " << action <<
";Pk: " << toString (pk) <<
";Pk: " << toBase58 (TokenType::TOKEN_NODE_PUBLIC, pk) <<
";Seq: " << seq <<
";OldSeq: " << oldSeq << ";";
return s;
}
Manifest::Manifest (std::string s,
AnyPublicKey pk,
AnyPublicKey spk,
PublicKey pk,
PublicKey spk,
std::uint32_t seq)
: serialized (std::move (s))
, masterKey (std::move (pk))
@@ -97,7 +97,7 @@ bool Manifest::verify () const
STObject st (sfGeneric);
SerialIter sit (serialized.data (), serialized.size ());
st.set (sit);
return ripple::verify (st, HashPrefix::manifest, masterKey);
return ripple::verify (st, HashPrefix::manifest, masterKey, true);
}
uint256 Manifest::hash () const
@@ -146,11 +146,11 @@ ManifestCache::configValidatorKey(
throw std::runtime_error ("Expected Ed25519 key (0xED)");
}
auto const masterKey = AnyPublicKey (key.data() + 1, key.size() - 1);
auto const masterKey = PublicKey (Slice(key.data() + 1, key.size() - 1));
std::string comment = std::move(words[1]);
if (journal.debug) journal.debug
<< masterKey << " " << comment;
<< toBase58(TokenType::TOKEN_NODE_PUBLIC, masterKey) << " " << comment;
addTrustedKey (masterKey, std::move(comment));
}
@@ -172,7 +172,7 @@ ManifestCache::configManifest(Manifest m, beast::Journal const& journal)
}
void
ManifestCache::addTrustedKey (AnyPublicKey const& pk, std::string comment)
ManifestCache::addTrustedKey (PublicKey const& pk, std::string comment)
{
std::lock_guard<std::mutex> lock (mutex_);
@@ -188,7 +188,7 @@ ManifestCache::addTrustedKey (AnyPublicKey const& pk, std::string comment)
}
ManifestDisposition
ManifestCache::canApply (AnyPublicKey const& pk, std::uint32_t seq,
ManifestCache::canApply (PublicKey const& pk, std::uint32_t seq,
beast::Journal const& journal) const
{
auto const iter = map_.find(pk);

View File

@@ -22,7 +22,7 @@
#include <ripple/basics/BasicConfig.h>
#include <ripple/basics/UnorderedContainers.h>
#include <ripple/protocol/AnyPublicKey.h>
#include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/STExchange.h>
#include <beast/utility/Journal.h>
#include <boost/optional.hpp>
@@ -85,11 +85,11 @@ namespace ripple {
struct Manifest
{
std::string serialized;
AnyPublicKey masterKey;
AnyPublicKey signingKey;
PublicKey masterKey;
PublicKey signingKey;
std::uint32_t sequence;
Manifest(std::string s, AnyPublicKey pk, AnyPublicKey spk, std::uint32_t seq);
Manifest(std::string s, PublicKey pk, PublicKey spk, std::uint32_t seq);
#ifdef _MSC_VER
Manifest(Manifest&& other)
@@ -166,7 +166,7 @@ private:
#endif
MappedType(std::string comment,
std::string serialized,
AnyPublicKey pk, AnyPublicKey spk, std::uint32_t seq)
PublicKey pk, PublicKey spk, std::uint32_t seq)
:comment (std::move(comment))
{
m.emplace (std::move(serialized), std::move(pk), std::move(spk),
@@ -177,13 +177,13 @@ private:
boost::optional<Manifest> m;
};
using MapType = hash_map<AnyPublicKey, MappedType>;
using MapType = hash_map<PublicKey, MappedType>;
mutable std::mutex mutex_;
MapType map_;
ManifestDisposition
canApply (AnyPublicKey const& pk, std::uint32_t seq,
canApply (PublicKey const& pk, std::uint32_t seq,
beast::Journal const& journal) const;
public:
@@ -195,7 +195,7 @@ public:
void configValidatorKey(std::string const& line, beast::Journal const& journal);
void configManifest(Manifest m, beast::Journal const& journal);
void addTrustedKey (AnyPublicKey const& pk, std::string comment);
void addTrustedKey (PublicKey const& pk, std::string comment);
ManifestDisposition
applyManifest (Manifest m, beast::Journal const& journal);

View File

@@ -1147,13 +1147,14 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMProposeSet> const& m)
if ((set.closetime() + 180) < getApp().getOPs().getCloseTimeNC())
return;
auto const type = publicKeyType(
makeSlice(set.nodepubkey()));
// VFALCO Magic numbers are bad
// Roll this into a validation function
if (
if ((! type) ||
(set.currenttxhash ().size () != 32) ||
(set.nodepubkey ().size () < 28) ||
(set.signature ().size () < 56) ||
(set.nodepubkey ().size () > 128) ||
(set.signature ().size () > 128)
)
{
@@ -1215,7 +1216,8 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMProposeSet> const& m)
auto proposal = std::make_shared<LedgerProposal> (
prevLedger, set.proposeseq (), proposeHash, set.closetime (),
signerPublic, suppression);
signerPublic, PublicKey(makeSlice(set.nodepubkey())),
suppression);
getApp().getJobQueue ().addJob (isTrusted ? jtPROPOSAL_t : jtPROPOSAL_ut,
"recvPropose->checkPropose", std::bind(beast::weak_fn(

View File

@@ -22,6 +22,7 @@
#include <ripple/overlay/impl/Manifest.h>
#include <ripple/core/DatabaseCon.h>
#include <ripple/app/main/DBInit.h>
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/Sign.h>
#include <ripple/protocol/STExchange.h>
#include <boost/filesystem.hpp>
@@ -85,18 +86,18 @@ public:
Manifest
make_Manifest
(AnySecretKey const& sk, AnyPublicKey const& spk, int seq,
(KeyType type, SecretKey const& sk, PublicKey const& spk, int seq,
bool broken = false)
{
auto const pk = sk.publicKey();
auto const pk = derivePublicKey(type, sk);
STObject st(sfGeneric);
set(st, sfSequence, seq);
set(st, sfPublicKey, pk);
set(st, sfSigningPubKey, spk);
sign(st, HashPrefix::manifest, sk);
expect(verify(st, HashPrefix::manifest, pk));
sign(st, HashPrefix::manifest, type, sk);
expect(verify(st, HashPrefix::manifest, pk, true));
if (broken)
{
@@ -191,19 +192,19 @@ public:
beast::Journal journal;
auto const sk_a = AnySecretKey::make_ed25519 ();
auto const sk_b = AnySecretKey::make_ed25519 ();
auto const pk_a = sk_a.publicKey ();
auto const pk_b = sk_b.publicKey ();
auto const kp_a = AnySecretKey::make_secp256k1_pair ();
auto const kp_b = AnySecretKey::make_secp256k1_pair ();
auto const sk_a = randomSecretKey();
auto const pk_a = derivePublicKey(KeyType::ed25519, sk_a);
auto const kp_a = randomKeyPair(KeyType::secp256k1);
auto const s_a0 = make_Manifest (KeyType::ed25519, sk_a, kp_a.first, 0);
auto const s_a1 = make_Manifest (KeyType::ed25519, sk_a, kp_a.first, 1);
auto const s_a0 = make_Manifest (sk_a, kp_a.second, 0);
auto const s_a1 = make_Manifest (sk_a, kp_a.second, 1);
auto const s_b0 = make_Manifest (sk_b, kp_b.second, 0);
auto const s_b1 = make_Manifest (sk_b, kp_b.second, 1);
auto const sk_b = randomSecretKey();
auto const pk_b = derivePublicKey(KeyType::ed25519, sk_b);
auto const kp_b = randomKeyPair(KeyType::secp256k1);
auto const s_b0 = make_Manifest (KeyType::ed25519, sk_b, kp_b.first, 0);
auto const s_b1 = make_Manifest (KeyType::ed25519, sk_b, kp_b.first, 1);
auto const s_b2 =
make_Manifest (sk_b, kp_b.second, 2, true); // broken
make_Manifest (KeyType::ed25519, sk_b, kp_b.first, 2, true); // broken
auto const fake = s_b1.serialized + '\0';
expect (cache.applyManifest (clone (s_a0), journal) == untrusted,

View File

@@ -22,7 +22,7 @@
#include <ripple/protocol/tokens.h>
// VFALCO Uncomment when the header issues are resolved
//#include <ripple/protocol/AnyPublicKey.h>
//#include <ripple/protocol/PublicKey.h>
#include <ripple/basics/base_uint.h>
#include <ripple/basics/UnorderedContainers.h>
#include <ripple/json/json_value.h>
@@ -33,9 +33,6 @@
namespace ripple {
// VFALCO Forward declared due to header issues
class AnyPublicKey;
namespace detail {
class AccountIDTag { };
@@ -96,8 +93,9 @@ parseHexOrBase58 (std::string const& s);
guard bytes included in the base58 representation.
*/
AccountID
calcAccountID (AnyPublicKey const& pk);
// VFALCO In PublicKey.h for now
//AccountID
//calcAccountID (PublicKey const& pk);
/** A special account that's used as the "issuer" for XRP. */
AccountID const&

View File

@@ -1,188 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_PROTOCOL_ANYPUBLICKEY_H_INCLUDED
#define RIPPLE_PROTOCOL_ANYPUBLICKEY_H_INCLUDED
#include <ripple/basics/Buffer.h>
#include <ripple/crypto/KeyType.h>
#include <ripple/protocol/HashPrefix.h>
#include <ripple/protocol/STExchange.h>
#include <ripple/protocol/STObject.h>
#include <beast/hash/hash_append.h>
#include <beast/utility/noexcept.h>
#include <boost/utility/base_from_member.hpp>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <utility>
namespace ripple {
/** Variant container for all public keys. */
class AnyPublicKeySlice
: public Slice
{
public:
#ifdef _MSC_VER
AnyPublicKeySlice (
void const* data, std::size_t size)
: Slice (data, size)
{
}
#else
using Slice::Slice;
#endif
AnyPublicKeySlice() = delete;
AnyPublicKeySlice (
AnyPublicKeySlice const&) = default;
AnyPublicKeySlice& operator= (
AnyPublicKeySlice const&) = default;
/** Returns the type of key stored. */
KeyType
type() const noexcept;
/** Verify a signature using this public key. */
bool
verify (void const* msg, std::size_t msg_size,
void const* sig, std::size_t sig_size) const;
};
template <>
struct STExchange<STBlob, AnyPublicKeySlice>
{
using value_type = AnyPublicKeySlice;
static
void
get (boost::optional<value_type>& t,
STBlob const& u)
{
t = boost::in_place(u.data(), u.size());
}
static
std::unique_ptr<STBlob>
set (SField const& f, AnyPublicKeySlice const& t)
{
return std::make_unique<STBlob>(
f, t.data(), t.size());
}
};
//------------------------------------------------------------------------------
/** Variant container for all public keys, with ownership. */
class AnyPublicKey
: private boost::base_from_member<Buffer>
, public AnyPublicKeySlice
{
private:
using buffer_type = boost::base_from_member<Buffer>;
public:
AnyPublicKey() = delete;
AnyPublicKey& operator= (AnyPublicKey const&) = delete;
AnyPublicKey (AnyPublicKey const& other)
: buffer_type(other.buffer_type::member.data(),
other.buffer_type::member.size())
, AnyPublicKeySlice (buffer_type::member.data(),
buffer_type::member.size())
{
}
#ifdef _MSC_VER
AnyPublicKey (AnyPublicKey&& other)
: buffer_type(std::move(other.buffer_type::member))
, AnyPublicKeySlice (buffer_type::member.data(),
buffer_type::member.size())
{
}
AnyPublicKey& operator= (AnyPublicKey&& other)
{
buffer_type::member =
std::move (other.buffer_type::member);
AnyPublicKeySlice::operator= (other);
return *this;
}
#else
AnyPublicKey (AnyPublicKey&&) = default;
AnyPublicKey& operator= (AnyPublicKey&&) = default;
#endif
AnyPublicKey (void const* data_, std::size_t size_)
: buffer_type (data_, size_)
, AnyPublicKeySlice (
member.data(), member.size())
{
}
/** Returns ownership of the underlying Buffer.
After calling this function, only the destructor
or the move assignment operator may be called.
*/
Buffer
releaseBuffer() noexcept
{
return std::move(buffer_type::member);
}
};
template <>
struct STExchange<STBlob, AnyPublicKey>
{
using value_type = AnyPublicKey;
static
void
get (boost::optional<value_type>& t,
STBlob const& u)
{
t = boost::in_place(u.data(), u.size());
}
static
std::unique_ptr<STBlob>
set (SField const& f, AnyPublicKey const& t)
{
return std::make_unique<STBlob>(
f, t.data(), t.size());
}
static
std::unique_ptr<STBlob>
set (SField const& f, AnyPublicKey&& t)
{
return std::make_unique<STBlob>(
f, t.releaseBuffer());
}
};
std::string
toString (AnyPublicKey const& pk);
} // ripple
#endif

View File

@@ -1,85 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_PROTOCOL_ANYSECRETKEY_H_INCLUDED
#define RIPPLE_PROTOCOL_ANYSECRETKEY_H_INCLUDED
#include <ripple/basics/Buffer.h>
#include <ripple/protocol/AnyPublicKey.h>
#include <ripple/protocol/HashPrefix.h>
#include <boost/utility/base_from_member.hpp>
#include <cstdint>
#include <memory>
#include <utility>
namespace ripple {
/** Variant container for secret key, with ownership. */
class AnySecretKey
{
private:
Buffer p_;
KeyType type_;
public:
AnySecretKey() = delete;
AnySecretKey (AnySecretKey const&) = delete;
AnySecretKey& operator= (AnySecretKey const&) = delete;
/** Destroy the key.
The memory area is secure erased.
*/
~AnySecretKey();
AnySecretKey (AnySecretKey&& other);
AnySecretKey& operator= (AnySecretKey&& other);
AnySecretKey (KeyType type,
void const* data, std::size_t size);
/** Returns the type of secret key. */
KeyType
type() const noexcept
{
return type_;
}
/** Returns the corresponding public key. */
AnyPublicKey
publicKey() const;
/** Create a signature for the given message. */
Buffer
sign (void const* msg, std::size_t msg_len) const;
/** Securely generate a new ed25519 secret key. */
static
AnySecretKey
make_ed25519();
/** Securely generate a new secp256k1 key pair. */
static
std::pair<AnySecretKey, AnyPublicKey>
make_secp256k1_pair();
};
} // ripple
#endif

View File

@@ -20,9 +20,9 @@
#ifndef RIPPLE_PROTOCOL_SIGN_H_INCLUDED
#define RIPPLE_PROTOCOL_SIGN_H_INCLUDED
#include <ripple/protocol/AnyPublicKey.h>
#include <ripple/protocol/AnySecretKey.h>
#include <ripple/protocol/HashPrefix.h>
#include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/STObject.h>
#include <utility>
@@ -35,7 +35,7 @@ namespace ripple {
void
sign (STObject& st,
HashPrefix const& prefix,
AnySecretKey const& sk);
KeyType type, SecretKey const& sk);
/** Verify the signature on a STObject.
The signature must be contained in sfSignature.
@@ -43,7 +43,8 @@ sign (STObject& st,
bool
verify (STObject const& st,
HashPrefix const& prefix,
AnyPublicKeySlice const& pk);
PublicKey const& pk,
bool mustBeFullyCanonical);
} // ripple

View File

@@ -19,7 +19,7 @@
#include <BeastConfig.h>
#include <ripple/protocol/AccountID.h>
#include <ripple/protocol/AnyPublicKey.h>
#include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/digest.h>
#include <ripple/protocol/tokens.h>
#include <cstring>
@@ -139,9 +139,8 @@ parseHexOrBase58 (std::string const& s)
less secure than Bitcoin. So where there was no good reason
to change something, it was not changed."
*/
AccountID
calcAccountID (AnyPublicKey const& pk)
calcAccountID (PublicKey const& pk)
{
ripesha_hasher rsh;
rsh(pk.data(), pk.size());

View File

@@ -1,104 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/protocol/AnyPublicKey.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/protocol/STExchange.h>
#include <ed25519-donna/ed25519.h>
#include <cassert>
namespace ripple {
/** Verify a secp256k1 signature. */
bool
verify_secp256k1 (void const* pk,
void const* msg, std::size_t msg_size,
void const* sig, std::size_t sig_size)
{
return false;
}
bool
verify_ed25519 (void const* pk,
void const* msg, std::size_t msg_size,
void const* sig, std::size_t sig_size)
{
if (sig_size != 64)
return false;
ed25519_public_key epk;
ed25519_signature es;
std::memcpy(epk, pk, 32);
std::memcpy(es, sig, sig_size);
return ed25519_sign_open(
reinterpret_cast<unsigned char const*>(msg),
msg_size, epk, es) == 0;
}
//------------------------------------------------------------------------------
KeyType
AnyPublicKeySlice::type() const noexcept
{
auto const pk = data();
auto const pk_size = size();
if (pk_size < 1)
return KeyType::unknown;
auto const len = pk_size - 1;
if (len == 32 &&
pk[0] == 0xED)
return KeyType::ed25519;
if (len == 33 &&
(pk[0] == 0x02 || pk[0] == 0x03))
return KeyType::secp256k1;
return KeyType::unknown;
}
bool
AnyPublicKeySlice::verify (
void const* msg, std::size_t msg_size,
void const* sig, std::size_t sig_size) const
{
switch(type())
{
case KeyType::ed25519:
return verify_ed25519(data() + 1,
msg, msg_size, sig, sig_size);
case KeyType::secp256k1:
return verify_secp256k1(data() + 1,
msg, msg_size, sig, sig_size);
default:
break;
}
// throw?
return false;
}
std::string
toString (AnyPublicKey const& pk)
{
Blob buffer;
buffer.reserve (1 + pk.size ());
buffer.push_back (TOKEN_NODE_PUBLIC);
auto const data = pk.data ();
buffer.insert (buffer.end (), data, data + pk.size ());
return Base58::encodeWithCheck (buffer);
}
} // ripple

View File

@@ -1,143 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/protocol/AnySecretKey.h>
#include <ripple/protocol/RippleAddress.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/crypto/RandomNumbers.h>
#include <ed25519-donna/ed25519.h>
#include <algorithm>
#include <cassert>
#include <cstring>
namespace ripple {
AnySecretKey::~AnySecretKey()
{
// secure erase
std::fill(p_.data(), p_.data() + p_.size(), 0);
}
AnySecretKey::AnySecretKey (AnySecretKey&& other)
: p_ (std::move(other.p_))
, type_ (other.type_)
{
other.type_ = KeyType::unknown;
}
AnySecretKey&
AnySecretKey::operator= (AnySecretKey&& other)
{
p_ = std::move(other.p_);
type_ = other.type_;
other.type_ = KeyType::unknown;
return *this;
}
AnySecretKey::AnySecretKey (KeyType type,
void const* data, std::size_t size)
: p_ (data, size)
, type_ (type)
{
if (type_ == KeyType::unknown)
throw std::runtime_error(
"AnySecretKey: unknown type");
if (type_ == KeyType::ed25519 &&
size != 32)
throw std::runtime_error(
"AnySecretKey: wrong ed25519 size");
if (type_ == KeyType::secp256k1 &&
size != 32)
throw std::runtime_error(
"AnySecretKey: wrong secp256k1 size");
}
AnyPublicKey
AnySecretKey::publicKey() const
{
switch (type())
{
case KeyType::ed25519:
{
unsigned char buf[33];
buf[0] = 0xED;
ed25519_publickey(p_.data(), &buf[1]);
return AnyPublicKey(buf, sizeof(buf));
}
default:
throw std::runtime_error(
"AnySecretKey: unknown type");
};
}
Buffer
AnySecretKey::sign (
void const* msg, std::size_t msg_len) const
{
switch(type_)
{
case KeyType::ed25519:
{
auto const sk = p_.data();
ed25519_public_key pk;
ed25519_publickey(sk, pk);
Buffer b(64);
ed25519_sign(reinterpret_cast<
unsigned char const*>(msg), msg_len,
sk, pk, b.data());
return b;
}
default:
break;
}
throw std::runtime_error(
"AnySecretKey: unknown type");
}
AnySecretKey
AnySecretKey::make_ed25519()
{
std::uint8_t buf[32];
random_fill(&buf[0], sizeof(buf));
AnySecretKey ask(KeyType::ed25519,
buf, sizeof(buf));
// secure erase
std::fill(buf, buf + sizeof(buf), 0);
return ask;
}
std::pair<AnySecretKey, AnyPublicKey>
AnySecretKey::make_secp256k1_pair()
{
// VFALCO What a pile
RippleAddress s;
s.setSeedRandom();
RippleAddress const g =
RippleAddress::createGeneratorPublic(s);
RippleAddress sk;
sk.setAccountPrivate (g, s, 0);
RippleAddress pk;
pk.setAccountPublic (g, 0);
return std::pair<AnySecretKey, AnyPublicKey>(
std::piecewise_construct, std::make_tuple(
KeyType::secp256k1, sk.data(), sk.size()),
std::make_tuple(pk.data(), pk.size()));
}
} // ripple

View File

@@ -17,6 +17,7 @@
*/
//==============================================================================
#include <BeastConfig.h>
#include <ripple/protocol/STAccount.h>
#include <ripple/protocol/STAmount.h>
#include <ripple/protocol/STArray.h>

View File

@@ -17,25 +17,27 @@
*/
//==============================================================================
#include <BeastConfig.h>
#include <ripple/protocol/Sign.h>
namespace ripple {
void
sign (STObject& st, HashPrefix const& prefix,
AnySecretKey const& sk)
KeyType type, SecretKey const& sk)
{
Serializer ss;
ss.add32(prefix);
st.addWithoutSigningFields(ss);
set(st, sfSignature,
sk.sign(ss.data(), ss.size()));
sign(type, sk, ss.slice()));
}
bool
verify (STObject const& st,
HashPrefix const& prefix,
AnyPublicKeySlice const& pk)
PublicKey const& pk,
bool mustBeFullyCanonical)
{
auto const sig = get(st, sfSignature);
if (! sig)
@@ -44,8 +46,9 @@ verify (STObject const& st,
ss.add32(prefix);
st.addWithoutSigningFields(ss);
return pk.verify(
ss.data(), ss.size(),
sig->data(), sig->size());
Slice(ss.data(), ss.size()),
Slice(sig->data(), sig->size()),
true);
}
} // ripple

View File

@@ -17,6 +17,7 @@
*/
//==============================================================================
#include <BeastConfig.h>
#include <ripple/protocol/tokens.h>
#include <ripple/protocol/digest.h>
#include <cassert>

View File

@@ -88,7 +88,7 @@ public:
txnSeed.setSeedRandom ();
// VFALCO Generators are no longer supported
RippleAddress txnGenerator = txnSeed.createGeneratorPublic (txnSeed);
// VFALCO Use AnyPublicKey here
// VFALCO Use PublicKey here
RippleAddress txnPublicAcct = txnSeed.createAccountPublic (txnGenerator, 1);
STTx txn (ttACCOUNT_SET);

View File

@@ -39,7 +39,7 @@ Json::Value accounts (
do
{
// VFALCO Should be AnyPublicKey
// VFALCO Should be PublicKey and Generator
RippleAddress pk;
pk.setAccountPublic (naMasterGenerator, uIndex++);

View File

@@ -21,6 +21,7 @@
#include <ripple/app/paths/FindPaths.h>
#include <ripple/basics/StringUtilities.h>
#include <ripple/json/json_reader.h>
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/TxFlags.h>
#include <ripple/rpc/impl/TransactionSign.h>
#include <beast/unit_test/suite.h>
@@ -920,8 +921,14 @@ public:
= RippleAddress::createAccountPublic (rootGeneratorMaster, 0);
std::uint64_t startAmount (100000);
auto const masterAccountID =
calcAccountID(generateKeyPair(
KeyType::secp256k1,
generateSeed("masterpassphrase")).first);
Ledger::pointer ledger (std::make_shared <Ledger> (
rootAddress, startAmount));
masterAccountID, startAmount));
using namespace detail;
TxnSignApiFacade apiFacade (TxnSignApiFacade::noNetOPs, ledger);

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

View File

@@ -20,8 +20,6 @@
#include <BeastConfig.h>
#include <ripple/protocol/impl/AccountID.cpp>
#include <ripple/protocol/impl/AnyPublicKey.cpp>
#include <ripple/protocol/impl/AnySecretKey.cpp>
#include <ripple/protocol/impl/BuildInfo.cpp>
#include <ripple/protocol/impl/ByteOrder.cpp>
#include <ripple/protocol/impl/digest.cpp>