-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.go
106 lines (97 loc) · 2.45 KB
/
main.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"crypto/ecdsa"
"crypto/rand"
"encoding/hex"
"flag"
"fmt"
"log"
"os"
"regexp"
"runtime"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
const (
colorGreen = "\u001b[32m"
colorReset = "\u001b[0m"
)
var (
alphabet = regexp.MustCompile("^[0-9a-f]*$")
numWorkers = runtime.NumCPU()
)
// Wallet stores private key and address containing desired substring at Index
type Wallet struct {
Address common.Address
PrivateKey *ecdsa.PrivateKey
}
func main() {
var one bool
var prefix, suffix string
flag.BoolVar(&one, "one", false, "Stop after finding first address")
flag.StringVar(&prefix, "p", "", "Public address prefix")
flag.StringVar(&suffix, "s", "", "Public address suffix")
flag.Parse()
if prefix == "" && suffix == "" {
fmt.Printf(`
This tool generates Ethereum public and private keypair until it finds address
which contains required prefix and/or suffix.
Address part can contain only digits and letters from A to F.
For fast results suggested length of sum of preffix and suffix is 4-6 characters.
If you want more, be patient.
Usage:
`)
flag.PrintDefaults()
os.Exit(1)
}
if !alphabet.MatchString(prefix) {
fmt.Println("Prefix must match the alphabet:", alphabet.String())
os.Exit(2)
}
if !alphabet.MatchString(suffix) {
fmt.Println("Suffix must match the alphabet:", alphabet.String())
os.Exit(3)
}
walletChan := make(chan Wallet)
for i := 0; i < numWorkers; i++ {
go generateWallet(prefix, suffix, walletChan)
}
for w := range walletChan {
addressHex := w.Address.Hex()[2:]
privateKeyHex := hex.EncodeToString(crypto.FromECDSA(w.PrivateKey))
fmt.Printf(
"Address: 0x%s%s%s%s%s%s%s PrivateKey: %s\n",
colorGreen,
addressHex[:len(prefix)],
colorReset,
addressHex[len(prefix):len(addressHex)-len(suffix)],
colorGreen,
addressHex[len(addressHex)-len(suffix):],
colorReset,
privateKeyHex)
if one {
break
}
}
}
func generateWallet(prefix, suffix string, walletChan chan Wallet) {
for {
privateKey, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader)
if err != nil {
log.Fatal(err)
}
address := crypto.PubkeyToAddress(privateKey.PublicKey)
addressHex := hex.EncodeToString(address[:])
if prefix != "" && !strings.HasPrefix(addressHex, prefix) {
continue
}
if suffix != "" && !strings.HasSuffix(addressHex, suffix) {
continue
}
walletChan <- Wallet{
Address: address,
PrivateKey: privateKey,
}
}
}