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
Commits
647bae19
Commit
647bae19
authored
5 years ago
by
Vincent Texier
Committed by
Vincent Texier
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#58
refactor ws2p messages classes
parent
6f83e07e
No related branches found
No related tags found
2 merge requests
!94
Merge dev into master for release 0.56.0
,
!84
#58: WS2P support
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
duniterpy/documents/ws2p/messages.py
+25
-71
25 additions, 71 deletions
duniterpy/documents/ws2p/messages.py
with
25 additions
and
71 deletions
duniterpy/documents/ws2p/messages.py
+
25
−
71
View file @
647bae19
...
...
@@ -7,9 +7,9 @@ from duniterpy.key import VerifyingKey, SigningKey
from
duniterpy.tools
import
get_ws2p_challenge
class
Connect
(
Document
):
class
HandshakeMessage
(
Document
):
version
=
2
auth
=
"
CONNECT
"
auth
=
""
def
__init__
(
self
,
...
...
@@ -21,8 +21,8 @@ class Connect(Document):
"""
Init Connect message document
:param currency: Name of currency
:param pubkey: Public key of node
:param currency: Name of
the
currency
:param pubkey: Public key of
the
node
:param challenge: [Optional, default=None] Big random string, typically an uuid
:param signature: [Optional, default=None] Base64 encoded signature of raw formated document
"""
...
...
@@ -52,8 +52,11 @@ class Connect(Document):
:return:
"""
return
"
WS2P:CONNECT:{currency}:{pub}:{challenge}
"
.
format
(
currency
=
self
.
currency
,
pub
=
self
.
pubkey
,
challenge
=
self
.
challenge
return
"
WS2P:{auth}:{currency}:{pub}:{challenge}
"
.
format
(
auth
=
self
.
auth
,
currency
=
self
.
currency
,
pub
=
self
.
pubkey
,
challenge
=
self
.
challenge
,
)
def
get_signed_json
(
self
,
signing_key
:
SigningKey
)
->
str
:
...
...
@@ -77,8 +80,11 @@ class Connect(Document):
return
self
.
raw
()
class
Ack
(
Document
):
version
=
2
class
Connect
(
HandshakeMessage
):
auth
=
"
CONNECT
"
class
Ack
(
HandshakeMessage
):
auth
=
"
ACK
"
def
__init__
(
...
...
@@ -89,37 +95,14 @@ class Ack(Document):
signature
:
Optional
[
str
]
=
None
,
)
->
None
:
"""
Init
Ack
message document
Init
Connect
message document
:param currency: Name of currency
:param pubkey: Public key of node
:param challenge:
The challenge sent in the connect message
:param currency: Name of
the
currency
:param pubkey: Public key of
the
node
:param challenge:
Big random string, typically an uuid
:param signature: [Optional, default=None] Base64 encoded signature of raw formated document
"""
if
signature
is
not
None
:
signatures
=
[
signature
]
else
:
signatures
=
[]
super
().
__init__
(
self
.
version
,
currency
,
signatures
)
self
.
pubkey
=
pubkey
self
.
challenge
=
challenge
if
signature
is
not
None
:
# verify signature
verifying_key
=
VerifyingKey
(
self
.
pubkey
)
verifying_key
.
verify_document
(
self
)
def
raw
(
self
):
"""
Return the document in raw format
:return:
"""
return
"
WS2P:ACK:{currency}:{pub}:{challenge}
"
.
format
(
currency
=
self
.
currency
,
pub
=
self
.
pubkey
,
challenge
=
self
.
challenge
)
super
().
__init__
(
currency
,
pubkey
,
challenge
,
signature
)
def
get_signed_json
(
self
,
signing_key
:
SigningKey
)
->
str
:
"""
...
...
@@ -133,12 +116,8 @@ class Ack(Document):
data
=
{
"
auth
"
:
self
.
auth
,
"
pub
"
:
self
.
pubkey
,
"
sig
"
:
self
.
signatures
[
0
]}
return
json
.
dumps
(
data
)
def
__str__
(
self
)
->
str
:
return
self
.
raw
()
class
Ok
(
Document
):
version
=
2
class
Ok
(
HandshakeMessage
):
auth
=
"
OK
"
def
__init__
(
...
...
@@ -149,36 +128,14 @@ class Ok(Document):
signature
:
Optional
[
str
]
=
None
,
)
->
None
:
"""
Init
Ok
message document
Init
Connect
message document
:param currency: Name of currency
:param pubkey: Public key of node
:param challenge:
The challenge sent in the connect message
:param currency: Name of
the
currency
:param pubkey: Public key of
the
node
:param challenge:
Big random string, typically an uuid
:param signature: [Optional, default=None] Base64 encoded signature of raw formated document
"""
if
signature
is
not
None
:
signatures
=
[
signature
]
else
:
signatures
=
[]
super
().
__init__
(
self
.
version
,
currency
,
signatures
)
self
.
pubkey
=
pubkey
self
.
challenge
=
challenge
if
signature
is
not
None
:
# verify signature
verifying_key
=
VerifyingKey
(
self
.
pubkey
)
verifying_key
.
verify_document
(
self
)
def
raw
(
self
):
"""
Return the document in raw format
:return:
"""
return
"
WS2P:OK:{currency}:{pub}:{challenge}
"
.
format
(
currency
=
self
.
currency
,
pub
=
self
.
pubkey
,
challenge
=
self
.
challenge
)
super
().
__init__
(
currency
,
pubkey
,
challenge
,
signature
)
def
get_signed_json
(
self
,
signing_key
:
SigningKey
)
->
str
:
"""
...
...
@@ -192,9 +149,6 @@ class Ok(Document):
data
=
{
"
auth
"
:
self
.
auth
,
"
sig
"
:
self
.
signatures
[
0
]}
return
json
.
dumps
(
data
)
def
__str__
(
self
)
->
str
:
return
self
.
raw
()
class
DocumentMessage
:
PEER_TYPE_ID
=
0
...
...
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