Kagome
Polkadot Runtime Engine in C++17
sr25519_types.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_CRYPTO_VRF_TYPES
7 #define KAGOME_CORE_CRYPTO_VRF_TYPES
8 
9 extern "C" {
10 #include <schnorrkel/schnorrkel.h>
11 }
12 #include <boost/multiprecision/cpp_int.hpp>
13 #include <gsl/span>
14 
15 #include "common/blob.hpp"
16 #include "common/mp_utils.hpp"
17 #include "scale/tie.hpp"
18 
19 namespace kagome::crypto {
20  namespace constants::sr25519 {
24  enum {
25  KEYPAIR_SIZE = SR25519_KEYPAIR_SIZE,
26  SECRET_SIZE = SR25519_SECRET_SIZE,
27  PUBLIC_SIZE = SR25519_PUBLIC_SIZE,
28  SIGNATURE_SIZE = SR25519_SIGNATURE_SIZE,
29  SEED_SIZE = SR25519_SEED_SIZE
30  };
31 
32  namespace vrf {
36  enum {
37  PROOF_SIZE = SR25519_VRF_PROOF_SIZE,
38  OUTPUT_SIZE = SR25519_VRF_OUTPUT_SIZE
39  };
40  } // namespace vrf
41 
42  } // namespace constants::sr25519
43 
44  using VRFPreOutput =
45  std::array<uint8_t, constants::sr25519::vrf::OUTPUT_SIZE>;
47  using VRFProof = std::array<uint8_t, constants::sr25519::vrf::PROOF_SIZE>;
48 
55  struct VRFOutput {
56  SCALE_TIE(2);
57 
58  // an internal representation of the generated random value
59  VRFPreOutput output{};
60  // the proof to the output, serves as the verification of its randomness
61  VRFProof proof{};
62  };
63 
67  struct VRFVerifyOutput {
68  // indicates if the proof is valid
69  bool is_valid;
70  // indicates if the value is less than the provided threshold
71  bool is_less;
72  };
73 } // namespace kagome::crypto
74 
76  Sr25519SecretKey,
79  Sr25519PublicKey,
82  Sr25519Signature,
85  Sr25519Seed,
87 
88 namespace kagome::crypto {
89  struct Sr25519Keypair {
90  Sr25519SecretKey secret_key;
91  Sr25519PublicKey public_key;
92 
93  Sr25519Keypair() = default;
94 
95  bool operator==(const Sr25519Keypair &other) const;
96  bool operator!=(const Sr25519Keypair &other) const;
97  };
98 
100  Sr25519Seed seed;
101  };
102 } // namespace kagome::crypto
103 
104 #endif // KAGOME_CORE_CRYPTO_VRF_TYPES
boost::multiprecision::uint128_t VRFThreshold
#define SCALE_TIE(N)
Definition: tie.hpp:11
KAGOME_BLOB_STRICT_TYPEDEF(kagome::crypto, Sr25519SecretKey, constants::sr25519::SECRET_SIZE)
std::array< uint8_t, constants::sr25519::vrf::PROOF_SIZE > VRFProof
std::array< uint8_t, constants::sr25519::vrf::OUTPUT_SIZE > VRFPreOutput
bool operator==(const Unused< N > &, const Unused< N > &)
Definition: unused.hpp:27
boost::multiprecision::uint128_t uint128_t
Definition: mp_utils.hpp:14