github.com/cosmos/cosmos-sdk@v0.50.10/types/tx/direct_aux.go (about) 1 package tx 2 3 import ( 4 codectypes "github.com/cosmos/cosmos-sdk/codec/types" 5 cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" 6 sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" 7 "github.com/cosmos/cosmos-sdk/types/tx/signing" 8 ) 9 10 // ValidateBasic performs stateless validation of the sign doc. 11 func (s *SignDocDirectAux) ValidateBasic() error { 12 if len(s.BodyBytes) == 0 { 13 return sdkerrors.ErrInvalidRequest.Wrap("body bytes cannot be empty") 14 } 15 16 if s.PublicKey == nil { 17 return sdkerrors.ErrInvalidPubKey.Wrap("public key cannot be empty") 18 } 19 20 return nil 21 } 22 23 // UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method 24 func (s *SignDocDirectAux) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { 25 return unpacker.UnpackAny(s.PublicKey, new(cryptotypes.PubKey)) 26 } 27 28 // ValidateBasic performs stateless validation of the auxiliary tx. 29 func (a *AuxSignerData) ValidateBasic() error { 30 if a.Address == "" { 31 return sdkerrors.ErrInvalidRequest.Wrapf("address cannot be empty") 32 } 33 34 if a.Mode != signing.SignMode_SIGN_MODE_DIRECT_AUX && a.Mode != signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON { 35 return sdkerrors.ErrInvalidRequest.Wrapf("AuxTxBuilder can only sign with %s or %s", signing.SignMode_SIGN_MODE_DIRECT_AUX, signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON) 36 } 37 38 if len(a.Sig) == 0 { 39 return sdkerrors.ErrNoSignatures.Wrap("signature cannot be empty") 40 } 41 42 return a.GetSignDoc().ValidateBasic() 43 } 44 45 // GetSignaturesV2 gets the SignatureV2 of the aux signer. 46 func (a *AuxSignerData) GetSignatureV2() (signing.SignatureV2, error) { 47 pk, ok := a.SignDoc.PublicKey.GetCachedValue().(cryptotypes.PubKey) 48 if !ok { 49 return signing.SignatureV2{}, sdkerrors.ErrInvalidType.Wrapf("expected %T, got %T", (cryptotypes.PubKey)(nil), pk) 50 } 51 52 return signing.SignatureV2{ 53 PubKey: pk, 54 Data: &signing.SingleSignatureData{ 55 SignMode: a.Mode, 56 Signature: a.Sig, 57 }, 58 Sequence: a.SignDoc.Sequence, 59 }, nil 60 } 61 62 // UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method 63 func (a *AuxSignerData) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { 64 return a.GetSignDoc().UnpackInterfaces(unpacker) 65 }