forked from TrueCloudLab/frostfs-node
[#1100] *: Adopt new SDK's owner.ID
API
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
4b5404047c
commit
fee2f5a330
21 changed files with 30 additions and 132 deletions
|
@ -192,12 +192,6 @@ var cmdSubnetCreate = &cobra.Command{
|
|||
return fmt.Errorf("read private key: %w", err)
|
||||
}
|
||||
|
||||
// calculate wallet address from key
|
||||
n3Wallet, err := owner.NEO3WalletFromPublicKey(&key.PrivateKey.PublicKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("wallet from key: %w", err)
|
||||
}
|
||||
|
||||
// generate subnet ID and marshal it
|
||||
var (
|
||||
id subnetid.ID
|
||||
|
@ -220,7 +214,7 @@ var cmdSubnetCreate = &cobra.Command{
|
|||
}
|
||||
|
||||
// declare creator ID and encode it
|
||||
creator := *owner.NewIDFromNeo3Wallet(n3Wallet)
|
||||
creator := *owner.NewIDFromPublicKey(&key.PrivateKey.PublicKey)
|
||||
|
||||
// fill subnet info and encode it
|
||||
var info subnet.Info
|
||||
|
|
|
@ -41,10 +41,7 @@ var accountingBalanceCmd = &cobra.Command{
|
|||
exitOnErr(cmd, err)
|
||||
|
||||
if balanceOwner == "" {
|
||||
wallet, err := owner.NEO3WalletFromPublicKey(&key.PublicKey)
|
||||
exitOnErr(cmd, err)
|
||||
|
||||
oid = owner.NewIDFromNeo3Wallet(wallet)
|
||||
oid = owner.NewIDFromPublicKey(&key.PublicKey)
|
||||
} else {
|
||||
oid, err = ownerFromString(balanceOwner)
|
||||
exitOnErr(cmd, err)
|
||||
|
|
|
@ -116,10 +116,7 @@ var listContainersCmd = &cobra.Command{
|
|||
exitOnErr(cmd, err)
|
||||
|
||||
if containerOwner == "" {
|
||||
wallet, err := owner.NEO3WalletFromPublicKey(&key.PublicKey)
|
||||
exitOnErr(cmd, err)
|
||||
|
||||
oid = owner.NewIDFromNeo3Wallet(wallet)
|
||||
oid = owner.NewIDFromPublicKey(&key.PublicKey)
|
||||
} else {
|
||||
oid, err = ownerFromString(containerOwner)
|
||||
exitOnErr(cmd, err)
|
||||
|
|
|
@ -594,13 +594,7 @@ func getObjectHash(cmd *cobra.Command, _ []string) {
|
|||
}
|
||||
|
||||
func getOwnerID(key *ecdsa.PrivateKey) (*owner.ID, error) {
|
||||
w, err := owner.NEO3WalletFromPublicKey(&key.PublicKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ownerID := owner.NewID()
|
||||
ownerID.SetNeo3Wallet(w)
|
||||
return ownerID, nil
|
||||
return owner.NewIDFromPublicKey(&key.PublicKey), nil
|
||||
}
|
||||
|
||||
var searchUnaryOpVocabulary = map[string]object.SearchMatchType{
|
||||
|
|
|
@ -228,15 +228,11 @@ func initCfg(path string) *cfg {
|
|||
|
||||
key := nodeconfig.Key(appCfg)
|
||||
|
||||
neo3Wallet, err := owner.NEO3WalletFromPublicKey(&key.PrivateKey.PublicKey)
|
||||
fatalOnErr(err)
|
||||
|
||||
ownerIDFromKey := owner.NewID()
|
||||
ownerIDFromKey.SetNeo3Wallet(neo3Wallet)
|
||||
ownerIDFromKey := owner.NewIDFromPublicKey(&key.PrivateKey.PublicKey)
|
||||
|
||||
var logPrm logger.Prm
|
||||
|
||||
err = logPrm.SetLevelString(
|
||||
err := logPrm.SetLevelString(
|
||||
loggerconfig.Level(appCfg),
|
||||
)
|
||||
fatalOnErr(err)
|
||||
|
|
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
|
@ -183,12 +182,6 @@ func (x *coreClientConstructor) Get(info coreclient.NodeInfo) (coreclient.MultiA
|
|||
func initObjectService(c *cfg) {
|
||||
ls := c.cfgObject.cfgLocalStorage.localStorage
|
||||
keyStorage := util.NewKeyStorage(&c.key.PrivateKey, c.privateTokenStore, c.cfgNetmap.state)
|
||||
nodeOwner := owner.NewID()
|
||||
|
||||
neo3Wallet, err := owner.NEO3WalletFromPublicKey((*ecdsa.PublicKey)(c.key.PublicKey()))
|
||||
fatalOnErr(err)
|
||||
|
||||
nodeOwner.SetNeo3Wallet(neo3Wallet)
|
||||
|
||||
clientConstructor := &reputationClientConstructor{
|
||||
log: c.log,
|
||||
|
|
2
go.mod
2
go.mod
|
@ -13,7 +13,7 @@ require (
|
|||
github.com/nspcc-dev/hrw v1.0.9
|
||||
github.com/nspcc-dev/neo-go v0.98.0
|
||||
github.com/nspcc-dev/neofs-api-go/v2 v2.11.2-0.20220114101721-227a871a04ac
|
||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220119080627-f83ff628fb19
|
||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220121080144-596774ce5bd3
|
||||
github.com/nspcc-dev/tzhash v1.4.0
|
||||
github.com/panjf2000/ants/v2 v2.4.0
|
||||
github.com/paulmach/orb v0.2.2
|
||||
|
|
BIN
go.sum
BIN
go.sum
Binary file not shown.
|
@ -26,10 +26,9 @@ func TestCheckFormat(t *testing.T) {
|
|||
|
||||
require.Error(t, CheckFormat(c))
|
||||
|
||||
wallet, err := owner.NEO3WalletFromPublicKey(&test.DecodeKey(-1).PublicKey)
|
||||
require.NoError(t, err)
|
||||
oid := owner.NewIDFromPublicKey(&test.DecodeKey(-1).PublicKey)
|
||||
|
||||
c.SetOwnerID(owner.NewIDFromNeo3Wallet(wallet))
|
||||
c.SetOwnerID(oid)
|
||||
|
||||
// set incorrect nonce
|
||||
cV2 := c.ToV2()
|
||||
|
|
|
@ -122,14 +122,7 @@ func (v *FormatValidator) checkOwnerKey(id *owner.ID, key []byte) error {
|
|||
return err
|
||||
}
|
||||
|
||||
wallet, err := owner.NEO3WalletFromPublicKey((*ecdsa.PublicKey)(pub))
|
||||
if err != nil {
|
||||
// TODO: check via NeoFSID
|
||||
return err
|
||||
}
|
||||
|
||||
id2 := owner.NewID()
|
||||
id2.SetNeo3Wallet(wallet)
|
||||
id2 := owner.NewIDFromPublicKey((*ecdsa.PublicKey)(pub))
|
||||
|
||||
if !id.Equal(id2) {
|
||||
return fmt.Errorf("(%T) different owner identifiers %s/%s", v, id, id2)
|
||||
|
|
|
@ -34,16 +34,10 @@ func testObjectID(t *testing.T) *object.ID {
|
|||
return id
|
||||
}
|
||||
|
||||
func blankValidObject(t *testing.T, key *ecdsa.PrivateKey) *RawObject {
|
||||
wallet, err := owner.NEO3WalletFromPublicKey(&key.PublicKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
ownerID := owner.NewID()
|
||||
ownerID.SetNeo3Wallet(wallet)
|
||||
|
||||
func blankValidObject(key *ecdsa.PrivateKey) *RawObject {
|
||||
obj := NewRaw()
|
||||
obj.SetContainerID(cidtest.ID())
|
||||
obj.SetOwnerID(ownerID)
|
||||
obj.SetOwnerID(owner.NewIDFromPublicKey(&key.PublicKey))
|
||||
|
||||
return obj
|
||||
}
|
||||
|
@ -94,11 +88,10 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("correct w/ session token", func(t *testing.T) {
|
||||
w, err := owner.NEO3WalletFromPublicKey((*ecdsa.PublicKey)(ownerKey.PublicKey()))
|
||||
require.NoError(t, err)
|
||||
oid := owner.NewIDFromPublicKey((*ecdsa.PublicKey)(ownerKey.PublicKey()))
|
||||
|
||||
tok := sessiontest.Token()
|
||||
tok.SetOwnerID(owner.NewIDFromNeo3Wallet(w))
|
||||
tok.SetOwnerID(oid)
|
||||
|
||||
obj := NewRaw()
|
||||
obj.SetContainerID(cidtest.ID())
|
||||
|
@ -111,7 +104,7 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("correct w/o session token", func(t *testing.T) {
|
||||
obj := blankValidObject(t, &ownerKey.PrivateKey)
|
||||
obj := blankValidObject(&ownerKey.PrivateKey)
|
||||
|
||||
require.NoError(t, object.SetIDWithSignature(&ownerKey.PrivateKey, obj.SDK()))
|
||||
|
||||
|
@ -188,7 +181,7 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
|
||||
t.Run("expiration", func(t *testing.T) {
|
||||
fn := func(val string) *Object {
|
||||
obj := blankValidObject(t, &ownerKey.PrivateKey)
|
||||
obj := blankValidObject(&ownerKey.PrivateKey)
|
||||
|
||||
a := object.NewAttribute()
|
||||
a.SetKey(objectV2.SysAttributeExpEpoch)
|
||||
|
@ -222,7 +215,7 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
|
||||
t.Run("attributes", func(t *testing.T) {
|
||||
t.Run("duplication", func(t *testing.T) {
|
||||
obj := blankValidObject(t, &ownerKey.PrivateKey)
|
||||
obj := blankValidObject(&ownerKey.PrivateKey)
|
||||
|
||||
a1 := object.NewAttribute()
|
||||
a1.SetKey("key1")
|
||||
|
@ -244,7 +237,7 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("empty value", func(t *testing.T) {
|
||||
obj := blankValidObject(t, &ownerKey.PrivateKey)
|
||||
obj := blankValidObject(&ownerKey.PrivateKey)
|
||||
|
||||
a := object.NewAttribute()
|
||||
a.SetKey("key")
|
||||
|
|
|
@ -52,17 +52,7 @@ func (cp *Processor) checkKeyOwnership(ownerIDSrc ownerIDSource, key *keys.Publi
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: need more convenient way to do this
|
||||
w, err := owner.NEO3WalletFromPublicKey(&ecdsa.PublicKey{
|
||||
Curve: key.Curve,
|
||||
X: key.X,
|
||||
Y: key.Y,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ownerIDSrc.OwnerID().Equal(owner.NewIDFromNeo3Wallet(w)) {
|
||||
if ownerIDSrc.OwnerID().Equal(owner.NewIDFromPublicKey((*ecdsa.PublicKey)(key))) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -319,13 +319,5 @@ func ownerFromKey(key []byte) (*owner.ID, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
n3wallet, err := owner.NEO3WalletFromPublicKey((*ecdsa.PublicKey)(pubKey))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
o := owner.NewID()
|
||||
o.SetNeo3Wallet(n3wallet)
|
||||
|
||||
return o, nil
|
||||
return owner.NewIDFromPublicKey((*ecdsa.PublicKey)(pubKey)), nil
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"math/big"
|
||||
"sync"
|
||||
|
||||
"github.com/mr-tron/base58"
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement/common"
|
||||
|
@ -85,16 +84,12 @@ func bankOwnerID() (*owner.ID, error) {
|
|||
u := util.Uint160{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // todo: define const
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
|
||||
|
||||
d, err := base58.Decode(address.Uint160ToString(u))
|
||||
o := owner.NewID()
|
||||
|
||||
err := o.Parse(address.Uint160ToString(u))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var w owner.NEO3Wallet
|
||||
copy(w[:], d)
|
||||
|
||||
o := owner.NewID()
|
||||
o.SetNeo3Wallet(&w)
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
|
|
@ -187,15 +187,7 @@ func (s settlementDeps) ResolveKey(ni common.NodeInfo) (*owner.ID, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
w, err := owner.NEO3WalletFromPublicKey((*ecdsa.PublicKey)(pub))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := owner.NewID()
|
||||
id.SetNeo3Wallet(w)
|
||||
|
||||
return id, nil
|
||||
return owner.NewIDFromPublicKey((*ecdsa.PublicKey)(pub)), nil
|
||||
}
|
||||
|
||||
func (s settlementDeps) Transfer(sender, recipient *owner.ID, amount *big.Int, details []byte) {
|
||||
|
|
|
@ -204,13 +204,8 @@ func (x putSubnetEvent) ReadCreator(id *owner.ID) error {
|
|||
return err
|
||||
}
|
||||
|
||||
wal, err := owner.NEO3WalletFromPublicKey((*ecdsa.PublicKey)(key))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// it would be better if we could do it not like this
|
||||
*id = *owner.NewIDFromNeo3Wallet(wal)
|
||||
*id = *owner.NewIDFromPublicKey((*ecdsa.PublicKey)(key))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -88,11 +88,8 @@ func generateRawObjectWithCID(t *testing.T, cid *cid.ID) *object.RawObject {
|
|||
version.SetMajor(2)
|
||||
version.SetMinor(1)
|
||||
|
||||
w, err := owner.NEO3WalletFromPublicKey(&test.DecodeKey(-1).PublicKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
csum := new(checksum.Checksum)
|
||||
csum.SetSHA256(sha256.Sum256(w.Bytes()))
|
||||
csum.SetSHA256(sha256.Sum256(owner.PublicKeyToIDBytes(&test.DecodeKey(-1).PublicKey)))
|
||||
|
||||
csumTZ := new(checksum.Checksum)
|
||||
csumTZ.SetTillichZemor(tz.Sum(csum.Sum()))
|
||||
|
|
|
@ -69,11 +69,8 @@ func generateRawObjectWithCID(t *testing.T, cid *cid.ID) *object.RawObject {
|
|||
version.SetMajor(2)
|
||||
version.SetMinor(1)
|
||||
|
||||
w, err := owner.NEO3WalletFromPublicKey(&test.DecodeKey(-1).PublicKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
csum := new(checksum.Checksum)
|
||||
csum.SetSHA256(sha256.Sum256(w.Bytes()))
|
||||
csum.SetSHA256(sha256.Sum256(owner.PublicKeyToIDBytes(&test.DecodeKey(-1).PublicKey)))
|
||||
|
||||
csumTZ := new(checksum.Checksum)
|
||||
csumTZ.SetTillichZemor(tz.Sum(csum.Sum()))
|
||||
|
|
|
@ -73,11 +73,8 @@ func generateRawObjectWithCID(t *testing.T, cid *cid.ID) *object.RawObject {
|
|||
version.SetMajor(2)
|
||||
version.SetMinor(1)
|
||||
|
||||
w, err := owner.NEO3WalletFromPublicKey(&test.DecodeKey(-1).PublicKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
csum := new(checksum.Checksum)
|
||||
csum.SetSHA256(sha256.Sum256(w.Bytes()))
|
||||
csum.SetSHA256(sha256.Sum256(owner.PublicKeyToIDBytes(&test.DecodeKey(-1).PublicKey)))
|
||||
|
||||
csumTZ := new(checksum.Checksum)
|
||||
csumTZ.SetTillichZemor(tz.Sum(csum.Sum()))
|
||||
|
|
|
@ -780,12 +780,7 @@ func isOwnerFromKey(id *owner.ID, key *keys.PublicKey) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
wallet, err := owner.NEO3WalletFromPublicKey((*ecdsa.PublicKey)(key))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return id.Equal(owner.NewIDFromNeo3Wallet(wallet))
|
||||
return id.Equal(owner.NewIDFromPublicKey((*ecdsa.PublicKey)(key)))
|
||||
}
|
||||
|
||||
// originalBearerToken goes down to original request meta header and fetches
|
||||
|
|
|
@ -113,16 +113,8 @@ func requestOwner(req metaWithToken) (*owner.ID, *keys.PublicKey, error) {
|
|||
}
|
||||
|
||||
key := unmarshalPublicKey(bodySignature.Key())
|
||||
neo3wallet, err := owner.NEO3WalletFromPublicKey((*ecdsa.PublicKey)(key))
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("can't create neo3 wallet: %w", err)
|
||||
}
|
||||
|
||||
// form user from public key
|
||||
user := new(owner.ID)
|
||||
user.SetNeo3Wallet(neo3wallet)
|
||||
|
||||
return user, key, nil
|
||||
return owner.NewIDFromPublicKey((*ecdsa.PublicKey)(key)), key, nil
|
||||
}
|
||||
|
||||
func originalBodySignature(v *session.RequestVerificationHeader) *signature.Signature {
|
||||
|
|
Loading…
Reference in a new issue