-
Notifications
You must be signed in to change notification settings - Fork 1
/
waves.go
44 lines (36 loc) · 1.22 KB
/
waves.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
package blockchainkeys
import (
"github.com/btcsuite/btcd/btcutil/hdkeychain"
"github.com/wavesplatform/gowaves/pkg/crypto"
"github.com/wavesplatform/gowaves/pkg/proto"
)
// GenerateKeyPair - for waves MainNetScheme
func (w *WavesNetwork) GenerateKeyPair() (privateKey string, publicKey string, address string, err error) {
seed, err := hdkeychain.GenerateSeed(hdkeychain.MinSeedBytes)
if err != nil {
return "", "", "", err
}
private, public, err := crypto.GenerateKeyPair(seed)
if err != nil {
return "", "", "", err
}
addrs, err := proto.NewAddressFromPublicKey(proto.MainNetScheme, public)
if err != nil {
return "", "", "", err
}
privateKey = private.String()
publicKey = public.String()
address = addrs.String()
return privateKey, publicKey, address, nil
}
func (w *WavesNetwork) GetPublicKeyAndAddressByPrivateKey(privateKey string) (publicKey string, address string, err error) {
secretKey := crypto.MustSecretKeyFromBase58(privateKey)
publicKeyBytes := crypto.GeneratePublicKey(secretKey)
addrs, err := proto.NewAddressFromPublicKey(proto.MainNetScheme, publicKeyBytes)
if err != nil {
return "", "", err
}
publicKey = publicKeyBytes.String()
address = addrs.String()
return publicKey, address, nil
}