mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-02-22 02:47:26 +08:00
42 lines
985 B
Go
42 lines
985 B
Go
package node
|
|
|
|
import (
|
|
"encoding/hex"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/libp2p/go-libp2p/core/crypto"
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
|
"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
|
|
}
|