Skip to content

Commit 32557a5

Browse files
committed
swapserverrpc: add MuSig2SignSweep function
1 parent d3401f8 commit 32557a5

File tree

5 files changed

+476
-180
lines changed

5 files changed

+476
-180
lines changed

server_mock_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/btcsuite/btcd/btcutil"
1010
"github.com/btcsuite/btcd/chaincfg"
1111
"github.com/lightninglabs/lndclient"
12+
"github.com/lightninglabs/loop/loopdb"
1213
"github.com/lightninglabs/loop/test"
1314
"github.com/lightningnetwork/lnd/channeldb"
1415
"github.com/lightningnetwork/lnd/lntypes"
@@ -253,3 +254,9 @@ func (s *serverMock) ReportRoutingResult(_ context.Context, _ lntypes.Hash,
253254

254255
return nil
255256
}
257+
258+
func (s *serverMock) MuSig2SignSweep(_ context.Context, _ loopdb.ProtocolVersion,
259+
_ lntypes.Hash, _ [32]byte, _ []byte, _ []byte) ([]byte, []byte, error) {
260+
261+
return nil, nil, nil
262+
}

swap_server_client.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ type swapServerClient interface {
121121
swapHash lntypes.Hash, paymentAddr [32]byte,
122122
plugin RoutingPluginType, success bool, attempts int32,
123123
totalTime int64) error
124+
125+
// MuSig2SignSweep calls the server to cooperatively sign the MuSig2
126+
// htlc spend. Returns the server's nonce and partial signature.
127+
MuSig2SignSweep(ctx context.Context,
128+
protocolVersion loopdb.ProtocolVersion, swapHash lntypes.Hash,
129+
paymentAddr [32]byte, nonce []byte, sigHash []byte) (
130+
[]byte, []byte, error)
124131
}
125132

126133
type grpcSwapServerClient struct {
@@ -720,6 +727,32 @@ func (s *grpcSwapServerClient) ReportRoutingResult(ctx context.Context,
720727
return err
721728
}
722729

730+
// MuSig2SignSweep calls the server to cooperatively sign the MuSig2 htlc
731+
// spend. Returns the server's nonce and partial signature.
732+
func (s *grpcSwapServerClient) MuSig2SignSweep(ctx context.Context,
733+
protocolVersion loopdb.ProtocolVersion, swapHash lntypes.Hash,
734+
paymentAddr [32]byte, nonce []byte, sigHash []byte) (
735+
[]byte, []byte, error) {
736+
737+
req := &looprpc.MuSig2SignSweepReq{
738+
ProtocolVersion: looprpc.ProtocolVersion(protocolVersion),
739+
SwapHash: swapHash[:],
740+
PaymentAddress: paymentAddr[:],
741+
Nonce: nonce,
742+
SigHash: sigHash,
743+
}
744+
745+
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
746+
defer rpcCancel()
747+
748+
res, err := s.server.MuSig2SignSweep(rpcCtx, req)
749+
if err != nil {
750+
return nil, nil, err
751+
}
752+
753+
return res.Nonce, res.PartialSignature, nil
754+
}
755+
723756
func rpcRouteCancel(details *outCancelDetails) (
724757
*looprpc.CancelLoopOutSwapRequest_RouteCancel, error) {
725758

0 commit comments

Comments
 (0)