JavaScript & Typescript
Installation
To use our SDK add your environment token to your .env
file under HEX57_KEY
and run
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:
This client fully types and validates 0x57 responses using Valibot.
All actions will target the Environment associated with the token.
hex57.register(parameters): Promise<CreateAccountResponse>
: Creates a new account based on a challenge and WebAuthn credential. Returns the new Account.hex57.login(parameters): Promise<Account>
: Validates a WebAuthn credential and challenge with 0x57, and either throws an error or returns the validated Account to create a session for.hex57.getAccount(id: string)
: Retrieves a 0x57 Account.hex57.editAccount(id: string, parameters)
: Updates the username and email of an Account.