forked from TrueCloudLab/frostfs-node
[#562] cmd/neofs-node: use NEP-6 wallet for keys
Also use neo-go private key wrapper where possible, as it already has methods for (un)marshaling. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
1553967328
commit
3f07313604
17 changed files with 119 additions and 53 deletions
|
@ -5,8 +5,10 @@ import (
|
|||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||
utilConfig "github.com/nspcc-dev/neofs-node/pkg/util/config"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -36,6 +38,20 @@ func Key(c *config.Config) string {
|
|||
return v
|
||||
}
|
||||
|
||||
// Wallet returns value of node private key from "node" section.
|
||||
func Wallet(c *config.Config) *keys.PrivateKey {
|
||||
v := c.Sub(subsection).Sub("wallet")
|
||||
acc, err := utilConfig.LoadAccount(
|
||||
config.String(v, "path"),
|
||||
config.String(v, "address"),
|
||||
config.String(v, "password"))
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("invalid wallet config: %w", err))
|
||||
}
|
||||
|
||||
return acc.PrivateKey()
|
||||
}
|
||||
|
||||
// BootstrapAddress returns value of "address" config parameter
|
||||
// from "node" section as network.Address.
|
||||
//
|
||||
|
|
|
@ -3,6 +3,7 @@ package nodeconfig
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
||||
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||
|
@ -43,6 +44,7 @@ func TestNodeSection(t *testing.T) {
|
|||
addr := BootstrapAddress(c)
|
||||
attributes := Attributes(c)
|
||||
relay := Relay(c)
|
||||
wKey := Wallet(c)
|
||||
|
||||
expectedAddr, err := network.AddressFromString("s01.neofs.devenv:8080")
|
||||
require.NoError(t, err)
|
||||
|
@ -54,6 +56,11 @@ func TestNodeSection(t *testing.T) {
|
|||
require.Len(t, attributes, 2)
|
||||
require.Equal(t, "Price:11", attributes[0])
|
||||
require.Equal(t, "UN-LOCODE:RU MSK", attributes[1])
|
||||
|
||||
require.NotNil(t, wKey)
|
||||
require.Equal(t,
|
||||
config.StringSafe(c.Sub("node").Sub("wallet"), "address"),
|
||||
address.Uint160ToString(wKey.GetScriptHash()))
|
||||
}
|
||||
|
||||
configtest.ForEachFileType(path, fileConfigTest)
|
||||
|
|
30
cmd/neofs-node/config/node/wallet.json
Normal file
30
cmd/neofs-node/config/node/wallet.json
Normal file
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"version": "3.0",
|
||||
"accounts": [
|
||||
{
|
||||
"address": "NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz",
|
||||
"key": "6PYXFRFUfoMNjWd2UmaaEjwHSWpifcLLTbEfhkwXdiSZ2n2WLfr75JpxmJ",
|
||||
"label": "testacc",
|
||||
"contract": {
|
||||
"script": "DCECaeaVhKFa+ENNUpRJLz6BRmRbkIaoN+xZt3VHzlzkHJZBVuezJw==",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "parameter0",
|
||||
"type": "Signature"
|
||||
}
|
||||
],
|
||||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isDefault": false
|
||||
}
|
||||
],
|
||||
"scrypt": {
|
||||
"n": 16384,
|
||||
"r": 8,
|
||||
"p": 8
|
||||
},
|
||||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue