Skip to content

Commit

Permalink
try load private key from config
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Oct 7, 2023
1 parent 88b1d62 commit 58ed5b0
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion cmd/fsd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package main

import (
"context"
"encoding/hex"
"errors"
"flag"
"net"
"net/http"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"

"github.com/libp2p/go-libp2p/core/crypto"
Expand Down Expand Up @@ -98,7 +100,24 @@ func main() {
}
defer db.Close()

privateKey, _, _ := crypto.GenerateEd25519Key(frand.Reader)
var privateKey crypto.PrivKey
if cfg.IPFS.PrivateKey != "" {
buf, err := hex.DecodeString(strings.TrimPrefix(cfg.IPFS.PrivateKey, "ed25519:"))
if err != nil {
log.Fatal("failed to decode private key", zap.Error(err))
} else if len(buf) != 64 {
log.Fatal("private key must be 64 bytes")
}
privateKey, err = crypto.UnmarshalEd25519PrivateKey(buf)
if err != nil {
log.Fatal("failed to unmarshal private key", zap.Error(err))
}
} else {
privateKey, _, err = crypto.GenerateEd25519Key(frand.Reader)
if err != nil {
log.Fatal("failed to generate private key", zap.Error(err))
}
}
store := ipfs.NewRenterdBlockStore(db, cfg.Renterd, log.Named("blockstore"))

node, err := ipfs.NewNode(ctx, privateKey, cfg.IPFS, store)
Expand Down Expand Up @@ -141,8 +160,15 @@ func main() {
}
}()

buf, err := privateKey.Raw()
if err != nil {
log.Fatal("failed to marshal private key", zap.Error(err))
}
prettyKey := "ed25519:" + hex.EncodeToString(buf)

log.Info("fsd started",
zap.Stringer("peerID", node.PeerID()),
zap.String("privateKey", prettyKey),
zap.String("apiAddress", apiListener.Addr().String()),
zap.String("gatewayAddress", gatewayListener.Addr().String()),
zap.String("version", build.Version()),
Expand Down

0 comments on commit 58ed5b0

Please sign in to comment.