Add peer id string for keys
This commit is contained in:
parent
c3e6af0032
commit
06222e33ff
@ -3,7 +3,6 @@ package accountdata
|
||||
import (
|
||||
"crypto/rand"
|
||||
"github.com/anytypeio/any-sync/util/crypto"
|
||||
"github.com/anytypeio/any-sync/util/peer"
|
||||
)
|
||||
|
||||
type AccountKeys struct {
|
||||
@ -13,11 +12,10 @@ type AccountKeys struct {
|
||||
}
|
||||
|
||||
func New(peerKey crypto.PrivKey, signKey crypto.PrivKey) *AccountKeys {
|
||||
peerId, _ := peer.IdFromSigningPubKey(peerKey.GetPublic())
|
||||
return &AccountKeys{
|
||||
PeerKey: peerKey,
|
||||
SignKey: signKey,
|
||||
PeerId: peerId.String(),
|
||||
PeerId: peerKey.GetPublic().PeerId(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,13 +28,9 @@ func NewRandom() (*AccountKeys, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
peerId, err := peer.IdFromSigningPubKey(peerKey.GetPublic())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &AccountKeys{
|
||||
PeerKey: peerKey,
|
||||
SignKey: signKey,
|
||||
PeerId: peerId.String(),
|
||||
PeerId: peerKey.GetPublic().PeerId(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/anytypeio/any-sync/util/crypto/cryptoproto"
|
||||
"github.com/anytypeio/any-sync/util/peer"
|
||||
"github.com/anytypeio/any-sync/util/strkey"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/libp2p/go-libp2p/core/crypto"
|
||||
@ -152,12 +153,18 @@ func (k *Ed25519PrivKey) LibP2P() (crypto.PrivKey, error) {
|
||||
return crypto.UnmarshalEd25519PrivateKey(k.privKey)
|
||||
}
|
||||
|
||||
// String returns string representation of key
|
||||
// Account returns string representation of key in anytype account format
|
||||
func (k *Ed25519PubKey) Account() string {
|
||||
res, _ := strkey.Encode(strkey.AccountAddressVersionByte, k.pubKey)
|
||||
return res
|
||||
}
|
||||
|
||||
// PeerId returns string representation of key for peer id
|
||||
func (k *Ed25519PubKey) PeerId() string {
|
||||
peerId, _ := peer.IdFromSigningPubKey(k)
|
||||
return peerId.String()
|
||||
}
|
||||
|
||||
// Raw public key bytes.
|
||||
func (k *Ed25519PubKey) Raw() ([]byte, error) {
|
||||
return k.pubKey, nil
|
||||
|
||||
@ -45,8 +45,10 @@ type PubKey interface {
|
||||
Marshall() ([]byte, error)
|
||||
// Storage returns underlying key storage
|
||||
Storage() []byte
|
||||
// Account returns string representation
|
||||
// Account returns string representation for anytype account
|
||||
Account() string
|
||||
// PeerId returns string representation for peer id
|
||||
PeerId() string
|
||||
// LibP2P returns libp2p model
|
||||
LibP2P() (crypto.PubKey, error)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user