| 181 | // Deserialize HD keypaths into a map |
| 182 | template<typename Stream> |
| 183 | void DeserializeHDKeypaths(Stream& s, const std::vector<unsigned char>& key, std::map<CPubKey, KeyOriginInfo>& hd_keypaths) |
| 184 | { |
| 185 | // Make sure that the key is the size of pubkey + 1 |
| 186 | if (key.size() != CPubKey::SIZE + 1 && key.size() != CPubKey::COMPRESSED_SIZE + 1) { |
| 187 | throw std::ios_base::failure("Size of key was not the expected size for the type BIP32 keypath"); |
| 188 | } |
| 189 | // Read in the pubkey from key |
| 190 | CPubKey pubkey(key.begin() + 1, key.end()); |
| 191 | if (!pubkey.IsFullyValid()) { |
| 192 | throw std::ios_base::failure("Invalid pubkey"); |
| 193 | } |
| 194 | if (hd_keypaths.count(pubkey) > 0) { |
| 195 | throw std::ios_base::failure("Duplicate Key, pubkey derivation path already provided"); |
| 196 | } |
| 197 | |
| 198 | KeyOriginInfo keypath; |
| 199 | DeserializeHDKeypath(s, keypath); |
| 200 | |
| 201 | // Add to map |
| 202 | hd_keypaths.emplace(pubkey, std::move(keypath)); |
| 203 | } |
| 204 | |
| 205 | // Serialize an individual HD keypath to a stream |
| 206 | template<typename Stream> |