| 157 | // Deserialize HD keypaths into a map |
| 158 | template<typename Stream> |
| 159 | void DeserializeHDKeypaths(Stream& s, const std::vector<unsigned char>& key, std::map<CPubKey, std::vector<uint32_t>>& hd_keypaths) |
| 160 | { |
| 161 | // Make sure that the key is the size of pubkey + 1 |
| 162 | if (key.size() != CPubKey::PUBLIC_KEY_SIZE + 1 && key.size() != CPubKey::COMPRESSED_PUBLIC_KEY_SIZE + 1) { |
| 163 | throw std::ios_base::failure("Size of key was not the expected size for the type BIP32 keypath"); |
| 164 | } |
| 165 | // Read in the pubkey from key |
| 166 | CPubKey pubkey(key.begin() + 1, key.end()); |
| 167 | if (!pubkey.IsFullyValid()) { |
| 168 | throw std::ios_base::failure("Invalid pubkey"); |
| 169 | } |
| 170 | if (hd_keypaths.count(pubkey) > 0) { |
| 171 | throw std::ios_base::failure("Duplicate Key, pubkey derivation path already provided"); |
| 172 | } |
| 173 | |
| 174 | // Read in key path |
| 175 | uint64_t value_len = ReadCompactSize(s); |
| 176 | std::vector<uint32_t> keypath; |
| 177 | for (unsigned int i = 0; i < value_len; i += sizeof(uint32_t)) { |
| 178 | uint32_t index; |
| 179 | s >> index; |
| 180 | keypath.push_back(index); |
| 181 | } |
| 182 | |
| 183 | // Add to map |
| 184 | hd_keypaths.emplace(pubkey, keypath); |
| 185 | } |
| 186 | |
| 187 | // Serialize HD keypaths to a stream from a map |
| 188 | template<typename Stream> |
no test coverage detected