@@ -3,6 +3,7 @@ package eip712
33import (
44 "errors"
55 "fmt"
6+ "strconv"
67
78 apitypes "github.com/ethereum/go-ethereum/signer/core/apitypes"
89
@@ -101,8 +102,17 @@ func decodeAminoSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
101102 return apitypes.TypedData {}, err
102103 }
103104
105+ // Extract the chain ID from the sign doc itself for EIP-712 domain
106+ // This ensures we use the same chain ID that was used during signing
107+ chainID := eip155ChainID
108+ if aminoDoc .ChainID != "" {
109+ if parsedChainID , err := parseChainID (aminoDoc .ChainID ); err == nil {
110+ chainID = parsedChainID
111+ }
112+ }
113+
104114 typedData , err := WrapTxToTypedData (
105- eip155ChainID ,
115+ chainID ,
106116 signDocBytes ,
107117 )
108118 if err != nil {
@@ -176,8 +186,17 @@ func decodeProtobufSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
176186 body .Memo ,
177187 )
178188
189+ // Extract the chain ID from the sign doc itself for EIP-712 domain
190+ // This ensures we use the same chain ID that was used during signing
191+ chainID := eip155ChainID
192+ if signDoc .ChainId != "" {
193+ if parsedChainID , err := parseChainID (signDoc .ChainId ); err == nil {
194+ chainID = parsedChainID
195+ }
196+ }
197+
179198 typedData , err := WrapTxToTypedData (
180- eip155ChainID ,
199+ chainID ,
181200 signBytes ,
182201 )
183202 if err != nil {
@@ -227,3 +246,9 @@ func validatePayloadMessages(msgs []sdk.Msg) error {
227246
228247 return nil
229248}
249+
250+ // parseChainID attempts to parse the chain ID string as a uint64.
251+ // The chain ID in the sign doc should be the EIP-155 chain ID.
252+ func parseChainID (chainIDStr string ) (uint64 , error ) {
253+ return strconv .ParseUint (chainIDStr , 10 , 64 )
254+ }
0 commit comments