i've tried different approach to authenticate but it seems the error comes from a bug on retool side, as the same code works fine on jupyter notebook but not on retool workflow i ve managed to drill down the problem into this code below: even though it doesnt authenticate, it shoots back the error : InvalidKeyError: Could not parse the provided public key.
any help would be greatly appreciated thanks
import json
import math
import secrets
import time
from hashlib import sha256
import jwt
class FireblocksRequestHandler(object):
def __init__(self, private_key, api_key):
self.private_key = private_key
self.api_key = api_key
def _sign_jwt(self, path, body_json=""):
timestamp = time.time()
nonce = secrets.randbits(63)
timestamp_secs = math.floor(timestamp)
path = path.replace("[", "%5B")
path = path.replace("]", "%5D")
token = {
"uri": path,
"nonce": nonce,
"iat": timestamp_secs,
"exp": timestamp_secs + 55,
"sub": self.api_key,
"bodyHash": sha256(json.dumps(body_json).encode("utf-8")).hexdigest()
}
return jwt.encode(token, key=self.private_key, algorithm="RS256")
def get_request(self, path):
token = self._sign_jwt(path)
print(self.api_key)
headers = {
"X-API-Key": self.api_key,
"Authorization": f"Bearer {token}"
}
print(headers)
return headers
base_url = 'https://api.fireblocks.io'
request_handler = FireblocksRequestHandler(FIREBLOCKS_API_SECRET, FIREBLOCKS_API_KEY)
response = request_handler.get_request('/v1/vault/accounts_paged')
return response