| 344 | } |
| 345 | |
| 346 | u8 *scriptpubkey_p2tr(const tal_t *ctx, const struct pubkey *inner_pubkey) |
| 347 | { |
| 348 | unsigned char key_bytes[33]; |
| 349 | unsigned char tweaked_key_bytes[33]; |
| 350 | size_t out_len = sizeof(key_bytes); |
| 351 | u8 *script = tal_arr(ctx, u8, 0); |
| 352 | |
| 353 | add_op(&script, OP_1); |
| 354 | |
| 355 | secp256k1_ec_pubkey_serialize(secp256k1_ctx, key_bytes, &out_len, &inner_pubkey->pubkey, SECP256K1_EC_COMPRESSED); |
| 356 | /* Only commit to inner pubkey in tweak */ |
| 357 | if (wally_ec_public_key_bip341_tweak(key_bytes, 33, /* merkle_root*/ NULL, 0, 0 /* flags */, tweaked_key_bytes, sizeof(tweaked_key_bytes)) != WALLY_OK) |
| 358 | abort(); |
| 359 | |
| 360 | /* Cut off the first byte from the serialized compressed key */ |
| 361 | script_push_bytes(&script, tweaked_key_bytes + 1, sizeof(tweaked_key_bytes) - 1); |
| 362 | assert(tal_count(script) == BITCOIN_SCRIPTPUBKEY_P2TR_LEN); |
| 363 | return script; |
| 364 | } |
| 365 | |
| 366 | u8 *scriptpubkey_p2tr_derkey(const tal_t *ctx, const u8 inner_der[33]) |
| 367 | { |
no test coverage detected