Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
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
张蕾
Geth-Modification
Commits
ab7dc924
Commit
ab7dc924
authored
Feb 18, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added import/exporting of private keys
parent
8c8554f5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
3 deletions
+52
-3
config.go
config.go
+4
-0
ethereum.go
ethereum.go
+48
-3
No files found.
config.go
View file @
ab7dc924
...
...
@@ -13,6 +13,8 @@ var AddPeer string
var
MaxPeer
int
var
GenAddr
bool
var
UseSeed
bool
var
ImportKey
string
var
ExportKey
bool
func
Init
()
{
flag
.
BoolVar
(
&
StartConsole
,
"c"
,
false
,
"debug and testing console"
)
...
...
@@ -21,7 +23,9 @@ func Init() {
flag
.
BoolVar
(
&
UseUPnP
,
"upnp"
,
false
,
"enable UPnP support"
)
flag
.
BoolVar
(
&
UseSeed
,
"seed"
,
true
,
"seed peers"
)
flag
.
BoolVar
(
&
GenAddr
,
"genaddr"
,
false
,
"create a new priv/pub key"
)
flag
.
BoolVar
(
&
ExportKey
,
"export"
,
false
,
"export private key"
)
flag
.
StringVar
(
&
OutboundPort
,
"p"
,
"30303"
,
"listening port"
)
flag
.
StringVar
(
&
ImportKey
,
"import"
,
""
,
"imports the given private key (hex)"
)
flag
.
IntVar
(
&
MaxPeer
,
"x"
,
5
,
"maximum desired peers"
)
flag
.
Parse
()
...
...
ethereum.go
View file @
ab7dc924
...
...
@@ -38,8 +38,6 @@ func CreateKeyPair(force bool) {
fmt
.
Printf
(
`
Generating new address and keypair.
Please keep your keys somewhere save.
Currently Ethereum(G) does not support
exporting keys.
++++++++++++++++ KeyRing +++++++++++++++++++
addr: %x
...
...
@@ -54,6 +52,29 @@ pubk: %x
}
}
func
ImportPrivateKey
(
prvKey
string
)
{
key
:=
ethutil
.
FromHex
(
prvKey
)
msg
:=
[]
byte
(
"tmp"
)
// Couldn't think of a better way to get the pub key
sig
,
_
:=
secp256k1
.
Sign
(
msg
,
key
)
pub
,
_
:=
secp256k1
.
RecoverPubkey
(
msg
,
sig
)
addr
:=
ethutil
.
Sha3Bin
(
pub
[
1
:
])[
12
:
]
fmt
.
Printf
(
`
Importing private key
++++++++++++++++ KeyRing +++++++++++++++++++
addr: %x
prvk: %x
pubk: %x
++++++++++++++++++++++++++++++++++++++++++++
`
,
addr
,
key
,
pub
)
keyRing
:=
ethutil
.
NewValue
([]
interface
{}{
key
,
addr
,
pub
[
1
:
]})
ethutil
.
Config
.
Db
.
Put
([]
byte
(
"KeyRing"
),
keyRing
.
Encode
())
}
func
main
()
{
runtime
.
GOMAXPROCS
(
runtime
.
NumCPU
())
Init
()
...
...
@@ -86,9 +107,33 @@ func main() {
CreateKeyPair
(
true
)
}
os
.
Exit
(
0
)
}
else
{
if
len
(
ImportKey
)
>
0
{
fmt
.
Println
(
"This action overwrites your old private key. Are you sure? (y/n)"
)
var
r
string
fmt
.
Scanln
(
&
r
)
for
;
;
fmt
.
Scanln
(
&
r
)
{
if
r
==
"n"
||
r
==
"y"
{
break
}
else
{
fmt
.
Printf
(
"Yes or no?"
,
r
)
}
}
if
r
==
"y"
{
ImportPrivateKey
(
ImportKey
)
}
}
else
{
CreateKeyPair
(
false
)
}
}
if
ExportKey
{
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
([]
byte
(
"KeyRing"
))
keyRing
:=
ethutil
.
NewValueFromBytes
(
data
)
fmt
.
Printf
(
"%x
\n
"
,
keyRing
.
Get
(
0
)
.
Bytes
())
os
.
Exit
(
0
)
}
if
ShowGenesis
{
fmt
.
Println
(
ethereum
.
BlockManager
.
BlockChain
()
.
Genesis
())
...
...
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