mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Recognize a new JSON parameter `key_type` in handlers for wallet_propose
and sign/submit. In addition to letting the caller to specify either of
secp256k1 or ed25519, its presence prohibits the (now-deprecated) use of
heuristically polymorphic parameters for secret data -- the `passphrase`
parameter to wallet_propose will be not be considered as an encoded seed
value (for which `seed` and `seed_hex` should be used), and the `secret`
parameter to sign and submit will be obsoleted entirely by the same trio
above.
* Use constants instead of literals for JSON parameter names.
* Move KeyType to its own unit and add string conversions.
* RippleAddress
* Pass the entire message, rather than a hash, to accountPrivateSign()
and accountPublicVerify().
* Recognize a 33-byte value beginning with 0xED as an Ed25519 key when
signing and verifying (for accounts only).
* Add keyFromSeed() to generate an Ed25519 secret key from a seed.
* Add getSeedFromRPC() to extract the seed from JSON parameters for an
RPC call.
* Add generateKeysFromSeed() to produce a key pair of either type from
a seed.
* Extend Ledger tests to cover both key types.
87 lines
2.7 KiB
C++
87 lines
2.7 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
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/protocol/RippleAddress.h>
|
|
#include <ripple/rpc/impl/KeypairForSignature.h>
|
|
|
|
namespace ripple {
|
|
namespace RPC {
|
|
|
|
KeyPair keypairForSignature (Json::Value const& params, Json::Value& error)
|
|
{
|
|
bool const has_key_type = params.isMember (jss::key_type);
|
|
bool const has_passphrase = params.isMember (jss::passphrase);
|
|
bool const has_secret = params.isMember (jss::secret);
|
|
bool const has_seed = params.isMember (jss::seed);
|
|
bool const has_seed_hex = params.isMember (jss::seed_hex);
|
|
|
|
int const n_secrets = has_passphrase + has_secret + has_seed + has_seed_hex;
|
|
|
|
if (n_secrets == 0)
|
|
{
|
|
error = RPC::missing_field_error (jss::secret);
|
|
return KeyPair();
|
|
}
|
|
|
|
if (n_secrets > 1)
|
|
{
|
|
// `passphrase`, `secret`, `seed`, and `seed_hex` are mutually exclusive.
|
|
error = rpcError (rpcBAD_SECRET);
|
|
return KeyPair();
|
|
}
|
|
|
|
if (has_key_type && has_secret)
|
|
{
|
|
// `secret` is deprecated.
|
|
error = rpcError (rpcBAD_SECRET);
|
|
return KeyPair();
|
|
}
|
|
|
|
KeyType type = KeyType::secp256k1;
|
|
|
|
RippleAddress seed;
|
|
|
|
if (has_key_type)
|
|
{
|
|
// `key_type` must be valid if present.
|
|
|
|
type = keyTypeFromString (params[jss::key_type].asString());
|
|
|
|
if (type == KeyType::invalid)
|
|
{
|
|
error = rpcError (rpcBAD_SEED);
|
|
return KeyPair();
|
|
}
|
|
|
|
seed = getSeedFromRPC (params);
|
|
}
|
|
else
|
|
if (! seed.setSeedGeneric (params[jss::secret].asString ()))
|
|
{
|
|
error = RPC::make_error (rpcBAD_SEED,
|
|
RPC::invalid_field_message (jss::secret));
|
|
}
|
|
|
|
return generateKeysFromSeed (type, seed);
|
|
}
|
|
|
|
} // RPC
|
|
} // ripple
|