2022-10-14 08:50:36 +00:00
|
|
|
package requests
|
|
|
|
|
|
|
|
import (
|
2024-03-28 15:57:59 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
|
|
|
utils "github.com/status-im/status-go/common"
|
2024-06-02 18:28:55 +00:00
|
|
|
"github.com/status-im/status-go/params"
|
2022-10-14 08:50:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var ErrCreateAccountInvalidDisplayName = errors.New("create-account: invalid display name")
|
|
|
|
var ErrCreateAccountInvalidPassword = errors.New("create-account: invalid password")
|
2023-03-22 17:48:42 +00:00
|
|
|
var ErrCreateAccountInvalidCustomizationColor = errors.New("create-account: invalid customization color")
|
2023-03-16 14:49:25 +00:00
|
|
|
var ErrCreateAccountInvalidRootKeystoreDir = errors.New("create-account: invalid root keystore directory")
|
2024-06-05 13:03:34 +00:00
|
|
|
var ErrCreateAccountInvalidRootDataDir = errors.New("create-account: invalid root data directory")
|
2024-03-28 15:01:44 +00:00
|
|
|
|
|
|
|
type ImageCropRectangle struct {
|
|
|
|
Ax int `json:"ax"`
|
|
|
|
Ay int `json:"ay"`
|
|
|
|
Bx int `json:"bx"`
|
|
|
|
By int `json:"by"`
|
|
|
|
}
|
2022-10-14 08:50:36 +00:00
|
|
|
|
2024-04-09 15:44:43 +00:00
|
|
|
type APIConfig struct {
|
2024-07-04 10:48:40 +00:00
|
|
|
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"`
|
2024-04-09 15:44:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 08:50:36 +00:00
|
|
|
type CreateAccount struct {
|
2024-06-05 13:03:34 +00:00
|
|
|
// RootDataDir is an absolute path to the root directory where all data will be stored.
|
|
|
|
RootDataDir string `json:"rootDataDir"`
|
|
|
|
KdfIterations int `json:"kdfIterations"`
|
2023-04-25 12:00:17 +00:00
|
|
|
|
2024-03-28 15:01:44 +00:00
|
|
|
DeviceName string `json:"deviceName"`
|
|
|
|
DisplayName string `json:"displayName"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
ImagePath string `json:"imagePath"`
|
|
|
|
ImageCropRectangle *ImageCropRectangle `json:"imageCropRectangle"`
|
|
|
|
CustomizationColor string `json:"customizationColor"`
|
2023-04-25 12:00:17 +00:00
|
|
|
|
2024-07-11 09:57:56 +00:00
|
|
|
WakuV2Nameserver *string `json:"wakuV2Nameserver"`
|
|
|
|
WakuV2LightClient bool `json:"wakuV2LightClient"`
|
|
|
|
WakuV2EnableStoreConfirmationForMessagesSent bool `json:"wakuV2EnableStoreConfirmationForMessagesSent"`
|
2024-07-26 19:19:19 +00:00
|
|
|
WakuV2EnableMissingMessageVerification bool `json:"wakuV2EnableMissingMessageVerification"`
|
2024-07-11 09:57:56 +00:00
|
|
|
WakuV2Fleet string `json:"wakuV2Fleet"`
|
2023-04-25 12:00:17 +00:00
|
|
|
|
|
|
|
LogLevel *string `json:"logLevel"`
|
2024-06-05 13:03:34 +00:00
|
|
|
LogFilePath string `json:"logFilePath"` // absolute path
|
2023-04-25 12:00:17 +00:00
|
|
|
LogEnabled bool `json:"logEnabled"`
|
|
|
|
|
|
|
|
PreviewPrivacy bool `json:"previewPrivacy"`
|
2023-03-16 14:49:25 +00:00
|
|
|
|
|
|
|
VerifyTransactionURL *string `json:"verifyTransactionURL"`
|
|
|
|
VerifyENSURL *string `json:"verifyENSURL"`
|
|
|
|
VerifyENSContractAddress *string `json:"verifyENSContractAddress"`
|
|
|
|
VerifyTransactionChainID *int64 `json:"verifyTransactionChainID"`
|
2023-03-28 14:47:58 +00:00
|
|
|
UpstreamConfig string `json:"upstreamConfig"`
|
2023-04-25 12:00:17 +00:00
|
|
|
|
2024-03-28 15:01:44 +00:00
|
|
|
// 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.
|
2024-06-02 18:28:55 +00:00
|
|
|
CurrentNetwork string `json:"currentNetwork"`
|
|
|
|
NetworkID *uint64 `json:"networkId"`
|
|
|
|
TestOverrideNetworks []params.Network `json:"-"` // This is used for testing purposes only
|
2023-05-24 15:02:53 +00:00
|
|
|
|
2024-03-26 11:38:16 +00:00
|
|
|
TestNetworksEnabled bool `json:"testNetworksEnabled"`
|
|
|
|
|
2023-05-24 15:02:53 +00:00
|
|
|
WalletSecretsConfig
|
2024-03-28 15:01:44 +00:00
|
|
|
|
|
|
|
TorrentConfigEnabled *bool
|
|
|
|
TorrentConfigPort *int
|
2024-04-09 15:44:43 +00:00
|
|
|
|
2024-05-22 22:01:54 +00:00
|
|
|
TelemetryServerURL string `json:"telemetryServerURL"`
|
|
|
|
|
2024-04-09 15:44:43 +00:00
|
|
|
APIConfig *APIConfig `json:"apiConfig"`
|
2024-06-26 11:14:27 +00:00
|
|
|
|
|
|
|
KeycardInstanceUID string `json:"keycardInstanceUID"`
|
|
|
|
KeycardPairingDataFile *string `json:"keycardPairingDataFile"`
|
2024-07-31 06:21:11 +00:00
|
|
|
StatusProxyEnabled bool `json:"statusProxyEnabled"`
|
2023-05-24 15:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type WalletSecretsConfig struct {
|
2023-10-12 19:40:13 +00:00
|
|
|
PoktToken string `json:"poktToken"`
|
|
|
|
InfuraToken string `json:"infuraToken"`
|
|
|
|
InfuraSecret string `json:"infuraSecret"`
|
|
|
|
OpenseaAPIKey string `json:"openseaApiKey"`
|
|
|
|
RaribleMainnetAPIKey string `json:"raribleMainnetApiKey"`
|
|
|
|
RaribleTestnetAPIKey string `json:"raribleTestnetApiKey"`
|
2023-04-25 12:00:17 +00:00
|
|
|
|
2024-07-31 06:21:11 +00:00
|
|
|
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"`
|
|
|
|
StatusProxyMarketUser string `json:"statusProxyMarketUser"`
|
|
|
|
StatusProxyMarketPassword string `json:"statusProxyMarketPassword"`
|
|
|
|
StatusProxyBlockchainUser string `json:"statusProxyBlockchainUser"`
|
|
|
|
StatusProxyBlockchainPassword string `json:"statusProxyBlockchainPassword"`
|
2024-07-30 13:48:22 +00:00
|
|
|
|
|
|
|
// Testing
|
|
|
|
GanacheURL string `json:"ganacheURL"`
|
2022-10-14 08:50:36 +00:00
|
|
|
}
|
|
|
|
|
2024-03-28 15:01:44 +00:00
|
|
|
func (c *CreateAccount) Validate(validation *CreateAccountValidation) error {
|
2022-10-14 08:50:36 +00:00
|
|
|
// TODO(cammellos): Add proper validation for password/displayname/etc
|
2024-03-28 15:01:44 +00:00
|
|
|
// Empty display name is allowed during account restore
|
|
|
|
if len(c.DisplayName) == 0 && !validation.AllowEmptyDisplayName {
|
2022-10-14 08:50:36 +00:00
|
|
|
return ErrCreateAccountInvalidDisplayName
|
|
|
|
}
|
|
|
|
|
2024-03-28 15:57:59 +00:00
|
|
|
if err := utils.ValidateDisplayName(&c.DisplayName); err != nil {
|
|
|
|
return errors.Wrap(ErrCreateAccountInvalidDisplayName, err.Error())
|
|
|
|
}
|
|
|
|
|
2022-10-14 08:50:36 +00:00
|
|
|
if len(c.Password) == 0 {
|
|
|
|
return ErrCreateAccountInvalidPassword
|
|
|
|
}
|
|
|
|
|
2023-03-22 17:48:42 +00:00
|
|
|
if len(c.CustomizationColor) == 0 {
|
|
|
|
return ErrCreateAccountInvalidCustomizationColor
|
2022-10-14 08:50:36 +00:00
|
|
|
}
|
|
|
|
|
2024-06-05 13:03:34 +00:00
|
|
|
if len(c.RootDataDir) == 0 {
|
2024-08-07 12:59:43 +00:00
|
|
|
return ErrCreateAccountInvalidRootDataDir
|
2023-03-16 14:49:25 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 08:50:36 +00:00
|
|
|
return nil
|
2024-03-28 15:01:44 +00:00
|
|
|
}
|
2022-10-14 08:50:36 +00:00
|
|
|
|
2024-03-28 15:01:44 +00:00
|
|
|
// NOTE: Reasoning for this struct here: https://github.com/status-im/status-go/pull/4980#discussion_r1539219099
|
|
|
|
type CreateAccountValidation struct {
|
|
|
|
AllowEmptyDisplayName bool
|
2022-10-14 08:50:36 +00:00
|
|
|
}
|