Kagome
Polkadot Runtime Engine in C++17
ecdsa_provider_impl.cpp
Go to the documentation of this file.
1 
7 
8 namespace kagome::crypto {
9 
11  : provider_{std::make_shared<Libp2pEcdsaProviderImpl>()} {}
12 
14  std::shared_ptr<Libp2pEcdsaProvider> provider)
15  : provider_{std::move(provider)},
16  logger_{log::createLogger("EcdsaProvider", "ecdsa")} {
17  BOOST_ASSERT(provider_ != nullptr);
18  }
19 
20  outcome::result<EcdsaKeypairAndSeed> EcdsaProviderImpl::generate() const {
21  OUTCOME_TRY(key_pair, provider_->generate());
22  return EcdsaKeypairAndSeed{
24  EcdsaPrivateKey{common::Blob{key_pair.private_key}},
25  EcdsaPublicKey{common::Blob{key_pair.public_key}},
26  },
27  EcdsaSeed{common::Blob{key_pair.private_key}},
28  };
29  }
30 
31  outcome::result<EcdsaPublicKey> EcdsaProviderImpl::derive(
32  const EcdsaSeed &seed) const {
33  // seed here is private key
34  OUTCOME_TRY(public_key, provider_->derive(EcdsaPrivateKey{seed}));
35  EcdsaPublicKey res;
36  std::copy(public_key.begin(), public_key.end(), res.begin());
37  return res;
38  }
39 
40  outcome::result<EcdsaSignature> EcdsaProviderImpl::sign(
41  gsl::span<const uint8_t> message, const EcdsaPrivateKey &key) const {
42  return provider_->sign(message, key);
43  }
44 
45  outcome::result<EcdsaSignature> EcdsaProviderImpl::signPrehashed(
46  const EcdsaPrehashedMessage &message, const EcdsaPrivateKey &key) const {
47  return provider_->signPrehashed(message, key);
48  }
49 
50  outcome::result<bool> EcdsaProviderImpl::verify(
51  gsl::span<const uint8_t> message,
52  const EcdsaSignature &signature,
53  const EcdsaPublicKey &publicKey) const {
54  return provider_->verify(message, signature, publicKey);
55  }
56 
57  outcome::result<bool> EcdsaProviderImpl::verifyPrehashed(
58  const EcdsaPrehashedMessage &message,
59  const EcdsaSignature &signature,
60  const EcdsaPublicKey &publicKey) const {
61  return provider_->verifyPrehashed(message, signature, publicKey);
62  }
63 } // namespace kagome::crypto
outcome::result< EcdsaPublicKey > derive(const EcdsaSeed &seed) const override
outcome::result< EcdsaSignature > signPrehashed(const EcdsaPrehashedMessage &message, const EcdsaPrivateKey &key) const override
outcome::result< EcdsaKeypairAndSeed > generate() const override
std::vector< uint8_t > EcdsaSignature
Definition: ecdsa_types.hpp:43
outcome::result< bool > verify(gsl::span< const uint8_t > message, const EcdsaSignature &signature, const EcdsaPublicKey &publicKey) const override
libp2p::crypto::ecdsa::PrehashedMessage EcdsaPrehashedMessage
Definition: ecdsa_types.hpp:45
Logger createLogger(const std::string &tag)
Definition: logger.cpp:112
outcome::result< bool > verifyPrehashed(const EcdsaPrehashedMessage &message, const EcdsaSignature &signature, const EcdsaPublicKey &publicKey) const override
outcome::result< EcdsaSignature > sign(gsl::span< const uint8_t > message, const EcdsaPrivateKey &key) const override
std::shared_ptr< Libp2pEcdsaProvider > provider_