In version 0.4.0, we've made significant improvements to our type system to ensure better type safety and consistency. Here are the key changes:
All Nostr-related types are now defined in a single location and exported from the package root. This ensures consistency and prevents type conflicts.
// ✅ New way - import from package root
import { NostrEvent, NostrEventKind } from 'nostr-crypto-utils';
// ❌ Deprecated - don't import from subdirectories
import { NostrEvent } from 'nostr-crypto-utils/dist/types/base';The NostrEventKind enum has been updated to include all standard NIP event kinds with proper documentation:
- Added missing NIP-28 event kinds
- Added NIP-42 authentication event kinds
- Improved documentation and references to NIPs
- Removed
anytypes in favor ofunknownfor better type safety - Added proper type constraints for tag filters
- Improved type definitions for crypto operations
-
NostrEvent.pubkeyis now astringinstead ofPublicKey// Before event.pubkey.hex // ✅ worked // After event.pubkey // ✅ string value
-
Filter types are more strictly typed
// Before filter['#t'] = ['sometag']; // ✅ worked // After filter[`#${tagName}`] = ['value']; // ✅ type-safe way
-
Removed duplicate type definitions
- Types are now only exported from the package root
- Importing from subdirectories will show deprecation warnings
-
Update your imports to use the package root:
import { NostrEvent, NostrEventKind, PublicKey } from 'nostr-crypto-utils';
-
Update pubkey handling:
// Before const pubkey = event.pubkey.hex; // After const pubkey = event.pubkey;
-
Update filter usage:
// Before const filter: NostrFilter = { '#t': ['tag'], authors: [pubkeyObj] }; // After const filter: NostrFilter = { '#t': ['tag'], authors: [pubkeyString] };
In v1.0.0, we plan to:
- Remove deprecated type exports from subdirectories
- Further enhance type safety with stricter validation
- Add more comprehensive NIP support
Please test your application thoroughly after upgrading, as these changes might affect type checking in your codebase.