Skip to content

Commit cd7a85c

Browse files
authored
Merge pull request #43 from uJhin/1.3.1
Update Version 1.3.1.1
2 parents db2b0c2 + 7acdbb1 commit cd7a85c

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

client/python/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ msgpack==1.0.2
2020
packaging==20.9
2121
pkginfo==1.7.0
2222
Pygments==2.8.0
23-
PyJWT==2.0.1
24-
pylint==2.7.0
23+
PyJWT==2.4.0
24+
pylint==2.13.0
2525
pyparsing==2.4.7
2626
pyrsistent==0.17.3
2727
python-dateutil==2.8.1

client/python/upbit/authentication.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

2-
import jwt
3-
import hashlib
4-
import uuid
5-
6-
from urllib.parse import urlencode
7-
82
from bravado.requests_client import Authenticator
93

104

115
class APIKeyAuthenticator(Authenticator):
126

7+
import jwt
8+
import uuid
9+
10+
from urllib.parse import urlencode
11+
12+
1313
MAPPER = "swg_mapper.json"
1414
QUERY_PARAMS = ( "uuids", "txids", "identifiers", "states" )
1515

@@ -26,6 +26,8 @@ def __init__(
2626
self.host = host
2727
self.access_key = access_key
2828
self.secret_key = secret_key
29+
self.algorithms = self.jwt.algorithms
30+
self.algo = "HS512"
2931

3032

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

5052
payload = {
5153
'access_key': self.access_key,
52-
'nonce': str(uuid.uuid4())
54+
'nonce': str(self.uuid.uuid4())
5355
}
5456
if isinstance(data, dict):
5557
params.update(data)
5658
if params:
5759
query = self.generate_query(params)
5860

59-
sha512 = hashlib.sha512()
61+
sha512 = self.get_hash_algo(self.algo)
6062
sha512.update(query.encode())
6163
query_hash = sha512.hexdigest()
6264

6365
payload["query_hash" ] = query_hash
64-
payload["query_hash_alg"] = "SHA512"
66+
payload["query_hash_alg"] = sha512.name
6567

66-
jwt_token = jwt.encode(payload, self.secret_key)
68+
jwt_token = self.jwt.encode(payload, self.secret_key, algorithm=self.algo)
6769
authorize_token = f"Bearer {jwt_token}"
6870
return authorize_token
6971

7072

7173
def generate_query(self, params):
72-
query = urlencode({
74+
query = self.urlencode({
7375
k: v
7476
for k, v in params.items()
7577
if k.lower() not in APIKeyAuthenticator.QUERY_PARAMS
@@ -84,3 +86,10 @@ def generate_query(self, params):
8486
])
8587
query = f"{query}&{query_params}" if query else query_params
8688
return query
89+
90+
91+
def get_hash_algo(self, algo):
92+
algorithms = self.algorithms.get_default_algorithms()
93+
algo = algorithms.get(algo, "HS512")
94+
hash_algo = algo.hash_alg()
95+
return hash_algo

client/python/upbit/pkginfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _get_versions(package_name):
2929
PACKAGE_NAME = "upbit-client"
3030

3131
OPEN_API_VERSION = "1.3.1"
32-
CURRENT_VERSION = OPEN_API_VERSION+".0"
32+
CURRENT_VERSION = OPEN_API_VERSION+".1"
3333

3434
RELEASED_VERSION = _get_versions(PACKAGE_NAME)
3535
LATEST_VERSION = RELEASED_VERSION[0]

0 commit comments

Comments
 (0)