ledger-core
TezosLikeExtendedPublicKey.h
1 /*
2  *
3  * TezosLikeExtendedPublicKey
4  * ledger-core
5  *
6  * Created by El Khalil Bellakrid on 25/04/2019.
7  *
8  * The MIT License (MIT)
9  *
10  * Copyright (c) 2019 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_TEZOSLIKEEXTENDEDPUBLICKEY_H
32 #define LEDGER_CORE_TEZOSLIKEEXTENDEDPUBLICKEY_H
33 
34 #include <common/AbstractExtendedPublicKey.h>
35 #include <api/TezosLikeExtendedPublicKey.hpp>
36 #include <crypto/DeterministicPublicKey.hpp>
37 #include <api/TezosLikeNetworkParameters.hpp>
38 #include <memory>
39 #include <utils/Option.hpp>
40 #include <utils/DerivationPath.hpp>
41 #include <api/Currency.hpp>
42 #include <api/TezosCurve.hpp>
43 
44 namespace ledger {
45  namespace core {
46  using TezosExtendedPublicKey = AbstractExtendedPublicKey<api::TezosLikeNetworkParameters>;
47 
49  public:
50 
52  const DeterministicPublicKey &key,
53  api::TezosCurve curve,
54  const DerivationPath &path = DerivationPath("m/"));
55 
56  std::shared_ptr<api::TezosLikeAddress> derive(const std::string &path) override;
57 
58  std::shared_ptr<TezosLikeExtendedPublicKey> derive(const DerivationPath &path);
59 
60  std::vector<uint8_t> derivePublicKey(const std::string &path) override;
61 
62  std::vector<uint8_t> deriveHash160(const std::string &path) override;
63 
64  std::string toBase58() override;
65 
66  std::string getRootPath() override;
67 
68  static std::shared_ptr<TezosLikeExtendedPublicKey> fromRaw(const api::Currency &params,
69  const optional<std::vector<uint8_t>> &parentPublicKey,
70  const std::vector<uint8_t> &publicKey,
71  const std::vector<uint8_t> &chainCode,
72  const std::string &path,
73  api::TezosCurve curve);
74 
75  static std::shared_ptr<TezosLikeExtendedPublicKey> fromBase58(const api::Currency &currency,
76  const std::string &xpubBase58,
77  const Option<std::string> &path);
78 
79  protected:
80  const api::TezosLikeNetworkParameters &params() const override {
81  return _currency.tezosLikeNetworkParameters.value();
82  };
83 
84  const DeterministicPublicKey &getKey() const override {
85  return _key;
86  };
87 
88  const DerivationPath &getPath() const override {
89  return _path;
90  };
91 
92  const api::Currency &getCurrency() const override {
93  return _currency;
94  };
95  private:
96  const api::Currency _currency;
97  const DerivationPath _path;
98  const DeterministicPublicKey _key;
99  api::TezosCurve _curve;
100 
101  };
102  }
103 }
104 
105 
106 #endif //LEDGER_CORE_TEZOSLIKEEXTENDEDPUBLICKEY_H
std::string getRootPath() override
Definition: TezosLikeExtendedPublicKey.cpp:88
Definition: TezosLikeExtendedPublicKey.hpp:24
std::string toBase58() override
Definition: TezosLikeExtendedPublicKey.cpp:84
Definition: DeterministicPublicKey.hpp:38
Definition: TezosLikeExtendedPublicKey.h:48
std::shared_ptr< api::TezosLikeAddress > derive(const std::string &path) override
Definition: TezosLikeExtendedPublicKey.cpp:60
std::vector< uint8_t > deriveHash160(const std::string &path) override
Definition: TezosLikeExtendedPublicKey.cpp:80
std::vector< uint8_t > derivePublicKey(const std::string &path) override
Definition: TezosLikeExtendedPublicKey.cpp:75
Definition: AbstractExtendedPublicKey.h:54
Definition: DerivationPath.hpp:40
Definition: Currency.hpp:23
Definition: Account.cpp:8
std::experimental::optional< TezosLikeNetworkParameters > tezosLikeNetworkParameters
Definition: Currency.hpp:47
Definition: TezosLikeNetworkParameters.hpp:15
Definition: optional.hpp:177