require seed for account creation

This commit is contained in:
Fabian
2018-03-17 22:14:19 +01:00
committed by Ethan Buchman
parent f8a34094bf
commit 4ef129d9e6
2 changed files with 41 additions and 12 deletions
+11 -9
View File
@@ -129,9 +129,7 @@ func printCreate(info keys.Info, seed string) {
type NewKeyBody struct {
Name string `json:"name"`
Password string `json:"password"`
// TODO make seed mandatory
// Seed string `json="seed"`
Type string `json:"type"`
Seed string `json="seed"`
}
func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
@@ -157,14 +155,18 @@ func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("You have to specify a name for the locally stored account."))
return
}
// algo type defaults to ed25519
if m.Type == "" {
m.Type = "ed25519"
if m.Password == "" {
w.WriteHeader(400)
w.Write([]byte("You have to specify a password for the locally stored account."))
return
}
if m.Seed == "" {
w.WriteHeader(400)
w.Write([]byte("You have to specify a seed for the locally stored account."))
return
}
algo := keys.CryptoAlgo(m.Type)
info, _, err := kb.Create(m.Name, m.Password, algo)
info, err := kb.Recover(m.Name, m.Password, m.Seed)
// TODO handle different errors
if err != nil {
w.WriteHeader(500)