Skip to content

Commit 91fc7fc

Browse files
theStackjosibake
authored andcommitted
build: add skeleton for new silentpayments (BIP352) module
1 parent 70f149b commit 91fc7fc

File tree

7 files changed

+90
-0
lines changed

7 files changed

+90
-0
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,21 @@ option(SECP256K1_ENABLE_MODULE_EXTRAKEYS "Enable extrakeys module." ON)
6262
option(SECP256K1_ENABLE_MODULE_SCHNORRSIG "Enable schnorrsig module." ON)
6363
option(SECP256K1_ENABLE_MODULE_MUSIG "Enable musig module." ON)
6464
option(SECP256K1_ENABLE_MODULE_ELLSWIFT "Enable ElligatorSwift module." ON)
65+
option(SECP256K1_ENABLE_MODULE_SILENTPAYMENTS "Enable Silent Payments module." ON)
6566

6667
# Processing must be done in a topological sorting of the dependency graph
6768
# (dependent module first).
69+
if(SECP256K1_ENABLE_MODULE_SILENTPAYMENTS)
70+
if(DEFINED SECP256K1_ENABLE_MODULE_SCHNORRSIG AND NOT SECP256K1_ENABLE_MODULE_SCHNORRSIG)
71+
message(FATAL_ERROR "Module dependency error: You have disabled the schnorrsig module explicitly, but it is required by the silentpayments module.")
72+
endif()
73+
if(DEFINED SECP256K1_ENABLE_MODULE_EXTRAKEYS AND NOT SECP256K1_ENABLE_MODULE_EXTRAKEYS)
74+
message(FATAL_ERROR "Module dependency error: You have disabled the extrakeys module explicitly, but it is required by the silentpayments module.")
75+
endif()
76+
set(SECP256K1_ENABLE_MODULE_EXTRAKEYS ON)
77+
add_compile_definitions(ENABLE_MODULE_SILENTPAYMENTS=1)
78+
endif()
79+
6880
if(SECP256K1_ENABLE_MODULE_ELLSWIFT)
6981
add_compile_definitions(ENABLE_MODULE_ELLSWIFT=1)
7082
endif()
@@ -329,6 +341,7 @@ message(" extrakeys ........................... ${SECP256K1_ENABLE_MODULE_EXTRA
329341
message(" schnorrsig .......................... ${SECP256K1_ENABLE_MODULE_SCHNORRSIG}")
330342
message(" musig ............................... ${SECP256K1_ENABLE_MODULE_MUSIG}")
331343
message(" ElligatorSwift ...................... ${SECP256K1_ENABLE_MODULE_ELLSWIFT}")
344+
message(" Silent Payments ..................... ${SECP256K1_ENABLE_MODULE_SILENTPAYMENTS}")
332345
message("Parameters:")
333346
message(" ecmult window size .................. ${SECP256K1_ECMULT_WINDOW_SIZE}")
334347
message(" ecmult gen table size ............... ${SECP256K1_ECMULT_GEN_KB} KiB")

Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,7 @@ endif
301301
if ENABLE_MODULE_ELLSWIFT
302302
include src/modules/ellswift/Makefile.am.include
303303
endif
304+
305+
if ENABLE_MODULE_SILENTPAYMENTS
306+
include src/modules/silentpayments/Makefile.am.include
307+
endif

configure.ac

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ AC_ARG_ENABLE(module_ellswift,
191191
AS_HELP_STRING([--enable-module-ellswift],[enable ElligatorSwift module [default=yes]]), [],
192192
[SECP_SET_DEFAULT([enable_module_ellswift], [yes], [yes])])
193193

194+
AC_ARG_ENABLE(module_silentpayments,
195+
AS_HELP_STRING([--enable-module-silentpayments],[enable Silent Payments module [default=no]]), [],
196+
[SECP_SET_DEFAULT([enable_module_silentpayments], [no], [yes])])
197+
194198
AC_ARG_ENABLE(external_default_callbacks,
195199
AS_HELP_STRING([--enable-external-default-callbacks],[enable external default callback functions [default=no]]), [],
196200
[SECP_SET_DEFAULT([enable_external_default_callbacks], [no], [no])])
@@ -397,6 +401,19 @@ SECP_CFLAGS="$SECP_CFLAGS $WERROR_CFLAGS"
397401

398402
# Processing must be done in a reverse topological sorting of the dependency graph
399403
# (dependent module first).
404+
if test x"$enable_module_silentpayments" = x"yes"; then
405+
if test x"$enable_module_schnorrsig" = x"no"; then
406+
AC_MSG_ERROR([Module dependency error: You have disabled the schnorrsig module explicitly, but it is required by the silentpayments module.])
407+
fi
408+
enable_module_schnorrsig=yes
409+
410+
if test x"$enable_module_extrakeys" = x"no"; then
411+
AC_MSG_ERROR([Module dependency error: You have disabled the extrakeys module explicitly, but it is required by the silentpayments module.])
412+
fi
413+
enable_module_extrakeys=yes
414+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_SILENTPAYMENTS=1"
415+
fi
416+
400417
if test x"$enable_module_ellswift" = x"yes"; then
401418
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ELLSWIFT=1"
402419
fi
@@ -462,6 +479,7 @@ AM_CONDITIONAL([ENABLE_MODULE_EXTRAKEYS], [test x"$enable_module_extrakeys" = x"
462479
AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG], [test x"$enable_module_schnorrsig" = x"yes"])
463480
AM_CONDITIONAL([ENABLE_MODULE_MUSIG], [test x"$enable_module_musig" = x"yes"])
464481
AM_CONDITIONAL([ENABLE_MODULE_ELLSWIFT], [test x"$enable_module_ellswift" = x"yes"])
482+
AM_CONDITIONAL([ENABLE_MODULE_SILENTPAYMENTS], [test x"$enable_module_silentpayments" = x"yes"])
465483
AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$enable_external_asm" = x"yes"])
466484
AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm32"])
467485
AM_CONDITIONAL([BUILD_WINDOWS], [test "$build_windows" = "yes"])
@@ -486,6 +504,7 @@ echo " module extrakeys = $enable_module_extrakeys"
486504
echo " module schnorrsig = $enable_module_schnorrsig"
487505
echo " module musig = $enable_module_musig"
488506
echo " module ellswift = $enable_module_ellswift"
507+
echo " module silentpayments = $enable_module_silentpayments"
489508
echo
490509
echo " asm = $set_asm"
491510
echo " ecmult window size = $set_ecmult_window"

include/secp256k1_silentpayments.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef SECP256K1_SILENTPAYMENTS_H
2+
#define SECP256K1_SILENTPAYMENTS_H
3+
4+
#include "secp256k1.h"
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
/** This module provides an implementation for Silent Payments, as specified in
11+
* BIP352. This particularly involves the creation of input tweak data by
12+
* summing up secret or public keys and the derivation of a shared secret using
13+
* Elliptic Curve Diffie-Hellman. Combined are either:
14+
* - spender's secret keys and recipient's public key (a * B, sender side)
15+
* - spender's public keys and recipient's secret key (A * b, recipient side)
16+
* With this result, the necessary key material for ultimately creating/scanning
17+
* or spending Silent Payment outputs can be determined.
18+
*
19+
* Note that this module is _not_ a full implementation of BIP352, as it
20+
* inherently doesn't deal with higher-level concepts like addresses, output
21+
* script types or transactions. The intent is to provide a module for
22+
* abstracting away the elliptic-curve operations required for the protocol. For
23+
* any wallet software already using libsecp256k1, this API should provide all
24+
* the functions needed for a Silent Payments implementation without requiring
25+
* any further elliptic-curve operations from the wallet.
26+
*/
27+
28+
#ifdef __cplusplus
29+
}
30+
#endif
31+
32+
#endif /* SECP256K1_SILENTPAYMENTS_H */
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include_HEADERS += include/secp256k1_silentpayments.h
2+
noinst_HEADERS += src/modules/silentpayments/main_impl.h
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/***********************************************************************
2+
* Distributed under the MIT software license, see the accompanying *
3+
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
4+
***********************************************************************/
5+
6+
#ifndef SECP256K1_MODULE_SILENTPAYMENTS_MAIN_H
7+
#define SECP256K1_MODULE_SILENTPAYMENTS_MAIN_H
8+
9+
#include "../../../include/secp256k1.h"
10+
#include "../../../include/secp256k1_silentpayments.h"
11+
12+
/* TODO: implement functions for sender side. */
13+
14+
/* TODO: implement functions for receiver side. */
15+
16+
#endif

src/secp256k1.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,3 +817,7 @@ int secp256k1_tagged_sha256(const secp256k1_context* ctx, unsigned char *hash32,
817817
#ifdef ENABLE_MODULE_ELLSWIFT
818818
# include "modules/ellswift/main_impl.h"
819819
#endif
820+
821+
#ifdef ENABLE_MODULE_SILENTPAYMENTS
822+
# include "modules/silentpayments/main_impl.h"
823+
#endif

0 commit comments

Comments
 (0)