-
Notifications
You must be signed in to change notification settings - Fork 10
/
dump_unencrypted_data.go
77 lines (62 loc) · 1.74 KB
/
dump_unencrypted_data.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"bufio"
"fmt"
"os"
"github.com/sedracoin/sedrad/cmd/sedrawallet/keys"
"github.com/sedracoin/sedrad/cmd/sedrawallet/libsedrawallet"
"github.com/sedracoin/sedrad/cmd/sedrawallet/utils"
"github.com/pkg/errors"
)
func dumpUnencryptedData(conf *dumpUnencryptedDataConfig) error {
if !conf.Yes {
err := confirmDump()
if err != nil {
return err
}
}
keysFile, err := keys.ReadKeysFile(conf.NetParams(), conf.KeysFile)
if err != nil {
return err
}
if len(conf.Password) == 0 {
conf.Password = keys.GetPassword("Password:")
}
mnemonics, err := keysFile.DecryptMnemonics(conf.Password)
if err != nil {
return err
}
mnemonicPublicKeys := make(map[string]struct{})
for i, mnemonic := range mnemonics {
fmt.Printf("Mnemonic #%d:\n%s\n\n", i+1, mnemonic)
publicKey, err := libsedrawallet.MasterPublicKeyFromMnemonic(conf.NetParams(), mnemonic, len(keysFile.ExtendedPublicKeys) > 1)
if err != nil {
return err
}
mnemonicPublicKeys[publicKey] = struct{}{}
}
i := 1
for _, extendedPublicKey := range keysFile.ExtendedPublicKeys {
if _, exists := mnemonicPublicKeys[extendedPublicKey]; exists {
continue
}
fmt.Printf("Extended Public key #%d:\n%s\n\n", i, extendedPublicKey)
i++
}
fmt.Printf("Minimum number of signatures: %d\n", keysFile.MinimumSignatures)
return nil
}
func confirmDump() error {
reader := bufio.NewReader(os.Stdin)
fmt.Printf("This operation will print your unencrypted keys on the screen. Anyone that sees this information " +
"will be able to steal your funds. Are you sure you want to proceed (y/N)? ")
line, err := utils.ReadLine(reader)
if err != nil {
return err
}
fmt.Println()
if string(line) != "y" {
return errors.Errorf("Dump aborted by user")
}
return nil
}