Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sidecar
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
sidecar
Commits
8c3e3ddb
Commit
8c3e3ddb
authored
Sep 16, 2021
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tool appchain command
parent
26ccabcc
Pipeline
#7998
canceled with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
32 deletions
+39
-32
tool.go
cmd/sidecar/tool.go
+39
-32
No files found.
cmd/sidecar/tool.go
View file @
8c3e3ddb
...
...
@@ -20,8 +20,45 @@ var toolCMD = cli.Command{
Usage
:
"generate tool for node"
,
Subcommands
:
[]
cli
.
Command
{
{
Name
:
"info"
,
Usage
:
"get sidecar keystore"
,
Name
:
"p2p"
,
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
{
privKey
,
err
:=
asym
.
GenerateKeyPair
(
crypto
.
Secp256k1
)
tool
.
Asset
(
err
)
...
...
@@ -54,36 +91,6 @@ var toolCMD = cli.Command{
fmt
.
Println
(
data
)
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
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment