Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Merge requests
!54
#71
: handle seedhex
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
#71
: handle seedhex
71_handle_seedhex
into
dev
Overview
3
Commits
4
Pipelines
2
Changes
2
Merged
#71: handle seedhex
Moul
requested to merge
71_handle_seedhex
into
dev
Jan 16, 2019
Overview
3
Commits
4
Pipelines
2
Changes
2
0
0
Merge request reports
Compare
dev
version 1
f6cedec6
Jan 16, 2019
dev (base)
and
latest version
latest version
36572ae8
4 commits,
Jan 20, 2019
version 1
f6cedec6
3 commits,
Jan 16, 2019
2 files
+
60
−
3
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
duniterpy/key/signing_key.py
+
39
−
3
View file @ 36572ae8
Edit in single-file editor
Open in Web IDE
Show full file
@@ -12,7 +12,7 @@ from libnacl.utils import load_key
from
pylibscrypt
import
scrypt
from
.base58
import
Base58Encoder
from
..helpers
import
ensure_bytes
,
xor_bytes
from
..helpers
import
ensure_bytes
,
xor_bytes
,
convert_seedhex_to_seed
,
convert_seed_to_seedhex
SEED_LENGTH
=
32
# Length of the key
crypto_sign_BYTES
=
64
@@ -68,6 +68,42 @@ class SigningKey(libnacl.sign.Signer):
return
cls
(
seed
)
def
save_seedhex_file
(
self
,
path
:
str
)
->
None
:
"""
Save hexadecimal seed file from seed
:param path: Authentication file path
"""
seedhex
=
convert_seed_to_seedhex
(
self
.
seed
)
with
open
(
path
,
'
w
'
)
as
fh
:
fh
.
write
(
seedhex
)
@staticmethod
def
from_seedhex_file
(
path
:
str
)
->
SigningKeyType
:
"""
Return SigningKey instance from Seedhex file
:param str path: Hexadecimal seed file path
"""
with
open
(
path
,
'
r
'
)
as
fh
:
seedhex
=
fh
.
read
()
return
SigningKey
.
from_seedhex
(
seedhex
)
@classmethod
def
from_seedhex
(
cls
:
Type
[
SigningKeyType
],
seedhex
:
str
)
->
SigningKeyType
:
"""
Return SigningKey instance from Seedhex
:param str seedhex: Hexadecimal seed string
"""
regex_seedhex
=
compile
(
"
([0-9a-fA-F]{64})
"
)
match
=
search
(
regex_seedhex
,
seedhex
)
if
not
match
:
raise
Exception
(
'
Error: Bad seed hexadecimal format
'
)
seedhex
=
match
.
groups
()[
0
]
seed
=
convert_seedhex_to_seed
(
seedhex
)
return
cls
(
seed
)
def
save_private_key
(
self
,
path
:
str
)
->
None
:
"""
Save authentication file
@@ -111,8 +147,8 @@ class SigningKey(libnacl.sign.Signer):
pubsec_content
=
fh
.
read
()
# line patterns
regex_pubkey
=
compile
(
"
pub: ([1-9A-HJ-NP-Za-km-z]
+
)
"
,
MULTILINE
)
regex_signkey
=
compile
(
"
sec: ([1-9A-HJ-NP-Za-km-z]
+
)
"
,
MULTILINE
)
regex_pubkey
=
compile
(
"
pub: ([1-9A-HJ-NP-Za-km-z]
{43,44}
)
"
,
MULTILINE
)
regex_signkey
=
compile
(
"
sec: ([1-9A-HJ-NP-Za-km-z]
{88,90}
)
"
,
MULTILINE
)
# check public key field
match
=
search
(
regex_pubkey
,
pubsec_content
)
Loading