A lightweight TypeScript library that implements WebAuthn with PRF (Pseudo-Random Function) for secure authentication and encryption. This package allows users to register, authenticate, and encrypt/decrypt messages using derived keys.
Install the package using npm:
# npm install webauthn-prf-example
To register a new user, call the handleRegister
function:
// import { handleRegister } from "webauthn-prf-example";
document.getElementById("registerBtn").addEventListener("click", async () => {
await handleRegister();
});
To authenticate an existing user, call the handleAuthenticate
function:
// import { handleAuthenticate } from "webauthn-prf-example";
document
.getElementById("authenticateBtn")
.addEventListener("click", async () => {
await handleAuthenticate();
});
To save and retrieve encrypted messages, use the saveMessage
and loadMessages
functions:
// import { saveMessage } from "webauthn-prf-example";
document
.getElementById("saveMessageBtn")
.addEventListener("click", async () => {
await saveMessage();
});
To log out and clear stored credentials and messages, use the handleLogout
function:
// import { handleLogout } from "webauthn-prf-example";
document.getElementById("logoutBtn").addEventListener("click", async () => {
await handleLogout();
});
Registers a new user with WebAuthn and securely stores authentication credentials.
Authenticates a registered user using WebAuthn credentials.
Encrypts and saves a message using the derived encryption key.
Loads and decrypts saved messages.
Clears stored credentials and messages, effectively logging out the user.
For more details, check out the official WebAuthn documentation: MDN WebAuthn Docs.