[#MuSig2AggregatePubkeys-04]
= MuSig2AggregatePubkeys
:mrdocs:

Compute the full aggregate pubkey from the given participant pubkeys in their current order&period; Outputs the secp256k1&lowbar;musig&lowbar;keyagg&lowbar;cache and validates that the computed aggregate pubkey matches an expected aggregate pubkey&period; This is necessary for most MuSig2 operations&period;

== Synopsis

Declared in `&lt;musig&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
std::optional&lt;CPubKey&gt;
MuSig2AggregatePubkeys(
    std::vector&lt;CPubKey&gt; const& pubkeys,
    xref:secp256k1_musig_keyagg_cache.adoc[secp256k1&lowbar;musig&lowbar;keyagg&lowbar;cache]& keyagg&lowbar;cache,
    std::optional&lt;CPubKey&gt; const& expected&lowbar;aggregate);
----

== Return Value

The aggregate public key, or std&colon;&colon;nullopt if aggregation fails or does not match expected&lowbar;aggregate&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *pubkeys*
| The participant public keys, in the order they should be aggregated&period;
| *keyagg&lowbar;cache*
| Output cache populated with the aggregation state for later MuSig2 operations&period;
| *expected&lowbar;aggregate*
| Optional aggregate pubkey to validate the computed result against&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
