Kagome
Polkadot Runtime Engine in C++17
dev_mnemonic_phrase.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CRYPTO_DEV_MNEMONIC_PHRASE_HPP
7 #define KAGOME_CRYPTO_DEV_MNEMONIC_PHRASE_HPP
8 
9 #include <map>
10 #include <optional>
11 
12 #include "crypto/ed25519_types.hpp"
13 #include "crypto/sr25519_types.hpp"
14 
15 namespace kagome::crypto {
17  static constexpr std::string_view kWords =
18  "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
19 
20  // junctions are not supported yet
21  std::map<std::string, std::pair<Ed25519Seed, Sr25519Seed>, std::less<>>
23 
24  // clang-format off
26  alice{precompute("//Alice",
27  "abf8e5bdbe30c65656c0a3cbd181ff8a56294a69dfedd27982aace4a76909115",
28  "e5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a"
29  )},
30  bob{precompute("//Bob",
31  "3b7b60af2abcd57ba401ab398f84f4ca54bd6b2140d2503fbcf3286535fe3ff1",
32  "398f0c28f98885e046333d4a41c19cee4c37368a9832c6502f6cfd182e2aef89"
33  )},
34  charlie{precompute("//Charlie",
35  "072c02fa1409dc37e03a4ed01703d4a9e6bba9c228a49a00366e9630a97cba7c",
36  "bc1ede780f784bb6991a585e4f6e61522c14e1cae6ad0895fb57b9a205a8f938"
37  )},
38  dave{precompute("//Dave",
39  "771f47d3caf8a2ee40b0719e1c1ecbc01d73ada220cf08df12a00453ab703738",
40  "868020ae0687dda7d57565093a69090211449845a7e11453612800b663307246"
41  )},
42  eve{precompute("//Eve",
43  "bef5a3cd63dd36ab9792364536140e5a0cce6925969940c431934de056398556",
44  "786ad0e2df456fe43dd1f91ebca22e235bc162e0bb8d53c633e8c85b2af68b7a"
45  )},
46  ferdie{precompute("//Ferdie",
47  "1441e38eb309b66e9286867a5cd05902b05413eb9723a685d4d77753d73d0a1d",
48  "42438b7883391c05512a938e36c2df0131e088b3756d6aa7a755fbff19d2f842"
49  )}
50  {}
51  // clang-format on
52 
53  std::string precompute(std::string_view junctions,
54  std::string_view ed25519_seed,
55  std ::string_view sr25519_seed) {
56  std::string mnemonic_phrase{kWords};
57  mnemonic_phrase += junctions;
58  precomputed[mnemonic_phrase] = {
59  Ed25519Seed::fromHex(ed25519_seed).value(),
60  Sr25519Seed::fromHex(sr25519_seed).value(),
61  };
62  return mnemonic_phrase;
63  }
64 
65  public:
66  static const DevMnemonicPhrase &get() {
67  static const DevMnemonicPhrase self;
68  return self;
69  }
70 
71  template <typename Seed>
72  std::optional<Seed> find(std::string_view mnemonic_phrase) const {
73  if constexpr (std::is_same_v<
74  Seed,
75  Ed25519Seed> || std::is_same_v<Seed, Sr25519Seed>) {
76  auto it = precomputed.find(mnemonic_phrase);
77  if (it != precomputed.end()) {
78  if constexpr (std::is_same_v<Seed, Ed25519Seed>) {
79  return it->second.first;
80  }
81  if constexpr (std::is_same_v<Seed, Sr25519Seed>) {
82  return it->second.second;
83  }
84  }
85  }
86  return std::nullopt;
87  }
88 
89  const std::string alice;
90  const std::string bob;
91  const std::string charlie;
92  const std::string dave;
93  const std::string eve;
94  const std::string ferdie;
95  };
96 } // namespace kagome::crypto
97 
98 #endif // KAGOME_CRYPTO_DEV_MNEMONIC_PHRASE_HPP
std::string precompute(std::string_view junctions, std::string_view ed25519_seed, std::string_view sr25519_seed)
static constexpr std::string_view kWords
std::optional< Seed > find(std::string_view mnemonic_phrase) const
std::map< std::string, std::pair< Ed25519Seed, Sr25519Seed >, std::less<> > precomputed