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,9 +792,24 @@ 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.
|
||||
func DecompressPublicKey(key string) string {
|
||||
decoded, err := types.DecodeHex(key)
|
||||
|
|
|
@ -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