mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add CryptoIdentifierType and RippleCryptoIdentifier Traits
This commit is contained in:
@@ -12,15 +12,6 @@ RippleAddress::RippleAddress ()
|
||||
nVersion = VER_NONE;
|
||||
}
|
||||
|
||||
RipplePublicKey RippleAddress::toRipplePublicKey () const
|
||||
{
|
||||
Blob const& b (getNodePublic ());
|
||||
|
||||
check_precondition (b.size () == RipplePublicKey::sizeInBytes);
|
||||
|
||||
return RipplePublicKey (&b [0]);
|
||||
}
|
||||
|
||||
void RippleAddress::clear ()
|
||||
{
|
||||
nVersion = VER_NONE;
|
||||
@@ -318,6 +309,10 @@ std::string RippleAddress::humanAccountID () const
|
||||
if (it != rncMap.end ())
|
||||
return it->second;
|
||||
|
||||
// VFALCO NOTE Why do we throw everything out? We could keep two maps
|
||||
// here, switch back and forth keep one of them full and clear the
|
||||
// other on a swap - but always check both maps for cache hits.
|
||||
//
|
||||
if (rncMap.size () > 10000)
|
||||
rncMap.clear ();
|
||||
|
||||
@@ -953,3 +948,74 @@ public:
|
||||
};
|
||||
|
||||
static RippleAddressTests rippleAddressTests;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class RippleCryptoIdentifierTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
void runTest ()
|
||||
{
|
||||
beginTestCase ("Seed");
|
||||
RippleAddress seed;
|
||||
expect (seed.setSeedGeneric ("masterpassphrase"));
|
||||
expect (seed.humanSeed () == "snoPBrXtMeMyMHUVTgbuqAfg1SUTb", seed.humanSeed ());
|
||||
|
||||
beginTestCase ("RipplePublicKey");
|
||||
RippleAddress deprecatedPublicKey (RippleAddress::createNodePublic (seed));
|
||||
expect (deprecatedPublicKey.humanNodePublic () ==
|
||||
"n94a1u4jAz288pZLtw6yFWVbi89YamiC6JBXPVUj5zmExe5fTVg9",
|
||||
deprecatedPublicKey.humanNodePublic ());
|
||||
RipplePublicKey publicKey (deprecatedPublicKey);
|
||||
expect (publicKey.to_string() == deprecatedPublicKey.humanNodePublic(),
|
||||
publicKey.to_string());
|
||||
|
||||
beginTestCase ("RipplePrivateKey");
|
||||
RippleAddress deprecatedPrivateKey (RippleAddress::createNodePrivate (seed));
|
||||
expect (deprecatedPrivateKey.humanNodePrivate () ==
|
||||
"pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe",
|
||||
deprecatedPrivateKey.humanNodePrivate ());
|
||||
RipplePrivateKey privateKey (deprecatedPrivateKey);
|
||||
expect (privateKey.to_string() == deprecatedPrivateKey.humanNodePrivate(),
|
||||
privateKey.to_string());
|
||||
|
||||
beginTestCase ("Generator");
|
||||
RippleAddress generator (RippleAddress::createGeneratorPublic (seed));
|
||||
expect (generator.humanGenerator () ==
|
||||
"fhuJKrhSDzV2SkjLn9qbwm5AaRmrxDPfFsHDCP6yfDZWcxDFz4mt",
|
||||
generator.humanGenerator ());
|
||||
|
||||
beginTestCase ("RippleAccountID");
|
||||
RippleAddress deprecatedAccountPublicKey (
|
||||
RippleAddress::createAccountPublic (generator, 0));
|
||||
expect (deprecatedAccountPublicKey.humanAccountID () ==
|
||||
"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
|
||||
deprecatedAccountPublicKey.humanAccountID ());
|
||||
RippleAccountID accountID (deprecatedAccountPublicKey);
|
||||
expect (accountID.to_string() ==
|
||||
deprecatedAccountPublicKey.humanAccountID(),
|
||||
accountID.to_string());
|
||||
|
||||
beginTestCase ("RippleAccountPublicKey");
|
||||
expect (deprecatedAccountPublicKey.humanAccountPublic () ==
|
||||
"aBQG8RQAzjs1eTKFEAQXr2gS4utcDiEC9wmi7pfUPTi27VCahwgw",
|
||||
deprecatedAccountPublicKey.humanAccountPublic ());
|
||||
|
||||
beginTestCase ("RippleAccountPrivateKey");
|
||||
RippleAddress deprecatedAccountPrivateKey (
|
||||
RippleAddress::createAccountPrivate (generator, seed, 0));
|
||||
expect (deprecatedAccountPrivateKey.humanAccountPrivate () ==
|
||||
"p9JfM6HHi64m6mvB6v5k7G2b1cXzGmYiCNJf6GHPKvFTWdeRVjh",
|
||||
deprecatedAccountPrivateKey.humanAccountPrivate ());
|
||||
RippleAccountPrivateKey accountPrivateKey (deprecatedAccountPrivateKey);
|
||||
expect (accountPrivateKey.to_string() ==
|
||||
deprecatedAccountPrivateKey.humanAccountPrivate(),
|
||||
privateKey.to_string());
|
||||
}
|
||||
|
||||
RippleCryptoIdentifierTests () : UnitTest ("RippleCryptoIdentifier", "ripple")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
static RippleCryptoIdentifierTests rippleCryptoIdentifierTests;
|
||||
|
||||
@@ -31,11 +31,6 @@ private:
|
||||
public:
|
||||
RippleAddress ();
|
||||
|
||||
// Convert to a binary public key. If the underlying data
|
||||
// is not appropriate, this will cause a fatal error.
|
||||
//
|
||||
RipplePublicKey toRipplePublicKey () const;
|
||||
|
||||
// For public and private key, checks if they are legal.
|
||||
bool isValid () const
|
||||
{
|
||||
@@ -209,4 +204,56 @@ public:
|
||||
static RippleAddress createSeedGeneric (const std::string& strText);
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template <>
|
||||
struct RipplePublicKeyTraits::assign <RippleAddress>
|
||||
{
|
||||
void operator() (value_type& value, RippleAddress const& v) const
|
||||
{
|
||||
Blob const& b (v.getNodePublic ());
|
||||
construct (&b.front(), &b.back()+1, value);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct RipplePrivateKeyTraits::assign <RippleAddress>
|
||||
{
|
||||
void operator() (value_type& value, RippleAddress const& v) const
|
||||
{
|
||||
uint256 const ui (v.getNodePrivate ());
|
||||
construct (ui.begin(), ui.end(), value);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct RippleAccountIDTraits::assign <RippleAddress>
|
||||
{
|
||||
void operator() (value_type& value, RippleAddress const& v) const
|
||||
{
|
||||
uint160 const ui (v.getAccountID ());
|
||||
construct (ui.begin(), ui.end(), value);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct RippleAccountPublicKeyTraits::assign <RippleAddress>
|
||||
{
|
||||
void operator() (value_type& value, RippleAddress const& v) const
|
||||
{
|
||||
Blob const& b (v.getAccountPublic ());
|
||||
construct (&b.front(), &b.back()+1, value);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct RippleAccountPrivateKeyTraits::assign <RippleAddress>
|
||||
{
|
||||
void operator() (value_type& value, RippleAddress const& v) const
|
||||
{
|
||||
uint256 const ui (v.getAccountPrivate ());
|
||||
construct (ui.begin(), ui.end(), value);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user