Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@teamhanko/hanko-webauthn
Advanced tools
A wrapper for the WebAuthn API that adapts input/output values to plain JSON with base64url.
@teamhanko/hanko-webauthn
@teamhanko/hanko-webauthn
is a client-side Javascript library that serves as a wrapper for the
WebAuthn API by encoding binary data using
base64url (also known as "websafe" or "urlsafe" base64).
The WebAuthn API itself takes input and output values that look almost like JSON, except that binary data is represented
as ArrayBuffer
s. Using hanko-webauthn
allows the data to be sent from/to the server as normal JSON without any custom
client-side processing.
# Using npm
npm install --save @teamhanko/hanko-webauthn
# Using yarn
yarn add @teamhanko/hanko-webauthn
Alternatively, you can load the library via CDN using a script tag in your application <head>
:
<script src="https://cdn.jsdelivr.net/npm/@teamhanko/hanko-webauthn@latest/dist/browser-global/hanko-webauthn.browser-global.js"></script>
When using this method a browser global hankoWebAuthn
will be set.
// destructure global
const { create: createCredentials, get: getCredentials } = hankoWebAuthn;
// using the global directly
hankoWebAuthn.create();
The following are simple examples for performing registration and authentication using the SDK . For more information, refer to the Hanko API implementation guide.
import {create as createCredential} from "@teamhanko/hanko-webauthn"
// register credential for a given userName, which typically would be read from
// a registration form
async function register(userName) {
try {
const credentialCreationOptions = await initializeRegistration(userName);
const webAuthnResponse = await createCredential(credentialCreationOptions);
return await finalizeRegistration(webAuthnResponse)
} catch (error) {
// handle error
}
}
// retrieve credential creation options to pass to the WebAuthn API
async function initializeRegistration(userName) {
// adjust fetch URL to backend handler for retrieving
// credential creation options from FIDO server
const response = await fetch(`/webauthn/registration/initialize?user_name=${userName}`);
if (!response.ok) {
// handle fetch error
}
return response.json();
}
// verify WebAuthn response
async function finalizeRegistration(webAuthnResponse) {
// adjust fetch URL to backend handler for verifying
// WebAuthn response with FIDO server
const response = await fetch('/webauthn/registration/finalize', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(webAuthnResponse)
});
if (!response.ok) {
// handle fetch error
}
return response.json();
}
import {get as getCredential} from "@teamhanko/hanko-webauthn"
// authenticate with a credential for a given userName, which typically would be read from
// a login form
async function authenticate(userName) {
try {
const credentialRequestOptions = await initializeAuthentication(userName);
const credential = await getCredential(credentialRequestOptions);
return await finalizeAuthentication(credential)
} catch (error) {
// handle error
}
}
// retrieve credential request options to pass to the WebAuthn API
async function initializeAuthentication(userName) {
// adjust fetch URL to backend handler for retrieving
// credential request options from FIDO server
const response = await fetch(`/webauthn/authentication/initialize?user_name=${userName}`);
if (!response.ok) {
// handle fetch error
}
return response.json()
}
// verify WebAuthn response
async function finalizeAuthentication(webAuthnResponse) {
// adjust fetch URL to backend handler for verifying
// WebAuthn response with FIDO server
const response = await fetch("/webauthn/authentication/finalize", {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(webAuthnResponse)
});
if (!response.ok) {
// handle fetch error
}
return response.json();
}
function create(requestJSON: CredentialCreationOptionsJSON): Promise<PublicKeyCredentialWithAttestationJSON>;
function get(requestJSON: CredentialRequestOptionsJSON): Promise<PublicKeyCredentialWithAssertionJSON>;
function supported(): boolean;
function isUserVerifyingPlatformAuthenticatorAvailable: Promise<boolean>;
function isSecurityKeySupported(): Promise<boolean>;
create(requestJSON: CredentialCreationOptionsJSON): Promise<PublicKeyCredentialWithAttestationJSON>
:
requestJSON
:
CredentialCreationOptionsJSON
publicKey
:
signal
:
PublicKeyCredentialWithAttestationJSON
(a PublicKeyCredential representation, whose response
value is an AuthenticatorAttestationResponse)get(requestJSON: CredentialRequestOptionsJSON): Promise<PublicKeyCredentialWithAssertionJSON>
:
CredentialRequestOptionsJSON
publicKey
:
signal
:
PublicKeyCredentialWithAssertionJSON
(a PublicKeyCredential representation, whose response
value is an AuthenticatorAssertionResponse)supported(): boolean
:
isUserVerifyingPlatformAuthenticatorAvailable(): Promise<boolean>
:
isSecurityKeySupported(): Promise<boolean>
:
supported()
check in any other browser.@teamhanko/hanko-webauthn
is a fork of the @github/webauthn-json
library.
FAQs
A wrapper for the WebAuthn API that adapts input/output values to plain JSON with base64url.
The npm package @teamhanko/hanko-webauthn receives a total of 372 weekly downloads. As such, @teamhanko/hanko-webauthn popularity was classified as not popular.
We found that @teamhanko/hanko-webauthn demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.