From 8f84bb0e9bcbdc1dfc00c5d35382927a8a6edd8e Mon Sep 17 00:00:00 2001 From: sputn1ck Date: Mon, 10 Jul 2023 16:40:26 +0200 Subject: [PATCH] musig2: fix early nonce gen option Previously the early nonce generation option was not being respected when creating the context, with the WithKnownSigners option being used. This commit fixes that. --- btcec/schnorr/musig2/context.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/btcec/schnorr/musig2/context.go b/btcec/schnorr/musig2/context.go index 44ed69c8ee..7ed759cd0a 100644 --- a/btcec/schnorr/musig2/context.go +++ b/btcec/schnorr/musig2/context.go @@ -234,24 +234,23 @@ func NewContext(signingKey *btcec.PrivateKey, shouldSort bool, opts.keySet = make([]*btcec.PublicKey, 0, opts.numSigners) opts.keySet = append(opts.keySet, pubKey) - // If early nonce generation is specified, then we'll generate - // the nonce now to pass in to the session once all the callers - // are known. - if opts.earlyNonce { - var err error - ctx.sessionNonce, err = GenNonces( - WithPublicKey(ctx.pubKey), - WithNonceSecretKeyAux(signingKey), - ) - if err != nil { - return nil, err - } - } - default: return nil, ErrSignersNotSpecified } + // If early nonce generation is specified, then we'll generate the + // nonce now to pass in to the session once all the callers are known. + if opts.earlyNonce { + var err error + ctx.sessionNonce, err = GenNonces( + WithPublicKey(ctx.pubKey), + WithNonceSecretKeyAux(signingKey), + ) + if err != nil { + return nil, err + } + } + return ctx, nil }