diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dac8872080a..ab2539fc0ed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -140,6 +140,7 @@ add_library(bitcoin_common STATIC EXCLUDE_FROM_ALL coins.cpp common/args.cpp common/bloom.cpp + common/bip352.cpp common/config.cpp common/init.cpp common/interfaces.cpp diff --git a/src/addresstype.cpp b/src/addresstype.cpp index 67e643943d4..0d751c47115 100644 --- a/src/addresstype.cpp +++ b/src/addresstype.cpp @@ -108,6 +108,10 @@ namespace { class CScriptVisitor { public: + CScript operator()(const V0SilentPaymentDestination& dest) const + { + return CScript(); + } CScript operator()(const CNoDestination& dest) const { return dest.GetScript(); @@ -156,6 +160,9 @@ public: bool operator()(const PubKeyDestination& dest) const { return false; } bool operator()(const PKHash& dest) const { return true; } bool operator()(const ScriptHash& dest) const { return true; } + // silent payment addresses are not valid until sending support has been implemented + // TODO: set this to true once sending is implemented + bool operator()(const V0SilentPaymentDestination& dest) const { return false; } bool operator()(const WitnessV0KeyHash& dest) const { return true; } bool operator()(const WitnessV0ScriptHash& dest) const { return true; } bool operator()(const WitnessV1Taproot& dest) const { return true; } diff --git a/src/addresstype.h b/src/addresstype.h index 78d3126d853..f6289caabd6 100644 --- a/src/addresstype.h +++ b/src/addresstype.h @@ -127,6 +127,25 @@ struct PayToAnchor : public WitnessUnknown }; }; +struct V0SilentPaymentDestination +{ + CPubKey m_scan_pubkey; + CPubKey m_spend_pubkey; + + friend bool operator==(const V0SilentPaymentDestination& a, const V0SilentPaymentDestination& b) { + if (a.m_scan_pubkey != b.m_scan_pubkey) return false; + if (a.m_spend_pubkey != b.m_spend_pubkey) return false; + return true; + } + + friend bool operator<(const V0SilentPaymentDestination& a, const V0SilentPaymentDestination& b) { + if (a.m_scan_pubkey < b.m_scan_pubkey) return true; + if (a.m_scan_pubkey > b.m_scan_pubkey) return false; + if (a.m_spend_pubkey < b.m_spend_pubkey) return true; + return false; + } +}; + /** * A txout script categorized into standard templates. * * CNoDestination: Optionally a script, no corresponding address. @@ -140,7 +159,7 @@ struct PayToAnchor : public WitnessUnknown * * WitnessUnknown: TxoutType::WITNESS_UNKNOWN destination (P2W??? address) * A CTxDestination is the internal data type encoded in a bitcoin address */ -using CTxDestination = std::variant; +using CTxDestination = std::variant; /** Check whether a CTxDestination corresponds to one with an address. */ bool IsValidDestination(const CTxDestination& dest); diff --git a/src/bech32.h b/src/bech32.h index 6d5a68ec5a1..daa4c18c78c 100644 --- a/src/bech32.h +++ b/src/bech32.h @@ -37,6 +37,7 @@ enum class Encoding { * and we would never encode an address with such a massive value */ enum CharLimit : size_t { BECH32 = 90, //!< BIP173/350 imposed character limit for Bech32(m) encoded addresses. This guarantees finding up to 4 errors. + SILENT_PAYMENTS = 1024, //!< BIP352 imposed 1024 character limit on Bech32m encoded silent payment addresses. This guarantees finding up to 3 errors }; /** Encode a Bech32 or Bech32m string. If hrp contains uppercase characters, this will cause an diff --git a/src/common/bip352.cpp b/src/common/bip352.cpp new file mode 100644 index 00000000000..24f2c6758c0 --- /dev/null +++ b/src/common/bip352.cpp @@ -0,0 +1,353 @@ +// Copyright (c) 2023 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include