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
b19b389d
Commit
b19b389d
authored
4 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
[feat]
#150
Add DUBP Mnemonic SigningKey feature
See
https://git.duniter.org/documents/rfcs/blob/dubp-mnemonic/rfc/0014_Dubp_Mnemonic.md
parent
5c00bd86
Branches
Branches containing commit
No related tags found
2 merge requests
!157
v1.0.0rc0: merge dev into master
,
!130
[feat] #150 Add DUBP Mnemonic SigningKey feature
Pipeline
#12512
waiting for manual action
Stage: checks
Stage: tests
Stage: release
Changes
2
Pipelines
3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
duniterpy/key/signing_key.py
+29
-1
29 additions, 1 deletion
duniterpy/key/signing_key.py
tests/key/test_signing_key.py
+14
-1
14 additions, 1 deletion
tests/key/test_signing_key.py
with
43 additions
and
2 deletions
duniterpy/key/signing_key.py
+
29
−
1
View file @
b19b389d
...
@@ -22,7 +22,7 @@ from typing import Optional, Union, TypeVar, Type
...
@@ -22,7 +22,7 @@ from typing import Optional, Union, TypeVar, Type
import
libnacl.sign
import
libnacl.sign
import
pyaes
import
pyaes
from
libnacl.utils
import
load_key
from
libnacl.utils
import
load_key
from
hashlib
import
scrypt
from
hashlib
import
scrypt
,
sha256
from
.scrypt_params
import
ScryptParams
from
.scrypt_params
import
ScryptParams
from
.base58
import
Base58Encoder
from
.base58
import
Base58Encoder
...
@@ -509,3 +509,31 @@ Data: {data}""".format(
...
@@ -509,3 +509,31 @@ Data: {data}""".format(
seed
=
bytes
(
base64
.
b64decode
(
secret
)[
0
:
32
])
seed
=
bytes
(
base64
.
b64decode
(
secret
)[
0
:
32
])
return
cls
(
seed
)
return
cls
(
seed
)
@classmethod
def
from_dubp_mnemonic
(
cls
,
mnemonic
:
str
,
scrypt_params
:
ScryptParams
=
None
)
->
SigningKeyType
:
"""
Generate key pair instance from a DUBP mnemonic passphrase
See https://git.duniter.org/documents/rfcs/blob/dubp-mnemonic/rfc/0014_Dubp_Mnemonic.md
:param mnemonic: Passphrase generated from a mnemonic algorithm
:param scrypt_params: ScryptParams instance (default=None)
:return:
"""
if
scrypt_params
is
None
:
scrypt_params
=
ScryptParams
()
_password
=
mnemonic
.
encode
(
"
utf-8
"
)
# type: bytes
_salt
=
sha256
(
b
"
dubp
"
+
_password
).
digest
()
# type: bytes
_seed
=
scrypt
(
password
=
_password
,
salt
=
_salt
,
n
=
scrypt_params
.
N
,
# 4096
r
=
scrypt_params
.
r
,
# 16
p
=
scrypt_params
.
p
,
# 1
dklen
=
scrypt_params
.
seed_length
,
# 32
)
# type: bytes
return
cls
(
_seed
)
This diff is collapsed.
Click to expand it.
tests/key/test_signing_key.py
+
14
−
1
View file @
b19b389d
...
@@ -14,7 +14,7 @@ GNU General Public License for more details.
...
@@ -14,7 +14,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
"""
import
base64
import
os
import
os
from
duniterpy.key
import
VerifyingKey
,
SigningKey
,
PublicKey
from
duniterpy.key
import
VerifyingKey
,
SigningKey
,
PublicKey
...
@@ -144,3 +144,16 @@ class TestSigningKey(unittest.TestCase):
...
@@ -144,3 +144,16 @@ class TestSigningKey(unittest.TestCase):
sign_key_load
.
vk
.
hex
(),
sign_key_load
.
vk
.
hex
(),
"
d27f4cb2bfadbaf45b61714b896d4639ab90db035aee746611cdd342bdaa8996
"
,
"
d27f4cb2bfadbaf45b61714b896d4639ab90db035aee746611cdd342bdaa8996
"
,
)
)
def
test_dubp_mnemonic
(
self
):
mnemonic
=
(
"
tongue cute mail fossil great frozen same social weasel impact brush kind
"
)
keypair
=
SigningKey
.
from_dubp_mnemonic
(
mnemonic
)
self
.
assertEqual
(
base64
.
b64encode
(
keypair
.
seed
).
decode
(
"
utf-8
"
),
"
qGdvpbP9lJe7ZG4ZUSyu33KFeAEs/KkshAp9gEI4ReY=
"
,
)
self
.
assertEqual
(
keypair
.
pubkey
,
"
732SSfuwjB7jkt9th1zerGhphs6nknaCBCTozxUcPWPU
"
)
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