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:
parent
91620b9982
commit
6a930ed0c6
2
go.mod
2
go.mod
|
@ -2,7 +2,7 @@ module github.com/status-im/status-go
|
||||||
|
|
||||||
go 1.13
|
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
|
replace github.com/Sirupsen/logrus v1.4.2 => github.com/sirupsen/logrus v1.4.2
|
||||||
|
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -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/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 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.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 h1:OT84UsUzTCwguqCpJqkrCMiL4VZ1SvUtH9a5MsZupBk=
|
||||||
github.com/status-im/go-multiaddr-ethv4 v1.2.0/go.mod h1:2VQ3C+9zEurcceasz12gPAtmEzCeyLUGPeKLSXYQKHo=
|
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=
|
github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
|
||||||
|
|
|
@ -101,6 +101,12 @@ func TestInteroparableWithSolidity(t *testing.T) {
|
||||||
"chainId": json.RawMessage("1"),
|
"chainId": json.RawMessage("1"),
|
||||||
"verifyingContract": json.RawMessage(`"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"`),
|
"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{
|
msg := map[string]json.RawMessage{
|
||||||
"from": json.RawMessage(fromWallet),
|
"from": json.RawMessage(fromWallet),
|
||||||
"to": json.RawMessage(toWallet),
|
"to": json.RawMessage(toWallet),
|
||||||
|
@ -112,6 +118,12 @@ func TestInteroparableWithSolidity(t *testing.T) {
|
||||||
Domain: domain,
|
Domain: domain,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
}
|
}
|
||||||
|
typedChainIDAsString := TypedData{
|
||||||
|
Types: mytypes,
|
||||||
|
PrimaryType: "Mail",
|
||||||
|
Domain: domainChainIDAsString,
|
||||||
|
Message: msg,
|
||||||
|
}
|
||||||
|
|
||||||
domainHash, err := hashStruct(eip712Domain, typed.Domain, typed.Types)
|
domainHash, err := hashStruct(eip712Domain, typed.Domain, typed.Types)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -125,6 +137,10 @@ func TestInteroparableWithSolidity(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, signature, 65)
|
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{}
|
r := [32]byte{}
|
||||||
copy(r[:], signature[:32])
|
copy(r[:], signature[:32])
|
||||||
s := [32]byte{}
|
s := [32]byte{}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -77,7 +78,13 @@ func (t TypedData) ValidateChainID(chain *big.Int) error {
|
||||||
}
|
}
|
||||||
var chainID int64
|
var chainID int64
|
||||||
if err := json.Unmarshal(t.Domain[chainIDKey], &chainID); err != nil {
|
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() {
|
if chainID != chain.Int64() {
|
||||||
return fmt.Errorf("chainId %d doesn't match selected chain %s", chainID, chain)
|
return fmt.Errorf("chainId %d doesn't match selected chain %s", chainID, chain)
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package math
|
package math
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
)
|
)
|
||||||
|
@ -49,6 +50,26 @@ func NewHexOrDecimal256(x int64) *HexOrDecimal256 {
|
||||||
return &h
|
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.
|
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||||
func (i *HexOrDecimal256) UnmarshalText(input []byte) error {
|
func (i *HexOrDecimal256) UnmarshalText(input []byte) error {
|
||||||
bigint, ok := ParseBig256(string(input))
|
bigint, ok := ParseBig256(string(input))
|
||||||
|
|
|
@ -37,7 +37,7 @@ github.com/edsrzf/mmap-go
|
||||||
# github.com/elastic/gosigar v0.10.4
|
# github.com/elastic/gosigar v0.10.4
|
||||||
github.com/elastic/gosigar
|
github.com/elastic/gosigar
|
||||||
github.com/elastic/gosigar/sys/windows
|
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
|
||||||
github.com/ethereum/go-ethereum/accounts
|
github.com/ethereum/go-ethereum/accounts
|
||||||
github.com/ethereum/go-ethereum/accounts/abi
|
github.com/ethereum/go-ethereum/accounts/abi
|
||||||
|
|
Loading…
Reference in New Issue