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

@anders94/siwe

v1.0.0

Published

A lightweight Sign In With Ethereum TypeScript module.

Downloads

12

Readme

@anders94/siwe

A lightweight TypeScript implementation of Sign-In with Ethereum (EIP-4361).

Why this library?

Most SIWE implementations depend on heavy Ethereum libraries like ethers.js or viem. This library uses only @noble/secp256k1 and @noble/hashes for cryptographic operations, resulting in a much smaller bundle size for applications that don't need a full Ethereum library.

Installation

npm install @anders94/siwe

Usage

Creating a SIWE message

import { SiweMessage } from '@anders94/siwe';

const message = new SiweMessage({
  domain: 'myapp.com',
  address: '0x1234567890123456789012345678901234567890',
  statement: 'Sign in to My App',
  uri: 'https://myapp.com',
  version: '1',
  chainId: 1,
  nonce: 'randomNonce123',
  issuedAt: new Date().toISOString(),
  expirationTime: new Date(Date.now() + 3600000).toISOString(), // optional
  notBefore: new Date().toISOString(), // optional
  requestId: 'request-123', // optional
  resources: ['https://myapp.com/api'] // optional
});

// Get the message string to be signed
const messageString = message.prepareMessage();

Parsing a SIWE message

import { SiweMessage } from '@anders94/siwe';

const messageString = `myapp.com wants you to sign in with your Ethereum account:
0x1234567890123456789012345678901234567890

Sign in to My App

URI: https://myapp.com
Version: 1
Chain ID: 1
Nonce: randomNonce123
Issued At: 2024-01-01T00:00:00.000Z`;

const message = SiweMessage.fromString(messageString);

Validating a signature

import { SiweMessage } from '@anders94/siwe';

const message = new SiweMessage({
  domain: 'myapp.com',
  address: userAddress,
  uri: 'https://myapp.com',
  version: '1',
  chainId: 1,
  nonce: 'randomNonce123',
  issuedAt: new Date().toISOString()
});

try {
  // Validates signature and checks expiration/notBefore times
  await message.validate(signature);
  console.log('Signature valid!');
} catch (error) {
  console.error('Validation failed:', error.message);
}

Low-level signature verification

import { checkSignature } from '@anders94/siwe';

const isValid = await checkSignature(message, signature, expectedAddress);

API

SiweMessage

Constructor Options

| Property | Type | Required | Description | |----------|------|----------|-------------| | domain | string | Yes | The domain requesting the sign-in | | address | string | Yes | Ethereum address (0x-prefixed) | | uri | string | Yes | URI of the resource | | version | string | Yes | SIWE version (typically "1") | | chainId | number | Yes | EIP-155 chain ID | | nonce | string | Yes | Randomized token for replay protection | | issuedAt | string | Yes | ISO 8601 timestamp | | statement | string | No | Human-readable message | | expirationTime | string | No | ISO 8601 expiration time | | notBefore | string | No | ISO 8601 time before which message is invalid | | requestId | string | No | Request identifier | | resources | string[] | No | List of resource URIs |

Methods

  • prepareMessage(): string - Returns the EIP-4361 formatted message string
  • toMessage(): string - Alias for prepareMessage()
  • validate(signature: string): Promise<SiweMessage> - Validates signature and time constraints
  • static fromString(str: string): SiweMessage - Parses an EIP-4361 message string

checkSignature

function checkSignature(
  message: string,
  signature: string,
  expectedAddress: string
): Promise<boolean>

Low-level function to verify an Ethereum signature matches an expected address.

License

MIT