Instance Method
add(_:)
Creates a new P256K.Signing.PrivateKey by computing secret_key' = (secret_key + tweak) mod n via secp256k1_ec_seckey_tweak_add (declared in Vendor/secp256k1/include/secp256k1.h), where n is the secp256k1 curve order.
- iOS 13.0+
- macCatalyst 13.0+
- macOS 10.15+
- tvOS 13.0+
- visionOS 1.0+
- watchOS 6.0+
func add(_ tweak: [UInt8]) throws -> P256K.Signing.PrivateKey
Parameters
-
tweak
-
A 32-byte tweak scalar; must not produce a result that is zero modulo n.
Return Value
A new P256K.Signing.PrivateKey with the tweaked secret scalar.
Discussion
Scalar addition on private keys pairs with public-key point addition through the homomorphism G × (sk + t) = pk + G × t — the foundation of BIP-32 unhardened child key derivation. For BIP-341 Taproot key-path tweaking, use add(_:) on the x-only form instead.
Throws
secp256k1Error.underlyingCryptoError if the tweak is invalid or the result is zero modulo n.