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
0050c779
Commit
0050c779
authored
1 year ago
by
Moul
Browse files
Options
Downloads
Patches
Plain Diff
[enh] SigningKey: allow to pass a Path
parent
02cb8758
No related branches found
No related tags found
1 merge request
!185
SigningKey: Allow to pass Path and store auth file with 600 permissions #203
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
duniterpy/key/signing_key.py
+16
-13
16 additions, 13 deletions
duniterpy/key/signing_key.py
with
16 additions
and
13 deletions
duniterpy/key/signing_key.py
+
16
−
13
View file @
0050c779
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
import
base64
import
base64
import
re
import
re
from
hashlib
import
scrypt
,
sha256
from
hashlib
import
scrypt
,
sha256
from
pathlib
import
Path
from
typing
import
Optional
,
Type
,
TypeVar
,
Union
from
typing
import
Optional
,
Type
,
TypeVar
,
Union
import
libnacl.sign
import
libnacl.sign
...
@@ -78,7 +79,7 @@ class SigningKey(libnacl.sign.Signer):
...
@@ -78,7 +79,7 @@ class SigningKey(libnacl.sign.Signer):
@classmethod
@classmethod
def
from_credentials_file
(
def
from_credentials_file
(
cls
:
Type
[
SigningKeyType
],
cls
:
Type
[
SigningKeyType
],
path
:
str
,
path
:
Union
[
Path
,
str
]
,
scrypt_params
:
Optional
[
ScryptParams
]
=
None
,
scrypt_params
:
Optional
[
ScryptParams
]
=
None
,
)
->
SigningKeyType
:
)
->
SigningKeyType
:
"""
"""
...
@@ -99,7 +100,7 @@ class SigningKey(libnacl.sign.Signer):
...
@@ -99,7 +100,7 @@ class SigningKey(libnacl.sign.Signer):
return
cls
.
from_credentials
(
salt
,
password
,
scrypt_params
)
return
cls
.
from_credentials
(
salt
,
password
,
scrypt_params
)
def
save_seedhex_file
(
self
,
path
:
str
)
->
None
:
def
save_seedhex_file
(
self
,
path
:
Union
[
Path
,
str
]
)
->
None
:
"""
"""
Save hexadecimal seed file from seed
Save hexadecimal seed file from seed
...
@@ -110,11 +111,11 @@ class SigningKey(libnacl.sign.Signer):
...
@@ -110,11 +111,11 @@ class SigningKey(libnacl.sign.Signer):
fh
.
write
(
seedhex
)
fh
.
write
(
seedhex
)
@staticmethod
@staticmethod
def
from_seedhex_file
(
path
:
str
)
->
Type
[
SigningKeyType
]:
def
from_seedhex_file
(
path
:
Union
[
Path
,
str
]
)
->
Type
[
SigningKeyType
]:
"""
"""
Return SigningKey instance from Seedhex file
Return SigningKey instance from Seedhex file
:param
str
path: Hexadecimal seed file path
:param path: Hexadecimal seed file path
"""
"""
with
open
(
path
,
encoding
=
"
utf-8
"
)
as
fh
:
with
open
(
path
,
encoding
=
"
utf-8
"
)
as
fh
:
seedhex
=
fh
.
read
()
seedhex
=
fh
.
read
()
...
@@ -135,7 +136,7 @@ class SigningKey(libnacl.sign.Signer):
...
@@ -135,7 +136,7 @@ class SigningKey(libnacl.sign.Signer):
seed
=
convert_seedhex_to_seed
(
seedhex
)
seed
=
convert_seedhex_to_seed
(
seedhex
)
return
cls
(
seed
)
return
cls
(
seed
)
def
save_private_key
(
self
,
path
:
str
)
->
None
:
def
save_private_key
(
self
,
path
:
Union
[
Path
,
str
]
)
->
None
:
"""
"""
Save authentication file
Save authentication file
...
@@ -144,7 +145,7 @@ class SigningKey(libnacl.sign.Signer):
...
@@ -144,7 +145,7 @@ class SigningKey(libnacl.sign.Signer):
self
.
save
(
path
)
self
.
save
(
path
)
@staticmethod
@staticmethod
def
from_private_key
(
path
:
str
)
->
Type
[
SigningKeyType
]:
def
from_private_key
(
path
:
Union
[
Path
,
str
]
)
->
Type
[
SigningKeyType
]:
"""
"""
Read authentication file
Read authentication file
Add public key attribute
Add public key attribute
...
@@ -170,7 +171,9 @@ class SigningKey(libnacl.sign.Signer):
...
@@ -170,7 +171,9 @@ class SigningKey(libnacl.sign.Signer):
)
)
@classmethod
@classmethod
def
from_pubsec_file
(
cls
:
Type
[
SigningKeyType
],
path
:
str
)
->
SigningKeyType
:
def
from_pubsec_file
(
cls
:
Type
[
SigningKeyType
],
path
:
Union
[
Path
,
str
]
)
->
SigningKeyType
:
"""
"""
Return SigningKey instance from Duniter WIF file
Return SigningKey instance from Duniter WIF file
...
@@ -201,7 +204,7 @@ class SigningKey(libnacl.sign.Signer):
...
@@ -201,7 +204,7 @@ class SigningKey(libnacl.sign.Signer):
return
cls
(
seed
)
return
cls
(
seed
)
def
save_pubsec_file
(
self
,
path
:
str
)
->
None
:
def
save_pubsec_file
(
self
,
path
:
Union
[
Path
,
str
]
)
->
None
:
"""
"""
Save a Duniter PubSec file (PubSec) v1
Save a Duniter PubSec file (PubSec) v1
...
@@ -223,7 +226,7 @@ sec: {base58_signing_key}"
...
@@ -223,7 +226,7 @@ sec: {base58_signing_key}"
@staticmethod
@staticmethod
def
from_wif_or_ewif_file
(
def
from_wif_or_ewif_file
(
path
:
str
,
password
:
Optional
[
str
]
=
None
path
:
Union
[
Path
,
str
]
,
password
:
Optional
[
str
]
=
None
)
->
Type
[
SigningKeyType
]:
)
->
Type
[
SigningKeyType
]:
"""
"""
Return SigningKey instance from Duniter WIF or EWIF file
Return SigningKey instance from Duniter WIF or EWIF file
...
@@ -268,7 +271,7 @@ sec: {base58_signing_key}"
...
@@ -268,7 +271,7 @@ sec: {base58_signing_key}"
return
result
return
result
@staticmethod
@staticmethod
def
from_wif_file
(
path
:
str
)
->
Type
[
SigningKeyType
]:
def
from_wif_file
(
path
:
Union
[
Path
,
str
]
)
->
Type
[
SigningKeyType
]:
"""
"""
Return SigningKey instance from Duniter WIF file
Return SigningKey instance from Duniter WIF file
...
@@ -315,7 +318,7 @@ sec: {base58_signing_key}"
...
@@ -315,7 +318,7 @@ sec: {base58_signing_key}"
return
cls
(
seed
)
return
cls
(
seed
)
def
save_wif_file
(
self
,
path
:
str
)
->
None
:
def
save_wif_file
(
self
,
path
:
Union
[
Path
,
str
]
)
->
None
:
"""
"""
Save a Wallet Import Format file (WIF) v1
Save a Wallet Import Format file (WIF) v1
...
@@ -342,7 +345,7 @@ Data: {wif_key}"
...
@@ -342,7 +345,7 @@ Data: {wif_key}"
fh
.
write
(
content
)
fh
.
write
(
content
)
@staticmethod
@staticmethod
def
from_ewif_file
(
path
:
str
,
password
:
str
)
->
Type
[
SigningKeyType
]:
def
from_ewif_file
(
path
:
Union
[
Path
,
str
]
,
password
:
str
)
->
Type
[
SigningKeyType
]:
"""
"""
Return SigningKey instance from Duniter EWIF file
Return SigningKey instance from Duniter EWIF file
...
@@ -421,7 +424,7 @@ Data: {wif_key}"
...
@@ -421,7 +424,7 @@ Data: {wif_key}"
return
cls
(
seed
)
return
cls
(
seed
)
def
save_ewif_file
(
self
,
path
:
str
,
password
:
str
)
->
None
:
def
save_ewif_file
(
self
,
path
:
Union
[
Path
,
str
]
,
password
:
str
)
->
None
:
"""
"""
Save an Encrypted Wallet Import Format file (WIF v2)
Save an Encrypted Wallet Import Format file (WIF v2)
...
...
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