| 1 | package node |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "github.com/libp2p/go-libp2p/core/crypto" |
| 7 | "github.com/libp2p/go-libp2p/core/peer" |
| 8 | ) |
| 9 | |
| 10 | func PeerID(id peer.ID) func() peer.ID { |
| 11 | return func() peer.ID { |
| 12 | return id |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | // PrivateKey loads the private key from config |
| 17 | func PrivateKey(sk crypto.PrivKey) func(id peer.ID) (crypto.PrivKey, error) { |
| 18 | return func(id peer.ID) (crypto.PrivKey, error) { |
| 19 | id2, err := peer.IDFromPrivateKey(sk) |
| 20 | if err != nil { |
| 21 | return nil, err |
| 22 | } |
| 23 | |
| 24 | if id2 != id { |
| 25 | return nil, fmt.Errorf("private key in config does not match id: %s != %s", id, id2) |
| 26 | } |
| 27 | return sk, nil |
| 28 | } |
| 29 | } |