You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.6 KiB
81 lines
1.6 KiB
package blsgen
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
bls_core "github.com/woop-chain/bls/ffi/go/bls"
|
|
)
|
|
|
|
func loadBasicKeyWithProvider(blsKeyFile string, pp passProvider) (*bls_core.SecretKey, error) {
|
|
pass, err := pp.getPassphrase(blsKeyFile)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
secretKey, err := LoadBLSKeyWithPassPhrase(blsKeyFile, pass)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return secretKey, nil
|
|
}
|
|
|
|
func checkIsFile(path string) error {
|
|
info, err := os.Stat(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if info.IsDir() {
|
|
return fmt.Errorf("%v is directory", path)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func checkIsDir(path string) error {
|
|
info, err := os.Stat(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !info.IsDir() {
|
|
return fmt.Errorf("%v is a file", path)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func keyFileToPassFileFull(keyFile string) string {
|
|
return strings.TrimSuffix(keyFile, basicKeyExt) + passExt
|
|
}
|
|
|
|
func promptGetPassword(prompt string) (string, error) {
|
|
if !strings.HasSuffix(prompt, ":") {
|
|
prompt += ":"
|
|
}
|
|
console.print(prompt)
|
|
return console.readPassword()
|
|
}
|
|
|
|
const yesNoPrompt = "[y/n]: "
|
|
|
|
func promptYesNo(prompt string) (bool, error) {
|
|
if !strings.HasSuffix(prompt, yesNoPrompt) {
|
|
prompt = prompt + yesNoPrompt
|
|
}
|
|
for {
|
|
console.print(prompt)
|
|
response, err := console.readln()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
response = strings.TrimSpace(strings.ToLower(response))
|
|
|
|
if response == "y" || response == "yes" {
|
|
return true, nil
|
|
} else if response == "n" || response == "no" {
|
|
return false, nil
|
|
}
|
|
}
|
|
}
|
|
|
|
func stringIsSet(val *string) bool {
|
|
return val != nil && *val != ""
|
|
}
|
|
|