How iamevanyt/electron-webauthn-native works
Project type and purpose
• This is a native Node/Electron library (NPM package) that provides WebAuthn/Passkey support by binding into Rust code via NAPI-RS.
• It targets Electron apps on macOS, Windows, and Linux and leverages platform-specific authentication APIs (Touch ID, Face ID, Windows Hello, etc.).
File structure
• Top-level “index.js”/“index.d.ts” : the JavaScript/TypeScript entry point and type definitions.
• “src/lib.rs” + “src/platform/*.rs” : Rust core logic and per-OS modules.
• “build.rs” & Cargo.toml : Rust build script and configuration.
• “npm/<platform>/…” folders : prebuilt native binaries for each OS/arch.
• CI/CD files (.github/workflows/CI.yml) and release config (.cargo/config.toml, yarnrc).
• Test folder: __test__/webauthn-flow.spec.mjs
README for additional insights
• Confirms use of NAPI-RS to expose Rust functions as async JS functions: createCredential() and getCredential().
• Specifies platform APIs: ASAuthorization (macOS), Windows Hello, generic Linux WebAuthn.
• Describes build & packaging with electron-builder and prebuilt binaries for multiple targets.
Main components and their interactions
a. Electron Application (Consumer)
– Calls JS API: createCredential(), getCredential()
b. JS / TypeScript Wrapper
– index.js exports functions
– index.d.ts provides types
– Uses NAPI-RS under the hood to call into native Rust
c. NAPI-RS Binding Layer
– Auto-generated glue that converts JS calls into Rust FFI calls
d. Rust Core Library (lib.rs)
– Implements WebAuthn logic, orchestrates platform modules, marshals data
e. Platform Modules (macos.rs, windows via cfg, linux generic in unknown.rs)
– Each module invokes the respective OS’s native authenticator APIs
f. Native OS Authenticator APIs
– macOS: ASAuthorization framework, Secure Enclave
– Windows: Windows Hello APIs
– Linux: libfido2 or generic WebAuthn libraries
g. Hardware Backends
– Touch ID sensor, Face ID, security keys, Apple Watch, TPM, etc.
h. Packaging / CI / Distribution
– build.rs and Cargo.toml compile the Rust code
– CI workflow builds & publishes per-platform binaries under npm/…
– electron-builder entitlements and packaging
Architectural patterns and principles
• Layered design: JS layer → NAPI layer → Rust core → platform modules → native APIs
• Plug-in style for platform modules using Rust’s conditional compilation (cfg)
• Single responsibility: each module handles one platform’s specifics
• Pre-build artifacts: provides zero-install binaries for every target