-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (33 loc) · 1005 Bytes
/
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
package main
import (
"errors"
"kang-by-xoverse/api/rest"
"kang-by-xoverse/api/utils"
"crypto/ecdsa"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
)
func generateWallet() (string, string, string, error) {
privateKey, err := crypto.GenerateKey()
if err != nil {
return "", "", "", err
}
privateKeyBytes := crypto.FromECDSA(privateKey)
privateKeyHex := hexutil.Encode(privateKeyBytes)
publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
return "", "", "", errors.New("cannot assert type: publicKey is not of type *ecdsa.PublicKey")
}
publicKeyBytes := crypto.FromECDSAPub(publicKeyECDSA)
publicKeyHex := hexutil.Encode(publicKeyBytes)
address := crypto.PubkeyToAddress(*publicKeyECDSA).Hex()
return privateKeyHex, publicKeyHex, address, nil
}
func main() {
// fmt.Println(generateWallet())
utils.LoadDotEnv()
rdb, close := utils.GetRedisClient()
rest.RunRestServer(rdb)
close()
}