- Introduced a TypeScript client library for the Distributed Directory Consensus Protocol (NIP-XX), providing a high-level API for managing directory events, identity resolution, and trust calculations. - Implemented core functionalities including event parsing, trust score aggregation, and replication filtering, mirroring the Go implementation. - Added comprehensive documentation and development guides for ease of use and integration. - Updated the `.gitignore` to include additional dependencies and build artifacts for the TypeScript client. - Enhanced validation mechanisms for group tag names and trust levels, ensuring robust input handling and security. - Created a new `bun.lock` file to manage package dependencies effectively.
5.6 KiB
Directory Client Libraries - Implementation Summary
Overview
Successfully created both TypeScript and Go client libraries for the Distributed Directory Consensus Protocol (NIP-XX), mirroring functionality while following language-specific idioms.
TypeScript Client (pkg/protocol/directory-client/)
Files Created
package.json- Dependencies and build configurationtsconfig.json- TypeScript compiler configurationREADME.md- Comprehensive documentation with examplesDEVELOPMENT.md- Development guidesrc/types.ts- Type definitions (304 lines)src/validation.ts- Validation functions (265 lines)src/parsers.ts- Event parsers for all kinds (408 lines)src/identity-resolver.ts- Identity & delegation management (288 lines)src/helpers.ts- Utility functions (199 lines)src/index.ts- Main entry point
Key Features
- Built on AppleSauce library for Nostr event handling
- Full TypeScript type safety
- RxJS-based observables for event streams
- Real-time identity resolution with live delegate updates
- Trust score calculation
- Replication filtering
Dependencies
applesauce-core: ^3.0.0rxjs: ^7.8.1
Go Client (pkg/protocol/directory-client/)
Files Created
doc.go- Comprehensive package documentationREADME.md- Full API reference and usage examplesclient.go- Core client functionsidentity_resolver.go- Identity resolution (258 lines)trust.go- Trust calculation & replication filtering (243 lines)helpers.go- Event collection & trust graph (224 lines)
Key Features
- Thread-safe with
sync.RWMutexprotection - Idiomatic Go API design
- No external dependencies (uses standard library + internal packages)
- Memory-efficient caching
- Trust graph construction
API Surface
IdentityResolver:
NewIdentityResolver() *IdentityResolverProcessEvent(ev *event.E)ResolveIdentity(pubkey string) stringIsDelegateKey(pubkey string) boolGetDelegatesForIdentity(identity string) []stringGetIdentityTag(delegate string) (*IdentityTag, error)FilterEventsByIdentity(events, identity) []*event.E
TrustCalculator:
NewTrustCalculator() *TrustCalculatorAddAct(act *TrustAct)CalculateTrust(pubkey string) float64GetActiveTrustActs(pubkey string) []*TrustAct
ReplicationFilter:
NewReplicationFilter(minTrustScore float64) *ReplicationFilterAddTrustAct(act *TrustAct)ShouldReplicate(pubkey string) boolGetTrustedRelays() []stringFilterEvents(events []*event.E) []*event.E
EventCollector:
NewEventCollector(events []*event.E) *EventCollectorRelayIdentities() []*RelayIdentityAnnouncementTrustActs() []*TrustActGroupTagActs() []*GroupTagActPublicKeyAdvertisements() []*PublicKeyAdvertisement
TrustGraph:
NewTrustGraph() *TrustGraphBuildTrustGraph(events []*event.E) *TrustGraphGetTrustedBy(target string) []stringGetTrustTargets(source string) []string
Implementation Notes
TypeScript-Specific Features
- Observable-based event streams with RxJS
- Promise-based async operations
- Optional chaining and nullish coalescing
- Class-based architecture
Go-Specific Features
- Goroutine-safe with mutexes
- Struct-based API (not classes)
- Multiple return values for error handling
- Zero-dependency beyond internal packages
- Memory-efficient with manual caching control
Differences from Protocol Package
The client libraries provide high-level conveniences over the base protocol package:
Protocol Package (pkg/protocol/directory/):
- Low-level event parsing
- Event construction
- Message validation
- Tag handling
Client Libraries:
- Identity relationship tracking
- Trust score aggregation
- Event filtering & collection
- Replication decision-making
- Trust graph analysis
Trust Score Calculation
Both implementations use identical weighted averaging:
- High trust: 100 points
- Medium trust: 50 points
- Low trust: 25 points
Expired acts are excluded from calculation.
Known Limitations
-
IdentityTag Structure: The Go implementation currently uses
NPubIdentityfield and maps it as both identity and delegate, as the actual I tag structure in the protocol needs clarification. -
GroupTagAct Fields: The Go struct has
GroupID,TagName,TagValue,Actorfields which differ from the TypeScript expectation oftargetPubkeyandgroupTag. Helper functions adapted accordingly. -
TypeScript Signature Verification: Not yet implemented - requires schnorr library integration.
-
Event Store Integration: TypeScript uses AppleSauce's EventStore; Go version designed for custom integration.
Testing Status
- TypeScript: Package structure complete, ready for
npm install && npm build - Go: Successfully compiles with
go build ., zero errors, one minor efficiency warning
Next Steps
- Implement unit tests for both libraries
- Add integration tests with actual event data
- Implement schnorr signature verification in TypeScript
- Clarify and align IdentityTag structure across implementations
- Add benchmark tests for performance-critical operations
- Create example applications demonstrating usage
File Counts
- TypeScript: 10 files (6 source, 4 config/docs)
- Go: 5 files (4 source, 1 doc)
- Total: 15 new files
Lines of Code
- TypeScript: ~1,800 lines
- Go: ~725 lines
- Total: ~2,525 lines
Documentation
Both libraries include:
- Comprehensive README with usage examples
- Inline code documentation
- Package-level documentation
- API reference
The implementations successfully mirror each other while respecting language idioms and ecosystem conventions.