Skip to content

Commit 6ffad28

Browse files
committed
Add silentpayments_test_outputs
1 parent 4ae75ac commit 6ffad28

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

examples/silentpayments.c

+40-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ int main(void) {
117117
secp256k1_xonly_pubkey *out_pubkeys_ptrs[N_TX_OUTPUTS];
118118
unsigned char output36[36];
119119
secp256k1_xonly_pubkey taproot_outputs[N_TX_INPUTS];
120+
secp256k1_pubkey plain_outputs[N_TX_INPUTS];
121+
122+
unsigned char plain_seckeys[N_TX_INPUTS][32];
123+
const unsigned char *plain_seckeys_ptrs[N_TX_INPUTS];
120124

121125
unsigned char randomize[32];
122126
unsigned char xonly_print[32];
@@ -185,6 +189,10 @@ int main(void) {
185189
printf("Failed to create keypair\n");
186190
return 1;
187191
}
192+
if (!fill_random(plain_seckeys[i], sizeof(plain_seckeys[i]))) {
193+
printf("Failed to generate randomness\n");
194+
return 1;
195+
}
188196
}
189197
/*** Create the recipient objects ***/
190198

@@ -225,6 +233,25 @@ int main(void) {
225233
generated_output_ptrs[i] = &generated_outputs[i];
226234
}
227235

236+
for (i = 0; i < N_TX_INPUTS; i++) {
237+
secp256k1_pubkey pubkey;
238+
unsigned char serialized_pubkey[33];
239+
size_t len = 33;
240+
241+
ret = secp256k1_ec_pubkey_create(ctx, &pubkey, plain_seckeys[i]);
242+
assert(ret);
243+
ret = secp256k1_ec_pubkey_serialize(ctx, serialized_pubkey, &len, &pubkey, SECP256K1_EC_COMPRESSED);
244+
assert(ret);
245+
246+
printf("plain_pubkeys %li:\n", i);
247+
print_hex(serialized_pubkey, 33);
248+
249+
250+
plain_seckeys_ptrs[i] = plain_seckeys[i];
251+
}
252+
253+
printf("\n");
254+
228255
for (i = 0; i < N_TX_OUTPUTS; i++) {
229256
out_pubkeys_ptrs[i] = &out_pubkeys[i];
230257
}
@@ -236,8 +263,10 @@ int main(void) {
236263
N_TX_OUTPUTS,
237264
smallest_outpoint,
238265
sender_seckey_ptrs, N_TX_INPUTS,
266+
plain_seckeys_ptrs, N_TX_INPUTS,
239267
output36,
240-
taproot_outputs
268+
taproot_outputs,
269+
plain_outputs
241270
);
242271
assert(ret);
243272

@@ -265,6 +294,9 @@ int main(void) {
265294
unsigned char serialized_original_xonly_pubkey[32];
266295
unsigned char serialized_xonly_pubkey[32];
267296

297+
unsigned char serialized_pubkey[33];
298+
size_t len = 33;
299+
268300
ret = secp256k1_keypair_xonly_pub(ctx, &orignal_pubkey, NULL, &sender_seckeys[i]);
269301
assert(ret);
270302
ret = secp256k1_xonly_pubkey_serialize(ctx, serialized_original_xonly_pubkey, &orignal_pubkey);
@@ -278,6 +310,13 @@ int main(void) {
278310
print_hex(serialized_original_xonly_pubkey, 32);
279311
printf("Taproot Output %li:\n", i);
280312
print_hex(serialized_xonly_pubkey, 32);
313+
314+
315+
ret = secp256k1_ec_pubkey_serialize(ctx, serialized_pubkey, &len, &plain_outputs[i], SECP256K1_EC_COMPRESSED);
316+
assert(ret);
317+
318+
printf("Plain Output %li:\n", i);
319+
print_hex(serialized_pubkey, 33);
281320
printf("\n");
282321
}
283322

include/secp256k1_silentpayments.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,11 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_silentpayments_test_out
115115
const unsigned char *outpoint_smallest36,
116116
const secp256k1_keypair * const *taproot_seckeys,
117117
size_t n_taproot_seckeys,
118+
const unsigned char * const *plain_seckeys,
119+
size_t n_plain_seckeys,
118120
unsigned char *output36,
119-
secp256k1_xonly_pubkey *taproot_outputs
121+
secp256k1_xonly_pubkey *taproot_outputs,
122+
secp256k1_pubkey *plain_outputs
120123
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
121124

122125
/** Create Silent Payment label tweak and label.

src/modules/silentpayments/main_impl.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@ int secp256k1_silentpayments_test_outputs(
156156
const unsigned char *outpoint_smallest36,
157157
const secp256k1_keypair * const *taproot_seckeys,
158158
size_t n_taproot_seckeys,
159+
const unsigned char * const *plain_seckeys,
160+
size_t n_plain_seckeys,
159161
unsigned char *output36,
160-
secp256k1_xonly_pubkey *taproot_outputs
162+
secp256k1_xonly_pubkey *taproot_outputs,
163+
secp256k1_pubkey *plain_outputs
161164
) {
162165
size_t i;
163166
int ret = 1;
@@ -185,6 +188,13 @@ int secp256k1_silentpayments_test_outputs(
185188
}
186189
}
187190

191+
for (i = 0; i < n_plain_seckeys; i++) {
192+
ret = secp256k1_ec_pubkey_create(ctx, &plain_outputs[i], plain_seckeys[i]);
193+
if (!ret) {
194+
return 0;
195+
}
196+
}
197+
188198
return ret;
189199
}
190200

0 commit comments

Comments
 (0)