@@ -4,124 +4,93 @@ import (
4
4
"flag"
5
5
"fmt"
6
6
"os"
7
- "gowallet/address"
7
+ "gowallet/view"
8
+ "gowallet/wallet"
8
9
)
9
10
10
- const goWalletTip = `
11
- GoWallet uses a secret phrase and a salt phrase to generate your safe wallets.
12
- Project location: https://github.com/aiportal/gowallet
13
-
14
- Secret at least 16 characters, containing uppercase letters, lowercase letters, numbers, and special characters.
15
- salt at least 6 characters.
16
- Secret and salt allow the use of hexadecimal notation similar to '\xff' or '\xFF' to represent a character.
17
-
18
- It is advisable to use more complex secret and to write secret on paper.
19
- It is also recommended that salt be memorized in the brain.`
20
-
21
- const debug = true
22
- const trace = false
23
-
24
-
25
11
func main () {
26
- vanity , number , export := parseParams ()
27
-
28
- var passPhrase string
29
- if _ , err := os .Stat ("./gowallet.wlt" ); os .IsNotExist (err ) {
30
- // New wallets.
31
- var seed []byte
32
- if ! debug {
33
- secret , salt , err := address .InputBrainWalletSecret (goWalletTip )
34
- if err != nil {
35
- println (err .Error ())
36
- return
37
- }
38
- if trace {
39
- println ("your secret is: " + secret )
40
- println ("your salt is: " + salt )
41
- }
42
- passPhrase = salt
43
- seed , err = address .GenerateBrainWalletSeed (secret , salt )
44
- if err != nil {
45
- println (err .Error ())
46
- return
47
- }
48
- } else {
49
- seed , err = address .GenerateBrainWalletSeed ("https://github.com/aiportal" , "gowallet" )
50
- if err != nil {
51
- println (err .Error ())
52
- return
53
- }
54
- passPhrase = "gowallet"
55
- }
56
-
57
- accountKey , accountPub , err := address .GenerateAccount (seed [:], 0 )
12
+ number , vanity , export := parseParams ()
13
+ if number > 0 {
14
+ err := generateWallets (uint32 (number ), vanity , export )
58
15
if err != nil {
59
16
println (err .Error ())
60
17
return
61
18
}
62
- fmt .Println ("" )
63
- fmt .Println ("Main account: " )
64
- // fmt.Printf(" key: %s\n", accountKey)
65
- fmt .Printf (" pub: %s\n " , accountPub )
19
+ } else {
20
+ view .ShowSplashView (view .SplashStartView )
66
21
67
- if vanity == "" {
68
- wallets , err := address .GenerateWallets (accountKey , uint32 (number ))
22
+ var ws []* wallet.Wallet
23
+ if ! wallet .IsFileExists () {
24
+ var err error
25
+ ws , err = createWallets (1 , 10 )
69
26
if err != nil {
70
- println (err .Error ())
27
+ fmt . Println (err .Error ())
71
28
return
72
29
}
73
- for i , w := range wallets {
74
- encrypt , err := address .EncryptKey (w [0 ], passPhrase )
75
- if err != nil {
76
- println (err .Error ())
77
- encrypt = w [0 ]
78
- }
79
- fmt .Printf ("wallet(%d): \n " , i )
80
- fmt .Printf (" private: %s\n " , encrypt )
81
- fmt .Printf (" address: %s\n " , w [1 ])
82
- }
83
- if export != "" {
84
- err := exportWallets (export , wallets )
85
- if err != nil {
86
- println (err .Error ())
87
- return
88
- }
89
- }
30
+ // save wallets
31
+ wf := wallet .NewWalletFile (ws )
32
+ wf .Save ()
90
33
} else {
91
- wallets , err := address .SearchVanities (accountKey , vanity , uint32 (number ),
92
- func (i uint32 , count uint32 , n uint32 ) {
93
- fmt .Printf ("processed:%d / %d, found: %d \n " , i , count , n )
94
- })
34
+ wf , err := wallet .LoadWalletFile ()
95
35
if err != nil {
96
- println (err .Error ())
36
+ fmt . Println (err .Error ())
97
37
return
98
38
}
99
- for _ , w := range wallets {
100
- fmt .Printf ("wallet(%s): \n " , w [2 ])
101
- fmt .Printf (" private: %s\n " , w [0 ])
102
- fmt .Printf (" address: %s\n " , w [1 ])
103
- }
104
- if export != "" {
105
- err := exportWallets (export , wallets )
106
- if err != nil {
107
- println (err .Error ())
108
- return
109
- }
110
- }
39
+ ws = wf .Wallets
111
40
}
112
- } else {
113
- // Open wallets file.
41
+
42
+ showUI (ws )
43
+ }
44
+ }
45
+
46
+ func showUI (ws []* wallet.Wallet ) {
47
+
48
+ accountView := view .NewAccountView (ws )
49
+ accountView .Show ()
50
+
51
+ for accountView .Data != nil {
52
+ cmd := accountView .Data .(string )
53
+ if cmd == "quit" {
54
+ break
55
+ }
56
+ tipView := view .NewTipView (cmd )
57
+ if tipView != nil {
58
+ tipView .Show ()
59
+ }
60
+ accountView .Show ()
114
61
}
115
62
}
116
63
64
+ // create wallets by secret and salt
65
+ func createWallets (start , count uint32 ) (ws []* wallet.Wallet , err error ) {
66
+ view .ShowSplashView (view .SplashCreateView )
67
+
68
+ // create wallets
69
+ wp , err := view .InputNewParameters (3 )
70
+ if err != nil {
71
+ return
72
+ }
73
+ //wp := view.WalletParam{Secret:"https://github.com/aiportal", Salt:"gowallet"}
74
+
75
+ wa , err := wallet .NewWalletAccount (wp .SecretBytes (), wp .SaltBytes ())
76
+ if err != nil {
77
+ return
78
+ }
79
+ ws , err = wa .GenerateWallets (start , count )
80
+ if err != nil {
81
+ return
82
+ }
83
+ return
84
+ }
85
+
117
86
//Parse command line parameters
118
- func parseParams () (vanity string , number uint , export string ) {
87
+ func parseParams () (number uint , vanity , export string ) {
119
88
120
- flag .StringVar ( & vanity , "vanity " , "" , "Find vanity wallet address matching. (prefix or regular) " )
121
- flag .StringVar ( & vanity , "v " , "" , "Find vanity wallet address matching. (prefix or regular) " )
89
+ flag .UintVar ( & number , "number " , 0 , "Number of wallets to generate. " )
90
+ flag .UintVar ( & number , "n " , 0 , "Number of wallets to generate. " )
122
91
123
- flag .UintVar ( & number , "number " , 1 , "Number of wallets to generate . (default 1 )" )
124
- flag .UintVar ( & number , "n " , 1 , "Number of wallets to generate . (default 1 )" )
92
+ flag .StringVar ( & vanity , "vanity " , "" , "Find vanity wallet address matching . (prefix )" )
93
+ flag .StringVar ( & vanity , "v " , "" , "Find vanity wallet address matching . (prefix )" )
125
94
126
95
flag .StringVar (& export , "export" , "" , "Export wallets in WIF format." )
127
96
flag .StringVar (& export , "e" , "" , "Export wallets in WIF format." )
@@ -130,21 +99,53 @@ func parseParams() (vanity string, number uint, export string) {
130
99
return
131
100
}
132
101
133
- // Export wallets
134
- func exportWallets (filename string , wallets [][]string ) (err error ) {
135
- f , err := os .Create (filename )
102
+ func generateWallets (number uint32 , vanity , export string ) (err error ) {
103
+
104
+ view .ShowSplashView (view .SplashStartView )
105
+ view .ShowSplashView (view .SplashCreateView )
106
+ wp , err := view .InputNewParameters (3 )
136
107
if err != nil {
137
108
return
138
109
}
139
- defer f .Close ()
140
- for i , w := range wallets {
141
- if len (w ) > 2 {
142
- f .WriteString (fmt .Sprintf ("wallet(%s): \n " , w [2 ]))
143
- } else {
144
- f .WriteString (fmt .Sprintf ("wallet(%d): \n " , i ))
110
+ wa , err := wallet .NewWalletAccount (wp .SecretBytes (), wp .SaltBytes ())
111
+ if err != nil {
112
+ return
113
+ }
114
+ var ws []* wallet.Wallet
115
+ if vanity == "" {
116
+ ws , err = wa .GenerateWallets (0 , uint32 (number ))
117
+ if err != nil {
118
+ return
119
+ }
120
+ } else {
121
+ var patterns []string
122
+ patterns , err = wa .NormalizeVanities ([]string {vanity })
123
+ if err != nil {
124
+ return
125
+ }
126
+ ws , err = wa .FindVanities (patterns , func (i , c , n uint32 ) bool {
127
+ fmt .Printf ("progress: %d, %d, %d\n " , i , c , n )
128
+ return (n >= number )
129
+ })
130
+ }
131
+ if export == "" {
132
+ for _ , w := range ws {
133
+ fmt .Printf ("wallet (%d): \n " , w .No )
134
+ fmt .Println (" " + w .Private )
135
+ fmt .Println (" " + w .Address )
136
+ }
137
+ } else {
138
+ var f * os.File
139
+ f , err = os .Create (export )
140
+ if err != nil {
141
+ return
142
+ }
143
+ defer f .Close ()
144
+ for _ , w := range ws {
145
+ f .WriteString (fmt .Sprintf ("wallet(%d): \r \n " , w .No ))
146
+ f .WriteString (fmt .Sprintf (" private: %s\r \n " , w .Private ))
147
+ f .WriteString (fmt .Sprintf (" address: %s\r \n " , w .Address ))
145
148
}
146
- f .WriteString (fmt .Sprintf (" private: %s\n " , w [0 ]))
147
- f .WriteString (fmt .Sprintf (" address: %s\n " , w [1 ]))
148
149
}
149
150
return
150
151
}
0 commit comments