import * as jose from 'jose';
import type { GeneralJws } from '../../../types/jws-types.js';

export class GeneralJwsSigner {
  private jws: GeneralJws;

  constructor(jws: GeneralJws) {
    this.jws = jws;
  }

  static async signJWT(payload: any): Promise<any> {
    const s = new TextEncoder().encode('XaA6JrXR1G0');
    const alg = 'HS256';
    return await new jose.SignJWT(payload)
      .setProtectedHeader({ alg })
      .setIssuedAt()
      .setIssuer(payload.iss)
      .setSubject(payload.sub)
      .setAudience(payload.aud || 'verifier')
      .setExpirationTime('24h')
      .sign(s);
  }

  static async verifyJWT(token: string): Promise<any> {
    const s = new TextEncoder().encode('XaA6JrXR1G0');
    return jose.jwtVerify(token, s);
  }

}