It is easy with node-jose library when you know how to do it.
It took me some time to learn, because this information is missing in the documentation. Luckily it was in tests. The missing example (creates a JWT with an embedded ‘jwk’): // {input} is a String
// {key} is from jwk keystore jose.JWS.createSign(
{
fields: {
typ: 'JWT',
},
format: 'compact',
opts: { protect: false },
},
{
key,
reference: 'jwk', // MISSING in documentation
},
).update(input, 'utf-8')
.final()
.then((result) => {
// {result} is a JSON object -- JWT using the JSON General Serialization
});