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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
a29a2011
Commit
a29a2011
authored
5 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#77
add authentication from credentials file
add test and example [enh]
#77
add authentication from credentials file add test and example
parent
dfee578a
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!101
Release 0.57.0
Pipeline
#8583
passed
5 years ago
Stage: format
Stage: test
Stage: build
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
duniterpy/key/signing_key.py
+23
-1
23 additions, 1 deletion
duniterpy/key/signing_key.py
examples/load_credentials_file.py
+24
-0
24 additions, 0 deletions
examples/load_credentials_file.py
tests/key/test_signing_key.py
+16
-0
16 additions, 0 deletions
tests/key/test_signing_key.py
with
63 additions
and
1 deletion
duniterpy/key/signing_key.py
+
23
−
1
View file @
a29a2011
...
@@ -46,7 +46,7 @@ class SigningKey(libnacl.sign.Signer):
...
@@ -46,7 +46,7 @@ class SigningKey(libnacl.sign.Signer):
:param salt: Secret salt passphrase credential
:param salt: Secret salt passphrase credential
:param password: Secret password credential
:param password: Secret password credential
:param scrypt_params: ScryptParams instance
:param scrypt_params: ScryptParams instance
or None
"""
"""
if
scrypt_params
is
None
:
if
scrypt_params
is
None
:
scrypt_params
=
ScryptParams
()
scrypt_params
=
ScryptParams
()
...
@@ -64,6 +64,28 @@ class SigningKey(libnacl.sign.Signer):
...
@@ -64,6 +64,28 @@ class SigningKey(libnacl.sign.Signer):
return
cls
(
seed
)
return
cls
(
seed
)
@classmethod
def
from_credentials_file
(
cls
,
path
:
str
,
scrypt_params
:
Optional
[
ScryptParams
]
=
None
)
->
SigningKeyType
:
"""
Create a SigningKey object from a credentials file
A file with the salt on the first line and the password on the second line
:param path: Credentials file path
:param scrypt_params: ScryptParams instance or None
:return:
"""
# capture credentials from file
with
open
(
path
,
"
r
"
)
as
fh
:
lines
=
fh
.
readlines
()
assert
len
(
lines
)
>
1
salt
=
lines
[
0
].
strip
()
password
=
lines
[
1
].
strip
()
return
cls
.
from_credentials
(
salt
,
password
,
scrypt_params
)
def
save_seedhex_file
(
self
,
path
:
str
)
->
None
:
def
save_seedhex_file
(
self
,
path
:
str
)
->
None
:
"""
"""
Save hexadecimal seed file from seed
Save hexadecimal seed file from seed
...
...
This diff is collapsed.
Click to expand it.
examples/load_credentials_file.py
0 → 100644
+
24
−
0
View file @
a29a2011
import
sys
from
duniterpy.key
import
SigningKey
if
__name__
==
"
__main__
"
:
if
len
(
sys
.
argv
)
<
2
:
print
(
"""
Usage:
python load_credentials_file.py FILEPATH
"""
)
# capture filepath argument
credentials_filepath
=
sys
.
argv
[
1
]
# create SigningKey instance from file
signing_key_instance
=
SigningKey
.
from_credentials_file
(
credentials_filepath
)
# type: SigningKey
# print pubkey
print
(
"
Public key from credentials file: {}
"
.
format
(
signing_key_instance
.
pubkey
))
This diff is collapsed.
Click to expand it.
tests/key/test_signing_key.py
+
16
−
0
View file @
a29a2011
...
@@ -77,3 +77,19 @@ class TestSigningKey(unittest.TestCase):
...
@@ -77,3 +77,19 @@ class TestSigningKey(unittest.TestCase):
sign_key_load
=
SigningKey
.
from_wif_or_ewif_file
(
TEST_FILE_PATH
)
sign_key_load
=
SigningKey
.
from_wif_or_ewif_file
(
TEST_FILE_PATH
)
self
.
assertEqual
(
sign_key_save
.
sk
,
sign_key_load
.
sk
)
self
.
assertEqual
(
sign_key_save
.
sk
,
sign_key_load
.
sk
)
def
test_load_credentials_file
(
self
):
salt
=
password
=
"
test
"
# create a dummy credentials file
with
open
(
TEST_FILE_PATH
,
"
w
"
)
as
fh
:
fh
.
write
(
"
{}
\n
{}
\n
"
.
format
(
salt
,
password
))
# same key from credentials
sign_key_test
=
SigningKey
.
from_credentials
(
salt
,
password
)
# test load file
sign_key_load
=
SigningKey
.
from_credentials_file
(
TEST_FILE_PATH
)
self
.
assertEqual
(
sign_key_test
.
sk
,
sign_key_load
.
sk
)
self
.
assertEqual
(
sign_key_test
.
pubkey
,
sign_key_load
.
pubkey
)
self
.
assertEqual
(
sign_key_test
.
vk
,
sign_key_load
.
vk
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment