Skip to content

Commit

Permalink
accept a JSON string as chainID in signTypedData_v3 (#2226)
Browse files Browse the repository at this point in the history
accept either a JSON number or string as chainID in signTypedData_v3/signTypedData_v4
  • Loading branch information
bitgamma authored May 12, 2021
1 parent 91620b9 commit 6a930ed
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.77.0
0.77.1
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/status-im/status-go

go 1.13

replace github.com/ethereum/go-ethereum v1.9.5 => github.com/status-im/go-ethereum v1.9.5-status.11
replace github.com/ethereum/go-ethereum v1.9.5 => github.com/status-im/go-ethereum v1.9.5-status.12

replace github.com/Sirupsen/logrus v1.4.2 => github.com/sirupsen/logrus v1.4.2

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ github.com/status-im/doubleratchet v3.0.0+incompatible h1:aJ1ejcSERpSzmWZBgtfYti
github.com/status-im/doubleratchet v3.0.0+incompatible/go.mod h1:1sqR0+yhiM/bd+wrdX79AOt2csZuJOni0nUDzKNuqOU=
github.com/status-im/go-ethereum v1.9.5-status.11 h1:97yCttJkIXoTZGrew7Lkl6uOGaeYELdp7gMnKBm1YwY=
github.com/status-im/go-ethereum v1.9.5-status.11/go.mod h1:YyH5DKB6+z+Vaya7eIm67pnuPZ1oiUMbbsZW41ktN0g=
github.com/status-im/go-ethereum v1.9.5-status.12 h1:+QZE2x5zF1CvNo3V+WaCzeOoar8pdh5Y7BGaAJ83pOw=
github.com/status-im/go-ethereum v1.9.5-status.12/go.mod h1:YyH5DKB6+z+Vaya7eIm67pnuPZ1oiUMbbsZW41ktN0g=
github.com/status-im/go-multiaddr-ethv4 v1.2.0 h1:OT84UsUzTCwguqCpJqkrCMiL4VZ1SvUtH9a5MsZupBk=
github.com/status-im/go-multiaddr-ethv4 v1.2.0/go.mod h1:2VQ3C+9zEurcceasz12gPAtmEzCeyLUGPeKLSXYQKHo=
github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
Expand Down
16 changes: 16 additions & 0 deletions services/typeddata/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ func TestInteroparableWithSolidity(t *testing.T) {
"chainId": json.RawMessage("1"),
"verifyingContract": json.RawMessage(`"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"`),
}
domainChainIDAsString := map[string]json.RawMessage{
"name": json.RawMessage(`"Ether Mail"`),
"version": json.RawMessage(`"1"`),
"chainId": json.RawMessage(`"1"`),
"verifyingContract": json.RawMessage(`"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"`),
}
msg := map[string]json.RawMessage{
"from": json.RawMessage(fromWallet),
"to": json.RawMessage(toWallet),
Expand All @@ -112,6 +118,12 @@ func TestInteroparableWithSolidity(t *testing.T) {
Domain: domain,
Message: msg,
}
typedChainIDAsString := TypedData{
Types: mytypes,
PrimaryType: "Mail",
Domain: domainChainIDAsString,
Message: msg,
}

domainHash, err := hashStruct(eip712Domain, typed.Domain, typed.Types)
require.NoError(t, err)
Expand All @@ -125,6 +137,10 @@ func TestInteroparableWithSolidity(t *testing.T) {
require.NoError(t, err)
require.Len(t, signature, 65)

signature2, err := Sign(typedChainIDAsString, key, big.NewInt(1))
require.NoError(t, err)
require.Equal(t, signature, signature2)

r := [32]byte{}
copy(r[:], signature[:32])
s := [32]byte{}
Expand Down
9 changes: 8 additions & 1 deletion services/typeddata/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/big"
"strconv"
)

const (
Expand Down Expand Up @@ -77,7 +78,13 @@ func (t TypedData) ValidateChainID(chain *big.Int) error {
}
var chainID int64
if err := json.Unmarshal(t.Domain[chainIDKey], &chainID); err != nil {
return err
var chainIDString string
if err = json.Unmarshal(t.Domain[chainIDKey], &chainIDString); err != nil {
return err
}
if chainID, err = strconv.ParseInt(chainIDString, 0, 64); err != nil {
return err
}
}
if chainID != chain.Int64() {
return fmt.Errorf("chainId %d doesn't match selected chain %s", chainID, chain)
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/ethereum/go-ethereum/common/math/big.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ github.com/edsrzf/mmap-go
# github.com/elastic/gosigar v0.10.4
github.com/elastic/gosigar
github.com/elastic/gosigar/sys/windows
# github.com/ethereum/go-ethereum v1.9.5 => github.com/status-im/go-ethereum v1.9.5-status.11
# github.com/ethereum/go-ethereum v1.9.5 => github.com/status-im/go-ethereum v1.9.5-status.12
github.com/ethereum/go-ethereum
github.com/ethereum/go-ethereum/accounts
github.com/ethereum/go-ethereum/accounts/abi
Expand Down

0 comments on commit 6a930ed

Please sign in to comment.