@pushforge/builder
Version:
A robust, cross-platform Web Push notification library that handles VAPID authentication and payload encryption following the Web Push Protocol standard. Works in Node.js 16+, Browsers, Deno, Bun and Cloudflare Workers.
20 lines (19 loc) • 1 kB
TypeScript
import type { JwtData } from './types.js';
/**
* Creates a JSON Web Token (JWT) using the ECDSA algorithm.
*
* This function takes a JSON Web Key (JWK) and JWT data, encodes them,
* and signs the token using the specified algorithm and hash function.
*
* In the Web Push protocol, the VAPID JWT includes an `exp` (expiration) claim
* that specifies the token's validity period. According to the VAPID specification,
* the `exp` value must not exceed 24 hours from the time of the request. If it does,
* the push service (like FCM) will reject the request with a 403 Forbidden error.
*
* @param {JsonWebKey} jwk - The JSON Web Key used for signing the JWT.
* @param {JwtData} jwtData - The data to be included in the JWT payload.
* @returns {Promise<string>} A promise that resolves to the signed JWT as a string.
*
* @throws {Error} Throws an error if the key import or signing process fails.
*/
export declare const createJwt: (jwk: JsonWebKey, jwtData: JwtData) => Promise<string>;