ledger-core
RippleLikeKeychain.h
1 /*
2  *
3  * RippleLikeKeychain
4  *
5  * Created by El Khalil Bellakrid on 05/01/2019.
6  *
7  * The MIT License (MIT)
8  *
9  * Copyright (c) 2019 Ledger
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a copy
12  * of this software and associated documentation files (the "Software"), to deal
13  * in the Software without restriction, including without limitation the rights
14  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  * copies of the Software, and to permit persons to whom the Software is
16  * furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in all
19  * copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  *
29  */
30 
31 
32 #ifndef LEDGER_CORE_RIPPLELIKEKEYCHAIN_H
33 #define LEDGER_CORE_RIPPLELIKEKEYCHAIN_H
34 
35 
36 #include <string>
37 #include <vector>
38 #include <utils/DerivationScheme.hpp>
39 #include <utils/Option.hpp>
40 #include <preferences/Preferences.hpp>
41 #include <api/Configuration.hpp>
42 #include <api/DynamicObject.hpp>
43 #include <api/Currency.hpp>
44 #include <api/AccountCreationInfo.hpp>
45 #include <api/ExtendedKeyAccountCreationInfo.hpp>
46 #include <api/RippleLikeExtendedPublicKey.hpp>
47 #include <ripple/RippleLikeAddress.h>
48 
49 namespace ledger {
50  namespace core {
51 
53 
54  public:
55  using Address = std::shared_ptr<RippleLikeAddress>;
56 
57  RippleLikeKeychain(const std::shared_ptr<api::DynamicObject> &configuration,
58  const api::Currency &params,
59  int account,
60  const std::shared_ptr<Preferences> &preferences);
61 
62 
63  RippleLikeKeychain(const std::shared_ptr<api::DynamicObject> &configuration,
64  const api::Currency &params,
65  int account,
66  const std::shared_ptr<api::RippleLikeExtendedPublicKey> &xpub,
67  const std::shared_ptr<Preferences> &preferences);
68 
69  RippleLikeKeychain(const std::shared_ptr<api::DynamicObject> &configuration,
70  const api::Currency &params,
71  int account,
72  const std::string &accountAddress,
73  const std::shared_ptr<Preferences> &preferences);
74 
75  std::vector<Address> getAllObservableAddresses(uint32_t from, uint32_t to);
76 
77  Address getAddress() const;
78 
79  Option<std::string> getAddressDerivationPath(const std::string &address) const;
80 
81  std::shared_ptr<api::RippleLikeExtendedPublicKey> getExtendedPublicKey() const;
82 
83  int getAccountIndex() const;
84 
85  const api::RippleLikeNetworkParameters &getNetworkParameters() const;
86 
87  const api::Currency &getCurrency() const;
88 
89  Option<std::vector<uint8_t>> getPublicKey(const std::string &address) const;
90 
91 
92  std::shared_ptr<api::DynamicObject> getConfiguration() const;
93 
94  const DerivationScheme &getDerivationScheme() const;
95 
96  const DerivationScheme &getFullDerivationScheme() const;
97 
98  std::string getRestoreKey() const;
99 
100  bool contains(const std::string &address) const;
101 
102  int32_t getOutputSizeAsSignedTxInput() const;
103 
104  protected:
105  std::shared_ptr<Preferences> getPreferences() const;
106 
107  DerivationScheme &getDerivationScheme();
108 
109  private:
110  RippleLikeKeychain::Address derive();
111 
112  const api::Currency _currency;
113  DerivationScheme _scheme;
114  DerivationScheme _fullScheme;
115  int _account;
116  std::shared_ptr<Preferences> _preferences;
117  std::shared_ptr<api::DynamicObject> _configuration;
118  std::shared_ptr<api::RippleLikeExtendedPublicKey> _xpub;
119  std::string _localPath;
120  std::string _address;
121  };
122  }
123 }
124 
125 
126 #endif //LEDGER_CORE_RIPPLELIKEKEYCHAIN_H
Definition: RippleLikeNetworkParameters.hpp:15
Definition: DerivationScheme.hpp:55
Definition: RippleLikeKeychain.h:52
Definition: Currency.hpp:23
Definition: Account.cpp:8