← All packages

@lacspace/signed-url

v1.0.2Backend Kit1 @lacspace dep

HMAC-signed, expiring URLs & tokens over Web Crypto — secure download links, magic-login links, unsubscribe links and one-time-action tokens. Tamper-proof, timing-safe, zero-config. Isomorphic (Node, edge, browser).

npm i @lacspace/signed-url

Usage

signed-url.ts
import { sign, verify } from "@lacspace/signed-url";

// e.g. a password-reset link
const token = await sign({ userId: 42, action: "reset" }, {
  secret: process.env.LINK_SECRET!,
  expiresIn: 3600, // seconds
});

const r = await verify<{ userId: number; action: string }>(token, { secret: process.env.LINK_SECRET! });
if (r.valid) {
  grantReset(r.data.userId);
} else {
  // r.reason → "malformed" | "bad-signature" | "expired"
}

Exports 7

isValidmagicLinkreadMagicLinksignsignUrlverifyverifyUrl

Keywords

signed-urlsigned-tokenhmacexpiring-urlpresigned-urlmagic-link

More in Backend Kit