Skip to content

Commit

Permalink
[Update] Update Version 1.3.1.1
Browse files Browse the repository at this point in the history
Update Version 1.3.1.1
  • Loading branch information
uJhin committed Jun 7, 2022
1 parent 9d85fcb commit 942573e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
31 changes: 20 additions & 11 deletions upbit/authentication.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

import jwt
import hashlib
import uuid

from urllib.parse import urlencode

from bravado.requests_client import Authenticator


class APIKeyAuthenticator(Authenticator):

import jwt
import uuid

from urllib.parse import urlencode


MAPPER = "swg_mapper.json"
QUERY_PARAMS = ( "uuids", "txids", "identifiers", "states" )

Expand All @@ -26,6 +26,8 @@ def __init__(
self.host = host
self.access_key = access_key
self.secret_key = secret_key
self.algorithms = self.jwt.algorithms
self.algo = "HS512"


def matches(self, url):
Expand All @@ -49,27 +51,27 @@ def generate_payload(self, request):

payload = {
'access_key': self.access_key,
'nonce': str(uuid.uuid4())
'nonce': str(self.uuid.uuid4())
}
if isinstance(data, dict):
params.update(data)
if params:
query = self.generate_query(params)

sha512 = hashlib.sha512()
sha512 = self.get_hash_algo(self.algo)
sha512.update(query.encode())
query_hash = sha512.hexdigest()

payload["query_hash" ] = query_hash
payload["query_hash_alg"] = "SHA512"
payload["query_hash_alg"] = sha512.name

jwt_token = jwt.encode(payload, self.secret_key)
jwt_token = self.jwt.encode(payload, self.secret_key, algorithm=self.algo)
authorize_token = f"Bearer {jwt_token}"
return authorize_token


def generate_query(self, params):
query = urlencode({
query = self.urlencode({
k: v
for k, v in params.items()
if k.lower() not in APIKeyAuthenticator.QUERY_PARAMS
Expand All @@ -84,3 +86,10 @@ def generate_query(self, params):
])
query = f"{query}&{query_params}" if query else query_params
return query


def get_hash_algo(self, algo):
algorithms = self.algorithms.get_default_algorithms()
algo = algorithms.get(algo, "HS512")
hash_algo = algo.hash_alg()
return hash_algo
2 changes: 1 addition & 1 deletion upbit/pkginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _get_versions(package_name):
PACKAGE_NAME = "upbit-client"

OPEN_API_VERSION = "1.3.1"
CURRENT_VERSION = OPEN_API_VERSION+".0"
CURRENT_VERSION = OPEN_API_VERSION+".1"

RELEASED_VERSION = _get_versions(PACKAGE_NAME)
LATEST_VERSION = RELEASED_VERSION[0]
Expand Down

0 comments on commit 942573e

Please sign in to comment.