ledger-core
EthereumLikeKeychain.hpp
1 /*
2  *
3  * EthereumLikeKeychain
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_ETHEREUMLIKEKEYCHAIN_HPP
32 #define LEDGER_CORE_ETHEREUMLIKEKEYCHAIN_HPP
33 
34 #include <string>
35 #include <vector>
36 #include <utils/DerivationScheme.hpp>
37 #include <utils/Option.hpp>
38 #include <preferences/Preferences.hpp>
39 #include <api/Configuration.hpp>
40 #include <api/DynamicObject.hpp>
41 #include <api/Currency.hpp>
42 #include <api/AccountCreationInfo.hpp>
43 #include <api/ExtendedKeyAccountCreationInfo.hpp>
44 #include <api/EthereumLikeExtendedPublicKey.hpp>
45 #include <ethereum/EthereumLikeAddress.h>
46 
47 namespace ledger {
48  namespace core {
49 
51 
52  public:
53  using Address = std::shared_ptr<EthereumLikeAddress>;
54 
55  EthereumLikeKeychain(const std::shared_ptr<api::DynamicObject>& configuration,
56  const api::Currency& params,
57  int account,
58  const std::shared_ptr<Preferences>& preferences);
59 
60 
61  EthereumLikeKeychain(const std::shared_ptr<api::DynamicObject> &configuration,
62  const api::Currency &params,
63  int account,
64  const std::shared_ptr<api::EthereumLikeExtendedPublicKey> &xpub,
65  const std::shared_ptr<Preferences> &preferences);
66 
67  EthereumLikeKeychain(const std::shared_ptr<api::DynamicObject> &configuration,
68  const api::Currency &params,
69  int account,
70  const std::string &accountAddress,
71  const std::shared_ptr<Preferences>& preferences);
72  std::vector<Address> getAllObservableAddresses(uint32_t from, uint32_t to);
73  Address getAddress() const;
74  Option<std::string> getAddressDerivationPath(const std::string &address) const ;
75  std::shared_ptr<api::EthereumLikeExtendedPublicKey> getExtendedPublicKey() const;
76 
77  int getAccountIndex() const;
78  const api::EthereumLikeNetworkParameters& getNetworkParameters() const;
79  const api::Currency& getCurrency() const;
80 
81  Option<std::vector<uint8_t>> getPublicKey(const std::string& address) const ;
82 
83 
84  std::shared_ptr<api::DynamicObject> getConfiguration() const;
85  const DerivationScheme& getDerivationScheme() const;
86  const DerivationScheme& getFullDerivationScheme() const;
87 
88  std::string getRestoreKey() const ;
89  bool contains(const std::string& address) const ;
90  int32_t getOutputSizeAsSignedTxInput() const ;
91  protected:
92  std::shared_ptr<Preferences> getPreferences() const;
93  DerivationScheme& getDerivationScheme();
94 
95  private:
96  EthereumLikeKeychain::Address derive();
97  const api::Currency _currency;
98  DerivationScheme _scheme;
99  DerivationScheme _fullScheme;
100  int _account;
101  std::shared_ptr<Preferences> _preferences;
102  std::shared_ptr<api::DynamicObject> _configuration;
103  std::shared_ptr<api::EthereumLikeExtendedPublicKey> _xpub;
104  std::string _localPath;
105  std::string _address;
106  };
107  }
108 }
109 
110 #endif //LEDGER_CORE_ETHEREUMLIKEKEYCHAIN_HPP
Definition: EthereumLikeKeychain.hpp:50
Definition: DerivationScheme.hpp:55
Definition: Currency.hpp:23
Definition: Account.cpp:8
Definition: EthereumLikeNetworkParameters.hpp:15