20 #include <ripple/basics/random.h>
21 #include <ripple/protocol/PublicKey.h>
22 #include <ripple/protocol/SecretKey.h>
23 #include <ripple/protocol/Seed.h>
24 #include <ripple/beast/unit_test.h>
25 #include <ripple/beast/utility/rngfill.h>
26 #include <ripple/beast/xor_shift_engine.h>
45 testcase (
"construction");
56 Seed const seed ({ src,
sizeof(src) });
57 BEAST_EXPECT(memcmp (seed.data(), src,
sizeof(src)) == 0);
61 for (
int i = 0; i < 64; i++)
68 Seed const seed (src);
69 BEAST_EXPECT(memcmp (seed.
data(), src.
data(), src.
size()) == 0);
76 auto const seed2 = parseBase58<Seed>(
toBase58(seed1));
78 BEAST_EXPECT(
static_cast<bool>(seed2));
79 BEAST_EXPECT(
equal (seed1, *seed2));
85 testcase (
"generation from passphrase");
87 "snoPBrXtMeMyMHUVTgbuqAfg1SUTb");
89 "snMKnVku798EnBwUfxeSD8953sLYA");
91 "sspUXGrmjQhq6mgc24jiRuevZiwKT");
96 testcase (
"base58 operations");
99 BEAST_EXPECT(parseBase58<Seed>(
"snoPBrXtMeMyMHUVTgbuqAfg1SUTb"));
100 BEAST_EXPECT(parseBase58<Seed>(
"snMKnVku798EnBwUfxeSD8953sLYA"));
101 BEAST_EXPECT(parseBase58<Seed>(
"sspUXGrmjQhq6mgc24jiRuevZiwKT"));
104 BEAST_EXPECT(!parseBase58<Seed>(
""));
105 BEAST_EXPECT(!parseBase58<Seed>(
"sspUXGrmjQhq6mgc24jiRuevZiwK"));
106 BEAST_EXPECT(!parseBase58<Seed>(
"sspUXGrmjQhq6mgc24jiRuevZiwKTT"));
107 BEAST_EXPECT(!parseBase58<Seed>(
"sspOXGrmjQhq6mgc24jiRuevZiwKT"));
108 BEAST_EXPECT(!parseBase58<Seed>(
"ssp/XGrmjQhq6mgc24jiRuevZiwKT"));
113 testcase (
"random generation");
115 for (
int i = 0; i < 32; i++)
118 auto const seed2 = parseBase58<Seed>(
toBase58(seed1));
120 BEAST_EXPECT(
static_cast<bool>(seed2));
121 BEAST_EXPECT(
equal (seed1, *seed2));
127 std::string const message1 =
"http://www.ripple.com";
128 std::string const message2 =
"https://www.ripple.com";
131 testcase (
"Node keypair generation & signing (secp256k1)");
139 "n94a1u4jAz288pZLtw6yFWVbi89YamiC6JBXPVUj5zmExe5fTVg9");
141 "pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe");
143 "7E59C17D50F5959C7B158FEC95C8F815BF653DC8");
146 BEAST_EXPECT(sig.size() != 0);
166 if (
auto ptr = sig.data())
167 ptr[sig.size() / 2]++;
174 testcase (
"Node keypair generation & signing (ed25519)");
182 "nHUeeJCSY2dM71oxM8Cgjouf5ekTuev2mwDpc374aLMxzDLXNmjf");
184 "paKv46LztLqK3GaKz1rG2nQGN6M4JLyRtxFBYFTw4wAVHtGys36");
186 "AA066C988C712815CC37AF71472B7CBBBD4E2A0A");
189 BEAST_EXPECT(sig.size() != 0);
209 if (
auto ptr = sig.data())
210 ptr[sig.size() / 2]++;
217 testcase (
"Account keypair generation & signing (secp256k1)");
224 "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
226 "aBQG8RQAzjs1eTKFEAQXr2gS4utcDiEC9wmi7pfUPTi27VCahwgw");
228 "p9JfM6HHi64m6mvB6v5k7G2b1cXzGmYiCNJf6GHPKvFTWdeRVjh");
231 BEAST_EXPECT(sig.size() != 0);
249 if (
auto ptr = sig.data())
250 ptr[sig.size() / 2]++;
257 testcase (
"Account keypair generation & signing (ed25519)");
264 "rGWrZyQqhTp9Xu7G5Pkayo7bXjH4k4QYpf");
266 "aKGheSBjmCsKJVuLNKRAKpZXT6wpk2FCuEZAXJupXgdAxX5THCqR");
268 "pwDQjwEhbUBmPuEjFpEG75bFhv2obkCB7NxQsfFxM7xGHBMVPu9");
271 BEAST_EXPECT(sig.size() != 0);
289 if (
auto ptr = sig.data())
290 ptr[sig.size() / 2]++;
299 testcase (
"Parsing");
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, ripple)
NodeID calcNodeID(PublicKey const &pk)
Calculate the 160-bit node ID from a node public key.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::string to_string(ListDisposition disposition)
void testKeypairGenerationAndSigning()
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
constexpr static std::size_t size()
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical)
Verify a signature on a message.
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
AccountID calcAccountID(PublicKey const &pk)
Seed randomSeed()
Create a seed using secure random numbers.
beast::xor_shift_engine & default_prng()
Return the default random engine.
boost::optional< Seed > parseGenericSeed(std::string const &str)
Attempt to parse a string as a seed.
SecretKey generateSecretKey(KeyType type, Seed const &seed)
Generate a new secret key deterministically.
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Seeds are used to generate deterministic secret keys.
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &m)
Generate a signature for a message.
void rngfill(void *buffer, std::size_t bytes, Generator &g)
static bool equal(Seed const &lhs, Seed const &rhs)
std::string testPassphrase(std::string passphrase)
std::uint8_t const * data() const