Socket
Socket
Sign inDemoInstall

@didtools/key-webauthn

Package Overview
Dependencies
40
Maintainers
7
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @didtools/key-webauthn

Implements support to authenticate, authorize and verify blocks produced by webauthn/passkey compatible hardware authenticators and OS/software implementations.


Version published
Maintainers
7
Install size
16.4 MB
Created

Readme

Source

Webauthn AuthMethod and Verifier

Implements support to authenticate, authorize and verify blocks produced by webauthn/passkey compatible hardware authenticators and OS/software implementations.

Installation

npm install --save @didtools/key-webauthn

Auth Usage

This module is designed to run in browser environments.

Create a Credential for first time use:

import { WebauthnAuth } from '@didtools/key-webauthn'

const did = await WebauthnAuth.createDid('app-user')

const authMethod = await WebauthnAuth.getAuthMethod({ did })
const session = await DIDSession.authorize(authMethod, { resources: ['ceramic://nil'] })

Verifier Usage

Verifiers are needed to verify different did:pkh signed payloads using CACAO. Libraries that need them will consume a verifiers map allowing your to register the verifiers you want to support.

import { Cacao } from '@didtools/cacao'
import { WebauthnAuth } from '@didtools/key-webauthn'
import { DID } from 'dids'

const verifiers = {
	...WebauthnAuth.getVerifier()
}

// Directly with cacao
Cacao.verify(cacao, { verifiers, ...opts})

// With DIDS, reference DIDS for more details
const dids = // configured dids instance
await dids.verifyJWS(jws, { capability, verifiers, ...opts})

Caveat: DID selection

The webauthn+fido2 standard was originally developed for use with databases and at that time a pesudo random CredentialID was preferred over the use of public keys.

The public key is exported only once when the credential is created - spec limitation. There are 3 options for getAuthMethod()

Option 1. Known DID
import { WebauthnAuth } from '@didtools/key-webauthn'

const authMethod = WebauthnAuth.getAuthMethod({ did: 'did:key:zDn...' })
Option 2. Probe

Probe the authenticator for public keys by asking user to sign a nonce:

import { WebauthnAuth } from '@didtools/key-webauthn'

const dids = await WebauthnAuth.probeDIDs()
const authMethod = WebauthnAuth.getAuthMethod({ dids })
Option 3. Callback

Use a callback with the following call signature:

(did1: string, did2: string) => Promise<string>

Example that probes on-demand:

import { WebauthnAuth } from '@didtools/key-webauthn'

const selectDIDs = async (did1, did2) {
    const dids = await WebauthnAuth.probeDIDs()
    if (dids.includes(did1)) return did1
    else return did2
}

const authMethod = WebauthnAuth.getAuthMethod({ selectDIDs })

Compatibility

Tests done via demo.

BrowserVersionOSDeviceAuthenticatorWorksRemark
Chrome107Mac OS 10.15.7DesktopYubikey v5 (USB-C)
Safari15.6Mac OS 10.15.7DesktopYubikey v5 (USB-C)
Safari15.6Mac OS 10.15.7DesktopOS-Authenticator
Brave119Mac OS 10.15.7Desktop1password
Mobile Safari16.6iOS 16.6MobileYubikey v5 (USB-C)
Mobile Safari16.6iOS 16.6MobileOS-Authenticator
Chrome122Windows 10DesktopYubikey v5
Chrome122Windows 10DesktopGPM+Android deviceTimeout
Firefox84Windows 10DesktopYubikey v5e1
Firefox120Windows 10DesktopYubikey v5
Chrome116LinuxDesktopYubikey v5
Firefox115LinuxDesktopYubikey v5
Chrome120Android 10MobileYubikey v5e2
Chrome120Android 10MobileOS-Authenticator
Firefox114Android 10MobileYubikey v5e2
Firefox114Android 10MobileOS-Authenticator

e1 - An attempt was made to use an object that is not, or is no longer available
e2 - OTG cable was used, when attempting NFC an error message was shown urging USB connection.

License

Apache-2.0 OR MIT

Keywords

FAQs

Last updated on 10 Apr 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc