mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
9d979de4ed
* implementation using petname and keystore * writing new account to disk along with password * more logic for properly writing accounts * print out mnemonic * save deposit data rlp * write deposit tx and ssz deposit data to account path * wrap up account creation * fix prompt * generate deposit tx * direct account creation test * fix up formatting * lint * match formatting * more sustainable approach towards unmarshaling config file * resolve feedback * fix broken import * comprehensive tests for create account * tests pass * Merge branch 'master' into direct-keys * tidy * Merge branch 'direct-keys' of github.com:prysmaticlabs/prysm into direct-keys * Merge refs/heads/master into direct-keys * gaz * Merge branch 'direct-keys' of github.com:prysmaticlabs/prysm into direct-keys * nondeterministic names * comment * gaz * better error wrap * Merge refs/heads/master into direct-keys * docker deps * Merge branch 'direct-keys' of github.com:prysmaticlabs/prysm into direct-keys * Merge refs/heads/master into direct-keys * Merge refs/heads/master into direct-keys * Merge refs/heads/master into direct-keys * Merge refs/heads/master into direct-keys * Merge refs/heads/master into direct-keys * Merge refs/heads/master into direct-keys * Merge refs/heads/master into direct-keys * Merge refs/heads/master into direct-keys * Merge refs/heads/master into direct-keys * ivan feedback * Merge refs/heads/master into direct-keys * Update validator/accounts/v2/wallet.go Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * fixed tests and comments * Merge refs/heads/master into direct-keys
61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
package direct
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"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{}
|
|
|
|
// 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 withdrawal key",
|
|
)
|
|
fmt.Printf(`
|
|
=================Withdrawal Key Recovery Phrase====================
|
|
|
|
%s
|
|
|
|
===================================================================
|
|
`, phrase)
|
|
// 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 result != expected {
|
|
result, err = prompt.Run()
|
|
if err != nil {
|
|
log.Errorf("Could not confirm acknowledgement of prompt, please enter y")
|
|
}
|
|
}
|
|
return nil
|
|
}
|