forked from TrueCloudLab/frostfs-node
eb26f92678
Implement wrapper over NeoFS ID contact's client which allows to which allows you to conveniently interact with the contract. Implement `AccountKeys` method for getting a list of keys by account ID. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
38 lines
835 B
Go
38 lines
835 B
Go
package neofsid
|
|
|
|
import (
|
|
"crypto/elliptic"
|
|
"fmt"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
|
|
)
|
|
|
|
// AccountKeys requests public keys of NeoFS account from NeoFS ID contract.
|
|
func (x *ClientWrapper) AccountKeys(id *owner.ID) (keys.PublicKeys, error) {
|
|
var args neofsid.KeyListingArgs
|
|
|
|
args.SetOwnerID(id.ToV2().GetValue())
|
|
|
|
res, err := (*neofsid.Client)(x).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
|
|
}
|