forked from TrueCloudLab/frostfs-node
[#625] client/neofsid: remove intermediate wrapper
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
8474abb911
commit
8c5c3ac9e8
11 changed files with 101 additions and 262 deletions
|
@ -33,7 +33,7 @@ import (
|
||||||
balanceClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
|
balanceClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
|
||||||
cntWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
cntWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
||||||
neofsClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs"
|
neofsClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs"
|
||||||
neofsidWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
|
||||||
nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
||||||
repWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
repWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
||||||
morphsubnet "github.com/nspcc-dev/neofs-node/pkg/morph/client/subnet"
|
morphsubnet "github.com/nspcc-dev/neofs-node/pkg/morph/client/subnet"
|
||||||
|
@ -503,7 +503,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
neofsIDClient, err := neofsidWrapper.NewFromMorph(server.morphClient, server.contracts.neofsID, fee, neofsidWrapper.TryNotary(), neofsidWrapper.AsAlphabet())
|
neofsIDClient, err := neofsid.NewFromMorph(server.morphClient, server.contracts.neofsID, fee, neofsid.TryNotary(), neofsid.AsAlphabet())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
neofsid "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/session"
|
"github.com/nspcc-dev/neofs-sdk-go/session"
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
||||||
neofsid "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
|
||||||
morphsubnet "github.com/nspcc-dev/neofs-node/pkg/morph/client/subnet"
|
morphsubnet "github.com/nspcc-dev/neofs-node/pkg/morph/client/subnet"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
|
containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/mempoolevent"
|
"github.com/nspcc-dev/neo-go/pkg/core/mempoolevent"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
||||||
neofsid "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
|
||||||
morphsubnet "github.com/nspcc-dev/neofs-node/pkg/morph/client/subnet"
|
morphsubnet "github.com/nspcc-dev/neofs-node/pkg/morph/client/subnet"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
|
containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
|
||||||
|
@ -26,7 +26,7 @@ type (
|
||||||
pool *ants.Pool
|
pool *ants.Pool
|
||||||
alphabetState AlphabetState
|
alphabetState AlphabetState
|
||||||
cnrClient *wrapper.Wrapper // notary must be enabled
|
cnrClient *wrapper.Wrapper // notary must be enabled
|
||||||
idClient *neofsid.ClientWrapper
|
idClient *neofsid.Client
|
||||||
subnetClient *morphsubnet.Client
|
subnetClient *morphsubnet.Client
|
||||||
netState NetworkState
|
netState NetworkState
|
||||||
notaryDisabled bool
|
notaryDisabled bool
|
||||||
|
@ -38,7 +38,7 @@ type (
|
||||||
PoolSize int
|
PoolSize int
|
||||||
AlphabetState AlphabetState
|
AlphabetState AlphabetState
|
||||||
ContainerClient *wrapper.Wrapper
|
ContainerClient *wrapper.Wrapper
|
||||||
NeoFSIDClient *neofsid.ClientWrapper
|
NeoFSIDClient *neofsid.Client
|
||||||
SubnetClient *morphsubnet.Client
|
SubnetClient *morphsubnet.Client
|
||||||
NetworkState NetworkState
|
NetworkState NetworkState
|
||||||
NotaryDisabled bool
|
NotaryDisabled bool
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
neofsid "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event/neofs"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event/neofs"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -95,25 +95,22 @@ func (np *Processor) approveBindCommon(e *bindCommonContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
prm := neofsid.ManageKeysPrm{}
|
prm := neofsid.CommonBindPrm{}
|
||||||
|
|
||||||
prm.SetOwnerID(wallet)
|
prm.SetOwnerID(wallet)
|
||||||
prm.SetKeys(e.Keys())
|
prm.SetKeys(e.Keys())
|
||||||
prm.SetAdd(e.bind)
|
|
||||||
prm.SetHash(e.bindCommon.TxHash())
|
prm.SetHash(e.bindCommon.TxHash())
|
||||||
|
|
||||||
err = np.neofsIDClient.ManageKeys(prm)
|
var typ string
|
||||||
|
if e.bind {
|
||||||
|
typ = "bind"
|
||||||
|
err = np.neofsIDClient.AddKeys(prm)
|
||||||
|
} else {
|
||||||
|
typ = "unbind"
|
||||||
|
err = np.neofsIDClient.RemoveKeys(prm)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var typ string
|
|
||||||
|
|
||||||
if e.bind {
|
|
||||||
typ = "bind"
|
|
||||||
} else {
|
|
||||||
typ = "unbind"
|
|
||||||
}
|
|
||||||
|
|
||||||
np.log.Error(fmt.Sprintf("could not approve %s", typ),
|
np.log.Error(fmt.Sprintf("could not approve %s", typ),
|
||||||
zap.String("error", err.Error()),
|
zap.String("error", err.Error()))
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
|
||||||
neofsid "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
|
||||||
nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
neofsEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/neofs"
|
neofsEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/neofs"
|
||||||
|
@ -51,7 +51,7 @@ type (
|
||||||
mintEmitValue fixedn.Fixed8
|
mintEmitValue fixedn.Fixed8
|
||||||
gasBalanceThreshold int64
|
gasBalanceThreshold int64
|
||||||
|
|
||||||
neofsIDClient *neofsid.ClientWrapper
|
neofsIDClient *neofsid.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// Params of the processor constructor.
|
// Params of the processor constructor.
|
||||||
|
@ -59,7 +59,7 @@ type (
|
||||||
Log *zap.Logger
|
Log *zap.Logger
|
||||||
PoolSize int
|
PoolSize int
|
||||||
NeoFSContract util.Uint160
|
NeoFSContract util.Uint160
|
||||||
NeoFSIDClient *neofsid.ClientWrapper
|
NeoFSIDClient *neofsid.Client
|
||||||
BalanceClient *balance.Client
|
BalanceClient *balance.Client
|
||||||
NetmapClient *nmWrapper.Wrapper
|
NetmapClient *nmWrapper.Wrapper
|
||||||
MorphClient *client.Client
|
MorphClient *client.Client
|
||||||
|
|
|
@ -6,19 +6,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddKeysArgs groups the arguments
|
type CommonBindPrm struct {
|
||||||
// of key binding call.
|
|
||||||
type AddKeysArgs struct {
|
|
||||||
commonBindArgs
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveKeysArgs groups the arguments
|
|
||||||
// of key unbinding call.
|
|
||||||
type RemoveKeysArgs struct {
|
|
||||||
commonBindArgs
|
|
||||||
}
|
|
||||||
|
|
||||||
type commonBindArgs struct {
|
|
||||||
ownerID []byte // NeoFS account identifier
|
ownerID []byte // NeoFS account identifier
|
||||||
|
|
||||||
keys [][]byte // list of serialized public keys
|
keys [][]byte // list of serialized public keys
|
||||||
|
@ -26,28 +14,27 @@ type commonBindArgs struct {
|
||||||
client.InvokePrmOptional
|
client.InvokePrmOptional
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *commonBindArgs) SetOptionalPrm(prm client.InvokePrmOptional) {
|
func (x *CommonBindPrm) SetOptionalPrm(prm client.InvokePrmOptional) {
|
||||||
x.InvokePrmOptional = prm
|
x.InvokePrmOptional = prm
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOwnerID sets NeoFS account identifier.
|
// SetOwnerID sets NeoFS account identifier.
|
||||||
func (x *commonBindArgs) SetOwnerID(v []byte) {
|
func (x *CommonBindPrm) SetOwnerID(v []byte) {
|
||||||
x.ownerID = v
|
x.ownerID = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetKeys sets list of public keys in a binary format.
|
// SetKeys sets list of public keys in a binary format.
|
||||||
func (x *commonBindArgs) SetKeys(v [][]byte) {
|
func (x *CommonBindPrm) SetKeys(v [][]byte) {
|
||||||
x.keys = v
|
x.keys = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddKeys invokes the call of key adding method
|
// AddKeys adds a list of public keys to/from NeoFS account.
|
||||||
// of NeoFS contract.
|
func (x *Client) AddKeys(p CommonBindPrm) error {
|
||||||
func (x *Client) AddKeys(args AddKeysArgs) error {
|
|
||||||
prm := client.InvokePrm{}
|
prm := client.InvokePrm{}
|
||||||
|
|
||||||
prm.SetMethod(addKeysMethod)
|
prm.SetMethod(addKeysMethod)
|
||||||
prm.SetArgs(args.ownerID, args.keys)
|
prm.SetArgs(p.ownerID, p.keys)
|
||||||
prm.InvokePrmOptional = args.InvokePrmOptional
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
||||||
|
|
||||||
err := x.client.Invoke(prm)
|
err := x.client.Invoke(prm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -57,9 +44,8 @@ func (x *Client) AddKeys(args AddKeysArgs) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveKeys invokes the call of key removing method
|
// RemoveKeys removes a list of public keys to/from NeoFS account.
|
||||||
// of NeoFS contract.
|
func (x *Client) RemoveKeys(args CommonBindPrm) error {
|
||||||
func (x *Client) RemoveKeys(args RemoveKeysArgs) error {
|
|
||||||
prm := client.InvokePrm{}
|
prm := client.InvokePrm{}
|
||||||
|
|
||||||
prm.SetMethod(removeKeysMethod)
|
prm.SetMethod(removeKeysMethod)
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package neofsid
|
package neofsid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,7 +26,47 @@ const (
|
||||||
removeKeysMethod = "removeKey"
|
removeKeysMethod = "removeKey"
|
||||||
)
|
)
|
||||||
|
|
||||||
// New creates, initializes and returns the Client instance.
|
// NewFromMorph wraps client to work with NeoFS ID contract.
|
||||||
func New(c *client.StaticClient) *Client {
|
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*Client, error) {
|
||||||
return &Client{client: c}
|
o := defaultOpts()
|
||||||
|
|
||||||
|
for i := range opts {
|
||||||
|
opts[i](o)
|
||||||
|
}
|
||||||
|
|
||||||
|
sc, err := client.NewStatic(cli, contract, fee, ([]client.StaticClientOption)(*o)...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not create client of NeoFS ID contract: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Client{client: sc}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Option allows to set an optional
|
||||||
|
// parameter of ClientWrapper.
|
||||||
|
type Option func(*opts)
|
||||||
|
|
||||||
|
type opts []client.StaticClientOption
|
||||||
|
|
||||||
|
func defaultOpts() *opts {
|
||||||
|
return new(opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TryNotary returns option to enable
|
||||||
|
// notary invocation tries.
|
||||||
|
func TryNotary() Option {
|
||||||
|
return func(o *opts) {
|
||||||
|
*o = append(*o, client.TryNotary())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AsAlphabet returns option to sign main TX
|
||||||
|
// of notary requests with client's private
|
||||||
|
// key.
|
||||||
|
//
|
||||||
|
// Considered to be used by IR nodes only.
|
||||||
|
func AsAlphabet() Option {
|
||||||
|
return func(o *opts) {
|
||||||
|
*o = append(*o, client.AsAlphabet())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,44 +1,31 @@
|
||||||
package neofsid
|
package neofsid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/elliptic"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KeyListingArgs groups the arguments
|
// AccountKeysPrm groups parameters of AccountKeys operation.
|
||||||
// of key listing call.
|
type AccountKeysPrm struct {
|
||||||
type KeyListingArgs struct {
|
id *owner.ID
|
||||||
ownerID []byte // account identifier
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeyListingValues groups the stack parameters
|
// SetID sets owner ID.
|
||||||
// returned by key listing call.
|
func (a *AccountKeysPrm) SetID(id *owner.ID) {
|
||||||
type KeyListingValues struct {
|
a.id = id
|
||||||
keys [][]byte // list of user public keys in binary format
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOwnerID sets the NeoFS account identifier
|
// AccountKeys requests public keys of NeoFS account from NeoFS ID contract.
|
||||||
// in a binary format.
|
func (x *Client) AccountKeys(p AccountKeysPrm) (keys.PublicKeys, error) {
|
||||||
func (l *KeyListingArgs) SetOwnerID(v []byte) {
|
prm := client.TestInvokePrm{}
|
||||||
l.ownerID = v
|
prm.SetMethod(keyListingMethod)
|
||||||
}
|
prm.SetArgs(p.id.ToV2().GetValue())
|
||||||
|
|
||||||
// Keys returns the list of account keys
|
items, err := x.client.TestInvoke(prm)
|
||||||
// in a binary format.
|
|
||||||
func (l *KeyListingValues) Keys() [][]byte {
|
|
||||||
return l.keys
|
|
||||||
}
|
|
||||||
|
|
||||||
// AccountKeys requests public keys of NeoFS account
|
|
||||||
// through method of NeoFS ID contract.
|
|
||||||
func (x *Client) AccountKeys(args KeyListingArgs) (*KeyListingValues, error) {
|
|
||||||
invokePrm := client.TestInvokePrm{}
|
|
||||||
|
|
||||||
invokePrm.SetMethod(keyListingMethod)
|
|
||||||
invokePrm.SetArgs(args.ownerID)
|
|
||||||
|
|
||||||
items, err := x.client.TestInvoke(invokePrm)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not perform test invocation (%s): %w", keyListingMethod, err)
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", keyListingMethod, err)
|
||||||
} else if ln := len(items); ln != 1 {
|
} else if ln := len(items); ln != 1 {
|
||||||
|
@ -50,18 +37,18 @@ func (x *Client) AccountKeys(args KeyListingArgs) (*KeyListingValues, error) {
|
||||||
return nil, fmt.Errorf("1st stack item must be an array (%s)", keyListingMethod)
|
return nil, fmt.Errorf("1st stack item must be an array (%s)", keyListingMethod)
|
||||||
}
|
}
|
||||||
|
|
||||||
keys := make([][]byte, 0, len(items))
|
pubs := make(keys.PublicKeys, len(items))
|
||||||
|
|
||||||
for i := range items {
|
for i := range items {
|
||||||
key, err := client.BytesFromStackItem(items[i])
|
rawPub, err := client.BytesFromStackItem(items[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid stack item, expected byte array (%s)", keyListingMethod)
|
return nil, fmt.Errorf("invalid stack item, expected byte array (%s)", keyListingMethod)
|
||||||
}
|
}
|
||||||
|
|
||||||
keys = append(keys, key)
|
pubs[i], err = keys.NewPublicKeyFromBytes(rawPub, elliptic.P256())
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("received invalid key (%s): %w", keyListingMethod, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &KeyListingValues{
|
return pubs, nil
|
||||||
keys: keys,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
package neofsid
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/internal"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ClientWrapper is a wrapper over NeoFS ID contract
|
|
||||||
// client which provides convenient methods for
|
|
||||||
// working with a contract.
|
|
||||||
//
|
|
||||||
// Working ClientWrapper must be created via Wrap.
|
|
||||||
type ClientWrapper struct {
|
|
||||||
internal.StaticClient
|
|
||||||
|
|
||||||
client *neofsid.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// Option allows to set an optional
|
|
||||||
// parameter of ClientWrapper.
|
|
||||||
type Option func(*opts)
|
|
||||||
|
|
||||||
type opts []client.StaticClientOption
|
|
||||||
|
|
||||||
func defaultOpts() *opts {
|
|
||||||
return new(opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TryNotary returns option to enable
|
|
||||||
// notary invocation tries.
|
|
||||||
func TryNotary() Option {
|
|
||||||
return func(o *opts) {
|
|
||||||
*o = append(*o, client.TryNotary())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AsAlphabet returns option to sign main TX
|
|
||||||
// of notary requests with client's private
|
|
||||||
// key.
|
|
||||||
//
|
|
||||||
// Considered to be used by IR nodes only.
|
|
||||||
func AsAlphabet() Option {
|
|
||||||
return func(o *opts) {
|
|
||||||
*o = append(*o, client.AsAlphabet())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFromMorph wraps client to work with NeoFS ID contract.
|
|
||||||
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*ClientWrapper, error) {
|
|
||||||
o := defaultOpts()
|
|
||||||
|
|
||||||
for i := range opts {
|
|
||||||
opts[i](o)
|
|
||||||
}
|
|
||||||
|
|
||||||
sc, err := client.NewStatic(cli, contract, fee, ([]client.StaticClientOption)(*o)...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("could not create client of NeoFS ID contract: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ClientWrapper{
|
|
||||||
StaticClient: sc,
|
|
||||||
client: neofsid.New(sc),
|
|
||||||
}, nil
|
|
||||||
}
|
|
|
@ -1,105 +0,0 @@
|
||||||
package neofsid
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/elliptic"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
|
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
|
||||||
)
|
|
||||||
|
|
||||||
// AccountKeysPrm groups parameters of AccountKeys operation.
|
|
||||||
type AccountKeysPrm struct {
|
|
||||||
id *owner.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetID sets owner ID.
|
|
||||||
func (a *AccountKeysPrm) SetID(id *owner.ID) {
|
|
||||||
a.id = id
|
|
||||||
}
|
|
||||||
|
|
||||||
// AccountKeys requests public keys of NeoFS account from NeoFS ID contract.
|
|
||||||
func (x *ClientWrapper) AccountKeys(prm AccountKeysPrm) (keys.PublicKeys, error) {
|
|
||||||
var args neofsid.KeyListingArgs
|
|
||||||
|
|
||||||
args.SetOwnerID(prm.id.ToV2().GetValue())
|
|
||||||
|
|
||||||
res, err := x.client.AccountKeys(args)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
binKeys := res.Keys()
|
|
||||||
ks := make(keys.PublicKeys, 0, len(binKeys))
|
|
||||||
|
|
||||||
curve := elliptic.P256()
|
|
||||||
|
|
||||||
for i := range binKeys {
|
|
||||||
k, err := keys.NewPublicKeyFromBytes(binKeys[i], curve)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("received invalid key: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ks = append(ks, k)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ks, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ManageKeysPrm groups parameters of ManageKeys operation.
|
|
||||||
type ManageKeysPrm struct {
|
|
||||||
ownerID []byte
|
|
||||||
ks [][]byte
|
|
||||||
add bool
|
|
||||||
|
|
||||||
client.InvokePrmOptional
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetOwnerID sets Owner ID.
|
|
||||||
func (m *ManageKeysPrm) SetOwnerID(ownerID []byte) {
|
|
||||||
m.ownerID = ownerID
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetKeys sets keys to add/remove.
|
|
||||||
func (m *ManageKeysPrm) SetKeys(ks [][]byte) {
|
|
||||||
m.ks = ks
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetAdd sets operation type.
|
|
||||||
func (m *ManageKeysPrm) SetAdd(add bool) {
|
|
||||||
m.add = add
|
|
||||||
}
|
|
||||||
|
|
||||||
// ManageKeys adds/removes list of public keys to/from NeoFS account.
|
|
||||||
func (x *ClientWrapper) ManageKeys(prm ManageKeysPrm) error {
|
|
||||||
type args interface {
|
|
||||||
SetOwnerID([]byte)
|
|
||||||
SetKeys([][]byte)
|
|
||||||
SetOptionalPrm(optional client.InvokePrmOptional)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
a args
|
|
||||||
call func(args) error
|
|
||||||
)
|
|
||||||
|
|
||||||
if prm.add {
|
|
||||||
a = new(neofsid.AddKeysArgs)
|
|
||||||
call = func(a args) error {
|
|
||||||
return x.client.AddKeys(*a.(*neofsid.AddKeysArgs))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
a = new(neofsid.RemoveKeysArgs)
|
|
||||||
call = func(a args) error {
|
|
||||||
return x.client.RemoveKeys(*a.(*neofsid.RemoveKeysArgs))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
a.SetOwnerID(prm.ownerID)
|
|
||||||
a.SetKeys(prm.ks)
|
|
||||||
a.SetOptionalPrm(prm.InvokePrmOptional)
|
|
||||||
|
|
||||||
return call(a)
|
|
||||||
}
|
|
Loading…
Reference in a new issue