mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-23 15:20:54 +00:00
Add unit tests for wallet keypair generation:
* Allow `passphrase` to be a seed encoded in any of three formats or a
literal passphrase.
* Recognize the absence of `passphrase` as requesting a random seed.
Extract walletPropose() and keypairForSignature() as separately factored
functions (from doWalletPropose() and transactionSign() respectively) to
facilitate unit testing.
This commit is contained in:
committed by
Tom Ritchford
parent
3ec88b3665
commit
436ded68b7
55
src/ripple/rpc/impl/KeypairForSignature.cpp
Normal file
55
src/ripple/rpc/impl/KeypairForSignature.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012-2015 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 <BeastConfig.h>
|
||||
#include <ripple/rpc/impl/KeypairForSignature.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace RPC {
|
||||
|
||||
KeyPair keypairForSignature (Json::Value const& params, Json::Value& error)
|
||||
{
|
||||
if (! params.isMember ("secret"))
|
||||
{
|
||||
error = RPC::missing_field_error ("secret");
|
||||
|
||||
return KeyPair();
|
||||
}
|
||||
|
||||
RippleAddress seed;
|
||||
|
||||
if (! seed.setSeedGeneric (params["secret"].asString ()))
|
||||
{
|
||||
error = RPC::make_error (rpcBAD_SEED,
|
||||
RPC::invalid_field_message ("secret"));
|
||||
|
||||
return KeyPair();
|
||||
}
|
||||
|
||||
KeyPair result;
|
||||
|
||||
RippleAddress generator = RippleAddress::createGeneratorPublic (seed);
|
||||
result.secretKey.setAccountPrivate (generator, seed, 0);
|
||||
result.publicKey.setAccountPublic (generator, 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // RPC
|
||||
} // ripple
|
||||
Reference in New Issue
Block a user