@@ -20,6 +20,12 @@ class CTransaction;
20
20
21
21
struct CMutableTransaction ;
22
22
23
+ struct KeyOriginInfo
24
+ {
25
+ unsigned char fingerprint[4 ];
26
+ std::vector<uint32_t > path;
27
+ };
28
+
23
29
/* * An interface to be implemented by keystores that support signing. */
24
30
class SigningProvider
25
31
{
@@ -155,7 +161,7 @@ void UnserializeFromVector(Stream& s, X&... args)
155
161
156
162
// Deserialize HD keypaths into a map
157
163
template <typename Stream>
158
- void DeserializeHDKeypaths (Stream& s, const std::vector<unsigned char >& key, std::map<CPubKey, std::vector< uint32_t > >& hd_keypaths)
164
+ void DeserializeHDKeypaths (Stream& s, const std::vector<unsigned char >& key, std::map<CPubKey, KeyOriginInfo >& hd_keypaths)
159
165
{
160
166
// Make sure that the key is the size of pubkey + 1
161
167
if (key.size () != CPubKey::PUBLIC_KEY_SIZE + 1 && key.size () != CPubKey::COMPRESSED_PUBLIC_KEY_SIZE + 1 ) {
@@ -172,25 +178,31 @@ void DeserializeHDKeypaths(Stream& s, const std::vector<unsigned char>& key, std
172
178
173
179
// Read in key path
174
180
uint64_t value_len = ReadCompactSize (s);
175
- std::vector<uint32_t > keypath;
176
- for (unsigned int i = 0 ; i < value_len; i += sizeof (uint32_t )) {
181
+ if (value_len % 4 || value_len == 0 ) {
182
+ throw std::ios_base::failure (" Invalid length for HD key path" );
183
+ }
184
+
185
+ KeyOriginInfo keypath;
186
+ s >> keypath.fingerprint ;
187
+ for (unsigned int i = 4 ; i < value_len; i += sizeof (uint32_t )) {
177
188
uint32_t index;
178
189
s >> index;
179
- keypath.push_back (index);
190
+ keypath.path . push_back (index);
180
191
}
181
192
182
193
// Add to map
183
- hd_keypaths.emplace (pubkey, keypath);
194
+ hd_keypaths.emplace (pubkey, std::move ( keypath) );
184
195
}
185
196
186
197
// Serialize HD keypaths to a stream from a map
187
198
template <typename Stream>
188
- void SerializeHDKeypaths (Stream& s, const std::map<CPubKey, std::vector< uint32_t > >& hd_keypaths, uint8_t type)
199
+ void SerializeHDKeypaths (Stream& s, const std::map<CPubKey, KeyOriginInfo >& hd_keypaths, uint8_t type)
189
200
{
190
201
for (auto keypath_pair : hd_keypaths) {
191
202
SerializeToVector (s, type, MakeSpan (keypath_pair.first ));
192
- WriteCompactSize (s, keypath_pair.second .size () * sizeof (uint32_t ));
193
- for (auto & path : keypath_pair.second ) {
203
+ WriteCompactSize (s, (keypath_pair.second .path .size () + 1 ) * sizeof (uint32_t ));
204
+ s << keypath_pair.second .fingerprint ;
205
+ for (const auto & path : keypath_pair.second .path ) {
194
206
s << path;
195
207
}
196
208
}
@@ -205,7 +217,7 @@ struct PSBTInput
205
217
CScript witness_script;
206
218
CScript final_script_sig;
207
219
CScriptWitness final_script_witness;
208
- std::map<CPubKey, std::vector< uint32_t > > hd_keypaths;
220
+ std::map<CPubKey, KeyOriginInfo > hd_keypaths;
209
221
std::map<CKeyID, SigPair> partial_sigs;
210
222
std::map<std::vector<unsigned char >, std::vector<unsigned char >> unknown;
211
223
int sighash_type = 0 ;
@@ -413,7 +425,7 @@ struct PSBTOutput
413
425
{
414
426
CScript redeem_script;
415
427
CScript witness_script;
416
- std::map<CPubKey, std::vector< uint32_t > > hd_keypaths;
428
+ std::map<CPubKey, KeyOriginInfo > hd_keypaths;
417
429
std::map<std::vector<unsigned char >, std::vector<unsigned char >> unknown;
418
430
419
431
bool IsNull () const ;
0 commit comments