-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.go
38 lines (32 loc) · 993 Bytes
/
new.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package key
import (
"fmt"
"github.com/spf13/cobra"
"github.com/dnerochain/dnero/cmd/dnerocli/cmd/utils"
"github.com/dnerochain/dnero/wallet"
wtypes "github.com/dnerochain/dnero/wallet/types"
)
// newCmd generates a new key
var newCmd = &cobra.Command{
Use: "new",
Short: "Generates a new private key",
Long: `Generates a new private key.`,
Example: "dnerocli key new",
Run: func(cmd *cobra.Command, args []string) {
cfgPath := cmd.Flag("config").Value.String()
wallet, err := wallet.OpenWallet(cfgPath, wtypes.WalletTypeSoft, true)
if err != nil {
utils.Error("Failed to open wallet: %v\n", err)
}
prompt := fmt.Sprintf("Please enter password: ")
password, err := utils.GetPassword(prompt)
if err != nil {
utils.Error("Failed to get password: %v\n", err)
}
address, err := wallet.NewKey(password)
if err != nil {
utils.Error("Failed to generate new key: %v\n", err)
}
fmt.Printf("Successfully created key: %v\n", address.Hex())
},
}