|
1 | | -# Nostr Biometric Login Service |
| 1 | +# Nostr Biometric Authentication Utilities |
2 | 2 |
|
3 | | -A service that enables biometric step-up authentication for Nostr applications using WebAuthn. |
| 3 | +A comprehensive utility library for implementing biometric authentication in Nostr applications using WebAuthn. This library provides a flexible set of tools for adding secure biometric authentication to your Nostr-based applications. |
4 | 4 |
|
5 | 5 | ## Features |
6 | 6 |
|
7 | | -- WebAuthn-based biometric authentication |
8 | | -- Support for multiple domains (localhost, .local domains, IP addresses) |
9 | | -- Implementations in both TypeScript (Fastify) and JavaScript (Express) |
10 | | -- Full NIP-19 compliance for Nostr entity encoding/decoding |
11 | | -- Nostr profile fetching from multiple relays |
12 | | -- Comprehensive error handling for all operations |
13 | | -- Example implementations with both Fastify and Express |
| 7 | +- **WebAuthn Integration**: Ready-to-use utilities for implementing WebAuthn-based biometric authentication |
| 8 | +- **Platform Support**: |
| 9 | + - TouchID/FaceID for iOS and macOS |
| 10 | + - Windows Hello |
| 11 | + - Android biometric authentication |
| 12 | + - Security Key support |
| 13 | +- **Nostr-Specific Tools**: |
| 14 | + - Full NIP-19 compliance for entity encoding/decoding |
| 15 | + - Nostr profile integration |
| 16 | + - Direct message-based settings management |
| 17 | +- **Type Safety**: Comprehensive TypeScript support with strict typing |
| 18 | +- **Flexible Integration**: Can be used with any web framework or Nostr client |
| 19 | +- **Security First**: Built with security best practices and proper error handling |
| 20 | + |
| 21 | +## Installation |
14 | 22 |
|
15 | | -## Technical Details |
| 23 | +```bash |
| 24 | +npm install nostr-biometric-auth-utils |
| 25 | +``` |
16 | 26 |
|
17 | | -### Nostr Integration |
| 27 | +## Usage |
| 28 | + |
| 29 | +### Basic Authentication Flow |
| 30 | + |
| 31 | +```typescript |
| 32 | +import { NostrBiometricClient } from 'nostr-biometric-auth-utils'; |
| 33 | + |
| 34 | +const client = new NostrBiometricClient({ |
| 35 | + relays: ['wss://relay.damus.io'], |
| 36 | + magicLinkExpiry: 300, |
| 37 | + sessionDuration: 86400 |
| 38 | +}); |
| 39 | + |
| 40 | +// Start authentication for a user |
| 41 | +await client.startAuth('npub1...'); |
| 42 | + |
| 43 | +// Listen for state changes |
| 44 | +client.onStateChange((state) => { |
| 45 | + switch (state.step) { |
| 46 | + case 'WAITING_FOR_MAGIC_LINK': |
| 47 | + console.log('Please check your Nostr client for the magic link'); |
| 48 | + break; |
| 49 | + case 'STARTING_WEBAUTHN': |
| 50 | + console.log('Please complete biometric verification'); |
| 51 | + break; |
| 52 | + case 'COMPLETED': |
| 53 | + console.log('Authentication successful!'); |
| 54 | + break; |
| 55 | + } |
| 56 | +}); |
| 57 | +``` |
18 | 58 |
|
19 | | -The service implements full NIP-19 support for bech32-encoded entities: |
20 | | -- Automatic conversion between npub and hex formats |
21 | | -- Type-safe handling of all NIP-19 entity types |
22 | | -- Profile fetching from multiple Nostr relays |
23 | | -- Comprehensive error handling for malformed inputs |
24 | | -- Strong TypeScript types for all Nostr-related data structures |
| 59 | +### Settings Management |
25 | 60 |
|
26 | | -### Type Safety |
| 61 | +```typescript |
| 62 | +import { SettingsManager } from 'nostr-biometric-auth-utils'; |
27 | 63 |
|
28 | | -The project emphasizes type safety through: |
29 | | -- Strict TypeScript configuration in the Fastify example |
30 | | -- Comprehensive type definitions for all Nostr entities |
31 | | -- Type guards for runtime validation |
32 | | -- Proper error handling with typed error responses |
| 64 | +const settings = new SettingsManager(nostrService, userPubkey); |
33 | 65 |
|
34 | | -## Project Structure |
| 66 | +// Load user settings |
| 67 | +const currentSettings = await settings.loadSettings(); |
35 | 68 |
|
36 | | -``` |
37 | | -. |
38 | | -├── src/ # Core library source code |
39 | | -│ ├── client/ # Client-side implementation |
40 | | -│ ├── server/ # Server-side implementation |
41 | | -│ └── types/ # TypeScript type definitions |
42 | | -├── examples/ # Example implementations |
43 | | -│ ├── fastify-typescript/ # Fastify server example with TypeScript |
44 | | -│ └── express-javascript/ # Express server example with JavaScript |
45 | | -└── proof-of-concept/ # Initial POC implementation |
| 69 | +// Update settings |
| 70 | +await settings.updateSettings({ |
| 71 | + biometricEnabled: true, |
| 72 | + sessionDuration: 3600 |
| 73 | +}); |
46 | 74 | ``` |
47 | 75 |
|
48 | | -## Getting Started |
| 76 | +## Architecture |
49 | 77 |
|
50 | | -### Prerequisites |
| 78 | +The library is organized into several core modules: |
51 | 79 |
|
52 | | -- Node.js (v16 or later) |
53 | | -- npm (v7 or later) |
| 80 | +- **Client**: Main client-side implementation for managing authentication flow |
| 81 | +- **Core**: |
| 82 | + - WebAuthn implementation |
| 83 | + - TouchID/FaceID integration |
| 84 | + - Security key support |
| 85 | +- **Settings**: Nostr-based settings management |
| 86 | +- **Utils**: Helper functions for Nostr entity handling |
54 | 87 |
|
55 | | -### Installation |
56 | | - |
57 | | -```bash |
58 | | -npm install |
59 | | -``` |
| 88 | +## Security Considerations |
60 | 89 |
|
61 | | -### Running the Examples |
62 | | - |
63 | | -#### Fastify TypeScript Example |
64 | | - |
65 | | -1. Navigate to the Fastify example: |
66 | | - ```bash |
67 | | - cd examples/fastify-typescript |
68 | | - npm install |
69 | | - ``` |
70 | | -2. Add the following entries to your `/etc/hosts` file: |
71 | | - ``` |
72 | | - 127.0.0.1 localhost |
73 | | - 127.0.0.1 nostr-auth.localhost |
74 | | - ``` |
75 | | -3. Start the server: |
76 | | - ```bash |
77 | | - npm run dev |
78 | | - ``` |
79 | | -4. Visit https://nostr-auth.localhost:3000 in your browser |
80 | | - |
81 | | -#### Express JavaScript Example |
82 | | - |
83 | | -1. Navigate to the Express example: |
84 | | - ```bash |
85 | | - cd examples/express-javascript |
86 | | - npm install |
87 | | - ``` |
88 | | -2. Start the server: |
89 | | - ```bash |
90 | | - npm start |
91 | | - ``` |
92 | | -3. Visit http://localhost:3000 in your browser |
93 | | - |
94 | | -### Example Features |
95 | | - |
96 | | -Both examples demonstrate: |
97 | | -- WebAuthn registration and authentication |
98 | | -- Nostr profile fetching from relays |
99 | | -- NIP-19 npub handling |
100 | | -- Biometric authentication flow |
101 | | - |
102 | | -Key differences: |
103 | | -- Fastify example uses TypeScript for enhanced type safety |
104 | | -- Express example uses JavaScript for simplicity |
105 | | -- Fastify example supports multiple domains |
106 | | -- Express example focuses on localhost development |
107 | | - |
108 | | -## Development |
109 | | - |
110 | | -The Fastify example server supports multiple ways to access it: |
111 | | -- https://nostr-auth.localhost:3000 (recommended for development) |
112 | | -- https://your-hostname.local:3000 (for local network access) |
113 | | -- https://your-ip-address:3000 (for local network access) |
114 | | - |
115 | | -The Express example is configured for localhost development: |
116 | | -- http://localhost:3000 (default development setup) |
117 | | - |
118 | | -Note: When accessing via IP address or hostname in the Fastify example, the WebAuthn implementation will use 'localhost' as the relying party ID for security reasons. |
| 90 | +- All biometric data remains on the user's device |
| 91 | +- Implements FIDO2 WebAuthn specifications |
| 92 | +- Follows security best practices for key management |
| 93 | +- Proper error handling for all security-critical operations |
119 | 94 |
|
120 | 95 | ## Contributing |
121 | 96 |
|
122 | | -Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests. |
| 97 | +Contributions are welcome! Please read our contributing guidelines for details on our code of conduct and the process for submitting pull requests. |
123 | 98 |
|
124 | 99 | ## License |
125 | 100 |
|
126 | | -This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 101 | +This project is licensed under the MIT License - see the LICENSE file for details. |
127 | 102 |
|
128 | | -## Security |
| 103 | +## Related Projects |
129 | 104 |
|
130 | | -For security concerns, please read our [SECURITY.md](SECURITY.md) document. |
| 105 | +- [nostr-dm-magiclink-utils](https://github.com/HumanjavaEnterprises/nostr-dm-magiclink-utils) |
| 106 | +- [MaiQR Platform](https://github.com/HumanjavaEnterprises/MaiQR-Platform) |
0 commit comments