npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@valve-tech/auth-lite

v0.18.0

Published

SIWE-lite authentication for viem-based dapps. Server-issued nonce + client personal_sign + server recover, with the EIP-4361 fields a single-app product doesn't need (domain, URI, chainId, statement, expiry, resources) stripped out. Smaller spec, smaller

Downloads

365

Readme

@valve-tech/auth-lite

SIWE-lite authentication for viem-based dapps. Server-issued nonce → client personal_sign → server recover. Deliberately narrower than full EIP-4361 — see Why not full SIWE.

Pure functions. No nonce storage. No session token issuance. Pairs with @valve-tech/wallet-crypto if you also need wallet-derived encryption.

npm install @valve-tech/auth-lite viem

Why not full SIWE

EIP-4361's structured fields (Domain, URI, Chain ID, Statement, Resources, Issued At, Expiration) exist to defend against cross-site signature replay between unrelated dapps. If you're a single-app product, that threat model is overkill — a server-issued single-use nonce already covers replay. Stripping the optional fields gives you:

  • Smaller signed plaintext → cleaner wallet UI.
  • Simpler spec → easier to audit.
  • One signing template per app → no field-ordering footguns.

Use full SIWE when you need cross-app session portability (e.g. an attestation a third party can verify). For everything else, this package is the right call.

API

import {
  // Client
  signAuthChallenge,
  // Server
  generateAuthNonce,
  verifyAuthSignature,
  // Shared
  formatAuthMessage,
  AUTH_MESSAGE_TEMPLATE,
  // Errors
  WalletDeclined,
  WalletUnavailable,
  InvalidNonce,
  SignatureMismatch,
} from '@valve-tech/auth-lite'

Server: generateAuthNonce({ bytes?, ttlSeconds? })

const { nonce, expiresAt } = generateAuthNonce()
// nonce: base64url string (32 bytes / 43 chars by default)
// expiresAt: ms-epoch timestamp

Bounds: bytes ∈ [16, 64] (default 32), ttlSeconds ∈ [30, 3600] (default 300). The caller MUST persist the nonce in an issued-but- unused set and delete it on successful verify (single-use enforcement is the caller's responsibility — this package is stateless).

Server: verifyAuthSignature({ app, nonce, signature, claimedAddress })

const recovered = await verifyAuthSignature({
  app: 'Explore',
  nonce: storedNonce,
  signature: req.body.signature,
  claimedAddress: req.body.address,
})
if (!recovered) return res.status(401).end()

Returns the recovered Address on success, null on any failure (bad signature, address mismatch, malformed input). The single-null return prevents the verify endpoint from leaking which check failed to an attacker.

app MUST come from trusted server context — environment config, route handler constant, etc. Pulling it from the request body lets an attacker rebind a signature to a different app.

Client: signAuthChallenge({ signer, app, nonce })

const { address, signature, message } = await signAuthChallenge({
  signer: walletClient,
  app: 'Explore',
  nonce: serverNonce,
})
await fetch('/auth/verify', {
  method: 'POST',
  body: JSON.stringify({ address, signature, nonce: serverNonce }),
})

Throws:

  • InvalidNonce — nonce isn't base64url with ≥16 raw bytes.
  • WalletDeclined — user rejected the prompt.
  • WalletUnavailableWalletClient has no account.

Shared: formatAuthMessage({ app, nonce })

The exact plaintext both sides format. Exposed so consumers can preview it in their UI ("about to sign:" copy) and so test fixtures can use the same source of truth.

End-to-end

// --- server ---
import express from 'express'
import { generateAuthNonce, verifyAuthSignature } from '@valve-tech/auth-lite'

const nonces = new Map<string, { expiresAt: number }>() // dev only — use Redis in prod

app.get('/auth/nonce', (_req, res) => {
  const { nonce, expiresAt } = generateAuthNonce()
  nonces.set(nonce, { expiresAt })
  res.json({ nonce })
})

app.post('/auth/verify', async (req, res) => {
  const { nonce, signature, address } = req.body
  const stored = nonces.get(nonce)
  if (!stored || stored.expiresAt < Date.now()) return res.status(401).end()
  nonces.delete(nonce) // single-use

  const recovered = await verifyAuthSignature({
    app: 'Explore',
    nonce,
    signature,
    claimedAddress: address,
  })
  if (!recovered) return res.status(401).end()

  const sessionToken = issueSession(recovered) // your session lib
  res.json({ sessionToken })
})

// --- client ---
import { createWalletClient, custom } from 'viem'
import { mainnet } from 'viem/chains'
import { signAuthChallenge } from '@valve-tech/auth-lite'

const walletClient = createWalletClient({
  chain: mainnet,
  transport: custom(window.ethereum),
})

const { nonce } = await fetch('/auth/nonce').then(r => r.json())
const { address, signature } = await signAuthChallenge({
  signer: walletClient,
  app: 'Explore',
  nonce,
})
const { sessionToken } = await fetch('/auth/verify', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({ nonce, signature, address }),
}).then(r => r.json())

Errors

| Class | Side | When | |---|---|---| | WalletDeclined | Client | User rejected the wallet prompt. | | WalletUnavailable | Client | WalletClient has no account. | | InvalidNonce | Client | Nonce sanity-check failed (empty, too short, non-base64url). | | SignatureMismatch | Server | (reserved — currently verifyAuthSignature returns null instead of throwing this; export retained for future strict-mode option.) |

Pitfalls

  1. verifyAuthSignature does NOT check nonce single-use or expiry. That's your storage layer's job. Always:

    • Look the nonce up in your issued-but-unused store.
    • Check expiresAt > now.
    • Delete on success.
  2. app for verify MUST come from trusted server config, not the request body. Otherwise an attacker can take a signature for app: "real" and verify it as app: "real" while sending a body that claims app: "evil" — but this isn't the failure mode. The failure is: if you let request-body app flow to the verify call, you've lost cross-app rejection entirely.

  3. The nonce in this package is NOT the AES-GCM nonce from @valve-tech/wallet-crypto's envelope. Unrelated; same word. Don't pass one where the other is expected.

  4. Don't put the nonce in the URL. Nonces are sensitive (until consumed) and URLs land in server access logs. Put it in the response body for /auth/nonce and the request body for /auth/verify.

  5. Don't reuse a nonce across sessions. That's the entire point of single-use; if your store leaks an issued-but-unused nonce, an attacker who has a stale signature can replay it.

Composition

  • @valve-tech/wallet-crypto — pair when you need both auth and encrypted cloud sync. Shared WalletDeclined/WalletUnavailable class names mean you can catch (e) once.
  • @valve-tech/viem-errors — used internally for the WalletDeclined rejection detection. You don't need to import it directly.

License

MIT