mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-10 18:10:49 +09:00
Update crypto and any-sync
This commit is contained in:
parent
22dfb59f40
commit
8a92ba0fbb
18 changed files with 274 additions and 128 deletions
|
@ -181,11 +181,8 @@ func (mw *Middleware) getInfo() *model.AccountInfo {
|
|||
at := mw.app.MustComponent(core.CName).(core.Service)
|
||||
gwAddr := mw.app.MustComponent(gateway.CName).(gateway.Gateway).Addr()
|
||||
wallet := mw.app.MustComponent(walletComp.CName).(walletComp.Wallet)
|
||||
var deviceId string
|
||||
deviceKey, err := wallet.GetDevicePrivkey()
|
||||
if err == nil {
|
||||
deviceId = deviceKey.GetPublic().Account()
|
||||
}
|
||||
deviceKey := wallet.GetDevicePrivkey()
|
||||
deviceId := deviceKey.GetPublic().Account()
|
||||
|
||||
if gwAddr != "" {
|
||||
gwAddr = "http://" + gwAddr
|
||||
|
@ -238,16 +235,16 @@ func (mw *Middleware) AccountCreate(cctx context.Context, req *pb.RpcAccountCrea
|
|||
}
|
||||
|
||||
cfg := anytype.BootstrapConfig(true, os.Getenv("ANYTYPE_STAGING") == "1", true)
|
||||
accountKey, err := core.WalletAccountAt(mw.mnemonic, 0)
|
||||
derivationResult, err := core.WalletAccountAt(mw.mnemonic, 0)
|
||||
if err != nil {
|
||||
return response(nil, pb.RpcAccountCreateResponseError_UNKNOWN_ERROR, err)
|
||||
}
|
||||
address := accountKey.GetPublic().Account()
|
||||
address := derivationResult.Identity.GetPublic().Account()
|
||||
if code, err := checkInviteCode(cfg, req.AlphaInviteCode, address); err != nil {
|
||||
return response(nil, code, err)
|
||||
}
|
||||
|
||||
if err = core.WalletInitRepo(mw.rootPath, accountKey); err != nil {
|
||||
if err = core.WalletInitRepo(mw.rootPath, derivationResult.Identity); err != nil {
|
||||
return response(nil, pb.RpcAccountCreateResponseError_UNKNOWN_ERROR, err)
|
||||
}
|
||||
if req.StorePath != "" && req.StorePath != mw.rootPath {
|
||||
|
@ -266,7 +263,7 @@ func (mw *Middleware) AccountCreate(cctx context.Context, req *pb.RpcAccountCrea
|
|||
|
||||
comps := []app.Component{
|
||||
cfg,
|
||||
anytype.BootstrapWallet(mw.rootPath, accountKey),
|
||||
anytype.BootstrapWallet(mw.rootPath, derivationResult),
|
||||
mw.EventSender,
|
||||
}
|
||||
|
||||
|
@ -347,11 +344,11 @@ func (mw *Middleware) AccountRecover(cctx context.Context, _ *pb.RpcAccountRecov
|
|||
return response(pb.RpcAccountRecoverResponseError_NEED_TO_RECOVER_WALLET_FIRST, nil)
|
||||
}
|
||||
|
||||
account, err := core.WalletAccountAt(mw.mnemonic, 0)
|
||||
res, err := core.WalletAccountAt(mw.mnemonic, 0)
|
||||
if err != nil {
|
||||
return response(pb.RpcAccountRecoverResponseError_BAD_INPUT, err)
|
||||
}
|
||||
sendAccountAddEvent(0, &model.Account{Id: account.GetPublic().Account(), Name: ""})
|
||||
sendAccountAddEvent(0, &model.Account{Id: res.Identity.GetPublic().Account(), Name: ""})
|
||||
return response(pb.RpcAccountRecoverResponseError_NULL, nil)
|
||||
}
|
||||
|
||||
|
@ -401,21 +398,21 @@ func (mw *Middleware) AccountSelect(cctx context.Context, req *pb.RpcAccountSele
|
|||
if mw.mnemonic == "" {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_LOCAL_REPO_NOT_EXISTS_AND_MNEMONIC_NOT_SET, fmt.Errorf("no mnemonic provided"))
|
||||
}
|
||||
account, err := core.WalletAccountAt(mw.mnemonic, 0)
|
||||
res, err := core.WalletAccountAt(mw.mnemonic, 0)
|
||||
if err != nil {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_UNKNOWN_ERROR, err)
|
||||
}
|
||||
var repoWasMissing bool
|
||||
if _, err := os.Stat(filepath.Join(mw.rootPath, req.Id)); os.IsNotExist(err) {
|
||||
repoWasMissing = true
|
||||
if err = core.WalletInitRepo(mw.rootPath, account); err != nil {
|
||||
if err = core.WalletInitRepo(mw.rootPath, res.Identity); err != nil {
|
||||
return response(nil, pb.RpcAccountSelectResponseError_FAILED_TO_CREATE_LOCAL_REPO, err)
|
||||
}
|
||||
}
|
||||
|
||||
comps := []app.Component{
|
||||
anytype.BootstrapConfig(false, os.Getenv("ANYTYPE_STAGING") == "1", false),
|
||||
anytype.BootstrapWallet(mw.rootPath, account),
|
||||
anytype.BootstrapWallet(mw.rootPath, res),
|
||||
mw.EventSender,
|
||||
}
|
||||
|
||||
|
@ -716,11 +713,11 @@ func (mw *Middleware) createAccountFromLegacyExport(profile *pb.Profile, req *pb
|
|||
return pb.RpcAccountRecoverFromLegacyExportResponseError_UNKNOWN_ERROR, err
|
||||
}
|
||||
|
||||
account, err := core.WalletAccountAt(mw.mnemonic, 0)
|
||||
res, err := core.WalletAccountAt(mw.mnemonic, 0)
|
||||
if err != nil {
|
||||
return pb.RpcAccountRecoverFromLegacyExportResponseError_UNKNOWN_ERROR, err
|
||||
}
|
||||
address := account.GetPublic().Account()
|
||||
address := res.Identity.GetPublic().Account()
|
||||
if address == "" || profile.Address != address {
|
||||
return pb.RpcAccountRecoverFromLegacyExportResponseError_DIFFERENT_ACCOUNT, fmt.Errorf("backup was made from different account")
|
||||
}
|
||||
|
@ -731,8 +728,8 @@ func (mw *Middleware) createAccountFromLegacyExport(profile *pb.Profile, req *pb
|
|||
return pb.RpcAccountRecoverFromLegacyExportResponseError_UNKNOWN_ERROR, err
|
||||
}
|
||||
mw.accountSearchCancel()
|
||||
if _, statErr := os.Stat(filepath.Join(mw.rootPath, address)); os.IsNotExist(statErr) && account != nil {
|
||||
if walletErr := core.WalletInitRepo(mw.rootPath, account); walletErr != nil {
|
||||
if _, statErr := os.Stat(filepath.Join(mw.rootPath, address)); os.IsNotExist(statErr) {
|
||||
if walletErr := core.WalletInitRepo(mw.rootPath, res.Identity); walletErr != nil {
|
||||
return pb.RpcAccountRecoverFromLegacyExportResponseError_UNKNOWN_ERROR, walletErr
|
||||
}
|
||||
}
|
||||
|
@ -741,7 +738,7 @@ func (mw *Middleware) createAccountFromLegacyExport(profile *pb.Profile, req *pb
|
|||
return pb.RpcAccountRecoverFromLegacyExportResponseError_UNKNOWN_ERROR, err
|
||||
}
|
||||
|
||||
err = mw.startApp(cfg, account, err)
|
||||
err = mw.startApp(cfg, res, err)
|
||||
if err != nil {
|
||||
return pb.RpcAccountRecoverFromLegacyExportResponseError_UNKNOWN_ERROR, err
|
||||
}
|
||||
|
@ -754,10 +751,10 @@ func (mw *Middleware) createAccountFromLegacyExport(profile *pb.Profile, req *pb
|
|||
return pb.RpcAccountRecoverFromLegacyExportResponseError_NULL, nil
|
||||
}
|
||||
|
||||
func (mw *Middleware) startApp(cfg *config.Config, account crypto.PrivKey, err error) error {
|
||||
func (mw *Middleware) startApp(cfg *config.Config, derivationResult crypto.DerivationResult, err error) error {
|
||||
comps := []app.Component{
|
||||
cfg,
|
||||
anytype.BootstrapWallet(mw.rootPath, account),
|
||||
anytype.BootstrapWallet(mw.rootPath, derivationResult),
|
||||
mw.EventSender,
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,12 @@ package anytype
|
|||
import (
|
||||
"context"
|
||||
"github.com/anytypeio/any-sync/util/crypto"
|
||||
"github.com/anytypeio/go-anytype-middleware/core/filestorage/filesync"
|
||||
"os"
|
||||
|
||||
"github.com/anytypeio/any-sync/app"
|
||||
"github.com/anytypeio/any-sync/commonfile/fileservice"
|
||||
"github.com/anytypeio/any-sync/commonspace"
|
||||
//nolint: misspell
|
||||
"github.com/anytypeio/any-sync/commonspace/credentialprovider"
|
||||
|
||||
"github.com/anytypeio/any-sync/coordinator/coordinatorclient"
|
||||
"github.com/anytypeio/any-sync/net/dialer"
|
||||
"github.com/anytypeio/any-sync/net/pool"
|
||||
|
@ -33,6 +31,7 @@ import (
|
|||
"github.com/anytypeio/go-anytype-middleware/core/configfetcher"
|
||||
"github.com/anytypeio/go-anytype-middleware/core/debug"
|
||||
"github.com/anytypeio/go-anytype-middleware/core/filestorage"
|
||||
"github.com/anytypeio/go-anytype-middleware/core/filestorage/filesync"
|
||||
"github.com/anytypeio/go-anytype-middleware/core/filestorage/rpcstore"
|
||||
"github.com/anytypeio/go-anytype-middleware/core/history"
|
||||
"github.com/anytypeio/go-anytype-middleware/core/indexer"
|
||||
|
@ -54,6 +53,8 @@ import (
|
|||
"github.com/anytypeio/go-anytype-middleware/pkg/lib/localstore/objectstore"
|
||||
"github.com/anytypeio/go-anytype-middleware/space"
|
||||
"github.com/anytypeio/go-anytype-middleware/space/clientserver"
|
||||
//nolint: misspell
|
||||
"github.com/anytypeio/go-anytype-middleware/space/credentialprovider"
|
||||
"github.com/anytypeio/go-anytype-middleware/space/debug/clientdebugrpc"
|
||||
"github.com/anytypeio/go-anytype-middleware/space/localdiscovery"
|
||||
"github.com/anytypeio/go-anytype-middleware/space/peermanager"
|
||||
|
@ -75,8 +76,8 @@ func BootstrapConfig(newAccount bool, isStaging bool, createBuiltinObjects bool)
|
|||
)
|
||||
}
|
||||
|
||||
func BootstrapWallet(rootPath string, accountKey crypto.PrivKey) wallet.Wallet {
|
||||
return wallet.NewWithAccountRepo(rootPath, accountKey)
|
||||
func BootstrapWallet(rootPath string, derivationResult crypto.DerivationResult) wallet.Wallet {
|
||||
return wallet.NewWithAccountRepo(rootPath, derivationResult)
|
||||
}
|
||||
|
||||
func StartNewApp(ctx context.Context, components ...app.Component) (a *app.App, err error) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package configfetcher
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/anytypeio/go-anytype-middleware/core/wallet"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -59,6 +60,7 @@ type configFetcher struct {
|
|||
periodicSync periodicsync.PeriodicSync
|
||||
client coordinatorclient.CoordinatorClient
|
||||
spaceService space.Service
|
||||
wallet wallet.Wallet
|
||||
}
|
||||
|
||||
func (c *configFetcher) GetAccountState() (state *pb.AccountState) {
|
||||
|
@ -88,6 +90,7 @@ func (c *configFetcher) Run(context.Context) error {
|
|||
|
||||
func (c *configFetcher) Init(a *app.App) (err error) {
|
||||
c.store = a.MustComponent(objectstore.CName).(objectstore.ObjectStore)
|
||||
c.wallet = a.MustComponent(wallet.CName).(wallet.Wallet)
|
||||
c.eventSender = a.MustComponent(event.CName).(event.Sender).Send
|
||||
c.periodicSync = periodicsync.NewPeriodicSync(300, time.Second*10, c.updateStatus, logger.CtxLogger{Logger: log.Desugar()})
|
||||
c.client = a.MustComponent(coordinatorclient.CName).(coordinatorclient.CoordinatorClient)
|
||||
|
@ -116,8 +119,14 @@ func (c *configFetcher) updateStatus(ctx context.Context) (err error) {
|
|||
if sErr != nil {
|
||||
return sErr
|
||||
}
|
||||
payload := coordinatorclient.SpaceSignPayload{
|
||||
SpaceId: header.Id,
|
||||
SpaceHeader: header.RawHeader,
|
||||
OldAccount: c.wallet.GetOldAccountKey(),
|
||||
Identity: c.wallet.GetDevicePrivkey(),
|
||||
}
|
||||
// registering space inside coordinator
|
||||
_, err = c.client.SpaceSign(ctx, header.Id, header.RawHeader)
|
||||
_, err = c.client.SpaceSign(ctx, payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -3,9 +3,6 @@ package filestorage
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/anytypeio/any-sync/app"
|
||||
"github.com/anytypeio/any-sync/app/logger"
|
||||
"github.com/anytypeio/any-sync/commonfile/fileblockstore"
|
||||
|
@ -13,9 +10,10 @@ import (
|
|||
"github.com/anytypeio/any-sync/commonspace/spacestorage"
|
||||
"github.com/anytypeio/any-sync/net/rpc/server"
|
||||
"github.com/dgraph-io/badger/v3"
|
||||
blocks "github.com/ipfs/go-block-format"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-libipfs/blocks"
|
||||
"go.uber.org/zap"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/anytypeio/go-anytype-middleware/core/anytype/config"
|
||||
"github.com/anytypeio/go-anytype-middleware/core/filestorage/rpcstore"
|
||||
|
@ -83,8 +81,6 @@ func (f *fileStorage) patchAccountIdCtx(ctx context.Context) context.Context {
|
|||
return fileblockstore.CtxWithSpaceId(ctx, f.spaceService.AccountId())
|
||||
}
|
||||
|
||||
const errDirectoryIsLocked = "Cannot acquire directory lock"
|
||||
|
||||
func (f *fileStorage) Run(ctx context.Context) (err error) {
|
||||
bs, err := newFlatStore(f.flatfsPath)
|
||||
if err != nil {
|
||||
|
@ -92,9 +88,12 @@ func (f *fileStorage) Run(ctx context.Context) (err error) {
|
|||
}
|
||||
f.handler.store = bs
|
||||
|
||||
oldStore, storeErr := f.initOldStore()
|
||||
if storeErr != nil {
|
||||
log.Error("can't open legacy file store", zap.Error(storeErr))
|
||||
var oldStore *badger.DB
|
||||
if f.cfg.LegacyFileStorePath != "" {
|
||||
oldStore, err = badger.Open(badger.DefaultOptions(f.cfg.LegacyFileStorePath))
|
||||
if err != nil {
|
||||
return fmt.Errorf("open old file store: %w", err)
|
||||
}
|
||||
}
|
||||
ps := &proxyStore{
|
||||
cache: bs,
|
||||
|
@ -104,16 +103,6 @@ func (f *fileStorage) Run(ctx context.Context) (err error) {
|
|||
f.BlockStoreLocal = ps
|
||||
return
|
||||
}
|
||||
|
||||
func (f *fileStorage) initOldStore() (*badger.DB, error) {
|
||||
if f.cfg.LegacyFileStorePath == "" {
|
||||
return nil, nil
|
||||
}
|
||||
if _, err := os.Stat(f.cfg.LegacyFileStorePath); os.IsNotExist(err) {
|
||||
return nil, nil
|
||||
}
|
||||
return badger.Open(badger.DefaultOptions(f.cfg.LegacyFileStorePath))
|
||||
}
|
||||
func (f *fileStorage) Get(ctx context.Context, k cid.Cid) (b blocks.Block, err error) {
|
||||
return f.BlockStoreLocal.Get(f.patchAccountIdCtx(ctx), k)
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
"github.com/anytypeio/any-sync/app/logger"
|
||||
"github.com/anytypeio/any-sync/commonfile/fileservice"
|
||||
"github.com/cheggaaa/mb/v3"
|
||||
blocks "github.com/ipfs/go-block-format"
|
||||
"github.com/ipfs/go-cid"
|
||||
ipld "github.com/ipfs/go-ipld-format"
|
||||
"github.com/ipfs/go-libipfs/blocks"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/anytypeio/go-anytype-middleware/core/filestorage/rpcstore"
|
||||
|
|
|
@ -13,8 +13,8 @@ import (
|
|||
"github.com/anytypeio/go-anytype-middleware/pkg/lib/datastore"
|
||||
"github.com/dgraph-io/badger/v3"
|
||||
"github.com/golang/mock/gomock"
|
||||
blocks "github.com/ipfs/go-block-format"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-libipfs/blocks"
|
||||
"github.com/stretchr/testify/require"
|
||||
"math/rand"
|
||||
"os"
|
||||
|
|
|
@ -7,11 +7,11 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/anytypeio/any-sync/commonfile/fileproto"
|
||||
blocks "github.com/ipfs/go-block-format"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-datastore"
|
||||
flatfs "github.com/ipfs/go-ds-flatfs"
|
||||
format "github.com/ipfs/go-ipld-format"
|
||||
"github.com/ipfs/go-libipfs/blocks"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
|
|
@ -2,22 +2,32 @@ package filestorage
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
format "github.com/ipfs/go-ipld-format"
|
||||
"github.com/ipfs/go-libipfs/blocks"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/anytypeio/go-anytype-middleware/core/filestorage/rpcstore"
|
||||
"github.com/dgraph-io/badger/v3"
|
||||
blocks "github.com/ipfs/go-block-format"
|
||||
"github.com/ipfs/go-cid"
|
||||
dshelp "github.com/ipfs/go-ipfs-ds-help"
|
||||
format "github.com/ipfs/go-ipld-format"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type proxyStore struct {
|
||||
cache *flatStore
|
||||
origin rpcstore.RpcStore
|
||||
|
||||
oldStore *badger.DB
|
||||
}
|
||||
|
||||
func (c *proxyStore) Get(ctx context.Context, k cid.Cid) (b blocks.Block, err error) {
|
||||
b, err = c.getFromOldStore(k)
|
||||
if err == nil {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
log.Debug("get cid", zap.String("cid", k.String()))
|
||||
if b, err = c.cache.Get(ctx, k); err != nil {
|
||||
if format.IsNotFound(err) {
|
||||
err = nil
|
||||
|
@ -38,14 +48,50 @@ func (c *proxyStore) Get(ctx context.Context, k cid.Cid) (b blocks.Block, err er
|
|||
return
|
||||
}
|
||||
|
||||
func (c *proxyStore) getFromOldStore(k cid.Cid) (blocks.Block, error) {
|
||||
if c.oldStore == nil {
|
||||
return nil, fmt.Errorf("old store is not used")
|
||||
}
|
||||
dsKey := cidToOldDsKey(k)
|
||||
var b blocks.Block
|
||||
err := c.oldStore.View(func(txn *badger.Txn) error {
|
||||
item, err := txn.Get([]byte(dsKey))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = item.Value(func(val []byte) error {
|
||||
b, err = blocks.NewBlockWithCid(val, k)
|
||||
return err
|
||||
})
|
||||
return err
|
||||
})
|
||||
if err == nil {
|
||||
return b, nil
|
||||
}
|
||||
if err != nil && err != badger.ErrKeyNotFound {
|
||||
log.Error("get from old store", zap.String("cid", k.String()), zap.String("key", dsKey), zap.Error(err))
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func cidToOldDsKey(k cid.Cid) string {
|
||||
return "/blocks" + dshelp.MultihashToDsKey(k.Hash()).String()
|
||||
}
|
||||
|
||||
func (c *proxyStore) GetMany(ctx context.Context, ks []cid.Cid) <-chan blocks.Block {
|
||||
fromCache, fromOrigin, localErr := c.cache.PartitionByExistence(ctx, ks)
|
||||
remaining, oldResults := c.getManyFromOldStore(ks)
|
||||
if len(remaining) == 0 {
|
||||
return oldResults
|
||||
}
|
||||
gotFromOldStore := len(ks) - len(remaining)
|
||||
|
||||
fromCache, fromOrigin, localErr := c.cache.PartitionByExistence(ctx, remaining)
|
||||
if localErr != nil {
|
||||
log.Error("proxy store hasCIDs error", zap.Error(localErr))
|
||||
fromOrigin = ks
|
||||
}
|
||||
log.Debug("get many cids", zap.Int("cached", len(fromCache)), zap.Int("origin", len(fromOrigin)))
|
||||
if len(fromOrigin) == 0 {
|
||||
if len(fromOrigin) == 0 && gotFromOldStore == 0 {
|
||||
return c.cache.GetMany(ctx, fromCache)
|
||||
}
|
||||
results := make(chan blocks.Block)
|
||||
|
@ -54,10 +100,14 @@ func (c *proxyStore) GetMany(ctx context.Context, ks []cid.Cid) <-chan blocks.Bl
|
|||
defer close(results)
|
||||
localResults := c.cache.GetMany(ctx, fromCache)
|
||||
originResults := c.origin.GetMany(ctx, fromOrigin)
|
||||
oOk, cOk := true, true
|
||||
oOk, cOk, oldOk := true, true, true
|
||||
for {
|
||||
var cb, ob blocks.Block
|
||||
var cb, ob, b blocks.Block
|
||||
select {
|
||||
case b, oldOk = <-oldResults:
|
||||
if oldOk {
|
||||
results <- b
|
||||
}
|
||||
case cb, cOk = <-localResults:
|
||||
if cOk {
|
||||
results <- cb
|
||||
|
@ -72,7 +122,7 @@ func (c *proxyStore) GetMany(ctx context.Context, ks []cid.Cid) <-chan blocks.Bl
|
|||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
if !oOk && !cOk {
|
||||
if !oOk && !cOk && !oldOk {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +130,59 @@ func (c *proxyStore) GetMany(ctx context.Context, ks []cid.Cid) <-chan blocks.Bl
|
|||
return results
|
||||
}
|
||||
|
||||
func (c *proxyStore) getManyFromOldStore(ks []cid.Cid) (remaining []cid.Cid, results chan blocks.Block) {
|
||||
results = make(chan blocks.Block)
|
||||
|
||||
if c.oldStore == nil {
|
||||
close(results)
|
||||
return ks, results
|
||||
}
|
||||
|
||||
get := func(txn *badger.Txn, k cid.Cid, dsKey string) (blocks.Block, error) {
|
||||
item, err := txn.Get([]byte(dsKey))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var b blocks.Block
|
||||
err = item.Value(func(val []byte) error {
|
||||
b, err = blocks.NewBlockWithCid(val, k)
|
||||
return err
|
||||
})
|
||||
return b, err
|
||||
}
|
||||
|
||||
var bs []blocks.Block
|
||||
err := c.oldStore.View(func(txn *badger.Txn) error {
|
||||
for _, k := range ks {
|
||||
dsKey := cidToOldDsKey(k)
|
||||
b, err := get(txn, k, dsKey)
|
||||
if err != nil {
|
||||
remaining = append(remaining, k)
|
||||
if err != badger.ErrKeyNotFound {
|
||||
log.Error("get many from old store", zap.String("cid", k.String()), zap.String("key", dsKey), zap.Error(err))
|
||||
}
|
||||
continue
|
||||
}
|
||||
bs = append(bs, b)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
log.Error("get many from old store: view tx", zap.Error(err))
|
||||
close(results)
|
||||
return remaining, results
|
||||
}
|
||||
|
||||
results = make(chan blocks.Block)
|
||||
go func() {
|
||||
defer close(results)
|
||||
for _, b := range bs {
|
||||
results <- b
|
||||
}
|
||||
}()
|
||||
return remaining, results
|
||||
}
|
||||
|
||||
func (c *proxyStore) Add(ctx context.Context, bs []blocks.Block) (err error) {
|
||||
if bs, err = c.cache.NotExistsBlocks(ctx, bs); err != nil {
|
||||
return
|
||||
|
@ -104,6 +207,11 @@ func (c *proxyStore) NotExistsBlocks(ctx context.Context, bs []blocks.Block) (no
|
|||
}
|
||||
|
||||
func (c *proxyStore) Close() error {
|
||||
if c.oldStore != nil {
|
||||
if err := c.oldStore.Close(); err != nil {
|
||||
log.Error("error while closing old store", zap.Error(err))
|
||||
}
|
||||
}
|
||||
if err := c.cache.Close(); err != nil {
|
||||
log.Error("error while closing cache store", zap.Error(err))
|
||||
}
|
||||
|
|
|
@ -10,9 +10,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/dgraph-io/badger/v3"
|
||||
blocks "github.com/ipfs/go-block-format"
|
||||
"github.com/ipfs/go-cid"
|
||||
format "github.com/ipfs/go-ipld-format"
|
||||
"github.com/ipfs/go-libipfs/blocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
|
||||
"github.com/anytypeio/any-sync/commonfile/fileblockstore"
|
||||
"github.com/anytypeio/any-sync/commonfile/fileproto"
|
||||
blocks "github.com/ipfs/go-block-format"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-libipfs/blocks"
|
||||
"go.uber.org/multierr"
|
||||
"go.uber.org/zap"
|
||||
"golang.org/x/exp/slices"
|
||||
|
|
|
@ -13,8 +13,8 @@ import (
|
|||
"github.com/anytypeio/any-sync/nodeconf"
|
||||
"github.com/anytypeio/go-anytype-middleware/space/peerstore"
|
||||
"github.com/golang/mock/gomock"
|
||||
blocks "github.com/ipfs/go-block-format"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-libipfs/blocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"sort"
|
||||
|
|
|
@ -22,25 +22,32 @@ type wallet struct {
|
|||
repoPath string // other components will init their files/dirs inside
|
||||
deviceKeyPath string
|
||||
|
||||
accountKeypair crypto.PrivKey
|
||||
deviceKeypair crypto.PrivKey
|
||||
accountData *accountdata.AccountKeys
|
||||
accountKey crypto.PrivKey
|
||||
deviceKey crypto.PrivKey
|
||||
masterKey crypto.PrivKey
|
||||
oldAccountKey crypto.PrivKey
|
||||
// this is needed for any-sync
|
||||
accountData *accountdata.AccountKeys
|
||||
}
|
||||
|
||||
func (r *wallet) GetAccountPrivkey() (crypto.PrivKey, error) {
|
||||
return r.accountData.SignKey, nil
|
||||
func (r *wallet) GetAccountPrivkey() crypto.PrivKey {
|
||||
return r.accountData.SignKey
|
||||
}
|
||||
|
||||
func (r *wallet) GetDevicePrivkey() (crypto.PrivKey, error) {
|
||||
return r.accountData.PeerKey, nil
|
||||
func (r *wallet) GetDevicePrivkey() crypto.PrivKey {
|
||||
return r.accountData.PeerKey
|
||||
}
|
||||
|
||||
func (r *wallet) GetOldAccountKey() crypto.PrivKey {
|
||||
return r.oldAccountKey
|
||||
}
|
||||
|
||||
func (r *wallet) Init(a *app.App) (err error) {
|
||||
if r.accountKeypair == nil {
|
||||
if r.accountKey == nil {
|
||||
return fmt.Errorf("no account key present")
|
||||
}
|
||||
var b []byte
|
||||
if r.deviceKeypair == nil {
|
||||
if r.deviceKey == nil {
|
||||
if r.deviceKeyPath == "" {
|
||||
return fmt.Errorf("no path for device key")
|
||||
}
|
||||
|
@ -48,23 +55,23 @@ func (r *wallet) Init(a *app.App) (err error) {
|
|||
if err != nil {
|
||||
return fmt.Errorf("failed to read device keyfile: %w", err)
|
||||
}
|
||||
dec, err := r.accountKeypair.Decrypt(b)
|
||||
dec, err := r.accountKey.Decrypt(b)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to decrypt device keyfile: %w", err)
|
||||
}
|
||||
r.deviceKeypair, err = crypto.UnmarshalEd25519PrivateKeyProto(dec)
|
||||
r.deviceKey, err = crypto.UnmarshalEd25519PrivateKeyProto(dec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to unmarshall device keyfile: %w", err)
|
||||
}
|
||||
}
|
||||
peerId := r.deviceKeypair.GetPublic().PeerId()
|
||||
accountId := r.accountKeypair.GetPublic().Account()
|
||||
peerId := r.deviceKey.GetPublic().PeerId()
|
||||
accountId := r.accountKey.GetPublic().Account()
|
||||
logging.SetHost(peerId)
|
||||
metrics.SharedClient.SetDeviceId(peerId)
|
||||
logging.SetAccount(accountId)
|
||||
metrics.SharedClient.SetUserId(accountId)
|
||||
|
||||
r.accountData = accountdata.New(r.deviceKeypair, r.accountKeypair)
|
||||
r.accountData = accountdata.New(r.deviceKey, r.accountKey, r.masterKey)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -84,30 +91,33 @@ func (r *wallet) Account() *accountdata.AccountKeys {
|
|||
return r.accountData
|
||||
}
|
||||
|
||||
func NewWithAccountRepo(rootPath string, accountKey crypto.PrivKey) Wallet {
|
||||
accountId := accountKey.GetPublic().Account()
|
||||
func NewWithAccountRepo(rootPath string, derivationResult crypto.DerivationResult) Wallet {
|
||||
accountId := derivationResult.Identity.GetPublic().Account()
|
||||
repoPath := filepath.Join(rootPath, accountId)
|
||||
return &wallet{
|
||||
rootPath: rootPath,
|
||||
repoPath: repoPath,
|
||||
accountKeypair: accountKey,
|
||||
deviceKeyPath: filepath.Join(repoPath, keyFileDevice),
|
||||
rootPath: rootPath,
|
||||
repoPath: repoPath,
|
||||
masterKey: derivationResult.MasterKey,
|
||||
oldAccountKey: derivationResult.OldAccountKey,
|
||||
accountKey: derivationResult.Identity,
|
||||
deviceKeyPath: filepath.Join(repoPath, keyFileDevice),
|
||||
}
|
||||
}
|
||||
|
||||
func NewWithRepoPathAndKeys(repoPath string, accountKeypair, deviceKeypair crypto.PrivKey) Wallet {
|
||||
return &wallet{
|
||||
repoPath: repoPath,
|
||||
accountKeypair: accountKeypair,
|
||||
deviceKeypair: deviceKeypair,
|
||||
repoPath: repoPath,
|
||||
accountKey: accountKeypair,
|
||||
deviceKey: deviceKeypair,
|
||||
}
|
||||
}
|
||||
|
||||
type Wallet interface {
|
||||
RootPath() string
|
||||
RepoPath() string
|
||||
GetAccountPrivkey() (crypto.PrivKey, error)
|
||||
GetDevicePrivkey() (crypto.PrivKey, error)
|
||||
GetAccountPrivkey() crypto.PrivKey
|
||||
GetDevicePrivkey() crypto.PrivKey
|
||||
GetOldAccountKey() crypto.PrivKey
|
||||
accountservice.Service
|
||||
app.Component
|
||||
}
|
||||
|
|
13
go.mod
13
go.mod
|
@ -7,7 +7,7 @@ require (
|
|||
github.com/PuerkitoBio/goquery v1.8.1
|
||||
github.com/VividCortex/ewma v1.2.0
|
||||
github.com/adrium/goheif v0.0.0-20230113233934-ca402e77a786
|
||||
github.com/anytypeio/any-sync v0.0.28-0.20230328192912-f472fd83c48c
|
||||
github.com/anytypeio/any-sync v0.0.30-0.20230402165302-13df75d0e077
|
||||
github.com/anytypeio/go-naturaldate/v2 v2.0.1
|
||||
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
|
||||
github.com/blevesearch/bleve/v2 v2.3.6
|
||||
|
@ -24,7 +24,7 @@ require (
|
|||
github.com/dsoprea/go-jpeg-image-structure/v2 v2.0.0-20210512043942-b434301c6836
|
||||
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8
|
||||
github.com/go-shiori/go-readability v0.0.0-20220215145315-dd6828d2f09b
|
||||
github.com/goccy/go-graphviz v0.1.0
|
||||
github.com/goccy/go-graphviz v0.1.1
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
github.com/gogo/status v1.1.0
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||
|
@ -52,7 +52,7 @@ require (
|
|||
github.com/ipfs/go-log v1.0.5
|
||||
github.com/ipfs/go-merkledag v0.10.0
|
||||
github.com/ipfs/go-path v0.3.0
|
||||
github.com/ipfs/go-unixfs v0.4.4
|
||||
github.com/ipfs/go-unixfs v0.4.5
|
||||
github.com/ipfs/interface-go-ipfs-core v0.10.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e
|
||||
|
@ -88,7 +88,7 @@ require (
|
|||
go.uber.org/multierr v1.9.0
|
||||
go.uber.org/zap v1.24.0
|
||||
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
|
||||
golang.org/x/image v0.0.0-20211028202545-6944b10bf410
|
||||
golang.org/x/image v0.6.0
|
||||
golang.org/x/net v0.8.0
|
||||
golang.org/x/oauth2 v0.3.0
|
||||
golang.org/x/text v0.8.0
|
||||
|
@ -103,6 +103,7 @@ require (
|
|||
filippo.io/edwards25519 v1.0.0 // indirect
|
||||
github.com/anytypeio/go-slip10 v0.0.0-20200330112030-a352ca8495e4 // indirect
|
||||
github.com/anytypeio/go-slip21 v0.0.0-20200218204727-e2e51e20ab51 // indirect
|
||||
github.com/ipfs/go-ipfs-files v0.3.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
)
|
||||
|
||||
|
@ -175,7 +176,7 @@ require (
|
|||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/ipfs/bbloom v0.0.4 // indirect
|
||||
github.com/ipfs/go-bitfield v1.1.0 // indirect
|
||||
github.com/ipfs/go-block-format v0.1.1 // indirect
|
||||
github.com/ipfs/go-block-format v0.1.2
|
||||
github.com/ipfs/go-blockservice v0.5.0 // indirect
|
||||
github.com/ipfs/go-ipfs-chunker v0.0.5 // indirect
|
||||
github.com/ipfs/go-ipfs-exchange-interface v0.2.0 // indirect
|
||||
|
@ -232,7 +233,7 @@ require (
|
|||
go.opentelemetry.io/otel v1.11.2 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.11.2 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
golang.org/x/crypto v0.5.0 // indirect
|
||||
golang.org/x/crypto v0.7.0 // indirect
|
||||
golang.org/x/mod v0.8.0 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.6.0 // indirect
|
||||
|
|
31
go.sum
31
go.sum
|
@ -57,8 +57,8 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYU
|
|||
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
||||
github.com/anytypeio/amplitude-go v0.0.0-20211130222238-8d16496a9b31 h1:fCXBjRAxXq4pKyfH8xmYPfjL/E6v5zTTxYrIKDz8ufw=
|
||||
github.com/anytypeio/amplitude-go v0.0.0-20211130222238-8d16496a9b31/go.mod h1:uX6FcwR+wTQWzFszLXQxeKfNeittg1408V7pVAtLKqQ=
|
||||
github.com/anytypeio/any-sync v0.0.28-0.20230328192912-f472fd83c48c h1:oGJz985UFqB5r8HA6N2JiMJhTQeYxdaR6j6Zjf5jTv0=
|
||||
github.com/anytypeio/any-sync v0.0.28-0.20230328192912-f472fd83c48c/go.mod h1:uTnp2CTKxOh8A/Z/CWhusKCLgaoXUAIwHj3qAjcXc4A=
|
||||
github.com/anytypeio/any-sync v0.0.30-0.20230402165302-13df75d0e077 h1:AErBSZINHbst87mbcU9I4DO/5L+tVuJS1nafUwkYGOw=
|
||||
github.com/anytypeio/any-sync v0.0.30-0.20230402165302-13df75d0e077/go.mod h1:xMdL2/gujnCz2VIOnA7asOgFG6JfxTdiCnj4KasTZAg=
|
||||
github.com/anytypeio/go-chash v0.0.2 h1:BSpyMC3HXNkf2eosQrHM4svov0DrvxL9tb4gnHbdmbA=
|
||||
github.com/anytypeio/go-chash v0.0.2/go.mod h1:G+R6q7jYgNa52NqcRhnNm28pogfWW+cuHtgBktrc2QA=
|
||||
github.com/anytypeio/go-ds-badger3 v0.3.1-0.20221103102622-3233d4e13cb8 h1:LC9w0M0SbA5VuZeBtUdq+uR4mdjbJhxurNtovmRiOrU=
|
||||
|
@ -193,7 +193,6 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
|
|||
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||
github.com/corona10/goimagehash v1.0.2 h1:pUfB0LnsJASMPGEZLj7tGY251vF+qLGqOgEP4rUs6kA=
|
||||
github.com/corona10/goimagehash v1.0.2/go.mod h1:/l9umBhvcHQXVtQO1V6Gp1yD20STawkhRnnX0D1bvVI=
|
||||
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
|
@ -343,8 +342,8 @@ github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8=
|
|||
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
||||
github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo=
|
||||
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
|
||||
github.com/goccy/go-graphviz v0.1.0 h1:6OqQoQ5PeAiHYe/YcusyeulqBrOkUb16HQ4ctRdyVUU=
|
||||
github.com/goccy/go-graphviz v0.1.0/go.mod h1:wXVsXxmyMQU6TN3zGRttjNn3h+iCAS7xQFC6TlNvLhk=
|
||||
github.com/goccy/go-graphviz v0.1.1 h1:MGrsnzBxTyt7KG8FhHsFPDTGvF7UaQMmSa6A610DqPg=
|
||||
github.com/goccy/go-graphviz v0.1.1/go.mod h1:lpnwvVDjskayq84ZxG8tGCPeZX/WxP88W+OJajh+gFk=
|
||||
github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
|
||||
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
|
||||
github.com/gogo/googleapis v1.3.1 h1:CzMaKrvF6Qa7XtRii064vKBQiyvmY8H8vG1xa1/W1JA=
|
||||
|
@ -528,8 +527,8 @@ github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1Hy
|
|||
github.com/ipfs/go-block-format v0.0.1/go.mod h1:DK/YYcsSUIVAFNwo/KZCdIIbpN0ROH/baNLgayt4pFc=
|
||||
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
|
||||
github.com/ipfs/go-block-format v0.0.3/go.mod h1:4LmD4ZUw0mhO+JSKdpWwrzATiEfM7WWgQ8H5l6P8MVk=
|
||||
github.com/ipfs/go-block-format v0.1.1 h1:129vSO3zwbsYADcyQWcOYiuCpAqt462SFfqFHdFJhhI=
|
||||
github.com/ipfs/go-block-format v0.1.1/go.mod h1:+McEIT+g52p+zz5xGAABGSOKrzmrdX97bc0USBdWPUs=
|
||||
github.com/ipfs/go-block-format v0.1.2 h1:GAjkfhVx1f4YTODS6Esrj1wt2HhrtwTnhEr+DyPUaJo=
|
||||
github.com/ipfs/go-block-format v0.1.2/go.mod h1:mACVcrxarQKstUU3Yf/RdwbC4DzPV6++rO2a3d+a/KE=
|
||||
github.com/ipfs/go-blockservice v0.1.0/go.mod h1:hzmMScl1kXHg3M2BjTymbVPjv627N7sYcvYaKbop39M=
|
||||
github.com/ipfs/go-blockservice v0.2.1/go.mod h1:k6SiwmgyYgs4M/qt+ww6amPeUH9EISLRBnvUurKJhi8=
|
||||
github.com/ipfs/go-blockservice v0.5.0 h1:B2mwhhhVQl2ntW2EIpaWPwSCxSuqr5fFA93Ms4bYLEY=
|
||||
|
@ -595,6 +594,8 @@ github.com/ipfs/go-ipfs-exchange-offline v0.0.1/go.mod h1:WhHSFCVYX36H/anEKQboAz
|
|||
github.com/ipfs/go-ipfs-exchange-offline v0.1.1/go.mod h1:vTiBRIbzSwDD0OWm+i3xeT0mO7jG2cbJYatp3HPk5XY=
|
||||
github.com/ipfs/go-ipfs-exchange-offline v0.3.0 h1:c/Dg8GDPzixGd0MC8Jh6mjOwU57uYokgWRFidfvEkuA=
|
||||
github.com/ipfs/go-ipfs-files v0.0.3/go.mod h1:INEFm0LL2LWXBhNJ2PMIIb2w45hpXgPjNoE7yA8Y1d4=
|
||||
github.com/ipfs/go-ipfs-files v0.3.0 h1:fallckyc5PYjuMEitPNrjRfpwl7YFt69heCOUhsbGxQ=
|
||||
github.com/ipfs/go-ipfs-files v0.3.0/go.mod h1:xAUtYMwB+iu/dtf6+muHNSFQCJG2dSiStR2P6sn9tIM=
|
||||
github.com/ipfs/go-ipfs-posinfo v0.0.1 h1:Esoxj+1JgSjX0+ylc0hUmJCOv6V2vFoZiETLR6OtpRs=
|
||||
github.com/ipfs/go-ipfs-posinfo v0.0.1/go.mod h1:SwyeVP+jCwiDu0C313l/8jg6ZxM0qqtlt2a0vILTc1A=
|
||||
github.com/ipfs/go-ipfs-pq v0.0.1/go.mod h1:LWIqQpqfRG3fNc5XsnIhz/wQ2XXGyugQwls7BgUmUfY=
|
||||
|
@ -640,8 +641,8 @@ github.com/ipfs/go-peertaskqueue v0.1.0/go.mod h1:Jmk3IyCcfl1W3jTW3YpghSwSEC6IJ3
|
|||
github.com/ipfs/go-peertaskqueue v0.7.0/go.mod h1:M/akTIE/z1jGNXMU7kFB4TeSEFvj68ow0Rrb04donIU=
|
||||
github.com/ipfs/go-peertaskqueue v0.8.1 h1:YhxAs1+wxb5jk7RvS0LHdyiILpNmRIRnZVztekOF0pg=
|
||||
github.com/ipfs/go-unixfs v0.2.4/go.mod h1:SUdisfUjNoSDzzhGVxvCL9QO/nKdwXdr+gbMUdqcbYw=
|
||||
github.com/ipfs/go-unixfs v0.4.4 h1:D/dLBOJgny5ZLIur2vIXVQVW0EyDHdOMBDEhgHrt6rY=
|
||||
github.com/ipfs/go-unixfs v0.4.4/go.mod h1:TSG7G1UuT+l4pNj91raXAPkX0BhJi3jST1FDTfQ5QyM=
|
||||
github.com/ipfs/go-unixfs v0.4.5 h1:wj8JhxvV1G6CD7swACwSKYa+NgtdWC1RUit+gFnymDU=
|
||||
github.com/ipfs/go-unixfs v0.4.5/go.mod h1:BIznJNvt/gEx/ooRMI4Us9K8+qeGO7vx1ohnbk8gjFg=
|
||||
github.com/ipfs/go-unixfsnode v1.1.2/go.mod h1:5dcE2x03pyjHk4JjamXmunTMzz+VUtqvPwZjIEkfV6s=
|
||||
github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0=
|
||||
github.com/ipfs/go-verifcid v0.0.2 h1:XPnUv0XmdH+ZIhLGKg6U2vaPaRDXb9urMyNVCE7uvTs=
|
||||
|
@ -908,6 +909,7 @@ github.com/libp2p/go-yamux v1.3.3/go.mod h1:FGTiPvoV/3DVdgWpX+tM0OW3tsM+W5bSE3gZ
|
|||
github.com/libp2p/go-yamux v1.3.5/go.mod h1:FGTiPvoV/3DVdgWpX+tM0OW3tsM+W5bSE3gZwqQTcow=
|
||||
github.com/libp2p/go-yamux v1.3.7/go.mod h1:fr7aVgmdNGJK+N1g+b6DW6VxzbRCjCOejR/hkmpooHE=
|
||||
github.com/libp2p/go-yamux v1.4.0/go.mod h1:fr7aVgmdNGJK+N1g+b6DW6VxzbRCjCOejR/hkmpooHE=
|
||||
github.com/libp2p/go-yamux v1.4.1 h1:P1Fe9vF4th5JOxxgQvfbOHkrGqIZniTLf+ddhZp8YTI=
|
||||
github.com/libp2p/go-yamux v1.4.1/go.mod h1:fr7aVgmdNGJK+N1g+b6DW6VxzbRCjCOejR/hkmpooHE=
|
||||
github.com/libp2p/go-yamux/v2 v2.2.0/go.mod h1:3So6P6TV6r75R9jiBpiIKgU/66lOarCZjqROGxzPpPQ=
|
||||
github.com/libp2p/go-yamux/v4 v4.0.0 h1:+Y80dV2Yx/kv7Y7JKu0LECyVdMXm1VUoko+VQ9rBfZQ=
|
||||
|
@ -1059,7 +1061,6 @@ github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OS
|
|||
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
|
||||
github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
|
||||
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/RzCAL/191HHwJA5b13R6diVlY=
|
||||
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
|
||||
|
@ -1418,7 +1419,6 @@ golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443/go.mod h1:yigFU9vqHzYiE8U
|
|||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
|
@ -1428,8 +1428,8 @@ golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWP
|
|||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
|
||||
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
|
||||
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
|
||||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
|
||||
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
|
@ -1443,9 +1443,8 @@ golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86h
|
|||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ=
|
||||
golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
|
||||
golang.org/x/image v0.6.0 h1:bR8b5okrPI3g/gyZakLZHeWxAR8Dn5CyxXv1hLH5g/4=
|
||||
golang.org/x/image v0.6.0/go.mod h1:MXLdDR43H7cDJq5GEGXEVeeNhPgi+YYEQ2pC1byI1x0=
|
||||
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
|
|
|
@ -67,14 +67,8 @@ func (c *Online) Init(a *app.App) (err error) {
|
|||
c.grpcAddress = cfg.CafeNodeGrpcAddr()
|
||||
c.apiInsecure = cfg.CafeAPIInsecure
|
||||
|
||||
c.device, err = wl.GetDevicePrivkey()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.account, err = wl.GetAccountPrivkey()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.device = wl.GetDevicePrivkey()
|
||||
c.account = wl.GetAccountPrivkey()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -153,19 +153,13 @@ func (a *Anytype) SpaceService() space.Service {
|
|||
|
||||
// Deprecated, use wallet component directly
|
||||
func (a *Anytype) Account() string {
|
||||
pk, _ := a.wallet.GetAccountPrivkey()
|
||||
if pk == nil {
|
||||
return ""
|
||||
}
|
||||
pk := a.wallet.GetAccountPrivkey()
|
||||
return pk.GetPublic().Account()
|
||||
}
|
||||
|
||||
// Deprecated, use wallet component directly
|
||||
func (a *Anytype) Device() string {
|
||||
pk, _ := a.wallet.GetDevicePrivkey()
|
||||
if pk == nil {
|
||||
return ""
|
||||
}
|
||||
pk := a.wallet.GetDevicePrivkey()
|
||||
return pk.GetPublic().PeerId()
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ func WalletGenerateMnemonic(wordCount int) (string, error) {
|
|||
return string(m), nil
|
||||
}
|
||||
|
||||
func WalletAccountAt(mnemonic string, index int) (crypto.PrivKey, error) {
|
||||
return crypto.Mnemonic(mnemonic).DeriveEd25519Key(index)
|
||||
func WalletAccountAt(mnemonic string, index int) (crypto.DerivationResult, error) {
|
||||
return crypto.Mnemonic(mnemonic).DeriveKeys(uint32(index))
|
||||
}
|
||||
|
||||
func WalletInitRepo(rootPath string, pk crypto.PrivKey) error {
|
||||
|
|
44
space/credentialprovider/credentialprovider.go
Normal file
44
space/credentialprovider/credentialprovider.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package credentialprovider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/anytypeio/any-sync/app"
|
||||
"github.com/anytypeio/any-sync/commonspace/credentialprovider"
|
||||
"github.com/anytypeio/any-sync/commonspace/spacesyncproto"
|
||||
"github.com/anytypeio/any-sync/coordinator/coordinatorclient"
|
||||
"github.com/anytypeio/go-anytype-middleware/core/wallet"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
func New() app.Component {
|
||||
return &credentialProvider{}
|
||||
}
|
||||
|
||||
type credentialProvider struct {
|
||||
client coordinatorclient.CoordinatorClient
|
||||
wallet wallet.Wallet
|
||||
}
|
||||
|
||||
func (c *credentialProvider) Init(a *app.App) (err error) {
|
||||
c.client = a.MustComponent(coordinatorclient.CName).(coordinatorclient.CoordinatorClient)
|
||||
c.wallet = a.MustComponent(wallet.CName).(wallet.Wallet)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *credentialProvider) Name() (name string) {
|
||||
return credentialprovider.CName
|
||||
}
|
||||
|
||||
func (c *credentialProvider) GetCredential(ctx context.Context, spaceHeader *spacesyncproto.RawSpaceHeaderWithId) ([]byte, error) {
|
||||
payload := coordinatorclient.SpaceSignPayload{
|
||||
SpaceId: spaceHeader.Id,
|
||||
SpaceHeader: spaceHeader.RawHeader,
|
||||
OldAccount: c.wallet.GetOldAccountKey(),
|
||||
Identity: c.wallet.GetDevicePrivkey(),
|
||||
}
|
||||
receipt, err := c.client.SpaceSign(ctx, payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return proto.Marshal(receipt)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue