kubo/core/node/identity.go
Łukasz Magiera ed514b9177 Invert constructor config handling
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
2019-04-29 23:37:37 +02:00

30 lines
582 B
Go

package node
import (
"fmt"
"github.com/libp2p/go-libp2p-crypto"
"github.com/libp2p/go-libp2p-peer"
)
func PeerID(id peer.ID) func() peer.ID {
return func() peer.ID {
return id
}
}
// PrivateKey loads the private key from config
func PrivateKey(sk crypto.PrivKey) func(id peer.ID) (crypto.PrivKey, error) {
return func(id peer.ID) (crypto.PrivKey, error) {
id2, err := peer.IDFromPrivateKey(sk)
if err != nil {
return nil, err
}
if id2 != id {
return nil, fmt.Errorf("private key in config does not match id: %s != %s", id, id2)
}
return sk, nil
}
}