2021-05-31 17:42:32 +00:00
|
|
|
package neofsid
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2021-05-31 17:42:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// AddKeysArgs groups the arguments
|
|
|
|
// 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
|
|
|
|
|
|
|
|
keys [][]byte // list of serialized public keys
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetOwnerID sets NeoFS account identifier.
|
|
|
|
func (x *commonBindArgs) SetOwnerID(v []byte) {
|
|
|
|
x.ownerID = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetKeys sets list of public keys in a binary format.
|
|
|
|
func (x *commonBindArgs) SetKeys(v [][]byte) {
|
|
|
|
x.keys = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddKeys invokes the call of key adding method
|
|
|
|
// of NeoFS contract.
|
|
|
|
func (x *Client) AddKeys(args AddKeysArgs) error {
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.InvokePrm{}
|
|
|
|
|
|
|
|
prm.SetMethod(x.addKeysMethod)
|
|
|
|
prm.SetArgs(args.ownerID, args.keys)
|
|
|
|
|
|
|
|
err := x.client.Invoke(prm)
|
2021-05-31 17:42:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", x.addKeysMethod, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveKeys invokes the call of key removing method
|
|
|
|
// of NeoFS contract.
|
|
|
|
func (x *Client) RemoveKeys(args RemoveKeysArgs) error {
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.InvokePrm{}
|
|
|
|
|
|
|
|
prm.SetMethod(x.removeKeysMethod)
|
|
|
|
prm.SetArgs(args.ownerID, args.keys)
|
|
|
|
|
|
|
|
err := x.client.Invoke(prm)
|
2021-05-31 17:42:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", x.removeKeysMethod, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|