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