diff --git a/cmd/neofs-node/config/node/config.go b/cmd/neofs-node/config/node/config.go index 3c7250923..1883ce1c8 100644 --- a/cmd/neofs-node/config/node/config.go +++ b/cmd/neofs-node/config/node/config.go @@ -3,6 +3,7 @@ package nodeconfig import ( "errors" "fmt" + "io/ioutil" "strconv" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" @@ -26,16 +27,26 @@ var ( // from "node" section. // // Panics if value is not a non-empty string. -func Key(c *config.Config) string { +func Key(c *config.Config) *keys.PrivateKey { v := config.StringSafe(c.Sub(subsection), "key") if v == "" { panic(errKeyNotSet) } - // TODO: add string -> `ecdsa.PrivateKey` parsing logic - // after https://github.com/nspcc-dev/neofs-node/pull/569. + var ( + key *keys.PrivateKey + err error + data []byte + ) + if data, err = ioutil.ReadFile(v); err == nil { + key, err = keys.NewPrivateKeyFromBytes(data) + } - return v + if err != nil { + panic(fmt.Errorf("can't read key: %w", err)) + } + + return key } // Wallet returns value of node private key from "node" section. diff --git a/cmd/neofs-node/config/node/config_test.go b/cmd/neofs-node/config/node/config_test.go index 041c6ef4f..d5335bbde 100644 --- a/cmd/neofs-node/config/node/config_test.go +++ b/cmd/neofs-node/config/node/config_test.go @@ -49,7 +49,7 @@ func TestNodeSection(t *testing.T) { expectedAddr, err := network.AddressFromString("s01.neofs.devenv:8080") require.NoError(t, err) - require.Equal(t, "path/hex/WIF", key) + require.Equal(t, "NbUgTSFvPmsRxmGeWpuuGeJUoRoi6PErcM", key.Address()) require.Equal(t, true, addr.Equal(expectedAddr)) require.Equal(t, true, relay) diff --git a/cmd/neofs-node/config/node/wallet.key b/cmd/neofs-node/config/node/wallet.key new file mode 100644 index 000000000..ba2021bd5 --- /dev/null +++ b/cmd/neofs-node/config/node/wallet.key @@ -0,0 +1 @@ +?ܳv/l \ No newline at end of file diff --git a/config/example/node.env b/config/example/node.env index 424328376..9e492ffd8 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -7,7 +7,7 @@ NEOFS_METRICS_ADDRESS=127.0.0.1:9090 NEOFS_METRICS_SHUTDOWN_TIMEOUT=15s # Node section -NEOFS_NODE_KEY=path/hex/WIF +NEOFS_NODE_KEY=./wallet.key NEOFS_NODE_WALLET_PATH=./wallet.json NEOFS_NODE_WALLET_ADDRESS=NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz NEOFS_NODE_WALLET_PASSWORD=password diff --git a/config/example/node.json b/config/example/node.json index 646ccea5e..c5fa0ee77 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -11,7 +11,7 @@ "shutdown_timeout": "15s" }, "node": { - "key": "path/hex/WIF", + "key": "./wallet.key", "wallet": { "path": "./wallet.json", "address": "NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz", diff --git a/config/example/node.yaml b/config/example/node.yaml index 59b01a9fd..65e0a3d9f 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -10,7 +10,7 @@ metrics: shutdown_timeout: 15s node: - key: path/hex/WIF + key: ./wallet.key wallet: path: "./wallet.json" address: "NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz"