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
e1ea41ee
Commit
e1ea41ee
authored
Jun 29, 2014
by
zelig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove ethutil helpers (refactored), and keypair (key management under ethcrypto package)
parent
d87857ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
179 deletions
+0
-179
helpers.go
ethutil/helpers.go
+0
-64
keypair.go
ethutil/keypair.go
+0
-115
No files found.
ethutil/helpers.go
deleted
100644 → 0
View file @
d87857ff
package
ethutil
import
(
"code.google.com/p/go.crypto/ripemd160"
"crypto/sha256"
"encoding/hex"
"github.com/obscuren/sha3"
"strconv"
)
func
Uitoa
(
i
uint32
)
string
{
return
strconv
.
FormatUint
(
uint64
(
i
),
10
)
}
func
Sha256Bin
(
data
[]
byte
)
[]
byte
{
hash
:=
sha256
.
Sum256
(
data
)
return
hash
[
:
]
}
func
Ripemd160
(
data
[]
byte
)
[]
byte
{
ripemd
:=
ripemd160
.
New
()
ripemd
.
Write
(
data
)
return
ripemd
.
Sum
(
nil
)
}
func
Sha3Bin
(
data
[]
byte
)
[]
byte
{
d
:=
sha3
.
NewKeccak256
()
d
.
Write
(
data
)
return
d
.
Sum
(
nil
)
}
// Helper function for comparing slices
func
CompareIntSlice
(
a
,
b
[]
int
)
bool
{
if
len
(
a
)
!=
len
(
b
)
{
return
false
}
for
i
,
v
:=
range
a
{
if
v
!=
b
[
i
]
{
return
false
}
}
return
true
}
// Returns the amount of nibbles that match each other from 0 ...
func
MatchingNibbleLength
(
a
,
b
[]
int
)
int
{
i
:=
0
for
CompareIntSlice
(
a
[
:
i
+
1
],
b
[
:
i
+
1
])
&&
i
<
len
(
b
)
{
i
+=
1
}
return
i
}
func
Hex
(
d
[]
byte
)
string
{
return
hex
.
EncodeToString
(
d
)
}
func
FromHex
(
str
string
)
[]
byte
{
h
,
_
:=
hex
.
DecodeString
(
str
)
return
h
}
ethutil/keypair.go
deleted
100644 → 0
View file @
d87857ff
package
ethutil
import
(
"github.com/obscuren/secp256k1-go"
)
type
KeyPair
struct
{
PrivateKey
[]
byte
PublicKey
[]
byte
// The associated account
account
*
StateObject
}
func
GenerateNewKeyPair
()
(
*
KeyPair
,
error
)
{
_
,
prv
:=
secp256k1
.
GenerateKeyPair
()
return
NewKeyPairFromSec
(
prv
)
}
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
NewKeyPairFromValue
(
val
*
Value
)
*
KeyPair
{
v
,
_
:=
NewKeyPairFromSec
(
val
.
Bytes
())
return
v
}
func
(
k
*
KeyPair
)
Address
()
[]
byte
{
return
Sha3Bin
(
k
.
PublicKey
[
1
:
])[
12
:
]
}
func
(
k
*
KeyPair
)
RlpEncode
()
[]
byte
{
return
k
.
RlpValue
()
.
Encode
()
}
func
(
k
*
KeyPair
)
RlpValue
()
*
Value
{
return
NewValue
(
k
.
PrivateKey
)
}
type
KeyRing
struct
{
keys
[]
*
KeyPair
}
func
(
k
*
KeyRing
)
Add
(
pair
*
KeyPair
)
{
k
.
keys
=
append
(
k
.
keys
,
pair
)
}
func
(
k
*
KeyRing
)
Get
(
i
int
)
*
KeyPair
{
if
len
(
k
.
keys
)
>
i
{
return
k
.
keys
[
i
]
}
return
nil
}
func
(
k
*
KeyRing
)
Len
()
int
{
return
len
(
k
.
keys
)
}
func
(
k
*
KeyRing
)
NewKeyPair
(
sec
[]
byte
)
(
*
KeyPair
,
error
)
{
keyPair
,
err
:=
NewKeyPairFromSec
(
sec
)
if
err
!=
nil
{
return
nil
,
err
}
k
.
Add
(
keyPair
)
Config
.
Db
.
Put
([]
byte
(
"KeyRing"
),
k
.
RlpValue
()
.
Encode
())
return
keyPair
,
nil
}
func
(
k
*
KeyRing
)
Reset
()
{
Config
.
Db
.
Put
([]
byte
(
"KeyRing"
),
nil
)
k
.
keys
=
nil
}
func
(
k
*
KeyRing
)
RlpValue
()
*
Value
{
v
:=
EmptyValue
()
for
_
,
keyPair
:=
range
k
.
keys
{
v
.
Append
(
keyPair
.
RlpValue
())
}
return
v
}
// The public "singleton" keyring
var
keyRing
*
KeyRing
func
GetKeyRing
()
*
KeyRing
{
if
keyRing
==
nil
{
keyRing
=
&
KeyRing
{}
data
,
_
:=
Config
.
Db
.
Get
([]
byte
(
"KeyRing"
))
it
:=
NewValueFromBytes
(
data
)
.
NewIterator
()
for
it
.
Next
()
{
v
:=
it
.
Value
()
key
,
err
:=
NewKeyPairFromSec
(
v
.
Bytes
())
if
err
!=
nil
{
panic
(
err
)
}
keyRing
.
Add
(
key
)
}
}
return
keyRing
}
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