From 740e350d5a31f4e79726acf2d0058cb3c9093f80 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Wies=C5=82aw=20K=C4=99dzierski?= <wkedzierski@syncad.com>
Date: Mon, 12 Feb 2024 14:19:21 +0100
Subject: [PATCH] Add token parameter to beekeeper api calls.

---
 helpy/_handles/beekeeper/api/async_api.py | 60 ++++++++++++++++-------
 helpy/_handles/beekeeper/api/sync_api.py  | 30 ++++++------
 2 files changed, 59 insertions(+), 31 deletions(-)

diff --git a/helpy/_handles/beekeeper/api/async_api.py b/helpy/_handles/beekeeper/api/async_api.py
index c90bb763..b2506c04 100644
--- a/helpy/_handles/beekeeper/api/async_api.py
+++ b/helpy/_handles/beekeeper/api/async_api.py
@@ -11,26 +11,26 @@ class BeekeeperApi(AbstractAsyncApi):
     api = AbstractAsyncApi._endpoint
 
     @api
-    async def create(self, *, wallet_name: str, password: str | None = None) -> beekeeper_api.Create:
+    async def create(self, *, token: str, wallet_name: str, password: str | None = None) -> beekeeper_api.Create:
         """
         Creates wallet with given name.
 
         Arguments:
-        ----
+            token (str) -- valid session token
             wallet_name (str) -- name of wallet to create
             password (str | None, optional) -- password for new wallet, if not given generates one. Defaults to None.
 
         Returns
-        -------
             beekeeper_api.Create: Returns password that was used for wallet creation.
         """
         raise NotImplementedError
 
     @api
-    async def open(self, *, wallet_name: str) -> beekeeper_api.EmptyResponse:  # noqa: A003
+    async def open(self, *, token: str, wallet_name: str) -> beekeeper_api.EmptyResponse:  # noqa: A003
         """Opens wallet, which makes it unaccessible for other sessions.
 
         Arguments:
+            token (str) -- valid session token
             wallet_name (str) -- wallet to open
 
         Returns:
@@ -39,10 +39,11 @@ class BeekeeperApi(AbstractAsyncApi):
         raise NotImplementedError
 
     @api
-    async def set_timeout(self, *, seconds: int) -> beekeeper_api.EmptyResponse:
+    async def set_timeout(self, *, token: str, seconds: int) -> beekeeper_api.EmptyResponse:
         """Sets timeout after all wallets opened in current session will be closed.
 
         Arguments:
+            token (str) -- valid session token
             seconds -- amount of seconds from last interaction (on any wallet) to wait before lock all wallets.
 
         Returns
@@ -52,19 +53,23 @@ class BeekeeperApi(AbstractAsyncApi):
         raise NotImplementedError
 
     @api
-    async def lock_all(self) -> beekeeper_api.EmptyResponse:
+    async def lock_all(self, *, token: str) -> beekeeper_api.EmptyResponse:
         """Locks all wallet in current session.
 
+        Arguments:
+            token (str) -- valid session token
+
         Returns:
             Nothing.
         """
         raise NotImplementedError
 
     @api
-    async def lock(self, *, wallet_name: str) -> beekeeper_api.EmptyResponse:
+    async def lock(self, *, token: str, wallet_name: str) -> beekeeper_api.EmptyResponse:
         """Locks specific wallet.
 
         Arguments:
+            token (str) -- valid session token
             wallet_name -- wallet to lock.
 
         Returns:
@@ -73,10 +78,11 @@ class BeekeeperApi(AbstractAsyncApi):
         raise NotImplementedError
 
     @api
-    async def unlock(self, *, wallet_name: str, password: str) -> beekeeper_api.EmptyResponse:
+    async def unlock(self, *, token: str, wallet_name: str, password: str) -> beekeeper_api.EmptyResponse:
         """Unlocks specific wallet (and opens it implicitly).
 
         Arguments:
+            token (str) -- valid session token
             wallet_name -- wallet to unlock (and open)
             password -- password to unlock wallet
 
@@ -86,13 +92,14 @@ class BeekeeperApi(AbstractAsyncApi):
         raise NotImplementedError
 
     @api
-    async def import_key(self, *, wallet_name: str, wif_key: str) -> beekeeper_api.ImportKey:
+    async def import_key(self, *, token: str, wallet_name: str, wif_key: str) -> beekeeper_api.ImportKey:
         """Imports key to given wallet.
 
         Warning:
             After importing this key to beekeeper, it's impossible to access it via api; Access to private keys is only possible with binary.
 
         Arguments:
+            token (str) -- valid session token
             wallet_name -- wallet to import given key
             wif_key -- private key to import
 
@@ -102,10 +109,13 @@ class BeekeeperApi(AbstractAsyncApi):
         raise NotImplementedError
 
     @api
-    async def remove_key(self, *, wallet_name: str, password: str, public_key: str) -> beekeeper_api.EmptyResponse:
+    async def remove_key(
+        self, *, token: str, wallet_name: str, password: str, public_key: str
+    ) -> beekeeper_api.EmptyResponse:
         """Removes imported key from given wallet.
 
         Arguments:
+            token (str) -- valid session token
             wallet_name -- wallet from key will be removed
             password -- to confirm action
             public_key -- public key, which is paired with private key to remove
@@ -116,31 +126,38 @@ class BeekeeperApi(AbstractAsyncApi):
         raise NotImplementedError
 
     @api
-    async def list_wallets(self) -> beekeeper_api.ListWallets:
+    async def list_wallets(self, *, token: str) -> beekeeper_api.ListWallets:
         """Lists all opened wallets in current session.
 
         Note:
             There is no way to list all not opened wallets.
 
+        Arguments:
+            token (str) -- valid session token
+
         Returns:
             List of wallets
         """
         raise NotImplementedError
 
     @api
-    async def get_public_keys(self) -> beekeeper_api.GetPublicKeys:
+    async def get_public_keys(self, *, token: str) -> beekeeper_api.GetPublicKeys:
         """Lists all public keys from all unlocked wallets.
 
+        Arguments:
+            token (str) -- valid session token
+
         Returns:
             List of public keys
         """
         raise NotImplementedError
 
     @api
-    async def sign_digest(self, *, sig_digest: str, public_key: str) -> beekeeper_api.SignDigest:
+    async def sign_digest(self, *, token: str, sig_digest: str, public_key: str) -> beekeeper_api.SignDigest:
         """Signs given digest with private key paired with given public key.
 
         Arguments:
+            token (str) -- valid session token
             sig_digest -- digest to sign
             public_key -- public key paired with private key to sign with
 
@@ -151,11 +168,12 @@ class BeekeeperApi(AbstractAsyncApi):
 
     @api
     async def sign_transaction(
-        self, *, transaction: Transaction, chain_id: str, public_key: str, sig_digest: str
+        self, *, token: str, transaction: Transaction, chain_id: str, public_key: str, sig_digest: str
     ) -> beekeeper_api.SignTransaction:
         """Signs transaction with given key.
 
         Arguments:
+            token (str) -- valid session token
             transaction -- transaction to sign
             chain_id -- chain id under which signature should be created (database_api.get_config -> HIVE_CHAIN_ID)
             public_key -- public key paired with private key to sign with
@@ -167,16 +185,21 @@ class BeekeeperApi(AbstractAsyncApi):
         raise NotImplementedError
 
     @api
-    async def get_info(self) -> beekeeper_api.GetInfo:
+    async def get_info(self, *, token: str) -> beekeeper_api.GetInfo:
         """Gets status of current session.
 
+        Arguments:
+            token (str) -- valid session token
+
         Returns:
             Information about current session.
         """
         raise NotImplementedError
 
     @api
-    async def create_session(self, *, notifications_endpoint: str, salt: str) -> beekeeper_api.CreateSession:
+    async def create_session(
+        self, *, token: str, notifications_endpoint: str, salt: str
+    ) -> beekeeper_api.CreateSession:
         """Creates session.
 
         Note:
@@ -192,9 +215,12 @@ class BeekeeperApi(AbstractAsyncApi):
         raise NotImplementedError
 
     @api
-    async def close_session(self) -> beekeeper_api.EmptyResponse:
+    async def close_session(self, *, token: str) -> beekeeper_api.EmptyResponse:
         """Closes session.
 
+        Arguments:
+            token (str) -- valid session token
+
         Returns:
             Noting.
         """
diff --git a/helpy/_handles/beekeeper/api/sync_api.py b/helpy/_handles/beekeeper/api/sync_api.py
index eaba32d7..13fd6a9a 100644
--- a/helpy/_handles/beekeeper/api/sync_api.py
+++ b/helpy/_handles/beekeeper/api/sync_api.py
@@ -9,57 +9,59 @@ class BeekeeperApi(AbstractSyncApi):
     api = AbstractSyncApi._endpoint
 
     @api
-    def create(self, *, wallet_name: str, password: str | None = None) -> beekeeper_api.Create:
+    def create(self, *, token: str, wallet_name: str, password: str | None = None) -> beekeeper_api.Create:
         raise NotImplementedError
 
     @api
-    def open(self, *, wallet_name: str) -> beekeeper_api.EmptyResponse:  # noqa: A003
+    def open(self, *, token: str, wallet_name: str) -> beekeeper_api.EmptyResponse:  # noqa: A003
         raise NotImplementedError
 
     @api
-    def set_timeout(self, *, seconds: int) -> beekeeper_api.EmptyResponse:
+    def set_timeout(self, *, token: str, seconds: int) -> beekeeper_api.EmptyResponse:
         raise NotImplementedError
 
     @api
-    def lock_all(self) -> beekeeper_api.EmptyResponse:
+    def lock_all(self, *, token: str) -> beekeeper_api.EmptyResponse:
         raise NotImplementedError
 
     @api
-    def lock(self, *, wallet_name: str) -> beekeeper_api.EmptyResponse:
+    def lock(self, *, token: str, wallet_name: str) -> beekeeper_api.EmptyResponse:
         raise NotImplementedError
 
     @api
-    def unlock(self, *, wallet_name: str, password: str) -> beekeeper_api.EmptyResponse:
+    def unlock(self, *, token: str, wallet_name: str, password: str) -> beekeeper_api.EmptyResponse:
         raise NotImplementedError
 
     @api
-    def import_key(self, *, wallet_name: str, wif_key: str) -> beekeeper_api.ImportKey:
+    def import_key(self, *, token: str, wallet_name: str, wif_key: str) -> beekeeper_api.ImportKey:
         raise NotImplementedError
 
     @api
-    def remove_key(self, *, wallet_name: str, password: str, public_key: str) -> beekeeper_api.EmptyResponse:
+    def remove_key(
+        self, *, token: str, wallet_name: str, password: str, public_key: str
+    ) -> beekeeper_api.EmptyResponse:
         raise NotImplementedError
 
     @api
-    def list_wallets(self) -> beekeeper_api.ListWallets:
+    def list_wallets(self, *, token: str) -> beekeeper_api.ListWallets:
         raise NotImplementedError
 
     @api
-    def get_public_keys(self) -> beekeeper_api.GetPublicKeys:
+    def get_public_keys(self, *, token: str) -> beekeeper_api.GetPublicKeys:
         raise NotImplementedError
 
     @api
-    def sign_digest(self, *, sig_digest: str, public_key: str) -> beekeeper_api.SignDigest:
+    def sign_digest(self, *, token: str, sig_digest: str, public_key: str) -> beekeeper_api.SignDigest:
         raise NotImplementedError
 
     @api
     def sign_transaction(
-        self, *, transaction: Transaction, chain_id: str, public_key: str, sig_digest: str
+        self, *, token: str, transaction: Transaction, chain_id: str, public_key: str, sig_digest: str
     ) -> beekeeper_api.SignTransaction:
         raise NotImplementedError
 
     @api
-    def get_info(self) -> beekeeper_api.GetInfo:
+    def get_info(self, *, token: str) -> beekeeper_api.GetInfo:
         raise NotImplementedError
 
     @api
@@ -67,5 +69,5 @@ class BeekeeperApi(AbstractSyncApi):
         raise NotImplementedError
 
     @api
-    def close_session(self) -> beekeeper_api.EmptyResponse:
+    def close_session(self, *, token: str) -> beekeeper_api.EmptyResponse:
         raise NotImplementedError
-- 
GitLab