feat: mobile status.go - getRandomMnemonic (#4712)

* feat: mobile status.go - getRandomMnemonic (#4712)
This commit is contained in:
Omar Basem 2024-02-19 16:53:01 +04:00 committed by GitHub
parent 38ee792081
commit 54d0cf28c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 12 deletions

View File

@ -1 +1 @@
0.174.9 0.175.1

View File

@ -114,16 +114,6 @@ func (m *DefaultManager) AccountsGenerator() *generator.Generator {
return m.accountsGenerator 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 // 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 // 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 // Public key of CKD#1 is returned, with CKD#2 securely encoded into account key file (to be used for

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/extkeys"
"github.com/status-im/status-go/multiaccounts" "github.com/status-im/status-go/multiaccounts"
) )
@ -117,3 +118,13 @@ func ToAddress(accountAddress string) *types.Address {
return &to.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
}

View File

@ -18,6 +18,7 @@ import (
"github.com/status-im/zxcvbn-go/scoring" "github.com/status-im/zxcvbn-go/scoring"
abi_spec "github.com/status-im/status-go/abi-spec" 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"
"github.com/status-im/status-go/api/multiformat" "github.com/status-im/status-go/api/multiformat"
"github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/eth-node/crypto"
@ -1327,3 +1328,11 @@ func InitLogging(logSettingsJSON string) string {
return makeJSONResponse(err) return makeJSONResponse(err)
} }
func GetRandomMnemonic() string {
mnemonic, err := account.GetRandomMnemonic()
if err != nil {
return makeJSONResponse(err)
}
return mnemonic
}

View File

@ -456,7 +456,7 @@ func (api *API) MakeSeedPhraseKeypairFullyOperable(ctx context.Context, mnemonic
// Creates a random new mnemonic. // Creates a random new mnemonic.
func (api *API) GetRandomMnemonic(ctx context.Context) (string, error) { 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 { func (api *API) VerifyKeystoreFileForAccount(address types.Address, password string) bool {