Instance Method
add(_:)
Creates a new P256K.Schnorr.PrivateKey by applying a BIP-341 Taproot x-only tweak to the secret scalar via secp256k1_keypair_xonly_tweak_add (declared in Vendor/secp256k1/include/secp256k1_extrakeys.h).
- iOS 13.0+
- macCatalyst 13.0+
- macOS 10.15+
- tvOS 13.0+
- visionOS 1.0+
- watchOS 6.0+
func add(_ tweak: [UInt8]) throws -> P256K.Schnorr.PrivateKey
Parameters
-
tweak
-
A 32-byte tweak scalar (typically the output of a Taproot TapTweak tagged hash).
Return Value
A new P256K.Schnorr.PrivateKey whose x-only public key is the Taproot-tweaked form of the original.
Discussion
When the x-only representation of the current key has odd Y, the upstream keypair helper implicitly negates the secret scalar before applying the tweak so the resulting keypair has even Y (the canonical BIP-340 form). See upstream discussion at bitcoin-core/secp256k1#1021.
This is the signing-side companion to add(_:); applying the same tweak to both forms yields a valid (sk', xonly') pair for BIP-341 Taproot key-path spending.
Throws
secp256k1Error.underlyingCryptoError if the tweak is invalid or any upstream step fails.