Skip to content

Commit afdccde

Browse files
committed
silentpayments: add routine for creating labelled spend pubkeys (for addresses)
1 parent 0a4dff1 commit afdccde

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

include/secp256k1_silentpayments.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,29 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_silentpayments_create_l
167167
unsigned int m
168168
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
169169

170+
/** Create Silent Payment labelled spend public key.
171+
*
172+
* Given a recipient's spend public key B_spend and a label_tweak, calculate
173+
* the corresponding serialized labelled spend public key:
174+
*
175+
* B_m = B_spend + label_tweak * G
176+
*
177+
* The result is used by the receiver to create a Silent Payment address, consisting
178+
* of the serialized and concatenated scan public key and (labelled) spend public key each.
179+
*
180+
* Returns: 1 if labellend spend public key creation was successful. 0 if an error occured.
181+
* Args: ctx: pointer to a context object
182+
* Out: l_addr_spend_pubkey33: pointer to the resulting labelled spend public key
183+
* In: receiver_spend_pubkey: pointer to the receiver's scan pubkey
184+
* label_tweak: pointer to the the receiver's spend
185+
*/
186+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_silentpayments_create_address_spend_pubkey(
187+
const secp256k1_context *ctx,
188+
unsigned char *l_addr_spend_pubkey33,
189+
const secp256k1_pubkey *receiver_spend_pubkey,
190+
const unsigned char *label_tweak32
191+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
192+
170193
#ifdef __cplusplus
171194
}
172195
#endif

src/modules/silentpayments/main_impl.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,29 @@ int secp256k1_silentpayments_create_label_tweak(const secp256k1_context *ctx, un
253253
return 1;
254254
}
255255

256+
int secp256k1_silentpayments_create_address_spend_pubkey(const secp256k1_context *ctx, unsigned char *l_addr_spend_pubkey33, const secp256k1_pubkey *receiver_spend_pubkey, const unsigned char *label_tweak32) {
257+
secp256k1_ge B_m;
258+
size_t ser_size;
259+
int ser_ret;
260+
261+
/* Sanity check inputs. */
262+
VERIFY_CHECK(ctx != NULL);
263+
VERIFY_CHECK(l_addr_spend_pubkey33 != NULL);
264+
VERIFY_CHECK(receiver_spend_pubkey != NULL);
265+
VERIFY_CHECK(label_tweak32 != NULL);
266+
267+
/* Calculate B_m = B_spend + label_tweak * G */
268+
secp256k1_pubkey_load(ctx, &B_m, receiver_spend_pubkey);
269+
if (!secp256k1_ec_pubkey_tweak_add_helper(&B_m, label_tweak32)) {
270+
return 0;
271+
}
272+
273+
/* Serialize B_m */
274+
ser_ret = secp256k1_eckey_pubkey_serialize(&B_m, l_addr_spend_pubkey33, &ser_size, 1);
275+
VERIFY_CHECK(ser_ret && ser_size == 33);
276+
(void)ser_ret;
277+
278+
return 1;
279+
}
280+
256281
#endif

0 commit comments

Comments
 (0)