mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
ee1adddd24
* Fix accounts v2 runtime * Accounts V2: Fix issues found by rkapka * Add to help * Merge refs/heads/master into fix-v2-runtime * Merge refs/heads/master into fix-v2-runtime * Merge refs/heads/master into fix-v2-runtime * Merge refs/heads/master into fix-v2-runtime * Fixes * add back error * Make new wallet error cleaner * Fix text * Fix log * Add case for normal error * Update validator/flags/flags.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Merge branch 'master' of github.com:prysmaticlabs/prysm into fix-v2-runtime * Merge refs/heads/master into fix-v2-runtime * Fix comment * Merge refs/heads/master into fix-v2-runtime * fix comment * Fix test * Merge branch 'master' into fix-v2-runtime * Merge refs/heads/master into fix-v2-runtime * Merge refs/heads/master into fix-v2-runtime * Merge refs/heads/master into fix-v2-runtime * Merge refs/heads/master into fix-v2-runtime
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package derived
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/manifoldco/promptui"
|
|
"github.com/tyler-smith/go-bip39"
|
|
)
|
|
|
|
// SeedPhraseFactory defines a struct which
|
|
// can generate new seed phrases in human-readable
|
|
// format from a source of entropy in raw bytes. It
|
|
// also provides methods for verifying a user has successfully
|
|
// acknowledged the mnemonic phrase and written it down offline.
|
|
type SeedPhraseFactory interface {
|
|
Generate(data []byte) (string, error)
|
|
ConfirmAcknowledgement(phrase string) error
|
|
}
|
|
|
|
// EnglishMnemonicGenerator implements methods for creating
|
|
// mnemonic seed phrases in english using a given
|
|
// source of entropy such as a private key.
|
|
type EnglishMnemonicGenerator struct {
|
|
skipMnemonicConfirm bool
|
|
}
|
|
|
|
// Generate a mnemonic seed phrase in english using a source of
|
|
// entropy given as raw bytes.
|
|
func (m *EnglishMnemonicGenerator) Generate(data []byte) (string, error) {
|
|
return bip39.NewMnemonic(data)
|
|
}
|
|
|
|
// ConfirmAcknowledgement displays the mnemonic phrase to the user
|
|
// and confirms the user has written down the phrase securely offline.
|
|
func (m *EnglishMnemonicGenerator) ConfirmAcknowledgement(phrase string) error {
|
|
log.Info(
|
|
"Write down the sentence below, as it is your only " +
|
|
"means of recovering your wallet",
|
|
)
|
|
fmt.Printf(`
|
|
=================Wallet Seed Recovery Phrase====================
|
|
|
|
%s
|
|
|
|
===================================================================
|
|
`, phrase)
|
|
if m.skipMnemonicConfirm {
|
|
return nil
|
|
}
|
|
// Confirm the user has written down the mnemonic phrase offline.
|
|
prompt := promptui.Prompt{
|
|
Label: "Confirm you have written down the recovery words somewhere safe (offline)",
|
|
IsConfirm: true,
|
|
}
|
|
expected := "y"
|
|
var result string
|
|
var err error
|
|
for strings.ToLower(result) != expected {
|
|
result, err = prompt.Run()
|
|
if err != nil {
|
|
log.Errorf("Could not confirm acknowledgement of prompt, please enter y")
|
|
}
|
|
}
|
|
return nil
|
|
}
|