Skip to content

Commit 3cda16f

Browse files
committed
refactor: simplify private key hex conversion by replacing GetPrivateKeyHex with keyToHex helper
1 parent 544634f commit 3cda16f

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

client.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,6 @@ func (c *Client) GetPeers() []PeerInfo {
276276
return peers
277277
}
278278

279-
// GetPrivateKeyHex returns the hex-encoded private key for this peer.
280-
// This can be saved and used in Config.PrivateKey to maintain the same peer ID across restarts.
281-
func (c *Client) GetPrivateKeyHex() (string, error) {
282-
priv := c.host.Peerstore().PrivKey(c.host.ID())
283-
if priv == nil {
284-
return "", fmt.Errorf("private key not found in peerstore")
285-
}
286-
return PrivateKeyToHex(priv)
287-
}
288-
289279
// Close shuts down the client and releases all resources.
290280
func (c *Client) Close() error {
291281
c.cancel()
@@ -582,3 +572,11 @@ func PrivateKeyFromHex(keyHex string) (crypto.PrivKey, error) {
582572

583573
return priv, nil
584574
}
575+
576+
func keyToHex(priv crypto.PrivKey) string {
577+
keyBytes, err := crypto.MarshalPrivateKey(priv)
578+
if err != nil {
579+
return ""
580+
}
581+
return hex.EncodeToString(keyBytes)
582+
}

0 commit comments

Comments
 (0)