-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermit.go
73 lines (70 loc) · 1.34 KB
/
permit.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
71
72
73
package eip712
import (
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/signer/core"
"math/big"
)
var typesPermit = core.Types{
"EIP712Domain": {
{
Name: "name",
Type: "string",
},
{
Name: "version",
Type: "string",
},
{
Name: "chainId",
Type: "uint256",
},
{
Name: "verifyingContract",
Type: "address",
},
{
Name: "salt",
Type: "string",
},
},
"Permit": {
{
Name: "owner",
Type: "address",
},
{
Name: "spender",
Type: "address",
},
{
Name: "value",
Type: "uint256",
},
{
Name: "deadline",
Type: "uint256",
},
},
}
// GenPermitTypedData 生成Permit的签名数据
func GenPermitTypedData(name string, chainId *big.Int, verifyingContract string, salt string,
owner, spender string, value *big.Int, deadline int64) core.TypedData {
valueBig := (math.HexOrDecimal256)(*value)
return core.TypedData{
Types: typesPermit,
PrimaryType: "Permit",
Domain: core.TypedDataDomain{
Name: name,
Version: "1",
ChainId: math.NewHexOrDecimal256(chainId.Int64()),
VerifyingContract: verifyingContract,
Salt: salt,
},
Message: core.TypedDataMessage{
"owner": owner,
"spender": spender,
"value": &valueBig,
"deadline": math.NewHexOrDecimal256(deadline),
},
}
}