Skip to content

Commit c56658f

Browse files
committed
add BIP352 silent payment primitives
add the scanning part of bip352 (silent payments) along with test vectors. this will likely be replaced in the future, either with the libsecp256k1 module or the ultrafastsecp implementation.
1 parent 84a72ce commit c56658f

6 files changed

Lines changed: 7261 additions & 1 deletion

File tree

Makefile.am

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ src_libbitcoin_system_la_SOURCES = \
5151
src/chain/point.cpp \
5252
src/chain/script.cpp \
5353
src/chain/script_extract.cpp \
54+
src/chain/silent_payment.cpp \
5455
src/chain/taproot.cpp \
5556
src/chain/transaction.cpp \
5657
src/chain/transaction_cache.cpp \
@@ -254,6 +255,8 @@ test_libbitcoin_system_test_SOURCES = \
254255
test/chain/output.cpp \
255256
test/chain/point.cpp \
256257
test/chain/satoshi_words.cpp \
258+
test/chain/silent_payment.cpp \
259+
test/chain/silent_payment_vectors.hpp \
257260
test/chain/script.cpp \
258261
test/chain/script.hpp \
259262
test/chain/stripper.cpp \
@@ -519,6 +522,7 @@ include_bitcoin_system_chain_HEADERS = \
519522
include/bitcoin/system/chain/point.hpp \
520523
include/bitcoin/system/chain/prevout.hpp \
521524
include/bitcoin/system/chain/script.hpp \
525+
include/bitcoin/system/chain/silent_payment.hpp \
522526
include/bitcoin/system/chain/stripper.hpp \
523527
include/bitcoin/system/chain/taproot.hpp \
524528
include/bitcoin/system/chain/tapscript.hpp \
@@ -1035,4 +1039,3 @@ target_examples = \
10351039
examples/libbitcoin-system-examples
10361040

10371041
examples: ${target_examples}
1038-

include/bitcoin/system/chain/chain.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <bitcoin/system/chain/point.hpp>
3737
#include <bitcoin/system/chain/prevout.hpp>
3838
#include <bitcoin/system/chain/script.hpp>
39+
#include <bitcoin/system/chain/silent_payment.hpp>
3940
#include <bitcoin/system/chain/stripper.hpp>
4041
#include <bitcoin/system/chain/taproot.hpp>
4142
#include <bitcoin/system/chain/tapscript.hpp>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* Copyright (c) 2011-2026 libbitcoin developers (see AUTHORS)
3+
*
4+
* This file is part of libbitcoin.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#ifndef LIBBITCOIN_SYSTEM_CHAIN_SILENT_PAYMENT_HPP
20+
#define LIBBITCOIN_SYSTEM_CHAIN_SILENT_PAYMENT_HPP
21+
22+
#include <optional>
23+
#include <bitcoin/system/chain/block.hpp>
24+
#include <bitcoin/system/chain/input.hpp>
25+
#include <bitcoin/system/chain/transaction.hpp>
26+
#include <bitcoin/system/crypto/secp256k1.hpp>
27+
#include <bitcoin/system/define.hpp>
28+
29+
namespace libbitcoin {
30+
namespace system {
31+
namespace chain {
32+
namespace silent_payment {
33+
34+
struct BC_API output
35+
{
36+
uint32_t index{};
37+
ec_xonly key{};
38+
};
39+
40+
struct BC_API record
41+
{
42+
ec_compressed tweak_key{};
43+
std_vector<output> outputs{};
44+
};
45+
46+
struct BC_API match
47+
{
48+
uint32_t index{};
49+
ec_secret tweak{};
50+
std::optional<uint32_t> label{};
51+
};
52+
53+
struct BC_API scan_context
54+
{
55+
ec_secret scan_secret{};
56+
ec_compressed spend_public{};
57+
ec_uncompressed spend_point{};
58+
std_vector<uint32_t> labels{};
59+
secret_list label_tweaks{};
60+
uncompressed_list label_points_uncompressed{};
61+
bool valid{};
62+
};
63+
64+
typedef std_vector<record> records;
65+
typedef std_vector<match> matches;
66+
67+
BC_API bool to_even_compressed(ec_compressed& out,
68+
const ec_xonly& point) NOEXCEPT;
69+
BC_API bool label_tweak(ec_secret& out, const ec_secret& scan_secret,
70+
uint32_t label) NOEXCEPT;
71+
BC_API bool is_excluded_segwit_future(const input& in) NOEXCEPT;
72+
BC_API bool is_nums_internal_key(const input& in) NOEXCEPT;
73+
BC_API bool extract_shared_secret_key(ec_compressed& out,
74+
const input& in) NOEXCEPT;
75+
BC_API bool compute_input_hash(ec_secret& out, const transaction& tx,
76+
const ec_compressed& sum) NOEXCEPT;
77+
BC_API bool compute_scan_record(record& out,
78+
const transaction& tx) NOEXCEPT;
79+
BC_API bool compute_scan_records(records& out, const block& block) NOEXCEPT;
80+
BC_API bool create_scan_context(scan_context& out,
81+
const ec_secret& scan_secret, const ec_compressed& spend_public,
82+
const std_vector<uint32_t>& labels) NOEXCEPT;
83+
BC_API bool scan_outputs(matches& out, const ec_secret& scan_secret,
84+
const ec_compressed& spend_public, const std_vector<uint32_t>& labels,
85+
const ec_compressed& tweak_key,
86+
const std_vector<output>& outputs) NOEXCEPT;
87+
BC_API bool scan_outputs(matches& out, const scan_context& context,
88+
const ec_compressed& tweak_key,
89+
const std_vector<output>& outputs) NOEXCEPT;
90+
BC_API bool scan_outputs(matches& out, const scan_context& context,
91+
const ec_uncompressed& tweak_key,
92+
const std_vector<output>& outputs) NOEXCEPT;
93+
BC_API bool match_outputs(bool& out, const scan_context& context,
94+
const ec_compressed& tweak_key,
95+
const std_vector<output>& outputs) NOEXCEPT;
96+
BC_API bool match_outputs(bool& out, const scan_context& context,
97+
const ec_uncompressed& tweak_key,
98+
const std_vector<output>& outputs) NOEXCEPT;
99+
100+
} // namespace silent_payment
101+
} // namespace chain
102+
} // namespace system
103+
} // namespace libbitcoin
104+
105+
#endif

0 commit comments

Comments
 (0)