Remove decoders and fix sync tree

This commit is contained in:
mcrakhman 2022-09-26 20:32:59 +02:00 committed by Mikhail Iudin
parent efd7cafd59
commit 9b196a6521
No known key found for this signature in database
GPG Key ID: FAAAA8BAABDFF1C0
21 changed files with 148 additions and 252 deletions

View File

@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/peer"
@ -100,15 +101,12 @@ func genConfig(addresses []string, apiPort string) (config.Config, error) {
return config.Config{}, err
}
encKeyDecoder := encryptionkey.NewRSAPrivKeyDecoder()
signKeyDecoder := signingkey.NewEDPrivKeyDecoder()
encEncKey, err := encKeyDecoder.EncodeToString(encKey)
encEncKey, err := keys.EncodeKeyToString(encKey)
if err != nil {
return config.Config{}, err
}
encSignKey, err := signKeyDecoder.EncodeToString(signKey)
encSignKey, err := keys.EncodeKeyToString(signKey)
if err != nil {
return config.Config{}, err
}

View File

@ -5,9 +5,3 @@ nodes:
- grpcAddresses:
- "127.0.0.1:4431"
apiPort: "8081"
- grpcAddresses:
- "127.0.0.1:4432"
apiPort: "8082"
- grpcAddresses:
- "127.0.0.1:4433"
apiPort: "8083"

View File

@ -4,6 +4,7 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey"
)
@ -34,33 +35,34 @@ func New() app.Component {
func (s *service) Init(a *app.App) (err error) {
cfg := a.MustComponent(config.CName).(*config.Config)
// decoding our keys
privateEncryptionDecoder := encryptionkey.NewRSAPrivKeyDecoder()
privateSigningDecoder := signingkey.NewEDPrivKeyDecoder()
publicSigningDecoder := signingkey.NewEDPubKeyDecoder()
// TODO: add deviceKey
acc := cfg.Account
decodedEncryptionKey, err := privateEncryptionDecoder.DecodeFromString(acc.EncryptionKey)
if err != nil {
return err
}
decodedSigningKey, err := privateSigningDecoder.DecodeFromString(acc.SigningKey)
if err != nil {
return err
}
signKey := decodedSigningKey.(signingkey.PrivKey)
identity, err := publicSigningDecoder.EncodeToString(signKey.GetPublic())
decodedEncryptionKey, err := keys.DecodeKeyFromString(
acc.EncryptionKey,
encryptionkey.NewEncryptionRsaPrivKeyFromBytes,
nil)
if err != nil {
return err
}
decodedSigningKey, err := keys.DecodeKeyFromString(
acc.SigningKey,
signingkey.NewSigningEd25519PrivKeyFromBytes,
nil)
if err != nil {
return err
}
identity, err := decodedSigningKey.GetPublic().Raw()
if err != nil {
return err
}
// TODO: using acl lib format basically, but we should simplify this
s.accountData = &account.AccountData{
Identity: identity,
SignKey: signKey,
EncKey: decodedEncryptionKey.(encryptionkey.PrivKey),
Decoder: signingkey.NewEDPubKeyDecoder(),
SignKey: decodedSigningKey,
EncKey: decodedEncryptionKey,
}
s.peerId = acc.PeerId

View File

@ -49,7 +49,7 @@ message HeadSyncResponse {
message ObjectSyncMessage {
string spaceId = 1;
ObjectSyncContentValue content = 2;
treechange.RootChange treeHeader = 3;
treechange.RawTreeChangeWithId rootChange = 3;
string treeId = 4;
string trackingId = 5;
//

View File

@ -320,11 +320,11 @@ func (m *HeadSyncResponse) GetResults() []*HeadSyncResult {
// ObjectSyncMessage is a message sent on object sync
type ObjectSyncMessage struct {
SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"`
Content *ObjectSyncContentValue `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"`
TreeHeader *treechangeproto.RootChange `protobuf:"bytes,3,opt,name=treeHeader,proto3" json:"treeHeader,omitempty"`
TreeId string `protobuf:"bytes,4,opt,name=treeId,proto3" json:"treeId,omitempty"`
TrackingId string `protobuf:"bytes,5,opt,name=trackingId,proto3" json:"trackingId,omitempty"`
SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"`
Content *ObjectSyncContentValue `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"`
RootChange *treechangeproto.RawTreeChangeWithId `protobuf:"bytes,3,opt,name=rootChange,proto3" json:"rootChange,omitempty"`
TreeId string `protobuf:"bytes,4,opt,name=treeId,proto3" json:"treeId,omitempty"`
TrackingId string `protobuf:"bytes,5,opt,name=trackingId,proto3" json:"trackingId,omitempty"`
}
func (m *ObjectSyncMessage) Reset() { *m = ObjectSyncMessage{} }
@ -374,9 +374,9 @@ func (m *ObjectSyncMessage) GetContent() *ObjectSyncContentValue {
return nil
}
func (m *ObjectSyncMessage) GetTreeHeader() *treechangeproto.RootChange {
func (m *ObjectSyncMessage) GetRootChange() *treechangeproto.RawTreeChangeWithId {
if m != nil {
return m.TreeHeader
return m.RootChange
}
return nil
}
@ -831,57 +831,57 @@ func init() {
}
var fileDescriptor_5855f4ef9cf24cdb = []byte{
// 797 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x55, 0xcd, 0x8e, 0xe3, 0x44,
0x10, 0xb6, 0x33, 0x99, 0x49, 0x52, 0x99, 0x99, 0x0d, 0x0d, 0x3b, 0x98, 0x00, 0xd9, 0xe0, 0x03,
0x8a, 0x40, 0x4a, 0x50, 0x90, 0x10, 0x30, 0x5c, 0xd8, 0x51, 0x46, 0x89, 0x56, 0xfc, 0xa8, 0x67,
0x17, 0x24, 0xc4, 0xa5, 0xd7, 0xae, 0x4d, 0xcc, 0xda, 0x6e, 0xe3, 0xee, 0xb0, 0xe4, 0x09, 0xb8,
0x80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0x00,
// 793 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x55, 0xcd, 0x8e, 0x1b, 0x45,
0x10, 0x9e, 0xf1, 0x7a, 0xd7, 0x76, 0xed, 0xae, 0x63, 0x1a, 0x12, 0x06, 0x03, 0x8e, 0x99, 0x03,
0xb2, 0x40, 0x5a, 0x23, 0x73, 0x01, 0x16, 0x09, 0x91, 0x95, 0x57, 0xb6, 0x22, 0x7e, 0xd4, 0x9b,
0x80, 0x84, 0xb8, 0x74, 0x66, 0x2a, 0xf6, 0x90, 0x99, 0xe9, 0xa1, 0xbb, 0x4d, 0xf0, 0x13, 0x70,
0x01, 0x09, 0xf1, 0x06, 0x3c, 0x0b, 0x17, 0x8e, 0x39, 0x72, 0x44, 0xde, 0x17, 0x41, 0x5d, 0xe3,
0xf1, 0xd8, 0x66, 0x92, 0x1c, 0xf7, 0xe2, 0xe9, 0xaa, 0xfe, 0xbe, 0xea, 0xaf, 0xab, 0xaa, 0xcb,
0xf0, 0x51, 0x20, 0x93, 0x44, 0xa6, 0xc3, 0xfc, 0xa3, 0x33, 0x11, 0xe0, 0x90, 0x7e, 0xf5, 0x32,
0x0d, 0x32, 0x25, 0x8d, 0x1c, 0xd2, 0xaf, 0x2e, 0xbd, 0x67, 0xe4, 0x60, 0x4d, 0x91, 0x2e, 0xaf,
0xac, 0xaf, 0x3b, 0xcc, 0x9e, 0xcc, 0x86, 0x22, 0x88, 0x87, 0x46, 0x21, 0x06, 0x73, 0x91, 0xce,
0x70, 0x87, 0x59, 0xba, 0x73, 0xaa, 0x3f, 0x85, 0xd3, 0x09, 0x8a, 0xf0, 0x6a, 0x99, 0x06, 0xdc,
0xba, 0x19, 0x83, 0xfa, 0x63, 0x25, 0x13, 0xcf, 0xed, 0xbb, 0x83, 0x3a, 0xa7, 0x35, 0x6b, 0x43,
0xcd, 0x48, 0xaf, 0x46, 0x9e, 0x9a, 0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0xac, 0x1a, 0x6b, 0xeb, 0xf1,
0xd8, 0x7d, 0xd1, 0xe6, 0xc0, 0xfd, 0xc0, 0xbd, 0x77, 0xfe, 0xf7, 0xaa, 0xe7, 0x3e, 0x5b, 0xf5,
0xdc, 0x7f, 0x57, 0x3d, 0xf7, 0xf7, 0xeb, 0x9e, 0xf3, 0xec, 0xba, 0xe7, 0xfc, 0x73, 0xdd, 0x73,
0xbe, 0x7b, 0xe7, 0xa5, 0xff, 0xc5, 0x8f, 0x8e, 0xe8, 0xf3, 0xe1, 0x7f, 0x01, 0x00, 0x00, 0xff,
0xff, 0x33, 0xca, 0x5b, 0xe5, 0xb7, 0x07, 0x00, 0x00,
}
func (m *HeadSyncRange) Marshal() (dAtA []byte, err error) {
@ -1123,9 +1123,9 @@ func (m *ObjectSyncMessage) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i--
dAtA[i] = 0x22
}
if m.TreeHeader != nil {
if m.RootChange != nil {
{
size, err := m.TreeHeader.MarshalToSizedBuffer(dAtA[:i])
size, err := m.RootChange.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
@ -1638,8 +1638,8 @@ func (m *ObjectSyncMessage) Size() (n int) {
l = m.Content.Size()
n += 1 + l + sovSpacesync(uint64(l))
}
if m.TreeHeader != nil {
l = m.TreeHeader.Size()
if m.RootChange != nil {
l = m.RootChange.Size()
n += 1 + l + sovSpacesync(uint64(l))
}
l = len(m.TreeId)
@ -2497,7 +2497,7 @@ func (m *ObjectSyncMessage) Unmarshal(dAtA []byte) error {
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field TreeHeader", wireType)
return fmt.Errorf("proto: wrong wireType = %d for field RootChange", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
@ -2524,10 +2524,10 @@ func (m *ObjectSyncMessage) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.TreeHeader == nil {
m.TreeHeader = &treechangeproto.RootChange{}
if m.RootChange == nil {
m.RootChange = &treechangeproto.RawTreeChangeWithId{}
}
if err := m.TreeHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
if err := m.RootChange.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex

View File

@ -5,12 +5,16 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/nodeconf"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto/aclpb"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto"
"time"
)
type SyncService interface {
NotifyHeadUpdate(ctx context.Context, treeId string, header *aclpb.TreeHeader, update *spacesyncproto.ObjectHeadUpdate) (err error)
NotifyHeadUpdate(
ctx context.Context,
treeId string,
root *treechangeproto.RawTreeChangeWithId,
update *spacesyncproto.ObjectHeadUpdate) (err error)
StreamPool() StreamPool
Init()
@ -72,7 +76,11 @@ func (s *syncService) Close() (err error) {
return s.streamPool.Close()
}
func (s *syncService) NotifyHeadUpdate(ctx context.Context, treeId string, header *aclpb.TreeHeader, update *spacesyncproto.ObjectHeadUpdate) (err error) {
func (s *syncService) NotifyHeadUpdate(
ctx context.Context,
treeId string,
header *treechangeproto.RawTreeChangeWithId,
update *spacesyncproto.ObjectHeadUpdate) (err error) {
s.headNotifiable.UpdateHeads(treeId, update.Heads)
return s.streamPool.BroadcastAsync(spacesyncproto.WrapHeadUpdate(update, header, treeId, ""))
}

View File

@ -4,10 +4,10 @@ import (
"context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/syncservice"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto/aclpb"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto"
)
type UpdateListener interface {
@ -91,7 +91,7 @@ func (s *SyncTree) AddContent(ctx context.Context, content tree.SignableChangeCo
return
}
func (s *SyncTree) AddRawChanges(ctx context.Context, changes ...*aclpb.RawTreeChangeWithId) (res tree.AddResult, err error) {
func (s *SyncTree) AddRawChanges(ctx context.Context, changes ...*treechangeproto.RawTreeChangeWithId) (res tree.AddResult, err error) {
res, err = s.AddRawChanges(ctx, changes...)
if err != nil {
return

View File

@ -1,7 +1,6 @@
package account
import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey"
)
@ -10,5 +9,4 @@ type AccountData struct { // TODO: create a convenient constructor for this
Identity []byte // public key
SignKey signingkey.PrivKey
EncKey encryptionkey.PrivKey
Decoder keys.Decoder
}

View File

@ -8,7 +8,6 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/common"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
"sync"
)
@ -58,7 +57,7 @@ func BuildACLListWithIdentity(acc *account.AccountData, storage storage.ListStor
return build(id, builder, newACLRecordBuilder(id, common.NewKeychain()), storage)
}
func BuildACLList(decoder keys.Decoder, storage storage.ListStorage) (ACLList, error) {
func BuildACLList(storage storage.ListStorage) (ACLList, error) {
id, err := storage.ID()
if err != nil {
return nil, err

View File

@ -3,7 +3,6 @@ package list
import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/acllistbuilder"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
@ -15,7 +14,7 @@ func TestAclList_ACLState_UserInviteAndJoin(t *testing.T) {
keychain := st.(*acllistbuilder.ACLListStorageBuilder).GetKeychain()
aclList, err := BuildACLList(signingkey.NewEDPubKeyDecoder(), st)
aclList, err := BuildACLList(st)
require.NoError(t, err, "building acl list should be without error")
idA := keychain.GetIdentity("A")
@ -54,7 +53,7 @@ func TestAclList_ACLState_UserJoinAndRemove(t *testing.T) {
keychain := st.(*acllistbuilder.ACLListStorageBuilder).GetKeychain()
aclList, err := BuildACLList(signingkey.NewEDPubKeyDecoder(), st)
aclList, err := BuildACLList(st)
require.NoError(t, err, "building acl list should be without error")
idA := keychain.GetIdentity("A")

View File

@ -2,6 +2,7 @@ package acllistbuilder
import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey"
"hash/fnv"
@ -23,7 +24,6 @@ type YAMLKeychain struct {
ReadKeysByHash map[uint64]*SymKey
GeneratedIdentities map[string]string
DerivedIdentity string
coder signingkey.PubKeyDecoder
}
func NewKeychain() *YAMLKeychain {
@ -34,7 +34,6 @@ func NewKeychain() *YAMLKeychain {
GeneratedIdentities: map[string]string{},
ReadKeysByYAMLIdentity: map[string]*SymKey{},
ReadKeysByHash: map[uint64]*SymKey{},
coder: signingkey.NewEd25519PubKeyDecoder(),
}
}
@ -67,12 +66,10 @@ func (k *YAMLKeychain) AddEncryptionKey(key *Key) {
panic(err)
}
} else {
decoder := encryptionkey.NewRSAPrivKeyDecoder()
privKey, err := decoder.DecodeFromString(key.Value)
newPrivKey, err = keys.DecodeKeyFromString(key.Value, encryptionkey.NewEncryptionRsaPrivKeyFromBytes, nil)
if err != nil {
panic(err)
}
newPrivKey = privKey.(encryptionkey.PrivKey)
}
k.EncryptionKeysByYAMLIdentity[key.Name] = newPrivKey
}
@ -92,12 +89,10 @@ func (k *YAMLKeychain) AddSigningKey(key *Key) {
panic(err)
}
} else {
decoder := signingkey.NewEDPrivKeyDecoder()
privKey, err := decoder.DecodeFromString(key.Value)
newPrivKey, err = keys.DecodeKeyFromString(key.Value, signingkey.NewSigningEd25519PrivKeyFromBytes, nil)
if err != nil {
panic(err)
}
newPrivKey = privKey.(signingkey.PrivKey)
pubKey = newPrivKey.GetPublic()
}

View File

@ -39,7 +39,7 @@ type ObjectTree interface {
RWLocker
ID() string
Header() *treechangeproto.RootChange
Header() *treechangeproto.RawTreeChangeWithId
Heads() []string
Root() *Change
HasChange(string) bool
@ -68,7 +68,7 @@ type objectTree struct {
aclList list.ACLList
id string
root *treechangeproto.RootChange
root *treechangeproto.RawTreeChangeWithId
tree *Tree
keys map[uint64]*symmetric.Key
@ -132,7 +132,7 @@ func (ot *objectTree) ID() string {
return ot.id
}
func (ot *objectTree) Header() *treechangeproto.RootChange {
func (ot *objectTree) Header() *treechangeproto.RawTreeChangeWithId {
return ot.root
}

View File

@ -2,13 +2,10 @@ package tree
import (
"context"
"crypto/rand"
"encoding/hex"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/acllistbuilder"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
@ -108,7 +105,7 @@ func prepareACLList(t *testing.T) list.ACLList {
st, err := acllistbuilder.NewListStorageWithTestName("userjoinexample.yml")
require.NoError(t, err, "building storage should not result in error")
aclList, err := list.BuildACLList(signingkey.NewEDPubKeyDecoder(), st)
aclList, err := list.BuildACLList(st)
require.NoError(t, err, "building acl list should be without error")
return aclList
@ -151,18 +148,6 @@ func prepareTreeContext(t *testing.T, aclList list.ACLList) testTreeContext {
}
}
func TestSameSignature(t *testing.T) {
privKey, _, err := signingkey.GenerateEd25519Key(rand.Reader)
require.NoError(t, err)
bytes := []byte("asefhiosahjfoiesjgioesajgihs")
for i := 0; i < 5; i++ {
signed, err := privKey.Sign(bytes)
require.NoError(t, err)
t.Log(hex.EncodeToString(signed))
}
// kitten step voyage hand cover funny timber auction differ mushroom update pulp
}
func TestObjectTree(t *testing.T) {
aclList := prepareACLList(t)

View File

@ -7,7 +7,6 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/symmetric"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice"
"github.com/gogo/protobuf/proto"
"go.uber.org/zap"
)
@ -114,19 +113,13 @@ func buildObjectTree(deps objectTreeDeps) (ObjectTree, error) {
return nil, err
}
rawRootWithId, err := objTree.treeStorage.Root()
objTree.root, err = objTree.treeStorage.Root()
if err != nil {
return nil, err
}
rawRoot := &treechangeproto.RawTreeChange{}
err = proto.Unmarshal(rawRootWithId.RawChange, rawRoot)
if err != nil {
return nil, err
}
objTree.root = &treechangeproto.RootChange{}
err = proto.Unmarshal(rawRoot.Payload, objTree.root)
// verifying root
_, err = objTree.changeBuilder.ConvertFromRaw(objTree.root, true)
if err != nil {
return nil, err
}

View File

@ -5,7 +5,6 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey"
"go.uber.org/zap"
@ -83,9 +82,7 @@ func (s *service) Nodes() []*Node {
func nodeFromConfigNode(
n config.Node,
peerId string,
privateSigningDecoder keys.Decoder,
privateEncryptionDecoder keys.Decoder) (*Node, error) {
peerId string) (*Node, error) {
decodedSigningKey, err := privateSigningDecoder.DecodeFromString(n.SigningKey)
if err != nil {
return nil, err

View File

@ -107,14 +107,6 @@ func NewEncryptionRsaPubKeyFromBytes(bytes []byte) (PubKey, error) {
return &EncryptionRsaPubKey{pubKey: *pk}, nil
}
func NewRSAPrivKeyDecoder() keys.Decoder {
return keys.NewKeyDecoder(NewEncryptionRsaPrivKeyFromBytes)
}
func NewRSAPubKeyDecoder() keys.Decoder {
return keys.NewKeyDecoder(NewEncryptionRsaPubKeyFromBytes)
}
func keyEquals(k1, k2 keys.Key) bool {
a, err := k1.Raw()
if err != nil {

View File

@ -9,8 +9,6 @@ import (
"fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
"io"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/strkey"
)
// Ed25519PrivateKey is an ed25519 private key.
@ -147,43 +145,3 @@ func UnmarshalEd25519PrivateKey(data []byte) (PrivKey, error) {
k: ed25519.PrivateKey(data),
}, nil
}
// TODO: remove this one in favor of new one
type Ed25519SigningPubKeyDecoder struct{}
func NewEd25519PubKeyDecoder() PubKeyDecoder {
return &Ed25519SigningPubKeyDecoder{}
}
func (e *Ed25519SigningPubKeyDecoder) DecodeFromBytes(bytes []byte) (PubKey, error) {
return NewSigningEd25519PubKeyFromBytes(bytes)
}
func (e *Ed25519SigningPubKeyDecoder) DecodeFromString(identity string) (PubKey, error) {
pubKeyRaw, err := strkey.Decode(0x5b, identity)
if err != nil {
return nil, err
}
return e.DecodeFromBytes(pubKeyRaw)
}
func (e *Ed25519SigningPubKeyDecoder) DecodeFromStringIntoBytes(identity string) ([]byte, error) {
return strkey.Decode(0x5b, identity)
}
func (e *Ed25519SigningPubKeyDecoder) EncodeToString(pubkey PubKey) (string, error) {
raw, err := pubkey.Raw()
if err != nil {
return "", err
}
return strkey.Encode(0x5b, raw)
}
func NewEDPrivKeyDecoder() keys.Decoder {
return keys.NewKeyDecoder(NewSigningEd25519PrivKeyFromBytes)
}
func NewEDPubKeyDecoder() keys.Decoder {
return keys.NewKeyDecoder(NewSigningEd25519PubKeyFromBytes)
}

View File

@ -15,10 +15,3 @@ type PubKey interface {
Verify(data []byte, sig []byte) (bool, error)
}
type PubKeyDecoder interface {
DecodeFromBytes(bytes []byte) (PubKey, error)
DecodeFromString(identity string) (PubKey, error)
DecodeFromStringIntoBytes(identity string) ([]byte, error)
EncodeToString(pubkey PubKey) (string, error)
}

30
util/keys/decode.go Normal file
View File

@ -0,0 +1,30 @@
package keys
import (
"encoding/base64"
)
func EncodeKeyToString[T Key](key T) (str string, err error) {
raw, err := key.Raw()
if err != nil {
return
}
str = EncodeBytesToString(raw)
return
}
func EncodeBytesToString(bytes []byte) string {
return base64.StdEncoding.EncodeToString(bytes)
}
func DecodeKeyFromString[T Key](str string, construct func([]byte) (T, error), def T) (T, error) {
dec, err := DecodeBytesFromString(str)
if err != nil {
return def, err
}
return construct(dec)
}
func DecodeBytesFromString(str string) (bytes []byte, err error) {
return base64.StdEncoding.DecodeString(str)
}

View File

@ -1,38 +0,0 @@
package keys
import "github.com/anytypeio/go-anytype-infrastructure-experiments/util/strkey"
type keyDecoder[T Key] struct {
create func([]byte) (T, error)
}
func NewKeyDecoder[T Key](create func(bytes []byte) (T, error)) Decoder {
return &keyDecoder[T]{
create: create,
}
}
func (e *keyDecoder[T]) DecodeFromBytes(bytes []byte) (Key, error) {
return e.create(bytes)
}
func (e *keyDecoder[T]) DecodeFromString(identity string) (Key, error) {
pubKeyRaw, err := strkey.Decode(0x5b, identity)
if err != nil {
return nil, err
}
return e.DecodeFromBytes(pubKeyRaw)
}
func (e *keyDecoder[T]) DecodeFromStringIntoBytes(identity string) ([]byte, error) {
return strkey.Decode(0x5b, identity)
}
func (e *keyDecoder[T]) EncodeToString(key Key) (string, error) {
raw, err := key.Raw()
if err != nil {
return "", err
}
return strkey.Encode(0x5b, raw)
}

View File

@ -8,13 +8,6 @@ type Key interface {
Raw() ([]byte, error)
}
type Decoder interface {
DecodeFromBytes(bytes []byte) (Key, error)
DecodeFromString(identity string) (Key, error)
DecodeFromStringIntoBytes(identity string) ([]byte, error)
EncodeToString(key Key) (string, error)
}
func KeyEquals(k1, k2 Key) bool {
a, err := k1.Raw()
if err != nil {