Skip to content

Commit 3793053

Browse files
committed
feat: refactor for npm package release
- Added ESLint configuration and ignore files - Added npm ignore file - Created NostrService interface and implementation - Added security key and TouchID core modules - Added CommonJS build configuration - Added basic test suite - Updated dependencies and build scripts
1 parent 2d7ad6e commit 3793053

17 files changed

Lines changed: 1147 additions & 1779 deletions

File tree

.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dist/
2+
node_modules/
3+
coverage/
4+
*.js
5+
*.d.ts

.eslintrc.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true
6+
},
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/recommended"
10+
],
11+
"parser": "@typescript-eslint/parser",
12+
"parserOptions": {
13+
"ecmaVersion": "latest",
14+
"sourceType": "module"
15+
},
16+
"plugins": [
17+
"@typescript-eslint"
18+
],
19+
"rules": {
20+
"@typescript-eslint/no-explicit-any": "off",
21+
"@typescript-eslint/explicit-function-return-type": "off",
22+
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
23+
"no-console": ["warn", { "allow": ["warn", "error"] }]
24+
}
25+
}

.npmignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Source
2+
src/
3+
4+
# Examples
5+
examples/
6+
7+
# Development files
8+
.github/
9+
.vscode/
10+
.idea/
11+
.git/
12+
.gitignore
13+
.eslintrc.js
14+
.eslintignore
15+
.prettierrc
16+
.prettierignore
17+
18+
# Test files
19+
__tests__/
20+
*.test.ts
21+
*.spec.ts
22+
23+
# Documentation
24+
docs/
25+
*.md
26+
!README.md
27+
28+
# Build artifacts
29+
*.log
30+
*.tsbuildinfo
31+
32+
# Certificates and keys
33+
*.pem
34+
*.key
35+
*.crt
36+
37+
# Development configs
38+
tsconfig.json
39+
tsconfig.cjs.json
40+
.env*

README.md

Lines changed: 81 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,106 @@
1-
# Nostr Biometric Login Service
1+
# Nostr Biometric Authentication Utilities
22

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.
44

55
## Features
66

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
1422

15-
## Technical Details
23+
```bash
24+
npm install nostr-biometric-auth-utils
25+
```
1626

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+
```
1858

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
2560

26-
### Type Safety
61+
```typescript
62+
import { SettingsManager } from 'nostr-biometric-auth-utils';
2763

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);
3365

34-
## Project Structure
66+
// Load user settings
67+
const currentSettings = await settings.loadSettings();
3568

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+
});
4674
```
4775

48-
## Getting Started
76+
## Architecture
4977

50-
### Prerequisites
78+
The library is organized into several core modules:
5179

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
5487

55-
### Installation
56-
57-
```bash
58-
npm install
59-
```
88+
## Security Considerations
6089

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
11994

12095
## Contributing
12196

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.
12398

12499
## License
125100

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.
127102

128-
## Security
103+
## Related Projects
129104

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

Comments
 (0)