Skip to content

Commit

Permalink
align eip712 (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinhphuctadang committed Jan 17, 2024
1 parent b0f68ed commit bf3ea70
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions eip712_cosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"github.com/InjectiveLabs/sdk-go/typeddata"
)

var ErrNoMessage = errors.New("no message found. There should be at least one message")

type EIP712Wrapper func(
cdc codec.ProtoCodecMarshaler,
chainID uint64,
Expand All @@ -48,10 +46,6 @@ func WrapTxToEIP712(
msgs []cosmtypes.Msg,
feeDelegation *FeeDelegationOptions,
) (typeddata.TypedData, error) {
if len(msgs) == 0 {
return typeddata.TypedData{}, ErrNoMessage
}

data := legacytx.StdSignBytes(
signerData.ChainID,
signerData.AccountNumber,
Expand Down Expand Up @@ -301,6 +295,10 @@ func traverseFields(
if isCollection {
ethTyp += "[]"
}
if field.Kind() == reflect.String && field.Len() == 0 {
// skip empty strings from type mapping
continue
}
if prefix == typeDefPrefix {
typeMap[rootType] = append(typeMap[rootType], typeddata.Type{
Name: fieldName,
Expand Down Expand Up @@ -459,25 +457,8 @@ func doRecover(err *error) {
}
}

func WrapTxToEIP712V2(
cdc codec.ProtoCodecMarshaler,
chainID uint64,
signerData *authsigning.SignerData,
timeoutHeight uint64,
memo string,
feeInfo legacytx.StdFee,
msgs []cosmtypes.Msg,
feeDelegation *FeeDelegationOptions,
) (typeddata.TypedData, error) {
domain := typeddata.TypedDataDomain{
Name: "Injective Web3",
Version: "1.0.0",
ChainId: math.NewHexOrDecimal256(int64(chainID)),
VerifyingContract: "cosmos",
Salt: "0",
}

msgTypes := typeddata.Types{
func signableTypes() typeddata.Types {
return typeddata.Types{
"EIP712Domain": {
{
Name: "name",
Expand All @@ -493,7 +474,7 @@ func WrapTxToEIP712V2(
},
{
Name: "verifyingContract",
Type: "string",
Type: "address",
},
{
Name: "salt",
Expand All @@ -505,7 +486,27 @@ func WrapTxToEIP712V2(
{Name: "msgs", Type: "string"},
},
}
}

func WrapTxToEIP712V2(
cdc codec.ProtoCodecMarshaler,
chainID uint64,
signerData *authsigning.SignerData,
timeoutHeight uint64,
memo string,
feeInfo legacytx.StdFee,
msgs []cosmtypes.Msg,
feeDelegation *FeeDelegationOptions,
) (typeddata.TypedData, error) {
domain := typeddata.TypedDataDomain{
Name: "Injective Web3",
Version: "1.0.0",
ChainId: math.NewHexOrDecimal256(int64(chainID)),
VerifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
Salt: "0",
}

msgTypes := signableTypes()
msgsJsons := make([]json.RawMessage, len(msgs))
for idx, m := range msgs {
bzMsg, err := cdc.MarshalInterfaceJSON(m)
Expand Down

0 comments on commit bf3ea70

Please sign in to comment.