Skip to content

Commit

Permalink
Merge pull request #30 from uJhin/1.3.1
Browse files Browse the repository at this point in the history
Update Version 1.3.1.1
  • Loading branch information
uJhin authored Jun 7, 2022
2 parents df9374b + 942573e commit ea93855
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ msgpack==1.0.2
packaging==20.9
pkginfo==1.7.0
Pygments==2.8.0
PyJWT==2.0.1
pylint==2.7.0
PyJWT==2.4.0
pylint==2.13.0
pyparsing==2.4.7
pyrsistent==0.17.3
python-dateutil==2.8.1
Expand Down
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 ea93855

Please sign in to comment.