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

passkeyme-web-sdk

v0.1.2

Published

Passkeys for everyone!

Downloads

6

Readme

alt text

Passkeyme Web SDK

Passkeyme Web SDK is a convenience SDK for the Passkeyme platform JavaScript/TypeScript library that provides simple functions to handle passkey registration and authentication using the WebAuthn API. This library helps you integrate passkey-based authentication into your web applications with ease.

See Passkeyme

Installation

You can install the Passkey SDK via npm:

npm install passkeyme-web-sdk

Usage

Importing the SDK

JavaScript

const PasskeySDK = require('passkeyme-web-sdk');

TypeScript

import PasskeySDK from 'passkeyme-web-sdk';

Creating an Instance

Create an instance of the PasskeySDK:

const sdk = new PasskeySDK();

Registering a Passkey

To register a passkey, use the passkeyRegister method. This method takes a challenge string as input and returns a promise that resolves to an object containing the credential.

sdk.passkeyRegister('challenge-from-passkeyme-API--start_registration')
    .then(response => {
        console.log('Registered credential:', response.credential);
        // Send to passkeyme-API complete_registration
    })
    .catch(error => {
        console.error('Registration error:', error);
    });

Authenticating with a Passkey

To authenticate using a passkey, use the passkeyAuthenticate method. This method takes a challenge string as input and returns a promise that resolves to an object containing the credential.

sdk.passkeyAuthenticate('challenge-from-passkeyme-API-start_authentication')
    .then(response => {
        console.log('Authenticated credential:', response.credential);
    })
    .catch(error => {
        console.error('Authentication error:', error);
        // Send to passkeyme-API complete_authentication
    });

API

passkeyRegister(challenge: string): Promise<{ credential: string }>

•	challenge: A string that represents the challenge provided by your server.
•	Returns: A promise that resolves to an object containing the credential.

passkeyAuthenticate(challenge: string): Promise<{ credential: string }>

•	challenge: A string that represents the challenge provided by your server.
•	Returns: A promise that resolves to an object containing the credential.

Example

Here is a full working example.

To get it working, first, go to Passkeyme, register, create an app and grab the AppID and API Key, and populate in your env as:

REACT_APP_PASSKEY_APP_ID=
REACT_APP_PASSKEY_API_KEY=

Then, create the app:

npx create-react-app passkeyme-react-demo
npm install passkeyme-web-sdk axios styled-components
npm start

You'll need to run it behind an addressible domain for Passkeys to work. You can host it, or use ngrok to serve it.

import React, { useState } from 'react';
import styled from 'styled-components';
import axios from 'axios';
import PasskeySDK from 'passkeyme-web-sdk';

const APP_ID = process.env.REACT_APP_PASSKEY_APP_ID;
const API_KEY = process.env.REACT_APP_PASSKEY_API_KEY;

const axiosInstance = axios.create({
  baseURL: `https://passkeyme.com/webauthn/${APP_ID}`,
  headers: {
    'x-api-key': API_KEY,
    'Content-Type': 'application/json'
  }
});

const App = () => {
    const [result, setResult] = useState(null);
    const [error, setError] = useState(null);
    const [username, setUsername] = useState('');
    const [displayName, setDisplayName] = useState('');

    const handleRegister = async () => {
        try {
            const start_response = await axiosInstance.post(`/start_registration`, { username, displayName });

            const { credential } = await PasskeySDK.passkeyRegister(start_response.data.challenge);

            const complete_response = await axiosInstance.post(`/complete_registration`, { username, credential });

            setResult(complete_response);
            setError(null);
        } catch (err) {
            setError(err.message);
            setResult(null);
        }
    };

    const handleAuthenticate = async () => {
        try {
          const start_response = await axiosInstance.post(`/start_authentication`,  { username });

            const { credential } = await PasskeySDK.passkeyAuthenticate(start_response.data.challenge);

            const complete_response = await axiosInstance.post(`/complete_authentication`, { username, credential });

            setResult(complete_response);
            setError(null);
        } catch (err) {
            setError(err.message);
            setResult(null);
        }
    };

    return (
        <Container>
            <h1>Passkey Demo</h1>
            <Input
                type="text"
                placeholder="Username"
                value={username}
                onChange={(e) => setUsername(e.target.value)}
                />
            <Input
                type="text"
                placeholder="Display Name"
                value={displayName}
                onChange={(e) => setDisplayName(e.target.value)}
                />

            <Button onClick={handleRegister}>Register</Button>
            <Button onClick={handleAuthenticate}>Authenticate</Button>
            {result && (
                <Result>
                    <h2>Result:</h2>
                    <pre>{result.data.message}</pre>
                </Result>
            )}
            {error && (
                <Result>
                    <h2>Error:</h2>
                    <pre>{error}</pre>
                </Result>
            )}
        </Container>
    );
};

const Container = styled.div`
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background-color: #f0f2f5;
    font-family: Arial, sans-serif;
`;

const Input = styled.input`
    padding: 10px;
    margin: 10px;
    font-size: 16px;
    border: 1px solid #ccc;
    border-radius: 5px;
`;

const Button = styled.button`
    padding: 10px 20px;
    margin: 10px;
    font-size: 16px;
    cursor: pointer;
    border: none;
    border-radius: 5px;
    background-color: #007BFF;
    color: white;
    transition: background-color 0.3s ease;

    &:hover {
        background-color: #0056b3;
    }
`;

const Result = styled.div`
    margin-top: 20px;
    padding: 10px;
    border-radius: 5px;
    background-color: #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
`;

export default App;```