Instance Method
signature(for:)
Generates a BIP-340 Schnorr signature from a pre-computed digest using secp256k1_schnorrsig_sign_custom with fresh 32-byte auxiliary randomness.
- iOS 13.0+
- macCatalyst 13.0+
- macOS 10.15+
- tvOS 13.0+
- visionOS 1.0+
- watchOS 6.0+
func signature<D>(for digest: D) throws -> P256K.Schnorr.SchnorrSignature where D : Digest
Parameters
-
digest
-
The pre-computed message digest to sign; signed at its natural byte length.
Return Value
A 64-byte P256K.Schnorr.SchnorrSignature.
Discussion
The auxiliary randomness is mixed into the BIP-340 nonce derivation (secp256k1_nonce_function_bip340) to protect against fault attacks. When the digest was produced using BIP-340 Tagged Hashes, the resulting signature is fully BIP-340 compliant.
Note
The digest’s raw bytes are passed to secp256k1_schnorrsig_sign_custom at their natural length as the message — BIP-340 (as amended) and the upstream custom signing API both accept arbitrary-length messages. This differs from the ECDSA and Recovery Digest overloads, which reduce the digest to a 32-byte msg32 per SEC1 §4.1.3, and from MuSig’s partialSignature, which requires exactly 32 bytes — those upstream entry points consume exactly 32 bytes.
Note
The produced signature is verified against this key’s xonly identity via secp256k1_schnorrsig_verify before it is returned — a failure is unreachable after input validation, reports through setInvariantViolationHandler(_:), and terminates the process.
Throws
Never throws in practice; throws is retained for API stability. An upstream signing failure is unreachable on a validated key and would report through setInvariantViolationHandler(_:) instead.