-
Notifications
You must be signed in to change notification settings - Fork 0
/
eip712.go
70 lines (61 loc) · 2.05 KB
/
eip712.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package eip712_go_example
import (
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
)
// type aliases to avoid importing "core" everywhere
type TypedData = apitypes.TypedData
type TypedDataDomain = apitypes.TypedDataDomain
type Types = apitypes.Types
type Type = apitypes.Type
type TypedDataMessage = apitypes.TypedDataMessage
// EIP712DomainType is the type description for the EIP712 Domain
var EIP712DomainType = []Type{
{Name: "name", Type: "string"},
{Name: "version", Type: "string"},
{Name: "chainId", Type: "uint256"},
{Name: "verifyingContract", Type: "address"},
}
var PersonType = []Type{
{Name: "name", Type: "string"},
{Name: "wallet", Type: "address"},
}
var MailType = []Type{
{Name: "from", Type: "Person"},
{Name: "to", Type: "Person"},
{Name: "contents", Type: "string"},
{Name: "amount", Type: "uint256"},
{Name: "expiration", Type: "uint256"},
}
type Person struct {
Name string `json:"name"`
Wallet string `json:"wallet"`
}
type Mail struct {
From Person `json:"from"`
To Person `json:"to"`
Contents string `json:"contents"`
Amount string `json:"amount"` //solidity's uint256 map to go's string in EIP712
Expiration string `json:"expiration"` //solidity's uint256 map to go's string in EIP712
}
var data = TypedData{
Types: Types{
"EIP712Domain": EIP712DomainType,
"Person": PersonType,
"Mail": MailType,
},
PrimaryType: "Mail",
Domain: TypedDataDomain{
Name: "Ether Mail",
Version: "1",
ChainId: math.NewHexOrDecimal256(1), //solidity's uint256 map to go's math.NewHexOrDecimal256 in EIP712
VerifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
},
Message: TypedDataMessage{
"from": map[string]interface{}{"name": "Cow", "wallet": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"},
"to": map[string]interface{}{"name": "Bob", "wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"},
"contents": "Hello, Bob!",
"amount": "10000000000",
"expiration": "1667659989",
},
}