export type EncryptedToken = {
  cipherText: ArrayBuffer;
  iv: Uint8Array<ArrayBuffer>;
};

export const encryptToken = async (
  token: string,
  key: CryptoKey,
): Promise<EncryptedToken> => {
  const encoder = new TextEncoder();
  const iv = crypto.getRandomValues(new Uint8Array(12));
  const cipherText = await crypto.subtle.encrypt(
    { name: "AES-GCM", iv },
    key,
    encoder.encode(token),
  );
  return { cipherText, iv };
};
