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

@tuwaio/siwx-react

v0.2.3

Published

Layer 2 (L2) of the TUWA Ecosystem. React bindings for @tuwaio/siwx. Provides hooks and Zustand-powered session store for managing CAIP-122 authentication.

Downloads

3,254

Readme

@tuwaio/siwx-react

NPM Version License

React bindings for @tuwaio/siwx (L2). Provides a Zustand-powered session store and hooks for managing the full CAIP-122 authentication lifecycle — completely independent of any backend SDK.


🏛️ Core Capabilities

  • Session State Management: A zustand store (with immer + persist via sessionStorage) tracks the client-side authentication lifecycle: idle → building → signing → verifying → authenticated | error.
  • useSiwx() Hook: Orchestrates the sign-in flow: requests challenge nonce → builds CAIP-122 message → triggers wallet signer → verifies with backend → sets verified session.
  • useSiwxSession() Hook: Lightweight selector for reading the current authentication state and active account details in any component.
  • Satellite Helpers: Duck-typed integration helpers for @tuwaio/satellite-core connections.
  • Backend Agnostic: Works with any EVM or Solana signer (wagmi, viem, gill, Wallet Standard) and any backend endpoint.

Important: Client-side session state in Zustand reflects UI parity only. Server actions and API routes must never trust client-provided session state as proof of identity and must always verify the server-issued HttpOnly session cookie or authorization token.


💾 Installation

pnpm add @tuwaio/siwx-react @tuwaio/siwx-core zustand immer

🚀 API & Usage Examples

1. useSiwx() Hook

Orchestrates wallet signing and backend verification.

import { useSiwx } from '@tuwaio/siwx-react';
import { createEvmSiwxSigner } from '@tuwaio/siwx-evm';

function LoginButton({ walletClient, address }: { walletClient: any; address: string }) {
  const { signIn, signOut } = useSiwx();

  const handleLogin = async () => {
    await signIn({
      // 1. Chain-specific signer adapter
      signer: createEvmSiwxSigner(walletClient),

      // 2. Backend verifier calling your Next.js route handler
      verifier: async (payload) => {
        const res = await fetch('/api/siwx/verify', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify(payload),
        });
        return res.ok ? res.json() : null;
      },

      // 3. CAIP-122 message fields
      fields: {
        domain: window.location.host,
        address: `eip155:1:${address}`,
        uri: window.location.origin,
        chainId: 'eip155:1',
        statement: 'Sign in to TUWA.',
      },
    });
  };

  return <button onClick={handleLogin}>Sign In</button>;
}

2. useSiwxSession() Hook

Reads the authenticated user session in React components.

import { useSiwxSession } from '@tuwaio/siwx-react';

function UserProfile() {
  const { isAuthenticated, session, status, error } = useSiwxSession();

  if (status === 'signing' || status === 'verifying') {
    return <span>Authenticating...</span>;
  }

  if (!isAuthenticated || !session) {
    return <span>Not signed in</span>;
  }

  return (
    <div>
      <p>Address: {session.address}</p>
      <p>Chain ID: {session.chainId}</p>
    </div>
  );
}

3. useSiwxSessionStore

Direct store access for subscribing to specific state slices.

import { useSiwxSessionStore } from '@tuwaio/siwx-react';

// Subscribe to address slice
const address = useSiwxSessionStore((s) => s.session?.address);

🛰️ Satellite Connection Helpers

Integration helpers for applications using @tuwaio/satellite-core.

getSatelliteSiwxFields(activeConnection, options?)

Extracts normalized CAIP-10 and CAIP-2 identifiers directly from the active connection.

import { getSatelliteSiwxFields } from '@tuwaio/siwx-react';

const fields = getSatelliteSiwxFields(activeConnection, {
  statement: 'Sign in to TUWA.',
});

createSatelliteSiwxSigner(activeConnection)

Returns the standardized message signer callback from the active connection.

import { createSatelliteSiwxSigner } from '@tuwaio/siwx-react';

const signer = await createSatelliteSiwxSigner(activeConnection);

isSessionMatchingConnection(session, activeConnection)

Evaluates whether the active SIWX session matches the current wallet connection.

import { isSessionMatchingConnection } from '@tuwaio/siwx-react';

const isMatching = isSessionMatchingConnection(session, activeConnection);

🔄 Session Lifecycle

idle
 └─ signIn() called
     └─ building    (requesting challenge nonce & assembling fields)
         └─ signing     (wallet signing prompt)
             └─ verifying   (backend verification)
                 ├─ authenticated ✅ (session persisted to sessionStorage)
                 └─ error ❌ (error message recorded)

Peer Dependencies

| Package | Version | | ------------------- | ---------------------- | | @tuwaio/siwx-core | workspace:* | | react | ^19.0.0 | | zustand | ^5.0.0 | | immer | ^10.0.0 \|\| ^11.0.0 |


📄 License

Licensed under the Apache-2.0 License. See the LICENSE file for details.