mirror of
https://github.com/status-im/status-go.git
synced 2025-02-23 04:08:27 +00:00
feat: 5 functions added, the same as we had, but without pass verification (need for a keycard users)
The following three new functions introduced, for which password should be verified on the client side (in case of a keycard user we don't have keystores to check pass): - `AddAccountWithMnemonicPasswordVerified` - `AddAccountWithMnemonicAndPathPasswordVerified` - `AddAccountWithPrivateKeyPasswordVerified` - `GenerateAccountPasswordVerified` - `GenerateAccountWithDerivedPathPasswordVerified` update
This commit is contained in:
parent
b0b23076a0
commit
c2b17acc07
@ -110,6 +110,17 @@ func (api *API) AddAccountWithMnemonic(
|
|||||||
return api.addAccountWithMnemonic(ctx, mnemonic, password, name, color, emoji, pathWalletRoot)
|
return api.addAccountWithMnemonic(ctx, mnemonic, password, name, color, emoji, pathWalletRoot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *API) AddAccountWithMnemonicPasswordVerified(
|
||||||
|
ctx context.Context,
|
||||||
|
mnemonic string,
|
||||||
|
password string,
|
||||||
|
name string,
|
||||||
|
color string,
|
||||||
|
emoji string,
|
||||||
|
) error {
|
||||||
|
return api.addAccountWithMnemonicPasswordVerified(ctx, mnemonic, password, name, color, emoji, pathWalletRoot)
|
||||||
|
}
|
||||||
|
|
||||||
func (api *API) AddAccountWithMnemonicAndPath(
|
func (api *API) AddAccountWithMnemonicAndPath(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
mnemonic string,
|
mnemonic string,
|
||||||
@ -122,7 +133,21 @@ func (api *API) AddAccountWithMnemonicAndPath(
|
|||||||
return api.addAccountWithMnemonic(ctx, mnemonic, password, name, color, emoji, path)
|
return api.addAccountWithMnemonic(ctx, mnemonic, password, name, color, emoji, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) AddAccountWithPrivateKey(
|
func (api *API) AddAccountWithMnemonicAndPathPasswordVerified(
|
||||||
|
ctx context.Context,
|
||||||
|
mnemonic string,
|
||||||
|
password string,
|
||||||
|
name string,
|
||||||
|
color string,
|
||||||
|
emoji string,
|
||||||
|
path string,
|
||||||
|
) error {
|
||||||
|
return api.addAccountWithMnemonicPasswordVerified(ctx, mnemonic, password, name, color, emoji, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddAccountWithPrivateKeyPasswordVerified adds an accounts.Account created from the given private key
|
||||||
|
// assuming that client has already authenticated logged in use, this function doesn't verify a password.
|
||||||
|
func (api *API) AddAccountWithPrivateKeyPasswordVerified(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
privateKey string,
|
privateKey string,
|
||||||
password string,
|
password string,
|
||||||
@ -130,10 +155,6 @@ func (api *API) AddAccountWithPrivateKey(
|
|||||||
color string,
|
color string,
|
||||||
emoji string,
|
emoji string,
|
||||||
) error {
|
) error {
|
||||||
err := api.verifyPassword(password)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
info, err := api.manager.AccountsGenerator().ImportPrivateKey(privateKey)
|
info, err := api.manager.AccountsGenerator().ImportPrivateKey(privateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -167,6 +188,22 @@ func (api *API) AddAccountWithPrivateKey(
|
|||||||
return api.SaveAccounts(ctx, []*accounts.Account{account})
|
return api.SaveAccounts(ctx, []*accounts.Account{account})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *API) AddAccountWithPrivateKey(
|
||||||
|
ctx context.Context,
|
||||||
|
privateKey string,
|
||||||
|
password string,
|
||||||
|
name string,
|
||||||
|
color string,
|
||||||
|
emoji string,
|
||||||
|
) error {
|
||||||
|
err := api.verifyPassword(password)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return api.AddAccountWithPrivateKeyPasswordVerified(ctx, privateKey, password, name, color, emoji)
|
||||||
|
}
|
||||||
|
|
||||||
func (api *API) GenerateAccount(
|
func (api *API) GenerateAccount(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
password string,
|
password string,
|
||||||
@ -200,6 +237,39 @@ func (api *API) GenerateAccount(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *API) GenerateAccountPasswordVerified(
|
||||||
|
ctx context.Context,
|
||||||
|
password string,
|
||||||
|
name string,
|
||||||
|
color string,
|
||||||
|
emoji string,
|
||||||
|
) error {
|
||||||
|
address, err := api.db.GetWalletRootAddress()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
latestDerivedPath, err := api.db.GetLatestDerivedPath()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
newDerivedPath := latestDerivedPath + 1
|
||||||
|
path := fmt.Sprint(pathWalletRoot, "/", newDerivedPath)
|
||||||
|
|
||||||
|
err = api.generateAccountPasswordVerified(ctx, password, name, color, emoji, path, address.Hex())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = api.db.SaveSettingField(settings.LatestDerivedPath, newDerivedPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (api *API) GenerateAccountWithDerivedPath(
|
func (api *API) GenerateAccountWithDerivedPath(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
password string,
|
password string,
|
||||||
@ -212,6 +282,18 @@ func (api *API) GenerateAccountWithDerivedPath(
|
|||||||
return api.generateAccount(ctx, password, name, color, emoji, path, derivedFrom)
|
return api.generateAccount(ctx, password, name, color, emoji, path, derivedFrom)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *API) GenerateAccountWithDerivedPathPasswordVerified(
|
||||||
|
ctx context.Context,
|
||||||
|
password string,
|
||||||
|
name string,
|
||||||
|
color string,
|
||||||
|
emoji string,
|
||||||
|
path string,
|
||||||
|
derivedFrom string,
|
||||||
|
) error {
|
||||||
|
return api.generateAccountPasswordVerified(ctx, password, name, color, emoji, path, derivedFrom)
|
||||||
|
}
|
||||||
|
|
||||||
func (api *API) verifyPassword(password string) error {
|
func (api *API) verifyPassword(password string) error {
|
||||||
address, err := api.db.GetChatAddress()
|
address, err := api.db.GetChatAddress()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -221,7 +303,9 @@ func (api *API) verifyPassword(password string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) addAccountWithMnemonic(
|
// addAccountWithMnemonicPasswordVerified adds an accounts.Account derived from the given Mnemonic
|
||||||
|
// assuming that client has already authenticated logged in use, this function doesn't verify a password.
|
||||||
|
func (api *API) addAccountWithMnemonicPasswordVerified(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
mnemonic string,
|
mnemonic string,
|
||||||
password string,
|
password string,
|
||||||
@ -232,11 +316,6 @@ func (api *API) addAccountWithMnemonic(
|
|||||||
) error {
|
) error {
|
||||||
mnemonicNoExtraSpaces := strings.Join(strings.Fields(mnemonic), " ")
|
mnemonicNoExtraSpaces := strings.Join(strings.Fields(mnemonic), " ")
|
||||||
|
|
||||||
err := api.verifyPassword(password)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
generatedAccountInfo, err := api.manager.AccountsGenerator().ImportMnemonic(mnemonicNoExtraSpaces, "")
|
generatedAccountInfo, err := api.manager.AccountsGenerator().ImportMnemonic(mnemonicNoExtraSpaces, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -266,7 +345,26 @@ func (api *API) addAccountWithMnemonic(
|
|||||||
return api.SaveAccounts(ctx, []*accounts.Account{account})
|
return api.SaveAccounts(ctx, []*accounts.Account{account})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) generateAccount(
|
func (api *API) addAccountWithMnemonic(
|
||||||
|
ctx context.Context,
|
||||||
|
mnemonic string,
|
||||||
|
password string,
|
||||||
|
name string,
|
||||||
|
color string,
|
||||||
|
emoji string,
|
||||||
|
path string,
|
||||||
|
) error {
|
||||||
|
err := api.verifyPassword(password)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return api.addAccountWithMnemonicPasswordVerified(ctx, mnemonic, password, name, color, emoji, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// generateAccountPasswordVerified adds an accounts.Account generated from the given path
|
||||||
|
// assuming that client has already authenticated logged in use, this function doesn't verify a password.
|
||||||
|
func (api *API) generateAccountPasswordVerified(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
password string,
|
password string,
|
||||||
name string,
|
name string,
|
||||||
@ -275,11 +373,6 @@ func (api *API) generateAccount(
|
|||||||
path string,
|
path string,
|
||||||
address string,
|
address string,
|
||||||
) error {
|
) error {
|
||||||
err := api.verifyPassword(password)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
info, err := api.manager.AccountsGenerator().LoadAccount(address, password)
|
info, err := api.manager.AccountsGenerator().LoadAccount(address, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -310,6 +403,23 @@ func (api *API) generateAccount(
|
|||||||
return api.SaveAccounts(ctx, []*accounts.Account{acc})
|
return api.SaveAccounts(ctx, []*accounts.Account{acc})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *API) generateAccount(
|
||||||
|
ctx context.Context,
|
||||||
|
password string,
|
||||||
|
name string,
|
||||||
|
color string,
|
||||||
|
emoji string,
|
||||||
|
path string,
|
||||||
|
address string,
|
||||||
|
) error {
|
||||||
|
err := api.verifyPassword(password)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return api.generateAccountPasswordVerified(ctx, password, name, color, emoji, path, address)
|
||||||
|
}
|
||||||
|
|
||||||
func (api *API) VerifyPassword(password string) bool {
|
func (api *API) VerifyPassword(password string) bool {
|
||||||
err := api.verifyPassword(password)
|
err := api.verifyPassword(password)
|
||||||
return err == nil
|
return err == nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user