-
Notifications
You must be signed in to change notification settings - Fork 144
Port eth2 binary main
style to eth1
#3712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
452616c
10a660e
05dd2b6
bdf6830
63386e6
574525b
1f864f5
66e1d44
37b3e8f
25b276c
bb68568
efd794b
7b8035d
8d9ccc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Nimbus | ||
# Copyright (c) 2021-2025 Status Research & Development GmbH | ||
# Licensed under either of | ||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) | ||
# * MIT license ([LICENSE-MIT](LICENSE-MIT)) | ||
# at your option. | ||
# This file may not be copied, modified, or distributed except according to | ||
# those terms. | ||
|
||
{.push raises: [].} | ||
|
||
import std/[strutils, os], stew/[io2, byteutils], results, eth/common/keys | ||
|
||
proc containsOnlyHexDigits(hex: string): bool = | ||
const HexDigitsX = HexDigits + {'x'} | ||
for c in hex: | ||
if c notin HexDigitsX: | ||
return false | ||
true | ||
|
||
proc getNetKeys*(rng: var HmacDrbgContext, netKey: string): Result[KeyPair, string] = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. portal client has code with a similar goal but obviously differently implemented 😅 : https://github.com/status-im/nimbus-eth1/blob/master/portal/common/common_utils.nim#L81 Probably something we want to also make common in another iteration (and potentially with rework of nimbus-eth2 keystore to also use that...) |
||
let privateKey = | ||
if netKey.len == 0 or netKey == "random": | ||
PrivateKey.random(rng) | ||
elif netKey.len in {64, 66} and netKey.containsOnlyHexDigits: | ||
PrivateKey.fromHex(netKey).valueOr: | ||
return err($error) | ||
else: | ||
# TODO: should we secure the private key with | ||
# keystore encryption? | ||
if fileAccessible(netKey, {AccessFlags.Find}): | ||
try: | ||
let lines = netKey.readLines(1) | ||
if lines.len == 0: | ||
return err("empty network key file") | ||
PrivateKey.fromHex(lines[0]).valueOr: | ||
return err($error) | ||
except IOError as e: | ||
return err("cannot open network key file: " & e.msg) | ||
else: | ||
let privateKey = PrivateKey.random(rng) | ||
|
||
try: | ||
createDir(netKey.splitFile.dir) | ||
netKey.writeFile(privateKey.toRaw.to0xHex) | ||
except OSError as e: | ||
return err("could not create network key file: " & e.msg) | ||
except IOError as e: | ||
return err("could not write network key file: " & e.msg) | ||
|
||
privateKey | ||
ok privateKey.toKeyPair() |
Uh oh!
There was an error while loading. Please reload this page.