Instance Method
signature(customMessage:auxiliaryRand:)
Generates a Schnorr signature over an arbitrary-length message using caller-supplied auxiliary randomness.
- iOS 13.0+
- macCatalyst 13.0+
- macOS 10.15+
- tvOS 13.0+
- visionOS 1.0+
- watchOS 6.0+
func signature(customMessage: some ContiguousBytes, auxiliaryRand: some ContiguousBytes) throws -> P256K.Schnorr.SchnorrSignature
Parameters
-
customMessage
-
The message bytes to sign — any length, including zero.
-
auxiliaryRand
-
Exactly 32 bytes of auxiliary randomness for BIP-340 nonce derivation, borrowed read-only for the call. Pass a zeroed 32-byte container to reproduce the all-zero-aux behavior (upstream treats a NULL ndata as all-zero).
Return Value
A 64-byte P256K.Schnorr.SchnorrSignature.
Discussion
Wraps secp256k1_schnorrsig_sign_custom, which accepts any message length (an empty message is legal and reaches upstream with msglen = 0 — msg may be NULL). BIP-340 requires domain separation for non-32-byte messages — prefer hashing to 32 bytes with a tagged hash and calling signature(message:auxiliaryRand:) unless the signed protocol defines its own.
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
secp256k1Error.incorrectParameterSize if auxiliaryRand is not exactly 32 bytes. An upstream signing failure is unreachable on a validated key and would report through setInvariantViolationHandler(_:) instead.