diff --git a/duniterpy/documents/ws2p/messages.py b/duniterpy/documents/ws2p/messages.py index 62d3d8d88f2e36376e46f3a42d73a2110be24ae8..71e849cfbcd6bebce540437432fc3f5c0e277e13 100644 --- a/duniterpy/documents/ws2p/messages.py +++ b/duniterpy/documents/ws2p/messages.py @@ -1,9 +1,10 @@ import json -import uuid + from typing import Optional from duniterpy.documents import Document from duniterpy.key import VerifyingKey, SigningKey +from duniterpy.helpers import get_ws2p_challenge class Connect(Document): @@ -25,7 +26,7 @@ class Connect(Document): self.pubkey = pubkey if challenge is None: # create challenge - self.challenge = uuid.uuid4().hex + uuid.uuid4().hex + self.challenge = get_ws2p_challenge() else: self.challenge = challenge # add and verify signature @@ -71,7 +72,7 @@ class Ack(Document): def __init__(self, currency: str, pubkey: str, challenge: str, signature: Optional[str] = None) -> None: """ - Init Connect message document + Init Ack message document :param currency: Name of currency :param pubkey: Public key of node @@ -124,7 +125,7 @@ class Ok(Document): def __init__(self, currency: str, pubkey: str, challenge: str, signature: Optional[str] = None) -> None: """ - Init Connect message document + Init Ok message document :param currency: Name of currency :param pubkey: Public key of node diff --git a/duniterpy/tools.py b/duniterpy/tools.py index d24ce3952b0ebb9740b5889f5b3fb4da88a7a4c7..f2bb3b2a6f24cb6bbdfcb47c217920247c5a0eba 100644 --- a/duniterpy/tools.py +++ b/duniterpy/tools.py @@ -1,3 +1,4 @@ +import uuid from typing import Union from libnacl.encode import hex_decode, hex_encode @@ -60,3 +61,12 @@ def convert_seed_to_seedhex(seed: bytes) -> str: :rtype str: """ return hex_encode(seed).decode("utf-8") + + +def get_ws2p_challenge() -> str: + """ + Return two uuid v4 concatened as ws2p challenge + + :rtype str: + """ + return str(uuid.uuid4()) + str(uuid.uuid4())