mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-02-21 18:37:26 +08:00
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package node
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"os/exec"
|
|
"path/filepath"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/libp2p/go-libp2p/core/crypto"
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
|
"source.quilibrium.com/quilibrium/monorepo/client/utils"
|
|
"source.quilibrium.com/quilibrium/monorepo/node/config"
|
|
)
|
|
|
|
func GetPeerIDFromConfig(cfg *config.Config) peer.ID {
|
|
peerPrivKey, err := hex.DecodeString(cfg.P2P.PeerPrivKey)
|
|
if err != nil {
|
|
panic(errors.Wrap(err, "error unmarshaling peerkey"))
|
|
}
|
|
|
|
privKey, err := crypto.UnmarshalEd448PrivateKey(peerPrivKey)
|
|
if err != nil {
|
|
panic(errors.Wrap(err, "error unmarshaling peerkey"))
|
|
}
|
|
|
|
pub := privKey.GetPublic()
|
|
id, err := peer.IDFromPublicKey(pub)
|
|
if err != nil {
|
|
panic(errors.Wrap(err, "error getting peer id"))
|
|
}
|
|
|
|
return id
|
|
}
|
|
|
|
func GetPrivKeyFromConfig(cfg *config.Config) (crypto.PrivKey, error) {
|
|
peerPrivKey, err := hex.DecodeString(cfg.P2P.PeerPrivKey)
|
|
if err != nil {
|
|
panic(errors.Wrap(err, "error unmarshaling peerkey"))
|
|
}
|
|
|
|
privKey, err := crypto.UnmarshalEd448PrivateKey(peerPrivKey)
|
|
return privKey, err
|
|
}
|
|
|
|
func IsExistingNodeVersion(version string) bool {
|
|
return utils.FileExists(filepath.Join(utils.NodeDataPath, version))
|
|
}
|
|
|
|
func CheckForSystemd() bool {
|
|
// Check if systemctl command exists
|
|
_, err := exec.LookPath("systemctl")
|
|
return err == nil
|
|
}
|