Return keyUID on succesfull validation of mnemonic
This commit is contained in:
parent
268cd72e96
commit
91c6949cd2
|
@ -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
|
||||
|
|
|
@ -792,7 +792,22 @@ func ColorID(pk string) string {
|
|||
func ValidateMnemonic(mnemonic string) string {
|
||||
m := extkeys.NewMnemonic()
|
||||
err := m.ValidateMnemonic(mnemonic, extkeys.Language(0))
|
||||
return makeJSONResponse(err)
|
||||
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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue