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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@uma-sdk/uma-auth-client

v0.0.10

Published

UMA Auth Client SDK for Web (Alpha)

Downloads

159

Readme

uma-auth-client

The UMA Auth Client SDK for web apps!

Installation

npm install @uma-sdk/uma-auth-client

or

yarn add @uma-sdk/uma-auth-client

Quick Start

See the full UMA Auth documentation here.

Connecting

The UMA Auth Client SDK helps you connect users' UMA wallets to your web app. Here's how you can get started.

First, generate a keypair and publish info about your app.

Next, add the connect button to your app and provide the pubkey you generated.

In React, you can use the UmaConnectButton element:

import { UmaConnectButton } from '@uma-sdk/uma-auth-client';

const App = () => {
  return (
    <UmaConnectButton
      app-identity-pubkey="npub1scmpzl2ehnrtnhu289d9rfrwprau9z6ka0pmuhz6czj2ae5rpuhs2l4j9d"
      nostr-relay="wss://nos.lol"
      redirect-uri="http://localhost:3001"
      required-commands={["pay_invoice", "get_balance"]}
      optional-commands={["list_transactions"]}
      budget-amount="500"
      budget-currency="USD"
      budget-period="monthly"
      style={{
        "--uma-connect-background": "#7366C5",
        "--uma-connect-radius": "8px",
        "--uma-connect-padding-x": "32px",
        "--uma-connect-padding-y": "16px",
        "--uma-connect-text-color": "#F9F9F9",
        "--uma-connect-font-family": "Arial",
        "--uma-connect-font-size": "16px",
        "--uma-connect-font-weight": "600",
      }}
    />
  );
};

Alternatively, in raw HTML or a non-react context, you can use the web component implementation:

<!-- TODO: Host the cjs package in a public CDN. -->
<script src="../../packages/uma-auth-client/dist/uma-auth-client-web-components.umd.cjs"></script>
<uma-connect-button
  app-identity-pubkey="npub1scmpzl2ehnrtnhu289d9rfrwprau9z6ka0pmuhz6czj2ae5rpuhs2l4j9d"
  nostr-relay="wss://nos.lol"
  redirect-uri="http://localhost:3001"
  required-commands="pay_invoice,get_balance"
  optional-commands="list_transactions"
  budget-amount="500"
  budget-currency="USD"
  budget-period="monthly"
/>

Users can click their button to move through the flow to connect their wallet. Note that like a normal OAuth flow, the user will be redirected to their wallet app to sign in, so make sure that you persist important state if needed for when you're redirected back to the redirect-uri.

Upon successful connection, connect button element will automatically exchange the authorization code for an access token.

If you don't have a connect button element on your redirect page, you can manually complete the exchange using the react hook useOAuth:

const oAuth = useOAuth();

useEffect(() => {
  if (oAuth.codeVerifier) {
    oAuth.oAuthTokenExchange().then((res) => {
      console.log(res);
    });
  }
}, [oAuth.codeVerifier]);

const isConnectionValid = oAuth.isConnectionValid();
const nwcConnectionUri = oAuth.nwcConnectionUri;

if (isConnectionValid) {
  return <div>Connected!</div>;
}

In non-react contexts, you can still use useOAuth to complete the token exchange:

const oAuth = useOAuth.getState();
if (oAuth.codeVerifier) {
  oAuth.oAuthTokenExchange().then((res) => {
    const isConnectionValid = oAuth.isConnectionValid();
    const nwcConnectionUri = oAuth.nwcConnectionUri;

    if (isConnectionValid) {
      return console.log("Connected!", res);
    }
  });
}

Sending requests

Once you have a valid access token, you can use the react hook useNwcRequester to send requests to the user's wallet.

const { nwcRequester } = useNwcRequester();
const [balance, setBalance] = useState<
  Nip47.GetBalanceResponse | undefined
>();

useEffect(() => {
  async function fetchBalance(nwcRequester: NwcRequester) {
    const res = await nwcRequester.getBalance();
    setBalance(res);
  }
  if (nwcRequester) {
    fetchBalance(nwcRequester);
  }
}, [nwcRequester]);

In non-react contexts, you can use the NwcRequester class directly.

let requester: NwcRequester | null = null;
useOAuth.subscribe((oAuth) => {
  if (oAuth.isConnectionValid() && oAuth.nwcConnectionUri && !requester) {
    requester = new NwcRequester(oAuth.nwcConnectionUri, oAuth.clearUserAuth, oAuth.oAuthTokenExchange);
    requester.getBalance().then((res) => {
      console.log("Balance:", res);
    });
  }
});

If provided a token exchange handler, the NwcRequester will also handle refreshing tokens in case the access token expires (e.g. oAuthTokenExchange).

If you need to send requests from your backend, you should send all the full token response info to your backend and utilize any NWC library with the nwcConnectUri, refreshing the URI with the refreshToken as needed.