Skip to content

Commit 04f66c6

Browse files
vveerrggclaude
andcommitted
docs: polish README, CHANGELOG, package metadata, and add doc stubs
Fix broken doc links, add keywords/repository/homepage/bugs to package.json, remove COLAB-DOCS from files, fix CHANGELOG date order and add v0.3.0-0.3.5 entries, create CODE_OF_CONDUCT and doc stubs for getting-started, API, security, and TypeScript guides. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 287e23e commit 04f66c6

8 files changed

Lines changed: 491 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
## [0.3.5] - 2025-02-19
11+
12+
### Changed
13+
- Updated dependencies to latest within major versions
14+
815
## [0.3.4] - 2025-02-09
916

1017
### Added
@@ -16,22 +23,44 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1623
- Enhanced browser compatibility checks
1724
- Better error messages for session-related operations
1825

19-
## [0.2.6] - 2023-12-05
26+
## [0.3.3] - 2025-02-01
27+
28+
### Added
29+
- JWT secret validation at startup
30+
31+
## [0.3.2] - 2025-01-25
32+
33+
### Added
34+
- Comprehensive JWT configuration and browser compatibility documentation
35+
36+
## [0.3.1] - 2025-01-20
37+
38+
### Changed
39+
- Included documentation in npm package
40+
41+
## [0.3.0] - 2025-01-15
42+
43+
### Changed
44+
- Major codebase improvements and documentation updates
45+
- Removed Node.js 16.x support, upgraded GitHub Actions to v4
46+
- Prepared for npm publish
47+
48+
## [0.2.6] - 2024-01-09
2049

2150
### Added
2251
- New TypeScript interfaces in `interfaces/nostr.interface.ts` for better type safety
2352
- More comprehensive event validation with detailed error messages
2453

25-
### Enhanced
54+
### Changed
2655
- Improved event validation with stricter type checking
2756
- Better error handling and logging in event validator
2857
- Updated to use latest crypto utilities
2958

30-
## [0.2.5] - 2024-01-09
59+
## [0.2.5] - 2023-12-08
3160

3261
### Changed
33-
- Updated to use published versions of @humanjavaenterprises/nostr-crypto-utils@0.2.0 and @humanjavaenterprises/nostr-nsec-seedphrase-library@0.2.0
34-
- Updated key generation to use new generateKeyPairWithSeed function from nostr-nsec-seedphrase-library
62+
- Updated to use published versions of nostr-crypto-utils and nostr-nsec-seedphrase
63+
- Updated key generation to use new generateKeyPairWithSeed function
3564

3665
## [0.2.3] - 2023-12-06
3766

@@ -48,7 +77,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4877
- Improved error handling in middleware
4978
- Enhanced TypeScript type safety
5079

51-
## [0.2.2] - Previous Release
80+
## [0.2.2] - 2023-12-01
5281

5382
### Added
5483
- Initial implementation of Nostr authentication middleware

CODE_OF_CONDUCT.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our
6+
community a harassment-free experience for everyone, regardless of age, body
7+
size, visible or invisible disability, ethnicity, sex characteristics, gender
8+
identity and expression, level of experience, education, socio-economic status,
9+
nationality, personal appearance, race, religion, or sexual identity
10+
and orientation.
11+
12+
We pledge to act and interact in ways that contribute to an open, welcoming,
13+
diverse, inclusive, and healthy community.
14+
15+
## Our Standards
16+
17+
Examples of behavior that contributes to a positive environment for our
18+
community include:
19+
20+
* Demonstrating empathy and kindness toward other people
21+
* Being respectful of differing opinions, viewpoints, and experiences
22+
* Giving and gracefully accepting constructive feedback
23+
* Accepting responsibility and apologizing to those affected by our mistakes,
24+
and learning from the experience
25+
* Focusing on what is best not just for us as individuals, but for the
26+
overall community
27+
28+
Examples of unacceptable behavior include:
29+
30+
* The use of sexualized language or imagery, and sexual attention or
31+
advances of any kind
32+
* Trolling, insulting or derogatory comments, and personal or political attacks
33+
* Public or private harassment
34+
* Publishing others' private information, such as a physical or email
35+
address, without their explicit permission
36+
* Other conduct which could reasonably be considered inappropriate in a
37+
professional setting
38+
39+
## Enforcement Responsibilities
40+
41+
Community leaders are responsible for clarifying and enforcing our standards of
42+
acceptable behavior and will take appropriate and fair corrective action in
43+
response to any behavior that they deem inappropriate, threatening, offensive,
44+
or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies within all community spaces, and also applies when
49+
an individual is officially representing the community in public spaces.
50+
51+
## Enforcement
52+
53+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
54+
reported to the community leaders responsible for enforcement at
55+
[conduct@humanjavaenterprises.org](mailto:conduct@humanjavaenterprises.org).
56+
All complaints will be reviewed and investigated promptly and fairly.
57+
58+
## Enforcement Guidelines
59+
60+
Community leaders will follow these Community Impact Guidelines in determining
61+
the consequences for any action they deem in violation of this Code of Conduct:
62+
63+
### 1. Correction
64+
65+
**Community Impact**: Use of inappropriate language or other behavior deemed
66+
unprofessional or unwelcome in the community.
67+
68+
**Consequence**: A private, written warning from community leaders, providing
69+
clarity around the nature of the violation and an explanation of why the
70+
behavior was inappropriate. A public apology may be requested.
71+
72+
### 2. Warning
73+
74+
**Community Impact**: A violation through a single incident or series
75+
of actions.
76+
77+
**Consequence**: A warning with consequences for continued behavior. No
78+
interaction with the people involved, including unsolicited interaction with
79+
those enforcing the Code of Conduct, for a specified period of time. This
80+
includes avoiding interactions in community spaces as well as external channels
81+
like social media. Violating these terms may lead to a temporary or
82+
permanent ban.
83+
84+
### 3. Temporary Ban
85+
86+
**Community Impact**: A serious violation of community standards, including
87+
sustained inappropriate behavior.
88+
89+
**Consequence**: A temporary ban from any sort of interaction or public
90+
communication with the community for a specified period of time. No public or
91+
private interaction with the people involved, including unsolicited interaction
92+
with those enforcing the Code of Conduct, is allowed during this period.
93+
Violating these terms may lead to a permanent ban.
94+
95+
### 4. Permanent Ban
96+
97+
**Community Impact**: Demonstrating a pattern of violation of community
98+
standards, including sustained inappropriate behavior, harassment of an
99+
individual, or aggression toward or disparagement of classes of individuals.
100+
101+
**Consequence**: A permanent ban from any sort of public interaction within
102+
the community.
103+
104+
## Attribution
105+
106+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
107+
version 2.0, available at
108+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
109+
110+
[homepage]: https://www.contributor-covenant.org

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,10 @@ Profile Cache Cleared: { pubkey }
197197

198198
## Documentation
199199

200-
- [Architecture Guide](docs/architecture-guide.md) - Understanding the service architecture
201-
- [Key Management Guide](docs/key-management.md) - Comprehensive key management documentation
202-
- [Deployment Guide](docs/deployment-guide.md) - Environment-specific deployment instructions
203200
- [Getting Started](docs/getting-started.md) - Quick start guide
204-
- [Authentication Flow](docs/authentication-flow.md) - Detailed authentication process
205-
- [Troubleshooting Guide](docs/troubleshooting.md) - Common issues and solutions
206201
- [API Documentation](docs/api.md) - API endpoints and usage
207-
- [Security Guide](docs/security.md) - Security best practices and considerations
208-
- [Automated Tests](docs/automated-tests.md) - Comprehensive test suite documentation
202+
- [Security Guide](docs/security.md) - Security best practices and key management
209203
- [TypeScript Guide](docs/typescript.md) - TypeScript declaration patterns and best practices
210-
- [Browser Authentication](docs/browser-authentication.md) - Browser-based authentication flow
211204

212205
### TypeScript Declaration Pattern
213206

docs/api.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# API Reference
2+
3+
## NostrAuthMiddleware
4+
5+
The main class for Nostr authentication.
6+
7+
### Constructor
8+
9+
```typescript
10+
new NostrAuthMiddleware(options: NostrAuthOptions)
11+
```
12+
13+
#### Options
14+
15+
| Option | Type | Default | Description |
16+
|--------|------|---------|-------------|
17+
| `jwtSecret` | `string` || Secret for JWT signing (required in production) |
18+
| `expiresIn` | `string` | `'24h'` | JWT token expiration time |
19+
20+
### Methods
21+
22+
#### `generateToken(payload)`
23+
24+
Generates a JWT token with minimal claims.
25+
26+
```typescript
27+
const token = await auth.generateToken({ pubkey: 'npub1...' });
28+
```
29+
30+
**Returns:** `Promise<string>` — The signed JWT token containing `pubkey`, `iat`, and `exp` claims.
31+
32+
#### `verifyToken(token)`
33+
34+
Verifies a JWT token.
35+
36+
```typescript
37+
const isValid = await auth.verifyToken(token);
38+
```
39+
40+
**Returns:** `Promise<boolean>`
41+
42+
#### `verifySession(pubkey)`
43+
44+
Verifies if a user's session is still valid.
45+
46+
```typescript
47+
const isValid = await auth.verifySession(userPubkey);
48+
```
49+
50+
**Returns:** `Promise<boolean>`
51+
52+
#### `authenticate()`
53+
54+
Returns Express middleware that authenticates requests using Nostr.
55+
56+
```typescript
57+
app.get('/protected', auth.authenticate(), handler);
58+
```
59+
60+
## NostrBrowserAuth
61+
62+
Lightweight browser-based authentication using NIP-07.
63+
64+
### Constructor
65+
66+
```typescript
67+
new NostrBrowserAuth(options?: BrowserAuthOptions)
68+
```
69+
70+
#### Options
71+
72+
| Option | Type | Default | Description |
73+
|--------|------|---------|-------------|
74+
| `customKind` | `number` | `22242` | Custom event kind for auth |
75+
| `timeout` | `number` | `30000` | Timeout in milliseconds |
76+
77+
### Methods
78+
79+
#### `getPublicKey()`
80+
81+
Gets the user's public key from their Nostr extension.
82+
83+
```typescript
84+
const publicKey = await auth.getPublicKey();
85+
```
86+
87+
#### `signChallenge()`
88+
89+
Signs an authentication challenge.
90+
91+
```typescript
92+
const challenge = await auth.signChallenge();
93+
```
94+
95+
#### `validateSession(session)`
96+
97+
Validates an existing session.
98+
99+
```typescript
100+
const isValid = await auth.validateSession(session);
101+
```

docs/getting-started.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Getting Started
2+
3+
## Prerequisites
4+
5+
- Node.js >= 18.0.0
6+
- npm >= 7.0.0
7+
8+
## Installation
9+
10+
```bash
11+
npm install nostr-auth-middleware
12+
```
13+
14+
## Basic Setup
15+
16+
### ESM (Recommended)
17+
18+
```typescript
19+
import { NostrAuthMiddleware } from 'nostr-auth-middleware';
20+
21+
const auth = new NostrAuthMiddleware({
22+
jwtSecret: process.env.JWT_SECRET,
23+
expiresIn: '24h',
24+
});
25+
```
26+
27+
### CommonJS
28+
29+
```javascript
30+
const { NostrAuthMiddleware } = require('nostr-auth-middleware');
31+
32+
const auth = new NostrAuthMiddleware({
33+
jwtSecret: process.env.JWT_SECRET,
34+
expiresIn: '24h',
35+
});
36+
```
37+
38+
## Express Integration
39+
40+
```typescript
41+
import express from 'express';
42+
import { NostrAuthMiddleware } from 'nostr-auth-middleware';
43+
44+
const app = express();
45+
app.use(express.json());
46+
47+
const auth = new NostrAuthMiddleware({
48+
jwtSecret: process.env.JWT_SECRET,
49+
});
50+
51+
// Protect routes with Nostr authentication
52+
app.get('/protected', auth.authenticate(), (req, res) => {
53+
res.json({ message: 'Authenticated!', pubkey: req.pubkey });
54+
});
55+
56+
app.listen(3000);
57+
```
58+
59+
## Environment Variables
60+
61+
| Variable | Required | Description |
62+
|----------|----------|-------------|
63+
| `JWT_SECRET` | Production | Secret key for signing JWTs |
64+
| `NODE_ENV` | No | Set to `production` for production mode |
65+
66+
In development mode, a default secret is used if `JWT_SECRET` is not provided. **Never use the default secret in production.**
67+
68+
## Next Steps
69+
70+
- [API Documentation](api.md) — Full API reference
71+
- [Security Guide](security.md) — Key management and security best practices
72+
- [TypeScript Guide](typescript.md) — TypeScript patterns and declarations

0 commit comments

Comments
 (0)