About JWT on browser

Job ID: 34251668

Budget: $10 – $30 USD

We are looking for someone familiar with JWT.

What I want to do is issue a signature in JWT.
The Python code below is working fine.

――――――――――――――――――
import jwt
from jwt.algorithms import ECAlgorithm
import time
privateKey = {
"crv":"P-256",
"d":"dddddddddddddddddddddddddddddddddddddddddd",
"ext":True,
"key_ops":["sign"],
"kty":"EC",
"x": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"y": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
}

headers = {
"typ": "dpop+jwt",
"alg": "ES256",
"jwk": {
"crv": "P-256",
"kty": "EC",
"x": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"y": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
}
}

payload = {
"iat": int(time.time()),
"jti": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"htu": "https://example.com/",
"htm": "GET",
"uuid": "uuiduuiduuiduuiduuiduuiduuiduuid"
}
key = ECAlgorithm.from_jwk(privateKey)
JWT = jwt.encode(payload, key, algorithm="ES256", headers=headers, json_encoder=None)
print(JWT)
――――――――――――――――――

However, we would like to rewrite it with JavaScript (ES Modules) that runs on the browser.

For Node.js, the "jsonwebtoken" module does something similar, but it didn't work for browsers. I considered "Browserify" etc., but gave up.

Would it be possible to have the same code in vanilla JavaScript that works on the browser?

Please lend me your help.
Related categories: JavaScript Python Django HTML Node.js