status-go/protocol/requests/create_account.go

115 lines
4.3 KiB
Go
Raw Normal View History

2022-10-14 08:50:36 +00:00
package requests
import (
"github.com/pkg/errors"
utils "github.com/status-im/status-go/common"
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")
var ErrCreateAccountInvalidBackupDisabledDataDir = errors.New("create-account: invalid backup disabled 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
type CreateAccount struct {
// BackupDisabledDataDir is the directory where backup is disabled
2024-03-28 15:01:44 +00:00
// WARNING: This is used as `RootDataDir`. Consider renaming?
BackupDisabledDataDir string `json:"backupDisabledDataDir"`
2024-03-28 15:01:44 +00:00
KdfIterations int `json:"kdfIterations"`
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"`
Emoji string `json:"emoji"`
2023-07-03 12:48:21 +00:00
WakuV2Nameserver *string `json:"wakuV2Nameserver"`
WakuV2LightClient bool `json:"wakuV2LightClient"`
LogLevel *string `json:"logLevel"`
LogFilePath string `json:"logFilePath"`
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"`
UpstreamConfig string `json:"upstreamConfig"`
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.
CurrentNetwork string `json:"currentNetwork"`
NetworkID *uint64 `json:"networkId"`
TestNetworksEnabled bool `json:"testNetworksEnabled"`
WalletSecretsConfig
2024-03-28 15:01:44 +00:00
TorrentConfigEnabled *bool
TorrentConfigPort *int
}
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"`
// Testing
GanacheURL string `json:"ganacheURL"`
AlchemyEthereumMainnetToken string `json:"alchemyEthereumMainnetToken"`
AlchemyEthereumGoerliToken string `json:"alchemyEthereumGoerliToken"`
2023-11-16 20:46:01 +00:00
AlchemyEthereumSepoliaToken string `json:"alchemyEthereumSepoliaToken"`
AlchemyArbitrumMainnetToken string `json:"alchemyArbitrumMainnetToken"`
AlchemyArbitrumGoerliToken string `json:"alchemyArbitrumGoerliToken"`
2023-11-16 20:46:01 +00:00
AlchemyArbitrumSepoliaToken string `json:"alchemyArbitrumSepoliaToken"`
AlchemyOptimismMainnetToken string `json:"alchemyOptimismMainnetToken"`
AlchemyOptimismGoerliToken string `json:"alchemyOptimismGoerliToken"`
2023-11-16 20:46:01 +00:00
AlchemyOptimismSepoliaToken string `json:"alchemyOptimismSepoliaToken"`
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
}
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
}
2023-03-16 14:49:25 +00:00
if len(c.BackupDisabledDataDir) == 0 {
return ErrCreateAccountInvalidBackupDisabledDataDir
}
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
}