MCPcopy Create free account
hub / github.com/ElementsProject/elements / ParseHDKeypath

Function ParseHDKeypath

src/util/bip32.cpp:12–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypath)
13{
14 std::stringstream ss(keypath_str);
15 std::string item;
16 bool first = true;
17 while (std::getline(ss, item, '/')) {
18 if (item.compare("m") == 0) {
19 if (first) {
20 first = false;
21 continue;
22 }
23 return false;
24 }
25 // Finds whether it is hardened
26 uint32_t path = 0;
27 size_t pos = item.find("'");
28 if (pos != std::string::npos) {
29 // The hardened tick can only be in the last index of the string
30 if (pos != item.size() - 1) {
31 return false;
32 }
33 path |= 0x80000000;
34 item = item.substr(0, item.size() - 1); // Drop the last character which is the hardened tick
35 }
36
37 // Ensure this is only numbers
38 if (item.find_first_not_of( "0123456789" ) != std::string::npos) {
39 return false;
40 }
41 uint32_t number;
42 if (!ParseUInt32(item, &number)) {
43 return false;
44 }
45 path |= number;
46
47 keypath.push_back(path);
48 first = false;
49 }
50 return true;
51}
52
53std::string FormatHDKeypath(const std::vector<uint32_t>& path)
54{

Callers 5

MarkUnusedAddressesMethod · 0.85
UpgradeKeyMetadataMethod · 0.85
walletdb.cppFile · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
FUZZ_TARGETFunction · 0.85

Calls 5

ParseUInt32Function · 0.85
compareMethod · 0.80
findMethod · 0.80
sizeMethod · 0.45
push_backMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGETFunction · 0.68