Return keyUID on succesfull validation of mnemonic

This commit is contained in:
Roman Volosovskyi 2023-03-28 10:12:37 +02:00
parent 268cd72e96
commit 91c6949cd2
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
4 changed files with 33 additions and 2 deletions

View File

@ -1 +1 @@
0.141.1
0.141.2

View File

@ -721,6 +721,17 @@ func (b *GethStatusBackend) RestoreAccountAndLogin(request *requests.RestoreAcco
return b.generateOrImportAccount(request.Mnemonic, &request.CreateAccount)
}
func (b *GethStatusBackend) GetKeyUIDByMnemonic(mnemonic string) (string, error) {
accountGenerator := b.accountManager.AccountsGenerator()
info, err := accountGenerator.ImportMnemonic(mnemonic, "")
if err != nil {
return "", err
}
return info.KeyUID, nil
}
func (b *GethStatusBackend) generateOrImportAccount(mnemonic string, request *requests.CreateAccount) error {
if err := b.accountManager.InitKeystore(filepath.Join(request.BackupDisabledDataDir, keystoreRelativePath)); err != nil {
return err

View File

@ -792,7 +792,22 @@ func ColorID(pk string) string {
func ValidateMnemonic(mnemonic string) string {
m := extkeys.NewMnemonic()
err := m.ValidateMnemonic(mnemonic, extkeys.Language(0))
if err != nil {
return makeJSONResponse(err)
}
keyUID, err := statusBackend.GetKeyUIDByMnemonic(mnemonic)
if err != nil {
return makeJSONResponse(err)
}
response := &APIKeyUIDResponse{KeyUID: keyUID}
data, err := json.Marshal(response)
if err != nil {
return makeJSONResponse(err)
}
return string(data)
}
// DecompressPublicKey decompresses 33-byte compressed format to uncompressed 65-byte format.

View File

@ -11,6 +11,11 @@ type APIResponse struct {
Error string `json:"error"`
}
// APIKeyUIDResponse
type APIKeyUIDResponse struct {
KeyUID string `json:"keyUID"`
}
// APIDetailedResponse represents a generic response
// with possible errors.
type APIDetailedResponse struct {