Skip to content

Commit fb1fd4e

Browse files
committed
introduce struct to hold DLEQ proof related data for silent payments
- structure contains 33-byte shared secret point + 64-byte DLEQ proof + index of recipient in original unsorted array of silent payment recipients - add functions to serialise and parse the structure to/from bytes
1 parent 1f42784 commit fb1fd4e

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

include/secp256k1_silentpayments.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ typedef struct secp256k1_silentpayments_recipient {
5050
size_t index;
5151
} secp256k1_silentpayments_recipient;
5252

53+
/* This struct contains details of the DLEQ proof
54+
*
55+
* Fields:
56+
* - shared_secret : 33-byte shared secret point
57+
* - proof: 64-byte serialized DLEQ proof
58+
* - index: Indicates which recipient the proof pertains to based on the original (not sorted) ordering of the addresses
59+
*/
60+
typedef struct {
61+
unsigned char shared_secret[33];
62+
unsigned char proof[64];
63+
size_t index;
64+
} secp256k1_silentpayments_dleq_data;
65+
5366
/** Create Silent Payment outputs for recipient(s).
5467
*
5568
* Given a list of n secret keys a_1...a_n (one for each silent payment
@@ -444,6 +457,30 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_silentpayments_recipien
444457
const uint32_t k
445458
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
446459

460+
/** Serialize a secp256k1_silentpayments_dleq_data object into a 101-byte sequence.
461+
* 101-byte sequence = 33 bytes shared secret + 64 bytes proof + 4 bytes index
462+
* where index is position in an array of pointers to silent payment recipients
463+
*
464+
* Out: output: pointer to a 101-byte array to place the serialized `secp256k1_silentpayments_dleq_data` in
465+
* In: dleq_data: pointer to an initialized secp256k1_silentpayments_dleq_data object
466+
*/
467+
SECP256K1_API void secp256k1_silentpayments_dleq_data_serialize(
468+
unsigned char *output33,
469+
const secp256k1_silentpayments_dleq_data *dleq_data
470+
)SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
471+
472+
/** Parse a 101-byte sequence into a secp256k1_silentpayments_dleq_data object.
473+
* 101-byte sequence = 33 bytes shared secret + 64 bytes proof + 4 bytes index
474+
* where index is position in an array of pointers to silent payment recipients
475+
*
476+
* Out: dleq_data: pointer to a secp256k1_silentpayments_dleq_data object.
477+
* In: input: pointer to a serialized secp256k1_silentpayments_dleq_data.
478+
*/
479+
SECP256K1_API void secp256k1_silentpayments_dleq_data_parse(
480+
secp256k1_silentpayments_dleq_data *dleq_data,
481+
const unsigned char *input
482+
)SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
483+
447484
#ifdef __cplusplus
448485
}
449486
#endif

src/modules/silentpayments/main_impl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,4 +790,16 @@ int secp256k1_silentpayments_recipient_create_output_pubkey(const secp256k1_cont
790790
}
791791

792792

793+
void secp256k1_silentpayments_dleq_data_serialize(unsigned char *output, const secp256k1_silentpayments_dleq_data *dleq_data) {
794+
memcpy(output, dleq_data->shared_secret, 33);
795+
memcpy(output + 33, dleq_data->proof, 64);
796+
secp256k1_write_be32(output + 33 + 64, dleq_data->index);
797+
}
798+
799+
void secp256k1_silentpayments_dleq_data_parse(secp256k1_silentpayments_dleq_data *dleq_data, const unsigned char *input) {
800+
memcpy(dleq_data->shared_secret, input, 33);
801+
memcpy(dleq_data->proof, input + 33, 64);
802+
dleq_data->index = secp256k1_read_be32(input + 33 + 64);
803+
}
804+
793805
#endif

0 commit comments

Comments
 (0)