Move peer util package into crypto

This commit is contained in:
mcrakhman 2023-03-27 21:22:32 +02:00 committed by Mikhail Iudin
parent 06222e33ff
commit 456fbe1f24
No known key found for this signature in database
GPG Key ID: FAAAA8BAABDFF1C0
4 changed files with 7 additions and 11 deletions

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"github.com/anytypeio/any-sync/net/secureservice/handshake/handshakeproto" "github.com/anytypeio/any-sync/net/secureservice/handshake/handshakeproto"
crypto2 "github.com/anytypeio/any-sync/util/crypto" crypto2 "github.com/anytypeio/any-sync/util/crypto"
peer2 "github.com/anytypeio/any-sync/util/peer"
"github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peer"
@ -568,9 +567,9 @@ func newConnPair(t require.TestingT) (sc1, sc2 *secConn) {
sk2b, err := sk2.Raw() sk2b, err := sk2.Raw()
signKey2, err := crypto.UnmarshalEd25519PrivateKey(sk2b) signKey2, err := crypto.UnmarshalEd25519PrivateKey(sk2b)
require.NoError(t, err) require.NoError(t, err)
peerId1, err := peer2.IdFromSigningPubKey(sk1.GetPublic()) peerId1, err := crypto2.IdFromSigningPubKey(sk1.GetPublic())
require.NoError(t, err) require.NoError(t, err)
peerId2, err := peer2.IdFromSigningPubKey(sk2.GetPublic()) peerId2, err := crypto2.IdFromSigningPubKey(sk2.GetPublic())
require.NoError(t, err) require.NoError(t, err)
sc1 = &secConn{ sc1 = &secConn{
Conn: c1, Conn: c1,
@ -594,7 +593,7 @@ type secConn struct {
func (s *secConn) LocalPeer() peer.ID { func (s *secConn) LocalPeer() peer.ID {
skB, _ := s.localKey.Raw() skB, _ := s.localKey.Raw()
sk, _ := crypto2.NewSigningEd25519PubKeyFromBytes(skB) sk, _ := crypto2.NewSigningEd25519PubKeyFromBytes(skB)
lp, _ := peer2.IdFromSigningPubKey(sk) lp, _ := crypto2.IdFromSigningPubKey(sk)
return lp return lp
} }

View File

@ -6,7 +6,6 @@ import (
"github.com/anytypeio/any-sync/commonspace/object/accountdata" "github.com/anytypeio/any-sync/commonspace/object/accountdata"
"github.com/anytypeio/any-sync/nodeconf" "github.com/anytypeio/any-sync/nodeconf"
"github.com/anytypeio/any-sync/util/crypto" "github.com/anytypeio/any-sync/util/crypto"
"github.com/anytypeio/any-sync/util/peer"
) )
// AccountTestService provides service for test purposes, generates new random account every Init // AccountTestService provides service for test purposes, generates new random account every Init
@ -28,7 +27,7 @@ func (s *AccountTestService) Init(a *app.App) (err error) {
return err return err
} }
peerId, err := peer.IdFromSigningPubKey(peerKey.GetPublic()) peerId, err := crypto.IdFromSigningPubKey(peerKey.GetPublic())
if err != nil { if err != nil {
return err return err
} }

View File

@ -8,7 +8,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/anytypeio/any-sync/util/crypto/cryptoproto" "github.com/anytypeio/any-sync/util/crypto/cryptoproto"
"github.com/anytypeio/any-sync/util/peer"
"github.com/anytypeio/any-sync/util/strkey" "github.com/anytypeio/any-sync/util/strkey"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
"github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/crypto"
@ -161,7 +160,7 @@ func (k *Ed25519PubKey) Account() string {
// PeerId returns string representation of key for peer id // PeerId returns string representation of key for peer id
func (k *Ed25519PubKey) PeerId() string { func (k *Ed25519PubKey) PeerId() string {
peerId, _ := peer.IdFromSigningPubKey(k) peerId, _ := IdFromSigningPubKey(k)
return peerId.String() return peerId.String()
} }

View File

@ -1,12 +1,11 @@
package peer package crypto
import ( import (
utilcrypto "github.com/anytypeio/any-sync/util/crypto"
"github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peer"
) )
func IdFromSigningPubKey(pubKey utilcrypto.PubKey) (peer.ID, error) { func IdFromSigningPubKey(pubKey PubKey) (peer.ID, error) {
rawSigning, err := pubKey.Raw() rawSigning, err := pubKey.Raw()
if err != nil { if err != nil {
return "", err return "", err