Skip to content

Commit 885e04e

Browse files
committed
Update JSDoc and remove Jest references for Vitest compatibility
### Version 0.5.0 Changes: - Added hardcoded test keys for `nsec` and `npub` for deterministic testing with warnings about their usage. - Moved test key constants inside mock functions to avoid hoisting issues with Vitest. - Added a new test section for randomly generated keys to validate library functions with dynamic data. - Updated mocks for `@noble/secp256k1` and `bech32` to use new test key constants. - Documented version 0.5.0 in the README under Recent Updates. - Enhanced test coverage for both static and dynamic key scenarios.
1 parent 82dc31d commit 885e04e

18 files changed

+2735
-225
lines changed

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,33 @@ const event = await createEvent(
142142
const isValidEvent = await verifyEvent(event);
143143
```
144144

145+
## Key Management Functions
146+
147+
### Public Key Generation
148+
```typescript
149+
import { getPublicKey } from 'nostr-nsec-seedphrase';
150+
151+
// Generate public key from private key
152+
const pubkey = getPublicKey(privateKeyHex);
153+
```
154+
155+
### NIP-19 Encoding/Decoding
156+
```typescript
157+
import { nip19 } from 'nostr-nsec-seedphrase';
158+
159+
// Encode/decode public keys (npub)
160+
const npub = nip19.npubEncode(pubkeyHex);
161+
const pubkey = nip19.npubDecode(npub);
162+
163+
// Encode/decode private keys (nsec)
164+
const nsec = nip19.nsecEncode(privkeyHex);
165+
const privkey = nip19.nsecDecode(nsec);
166+
167+
// Encode/decode event IDs (note)
168+
const note = nip19.noteEncode(eventIdHex);
169+
const eventId = nip19.noteDecode(note);
170+
```
171+
145172
## API Reference
146173

147174
### Key Management
@@ -210,6 +237,13 @@ npm run format
210237

211238
## Recent Updates
212239

240+
### v0.5.0
241+
- 🔧 Fixed Bech32 mocking in test suite
242+
- 🔄 Improved signature verification consistency
243+
- 🎯 Enhanced key pair generation and validation
244+
- 🛠️ Updated test infrastructure for better reliability
245+
- 📦 Streamlined dependency mocking system
246+
213247
### v0.4.0
214248
- 📚 Added comprehensive documentation and examples
215249
- 📝 Added Code of Conduct
@@ -239,7 +273,11 @@ We welcome contributions! Please follow these steps:
239273
4. Push to the branch (`git push origin feature/amazing-feature`)
240274
5. Open a Pull Request
241275

242-
Please read our [Code of Conduct](CODE_OF_CONDUCT.md) before contributing.
276+
Before contributing:
277+
- Read our [Code of Conduct](CODE_OF_CONDUCT.md)
278+
- Check our [Contributing Guidelines](.github/CONTRIBUTING.md)
279+
- Review our [Security Policy](SECURITY.md)
280+
- Search [existing issues](https://github.com/humanjavaenterprises/nostr-nsec-seedphrase/issues) before creating a new one
243281

244282
## License
245283

__mocks__/@noble/secp256k1.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

docs/.nojekyll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.

docs/README.md

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
nostr-nsec-seedphrase / [Exports](modules.md)
2+
3+
# nostr-nsec-seedphrase
4+
5+
<div align="center">
6+
7+
[![npm version](https://img.shields.io/npm/v/nostr-nsec-seedphrase.svg)](https://www.npmjs.com/package/nostr-nsec-seedphrase)
8+
[![npm downloads](https://img.shields.io/npm/dm/nostr-nsec-seedphrase.svg)](https://www.npmjs.com/package/nostr-nsec-seedphrase)
9+
[![License](https://img.shields.io/npm/l/nostr-nsec-seedphrase.svg)](https://github.com/humanjavaenterprises/nostr-nsec-seedphrase/blob/main/LICENSE)
10+
[![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
11+
[![Test Status](https://img.shields.io/github/actions/workflow/status/humanjavaenterprises/nostr-nsec-seedphrase/test.yml?branch=main&label=tests)](https://github.com/humanjavaenterprises/nostr-nsec-seedphrase/actions)
12+
[![Code Style](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://prettier.io/)
13+
14+
</div>
15+
16+
A comprehensive TypeScript library for managing Nostr keys with seed phrases, including event signing, verification, and WebSocket utilities.
17+
18+
## Features
19+
20+
- 🔑 Generate and manage seed phrases for Nostr keys
21+
- 🔄 Convert between different key formats (hex, nsec, npub)
22+
- ✍️ Sign and verify messages
23+
- 📝 Create and verify Nostr events
24+
- 🌐 WebSocket utilities for Nostr applications
25+
- 📦 TypeScript support with full type definitions
26+
- ✅ Comprehensive test coverage
27+
- 🔒 Secure key management practices
28+
29+
## NIPs Support Status
30+
31+
🟢 Fully implemented 🟡 Partially implemented 🔴 Not implemented
32+
33+
| NIP | Status | Description |
34+
|-----|--------|-------------|
35+
| 01 | 🟢 | Basic protocol flow & event signing |
36+
| 06 | 🟢 | Basic key derivation and event signing |
37+
| 13 | 🟢 | Proof of Work support |
38+
| 19 | 🟢 | bech32-encoded entities |
39+
| 49 | 🟢 | Private Key Generation from Seed Phrases |
40+
41+
### NIP-49 Implementation Details
42+
43+
This package fully implements NIP-49, which specifies the use of BIP-39-style mnemonic seed phrases for generating private keys in the Nostr protocol. Our implementation ensures full compatibility with the NIP-49 specification while providing robust tooling for developers.
44+
45+
#### Key Features & Compliance
46+
47+
1. **Mnemonic Generation & Handling**:
48+
- Full BIP-39 compliance for seed phrase generation
49+
- Support for multiple languages and word lists
50+
- Secure entropy generation for new seed phrases
51+
52+
2. **Standardized Key Derivation**:
53+
- Implements the standard derivation path (m/44'/1237'/0'/0/0)
54+
- Ensures compatibility with other NIP-49 compliant tools and wallets
55+
- Supports custom derivation paths for advanced use cases
56+
57+
3. **Key Format & Encoding**:
58+
- Outputs Nostr-compatible `nsec` and `npub` keys
59+
- Supports conversion between different key formats
60+
- Maintains compatibility with existing Nostr infrastructure
61+
62+
4. **Security & Best Practices**:
63+
- Implements secure key generation and storage practices
64+
- Provides validation utilities for seed phrases
65+
- Follows cryptographic best practices for key management
66+
67+
#### Interoperability
68+
69+
This implementation ensures compatibility with:
70+
- Nostr wallets implementing NIP-49
71+
- Key management tools using BIP-39 mnemonics
72+
- Other Nostr clients and libraries following the specification
73+
74+
#### Validation & Testing
75+
76+
To verify compatibility, the package includes:
77+
- Comprehensive test suites against NIP-49 specifications
78+
- Validation against known test vectors
79+
- Integration tests with common Nostr tools and libraries
80+
81+
## Installation
82+
83+
```bash
84+
npm install nostr-nsec-seedphrase
85+
```
86+
87+
## Getting Started
88+
89+
This library provides a comprehensive set of tools for managing Nostr keys with seed phrases. Here's how to get started:
90+
91+
### Prerequisites
92+
93+
- Node.js 16.0.0 or later
94+
- npm or yarn package manager
95+
96+
### Basic Usage
97+
98+
#### Key Generation and Management
99+
100+
```typescript
101+
import { generateKeyPairWithSeed, seedPhraseToKeyPair } from 'nostr-nsec-seedphrase';
102+
103+
// Generate a new key pair with seed phrase
104+
const keyPair = generateKeyPairWithSeed();
105+
console.log(keyPair);
106+
// {
107+
// privateKey: '...',
108+
// publicKey: '...',
109+
// nsec: '...',
110+
// npub: '...',
111+
// seedPhrase: '...'
112+
// }
113+
114+
// Convert existing seed phrase to key pair
115+
const existingKeyPair = seedPhraseToKeyPair('your twelve word seed phrase here');
116+
```
117+
118+
### Message Signing and Verification
119+
120+
```typescript
121+
import { signMessage, verifySignature } from 'nostr-nsec-seedphrase';
122+
123+
// Sign a message
124+
const signature = await signMessage('Hello Nostr!', keyPair.privateKey);
125+
126+
// Verify a signature
127+
const isValid = await verifySignature('Hello Nostr!', signature, keyPair.publicKey);
128+
```
129+
130+
### Event Creation and Verification
131+
132+
```typescript
133+
import { createEvent, verifyEvent } from 'nostr-nsec-seedphrase';
134+
135+
// Create a new event
136+
const event = await createEvent(
137+
'Hello Nostr!', // content
138+
1, // kind (1 = text note)
139+
keyPair.privateKey,
140+
[] // tags (optional)
141+
);
142+
143+
// Verify an event
144+
const isValidEvent = await verifyEvent(event);
145+
```
146+
147+
## API Reference
148+
149+
### Key Management
150+
- `generateKeyPairWithSeed()`: Generate a new key pair with seed phrase
151+
- `seedPhraseToKeyPair(seedPhrase: string)`: Convert seed phrase to key pair
152+
- `fromHex(privateKeyHex: string)`: Create key pair from hex private key
153+
- `validateSeedPhrase(seedPhrase: string)`: Validate a seed phrase
154+
155+
### Format Conversion
156+
- `nsecToHex(nsec: string)`: Convert nsec to hex format
157+
- `npubToHex(npub: string)`: Convert npub to hex format
158+
- `hexToNsec(privateKeyHex: string)`: Convert hex to nsec format
159+
- `hexToNpub(publicKeyHex: string)`: Convert hex to npub format
160+
161+
### Signing and Verification
162+
- `signMessage(message: string, privateKey: string)`: Sign a message
163+
- `verifySignature(message: string, signature: string, publicKey: string)`: Verify a signature
164+
- `createEvent(content: string, kind: number, privateKey: string, tags?: string[][])`: Create a Nostr event
165+
- `verifyEvent(event: NostrEvent)`: Verify a Nostr event
166+
167+
## Development
168+
169+
### Setting Up Development Environment
170+
171+
1. Clone the repository
172+
```bash
173+
git clone https://github.com/humanjavaenterprises/nostr-nsec-seedphrase.git
174+
cd nostr-nsec-seedphrase
175+
```
176+
177+
2. Install dependencies
178+
```bash
179+
npm install
180+
```
181+
182+
3. Build the project
183+
```bash
184+
npm run build
185+
```
186+
187+
### Running Tests
188+
189+
```bash
190+
# Run all tests
191+
npm test
192+
193+
# Run tests with coverage
194+
npm run test:coverage
195+
```
196+
197+
### Code Style
198+
199+
This project uses Prettier for code formatting. Format your code before committing:
200+
201+
```bash
202+
npm run format
203+
```
204+
205+
## Security Considerations
206+
207+
- Always keep your seed phrases and private keys secure
208+
- Never share your private keys or seed phrases
209+
- Be cautious when using this library in a browser environment
210+
- Consider using a hardware wallet for additional security
211+
- Validate all inputs and handle errors appropriately
212+
213+
## Recent Updates
214+
215+
### v0.4.0
216+
- 📚 Added comprehensive documentation and examples
217+
- 📝 Added Code of Conduct
218+
- 🔍 Enhanced development setup instructions
219+
- 🛡️ Added security considerations section
220+
221+
### v0.3.0
222+
- 🔧 Enhanced module resolution for better compatibility
223+
- ✨ Improved testing infrastructure and mocks
224+
- 📝 Enhanced TypeScript support and configurations
225+
- 🔒 Enhanced cryptographic functionality
226+
- 🎯 Updated ESLint and TypeScript configurations
227+
228+
### v0.2.0
229+
- 🔧 Fixed HMAC configuration for secp256k1
230+
- ✅ Added comprehensive test coverage
231+
- 🎯 Improved TypeScript types
232+
- 📚 Enhanced documentation
233+
234+
## Contributing
235+
236+
We welcome contributions! Please follow these steps:
237+
238+
1. Fork the repository
239+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
240+
3. Commit your changes (`git commit -m 'feat: add amazing feature'`)
241+
4. Push to the branch (`git push origin feature/amazing-feature`)
242+
5. Open a Pull Request
243+
244+
Please read our [Code of Conduct](CODE_OF_CONDUCT.md) before contributing.
245+
246+
## License
247+
248+
[MIT](LICENSE)
249+
250+
## Author
251+
252+
[Vergel Evans](https://github.com/vergelevans)
253+
254+
---
255+
<div align="center">
256+
Made with ❤️ by <a href="https://github.com/humanjavaenterprises">Humanjava Enterprises</a>
257+
</div>

0 commit comments

Comments
 (0)