@@ -79,6 +79,11 @@ func isValidEIP712Payload(typedData apitypes.TypedData) bool {
7979// decodeAminoSignDoc attempts to decode the provided sign doc (bytes) as an Amino payload
8080// and returns a signable EIP-712 TypedData object.
8181func decodeAminoSignDoc (signDocBytes []byte ) (apitypes.TypedData , error ) {
82+ // Ensure codecs have been initialized
83+ if err := validateCodecInit (); err != nil {
84+ return apitypes.TypedData {}, err
85+ }
86+
8287 var aminoDoc legacytx.StdSignDoc
8388 if err := aminoCodec .UnmarshalJSON (signDocBytes , & aminoDoc ); err != nil {
8489 return apitypes.TypedData {}, err
@@ -134,6 +139,11 @@ func decodeAminoSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
134139// decodeProtobufSignDoc attempts to decode the provided sign doc (bytes) as a Protobuf payload
135140// and returns a signable EIP-712 TypedData object.
136141func decodeProtobufSignDoc (signDocBytes []byte ) (apitypes.TypedData , error ) {
142+ // Ensure codecs have been initialized
143+ if err := validateCodecInit (); err != nil {
144+ return apitypes.TypedData {}, err
145+ }
146+
137147 signDoc := & txTypes.SignDoc {}
138148 if err := signDoc .Unmarshal (signDocBytes ); err != nil {
139149 return apitypes.TypedData {}, err
@@ -220,6 +230,16 @@ func decodeProtobufSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
220230 return typedData , nil
221231}
222232
233+ // validateCodecInit ensures that both Amino and Protobuf encoding codecs have been set on app init,
234+ // so the module does not panic if either codec is not found.
235+ func validateCodecInit () error {
236+ if aminoCodec == nil || protoCodec == nil {
237+ return errors .New ("missing codec: codecs have not been properly initialized using SetEncodingConfig" )
238+ }
239+
240+ return nil
241+ }
242+
223243// validatePayloadMessages ensures that the transaction messages can be represented in an EIP-712
224244// encoding by checking that messages exist, are of the same type, and share a single signer.
225245func validatePayloadMessages (msgs []sdk.Msg ) error {
0 commit comments