Continue adjusting folder structure
This commit is contained in:
parent
2a1e3241dd
commit
3df678bc80
1
Makefile
1
Makefile
@ -12,6 +12,7 @@ endif
|
|||||||
|
|
||||||
export PATH=$(GOPATH)/bin:$(shell echo $$PATH)
|
export PATH=$(GOPATH)/bin:$(shell echo $$PATH)
|
||||||
|
|
||||||
|
# TODO: folders were changed, so we should update Makefile and protos generation
|
||||||
protos-go:
|
protos-go:
|
||||||
@echo 'Generating protobuf packages (Go)...'
|
@echo 'Generating protobuf packages (Go)...'
|
||||||
$(eval P_TIMESTAMP := Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types)
|
$(eval P_TIMESTAMP := Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types)
|
||||||
|
|||||||
9
account/accountdata.go
Normal file
9
account/accountdata.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package account
|
||||||
|
|
||||||
|
import "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
|
|
||||||
|
type AccountData struct {
|
||||||
|
Identity string
|
||||||
|
SignKey keys.SigningPrivKey
|
||||||
|
EncKey keys.EncryptionPrivKey
|
||||||
|
}
|
||||||
@ -6,7 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acltree/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/aclchanges/pb"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
"github.com/textileio/go-threads/crypto/symmetric"
|
"github.com/textileio/go-threads/crypto/symmetric"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -3,7 +3,8 @@ package acltree
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acltree/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/account"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/aclchanges/pb"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ type decreasedPermissionsParameters struct {
|
|||||||
startChange string
|
startChange string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewACLStateBuilder(decoder keys.SigningPubKeyDecoder, accountData *AccountData) *ACLStateBuilder {
|
func NewACLStateBuilder(decoder keys.SigningPubKeyDecoder, accountData *account.AccountData) *ACLStateBuilder {
|
||||||
return &ACLStateBuilder{
|
return &ACLStateBuilder{
|
||||||
decoder: decoder,
|
decoder: decoder,
|
||||||
identity: accountData.Identity,
|
identity: accountData.Identity,
|
||||||
|
|||||||
@ -3,13 +3,78 @@ package acltree
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acltree/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/account"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/aclchanges/pb"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/testutils/threadbuilder"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/testutils/threadbuilder"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/thread"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ACLContext struct {
|
||||||
|
Tree *Tree
|
||||||
|
ACLState *aclState
|
||||||
|
}
|
||||||
|
|
||||||
|
func createTreeFromThread(t thread.Thread, fromStart bool) (*Tree, error) {
|
||||||
|
treeBuilder := NewTreeBuilder(t, keys.NewEd25519Decoder())
|
||||||
|
treeBuilder.Init()
|
||||||
|
return treeBuilder.Build(fromStart)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createACLStateFromThread(
|
||||||
|
t thread.Thread,
|
||||||
|
identity string,
|
||||||
|
key keys.EncryptionPrivKey,
|
||||||
|
decoder keys.SigningPubKeyDecoder,
|
||||||
|
fromStart bool) (*ACLContext, error) {
|
||||||
|
tree, err := createTreeFromThread(t, fromStart)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
accountData := &account.AccountData{
|
||||||
|
Identity: identity,
|
||||||
|
EncKey: key,
|
||||||
|
}
|
||||||
|
|
||||||
|
aclTreeBuilder := NewACLTreeBuilder(t, decoder)
|
||||||
|
aclTreeBuilder.Init()
|
||||||
|
aclTree, err := aclTreeBuilder.Build()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !fromStart {
|
||||||
|
snapshotValidator := NewSnapshotValidator(decoder, accountData)
|
||||||
|
snapshotValidator.Init(aclTree)
|
||||||
|
valid, err := snapshotValidator.ValidateSnapshot(tree.root)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !valid {
|
||||||
|
// TODO: think about what to do if the snapshot is invalid - should we rebuild the tree without it
|
||||||
|
return createACLStateFromThread(t, identity, key, decoder, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
aclBuilder := NewACLStateBuilder(decoder, accountData)
|
||||||
|
err = aclBuilder.Init(tree)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
aclState, err := aclBuilder.Build()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &ACLContext{
|
||||||
|
Tree: tree,
|
||||||
|
ACLState: aclState,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestACLStateBuilder_UserJoinBuild(t *testing.T) {
|
func TestACLStateBuilder_UserJoinBuild(t *testing.T) {
|
||||||
thread, err := threadbuilder.NewThreadBuilderFromFile("threadbuilder/userjoinexample.yml")
|
thread, err := threadbuilder.NewThreadBuilderFromFile("threadbuilder/userjoinexample.yml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -21,7 +86,6 @@ func TestACLStateBuilder_UserJoinBuild(t *testing.T) {
|
|||||||
keychain.GetIdentity("A"),
|
keychain.GetIdentity("A"),
|
||||||
keychain.EncryptionKeys["A"],
|
keychain.EncryptionKeys["A"],
|
||||||
keys.NewEd25519Decoder(),
|
keys.NewEd25519Decoder(),
|
||||||
NewPlainTextDocumentStateProvider(),
|
|
||||||
false)
|
false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should build acl aclState without err: %v", err)
|
t.Fatalf("should build acl aclState without err: %v", err)
|
||||||
@ -56,7 +120,6 @@ func TestACLStateBuilder_UserRemoveBuild(t *testing.T) {
|
|||||||
keychain.GetIdentity("A"),
|
keychain.GetIdentity("A"),
|
||||||
keychain.EncryptionKeys["A"],
|
keychain.EncryptionKeys["A"],
|
||||||
keys.NewEd25519Decoder(),
|
keys.NewEd25519Decoder(),
|
||||||
NewPlainTextDocumentStateProvider(),
|
|
||||||
false)
|
false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should build acl aclState without err: %v", err)
|
t.Fatalf("should build acl aclState without err: %v", err)
|
||||||
@ -87,7 +150,6 @@ func TestACLStateBuilder_UserRemoveBeforeBuild(t *testing.T) {
|
|||||||
keychain.GetIdentity("A"),
|
keychain.GetIdentity("A"),
|
||||||
keychain.EncryptionKeys["A"],
|
keychain.EncryptionKeys["A"],
|
||||||
keys.NewEd25519Decoder(),
|
keys.NewEd25519Decoder(),
|
||||||
NewPlainTextDocumentStateProvider(),
|
|
||||||
false)
|
false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should build acl aclState without err: %v", err)
|
t.Fatalf("should build acl aclState without err: %v", err)
|
||||||
@ -119,7 +181,6 @@ func TestACLStateBuilder_InvalidSnapshotBuild(t *testing.T) {
|
|||||||
keychain.GetIdentity("A"),
|
keychain.GetIdentity("A"),
|
||||||
keychain.EncryptionKeys["A"],
|
keychain.EncryptionKeys["A"],
|
||||||
keys.NewEd25519Decoder(),
|
keys.NewEd25519Decoder(),
|
||||||
NewPlainTextDocumentStateProvider(),
|
|
||||||
false)
|
false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should build acl aclState without err: %v", err)
|
t.Fatalf("should build acl aclState without err: %v", err)
|
||||||
@ -150,7 +211,6 @@ func TestACLStateBuilder_ValidSnapshotBuild(t *testing.T) {
|
|||||||
keychain.GetIdentity("A"),
|
keychain.GetIdentity("A"),
|
||||||
keychain.EncryptionKeys["A"],
|
keychain.EncryptionKeys["A"],
|
||||||
keys.NewEd25519Decoder(),
|
keys.NewEd25519Decoder(),
|
||||||
NewPlainTextDocumentStateProvider(),
|
|
||||||
false)
|
false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should build acl aclState without err: %v", err)
|
t.Fatalf("should build acl aclState without err: %v", err)
|
||||||
|
|||||||
@ -2,9 +2,9 @@ package acltree
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/thread"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/thread"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice"
|
||||||
gothread "github.com/textileio/go-threads/core/thread"
|
gothread "github.com/textileio/go-threads/core/thread"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package acltree
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acltree/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/aclchanges/pb"
|
||||||
"github.com/textileio/go-threads/crypto/symmetric"
|
"github.com/textileio/go-threads/crypto/symmetric"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/acltree/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/aclchanges/pb"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/thread"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/thread"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
|
|||||||
@ -1,8 +0,0 @@
|
|||||||
package acltree
|
|
||||||
|
|
||||||
type documentContext struct {
|
|
||||||
aclTree *Tree // TODO: remove it, because we don't use it
|
|
||||||
fullTree *Tree
|
|
||||||
aclState *aclState
|
|
||||||
docState DocumentState
|
|
||||||
}
|
|
||||||
@ -2,19 +2,22 @@ package acltree
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/account"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SnapshotValidator struct {
|
type SnapshotValidator struct {
|
||||||
aclTree *Tree
|
aclTree *Tree
|
||||||
identity string
|
identity string
|
||||||
key threadmodels.EncryptionPrivKey
|
key keys.EncryptionPrivKey
|
||||||
decoder threadmodels.SigningPubKeyDecoder
|
decoder keys.SigningPubKeyDecoder
|
||||||
stateBuilder *ACLStateBuilder
|
stateBuilder *ACLStateBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSnapshotValidator(
|
func NewSnapshotValidator(
|
||||||
decoder threadmodels.SigningPubKeyDecoder,
|
decoder keys.SigningPubKeyDecoder,
|
||||||
accountData *AccountData) *SnapshotValidator {
|
accountData *account.AccountData) *SnapshotValidator {
|
||||||
return &SnapshotValidator{
|
return &SnapshotValidator{
|
||||||
identity: accountData.Identity,
|
identity: accountData.Identity,
|
||||||
key: accountData.EncKey,
|
key: accountData.EncKey,
|
||||||
|
|||||||
@ -1,88 +0,0 @@
|
|||||||
package acltree
|
|
||||||
|
|
||||||
type ACLContext struct {
|
|
||||||
Tree *Tree
|
|
||||||
ACLState *aclState
|
|
||||||
DocState DocumentState
|
|
||||||
}
|
|
||||||
|
|
||||||
func createTreeFromThread(t threadmodels.Thread, fromStart bool) (*Tree, error) {
|
|
||||||
treeBuilder := NewTreeBuilder(t, threadmodels.NewEd25519Decoder())
|
|
||||||
treeBuilder.Init()
|
|
||||||
return treeBuilder.Build(fromStart)
|
|
||||||
}
|
|
||||||
|
|
||||||
func createACLStateFromThread(
|
|
||||||
t threadmodels.Thread,
|
|
||||||
identity string,
|
|
||||||
key threadmodels.EncryptionPrivKey,
|
|
||||||
decoder threadmodels.SigningPubKeyDecoder,
|
|
||||||
provider InitialStateProvider,
|
|
||||||
fromStart bool) (*ACLContext, error) {
|
|
||||||
tree, err := createTreeFromThread(t, fromStart)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
accountData := &AccountData{
|
|
||||||
Identity: identity,
|
|
||||||
EncKey: key,
|
|
||||||
}
|
|
||||||
|
|
||||||
aclTreeBuilder := NewACLTreeBuilder(t, decoder)
|
|
||||||
aclTreeBuilder.Init()
|
|
||||||
aclTree, err := aclTreeBuilder.Build()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !fromStart {
|
|
||||||
snapshotValidator := NewSnapshotValidator(decoder, accountData)
|
|
||||||
snapshotValidator.Init(aclTree)
|
|
||||||
valid, err := snapshotValidator.ValidateSnapshot(tree.root)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if !valid {
|
|
||||||
// TODO: think about what to do if the snapshot is invalid - should we rebuild the tree without it
|
|
||||||
return createACLStateFromThread(t, identity, key, decoder, provider, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
aclBuilder := NewACLStateBuilder(decoder, accountData)
|
|
||||||
err = aclBuilder.Init(tree)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
aclState, err := aclBuilder.Build()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &ACLContext{
|
|
||||||
Tree: tree,
|
|
||||||
ACLState: aclState,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func createDocumentStateFromThread(
|
|
||||||
t threadmodels.Thread,
|
|
||||||
identity string,
|
|
||||||
key threadmodels.EncryptionPrivKey,
|
|
||||||
provider InitialStateProvider,
|
|
||||||
decoder threadmodels.SigningPubKeyDecoder) (*ACLContext, error) {
|
|
||||||
context, err := createACLStateFromThread(t, identity, key, decoder, provider, false)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
docStateBuilder := newDocumentStateBuilder(provider)
|
|
||||||
docStateBuilder.init(context.ACLState, context.Tree)
|
|
||||||
docState, err := docStateBuilder.build()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
context.DocState = docState
|
|
||||||
|
|
||||||
return context, nil
|
|
||||||
}
|
|
||||||
@ -3,9 +3,9 @@ package acltree
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/thread"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/thread"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
//"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/lib/logging"
|
//"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/lib/logging"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice"
|
||||||
"github.com/prometheus/common/log"
|
"github.com/prometheus/common/log"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package acltree
|
package exampledocument
|
||||||
|
|
||||||
type DocumentState interface {
|
type DocumentState interface {
|
||||||
ApplyChange(change []byte, id string) (DocumentState, error)
|
ApplyChange(change []byte, id string) (DocumentState, error)
|
||||||
@ -1,7 +1,8 @@
|
|||||||
package acltree
|
package exampledocument
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/acltree"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/data/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/data/pb"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice"
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
@ -20,13 +21,13 @@ type Document struct {
|
|||||||
accountData *AccountData
|
accountData *AccountData
|
||||||
decoder threadmodels.SigningPubKeyDecoder
|
decoder threadmodels.SigningPubKeyDecoder
|
||||||
|
|
||||||
treeBuilder *TreeBuilder
|
treeBuilder *acltree.TreeBuilder
|
||||||
aclTreeBuilder *ACLTreeBuilder
|
aclTreeBuilder *acltree.ACLTreeBuilder
|
||||||
aclStateBuilder *ACLStateBuilder
|
aclStateBuilder *acltree.ACLStateBuilder
|
||||||
snapshotValidator *SnapshotValidator
|
snapshotValidator *acltree.SnapshotValidator
|
||||||
docStateBuilder *documentStateBuilder
|
docStateBuilder *acltree.documentStateBuilder
|
||||||
|
|
||||||
docContext *documentContext
|
docContext *acltree.documentContext
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateResult int
|
type UpdateResult int
|
||||||
@ -54,12 +55,12 @@ func NewDocument(
|
|||||||
stateProvider: stateProvider,
|
stateProvider: stateProvider,
|
||||||
accountData: accountData,
|
accountData: accountData,
|
||||||
decoder: decoder,
|
decoder: decoder,
|
||||||
aclTreeBuilder: NewACLTreeBuilder(thread, decoder),
|
aclTreeBuilder: acltree.NewACLTreeBuilder(thread, decoder),
|
||||||
treeBuilder: NewTreeBuilder(thread, decoder),
|
treeBuilder: acltree.NewTreeBuilder(thread, decoder),
|
||||||
snapshotValidator: NewSnapshotValidator(decoder, accountData),
|
snapshotValidator: acltree.NewSnapshotValidator(decoder, accountData),
|
||||||
aclStateBuilder: NewACLStateBuilder(decoder, accountData),
|
aclStateBuilder: acltree.NewACLStateBuilder(decoder, accountData),
|
||||||
docStateBuilder: newDocumentStateBuilder(stateProvider),
|
docStateBuilder: acltree.newDocumentStateBuilder(stateProvider),
|
||||||
docContext: &documentContext{},
|
docContext: &acltree.documentContext{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ func (d *Document) CreateChange(payload *CreateChangePayload) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add CID creation logic based on content
|
// TODO: add CID creation logic based on content
|
||||||
ch := NewChange(payload.Id, aclChange)
|
ch := acltree.NewChange(payload.Id, aclChange)
|
||||||
ch.DecryptedDocumentChange = marshalled
|
ch.DecryptedDocumentChange = marshalled
|
||||||
|
|
||||||
fullMarshalledChange, err := proto.Marshal(aclChange)
|
fullMarshalledChange, err := proto.Marshal(aclChange)
|
||||||
@ -115,7 +116,7 @@ func (d *Document) CreateChange(payload *CreateChangePayload) error {
|
|||||||
}
|
}
|
||||||
d.docContext.fullTree.AddFast(ch)
|
d.docContext.fullTree.AddFast(ch)
|
||||||
|
|
||||||
err = d.thread.AddChange(&threadmodels.RawChange{
|
err = d.thread.AddChange(&thread.RawChange{
|
||||||
Payload: marshalled,
|
Payload: marshalled,
|
||||||
Signature: signature,
|
Signature: signature,
|
||||||
Id: payload.Id,
|
Id: payload.Id,
|
||||||
@ -130,8 +131,8 @@ func (d *Document) CreateChange(payload *CreateChangePayload) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Document) Update(changes ...*threadmodels.RawChange) (DocumentState, UpdateResult, error) {
|
func (d *Document) Update(changes ...*thread.RawChange) (DocumentState, UpdateResult, error) {
|
||||||
var treeChanges []*Change
|
var treeChanges []*acltree.Change
|
||||||
|
|
||||||
var foundACLChange bool
|
var foundACLChange bool
|
||||||
for _, ch := range changes {
|
for _, ch := range changes {
|
||||||
@ -162,9 +163,9 @@ func (d *Document) Update(changes ...*threadmodels.RawChange) (DocumentState, Up
|
|||||||
prevHeads := d.docContext.fullTree.Heads()
|
prevHeads := d.docContext.fullTree.Heads()
|
||||||
mode := d.docContext.fullTree.Add(treeChanges...)
|
mode := d.docContext.fullTree.Add(treeChanges...)
|
||||||
switch mode {
|
switch mode {
|
||||||
case Nothing:
|
case acltree.Nothing:
|
||||||
return d.docContext.docState, UpdateResultNoAction, nil
|
return d.docContext.docState, UpdateResultNoAction, nil
|
||||||
case Rebuild:
|
case acltree.Rebuild:
|
||||||
res, err := d.Build()
|
res, err := d.Build()
|
||||||
return res, UpdateResultRebuild, err
|
return res, UpdateResultRebuild, err
|
||||||
default:
|
default:
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package acltree
|
package exampledocument
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/testutils/threadbuilder"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/testutils/threadbuilder"
|
||||||
10
exampledocument/documentcontext.go
Normal file
10
exampledocument/documentcontext.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package exampledocument
|
||||||
|
|
||||||
|
import "github.com/anytypeio/go-anytype-infrastructure-experiments/acltree"
|
||||||
|
|
||||||
|
type documentContext struct {
|
||||||
|
aclTree *acltree.Tree // TODO: remove it, because we don't use it
|
||||||
|
fullTree *acltree.Tree
|
||||||
|
aclState *acltree.aclState
|
||||||
|
docState DocumentState
|
||||||
|
}
|
||||||
@ -1,14 +1,15 @@
|
|||||||
package acltree
|
package exampledocument
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/acltree"
|
||||||
)
|
)
|
||||||
|
|
||||||
// example ->
|
// example ->
|
||||||
|
|
||||||
type documentStateBuilder struct {
|
type documentStateBuilder struct {
|
||||||
tree *Tree
|
tree *acltree.Tree
|
||||||
aclState *aclState // TODO: decide if this is needed or not
|
aclState *acltree.aclState // TODO: decide if this is needed or not
|
||||||
stateProvider InitialStateProvider
|
stateProvider InitialStateProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ func newDocumentStateBuilder(stateProvider InitialStateProvider) *documentStateB
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *documentStateBuilder) init(aclState *aclState, tree *Tree) {
|
func (d *documentStateBuilder) init(aclState *acltree.aclState, tree *acltree.Tree) {
|
||||||
d.tree = tree
|
d.tree = tree
|
||||||
d.aclState = aclState
|
d.aclState = aclState
|
||||||
}
|
}
|
||||||
@ -44,7 +45,7 @@ func (d *documentStateBuilder) build() (s DocumentState, err error) {
|
|||||||
t := d.tree
|
t := d.tree
|
||||||
startId = rootChange.Id
|
startId = rootChange.Id
|
||||||
|
|
||||||
t.Iterate(startId, func(c *Change) (isContinue bool) {
|
t.Iterate(startId, func(c *acltree.Change) (isContinue bool) {
|
||||||
count++
|
count++
|
||||||
if startId == c.Id {
|
if startId == c.Id {
|
||||||
return true
|
return true
|
||||||
@ -67,7 +68,7 @@ func (d *documentStateBuilder) appendFrom(fromId string, init DocumentState) (s
|
|||||||
// TODO: we should do something like state copy probably
|
// TODO: we should do something like state copy probably
|
||||||
s = init
|
s = init
|
||||||
// TODO: we should have the same logic as in ACLStateBuilder, that means we should either pass in both methods state from the outside or save the state inside the builder
|
// TODO: we should have the same logic as in ACLStateBuilder, that means we should either pass in both methods state from the outside or save the state inside the builder
|
||||||
d.tree.Iterate(fromId, func(c *Change) (isContinue bool) {
|
d.tree.Iterate(fromId, func(c *acltree.Change) (isContinue bool) {
|
||||||
if c.Id == fromId {
|
if c.Id == fromId {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package acltree
|
package exampledocument
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/acltree"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/testutils/threadbuilder"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/testutils/threadbuilder"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
"testing"
|
||||||
@ -12,7 +13,7 @@ func TestDocumentStateBuilder_UserJoinBuild(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
keychain := thread.GetKeychain()
|
keychain := thread.GetKeychain()
|
||||||
ctx, err := createDocumentStateFromThread(
|
ctx, err := acltree.createDocumentStateFromThread(
|
||||||
thread,
|
thread,
|
||||||
keychain.GetIdentity("A"),
|
keychain.GetIdentity("A"),
|
||||||
keychain.EncryptionKeys["A"],
|
keychain.EncryptionKeys["A"],
|
||||||
@ -32,7 +33,7 @@ func TestDocumentStateBuilder_UserRemoveBuild(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
keychain := thread.GetKeychain()
|
keychain := thread.GetKeychain()
|
||||||
ctx, err := createDocumentStateFromThread(
|
ctx, err := acltree.createDocumentStateFromThread(
|
||||||
thread,
|
thread,
|
||||||
keychain.GetIdentity("A"),
|
keychain.GetIdentity("A"),
|
||||||
keychain.EncryptionKeys["A"],
|
keychain.EncryptionKeys["A"],
|
||||||
@ -1,8 +1,7 @@
|
|||||||
package acltree
|
package exampledocument
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/data/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/data/pb"
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
)
|
)
|
||||||
@ -4,6 +4,8 @@ import (
|
|||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
|
|
||||||
"github.com/textileio/go-threads/crypto/symmetric"
|
"github.com/textileio/go-threads/crypto/symmetric"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,24 +15,24 @@ type SymKey struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Keychain struct {
|
type Keychain struct {
|
||||||
SigningKeys map[string]threadmodels.SigningPrivKey
|
SigningKeys map[string]keys.SigningPrivKey
|
||||||
SigningKeysByIdentity map[string]threadmodels.SigningPrivKey
|
SigningKeysByIdentity map[string]keys.SigningPrivKey
|
||||||
EncryptionKeys map[string]threadmodels.EncryptionPrivKey
|
EncryptionKeys map[string]keys.EncryptionPrivKey
|
||||||
ReadKeys map[string]*SymKey
|
ReadKeys map[string]*SymKey
|
||||||
ReadKeysByHash map[uint64]*SymKey
|
ReadKeysByHash map[uint64]*SymKey
|
||||||
GeneratedIdentities map[string]string
|
GeneratedIdentities map[string]string
|
||||||
coder *threadmodels.Ed25519SigningPubKeyDecoder
|
coder *keys.Ed25519SigningPubKeyDecoder
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKeychain() *Keychain {
|
func NewKeychain() *Keychain {
|
||||||
return &Keychain{
|
return &Keychain{
|
||||||
SigningKeys: map[string]threadmodels.SigningPrivKey{},
|
SigningKeys: map[string]keys.SigningPrivKey{},
|
||||||
SigningKeysByIdentity: map[string]threadmodels.SigningPrivKey{},
|
SigningKeysByIdentity: map[string]keys.SigningPrivKey{},
|
||||||
EncryptionKeys: map[string]threadmodels.EncryptionPrivKey{},
|
EncryptionKeys: map[string]keys.EncryptionPrivKey{},
|
||||||
GeneratedIdentities: map[string]string{},
|
GeneratedIdentities: map[string]string{},
|
||||||
ReadKeys: map[string]*SymKey{},
|
ReadKeys: map[string]*SymKey{},
|
||||||
ReadKeysByHash: map[uint64]*SymKey{},
|
ReadKeysByHash: map[uint64]*SymKey{},
|
||||||
coder: threadmodels.NewEd25519Decoder(),
|
coder: keys.NewEd25519Decoder(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +54,7 @@ func (k *Keychain) AddEncryptionKey(name string) {
|
|||||||
if _, exists := k.EncryptionKeys[name]; exists {
|
if _, exists := k.EncryptionKeys[name]; exists {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newPrivKey, _, err := threadmodels.GenerateRandomRSAKeyPair(2048)
|
newPrivKey, _, err := keys.GenerateRandomRSAKeyPair(2048)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -64,7 +66,7 @@ func (k *Keychain) AddSigningKey(name string) {
|
|||||||
if _, exists := k.SigningKeys[name]; exists {
|
if _, exists := k.SigningKeys[name]; exists {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newPrivKey, pubKey, err := threadmodels.GenerateRandomEd25519KeyPair()
|
newPrivKey, pubKey, err := keys.GenerateRandomEd25519KeyPair()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,10 @@ import (
|
|||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/data/pb"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/aclchanges/pb"
|
||||||
|
testpb "github.com/anytypeio/go-anytype-infrastructure-experiments/testutils/testchanges/pb"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/thread"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
)
|
)
|
||||||
|
|
||||||
const plainTextDocType uint16 = 1
|
const plainTextDocType uint16 = 1
|
||||||
@ -17,7 +20,7 @@ type threadChange struct {
|
|||||||
*pb.ACLChange
|
*pb.ACLChange
|
||||||
id string
|
id string
|
||||||
readKey *SymKey
|
readKey *SymKey
|
||||||
signKey threadmodels.SigningPrivKey
|
signKey keys.SigningPrivKey
|
||||||
|
|
||||||
changesDataDecrypted []byte
|
changesDataDecrypted []byte
|
||||||
}
|
}
|
||||||
@ -45,7 +48,7 @@ func NewThreadBuilderFromFile(file string) (*ThreadBuilder, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
thread := YMLThread{Some: &Super{}}
|
thread := YMLThread{}
|
||||||
err = yaml.Unmarshal(content, &thread)
|
err = yaml.Unmarshal(content, &thread)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -74,7 +77,7 @@ func (t *ThreadBuilder) Heads() []string {
|
|||||||
return t.heads
|
return t.heads
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ThreadBuilder) AddChange(change *threadmodels.RawChange) error {
|
func (t *ThreadBuilder) AddChange(change *thread.RawChange) error {
|
||||||
aclChange := new(pb.ACLChange)
|
aclChange := new(pb.ACLChange)
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@ -121,12 +124,12 @@ func (t *ThreadBuilder) SetHeads(heads []string) {
|
|||||||
t.heads = heads
|
t.heads = heads
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ThreadBuilder) GetChange(ctx context.Context, recordID string) (*threadmodels.RawChange, error) {
|
func (t *ThreadBuilder) GetChange(ctx context.Context, recordID string) (*thread.RawChange, error) {
|
||||||
return t.getChange(recordID, t.allChanges), nil
|
return t.getChange(recordID, t.allChanges), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ThreadBuilder) GetUpdatedChanges() []*threadmodels.RawChange {
|
func (t *ThreadBuilder) GetUpdatedChanges() []*thread.RawChange {
|
||||||
var res []*threadmodels.RawChange
|
var res []*thread.RawChange
|
||||||
for _, ch := range t.updatedChanges {
|
for _, ch := range t.updatedChanges {
|
||||||
rawCh := t.getChange(ch.id, t.updatedChanges)
|
rawCh := t.getChange(ch.id, t.updatedChanges)
|
||||||
res = append(res, rawCh)
|
res = append(res, rawCh)
|
||||||
@ -134,7 +137,7 @@ func (t *ThreadBuilder) GetUpdatedChanges() []*threadmodels.RawChange {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ThreadBuilder) getChange(changeId string, m map[string]*threadChange) *threadmodels.RawChange {
|
func (t *ThreadBuilder) getChange(changeId string, m map[string]*threadChange) *thread.RawChange {
|
||||||
rec := m[changeId]
|
rec := m[changeId]
|
||||||
|
|
||||||
if rec.changesDataDecrypted != nil {
|
if rec.changesDataDecrypted != nil {
|
||||||
@ -156,7 +159,7 @@ func (t *ThreadBuilder) getChange(changeId string, m map[string]*threadChange) *
|
|||||||
panic("should be able to sign final acl message!")
|
panic("should be able to sign final acl message!")
|
||||||
}
|
}
|
||||||
|
|
||||||
transformedRec := &threadmodels.RawChange{
|
transformedRec := &thread.RawChange{
|
||||||
Payload: aclMarshaled,
|
Payload: aclMarshaled,
|
||||||
Signature: signature,
|
Signature: signature,
|
||||||
Id: changeId,
|
Id: changeId,
|
||||||
@ -208,12 +211,12 @@ func (t *ThreadBuilder) parseChange(ch *Change) *threadChange {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(ch.Changes) > 0 || ch.Snapshot != nil {
|
if len(ch.Changes) > 0 || ch.Snapshot != nil {
|
||||||
changesData := &pb.PlainTextChangeData{}
|
changesData := &testpb.PlainTextChangeData{}
|
||||||
if ch.Snapshot != nil {
|
if ch.Snapshot != nil {
|
||||||
changesData.Snapshot = t.parseChangeSnapshot(ch.Snapshot)
|
changesData.Snapshot = t.parseChangeSnapshot(ch.Snapshot)
|
||||||
}
|
}
|
||||||
if len(ch.Changes) > 0 {
|
if len(ch.Changes) > 0 {
|
||||||
var changeContents []*pb.PlainTextChangeContent
|
var changeContents []*testpb.PlainTextChangeContent
|
||||||
for _, ch := range ch.Changes {
|
for _, ch := range ch.Changes {
|
||||||
aclChangeContent := t.parseDocumentChange(ch)
|
aclChangeContent := t.parseDocumentChange(ch)
|
||||||
changeContents = append(changeContents, aclChangeContent)
|
changeContents = append(changeContents, aclChangeContent)
|
||||||
@ -236,7 +239,7 @@ func (t *ThreadBuilder) parseThreadId(description *ThreadDescription) string {
|
|||||||
panic("no author in thread")
|
panic("no author in thread")
|
||||||
}
|
}
|
||||||
key := t.keychain.SigningKeys[description.Author]
|
key := t.keychain.SigningKeys[description.Author]
|
||||||
id, err := threadmodels.CreateACLThreadID(key.GetPublic(), plainTextDocType)
|
id, err := thread.CreateACLThreadID(key.GetPublic(), plainTextDocType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -244,8 +247,8 @@ func (t *ThreadBuilder) parseThreadId(description *ThreadDescription) string {
|
|||||||
return id.String()
|
return id.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ThreadBuilder) parseChangeSnapshot(s *PlainTextSnapshot) *pb.PlainTextChangeSnapshot {
|
func (t *ThreadBuilder) parseChangeSnapshot(s *PlainTextSnapshot) *testpb.PlainTextChangeSnapshot {
|
||||||
return &pb.PlainTextChangeSnapshot{
|
return &testpb.PlainTextChangeSnapshot{
|
||||||
Text: s.Text,
|
Text: s.Text,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,7 +260,7 @@ func (t *ThreadBuilder) parseACLSnapshot(s *ACLSnapshot) *pb.ACLChangeACLSnapsho
|
|||||||
aclUserState.Identity = t.keychain.GetIdentity(state.Identity)
|
aclUserState.Identity = t.keychain.GetIdentity(state.Identity)
|
||||||
|
|
||||||
encKey := t.keychain.
|
encKey := t.keychain.
|
||||||
GetKey(state.EncryptionKey).(threadmodels.EncryptionPrivKey)
|
GetKey(state.EncryptionKey).(keys.EncryptionPrivKey)
|
||||||
rawKey, _ := encKey.GetPublic().Raw()
|
rawKey, _ := encKey.GetPublic().Raw()
|
||||||
aclUserState.EncryptionKey = rawKey
|
aclUserState.EncryptionKey = rawKey
|
||||||
|
|
||||||
@ -270,12 +273,12 @@ func (t *ThreadBuilder) parseACLSnapshot(s *ACLSnapshot) *pb.ACLChangeACLSnapsho
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ThreadBuilder) parseDocumentChange(ch *PlainTextChange) (convCh *pb.PlainTextChangeContent) {
|
func (t *ThreadBuilder) parseDocumentChange(ch *PlainTextChange) (convCh *testpb.PlainTextChangeContent) {
|
||||||
switch {
|
switch {
|
||||||
case ch.TextAppend != nil:
|
case ch.TextAppend != nil:
|
||||||
convCh = &pb.PlainTextChangeContent{
|
convCh = &testpb.PlainTextChangeContent{
|
||||||
Value: &pb.PlainTextChangeContentValueOfTextAppend{
|
Value: &testpb.PlainTextChangeContentValueOfTextAppend{
|
||||||
TextAppend: &pb.PlainTextChangeTextAppend{
|
TextAppend: &testpb.PlainTextChangeTextAppend{
|
||||||
Text: ch.TextAppend.Text,
|
Text: ch.TextAppend.Text,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -294,7 +297,7 @@ func (t *ThreadBuilder) parseACLChange(ch *ACLChange) (convCh *pb.ACLChangeACLCo
|
|||||||
add := ch.UserAdd
|
add := ch.UserAdd
|
||||||
|
|
||||||
encKey := t.keychain.
|
encKey := t.keychain.
|
||||||
GetKey(add.EncryptionKey).(threadmodels.EncryptionPrivKey)
|
GetKey(add.EncryptionKey).(keys.EncryptionPrivKey)
|
||||||
rawKey, _ := encKey.GetPublic().Raw()
|
rawKey, _ := encKey.GetPublic().Raw()
|
||||||
|
|
||||||
convCh = &pb.ACLChangeACLContentValue{
|
convCh = &pb.ACLChangeACLContentValue{
|
||||||
@ -311,11 +314,11 @@ func (t *ThreadBuilder) parseACLChange(ch *ACLChange) (convCh *pb.ACLChangeACLCo
|
|||||||
join := ch.UserJoin
|
join := ch.UserJoin
|
||||||
|
|
||||||
encKey := t.keychain.
|
encKey := t.keychain.
|
||||||
GetKey(join.EncryptionKey).(threadmodels.EncryptionPrivKey)
|
GetKey(join.EncryptionKey).(keys.EncryptionPrivKey)
|
||||||
rawKey, _ := encKey.GetPublic().Raw()
|
rawKey, _ := encKey.GetPublic().Raw()
|
||||||
|
|
||||||
idKey, _ := t.keychain.SigningKeys[join.Identity].GetPublic().Raw()
|
idKey, _ := t.keychain.SigningKeys[join.Identity].GetPublic().Raw()
|
||||||
signKey := t.keychain.GetKey(join.AcceptSignature).(threadmodels.SigningPrivKey)
|
signKey := t.keychain.GetKey(join.AcceptSignature).(keys.SigningPrivKey)
|
||||||
signature, err := signKey.Sign(idKey)
|
signature, err := signKey.Sign(idKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -334,9 +337,9 @@ func (t *ThreadBuilder) parseACLChange(ch *ACLChange) (convCh *pb.ACLChangeACLCo
|
|||||||
}
|
}
|
||||||
case ch.UserInvite != nil:
|
case ch.UserInvite != nil:
|
||||||
invite := ch.UserInvite
|
invite := ch.UserInvite
|
||||||
rawAcceptKey, _ := t.keychain.GetKey(invite.AcceptKey).(threadmodels.SigningPrivKey).GetPublic().Raw()
|
rawAcceptKey, _ := t.keychain.GetKey(invite.AcceptKey).(keys.SigningPrivKey).GetPublic().Raw()
|
||||||
encKey := t.keychain.
|
encKey := t.keychain.
|
||||||
GetKey(invite.EncryptionKey).(threadmodels.EncryptionPrivKey)
|
GetKey(invite.EncryptionKey).(keys.EncryptionPrivKey)
|
||||||
rawEncKey, _ := encKey.GetPublic().Raw()
|
rawEncKey, _ := encKey.GetPublic().Raw()
|
||||||
|
|
||||||
convCh = &pb.ACLChangeACLContentValue{
|
convCh = &pb.ACLChangeACLContentValue{
|
||||||
@ -408,7 +411,7 @@ func (t *ThreadBuilder) parseACLChange(ch *ACLChange) (convCh *pb.ACLChangeACLCo
|
|||||||
return convCh
|
return convCh
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ThreadBuilder) encryptReadKeys(keys []string, encKey threadmodels.EncryptionPrivKey) (enc [][]byte) {
|
func (t *ThreadBuilder) encryptReadKeys(keys []string, encKey keys.EncryptionPrivKey) (enc [][]byte) {
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
realKey := t.keychain.GetKey(k).(*SymKey).Key.Bytes()
|
realKey := t.keychain.GetKey(k).(*SymKey).Key.Bytes()
|
||||||
res, err := encKey.GetPublic().Encrypt(realKey)
|
res, err := encKey.GetPublic().Encrypt(realKey)
|
||||||
|
|||||||
@ -9,12 +9,14 @@ package threadbuilder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/data/pb"
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/awalterschulze/gographviz"
|
"github.com/awalterschulze/gographviz"
|
||||||
|
|
||||||
|
testpb "github.com/anytypeio/go-anytype-infrastructure-experiments/testutils/testchanges/pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// To quickly look at visualized string you can use https://dreampuf.github.io/GraphvizOnline
|
// To quickly look at visualized string you can use https://dreampuf.github.io/GraphvizOnline
|
||||||
@ -44,7 +46,7 @@ func (t *ThreadBuilder) Graph() (string, error) {
|
|||||||
|
|
||||||
var chSymbs []string
|
var chSymbs []string
|
||||||
if r.changesDataDecrypted != nil {
|
if r.changesDataDecrypted != nil {
|
||||||
res := &pb.PlainTextChangeData{}
|
res := &testpb.PlainTextChangeData{}
|
||||||
err := proto.Unmarshal(r.changesDataDecrypted, res)
|
err := proto.Unmarshal(r.changesDataDecrypted, res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user