mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
Merge pull request #495 from sputn1ck/check_p2pk_dest
loopout: reject P2PK addresses
This commit is contained in:
commit
e98d813885
2 changed files with 29 additions and 0 deletions
|
|
@ -55,6 +55,12 @@ var (
|
|||
errBalanceTooLow = errors.New(
|
||||
"channel balance too low for loop out amount",
|
||||
)
|
||||
|
||||
// errInvalidAddress is returned when the destination address is of
|
||||
// an unsupported format such as P2PK or P2TR addresses.
|
||||
errInvalidAddress = errors.New(
|
||||
"invalid or unsupported address",
|
||||
)
|
||||
)
|
||||
|
||||
// swapClientServer implements the grpc service exposed by loopd.
|
||||
|
|
@ -1153,6 +1159,18 @@ func validateLoopOutRequest(ctx context.Context, lnd lndclient.LightningClient,
|
|||
errIncorrectChain, chainParams.Name)
|
||||
}
|
||||
|
||||
// Check that the provided destination address is a supported
|
||||
// address format.
|
||||
switch sweepAddr.(type) {
|
||||
case *btcutil.AddressWitnessScriptHash,
|
||||
*btcutil.AddressWitnessPubKeyHash,
|
||||
*btcutil.AddressScriptHash,
|
||||
*btcutil.AddressPubKeyHash:
|
||||
|
||||
default:
|
||||
return 0, errInvalidAddress
|
||||
}
|
||||
|
||||
// Check that the label is valid.
|
||||
if err := labels.Validate(req.Label); err != nil {
|
||||
return 0, err
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ var (
|
|||
[]byte{123}, &chaincfg.MainNetParams,
|
||||
)
|
||||
|
||||
nodepubkeyAddr, _ = btcutil.DecodeAddress(
|
||||
mock_lnd.NewMockLnd().NodePubkey, &chaincfg.MainNetParams,
|
||||
)
|
||||
|
||||
chanID1 = lnwire.NewShortChanIDFromInt(1)
|
||||
chanID2 = lnwire.NewShortChanIDFromInt(2)
|
||||
chanID3 = lnwire.NewShortChanIDFromInt(3)
|
||||
|
|
@ -445,6 +449,13 @@ func TestValidateLoopOutRequest(t *testing.T) {
|
|||
err: errBalanceTooLow,
|
||||
expectedTarget: 0,
|
||||
},
|
||||
{
|
||||
name: "node pubkey as dest addr",
|
||||
chain: chaincfg.MainNetParams,
|
||||
destAddr: nodepubkeyAddr,
|
||||
err: errInvalidAddress,
|
||||
expectedTarget: 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue