From f80f65e3987b335587a1665a912c42366ed48606 Mon Sep 17 00:00:00 2001 From: vtexier <vit@free.fr> Date: Sat, 11 May 2019 11:26:05 +0200 Subject: [PATCH] [fix] #58 fix challenge uuid string format --- duniterpy/documents/ws2p/messages.py | 9 +++++---- duniterpy/tools.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/duniterpy/documents/ws2p/messages.py b/duniterpy/documents/ws2p/messages.py index 62d3d8d8..71e849cf 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 d24ce395..f2bb3b2a 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()) -- GitLab