any-sync/common/account/service.go
mcrakhman 3cbdf798a2
Merge branch 'drpc-services' into space-sync
# Conflicts:
#	Makefile
#	cmd/node/node.go
#	pkg/acl/aclchanges/aclpb/aclchanges.pb.go
#	pkg/acl/acltree/aclstatebuilder.go
#	pkg/acl/acltree/change.go
#	pkg/acl/example/plaintextdocument/document.go
#	pkg/acl/example/plaintextdocument/plaintextdocstate.go
#	pkg/acl/list/aclstate.go
#	pkg/acl/list/changebuilder.go
#	pkg/acl/testutils/testchanges/proto/test.pb.go
#	pkg/acl/testutils/treestoragebuilder/treestoragebuilder.go
#	pkg/acl/testutils/treestoragebuilder/treestoragebuildergraph_nix.go
#	pkg/acl/tree/treegraph_nix.go
#	service/document/service.go
#	service/space/service.go
#	service/space/space.go
#	service/sync/requesthandler/requesthandler.go
#	service/treecache/service.go
#	syncproto/helpers.go
#	syncproto/sync.pb.go
2022-09-11 15:36:38 +02:00

73 lines
1.9 KiB
Go

package account
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/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey"
)
const CName = "account"
type Service interface {
Account() *account.AccountData
}
type service struct {
accountData *account.AccountData
peerId string
}
func (s *service) Account() *account.AccountData {
return s.accountData
}
type StaticAccount struct {
SigningKey string `yaml:"signingKey"`
EncryptionKey string `yaml:"encryptionKey"`
}
func New() app.Component {
return &service{}
}
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()
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())
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(),
}
s.peerId = acc.PeerId
return nil
}
func (s *service) Name() (name string) {
return CName
}