Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
vicotor
mybee
Commits
669ce573
Unverified
Commit
669ce573
authored
Jun 11, 2020
by
Janoš Guljaš
Committed by
GitHub
Jun 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Overlay from eth addr (#281)
parent
8d746790
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
5 deletions
+22
-5
crypto.go
pkg/crypto/crypto.go
+18
-4
key.go
pkg/keystore/file/key.go
+4
-1
No files found.
pkg/crypto/crypto.go
View file @
669ce573
...
...
@@ -18,10 +18,10 @@ import (
// NewOverlayAddress constructs a Swarm Address from ECDSA private key.
func
NewOverlayAddress
(
p
ecdsa
.
PublicKey
,
networkID
uint64
)
swarm
.
Address
{
data
:=
make
([]
byte
,
28
)
copy
(
data
,
elliptic
.
Marshal
(
btcec
.
S256
(),
p
.
X
,
p
.
Y
)[
12
:
32
]
)
binary
.
LittleEndian
.
PutUint64
(
data
[
20
:
28
]
,
networkID
)
h
:=
sha3
.
Sum256
(
data
)
ethAddr
:=
NewEthereumAddress
(
p
)
netIDBytes
:=
make
([]
byte
,
8
)
binary
.
LittleEndian
.
PutUint64
(
netIDBytes
,
networkID
)
h
:=
sha3
.
Sum256
(
append
(
ethAddr
,
netIDBytes
...
)
)
return
swarm
.
NewAddress
(
h
[
:
])
}
...
...
@@ -44,3 +44,17 @@ func DecodeSecp256k1PrivateKey(data []byte) (*ecdsa.PrivateKey, error) {
privk
,
_
:=
btcec
.
PrivKeyFromBytes
(
btcec
.
S256
(),
data
)
return
(
*
ecdsa
.
PrivateKey
)(
privk
),
nil
}
// NewEthereumAddress returns a binary representation of ethereum blockchain address.
// This function is based on github.com/ethereum/go-ethereum/crypto.PubkeyToAddress.
func
NewEthereumAddress
(
p
ecdsa
.
PublicKey
)
[]
byte
{
if
p
.
X
==
nil
||
p
.
Y
==
nil
{
return
nil
}
pubBytes
:=
elliptic
.
Marshal
(
btcec
.
S256
(),
p
.
X
,
p
.
Y
)
return
legacyKeccak256
(
pubBytes
[
1
:
])[
12
:
]
}
func
legacyKeccak256
(
data
[]
byte
)
[]
byte
{
return
sha3
.
NewLegacyKeccak256
()
.
Sum
(
data
)
}
pkg/keystore/file/key.go
View file @
669ce573
...
...
@@ -25,7 +25,7 @@ var _ keystore.Service = (*Service)(nil)
const
(
keyHeaderKDF
=
"scrypt"
keyVersion
=
1
keyVersion
=
3
scryptN
=
1
<<
15
scryptR
=
8
...
...
@@ -33,7 +33,9 @@ const (
scryptDKLen
=
32
)
// This format is compatible with Ethereum JSON v3 key file format.
type
encryptedKey
struct
{
Address
string
`json:"address"`
Crypto
keyCripto
`json:"crypto"`
Version
int
`json:"version"`
}
...
...
@@ -66,6 +68,7 @@ func encryptKey(k *ecdsa.PrivateKey, password string) ([]byte, error) {
return
nil
,
err
}
return
json
.
Marshal
(
encryptedKey
{
Address
:
hex
.
EncodeToString
(
crypto
.
NewEthereumAddress
(
k
.
PublicKey
)),
Crypto
:
*
kc
,
Version
:
keyVersion
,
})
...
...
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