import json
from base64 import b64encode

from . import private_key, encoding


def sign_request(request: dict):
    request = json.dumps(request, indent=4)
    signed_request = {"request": str(b64encode(str(request).encode(encoding)), encoding)}
    signed_request["signature"] = str(b64encode(private_key.sign(bytes(signed_request["request"], encoding))), encoding)
    return signed_request
