Skip to content

Instantly share code, notes, and snippets.

@alanshaw
Created March 12, 2025 12:28
Show Gist options
  • Save alanshaw/a0540b3e956a3a50cdf4d48829bef285 to your computer and use it in GitHub Desktop.
Save alanshaw/a0540b3e956a3a50cdf4d48829bef285 to your computer and use it in GitHub Desktop.
Ucanto private key to libp2p Peer ID
package main
import (
"fmt"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
ed25519 "github.com/storacha/go-ucanto/principal/ed25519/signer"
)
var priv = ""
func main() {
id, _ := ed25519.Parse(priv)
priv, _ := crypto.UnmarshalEd25519PrivateKey(id.Raw())
peerID, _ := peer.IDFromPrivateKey(priv)
fmt.Println(peerID.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment