forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (46 loc) · 1.13 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
package main
import (
"fmt"
"log"
"os"
"strconv"
"strings"
"github.com/cowry-network/go/keypair"
)
var prefix string
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
func main() {
if len(os.Args) != 2 {
usage()
os.Exit(1)
}
prefix = strings.ToUpper(os.Args[1])
checkPlausible()
for {
kp, err := keypair.Random()
if err != nil {
log.Fatal(err)
}
// NOTE: the first letter of an address will always be G, and the second letter will be one of only a few
// possibilities in the base32 alphabet, so we are actually searching for the vanity value after this 2
// character prefix.
if strings.HasPrefix(kp.Address()[2:], prefix) {
fmt.Println("Found!")
fmt.Printf("Secret seed: %s\n", kp.Seed())
fmt.Printf("Public: %s\n", kp.Address())
os.Exit(0)
}
}
}
func usage() {
fmt.Printf("Usage:\n\tstellar-vanity-gen PREFIX\n")
}
// aborts the attempt if a desired character is not a valid base32 digit
func checkPlausible() {
for _, r := range prefix {
if !strings.ContainsRune(alphabet, r) {
fmt.Printf("Invalid prefix: %s is not in the base32 alphabet\n", strconv.QuoteRune(r))
os.Exit(1)
}
}
}