github.com/igggame/nebulas-go@v2.1.0+incompatible/cmd/neb/networkcmd.go (about) 1 // Copyright (C) 2017 go-nebulas authors 2 // 3 // This file is part of the go-nebulas library. 4 // 5 // the go-nebulas library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // the go-nebulas library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with the go-nebulas library. If not, see <http://www.gnu.org/licenses/>. 17 // 18 19 package main 20 21 import ( 22 "fmt" 23 24 "github.com/nebulasio/go-nebulas/net" 25 "github.com/nebulasio/go-nebulas/util" 26 "github.com/urfave/cli" 27 ) 28 29 var ( 30 networkCommand = cli.Command{ 31 Name: "network", 32 Usage: "Manage network", 33 Category: "NETWORK COMMANDS", 34 Description: ` 35 Manage neblas network, generate a private key for node.`, 36 37 Subcommands: []cli.Command{ 38 { 39 Name: "ssh-keygen", 40 Usage: "Generate a private key for network node", 41 Action: generatePrivateKey, 42 ArgsUsage: "<path>", 43 Description: ` 44 45 Generate a private key for network node. 46 47 If the private key of a network node is exist, the nodeID will not change. 48 49 Make sure that the seed node should have a private key.`, 50 }, 51 }, 52 } 53 ) 54 55 // accountCreate creates a new account into the keystore 56 func generatePrivateKey(ctx *cli.Context) error { 57 key, err := net.GenerateEd25519Key() 58 if err != nil { 59 return err 60 } 61 62 str, _ := net.MarshalNetworkKey(key) 63 fmt.Printf("private.key: %s\n", key) 64 65 path := ctx.Args().First() 66 if len(path) == 0 { 67 path = net.DefaultPrivateKeyPath 68 } 69 70 return util.FileWrite(path, []byte(str), false) 71 }