[#CKey-ComputeKeyPair]
= xref:CKey.adoc[CKey]::ComputeKeyPair
:relfileprefix: ../
:mrdocs:

Compute a KeyPair

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:KeyPair.adoc[KeyPair]
ComputeKeyPair(xref:uint256.adoc[uint256] const* merkle&lowbar;root) const;
----

== Description

Wraps a `secp256k1&lowbar;keypair` type&period;

`merkle&lowbar;root` is used to optionally perform tweaking of the internal key, as specified in BIP341&colon;

* If merkle&lowbar;root &equals;&equals; nullptr&colon; no tweaking is done, use the internal key directly (this is used for signatures in BIP342 script)&period;
* If merkle&lowbar;root&hyphen;&gt;IsNull()&colon; tweak the internal key with H&lowbar;TapTweak(pubkey) (this is used for key path spending when no scripts are present)&period;
* Otherwise&colon; tweak the internal key with H&lowbar;TapTweak(pubkey &verbar;&verbar; &ast;merkle&lowbar;root) (this is used for key path spending with the Merkle root of the script tree)&period;

== Return Value

The computed key pair&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *merkle&lowbar;root*
| Optional Merkle root controlling BIP341 tweaking (see above)&period;
|===


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