From df6d4ed158e12e37daa69101844c1d207039133d Mon Sep 17 00:00:00 2001 From: dsc Date: Sun, 28 Mar 2021 21:51:13 +0200 Subject: [PATCH] Add password authentication --- README.md | 17 +++++++++++++++-- wowlet_ws_client/client.py | 11 ++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index effa6e6..d6db431 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,18 @@ import asyncio from wowlet_ws_client.client import WowletWSClient -wowlet = WowletWSClient(host="127.0.0.1", port=42069, debug=True) +wowlet = WowletWSClient( + host="127.0.0.1", port=1234, password="sekrit", debug=True) + + +@wowlet.event("passwordIncorrect") +async def on_password_incorrect(data): + print(data) + + +@wowlet.event("passwordSuccess") +async def on_password_success(data): + print(data) @wowlet.event("walletList") @@ -63,7 +74,9 @@ async def on_transaction_commited(data): async def main(): await wowlet.connect() - await asyncio.sleep(2) + await asyncio.sleep(3) + await wowlet.authenticate() + await asyncio.sleep(3) await wowlet.open_wallet("/home/user/Wownero/wallets/wstest.keys", "test") diff --git a/wowlet_ws_client/client.py b/wowlet_ws_client/client.py index e091762..425997b 100644 --- a/wowlet_ws_client/client.py +++ b/wowlet_ws_client/client.py @@ -12,9 +12,10 @@ from wowlet_ws_client import WowletState, decorator_parametrized, WALLET_OPERATI class WowletWSClient: - def __init__(self, host: str = "127.0.0.1", port: int = 42069, debug: bool = False): + def __init__(self, host: str = "127.0.0.1", port: int = 42069, password: str = None, debug: bool = False): self.host = host self.port = port + self.password = password self.ses = aiohttp.ClientSession() self.debug = debug @@ -178,6 +179,14 @@ class WowletWSClient: self._ws = await self.ses.ws_connect(f"ws://{self.host}:{self.port}") self._loop_task = asyncio.create_task(self.loop()) + async def authenticate(self): + return await self.send(json.dumps({ + "cmd": "password", + "data": { + "password": self.password + } + }).encode()) + async def send(self, data: bytes) -> None: return await self._ws.send_bytes(data)