Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions include/secp256k1_silentpayments.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ typedef struct secp256k1_silentpayments_recipient {
size_t index;
} secp256k1_silentpayments_recipient;

/* This struct contains details of the DLEQ proof
*
* Fields:
* - shared_secret : 33-byte shared secret point
* - proof: 64-byte serialized DLEQ proof
* - index: Indicates which recipient the proof pertains to based on the original (not sorted) ordering of the addresses
*/
typedef struct {
unsigned char shared_secret[33];
unsigned char proof[64];
size_t index;
} secp256k1_silentpayments_dleq_data;

/** Create Silent Payment outputs for recipient(s).
*
* Given a list of n secret keys a_1...a_n (one for each silent payment
Expand Down Expand Up @@ -444,6 +457,30 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_silentpayments_recipien
const uint32_t k
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);

/** Serialize a secp256k1_silentpayments_dleq_data object into a 101-byte sequence.
* 101-byte sequence = 33 bytes shared secret + 64 bytes proof + 4 bytes index
* where index is position in an array of pointers to silent payment recipients
*
* Out: output: pointer to a 101-byte array to place the serialized `secp256k1_silentpayments_dleq_data` in
* In: dleq_data: pointer to an initialized secp256k1_silentpayments_dleq_data object
*/
SECP256K1_API void secp256k1_silentpayments_dleq_data_serialize(
unsigned char *output33,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsigned char *output33,
unsigned char *output101,

const secp256k1_silentpayments_dleq_data *dleq_data
)SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);

/** Parse a 101-byte sequence into a secp256k1_silentpayments_dleq_data object.
* 101-byte sequence = 33 bytes shared secret + 64 bytes proof + 4 bytes index
* where index is position in an array of pointers to silent payment recipients
*
* Out: dleq_data: pointer to a secp256k1_silentpayments_dleq_data object.
* In: input: pointer to a serialized secp256k1_silentpayments_dleq_data.
*/
SECP256K1_API void secp256k1_silentpayments_dleq_data_parse(
secp256k1_silentpayments_dleq_data *dleq_data,
const unsigned char *input
)SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);

#ifdef __cplusplus
}
#endif
Expand Down
12 changes: 12 additions & 0 deletions src/modules/silentpayments/main_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -790,4 +790,16 @@ int secp256k1_silentpayments_recipient_create_output_pubkey(const secp256k1_cont
}


void secp256k1_silentpayments_dleq_data_serialize(unsigned char *output, const secp256k1_silentpayments_dleq_data *dleq_data) {
memcpy(output, dleq_data->shared_secret, 33);
memcpy(output + 33, dleq_data->proof, 64);
secp256k1_write_be32(output + 33 + 64, dleq_data->index);
}

void secp256k1_silentpayments_dleq_data_parse(secp256k1_silentpayments_dleq_data *dleq_data, const unsigned char *input) {
memcpy(dleq_data->shared_secret, input, 33);
memcpy(dleq_data->proof, input + 33, 64);
dleq_data->index = secp256k1_read_be32(input + 33 + 64);
}

#endif