Successfully created both TypeScript and Go client libraries for the Distributed Directory Consensus Protocol (NIP-XX), mirroring functionality while following language-specific idioms.
pkg/protocol/directory-client/)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 pointapplesauce-core: ^3.0.0rxjs: ^7.8.1pkg/protocol/directory-client/)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)sync.RWMutex protectionIdentityResolver:
NewIdentityResolver() *IdentityResolverProcessEvent(ev *event.E)ResolveIdentity(pubkey string) stringIsDelegateKey(pubkey string) boolGetDelegatesForIdentity(identity string) []stringGetIdentityTag(delegate string) (*IdentityTag, error)FilterEventsByIdentity(events, identity) []*event.ETrustCalculator:
NewTrustCalculator() *TrustCalculatorAddAct(act *TrustAct)CalculateTrust(pubkey string) float64GetActiveTrustActs(pubkey string) []*TrustActReplicationFilter:
NewReplicationFilter(minTrustScore float64) *ReplicationFilterAddTrustAct(act *TrustAct)ShouldReplicate(pubkey string) boolGetTrustedRelays() []stringFilterEvents(events []*event.E) []*event.EEventCollector:
NewEventCollector(events []*event.E) *EventCollectorRelayIdentities() []*RelayIdentityAnnouncementTrustActs() []*TrustActGroupTagActs() []*GroupTagActPublicKeyAdvertisements() []*PublicKeyAdvertisementTrustGraph:
NewTrustGraph() *TrustGraphBuildTrustGraph(events []*event.E) *TrustGraphGetTrustedBy(target string) []stringGetTrustTargets(source string) []stringThe client libraries provide high-level conveniences over the base protocol package:
Protocol Package (`pkg/protocol/directory/`):
Client Libraries:
Both implementations use identical weighted averaging:
Expired acts are excluded from calculation.
NPubIdentity field and maps it as both identity and delegate, as the actual I tag structure in the protocol needs clarification.GroupID, TagName, TagValue, Actor fields which differ from the TypeScript expectation of targetPubkey and groupTag. Helper functions adapted accordingly.npm install && npm buildgo build ., zero errors, one minor efficiency warningBoth libraries include:
The implementations successfully mirror each other while respecting language idioms and ecosystem conventions.