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
82fc26ca
Commit
82fc26ca
authored
5 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
[fix]
#58
fix documents.ws2p.messages
parent
2c4d2507
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
duniterpy/documents/ws2p/messages.py
+27
-15
27 additions, 15 deletions
duniterpy/documents/ws2p/messages.py
with
27 additions
and
15 deletions
duniterpy/documents/ws2p/messages.py
+
27
−
15
View file @
82fc26ca
import
json
import
json
from
typing
import
Optional
,
Any
from
typing
import
Optional
from
duniterpy.documents
import
Document
from
duniterpy.documents
import
Document
from
duniterpy.key
import
VerifyingKey
,
SigningKey
from
duniterpy.key
import
VerifyingKey
,
SigningKey
...
@@ -21,17 +21,23 @@ class Connect(Document):
...
@@ -21,17 +21,23 @@ class Connect(Document):
:param challenge: [Optional, default=None] Big random string, typically an uuid
:param challenge: [Optional, default=None] Big random string, typically an uuid
:param signature: [Optional, default=None] Base64 encoded signature of raw formated document
:param signature: [Optional, default=None] Base64 encoded signature of raw formated document
"""
"""
super
().
__init__
(
self
.
version
,
currency
,
[
signature
])
if
signature
is
not
None
:
signatures
=
[
signature
]
else
:
signatures
=
[]
super
().
__init__
(
self
.
version
,
currency
,
signatures
)
self
.
pubkey
=
pubkey
self
.
pubkey
=
pubkey
if
challenge
is
None
:
if
challenge
is
None
:
# create challenge
# create challenge
self
.
challenge
=
get_ws2p_challenge
()
self
.
challenge
=
get_ws2p_challenge
()
else
:
else
:
self
.
challenge
=
challenge
self
.
challenge
=
challenge
# add and verify signature
if
signature
is
not
None
:
if
signature
is
not
None
:
self
.
signatures
.
append
(
signature
)
# verify signature
verifying_key
=
VerifyingKey
(
self
.
pubkey
)
verifying_key
=
VerifyingKey
(
self
.
pubkey
)
verifying_key
.
verify_document
(
self
)
verifying_key
.
verify_document
(
self
)
...
@@ -79,13 +85,18 @@ class Ack(Document):
...
@@ -79,13 +85,18 @@ class Ack(Document):
:param challenge: The challenge sent in the connect message
:param challenge: The challenge sent in the connect message
:param signature: [Optional, default=None] Base64 encoded signature of raw formated document
:param signature: [Optional, default=None] Base64 encoded signature of raw formated document
"""
"""
super
().
__init__
(
self
.
version
,
currency
,
[
signature
])
if
signature
is
not
None
:
signatures
=
[
signature
]
else
:
signatures
=
[]
super
().
__init__
(
self
.
version
,
currency
,
signatures
)
self
.
pubkey
=
pubkey
self
.
pubkey
=
pubkey
self
.
challenge
=
challenge
self
.
challenge
=
challenge
# add and verify signature
if
signature
is
not
None
:
if
signature
is
not
None
:
self
.
signatures
.
append
(
signature
)
# verify signature
verifying_key
=
VerifyingKey
(
self
.
pubkey
)
verifying_key
=
VerifyingKey
(
self
.
pubkey
)
verifying_key
.
verify_document
(
self
)
verifying_key
.
verify_document
(
self
)
...
@@ -132,13 +143,17 @@ class Ok(Document):
...
@@ -132,13 +143,17 @@ class Ok(Document):
:param challenge: The challenge sent in the connect message
:param challenge: The challenge sent in the connect message
:param signature: [Optional, default=None] Base64 encoded signature of raw formated document
:param signature: [Optional, default=None] Base64 encoded signature of raw formated document
"""
"""
super
().
__init__
(
self
.
version
,
currency
,
[
signature
])
if
signature
is
not
None
:
signatures
=
[
signature
]
else
:
signatures
=
[]
super
().
__init__
(
self
.
version
,
currency
,
signatures
)
self
.
pubkey
=
pubkey
self
.
pubkey
=
pubkey
self
.
challenge
=
challenge
self
.
challenge
=
challenge
# add and verify signature
if
signature
is
not
None
:
if
signature
is
not
None
:
self
.
signatures
.
append
(
signature
)
# verify signature
verifying_key
=
VerifyingKey
(
self
.
pubkey
)
verifying_key
=
VerifyingKey
(
self
.
pubkey
)
verifying_key
.
verify_document
(
self
)
verifying_key
.
verify_document
(
self
)
...
@@ -170,8 +185,6 @@ class Ok(Document):
...
@@ -170,8 +185,6 @@ class Ok(Document):
return
self
.
raw
()
return
self
.
raw
()
# fixme: the document format to send is to be determine
# does raw or inline format works ?
class
DocumentMessage
:
class
DocumentMessage
:
PEER_TYPE_ID
=
0
PEER_TYPE_ID
=
0
TRANSACTION_TYPE_ID
=
1
TRANSACTION_TYPE_ID
=
1
...
@@ -189,13 +202,12 @@ class DocumentMessage:
...
@@ -189,13 +202,12 @@ class DocumentMessage:
5
:
"
block
"
5
:
"
block
"
}
}
def
get_json
(
self
,
document_type_id
:
int
,
document
:
Any
)
->
str
:
def
get_json
(
self
,
document_type_id
:
int
,
document
:
str
)
->
str
:
"""
"""
Return the document message in json format
Return the document message in json format
:param document_type_id: Id of the document type, use class properties
:param document_type_id: Id of the document type, use class properties
:param document: Document object to send
:param document: Raw or Inline Document to send
:return:
"""
"""
data
=
{
data
=
{
"
body
"
:
{
"
body
"
:
{
...
...
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