20 #include <ripple/basics/random.h>
21 #include <ripple/beast/unit_test.h>
22 #include <ripple/beast/utility/rngfill.h>
23 #include <ripple/beast/xor_shift_engine.h>
24 #include <ripple/protocol/PublicKey.h>
25 #include <ripple/protocol/SecretKey.h>
26 #include <ripple/protocol/Seed.h>
47 testcase(
"construction");
55 Seed const seed({src,
sizeof(src)});
56 BEAST_EXPECT(memcmp(seed.data(), src,
sizeof(src)) == 0);
60 for (
int i = 0; i < 64; i++)
65 BEAST_EXPECT(memcmp(seed.
data(), src.
data(), src.
size()) == 0);
73 auto const seed2 = parseBase58<Seed>(
toBase58(seed1));
75 BEAST_EXPECT(
static_cast<bool>(seed2));
76 BEAST_EXPECT(
equal(seed1, *seed2));
83 testcase(
"generation from passphrase");
86 "snoPBrXtMeMyMHUVTgbuqAfg1SUTb");
89 "snMKnVku798EnBwUfxeSD8953sLYA");
92 "sspUXGrmjQhq6mgc24jiRuevZiwKT");
98 testcase(
"base58 operations");
101 BEAST_EXPECT(parseBase58<Seed>(
"snoPBrXtMeMyMHUVTgbuqAfg1SUTb"));
102 BEAST_EXPECT(parseBase58<Seed>(
"snMKnVku798EnBwUfxeSD8953sLYA"));
103 BEAST_EXPECT(parseBase58<Seed>(
"sspUXGrmjQhq6mgc24jiRuevZiwKT"));
106 BEAST_EXPECT(!parseBase58<Seed>(
""));
107 BEAST_EXPECT(!parseBase58<Seed>(
"sspUXGrmjQhq6mgc24jiRuevZiwK"));
108 BEAST_EXPECT(!parseBase58<Seed>(
"sspUXGrmjQhq6mgc24jiRuevZiwKTT"));
109 BEAST_EXPECT(!parseBase58<Seed>(
"sspOXGrmjQhq6mgc24jiRuevZiwKT"));
110 BEAST_EXPECT(!parseBase58<Seed>(
"ssp/XGrmjQhq6mgc24jiRuevZiwKT"));
116 testcase(
"random generation");
118 for (
int i = 0; i < 32; i++)
121 auto const seed2 = parseBase58<Seed>(
toBase58(seed1));
123 BEAST_EXPECT(
static_cast<bool>(seed2));
124 BEAST_EXPECT(
equal(seed1, *seed2));
131 std::string const message1 =
"http://www.ripple.com";
132 std::string const message2 =
"https://www.ripple.com";
135 testcase(
"Node keypair generation & signing (secp256k1)");
139 auto const publicKey =
144 "n94a1u4jAz288pZLtw6yFWVbi89YamiC6JBXPVUj5zmExe5fTVg9");
147 "pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe");
150 "7E59C17D50F5959C7B158FEC95C8F815BF653DC8");
153 BEAST_EXPECT(sig.size() != 0);
172 if (
auto ptr = sig.data())
173 ptr[sig.size() / 2]++;
180 testcase(
"Node keypair generation & signing (ed25519)");
188 "nHUeeJCSY2dM71oxM8Cgjouf5ekTuev2mwDpc374aLMxzDLXNmjf");
191 "paKv46LztLqK3GaKz1rG2nQGN6M4JLyRtxFBYFTw4wAVHtGys36");
194 "AA066C988C712815CC37AF71472B7CBBBD4E2A0A");
197 BEAST_EXPECT(sig.size() != 0);
216 if (
auto ptr = sig.data())
217 ptr[sig.size() / 2]++;
224 testcase(
"Account keypair generation & signing (secp256k1)");
231 "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
234 "aBQG8RQAzjs1eTKFEAQXr2gS4utcDiEC9wmi7pfUPTi27VCahwgw");
237 "p9JfM6HHi64m6mvB6v5k7G2b1cXzGmYiCNJf6GHPKvFTWdeRVjh");
240 BEAST_EXPECT(sig.size() != 0);
258 if (
auto ptr = sig.data())
259 ptr[sig.size() / 2]++;
266 testcase(
"Account keypair generation & signing (ed25519)");
273 "rGWrZyQqhTp9Xu7G5Pkayo7bXjH4k4QYpf");
276 "aKGheSBjmCsKJVuLNKRAKpZXT6wpk2FCuEZAXJupXgdAxX5THCqR");
279 "pwDQjwEhbUBmPuEjFpEG75bFhv2obkCB7NxQsfFxM7xGHBMVPu9");
282 BEAST_EXPECT(sig.size() != 0);
300 if (
auto ptr = sig.data())
301 ptr[sig.size() / 2]++;
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.
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical) noexcept
Verify a signature on a message.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
void testKeypairGenerationAndSigning()
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
constexpr static std::size_t size()
Integers of any length that is a multiple of 32-bits.
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.
SecretKey generateSecretKey(KeyType type, Seed const &seed)
Generate a new secret key deterministically.
std::optional< Seed > parseGenericSeed(std::string const &str, bool rfc1751)
Attempt to parse a string as a seed.
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 to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
std::string testPassphrase(std::string passphrase)
std::uint8_t const * data() const