-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
125 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,22 @@ | ||
package requests | ||
|
||
import ( | ||
"errors" | ||
"gopkg.in/go-playground/validator.v9" | ||
) | ||
|
||
// DeleteImportedKey represents a request to delete an imported key. | ||
type DeleteImportedKey struct { | ||
// Address is the address of the imported key to delete. | ||
Address string `json:"address"` | ||
Address string `json:"address" validate:"required"` | ||
|
||
// Password is the password used to decrypt the key. | ||
Password string `json:"password"` | ||
Password string `json:"password" validate:"required"` | ||
|
||
// KeyStoreDir is the directory where the key is stored. | ||
KeyStoreDir string `json:"keyStoreDir"` | ||
KeyStoreDir string `json:"keyStoreDir" validate:"required"` | ||
} | ||
|
||
// Validate checks the validity of the DeleteImportedKey request. | ||
var ( | ||
ErrDeleteImportedKeyEmptyAddress = errors.New("delete-imported-key: Address cannot be empty") | ||
ErrDeleteImportedKeyEmptyPassword = errors.New("delete-imported-key: Password cannot be empty") | ||
ErrDeleteImportedKeyEmptyKeyStoreDir = errors.New("delete-imported-key: KeyStoreDir cannot be empty") | ||
) | ||
|
||
func (r *DeleteImportedKey) Validate() error { | ||
if r.Address == "" { | ||
return ErrDeleteImportedKeyEmptyAddress | ||
} | ||
if r.Password == "" { | ||
return ErrDeleteImportedKeyEmptyPassword | ||
} | ||
if r.KeyStoreDir == "" { | ||
return ErrDeleteImportedKeyEmptyKeyStoreDir | ||
} | ||
return nil | ||
return validator.New().Struct(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,26 @@ | ||
package requests | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/status-im/status-go/multiaccounts" | ||
"gopkg.in/go-playground/validator.v9" | ||
) | ||
|
||
// MigrateKeyStoreDir represents a request to migrate key files to a new directory. | ||
type MigrateKeyStoreDir struct { | ||
// Account represents the account associated with the key files. | ||
// MigrateKeystoreDir represents a request to migrate keystore directory. | ||
type MigrateKeystoreDir struct { | ||
// Account is the account associated with the keystore. | ||
Account multiaccounts.Account `json:"account"` | ||
|
||
// Password is the password used to decrypt the key files. | ||
Password string `json:"password"` | ||
// Password is the password for the keystore. | ||
Password string `json:"password" validate:"required"` | ||
|
||
// OldDir is the old directory path where the key files are currently located. | ||
OldDir string `json:"oldDir"` | ||
// OldDir is the old keystore directory. | ||
OldDir string `json:"oldDir" validate:"required"` | ||
|
||
// NewDir is the new directory path where the key files will be migrated to. | ||
NewDir string `json:"newDir"` | ||
// NewDir is the new keystore directory. | ||
NewDir string `json:"newDir" validate:"required"` | ||
} | ||
|
||
// Validate checks the validity of the MigrateKeyStoreDir request. | ||
var ( | ||
ErrMigrateKeyStoreDirEmptyAccount = errors.New("migrate-keystore-dir: Account cannot be empty") | ||
ErrMigrateKeyStoreDirEmptyPassword = errors.New("migrate-keystore-dir: Password cannot be empty") | ||
ErrMigrateKeyStoreDirEmptyOldDir = errors.New("migrate-keystore-dir: OldDir cannot be empty") | ||
ErrMigrateKeyStoreDirEmptyNewDir = errors.New("migrate-keystore-dir: NewDir cannot be empty") | ||
) | ||
|
||
func (r *MigrateKeyStoreDir) Validate() error { | ||
if r.Account.KeyUID == "" { | ||
return ErrMigrateKeyStoreDirEmptyAccount | ||
} | ||
if r.Password == "" { | ||
return ErrMigrateKeyStoreDirEmptyPassword | ||
} | ||
if r.OldDir == "" { | ||
return ErrMigrateKeyStoreDirEmptyOldDir | ||
} | ||
if r.NewDir == "" { | ||
return ErrMigrateKeyStoreDirEmptyNewDir | ||
} | ||
return nil | ||
// Validate checks the validity of the MigrateKeystoreDir request. | ||
func (r *MigrateKeystoreDir) Validate() error { | ||
return validator.New().Struct(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,34 @@ | ||
package requests | ||
|
||
import ( | ||
"errors" | ||
"gopkg.in/go-playground/validator.v9" | ||
|
||
"github.com/status-im/status-go/services/typeddata" | ||
) | ||
|
||
// SignTypedData represents a request to sign typed data. | ||
type SignTypedData struct { | ||
// TypedData is the typed data to sign. | ||
TypedData typeddata.TypedData `json:"typedData"` | ||
TypedData typeddata.TypedData `json:"typedData" validate:"required"` | ||
|
||
// Address is the address of the account to sign with. | ||
Address string `json:"address"` | ||
Address string `json:"address" validate:"required"` | ||
|
||
// Password is the password of the account to sign with. | ||
Password string `json:"password"` | ||
Password string `json:"password" validate:"required"` | ||
} | ||
|
||
// Validate checks the validity of the SignTypedData request. | ||
var ( | ||
ErrSignTypedDataEmptyTypedData = errors.New("sign-typed-data: TypedData cannot be empty") | ||
ErrSignTypedDataEmptyAddress = errors.New("sign-typed-data: Address cannot be empty") | ||
ErrSignTypedDataEmptyPassword = errors.New("sign-typed-data: Password cannot be empty") | ||
) | ||
|
||
func (r *SignTypedData) Validate() error { | ||
if err := r.TypedData.Validate(); err != nil { | ||
return ErrSignTypedDataEmptyTypedData | ||
} | ||
if r.Address == "" { | ||
return ErrSignTypedDataEmptyAddress | ||
// Use the validator package to validate the struct fields | ||
if err := validator.New().Struct(r); err != nil { | ||
return err | ||
} | ||
if r.Password == "" { | ||
return ErrSignTypedDataEmptyPassword | ||
|
||
// Additional validation logic from the old signTypedData function | ||
if err := r.TypedData.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.