| Copyright | (c) 2025 Jose Storopoli |
|---|---|
| License | MIT |
| Maintainer | Jose Storopoli <jose@storopoli.com> |
| Safe Haskell | None |
| Language | Haskell2010 |
Crypto.Curve.Secp256k1.MuSig2
Description
BIP-327 MuSig2 multi-signatures on secp256k1: \(n\) signers produce one ordinary BIP-340 Schnorr signature for their aggregate public key, in two rounds.
- Key aggregation: everyone runs
keyAggon the same list of public keys (optionally sorted withkeySort) and applies the same tweaks, e.g.applyTaprootTweak. - Round one: each signer runs
nonceGenand sends itsPubNonceto the others (or to a coordinator), who aggregate them withnonceAgg. - Round two: everyone opens the same
SessionwithnewSession; each signer runssignonce (it consumes the secret nonce) and sends itsPartialSignature. - The aggregator checks each partial signature with
partialSigVerifyand combines them withpartialSigAgg. Anyone can check the result withverifyagainstaggXOnlyPubKey.
Crypto.Curve.Secp256k1.MuSig2.Coordinator runs both rounds for a coordinator that receives the contributions as bytes: it decodes and verifies each one and blames the signer of an invalid, conflicting or missing one.
Values sent between signers are encoded and decoded with Encode, in the
BIP-327 byte formats. Decoding validates: every value of a type exported here
is valid by construction.
Security considerations
- Each nonce signs once. Signing twice with the same secret nonce, in
any two sessions, lets the other signers compute your secret key. A
SecNoncefromnonceGenis one-shot:signatomically marks it used before doing anything else, so a secondsignwith it (or with any copy of it, from any thread) returnsSecNonceAlreadyUsed. A failedsignuses the nonce up too: after anySignError, generate a new nonce and start again from round one.SecNoncecannot be encoded, shown, compared or rebuilt from its parts, andnonceGenalways draws fresh randomness. Crypto.Curve.Secp256k1.MuSig2.Unsafe has the escape hatches (caller-supplied randomness, counters, export and import of secret nonces) that this protection cannot cover. - Bind nonces to the session when you can. If the aggregate key or the
message is known in round one, pass them to
nonceGen(seeNonceInputs):signthen refuses any other session (SecNonceSessionMismatch), and they add protection should the random number generator fail. - Signers without randomness can use
deterministicSign(BIP-327DeterministicSign) if they are the last to send their public nonce, after receiving everyone else's. - Verify partial signatures.
partialSigAggdoes not check its inputs; runpartialSigVerifyon every partial signature you did not make, so a wrong one is attributed to its signer instead of producing an invalid signature (Crypto.Curve.Secp256k1.MuSig2.Coordinator does this).signchecks its own result. - Bound the size of untrusted messages. BIP-327 allows messages of any length. No function copies a long message or extra input to hash it, but each one holds the whole message in memory, so if messages come from untrusted parties, cap their size before passing them in.
Constant-time arithmetic on secrets. Secret keys and nonces are never held in an
Integer. They are parsed, range-checked, reduced from hashes, combined (\(k_1 + b k_2\) and \(k + e a d\) insign), negated and encoded with the fixed-width, constant-time Montgomery arithmetic ofppad-fixed, and multiplied with the generator byppad-secp256k1's timing-safe wNAF. Caveats:- Public values (key aggregation coefficients, nonce coefficients,
challenges, tweaks, partial signatures, public keys and nonces) use
variable-time
Integerarithmetic and curve operations, by design. - Constant time is a property of the machine code, which GHC does not
guarantee. The Haskell code has no branch or memory access that
depends on a secret (checked in GHC Core); with the
llvmflag on x86_64, LLVM's conversion of conditional moves into branches is disabled, as inppad-fixedandppad-secp256k1. Other code generators and architectures are not audited.
- Public values (key aggregation coefficients, nonce coefficients,
challenges, tweaks, partial signatures, public keys and nonces) use
variable-time
- Zeroization is best-effort. The scalars of a
SecNoncelive in a pinned buffer (which the garbage collector never copies) thatsignzero-fills when it consumes the nonce. Everything else is an ordinary Haskell value that is not wiped and may be copied by the garbage collector: secret keys, the intermediate values computed from the nonce while signing (fixed-width words, but still heap values), and the buffer of a nonce that is dropped without being used. - Randomness.
nonceGenreads 32 bytes from the operating system's random number generator (getrandomon Linux, via theentropypackage). Passing the optionalNonceInputsadds protection should it fail.
Usage
Two signers (this example is compiled and run by the test suite; it needs
the OverloadedStrings language extension):
import Control.Exception (Exception, throwIO) import qualified Crypto.Curve.Secp256k1.MuSig2 as MuSig2 import qualified Data.ByteString as BS import Data.List.NonEmpty (NonEmpty (..)) import qualified Data.List.NonEmpty as NE
-- | Throws the error of a 'Left'.
orThrow :: (Exception e) => Either e a -> IO a
orThrow = either throwIO pure
-- | Two signers sign a message; returns whether the signature verifies.
example :: IO Bool
example = do
-- Each signer has a secret key and publishes its public key.
-- (Fixed keys for the example only: never hard-code real keys.)
sk1 <- orThrow (MuSig2.secKeyFromBytes (BS.replicate 32 0x11))
sk2 <- orThrow (MuSig2.secKeyFromBytes (BS.replicate 32 0x22))
let pk1 = MuSig2.secKeyPubKey sk1
pk2 = MuSig2.secKeyPubKey sk2
-- Everyone aggregates the same list of public keys, here sorted.
keyAggCtx <- orThrow (MuSig2.keyAgg (MuSig2.keySort (pk1 :| [pk2])))
let aggKey = MuSig2.aggXOnlyPubKey keyAggCtx
msg = "i approve of this message"
-- Each signer generates a fresh nonce and publishes the public part.
(secNonce1, pubNonce1) <- MuSig2.nonceGen pk1 MuSig2.noNonceInputs >>= orThrow
(secNonce2, pubNonce2) <- MuSig2.nonceGen pk2 MuSig2.noNonceInputs >>= orThrow
-- Values travel as bytes; decoding validates them.
received <- orThrow (MuSig2.decode (MuSig2.encode pubNonce2))
-- Everyone aggregates the public nonces and opens the same session.
let session = MuSig2.newSession keyAggCtx (MuSig2.nonceAgg (pubNonce1 :| [received])) msg
-- Each signer signs once with its nonce and publishes its partial signature.
-- 'sign' consumes the secret nonce: signing again with it fails.
psig1 <- MuSig2.sign secNonce1 sk1 session >>= orThrow
psig2 <- MuSig2.sign secNonce2 sk2 session >>= orThrow
-- The aggregator checks each partial signature, then aggregates them.
let valid =
MuSig2.partialSigVerify session pk1 pubNonce1 psig1
&& MuSig2.partialSigVerify session pk2 pubNonce2 psig2
signature = MuSig2.partialSigAgg session (psig1 :| [psig2])
-- The result is an ordinary BIP-340 signature for the aggregate key.
pure (valid && MuSig2.verify aggKey msg signature)Taproot
A Taproot output key is the aggregate key tweaked with applyTaprootTweak:
-- | Three signers spend a Taproot output by key path.
taprootExample :: IO Bool
taprootExample = do
sks <- traverse (orThrow . MuSig2.secKeyFromBytes . BS.replicate 32) (0x33 :| [0x44, 0x55])
let pks = fmap MuSig2.secKeyPubKey sks
-- The internal key is the aggregate key; the output key commits to the
-- script tree's merkle root ('Nothing' for a key-path-only output, BIP-86).
internal <- orThrow (MuSig2.keyAgg (MuSig2.keySort pks))
output <- orThrow (MuSig2.applyTaprootTweak (Just (BS.replicate 32 0xAB)) internal)
let outputKey = MuSig2.aggXOnlyPubKey output
sighash = BS.replicate 32 0x01
-- Binding the nonces to the key and message adds protection against bad randomness.
let inputs sk =
MuSig2.noNonceInputs
{ MuSig2.nonceSecKey = Just sk
, MuSig2.nonceAggPubKey = Just outputKey
, MuSig2.nonceMessage = Just sighash
}
nonces <- traverse (\sk -> MuSig2.nonceGen (MuSig2.secKeyPubKey sk) (inputs sk) >>= orThrow) sks
-- Sessions are opened on the tweaked context: the tweak lives in the context only.
let session = MuSig2.newSession output (MuSig2.nonceAgg (fmap snd nonces)) sighash
psigs <- traverse (\(sk, (secNonce, _)) -> MuSig2.sign secNonce sk session >>= orThrow) (NE.zip sks nonces)
let signature = MuSig2.partialSigAgg session psigs
pure (MuSig2.verify outputKey sighash signature)Synopsis
- data SecKey
- secKeyFromBytes :: ByteString -> Either DecodeError SecKey
- secKeyToBytes :: SecKey -> ByteString
- secKeyPubKey :: SecKey -> PubKey
- data PubKey
- pubKeyFromPoint :: Projective -> Either DecodeError PubKey
- pubKeyPoint :: PubKey -> Projective
- data XOnlyPubKey
- pubKeyXOnly :: PubKey -> XOnlyPubKey
- class Encode a where
- encode :: a -> ByteString
- decode :: ByteString -> Either DecodeError a
- data KeyAggContext
- keySort :: NonEmpty PubKey -> NonEmpty PubKey
- keyAgg :: NonEmpty PubKey -> Either KeyAggError KeyAggContext
- aggPubKey :: KeyAggContext -> PubKey
- aggXOnlyPubKey :: KeyAggContext -> XOnlyPubKey
- keyAggPubKeys :: KeyAggContext -> NonEmpty PubKey
- signerIndex :: KeyAggContext -> PubKey -> Maybe Int
- data Tweak
- tweakFromBytes :: ByteString -> Either DecodeError Tweak
- applyPlainTweak :: Tweak -> KeyAggContext -> Either KeyAggError KeyAggContext
- applyXOnlyTweak :: Tweak -> KeyAggContext -> Either KeyAggError KeyAggContext
- applyTaprootTweak :: Maybe ByteString -> KeyAggContext -> Either KeyAggError KeyAggContext
- data SecNonce
- data PubNonce
- data AggNonce
- data NonceInputs = NonceInputs {
- nonceSecKey :: !(Maybe SecKey)
- nonceAggPubKey :: !(Maybe XOnlyPubKey)
- nonceMessage :: !(Maybe ByteString)
- nonceExtraInput :: !(Maybe ByteString)
- noNonceInputs :: NonceInputs
- nonceGen :: PubKey -> NonceInputs -> IO (Either NonceGenError (SecNonce, PubNonce))
- nonceAgg :: NonEmpty PubNonce -> AggNonce
- data Session
- newSession :: KeyAggContext -> AggNonce -> ByteString -> Session
- sessionKeyAgg :: Session -> KeyAggContext
- data PartialSignature
- sign :: SecNonce -> SecKey -> Session -> IO (Either SignError PartialSignature)
- deterministicSign :: SecKey -> AggNonce -> KeyAggContext -> ByteString -> Maybe ByteString -> Either SignError (PubNonce, PartialSignature)
- partialSigVerify :: Session -> PubKey -> PubNonce -> PartialSignature -> Bool
- partialSigAgg :: Session -> NonEmpty PartialSignature -> Signature
- data Signature
- verify :: XOnlyPubKey -> ByteString -> Signature -> Bool
- data DecodeError
- = InvalidLength {
- expectedLength :: !Int
- actualLength :: !Int
- | InvalidPoint
- | PointAtInfinity
- | ScalarOutOfRange
- | ScalarZero
- = InvalidLength {
- data KeyAggError
- data NonceGenError
- data SignError
Keys
secKeyFromBytes :: ByteString -> Either DecodeError SecKey Source #
A secret key from 32 big-endian bytes in \([1, n)\). The range check
runs in constant time; only its outcome (valid, ScalarZero or
ScalarOutOfRange) is revealed.
secKeyToBytes :: SecKey -> ByteString Source #
The 32-byte big-endian encoding of a secret key, in constant time.
secKeyPubKey :: SecKey -> PubKey Source #
The public key \(d \cdot G\) of a secret key.
A public key: a finite point on the curve.
Caches its 33-byte compressed encoding; Eq and Ord compare that encoding
(the order is the one BIP-327 KeySort uses), and Show prints it in hex.
Instances
| NFData PubKey Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Types | |
| Show PubKey Source # | |
| Eq PubKey Source # | |
| Ord PubKey Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Types | |
| Encode PubKey Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Types Methods encode :: PubKey -> ByteString Source # decode :: ByteString -> Either DecodeError PubKey Source # | |
pubKeyFromPoint :: Projective -> Either DecodeError PubKey Source #
A PubKey from any point: rejects infinity and points not on the curve.
pubKeyPoint :: PubKey -> Projective Source #
The public key as a ppad-secp256k1 point.
data XOnlyPubKey Source #
A BIP-340 x-only public key: the finite point with the given x-coordinate and an even y-coordinate.
Instances
pubKeyXOnly :: PubKey -> XOnlyPubKey Source #
The x-only key of a public key (negated to even y if needed).
Encodings
Types with a canonical BIP-327 byte encoding.
, and decode . encode = Rightdecode accepts exactly the canonical
encodings: it rejects wrong lengths, invalid points and out-of-range scalars.
Secrets have no instance.
Methods
encode :: a -> ByteString Source #
The canonical encoding.
decode :: ByteString -> Either DecodeError a Source #
Parses and validates an encoding.
Instances
Key aggregation
data KeyAggContext Source #
The result of key aggregation, plus any tweaks applied since.
Holds the signers' keys in order, each signer's key aggregation coefficient, the (possibly tweaked) aggregate key \(Q\), and the tweak accumulators \(gacc\) and \(tacc\) of BIP-327.
Instances
| NFData KeyAggContext Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.KeyAgg Methods rnf :: KeyAggContext -> () # | |
keySort :: NonEmpty PubKey -> NonEmpty PubKey Source #
BIP-327 KeySort: sorts keys by their 33-byte encoding.
keyAgg :: NonEmpty PubKey -> Either KeyAggError KeyAggContext Source #
BIP-327 KeyAgg, in \(O(n)\): the key list is hashed once, the second
distinct key is found once, each coefficient takes one hash, and keys with
coefficient \(1\) are added without a multiplication.
aggPubKey :: KeyAggContext -> PubKey Source #
The aggregate key \(Q\), including the tweaks applied so far.
aggXOnlyPubKey :: KeyAggContext -> XOnlyPubKey Source #
The x-only aggregate key: the key the final signature verifies against.
keyAggPubKeys :: KeyAggContext -> NonEmpty PubKey Source #
The signers' public keys, in the order they were aggregated.
signerIndex :: KeyAggContext -> PubKey -> Maybe Int Source #
The index of a public key among the signers (its first position if it appears more than once).
Tweaks
Instances
| NFData Tweak Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Types | |
| Show Tweak Source # | |
| Eq Tweak Source # | |
| Ord Tweak Source # | |
| Encode Tweak Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Types Methods encode :: Tweak -> ByteString Source # decode :: ByteString -> Either DecodeError Tweak Source # | |
applyPlainTweak :: Tweak -> KeyAggContext -> Either KeyAggError KeyAggContext Source #
BIP-327 ApplyTweak with a plain tweak: \(Q' = Q + t \cdot G\). Use it
for BIP-32 derivation from the aggregate key.
applyXOnlyTweak :: Tweak -> KeyAggContext -> Either KeyAggError KeyAggContext Source #
BIP-327 ApplyTweak with an x-only tweak: \(Q' = g \cdot Q + t \cdot G\)
where \(g = -1\) if \(Q\) has odd \(y\).
applyTaprootTweak :: Maybe ByteString -> KeyAggContext -> Either KeyAggError KeyAggContext Source #
The BIP-341 Taproot tweak: an x-only tweak by
\(t = hash_{TapTweak}(xbytes(Q) \| merkle\_root)\) (no merkle root for Nothing).
Nonces
A secret nonce: two secret scalars \(0 < k_1, k_2 < n\), bound to the signer's public key (and, optionally, to an aggregate key and a message), with the matching public nonce.
The scalars live in a pinned buffer that can be read once: signing (or
exporting) the nonce marks it used and zero-fills the buffer. Copies of a
tSecNonce share that buffer, so they are used up together.
Deliberately has no Show, Eq, Ord, Encode or other instance that
could copy, compare or leak it.
A signer's public nonce \((R_1, R_2)\): two finite points.
Instances
| NFData PubNonce Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Types | |
| Show PubNonce Source # | |
| Eq PubNonce Source # | |
| Ord PubNonce Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Types | |
| Encode PubNonce Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Types Methods encode :: PubNonce -> ByteString Source # decode :: ByteString -> Either DecodeError PubNonce Source # | |
An aggregate nonce \((R_1, R_2)\); either point may be infinity.
Eq, Ord and Show use the 66-byte encoding (infinity as 33 zero bytes).
Instances
| NFData AggNonce Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Types | |
| Show AggNonce Source # | |
| Eq AggNonce Source # | |
| Ord AggNonce Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Types | |
| Encode AggNonce Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Types Methods encode :: AggNonce -> ByteString Source # decode :: ByteString -> Either DecodeError AggNonce Source # | |
data NonceInputs Source #
The optional inputs of BIP-327 NonceGen. Each one that is given is
hashed into the nonce, as extra protection should the random number
generator fail.
Constructors
| NonceInputs | |
Fields
| |
noNonceInputs :: NonceInputs Source #
No optional inputs: the nonce depends only on fresh randomness and the public key.
nonceGen :: PubKey -> NonceInputs -> IO (Either NonceGenError (SecNonce, PubNonce)) Source #
BIP-327 NonceGen with fresh randomness from the operating system
(getrandom on Linux, via the entropy package).
nonceAgg :: NonEmpty PubNonce -> AggNonce Source #
BIP-327 NonceAgg: sums the first and the second points. Either sum may be infinity.
Signing
A signing session: a key aggregation context, an aggregate nonce and a message, with the BIP-327 session values computed once.
newSession :: KeyAggContext -> AggNonce -> ByteString -> Session Source #
Starts a signing session (BIP-327 GetSessionValues): computes \(b\),
\(R = R_1 + b \cdot R_2\) (or \(G\) if that is infinity) and \(e\).
sessionKeyAgg :: Session -> KeyAggContext Source #
The key aggregation context of a session.
data PartialSignature Source #
Instances
sign :: SecNonce -> SecKey -> Session -> IO (Either SignError PartialSignature) Source #
BIP-327 Sign, followed by PartialSigVerifyInternal on the result as
the BIP recommends.
Consumes the secret nonce first, as BIP-327 and libsecp256k1 do: the nonce
is atomically marked used and its buffer zero-filled before any check, so
every call after the first, through any copy of the SecNonce and from any
thread, returns SecNonceAlreadyUsed, and a failed call uses the nonce up
too. Then, in order: SecNonceKeyMismatch, SecNonceSessionMismatch (if
the nonce was generated with an aggregate key or a message, they must be the
session's), SignerNotInSession, and SelfVerificationFailed.
Arguments
| :: SecKey | The signer's secret key. |
| -> AggNonce |
|
| -> KeyAggContext | The key aggregation context, with all tweaks applied. |
| -> ByteString | The message. |
| -> Maybe ByteString | Optional auxiliary randomness: 32 bytes. |
| -> Either SignError (PubNonce, PartialSignature) |
BIP-327 DeterministicSign: signing without a random nonce, for the
signer who contributes its nonce last.
Derives the nonce from the secret key, the other signers' aggregate nonce
aggothernonce (the nonceAgg of all other
signers' public nonces), the (tweaked) aggregate key of the context and the
message, and optionally 32 bytes of auxiliary randomness. Returns this
signer's public nonce, to send with the partial signature, and the partial
signature for the session whose aggregate nonce combines the two.
Safe without randomness only if every other signer's public nonce is fixed before this one is revealed: call it only after receiving all other public nonces, never before. The secret nonce never leaves this function, and the same inputs always give the same output.
Fails with InvalidAuxRandLength, DeterministicNonceIsZero (negligible
probability), AggOtherNonceAtInfinity, SignerNotInSession or
SelfVerificationFailed.
partialSigVerify :: Session -> PubKey -> PubNonce -> PartialSignature -> Bool Source #
BIP-327 PartialSigVerify for one signer of the session: False if the
public key is not one of the session's keys.
Takes no hashing: the session caches \(b\), \(e\) and the coefficients.
partialSigAgg :: Session -> NonEmpty PartialSignature -> Signature Source #
BIP-327 PartialSigAgg: \(s = \sum s_i + e \cdot g \cdot tacc\) with
\(g\) from the parity of \(Q\).
Does not check the partial signatures: verify each one with
partialSigVerify first, or the result may not be a valid signature.
A 64-byte BIP-340 Schnorr signature R.x || s with \(R.x < p\) and
\(s < n\).
Instances
| NFData Signature Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Types | |
| Show Signature Source # | |
| Eq Signature Source # | |
| Ord Signature Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Types | |
| Encode Signature Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Types Methods encode :: Signature -> ByteString Source # decode :: ByteString -> Either DecodeError Signature Source # | |
verify :: XOnlyPubKey -> ByteString -> Signature -> Bool Source #
BIP-340 verification of a Schnorr signature.
Errors
data DecodeError Source #
Why a byte string (or a ppad-secp256k1 point) is not a valid value of the requested type.
Constructors
| InvalidLength | The input has the wrong length. |
Fields
| |
| InvalidPoint | Not the encoding of a point on the curve: unknown prefix byte, an
x-coordinate that is not below the field size or not on the curve, or
(for |
| PointAtInfinity | The point at infinity where a finite point is required. |
| ScalarOutOfRange | A scalar that is not below the group order \(n\). |
| ScalarZero | A scalar that must be non-zero (a secret key or nonce) is zero. |
Instances
| NFData DecodeError Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Error Methods rnf :: DecodeError -> () # | |
| Exception DecodeError Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Error Methods toException :: DecodeError -> SomeException # fromException :: SomeException -> Maybe DecodeError # displayException :: DecodeError -> String # backtraceDesired :: DecodeError -> Bool # | |
| Show DecodeError Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Error Methods showsPrec :: Int -> DecodeError -> ShowS # show :: DecodeError -> String # showList :: [DecodeError] -> ShowS # | |
| Eq DecodeError Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Error | |
data KeyAggError Source #
Key aggregation and tweaking failures.
Constructors
| TooManyPublicKeys | More than \(2^{32} - 1\) public keys. |
| AggPubKeyAtInfinity | The aggregate public key is the point at infinity (the keys cancel out). |
| TweakResultAtInfinity | Applying a tweak gave the point at infinity. |
| TaprootTweakOutOfRange | The BIP-341 Taproot tweak hash is not below the group order (negligible probability). |
| InvalidMerkleRootLength !Int | The Taproot merkle root is not 32 bytes; carries the actual length. |
Instances
| NFData KeyAggError Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Error Methods rnf :: KeyAggError -> () # | |
| Exception KeyAggError Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Error Methods toException :: KeyAggError -> SomeException # fromException :: SomeException -> Maybe KeyAggError # displayException :: KeyAggError -> String # backtraceDesired :: KeyAggError -> Bool # | |
| Show KeyAggError Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Error Methods showsPrec :: Int -> KeyAggError -> ShowS # show :: KeyAggError -> String # showList :: [KeyAggError] -> ShowS # | |
| Eq KeyAggError Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Error | |
data NonceGenError Source #
Nonce generation failures. nonceGen
fails only for invalid inputs; the last two constructors come from the
functions of Crypto.Curve.Secp256k1.MuSig2.Unsafe.
Constructors
| NonceSecKeyMismatch | The optional secret key does not belong to the signer's public key. |
| NonceExtraInputTooLong | The extra input is longer than \(2^{32} - 1\) bytes. |
| NonceMessageTooLong | The message is longer than \(2^{64} - 1\) bytes (BIP-327's limit; a
|
| InvalidRandLength !Int | The random bytes are not 32 bytes long; carries the actual length. |
| NonceIsZero | A derived nonce scalar is zero, so no nonce exists for these inputs.
Happens with negligible probability (a hash would have to be \(0\) or
\(n\)); |
Instances
| NFData NonceGenError Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Error Methods rnf :: NonceGenError -> () # | |
| Exception NonceGenError Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Error Methods toException :: NonceGenError -> SomeException # fromException :: SomeException -> Maybe NonceGenError # displayException :: NonceGenError -> String # backtraceDesired :: NonceGenError -> Bool # | |
| Show NonceGenError Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Error Methods showsPrec :: Int -> NonceGenError -> ShowS # show :: NonceGenError -> String # showList :: [NonceGenError] -> ShowS # | |
| Eq NonceGenError Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Error Methods (==) :: NonceGenError -> NonceGenError -> Bool # (/=) :: NonceGenError -> NonceGenError -> Bool # | |
Signing failures.
sign consumes the secret nonce before any
check, so after any of these errors the nonce is used up: generate a new one
and start again from the first round.
Constructors
| SecNonceAlreadyUsed | The secret nonce was already used, by an earlier |
| SecNonceKeyMismatch | The secret nonce was generated for a different public key than the secret key's. |
| SecNonceSessionMismatch | The secret nonce was generated with an aggregate public key or a
message (in |
| SignerNotInSession | The secret key's public key is not one of the session's public keys. |
| SelfVerificationFailed | The partial signature did not pass verification before being returned (a bug or a fault, e.g. a bit flip). |
| InvalidAuxRandLength !Int |
|
| DeterministicNonceIsZero |
|
| AggOtherNonceAtInfinity |
|
Instances
| NFData SignError Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Error | |
| Exception SignError Source # | |
Defined in Crypto.Curve.Secp256k1.MuSig2.Internal.Error Methods toException :: SignError -> SomeException # fromException :: SomeException -> Maybe SignError # displayException :: SignError -> String # backtraceDesired :: SignError -> Bool # | |
| Show SignError Source # | |
| Eq SignError Source # | |