// https://datatracker.ietf.org/doc/html/rfc8292#section-2 // ECDSA on the NIST P-256 curve [FIPS186], which is identified as "ES256" [RFC7518]. const rawHeader = { typ: "JWT", alg: "ES256" }; const header = toBase64Url(new TextEncoder().encode(JSON.stringify(rawHeader)));
// https://datatracker.ietf.org/doc/html/rfc8292#section-2 const rawPayload = { // An "aud" (Audience) claim in the token MUST include the Unicode // serialization of the origin (Section 6.1 of [RFC6454]) of the push // resource URL.
aud: audience, // An "exp" (Expiry) claim MUST be included with the time after which // the token expires.
exp: parseInt(new Date().getTime() / 1000) + 24 * 60 * 60, // seconds, 24hr // The "sub" claim SHOULD include a contact URI for the application server as either a // "mailto:" (email) [RFC6068] or an "https:" [RFC2818] URI.
sub: "mailto:webpush@example.com",
}; const payload = toBase64Url(new TextEncoder().encode(JSON.stringify(rawPayload)));
async generateAuthHeader(audience) { // https://datatracker.ietf.org/doc/html/rfc8292#section-3.1 // The "t" parameter of the "vapid" authentication scheme carries a JWT // as described in Section 2. const t = await this.#jws(audience); // https://datatracker.ietf.org/doc/html/rfc8292#section-3.2 // The "k" parameter includes an ECDSA public key [FIPS186] in // uncompressed form [X9.62] that is encoded using base64url encoding // [RFC7515]. const k = toBase64Url(this.#publicKey) return `vapid t=${t},k=${k}`;
}
};
export async function createVapid() { // https://datatracker.ietf.org/doc/html/rfc8292#section-2 // The signature MUST use ECDSA on the NIST P-256 curve [FIPS186] const keys = await crypto.subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, ["sign"]); const publicKey = new Uint8Array(await crypto.subtle.exportKey("raw", keys.publicKey)); const privateKey = keys.privateKey; returnnew VAPID(publicKey, privateKey);
};
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.