Skip to content

Commit cebd16d

Browse files
committed
Add silentpayments_test_outputs
1 parent c4e3d89 commit cebd16d

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

examples/silentpayments.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ const unsigned char* label_lookup(
111111
}
112112

113113
int main(void) {
114-
enum { N_TX_INPUTS = 2, N_TX_OUTPUTS = 3 };
114+
enum { N_TX_INPUTS = 2, N_TX_OUTPUTS = 3, N_OUT_PUBKEYS = 198 };
115+
116+
int n_out_pubkeys = N_OUT_PUBKEYS;
117+
unsigned char out_pubkeys[N_OUT_PUBKEYS];
118+
115119
unsigned char randomize[32];
116120
unsigned char xonly_print[32];
117121
secp256k1_xonly_pubkey tx_inputs[N_TX_INPUTS];
@@ -219,8 +223,17 @@ int main(void) {
219223
generated_output_ptrs[i] = &generated_outputs[i];
220224
}
221225

222-
ret = secp256k1_silentpayments_test_outputs(ctx, recipients, N_TX_OUTPUTS);
226+
ret = secp256k1_silentpayments_test_outputs(
227+
ctx,
228+
recipients,
229+
N_TX_OUTPUTS,
230+
out_pubkeys,
231+
n_out_pubkeys
232+
);
223233
assert(ret);
234+
235+
printf("out_pubkeys: ");
236+
print_hex(out_pubkeys, n_out_pubkeys);
224237

225238
ret = secp256k1_silentpayments_sender_create_outputs(ctx,
226239
generated_output_ptrs,

include/secp256k1_silentpayments.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_silentpayments_sender_c
110110
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_silentpayments_test_outputs(
111111
const secp256k1_context *ctx,
112112
const secp256k1_silentpayments_recipient *recipients,
113-
size_t n_recipients
113+
size_t n_recipients,
114+
unsigned char *out_pubkeys,
115+
size_t n_out_pubkeys
114116
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
115117

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

src/modules/silentpayments/main_impl.h

+23-14
Original file line numberDiff line numberDiff line change
@@ -139,54 +139,63 @@ static int secp256k1_silentpayments_create_output_pubkey(const secp256k1_context
139139
return ret;
140140
}
141141

142-
static void print_hex(unsigned char* data, size_t size) {
142+
/* static void print_hex(unsigned char* data, size_t size) {
143143
size_t i;
144144
printf("0x");
145145
for (i = 0; i < size; i++) {
146146
printf("%02x", data[i]);
147147
}
148148
printf("\n");
149-
}
149+
} */
150150

151151
int secp256k1_silentpayments_test_outputs(
152152
const secp256k1_context *ctx,
153153
const secp256k1_silentpayments_recipient *recipients,
154-
size_t n_recipients
154+
size_t n_recipients,
155+
unsigned char *out_pubkeys,
156+
size_t n_out_pubkeys
155157
) {
156158
size_t i;
157159
int ret = 1;
158160

161+
VERIFY_CHECK(n_out_pubkeys == 66 * n_recipients);
159162

160163
for (i = 0; i < n_recipients; i++) {
161164
ARG_CHECK(recipients[i].index == i);
162165
}
163166

167+
/* Initialize out_pubkeys to zero */
168+
memset(out_pubkeys, 0, n_out_pubkeys);
169+
164170
for (i = 0; i < n_recipients; i++) {
165-
unsigned char compressed_scan_pubkey[33];
166-
unsigned char compressed_spend_pubkey[33];
171+
unsigned char *compressed_scan_pubkey = &out_pubkeys[i * 66];
172+
unsigned char *compressed_spend_pubkey = &out_pubkeys[i * 66 + 33];
173+
167174
size_t len;
168175

169-
printf("index: %ld\n", recipients[i].index);
176+
// printf("index: %ld\n", recipients[i].index);
170177

171178
/* Serialize pubkey1 in a compressed form (33 bytes), should always return 1 */
172-
len = sizeof(compressed_scan_pubkey);
179+
len = 33;
173180
ret = secp256k1_ec_pubkey_serialize(ctx, compressed_scan_pubkey, &len, &recipients[i].scan_pubkey, SECP256K1_EC_COMPRESSED);
174181
/* Should be the same size as the size of the output, because we passed a 33 byte array. */
175-
VERIFY_CHECK(len == sizeof(compressed_scan_pubkey));
182+
VERIFY_CHECK(len == 33);
176183

177-
len = sizeof(compressed_spend_pubkey);
184+
len = 33;
178185
ret = secp256k1_ec_pubkey_serialize(ctx, compressed_spend_pubkey, &len, &recipients[i].spend_pubkey, SECP256K1_EC_COMPRESSED);
179186
/* Should be the same size as the size of the output, because we passed a 33 byte array. */
180-
VERIFY_CHECK(len == sizeof(compressed_spend_pubkey));
187+
VERIFY_CHECK(len == 33);
181188

182-
printf("scan_pubkey: ");
183-
print_hex(compressed_scan_pubkey, sizeof(compressed_scan_pubkey));
189+
// printf("scan_pubkey: ");
190+
// print_hex(compressed_scan_pubkey, 33);
184191

185-
printf("spend_pubkey: ");
186-
print_hex(compressed_spend_pubkey, sizeof(compressed_spend_pubkey));
192+
// printf("spend_pubkey: ");
193+
// print_hex(compressed_spend_pubkey, 33);
187194

188195
}
189196

197+
VERIFY_CHECK((i * 66) == n_out_pubkeys);
198+
190199
return ret;
191200
}
192201

0 commit comments

Comments
 (0)