Last active
September 30, 2025 11:04
-
-
Save alanshaw/a0540b3e956a3a50cdf4d48829bef285 to your computer and use it in GitHub Desktop.
Ucanto private key to libp2p Peer ID and Peer ID to Ucanto public key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/verifier" | |
| ) | |
| func main() { | |
| d, _ := ed25519.Parse("did:key:z6MkjS68sxgvgSnGXe62GSZgtXF3veGEqK3rBx8uvivAviWi") | |
| pub, _ := crypto.UnmarshalEd25519PublicKey(d.Raw()) | |
| peerid, _ := peer.IDFromPublicKey(pub) | |
| fmt.Println(peerid.String()) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/verifier" | |
| ) | |
| func main() { | |
| priv, _, _ := crypto.GenerateEd25519Key(nil) | |
| peerid, _ := peer.IDFromPrivateKey(priv) | |
| fmt.Println(peerid.String()) | |
| pub, _ := peerid.ExtractPublicKey() | |
| pubBytes, _ := pub.Raw() | |
| verifier, _ := ed25519.FromRaw(pubBytes) | |
| fmt.Println(verifier.DID().String()) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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