Skip to content

Commit 38c8c30

Browse files
committed
accounts, cmd: add note about backing up the keystore (ethereum#19432)
1 parent de04fe3 commit 38c8c30

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

accounts/keystore/passphrase.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"os"
3838
"path/filepath"
3939

40+
"github.com/XinFinOrg/XDPoSChain/accounts"
4041
"github.com/XinFinOrg/XDPoSChain/common"
4142
"github.com/XinFinOrg/XDPoSChain/common/math"
4243
"github.com/XinFinOrg/XDPoSChain/crypto"
@@ -96,9 +97,9 @@ func (ks keyStorePassphrase) GetKey(addr common.Address, filename, auth string)
9697
}
9798

9899
// StoreKey generates a key, encrypts with 'auth' and stores in the given directory
99-
func StoreKey(dir, auth string, scryptN, scryptP int) (common.Address, error) {
100+
func StoreKey(dir, auth string, scryptN, scryptP int) (accounts.Account, error) {
100101
_, a, err := storeNewKey(&keyStorePassphrase{dir, scryptN, scryptP, false}, rand.Reader, auth)
101-
return a.Address, err
102+
return a, err
102103
}
103104

104105
func (ks keyStorePassphrase) StoreKey(filename string, key *Key, auth string) error {

cmd/XDC/accountcmd.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,18 @@ func accountCreate(ctx *cli.Context) error {
310310

311311
password := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx))
312312

313-
address, err := keystore.StoreKey(keydir, password, scryptN, scryptP)
313+
account, err := keystore.StoreKey(keydir, password, scryptN, scryptP)
314314

315315
if err != nil {
316316
utils.Fatalf("Failed to create account: %v", err)
317317
}
318-
fmt.Printf("Address: {xdc%x}\n", address)
318+
fmt.Printf("\nYour new key was generated\n\n")
319+
fmt.Printf("Public address of the key: %s\n", account.Address.Hex())
320+
fmt.Printf("Path of the secret key file: %s\n\n", account.URL.Path)
321+
fmt.Printf("- You can share your public address with anyone. Others need it to interact with you.\n")
322+
fmt.Printf("- You must NEVER share the secret key with anyone! The key controls access to your funds!\n")
323+
fmt.Printf("- You must BACKUP your key file! Without the key, it's impossible to access account funds!\n")
324+
fmt.Printf("- You must REMEMBER your password! Without the password, it's impossible to decrypt the key!\n\n")
319325
return nil
320326
}
321327

cmd/XDC/accountcmd_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,20 @@ Your new account is locked with a password. Please give a password. Do not forge
7979
!! Unsupported terminal, password will be echoed.
8080
Passphrase: {{.InputLine "foobar"}}
8181
Repeat passphrase: {{.InputLine "foobar"}}
82+
83+
Your new key was generated
84+
85+
`)
86+
XDC.ExpectRegexp(`
87+
Public address of the key: xdc[0-9a-fA-F]{40}
88+
Path of the secret key file: .*UTC--.+--xdc[0-9a-fA-F]{40}
89+
90+
- You can share your public address with anyone. Others need it to interact with you.
91+
- You must NEVER share the secret key with anyone! The key controls access to your funds!
92+
- You must BACKUP your key file! Without the key, it's impossible to access account funds!
93+
- You must REMEMBER your password! Without the password, it's impossible to decrypt the key!
94+
8295
`)
83-
XDC.ExpectRegexp(`Address: \{xdc[0-9a-f]{40}\}\n`)
8496
}
8597

8698
func TestAccountNewBadRepeat(t *testing.T) {

0 commit comments

Comments
 (0)