6 #ifndef KAGOME_CRYPTO_SUITES_HPP 7 #define KAGOME_CRYPTO_SUITES_HPP 19 template <
typename PublicKeyT,
22 typename KeypairAndSeedT,
38 const Seed &seed)
const noexcept = 0;
60 const
Keypair &kp) const noexcept = 0;
66 gsl::span<const uint8_t> bytes) const noexcept = 0;
72 gsl::span<const uint8_t> bytes) const noexcept = 0;
81 explicit EcdsaSuite(std::shared_ptr<EcdsaProvider> ecdsa_provider)
82 : ecdsa_provider_{std::move(ecdsa_provider)} {
83 BOOST_ASSERT(ecdsa_provider_ !=
nullptr);
89 const noexcept
override {
90 return ecdsa_provider_->generate();
94 const EcdsaSeed &seed)
const noexcept
override {
95 OUTCOME_TRY(public_key, ecdsa_provider_->derive(seed));
101 return EcdsaKeypair{.
secret_key = std::move(priv),
102 .public_key = std::move(pub)};
106 const EcdsaKeypair &kp)
const noexcept
override {
107 return {kp.public_key, kp.secret_key};
111 gsl::span<const uint8_t> bytes)
const noexcept
override {
112 OUTCOME_TRY(blob, EcdsaPublicKey::fromSpan(bytes));
113 return EcdsaPublicKey{blob};
117 gsl::span<const uint8_t> bytes)
const noexcept
override {
128 Ed25519KeypairAndSeed,
132 : ed_provider_{std::move(ed_provider)} {
133 BOOST_ASSERT(ed_provider_ !=
nullptr);
139 const noexcept
override {
140 return ed_provider_->generateKeypair();
144 const Ed25519Seed &seed)
const noexcept
override {
145 return ed_provider_->generateKeypair(seed);
151 .public_key = std::move(pub)};
156 return {kp.public_key, kp.secret_key};
160 gsl::span<const uint8_t> bytes)
const noexcept
override {
161 OUTCOME_TRY(blob, Ed25519PublicKey::fromSpan(bytes));
162 return Ed25519PublicKey{blob};
166 gsl::span<const uint8_t> bytes)
const noexcept
override {
167 return Ed25519Seed::fromSpan(bytes);
177 Sr25519KeypairAndSeed,
181 : sr_provider_{std::move(sr_provider)} {
182 BOOST_ASSERT(sr_provider_ !=
nullptr);
188 const noexcept
override {
189 return sr_provider_->generateKeypair();
193 const Sr25519Seed &seed)
const noexcept
override {
194 return sr_provider_->generateKeypair(seed);
200 .public_key = std::move(pub)};
205 return {kp.public_key, kp.secret_key};
209 gsl::span<const uint8_t> bytes)
const noexcept
override {
210 OUTCOME_TRY(blob, Sr25519PublicKey::fromSpan(bytes));
211 return Sr25519PublicKey{std::move(blob)};
215 gsl::span<const uint8_t> bytes)
const noexcept
override {
216 return Sr25519Seed::fromSpan(bytes);
225 #endif // KAGOME_CRYPTO_SUITES_HPP EcdsaSuite(std::shared_ptr< EcdsaProvider > ecdsa_provider)
outcome::result< Sr25519Keypair > generateKeypair(const Sr25519Seed &seed) const noexceptoverride
Sr25519Keypair composeKeypair(PublicKey pub, PrivateKey priv) const noexceptoverride
Sr25519SecretKey secret_key
std::shared_ptr< EcdsaProvider > ecdsa_provider_
Sr25519Suite(std::shared_ptr< Sr25519Provider > sr_provider)
Ed25519Keypair composeKeypair(PublicKey pub, PrivateKey priv) const noexceptoverride
virtual outcome::result< Seed > toSeed(gsl::span< const uint8_t > bytes) const noexcept=0
Ed25519PrivateKey secret_key
virtual outcome::result< KeypairAndSeed > generateRandomKeypair() const noexcept=0
outcome::result< Seed > toSeed(gsl::span< const uint8_t > bytes) const noexceptoverride
virtual outcome::result< PublicKey > toPublicKey(gsl::span< const uint8_t > bytes) const noexcept=0
virtual Keypair composeKeypair(PublicKey pub, PrivateKey priv) const noexcept=0
Ed25519PrivateKey PrivateKey
EcdsaPrivateKey secret_key
outcome::result< Ed25519KeypairAndSeed > generateRandomKeypair() const noexceptoverride
outcome::result< Ed25519Keypair > generateKeypair(const Ed25519Seed &seed) const noexceptoverride
std::shared_ptr< Sr25519Provider > sr_provider_
static outcome::result< Blob< size_ > > fromSpan(const gsl::span< const uint8_t > &span)
outcome::result< Seed > toSeed(gsl::span< const uint8_t > bytes) const noexceptoverride
outcome::result< PublicKey > toPublicKey(gsl::span< const uint8_t > bytes) const noexceptoverride
Ed25519Suite(std::shared_ptr< Ed25519Provider > ed_provider)
std::shared_ptr< Ed25519Provider > ed_provider_
std::pair< PublicKey, PrivateKey > decomposeKeypair(const EcdsaKeypair &kp) const noexceptoverride
outcome::result< Sr25519KeypairAndSeed > generateRandomKeypair() const noexceptoverride
outcome::result< EcdsaKeypair > generateKeypair(const EcdsaSeed &seed) const noexceptoverride
Ed25519PublicKey PublicKey
outcome::result< PublicKey > toPublicKey(gsl::span< const uint8_t > bytes) const noexceptoverride
outcome::result< PublicKey > toPublicKey(gsl::span< const uint8_t > bytes) const noexceptoverride
virtual outcome::result< Keypair > generateKeypair(const Seed &seed) const noexcept=0
outcome::result< Seed > toSeed(gsl::span< const uint8_t > bytes) const noexceptoverride
std::pair< PublicKey, PrivateKey > decomposeKeypair(const Ed25519Keypair &kp) const noexceptoverride
outcome::result< EcdsaKeypairAndSeed > generateRandomKeypair() const noexceptoverride
virtual std::pair< PublicKey, PrivateKey > decomposeKeypair(const Keypair &kp) const noexcept=0
virtual ~CryptoSuite()=default
EcdsaKeypair composeKeypair(PublicKey pub, PrivateKey priv) const noexceptoverride
std::pair< PublicKey, PrivateKey > decomposeKeypair(const Sr25519Keypair &kp) const noexceptoverride