diff options
Diffstat (limited to 'src/script/sign.h')
-rw-r--r-- | src/script/sign.h | 78 |
1 files changed, 1 insertions, 77 deletions
diff --git a/src/script/sign.h b/src/script/sign.h index 50525af332..7301826ba5 100644 --- a/src/script/sign.h +++ b/src/script/sign.h @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2020 The Bitcoin Core developers +// Copyright (c) 2009-2021 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -12,8 +12,6 @@ #include <script/interpreter.h> #include <script/keyorigin.h> #include <script/standard.h> -#include <span.h> -#include <streams.h> class CKey; class CKeyID; @@ -84,80 +82,6 @@ struct SignatureData { void MergeSignatureData(SignatureData sigdata); }; -// Takes a stream and multiple arguments and serializes them as if first serialized into a vector and then into the stream -// The resulting output into the stream has the total serialized length of all of the objects followed by all objects concatenated with each other. -template<typename Stream, typename... X> -void SerializeToVector(Stream& s, const X&... args) -{ - WriteCompactSize(s, GetSerializeSizeMany(s.GetVersion(), args...)); - SerializeMany(s, args...); -} - -// Takes a stream and multiple arguments and unserializes them first as a vector then each object individually in the order provided in the arguments -template<typename Stream, typename... X> -void UnserializeFromVector(Stream& s, X&... args) -{ - size_t expected_size = ReadCompactSize(s); - size_t remaining_before = s.size(); - UnserializeMany(s, args...); - size_t remaining_after = s.size(); - if (remaining_after + expected_size != remaining_before) { - throw std::ios_base::failure("Size of value was not the stated size"); - } -} - -// Deserialize HD keypaths into a map -template<typename Stream> -void DeserializeHDKeypaths(Stream& s, const std::vector<unsigned char>& key, std::map<CPubKey, KeyOriginInfo>& hd_keypaths) -{ - // Make sure that the key is the size of pubkey + 1 - if (key.size() != CPubKey::SIZE + 1 && key.size() != CPubKey::COMPRESSED_SIZE + 1) { - throw std::ios_base::failure("Size of key was not the expected size for the type BIP32 keypath"); - } - // Read in the pubkey from key - CPubKey pubkey(key.begin() + 1, key.end()); - if (!pubkey.IsFullyValid()) { - throw std::ios_base::failure("Invalid pubkey"); - } - if (hd_keypaths.count(pubkey) > 0) { - throw std::ios_base::failure("Duplicate Key, pubkey derivation path already provided"); - } - - // Read in key path - uint64_t value_len = ReadCompactSize(s); - if (value_len % 4 || value_len == 0) { - throw std::ios_base::failure("Invalid length for HD key path"); - } - - KeyOriginInfo keypath; - s >> keypath.fingerprint; - for (unsigned int i = 4; i < value_len; i += sizeof(uint32_t)) { - uint32_t index; - s >> index; - keypath.path.push_back(index); - } - - // Add to map - hd_keypaths.emplace(pubkey, std::move(keypath)); -} - -// Serialize HD keypaths to a stream from a map -template<typename Stream> -void SerializeHDKeypaths(Stream& s, const std::map<CPubKey, KeyOriginInfo>& hd_keypaths, uint8_t type) -{ - for (auto keypath_pair : hd_keypaths) { - if (!keypath_pair.first.IsValid()) { - throw std::ios_base::failure("Invalid CPubKey being serialized"); - } - SerializeToVector(s, type, Span{keypath_pair.first}); - WriteCompactSize(s, (keypath_pair.second.path.size() + 1) * sizeof(uint32_t)); - s << keypath_pair.second.fingerprint; - for (const auto& path : keypath_pair.second.path) { - s << path; - } - } -} - /** Produce a script signature using a generic signature creator. */ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreator& creator, const CScript& scriptPubKey, SignatureData& sigdata); |