|
| 1 | +nostr-nsec-seedphrase / [Exports](modules.md) |
| 2 | + |
| 3 | +# nostr-nsec-seedphrase |
| 4 | + |
| 5 | +<div align="center"> |
| 6 | + |
| 7 | +[](https://www.npmjs.com/package/nostr-nsec-seedphrase) |
| 8 | +[](https://www.npmjs.com/package/nostr-nsec-seedphrase) |
| 9 | +[](https://github.com/humanjavaenterprises/nostr-nsec-seedphrase/blob/main/LICENSE) |
| 10 | +[](https://www.typescriptlang.org/) |
| 11 | +[](https://github.com/humanjavaenterprises/nostr-nsec-seedphrase/actions) |
| 12 | +[](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