13 namespace vrf_constants = constants::sr25519::vrf;
16 : generator_{std::move(generator)} {}
21 std::array<uint8_t, constants::sr25519::KEYPAIR_SIZE> kp{};
22 sr25519_keypair_from_seed(kp.data(), seed.data());
27 keypair.secret_key.begin());
31 keypair.public_key.begin());
50 const std::optional<std::reference_wrapper<const VRFThreshold>> threshold)
55 std::array<uint8_t, vrf_constants::OUTPUT_SIZE + vrf_constants::PROOF_SIZE>
57 auto threshold_value = threshold.value_or(std::cref(
kMaxThreshold));
59 auto sign_res = sr25519_vrf_sign_transcript(
62 reinterpret_cast<const Strobe128 *
>(msg.
data().data()),
63 threshold_bytes.data());
65 if (SR25519_SIGNATURE_RESULT_OK != sign_res.result) {
68 if (threshold.has_value() and not sign_res.is_less) {
85 const Sr25519PublicKey &public_key,
87 auto res = sr25519_vrf_verify_transcript(
89 reinterpret_cast<const Strobe128 *
>(msg.
data().data()),
94 .
is_valid = res.result == SR25519_SIGNATURE_RESULT_OK,
95 .is_less = res.is_less};
105 std::array<uint8_t, vrf_constants::OUTPUT_SIZE + vrf_constants::PROOF_SIZE>
108 auto sign_res = sr25519_vrf_sign_if_less(out_proof.data(),
112 threshold_bytes.data());
113 if (not sign_res.is_less
114 or (SR25519_SIGNATURE_RESULT_OK != sign_res.result)) {
130 const Sr25519PublicKey &public_key,
133 sr25519_vrf_verify(public_key.data(),
140 .
is_valid = res.result == SR25519_SIGNATURE_RESULT_OK,
141 .is_less = res.is_less};
Class represents arbitrary (including empty) byte buffer.
std::optional< VRFOutput > signTranscript(const primitives::Transcript &msg, const Sr25519Keypair &keypair, const VRFThreshold &threshold) const override
Sr25519SecretKey secret_key
std::optional< VRFOutput > signTranscriptImpl(const primitives::Transcript &msg, const Sr25519Keypair &keypair, const std::optional< std::reference_wrapper< const VRFThreshold >> threshold) const
VRFVerifyOutput verifyTranscript(const primitives::Transcript &msg, const VRFOutput &output, const Sr25519PublicKey &public_key, const VRFThreshold &threshold) const override
boost::multiprecision::uint128_t VRFThreshold
Sr25519Keypair generateKeypair() const override
std::shared_ptr< CSPRNG > generator_
SLBuffer & put(std::string_view view)
Put a string into byte buffer.
std::array< uint8_t, 16 > uint128_to_le_bytes(const boost::multiprecision::uint128_t &i)
VRFVerifyOutput verify(const common::Buffer &msg, const VRFOutput &output, const Sr25519PublicKey &public_key, const VRFThreshold &threshold) const override
std::optional< VRFOutput > sign(const common::Buffer &msg, const Sr25519Keypair &keypair, const VRFThreshold &threshold) const override
VRFProviderImpl(std::shared_ptr< CSPRNG > generator)
static constexpr VRFThreshold kMaxThreshold
Sr25519PublicKey public_key