Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
619a3e70
Unverified
Commit
619a3e70
authored
Dec 05, 2021
by
Martin Holst Swende
Committed by
GitHub
Dec 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
signer/core: move EIP-712 types to package apitypes (#24029)
Fixes #23972
parent
93f196c4
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
776 additions
and
771 deletions
+776
-771
main.go
cmd/clef/main.go
+2
-2
api.go
signer/core/api.go
+2
-2
signed_data_internal_test.go
signer/core/apitypes/signed_data_internal_test.go
+1
-1
types.go
signer/core/apitypes/types.go
+718
-0
auditlog.go
signer/core/auditlog.go
+1
-1
gnosis_safe.go
signer/core/gnosis_safe.go
+7
-7
signed_data.go
signer/core/signed_data.go
+19
-733
signed_data_test.go
signer/core/signed_data_test.go
+25
-24
rules_test.go
signer/rules/rules_test.go
+1
-1
No files found.
cmd/clef/main.go
View file @
619a3e70
...
...
@@ -898,7 +898,7 @@ func testExternalUI(api *core.SignerAPI) {
addr
,
_
:=
common
.
NewMixedcaseAddressFromString
(
"0x0011223344556677889900112233445566778899"
)
data
:=
`{"types":{"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}],"Person":[{"name":"name","type":"string"},{"name":"test","type":"uint8"},{"name":"wallet","type":"address"}],"Mail":[{"name":"from","type":"Person"},{"name":"to","type":"Person"},{"name":"contents","type":"string"}]},"primaryType":"Mail","domain":{"name":"Ether Mail","version":"1","chainId":"1","verifyingContract":"0xCCCcccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"},"message":{"from":{"name":"Cow","test":"3","wallet":"0xcD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"},"to":{"name":"Bob","wallet":"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB","test":"2"},"contents":"Hello, Bob!"}}`
//_, err := api.SignData(ctx, accounts.MimetypeTypedData, *addr, hexutil.Encode([]byte(data)))
var
typedData
core
.
TypedData
var
typedData
apitypes
.
TypedData
json
.
Unmarshal
([]
byte
(
data
),
&
typedData
)
_
,
err
:=
api
.
SignTypedData
(
ctx
,
*
addr
,
typedData
)
expectApprove
(
"sign 712 typed data"
,
err
)
...
...
@@ -1025,7 +1025,7 @@ func GenDoc(ctx *cli.Context) {
"of the work in canonicalizing and making sense of the data, and it's up to the UI to present"
+
"the user with the contents of the `message`"
sighash
,
msg
:=
accounts
.
TextAndHash
([]
byte
(
"hello world"
))
messages
:=
[]
*
core
.
NameValueType
{{
Name
:
"message"
,
Value
:
msg
,
Typ
:
accounts
.
MimetypeTextPlain
}}
messages
:=
[]
*
apitypes
.
NameValueType
{{
Name
:
"message"
,
Value
:
msg
,
Typ
:
accounts
.
MimetypeTextPlain
}}
add
(
"SignDataRequest"
,
desc
,
&
core
.
SignDataRequest
{
Address
:
common
.
NewMixedcaseAddress
(
a
),
...
...
signer/core/api.go
View file @
619a3e70
...
...
@@ -57,7 +57,7 @@ type ExternalAPI interface {
// SignData - request to sign the given data (plus prefix)
SignData
(
ctx
context
.
Context
,
contentType
string
,
addr
common
.
MixedcaseAddress
,
data
interface
{})
(
hexutil
.
Bytes
,
error
)
// SignTypedData - request to sign the given structured data (plus prefix)
SignTypedData
(
ctx
context
.
Context
,
addr
common
.
MixedcaseAddress
,
data
TypedData
)
(
hexutil
.
Bytes
,
error
)
SignTypedData
(
ctx
context
.
Context
,
addr
common
.
MixedcaseAddress
,
data
apitypes
.
TypedData
)
(
hexutil
.
Bytes
,
error
)
// EcRecover - recover public key from given message and signature
EcRecover
(
ctx
context
.
Context
,
data
hexutil
.
Bytes
,
sig
hexutil
.
Bytes
)
(
common
.
Address
,
error
)
// Version info about the APIs
...
...
@@ -235,7 +235,7 @@ type (
ContentType
string
`json:"content_type"`
Address
common
.
MixedcaseAddress
`json:"address"`
Rawdata
[]
byte
`json:"raw_data"`
Messages
[]
*
NameValueType
`json:"messages"`
Messages
[]
*
apitypes
.
NameValueType
`json:"messages"`
Callinfo
[]
apitypes
.
ValidationInfo
`json:"call_info"`
Hash
hexutil
.
Bytes
`json:"hash"`
Meta
Metadata
`json:"meta"`
...
...
signer/core/signed_data_internal_test.go
→
signer/core/
apitypes/
signed_data_internal_test.go
View file @
619a3e70
...
...
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package
core
package
apitypes
import
(
"bytes"
...
...
signer/core/apitypes/types.go
View file @
619a3e70
This diff is collapsed.
Click to expand it.
signer/core/auditlog.go
View file @
619a3e70
...
...
@@ -89,7 +89,7 @@ func (l *AuditLogger) SignGnosisSafeTx(ctx context.Context, addr common.Mixedcas
return
res
,
e
}
func
(
l
*
AuditLogger
)
SignTypedData
(
ctx
context
.
Context
,
addr
common
.
MixedcaseAddress
,
data
TypedData
)
(
hexutil
.
Bytes
,
error
)
{
func
(
l
*
AuditLogger
)
SignTypedData
(
ctx
context
.
Context
,
addr
common
.
MixedcaseAddress
,
data
apitypes
.
TypedData
)
(
hexutil
.
Bytes
,
error
)
{
l
.
log
.
Info
(
"SignTypedData"
,
"type"
,
"request"
,
"metadata"
,
MetadataFromContext
(
ctx
)
.
String
(),
"addr"
,
addr
.
String
(),
"data"
,
data
)
b
,
e
:=
l
.
api
.
SignTypedData
(
ctx
,
addr
,
data
)
...
...
signer/core/gnosis_safe.go
View file @
619a3e70
...
...
@@ -34,15 +34,15 @@ type GnosisSafeTx struct {
}
// ToTypedData converts the tx to a EIP-712 Typed Data structure for signing
func
(
tx
*
GnosisSafeTx
)
ToTypedData
()
TypedData
{
func
(
tx
*
GnosisSafeTx
)
ToTypedData
()
apitypes
.
TypedData
{
var
data
hexutil
.
Bytes
if
tx
.
Data
!=
nil
{
data
=
*
tx
.
Data
}
gnosisTypedData
:=
TypedData
{
Types
:
Types
{
"EIP712Domain"
:
[]
Type
{{
Name
:
"verifyingContract"
,
Type
:
"address"
}},
"SafeTx"
:
[]
Type
{
gnosisTypedData
:=
apitypes
.
TypedData
{
Types
:
apitypes
.
Types
{
"EIP712Domain"
:
[]
apitypes
.
Type
{{
Name
:
"verifyingContract"
,
Type
:
"address"
}},
"SafeTx"
:
[]
apitypes
.
Type
{
{
Name
:
"to"
,
Type
:
"address"
},
{
Name
:
"value"
,
Type
:
"uint256"
},
{
Name
:
"data"
,
Type
:
"bytes"
},
...
...
@@ -55,11 +55,11 @@ func (tx *GnosisSafeTx) ToTypedData() TypedData {
{
Name
:
"nonce"
,
Type
:
"uint256"
},
},
},
Domain
:
TypedDataDomain
{
Domain
:
apitypes
.
TypedDataDomain
{
VerifyingContract
:
tx
.
Safe
.
Address
()
.
Hex
(),
},
PrimaryType
:
"SafeTx"
,
Message
:
TypedDataMessage
{
Message
:
apitypes
.
TypedDataMessage
{
"to"
:
tx
.
To
.
Address
()
.
Hex
(),
"value"
:
tx
.
Value
.
String
(),
"data"
:
data
,
...
...
signer/core/signed_data.go
View file @
619a3e70
This diff is collapsed.
Click to expand it.
signer/core/signed_data_test.go
View file @
619a3e70
...
...
@@ -32,9 +32,10 @@ import (
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/signer/core"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
)
var
typesStandard
=
core
.
Types
{
var
typesStandard
=
apitypes
.
Types
{
"EIP712Domain"
:
{
{
Name
:
"name"
,
...
...
@@ -153,12 +154,12 @@ var jsonTypedData = `
const
primaryType
=
"Mail"
var
domainStandard
=
core
.
TypedDataDomain
{
"Ether Mail"
,
"1"
,
math
.
NewHexOrDecimal256
(
1
),
"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
,
""
,
var
domainStandard
=
apitypes
.
TypedDataDomain
{
Name
:
"Ether Mail"
,
Version
:
"1"
,
ChainId
:
math
.
NewHexOrDecimal256
(
1
),
VerifyingContract
:
"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
,
Salt
:
""
,
}
var
messageStandard
=
map
[
string
]
interface
{}{
...
...
@@ -173,7 +174,7 @@ var messageStandard = map[string]interface{}{
"contents"
:
"Hello, Bob!"
,
}
var
typedData
=
core
.
TypedData
{
var
typedData
=
apitypes
.
TypedData
{
Types
:
typesStandard
,
PrimaryType
:
primaryType
,
Domain
:
domainStandard
,
...
...
@@ -194,7 +195,7 @@ func TestSignData(t *testing.T) {
control
.
approveCh
<-
"Y"
control
.
inputCh
<-
"wrongpassword"
signature
,
err
:=
api
.
SignData
(
context
.
Background
(),
core
.
TextPlain
.
Mime
,
a
,
hexutil
.
Encode
([]
byte
(
"EHLO world"
)))
signature
,
err
:=
api
.
SignData
(
context
.
Background
(),
apitypes
.
TextPlain
.
Mime
,
a
,
hexutil
.
Encode
([]
byte
(
"EHLO world"
)))
if
signature
!=
nil
{
t
.
Errorf
(
"Expected nil-data, got %x"
,
signature
)
}
...
...
@@ -202,7 +203,7 @@ func TestSignData(t *testing.T) {
t
.
Errorf
(
"Expected ErrLocked! '%v'"
,
err
)
}
control
.
approveCh
<-
"No way"
signature
,
err
=
api
.
SignData
(
context
.
Background
(),
core
.
TextPlain
.
Mime
,
a
,
hexutil
.
Encode
([]
byte
(
"EHLO world"
)))
signature
,
err
=
api
.
SignData
(
context
.
Background
(),
apitypes
.
TextPlain
.
Mime
,
a
,
hexutil
.
Encode
([]
byte
(
"EHLO world"
)))
if
signature
!=
nil
{
t
.
Errorf
(
"Expected nil-data, got %x"
,
signature
)
}
...
...
@@ -212,7 +213,7 @@ func TestSignData(t *testing.T) {
// text/plain
control
.
approveCh
<-
"Y"
control
.
inputCh
<-
"a_long_password"
signature
,
err
=
api
.
SignData
(
context
.
Background
(),
core
.
TextPlain
.
Mime
,
a
,
hexutil
.
Encode
([]
byte
(
"EHLO world"
)))
signature
,
err
=
api
.
SignData
(
context
.
Background
(),
apitypes
.
TextPlain
.
Mime
,
a
,
hexutil
.
Encode
([]
byte
(
"EHLO world"
)))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -232,13 +233,13 @@ func TestSignData(t *testing.T) {
}
func
TestDomainChainId
(
t
*
testing
.
T
)
{
withoutChainID
:=
core
.
TypedData
{
Types
:
core
.
Types
{
"EIP712Domain"
:
[]
core
.
Type
{
withoutChainID
:=
apitypes
.
TypedData
{
Types
:
apitypes
.
Types
{
"EIP712Domain"
:
[]
apitypes
.
Type
{
{
Name
:
"name"
,
Type
:
"string"
},
},
},
Domain
:
core
.
TypedDataDomain
{
Domain
:
apitypes
.
TypedDataDomain
{
Name
:
"test"
,
},
}
...
...
@@ -250,14 +251,14 @@ func TestDomainChainId(t *testing.T) {
if
_
,
err
:=
withoutChainID
.
HashStruct
(
"EIP712Domain"
,
withoutChainID
.
Domain
.
Map
());
err
!=
nil
{
t
.
Errorf
(
"Expected the typedData to encode the domain successfully, got %v"
,
err
)
}
withChainID
:=
core
.
TypedData
{
Types
:
core
.
Types
{
"EIP712Domain"
:
[]
core
.
Type
{
withChainID
:=
apitypes
.
TypedData
{
Types
:
apitypes
.
Types
{
"EIP712Domain"
:
[]
apitypes
.
Type
{
{
Name
:
"name"
,
Type
:
"string"
},
{
Name
:
"chainId"
,
Type
:
"uint256"
},
},
},
Domain
:
core
.
TypedDataDomain
{
Domain
:
apitypes
.
TypedDataDomain
{
Name
:
"test"
,
ChainId
:
math
.
NewHexOrDecimal256
(
1
),
},
...
...
@@ -323,7 +324,7 @@ func TestEncodeData(t *testing.T) {
}
func
TestFormatter
(
t
*
testing
.
T
)
{
var
d
core
.
TypedData
var
d
apitypes
.
TypedData
err
:=
json
.
Unmarshal
([]
byte
(
jsonTypedData
),
&
d
)
if
err
!=
nil
{
t
.
Fatalf
(
"unmarshalling failed '%v'"
,
err
)
...
...
@@ -337,7 +338,7 @@ func TestFormatter(t *testing.T) {
t
.
Logf
(
"'%v'
\n
"
,
string
(
j
))
}
func
sign
(
typedData
core
.
TypedData
)
([]
byte
,
[]
byte
,
error
)
{
func
sign
(
typedData
apitypes
.
TypedData
)
([]
byte
,
[]
byte
,
error
)
{
domainSeparator
,
err
:=
typedData
.
HashStruct
(
"EIP712Domain"
,
typedData
.
Domain
.
Map
())
if
err
!=
nil
{
return
nil
,
nil
,
err
...
...
@@ -366,7 +367,7 @@ func TestJsonFiles(t *testing.T) {
t
.
Errorf
(
"Failed to read file %v: %v"
,
fInfo
.
Name
(),
err
)
continue
}
var
typedData
core
.
TypedData
var
typedData
apitypes
.
TypedData
err
=
json
.
Unmarshal
(
data
,
&
typedData
)
if
err
!=
nil
{
t
.
Errorf
(
"Test %d, file %v, json unmarshalling failed: %v"
,
i
,
fInfo
.
Name
(),
err
)
...
...
@@ -398,7 +399,7 @@ func TestFuzzerFiles(t *testing.T) {
t
.
Errorf
(
"Failed to read file %v: %v"
,
fInfo
.
Name
(),
err
)
continue
}
var
typedData
core
.
TypedData
var
typedData
apitypes
.
TypedData
err
=
json
.
Unmarshal
(
data
,
&
typedData
)
if
err
!=
nil
{
t
.
Errorf
(
"Test %d, file %v, json unmarshalling failed: %v"
,
i
,
fInfo
.
Name
(),
err
)
...
...
@@ -498,7 +499,7 @@ var gnosisTx = `
// TestGnosisTypedData tests the scenario where a user submits a full EIP-712
// struct without using the gnosis-specific endpoint
func
TestGnosisTypedData
(
t
*
testing
.
T
)
{
var
td
core
.
TypedData
var
td
apitypes
.
TypedData
err
:=
json
.
Unmarshal
([]
byte
(
gnosisTypedData
),
&
td
)
if
err
!=
nil
{
t
.
Fatalf
(
"unmarshalling failed '%v'"
,
err
)
...
...
signer/rules/rules_test.go
View file @
619a3e70
...
...
@@ -605,7 +605,7 @@ function ApproveSignData(r){
t
.
Logf
(
"address %v %v
\n
"
,
addr
.
String
(),
addr
.
Original
())
nvt
:=
[]
*
core
.
NameValueType
{
nvt
:=
[]
*
apitypes
.
NameValueType
{
{
Name
:
"message"
,
Typ
:
"text/plain"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment