Kagome
Polkadot Runtime Engine in C++17
session_keys.cpp
Go to the documentation of this file.
1 
7 
9 
10 namespace kagome::crypto {
11 
12  SessionKeys::SessionKeys(std::shared_ptr<CryptoStore> store,
13  const network::Roles &roles)
14  : roles_(roles), store_(store) {}
15 
16  const std::shared_ptr<Sr25519Keypair> &SessionKeys::getBabeKeyPair() {
17  if (!babe_key_pair_ && roles_.flags.authority) {
18  auto keys = store_->getSr25519PublicKeys(KEY_TYPE_BABE);
19  if (keys and not keys.value().empty()) {
20  auto kp = store_->findSr25519Keypair(KEY_TYPE_BABE, keys.value().at(0));
21  babe_key_pair_ = std::make_shared<Sr25519Keypair>(kp.value());
22  }
23  }
24  return babe_key_pair_;
25  }
26 
27  const std::shared_ptr<Ed25519Keypair> &SessionKeys::getGranKeyPair() {
28  if (!gran_key_pair_ && roles_.flags.authority) {
29  auto keys = store_->getEd25519PublicKeys(KEY_TYPE_GRAN);
30  if (keys and not keys.value().empty()) {
31  auto kp = store_->findEd25519Keypair(KEY_TYPE_GRAN, keys.value().at(0));
32  gran_key_pair_ = std::make_shared<Ed25519Keypair>(kp.value());
33  }
34  }
35  return gran_key_pair_;
36  }
37 
38  const std::shared_ptr<Sr25519Keypair> &SessionKeys::getParaKeyPair() {
39  if (not para_key_pair_ && roles_.flags.authority) {
40  auto keys = store_->getSr25519PublicKeys(KEY_TYPE_PARA);
41  if (keys and not keys.value().empty()) {
42  auto kp = store_->findSr25519Keypair(KEY_TYPE_PARA, keys.value().at(0));
43  para_key_pair_ = std::make_shared<Sr25519Keypair>(kp.value());
44  }
45  }
46  return para_key_pair_;
47  }
48 
49  const std::shared_ptr<Sr25519Keypair> &SessionKeys::getAudiKeyPair() {
50  if (!audi_key_pair_ && roles_.flags.authority) {
51  auto keys = store_->getSr25519PublicKeys(KEY_TYPE_AUDI);
52  if (keys and not keys.value().empty()) {
53  auto kp = store_->findSr25519Keypair(KEY_TYPE_AUDI, keys.value().at(0));
54  audi_key_pair_ = std::make_shared<Sr25519Keypair>(kp.value());
55  }
56  }
57  return audi_key_pair_;
58  }
59 
60 } // namespace kagome::crypto
struct kagome::network::Roles::@11 flags
const std::shared_ptr< Sr25519Keypair > & getBabeKeyPair()
const std::shared_ptr< Ed25519Keypair > & getGranKeyPair()
const std::shared_ptr< Sr25519Keypair > & getParaKeyPair()
const std::shared_ptr< Sr25519Keypair > & getAudiKeyPair()
std::shared_ptr< Sr25519Keypair > para_key_pair_
std::shared_ptr< Ed25519Keypair > gran_key_pair_
std::shared_ptr< CryptoStore > store_
std::shared_ptr< Sr25519Keypair > audi_key_pair_
std::shared_ptr< Sr25519Keypair > babe_key_pair_
SessionKeys(std::shared_ptr< CryptoStore > store, const network::Roles &roles)