0.2.0 • Published 11 months ago

@hazelnutcloud/openauth-siwe v0.2.0

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

@hazelnutcloud/openauth-siwe

Sign-In with Ethereum (SIWE) provider for OpenAuth.

Features

  • Easy integration with OpenAuth
  • Built-in UI with wallet connection support
  • Support for injected wallets, Coinbase Wallet and WalletConnect
  • Customizable SIWE message parameters
  • Type-safe implementation using TypeScript

Installation

npm install @hazelnutcloud/openauth-siwe

Usage

import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";
import { SiweUi, SiweProvider } from "@openauthjs/openauth-siwe";
import { issuer } from "@openauthjs/openauth";

// Create a Viem public client
const client = createPublicClient({
  chain: mainnet,
  transport: http(),
});

// Use with OpenAuth
const app = issuer({
  providers: {
    siwe: SiweProvider(
      SiweUi({
        client,
        statement: "Sign in to My dApp",
        walletConnectProjectId: "your-project-id", // Optional
      })
    ),
  },
});

Configuration Options

SiweUiOptions

OptionTypeDescription
chainIdnumberChain ID of the target Ethereum network
clientPublicClientViem public client instance
statementstring?Optional statement to display in the SIWE message
resourcesstring[]?Optional list of resources to include in the SIWE message
walletConnectProjectIdstring?Optional WalletConnect project ID

Custom UI Implementation

You can also implement your own UI by using the SiweProvider directly:

const provider = SiweProvider({
  client,
  async signin(request, nonce) {
    // Return your custom signin page.
    return new Response("Custom signin page");
  },
});

License

MIT

0.2.0

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago