2023-02-28 12:32:45 +00:00
|
|
|
package pairing
|
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2023-02-28 12:32:45 +00:00
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
"github.com/status-im/status-go/account/generator"
|
|
|
|
"github.com/status-im/status-go/eth-node/keystore"
|
|
|
|
)
|
|
|
|
|
|
|
|
func validateKeys(keys map[string][]byte, password string) error {
|
|
|
|
for _, key := range keys {
|
|
|
|
k, err := keystore.DecryptKey(key, password)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = generator.ValidateKeystoreExtendedKey(k)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func emptyDir(dir string) error {
|
|
|
|
// Open the directory
|
|
|
|
d, err := os.Open(dir)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer d.Close()
|
|
|
|
|
|
|
|
// Get all the directory entries
|
|
|
|
entries, err := d.Readdir(-1)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all the files and directories
|
|
|
|
for _, entry := range entries {
|
|
|
|
name := entry.Name()
|
|
|
|
if name == "." || name == ".." {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
path := filepath.Join(dir, name)
|
|
|
|
if entry.IsDir() {
|
|
|
|
err = os.RemoveAll(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
err = os.Remove(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2023-02-28 12:32:45 +00:00
|
|
|
}
|
2023-03-23 11:44:15 +00:00
|
|
|
return nil
|
2023-02-28 12:32:45 +00:00
|
|
|
}
|