Skip to content

help upgrading code from jose 2.0.4 to the latest #339

Answered by panva
dagda1 asked this question in Q&A
Discussion options

You must be logged in to vote

Roughly, like so.

const hkdf = require('futoin-hkdf');
const jose = require('jose')

const BYTE_LENGTH = 32;
const ENCRYPTION_INFO = 'JWE CEK';

const deriveKey = (secret) => hkdf(secret, BYTE_LENGTH, { info: ENCRYPTION_INFO, hash: 'SHA-256' });

module.exports = async function encrypt(arg) {
  let { secret, ...thingToEncrypt } = arg;
  let epochNow = (Date.now() / 1000) | 0;

  return new jose.EncryptJWT(thingToEncrypt)
    .setProtectedHeader({
      alg: 'dir',
      enc: 'A256GCM',
      uat: epochNow,
      iat: epochNow,
      exp: epochNow + 7 * 24 * 60 * 60
    })
    .setIssuedAt(epochNow) // this is extra, added to the JWT payload
    .setExpirationTime(epochNow + 7 * 24 * 60 * 60)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dagda1
Comment options

Answer selected by dagda1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants