-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathcreate_account.go
146 lines (117 loc) · 5.87 KB
/
create_account.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package requests
import (
"github.com/pkg/errors"
utils "github.com/status-im/status-go/common"
"github.com/status-im/status-go/params"
)
var ErrCreateAccountInvalidDisplayName = errors.New("create-account: invalid display name")
var ErrCreateAccountInvalidPassword = errors.New("create-account: invalid password")
var ErrCreateAccountInvalidCustomizationColor = errors.New("create-account: invalid customization color")
var ErrCreateAccountInvalidRootKeystoreDir = errors.New("create-account: invalid root keystore directory")
var ErrCreateAccountInvalidRootDataDir = errors.New("create-account: invalid root data directory")
type ImageCropRectangle struct {
Ax int `json:"ax"`
Ay int `json:"ay"`
Bx int `json:"bx"`
By int `json:"by"`
}
type APIConfig struct {
APIModules string `json:"apiModules"`
ConnectorEnabled bool `json:"connectorEnabled"`
HTTPEnabled bool `json:"httpEnabled"`
HTTPHost string `json:"httpHost"`
HTTPPort int `json:"httpPort"`
HTTPVirtualHosts []string `json:"httpVirtualHosts"`
WSEnabled bool `json:"wsEnabled"`
WSHost string `json:"wsHost"`
WSPort int `json:"wsPort"`
}
type CreateAccount struct {
// RootDataDir is an absolute path to the root directory where all data will be stored.
RootDataDir string `json:"rootDataDir"`
KdfIterations int `json:"kdfIterations"`
DeviceName string `json:"deviceName"`
DisplayName string `json:"displayName"`
Password string `json:"password"`
ImagePath string `json:"imagePath"`
ImageCropRectangle *ImageCropRectangle `json:"imageCropRectangle"`
CustomizationColor string `json:"customizationColor"`
WakuV2Nameserver *string `json:"wakuV2Nameserver"`
WakuV2LightClient bool `json:"wakuV2LightClient"`
WakuV2EnableStoreConfirmationForMessagesSent bool `json:"wakuV2EnableStoreConfirmationForMessagesSent"`
WakuV2EnableMissingMessageVerification bool `json:"wakuV2EnableMissingMessageVerification"`
WakuV2Fleet string `json:"wakuV2Fleet"`
LogLevel *string `json:"logLevel"`
LogFilePath string `json:"logFilePath"` // absolute path
LogEnabled bool `json:"logEnabled"`
PreviewPrivacy bool `json:"previewPrivacy"`
VerifyTransactionURL *string `json:"verifyTransactionURL"`
VerifyENSURL *string `json:"verifyENSURL"`
VerifyENSContractAddress *string `json:"verifyENSContractAddress"`
VerifyTransactionChainID *int64 `json:"verifyTransactionChainID"`
UpstreamConfig string `json:"upstreamConfig"`
// Deprecated: CurrentNetwork is deprecated. It was passed and not used, so nothing should be passed instead.
// If you want to use non-default network, use NetworkID.
CurrentNetwork string `json:"currentNetwork"`
NetworkID *uint64 `json:"networkId"`
TestOverrideNetworks []params.Network `json:"-"` // This is used for testing purposes only
TestNetworksEnabled bool `json:"testNetworksEnabled"`
WalletSecretsConfig
TorrentConfigEnabled *bool
TorrentConfigPort *int
TelemetryServerURL string `json:"telemetryServerURL"`
APIConfig *APIConfig `json:"apiConfig"`
KeycardInstanceUID string `json:"keycardInstanceUID"`
KeycardPairingDataFile *string `json:"keycardPairingDataFile"`
StatusProxyEnabled bool `json:"statusProxyEnabled"`
}
type WalletSecretsConfig struct {
PoktToken string `json:"poktToken"`
InfuraToken string `json:"infuraToken"`
InfuraSecret string `json:"infuraSecret"`
OpenseaAPIKey string `json:"openseaApiKey"`
RaribleMainnetAPIKey string `json:"raribleMainnetApiKey"`
RaribleTestnetAPIKey string `json:"raribleTestnetApiKey"`
AlchemyEthereumMainnetToken string `json:"alchemyEthereumMainnetToken"`
AlchemyEthereumGoerliToken string `json:"alchemyEthereumGoerliToken"`
AlchemyEthereumSepoliaToken string `json:"alchemyEthereumSepoliaToken"`
AlchemyArbitrumMainnetToken string `json:"alchemyArbitrumMainnetToken"`
AlchemyArbitrumGoerliToken string `json:"alchemyArbitrumGoerliToken"`
AlchemyArbitrumSepoliaToken string `json:"alchemyArbitrumSepoliaToken"`
AlchemyOptimismMainnetToken string `json:"alchemyOptimismMainnetToken"`
AlchemyOptimismGoerliToken string `json:"alchemyOptimismGoerliToken"`
AlchemyOptimismSepoliaToken string `json:"alchemyOptimismSepoliaToken"`
StatusProxyStageName string `json:"statusProxyStageName"`
StatusProxyMarketUser string `json:"statusProxyMarketUser"`
StatusProxyMarketPassword string `json:"statusProxyMarketPassword"`
StatusProxyBlockchainUser string `json:"statusProxyBlockchainUser"`
StatusProxyBlockchainPassword string `json:"statusProxyBlockchainPassword"`
// Testing
GanacheURL string `json:"ganacheURL"`
}
func (c *CreateAccount) Validate(validation *CreateAccountValidation) error {
// TODO(cammellos): Add proper validation for password/displayname/etc
// Empty display name is allowed during account restore
if len(c.DisplayName) == 0 && !validation.AllowEmptyDisplayName {
return ErrCreateAccountInvalidDisplayName
}
if err := utils.ValidateDisplayName(&c.DisplayName); err != nil {
return errors.Wrap(ErrCreateAccountInvalidDisplayName, err.Error())
}
if len(c.Password) == 0 && !validation.AllowEmptyPassword {
return ErrCreateAccountInvalidPassword
}
if len(c.CustomizationColor) == 0 && !validation.AllowEmptyCustomizationColor {
return ErrCreateAccountInvalidCustomizationColor
}
if len(c.RootDataDir) == 0 {
return ErrCreateAccountInvalidRootDataDir
}
return nil
}
// NOTE: Reasoning for this struct here: /~https://github.com/status-im/status-go/pull/4980#discussion_r1539219099
type CreateAccountValidation struct {
AllowEmptyDisplayName bool
AllowEmptyPassword bool
AllowEmptyCustomizationColor bool
}