19 const std::string_view raw{elem.begin(), elem.end()};
24 bool is_hardened =
false;
25 const char last = elem.back();
26 if (last ==
'\'' || last ==
'h') {
27 elem = elem.first(elem.size() - 1);
31 const auto number{ToIntegral<uint32_t>(std::string_view{elem.begin(), elem.end()})};
41bool ParseHDKeypath(
const std::string& keypath_str, std::vector<uint32_t>& keypath)
43 std::stringstream ss(keypath_str);
46 while (std::getline(ss, item,
'/') || std::getline(ss, item,
'h')) {
47 if (item.compare(
"m") == 0) {
55 if (!parsed)
return false;
56 keypath.push_back(parsed->ChildNumber());
67 if (i >> 31)
ret += apostrophe ?
'\'' :
'h';
72std::string
WriteHDKeypath(
const std::vector<uint32_t>& keypath,
bool apostrophe)
79 return std::any_of(keypath.begin(), keypath.end(), [](uint32_t index) {
bool ParseHDKeypath(const std::string &keypath_str, std::vector< uint32_t > &keypath)
Parse an HD keypaths like "m/7/0'/2000".
std::string FormatHDKeypath(const std::vector< uint32_t > &path, bool apostrophe)
std::string WriteHDKeypath(const std::vector< uint32_t > &keypath, bool apostrophe)
Write HD keypaths as strings.
util::Expected< KeyPathElement, std::string > ParseKeyPathElement(std::span< const char > elem)
Parse a single key path element like "0", "0'", or "0h".
bool HasHardenedDerivation(std::span< const uint32_t > keypath)
Whether a parsed HD keypath contains at least one hardened derivation step.
static constexpr uint32_t BIP32_HARDENED_FLAG
BIP32 hardened derivation flag (2^31)
The util::Expected class provides a standard way for low-level functions to return either error value...
The util::Unexpected class represents an unexpected value stored in util::Expected.