packages feed

musig2 0.3.2 → 0.3.3

raw patch · 13 files changed

+177/−28 lines, 13 filesdep ~deepseqPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: deepseq

API changes (from Hackage documentation)

Files

CHANGELOG view
@@ -1,5 +1,35 @@ # Changelog +## 0.3.3 (2026-11-23)++* Security and memory hygiene:+  - `secNonceFromBytes` now validates the secret scalars before decoding the+    public key, so a 97-byte all-zero wiped nonce fails with `ScalarZero`+    (matching its documentation) instead of `PointAtInfinity`, and copies the+    public-key slice so the imported `SecNonce` does not retain the caller's+    97-byte secret buffer+  - `decode` for `PubKey`, `XOnlyPubKey`, `PubNonce`, `AggNonce` and+    `Signature` now copies its input bytes so decoding a slice of a larger+    `ByteString` does not retain the parent buffer+* Bug fixes:+  - Fix `NFData SigRoundError` to force the `NonEmpty Blame` payload of+    `SigRoundBlame` instead of evaluating only to WHNF+  - Add the missing `NFData NonceInputs` instance so every exported type has+    an `NFData` instance+  - Tighten `pubKeyFromPoint` so invalid projective triples with `Z = 0`+    (such as `(0, 0, 0)` or `(1, 2, 0)`) return `InvalidPoint`, reserving+    `PointAtInfinity` for genuine projective points at infinity `(0 : Y : 0)`+    with `Y /= 0`+  - Use `atomicReadIntArray#` in `OneShot.isClaimed` so concurrent reads+    synchronize properly with `casIntArray#` in `claimOneShot` on weakly+    ordered architectures+* Tests:+  - Accept the optional `"comment"` field on valid `key_agg_vectors.json`+    test cases in `OfficialVectors`, matching upstream BIP-327 vector parsers+  - Add regression tests for `secNonceFromBytes` validation order and buffer+    detachment, `NFData NonceInputs`, `NFData SigRoundError`, `Z = 0`+    projective triples in `pubKeyFromPoint`, and `Encode` slice detachment+ ## 0.3.2 (2026-11-13)  * Dependencies:
README.md view
@@ -178,8 +178,8 @@ before anything else, so a second `sign` with the same nonce, from any copy or thread, fails with `SecNonceAlreadyUsed`. The `Crypto.Curve.Secp256k1.MuSig2.Unsafe` module holds the escape hatches this-cannot cover (caller-supplied randomness, counters, exporting secret nonces).-Arithmetic on secret keys and nonces is constant-time (fixed-width+cannot cover (caller-supplied randomness, counters, exporting and importing+secret nonces). Arithmetic on secret keys and nonces is constant-time (fixed-width Montgomery arithmetic from `ppad-fixed`); the module documentation lists the remaining caveats. 
internal/Crypto/Curve/Secp256k1/MuSig2/Internal/Nonce.hs view
@@ -171,9 +171,10 @@  where   parts = do     expectLength 97 b-    pk <- decode (BS.drop 64 b)     k1 <- secScalarFromBytes (BS.take 32 b)     k2 <- secScalarFromBytes (BS.take 32 (BS.drop 32 b))+    -- Copy so snPubKey does not retain the 97-byte input buffer holding k1 || k2.+    pk <- decode (BS.copy (BS.drop 64 b))     Right (k1, k2, pk)  {- | Consumes the nonce and returns its 97-byte BIP-327 encoding; 'Nothing' if@@ -206,6 +207,9 @@   -- ^ Any other data, e.g. a session identifier or a counter.   } +instance NFData NonceInputs where+  rnf (NonceInputs sk apk m extra) = rnf sk `seq` rnf apk `seq` rnf m `seq` rnf extra+ -- | No optional inputs: the nonce depends only on fresh randomness and the public key. noNonceInputs :: NonceInputs noNonceInputs = NonceInputs Nothing Nothing Nothing Nothing@@ -231,7 +235,7 @@     rand <- getEntropy 32     let (k1, k2) = nonceGenScalars rand pk inputs     case pubNonceFromScalars k1 k2 of-      -- k1 = 0 or k2 = 0: probability ~2^-127, draw again.+      -- k1 = 0 or k2 = 0: probability ~2^-254, draw again.       Nothing -> loop       Just pn -> do         sn <- newSecNonce k1 k2 pk pn (nonceAggPubKey inputs) (nonceMessage inputs)
internal/Crypto/Curve/Secp256k1/MuSig2/Internal/OneShot.hs view
@@ -41,12 +41,12 @@   MutableByteArray#,   Ptr (..),   RealWorld,+  atomicReadIntArray#,   casIntArray#,   copyAddrToByteArray#,   copyMutableByteArrayToAddr#,   isTrue#,   newAlignedPinnedByteArray#,-  readIntArray#,   setByteArray#,   touch#,   writeIntArray#,@@ -103,7 +103,7 @@  -- | Whether the buffer has been claimed. isClaimed :: OneShot -> IO Bool-isClaimed (OneShot _ mba) = IO $ \s0 -> case readIntArray# mba 0# s0 of+isClaimed (OneShot _ mba) = IO $ \s0 -> case atomicReadIntArray# mba 0# s0 of   (# s1, st #) -> (# s1, isTrue# (st ==# 1#) #)  {- | The current contents of the secret area, without claiming it (all zero
internal/Crypto/Curve/Secp256k1/MuSig2/Internal/Point.hs view
@@ -28,20 +28,26 @@   sumPoints, ) where -import Crypto.Curve.Secp256k1 (Context, Projective, add, mul_vartime, mul_wnaf, precompute, serialize_point, valid, _CURVE_ZERO)+import Crypto.Curve.Secp256k1 (Context, Projective (..), add, mul_vartime, mul_wnaf, precompute, serialize_point, valid, _CURVE_ZERO) import Crypto.Curve.Secp256k1.MuSig2.Internal.Scalar (SecScalar, modQ, secScalarWider) import Data.ByteString (ByteString) import qualified Data.ByteString as BS import qualified Data.ByteString.Unsafe as BU import Data.Maybe (fromMaybe)+import qualified Numeric.Montgomery.Secp256k1.Curve as C --- | Whether a point is the point at infinity.+{- | Whether a point is the point at infinity: projective coordinates+@(0 : Y : 0)@ with \(Y \neq 0\).++Unlike @p == _CURVE_ZERO@ (which checks only \(Z = 0\)), this rejects invalid+\(Z = 0\) triples such as @(0, 0, 0)@ and @(1, 2, 0)@.+-} isInfinity :: Projective -> Bool-isInfinity p = p == _CURVE_ZERO+isInfinity (Projective x y z) = C.eq_vartime z C.zero && C.eq_vartime x C.zero && not (C.eq_vartime y C.zero) --- | A finite point on the curve (ppad's 'Projective' constructor is exported, so values may be anything).+-- | A finite point on the curve (ppad's v'Projective' constructor is exported, so values may be anything). isValidPoint :: Projective -> Bool-isValidPoint p = not (isInfinity p) && valid p+isValidPoint p@(Projective _ _ z) = not (C.eq_vartime z C.zero) && valid p  {- | @cbytes@: 33-byte compressed encoding of a finite point. 
internal/Crypto/Curve/Secp256k1/MuSig2/Internal/Types.hs view
@@ -56,6 +56,7 @@ ) where  import Control.DeepSeq (NFData (..))+import Control.Monad (void, when) import Crypto.Curve.Secp256k1 (Projective, neg, parse_point, _CURVE_ZERO) import Crypto.Curve.Secp256k1.MuSig2.Internal.Error (DecodeError (..)) import Crypto.Curve.Secp256k1.MuSig2.Internal.Point (cbytes, cbytesExt, hasEvenYBytes, infinityBytes, isInfinity, isValidPoint, mulGSecret)@@ -70,7 +71,8 @@  @'decode' . 'encode' = 'Right'@, and 'decode' accepts exactly the canonical encodings: it rejects wrong lengths, invalid points and out-of-range scalars.-Secrets have no instance.+'decode' copies its input bytes so decoding a slice does not retain a larger+parent buffer. Secrets have no instance. -} class Encode a where   -- | The canonical encoding.@@ -153,7 +155,9 @@  instance Encode PubKey where   encode = pubKeyBytes-  decode b = (`PubKey` b) <$> decodeCPoint b+  decode b = do+    p <- decodeCPoint b+    Right $! PubKey p (BS.copy b)  -- | A t'PubKey' from a point already known to be finite and on the curve. mkPubKey :: Projective -> PubKey@@ -200,7 +204,7 @@     expectLength 32 b     -- 'parse_point' lifts 32 bytes as a BIP-340 key: x < p, on the curve, even y.     p <- maybe (Left InvalidPoint) Right (parse_point b)-    Right (XOnlyPubKey p b)+    Right $! XOnlyPubKey p (BS.copy b)  -- | The x-only key of a public key (negated to even y if needed). pubKeyXOnly :: PubKey -> XOnlyPubKey@@ -306,7 +310,7 @@     expectLength 66 b     r1 <- decodeCPoint (BS.take 33 b)     r2 <- decodeCPoint (BS.drop 33 b)-    Right (PubNonce r1 r2 b)+    Right $! PubNonce r1 r2 (BS.copy b)  -- | A t'PubNonce' from two points already known to be finite and on the curve. mkPubNonce :: Projective -> Projective -> PubNonce@@ -343,7 +347,7 @@     expectLength 66 b     r1 <- decodeCPointExt (BS.take 33 b)     r2 <- decodeCPointExt (BS.drop 33 b)-    Right (AggNonce r1 r2 b)+    Right $! AggNonce r1 r2 (BS.copy b)  -- | An t'AggNonce' from two points on the curve (or infinity). mkAggNonce :: Projective -> Projective -> AggNonce@@ -392,6 +396,6 @@   encode = signatureBytes   decode b = do     expectLength 64 b-    if bytesToInteger (BS.take 32 b) >= fieldSize-      then Left InvalidPoint-      else Signature b <$ decodeScalar (BS.drop 32 b)+    when (bytesToInteger (BS.take 32 b) >= fieldSize) (Left InvalidPoint)+    void (decodeScalar (BS.drop 32 b))+    Right $! Signature (BS.copy b)
lib/Crypto/Curve/Secp256k1/MuSig2/Coordinator.hs view
@@ -389,7 +389,8 @@ instance Exception SigRoundError  instance NFData SigRoundError where-  rnf = rwhnf+  rnf (SigRoundBlame bs) = rnf bs+  rnf FinalSignatureInvalid = ()  {- | Ends round two: aggregates the partial signatures (BIP-327 @PartialSigAgg@) and checks the result with 'verify' against the session's
lib/Crypto/Curve/Secp256k1/MuSig2/Unsafe.hs view
@@ -126,7 +126,8 @@ one-shot t'SecNonce'. Checks that both scalars are in \([1, n)\) (a nonce zeroed by another BIP-327 implementation after use is rejected with 'Crypto.Curve.Secp256k1.MuSig2.ScalarZero') and that the public key is a-valid encoding.+valid encoding. Copies the public key out of the input bytes so the imported+nonce does not retain the caller's secret buffer.  __Each encoding must be imported at most once__: the library cannot know that two imports are the same nonce. See the module documentation.
musig2.cabal view
@@ -1,6 +1,6 @@ cabal-version:      3.0 name:               musig2-version:            0.3.2+version:            0.3.3 synopsis:           MuSig2 library license:            MIT license-file:       LICENSE@@ -127,6 +127,7 @@     , base               >=4.20 && <5     , base16-bytestring     , bytestring+    , deepseq     , directory     , filepath     , musig2:internal
test/CoordinatorRounds.hs view
@@ -7,6 +7,7 @@ -} module CoordinatorRounds (testCoordinator) where +import Control.Exception (ErrorCall (..), fromException) import Control.Monad (foldM, forM) import Crypto.Curve.Secp256k1.MuSig2 import Crypto.Curve.Secp256k1.MuSig2.Coordinator@@ -20,6 +21,7 @@ import Data.List.NonEmpty (NonEmpty (..)) import qualified Data.List.NonEmpty as NE import Generators (TweakOp, applyTweakOp, genMessage, genNonZeroScalar, genTweakOp)+import qualified Test.QuickCheck as QC import Test.Tasty import Test.Tasty.HUnit import Test.Tasty.QuickCheck@@ -48,6 +50,7 @@         , testCase "an index outside the key list is an unknown signer" sigRoundUnknown         , testCase "finishing blames every signer whose partial signature is missing" sigRoundMissingBlame         , testCase "the coordinator can sign in sigRoundSession" sigRoundCoordinatorSigns+        , testCase "NFData SigRoundError forces all blames in SigRoundBlame" sigRoundErrorNFData         ]     , testGroup         "properties"@@ -243,6 +246,31 @@   psigs <- forM (zip (NE.toList (fxSecKeys fixture)) ns) $ \(sk, (sn, _)) -> unsafeRight <$> sign sn sk (sigRoundSession sr0)   sr <- either (assertFailure . show) pure (foldM (\r (i, psig) -> receivePartialSig i (encode psig) r) sr0 (zip [0 ..] psigs))   assertBool "signature" (either (const False) (verify (aggXOnlyPubKey (fxCtx fixture)) (fxMsg fixture)) (finishSigRound sr))++sigRoundErrorNFData :: Assertion+sigRoundErrorNFData = do+  -- QuickCheck's 'total' invokes 'Control.DeepSeq.rnf' without needing a direct+  -- deepseq dependency in the test suite.+  assertEvaluates FinalSignatureInvalid+  assertEvaluates (SigRoundBlame (Blame 0 MissingContribution :| []))+  assertThrowsError "head" (SigRoundBlame (error "head" :| []))+  assertThrowsError "tail" (SigRoundBlame (Blame 0 MissingContribution :| error "tail"))+  assertThrowsError "elem" (SigRoundBlame (Blame 0 MissingContribution :| [error "elem"]))+ where+  eval :: SigRoundError -> IO QC.Result+  eval = QC.quickCheckWithResult QC.stdArgs{QC.chatty = False, QC.maxSuccess = 1} . QC.total+  assertEvaluates :: SigRoundError -> Assertion+  assertEvaluates x = do+    res <- eval x+    assertBool (show res) (QC.isSuccess res)+  assertThrowsError :: String -> SigRoundError -> Assertion+  assertThrowsError expected x = do+    res <- eval x+    case res of+      QC.Failure{QC.theException = Just ex} -> case fromException ex of+        Just (ErrorCall msg) -> msg @?= expected+        Nothing -> assertFailure ("expected ErrorCall, got: " <> show ex)+      _ -> assertFailure ("expected ErrorCall " <> show expected <> ", got: " <> show res)  -- Properties ------------------------------------------------------------------- 
test/Encoding.hs view
@@ -26,10 +26,13 @@   secKeyToBytes,  ) import Crypto.Curve.Secp256k1.MuSig2.Internal.Scalar (curveOrder, fieldSize, integerToBytes32)-import Crypto.Curve.Secp256k1.MuSig2.Internal.Types (Signature (..))+import Crypto.Curve.Secp256k1.MuSig2.Internal.Types (Signature (..), mkAggNonce, mkPubNonce) import Data.ByteString (ByteString) import qualified Data.ByteString as BS+import qualified Data.ByteString.Internal as BI import Data.Proxy (Proxy (..))+import Foreign.ForeignPtr (withForeignPtr)+import Foreign.Ptr (plusPtr) import Generators import Test.Tasty import Test.Tasty.HUnit@@ -95,6 +98,10 @@                   .&&. decodeAs @AggNonce (BS.take 33 (encode pn) <> bad) === Left InvalidPoint         , testCase "pubKeyFromPoint: infinity and points off the curve" $ do             pubKeyFromPoint _CURVE_ZERO @?= Left PointAtInfinity+            pubKeyFromPoint (Projective 0 2 0) @?= Left PointAtInfinity+            pubKeyFromPoint (Projective 0 0 0) @?= Left InvalidPoint+            pubKeyFromPoint (Projective 1 0 0) @?= Left InvalidPoint+            pubKeyFromPoint (Projective 1 2 0) @?= Left InvalidPoint             pubKeyFromPoint (Projective 1 1 1) @?= Left InvalidPoint             fmap encode (pubKeyFromPoint _CURVE_G) @?= Right (encode (secKeyPubKey (unsafeSecKey 1)))         ]@@ -115,6 +122,14 @@         , testCase "SecKey: zero" $             either Just (const Nothing) (secKeyFromBytes (BS.replicate 32 0)) @?= Just ScalarZero         ]+    , testGroup+        "slice detachment"+        [ decodedCopiesSlice "PubKey" (secKeyPubKey (unsafeSecKey 1))+        , decodedCopiesSlice "XOnlyPubKey" (pubKeyXOnly (secKeyPubKey (unsafeSecKey 1)))+        , decodedCopiesSlice "PubNonce" (mkPubNonce _CURVE_G (pubKeyPoint (secKeyPubKey (unsafeSecKey 2))))+        , decodedCopiesSlice "AggNonce" (mkAggNonce _CURVE_G _CURVE_ZERO)+        , decodedCopiesSlice "Signature" (Signature (integerToBytes32 1 <> integerToBytes32 2))+        ]     ]  where   unsafeSecKey d = either (error . show) id (secKeyFromBytes (integerToBytes32 d))@@ -139,3 +154,19 @@ wrongLength :: forall a. (Encode a, Show a, Eq a) => Proxy a -> Int -> TestTree wrongLength _ n = testProperty ("length /= " <> show n) . forAll (lengthOtherThan n) $ \b ->   (decode b :: Either DecodeError a) === Left (InvalidLength n (BS.length b))++decodedCopiesSlice :: forall a. (Encode a, Eq a, Show a) => String -> a -> TestTree+decodedCopiesSlice name val = testCase name $ do+  let raw = encode val+      pad = BS.replicate 100 0xAA+      bigBuf = pad <> raw <> pad+      slice = BS.take (BS.length raw) (BS.drop 100 bigBuf)+  decoded <- either (assertFailure . show) pure (decodeAs @a slice)+  decoded @?= val+  let BI.BS fpBig lenBig = bigBuf+      BI.BS fpSlice _ = slice+      BI.BS fpOut _ = encode decoded+  assertBool "decoded value retains slice ForeignPtr" (fpOut /= fpSlice)+  withForeignPtr fpBig $ \pBig ->+    withForeignPtr fpOut $ \pOut ->+      assertBool "decoded value points inside parent buffer" (pOut < pBig || pOut >= plusPtr pBig lenBig)
test/NonceSafety.hs view
@@ -7,17 +7,22 @@  import Control.Concurrent (forkIO, getNumCapabilities) import Control.Concurrent.MVar (newEmptyMVar, putMVar, readMVar, takeMVar)+import Control.DeepSeq (rnf)+import Control.Exception (ErrorCall, evaluate, try) import Control.Monad (forM_, replicateM, void) import Crypto.Curve.Secp256k1.MuSig2-import Crypto.Curve.Secp256k1.MuSig2.Internal.Nonce (peekSecNonce, secNonceIsUsed, secNoncePubNonce)+import Crypto.Curve.Secp256k1.MuSig2.Internal.Nonce (peekSecNonce, secNonceIsUsed, secNoncePubKey, secNoncePubNonce) import Crypto.Curve.Secp256k1.MuSig2.Unsafe import Data.ByteString (ByteString) import qualified Data.ByteString as BS-import Data.Either (lefts, rights)+import qualified Data.ByteString.Internal as BI+import Data.Either (isLeft, lefts, rights) import Data.IORef (newIORef, readIORef) import Data.List.NonEmpty (NonEmpty (..)) import Data.Maybe (isJust) import Data.Word (Word64)+import Foreign.ForeignPtr (withForeignPtr)+import Foreign.Ptr (plusPtr) import Test.Tasty import Test.Tasty.HUnit import Util (failsWith, pubNonceFromInts, secKeyFromInt, unsafeRight)@@ -39,12 +44,14 @@         [ testCase "a nonce bound to an aggregate key refuses other sessions" bindAggPubKey         , testCase "a nonce bound to a message refuses other messages" bindMessage         , testCase "a nonce bound to the session's key and message signs" bindMatches+        , testCase "NonceInputs NFData forces all fields" nonceInputsNFData         ]     , testGroup         "Unsafe"         [ testCase "secNonceToBytes consumes the nonce" exportConsumes         , testCase "secNonceFromBytes . secNonceToBytes signs like the original" exportImport         , testCase "secNonceFromBytes validates its input" importValidates+        , testCase "secNonceFromBytes copies the public key out of the 97-byte secret buffer" importCopiesPubKey         , testCase "nonceGenWithRand rejects random bytes that are not 32 long" randLength         , testCase "nonceGenWithRand is deterministic and each result is a fresh nonce" withRandFresh         , testCase "nonceGenCounter is NonceGen with bytes(8, counter) || 0^24 and the secret key" counterIsNonceGen@@ -200,6 +207,27 @@   psig <- sign sn sk1 ses >>= either (assertFailure . show) pure   assertBool "partialSigVerify" (partialSigVerify ses pk1 pn psig) +nonceInputsNFData :: Assertion+nonceInputsNFData = do+  rnf noNonceInputs @?= ()+  let full =+        NonceInputs+          { nonceSecKey = Just sk1+          , nonceAggPubKey = Just (aggXOnlyPubKey ctx12)+          , nonceMessage = Just msgA+          , nonceExtraInput = Just "extra"+          }+  rnf full @?= ()+  expectError noNonceInputs{nonceSecKey = Just (error "boom")}+  expectError noNonceInputs{nonceAggPubKey = Just (error "boom")}+  expectError noNonceInputs{nonceMessage = Just (error "boom")}+  expectError noNonceInputs{nonceExtraInput = Just (error "boom")}+ where+  expectError :: NonceInputs -> Assertion+  expectError inputs = do+    result <- try (evaluate (rnf inputs)) :: IO (Either ErrorCall ())+    assertBool "expected rnf to force bottom field" (isLeft result)+ -- Unsafe --------------------------------------------------------------------------  exportConsumes :: Assertion@@ -234,10 +262,23 @@   bytes <- secNonceToBytes sn >>= maybe (assertFailure "export failed") pure   let err b = failure <$> secNonceFromBytes b   err (BS.take 96 bytes) >>= (@?= Just (InvalidLength 97 96))+  err (BS.replicate 97 0) >>= (@?= Just ScalarZero)   err (BS.replicate 32 0 <> BS.drop 32 bytes) >>= (@?= Just ScalarZero)+  err (BS.take 32 bytes <> BS.replicate 32 0 <> BS.drop 64 bytes) >>= (@?= Just ScalarZero)   err (BS.take 32 bytes <> BS.replicate 32 0xFF <> BS.drop 64 bytes) >>= (@?= Just ScalarOutOfRange)   err (BS.take 64 bytes <> BS.replicate 33 0) >>= (@?= Just PointAtInfinity)   err (BS.take 64 bytes <> BS.cons 0x04 (BS.drop 65 bytes)) >>= (@?= Just InvalidPoint)++importCopiesPubKey :: Assertion+importCopiesPubKey = do+  (sn, _) <- setup noNonceInputs ctx12 msgA+  raw <- secNonceToBytes sn >>= maybe (assertFailure "export failed") pure+  imported <- secNonceFromBytes raw >>= either (assertFailure . show) pure+  let BI.BS rawFp rawLen = raw+      BI.BS pkFp _ = encode (secNoncePubKey imported)+  withForeignPtr rawFp $ \rawPtr ->+    withForeignPtr pkFp $ \pkPtr ->+      assertBool "snPubKey does not share the 97-byte input buffer" (pkPtr < rawPtr || pkPtr >= rawPtr `plusPtr` rawLen)  randLength :: Assertion randLength = do
test/OfficialVectors.hs view
@@ -197,7 +197,7 @@ data KeyAggVectors = KeyAggVectors   { kaPubkeys :: [ByteString]   , kaTweaks :: [ByteString]-  , kaValid :: [([Int], ByteString)]+  , kaValid :: [([Int], ByteString, Maybe String)]   , kaError :: [KeyAggErrorCase]   } @@ -213,7 +213,9 @@ parseKeyAgg = strictObject "key_agg" ["pubkeys", "tweaks", "valid_test_cases", "error_test_cases"] $ \o -> do   pubkeys <- hexList o "pubkeys"   tweaks <- hexList o "tweaks"-  valid <- o .: "valid_test_cases" >>= traverse (strictObject "key_agg valid case" ["key_indices", "expected"] (\c -> (,) <$> c .: "key_indices" <*> hexField c "expected"))+  valid <-+    o .: "valid_test_cases"+      >>= traverse (strictObject "key_agg valid case" ["key_indices", "expected", "comment"] (\c -> (,,) <$> c .: "key_indices" <*> hexField c "expected" <*> c .:? "comment"))   errs <-     o .: "error_test_cases"       >>= traverse@@ -671,7 +673,7 @@ keyAggTests :: KeyAggVectors -> [TestTree] keyAggTests v = zipWith validCase [0 ..] (kaValid v) <> zipWith errorCase [0 ..] (kaError v)  where-  validCase i (keyIdxs, expected) = testCase (caseName "valid" i Nothing) $ do+  validCase i (keyIdxs, expected, comment) = testCase (caseName "valid" i comment) $ do     keys <- expectRight "vector" (select "pubkey" (kaPubkeys v) keyIdxs)     ctx <- expectLib "KeyAgg" (keyAggBytes keys [])     assertBytes "xbytes(Q)" expected (encode (aggXOnlyPubKey ctx))