@pkcprotocol/pkc-js 0.0.72 → 0.0.74

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 (114) hide show
  1. package/README.md +1 -0
  2. package/dist/browser/clients/base-client-manager.d.ts +1 -0
  3. package/dist/browser/clients/base-client-manager.js +9 -2
  4. package/dist/browser/clients/base-client-manager.js.map +1 -1
  5. package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +1 -0
  6. package/dist/browser/clients/rpc-client/schema.d.ts +1 -0
  7. package/dist/browser/community/community-client-manager.d.ts +1 -0
  8. package/dist/browser/community/community-client-manager.js +7 -0
  9. package/dist/browser/community/community-client-manager.js.map +1 -1
  10. package/dist/browser/community/remote-community.js +18 -9
  11. package/dist/browser/community/remote-community.js.map +1 -1
  12. package/dist/browser/community/schema.d.ts +6 -0
  13. package/dist/browser/community/schema.js +4 -1
  14. package/dist/browser/community/schema.js.map +1 -1
  15. package/dist/browser/community/types.d.ts +1 -0
  16. package/dist/browser/errors.d.ts +2 -0
  17. package/dist/browser/errors.js +2 -0
  18. package/dist/browser/errors.js.map +1 -1
  19. package/dist/browser/generated-version.d.ts +1 -1
  20. package/dist/browser/generated-version.js +1 -1
  21. package/dist/browser/pkc-error.d.ts +1 -1
  22. package/dist/browser/publications/community-edit/schema.d.ts +4 -0
  23. package/dist/browser/publications/publication.d.ts +2 -1
  24. package/dist/browser/publications/publication.js +63 -24
  25. package/dist/browser/publications/publication.js.map +1 -1
  26. package/dist/browser/pubsub-messages/schema.d.ts +2 -0
  27. package/dist/browser/runtime/node/community/db-handler.d.ts +1 -0
  28. package/dist/browser/runtime/node/community/db-handler.js +9 -1
  29. package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
  30. package/dist/browser/runtime/node/community/local-community/challenges.js +26 -25
  31. package/dist/browser/runtime/node/community/local-community/challenges.js.map +1 -1
  32. package/dist/browser/runtime/node/community/local-community/comment-updates.d.ts +2 -1
  33. package/dist/browser/runtime/node/community/local-community/comment-updates.js +14 -2
  34. package/dist/browser/runtime/node/community/local-community/comment-updates.js.map +1 -1
  35. package/dist/browser/runtime/node/community/local-community/db-state.js +12 -1
  36. package/dist/browser/runtime/node/community/local-community/db-state.js.map +1 -1
  37. package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +22 -1
  38. package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
  39. package/dist/browser/runtime/node/community/local-community/lifecycle.js +17 -5
  40. package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
  41. package/dist/browser/runtime/node/community/local-community/pubsub.js +42 -4
  42. package/dist/browser/runtime/node/community/local-community/pubsub.js.map +1 -1
  43. package/dist/browser/runtime/node/community/local-community.d.ts +1 -0
  44. package/dist/browser/runtime/node/community/local-community.js +10 -1
  45. package/dist/browser/runtime/node/community/local-community.js.map +1 -1
  46. package/dist/browser/schema/schema-util.d.ts +4 -0
  47. package/dist/browser/signer/signatures.d.ts +4 -4
  48. package/dist/browser/signer/signatures.js +23 -4
  49. package/dist/browser/signer/signatures.js.map +1 -1
  50. package/dist/browser/test/test-util.d.ts +3 -0
  51. package/dist/browser/test/test-util.js +15 -1
  52. package/dist/browser/test/test-util.js.map +1 -1
  53. package/dist/bundled/bundle-manifest.json +31 -31
  54. package/dist/bundled/chunks/{helia-for-pkc-BcZhGLB0.js → helia-for-pkc-B-75U9z9.js} +2 -2
  55. package/dist/bundled/chunks/{local-community-DWf7A4hj.js → local-community-Br1ipu1Z.js} +77 -32
  56. package/dist/bundled/chunks/{local-community-Cd5HOxwM.js → local-community-CIVs_iuS.js} +1 -1
  57. package/dist/bundled/chunks/{node-sP-twQPW.js → node-Cn7VaPDJ.js} +53 -27
  58. package/dist/bundled/chunks/{rpc-local-community-ZxNkZCBr.js → rpc-local-community-DtdeJBOq.js} +22 -11
  59. package/dist/bundled/chunks/{schema-B3duXSG7.js → schema-B1Ot-kux.js} +5 -2
  60. package/dist/bundled/chunks/{util-DOWWxZIE.js → util-B6v5HAdy.js} +1 -1
  61. package/dist/bundled/index.js +1 -1
  62. package/dist/bundled/rpc/src/index.js +4 -4
  63. package/dist/node/clients/base-client-manager.d.ts +1 -0
  64. package/dist/node/clients/base-client-manager.js +9 -2
  65. package/dist/node/clients/base-client-manager.js.map +1 -1
  66. package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +1 -0
  67. package/dist/node/clients/rpc-client/schema.d.ts +1 -0
  68. package/dist/node/community/community-client-manager.d.ts +1 -0
  69. package/dist/node/community/community-client-manager.js +7 -0
  70. package/dist/node/community/community-client-manager.js.map +1 -1
  71. package/dist/node/community/remote-community.js +18 -9
  72. package/dist/node/community/remote-community.js.map +1 -1
  73. package/dist/node/community/schema.d.ts +6 -0
  74. package/dist/node/community/schema.js +4 -1
  75. package/dist/node/community/schema.js.map +1 -1
  76. package/dist/node/community/types.d.ts +1 -0
  77. package/dist/node/errors.d.ts +2 -0
  78. package/dist/node/errors.js +2 -0
  79. package/dist/node/errors.js.map +1 -1
  80. package/dist/node/generated-version.d.ts +1 -1
  81. package/dist/node/generated-version.js +1 -1
  82. package/dist/node/pkc-error.d.ts +1 -1
  83. package/dist/node/publications/community-edit/schema.d.ts +4 -0
  84. package/dist/node/publications/publication.d.ts +2 -1
  85. package/dist/node/publications/publication.js +63 -24
  86. package/dist/node/publications/publication.js.map +1 -1
  87. package/dist/node/pubsub-messages/schema.d.ts +2 -0
  88. package/dist/node/runtime/node/community/db-handler.d.ts +1 -0
  89. package/dist/node/runtime/node/community/db-handler.js +9 -1
  90. package/dist/node/runtime/node/community/db-handler.js.map +1 -1
  91. package/dist/node/runtime/node/community/local-community/challenges.js +26 -25
  92. package/dist/node/runtime/node/community/local-community/challenges.js.map +1 -1
  93. package/dist/node/runtime/node/community/local-community/comment-updates.d.ts +2 -1
  94. package/dist/node/runtime/node/community/local-community/comment-updates.js +14 -2
  95. package/dist/node/runtime/node/community/local-community/comment-updates.js.map +1 -1
  96. package/dist/node/runtime/node/community/local-community/db-state.js +12 -1
  97. package/dist/node/runtime/node/community/local-community/db-state.js.map +1 -1
  98. package/dist/node/runtime/node/community/local-community/ipns-publishing.js +22 -1
  99. package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
  100. package/dist/node/runtime/node/community/local-community/lifecycle.js +17 -5
  101. package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
  102. package/dist/node/runtime/node/community/local-community/pubsub.js +42 -4
  103. package/dist/node/runtime/node/community/local-community/pubsub.js.map +1 -1
  104. package/dist/node/runtime/node/community/local-community.d.ts +1 -0
  105. package/dist/node/runtime/node/community/local-community.js +10 -1
  106. package/dist/node/runtime/node/community/local-community.js.map +1 -1
  107. package/dist/node/schema/schema-util.d.ts +4 -0
  108. package/dist/node/signer/signatures.d.ts +4 -4
  109. package/dist/node/signer/signatures.js +23 -4
  110. package/dist/node/signer/signatures.js.map +1 -1
  111. package/dist/node/test/test-util.d.ts +3 -0
  112. package/dist/node/test/test-util.js +15 -1
  113. package/dist/node/test/test-util.js.map +1 -1
  114. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
2
- import { $ as pubsubTopicToDhtKey, $n as t$7, At as trackStartedCommunity, Bt as CommunityEditPublicationPubsubReservedFields, C as contentContainsMarkdownAudio, Ct as findUpdatingCommunity, En as CommentUpdateSchema, F as getIpnsRecordInLocalKuboNode, Fn as CommentEditPubsubMessagePublicationSchema, Ft as untrackUpdatingCommunity, G as isLinkOfAudio, Gt as CommentModerationPubsubMessagePublicationSchema, In as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, It as require_sha256, J as isLinkOfVideo, Jt as CommentModerationsTableRowSchema, K as isLinkOfImage, Kt as CommentModerationReservedFields, L as hideClassPrivateProps, Ln as CommentEditReservedFields, M as genToArray, Mr as ZodError, Mt as trackUpdatingCommunity, N as getEquivalentCommunityAddresses, Nt as untrackStartedCommunity, O as derivePublicationFromChallengeRequest, On as CommentUpdateTableRowSchema, P as getErrorCodeFromMessage, Q as isStringDomain, Qn as n$3, R as ipnsNameToIpnsOverPubsubTopic, Rt as pTimeout, S as calculateStringSizeSameAsIpfsAddCidV0, T as contentContainsMarkdownVideos, Un as AuthorReservedFields, W as isLinkOfAnimatedImage, Xn as n$4, Y as isLinkValid, Zn as t$8, _r as PKCError, _t as timestamp, a as ChallengeRequestMessageSchema, ar as t$4, at as removeNullUndefinedValues, b as areEquivalentCommunityAddresses, bt as findCommunityInRegistry, cr as t$5, d as DecryptedChallengeRequestSchema, dr as require_retry, dt as retryKuboIpfsAddAndProvide, er as t$6, fn as VotePubsubMessagePublicationSchema, hn as VoteTablesRowSchema, ht as statMfsPathSafely, ir as r$1, k as doesDomainAddressHaveCapitalLetter, kn as CommentsTableRowSchema, kt as syncCommunityRegistryEntry, lr as t$3, lt as retryKuboBlockPutPinAndProvidePubsubTopic, mt as sleepUntilTimeoutOrAbort, nn as CommunityIpfsSchema, nr as e$1, nt as removeBlocksFromKuboNode, pn as VotePubsubReservedFields, q as isLinkOfMedia, r as ChallengeMessageSchema, rn as CommunitySignedPropertyNames, rt as removeMfsFilesSafely, s as ChallengeVerificationMessageSchema, t as ChallengeAnswerMessageSchema, tr as e, u as DecryptedChallengeRequestPublicationSchema, vn as CommentIpfsSchema, vr as messages, w as contentContainsMarkdownImages, x as calculateIpfsCidV0, xt as findStartedCommunity, y as version_default, yn as CommentPubsubMessageReservedFields, yr as logger_default, yt as writeKuboFilesWithTimeout, zn as CommentEditsTableRowSchema } from "./schema-B3duXSG7.js";
3
- import { $n as t$10, A as deriveDbPosts, At as verifyCommunityEdit, Bt as getCommunityPublicKeyFromWire, C as BackupAbortError, Dt as verifyCommentPubsubMessage, E as calculateInlineRepliesBudget, Et as verifyCommentModeration, F as importSignerIntoKuboNode, Ft as getAuthorNameFromWire, G as REPLY_REPLIES_SORT_TYPES, Gt as getIpfsKeyFromPrivateKey, Ht as decode, Jn as r$2, Jt as getPublicKeyFromPrivateKey, K as TIMEFRAMES_TO_SECONDS, Kn as t$9, Kt as getPKCAddressFromPublicKey, M as getDefaultCommunityDbConfig, Mt as buildRuntimeAuthor, Nt as cleanWireAuthor, O as deleteOldCommunityInWindows, Ot as verifyCommentUpdate, P as getThumbnailPropsOfLink, R as moveCommunityDbToDeletedDirectory, S as encryptEd25519AesGcmPublicKeyBuffer, St as verifyChallengeRequest, T as calculateExpectedSignatureSize, Tt as verifyCommentIpfs, U as POSTS_SORT_TYPES, Ut as encode, W as POST_REPLIES_SORT_TYPES, Xn as n$6, Yn as t$11, Yt as createSchemaRowParser, Z as iterateOverPageCidsToFindAllCids, Zn as n$5, _ as SignerWithPublicKeyAddress, _t as signCommunity, a as pkcJsChallenges, b as decryptEd25519AesGcmPublicKeyBuffer, bt as verifyChallengeAnswer, cn as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, d as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, dt as signChallengeVerification, er as stringify, f as KeyvBetterSqlite3, ft as signComment, gt as signCommentUpdateForChallengeVerification, ht as signCommentUpdate, i as getCommunityChallengeFromCommunityChallengeSettings, it as pLimit, j as deriveDbReplies, jt as verifyVote, k as deriveCommentIpfsFromCommentTableRow, kt as verifyCommunity, l as normalizeSelfAddrsForProvider, lt as signChallengeMessage, nr as require_lodash_merge, o as TrackedInstanceRegistry, on as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, pt as signCommentEdit, qn as t$12, qt as getPKCAddressFromPublicKeySync, r as getChallengeVerification, s as LRUCache, st as cleanUpBeforePublishing, t as RpcLocalCommunity, tr as STORAGE_KEYS, vn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, w as backupCommunityDb, wt as verifyCommentEdit, xn as parseJsonWithPKCErrorIfFails, z as resolveDbPostsCidRefs, zt as getCommunityNameFromWire } from "./rpc-local-community-ZxNkZCBr.js";
2
+ import { $ as pubsubTopicToDhtKey, $n as t$7, At as trackStartedCommunity, Bt as CommunityEditPublicationPubsubReservedFields, C as contentContainsMarkdownAudio, Ct as findUpdatingCommunity, En as CommentUpdateSchema, F as getIpnsRecordInLocalKuboNode, Fn as CommentEditPubsubMessagePublicationSchema, Ft as untrackUpdatingCommunity, G as isLinkOfAudio, Gt as CommentModerationPubsubMessagePublicationSchema, In as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, It as require_sha256, J as isLinkOfVideo, Jt as CommentModerationsTableRowSchema, K as isLinkOfImage, Kt as CommentModerationReservedFields, L as hideClassPrivateProps, Ln as CommentEditReservedFields, M as genToArray, Mr as ZodError, Mt as trackUpdatingCommunity, N as getEquivalentCommunityAddresses, Nt as untrackStartedCommunity, O as derivePublicationFromChallengeRequest, On as CommentUpdateTableRowSchema, P as getErrorCodeFromMessage, Q as isStringDomain, Qn as n$3, R as ipnsNameToIpnsOverPubsubTopic, Rt as pTimeout, S as calculateStringSizeSameAsIpfsAddCidV0, T as contentContainsMarkdownVideos, Un as AuthorReservedFields, W as isLinkOfAnimatedImage, Xn as n$4, Y as isLinkValid, Zn as t$8, _r as PKCError, _t as timestamp, a as ChallengeRequestMessageSchema, ar as t$4, at as removeNullUndefinedValues, b as areEquivalentCommunityAddresses, bt as findCommunityInRegistry, cr as t$5, d as DecryptedChallengeRequestSchema, dr as require_retry, dt as retryKuboIpfsAddAndProvide, er as t$6, fn as VotePubsubMessagePublicationSchema, hn as VoteTablesRowSchema, ht as statMfsPathSafely, ir as r$1, k as doesDomainAddressHaveCapitalLetter, kn as CommentsTableRowSchema, kt as syncCommunityRegistryEntry, lr as t$3, lt as retryKuboBlockPutPinAndProvidePubsubTopic, mt as sleepUntilTimeoutOrAbort, nn as CommunityIpfsSchema, nr as e$1, nt as removeBlocksFromKuboNode, pn as VotePubsubReservedFields, q as isLinkOfMedia, r as ChallengeMessageSchema, rn as CommunitySignedPropertyNames, rt as removeMfsFilesSafely, s as ChallengeVerificationMessageSchema, t as ChallengeAnswerMessageSchema, tr as e, u as DecryptedChallengeRequestPublicationSchema, vn as CommentIpfsSchema, vr as messages, w as contentContainsMarkdownImages, x as calculateIpfsCidV0, xt as findStartedCommunity, y as version_default, yn as CommentPubsubMessageReservedFields, yr as logger_default, yt as writeKuboFilesWithTimeout, zn as CommentEditsTableRowSchema } from "./schema-B1Ot-kux.js";
3
+ import { $n as t$10, A as deriveDbPosts, At as verifyCommunityEdit, Bt as getCommunityPublicKeyFromWire, C as BackupAbortError, Dt as verifyCommentPubsubMessage, E as calculateInlineRepliesBudget, Et as verifyCommentModeration, F as importSignerIntoKuboNode, Ft as getAuthorNameFromWire, G as REPLY_REPLIES_SORT_TYPES, Gt as getIpfsKeyFromPrivateKey, Ht as decode, Jn as r$2, Jt as getPublicKeyFromPrivateKey, K as TIMEFRAMES_TO_SECONDS, Kn as t$9, Kt as getPKCAddressFromPublicKey, M as getDefaultCommunityDbConfig, Mt as buildRuntimeAuthor, Nt as cleanWireAuthor, O as deleteOldCommunityInWindows, Ot as verifyCommentUpdate, P as getThumbnailPropsOfLink, R as moveCommunityDbToDeletedDirectory, S as encryptEd25519AesGcmPublicKeyBuffer, St as verifyChallengeRequest, T as calculateExpectedSignatureSize, Tt as verifyCommentIpfs, U as POSTS_SORT_TYPES, Ut as encode, W as POST_REPLIES_SORT_TYPES, Xn as n$6, Yn as t$11, Yt as createSchemaRowParser, Z as iterateOverPageCidsToFindAllCids, Zn as n$5, _ as SignerWithPublicKeyAddress, _t as signCommunity, a as pkcJsChallenges, b as decryptEd25519AesGcmPublicKeyBuffer, bt as verifyChallengeAnswer, cn as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, d as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, dt as signChallengeVerification, er as stringify, f as KeyvBetterSqlite3, ft as signComment, gt as signCommentUpdateForChallengeVerification, ht as signCommentUpdate, i as getCommunityChallengeFromCommunityChallengeSettings, it as pLimit, j as deriveDbReplies, jt as verifyVote, k as deriveCommentIpfsFromCommentTableRow, kt as verifyCommunity, l as normalizeSelfAddrsForProvider, lt as signChallengeMessage, nr as require_lodash_merge, o as TrackedInstanceRegistry, on as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, pt as signCommentEdit, qn as t$12, qt as getPKCAddressFromPublicKeySync, r as getChallengeVerification, s as LRUCache, st as cleanUpBeforePublishing, t as RpcLocalCommunity, tr as STORAGE_KEYS, vn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, w as backupCommunityDb, wt as verifyCommentEdit, xn as parseJsonWithPKCErrorIfFails, z as resolveDbPostsCidRefs, zt as getCommunityNameFromWire } from "./rpc-local-community-DtdeJBOq.js";
4
4
  import { randomFillSync, randomUUID } from "node:crypto";
5
5
  import { fileURLToPath, pathToFileURL } from "node:url";
6
6
  import path from "node:path";
@@ -65,8 +65,12 @@ function r(t) {
65
65
  }
66
66
  //#endregion
67
67
  //#region dist/node/runtime/node/community/local-community/comment-updates.js
68
- function pubsubTopicWithfallback(community) {
69
- return community.pubsubTopic || community.address;
68
+ function communityChallengePubsubTopic(community) {
69
+ return community.pubsubTopic || community.signer?.address;
70
+ }
71
+ function challengeExchangePubsubTopic(community) {
72
+ if (community.settings?.disablePubsubChallengeExchange) return void 0;
73
+ return communityChallengePubsubTopic(community);
70
74
  }
71
75
  function calculateLocalMfsPathForCommentUpdate(community, postDbComment, timestampRange) {
72
76
  return [
@@ -480,11 +484,11 @@ async function publishChallenges(community, challenges, request) {
480
484
  signer: community.signer
481
485
  })
482
486
  };
483
- const pubsubClient = community._clientsManager.getDefaultKuboPubsubClient();
484
- community._clientsManager.updateKuboRpcPubsubState("publishing-challenge", pubsubClient.url);
485
- if (!community._challengeExchangesFromLocalPublishers[request.challengeRequestId.toString()]) await community._clientsManager.pubsubPublish(pubsubTopicWithfallback(community), challengeMessage);
486
- log(`Community ${community.address} with pubsub topic ${pubsubTopicWithfallback(community)} published ${challengeMessage.type} over pubsub: `, t$9(toSignChallenge, ["timestamp"]), toEncryptChallenge.challenges.map((challenge) => challenge.type));
487
- community._clientsManager.updateKuboRpcPubsubState("waiting-challenge-answers", pubsubClient.url);
487
+ community._clientsManager.updateKuboRpcPubsubStateIfProviderExists("publishing-challenge");
488
+ const challengeTopic = challengeExchangePubsubTopic(community);
489
+ if (challengeTopic && !community._challengeExchangesFromLocalPublishers[request.challengeRequestId.toString()]) await community._clientsManager.pubsubPublish(challengeTopic, challengeMessage);
490
+ log(`Community ${community.address} with pubsub topic ${challengeTopic} published ${challengeMessage.type} over pubsub: `, t$9(toSignChallenge, ["timestamp"]), toEncryptChallenge.challenges.map((challenge) => challenge.type));
491
+ community._clientsManager.updateKuboRpcPubsubStateIfProviderExists("waiting-challenge-answers");
488
492
  community.emit("challenge", {
489
493
  ...challengeMessage,
490
494
  challenges
@@ -509,11 +513,11 @@ async function publishFailedChallengeVerification(community, result, challengeRe
509
513
  signer: community.signer
510
514
  })
511
515
  };
512
- const pubsubClient = community._clientsManager.getDefaultKuboPubsubClient();
513
- community._clientsManager.updateKuboRpcPubsubState("publishing-challenge-verification", pubsubClient.url);
514
- log(`Will publish ${challengeVerification.type} over pubsub topic ${pubsubTopicWithfallback(community)} on community ${community.address}:`, n$3(toSignVerification, ["challengeRequestId"]));
515
- if (!community._challengeExchangesFromLocalPublishers[challengeRequestId.toString()]) await community._clientsManager.pubsubPublish(pubsubTopicWithfallback(community), challengeVerification);
516
- community._clientsManager.updateKuboRpcPubsubState("waiting-challenge-requests", pubsubClient.url);
516
+ community._clientsManager.updateKuboRpcPubsubStateIfProviderExists("publishing-challenge-verification");
517
+ const challengeTopic = challengeExchangePubsubTopic(community);
518
+ log(`Will publish ${challengeVerification.type} over pubsub topic ${challengeTopic} on community ${community.address}:`, n$3(toSignVerification, ["challengeRequestId"]));
519
+ if (challengeTopic && !community._challengeExchangesFromLocalPublishers[challengeRequestId.toString()]) await community._clientsManager.pubsubPublish(challengeTopic, challengeVerification);
520
+ community._clientsManager.updateKuboRpcPubsubStateIfProviderExists("waiting-challenge-requests");
517
521
  community.emit("challengeverification", challengeVerification);
518
522
  community._ongoingChallengeExchanges.delete(challengeRequestId.toString());
519
523
  delete community._challengeExchangesFromLocalPublishers[challengeRequestId.toString()];
@@ -568,10 +572,10 @@ async function publishIdempotentDuplicateVerification(community, request, challe
568
572
  signer: community.signer
569
573
  })
570
574
  };
571
- const pubsubClient = community._clientsManager.getDefaultKuboPubsubClient();
572
- community._clientsManager.updateKuboRpcPubsubState("publishing-challenge-verification", pubsubClient.url);
573
- if (!community._challengeExchangesFromLocalPublishers[challengeRequestId.toString()]) await community._clientsManager.pubsubPublish(pubsubTopicWithfallback(community), challengeVerification);
574
- community._clientsManager.updateKuboRpcPubsubState("waiting-challenge-requests", pubsubClient.url);
575
+ community._clientsManager.updateKuboRpcPubsubStateIfProviderExists("publishing-challenge-verification");
576
+ const challengeTopic = challengeExchangePubsubTopic(community);
577
+ if (challengeTopic && !community._challengeExchangesFromLocalPublishers[challengeRequestId.toString()]) await community._clientsManager.pubsubPublish(challengeTopic, challengeVerification);
578
+ community._clientsManager.updateKuboRpcPubsubStateIfProviderExists("waiting-challenge-requests");
575
579
  const objectToEmit = {
576
580
  ...challengeVerification,
577
581
  ...toEncryptDecrypted
@@ -649,10 +653,10 @@ async function publishChallengeVerification(community, challengeResult, request,
649
653
  signer: community.signer
650
654
  })
651
655
  };
652
- const pubsubClient = community._clientsManager.getDefaultKuboPubsubClient();
653
- community._clientsManager.updateKuboRpcPubsubState("publishing-challenge-verification", pubsubClient.url);
654
- if (!community._challengeExchangesFromLocalPublishers[request.challengeRequestId.toString()]) await community._clientsManager.pubsubPublish(pubsubTopicWithfallback(community), challengeVerification);
655
- community._clientsManager.updateKuboRpcPubsubState("waiting-challenge-requests", pubsubClient.url);
656
+ community._clientsManager.updateKuboRpcPubsubStateIfProviderExists("publishing-challenge-verification");
657
+ const challengeTopic = challengeExchangePubsubTopic(community);
658
+ if (challengeTopic && !community._challengeExchangesFromLocalPublishers[request.challengeRequestId.toString()]) await community._clientsManager.pubsubPublish(challengeTopic, challengeVerification);
659
+ community._clientsManager.updateKuboRpcPubsubStateIfProviderExists("waiting-challenge-requests");
656
660
  const objectToEmit = {
657
661
  ...challengeVerification,
658
662
  ...toEncrypt
@@ -661,7 +665,7 @@ async function publishChallengeVerification(community, challengeResult, request,
661
665
  community._ongoingChallengeExchanges.delete(request.challengeRequestId.toString());
662
666
  delete community._challengeExchangesFromLocalPublishers[request.challengeRequestId.toString()];
663
667
  cleanUpChallengeAnswerPromise(community, request.challengeRequestId.toString());
664
- log.trace(`Published ${challengeVerification.type} over pubsub topic ${pubsubTopicWithfallback(community)}:`, n$3(objectToEmit, [
668
+ log.trace(`Published ${challengeVerification.type} over pubsub topic ${challengeTopic}:`, n$3(objectToEmit, [
665
669
  "signature",
666
670
  "encrypted",
667
671
  "challengeRequestId"
@@ -4318,7 +4322,15 @@ var DbHandler = class {
4318
4322
  JOIN ${TABLES.COMMENT_UPDATES} cu_child ON cu_child.cid = child_ref.value
4319
4323
  WHERE cu_parent.replies IS NOT NULL
4320
4324
  AND json_type(cu_parent.replies, '$.best.commentCids') = 'array'
4321
- AND cu_child.updatedAt > cu_parent.insertedAt
4325
+ -- Compare against the parent's updatedAt, not its insertedAt (issue #230). insertedAt is
4326
+ -- the batch's start timestamp, shared by every row the batch writes (issue #209/#211),
4327
+ -- while updatedAt is stamped when that row is actually calculated. A batch walks a post
4328
+ -- tree deepest-depth-first, so a child is always calculated before its parent and its
4329
+ -- updatedAt lands after the batch's start: comparing against insertedAt re-flagged every
4330
+ -- parent of any batch spanning >= 1 second, which produced another such batch, and the
4331
+ -- update loop never converged. updatedAt is when the parent's replies page was actually
4332
+ -- generated, which is the point the child's data could have gone stale relative to.
4333
+ AND cu_child.updatedAt > cu_parent.updatedAt
4322
4334
  ),
4323
4335
  base_updates AS (
4324
4336
  SELECT * FROM direct_updates
@@ -5853,7 +5865,7 @@ async function createNewLocalCommunityDb(community) {
5853
5865
  await community._dbHandler.initDbIfNeeded({ fileMustExist: false });
5854
5866
  await community._dbHandler.createOrMigrateTablesIfNeeded();
5855
5867
  await initSignerProps(community, community.signer);
5856
- if (!community.pubsubTopic) community.pubsubTopic = t$10(community.signer.address);
5868
+ if (!community.pubsubTopic && !community.settings?.disablePubsubChallengeExchange) community.pubsubTopic = t$10(community.signer.address);
5857
5869
  if (typeof community.createdAt !== "number") community.createdAt = timestamp();
5858
5870
  if (!community.protocolVersion) community.protocolVersion = version_default.PROTOCOL_VERSION;
5859
5871
  if (!community.settings?.maxPendingApprovalCount) community.settings = {
@@ -5932,6 +5944,7 @@ async function initInternalCommunityAfterFirstUpdateNoMerge(community, newProps)
5932
5944
  },
5933
5945
  runtimeFields: { updateCid: newProps.updateCid }
5934
5946
  });
5947
+ if (!newProps.pubsubTopic && newProps._configuredPubsubTopic) community.pubsubTopic = newProps._configuredPubsubTopic;
5935
5948
  await initSignerProps(community, newProps.signer);
5936
5949
  community._internalStateUpdateId = newProps._internalStateUpdateId;
5937
5950
  if (Array.isArray(newProps._cidsToUnPin)) newProps._cidsToUnPin.forEach((cid) => community._cidsToUnPin.add(cid));
@@ -5976,22 +5989,42 @@ async function initDbHandlerIfNeeded(community) {
5976
5989
  //#region dist/node/runtime/node/community/local-community/pubsub.js
5977
5990
  async function listenToIncomingRequests(community) {
5978
5991
  const log = logger_default("pkc-js:local-community:sync:_listenToIncomingRequests");
5979
- const pubsubClient = community._clientsManager.getDefaultKuboPubsubClient();
5992
+ const topic = challengeExchangePubsubTopic(community);
5993
+ const pubsubClient = topic ? community._clientsManager.getDefaultKuboPubsubClient() : community._clientsManager.getDefaultKuboPubsubClientIfAny();
5994
+ if (!pubsubClient) return;
5980
5995
  const subscribedTopics = await pubsubClient._client.pubsub.ls();
5981
- const topic = pubsubTopicWithfallback(community);
5996
+ const staleTopic = community._subscribedChallengePubsubTopic;
5997
+ const unsubscribeStaleTopicIfNeeded = async (currentTopic) => {
5998
+ if (!staleTopic || staleTopic === currentTopic) return;
5999
+ if (subscribedTopics.includes(staleTopic)) await community._clientsManager.pubsubUnsubscribe(staleTopic, community.handleChallengeExchange);
6000
+ community._subscribedChallengePubsubTopic = void 0;
6001
+ log(`Stopped listening on the previous challenge exchange pubsub topic (${staleTopic})`);
6002
+ };
6003
+ if (!topic) {
6004
+ const disabledTopic = communityChallengePubsubTopic(community);
6005
+ if (disabledTopic && subscribedTopics.includes(disabledTopic)) {
6006
+ await community._clientsManager.pubsubUnsubscribe(disabledTopic, community.handleChallengeExchange);
6007
+ if (community._subscribedChallengePubsubTopic === disabledTopic) community._subscribedChallengePubsubTopic = void 0;
6008
+ log(`Challenge exchange is disabled, unsubscribed from pubsub topic (${disabledTopic})`);
6009
+ }
6010
+ await unsubscribeStaleTopicIfNeeded(void 0);
6011
+ return;
6012
+ }
6013
+ await unsubscribeStaleTopicIfNeeded(topic);
5982
6014
  if (!subscribedTopics.includes(topic)) {
5983
6015
  await community._clientsManager.pubsubUnsubscribe(topic, community.handleChallengeExchange);
5984
6016
  await community._clientsManager.pubsubSubscribe(topic, community.handleChallengeExchange);
5985
6017
  community._clientsManager.updateKuboRpcPubsubState("waiting-challenge-requests", pubsubClient.url);
5986
6018
  log(`Waiting for publications on pubsub topic (${topic})`);
5987
6019
  }
6020
+ community._subscribedChallengePubsubTopic = topic;
5988
6021
  }
5989
6022
  async function providePubsubTopicRoutingCidsIfNeeded(community, force = false) {
5990
6023
  const log = logger_default("pkc-js:local-community:_providePubsubTopicRoutingCidsIfNeeded");
5991
6024
  const reprovideIntervalMs = 3600 * 1e3;
5992
6025
  const now = Date.now();
5993
6026
  if (!force && community._lastPubsubTopicRoutingProvideAt && now - community._lastPubsubTopicRoutingProvideAt < reprovideIntervalMs) return;
5994
- const topics = [pubsubTopicWithfallback(community), community.ipnsPubsubTopic].filter((topic) => typeof topic === "string");
6027
+ const topics = [challengeExchangePubsubTopic(community), community.ipnsPubsubTopic].filter((topic) => typeof topic === "string");
5995
6028
  if (topics.length === 0) return;
5996
6029
  community._lastPubsubTopicRoutingProvideAt = now;
5997
6030
  const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient()._client;
@@ -6116,6 +6149,7 @@ async function calculateNextCommunityRecord(community, commentUpdateRowsToPublis
6116
6149
  const newIpns = { ...cleanUpBeforePublishing({
6117
6150
  ...n$3(community._toJSONIpfsBaseNoPosts(), ["signature"]),
6118
6151
  ...pendingCommunityIpfsEditProps,
6152
+ pubsubTopic: challengeExchangePubsubTopic(community),
6119
6153
  lastPostCid: latestPost?.cid,
6120
6154
  lastCommentCid: latestComment?.cid,
6121
6155
  statsCid,
@@ -6214,7 +6248,13 @@ async function publishCommunityRecordToIpns(community, build, newCommunityRecord
6214
6248
  community._blocksToRm = community._blocksToRm.filter((blockCid) => !removedBlocks.includes(blockCid));
6215
6249
  }
6216
6250
  if (community.updateCid) community._cidsToUnPin.add(community.updateCid);
6251
+ const configuredPubsubTopic = community.pubsubTopic;
6252
+ const editedPubsubTopic = community._pendingEditProps.filter((editProps) => editProps.editId && editIdsToIncludeInNextUpdate.includes(editProps.editId)).map((editProps) => editProps.pubsubTopic).filter((topic) => typeof topic === "string").pop();
6217
6253
  community.initCommunityIpfsPropsNoMerge(newCommunityRecord);
6254
+ if (!newCommunityRecord.pubsubTopic) {
6255
+ const topicToKeep = editedPubsubTopic ?? configuredPubsubTopic;
6256
+ if (topicToKeep) community.pubsubTopic = topicToKeep;
6257
+ }
6218
6258
  community.updateCid = file.path;
6219
6259
  community._pendingEditProps = community._pendingEditProps.filter((editProps) => !editIdsToIncludeInNextUpdate.includes(editProps.editId));
6220
6260
  if (community._pendingEditProps.length > 0) {
@@ -6587,7 +6627,9 @@ async function stop(community) {
6587
6627
  if (community.state === "started") {
6588
6628
  log("Stopping running community", community.address);
6589
6629
  try {
6590
- await community._clientsManager.pubsubUnsubscribe(pubsubTopicWithfallback(community), community.handleChallengeExchange);
6630
+ const challengeTopics = new Set([communityChallengePubsubTopic(community), community._subscribedChallengePubsubTopic].filter((topic) => typeof topic === "string"));
6631
+ for (const challengeTopic of challengeTopics) await community._clientsManager.pubsubUnsubscribe(challengeTopic, community.handleChallengeExchange);
6632
+ community._subscribedChallengePubsubTopic = void 0;
6591
6633
  } catch (e) {
6592
6634
  log.error("Failed to unsubscribe from challenge exchange pubsub when stopping community", e);
6593
6635
  }
@@ -6615,7 +6657,6 @@ async function stop(community) {
6615
6657
  log.error(`Failed to unlock start lock on community (${community.address})`, e);
6616
6658
  }
6617
6659
  const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient();
6618
- const pubsubClient = community._clientsManager.getDefaultKuboPubsubClient();
6619
6660
  community._setStartedStateWithEmission("stopped");
6620
6661
  untrackStartedCommunity(community._pkc, community);
6621
6662
  processStartedCommunities.untrack(community);
@@ -6624,7 +6665,7 @@ async function stop(community) {
6624
6665
  await community._dbHandler.unlockCommunityState();
6625
6666
  await community._updateStartedValue();
6626
6667
  community._clientsManager.updateKuboRpcState("stopped", kuboRpcClient.url);
6627
- community._clientsManager.updateKuboRpcPubsubState("stopped", pubsubClient.url);
6668
+ community._clientsManager.updateKuboRpcPubsubStateIfProviderExists("stopped");
6628
6669
  if (community._dbHandler) community._dbHandler.destoryConnection();
6629
6670
  log(`Stopped the running of local community (${community.address})`);
6630
6671
  community._setState("stopped");
@@ -6683,6 +6724,8 @@ async function deleteCommunity(community) {
6683
6724
  log.error("Failed to add old page cids from community.posts to be unpinned", e);
6684
6725
  }
6685
6726
  if (community.ipnsPubsubTopicRoutingCid) community._cidsToUnPin.add(community.ipnsPubsubTopicRoutingCid);
6727
+ const configuredChallengeTopic = communityChallengePubsubTopic(community);
6728
+ if (configuredChallengeTopic) community._cidsToUnPin.add(pubsubTopicToDhtKey(configuredChallengeTopic));
6686
6729
  if (community.pubsubTopicRoutingCid) community._cidsToUnPin.add(community.pubsubTopicRoutingCid);
6687
6730
  try {
6688
6731
  await community.initDbHandlerIfNeeded();
@@ -7081,6 +7124,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
7081
7124
  this._firstUpdateAfterStart = true;
7082
7125
  this._internalStateUpdateId = "";
7083
7126
  this._lastPubsubTopicRoutingProvideAt = void 0;
7127
+ this._subscribedChallengePubsubTopic = void 0;
7084
7128
  this._lastProvidedBrowserDialableSelfAddrs = void 0;
7085
7129
  this._lastAddressReprovideCheckAt = void 0;
7086
7130
  this._mirroredStartedOrUpdatingCommunity = void 0;
@@ -7119,7 +7163,8 @@ var LocalCommunity = class extends RpcLocalCommunity {
7119
7163
  _internalStateUpdateId: this._internalStateUpdateId,
7120
7164
  _cidsToUnPin: [...this._cidsToUnPin],
7121
7165
  _mfsPathsToRemove: [...this._mfsPathsToRemove],
7122
- _pendingEditProps: this._pendingEditProps
7166
+ _pendingEditProps: this._pendingEditProps,
7167
+ _configuredPubsubTopic: this.pubsubTopic
7123
7168
  };
7124
7169
  }
7125
7170
  toJSONInternalBeforeFirstUpdate() {
@@ -1,2 +1,2 @@
1
- import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-DWf7A4hj.js";
1
+ import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-Br1ipu1Z.js";
2
2
  export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };
@@ -1,7 +1,7 @@
1
1
  import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
2
- import { B as isIpfsCid, Cn as CommentUpdateForChallengeVerificationSchema, Ct as findUpdatingCommunity, D as deepMergeRuntimeFields, Dt as refreshTrackedCommentAliases, E as createAbortError, En as CommentUpdateSchema, Et as listUpdatingCommunities, Fr as stringifyPrimitive, H as isIpns, It as require_sha256, L as hideClassPrivateProps, Lt as TimeoutError, Nr as joinValues, Pr as parsedType, Pt as untrackUpdatingComment, Q as isStringDomain, Qn as n$1, R as ipnsNameToIpnsOverPubsubTopic, Rt as pTimeout, Sr as setErrorMap, St as findUpdatingComment, Tt as listUpdatingComments, Xn as n$2, _r as PKCError, _t as timestamp, a as ChallengeRequestMessageSchema, b as areEquivalentCommunityAddresses, br as require_supports_color, cn as PubsubTopicSchema, ct as resolveWhenPredicateIsTrue, dr as require_retry, er as t$1, fr as FailedToFetchCommentIpfsFromGatewaysError, ft as shortifyAddress, ir as r, jt as trackUpdatingComment, k as doesDomainAddressHaveCapitalLetter, mt as sleepUntilTimeoutOrAbort, nn as CommunityIpfsSchema, nr as e$1, ot as removeUndefinedValuesRecursively, pt as shortifyCid, r as ChallengeMessageSchema, s as ChallengeVerificationMessageSchema, st as replaceXWithY, t as ChallengeAnswerMessageSchema, tr as e, ut as retryKuboIpfsAdd, vn as CommentIpfsSchema, vr as messages, vt as waitForUpdateInCommunityInstanceWithErrorAndTimeout, wt as listStartedCommunities, xt as findStartedCommunity, y as version_default, yr as logger_default, z as isAbortError } from "./schema-B3duXSG7.js";
3
- import { $ as RepliesPages, $n as t$5, $t as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, An as RpcCidParamSchema, At as verifyCommunityEdit, B as setNativeFunctions$1, Bn as RpcFetchCidResultSchema, Bt as getCommunityPublicKeyFromWire, Cn as parseRpcCommentEventWithPKCErrorIfItFails, Ct as verifyChallengeVerification, D as createKuboRpcClient, Dn as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, Dt as verifyCommentPubsubMessage, Et as verifyCommentModeration, Fn as RpcExportCommunityModLogsParamSchema, Gn as RpcUnsubscribeParamSchema, H as CommentClientsManager, Hn as RpcResolveAuthorNameResultSchema, Ht as decode, I as listCommunitiesSync, In as RpcExportCommunityModLogsResultSchema, It as normalizeCreatePublicationAuthor, Kn as t$4, L as monitorCommunitiesDirectory, Ln as RpcExportCommunityParamSchema, Lt as buildRuntimeCommunityFields, Mn as RpcCommunityIdentifierParamSchema, Mt as buildRuntimeAuthor, N as getDefaultDataPath, Nn as RpcCommunityPageParamSchema, Nt as cleanWireAuthor, On as RpcAuthorNameParamSchema, Ot as verifyCommentUpdate, Pn as RpcEditCommunityParamSchema, Pt as getAuthorNameFromRuntime, Q as parseRawPages, Qn as t$2, Rn as RpcExportCommunityResultSchema, Rt as getCommunityAddressFromRecord, Sn as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, Tn as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, Tt as verifyCommentIpfs, Un as RpcSubscriptionIdResultSchema, V as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, Vn as RpcPublishChallengeAnswersParamSchema, Vt as normalizeCommunityInputFromCommunity, Wn as RpcSuccessResultSchema, Wt as getBufferedPKCAddressFromPublicKey, X as findCommentInPageInstanceRecursively, Xn as n$3, Xt as parseCidStringSchemaWithPKCErrorIfItFails, Y as extractCommunityRuntimeFieldsFromParsedPages, Yn as t$3, _n as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, a as pkcJsChallenges, at as PKCTypedEmitter, bn as parseDecryptedChallengeWithPKCErrorIfItFails, c as AddressesRewriterProxyServer, ct as signChallengeAnswer, dn as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, en as parseCommentIpfsSchemaWithPKCErrorIfItFails, et as PublicationClientsManager, f as KeyvBetterSqlite3, fn as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, ft as signComment, g as decodeRpcChallengeVerificationPubsubMsg, gn as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, h as decodeRpcChallengeRequestPubsubMsg, hn as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, in as parseCommunityAddressWithPKCErrorIfItFails, ir as require_undici, jn as RpcCommentRepliesPageParamSchema, jt as verifyVote, kn as RpcCancelExportParamSchema, ln as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, m as decodeRpcChallengePubsubMsg, mt as signCommentModeration, n as RpcRemoteCommunity, nn as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, nt as InflightFetchManager, o as TrackedInstanceRegistry, ot as require_lib$1, p as decodeRpcChallengeAnswerPubsubMsg, pt as signCommentEdit, rn as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, rr as nativeFunctions$2, s as LRUCache, sn as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, st as cleanUpBeforePublishing, t as RpcLocalCommunity, tt as PKCClientsManager, u as RemoteCommunity, un as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, ut as signChallengeRequest, v as createSigner, vn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, vt as signCommunityEdit, wn as parseRpcCommentUpdateEventWithPKCErrorIfItFails, wt as verifyCommentEdit, x as encryptEd25519AesGcm, xn as parseJsonWithPKCErrorIfFails, xt as verifyChallengeMessage, y as decryptEd25519AesGcm, yn as parseDecryptedChallengeVerification, yt as signVote, zn as RpcFetchCidParamSchema, zt as getCommunityNameFromWire } from "./rpc-local-community-ZxNkZCBr.js";
4
- import { o as getHeliaDebugContext } from "./util-DOWWxZIE.js";
2
+ import { B as isIpfsCid, Cn as CommentUpdateForChallengeVerificationSchema, Ct as findUpdatingCommunity, D as deepMergeRuntimeFields, Dt as refreshTrackedCommentAliases, E as createAbortError, En as CommentUpdateSchema, Et as listUpdatingCommunities, Fr as stringifyPrimitive, H as isIpns, It as require_sha256, L as hideClassPrivateProps, Lt as TimeoutError, Nr as joinValues, Pr as parsedType, Pt as untrackUpdatingComment, Q as isStringDomain, Qn as n$1, R as ipnsNameToIpnsOverPubsubTopic, Rt as pTimeout, Sr as setErrorMap, St as findUpdatingComment, Tt as listUpdatingComments, Xn as n$2, _r as PKCError, _t as timestamp, a as ChallengeRequestMessageSchema, b as areEquivalentCommunityAddresses, br as require_supports_color, cn as PubsubTopicSchema, ct as resolveWhenPredicateIsTrue, dr as require_retry, er as t$1, fr as FailedToFetchCommentIpfsFromGatewaysError, ft as shortifyAddress, ir as r, jt as trackUpdatingComment, k as doesDomainAddressHaveCapitalLetter, mt as sleepUntilTimeoutOrAbort, nn as CommunityIpfsSchema, nr as e$1, ot as removeUndefinedValuesRecursively, pt as shortifyCid, r as ChallengeMessageSchema, s as ChallengeVerificationMessageSchema, st as replaceXWithY, t as ChallengeAnswerMessageSchema, tr as e, ut as retryKuboIpfsAdd, vn as CommentIpfsSchema, vr as messages, vt as waitForUpdateInCommunityInstanceWithErrorAndTimeout, wt as listStartedCommunities, xt as findStartedCommunity, y as version_default, yr as logger_default, z as isAbortError } from "./schema-B1Ot-kux.js";
3
+ import { $ as RepliesPages, $n as t$5, $t as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, An as RpcCidParamSchema, At as verifyCommunityEdit, B as setNativeFunctions$1, Bn as RpcFetchCidResultSchema, Bt as getCommunityPublicKeyFromWire, Cn as parseRpcCommentEventWithPKCErrorIfItFails, Ct as verifyChallengeVerification, D as createKuboRpcClient, Dn as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, Dt as verifyCommentPubsubMessage, Et as verifyCommentModeration, Fn as RpcExportCommunityModLogsParamSchema, Gn as RpcUnsubscribeParamSchema, H as CommentClientsManager, Hn as RpcResolveAuthorNameResultSchema, Ht as decode, I as listCommunitiesSync, In as RpcExportCommunityModLogsResultSchema, It as normalizeCreatePublicationAuthor, Kn as t$4, L as monitorCommunitiesDirectory, Ln as RpcExportCommunityParamSchema, Lt as buildRuntimeCommunityFields, Mn as RpcCommunityIdentifierParamSchema, Mt as buildRuntimeAuthor, N as getDefaultDataPath, Nn as RpcCommunityPageParamSchema, Nt as cleanWireAuthor, On as RpcAuthorNameParamSchema, Ot as verifyCommentUpdate, Pn as RpcEditCommunityParamSchema, Pt as getAuthorNameFromRuntime, Q as parseRawPages, Qn as t$2, Rn as RpcExportCommunityResultSchema, Rt as getCommunityAddressFromRecord, Sn as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, Tn as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, Tt as verifyCommentIpfs, Un as RpcSubscriptionIdResultSchema, V as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, Vn as RpcPublishChallengeAnswersParamSchema, Vt as normalizeCommunityInputFromCommunity, Wn as RpcSuccessResultSchema, Wt as getBufferedPKCAddressFromPublicKey, X as findCommentInPageInstanceRecursively, Xn as n$3, Xt as parseCidStringSchemaWithPKCErrorIfItFails, Y as extractCommunityRuntimeFieldsFromParsedPages, Yn as t$3, _n as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, a as pkcJsChallenges, at as PKCTypedEmitter, bn as parseDecryptedChallengeWithPKCErrorIfItFails, c as AddressesRewriterProxyServer, ct as signChallengeAnswer, dn as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, en as parseCommentIpfsSchemaWithPKCErrorIfItFails, et as PublicationClientsManager, f as KeyvBetterSqlite3, fn as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, ft as signComment, g as decodeRpcChallengeVerificationPubsubMsg, gn as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, h as decodeRpcChallengeRequestPubsubMsg, hn as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, in as parseCommunityAddressWithPKCErrorIfItFails, ir as require_undici, jn as RpcCommentRepliesPageParamSchema, jt as verifyVote, kn as RpcCancelExportParamSchema, ln as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, m as decodeRpcChallengePubsubMsg, mt as signCommentModeration, n as RpcRemoteCommunity, nn as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, nt as InflightFetchManager, o as TrackedInstanceRegistry, ot as require_lib$1, p as decodeRpcChallengeAnswerPubsubMsg, pt as signCommentEdit, qt as getPKCAddressFromPublicKeySync, rn as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, rr as nativeFunctions$2, s as LRUCache, sn as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, st as cleanUpBeforePublishing, t as RpcLocalCommunity, tt as PKCClientsManager, u as RemoteCommunity, un as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, ut as signChallengeRequest, v as createSigner, vn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, vt as signCommunityEdit, wn as parseRpcCommentUpdateEventWithPKCErrorIfItFails, wt as verifyCommentEdit, x as encryptEd25519AesGcm, xn as parseJsonWithPKCErrorIfFails, xt as verifyChallengeMessage, y as decryptEd25519AesGcm, yn as parseDecryptedChallengeVerification, yt as signVote, zn as RpcFetchCidParamSchema, zt as getCommunityNameFromWire } from "./rpc-local-community-DtdeJBOq.js";
4
+ import { o as getHeliaDebugContext } from "./util-B6v5HAdy.js";
5
5
  import path from "path";
6
6
  import assert from "assert";
7
7
  import fs from "fs";
@@ -289,7 +289,7 @@ var Publication = class extends import_lib.TypedEmitter {
289
289
  if (Object.values(this._challengeExchanges).some((exchange) => exchange.challenge)) return;
290
290
  const challengeMsgValidity = await verifyChallengeMessage({
291
291
  challenge: msg,
292
- pubsubTopic: this._communityPubsubTopicWithFallback(),
292
+ communityChallengeSignerAddress: this._communityChallengeMsgSignerAddress(),
293
293
  validateTimestampRange: true
294
294
  });
295
295
  if (!challengeMsgValidity.valid) {
@@ -359,7 +359,8 @@ var Publication = class extends import_lib.TypedEmitter {
359
359
  };
360
360
  this._challengeExchanges[msg.challengeRequestId.toString()].challenge = decryptedChallengeMsg;
361
361
  this._updatePublishingStateWithEmission("waiting-challenge-answers");
362
- Object.entries(this._clientsManager.pubsubProviderSubscriptions).filter(([, pubsubTopics]) => pubsubTopics.includes(this._communityPubsubTopicWithFallback())).map(([provider]) => provider).forEach((provider) => this._updatePubsubState("waiting-challenge-answers", provider));
362
+ const challengeTopic = this._community?.pubsubTopic;
363
+ Object.entries(this._clientsManager.pubsubProviderSubscriptions).filter(([, pubsubTopics]) => typeof challengeTopic === "string" && pubsubTopics.includes(challengeTopic)).map(([provider]) => provider).forEach((provider) => this._updatePubsubState("waiting-challenge-answers", provider));
363
364
  this.emit("challenge", decryptedChallengeMsg);
364
365
  }
365
366
  async _handleIncomingChallengeVerificationPubsubMessage(msg) {
@@ -367,7 +368,7 @@ var Publication = class extends import_lib.TypedEmitter {
367
368
  if (this._challengeExchanges[msg.challengeRequestId.toString()].challengeVerification) return;
368
369
  const signatureValidation = await verifyChallengeVerification({
369
370
  verification: msg,
370
- pubsubTopic: this._communityPubsubTopicWithFallback(),
371
+ communityChallengeSignerAddress: this._communityChallengeMsgSignerAddress(),
371
372
  validateTimestampRange: true
372
373
  });
373
374
  if (!signatureValidation.valid) {
@@ -522,7 +523,7 @@ var Publication = class extends import_lib.TypedEmitter {
522
523
  throw e;
523
524
  }
524
525
  else try {
525
- await this._clientsManager.pubsubPublishOnProvider(this._communityPubsubTopicWithFallback(), answerMsgToPublish, challengeExchange.providerUrl);
526
+ await this._clientsManager.pubsubPublishOnProvider(this._communityChallengePubsubExchangeTopic(), answerMsgToPublish, challengeExchange.providerUrl);
526
527
  } catch (e) {
527
528
  this._challengeExchanges[challengeExchange.challengeRequest.challengeRequestId.toString()].challengeAnswerPublishError = e;
528
529
  this._updatePublishingStateWithEmission("failed");
@@ -536,7 +537,8 @@ var Publication = class extends import_lib.TypedEmitter {
536
537
  this._challengeExchanges[challengeExchange.challengeRequest.challengeRequestId.toString()].challengeAnswer = decryptedChallengeAnswer;
537
538
  this._challengeExchanges[challengeExchange.challengeRequest.challengeRequestId.toString()].challengeAnswerPublishTimestamp = timestamp();
538
539
  this._updatePublishingStateWithEmission("waiting-challenge-verification");
539
- Object.entries(this._clientsManager.pubsubProviderSubscriptions).filter(([, pubsubTopics]) => pubsubTopics.includes(this._communityPubsubTopicWithFallback())).map(([provider]) => provider).forEach((provider) => this._updatePubsubState("waiting-challenge-verification", provider));
540
+ const challengeTopic = this._community?.pubsubTopic;
541
+ Object.entries(this._clientsManager.pubsubProviderSubscriptions).filter(([, pubsubTopics]) => typeof challengeTopic === "string" && pubsubTopics.includes(challengeTopic)).map(([provider]) => provider).forEach((provider) => this._updatePubsubState("waiting-challenge-verification", provider));
540
542
  log(`Responded to challenge with answers`, challengeAnswers);
541
543
  this.emit("challengeanswer", decryptedChallengeAnswer);
542
544
  }
@@ -556,10 +558,6 @@ var Publication = class extends import_lib.TypedEmitter {
556
558
  }
557
559
  _validateCommunityFields() {
558
560
  if (typeof this._community?.encryption?.publicKey !== "string") throw new PKCError("ERR_COMMUNITY_MISSING_FIELD", { communityPublicKey: this._community?.encryption?.publicKey });
559
- if (typeof this._communityPubsubTopicWithFallback() !== "string") throw new PKCError("ERR_COMMUNITY_MISSING_FIELD", {
560
- pubsubTopic: this._community?.pubsubTopic,
561
- address: this._community?.address
562
- });
563
561
  }
564
562
  _updatePublishingStateNoEmission(newState) {
565
563
  this.publishingState = newState;
@@ -599,11 +597,21 @@ var Publication = class extends import_lib.TypedEmitter {
599
597
  this.clients.pkcRpcClients[currentRpcUrl].state = newState;
600
598
  this.clients.pkcRpcClients[currentRpcUrl].emit("statechange", newState);
601
599
  }
602
- _communityPubsubTopicWithFallback() {
603
- const pubsubTopic = this._community?.pubsubTopic || this._community?.address;
604
- if (typeof pubsubTopic !== "string") throw Error("Failed to load the pubsub topic of community");
600
+ _communityChallengePubsubExchangeTopic() {
601
+ const pubsubTopic = this._community?.pubsubTopic;
602
+ if (typeof pubsubTopic !== "string") throw new PKCError("ERR_COMMUNITY_CHALLENGE_EXCHANGE_DISABLED", {
603
+ communityAddress: this._community?.address ?? this.communityAddress,
604
+ communityName: this._community?.name ?? this.communityName,
605
+ communityPublicKey: this._community?.publicKey ?? this.communityPublicKey,
606
+ publicationType: this.getType()
607
+ });
605
608
  return pubsubTopic;
606
609
  }
610
+ _communityChallengeMsgSignerAddress() {
611
+ const encryptionPublicKey = this._community?.encryption?.publicKey;
612
+ if (typeof encryptionPublicKey !== "string") throw Error("Failed to load the encryption public key of community");
613
+ return getPKCAddressFromPublicKeySync(encryptionPublicKey);
614
+ }
607
615
  _getCommunityCache() {
608
616
  const cached = this._pkc._memCaches.communityForPublishing.get(this.communityAddress, { allowStale: true });
609
617
  if (cached) return cached;
@@ -659,8 +667,8 @@ var Publication = class extends import_lib.TypedEmitter {
659
667
  }
660
668
  this._rpcPublishSubscriptionId = void 0;
661
669
  this._setRpcClientState("stopped");
662
- } else if (this._community) {
663
- await this._clientsManager.pubsubUnsubscribe(this._communityPubsubTopicWithFallback(), this._handleChallengeExchange);
670
+ } else if (typeof this._community?.pubsubTopic === "string") {
671
+ await this._clientsManager.pubsubUnsubscribe(this._community.pubsubTopic, this._handleChallengeExchange);
664
672
  Object.values(this._challengeExchanges).forEach((exchange) => this._updatePubsubState("stopped", exchange.providerUrl));
665
673
  }
666
674
  }
@@ -775,7 +783,7 @@ var Publication = class extends import_lib.TypedEmitter {
775
783
  timestamp: timestamp()
776
784
  });
777
785
  const challengeRequest = await this._signAndValidateChallengeRequestBeforePublishing(toSignMsg, pubsubMessageSigner);
778
- log("Attempting to publish", this.getType(), "to pubsub topic", this._communityPubsubTopicWithFallback(), "with provider", providerUrl, "request.encrypted=", pubsubMsgToEncrypt);
786
+ log("Attempting to publish", this.getType(), "to pubsub topic", this._community?.pubsubTopic, "with provider", providerUrl, "request.encrypted=", pubsubMsgToEncrypt);
779
787
  const decryptedChallengeRequest = {
780
788
  ...challengeRequest,
781
789
  ...pubsubMsgToEncrypt
@@ -868,9 +876,9 @@ var Publication = class extends import_lib.TypedEmitter {
868
876
  this._updatePublishingStateWithEmission("publishing-challenge-request");
869
877
  this._updatePubsubState("subscribing-pubsub", providerUrl);
870
878
  try {
871
- await this._clientsManager.pubsubSubscribeOnProvider(this._communityPubsubTopicWithFallback(), this._handleChallengeExchange, providerUrl);
879
+ await this._clientsManager.pubsubSubscribeOnProvider(this._communityChallengePubsubExchangeTopic(), this._handleChallengeExchange, providerUrl);
872
880
  this._updatePubsubState("publishing-challenge-request", providerUrl);
873
- await this._clientsManager.pubsubPublishOnProvider(this._communityPubsubTopicWithFallback(), challengeRequest, providerUrl);
881
+ await this._clientsManager.pubsubPublishOnProvider(this._communityChallengePubsubExchangeTopic(), challengeRequest, providerUrl);
874
882
  this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequestPublishTimestamp = timestamp();
875
883
  } catch (e) {
876
884
  log.error("Failed to publish challenge request using provider ", providerUrl, e);
@@ -894,7 +902,7 @@ var Publication = class extends import_lib.TypedEmitter {
894
902
  await this._postSucessOrFailurePublishing();
895
903
  const allAttemptsFailedError = new PKCError("ERR_ALL_PUBSUB_PROVIDERS_THROW_ERRORS", {
896
904
  challengeExchanges: this._challengeExchangesFormattedForErrors(),
897
- pubsubTopic: this._communityPubsubTopicWithFallback(),
905
+ pubsubTopic: this._community?.pubsubTopic,
898
906
  providerHeliaContexts: this._libp2pJsClientHeliaContexts()
899
907
  });
900
908
  log.error("All attempts to publish", this.getType(), "has failed", allAttemptsFailedError);
@@ -958,12 +966,30 @@ var Publication = class extends import_lib.TypedEmitter {
958
966
  await this._validateSignatureHook();
959
967
  if (this._pkc._pkcRpcClient) return this._publishWithRpc();
960
968
  const options = { acceptedChallengeTypes: [] };
961
- const providers = this._getPubsubProviders();
962
969
  const startedCommunity = findStartedCommunity(this._pkc, {
963
970
  publicKey: this.communityPublicKey,
964
971
  name: this.communityName
965
972
  });
966
973
  if (startedCommunity) return this._publishWithLocalCommunity(startedCommunity, await this._generateChallengeRequestToPublish("publishing directly to local community instance", options.acceptedChallengeTypes));
974
+ if (typeof this._community?.pubsubTopic !== "string") {
975
+ await this._postSucessOrFailurePublishing();
976
+ const error = new PKCError("ERR_COMMUNITY_CHALLENGE_EXCHANGE_DISABLED", {
977
+ communityAddress: this._community?.address ?? this.communityAddress,
978
+ communityName: this._community?.name ?? this.communityName,
979
+ communityPublicKey: this._community?.publicKey ?? this.communityPublicKey,
980
+ publicationType: this.getType()
981
+ });
982
+ log.error("Community has its challenge exchange disabled, will not publish", this.getType(), error);
983
+ this._changePublicationStateEmitEventEmitStateChangeEvent({
984
+ newPublishingState: "failed",
985
+ event: {
986
+ name: "error",
987
+ args: [error]
988
+ }
989
+ });
990
+ throw error;
991
+ }
992
+ const providers = this._getPubsubProviders();
967
993
  let currentPubsubProviderIndex = 0;
968
994
  while (!this._didWeReceiveChallengeOrChallengeVerification() && currentPubsubProviderIndex < providers.length) {
969
995
  const providerUrl = providers[currentPubsubProviderIndex];
@@ -971,9 +997,9 @@ var Publication = class extends import_lib.TypedEmitter {
971
997
  this._updatePublishingStateWithEmission("publishing-challenge-request");
972
998
  this._updatePubsubState("subscribing-pubsub", providerUrl);
973
999
  try {
974
- await this._clientsManager.pubsubSubscribeOnProvider(this._communityPubsubTopicWithFallback(), this._handleChallengeExchange, providerUrl);
1000
+ await this._clientsManager.pubsubSubscribeOnProvider(this._communityChallengePubsubExchangeTopic(), this._handleChallengeExchange, providerUrl);
975
1001
  this._updatePubsubState("publishing-challenge-request", providerUrl);
976
- await this._clientsManager.pubsubPublishOnProvider(this._communityPubsubTopicWithFallback(), challengeRequest, providerUrl);
1002
+ await this._clientsManager.pubsubPublishOnProvider(this._communityChallengePubsubExchangeTopic(), challengeRequest, providerUrl);
977
1003
  this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequestPublishTimestamp = timestamp();
978
1004
  } catch (e) {
979
1005
  this._updatePubsubState("stopped", providerUrl);
@@ -984,7 +1010,7 @@ var Publication = class extends import_lib.TypedEmitter {
984
1010
  await this._postSucessOrFailurePublishing();
985
1011
  const allAttemptsFailedError = new PKCError("ERR_ALL_PUBSUB_PROVIDERS_THROW_ERRORS", {
986
1012
  challengeExchanges: this._challengeExchangesFormattedForErrors(),
987
- pubsubTopic: this._communityPubsubTopicWithFallback(),
1013
+ pubsubTopic: this._community?.pubsubTopic,
988
1014
  providerHeliaContexts: this._libp2pJsClientHeliaContexts()
989
1015
  });
990
1016
  log.error("All attempts to publish", this.getType(), "has failed", allAttemptsFailedError);
@@ -8875,7 +8901,7 @@ var PKC$1 = class extends PKCTypedEmitter {
8875
8901
  this.clients.libp2pJsClients = {};
8876
8902
  if (!this.libp2pJsClientsOptions) return;
8877
8903
  if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
8878
- const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-BcZhGLB0.js");
8904
+ const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-B-75U9z9.js");
8879
8905
  for (const clientOptions of this.libp2pJsClientsOptions) {
8880
8906
  const heliaNode = await createLibp2pJsClientOrUseExistingOne({
8881
8907
  ...clientOptions,
@@ -9123,7 +9149,7 @@ var PKC$1 = class extends PKCTypedEmitter {
9123
9149
  const log = logger_default("pkc-js:pkc:createLocalCommunity");
9124
9150
  log.trace("Received community options to create a local community instance:", options);
9125
9151
  if (!this._canCreateNewLocalCommunity()) throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
9126
- const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-Cd5HOxwM.js");
9152
+ const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-CIVs_iuS.js");
9127
9153
  const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
9128
9154
  const community = new LocalCommunity(this);
9129
9155
  if (isLocalCommunity) {
@@ -1,5 +1,5 @@
1
1
  import { i as __toESM, n as __exportAll, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
2
- import { $ as pubsubTopicToDhtKey, $t as CommunityEditOptionsSchema, A as extractNetworkErrorDetails, An as CreateCommentOptionsWithRefinementSchema, Ar as record, At as trackStartedCommunity, B as isIpfsCid, Bn as CreateCommentEditOptionsWithRefinementSchema, Cr as _enum, Ct as findUpdatingCommunity, D as deepMergeRuntimeFields, Dn as CommentUpdateSignedPropertyNames, Dr as literal, E as createAbortError, En as CommentUpdateSchema, Er as custom, Et as listUpdatingCommunities, Ft as untrackUpdatingCommunity, Gn as CidPathSchema, Gt as CommentModerationPubsubMessagePublicationSchema, H as isIpns, Hn as AuthorCommentIpfsReservedFields, Ht as CommunityEditPubsubMessagePublicationSchema, I as getPostUpdateTimestampRange, In as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, It as require_sha256$1, Jn as CommunityAuthorChallengeReservedFieldNames, Jt as CommentModerationsTableRowSchema, Kn as CidStringSchema, L as hideClassPrivateProps, Mn as ModQueuePageIpfsSchema, Mt as trackUpdatingCommunity, Nn as PageIpfsSchema, Nt as untrackStartedCommunity, O as derivePublicationFromChallengeRequest, Or as number, Ot as refreshTrackedCommunityAliases, Pn as CommentEditChallengeRequestToEncryptSchema, Q as isStringDomain, Qn as n$9, Qt as CommunityChallengeSettingSchema, R as ipnsNameToIpnsOverPubsubTopic, Rn as CommentEditSignedPropertyNames, Rt as pTimeout, Sn as CommentUpdateChallengeReservedFieldNames, St as findUpdatingComment, Tn as CommentUpdateReservedFields, Tr as boolean, U as isIpnsPath, Ut as CreateCommunityEditPublicationOptionsWithRefinementSchema, V as isIpfsPath, Vn as AuthorAddressSchema, Vt as CommunityEditPublicationSignedPropertyNames, Wn as ChallengeAnswersSchema, Wt as CommentModerationChallengeRequestToEncryptSchema, X as isRequestPubsubPublicationOfPost, Xn as n$10, Xt as ChallengeFileFactorySchema, Yn as CreateSignerSchema, Yt as CreateCommentModerationOptionsWithRefinementSchema, Z as isRequestPubsubPublicationOfReply, Zt as ChallengeFileSchema, _ as PKCUserOptionBaseSchema, _n as CommentIpfsReservedFields, _r as PKCError, _t as timestamp, an as CreateRemoteCommunityFunctionArgumentSchema, ar as t$12, b as areEquivalentCommunityAddresses, bn as CommentPubsubMessageWithFlexibleAuthorRefinementSchema, br as require_supports_color, c as ChallengeVerificationMessageSignedPropertyNames, cr as t$10, ct as resolveWhenPredicateIsTrue, dn as VoteChallengeRequestToEncryptSchema, dr as require_retry$1, en as CommunityExportRecordsSchema, er as t$13, f as DecryptedChallengeSchema, fn as VotePubsubMessagePublicationSchema, fr as FailedToFetchCommentIpfsFromGatewaysError, ft as shortifyAddress, g as PKCParsedOptionsSchema, gn as CommentChallengeRequestToEncryptSchema, gr as FailedToFetchPageIpfsFromGatewaysError, gt as throwIfAbortSignalAborted, h as NameResolverSerializedSchema, hr as FailedToFetchGenericIpfsFromGatewaysError, i as ChallengeMessageSignedPropertyNames, in as CreateNewLocalCommunityUserOptionsSchema, ir as r$8, it as removeNullUndefinedEmptyObjectsValuesRecursively, j as fetchAndValidateIpnsRecordFromGateway, jn as GetPageParamSchema, jr as string, k as doesDomainAddressHaveCapitalLetter, kr as object, l as DecryptedChallengeAnswerSchema, ln as RpcRemoteCommunityUpdateEventResultSchema, lr as t$9, m as NameResolveCacheOptionsSchema, mn as VoteSignedPropertyNames, mr as FailedToFetchCommunityFromGatewaysError, mt as sleepUntilTimeoutOrAbort, n as ChallengeAnswerMessageSignedPropertyNames, nn as CommunityIpfsSchema, nr as e$5, o as ChallengeRequestMessageSignedPropertyNames, on as CreateRpcCommunityFunctionArgumentSchema, or as n$8, p as DecryptedChallengeVerificationSchema, pr as FailedToFetchCommentUpdateFromGatewaysError, pt as shortifyCid, qn as CommunityAddressSchema, qt as CommentModerationSignedPropertyNames, rn as CommunitySignedPropertyNames, rr as t$11, sn as ExportCommunityModLogsOptionsSchema, sr as r$7, tn as CommunityIpfsReservedFields, tr as e$6, tt as raceAgainstAbort, un as CreateVoteUserOptionsWithRefinementSchema, ur as e$4, v as PKCUserOptionsSchema, vn as CommentIpfsSchema, vr as messages, vt as waitForUpdateInCommunityInstanceWithErrorAndTimeout, wn as CommentUpdateForChallengeVerificationSignedPropertyNames, wr as array, wt as listStartedCommunities, x as calculateIpfsCidV0, xn as CommentSignedPropertyNames, xr as require_ms$1, xt as findStartedCommunity, yr as logger_default, z as isAbortError, zt as CommunityEditPublicationChallengeRequestToEncryptSchema } from "./schema-B3duXSG7.js";
2
+ import { $ as pubsubTopicToDhtKey, $t as CommunityEditOptionsSchema, A as extractNetworkErrorDetails, An as CreateCommentOptionsWithRefinementSchema, Ar as record, At as trackStartedCommunity, B as isIpfsCid, Bn as CreateCommentEditOptionsWithRefinementSchema, Cr as _enum, Ct as findUpdatingCommunity, D as deepMergeRuntimeFields, Dn as CommentUpdateSignedPropertyNames, Dr as literal, E as createAbortError, En as CommentUpdateSchema, Er as custom, Et as listUpdatingCommunities, Ft as untrackUpdatingCommunity, Gn as CidPathSchema, Gt as CommentModerationPubsubMessagePublicationSchema, H as isIpns, Hn as AuthorCommentIpfsReservedFields, Ht as CommunityEditPubsubMessagePublicationSchema, I as getPostUpdateTimestampRange, In as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, It as require_sha256$1, Jn as CommunityAuthorChallengeReservedFieldNames, Jt as CommentModerationsTableRowSchema, Kn as CidStringSchema, L as hideClassPrivateProps, Mn as ModQueuePageIpfsSchema, Mt as trackUpdatingCommunity, Nn as PageIpfsSchema, Nt as untrackStartedCommunity, O as derivePublicationFromChallengeRequest, Or as number, Ot as refreshTrackedCommunityAliases, Pn as CommentEditChallengeRequestToEncryptSchema, Q as isStringDomain, Qn as n$9, Qt as CommunityChallengeSettingSchema, R as ipnsNameToIpnsOverPubsubTopic, Rn as CommentEditSignedPropertyNames, Rt as pTimeout, Sn as CommentUpdateChallengeReservedFieldNames, St as findUpdatingComment, Tn as CommentUpdateReservedFields, Tr as boolean, U as isIpnsPath, Ut as CreateCommunityEditPublicationOptionsWithRefinementSchema, V as isIpfsPath, Vn as AuthorAddressSchema, Vt as CommunityEditPublicationSignedPropertyNames, Wn as ChallengeAnswersSchema, Wt as CommentModerationChallengeRequestToEncryptSchema, X as isRequestPubsubPublicationOfPost, Xn as n$10, Xt as ChallengeFileFactorySchema, Yn as CreateSignerSchema, Yt as CreateCommentModerationOptionsWithRefinementSchema, Z as isRequestPubsubPublicationOfReply, Zt as ChallengeFileSchema, _ as PKCUserOptionBaseSchema, _n as CommentIpfsReservedFields, _r as PKCError, _t as timestamp, an as CreateRemoteCommunityFunctionArgumentSchema, ar as t$12, b as areEquivalentCommunityAddresses, bn as CommentPubsubMessageWithFlexibleAuthorRefinementSchema, br as require_supports_color, c as ChallengeVerificationMessageSignedPropertyNames, cr as t$10, ct as resolveWhenPredicateIsTrue, dn as VoteChallengeRequestToEncryptSchema, dr as require_retry$1, en as CommunityExportRecordsSchema, er as t$13, f as DecryptedChallengeSchema, fn as VotePubsubMessagePublicationSchema, fr as FailedToFetchCommentIpfsFromGatewaysError, ft as shortifyAddress, g as PKCParsedOptionsSchema, gn as CommentChallengeRequestToEncryptSchema, gr as FailedToFetchPageIpfsFromGatewaysError, gt as throwIfAbortSignalAborted, h as NameResolverSerializedSchema, hr as FailedToFetchGenericIpfsFromGatewaysError, i as ChallengeMessageSignedPropertyNames, in as CreateNewLocalCommunityUserOptionsSchema, ir as r$8, it as removeNullUndefinedEmptyObjectsValuesRecursively, j as fetchAndValidateIpnsRecordFromGateway, jn as GetPageParamSchema, jr as string, k as doesDomainAddressHaveCapitalLetter, kr as object, l as DecryptedChallengeAnswerSchema, ln as RpcRemoteCommunityUpdateEventResultSchema, lr as t$9, m as NameResolveCacheOptionsSchema, mn as VoteSignedPropertyNames, mr as FailedToFetchCommunityFromGatewaysError, mt as sleepUntilTimeoutOrAbort, n as ChallengeAnswerMessageSignedPropertyNames, nn as CommunityIpfsSchema, nr as e$5, o as ChallengeRequestMessageSignedPropertyNames, on as CreateRpcCommunityFunctionArgumentSchema, or as n$8, p as DecryptedChallengeVerificationSchema, pr as FailedToFetchCommentUpdateFromGatewaysError, pt as shortifyCid, qn as CommunityAddressSchema, qt as CommentModerationSignedPropertyNames, rn as CommunitySignedPropertyNames, rr as t$11, sn as ExportCommunityModLogsOptionsSchema, sr as r$7, tn as CommunityIpfsReservedFields, tr as e$6, tt as raceAgainstAbort, un as CreateVoteUserOptionsWithRefinementSchema, ur as e$4, v as PKCUserOptionsSchema, vn as CommentIpfsSchema, vr as messages, vt as waitForUpdateInCommunityInstanceWithErrorAndTimeout, wn as CommentUpdateForChallengeVerificationSignedPropertyNames, wr as array, wt as listStartedCommunities, x as calculateIpfsCidV0, xn as CommentSignedPropertyNames, xr as require_ms$1, xt as findStartedCommunity, yr as logger_default, z as isAbortError, zt as CommunityEditPublicationChallengeRequestToEncryptSchema } from "./schema-B1Ot-kux.js";
3
3
  import { t as all } from "./src-CYIMjhjK.js";
4
4
  import http from "node:http";
5
5
  import { createHash } from "node:crypto";
@@ -97854,6 +97854,10 @@ async function verifyCommunity({ community, communityIpnsName, resolveAuthorName
97854
97854
  valid: false,
97855
97855
  reason: messages.ERR_COMMUNITY_IPNS_NAME_DOES_NOT_MATCH_SIGNATURE_PUBLIC_KEY
97856
97856
  };
97857
+ if (!getPeerIdFromPublicKey(community.encryption.publicKey).equals(signaturePeerId)) return {
97858
+ valid: false,
97859
+ reason: messages.ERR_COMMUNITY_ENCRYPTION_PUBLIC_KEY_DOES_NOT_MATCH_SIGNATURE_PUBLIC_KEY
97860
+ };
97857
97861
  clientsManager._pkc._memCaches.communityVerificationCache.set(cacheKey, true);
97858
97862
  return { valid: true };
97859
97863
  }
@@ -97962,12 +97966,12 @@ async function verifyChallengeRequest({ request, validateTimestampRange }) {
97962
97966
  };
97963
97967
  return _validateSignatureOfPubsubMsg(request);
97964
97968
  }
97965
- async function verifyChallengeMessage({ challenge, pubsubTopic, validateTimestampRange }) {
97969
+ async function verifyChallengeMessage({ challenge, communityChallengeSignerAddress, validateTimestampRange }) {
97966
97970
  if (!_allFieldsOfRecordInSignedPropertyNames(challenge)) return {
97967
97971
  valid: false,
97968
97972
  reason: messages.ERR_CHALLENGE_INCLUDES_FIELD_NOT_IN_SIGNED_PROPERTY_NAMES
97969
97973
  };
97970
- if (await getPKCAddressFromPublicKeyBuffer(challenge.signature.publicKey) !== pubsubTopic) return {
97974
+ if (await getPKCAddressFromPublicKeyBuffer(challenge.signature.publicKey) !== communityChallengeSignerAddress) return {
97971
97975
  valid: false,
97972
97976
  reason: messages.ERR_CHALLENGE_MSG_SIGNER_IS_NOT_COMMUNITY
97973
97977
  };
@@ -97990,12 +97994,12 @@ async function verifyChallengeAnswer({ answer, validateTimestampRange }) {
97990
97994
  };
97991
97995
  return _validateSignatureOfPubsubMsg(answer);
97992
97996
  }
97993
- async function verifyChallengeVerification({ verification, pubsubTopic, validateTimestampRange }) {
97997
+ async function verifyChallengeVerification({ verification, communityChallengeSignerAddress, validateTimestampRange }) {
97994
97998
  if (!_allFieldsOfRecordInSignedPropertyNames(verification)) return {
97995
97999
  valid: false,
97996
98000
  reason: messages.ERR_CHALLENGE_VERIFICATION_INCLUDES_FIELD_NOT_IN_SIGNED_PROPERTY_NAMES
97997
98001
  };
97998
- if (await getPKCAddressFromPublicKeyBuffer(verification.signature.publicKey) !== pubsubTopic) return {
98002
+ if (await getPKCAddressFromPublicKeyBuffer(verification.signature.publicKey) !== communityChallengeSignerAddress) return {
97999
98003
  valid: false,
98000
98004
  reason: messages.ERR_CHALLENGE_VERIFICATION_MSG_SIGNER_IS_NOT_COMMUNITY
98001
98005
  };
@@ -98603,10 +98607,14 @@ var BaseClientsManager = class BaseClientsManager {
98603
98607
  });
98604
98608
  }
98605
98609
  getDefaultKuboPubsubClient() {
98606
- const defaultKuboPubsubClient = t$13(this._pkc.clients.pubsubKuboRpcClients)[0];
98607
- if (defaultKuboPubsubClient) return this._pkc.clients.pubsubKuboRpcClients[defaultKuboPubsubClient];
98610
+ const defaultKuboPubsubClient = this.getDefaultKuboPubsubClientIfAny();
98611
+ if (defaultKuboPubsubClient) return defaultKuboPubsubClient;
98608
98612
  throw new PKCError("ERR_NO_DEFAULT_KUBO_RPC_PUBSUB_PROVIDER", { pubsubKuboRpcClients: this._pkc.clients.pubsubKuboRpcClients });
98609
98613
  }
98614
+ getDefaultKuboPubsubClientIfAny() {
98615
+ const defaultKuboPubsubClient = t$13(this._pkc.clients.pubsubKuboRpcClients)[0];
98616
+ return defaultKuboPubsubClient ? this._pkc.clients.pubsubKuboRpcClients[defaultKuboPubsubClient] : void 0;
98617
+ }
98610
98618
  getIpfsClientWithKuboRpcClientFunctions() {
98611
98619
  const defaultKuboRpcClient = t$13(this._pkc.clients.kuboRpcClients)[0];
98612
98620
  if (defaultKuboRpcClient) return this._pkc.clients.kuboRpcClients[defaultKuboRpcClient]._client;
@@ -124735,6 +124743,10 @@ var CommunityClientsManager = class extends PKCClientsManager {
124735
124743
  updateKuboRpcPubsubState(newState, pubsubProvider) {
124736
124744
  super.updateKuboRpcPubsubState(newState, pubsubProvider);
124737
124745
  }
124746
+ updateKuboRpcPubsubStateIfProviderExists(newState) {
124747
+ const pubsubClient = this.getDefaultKuboPubsubClientIfAny();
124748
+ if (pubsubClient) this.updateKuboRpcPubsubState(newState, pubsubClient.url);
124749
+ }
124738
124750
  updateGatewayState(newState, gateway) {
124739
124751
  super.updateGatewayState(newState, gateway);
124740
124752
  }
@@ -125488,6 +125500,7 @@ var RemoteCommunity = class extends import_lib$1.TypedEmitter {
125488
125500
  const log = logger_default("pkc-js:remote-community:initCommunityIpfsPropsNoMerge");
125489
125501
  this.raw.communityIpfs = newProps;
125490
125502
  this.initRemoteCommunityPropsNoMerge(newProps);
125503
+ this.pubsubTopicRoutingCid = newProps.pubsubTopic ? pubsubTopicToDhtKey(newProps.pubsubTopic) : void 0;
125491
125504
  const unknownProps = r$8(t$13(this.raw.communityIpfs), t$13(CommunityIpfsSchema.shape));
125492
125505
  if (unknownProps.length > 0) {
125493
125506
  log(`Found unknown props on community (${this.address}) ipfs record`, unknownProps);
@@ -125513,10 +125526,7 @@ var RemoteCommunity = class extends import_lib$1.TypedEmitter {
125513
125526
  this.ipnsPubsubTopic = ipnsNameToIpnsOverPubsubTopic(this.ipnsName);
125514
125527
  this.ipnsPubsubTopicRoutingCid = pubsubTopicToDhtKey(this.ipnsPubsubTopic);
125515
125528
  }
125516
- if (!this.pubsubTopicRoutingCid) {
125517
- if ("pubsubTopicRoutingCid" in newProps) this.pubsubTopicRoutingCid = newProps.pubsubTopicRoutingCid;
125518
- else if (this.raw.communityIpfs) this.pubsubTopicRoutingCid = pubsubTopicToDhtKey(newProps.pubsubTopic || this.pubsubTopic || ("address" in newProps ? newProps.address : void 0) || this.address);
125519
- }
125529
+ if (!this.pubsubTopicRoutingCid && "pubsubTopicRoutingCid" in newProps) this.pubsubTopicRoutingCid = newProps.pubsubTopicRoutingCid;
125520
125530
  }
125521
125531
  initRemoteCommunityPropsNoMerge(newProps) {
125522
125532
  const incomingIpnsHops = newProps.ipnsHops;
@@ -125584,6 +125594,7 @@ var RemoteCommunity = class extends import_lib$1.TypedEmitter {
125584
125594
  this.raw.communityIpfs = void 0;
125585
125595
  this.updateCid = void 0;
125586
125596
  this.initRemoteCommunityPropsNoMerge({});
125597
+ this.pubsubTopicRoutingCid = void 0;
125587
125598
  this.publicKey = newPublicKey;
125588
125599
  this.ipnsName = newPublicKey;
125589
125600
  this.ipnsPubsubTopic = ipnsNameToIpnsOverPubsubTopic(newPublicKey);