Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Sep 23, 2024
1 parent 990fa97 commit 01c19a3
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions multiversx_sdk_cli/native_auth_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from multiversx_sdk_cli.errors import NativeAuthClientError

EXPIRY_TIME_IN_SECONDS = 60 * 60 * 2
DEFAULT_EXPIRY_TIME_IN_SECONDS = 60 * 60 * 2
DEFAULT_API_URL = "https://api.multiversx.com"


Expand All @@ -15,7 +15,7 @@ def __init__(
self,
origin: str = '',
api_url: str = DEFAULT_API_URL,
expiry_seconds: int = EXPIRY_TIME_IN_SECONDS,
expiry_seconds: int = DEFAULT_EXPIRY_TIME_IN_SECONDS,
block_hash_shard: Optional[int] = None,
gateway_url: Optional[str] = None,
extra_request_headers: Optional[Dict[str, str]] = None
Expand All @@ -32,19 +32,19 @@ class NativeAuthClient:
def __init__(self, config: Optional[NativeAuthClientConfig] = None) -> None:
self.config = config or NativeAuthClientConfig()

def get_token(self, address: str, token: str, signature: str) -> str:
encoded_address = self.encode_value(address)
encoded_token = self.encode_value(token)

return f"{encoded_address}.{encoded_token}.{signature}"

def initialize(self, extra_info: Dict[Any, Any] = {}) -> str:
block_hash = self.get_current_block_hash()
encoded_extra_info = self.encode_value(json.dumps(extra_info))
encoded_origin = self.encode_value(self.config.origin)
encoded_extra_info = self._encode_value(json.dumps(extra_info))
encoded_origin = self._encode_value(self.config.origin)

return f"{encoded_origin}.{block_hash}.{self.config.expiry_seconds}.{encoded_extra_info}"

def get_token(self, address: str, token: str, signature: str) -> str:
encoded_address = self._encode_value(address)
encoded_token = self._encode_value(token)

return f"{encoded_address}.{encoded_token}.{signature}"

def get_current_block_hash(self) -> str:
if self.config.gateway_url:
return self._get_current_block_hash_using_gateway()
Expand Down Expand Up @@ -91,11 +91,11 @@ def _get_current_block_hash_using_api_fallback(self) -> str:
response = self._execute_request(url)
return response[0]["hash"]

def encode_value(self, string: str) -> str:
def _encode_value(self, string: str) -> str:
encoded = base64.b64encode(string.encode('utf-8')).decode('utf-8')
return self.escape(encoded)
return self._escape(encoded)

def escape(self, string: str) -> str:
def _escape(self, string: str) -> str:
return string.replace("+", "-").replace("/", "_").replace("=", "")

def _execute_request(self, url: str) -> Any:
Expand Down

0 comments on commit 01c19a3

Please sign in to comment.