Skip to content

Commit

Permalink
Add silentpayments_test_outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
jlest01 committed Aug 2, 2024
1 parent 097f607 commit 4ae75ac
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
29 changes: 25 additions & 4 deletions examples/silentpayments.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ int main(void) {
secp256k1_xonly_pubkey out_pubkeys[N_TX_OUTPUTS];
secp256k1_xonly_pubkey *out_pubkeys_ptrs[N_TX_OUTPUTS];
unsigned char output36[36];
secp256k1_xonly_pubkey taproot_outputs[N_TX_INPUTS];

unsigned char randomize[32];
unsigned char xonly_print[32];
Expand Down Expand Up @@ -234,7 +235,9 @@ int main(void) {
recipient_ptrs,
N_TX_OUTPUTS,
smallest_outpoint,
output36
sender_seckey_ptrs, N_TX_INPUTS,
output36,
taproot_outputs
);
assert(ret);

Expand All @@ -256,9 +259,27 @@ int main(void) {

printf("output36:\n");
print_hex(output36, 36);

/* printf("out_pubkeys: ");
print_hex(out_pubkeys, n_out_pubkeys); */

for (i = 0; i < N_TX_INPUTS; i++) {
secp256k1_xonly_pubkey orignal_pubkey;
unsigned char serialized_original_xonly_pubkey[32];
unsigned char serialized_xonly_pubkey[32];

ret = secp256k1_keypair_xonly_pub(ctx, &orignal_pubkey, NULL, &sender_seckeys[i]);
assert(ret);
ret = secp256k1_xonly_pubkey_serialize(ctx, serialized_original_xonly_pubkey, &orignal_pubkey);
assert(ret);

ret = secp256k1_xonly_pubkey_serialize(ctx, serialized_xonly_pubkey, &taproot_outputs[i]);
assert(ret);

printf("\n");
printf("Original Taproot Input %li:\n", i);
print_hex(serialized_original_xonly_pubkey, 32);
printf("Taproot Output %li:\n", i);
print_hex(serialized_xonly_pubkey, 32);
printf("\n");
}

ret = secp256k1_silentpayments_sender_create_outputs(ctx,
generated_output_ptrs,
Expand Down
5 changes: 4 additions & 1 deletion include/secp256k1_silentpayments.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_silentpayments_test_out
const secp256k1_silentpayments_recipient **recipients,
size_t n_recipients,
const unsigned char *outpoint_smallest36,
unsigned char *output36
const secp256k1_keypair * const *taproot_seckeys,
size_t n_taproot_seckeys,
unsigned char *output36,
secp256k1_xonly_pubkey *taproot_outputs
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);

/** Create Silent Payment label tweak and label.
Expand Down
12 changes: 11 additions & 1 deletion src/modules/silentpayments/main_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ int secp256k1_silentpayments_test_outputs(
const secp256k1_silentpayments_recipient **recipients,
size_t n_recipients,
const unsigned char *outpoint_smallest36,
unsigned char *output36
const secp256k1_keypair * const *taproot_seckeys,
size_t n_taproot_seckeys,
unsigned char *output36,
secp256k1_xonly_pubkey *taproot_outputs
) {
size_t i;
int ret = 1;
Expand All @@ -175,6 +178,13 @@ int secp256k1_silentpayments_test_outputs(

memcpy(output36, outpoint_smallest36, 36);

for (i = 0; i < n_taproot_seckeys; i++) {
ret = secp256k1_keypair_xonly_pub(ctx, &taproot_outputs[i], NULL, taproot_seckeys[i]);
if (!ret) {
return 0;
}
}

return ret;
}

Expand Down

0 comments on commit 4ae75ac

Please sign in to comment.