-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgenerator.go
42 lines (34 loc) · 936 Bytes
/
generator.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
package btcvanity
import (
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil"
)
// Generator hold the logic for generating bitcoin address
// Depending on chain configuration, it can generate main/test net versions of wallet
type Generator struct {
params *chaincfg.Params
}
// IGenerator is interface for generator
type IGenerator interface {
Generate() (IWallet, error)
}
// Generate generates bitcoin wallet interface
func (g *Generator) Generate() (IWallet, error) {
wallet := &Wallet{}
var err error
privKey, err := btcec.NewPrivateKey(btcec.S256())
if err != nil {
return nil, err
}
wallet.privKey, err = btcutil.NewWIF(privKey, g.params, false)
if err != nil {
return nil, err
}
wallet.pubKey, err = btcutil.NewAddressPubKey(
wallet.privKey.PrivKey.PubKey().SerializeUncompressed(), g.params)
if err != nil {
return nil, err
}
return wallet, nil
}