-
Notifications
You must be signed in to change notification settings - Fork 7
/
utils.go
45 lines (36 loc) · 1.04 KB
/
utils.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
package importer
import (
"encoding/base64"
"fmt"
"os"
"github.com/tendermint/tendermint/crypto/ed25519"
)
type tendermintKey struct {
PrivateKey string
PublicKey string
NodeID string
}
func decodeBase64TendermintPrivateKey(privateKey string) (*tendermintKey, error) {
var privKey ed25519.PrivKey
privKey, err := base64.StdEncoding.DecodeString(privateKey)
if err != nil {
return nil, fmt.Errorf("failed to decode private key %s, %w", privateKey, err)
}
publicKey := base64.StdEncoding.EncodeToString(privKey.PubKey().Bytes())
nodeId := privKey.PubKey().Address().String()
return &tendermintKey{
PrivateKey: privateKey,
PublicKey: publicKey,
NodeID: nodeId,
}, nil
}
func createTempFile(content string) (string, error) {
file, err := os.CreateTemp("", "vegacapsule_import")
if err != nil {
return "", fmt.Errorf("failed to create temporary file: %w", err)
}
if _, err := file.WriteString(content); err != nil {
return "", fmt.Errorf("failed to write content to temp file: %w", err)
}
return file.Name(), nil
}