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 🙏

© 2024 – Pkg Stats / Ryan Hefner

web-passkey

v1.0.0

Published

The WebPasskey library provides a simple interface for implementing WebAuthn passkey authentication in your web applications.

Downloads

15

Readme

WebPasskey Library

The WebPasskey library provides a simple interface for implementing WebAuthn passkey authentication in your web applications.

Installation

First, install the WebPasskey library via npm:

npm install web-passkey

Usage

Here is an example of how to use the usePasskey hook in your React application.

import { uuid } from "uuidv4"; // Import uuid for generating unique user IDs
import { usePasskey } from "web-passkey"; // Import usePasskey from the web-passkey library
import { PasskeyOptions } from "web-passkey/core/interface"; // Import PasskeyOptions interface

function App() {
  // Define the passkey configuration options
  const passkeyConfig: PasskeyOptions = {
    user: {
      id: uuid(), // Generate a unique ID for the user
      name: "John Doe", // User's name
      displayName: 'thecodeguyy', // User's display name
    },
    challenge: undefined, // Challenge for WebAuthn (can be undefined)
    type: "platform" // Type of authenticator
  }

  // Create a passkey instance using the configuration options
  const passkey = usePasskey(passkeyConfig);

  // Render a button that triggers the passkey authentication
  return (
    <div style={{
      display: "flex",
      placeItems: "center",
      justifyContent: "center",
      alignItems: "center",
      width: "100vw",
      height: "100vh"
    }}>
      <button onClick={async () => {
        const psk = await passkey(); // Trigger the passkey authentication
        console.log(psk); // Log the authentication result
      }} style={{
        padding: "15px 30px",
        backgroundColor: "#1E90FF",
        borderRadius: "5px",
        border: "none",
        cursor: "pointer",
        color: "#ffffff",
        fontFamily: "monospace"
      }}>
        Use Passkey
      </button>
    </div>
  )
}

export default App;

API

usePasskey(options: PasskeyOptions): () => Promise<Credential | null>

Creates a new passkey instance with the provided options.

Parameters:

  • options (PasskeyOptions): Configuration options for the passkey.

Returns:

  • A function that triggers the authentication process and returns a promise that resolves to a Credential object or null if authentication fails.

PasskeyOptions

An interface defining the configuration options for the passkey.

Properties:

  • user (object): User information.
    • id (string): Unique identifier for the user.
    • name (string): User's name.
    • displayName (string): User's display name.
  • challenge (Uint8Array | function | undefined): A challenge for the WebAuthn process. Can be undefined.
  • type (string): Type of authenticator ("platform" or "cross-platform").

Example

Here is a full example of how to integrate the usePasskey hook in a React component:

import { uuid } from "uuidv4";
import { usePasskey } from "web-passkey";
import { PasskeyOptions } from "web-passkey/core/interface";

function App() {
  const passkeyConfig: PasskeyOptions = {
    user: {
      id: uuid(),
      name: "John Doe",
      displayName: 'thecodeguyy',
    },
    challenge: undefined, // Challenge can be undefined
    type: "platform"
  }
  const passkey = usePasskey(passkeyConfig);
  
  return (
    <div style={{
      display: "flex",
      placeItems: "center",
      justifyContent: "center",
      alignItems: "center",
      width: "100vw",
      height: "100vh"
    }}>
      <button onClick={async () => {
        const psk = await passkey();
        console.log(psk);
      }} style={{
        padding: "15px 30px",
        backgroundColor: "#1E90FF",
        borderRadius: "5px",
        border: "none",
        cursor: "pointer",
        color: "#ffffff",
        fontFamily: "monospace"
      }}>
        Use Passkey
      </button>
    </div>
  )
}

export default App;

Notes

  • Ensure your application is served over HTTPS, as WebAuthn requires a secure context.
  • The challenge should be a randomly generated value unique to each authentication request. If challenge is undefined, the library will handle it appropriately.

For more detailed documentation and examples, please visit the WebPasskey GitHub repository.

Contribution

We welcome contributions to improve web-passkey. Feel free to submit pull requests for bug fixes, new features, or improved documentation.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author

Buy Me a Coffee

If you find this library helpful, consider buying me a coffee to support further development:

Buy me a coffee