Skip to content

Commit

Permalink
Improves 'chainId' validation
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodeev committed Dec 13, 2024
1 parent 3900aee commit 1b5d956
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions typedData/typedData.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ func (domain *Domain) UnmarshalJSON(data []byte) error {
getField := func(fieldName string) (string, error) {
value, ok := dec[fieldName]
if !ok {
return "", fmt.Errorf("error getting value of '%s' from 'domain' struct", fieldName)
return "", fmt.Errorf("error getting the value of '%s' from 'domain' struct", fieldName)
}
return fmt.Sprintf("%v", value), nil
}
Expand All @@ -867,16 +867,6 @@ func (domain *Domain) UnmarshalJSON(data []byte) error {
return err
}

chainId, err := getField("chainId")
if err != nil {
var err2 error
// ref: https://community.starknet.io/t/signing-transactions-and-off-chain-messages/66
chainId, err2 = getField("chain_id")
if err2 != nil {
return err
}
}

revision, err := getField("revision")
if err != nil {
revision = "0"
Expand All @@ -886,6 +876,19 @@ func (domain *Domain) UnmarshalJSON(data []byte) error {
return err
}

chainId, err := getField("chainId")
if err != nil {
if numRevision == 1 {
return err
}
var err2 error
// ref: https://community.starknet.io/t/signing-transactions-and-off-chain-messages/66
chainId, err2 = getField("chain_id")
if err2 != nil {
return fmt.Errorf("%w: %w", err, err2)
}
}

*domain = Domain{
Name: name,
Version: version,
Expand Down

0 comments on commit 1b5d956

Please sign in to comment.