-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
31 lines (27 loc) · 775 Bytes
/
utils.py
File metadata and controls
31 lines (27 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import time
import jwt
from cryptography.hazmat.primitives import serialization
import time
import secrets
from dotenv import load_dotenv
import os
load_dotenv()
API_KEY_ID = os.getenv("COINBASE_API_KEY")
API_SECRET = os.getenv("COINBASE_API_SECRET_KEY")
def build_jwt(uri):
private_key_bytes = API_SECRET.encode('utf-8')
private_key = serialization.load_pem_private_key(private_key_bytes, password=None)
jwt_payload = {
'sub': API_KEY_ID,
'iss': "cdp",
'nbf': int(time.time()),
'exp': int(time.time()) + 120,
'uri': uri,
}
jwt_token = jwt.encode(
jwt_payload,
private_key,
algorithm='ES256',
headers={'kid': API_KEY_ID, 'nonce': secrets.token_hex()},
)
return jwt_token