@pkcprotocol/pkc-js 0.0.97 → 0.0.99

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 (63) hide show
  1. package/dist/browser/clients/base-client-manager.js +10 -1
  2. package/dist/browser/clients/base-client-manager.js.map +1 -1
  3. package/dist/browser/errors.d.ts +1 -0
  4. package/dist/browser/errors.js +1 -0
  5. package/dist/browser/errors.js.map +1 -1
  6. package/dist/browser/generated-version.d.ts +1 -1
  7. package/dist/browser/generated-version.js +1 -1
  8. package/dist/browser/helia/helia-for-pkc.js +47 -1
  9. package/dist/browser/helia/helia-for-pkc.js.map +1 -1
  10. package/dist/browser/pkc-error.d.ts +1 -1
  11. package/dist/browser/publications/publication.js +20 -2
  12. package/dist/browser/publications/publication.js.map +1 -1
  13. package/dist/browser/runtime/node/community/local-community/challenges.js +131 -17
  14. package/dist/browser/runtime/node/community/local-community/challenges.js.map +1 -1
  15. package/dist/browser/runtime/node/community/local-community/defaults.d.ts +1 -0
  16. package/dist/browser/runtime/node/community/local-community/defaults.js +5 -0
  17. package/dist/browser/runtime/node/community/local-community/defaults.js.map +1 -1
  18. package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +18 -4
  19. package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
  20. package/dist/browser/runtime/node/community/local-community/lifecycle.js +5 -4
  21. package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
  22. package/dist/browser/runtime/node/community/local-community/publication-store.js +12 -1
  23. package/dist/browser/runtime/node/community/local-community/publication-store.js.map +1 -1
  24. package/dist/browser/runtime/node/community/local-community.d.ts +2 -0
  25. package/dist/browser/runtime/node/community/local-community.js +8 -1
  26. package/dist/browser/runtime/node/community/local-community.js.map +1 -1
  27. package/dist/bundled/bundle-manifest.json +25 -25
  28. package/dist/bundled/chunks/{helia-for-pkc-BvZheFmK.js → helia-for-pkc-DUaUFShG.js} +28 -2
  29. package/dist/bundled/chunks/{local-community-CE8orbFt.js → local-community-BGcQIioy.js} +102 -23
  30. package/dist/bundled/chunks/{local-community-bPjJm35w.js → local-community-CM2GS9Ya.js} +1 -1
  31. package/dist/bundled/chunks/{node-DmZww4LL.js → node-CF18iVMW.js} +14 -7
  32. package/dist/bundled/chunks/{rpc-local-community-CH7vnXLI.js → rpc-local-community-CTyhIJyD.js} +2 -1
  33. package/dist/bundled/chunks/{schema-DzFAY-My.js → schema-f2Zr1ZxK.js} +2 -1
  34. package/dist/bundled/chunks/{util-BiM-_F_H.js → util-BbXV7Dcu.js} +1 -1
  35. package/dist/bundled/index.js +1 -1
  36. package/dist/bundled/rpc/src/index.js +4 -4
  37. package/dist/node/clients/base-client-manager.js +10 -1
  38. package/dist/node/clients/base-client-manager.js.map +1 -1
  39. package/dist/node/errors.d.ts +1 -0
  40. package/dist/node/errors.js +1 -0
  41. package/dist/node/errors.js.map +1 -1
  42. package/dist/node/generated-version.d.ts +1 -1
  43. package/dist/node/generated-version.js +1 -1
  44. package/dist/node/helia/helia-for-pkc.js +47 -1
  45. package/dist/node/helia/helia-for-pkc.js.map +1 -1
  46. package/dist/node/pkc-error.d.ts +1 -1
  47. package/dist/node/publications/publication.js +20 -2
  48. package/dist/node/publications/publication.js.map +1 -1
  49. package/dist/node/runtime/node/community/local-community/challenges.js +131 -17
  50. package/dist/node/runtime/node/community/local-community/challenges.js.map +1 -1
  51. package/dist/node/runtime/node/community/local-community/defaults.d.ts +1 -0
  52. package/dist/node/runtime/node/community/local-community/defaults.js +5 -0
  53. package/dist/node/runtime/node/community/local-community/defaults.js.map +1 -1
  54. package/dist/node/runtime/node/community/local-community/ipns-publishing.js +18 -4
  55. package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
  56. package/dist/node/runtime/node/community/local-community/lifecycle.js +5 -4
  57. package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
  58. package/dist/node/runtime/node/community/local-community/publication-store.js +12 -1
  59. package/dist/node/runtime/node/community/local-community/publication-store.js.map +1 -1
  60. package/dist/node/runtime/node/community/local-community.d.ts +2 -0
  61. package/dist/node/runtime/node/community/local-community.js +8 -1
  62. package/dist/node/runtime/node/community/local-community.js.map +1 -1
  63. 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 { B as ipnsNameToIpnsOverPubsubTopic, R as hideClassPrivateProps, Sr as PKCError, wr as logger_default, x as binaryKeyToPubsubTopic } from "./schema-DzFAY-My.js";
3
- import { a as fetchBlockWithStalledSessionFailover, c as selectBitswapSessionSeedPeers, i as directFetchIpnsRecordFromProviders, n as cacheIpnsRecordInPubsubLocalStore, o as getHeliaDebugContext, r as connectToPubsubPeers, s as readFreshCachedIpnsRecordFromPubsubLocalStore } from "./util-BiM-_F_H.js";
2
+ import { B as ipnsNameToIpnsOverPubsubTopic, R as hideClassPrivateProps, Sr as PKCError, wr as logger_default, x as binaryKeyToPubsubTopic } from "./schema-f2Zr1ZxK.js";
3
+ import { a as fetchBlockWithStalledSessionFailover, c as selectBitswapSessionSeedPeers, i as directFetchIpnsRecordFromProviders, n as cacheIpnsRecordInPubsubLocalStore, o as getHeliaDebugContext, r as connectToPubsubPeers, s as readFreshCachedIpnsRecordFromPubsubLocalStore } from "./util-BbXV7Dcu.js";
4
4
  import { t as map } from "./src-Cpx2Sts8.js";
5
5
  import { t as parallelBatch } from "./src-DKntVmyX.js";
6
6
  import { fileURLToPath } from "node:url";
@@ -6486,6 +6486,7 @@ function getDelegatedRoutingFields(routers) {
6486
6486
  try {
6487
6487
  yield* originalFindProviders(cid, options);
6488
6488
  } catch (e) {
6489
+ if (options?.signal?.aborted) return;
6489
6490
  log.trace("Content router", routerUrl, "errored during findProviders; treating it as returning no providers", e);
6490
6491
  }
6491
6492
  };
@@ -6700,6 +6701,9 @@ async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
6700
6701
  ...getHeliaDebugContext(helia)
6701
6702
  });
6702
6703
  };
6704
+ const catStopController = new AbortController();
6705
+ const inFlightCats = /* @__PURE__ */ new Set();
6706
+ const IN_FLIGHT_CATS_UNWIND_TIMEOUT_MS = 5e3;
6703
6707
  const heliaWithKuboRpcClientShape = {
6704
6708
  name: { resolve: (ipnsName, options) => {
6705
6709
  throwIfHeliaIsStoppingOrStopped();
@@ -6846,6 +6850,16 @@ async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
6846
6850
  const abortFromCallerSignal = () => controller.abort(callerSignal?.reason);
6847
6851
  if (callerSignal?.aborted) abortFromCallerSignal();
6848
6852
  else callerSignal?.addEventListener("abort", abortFromCallerSignal, { once: true });
6853
+ const abortFromStop = () => controller.abort(new PKCError("ERR_HELIAS_STOPPING_OR_STOPPED", {
6854
+ heliaKey: pkcOptions.key,
6855
+ ipfsPath,
6856
+ ...getHeliaDebugContext(helia)
6857
+ }));
6858
+ if (catStopController.signal.aborted) abortFromStop();
6859
+ else catStopController.signal.addEventListener("abort", abortFromStop, { once: true });
6860
+ let markUnwound;
6861
+ const unwound = new Promise((resolve) => markUnwound = resolve);
6862
+ inFlightCats.add(unwound);
6849
6863
  const timeoutTimer = timeoutMs !== void 0 ? setTimeout(() => controller.abort(new PKCError("ERR_FETCH_CID_P2P_TIMEOUT", {
6850
6864
  ipfsPath,
6851
6865
  timeoutMs
@@ -6894,6 +6908,9 @@ async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
6894
6908
  } finally {
6895
6909
  if (timeoutTimer !== void 0) clearTimeout(timeoutTimer);
6896
6910
  callerSignal?.removeEventListener("abort", abortFromCallerSignal);
6911
+ catStopController.signal.removeEventListener("abort", abortFromStop);
6912
+ inFlightCats.delete(unwound);
6913
+ markUnwound();
6897
6914
  }
6898
6915
  })();
6899
6916
  },
@@ -6961,6 +6978,15 @@ async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
6961
6978
  }
6962
6979
  }
6963
6980
  for (const topic of helia.libp2p.services.pubsub.getTopics()) helia.libp2p.services.pubsub.unsubscribe(topic);
6981
+ catStopController.abort();
6982
+ if (inFlightCats.size > 0) {
6983
+ const unwindTimeout = new AbortController();
6984
+ const allUnwound = Promise.all([...inFlightCats]).then(() => "unwound");
6985
+ const timedOut = delayAbortable(IN_FLIGHT_CATS_UNWIND_TIMEOUT_MS, unwindTimeout.signal).then(() => "timed out");
6986
+ const outcome = await Promise.race([allUnwound, timedOut]);
6987
+ unwindTimeout.abort();
6988
+ if (outcome === "timed out") log.error("Timed out waiting for", inFlightCats.size, "in-flight cat() call(s) to unwind before stopping helia");
6989
+ }
6964
6990
  for (const connection of helia.libp2p.getConnections()) try {
6965
6991
  connection.abort(/* @__PURE__ */ new Error("pkc-js libp2p instance is stopping"));
6966
6992
  } catch (e) {
@@ -1,6 +1,6 @@
1
1
  import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
2
- import { A as doesDomainAddressHaveCapitalLetter, B as ipnsNameToIpnsOverPubsubTopic, Bn as CommentEditPubsubMessagePublicationSchema, Bt as require_sha256, C as calculateStringSizeSameAsIpfsAddCidV0, Cn as CommentIpfsSchema, Cr as messages, Ct as writeKuboFilesWithTimeout, Dt as findUpdatingCommunity, E as contentContainsMarkdownVideos, F as getErrorCodeFromMessage, Hn as CommentEditReservedFields, I as getIpnsRecordInLocalKuboNode, It as trackUpdatingCommunity, J as isLinkOfImage, Jn as AuthorReservedFields, K as isLinkOfAnimatedImage, Lr as ZodError, Lt as untrackStartedCommunity, N as genToArray, Nn as CommentUpdateTableRowSchema, Nt as syncCommunityRegistryEntry, P as getEquivalentCommunityAddresses, Pn as CommentsTableRowSchema, Pt as trackStartedCommunity, Qt as CommentModerationsTableRowSchema, R as hideClassPrivateProps, S as calculateIpfsCidV0, Sr as PKCError, T as contentContainsMarkdownImages, Tt as findStartedCommunity, Vn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Wn as CommentEditsTableRowSchema, Wt as CommunityEditPublicationPubsubReservedFields, X as isLinkOfVideo, Xt as CommentModerationReservedFields, Y as isLinkOfMedia, Yt as CommentModerationPubsubMessagePublicationSchema, Z as isLinkValid, _n as VotePubsubMessagePublicationSchema, a as ChallengeRequestMessageSchema, ar as t$6, b as areEquivalentCommunityAddresses, bn as VoteTablesRowSchema, cn as CommunitySignedPropertyNames, d as DecryptedChallengeRequestSchema, et as isStringDomain, gr as require_retry, ht as retryKuboIpfsAddAndProvide, ir as t$7, jn as CommentUpdateSchema, k as derivePublicationFromChallengeRequest, lr as r$1, lt as removeNullUndefinedValues, mr as t$3, nr as t$8, or as e, ot as removeBlocksFromKuboNode, pr as t$5, pt as retryKuboBlockPutPinAndProvidePubsubTopic, q as isLinkOfAudio, r as ChallengeMessageSchema, rr as n$3, s as ChallengeVerificationMessageSchema, sn as CommunityIpfsSchema, sr as e$1, st as removeMfsFilesSafely, t as ChallengeAnswerMessageSchema, tr as n$4, tt as pubsubTopicToDhtKey, u as DecryptedChallengeRequestPublicationSchema, ur as t$4, vn as VotePubsubReservedFields, vt as sleepUntilTimeoutOrAbort, w as contentContainsMarkdownAudio, wn as CommentPubsubMessageReservedFields, wr as logger_default, wt as findCommunityInRegistry, xt as timestamp, y as version_default, yt as statMfsPathSafely, zt as untrackUpdatingCommunity } from "./schema-DzFAY-My.js";
3
- import { $t as getPublicKeyFromPrivateKey, A as deriveDbPosts, At as verifyCommentIpfs, Bt as getAuthorNameFromWire, C as BackupAbortError, Cn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Dt as verifyChallengeRequest, E as calculateInlineRepliesBudget, En as parseJsonWithPKCErrorIfFails, F as importSignerIntoKuboNode, Ft as verifyCommunityEdit, G as REPLY_REPLIES_SORT_TYPES, Gt as getCommunityPublicKeyFromWire, It as verifyVote, Jt as encode, K as TIMEFRAMES_TO_SECONDS, Lt as buildRuntimeAuthor, M as getDefaultCommunityDbConfig, Mt as verifyCommentPubsubMessage, Nt as verifyCommentUpdate, O as deleteOldCommunityInWindows, P as getThumbnailPropsOfLink, Pt as verifyCommunity, Qt as getPKCAddressFromPublicKeySync, R as moveCommunityDbToDeletedDirectory, Rt as cleanWireAuthor, S as encryptEd25519AesGcmPublicKeyBuffer, St as signCommunity, T as calculateExpectedSignatureSize, Tt as verifyChallengeAnswer, U as POSTS_SORT_TYPES, W as POST_REPLIES_SORT_TYPES, Wt as getCommunityNameFromWire, Xt as getIpfsKeyFromPrivateKey, Z as iterateOverPageCidsToFindAllCids, Zt as getPKCAddressFromPublicKey, _t as signComment, a as loadChallengeFileFromCommunityChallengeSettings, ar as t$11, b as decryptEd25519AesGcmPublicKeyBuffer, bt as signCommentUpdate, c as LRUCache, d as KeyvBetterSqlite3, dn as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, dr as STORAGE_KEYS, en as createSchemaRowParser, er as crosspostChainDepthUpTo, fr as require_lodash_merge, ft as cleanUpBeforePublishing, g as SignerWithPublicKeyAddress, gt as signChallengeVerification, i as getCommunityChallengeFromCommunityChallengeSettings, ir as r$2, j as deriveDbReplies, jt as verifyCommentModeration, k as deriveCommentIpfsFromCommentTableRow, kt as verifyCommentEdit, lr as t$10, lt as pLimit, mt as signChallengeMessage, nr as t$9, o as pkcJsChallenges, or as n$6, pn as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, qt as decode, r as getChallengeVerification, rr as t$12, s as TrackedInstanceRegistry, sr as n$5, t as RpcLocalCommunity, tr as effectiveMaxCrosspostDepth, u as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, ur as stringify, vt as signCommentEdit, w as backupCommunityDb, xt as signCommentUpdateForChallengeVerification, z as resolveDbPostsCidRefs } from "./rpc-local-community-CH7vnXLI.js";
2
+ import { A as doesDomainAddressHaveCapitalLetter, B as ipnsNameToIpnsOverPubsubTopic, Bn as CommentEditPubsubMessagePublicationSchema, Bt as require_sha256, C as calculateStringSizeSameAsIpfsAddCidV0, Cn as CommentIpfsSchema, Cr as messages, Ct as writeKuboFilesWithTimeout, Dt as findUpdatingCommunity, E as contentContainsMarkdownVideos, F as getErrorCodeFromMessage, Hn as CommentEditReservedFields, Ht as pTimeout, I as getIpnsRecordInLocalKuboNode, It as trackUpdatingCommunity, J as isLinkOfImage, Jn as AuthorReservedFields, K as isLinkOfAnimatedImage, Lr as ZodError, Lt as untrackStartedCommunity, N as genToArray, Nn as CommentUpdateTableRowSchema, Nt as syncCommunityRegistryEntry, P as getEquivalentCommunityAddresses, Pn as CommentsTableRowSchema, Pt as trackStartedCommunity, Qt as CommentModerationsTableRowSchema, R as hideClassPrivateProps, S as calculateIpfsCidV0, Sr as PKCError, T as contentContainsMarkdownImages, Tt as findStartedCommunity, Vn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Wn as CommentEditsTableRowSchema, Wt as CommunityEditPublicationPubsubReservedFields, X as isLinkOfVideo, Xt as CommentModerationReservedFields, Y as isLinkOfMedia, Yt as CommentModerationPubsubMessagePublicationSchema, Z as isLinkValid, _n as VotePubsubMessagePublicationSchema, a as ChallengeRequestMessageSchema, ar as t$6, b as areEquivalentCommunityAddresses, bn as VoteTablesRowSchema, cn as CommunitySignedPropertyNames, d as DecryptedChallengeRequestSchema, et as isStringDomain, gr as require_retry, ht as retryKuboIpfsAddAndProvide, ir as t$7, jn as CommentUpdateSchema, k as derivePublicationFromChallengeRequest, lr as r$1, lt as removeNullUndefinedValues, mr as t$3, nr as t$8, or as e, ot as removeBlocksFromKuboNode, pr as t$5, pt as retryKuboBlockPutPinAndProvidePubsubTopic, q as isLinkOfAudio, r as ChallengeMessageSchema, rr as n$3, s as ChallengeVerificationMessageSchema, sn as CommunityIpfsSchema, sr as e$1, st as removeMfsFilesSafely, t as ChallengeAnswerMessageSchema, tr as n$4, tt as pubsubTopicToDhtKey, u as DecryptedChallengeRequestPublicationSchema, ur as t$4, vn as VotePubsubReservedFields, vt as sleepUntilTimeoutOrAbort, w as contentContainsMarkdownAudio, wn as CommentPubsubMessageReservedFields, wr as logger_default, wt as findCommunityInRegistry, xt as timestamp, y as version_default, yt as statMfsPathSafely, zt as untrackUpdatingCommunity } from "./schema-f2Zr1ZxK.js";
3
+ import { $t as getPublicKeyFromPrivateKey, A as deriveDbPosts, At as verifyCommentIpfs, Bt as getAuthorNameFromWire, C as BackupAbortError, Cn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Dt as verifyChallengeRequest, E as calculateInlineRepliesBudget, En as parseJsonWithPKCErrorIfFails, F as importSignerIntoKuboNode, Ft as verifyCommunityEdit, G as REPLY_REPLIES_SORT_TYPES, Gt as getCommunityPublicKeyFromWire, It as verifyVote, Jt as encode, K as TIMEFRAMES_TO_SECONDS, Lt as buildRuntimeAuthor, M as getDefaultCommunityDbConfig, Mt as verifyCommentPubsubMessage, Nt as verifyCommentUpdate, O as deleteOldCommunityInWindows, P as getThumbnailPropsOfLink, Pt as verifyCommunity, Qt as getPKCAddressFromPublicKeySync, R as moveCommunityDbToDeletedDirectory, Rt as cleanWireAuthor, S as encryptEd25519AesGcmPublicKeyBuffer, St as signCommunity, T as calculateExpectedSignatureSize, Tt as verifyChallengeAnswer, U as POSTS_SORT_TYPES, W as POST_REPLIES_SORT_TYPES, Wt as getCommunityNameFromWire, Xt as getIpfsKeyFromPrivateKey, Z as iterateOverPageCidsToFindAllCids, Zt as getPKCAddressFromPublicKey, _t as signComment, a as loadChallengeFileFromCommunityChallengeSettings, ar as t$11, b as decryptEd25519AesGcmPublicKeyBuffer, bt as signCommentUpdate, c as LRUCache, d as KeyvBetterSqlite3, dn as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, dr as STORAGE_KEYS, en as createSchemaRowParser, er as crosspostChainDepthUpTo, fr as require_lodash_merge, ft as cleanUpBeforePublishing, g as SignerWithPublicKeyAddress, gt as signChallengeVerification, i as getCommunityChallengeFromCommunityChallengeSettings, ir as r$2, j as deriveDbReplies, jt as verifyCommentModeration, k as deriveCommentIpfsFromCommentTableRow, kt as verifyCommentEdit, lr as t$10, lt as pLimit, mt as signChallengeMessage, nr as t$9, o as pkcJsChallenges, or as n$6, pn as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, qt as decode, r as getChallengeVerification, rr as t$12, s as TrackedInstanceRegistry, sr as n$5, t as RpcLocalCommunity, tr as effectiveMaxCrosspostDepth, u as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, ur as stringify, vt as signCommentEdit, w as backupCommunityDb, xt as signCommentUpdateForChallengeVerification, z as resolveDbPostsCidRefs } from "./rpc-local-community-CTyhIJyD.js";
4
4
  import { randomFillSync, randomUUID } from "node:crypto";
5
5
  import { fileURLToPath, pathToFileURL } from "node:url";
6
6
  import Path from "node:path";
@@ -678,6 +678,7 @@ const DUPLICATE_PUBLICATION_ERRORS = new Set([
678
678
  messages.ERR_DUPLICATE_COMMENT_EDIT,
679
679
  messages.ERR_DUPLICATE_COMMENT_MODERATION
680
680
  ]);
681
+ const CHALLENGE_EXCHANGE_TTL_MS = 600 * 1e3;
681
682
  const defaultChallengeQuestionText = "What is the answer to this community's challenge? (check community.settings.challenges to see the answer, or set your own challenge)";
682
683
  function generateDefaultChallenges(answer) {
683
684
  return [{
@@ -784,6 +785,7 @@ async function publishIdempotentDuplicateVerification(community, request, challe
784
785
  author: { community: authorCommunity },
785
786
  cid: existingComment.cid,
786
787
  protocolVersion: version_default.PROTOCOL_VERSION,
788
+ pendingApproval: existingComment.pendingApproval ? true : void 0,
787
789
  ...commentNumberPostNumber
788
790
  });
789
791
  const commentUpdate = {
@@ -794,7 +796,7 @@ async function publishIdempotentDuplicateVerification(community, request, challe
794
796
  })
795
797
  };
796
798
  toEncryptDecrypted = {
797
- comment: CommentIpfsSchema.strip().parse(existingComment),
799
+ comment: deriveCommentIpfsFromCommentTableRow(existingComment),
798
800
  commentUpdate
799
801
  };
800
802
  encrypted = await encryptEd25519AesGcmPublicKeyBuffer(stringify(toEncryptDecrypted), community.signer.privateKey, request.signature.publicKey);
@@ -871,7 +873,12 @@ async function publishChallengeVerification(community, challengeResult, request,
871
873
  try {
872
874
  toEncrypt = await storePublicationAndEncryptForChallengeVerification(community, request, pendingApproval, challengeAggregate);
873
875
  } catch (e) {
874
- failureReason = e.message;
876
+ const error = e;
877
+ if (DUPLICATE_PUBLICATION_ERRORS.has(error.message)) {
878
+ log("Publication was stored by an overlapping exchange, answering idempotently", request.challengeRequestId.toString());
879
+ return publishIdempotentDuplicateVerification(community, request, request.challengeRequestId, error.message);
880
+ }
881
+ failureReason = error.message;
875
882
  log.error("Failed to store store Publication And Encrypt For ChallengeVerification", e);
876
883
  }
877
884
  const toSignMsg = cleanUpBeforePublishing({
@@ -968,7 +975,7 @@ function buildRuntimeChallengeRequest({ request, authorCommunity }) {
968
975
  });
969
976
  return runtimeRequest;
970
977
  }
971
- async function parseAndValidateChallengeRequest(community, request, log) {
978
+ async function parseChallengeRequest(community, request, log) {
972
979
  const decryptedRequest = await parseChallengeRequestPublicationOrRespondWithFailure(community, request, await decryptOrRespondWithFailure(community, request));
973
980
  const publicationFieldNames = t$6(DecryptedChallengeRequestPublicationSchema.shape);
974
981
  let publication;
@@ -1014,18 +1021,34 @@ async function parseAndValidateChallengeRequest(community, request, log) {
1014
1021
  }
1015
1022
  log.trace("Received a valid challenge request", decryptedRequestWithCommunityAuthor);
1016
1023
  community.emit("challengerequest", decryptedRequestWithCommunityAuthor);
1024
+ return {
1025
+ decryptedRequestMsg,
1026
+ publication
1027
+ };
1028
+ }
1029
+ async function validatePublicationOrRespondWithFailure({ community, decryptedRequestMsg, publication, countDuplicateAttempt }) {
1030
+ const authorSignerAddress = await getPKCAddressFromPublicKey(publication.signature.publicKey);
1031
+ const authorDomain = getAuthorNameFromWire(publication.author);
1032
+ const communityAuthor = community._dbHandler.queryCommunityAuthor(authorSignerAddress, authorDomain);
1033
+ const decryptedRequestWithCommunityAuthor = buildRuntimeChallengeRequest({
1034
+ request: decryptedRequestMsg,
1035
+ authorCommunity: communityAuthor
1036
+ });
1017
1037
  const publicationInvalidityReason = await checkPublicationValidity(community, decryptedRequestMsg, publication, communityAuthor);
1018
1038
  if (publicationInvalidityReason) {
1019
1039
  if (DUPLICATE_PUBLICATION_ERRORS.has(publicationInvalidityReason)) {
1020
1040
  const sig = publication.signature.signature;
1021
- const attempts = (community._duplicatePublicationAttempts.get(sig) || 0) + 1;
1022
- community._duplicatePublicationAttempts.set(sig, attempts);
1041
+ let attempts = 0;
1042
+ if (countDuplicateAttempt) {
1043
+ attempts = (community._duplicatePublicationAttempts.get(sig) || 0) + 1;
1044
+ community._duplicatePublicationAttempts.set(sig, attempts);
1045
+ }
1023
1046
  if (attempts <= 1) {
1024
- await publishIdempotentDuplicateVerification(community, decryptedRequestMsg, request.challengeRequestId, publicationInvalidityReason);
1047
+ await publishIdempotentDuplicateVerification(community, decryptedRequestMsg, decryptedRequestMsg.challengeRequestId, publicationInvalidityReason);
1025
1048
  return;
1026
1049
  }
1027
1050
  }
1028
- await publishFailedChallengeVerification(community, { reason: publicationInvalidityReason }, request.challengeRequestId);
1051
+ await publishFailedChallengeVerification(community, { reason: publicationInvalidityReason }, decryptedRequestMsg.challengeRequestId);
1029
1052
  return;
1030
1053
  }
1031
1054
  return {
@@ -1040,12 +1063,21 @@ async function runChallengeExchangeIfNeeded(community, parsed, log) {
1040
1063
  const answerPromiseKey = decryptedRequestWithCommunityAuthor.challengeRequestId.toString();
1041
1064
  const getChallengeAnswers = async (challenges) => {
1042
1065
  await publishChallenges(community, challenges, decryptedRequestWithCommunityAuthor);
1066
+ community._ongoingChallengeExchanges.set(answerPromiseKey, true);
1043
1067
  const challengeAnswerPromise = new Promise((resolve, reject) => community._challengeAnswerResolveReject.set(answerPromiseKey, {
1044
1068
  resolve,
1045
1069
  reject
1046
1070
  }));
1047
1071
  community._challengeAnswerPromises.set(answerPromiseKey, challengeAnswerPromise);
1048
- const challengeAnswers = await community._challengeAnswerPromises.get(answerPromiseKey);
1072
+ const challengeAnswers = await pTimeout(challengeAnswerPromise, {
1073
+ milliseconds: community._challengeExchangeTtlMs,
1074
+ fallback: () => {
1075
+ throw new PKCError("ERR_COMMUNITY_TIMED_OUT_WAITING_FOR_CHALLENGE_ANSWER", {
1076
+ challengeRequestId: answerPromiseKey,
1077
+ challengeExchangeTtlMs: community._challengeExchangeTtlMs
1078
+ });
1079
+ }
1080
+ });
1049
1081
  if (!challengeAnswers) throw Error("Failed to retrieve challenge answers from promise. This is a critical error");
1050
1082
  cleanUpChallengeAnswerPromise(community, answerPromiseKey);
1051
1083
  return challengeAnswers;
@@ -1058,6 +1090,15 @@ async function runChallengeExchangeIfNeeded(community, parsed, log) {
1058
1090
  getChallengeAnswers
1059
1091
  });
1060
1092
  } catch (e) {
1093
+ if (e instanceof PKCError && e.code === "ERR_COMMUNITY_TIMED_OUT_WAITING_FOR_CHALLENGE_ANSWER") {
1094
+ log("Timed out waiting for the challenge answer, failing the exchange", answerPromiseKey);
1095
+ cleanUpChallengeAnswerPromise(community, answerPromiseKey);
1096
+ challengeVerification = {
1097
+ challengeSuccess: false,
1098
+ reason: messages.ERR_COMMUNITY_TIMED_OUT_WAITING_FOR_CHALLENGE_ANSWER
1099
+ };
1100
+ return challengeVerification;
1101
+ }
1061
1102
  log.error("getChallenge failed, the community owner needs to check the challenge code. The error is: ", e);
1062
1103
  community.emit("error", e);
1063
1104
  challengeVerification = {
@@ -1095,11 +1136,39 @@ async function handleChallengeRequest(community, request, isLocalPublisher) {
1095
1136
  validateTimestampRange: true
1096
1137
  });
1097
1138
  if (!requestSignatureValidation.valid) throw new PKCError(getErrorCodeFromMessage(requestSignatureValidation.reason), { challengeRequest: n$3(request, ["encrypted"]) });
1098
- const parsed = await parseAndValidateChallengeRequest(community, request, log);
1099
- if (!parsed) return;
1100
- const challengeVerification = await runChallengeExchangeIfNeeded(community, parsed, log);
1101
- if (!challengeVerification) return;
1102
- await runVerificationAndStorePublication(community, parsed, challengeVerification);
1139
+ const decrypted = await parseChallengeRequest(community, request, log);
1140
+ if (!decrypted) return;
1141
+ const publicationSignature = decrypted.publication.signature.signature;
1142
+ let waitedForInFlightExchange = false;
1143
+ while (community._inFlightPublicationExchanges.has(publicationSignature)) {
1144
+ waitedForInFlightExchange = true;
1145
+ log("Received a challenge request for a signed publication whose challenge exchange is in flight, waiting for it to settle", request.challengeRequestId.toString());
1146
+ if (!await pTimeout(community._inFlightPublicationExchanges.get(publicationSignature), {
1147
+ milliseconds: community._challengeExchangeTtlMs,
1148
+ fallback: () => false
1149
+ }).then((result) => result !== false)) {
1150
+ log("The in-flight challenge exchange did not settle within the challenge exchange ttl, proceeding with this request", request.challengeRequestId.toString());
1151
+ break;
1152
+ }
1153
+ }
1154
+ let settleInFlightExchange;
1155
+ const inFlightExchange = new Promise((resolve) => settleInFlightExchange = resolve);
1156
+ community._inFlightPublicationExchanges.set(publicationSignature, inFlightExchange);
1157
+ try {
1158
+ const parsed = await validatePublicationOrRespondWithFailure({
1159
+ community,
1160
+ decryptedRequestMsg: decrypted.decryptedRequestMsg,
1161
+ publication: decrypted.publication,
1162
+ countDuplicateAttempt: !waitedForInFlightExchange
1163
+ });
1164
+ if (!parsed) return;
1165
+ const challengeVerification = await runChallengeExchangeIfNeeded(community, parsed, log);
1166
+ if (!challengeVerification) return;
1167
+ await runVerificationAndStorePublication(community, parsed, challengeVerification);
1168
+ } finally {
1169
+ if (community._inFlightPublicationExchanges.get(publicationSignature) === inFlightExchange) community._inFlightPublicationExchanges.delete(publicationSignature);
1170
+ settleInFlightExchange();
1171
+ }
1103
1172
  }
1104
1173
  async function parseChallengeAnswerOrRespondWithFailure(community, challengeAnswer, decryptedRawString) {
1105
1174
  let parsedJson;
@@ -1602,9 +1671,9 @@ async function storeCommentEdit(community, commentEditRaw, challengeRequestId) {
1602
1671
  if (isPending || isDisapproved) {
1603
1672
  log("Author deleted a pending/disapproved comment, purging immediately", commentEditRaw.commentCid);
1604
1673
  community._dbHandler.purgeComment(commentEditRaw.commentCid);
1605
- community._communityUpdateTrigger = true;
1606
1674
  }
1607
1675
  }
1676
+ community._communityUpdateTrigger = true;
1608
1677
  }
1609
1678
  async function storeCommentModeration(community, commentModRaw, challengeRequestId) {
1610
1679
  const log = logger_default("pkc-js:local-community:storeCommentModeration");
@@ -1685,6 +1754,7 @@ async function storeVote(community, newVoteProps, challengeRequestId) {
1685
1754
  voteTableRow.extraProps = t$9(newVoteProps, extraPropsInVote);
1686
1755
  }
1687
1756
  community._dbHandler.insertVotes([voteTableRow]);
1757
+ community._communityUpdateTrigger = true;
1688
1758
  log("Inserted vote", "of comment", voteTableRow.commentCid, "into db", "with props", voteTableRow);
1689
1759
  }
1690
1760
  async function storeCommunityEditPublication(community, editProps, challengeRequestId) {
@@ -1763,6 +1833,7 @@ async function storeComment(community, opts) {
1763
1833
  community._dbHandler.rollbackTransaction();
1764
1834
  throw e;
1765
1835
  }
1836
+ if (pendingApproval) community._communityUpdateTrigger = true;
1766
1837
  log("Inserted comment", commentRow.cid, "into db", "with props", commentRow);
1767
1838
  return {
1768
1839
  comment: commentIpfs,
@@ -6606,7 +6677,6 @@ async function publishCommunityRecordToIpns(community, build, newCommunityRecord
6606
6677
  const remainingEditProps = Object.assign({}, ...community._pendingEditProps.map((editProps) => t$9(editProps, t$6(CommunityIpfsSchema.shape))));
6607
6678
  Object.assign(community, remainingEditProps);
6608
6679
  }
6609
- community._communityUpdateTrigger = false;
6610
6680
  community._firstUpdateAfterStart = false;
6611
6681
  try {
6612
6682
  const ipnsRecord = await getIpnsRecordInLocalKuboNode(kuboRpcClient, community.signer.address);
@@ -6629,9 +6699,15 @@ async function updateCommunityIpnsIfNeeded(community, commentUpdateRowsToPublish
6629
6699
  const log = logger_default("pkc-js:local-community:start:updateCommunityIpnsIfNeeded");
6630
6700
  community._calculateLatestUpdateTrigger();
6631
6701
  if (!community._communityUpdateTrigger) return;
6702
+ community._communityUpdateTrigger = false;
6632
6703
  const cycleStartedAtMs = Date.now();
6633
- const build = await calculateNextCommunityRecord(community, commentUpdateRowsToPublishToIpfs, log);
6634
- await publishCommunityRecordToIpns(community, build, await validateAndSignCommunityRecord(community, build), cycleStartedAtMs);
6704
+ try {
6705
+ const build = await calculateNextCommunityRecord(community, commentUpdateRowsToPublishToIpfs, log);
6706
+ await publishCommunityRecordToIpns(community, build, await validateAndSignCommunityRecord(community, build), cycleStartedAtMs);
6707
+ } catch (e) {
6708
+ community._communityUpdateTrigger = true;
6709
+ throw e;
6710
+ }
6635
6711
  }
6636
6712
  async function syncIpnsWithDb(community) {
6637
6713
  const log = logger_default("pkc-js:local-community:sync");
@@ -6774,19 +6850,19 @@ async function initBeforeStarting(community) {
6774
6850
  if (!community.signer?.address) throw new PKCError("ERR_COMMUNITY_SIGNER_NOT_DEFINED");
6775
6851
  if (!community._challengeAnswerPromises) community._challengeAnswerPromises = new LRUCache({
6776
6852
  max: 1e3,
6777
- ttl: 6e5
6853
+ ttl: community._challengeExchangeTtlMs
6778
6854
  });
6779
6855
  if (!community._challengeAnswerResolveReject) community._challengeAnswerResolveReject = new LRUCache({
6780
6856
  max: 1e3,
6781
- ttl: 6e5
6857
+ ttl: community._challengeExchangeTtlMs
6782
6858
  });
6783
6859
  if (!community._ongoingChallengeExchanges) community._ongoingChallengeExchanges = new LRUCache({
6784
6860
  max: 1e3,
6785
- ttl: 6e5
6861
+ ttl: community._challengeExchangeTtlMs
6786
6862
  });
6787
6863
  if (!community._duplicatePublicationAttempts) community._duplicatePublicationAttempts = new LRUCache({
6788
6864
  max: 1e3,
6789
- ttl: 6e5
6865
+ ttl: community._challengeExchangeTtlMs
6790
6866
  });
6791
6867
  await community._dbHandler.initDbIfNeeded();
6792
6868
  }
@@ -7038,6 +7114,7 @@ async function stop(community) {
7038
7114
  untrackStartedCommunity(community._pkc, community);
7039
7115
  processStartedCommunities.untrack(community);
7040
7116
  community._duplicatePublicationAttempts?.clear();
7117
+ community._inFlightPublicationExchanges.clear();
7041
7118
  await community._dbHandler.rollbackAllTransactions();
7042
7119
  await community._dbHandler.unlockCommunityState();
7043
7120
  await community._updateStartedValue();
@@ -7491,6 +7568,8 @@ var LocalCommunity = class extends RpcLocalCommunity {
7491
7568
  ];
7492
7569
  this._defaultCommunityChallenges = generateDefaultChallenges();
7493
7570
  this._challengeExchangesFromLocalPublishers = {};
7571
+ this._inFlightPublicationExchanges = /* @__PURE__ */ new Map();
7572
+ this._challengeExchangeTtlMs = CHALLENGE_EXCHANGE_TTL_MS;
7494
7573
  this._cidsToUnPin = /* @__PURE__ */ new Set();
7495
7574
  this._mfsPathsToRemove = /* @__PURE__ */ new Set();
7496
7575
  this._communityUpdateTrigger = false;
@@ -1,2 +1,2 @@
1
- import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-CE8orbFt.js";
1
+ import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-BGcQIioy.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 { A as doesDomainAddressHaveCapitalLetter, At as listUpdatingCommunities, B as ipnsNameToIpnsOverPubsubTopic, Br as stringifyPrimitive, Bt as require_sha256, Cn as CommentIpfsSchema, Cr as messages, D as createAbortError, Dr as setErrorMap, Dt as findUpdatingCommunity, Et as findUpdatingComment, Ft as trackUpdatingComment, H as isIpfsCid, Ht as pTimeout, O as deepMergeRuntimeFields, On as CommentUpdateForChallengeVerificationSchema, Ot as listStartedCommunities, R as hideClassPrivateProps, Rr as joinValues, Rt as untrackUpdatingComment, Sr as PKCError, St as waitForUpdateInCommunityInstanceWithErrorAndTimeout, Tt as findStartedCommunity, V as isAbortError, Vt as TimeoutError, W as isIpns, _r as FailedToFetchCommentIpfsFromGatewaysError, _t as shortifyCid, a as ChallengeRequestMessageSchema, ar as t$1, at as rejectWhenCommunityStopsOrAborts, b as areEquivalentCommunityAddresses, bt as throwIfAbortSignalAborted, dt as replaceXWithY, et as isStringDomain, ft as resolveWhenPredicateIsTrue, gr as require_retry, gt as shortifyAddress, it as rejectWhenAbortSignalFires, jn as CommentUpdateSchema, jt as refreshTrackedCommentAliases, kt as listUpdatingComments, lr as r, mt as retryKuboIpfsAdd, nn as CommunityAnchorSchema, or as e, pn as PubsubTopicSchema, r as ChallengeMessageSchema, rr as n$1, s as ChallengeVerificationMessageSchema, sn as CommunityIpfsSchema, sr as e$1, t as ChallengeAnswerMessageSchema, tr as n$2, ut as removeUndefinedValuesRecursively, vt as sleepUntilTimeoutOrAbort, wr as logger_default, xt as timestamp, y as version_default, zr as parsedType } from "./schema-DzFAY-My.js";
3
- import { $ as RepliesPages, $n as RpcUnsubscribeParamSchema, An as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, At as verifyCommentIpfs, B as setNativeFunctions$1, Bn as RpcEditCommunityParamSchema, Cn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Ct as signCommunityEdit, D as createKuboRpcClient, Dn as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, En as parseJsonWithPKCErrorIfFails, Et as verifyChallengeMessage, Fn as RpcCancelExportParamSchema, Ft as verifyCommunityEdit, Gn as RpcFetchCidParamSchema, Gt as getCommunityPublicKeyFromWire, H as CommentClientsManager, Hn as RpcExportCommunityModLogsResultSchema, Ht as buildRuntimeCommunityFields, I as listCommunitiesSync, In as RpcCidParamSchema, It as verifyVote, Jn as RpcPublishChallengeAnswersParamSchema, Kn as RpcFetchCidResultSchema, Kt as normalizeCommunityInputFromCommunity, L as monitorCommunitiesDirectory, Ln as RpcCommentRepliesPageParamSchema, Lt as buildRuntimeAuthor, Mn as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, Mt as verifyCommentPubsubMessage, N as getDefaultDataPath, Nn as RpcAnchorPublishPreparationResultSchema, Nt as verifyCommentUpdate, On as parseRpcCommentEventWithPKCErrorIfItFails, Ot as verifyChallengeVerification, Pn as RpcAuthorNameParamSchema, Q as parseRawPages, Qn as RpcSuccessResultSchema, Qt as getPKCAddressFromPublicKeySync, Rn as RpcCommunityIdentifierParamSchema, Rt as cleanWireAuthor, Sn as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, Tn as parseDecryptedChallengeWithPKCErrorIfItFails, Un as RpcExportCommunityParamSchema, Ut as getCommunityAddressFromRecord, V as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, Vn as RpcExportCommunityModLogsParamSchema, Vt as normalizeCreatePublicationAuthor, Wn as RpcExportCommunityResultSchema, Wt as getCommunityNameFromWire, X as findCommentInPageInstanceRecursively, Xn as RpcResolveAuthorNameResultSchema, Y as extractCommunityRuntimeFieldsFromParsedPages, Yn as RpcPublishedAnchorRecordResultSchema, Yt as getBufferedPKCAddressFromPublicKey, Zn as RpcSubscriptionIdResultSchema, _ as createSigner, _n as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, _t as signComment, an as parseCommentIpfsSchemaWithPKCErrorIfItFails, ar as t$3, at as PublicationClientsManager, bn as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, c as LRUCache, cn as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, cr as t$2, d as KeyvBetterSqlite3, dt as require_lib$1, et as applyNameResolvedCacheToCrosspost, f as decodeRpcChallengeAnswerPubsubMsg, fn as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, ft as cleanUpBeforePublishing, gn as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, h as decodeRpcChallengeVerificationPubsubMsg, hn as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, ht as signChallengeRequest, in as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, it as stripNameResolvedFromCrosspost, jt as verifyCommentModeration, kn as parseRpcCommentUpdateEventWithPKCErrorIfItFails, kt as verifyCommentEdit, l as RemoteCommunity, ln as parseCommunityAddressWithPKCErrorIfItFails, lr as t$5, m as decodeRpcChallengeRequestPubsubMsg, mn as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, mr as require_undici, n as RpcRemoteCommunity, nr as t$4, nt as collectCrosspostAuthorsToResolve, o as pkcJsChallenges, or as n$3, ot as PKCClientsManager, p as decodeRpcChallengePubsubMsg, pr as nativeFunctions$2, pt as signChallengeAnswer, qn as RpcPublishAnchorRecordParamSchema, qt as decode, s as TrackedInstanceRegistry, sn as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, st as InflightFetchManager, t as RpcLocalCommunity, tn as parseCidStringSchemaWithPKCErrorIfItFails, tt as cloneCrosspostForRuntime, ut as PKCTypedEmitter, v as createAnchorIpnsRecord$1, vt as signCommentEdit, wn as parseDecryptedChallengeVerification, wt as signVote, x as encryptEd25519AesGcm, xn as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, y as decryptEd25519AesGcm, yt as signCommentModeration, zn as RpcCommunityPageParamSchema, zt as getAuthorNameFromRuntime } from "./rpc-local-community-CH7vnXLI.js";
4
- import { o as getHeliaDebugContext } from "./util-BiM-_F_H.js";
2
+ import { A as doesDomainAddressHaveCapitalLetter, At as listUpdatingCommunities, B as ipnsNameToIpnsOverPubsubTopic, Br as stringifyPrimitive, Bt as require_sha256, Cn as CommentIpfsSchema, Cr as messages, D as createAbortError, Dr as setErrorMap, Dt as findUpdatingCommunity, Et as findUpdatingComment, Ft as trackUpdatingComment, H as isIpfsCid, Ht as pTimeout, O as deepMergeRuntimeFields, On as CommentUpdateForChallengeVerificationSchema, Ot as listStartedCommunities, R as hideClassPrivateProps, Rr as joinValues, Rt as untrackUpdatingComment, Sr as PKCError, St as waitForUpdateInCommunityInstanceWithErrorAndTimeout, Tt as findStartedCommunity, V as isAbortError, Vt as TimeoutError, W as isIpns, _r as FailedToFetchCommentIpfsFromGatewaysError, _t as shortifyCid, a as ChallengeRequestMessageSchema, ar as t$1, at as rejectWhenCommunityStopsOrAborts, b as areEquivalentCommunityAddresses, bt as throwIfAbortSignalAborted, dt as replaceXWithY, et as isStringDomain, ft as resolveWhenPredicateIsTrue, gr as require_retry, gt as shortifyAddress, it as rejectWhenAbortSignalFires, jn as CommentUpdateSchema, jt as refreshTrackedCommentAliases, kt as listUpdatingComments, lr as r, mt as retryKuboIpfsAdd, nn as CommunityAnchorSchema, or as e, pn as PubsubTopicSchema, r as ChallengeMessageSchema, rr as n$1, s as ChallengeVerificationMessageSchema, sn as CommunityIpfsSchema, sr as e$1, t as ChallengeAnswerMessageSchema, tr as n$2, ut as removeUndefinedValuesRecursively, vt as sleepUntilTimeoutOrAbort, wr as logger_default, xt as timestamp, y as version_default, zr as parsedType } from "./schema-f2Zr1ZxK.js";
3
+ import { $ as RepliesPages, $n as RpcUnsubscribeParamSchema, An as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, At as verifyCommentIpfs, B as setNativeFunctions$1, Bn as RpcEditCommunityParamSchema, Cn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Ct as signCommunityEdit, D as createKuboRpcClient, Dn as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, En as parseJsonWithPKCErrorIfFails, Et as verifyChallengeMessage, Fn as RpcCancelExportParamSchema, Ft as verifyCommunityEdit, Gn as RpcFetchCidParamSchema, Gt as getCommunityPublicKeyFromWire, H as CommentClientsManager, Hn as RpcExportCommunityModLogsResultSchema, Ht as buildRuntimeCommunityFields, I as listCommunitiesSync, In as RpcCidParamSchema, It as verifyVote, Jn as RpcPublishChallengeAnswersParamSchema, Kn as RpcFetchCidResultSchema, Kt as normalizeCommunityInputFromCommunity, L as monitorCommunitiesDirectory, Ln as RpcCommentRepliesPageParamSchema, Lt as buildRuntimeAuthor, Mn as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, Mt as verifyCommentPubsubMessage, N as getDefaultDataPath, Nn as RpcAnchorPublishPreparationResultSchema, Nt as verifyCommentUpdate, On as parseRpcCommentEventWithPKCErrorIfItFails, Ot as verifyChallengeVerification, Pn as RpcAuthorNameParamSchema, Q as parseRawPages, Qn as RpcSuccessResultSchema, Qt as getPKCAddressFromPublicKeySync, Rn as RpcCommunityIdentifierParamSchema, Rt as cleanWireAuthor, Sn as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, Tn as parseDecryptedChallengeWithPKCErrorIfItFails, Un as RpcExportCommunityParamSchema, Ut as getCommunityAddressFromRecord, V as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, Vn as RpcExportCommunityModLogsParamSchema, Vt as normalizeCreatePublicationAuthor, Wn as RpcExportCommunityResultSchema, Wt as getCommunityNameFromWire, X as findCommentInPageInstanceRecursively, Xn as RpcResolveAuthorNameResultSchema, Y as extractCommunityRuntimeFieldsFromParsedPages, Yn as RpcPublishedAnchorRecordResultSchema, Yt as getBufferedPKCAddressFromPublicKey, Zn as RpcSubscriptionIdResultSchema, _ as createSigner, _n as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, _t as signComment, an as parseCommentIpfsSchemaWithPKCErrorIfItFails, ar as t$3, at as PublicationClientsManager, bn as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, c as LRUCache, cn as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, cr as t$2, d as KeyvBetterSqlite3, dt as require_lib$1, et as applyNameResolvedCacheToCrosspost, f as decodeRpcChallengeAnswerPubsubMsg, fn as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, ft as cleanUpBeforePublishing, gn as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, h as decodeRpcChallengeVerificationPubsubMsg, hn as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, ht as signChallengeRequest, in as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, it as stripNameResolvedFromCrosspost, jt as verifyCommentModeration, kn as parseRpcCommentUpdateEventWithPKCErrorIfItFails, kt as verifyCommentEdit, l as RemoteCommunity, ln as parseCommunityAddressWithPKCErrorIfItFails, lr as t$5, m as decodeRpcChallengeRequestPubsubMsg, mn as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, mr as require_undici, n as RpcRemoteCommunity, nr as t$4, nt as collectCrosspostAuthorsToResolve, o as pkcJsChallenges, or as n$3, ot as PKCClientsManager, p as decodeRpcChallengePubsubMsg, pr as nativeFunctions$2, pt as signChallengeAnswer, qn as RpcPublishAnchorRecordParamSchema, qt as decode, s as TrackedInstanceRegistry, sn as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, st as InflightFetchManager, t as RpcLocalCommunity, tn as parseCidStringSchemaWithPKCErrorIfItFails, tt as cloneCrosspostForRuntime, ut as PKCTypedEmitter, v as createAnchorIpnsRecord$1, vt as signCommentEdit, wn as parseDecryptedChallengeVerification, wt as signVote, x as encryptEd25519AesGcm, xn as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, y as decryptEd25519AesGcm, yt as signCommentModeration, zn as RpcCommunityPageParamSchema, zt as getAuthorNameFromRuntime } from "./rpc-local-community-CTyhIJyD.js";
4
+ import { o as getHeliaDebugContext } from "./util-BbXV7Dcu.js";
5
5
  import path from "path";
6
6
  import assert from "assert";
7
7
  import fs from "fs";
@@ -682,6 +682,7 @@ var Publication = class extends import_lib.TypedEmitter {
682
682
  _isAllAttemptsExhausted(maxNumOfChallengeExchanges) {
683
683
  if (Object.keys(this._challengeExchanges).length !== maxNumOfChallengeExchanges) return false;
684
684
  return Object.values(this._challengeExchanges).every((exchange) => {
685
+ if (exchange.challenge || exchange.challengeVerification) return false;
685
686
  if (exchange.challengeRequestPublishError || exchange.challengeAnswerPublishError) return true;
686
687
  return typeof exchange.challengeRequestPublishTimestamp === "number" && exchange.challengeRequestPublishTimestamp + this._setProviderFailureThresholdSeconds <= timestamp();
687
688
  });
@@ -947,8 +948,10 @@ var Publication = class extends import_lib.TypedEmitter {
947
948
  currentPubsubProviderIndex += 1;
948
949
  }
949
950
  const decryptedRequest = this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequest;
950
- this._updatePubsubState("waiting-challenge", providerUrl);
951
- this._updatePublishingStateWithEmission("waiting-challenge");
951
+ if (!this._didWeReceiveChallengeOrChallengeVerification()) {
952
+ this._updatePubsubState("waiting-challenge", providerUrl);
953
+ this._updatePublishingStateWithEmission("waiting-challenge");
954
+ }
952
955
  log(`Published a challenge request of publication`, this.getType(), "with provider", providerUrl);
953
956
  this.emit("challengerequest", decryptedRequest);
954
957
  if (currentPubsubProviderIndex !== providers.length) await sleepUntilTimeoutOrAbort(this._publishToDifferentProviderThresholdSeconds * 1e3, this._pkc._getDestroyAbortSignal());
@@ -957,6 +960,10 @@ var Publication = class extends import_lib.TypedEmitter {
957
960
  await sleepUntilTimeoutOrAbort(this._setProviderFailureThresholdSeconds * 1e3, this._pkc._getDestroyAbortSignal());
958
961
  if (this._pkc.destroyed) return;
959
962
  if (this.state === "stopped") return;
963
+ if (this._didWeReceiveChallengeOrChallengeVerification()) {
964
+ log(`Received a challenge or challenge verification while waiting for retried providers, will keep the exchange alive`);
965
+ return;
966
+ }
960
967
  if (this._isAllAttemptsExhausted(providers.length)) {
961
968
  await this._postSucessOrFailurePublishing();
962
969
  const allAttemptsFailedError = new PKCError("ERR_ALL_PUBSUB_PROVIDERS_THROW_ERRORS", {
@@ -7025,7 +7032,7 @@ var PKC$1 = class extends PKCTypedEmitter {
7025
7032
  this.clients.libp2pJsClients = {};
7026
7033
  if (!this.libp2pJsClientsOptions) return;
7027
7034
  if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
7028
- const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-BvZheFmK.js");
7035
+ const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-DUaUFShG.js");
7029
7036
  for (const clientOptions of this.libp2pJsClientsOptions) {
7030
7037
  const heliaNode = await createLibp2pJsClientOrUseExistingOne({
7031
7038
  ...clientOptions,
@@ -7304,7 +7311,7 @@ var PKC$1 = class extends PKCTypedEmitter {
7304
7311
  const log = logger_default("pkc-js:pkc:createLocalCommunity");
7305
7312
  log.trace("Received community options to create a local community instance:", options);
7306
7313
  if (!this._canCreateNewLocalCommunity()) throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
7307
- const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-bPjJm35w.js");
7314
+ const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-CM2GS9Ya.js");
7308
7315
  const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
7309
7316
  const community = new LocalCommunity(this);
7310
7317
  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 isRequestPubsubPublicationOfReply, $n as CommunityAuthorChallengeReservedFieldNames, $t as CreateCommentModerationOptionsWithRefinementSchema, A as doesDomainAddressHaveCapitalLetter, An as CommentUpdateReservedFields, Ar as boolean, At as listUpdatingCommunities, B as ipnsNameToIpnsOverPubsubTopic, Bt as require_sha256$1, Cn as CommentIpfsSchema, Cr as messages, D as createAbortError, Dn as CommentUpdateChallengeReservedFieldNames, Dt as findUpdatingCommunity, En as CommentSignedPropertyNames, Er as require_ms$1, Et as findUpdatingComment, Fn as CreateCommentOptionsWithRefinementSchema, Fr as record, G as isIpnsPath, Gn as CreateCommentEditOptionsWithRefinementSchema, Gt as CommunityEditPublicationSignedPropertyNames, H as isIpfsCid, Ht as pTimeout, In as GetPageParamSchema, Ir as string, It as trackUpdatingCommunity, Jt as CommentModerationChallengeRequestToEncryptSchema, Kn as AuthorAddressSchema, Kt as CommunityEditPubsubMessagePublicationSchema, L as getPostUpdateTimestampRange, Ln as ModQueuePageIpfsSchema, Lt as untrackStartedCommunity, M as fetchAndValidateIpnsRecordFromGateway, Mn as CommentUpdateSignedPropertyNames, Mr as literal, Mt as refreshTrackedCommunityAliases, Nr as number, O as deepMergeRuntimeFields, Or as _enum, Ot as listStartedCommunities, Pr as object, Pt as trackStartedCommunity, Q as isRequestPubsubPublicationOfPost, Qn as CommunityAddressSchema, Qt as CommentModerationsTableRowSchema, R as hideClassPrivateProps, Rn as PageIpfsSchema, Rt as untrackUpdatingComment, S as calculateIpfsCidV0, Sn as CommentIpfsReservedFields, Sr as PKCError, St as waitForUpdateInCommunityInstanceWithErrorAndTimeout, Tn as CommentPubsubMessageWithFlexibleAuthorRefinementSchema, Tr as require_supports_color, Tt as findStartedCommunity, U as isIpfsPath, Un as CommentEditSignedPropertyNames, Ut as CommunityEditPublicationChallengeRequestToEncryptSchema, V as isAbortError, Vn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, W as isIpns, Xn as CidPathSchema, Yn as ChallengeAnswersSchema, Yt as CommentModerationPubsubMessagePublicationSchema, Zn as CidStringSchema, Zt as CommentModerationSignedPropertyNames, _ as PKCUserOptionBaseSchema, _n as VotePubsubMessagePublicationSchema, _r as FailedToFetchCommentIpfsFromGatewaysError, _t as shortifyCid, an as CommunityExportRecordsSchema, ar as t$13, b as areEquivalentCommunityAddresses, br as FailedToFetchGenericIpfsFromGatewaysError, bt as throwIfAbortSignalAborted, c as ChallengeVerificationMessageSignedPropertyNames, cn as CommunitySignedPropertyNames, cr as t$11, ct as removeNullUndefinedEmptyObjectsValuesRecursively, dn as CreateRpcCommunityFunctionArgumentSchema, dr as n$8, en as ChallengeFileFactorySchema, er as CreateSignerSchema, et as isStringDomain, f as DecryptedChallengeSchema, fn as ExportCommunityModLogsOptionsSchema, fr as r$7, ft as resolveWhenPredicateIsTrue, g as PKCParsedOptionsSchema, gn as VoteChallengeRequestToEncryptSchema, gr as require_retry$1, gt as shortifyAddress, h as NameResolverSerializedSchema, hn as CreateVoteUserOptionsWithRefinementSchema, hr as e$4, i as ChallengeMessageSignedPropertyNames, in as CommunityEditOptionsSchema, j as extractNetworkErrorDetails, jn as CommentUpdateSchema, jr as custom, k as derivePublicationFromChallengeRequest, kn as CommentUpdateForChallengeVerificationSignedPropertyNames, kr as array, l as DecryptedChallengeAnswerSchema, ln as CreateNewLocalCommunityUserOptionsSchema, lr as r$8, m as NameResolveCacheOptionsSchema, mn as RpcRemoteCommunityUpdateEventResultSchema, mr as t$9, n as ChallengeAnswerMessageSignedPropertyNames, o as ChallengeRequestMessageSignedPropertyNames, on as CommunityIpfsReservedFields, or as e$6, p as DecryptedChallengeVerificationSchema, pr as t$10, qn as AuthorCommentIpfsReservedFields, qt as CreateCommunityEditPublicationOptionsWithRefinementSchema, rn as CommunityChallengeSettingSchema, rr as n$9, rt as raceAgainstAbort, sn as CommunityIpfsSchema, sr as e$5, tn as ChallengeFileSchema, tr as n$10, tt as pubsubTopicToDhtKey, un as CreateRemoteCommunityFunctionArgumentSchema, ur as t$12, v as PKCUserOptionsSchema, vr as FailedToFetchCommentUpdateFromGatewaysError, vt as sleepUntilTimeoutOrAbort, wr as logger_default, xn as CommentChallengeRequestToEncryptSchema, xr as FailedToFetchPageIpfsFromGatewaysError, xt as timestamp, yn as VoteSignedPropertyNames, yr as FailedToFetchCommunityFromGatewaysError, z as interruptibleSleep, zn as CommentEditChallengeRequestToEncryptSchema, zt as untrackUpdatingCommunity } from "./schema-DzFAY-My.js";
2
+ import { $ as isRequestPubsubPublicationOfReply, $n as CommunityAuthorChallengeReservedFieldNames, $t as CreateCommentModerationOptionsWithRefinementSchema, A as doesDomainAddressHaveCapitalLetter, An as CommentUpdateReservedFields, Ar as boolean, At as listUpdatingCommunities, B as ipnsNameToIpnsOverPubsubTopic, Bt as require_sha256$1, Cn as CommentIpfsSchema, Cr as messages, D as createAbortError, Dn as CommentUpdateChallengeReservedFieldNames, Dt as findUpdatingCommunity, En as CommentSignedPropertyNames, Er as require_ms$1, Et as findUpdatingComment, Fn as CreateCommentOptionsWithRefinementSchema, Fr as record, G as isIpnsPath, Gn as CreateCommentEditOptionsWithRefinementSchema, Gt as CommunityEditPublicationSignedPropertyNames, H as isIpfsCid, Ht as pTimeout, In as GetPageParamSchema, Ir as string, It as trackUpdatingCommunity, Jt as CommentModerationChallengeRequestToEncryptSchema, Kn as AuthorAddressSchema, Kt as CommunityEditPubsubMessagePublicationSchema, L as getPostUpdateTimestampRange, Ln as ModQueuePageIpfsSchema, Lt as untrackStartedCommunity, M as fetchAndValidateIpnsRecordFromGateway, Mn as CommentUpdateSignedPropertyNames, Mr as literal, Mt as refreshTrackedCommunityAliases, Nr as number, O as deepMergeRuntimeFields, Or as _enum, Ot as listStartedCommunities, Pr as object, Pt as trackStartedCommunity, Q as isRequestPubsubPublicationOfPost, Qn as CommunityAddressSchema, Qt as CommentModerationsTableRowSchema, R as hideClassPrivateProps, Rn as PageIpfsSchema, Rt as untrackUpdatingComment, S as calculateIpfsCidV0, Sn as CommentIpfsReservedFields, Sr as PKCError, St as waitForUpdateInCommunityInstanceWithErrorAndTimeout, Tn as CommentPubsubMessageWithFlexibleAuthorRefinementSchema, Tr as require_supports_color, Tt as findStartedCommunity, U as isIpfsPath, Un as CommentEditSignedPropertyNames, Ut as CommunityEditPublicationChallengeRequestToEncryptSchema, V as isAbortError, Vn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, W as isIpns, Xn as CidPathSchema, Yn as ChallengeAnswersSchema, Yt as CommentModerationPubsubMessagePublicationSchema, Zn as CidStringSchema, Zt as CommentModerationSignedPropertyNames, _ as PKCUserOptionBaseSchema, _n as VotePubsubMessagePublicationSchema, _r as FailedToFetchCommentIpfsFromGatewaysError, _t as shortifyCid, an as CommunityExportRecordsSchema, ar as t$13, b as areEquivalentCommunityAddresses, br as FailedToFetchGenericIpfsFromGatewaysError, bt as throwIfAbortSignalAborted, c as ChallengeVerificationMessageSignedPropertyNames, cn as CommunitySignedPropertyNames, cr as t$11, ct as removeNullUndefinedEmptyObjectsValuesRecursively, dn as CreateRpcCommunityFunctionArgumentSchema, dr as n$8, en as ChallengeFileFactorySchema, er as CreateSignerSchema, et as isStringDomain, f as DecryptedChallengeSchema, fn as ExportCommunityModLogsOptionsSchema, fr as r$7, ft as resolveWhenPredicateIsTrue, g as PKCParsedOptionsSchema, gn as VoteChallengeRequestToEncryptSchema, gr as require_retry$1, gt as shortifyAddress, h as NameResolverSerializedSchema, hn as CreateVoteUserOptionsWithRefinementSchema, hr as e$4, i as ChallengeMessageSignedPropertyNames, in as CommunityEditOptionsSchema, j as extractNetworkErrorDetails, jn as CommentUpdateSchema, jr as custom, k as derivePublicationFromChallengeRequest, kn as CommentUpdateForChallengeVerificationSignedPropertyNames, kr as array, l as DecryptedChallengeAnswerSchema, ln as CreateNewLocalCommunityUserOptionsSchema, lr as r$8, m as NameResolveCacheOptionsSchema, mn as RpcRemoteCommunityUpdateEventResultSchema, mr as t$9, n as ChallengeAnswerMessageSignedPropertyNames, o as ChallengeRequestMessageSignedPropertyNames, on as CommunityIpfsReservedFields, or as e$6, p as DecryptedChallengeVerificationSchema, pr as t$10, qn as AuthorCommentIpfsReservedFields, qt as CreateCommunityEditPublicationOptionsWithRefinementSchema, rn as CommunityChallengeSettingSchema, rr as n$9, rt as raceAgainstAbort, sn as CommunityIpfsSchema, sr as e$5, tn as ChallengeFileSchema, tr as n$10, tt as pubsubTopicToDhtKey, un as CreateRemoteCommunityFunctionArgumentSchema, ur as t$12, v as PKCUserOptionsSchema, vr as FailedToFetchCommentUpdateFromGatewaysError, vt as sleepUntilTimeoutOrAbort, wr as logger_default, xn as CommentChallengeRequestToEncryptSchema, xr as FailedToFetchPageIpfsFromGatewaysError, xt as timestamp, yn as VoteSignedPropertyNames, yr as FailedToFetchCommunityFromGatewaysError, z as interruptibleSleep, zn as CommentEditChallengeRequestToEncryptSchema, zt as untrackUpdatingCommunity } from "./schema-f2Zr1ZxK.js";
3
3
  import { t as all } from "./src-CYIMjhjK.js";
4
4
  import { createHash } from "node:crypto";
5
5
  import { pathToFileURL } from "node:url";
@@ -99650,6 +99650,7 @@ var BaseClientsManager = class BaseClientsManager {
99650
99650
  const data = concat(await all(ipfsClient.cat(cidV0, {
99651
99651
  length: loadOpts.maxFileSizeBytes,
99652
99652
  timeout: `${loadOpts.timeoutMs}ms`,
99653
+ signal: loadOpts.abortSignal,
99653
99654
  ...seedScopeOptions
99654
99655
  })));
99655
99656
  const fileContent = toString(data);
@@ -5404,6 +5404,7 @@ var messages;
5404
5404
  messages["ERR_PAGE_SIGNATURE_IS_INVALID"] = "The signature of one of the comment in the page is invalid";
5405
5405
  messages["ERR_MOD_QUEUE_PAGE_IS_INVALID"] = "The signature of mod queue page is invalid";
5406
5406
  messages["ERR_CHALLENGE_ANSWER_WITH_NO_CHALLENGE_REQUEST"] = "Received a challenge answer without a prior challenge request";
5407
+ messages["ERR_COMMUNITY_TIMED_OUT_WAITING_FOR_CHALLENGE_ANSWER"] = "The community did not receive a challenge answer within the challenge exchange ttl";
5407
5408
  messages["ERR_REUSED_PUBSUB_MSG_SIGNER"] = "Reusing a pubsub message signer is forbidden";
5408
5409
  messages["ERR_PUBSUB_MSG_TIMESTAMP_IS_OUTDATED"] = "The timestamp of the pubsub message is outdated";
5409
5410
  messages["ERR_UNAUTHORIZED_COMMENT_EDIT"] = "The author of this edit is not a mod/admin/owner or an author of the original comment. Can't edit";
@@ -16223,7 +16224,7 @@ function extractNetworkErrorDetails(err, depth = 0) {
16223
16224
  }
16224
16225
  //#endregion
16225
16226
  //#region dist/node/generated-version.js
16226
- const version = "0.0.97";
16227
+ const version = "0.0.99";
16227
16228
  //#endregion
16228
16229
  //#region dist/node/version.js
16229
16230
  const protocolVersion = ProtocolVersionSchema.parse("1.0.0");
@@ -1,4 +1,4 @@
1
- import { Sr as PKCError, nt as pubsubTopicToDhtKeyCid } from "./schema-DzFAY-My.js";
1
+ import { Sr as PKCError, nt as pubsubTopicToDhtKeyCid } from "./schema-f2Zr1ZxK.js";
2
2
  import { ipnsSelector } from "ipns/selector";
3
3
  import { ipnsValidator } from "ipns/validator";
4
4
  import { unmarshalIPNSRecord } from "ipns";
@@ -1,2 +1,2 @@
1
- import { a as getShortCid, i as getShortAddress, n as challenges, o as nativeFunctions, r as createAnchorIpnsRecord, s as setNativeFunctions, t as PKC } from "./chunks/node-DmZww4LL.js";
1
+ import { a as getShortCid, i as getShortAddress, n as challenges, o as nativeFunctions, r as createAnchorIpnsRecord, s as setNativeFunctions, t as PKC } from "./chunks/node-CF18iVMW.js";
2
2
  export { challenges, createAnchorIpnsRecord, PKC as default, getShortAddress, getShortCid, nativeFunctions, setNativeFunctions };
@@ -1,7 +1,7 @@
1
- import { Ht as pTimeout, R as hideClassPrivateProps, Sr as PKCError, Tt as findStartedCommunity, ar as t, dt as replaceXWithY, rr as n, wr as logger_default } from "../../chunks/schema-DzFAY-My.js";
2
- import { _ as parseRpcPublishAnchorRecordParam, c as parseRpcAuthorNameParam, d as parseRpcCommentRepliesPageParam, f as parseRpcCommunityIdentifierParam, g as parseRpcExportCommunityParam, h as parseRpcExportCommunityModLogsParam, l as parseRpcCancelExportParam, m as parseRpcEditCommunityParam, p as parseRpcCommunityPageParam, t as PKC, u as parseRpcCidParam, v as parseRpcPublishChallengeAnswersParam, y as parseRpcUnsubscribeParam } from "../../chunks/node-DmZww4LL.js";
3
- import { An as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, Cn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, J as buildPagesRuntimeFields, ct as pRetry, dn as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, dt as require_lib, jn as parseVoteChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, lt as pLimit, nn as parseCommentChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, on as parseCommentModerationChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, q as buildPageRuntimeFields, rn as parseCommentEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, rr as t$1, rt as extractCrosspostRuntimeFields, un as parseCommunityEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, ur as stringify, vn as parseCreateNewLocalCommunityUserOptionsSchemaWithPKCErrorIfItFails, yn as parseCreatePKCWsServerOptionsSchemaWithPKCErrorIfItFails } from "../../chunks/rpc-local-community-CH7vnXLI.js";
4
- import { t as LocalCommunity } from "../../chunks/local-community-CE8orbFt.js";
1
+ import { Ht as pTimeout, R as hideClassPrivateProps, Sr as PKCError, Tt as findStartedCommunity, ar as t, dt as replaceXWithY, rr as n, wr as logger_default } from "../../chunks/schema-f2Zr1ZxK.js";
2
+ import { _ as parseRpcPublishAnchorRecordParam, c as parseRpcAuthorNameParam, d as parseRpcCommentRepliesPageParam, f as parseRpcCommunityIdentifierParam, g as parseRpcExportCommunityParam, h as parseRpcExportCommunityModLogsParam, l as parseRpcCancelExportParam, m as parseRpcEditCommunityParam, p as parseRpcCommunityPageParam, t as PKC, u as parseRpcCidParam, v as parseRpcPublishChallengeAnswersParam, y as parseRpcUnsubscribeParam } from "../../chunks/node-CF18iVMW.js";
3
+ import { An as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, Cn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, J as buildPagesRuntimeFields, ct as pRetry, dn as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, dt as require_lib, jn as parseVoteChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, lt as pLimit, nn as parseCommentChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, on as parseCommentModerationChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, q as buildPageRuntimeFields, rn as parseCommentEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, rr as t$1, rt as extractCrosspostRuntimeFields, un as parseCommunityEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, ur as stringify, vn as parseCreateNewLocalCommunityUserOptionsSchemaWithPKCErrorIfItFails, yn as parseCreatePKCWsServerOptionsSchemaWithPKCErrorIfItFails } from "../../chunks/rpc-local-community-CTyhIJyD.js";
4
+ import { t as LocalCommunity } from "../../chunks/local-community-BGcQIioy.js";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import path from "path";
7
7
  import assert from "assert";
@@ -605,7 +605,16 @@ export class BaseClientsManager {
605
605
  const seedScopeOptions = "_helia" in kuboRpcOrHelia && loadOpts.bitswapSessionSeedScopeIpnsPubsubTopic
606
606
  ? { bitswapSessionSeedScopeIpnsPubsubTopic: loadOpts.bitswapSessionSeedScopeIpnsPubsubTopic }
607
607
  : undefined;
608
- const rawData = await all(ipfsClient.cat(cidV0, { length: loadOpts.maxFileSizeBytes, timeout: `${loadOpts.timeoutMs}ms`, ...seedScopeOptions }));
608
+ // The caller's signal goes to cat() as well as to the pTimeout below: pTimeout only
609
+ // abandons the promise on abort, and a helia cat left running would keep opening bitswap
610
+ // sessions and retrying "no providers" until its own timeout fired, long after the
611
+ // comment/community/pkc that asked for it was stopped (issue #345).
612
+ const rawData = await all(ipfsClient.cat(cidV0, {
613
+ length: loadOpts.maxFileSizeBytes,
614
+ timeout: `${loadOpts.timeoutMs}ms`,
615
+ signal: loadOpts.abortSignal,
616
+ ...seedScopeOptions
617
+ }));
609
618
  const data = uint8ArrayConcat(rawData);
610
619
  const fileContent = uint8ArrayToString(data);
611
620
  if (typeof fileContent !== "string") {