-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmds.go
72 lines (51 loc) · 1.49 KB
/
cmds.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
package main
import (
"fmt"
"github.com/stellar/go/exp/crypto/derivation"
"github.com/stellar/go/keypair"
"github.com/urfave/cli"
"strconv"
"strings"
)
func genKeypair(c *cli.Context) error {
k, err := keypair.Random()
if err != nil {
return fmt.Errorf("there was an error generating the keypair, try again")
}
fmt.Printf("New Seed: %s\n", k.Seed())
fmt.Printf("New Address: %s\n", k.Address())
return nil
}
func parseAddressOrSeed(c *cli.Context) error {
k, err := keypair.Parse(string(c.Args()[0]))
if err != nil {
return fmt.Errorf("the string provided was not a valid Stellar seed")
}
fmt.Printf("Address: %s\n", k.Address())
return nil
}
func deriveKeypairsFromSeed(c *cli.Context) error {
seed := c.String("seed")
if len(seed) == 0 {
return fmt.Errorf("please inform a valid `SEED`")
}
rangeStr := strings.Split(c.String("range"), "..")
start, err := strconv.Atoi(rangeStr[0])
if err != nil {
return fmt.Errorf("invalid start for range")
}
end, err := strconv.Atoi(rangeStr[1])
if err != nil {
return fmt.Errorf("invalid end for range")
}
for i := start; i <= end; i++ {
path := fmt.Sprintf(derivation.StellarAccountPathFormat, i)
key, err := derivation.DeriveForPath(path, []byte(fmt.Sprintf("%s", seed)))
if err != nil {
return fmt.Errorf("there was an error trying to derive ")
}
kp, err := keypair.FromRawSeed(key.RawSeed())
fmt.Printf("KeyPair %d:\nSeed: %s\nAddress: %s\n-----------------\n", i, kp.Seed(), kp.Address())
}
return nil
}