nostr-tools 2.23.8 → 2.23.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/lib/cjs/abstract-pool.js +163 -7
  2. package/lib/cjs/abstract-pool.js.map +4 -4
  3. package/lib/cjs/abstract-relay.js +59 -6
  4. package/lib/cjs/abstract-relay.js.map +2 -2
  5. package/lib/cjs/filter.js.map +1 -1
  6. package/lib/cjs/index.js +412 -64
  7. package/lib/cjs/index.js.map +4 -4
  8. package/lib/cjs/kinds.js +196 -4
  9. package/lib/cjs/kinds.js.map +2 -2
  10. package/lib/cjs/nip17.js.map +2 -2
  11. package/lib/cjs/nip18.js.map +2 -2
  12. package/lib/cjs/nip25.js.map +1 -1
  13. package/lib/cjs/nip28.js.map +2 -2
  14. package/lib/cjs/nip42.js.map +2 -2
  15. package/lib/cjs/nip45.js +183 -0
  16. package/lib/cjs/nip45.js.map +7 -0
  17. package/lib/cjs/nip46.js +163 -7
  18. package/lib/cjs/nip46.js.map +4 -4
  19. package/lib/cjs/nip47.js.map +2 -2
  20. package/lib/cjs/nip57.js.map +1 -1
  21. package/lib/cjs/nip58.js.map +2 -2
  22. package/lib/cjs/nip59.js.map +2 -2
  23. package/lib/cjs/nip75.js.map +2 -2
  24. package/lib/cjs/nip94.js.map +2 -2
  25. package/lib/cjs/nip98.js.map +2 -2
  26. package/lib/cjs/nip99.js.map +2 -2
  27. package/lib/cjs/nipb0.js +1064 -0
  28. package/lib/cjs/nipb0.js.map +7 -0
  29. package/lib/cjs/pool.js +163 -7
  30. package/lib/cjs/pool.js.map +4 -4
  31. package/lib/cjs/relay.js +59 -6
  32. package/lib/cjs/relay.js.map +2 -2
  33. package/lib/esm/abstract-pool.js +163 -7
  34. package/lib/esm/abstract-pool.js.map +4 -4
  35. package/lib/esm/abstract-relay.js +59 -6
  36. package/lib/esm/abstract-relay.js.map +2 -2
  37. package/lib/esm/filter.js.map +1 -1
  38. package/lib/esm/index.js +388 -40
  39. package/lib/esm/index.js.map +4 -4
  40. package/lib/esm/kinds.js +196 -4
  41. package/lib/esm/kinds.js.map +2 -2
  42. package/lib/esm/nip17.js.map +2 -2
  43. package/lib/esm/nip18.js.map +2 -2
  44. package/lib/esm/nip25.js.map +1 -1
  45. package/lib/esm/nip28.js.map +2 -2
  46. package/lib/esm/nip42.js.map +2 -2
  47. package/lib/esm/nip45.js +162 -0
  48. package/lib/esm/nip45.js.map +7 -0
  49. package/lib/esm/nip46.js +163 -7
  50. package/lib/esm/nip46.js.map +4 -4
  51. package/lib/esm/nip47.js.map +2 -2
  52. package/lib/esm/nip57.js.map +1 -1
  53. package/lib/esm/nip58.js.map +2 -2
  54. package/lib/esm/nip59.js.map +2 -2
  55. package/lib/esm/nip75.js.map +2 -2
  56. package/lib/esm/nip94.js.map +2 -2
  57. package/lib/esm/nip98.js.map +2 -2
  58. package/lib/esm/nip99.js.map +2 -2
  59. package/lib/esm/nipb0.js +1049 -0
  60. package/lib/esm/nipb0.js.map +7 -0
  61. package/lib/esm/pool.js +163 -7
  62. package/lib/esm/pool.js.map +4 -4
  63. package/lib/esm/relay.js +59 -6
  64. package/lib/esm/relay.js.map +2 -2
  65. package/lib/nostr.bundle.js +361 -15
  66. package/lib/nostr.bundle.js.map +4 -4
  67. package/lib/types/abstract-pool.d.ts +10 -0
  68. package/lib/types/abstract-relay.d.ts +15 -1
  69. package/lib/types/kinds.d.ts +200 -8
  70. package/lib/types/nip45.d.ts +13 -0
  71. package/lib/types/nip45.test.d.ts +1 -0
  72. package/lib/types/nipb0.d.ts +129 -0
  73. package/lib/types/relay.d.ts +2 -2
  74. package/package.json +13 -1
package/lib/cjs/index.js CHANGED
@@ -293,39 +293,61 @@ var verifyEvent = i.verifyEvent;
293
293
  // kinds.ts
294
294
  var kinds_exports = {};
295
295
  __export(kinds_exports, {
296
+ AIEmbeddings: () => AIEmbeddings,
297
+ AppCurationSet: () => AppCurationSet,
296
298
  Application: () => Application,
299
+ AuthoredPodcasts: () => AuthoredPodcasts,
297
300
  BadgeAward: () => BadgeAward,
298
301
  BadgeDefinition: () => BadgeDefinition,
302
+ Bid: () => Bid,
303
+ BidConfirmation: () => BidConfirmation,
304
+ BlobsAuth: () => BlobsAuth,
299
305
  BlockedRelaysList: () => BlockedRelaysList,
300
306
  BlossomServerList: () => BlossomServerList,
301
307
  BookmarkList: () => BookmarkList,
302
308
  Bookmarksets: () => Bookmarksets,
303
309
  Calendar: () => Calendar,
304
310
  CalendarEventRSVP: () => CalendarEventRSVP,
311
+ CashuMintAnnouncement: () => CashuMintAnnouncement,
312
+ CashuWalletEvent: () => CashuWalletEvent,
313
+ CashuWalletHistory: () => CashuWalletHistory,
314
+ CashuWalletTokens: () => CashuWalletTokens,
305
315
  ChannelCreation: () => ChannelCreation,
306
316
  ChannelHideMessage: () => ChannelHideMessage,
307
317
  ChannelMessage: () => ChannelMessage,
308
318
  ChannelMetadata: () => ChannelMetadata,
309
319
  ChannelMuteUser: () => ChannelMuteUser,
310
320
  ChatMessage: () => ChatMessage,
321
+ Chess: () => Chess,
311
322
  ClassifiedListing: () => ClassifiedListing,
312
323
  ClientAuth: () => ClientAuth,
324
+ CodeSnippet: () => CodeSnippet,
325
+ CoinjoinPool: () => CoinjoinPool,
313
326
  Comment: () => Comment,
314
327
  CommunitiesList: () => CommunitiesList,
315
328
  CommunityDefinition: () => CommunityDefinition,
316
329
  CommunityPostApproval: () => CommunityPostApproval,
330
+ ConferenceEvent: () => ConferenceEvent,
317
331
  Contacts: () => Contacts,
318
332
  CreateOrUpdateProduct: () => CreateOrUpdateProduct,
319
333
  CreateOrUpdateStall: () => CreateOrUpdateStall,
334
+ CuratedVideoSets: () => CuratedVideoSets,
320
335
  Curationsets: () => Curationsets,
321
336
  Date: () => Date2,
337
+ DecoupledEncryptionKeyDistribution: () => DecoupledEncryptionKeyDistribution,
338
+ DecoupledKeyAnnouncement: () => DecoupledKeyAnnouncement,
339
+ DecoupledKeyClientAnnouncement: () => DecoupledKeyClientAnnouncement,
322
340
  DirectMessageRelaysList: () => DirectMessageRelaysList,
323
341
  DraftClassifiedListing: () => DraftClassifiedListing,
342
+ DraftEvent: () => DraftEvent,
324
343
  DraftLong: () => DraftLong,
325
344
  Emojisets: () => Emojisets,
326
345
  EncryptedDirectMessage: () => EncryptedDirectMessage,
327
346
  EventDeletion: () => EventDeletion,
347
+ FavoritePodcasts: () => FavoritePodcasts,
328
348
  FavoriteRelays: () => FavoriteRelays,
349
+ FedimintAnnouncement: () => FedimintAnnouncement,
350
+ Feed: () => Feed,
329
351
  FileMessage: () => FileMessage,
330
352
  FileMetadata: () => FileMetadata,
331
353
  FileServerPreference: () => FileServerPreference,
@@ -333,55 +355,129 @@ __export(kinds_exports, {
333
355
  ForumThread: () => ForumThread,
334
356
  GenericRepost: () => GenericRepost,
335
357
  Genericlists: () => Genericlists,
358
+ GeocacheListing: () => GeocacheListing,
359
+ GeocacheLog: () => GeocacheLog,
360
+ GeocacheLogEntry: () => GeocacheLogEntry,
361
+ GeocacheProofOfFind: () => GeocacheProofOfFind,
336
362
  GiftWrap: () => GiftWrap,
363
+ GitPullRequest: () => GitPullRequest,
364
+ GitPullRequestUpdate: () => GitPullRequestUpdate,
365
+ GoodWikiAuthorList: () => GoodWikiAuthorList,
366
+ GoodWikiRelayList: () => GoodWikiRelayList,
337
367
  GroupMetadata: () => GroupMetadata,
338
368
  HTTPAuth: () => HTTPAuth,
339
369
  Handlerinformation: () => Handlerinformation,
340
370
  Handlerrecommendation: () => Handlerrecommendation,
341
371
  Highlights: () => Highlights,
372
+ InteractiveRoom: () => InteractiveRoom,
342
373
  InterestsList: () => InterestsList,
343
374
  Interestsets: () => Interestsets,
375
+ Issue: () => Issue,
344
376
  JobFeedback: () => JobFeedback,
345
377
  JobRequest: () => JobRequest,
346
378
  JobResult: () => JobResult,
347
379
  Label: () => Label,
380
+ LegacyNsiteFile: () => LegacyNsiteFile,
348
381
  LightningPubRPC: () => LightningPubRPC,
382
+ LinkSet: () => LinkSet,
349
383
  LiveChatMessage: () => LiveChatMessage,
350
384
  LiveEvent: () => LiveEvent,
351
385
  LongFormArticle: () => LongFormArticle,
386
+ MarketplaceUI: () => MarketplaceUI,
387
+ MediaFollows: () => MediaFollows,
388
+ MediaStarterPacks: () => MediaStarterPacks,
389
+ MergeRequests: () => MergeRequests,
352
390
  Metadata: () => Metadata,
391
+ ModularArticleContent: () => ModularArticleContent,
392
+ ModularArticleHeader: () => ModularArticleHeader,
393
+ MuteSets: () => MuteSets,
353
394
  Mutelist: () => Mutelist,
354
395
  NWCWalletInfo: () => NWCWalletInfo,
355
396
  NWCWalletRequest: () => NWCWalletRequest,
356
397
  NWCWalletResponse: () => NWCWalletResponse,
357
398
  NormalVideo: () => NormalVideo,
358
399
  NostrConnect: () => NostrConnect,
400
+ NsiteNamed: () => NsiteNamed,
401
+ NsiteRoot: () => NsiteRoot,
402
+ NutZap: () => NutZap,
403
+ NutZapInfo: () => NutZapInfo,
359
404
  OpenTimestamps: () => OpenTimestamps,
405
+ Patch: () => Patch,
406
+ PeerToPeerOrderEvents: () => PeerToPeerOrderEvents,
360
407
  Photo: () => Photo,
361
408
  Pinlist: () => Pinlist,
409
+ PodcastEpisode: () => PodcastEpisode,
410
+ PodcastMetadata: () => PodcastMetadata,
362
411
  Poll: () => Poll,
363
412
  PollResponse: () => PollResponse,
364
413
  PrivateDirectMessage: () => PrivateDirectMessage,
414
+ PrivateEventRelayList: () => PrivateEventRelayList,
365
415
  ProblemTracker: () => ProblemTracker,
416
+ ProductSoldAsAuction: () => ProductSoldAsAuction,
366
417
  ProfileBadges: () => ProfileBadges,
418
+ ProxyAnnouncement: () => ProxyAnnouncement,
367
419
  PublicChatsList: () => PublicChatsList,
420
+ PublicMessage: () => PublicMessage,
368
421
  Reaction: () => Reaction,
422
+ ReactionToWebsite: () => ReactionToWebsite,
369
423
  RecommendRelay: () => RecommendRelay,
424
+ Redirects: () => Redirects,
425
+ RelayDiscovery: () => RelayDiscovery,
370
426
  RelayList: () => RelayList,
427
+ RelayMonitorAnnouncement: () => RelayMonitorAnnouncement,
371
428
  RelayReview: () => RelayReview,
429
+ RelayReviews: () => RelayReviews,
372
430
  Relaysets: () => Relaysets,
431
+ ReleaseArtifactSets: () => ReleaseArtifactSets,
432
+ Reply: () => Reply,
373
433
  Report: () => Report,
374
434
  Reporting: () => Reporting,
435
+ RepositoryAnnouncement: () => RepositoryAnnouncement,
436
+ RepositoryState: () => RepositoryState,
375
437
  Repost: () => Repost,
438
+ ReservedCashuWalletTokens: () => ReservedCashuWalletTokens,
439
+ RoomPresence: () => RoomPresence,
440
+ Scroll: () => Scroll,
376
441
  Seal: () => Seal,
377
442
  SearchRelaysList: () => SearchRelaysList,
378
443
  ShortTextNote: () => ShortTextNote,
379
444
  ShortVideo: () => ShortVideo,
445
+ SimpleGroupAdmins: () => SimpleGroupAdmins,
446
+ SimpleGroupCreateGroup: () => SimpleGroupCreateGroup,
447
+ SimpleGroupCreateInvite: () => SimpleGroupCreateInvite,
448
+ SimpleGroupDeleteEvent: () => SimpleGroupDeleteEvent,
449
+ SimpleGroupDeleteGroup: () => SimpleGroupDeleteGroup,
450
+ SimpleGroupEditMetadata: () => SimpleGroupEditMetadata,
451
+ SimpleGroupJoinRequest: () => SimpleGroupJoinRequest,
452
+ SimpleGroupLeaveRequest: () => SimpleGroupLeaveRequest,
453
+ SimpleGroupList: () => SimpleGroupList,
454
+ SimpleGroupLiveKitParticipants: () => SimpleGroupLiveKitParticipants,
455
+ SimpleGroupMembers: () => SimpleGroupMembers,
456
+ SimpleGroupPutUser: () => SimpleGroupPutUser,
457
+ SimpleGroupRemoveUser: () => SimpleGroupRemoveUser,
458
+ SimpleGroupReply: () => SimpleGroupReply,
459
+ SimpleGroupRoles: () => SimpleGroupRoles,
460
+ SimpleGroupThreadedReply: () => SimpleGroupThreadedReply,
461
+ SlideSet: () => SlideSet,
462
+ SoftwareApplication: () => SoftwareApplication,
463
+ StarterPacks: () => StarterPacks,
464
+ StatusApplied: () => StatusApplied,
465
+ StatusClosed: () => StatusClosed,
466
+ StatusDraft: () => StatusDraft,
467
+ StatusOpen: () => StatusOpen,
468
+ TidalLogin: () => TidalLogin,
380
469
  Time: () => Time,
470
+ Torrent: () => Torrent,
471
+ TorrentComment: () => TorrentComment,
472
+ TransportMethodAnnouncement: () => TransportMethodAnnouncement,
381
473
  UserEmojiList: () => UserEmojiList,
474
+ UserGraspList: () => UserGraspList,
382
475
  UserStatuses: () => UserStatuses,
476
+ VideoViewEvent: () => VideoViewEvent,
383
477
  Voice: () => Voice,
384
478
  VoiceComment: () => VoiceComment,
479
+ WebBookmarks: () => WebBookmarks,
480
+ WikiArticle: () => WikiArticle,
385
481
  Zap: () => Zap,
386
482
  ZapGoal: () => ZapGoal,
387
483
  ZapRequest: () => ZapRequest,
@@ -429,40 +525,83 @@ var Repost = 6;
429
525
  var Reaction = 7;
430
526
  var BadgeAward = 8;
431
527
  var ChatMessage = 9;
528
+ var SimpleGroupThreadedReply = 10;
432
529
  var ForumThread = 11;
530
+ var SimpleGroupReply = 12;
433
531
  var Seal = 13;
434
532
  var PrivateDirectMessage = 14;
435
533
  var FileMessage = 15;
436
534
  var GenericRepost = 16;
535
+ var ReactionToWebsite = 17;
437
536
  var Photo = 20;
438
537
  var NormalVideo = 21;
439
538
  var ShortVideo = 22;
539
+ var PublicMessage = 24;
440
540
  var ChannelCreation = 40;
441
541
  var ChannelMetadata = 41;
442
542
  var ChannelMessage = 42;
443
543
  var ChannelHideMessage = 43;
444
544
  var ChannelMuteUser = 44;
545
+ var PodcastEpisode = 54;
546
+ var Chess = 64;
547
+ var MergeRequests = 818;
548
+ var PollResponse = 1018;
549
+ var Bid = 1021;
550
+ var BidConfirmation = 1022;
445
551
  var OpenTimestamps = 1040;
446
552
  var GiftWrap = 1059;
447
- var Poll = 1068;
448
553
  var FileMetadata = 1063;
554
+ var Poll = 1068;
449
555
  var Comment = 1111;
450
- var LiveChatMessage = 1311;
451
556
  var Voice = 1222;
557
+ var Scroll = 1227;
452
558
  var VoiceComment = 1244;
559
+ var LiveChatMessage = 1311;
560
+ var CodeSnippet = 1337;
561
+ var Patch = 1617;
562
+ var GitPullRequest = 1618;
563
+ var GitPullRequestUpdate = 1619;
564
+ var Issue = 1621;
565
+ var Reply = 1622;
566
+ var StatusOpen = 1630;
567
+ var StatusApplied = 1631;
568
+ var StatusClosed = 1632;
569
+ var StatusDraft = 1633;
453
570
  var ProblemTracker = 1971;
454
571
  var Report = 1984;
455
572
  var Reporting = 1984;
456
573
  var Label = 1985;
574
+ var RelayReviews = 1986;
575
+ var AIEmbeddings = 1987;
576
+ var Torrent = 2003;
577
+ var TorrentComment = 2004;
578
+ var CoinjoinPool = 2022;
579
+ var DecoupledKeyClientAnnouncement = 4454;
580
+ var DecoupledEncryptionKeyDistribution = 4455;
457
581
  var CommunityPostApproval = 4550;
458
582
  var JobRequest = 5999;
459
583
  var JobResult = 6999;
460
584
  var JobFeedback = 7e3;
585
+ var ReservedCashuWalletTokens = 7374;
586
+ var CashuWalletTokens = 7375;
587
+ var CashuWalletHistory = 7376;
588
+ var GeocacheLog = 7516;
589
+ var GeocacheProofOfFind = 7517;
590
+ var SimpleGroupPutUser = 9e3;
591
+ var SimpleGroupRemoveUser = 9001;
592
+ var SimpleGroupEditMetadata = 9002;
593
+ var SimpleGroupDeleteEvent = 9005;
594
+ var SimpleGroupCreateGroup = 9007;
595
+ var SimpleGroupDeleteGroup = 9008;
596
+ var SimpleGroupCreateInvite = 9009;
597
+ var SimpleGroupJoinRequest = 9021;
598
+ var SimpleGroupLeaveRequest = 9022;
461
599
  var ZapGoal = 9041;
600
+ var NutZap = 9321;
601
+ var TidalLogin = 9467;
462
602
  var ZapRequest = 9734;
463
603
  var Zap = 9735;
464
604
  var Highlights = 9802;
465
- var PollResponse = 1018;
466
605
  var Mutelist = 1e4;
467
606
  var Pinlist = 10001;
468
607
  var RelayList = 10002;
@@ -471,37 +610,74 @@ var CommunitiesList = 10004;
471
610
  var PublicChatsList = 10005;
472
611
  var BlockedRelaysList = 10006;
473
612
  var SearchRelaysList = 10007;
613
+ var SimpleGroupList = 10009;
474
614
  var FavoriteRelays = 10012;
615
+ var PrivateEventRelayList = 10013;
475
616
  var InterestsList = 10015;
617
+ var NutZapInfo = 10019;
618
+ var MediaFollows = 10020;
476
619
  var UserEmojiList = 10030;
620
+ var DecoupledKeyAnnouncement = 10044;
477
621
  var DirectMessageRelaysList = 10050;
478
- var FileServerPreference = 10096;
622
+ var FavoritePodcasts = 10054;
479
623
  var BlossomServerList = 10063;
624
+ var FileServerPreference = 10096;
625
+ var GoodWikiAuthorList = 10101;
626
+ var GoodWikiRelayList = 10102;
627
+ var PodcastMetadata = 10154;
628
+ var AuthoredPodcasts = 10164;
629
+ var RelayMonitorAnnouncement = 10166;
630
+ var RoomPresence = 10312;
631
+ var UserGraspList = 10317;
632
+ var ProxyAnnouncement = 10377;
633
+ var TransportMethodAnnouncement = 11111;
480
634
  var NWCWalletInfo = 13194;
635
+ var NsiteRoot = 15128;
636
+ var CashuWalletEvent = 17375;
481
637
  var LightningPubRPC = 21e3;
482
638
  var ClientAuth = 22242;
483
639
  var NWCWalletRequest = 23194;
484
640
  var NWCWalletResponse = 23195;
485
641
  var NostrConnect = 24133;
642
+ var BlobsAuth = 24242;
486
643
  var HTTPAuth = 27235;
487
644
  var Followsets = 3e4;
488
645
  var Genericlists = 30001;
489
646
  var Relaysets = 30002;
490
647
  var Bookmarksets = 30003;
491
648
  var Curationsets = 30004;
649
+ var CuratedVideoSets = 30005;
650
+ var MuteSets = 30007;
492
651
  var ProfileBadges = 30008;
493
652
  var BadgeDefinition = 30009;
494
653
  var Interestsets = 30015;
495
654
  var CreateOrUpdateStall = 30017;
496
655
  var CreateOrUpdateProduct = 30018;
656
+ var MarketplaceUI = 30019;
657
+ var ProductSoldAsAuction = 30020;
497
658
  var LongFormArticle = 30023;
498
659
  var DraftLong = 30024;
499
660
  var Emojisets = 30030;
661
+ var ModularArticleHeader = 30040;
662
+ var ModularArticleContent = 30041;
663
+ var ReleaseArtifactSets = 30063;
500
664
  var Application = 30078;
665
+ var RelayDiscovery = 30166;
666
+ var AppCurationSet = 30267;
501
667
  var LiveEvent = 30311;
668
+ var InteractiveRoom = 30312;
669
+ var ConferenceEvent = 30313;
502
670
  var UserStatuses = 30315;
671
+ var SlideSet = 30388;
503
672
  var ClassifiedListing = 30402;
504
673
  var DraftClassifiedListing = 30403;
674
+ var RepositoryAnnouncement = 30617;
675
+ var RepositoryState = 30618;
676
+ var WikiArticle = 30818;
677
+ var Redirects = 30819;
678
+ var DraftEvent = 31234;
679
+ var LinkSet = 31388;
680
+ var Feed = 31890;
505
681
  var Date2 = 31922;
506
682
  var Time = 31923;
507
683
  var Calendar = 31924;
@@ -509,8 +685,24 @@ var CalendarEventRSVP = 31925;
509
685
  var RelayReview = 31987;
510
686
  var Handlerrecommendation = 31989;
511
687
  var Handlerinformation = 31990;
688
+ var SoftwareApplication = 32267;
689
+ var LegacyNsiteFile = 34128;
690
+ var VideoViewEvent = 34237;
512
691
  var CommunityDefinition = 34550;
692
+ var NsiteNamed = 35128;
693
+ var GeocacheListing = 37515;
694
+ var GeocacheLogEntry = 37516;
695
+ var CashuMintAnnouncement = 38172;
696
+ var FedimintAnnouncement = 38173;
697
+ var PeerToPeerOrderEvents = 38383;
513
698
  var GroupMetadata = 39e3;
699
+ var SimpleGroupAdmins = 39001;
700
+ var SimpleGroupMembers = 39002;
701
+ var SimpleGroupRoles = 39003;
702
+ var SimpleGroupLiveKitParticipants = 39004;
703
+ var StarterPacks = 39089;
704
+ var MediaStarterPacks = 39092;
705
+ var WebBookmarks = 39701;
514
706
 
515
707
  // filter.ts
516
708
  function matchFilter(filter, event) {
@@ -672,12 +864,14 @@ var AbstractRelay = class {
672
864
  openSubs = /* @__PURE__ */ new Map();
673
865
  enablePing;
674
866
  enableReconnect;
867
+ idleTimeout = 0;
675
868
  idleSince = Date.now();
676
869
  ongoingOperations = 0;
677
870
  reconnectTimeoutHandle;
678
871
  pingIntervalHandle;
679
872
  reconnectAttempts = 0;
680
873
  skipReconnection = false;
874
+ idleTimeoutHandle;
681
875
  connectionPromise;
682
876
  openCountRequests = /* @__PURE__ */ new Map();
683
877
  openEventPublishes = /* @__PURE__ */ new Map();
@@ -693,6 +887,8 @@ var AbstractRelay = class {
693
887
  this._WebSocket = opts.websocketImplementation || WebSocket;
694
888
  this.enablePing = opts.enablePing;
695
889
  this.enableReconnect = opts.enableReconnect || false;
890
+ if (opts.idleTimeout)
891
+ this.idleTimeout = opts.idleTimeout;
696
892
  }
697
893
  static async connect(url, opts) {
698
894
  const relay = new AbstractRelay(url, opts);
@@ -716,6 +912,22 @@ var AbstractRelay = class {
716
912
  get connected() {
717
913
  return this._connected;
718
914
  }
915
+ clearIdleTimeout() {
916
+ if (this.idleTimeoutHandle) {
917
+ clearTimeout(this.idleTimeoutHandle);
918
+ this.idleTimeoutHandle = void 0;
919
+ }
920
+ }
921
+ scheduleIdleClose() {
922
+ this.clearIdleTimeout();
923
+ if (this.idleTimeout > 0) {
924
+ this.idleTimeoutHandle = setTimeout(() => {
925
+ if (this.ongoingOperations === 0 && this.idleSince) {
926
+ this.close();
927
+ }
928
+ }, this.idleTimeout);
929
+ }
930
+ }
719
931
  async reconnect() {
720
932
  const backoff = this.resubscribeBackoff[Math.min(this.reconnectAttempts, this.resubscribeBackoff.length - 1)];
721
933
  this.reconnectAttempts++;
@@ -734,6 +946,7 @@ var AbstractRelay = class {
734
946
  this._connected = false;
735
947
  this.connectionPromise = void 0;
736
948
  this.idleSince = void 0;
949
+ this.clearIdleTimeout();
737
950
  if (this.enableReconnect && !this.skipReconnection) {
738
951
  this.reconnect();
739
952
  } else {
@@ -891,6 +1104,7 @@ var AbstractRelay = class {
891
1104
  }
892
1105
  async publish(event) {
893
1106
  this.idleSince = void 0;
1107
+ this.clearIdleTimeout();
894
1108
  this.ongoingOperations++;
895
1109
  const ret = new Promise((resolve, reject) => {
896
1110
  const timeout = setTimeout(() => {
@@ -902,24 +1116,46 @@ var AbstractRelay = class {
902
1116
  }, this.publishTimeout);
903
1117
  this.openEventPublishes.set(event.id, { resolve, reject, timeout });
904
1118
  });
905
- this.send('["EVENT",' + JSON.stringify(event) + "]");
1119
+ try {
1120
+ await this.send('["EVENT",' + JSON.stringify(event) + "]");
1121
+ } catch (err) {
1122
+ const ep = this.openEventPublishes.get(event.id);
1123
+ if (ep) {
1124
+ ep.reject(err);
1125
+ this.openEventPublishes.delete(event.id);
1126
+ }
1127
+ }
906
1128
  this.ongoingOperations--;
907
- if (this.ongoingOperations === 0)
1129
+ if (this.ongoingOperations === 0) {
908
1130
  this.idleSince = Date.now();
1131
+ this.scheduleIdleClose();
1132
+ }
909
1133
  return ret;
910
1134
  }
911
1135
  async count(filters, params) {
1136
+ return (await this.countWithHLL(filters, params)).count;
1137
+ }
1138
+ async countWithHLL(filters, params) {
912
1139
  this.serial++;
913
1140
  const id = params?.id || "count:" + this.serial;
914
1141
  const ret = new Promise((resolve, reject) => {
915
1142
  this.openCountRequests.set(id, { resolve, reject });
916
1143
  });
917
- this.send('["COUNT","' + id + '",' + JSON.stringify(filters).substring(1));
1144
+ try {
1145
+ await this.send('["COUNT","' + id + '",' + JSON.stringify(filters).substring(1));
1146
+ } catch (err) {
1147
+ const cr = this.openCountRequests.get(id);
1148
+ if (cr) {
1149
+ cr.reject(err);
1150
+ this.openCountRequests.delete(id);
1151
+ }
1152
+ }
918
1153
  return ret;
919
1154
  }
920
1155
  subscribe(filters, params) {
921
1156
  if (params.label !== "<forced-ping>") {
922
1157
  this.idleSince = void 0;
1158
+ this.clearIdleTimeout();
923
1159
  this.ongoingOperations++;
924
1160
  }
925
1161
  const sub = this.prepareSubscription(filters, params);
@@ -949,6 +1185,7 @@ var AbstractRelay = class {
949
1185
  this.closeAllSubscriptions("relay connection closed by us");
950
1186
  this._connected = false;
951
1187
  this.idleSince = void 0;
1188
+ this.clearIdleTimeout();
952
1189
  this.onclose?.();
953
1190
  if (this.ws?.readyState === this._WebSocket.OPEN) {
954
1191
  this.ws?.close();
@@ -992,7 +1229,7 @@ var AbstractRelay = class {
992
1229
  const payload = data[2];
993
1230
  const cr = this.openCountRequests.get(id);
994
1231
  if (cr) {
995
- cr.resolve(payload.count);
1232
+ cr.resolve(payload);
996
1233
  this.openCountRequests.delete(id);
997
1234
  }
998
1235
  return;
@@ -1022,8 +1259,14 @@ var AbstractRelay = class {
1022
1259
  case "CLOSED": {
1023
1260
  const id = data[1];
1024
1261
  const so = this.openSubs.get(id);
1025
- if (!so)
1262
+ if (!so) {
1263
+ const cr = this.openCountRequests.get(id);
1264
+ if (cr) {
1265
+ cr.reject(new Error(data[2]));
1266
+ this.openCountRequests.delete(id);
1267
+ }
1026
1268
  return;
1269
+ }
1027
1270
  so.closed = true;
1028
1271
  so.close(data[2]);
1029
1272
  return;
@@ -1120,8 +1363,10 @@ var Subscription = class {
1120
1363
  }
1121
1364
  this.relay.openSubs.delete(this.id);
1122
1365
  this.relay.ongoingOperations--;
1123
- if (this.relay.ongoingOperations === 0)
1366
+ if (this.relay.ongoingOperations === 0) {
1124
1367
  this.relay.idleSince = Date.now();
1368
+ this.relay.scheduleIdleClose();
1369
+ }
1125
1370
  this.onclose?.(reason);
1126
1371
  }
1127
1372
  };
@@ -1149,6 +1394,63 @@ var alwaysTrue = (t) => {
1149
1394
  return true;
1150
1395
  };
1151
1396
 
1397
+ // nip45.ts
1398
+ var import_sha22 = require("@noble/hashes/sha2.js");
1399
+ var import_utils5 = require("@noble/hashes/utils.js");
1400
+ var M = 256;
1401
+ var HLL_HEX_LENGTH = M * 2;
1402
+ var utf8Encoder2 = new TextEncoder();
1403
+ function getCountManyFilter(target, directive) {
1404
+ switch (directive) {
1405
+ case "reactions":
1406
+ return { "#e": [target], kinds: [7] };
1407
+ case "reposts":
1408
+ return { "#e": [target], kinds: [6] };
1409
+ case "quotes":
1410
+ return { "#q": [target], kinds: [1, 1111] };
1411
+ case "replies":
1412
+ return { "#e": [target], kinds: [1] };
1413
+ case "comments":
1414
+ return { "#E": [target], kinds: [1111] };
1415
+ case "followers":
1416
+ return { "#p": [target], kinds: [3] };
1417
+ }
1418
+ }
1419
+ function newHll() {
1420
+ return new Uint8Array(M);
1421
+ }
1422
+ function hllDecode(hex) {
1423
+ if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-fA-F]+$/.test(hex))
1424
+ return void 0;
1425
+ const registers = new Uint8Array(M);
1426
+ for (let i2 = 0; i2 < M; i2++) {
1427
+ registers[i2] = parseInt(hex.slice(i2 * 2, i2 * 2 + 2), 16);
1428
+ }
1429
+ return registers;
1430
+ }
1431
+ function hllEncode(registers) {
1432
+ if (registers.length !== M)
1433
+ throw new Error(`invalid number of registers ${registers.length}`);
1434
+ let hex = "";
1435
+ for (let i2 = 0; i2 < M; i2++) {
1436
+ hex += registers[i2].toString(16).padStart(2, "0");
1437
+ }
1438
+ return hex;
1439
+ }
1440
+ function mergeHll(target, source) {
1441
+ if (target.length === 0)
1442
+ target = newHll();
1443
+ if (target.length !== M)
1444
+ throw new Error(`invalid number of registers ${target.length}`);
1445
+ if (source.length !== M)
1446
+ throw new Error(`invalid number of registers ${source.length}`);
1447
+ for (let i2 = 0; i2 < M; i2++) {
1448
+ if (source[i2] > target[i2])
1449
+ target[i2] = source[i2];
1450
+ }
1451
+ return target;
1452
+ }
1453
+
1152
1454
  // abstract-pool.ts
1153
1455
  var AbstractSimplePool = class {
1154
1456
  relays = /* @__PURE__ */ new Map();
@@ -1157,6 +1459,7 @@ var AbstractSimplePool = class {
1157
1459
  verifyEvent;
1158
1460
  enablePing;
1159
1461
  enableReconnect;
1462
+ idleTimeout = 2e4;
1160
1463
  automaticallyAuth;
1161
1464
  trustedRelayURLs = /* @__PURE__ */ new Set();
1162
1465
  onRelayConnectionFailure;
@@ -1169,6 +1472,8 @@ var AbstractSimplePool = class {
1169
1472
  this._WebSocket = opts.websocketImplementation;
1170
1473
  this.enablePing = opts.enablePing;
1171
1474
  this.enableReconnect = opts.enableReconnect || false;
1475
+ if (opts.idleTimeout)
1476
+ this.idleTimeout = opts.idleTimeout;
1172
1477
  this.automaticallyAuth = opts.automaticallyAuth;
1173
1478
  this.onRelayConnectionFailure = opts.onRelayConnectionFailure;
1174
1479
  this.onRelayConnectionSuccess = opts.onRelayConnectionSuccess;
@@ -1183,7 +1488,8 @@ var AbstractSimplePool = class {
1183
1488
  verifyEvent: this.trustedRelayURLs.has(url) ? alwaysTrue : this.verifyEvent,
1184
1489
  websocketImplementation: this._WebSocket,
1185
1490
  enablePing: this.enablePing,
1186
- enableReconnect: this.enableReconnect
1491
+ enableReconnect: this.enableReconnect,
1492
+ idleTimeout: this.idleTimeout
1187
1493
  });
1188
1494
  relay.onclose = () => {
1189
1495
  this.relays.delete(url);
@@ -1376,6 +1682,48 @@ var AbstractSimplePool = class {
1376
1682
  events.sort((a, b) => b.created_at - a.created_at);
1377
1683
  return events[0] || null;
1378
1684
  }
1685
+ async countMany(relays, target, directive, params) {
1686
+ const filter = getCountManyFilter(target, directive);
1687
+ const urls = [];
1688
+ for (let i2 = 0; i2 < relays.length; i2++) {
1689
+ const url = normalizeURL(relays[i2]);
1690
+ if (urls.indexOf(url) === -1)
1691
+ urls.push(url);
1692
+ }
1693
+ const responses = await Promise.all(
1694
+ urls.map(async (url) => {
1695
+ if (this.allowConnectingToRelay?.(url, ["read", [filter]]) === false)
1696
+ return null;
1697
+ let relay;
1698
+ try {
1699
+ relay = await this.ensureRelay(url, {
1700
+ connectionTimeout: this.maxWaitForConnection < (params?.maxWait || 0) ? Math.max(params.maxWait * 0.8, params.maxWait - 1e3) : this.maxWaitForConnection,
1701
+ abort: params?.abort
1702
+ });
1703
+ } catch (err) {
1704
+ this.onRelayConnectionFailure?.(url);
1705
+ return null;
1706
+ }
1707
+ this.onRelayConnectionSuccess?.(url);
1708
+ return relay.countWithHLL([filter], { id: params?.id }).catch(() => null);
1709
+ })
1710
+ );
1711
+ let count = 0;
1712
+ let hll;
1713
+ for (const response of responses) {
1714
+ if (!response)
1715
+ continue;
1716
+ if (response.count > count)
1717
+ count = response.count;
1718
+ if (!response.hll || response.hll.length !== 512)
1719
+ continue;
1720
+ const registers = hllDecode(response.hll);
1721
+ if (!registers)
1722
+ continue;
1723
+ hll = mergeHll(hll || new Uint8Array(0), registers);
1724
+ }
1725
+ return hll ? { count, hll: hllEncode(hll) } : { count };
1726
+ }
1379
1727
  publish(relays, event, params) {
1380
1728
  return relays.map(normalizeURL).map(async (url, i2, arr) => {
1381
1729
  if (arr.indexOf(url) !== i2) {
@@ -1463,7 +1811,7 @@ __export(nip19_exports, {
1463
1811
  npubEncode: () => npubEncode,
1464
1812
  nsecEncode: () => nsecEncode
1465
1813
  });
1466
- var import_utils6 = require("@noble/hashes/utils.js");
1814
+ var import_utils7 = require("@noble/hashes/utils.js");
1467
1815
  var import_base = require("@scure/base");
1468
1816
  var NostrTypeGuard = {
1469
1817
  isNProfile: (value) => /^nprofile1[a-z\d]+$/.test(value || ""),
@@ -1506,7 +1854,7 @@ function decode(code) {
1506
1854
  return {
1507
1855
  type: "nprofile",
1508
1856
  data: {
1509
- pubkey: (0, import_utils6.bytesToHex)(tlv[0][0]),
1857
+ pubkey: (0, import_utils7.bytesToHex)(tlv[0][0]),
1510
1858
  relays: tlv[1] ? tlv[1].map((d) => utf8Decoder.decode(d)) : []
1511
1859
  }
1512
1860
  };
@@ -1524,10 +1872,10 @@ function decode(code) {
1524
1872
  return {
1525
1873
  type: "nevent",
1526
1874
  data: {
1527
- id: (0, import_utils6.bytesToHex)(tlv[0][0]),
1875
+ id: (0, import_utils7.bytesToHex)(tlv[0][0]),
1528
1876
  relays: tlv[1] ? tlv[1].map((d) => utf8Decoder.decode(d)) : [],
1529
- author: tlv[2]?.[0] ? (0, import_utils6.bytesToHex)(tlv[2][0]) : void 0,
1530
- kind: tlv[3]?.[0] ? parseInt((0, import_utils6.bytesToHex)(tlv[3][0]), 16) : void 0
1877
+ author: tlv[2]?.[0] ? (0, import_utils7.bytesToHex)(tlv[2][0]) : void 0,
1878
+ kind: tlv[3]?.[0] ? parseInt((0, import_utils7.bytesToHex)(tlv[3][0]), 16) : void 0
1531
1879
  }
1532
1880
  };
1533
1881
  }
@@ -1547,8 +1895,8 @@ function decode(code) {
1547
1895
  type: "naddr",
1548
1896
  data: {
1549
1897
  identifier: utf8Decoder.decode(tlv[0][0]),
1550
- pubkey: (0, import_utils6.bytesToHex)(tlv[2][0]),
1551
- kind: parseInt((0, import_utils6.bytesToHex)(tlv[3][0]), 16),
1898
+ pubkey: (0, import_utils7.bytesToHex)(tlv[2][0]),
1899
+ kind: parseInt((0, import_utils7.bytesToHex)(tlv[3][0]), 16),
1552
1900
  relays: tlv[1] ? tlv[1].map((d) => utf8Decoder.decode(d)) : []
1553
1901
  }
1554
1902
  };
@@ -1557,7 +1905,7 @@ function decode(code) {
1557
1905
  return { type: prefix, data };
1558
1906
  case "npub":
1559
1907
  case "note":
1560
- return { type: prefix, data: (0, import_utils6.bytesToHex)(data) };
1908
+ return { type: prefix, data: (0, import_utils7.bytesToHex)(data) };
1561
1909
  default:
1562
1910
  throw new Error(`unknown prefix ${prefix}`);
1563
1911
  }
@@ -1583,10 +1931,10 @@ function nsecEncode(key) {
1583
1931
  return encodeBytes("nsec", key);
1584
1932
  }
1585
1933
  function npubEncode(hex) {
1586
- return encodeBytes("npub", (0, import_utils6.hexToBytes)(hex));
1934
+ return encodeBytes("npub", (0, import_utils7.hexToBytes)(hex));
1587
1935
  }
1588
1936
  function noteEncode(hex) {
1589
- return encodeBytes("note", (0, import_utils6.hexToBytes)(hex));
1937
+ return encodeBytes("note", (0, import_utils7.hexToBytes)(hex));
1590
1938
  }
1591
1939
  function encodeBech32(prefix, data) {
1592
1940
  let words = import_base.bech32.toWords(data);
@@ -1597,7 +1945,7 @@ function encodeBytes(prefix, bytes) {
1597
1945
  }
1598
1946
  function nprofileEncode(profile) {
1599
1947
  let data = encodeTLV({
1600
- 0: [(0, import_utils6.hexToBytes)(profile.pubkey)],
1948
+ 0: [(0, import_utils7.hexToBytes)(profile.pubkey)],
1601
1949
  1: (profile.relays || []).map((url) => utf8Encoder.encode(url))
1602
1950
  });
1603
1951
  return encodeBech32("nprofile", data);
@@ -1608,9 +1956,9 @@ function neventEncode(event) {
1608
1956
  kindArray = integerToUint8Array(event.kind);
1609
1957
  }
1610
1958
  let data = encodeTLV({
1611
- 0: [(0, import_utils6.hexToBytes)(event.id)],
1959
+ 0: [(0, import_utils7.hexToBytes)(event.id)],
1612
1960
  1: (event.relays || []).map((url) => utf8Encoder.encode(url)),
1613
- 2: event.author ? [(0, import_utils6.hexToBytes)(event.author)] : [],
1961
+ 2: event.author ? [(0, import_utils7.hexToBytes)(event.author)] : [],
1614
1962
  3: kindArray ? [new Uint8Array(kindArray)] : []
1615
1963
  });
1616
1964
  return encodeBech32("nevent", data);
@@ -1621,7 +1969,7 @@ function naddrEncode(addr) {
1621
1969
  let data = encodeTLV({
1622
1970
  0: [utf8Encoder.encode(addr.identifier)],
1623
1971
  1: (addr.relays || []).map((url) => utf8Encoder.encode(url)),
1624
- 2: [(0, import_utils6.hexToBytes)(addr.pubkey)],
1972
+ 2: [(0, import_utils7.hexToBytes)(addr.pubkey)],
1625
1973
  3: [new Uint8Array(kind)]
1626
1974
  });
1627
1975
  return encodeBech32("naddr", data);
@@ -1637,7 +1985,7 @@ function encodeTLV(tlv) {
1637
1985
  entries.push(entry);
1638
1986
  });
1639
1987
  });
1640
- return (0, import_utils6.concatBytes)(...entries);
1988
+ return (0, import_utils7.concatBytes)(...entries);
1641
1989
  }
1642
1990
 
1643
1991
  // references.ts
@@ -1735,15 +2083,15 @@ __export(nip04_exports, {
1735
2083
  decrypt: () => decrypt,
1736
2084
  encrypt: () => encrypt
1737
2085
  });
1738
- var import_utils8 = require("@noble/hashes/utils.js");
2086
+ var import_utils9 = require("@noble/hashes/utils.js");
1739
2087
  var import_secp256k12 = require("@noble/curves/secp256k1.js");
1740
2088
  var import_aes = require("@noble/ciphers/aes.js");
1741
2089
  var import_base2 = require("@scure/base");
1742
2090
  function encrypt(secretKey, pubkey, text) {
1743
- const privkey = secretKey instanceof Uint8Array ? secretKey : (0, import_utils8.hexToBytes)(secretKey);
1744
- const key = import_secp256k12.secp256k1.getSharedSecret(privkey, (0, import_utils8.hexToBytes)("02" + pubkey));
2091
+ const privkey = secretKey instanceof Uint8Array ? secretKey : (0, import_utils9.hexToBytes)(secretKey);
2092
+ const key = import_secp256k12.secp256k1.getSharedSecret(privkey, (0, import_utils9.hexToBytes)("02" + pubkey));
1745
2093
  const normalizedKey = getNormalizedX(key);
1746
- let iv = Uint8Array.from((0, import_utils8.randomBytes)(16));
2094
+ let iv = Uint8Array.from((0, import_utils9.randomBytes)(16));
1747
2095
  let plaintext = utf8Encoder.encode(text);
1748
2096
  let ciphertext = (0, import_aes.cbc)(normalizedKey, iv).encrypt(plaintext);
1749
2097
  let ctb64 = import_base2.base64.encode(new Uint8Array(ciphertext));
@@ -1751,9 +2099,9 @@ function encrypt(secretKey, pubkey, text) {
1751
2099
  return `${ctb64}?iv=${ivb64}`;
1752
2100
  }
1753
2101
  function decrypt(secretKey, pubkey, data) {
1754
- const privkey = secretKey instanceof Uint8Array ? secretKey : (0, import_utils8.hexToBytes)(secretKey);
2102
+ const privkey = secretKey instanceof Uint8Array ? secretKey : (0, import_utils9.hexToBytes)(secretKey);
1755
2103
  let [ctb64, ivb64] = data.split("?iv=");
1756
- let key = import_secp256k12.secp256k1.getSharedSecret(privkey, (0, import_utils8.hexToBytes)("02" + pubkey));
2104
+ let key = import_secp256k12.secp256k1.getSharedSecret(privkey, (0, import_utils9.hexToBytes)("02" + pubkey));
1757
2105
  let normalizedKey = getNormalizedX(key);
1758
2106
  let iv = import_base2.base64.decode(ivb64);
1759
2107
  let ciphertext = import_base2.base64.decode(ctb64);
@@ -1953,8 +2301,8 @@ __export(nip13_exports, {
1953
2301
  getPow: () => getPow,
1954
2302
  minePow: () => minePow
1955
2303
  });
1956
- var import_utils10 = require("@noble/hashes/utils.js");
1957
- var import_sha22 = require("@noble/hashes/sha2.js");
2304
+ var import_utils11 = require("@noble/hashes/utils.js");
2305
+ var import_sha23 = require("@noble/hashes/sha2.js");
1958
2306
  function getPow(hex) {
1959
2307
  let count = 0;
1960
2308
  for (let i2 = 0; i2 < 64; i2 += 8) {
@@ -1993,11 +2341,11 @@ function minePow(unsigned, difficulty) {
1993
2341
  event.created_at = now2;
1994
2342
  }
1995
2343
  tag[1] = (++count).toString();
1996
- const hash = (0, import_sha22.sha256)(
2344
+ const hash = (0, import_sha23.sha256)(
1997
2345
  utf8Encoder.encode(JSON.stringify([0, event.pubkey, event.created_at, event.kind, event.tags, event.content]))
1998
2346
  );
1999
2347
  if (getPowFromBytes(hash) >= difficulty) {
2000
- event.id = (0, import_utils10.bytesToHex)(hash);
2348
+ event.id = (0, import_utils11.bytesToHex)(hash);
2001
2349
  break;
2002
2350
  }
2003
2351
  }
@@ -2034,22 +2382,22 @@ __export(nip44_exports, {
2034
2382
  v2: () => v2
2035
2383
  });
2036
2384
  var import_chacha = require("@noble/ciphers/chacha.js");
2037
- var import_utils12 = require("@noble/ciphers/utils.js");
2385
+ var import_utils13 = require("@noble/ciphers/utils.js");
2038
2386
  var import_secp256k13 = require("@noble/curves/secp256k1.js");
2039
2387
  var import_hkdf = require("@noble/hashes/hkdf.js");
2040
2388
  var import_hmac = require("@noble/hashes/hmac.js");
2041
- var import_sha23 = require("@noble/hashes/sha2.js");
2042
- var import_utils13 = require("@noble/hashes/utils.js");
2389
+ var import_sha24 = require("@noble/hashes/sha2.js");
2390
+ var import_utils14 = require("@noble/hashes/utils.js");
2043
2391
  var import_base3 = require("@scure/base");
2044
2392
  var minPlaintextSize = 1;
2045
2393
  var maxPlaintextSize = 4294967295;
2046
2394
  var extendedPrefixThreshold = 65536;
2047
2395
  function getConversationKey(privkeyA, pubkeyB) {
2048
- const sharedX = import_secp256k13.secp256k1.getSharedSecret(privkeyA, (0, import_utils13.hexToBytes)("02" + pubkeyB)).subarray(1, 33);
2049
- return (0, import_hkdf.extract)(import_sha23.sha256, sharedX, utf8Encoder.encode("nip44-v2"));
2396
+ const sharedX = import_secp256k13.secp256k1.getSharedSecret(privkeyA, (0, import_utils14.hexToBytes)("02" + pubkeyB)).subarray(1, 33);
2397
+ return (0, import_hkdf.extract)(import_sha24.sha256, sharedX, utf8Encoder.encode("nip44-v2"));
2050
2398
  }
2051
2399
  function getMessageKeys(conversationKey, nonce) {
2052
- const keys = (0, import_hkdf.expand)(import_sha23.sha256, conversationKey, nonce, 76);
2400
+ const keys = (0, import_hkdf.expand)(import_sha24.sha256, conversationKey, nonce, 76);
2053
2401
  return {
2054
2402
  chacha_key: keys.subarray(0, 32),
2055
2403
  chacha_nonce: keys.subarray(32, 44),
@@ -2084,9 +2432,9 @@ function pad(plaintext) {
2084
2432
  const unpaddedLen = unpadded.length;
2085
2433
  if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize)
2086
2434
  throw new Error("invalid plaintext size: must be between 1 and 4294967295 bytes");
2087
- const prefix = unpaddedLen >= extendedPrefixThreshold ? (0, import_utils13.concatBytes)(new Uint8Array([0, 0]), writeU32BE(unpaddedLen)) : writeU16BE(unpaddedLen);
2435
+ const prefix = unpaddedLen >= extendedPrefixThreshold ? (0, import_utils14.concatBytes)(new Uint8Array([0, 0]), writeU32BE(unpaddedLen)) : writeU16BE(unpaddedLen);
2088
2436
  const suffix = new Uint8Array(calcPaddedLen(unpaddedLen) - unpaddedLen);
2089
- return (0, import_utils13.concatBytes)(prefix, unpadded, suffix);
2437
+ return (0, import_utils14.concatBytes)(prefix, unpadded, suffix);
2090
2438
  }
2091
2439
  function unpad(padded) {
2092
2440
  const dv = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);
@@ -2110,8 +2458,8 @@ function unpad(padded) {
2110
2458
  function hmacAad(key, message, aad) {
2111
2459
  if (aad.length !== 32)
2112
2460
  throw new Error("AAD associated data must be 32 bytes");
2113
- const combined = (0, import_utils13.concatBytes)(aad, message);
2114
- return (0, import_hmac.hmac)(import_sha23.sha256, key, combined);
2461
+ const combined = (0, import_utils14.concatBytes)(aad, message);
2462
+ return (0, import_hmac.hmac)(import_sha24.sha256, key, combined);
2115
2463
  }
2116
2464
  function decodePayload(payload) {
2117
2465
  if (typeof payload !== "string")
@@ -2139,18 +2487,18 @@ function decodePayload(payload) {
2139
2487
  mac: data.subarray(-32)
2140
2488
  };
2141
2489
  }
2142
- function encrypt2(plaintext, conversationKey, nonce = (0, import_utils13.randomBytes)(32)) {
2490
+ function encrypt2(plaintext, conversationKey, nonce = (0, import_utils14.randomBytes)(32)) {
2143
2491
  const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
2144
2492
  const padded = pad(plaintext);
2145
2493
  const ciphertext = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, padded);
2146
2494
  const mac = hmacAad(hmac_key, ciphertext, nonce);
2147
- return import_base3.base64.encode((0, import_utils13.concatBytes)(new Uint8Array([2]), nonce, ciphertext, mac));
2495
+ return import_base3.base64.encode((0, import_utils14.concatBytes)(new Uint8Array([2]), nonce, ciphertext, mac));
2148
2496
  }
2149
2497
  function decrypt2(payload, conversationKey) {
2150
2498
  const { nonce, ciphertext, mac } = decodePayload(payload);
2151
2499
  const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
2152
2500
  const calculatedMac = hmacAad(hmac_key, ciphertext, nonce);
2153
- if (!(0, import_utils12.equalBytes)(calculatedMac, mac))
2501
+ if (!(0, import_utils13.equalBytes)(calculatedMac, mac))
2154
2502
  throw new Error("invalid MAC");
2155
2503
  const padded = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, ciphertext);
2156
2504
  return unpad(padded);
@@ -3070,8 +3418,8 @@ __export(nip77_exports, {
3070
3418
  NegentropyStorageVector: () => NegentropyStorageVector,
3071
3419
  NegentropySync: () => NegentropySync
3072
3420
  });
3073
- var import_utils16 = require("@noble/hashes/utils.js");
3074
- var import_sha24 = require("@noble/hashes/sha2.js");
3421
+ var import_utils17 = require("@noble/hashes/utils.js");
3422
+ var import_sha25 = require("@noble/hashes/sha2.js");
3075
3423
  var PROTOCOL_VERSION = 97;
3076
3424
  var ID_SIZE = 32;
3077
3425
  var FINGERPRINT_SIZE = 16;
@@ -3202,7 +3550,7 @@ var Accumulator = class {
3202
3550
  let input = new WrappedBuffer();
3203
3551
  input.extend(this.buf);
3204
3552
  input.extend(encodeVarInt(n));
3205
- let hash = (0, import_sha24.sha256)(input.unwrap());
3553
+ let hash = (0, import_sha25.sha256)(input.unwrap());
3206
3554
  return hash.subarray(0, FINGERPRINT_SIZE);
3207
3555
  }
3208
3556
  };
@@ -3216,7 +3564,7 @@ var NegentropyStorageVector = class {
3216
3564
  insert(timestamp, id) {
3217
3565
  if (this.sealed)
3218
3566
  throw Error("already sealed");
3219
- const idb = (0, import_utils16.hexToBytes)(id);
3567
+ const idb = (0, import_utils17.hexToBytes)(id);
3220
3568
  if (idb.byteLength !== ID_SIZE)
3221
3569
  throw Error("bad id size for added item");
3222
3570
  this.items.push({ timestamp, id: idb });
@@ -3310,10 +3658,10 @@ var Negentropy = class {
3310
3658
  let output = new WrappedBuffer();
3311
3659
  output.extend(new Uint8Array([PROTOCOL_VERSION]));
3312
3660
  this.splitRange(0, this.storage.size(), this._bound(Number.MAX_VALUE), output);
3313
- return (0, import_utils16.bytesToHex)(output.unwrap());
3661
+ return (0, import_utils17.bytesToHex)(output.unwrap());
3314
3662
  }
3315
3663
  reconcile(queryMsg, onhave, onneed) {
3316
- const query = new WrappedBuffer((0, import_utils16.hexToBytes)(queryMsg));
3664
+ const query = new WrappedBuffer((0, import_utils17.hexToBytes)(queryMsg));
3317
3665
  this.lastTimestampIn = this.lastTimestampOut = 0;
3318
3666
  let fullOutput = new WrappedBuffer();
3319
3667
  fullOutput.extend(new Uint8Array([PROTOCOL_VERSION]));
@@ -3356,22 +3704,22 @@ var Negentropy = class {
3356
3704
  let theirElems = {};
3357
3705
  for (let i2 = 0; i2 < numIds; i2++) {
3358
3706
  let e = getBytes(query, ID_SIZE);
3359
- theirElems[(0, import_utils16.bytesToHex)(e)] = e;
3707
+ theirElems[(0, import_utils17.bytesToHex)(e)] = e;
3360
3708
  }
3361
3709
  skip = true;
3362
3710
  this.storage.iterate(lower, upper, (item) => {
3363
3711
  let k = item.id;
3364
- const id = (0, import_utils16.bytesToHex)(k);
3712
+ const id = (0, import_utils17.bytesToHex)(k);
3365
3713
  if (!theirElems[id]) {
3366
3714
  onhave?.(id);
3367
3715
  } else {
3368
- delete theirElems[(0, import_utils16.bytesToHex)(k)];
3716
+ delete theirElems[(0, import_utils17.bytesToHex)(k)];
3369
3717
  }
3370
3718
  return true;
3371
3719
  });
3372
3720
  if (onneed) {
3373
3721
  for (let v of Object.values(theirElems)) {
3374
- onneed((0, import_utils16.bytesToHex)(v));
3722
+ onneed((0, import_utils17.bytesToHex)(v));
3375
3723
  }
3376
3724
  }
3377
3725
  } else {
@@ -3389,7 +3737,7 @@ var Negentropy = class {
3389
3737
  prevIndex = upper;
3390
3738
  prevBound = currBound;
3391
3739
  }
3392
- return fullOutput.length === 1 ? null : (0, import_utils16.bytesToHex)(fullOutput.unwrap());
3740
+ return fullOutput.length === 1 ? null : (0, import_utils17.bytesToHex)(fullOutput.unwrap());
3393
3741
  }
3394
3742
  splitRange(lower, upper, upperBound, o) {
3395
3743
  let numElems = upper - lower;
@@ -3577,8 +3925,8 @@ __export(nip98_exports, {
3577
3925
  validateEventUrlTag: () => validateEventUrlTag,
3578
3926
  validateToken: () => validateToken
3579
3927
  });
3580
- var import_sha25 = require("@noble/hashes/sha2.js");
3581
- var import_utils17 = require("@noble/hashes/utils.js");
3928
+ var import_sha26 = require("@noble/hashes/sha2.js");
3929
+ var import_utils18 = require("@noble/hashes/utils.js");
3582
3930
  var import_base5 = require("@scure/base");
3583
3931
  var _authorizationScheme = "Nostr ";
3584
3932
  async function getToken(loginUrl, httpMethod, sign, includeAuthorizationScheme = false, payload) {
@@ -3643,8 +3991,8 @@ function validateEventMethodTag(event, method) {
3643
3991
  return methodTag.length > 0 && methodTag[1].toLowerCase() === method.toLowerCase();
3644
3992
  }
3645
3993
  function hashPayload(payload) {
3646
- const hash = (0, import_sha25.sha256)(utf8Encoder.encode(JSON.stringify(payload)));
3647
- return (0, import_utils17.bytesToHex)(hash);
3994
+ const hash = (0, import_sha26.sha256)(utf8Encoder.encode(JSON.stringify(payload)));
3995
+ return (0, import_utils18.bytesToHex)(hash);
3648
3996
  }
3649
3997
  function validateEventPayloadTag(event, payload) {
3650
3998
  const payloadTag = event.tags.find((t) => t[0] === "payload");