-
Notifications
You must be signed in to change notification settings - Fork 1
/
pool.go
executable file
·55 lines (49 loc) · 1.5 KB
/
pool.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
package pool_party
import (
"github.com/Pantani/errors"
"github.com/Pantani/pool-party/bip39"
"github.com/Pantani/pool-party/bip44"
)
type Pool struct {
coin bip44.Coin
mnemonic string
passphrase string
}
func NewPool(coin bip44.Coin) *Pool {
return &Pool{
coin: coin,
}
}
func NewPoolWithSecret(coin bip44.Coin, mnemonic, passphrase string) *Pool {
return &Pool{
coin: coin,
mnemonic: mnemonic,
passphrase: passphrase,
}
}
// GenerateMnemonic generates a new mnemonic key based in the bit size
// It returns an error if occurs
func (p *Pool) GenerateMnemonic(bitSize int, passphrase string) error {
// NewEntropy will create random entropy bytes
// Return non-zero first byte, unless all random zeros occurs.
entropy, err := bip39.NewEntropy(bitSize)
if err != nil {
return err
}
// generate (english) seed words based on the entropy
p.mnemonic, err = bip39.NewMnemonic(entropy)
p.passphrase = passphrase
return err
}
// GenerateAddressPool generates the address pool based in the index and length
// It returns the generated addresses and an error if occurs
func (p *Pool) GenerateAddressPool(start, length int) (bip44.Addresses, error) {
if len(p.mnemonic) == 0 {
return nil, errors.E("empty mnemonic")
}
account, err := bip44.GenerateWallets(p.coin, p.mnemonic, p.passphrase, start, length)
if err != nil {
return nil, errors.E(err, "error to generate bip44 wallets", errors.Params{"coin": p.coin, "start": start, "length": length})
}
return account.Addresses, nil
}