1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-11 10:18:08 +09:00

Use account key instead of generating new

This commit is contained in:
mcrakhman 2022-07-18 22:27:27 +02:00 committed by Mikhail Iudin
parent 5ecff24268
commit e42e0843e7
No known key found for this signature in database
GPG key ID: FAAAA8BAABDFF1C0

View file

@ -2,9 +2,9 @@ package transport
import ( import (
"context" "context"
"crypto/rand"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/account"
"github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/sec" "github.com/libp2p/go-libp2p-core/sec"
libp2ptls "github.com/libp2p/go-libp2p/p2p/security/tls" libp2ptls "github.com/libp2p/go-libp2p/p2p/security/tls"
@ -33,12 +33,19 @@ type service struct {
} }
func (s *service) Init(ctx context.Context, a *app.App) (err error) { func (s *service) Init(ctx context.Context, a *app.App) (err error) {
var pubKey crypto.PubKey acc := a.MustComponent(account.CName).(account.Service)
s.key, pubKey, err = crypto.GenerateEd25519Key(rand.Reader) rawKey, err := acc.Account().SignKey.Raw()
if err != nil { if err != nil {
return return err
} }
pubKeyRaw, _ := pubKey.Raw()
// converting into libp2p crypto structure
s.key, err = crypto.UnmarshalEd25519PrivateKey(rawKey)
if err != nil {
return err
}
pubKeyRaw, _ := s.key.GetPublic().Raw()
log.Info("transport keys generated", zap.Binary("pubKey", pubKeyRaw)) log.Info("transport keys generated", zap.Binary("pubKey", pubKeyRaw))
return nil return nil
} }