Skip to content

Commit fae6014

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 b5ef01f commit fae6014

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
@@ -43,6 +43,19 @@ typedef struct {
4343
size_t index;
4444
} secp256k1_silentpayments_recipient;
4545

46+
/* This struct contains details of the DLEQ proof
47+
*
48+
* Fields:
49+
* - shared_secret : 33-byte shared secret point
50+
* - proof: 64-byte serialized DLEQ proof
51+
* - index: Indicates which recipient the proof pertains to based on the original (not sorted) ordering of the addresses
52+
*/
53+
typedef struct {
54+
unsigned char shared_secret[33];
55+
unsigned char proof[64];
56+
size_t index;
57+
} secp256k1_silentpayments_dleq_data;
58+
4659
/** Create Silent Payment outputs for recipient(s).
4760
*
4861
* Given a list of n private keys a_1...a_n (one for each silent payment
@@ -399,6 +412,30 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_silentpayments_recipien
399412
unsigned int k
400413
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
401414

415+
/** Serialize a secp256k1_silentpayments_dleq_data object into a 101-byte sequence.
416+
* 101-byte sequence = 33 bytes shared secret + 64 bytes proof + 4 bytes index
417+
* where index is position in an array of pointers to silent payment recipients
418+
*
419+
* Out: output: pointer to a 101-byte array to place the serialized `secp256k1_silentpayments_dleq_data` in
420+
* In: dleq_data: pointer to an initialized secp256k1_silentpayments_dleq_data object
421+
*/
422+
SECP256K1_API void secp256k1_silentpayments_dleq_data_serialize(
423+
unsigned char *output33,
424+
const secp256k1_silentpayments_dleq_data *dleq_data
425+
)SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
426+
427+
/** Parse a 101-byte sequence into a secp256k1_silentpayments_dleq_data object.
428+
* 101-byte sequence = 33 bytes shared secret + 64 bytes proof + 4 bytes index
429+
* where index is position in an array of pointers to silent payment recipients
430+
*
431+
* Out: dleq_data: pointer to a secp256k1_silentpayments_dleq_data object.
432+
* In: input: pointer to a serialized secp256k1_silentpayments_dleq_data.
433+
*/
434+
SECP256K1_API void secp256k1_silentpayments_dleq_data_parse(
435+
secp256k1_silentpayments_dleq_data *dleq_data,
436+
const unsigned char *input
437+
)SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
438+
402439
#ifdef __cplusplus
403440
}
404441
#endif

src/modules/silentpayments/main_impl.h

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

659659

660+
void secp256k1_silentpayments_dleq_data_serialize(unsigned char *output, const secp256k1_silentpayments_dleq_data *dleq_data) {
661+
memcpy(output, dleq_data->shared_secret, 33);
662+
memcpy(output + 33, dleq_data->proof, 64);
663+
secp256k1_write_be32(output + 33 + 64, dleq_data->index);
664+
}
665+
666+
void secp256k1_silentpayments_dleq_data_parse(secp256k1_silentpayments_dleq_data *dleq_data, const unsigned char *input) {
667+
memcpy(dleq_data->shared_secret, input, 33);
668+
memcpy(dleq_data->proof, input + 33, 64);
669+
dleq_data->index = secp256k1_read_be32(input + 33 + 64);
670+
}
671+
660672
#endif

0 commit comments

Comments
 (0)