Add individual key derivation for trees
This commit is contained in:
parent
72a64afbec
commit
07f658a96f
@ -45,7 +45,11 @@ func (h *historyTree) rebuildFromStorage(beforeId string, include bool) (err err
|
|||||||
|
|
||||||
if len(ot.keys) != len(state.UserReadKeys()) {
|
if len(ot.keys) != len(state.UserReadKeys()) {
|
||||||
for key, value := range state.UserReadKeys() {
|
for key, value := range state.UserReadKeys() {
|
||||||
ot.keys[key] = value
|
treeKey, err := deriveTreeKey(value, h.id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ot.keys[key] = treeKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@ -640,7 +640,11 @@ func (ot *objectTree) validateTree(newChanges []*Change) error {
|
|||||||
// just not to take lock many times, updating the key map from aclList
|
// just not to take lock many times, updating the key map from aclList
|
||||||
if len(ot.keys) != len(state.UserReadKeys()) {
|
if len(ot.keys) != len(state.UserReadKeys()) {
|
||||||
for key, value := range state.UserReadKeys() {
|
for key, value := range state.UserReadKeys() {
|
||||||
ot.keys[key] = value
|
treeKey, err := deriveTreeKey(value, ot.id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ot.keys[key] = treeKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(newChanges) == 0 {
|
if len(newChanges) == 0 {
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
package objecttree
|
package objecttree
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/anytypeio/any-sync/util/crypto"
|
||||||
|
)
|
||||||
|
|
||||||
func commonSnapshotForTwoPaths(ourPath []string, theirPath []string) (string, error) {
|
func commonSnapshotForTwoPaths(ourPath []string, theirPath []string) (string, error) {
|
||||||
var i int
|
var i int
|
||||||
var j int
|
var j int
|
||||||
@ -27,3 +32,11 @@ OuterLoop:
|
|||||||
}
|
}
|
||||||
return ourPath[i+1], nil
|
return ourPath[i+1], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deriveTreeKey(key crypto.SymKey, cid string) (crypto.SymKey, error) {
|
||||||
|
raw, err := key.Raw()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return crypto.DeriveSymmetricKey(raw, fmt.Sprintf(crypto.AnysyncTreePath, cid))
|
||||||
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
AnytypeAccountPath = "m/SLIP-0021/anytype/account"
|
AnytypeAccountPath = "m/SLIP-0021/anytype/account"
|
||||||
|
AnysyncTreePath = "m/SLIP-0021/anysync/tree/%s"
|
||||||
AnytypeAccountPrefix = "m/44'/607'"
|
AnytypeAccountPrefix = "m/44'/607'"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user