diff --git a/types/btc_schnorr_sig.go b/types/btc_schnorr_sig.go index 1fe61888e..336cf037b 100644 --- a/types/btc_schnorr_sig.go +++ b/types/btc_schnorr_sig.go @@ -2,6 +2,7 @@ package types import ( "encoding/hex" + "errors" "github.com/btcsuite/btcd/btcec/v2/schnorr" ) @@ -11,8 +12,14 @@ type BIP340Signature []byte const BIP340SignatureLen = schnorr.SignatureSize func NewBIP340Signature(data []byte) (*BIP340Signature, error) { + var sig BIP340Signature err := sig.Unmarshal(data) + + if _, err := sig.ToBTCSig(); err != nil { + return nil, errors.New("bytes cannot be converted to a *schnorr.Signature object") + } + return &sig, err } diff --git a/x/btcstaking/types/msg.go b/x/btcstaking/types/msg.go index 7583a951b..b1d763ff0 100644 --- a/x/btcstaking/types/msg.go +++ b/x/btcstaking/types/msg.go @@ -82,9 +82,7 @@ func (m *MsgCreateBTCDelegation) ValidateBasic() error { return fmt.Errorf("empty delegator signature") } - _, err := m.DelegatorSlashingSig.ToBTCSig() - - if err != nil { + if _, err := m.DelegatorSlashingSig.ToBTCSig(); err != nil { return fmt.Errorf("invalid delegator slashing signature: %w", err) } @@ -128,9 +126,7 @@ func (m *MsgCreateBTCDelegation) ValidateBasic() error { return fmt.Errorf("invalid unbonding slashing tx: %w", err) } - _, err = m.DelegatorUnbondingSlashingSig.ToBTCSig() - - if err != nil { + if _, err := m.DelegatorUnbondingSlashingSig.ToBTCSig(); err != nil { return fmt.Errorf("invalid delegator unbonding slashing signature: %w", err) } @@ -169,9 +165,7 @@ func (m *MsgAddCovenantSigs) ValidateBasic() error { return fmt.Errorf("empty covenant signature") } - _, err := m.UnbondingTxSig.ToBTCSig() - - if err != nil { + if _, err := m.UnbondingTxSig.ToBTCSig(); err != nil { return fmt.Errorf("invalid covenant unbonding signature: %w", err) } @@ -191,9 +185,7 @@ func (m *MsgBTCUndelegate) ValidateBasic() error { return fmt.Errorf("empty signature from the delegator") } - _, err := m.UnbondingTxSig.ToBTCSig() - - if err != nil { + if _, err := m.UnbondingTxSig.ToBTCSig(); err != nil { return fmt.Errorf("invalid delegator unbonding signature: %w", err) }