ledger-core
TezosLikeAddress.h
1 /*
2  *
3  * TezosLikeAddress
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_TEZOSLIKEADDRESS_H
32 #define LEDGER_CORE_TEZOSLIKEADDRESS_H
33 
34 #include <api/TezosLikeAddress.hpp>
35 #include <api/TezosLikeNetworkParameters.hpp>
36 #include "../utils/optional.hpp"
37 #include <wallet/common/AbstractAddress.h>
38 #include <api/TezosCurve.hpp>
39 
40 namespace ledger {
41  namespace core {
43  public:
44  TezosLikeAddress(const api::Currency &currency,
45  const std::vector<uint8_t> &hash160,
46  const std::vector<uint8_t> &version,
47  const Option<std::string> &derivationPath = Option<std::string>());
48 
49  TezosLikeAddress(const api::Currency &currency,
50  const std::vector<uint8_t> &pubKey,
51  const std::vector<uint8_t> &version,
52  api::TezosCurve curve,
53  const Option<std::string> &derivationPath = Option<std::string>());
54 
55  std::vector<uint8_t> getVersion() override;
56 
57  std::vector<uint8_t> getHash160() override;
58 
60 
61  std::string toBase58() override;
62 
63  virtual optional<std::string> getDerivationPath() override;
64 
65  std::string toString() override;
66 
67  static std::shared_ptr<AbstractAddress> parse(const std::string &address,
68  const api::Currency &currency,
69  const Option<std::string> &derivationPath = Option<std::string>());
70 
71  static std::shared_ptr<TezosLikeAddress> fromBase58(const std::string &address,
72  const api::Currency &currency,
73  const Option<std::string> &derivationPath = Option<std::string>());
74 
75  static std::vector<uint8_t> getPrefixFromImplicitVersion(const std::vector<uint8_t> &implicitVersion, api::TezosCurve curve);
76  private:
77  static std::vector<uint8_t> getPublicKeyHash160(const std::vector<uint8_t> &pubKey, api::TezosCurve curve);
78  const std::vector<uint8_t> _hash160;
79  const std::vector<uint8_t> _version;
80  const api::TezosLikeNetworkParameters _params;
81  const Option<std::string> _derivationPath;
82  };
83  }
84 }
85 #endif //LEDGER_CORE_TEZOSLIKEADDRESS_H
std::string toString() override
Definition: TezosLikeAddress.cpp:84
virtual optional< std::string > getDerivationPath() override
Definition: TezosLikeAddress.cpp:80
Definition: TezosLikeAddress.hpp:23
std::vector< uint8_t > getHash160() override
Definition: TezosLikeAddress.cpp:66
Definition: AbstractAddress.h:42
Definition: TezosLikeAddress.h:42
Definition: Currency.hpp:23
Definition: Account.cpp:8
std::vector< uint8_t > getVersion() override
Definition: TezosLikeAddress.cpp:62
std::string toBase58() override
Definition: TezosLikeAddress.cpp:74
Definition: TezosLikeNetworkParameters.hpp:15
api::TezosLikeNetworkParameters getNetworkParameters() override
Definition: TezosLikeAddress.cpp:70
Definition: optional.hpp:177