-
Notifications
You must be signed in to change notification settings - Fork 7
/
ChangePubKey.go
93 lines (75 loc) · 2.39 KB
/
ChangePubKey.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package zksync
import (
"encoding/hex"
"github.com/ethereum/go-ethereum/common"
)
type TransactionTypeChangePubKey struct {
ChangePubKey string `json:"ChangePubKey"`
}
const (
TransactionTypeChangePubKeyOnchain TransactionType = "Onchain"
TransactionTypeChangePubKeyECDSA TransactionType = "ECDSA"
TransactionTypeChangePubKeyCREATE2 TransactionType = "CREATE2"
)
type ChangePubKey struct {
Type string `json:"type"`
AccountId uint32 `json:"accountId"`
Account common.Address `json:"account"`
NewPkHash string `json:"newPkHash"`
FeeToken uint32 `json:"feeToken"`
Fee string `json:"fee"`
Nonce uint32 `json:"nonce"`
Signature *Signature `json:"signature"`
EthAuthData ChangePubKeyVariant `json:"ethAuthData"`
*TimeRange
}
func (t *ChangePubKey) getType() string {
return "ChangePubKey"
}
type ChangePubKeyAuthType string
const (
ChangePubKeyAuthTypeOnchain ChangePubKeyAuthType = `Onchain`
ChangePubKeyAuthTypeECDSA ChangePubKeyAuthType = `ECDSA`
ChangePubKeyAuthTypeCREATE2 ChangePubKeyAuthType = `CREATE2`
)
type ChangePubKeyVariant interface {
getType() ChangePubKeyAuthType
getBytes() []byte
}
type ChangePubKeyOnchain struct {
Type ChangePubKeyAuthType `json:"type"`
}
func (t *ChangePubKeyOnchain) getType() ChangePubKeyAuthType {
return ChangePubKeyAuthTypeOnchain
}
func (t *ChangePubKeyOnchain) getBytes() []byte {
return make([]byte, 32)
}
type ChangePubKeyECDSA struct {
Type ChangePubKeyAuthType `json:"type"`
EthSignature string `json:"ethSignature"`
BatchHash string `json:"batchHash"`
}
func (t *ChangePubKeyECDSA) getType() ChangePubKeyAuthType {
return ChangePubKeyAuthTypeECDSA
}
func (t *ChangePubKeyECDSA) getBytes() []byte {
res, _ := hex.DecodeString(t.BatchHash[2:])
return res
}
type ChangePubKeyCREATE2 struct {
Type ChangePubKeyAuthType `json:"type"`
CreatorAddress string `json:"creatorAddress"`
SaltArg string `json:"saltArg"`
CodeHash string `json:"codeHash"`
}
func (t *ChangePubKeyCREATE2) getType() ChangePubKeyAuthType {
return ChangePubKeyAuthTypeCREATE2
}
func (t *ChangePubKeyCREATE2) getBytes() []byte {
return make([]byte, 32)
}
type Signature struct {
PubKey string `json:"pubKey"`
Signature string `json:"signature"`
}