Commit 8c3e3ddb authored by suyanlong's avatar suyanlong

Add tool appchain command

parent 26ccabcc
Pipeline #7998 canceled with stages
...@@ -20,8 +20,45 @@ var toolCMD = cli.Command{ ...@@ -20,8 +20,45 @@ var toolCMD = cli.Command{
Usage: "generate tool for node", Usage: "generate tool for node",
Subcommands: []cli.Command{ Subcommands: []cli.Command{
{ {
Name: "info", Name: "p2p",
Usage: "get sidecar keystore", Usage: "about p2p information",
Action: func(ctx *cli.Context) error {
// 指定类型ECDSA_P256,随机产生p2p私钥
p2pPrivateKey, err := asym.GenerateKeyPair(crypto.ECDSA_P256)
tool.Asset(err)
// 编码16
priKeyEncode, err := p2pPrivateKey.Bytes()
tool.Asset(err)
// 产生x509 ecdsa.PrivateKey 类型私钥
stdKey, err := x509.ParseECPrivateKey(priKeyEncode)
tool.Asset(err)
pemEncodePrivrateData := pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: priKeyEncode})
fmt.Println("--------p2p node peer PrivateKey ----------begin\n")
fmt.Println(string(pemEncodePrivrateData))
fmt.Println("--------p2p node peer PrivateKey----------end\n")
// 类型转换
k, err := asym.PrivateKeyFromStdKey(stdKey)
tool.Asset(err)
sdKey, err := asym.PrivKeyToStdKey(k)
tool.Asset(err)
_, pk, err := crypto2.KeyPairFromStdKey(&sdKey)
tool.Asset(err)
id, err := peer.IDFromPublicKey(pk)
tool.Asset(err)
fmt.Println("--------p2p node ID----------begin")
fmt.Println(id.Pretty())
fmt.Println("--------p2p node ID----------end")
return nil
},
},
{
Name: "appchain",
Usage: "about appchain information",
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
privKey, err := asym.GenerateKeyPair(crypto.Secp256k1) privKey, err := asym.GenerateKeyPair(crypto.Secp256k1)
tool.Asset(err) tool.Asset(err)
...@@ -54,36 +91,6 @@ var toolCMD = cli.Command{ ...@@ -54,36 +91,6 @@ var toolCMD = cli.Command{
fmt.Println(data) fmt.Println(data)
fmt.Println("--------user keyStore----------end \n") fmt.Println("--------user keyStore----------end \n")
// 指定类型ECDSA_P256,随机产生p2p私钥
p2pPrivateKey, err := asym.GenerateKeyPair(crypto.ECDSA_P256)
tool.Asset(err)
// 编码16
priKeyEncode, err := p2pPrivateKey.Bytes()
tool.Asset(err)
// 产生x509 ecdsa.PrivateKey 类型私钥
stdKey, err := x509.ParseECPrivateKey(priKeyEncode)
tool.Asset(err)
pemEncodePrivrateData := pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: priKeyEncode})
fmt.Println("--------p2p node peer PrivateKey ----------begin\n")
fmt.Println(string(pemEncodePrivrateData))
fmt.Println("--------p2p node peer PrivateKey----------end\n")
// 类型转换
k, err := asym.PrivateKeyFromStdKey(stdKey)
tool.Asset(err)
sdKey, err := asym.PrivKeyToStdKey(k)
tool.Asset(err)
_, pk, err := crypto2.KeyPairFromStdKey(&sdKey)
tool.Asset(err)
id, err := peer.IDFromPublicKey(pk)
tool.Asset(err)
fmt.Println("--------p2p node ID----------begin")
fmt.Println(id.Pretty())
fmt.Println("--------p2p node ID----------end")
return nil return nil
}, },
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment