From 54d0cf28c714af150bf84ee842b8a06cde4df667 Mon Sep 17 00:00:00 2001 From: Omar Basem Date: Mon, 19 Feb 2024 16:53:01 +0400 Subject: [PATCH] feat: mobile status.go - getRandomMnemonic (#4712) * feat: mobile status.go - getRandomMnemonic (#4712) --- VERSION | 2 +- account/accounts.go | 10 ---------- account/utils.go | 11 +++++++++++ mobile/status.go | 9 +++++++++ services/accounts/accounts.go | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/VERSION b/VERSION index 66007cbb5..e99e78f80 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.174.9 +0.175.1 \ No newline at end of file diff --git a/account/accounts.go b/account/accounts.go index d6ef097d0..7cc1cfc0f 100644 --- a/account/accounts.go +++ b/account/accounts.go @@ -114,16 +114,6 @@ func (m *DefaultManager) AccountsGenerator() *generator.Generator { return m.accountsGenerator } -func (m *DefaultManager) GetRandomMnemonic() (string, error) { - // generate mnemonic phrase - mn := extkeys.NewMnemonic() - mnemonic, err := mn.MnemonicPhrase(extkeys.EntropyStrength128, extkeys.EnglishLanguage) - if err != nil { - return "", fmt.Errorf("can not create mnemonic seed: %v", err) - } - return mnemonic, nil -} - // CreateAccount creates an internal geth account // BIP44-compatible keys are generated: CKD#1 is stored as account key, CKD#2 stored as sub-account root // Public key of CKD#1 is returned, with CKD#2 securely encoded into account key file (to be used for diff --git a/account/utils.go b/account/utils.go index 2022979a9..c33e65536 100644 --- a/account/utils.go +++ b/account/utils.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/status-im/status-go/eth-node/types" + "github.com/status-im/status-go/extkeys" "github.com/status-im/status-go/multiaccounts" ) @@ -117,3 +118,13 @@ func ToAddress(accountAddress string) *types.Address { return &to.Address } + +func GetRandomMnemonic() (string, error) { + // generate mnemonic phrase + mn := extkeys.NewMnemonic() + mnemonic, err := mn.MnemonicPhrase(extkeys.EntropyStrength128, extkeys.EnglishLanguage) + if err != nil { + return "", fmt.Errorf("can not create mnemonic seed: %v", err) + } + return mnemonic, nil +} diff --git a/mobile/status.go b/mobile/status.go index 5eac0ad3e..0b5fa4e98 100644 --- a/mobile/status.go +++ b/mobile/status.go @@ -18,6 +18,7 @@ import ( "github.com/status-im/zxcvbn-go/scoring" abi_spec "github.com/status-im/status-go/abi-spec" + "github.com/status-im/status-go/account" "github.com/status-im/status-go/api" "github.com/status-im/status-go/api/multiformat" "github.com/status-im/status-go/eth-node/crypto" @@ -1327,3 +1328,11 @@ func InitLogging(logSettingsJSON string) string { return makeJSONResponse(err) } + +func GetRandomMnemonic() string { + mnemonic, err := account.GetRandomMnemonic() + if err != nil { + return makeJSONResponse(err) + } + return mnemonic +} diff --git a/services/accounts/accounts.go b/services/accounts/accounts.go index 56574b851..a47413497 100644 --- a/services/accounts/accounts.go +++ b/services/accounts/accounts.go @@ -456,7 +456,7 @@ func (api *API) MakeSeedPhraseKeypairFullyOperable(ctx context.Context, mnemonic // Creates a random new mnemonic. func (api *API) GetRandomMnemonic(ctx context.Context) (string, error) { - return api.manager.GetRandomMnemonic() + return account.GetRandomMnemonic() } func (api *API) VerifyKeystoreFileForAccount(address types.Address, password string) bool {