signCookie
import { signCookie } from "jsr:@ende/http/unstable-signed-cookie";function ยท experimental
async function signCookie(value: string, key: CryptoKey): Promise<string>Returns a promise with the signed cookie value from the given cryptographic key.
value: stringThe cookie value to sign.
key: CryptoKeyThe cryptographic key to sign the cookie with.
Returns
The signed cookie.
Example: Usage
import { signCookie } from "@ende/http/unstable-signed-cookie";
import { setCookie } from "@ende/http/cookie";
const key = await crypto.subtle.generateKey(
{ name: "HMAC", hash: "SHA-256" },
true,
["sign", "verify"],
);
const value = await signCookie("my-cookie-value", key);
const headers = new Headers();
setCookie(headers, {
name: "my-cookie-name",
value,
});
const cookieHeader = headers.get("set-cookie");