| 4445 | } |
| 4446 | |
| 4447 | bool ParseHDKeypath(std::string keypath_str, std::vector<uint32_t>& keypath) |
| 4448 | { |
| 4449 | std::stringstream ss(keypath_str); |
| 4450 | std::string item; |
| 4451 | bool first = true; |
| 4452 | while (std::getline(ss, item, '/')) { |
| 4453 | if (item.compare("m") == 0) { |
| 4454 | if (first) { |
| 4455 | first = false; |
| 4456 | continue; |
| 4457 | } |
| 4458 | return false; |
| 4459 | } |
| 4460 | // Finds whether it is hardened |
| 4461 | uint32_t path = 0; |
| 4462 | size_t pos = item.find("'"); |
| 4463 | if (pos != std::string::npos) { |
| 4464 | // The hardened tick can only be in the last index of the string |
| 4465 | if (pos != item.size() - 1) { |
| 4466 | return false; |
| 4467 | } |
| 4468 | path |= 0x80000000; |
| 4469 | item = item.substr(0, item.size() - 1); // Drop the last character which is the hardened tick |
| 4470 | } |
| 4471 | |
| 4472 | // Ensure this is only numbers |
| 4473 | if (item.find_first_not_of( "0123456789" ) != std::string::npos) { |
| 4474 | return false; |
| 4475 | } |
| 4476 | uint32_t number; |
| 4477 | if (!ParseUInt32(item, &number)) { |
| 4478 | return false; |
| 4479 | } |
| 4480 | path |= number; |
| 4481 | |
| 4482 | keypath.push_back(path); |
| 4483 | first = false; |
| 4484 | } |
| 4485 | return true; |
| 4486 | } |
| 4487 | |
| 4488 | void AddKeypathToMap(const CWallet* pwallet, const CKeyID& keyID, std::map<CPubKey, std::vector<uint32_t>>& hd_keypaths) |
| 4489 | { |