Bitcoin Core 32.99.0
P2P Digital Currency
Classes | Typedefs | Enumerations | Functions
bip352 Namespace Reference

Classes

struct  BIP352Comparator
 
class  PrevoutsSummary
 
struct  SilentPaymentsDestination
 
class  SilentPaymentsLabel
 
struct  SilentPaymentsOutput
 
class  SilentPaymentsReceiver
 A silent payments recipient's scanning identity. More...
 

Typedefs

using PubKey = std::variant< CPubKey, XOnlyPubKey >
 
using LabelTweakMap = std::map< SilentPaymentsLabel, uint256, std::less<> >
 

Enumerations

enum class  PrevoutsSummaryError { MISSING_COIN , NOT_ELIGIBLE }
 

Functions

util::Expected< SilentPaymentsDestination, std::string > DecodeSilentPaymentsAddress (const std::string &str, const CChainParams &params)
 Decode a BIP352 "sp1..." address. Returns the destination, or an error message on failure. More...
 
std::optional< PubKey > GetPubKeyFromInput (const CTxIn &txin, const CScript &spk)
 Get the public key from an input. More...
 
static std::optional< PrevoutsSummary > CreateInputPubkeysTweak (const std::vector< CPubKey > &plain_pubkeys, const std::vector< XOnlyPubKey > &taproot_pubkeys, const COutPoint &smallest_outpoint)
 
util::Expected< PrevoutsSummary, PrevoutsSummaryError > GetSilentPaymentsPrevoutsSummary (const std::vector< CTxIn > &vin, const std::map< COutPoint, Coin > &coins)
 Get silent payments public data from transaction inputs. More...
 
static std::optional< std::vector< secp256k1_xonly_pubkey > > CreateOutputs (const std::vector< SilentPaymentsDestination > &recipients, const std::vector< CKey > &plain_keys, const std::vector< KeyPair > &taproot_keypairs, const COutPoint &smallest_outpoint)
 
std::optional< std::map< size_t, WitnessV1Taproot > > GenerateSilentPaymentsTaprootDestinations (const std::map< size_t, SilentPaymentsDestination > &sp_dests, const std::vector< CKey > &plain_keys, const std::vector< KeyPair > &taproot_keys, const COutPoint &smallest_outpoint)
 Generate silent payments taproot destinations. More...
 
static const unsigned char * LabelLookupCallback (const unsigned char *key, const void *context)
 
static std::pair< SilentPaymentsLabel, uint256 > CreateLabel (const CKey &scan_key, const uint32_t m)
 
static CPubKey CreateLabeledSpendPubKey (const CPubKey &spend_pubkey, const SilentPaymentsLabel &label)
 
CKey ParseHexToCKey (std::string_view hex)
 
 BOOST_AUTO_TEST_CASE (bip352_send_and_receive_test_vectors)
 
 BOOST_AUTO_TEST_CASE (bip352_preserves_requested_output_indexes)
 
 BOOST_AUTO_TEST_CASE (bip352_skips_transactions_spending_unknown_segwit_versions)
 
 BOOST_AUTO_TEST_CASE (bip352_scan_skips_invalid_taproot_outputs)
 
 BOOST_AUTO_TEST_CASE (bip352_label_serialize_roundtrip)
 
 BOOST_AUTO_TEST_CASE (bip352_decode_address)
 

Typedef Documentation

◆ LabelTweakMap

using bip352::LabelTweakMap = typedef std::map<SilentPaymentsLabel, uint256, std::less<> >

Definition at line 227 of file bip352.h.

◆ PubKey

using bip352::PubKey = typedef std::variant<CPubKey, XOnlyPubKey>

Definition at line 39 of file bip352.h.

Enumeration Type Documentation

◆ PrevoutsSummaryError

enum class bip352::PrevoutsSummaryError
strong
Enumerator
MISSING_COIN 

A prevout referenced by an input in vin has no corresponding entry in coins.

NOT_ELIGIBLE 

This transaction is not eligible to be scanned for silent payments outputs: either none of its inputs yielded a public key eligible for silent payments (e.g.

an input spends an unknown segwit version), or the eligible inputs' public keys summed to the point at infinity.

Definition at line 200 of file bip352.h.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/6]

bip352::BOOST_AUTO_TEST_CASE ( bip352_decode_address  )

Definition at line 293 of file bip352_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/6]

bip352::BOOST_AUTO_TEST_CASE ( bip352_label_serialize_roundtrip  )

Definition at line 276 of file bip352_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/6]

bip352::BOOST_AUTO_TEST_CASE ( bip352_preserves_requested_output_indexes  )

Definition at line 204 of file bip352_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/6]

bip352::BOOST_AUTO_TEST_CASE ( bip352_scan_skips_invalid_taproot_outputs  )

Definition at line 242 of file bip352_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/6]

bip352::BOOST_AUTO_TEST_CASE ( bip352_send_and_receive_test_vectors  )

Definition at line 32 of file bip352_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/6]

bip352::BOOST_AUTO_TEST_CASE ( bip352_skips_transactions_spending_unknown_segwit_versions  )

Definition at line 223 of file bip352_tests.cpp.

Here is the call graph for this function:

◆ CreateInputPubkeysTweak()

static std::optional< PrevoutsSummary > bip352::CreateInputPubkeysTweak ( const std::vector< CPubKey > &  plain_pubkeys,
const std::vector< XOnlyPubKey > &  taproot_pubkeys,
const COutPoint &  smallest_outpoint 
)
static

Definition at line 210 of file bip352.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateLabel()

static std::pair< SilentPaymentsLabel, uint256 > bip352::CreateLabel ( const CKey &  scan_key,
const uint32_t  m 
)
static

Definition at line 392 of file bip352.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateLabeledSpendPubKey()

static CPubKey bip352::CreateLabeledSpendPubKey ( const CPubKey &  spend_pubkey,
const SilentPaymentsLabel &  label 
)
static

Definition at line 400 of file bip352.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateOutputs()

static std::optional< std::vector< secp256k1_xonly_pubkey > > bip352::CreateOutputs ( const std::vector< SilentPaymentsDestination > &  recipients,
const std::vector< CKey > &  plain_keys,
const std::vector< KeyPair > &  taproot_keypairs,
const COutPoint &  smallest_outpoint 
)
static

Definition at line 292 of file bip352.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DecodeSilentPaymentsAddress()

util::Expected< SilentPaymentsDestination, std::string > bip352::DecodeSilentPaymentsAddress ( const std::string &  str,
const CChainParams &  params 
)

Decode a BIP352 "sp1..." address. Returns the destination, or an error message on failure.

Definition at line 67 of file bip352.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GenerateSilentPaymentsTaprootDestinations()

std::optional< std::map< size_t, WitnessV1Taproot > > bip352::GenerateSilentPaymentsTaprootDestinations ( const std::map< size_t, SilentPaymentsDestination > &  sp_dests,
const std::vector< CKey > &  plain_keys,
const std::vector< KeyPair > &  taproot_keys,
const COutPoint &  smallest_outpoint 
)

Generate silent payments taproot destinations.

Given a set of silent payments destinations, generate the requested number of outputs. If a silent payment destination is repeated, this indicates multiple outputs are requested for the same recipient. The silent payment destinations are passed in a map where the key indicates their desired position in the final tx.vout array.

Parameters
sp_destsThe silent payments destinations.
plain_keysThe private keys for non-taproot inputs.
taproot_keysThe keypairs for taproot inputs.
smallest_outpointThe smallest_outpoint from the transaction inputs.
Precondition
smallest_outpoint is not null, and at least one of plain_keys or taproot_keys is non-empty.
Returns
The generated silent payments taproot destinations or std::nullopt if the set of provided inputs is invalid:
  • The size of any group (i.e. recipients sharing the same scan public key) exceeds the protocol limit SECP256K1_SILENTPAYMENTS_RECIPIENT_GROUP_LIMIT.
  • There is an invalid key in the set.
  • The inputs sum to zero.

Definition at line 353 of file bip352.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPubKeyFromInput()

std::optional< PubKey > bip352::GetPubKeyFromInput ( const CTxIn &  txin,
const CScript &  spk 
)

Get the public key from an input.

Get the public key from a silent payments eligible input. This requires knowledge of the prevout scriptPubKey to determine the type of input and whether or not it is eligible for silent payments.

If the input is not eligible for silent payments, the input is skipped (indicated by returning a nullopt).

Parameters
txinThe transaction input.
spkThe scriptPubKey of the prevout.
Returns
The public key, or nullopt if not found.

Definition at line 143 of file bip352.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSilentPaymentsPrevoutsSummary()

util::Expected< PrevoutsSummary, PrevoutsSummaryError > bip352::GetSilentPaymentsPrevoutsSummary ( const std::vector< CTxIn > &  vin,
const std::map< COutPoint, Coin > &  coins 
)

Get silent payments public data from transaction inputs.

Get the necessary data from the transaction inputs to be able to scan the transaction outputs for silent payments outputs. This requires knowledge of the prevout scriptPubKey, which is passed via coins.

This function returns the public key sum and the input hash separately and is intended to be used by the wallet when scanning a transaction.

If there are no eligible inputs, or one of the inputs spends an unknown segwit version (i.e > 1), this transaction is not eligible to be scanned for silent payments outputs; see PrevoutsSummaryError.

Parameters
vinThe transaction inputs.
coinsThe coins (potentially) spent in this transaction.
Returns
util::Expected<PrevoutsSummary, PrevoutsSummaryError> The silent payments public data, or the reason it could not be computed.

Definition at line 255 of file bip352.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LabelLookupCallback()

static const unsigned char * bip352::LabelLookupCallback ( const unsigned char *  key,
const void *  context 
)
static

Definition at line 383 of file bip352.cpp.

Here is the caller graph for this function:

◆ ParseHexToCKey()

CKey bip352::ParseHexToCKey ( std::string_view  hex)

Definition at line 25 of file bip352_tests.cpp.

Here is the call graph for this function:
Here is the caller graph for this function: