Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: align eip712 v2 def #200

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading