import jwt
import json
import datetime
import hashlib
# Required inputs
method = "POST"
url = "/v2/accounts"
body = "{\n \"request_id\": \"2de34f56-d549-5651-af61-e2316bc3c47a\",\n \"identity_id\": \"2zwoDFH1yR9ofx1DFHqNDNL2aFS\"\n}"
# Loaded EC private key object (ES256)
# This assumes PRIVATE_KEY is already loaded
hashedBody = hashlib.sha256(body.encode()).hexdigest()
# Generate timestamp
timestamp = datetime.datetime.now(datetime.UTC).timestamp()
# Construct claims
claims = {
"iat": int(timestamp),
"req-method": method,
"req-path": url,
"body": hashedBody
}
# Sign JWT using ES256
token = jwt.encode(claims, PRIVATE_KEY, algorithm="ES256")