accept a JSON string as chainID in signTypedData_v3 (#2226)

accept either a JSON number or string as chainID in signTypedData_v3/signTypedData_v4
This commit is contained in:
Bitgamma 2021-05-12 12:25:42 +03:00 committed by GitHub
parent 91620b9982
commit 6a930ed0c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 4 deletions

View File

@ -1 +1 @@
0.77.0
0.77.1

2
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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),
@ -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)
@ -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{}

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/big"
"strconv"
)
const (
@ -77,8 +78,14 @@ func (t TypedData) ValidateChainID(chain *big.Int) error {
}
var chainID int64
if err := json.Unmarshal(t.Domain[chainIDKey], &chainID); err != nil {
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)
}

View File

@ -18,6 +18,7 @@
package math
import (
"encoding/json"
"fmt"
"math/big"
)
@ -49,6 +50,26 @@ func NewHexOrDecimal256(x int64) *HexOrDecimal256 {
return &h
}
func (i *HexOrDecimal256) UnmarshalJSON(data []byte) error {
var x int64
var s string
var b *big.Int
var err error
if err = json.Unmarshal(data, &x); err == nil {
b = big.NewInt(x)
} else if err = json.Unmarshal(data, &s); err == nil {
var ok bool
b, ok = ParseBig256(s)
if !ok {
return fmt.Errorf("invalid hex or decimal integer %q", s)
}
} else {
return err
}
*i = HexOrDecimal256(*b)
return nil
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (i *HexOrDecimal256) UnmarshalText(input []byte) error {
bigint, ok := ParseBig256(string(input))

2
vendor/modules.txt vendored
View File

@ -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