JavaScript & Typescript

Installation

To use our SDK add your environment token to your .env file under HEX57_KEY and run

npm install @0x57/passkey

Usage

Frontend

isWebAuthnAvailable(): Promise<boolean>

WebAuthn is not available everywhere. You can use this function to gracefully degrade on browsers where it is not available.

createCredential

WebAuthn credentials are not JSON serializable by default. Calling this function will handle the hard part of asking the browser to create a new WebAuthn credential and then transforming it into a serializable format.

This should be used to register new users.

getCredential

Similar to the register process, when you want to retrieve a previously created WebAuthn credential the response is not seriablizable by default. Calling this function will retrieve the WebAuthn credential and then transform it into a serializable format.

This should be used to sign users back in.

Backend

generateChallenge(): string

WebAuthn requires server-validated challenges to work properly. This method will generate a cryptographically random byte sequence to use on the front-end and to validate subsequent credentials with.

class PasskeyClient

The PasskeyClient class provides a helpful wrapper around our API. To use it, create a file named lib/0x57.ts or similar:

import { PasskeyClient } from "@0x57/passkey";
 
const hex57 = new PasskeyClient(process.env.HEX57_KEY!, {
	rpid: "localhost",
	origin: "http://localhost:3000",
});
 
export default hex57;

This client fully types and validates 0x57 responses using Valibot.

All actions will target the Environment associated with the token.