ledger-core
RippleLikeExtendedPublicKey.h
1 /*
2  *
3  * RippleLikeExtendedPublicKey
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_RIPPLELIKEEXTENDEDPUBLICKEY_H
33 #define LEDGER_CORE_RIPPLELIKEEXTENDEDPUBLICKEY_H
34 
35 #include <memory>
36 #include "RippleLikeAddress.h"
37 #include <common/AbstractExtendedPublicKey.h>
38 #include <api/RippleLikeExtendedPublicKey.hpp>
39 #include <crypto/DeterministicPublicKey.hpp>
40 #include <api/RippleLikeNetworkParameters.hpp>
41 #include <utils/Option.hpp>
42 #include <utils/DerivationPath.hpp>
43 #include <api/Currency.hpp>
44 
45 namespace ledger {
46  namespace core {
47  using RippleExtendedPublicKey = AbstractExtendedPublicKey<api::RippleLikeNetworkParameters>;
49  public:
50 
52  const DeterministicPublicKey& key,
53  const DerivationPath& path = DerivationPath("m/"));
54 
55  std::shared_ptr<api::RippleLikeAddress> derive(const std::string & path) override ;
56  std::shared_ptr<RippleLikeExtendedPublicKey> derive(const DerivationPath &path);
57  std::vector<uint8_t> derivePublicKey(const std::string & path) override ;
58 
59  std::vector<uint8_t> deriveHash160(const std::string & path) override ;
60 
61  std::string toBase58() override ;
62 
63  std::string getRootPath() override ;
64 
65  static std::shared_ptr<RippleLikeExtendedPublicKey> fromRaw(const api::Currency& params,
66  const optional<std::vector<uint8_t>>& parentPublicKey,
67  const std::vector<uint8_t>& publicKey,
68  const std::vector<uint8_t> &chainCode,
69  const std::string& path);
70 
71  static std::shared_ptr<RippleLikeExtendedPublicKey> fromBase58(const api::Currency& currency,
72  const std::string& xpubBase58,
73  const Option<std::string>& path);
74 
75  protected:
76  const api::RippleLikeNetworkParameters &params() const override {
77  return _currency.rippleLikeNetworkParameters.value();
78  };
79  const DeterministicPublicKey &getKey() const override {
80  return _key;
81  };
82  const DerivationPath &getPath() const override {
83  return _path;
84  };
85  const api::Currency &getCurrency() const override {
86  return _currency;
87  };
88  private:
89  const api::Currency _currency;
90  const DerivationPath _path;
91  const DeterministicPublicKey _key;
92 
93  };
94  }
95 }
96 
97 
98 #endif //LEDGER_CORE_RIPPLELIKEEXTENDEDPUBLICKEY_H
Definition: DeterministicPublicKey.hpp:38
Definition: RippleLikeNetworkParameters.hpp:15
Definition: RippleLikeExtendedPublicKey.hpp:23
Definition: AbstractExtendedPublicKey.h:54
Definition: DerivationPath.hpp:40
Definition: RippleLikeExtendedPublicKey.h:48
Definition: Currency.hpp:23
Definition: Account.cpp:8
Definition: optional.hpp:177
std::experimental::optional< RippleLikeNetworkParameters > rippleLikeNetworkParameters
Definition: Currency.hpp:45