I don’t currently know of any libraries that will take a libp2p
Key and turn it into a GPG key, although nothing stops you from doing that.
Key interface has a
Raw function for getting the raw key bytes out, and the
Type function for figuring out what type of key it is (you could also do a type cast on the interface, but this is better if there are multiple implementations of the same key type). These two should be sufficient to be able to export the key.
If you end up writing some code doing the GPG import/export post back so other people can find it .
peerID.ExtractPublicKey() is only going to work on small keys (e.g. Ed25519), however, if the key is large (e.g. RSA keys) then the peerID becomes the SHA256 hash of the protobuf containing the key and you therefore can’t do an extraction.
An implementation of the KeyBook interface, such as the one in the Host’s Peerstore, might know about a peer’s corresponding public key (e.g.
host.Peerstore().PubKey(peerID)) if you’ve connected to them.
Also, IIRC GPG compatibility with certain key types (like Ed25519) is a bit annoying (i.e. not everything supports it). So you’ll have to tackle that when you do your import.