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
d4da2f63
Commit
d4da2f63
authored
Aug 17, 2015
by
zelig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crypto: remove obsolete key files
parent
e1da1244
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
0 additions
and
1878 deletions
+0
-1878
keypair.go
crypto/keypair.go
+0
-66
mnemonic.go
crypto/mnemonic.go
+0
-76
mnemonic_test.go
crypto/mnemonic_test.go
+0
-90
mnemonic_words.go
crypto/mnemonic_words.go
+0
-1646
No files found.
crypto/keypair.go
deleted
100644 → 0
View file @
e1da1244
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package
crypto
import
(
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
)
type
KeyPair
struct
{
PrivateKey
[]
byte
PublicKey
[]
byte
address
[]
byte
mnemonic
string
// The associated account
// account *StateObject
}
func
GenerateNewKeyPair
()
*
KeyPair
{
_
,
prv
:=
secp256k1
.
GenerateKeyPair
()
keyPair
,
_
:=
NewKeyPairFromSec
(
prv
)
// swallow error, this one cannot err
return
keyPair
}
func
NewKeyPairFromSec
(
seckey
[]
byte
)
(
*
KeyPair
,
error
)
{
pubkey
,
err
:=
secp256k1
.
GeneratePubKey
(
seckey
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
KeyPair
{
PrivateKey
:
seckey
,
PublicKey
:
pubkey
},
nil
}
func
(
k
*
KeyPair
)
Address
()
[]
byte
{
if
k
.
address
==
nil
{
k
.
address
=
Sha3
(
k
.
PublicKey
[
1
:
])[
12
:
]
}
return
k
.
address
}
func
(
k
*
KeyPair
)
Mnemonic
()
string
{
if
k
.
mnemonic
==
""
{
k
.
mnemonic
=
strings
.
Join
(
MnemonicEncode
(
common
.
Bytes2Hex
(
k
.
PrivateKey
)),
" "
)
}
return
k
.
mnemonic
}
func
(
k
*
KeyPair
)
AsStrings
()
(
string
,
string
,
string
,
string
)
{
return
k
.
Mnemonic
(),
common
.
Bytes2Hex
(
k
.
Address
()),
common
.
Bytes2Hex
(
k
.
PrivateKey
),
common
.
Bytes2Hex
(
k
.
PublicKey
)
}
crypto/mnemonic.go
deleted
100644 → 0
View file @
e1da1244
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package
crypto
import
(
"fmt"
"strconv"
)
// TODO: See if we can refactor this into a shared util lib if we need it multiple times
func
IndexOf
(
slice
[]
string
,
value
string
)
int64
{
for
p
,
v
:=
range
slice
{
if
v
==
value
{
return
int64
(
p
)
}
}
return
-
1
}
func
MnemonicEncode
(
message
string
)
[]
string
{
var
out
[]
string
n
:=
int64
(
len
(
MnemonicWords
))
for
i
:=
0
;
i
<
len
(
message
);
i
+=
(
len
(
message
)
/
8
)
{
x
:=
message
[
i
:
i
+
8
]
bit
,
_
:=
strconv
.
ParseInt
(
x
,
16
,
64
)
w1
:=
(
bit
%
n
)
w2
:=
((
bit
/
n
)
+
w1
)
%
n
w3
:=
((
bit
/
n
/
n
)
+
w2
)
%
n
out
=
append
(
out
,
MnemonicWords
[
w1
],
MnemonicWords
[
w2
],
MnemonicWords
[
w3
])
}
return
out
}
func
MnemonicDecode
(
wordsar
[]
string
)
string
{
var
out
string
n
:=
int64
(
len
(
MnemonicWords
))
for
i
:=
0
;
i
<
len
(
wordsar
);
i
+=
3
{
word1
:=
wordsar
[
i
]
word2
:=
wordsar
[
i
+
1
]
word3
:=
wordsar
[
i
+
2
]
w1
:=
IndexOf
(
MnemonicWords
,
word1
)
w2
:=
IndexOf
(
MnemonicWords
,
word2
)
w3
:=
IndexOf
(
MnemonicWords
,
word3
)
y
:=
(
w2
-
w1
)
%
n
z
:=
(
w3
-
w2
)
%
n
// Golang handles modulo with negative numbers different then most languages
// The modulo can be negative, we don't want that.
if
z
<
0
{
z
+=
n
}
if
y
<
0
{
y
+=
n
}
x
:=
w1
+
n
*
(
y
)
+
n
*
n
*
(
z
)
out
+=
fmt
.
Sprintf
(
"%08x"
,
x
)
}
return
out
}
crypto/mnemonic_test.go
deleted
100644 → 0
View file @
e1da1244
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package
crypto
import
(
"testing"
)
func
TestMnDecode
(
t
*
testing
.
T
)
{
words
:=
[]
string
{
"ink"
,
"balance"
,
"gain"
,
"fear"
,
"happen"
,
"melt"
,
"mom"
,
"surface"
,
"stir"
,
"bottle"
,
"unseen"
,
"expression"
,
"important"
,
"curl"
,
"grant"
,
"fairy"
,
"across"
,
"back"
,
"figure"
,
"breast"
,
"nobody"
,
"scratch"
,
"worry"
,
"yesterday"
,
}
encode
:=
"c61d43dc5bb7a4e754d111dae8105b6f25356492df5e50ecb33b858d94f8c338"
result
:=
MnemonicDecode
(
words
)
if
encode
!=
result
{
t
.
Error
(
"We expected"
,
encode
,
"got"
,
result
,
"instead"
)
}
}
func
TestMnEncode
(
t
*
testing
.
T
)
{
encode
:=
"c61d43dc5bb7a4e754d111dae8105b6f25356492df5e50ecb33b858d94f8c338"
result
:=
[]
string
{
"ink"
,
"balance"
,
"gain"
,
"fear"
,
"happen"
,
"melt"
,
"mom"
,
"surface"
,
"stir"
,
"bottle"
,
"unseen"
,
"expression"
,
"important"
,
"curl"
,
"grant"
,
"fairy"
,
"across"
,
"back"
,
"figure"
,
"breast"
,
"nobody"
,
"scratch"
,
"worry"
,
"yesterday"
,
}
words
:=
MnemonicEncode
(
encode
)
for
i
,
word
:=
range
words
{
if
word
!=
result
[
i
]
{
t
.
Error
(
"Mnenonic does not match:"
,
words
,
result
)
}
}
}
crypto/mnemonic_words.go
deleted
100644 → 0
View file @
e1da1244
This diff is collapsed.
Click to expand it.
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