ledger-core
EthereumLikeExtendedPublicKey.h
1 /*
2  *
3  * EthereumLikeExtendedPublicKey
4  * ledger-core
5  *
6  * Created by El Khalil Bellakrid on 08/07/2018.
7  *
8  * The MIT License (MIT)
9  *
10  * Copyright (c) 2018 Ledger
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy
13  * of this software and associated documentation files (the "Software"), to deal
14  * in the Software without restriction, including without limitation the rights
15  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16  * copies of the Software, and to permit persons to whom the Software is
17  * furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included in all
20  * copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28  * SOFTWARE.
29  *
30  */
31 #ifndef LEDGER_CORE_ETHEREUMLIKEEXTENDEDPUBLICKEY_H
32 #define LEDGER_CORE_ETHEREUMLIKEEXTENDEDPUBLICKEY_H
33 
34 #include <common/AbstractExtendedPublicKey.h>
35 #include <api/EthereumLikeExtendedPublicKey.hpp>
36 #include <crypto/DeterministicPublicKey.hpp>
37 #include <api/EthereumLikeNetworkParameters.hpp>
38 #include <memory>
39 #include <utils/Option.hpp>
40 #include <utils/DerivationPath.hpp>
41 #include <api/Currency.hpp>
42 
43 namespace ledger {
44  namespace core {
45  using EthereumExtendedPublicKey = AbstractExtendedPublicKey<api::EthereumLikeNetworkParameters>;
47  public:
48 
50  const DeterministicPublicKey& key,
51  const DerivationPath& path = DerivationPath("m/"));
52 
53  std::shared_ptr<api::EthereumLikeAddress> derive(const std::string & path) override ;
54  std::shared_ptr<EthereumLikeExtendedPublicKey> derive(const DerivationPath &path);
55  std::vector<uint8_t> derivePublicKey(const std::string & path) override ;
56 
57  std::vector<uint8_t> deriveHash160(const std::string & path) override ;
58 
59  std::string toBase58() override ;
60 
61  std::string getRootPath() override ;
62 
63  static std::shared_ptr<EthereumLikeExtendedPublicKey> fromRaw(const api::Currency& params,
64  const optional<std::vector<uint8_t>>& parentPublicKey,
65  const std::vector<uint8_t>& publicKey,
66  const std::vector<uint8_t> &chainCode,
67  const std::string& path);
68 
69  static std::shared_ptr<EthereumLikeExtendedPublicKey> fromBase58(const api::Currency& currency,
70  const std::string& xpubBase58,
71  const Option<std::string>& path);
72  protected:
73  const api::EthereumLikeNetworkParameters &params() const override {
74  return _currency.ethereumLikeNetworkParameters.value();
75  };
76  const DeterministicPublicKey &getKey() const override {
77  return _key;
78  };
79  const DerivationPath &getPath() const override {
80  return _path;
81  };
82  const api::Currency &getCurrency() const override {
83  return _currency;
84  };
85  private:
86  const api::Currency _currency;
87  const DerivationPath _path;
88  const DeterministicPublicKey _key;
89 
90  };
91  }
92 }
93 
94 
95 #endif //LEDGER_CORE_ETHEREUMLIKEEXTENDEDPUBLICKEY_H
std::string toBase58() override
Definition: EthereumLikeExtendedPublicKey.cpp:81
Definition: DeterministicPublicKey.hpp:38
std::string getRootPath() override
Definition: EthereumLikeExtendedPublicKey.cpp:85
Definition: AbstractExtendedPublicKey.h:54
std::vector< uint8_t > derivePublicKey(const std::string &path) override
Definition: EthereumLikeExtendedPublicKey.cpp:72
Definition: DerivationPath.hpp:40
Definition: EthereumLikeExtendedPublicKey.h:46
Definition: EthereumLikeExtendedPublicKey.hpp:24
Definition: Currency.hpp:23
std::vector< uint8_t > deriveHash160(const std::string &path) override
Definition: EthereumLikeExtendedPublicKey.cpp:77
Definition: Account.cpp:8
std::shared_ptr< api::EthereumLikeAddress > derive(const std::string &path) override
Definition: EthereumLikeExtendedPublicKey.cpp:59
Definition: EthereumLikeNetworkParameters.hpp:15
Definition: optional.hpp:177
std::experimental::optional< EthereumLikeNetworkParameters > ethereumLikeNetworkParameters
Definition: Currency.hpp:43