diff --git a/input/musig2.go b/input/musig2.go index 4f7d19c08..28a15af73 100644 --- a/input/musig2.go +++ b/input/musig2.go @@ -49,12 +49,13 @@ type MuSig2Signer interface { // already known, they can be submitted as well to reduce the number of // method calls necessary later on. // - // The set of sessionOpts are _optional_ and allow a caller to modify - // the generated sessions. As an example the local nonce might already - // be generated ahead of time. + // The localNonces field is optional. If it is set, then the specified + // nonces will be used instead of generating from scratch. This is + // useful in instances where the nonces are generated ahead of time + // before the set of signers is known. MuSig2CreateSession(MuSig2Version, keychain.KeyLocator, []*btcec.PublicKey, *MuSig2Tweaks, [][musig2.PubNonceSize]byte, - ...musig2.SessionOption) (*MuSig2SessionInfo, error) + *musig2.Nonces) (*MuSig2SessionInfo, error) // MuSig2RegisterNonces registers one or more public nonces of other // signing participants for a session identified by its ID. This method @@ -379,18 +380,18 @@ func combineKeysV040(allSignerPubKeys []*btcec.PublicKey, sortKeys bool, // MuSig2CreateContext creates a new MuSig2 signing context. func MuSig2CreateContext(bipVersion MuSig2Version, privKey *btcec.PrivateKey, allSignerPubKeys []*btcec.PublicKey, tweaks *MuSig2Tweaks, - sessionOpts ...musig2.SessionOption, + localNonces *musig2.Nonces, ) (MuSig2Context, MuSig2Session, error) { switch bipVersion { case MuSig2Version040: return createContextV040( - privKey, allSignerPubKeys, tweaks, sessionOpts..., + privKey, allSignerPubKeys, tweaks, localNonces, ) case MuSig2Version100RC2: return createContextV100RC2( - privKey, allSignerPubKeys, tweaks, sessionOpts..., + privKey, allSignerPubKeys, tweaks, localNonces, ) default: @@ -403,7 +404,7 @@ func MuSig2CreateContext(bipVersion MuSig2Version, privKey *btcec.PrivateKey, // BIP draft version 1.0.0rc2. func createContextV100RC2(privKey *btcec.PrivateKey, allSignerPubKeys []*btcec.PublicKey, tweaks *MuSig2Tweaks, - sessionOpts ...musig2.SessionOption, + localNonces *musig2.Nonces, ) (*musig2.Context, *musig2.Session, error) { // The context keeps track of all signing keys and our local key. @@ -419,6 +420,13 @@ func createContextV100RC2(privKey *btcec.PrivateKey, "context: %v", err) } + var sessionOpts []musig2.SessionOption + if localNonces != nil { + sessionOpts = append( + sessionOpts, musig2.WithPreGeneratedNonce(localNonces), + ) + } + muSigSession, err := muSigContext.NewSession(sessionOpts...) if err != nil { return nil, nil, fmt.Errorf("error creating MuSig2 signing "+ @@ -432,7 +440,7 @@ func createContextV100RC2(privKey *btcec.PrivateKey, // draft version 0.4.0. func createContextV040(privKey *btcec.PrivateKey, allSignerPubKeys []*btcec.PublicKey, tweaks *MuSig2Tweaks, - _ ...musig2.SessionOption, + _ *musig2.Nonces, ) (*musig2v040.Context, *musig2v040.Session, error) { // The context keeps track of all signing keys and our local key. diff --git a/input/musig2_session_manager.go b/input/musig2_session_manager.go index 4b1d412d1..827652cc2 100644 --- a/input/musig2_session_manager.go +++ b/input/musig2_session_manager.go @@ -63,7 +63,7 @@ func NewMusigSessionManager(keyFetcher PrivKeyFetcher) *MusigSessionManager { func (m *MusigSessionManager) MuSig2CreateSession(bipVersion MuSig2Version, keyLoc keychain.KeyLocator, allSignerPubKeys []*btcec.PublicKey, tweaks *MuSig2Tweaks, otherSignerNonces [][musig2.PubNonceSize]byte, - sessionOpts ...musig2.SessionOption) (*MuSig2SessionInfo, error) { + localNonces *musig2.Nonces) (*MuSig2SessionInfo, error) { // We need to derive the private key for signing. In the remote signing // setup, this whole RPC call will be forwarded to the signing @@ -78,7 +78,7 @@ func (m *MusigSessionManager) MuSig2CreateSession(bipVersion MuSig2Version, // Create a signing context and session with the given private key and // list of all known signer public keys. musigContext, musigSession, err := MuSig2CreateContext( - bipVersion, privKey, allSignerPubKeys, tweaks, sessionOpts..., + bipVersion, privKey, allSignerPubKeys, tweaks, localNonces, ) if err != nil { return nil, fmt.Errorf("error creating signing context: %w", diff --git a/lntest/mock/signer.go b/lntest/mock/signer.go index 150611257..1d30204ea 100644 --- a/lntest/mock/signer.go +++ b/lntest/mock/signer.go @@ -57,7 +57,7 @@ func (d *DummySigner) ComputeInputScript(tx *wire.MsgTx, // submitted as well to reduce the number of method calls necessary later on. func (d *DummySigner) MuSig2CreateSession(input.MuSig2Version, keychain.KeyLocator, []*btcec.PublicKey, *input.MuSig2Tweaks, - [][musig2.PubNonceSize]byte, ...musig2.SessionOption, + [][musig2.PubNonceSize]byte, *musig2.Nonces, ) (*input.MuSig2SessionInfo, error) { return nil, nil diff --git a/lnwallet/musig_session.go b/lnwallet/musig_session.go index f850f8cf6..ecc60d07f 100644 --- a/lnwallet/musig_session.go +++ b/lnwallet/musig_session.go @@ -260,7 +260,7 @@ func (m *MusigSession) FinalizeSession(signingNonce musig2.Nonces) error { m.session, err = m.signer.MuSig2CreateSession( input.MuSig2Version100RC2, m.localKey.KeyLocator, m.signerKeys, &tweakDesc, [][musig2.PubNonceSize]byte{remoteNonce.PubNonce}, - musig2.WithPreGeneratedNonce(&localNonce), + &localNonce, ) if err != nil { return err diff --git a/lnwallet/rpcwallet/rpcwallet.go b/lnwallet/rpcwallet/rpcwallet.go index f8201905f..d805ed45b 100644 --- a/lnwallet/rpcwallet/rpcwallet.go +++ b/lnwallet/rpcwallet/rpcwallet.go @@ -657,7 +657,7 @@ func (r *RPCKeyRing) ComputeInputScript(tx *wire.MsgTx, func (r *RPCKeyRing) MuSig2CreateSession(bipVersion input.MuSig2Version, keyLoc keychain.KeyLocator, pubKeys []*btcec.PublicKey, tweaks *input.MuSig2Tweaks, otherNonces [][musig2.PubNonceSize]byte, - _ ...musig2.SessionOption) (*input.MuSig2SessionInfo, error) { + localNonces *musig2.Nonces) (*input.MuSig2SessionInfo, error) { apiVersion, err := signrpc.MarshalMuSig2Version(bipVersion) if err != nil { diff --git a/watchtower/wtmock/signer.go b/watchtower/wtmock/signer.go index 8b8056493..1cf1f5664 100644 --- a/watchtower/wtmock/signer.go +++ b/watchtower/wtmock/signer.go @@ -72,7 +72,7 @@ func (s *MockSigner) ComputeInputScript(tx *wire.MsgTx, func (s *MockSigner) MuSig2CreateSession(input.MuSig2Version, keychain.KeyLocator, []*btcec.PublicKey, *input.MuSig2Tweaks, [][musig2.PubNonceSize]byte, - ...musig2.SessionOption) (*input.MuSig2SessionInfo, error) { + *musig2.Nonces) (*input.MuSig2SessionInfo, error) { return nil, nil }