@pkcprotocol/pkc-js 0.0.73 → 0.0.75
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.
- package/README.md +25 -1
- package/dist/browser/clients/base-client-manager.d.ts +1 -0
- package/dist/browser/clients/base-client-manager.js +9 -2
- package/dist/browser/clients/base-client-manager.js.map +1 -1
- package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +1 -0
- package/dist/browser/clients/rpc-client/schema.d.ts +1 -0
- package/dist/browser/community/community-client-manager.d.ts +1 -0
- package/dist/browser/community/community-client-manager.js +7 -0
- package/dist/browser/community/community-client-manager.js.map +1 -1
- package/dist/browser/community/remote-community.js +18 -9
- package/dist/browser/community/remote-community.js.map +1 -1
- package/dist/browser/community/schema.d.ts +6 -0
- package/dist/browser/community/schema.js +4 -1
- package/dist/browser/community/schema.js.map +1 -1
- package/dist/browser/community/types.d.ts +1 -0
- package/dist/browser/errors.d.ts +2 -0
- package/dist/browser/errors.js +2 -0
- package/dist/browser/errors.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/helia/helia-for-pkc.d.ts +1 -1
- package/dist/browser/helia/helia-for-pkc.js +41 -5
- package/dist/browser/helia/helia-for-pkc.js.map +1 -1
- package/dist/browser/helia/lru-blockstore.d.ts +92 -0
- package/dist/browser/helia/lru-blockstore.js +224 -0
- package/dist/browser/helia/lru-blockstore.js.map +1 -0
- package/dist/browser/pkc/pkc.js +4 -1
- package/dist/browser/pkc/pkc.js.map +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/community-edit/schema.d.ts +4 -0
- package/dist/browser/publications/publication.d.ts +2 -1
- package/dist/browser/publications/publication.js +63 -24
- package/dist/browser/publications/publication.js.map +1 -1
- package/dist/browser/pubsub-messages/schema.d.ts +2 -0
- package/dist/browser/rpc/src/schema.d.ts +16 -0
- package/dist/browser/runtime/browser/blockstore.d.ts +25 -0
- package/dist/browser/runtime/browser/blockstore.js +40 -0
- package/dist/browser/runtime/browser/blockstore.js.map +1 -0
- package/dist/browser/runtime/node/blockstore.d.ts +32 -0
- package/dist/browser/runtime/node/blockstore.js +42 -0
- package/dist/browser/runtime/node/blockstore.js.map +1 -0
- package/dist/browser/runtime/node/community/db-handler.d.ts +1 -0
- package/dist/browser/runtime/node/community/local-community/challenges.js +26 -25
- package/dist/browser/runtime/node/community/local-community/challenges.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/comment-updates.d.ts +2 -1
- package/dist/browser/runtime/node/community/local-community/comment-updates.js +14 -2
- package/dist/browser/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/db-state.js +12 -1
- package/dist/browser/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +22 -1
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +17 -5
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/pubsub.js +42 -4
- package/dist/browser/runtime/node/community/local-community/pubsub.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community.d.ts +1 -0
- package/dist/browser/runtime/node/community/local-community.js +10 -1
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/schema/schema-util.d.ts +4 -0
- package/dist/browser/schema.d.ts +20 -0
- package/dist/browser/schema.js +11 -1
- package/dist/browser/schema.js.map +1 -1
- package/dist/browser/signer/signatures.d.ts +4 -4
- package/dist/browser/signer/signatures.js +23 -4
- package/dist/browser/signer/signatures.js.map +1 -1
- package/dist/browser/test/test-util.d.ts +3 -0
- package/dist/browser/test/test-util.js +15 -1
- package/dist/browser/test/test-util.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +201 -94
- package/dist/bundled/chunks/helia-for-pkc-BPj1zAUb.js +6915 -0
- package/dist/bundled/chunks/{local-community-EFv2VpQI.js → local-community-ChTkd8lH.js} +1 -1
- package/dist/bundled/chunks/{local-community-DLVCXKMM.js → local-community-D4efR9XJ.js} +92 -55
- package/dist/bundled/chunks/{node-Dpuw7iSW.js → node-BK6GBM0d.js} +55 -28
- package/dist/bundled/chunks/{rpc-local-community-8CqOzaX3.js → rpc-local-community-O94vseOA.js} +45 -34
- package/dist/bundled/chunks/{schema-DMHTAMSM.js → schema-wNdSno5O.js} +11 -4
- package/dist/bundled/chunks/{src-o_MYSn-E.js → src-B2CwDTfy.js} +2 -142
- package/dist/bundled/chunks/{src-4u0f92eE.js → src-BKg5Lhod.js} +2 -127
- package/dist/bundled/chunks/src-Cpx2Sts8.js +127 -0
- package/dist/bundled/chunks/src-DKntVmyX.js +142 -0
- package/dist/bundled/chunks/{util-hdyyy-HI.js → util-iNnH2bP5.js} +1 -1
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/rpc/src/index.js +4 -4
- package/dist/node/clients/base-client-manager.d.ts +1 -0
- package/dist/node/clients/base-client-manager.js +9 -2
- package/dist/node/clients/base-client-manager.js.map +1 -1
- package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +1 -0
- package/dist/node/clients/rpc-client/schema.d.ts +1 -0
- package/dist/node/community/community-client-manager.d.ts +1 -0
- package/dist/node/community/community-client-manager.js +7 -0
- package/dist/node/community/community-client-manager.js.map +1 -1
- package/dist/node/community/remote-community.js +18 -9
- package/dist/node/community/remote-community.js.map +1 -1
- package/dist/node/community/schema.d.ts +6 -0
- package/dist/node/community/schema.js +4 -1
- package/dist/node/community/schema.js.map +1 -1
- package/dist/node/community/types.d.ts +1 -0
- package/dist/node/errors.d.ts +2 -0
- package/dist/node/errors.js +2 -0
- package/dist/node/errors.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/helia/helia-for-pkc.d.ts +1 -1
- package/dist/node/helia/helia-for-pkc.js +41 -5
- package/dist/node/helia/helia-for-pkc.js.map +1 -1
- package/dist/node/helia/lru-blockstore.d.ts +92 -0
- package/dist/node/helia/lru-blockstore.js +224 -0
- package/dist/node/helia/lru-blockstore.js.map +1 -0
- package/dist/node/pkc/pkc.js +4 -1
- package/dist/node/pkc/pkc.js.map +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/community-edit/schema.d.ts +4 -0
- package/dist/node/publications/publication.d.ts +2 -1
- package/dist/node/publications/publication.js +63 -24
- package/dist/node/publications/publication.js.map +1 -1
- package/dist/node/pubsub-messages/schema.d.ts +2 -0
- package/dist/node/rpc/src/schema.d.ts +16 -0
- package/dist/node/runtime/browser/blockstore.d.ts +25 -0
- package/dist/node/runtime/browser/blockstore.js +40 -0
- package/dist/node/runtime/browser/blockstore.js.map +1 -0
- package/dist/node/runtime/node/blockstore.d.ts +32 -0
- package/dist/node/runtime/node/blockstore.js +42 -0
- package/dist/node/runtime/node/blockstore.js.map +1 -0
- package/dist/node/runtime/node/community/db-handler.d.ts +1 -0
- package/dist/node/runtime/node/community/local-community/challenges.js +26 -25
- package/dist/node/runtime/node/community/local-community/challenges.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/comment-updates.d.ts +2 -1
- package/dist/node/runtime/node/community/local-community/comment-updates.js +14 -2
- package/dist/node/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/db-state.js +12 -1
- package/dist/node/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js +22 -1
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.js +17 -5
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/pubsub.js +42 -4
- package/dist/node/runtime/node/community/local-community/pubsub.js.map +1 -1
- package/dist/node/runtime/node/community/local-community.d.ts +1 -0
- package/dist/node/runtime/node/community/local-community.js +10 -1
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/schema/schema-util.d.ts +4 -0
- package/dist/node/schema.d.ts +20 -0
- package/dist/node/schema.js +11 -1
- package/dist/node/schema.js.map +1 -1
- package/dist/node/signer/signatures.d.ts +4 -4
- package/dist/node/signer/signatures.js +23 -4
- package/dist/node/signer/signatures.js.map +1 -1
- package/dist/node/test/test-util.d.ts +3 -0
- package/dist/node/test/test-util.js +15 -1
- package/dist/node/test/test-util.js.map +1 -1
- package/package.json +8 -5
- package/dist/bundled/chunks/helia-for-pkc-DooZDxJi.js +0 -495
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-
|
|
1
|
+
import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-D4efR9XJ.js";
|
|
2
2
|
export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };
|
|
@@ -1,12 +1,12 @@
|
|
|
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-
|
|
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-
|
|
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-wNdSno5O.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-O94vseOA.js";
|
|
4
4
|
import { randomFillSync, randomUUID } from "node:crypto";
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
-
import
|
|
6
|
+
import path from "node:path";
|
|
7
7
|
import os from "os";
|
|
8
8
|
import { existsSync, promises } from "node:fs";
|
|
9
|
-
import path from "path";
|
|
9
|
+
import path$1 from "path";
|
|
10
10
|
import assert from "assert";
|
|
11
11
|
import fs from "fs";
|
|
12
12
|
import Database from "better-sqlite3";
|
|
@@ -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
|
|
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
|
-
|
|
484
|
-
community
|
|
485
|
-
if (!community._challengeExchangesFromLocalPublishers[request.challengeRequestId.toString()]) await community._clientsManager.pubsubPublish(
|
|
486
|
-
log(`Community ${community.address} with pubsub topic ${
|
|
487
|
-
community._clientsManager.
|
|
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
|
-
|
|
513
|
-
community
|
|
514
|
-
log(`Will publish ${challengeVerification.type} over pubsub topic ${
|
|
515
|
-
if (!community._challengeExchangesFromLocalPublishers[challengeRequestId.toString()]) await community._clientsManager.pubsubPublish(
|
|
516
|
-
community._clientsManager.
|
|
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
|
-
|
|
572
|
-
community
|
|
573
|
-
if (!community._challengeExchangesFromLocalPublishers[challengeRequestId.toString()]) await community._clientsManager.pubsubPublish(
|
|
574
|
-
community._clientsManager.
|
|
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
|
-
|
|
653
|
-
community
|
|
654
|
-
if (!community._challengeExchangesFromLocalPublishers[request.challengeRequestId.toString()]) await community._clientsManager.pubsubPublish(
|
|
655
|
-
community._clientsManager.
|
|
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 ${
|
|
668
|
+
log.trace(`Published ${challengeVerification.type} over pubsub topic ${challengeTopic}:`, n$3(objectToEmit, [
|
|
665
669
|
"signature",
|
|
666
670
|
"encrypted",
|
|
667
671
|
"challengeRequestId"
|
|
@@ -3279,9 +3283,9 @@ var DbHandler = class {
|
|
|
3279
3283
|
if (needToMigrate) {
|
|
3280
3284
|
if (dbExistsAlready && currentDbVersion > 0) {
|
|
3281
3285
|
this.destoryConnection();
|
|
3282
|
-
backupDbPath = path.join(path.dirname(dbPath), ".backup_before_migration", `${path.basename(dbPath)}.${currentDbVersion}.${timestamp()}`);
|
|
3283
|
-
log(`Copying db ${path.basename(dbPath)} to ${backupDbPath} before migration`);
|
|
3284
|
-
if (!fs.existsSync(path.dirname(backupDbPath))) await fs.promises.mkdir(path.dirname(backupDbPath), { recursive: true });
|
|
3286
|
+
backupDbPath = path$1.join(path$1.dirname(dbPath), ".backup_before_migration", `${path$1.basename(dbPath)}.${currentDbVersion}.${timestamp()}`);
|
|
3287
|
+
log(`Copying db ${path$1.basename(dbPath)} to ${backupDbPath} before migration`);
|
|
3288
|
+
if (!fs.existsSync(path$1.dirname(backupDbPath))) await fs.promises.mkdir(path$1.dirname(backupDbPath), { recursive: true });
|
|
3285
3289
|
const sourceDb = new Database(dbPath, { fileMustExist: true });
|
|
3286
3290
|
await sourceDb.backup(backupDbPath);
|
|
3287
3291
|
sourceDb.close();
|
|
@@ -5092,10 +5096,10 @@ var DbHandler = class {
|
|
|
5092
5096
|
if (this._db || this._keyv) await this.destoryConnection();
|
|
5093
5097
|
this._transactionDepth = 0;
|
|
5094
5098
|
const dataPath = this._community._pkc.dataPath;
|
|
5095
|
-
const oldPathString = path.join(dataPath, "communities", oldDbName);
|
|
5096
|
-
const newPathString = path.join(dataPath, "communities", newDbName);
|
|
5097
|
-
await fs.promises.mkdir(path.dirname(oldPathString), { recursive: true });
|
|
5098
|
-
await fs.promises.mkdir(path.dirname(newPathString), { recursive: true });
|
|
5099
|
+
const oldPathString = path$1.join(dataPath, "communities", oldDbName);
|
|
5100
|
+
const newPathString = path$1.join(dataPath, "communities", newDbName);
|
|
5101
|
+
await fs.promises.mkdir(path$1.dirname(oldPathString), { recursive: true });
|
|
5102
|
+
await fs.promises.mkdir(path$1.dirname(newPathString), { recursive: true });
|
|
5099
5103
|
try {
|
|
5100
5104
|
if (!fs.existsSync(oldPathString)) log(`Old DB file ${oldPathString} does not exist. Cannot backup/rename.`);
|
|
5101
5105
|
else {
|
|
@@ -5117,8 +5121,8 @@ var DbHandler = class {
|
|
|
5117
5121
|
}
|
|
5118
5122
|
async lockCommunityStart(communityAddress = this._community.address) {
|
|
5119
5123
|
const log = logger_default("pkc-js:local-community:db-handler:lock:start");
|
|
5120
|
-
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
5121
|
-
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
5124
|
+
const lockfilePath = path$1.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
5125
|
+
const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
5122
5126
|
try {
|
|
5123
5127
|
await import_src.default.lock(communityDbPath, {
|
|
5124
5128
|
lockfilePath,
|
|
@@ -5139,8 +5143,8 @@ var DbHandler = class {
|
|
|
5139
5143
|
async unlockCommunityStart(communityAddress = this._community.address) {
|
|
5140
5144
|
const log = logger_default("pkc-js:local-community:db-handler:unlock:start");
|
|
5141
5145
|
log.trace(`Attempting to unlock the start of community (${communityAddress})`);
|
|
5142
|
-
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
5143
|
-
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
5146
|
+
const lockfilePath = path$1.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
5147
|
+
const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
5144
5148
|
if (!fs.existsSync(lockfilePath) || !fs.existsSync(communityDbPath)) return;
|
|
5145
5149
|
try {
|
|
5146
5150
|
await import_src.default.unlock(communityDbPath, { lockfilePath });
|
|
@@ -5151,8 +5155,8 @@ var DbHandler = class {
|
|
|
5151
5155
|
}
|
|
5152
5156
|
}
|
|
5153
5157
|
async isCommunityStartLocked(communityAddress = this._community.address) {
|
|
5154
|
-
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
5155
|
-
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
5158
|
+
const lockfilePath = path$1.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
5159
|
+
const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
5156
5160
|
return await import_src.default.check(communityDbPath, {
|
|
5157
5161
|
lockfilePath,
|
|
5158
5162
|
realpath: false,
|
|
@@ -5161,8 +5165,8 @@ var DbHandler = class {
|
|
|
5161
5165
|
}
|
|
5162
5166
|
async lockCommunityState() {
|
|
5163
5167
|
const log = logger_default("pkc-js:local-community:db-handler:lock:lockCommunityState");
|
|
5164
|
-
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
|
|
5165
|
-
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
5168
|
+
const lockfilePath = path$1.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
|
|
5169
|
+
const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
5166
5170
|
try {
|
|
5167
5171
|
await import_src.default.lock(communityDbPath, {
|
|
5168
5172
|
lockfilePath,
|
|
@@ -5179,8 +5183,8 @@ var DbHandler = class {
|
|
|
5179
5183
|
}
|
|
5180
5184
|
async unlockCommunityState() {
|
|
5181
5185
|
const log = logger_default("pkc-js:local-community:db-handler:lock:unlockCommunityState");
|
|
5182
|
-
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
|
|
5183
|
-
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
5186
|
+
const lockfilePath = path$1.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
|
|
5187
|
+
const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
5184
5188
|
if (!fs.existsSync(lockfilePath)) return;
|
|
5185
5189
|
try {
|
|
5186
5190
|
await import_src.default.unlock(communityDbPath, { lockfilePath });
|
|
@@ -5190,7 +5194,7 @@ var DbHandler = class {
|
|
|
5190
5194
|
}
|
|
5191
5195
|
}
|
|
5192
5196
|
communityDbExists() {
|
|
5193
|
-
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
5197
|
+
const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
5194
5198
|
return fs.existsSync(communityDbPath);
|
|
5195
5199
|
}
|
|
5196
5200
|
markCommentsAsPublishedToPostUpdates(commentCids) {
|
|
@@ -5861,7 +5865,7 @@ async function createNewLocalCommunityDb(community) {
|
|
|
5861
5865
|
await community._dbHandler.initDbIfNeeded({ fileMustExist: false });
|
|
5862
5866
|
await community._dbHandler.createOrMigrateTablesIfNeeded();
|
|
5863
5867
|
await initSignerProps(community, community.signer);
|
|
5864
|
-
if (!community.pubsubTopic) community.pubsubTopic = t$10(community.signer.address);
|
|
5868
|
+
if (!community.pubsubTopic && !community.settings?.disablePubsubChallengeExchange) community.pubsubTopic = t$10(community.signer.address);
|
|
5865
5869
|
if (typeof community.createdAt !== "number") community.createdAt = timestamp();
|
|
5866
5870
|
if (!community.protocolVersion) community.protocolVersion = version_default.PROTOCOL_VERSION;
|
|
5867
5871
|
if (!community.settings?.maxPendingApprovalCount) community.settings = {
|
|
@@ -5940,6 +5944,7 @@ async function initInternalCommunityAfterFirstUpdateNoMerge(community, newProps)
|
|
|
5940
5944
|
},
|
|
5941
5945
|
runtimeFields: { updateCid: newProps.updateCid }
|
|
5942
5946
|
});
|
|
5947
|
+
if (!newProps.pubsubTopic && newProps._configuredPubsubTopic) community.pubsubTopic = newProps._configuredPubsubTopic;
|
|
5943
5948
|
await initSignerProps(community, newProps.signer);
|
|
5944
5949
|
community._internalStateUpdateId = newProps._internalStateUpdateId;
|
|
5945
5950
|
if (Array.isArray(newProps._cidsToUnPin)) newProps._cidsToUnPin.forEach((cid) => community._cidsToUnPin.add(cid));
|
|
@@ -5984,22 +5989,42 @@ async function initDbHandlerIfNeeded(community) {
|
|
|
5984
5989
|
//#region dist/node/runtime/node/community/local-community/pubsub.js
|
|
5985
5990
|
async function listenToIncomingRequests(community) {
|
|
5986
5991
|
const log = logger_default("pkc-js:local-community:sync:_listenToIncomingRequests");
|
|
5987
|
-
const
|
|
5992
|
+
const topic = challengeExchangePubsubTopic(community);
|
|
5993
|
+
const pubsubClient = topic ? community._clientsManager.getDefaultKuboPubsubClient() : community._clientsManager.getDefaultKuboPubsubClientIfAny();
|
|
5994
|
+
if (!pubsubClient) return;
|
|
5988
5995
|
const subscribedTopics = await pubsubClient._client.pubsub.ls();
|
|
5989
|
-
const
|
|
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);
|
|
5990
6014
|
if (!subscribedTopics.includes(topic)) {
|
|
5991
6015
|
await community._clientsManager.pubsubUnsubscribe(topic, community.handleChallengeExchange);
|
|
5992
6016
|
await community._clientsManager.pubsubSubscribe(topic, community.handleChallengeExchange);
|
|
5993
6017
|
community._clientsManager.updateKuboRpcPubsubState("waiting-challenge-requests", pubsubClient.url);
|
|
5994
6018
|
log(`Waiting for publications on pubsub topic (${topic})`);
|
|
5995
6019
|
}
|
|
6020
|
+
community._subscribedChallengePubsubTopic = topic;
|
|
5996
6021
|
}
|
|
5997
6022
|
async function providePubsubTopicRoutingCidsIfNeeded(community, force = false) {
|
|
5998
6023
|
const log = logger_default("pkc-js:local-community:_providePubsubTopicRoutingCidsIfNeeded");
|
|
5999
6024
|
const reprovideIntervalMs = 3600 * 1e3;
|
|
6000
6025
|
const now = Date.now();
|
|
6001
6026
|
if (!force && community._lastPubsubTopicRoutingProvideAt && now - community._lastPubsubTopicRoutingProvideAt < reprovideIntervalMs) return;
|
|
6002
|
-
const topics = [
|
|
6027
|
+
const topics = [challengeExchangePubsubTopic(community), community.ipnsPubsubTopic].filter((topic) => typeof topic === "string");
|
|
6003
6028
|
if (topics.length === 0) return;
|
|
6004
6029
|
community._lastPubsubTopicRoutingProvideAt = now;
|
|
6005
6030
|
const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient()._client;
|
|
@@ -6124,6 +6149,7 @@ async function calculateNextCommunityRecord(community, commentUpdateRowsToPublis
|
|
|
6124
6149
|
const newIpns = { ...cleanUpBeforePublishing({
|
|
6125
6150
|
...n$3(community._toJSONIpfsBaseNoPosts(), ["signature"]),
|
|
6126
6151
|
...pendingCommunityIpfsEditProps,
|
|
6152
|
+
pubsubTopic: challengeExchangePubsubTopic(community),
|
|
6127
6153
|
lastPostCid: latestPost?.cid,
|
|
6128
6154
|
lastCommentCid: latestComment?.cid,
|
|
6129
6155
|
statsCid,
|
|
@@ -6222,7 +6248,13 @@ async function publishCommunityRecordToIpns(community, build, newCommunityRecord
|
|
|
6222
6248
|
community._blocksToRm = community._blocksToRm.filter((blockCid) => !removedBlocks.includes(blockCid));
|
|
6223
6249
|
}
|
|
6224
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();
|
|
6225
6253
|
community.initCommunityIpfsPropsNoMerge(newCommunityRecord);
|
|
6254
|
+
if (!newCommunityRecord.pubsubTopic) {
|
|
6255
|
+
const topicToKeep = editedPubsubTopic ?? configuredPubsubTopic;
|
|
6256
|
+
if (topicToKeep) community.pubsubTopic = topicToKeep;
|
|
6257
|
+
}
|
|
6226
6258
|
community.updateCid = file.path;
|
|
6227
6259
|
community._pendingEditProps = community._pendingEditProps.filter((editProps) => !editIdsToIncludeInNextUpdate.includes(editProps.editId));
|
|
6228
6260
|
if (community._pendingEditProps.length > 0) {
|
|
@@ -6595,7 +6627,9 @@ async function stop(community) {
|
|
|
6595
6627
|
if (community.state === "started") {
|
|
6596
6628
|
log("Stopping running community", community.address);
|
|
6597
6629
|
try {
|
|
6598
|
-
|
|
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;
|
|
6599
6633
|
} catch (e) {
|
|
6600
6634
|
log.error("Failed to unsubscribe from challenge exchange pubsub when stopping community", e);
|
|
6601
6635
|
}
|
|
@@ -6623,7 +6657,6 @@ async function stop(community) {
|
|
|
6623
6657
|
log.error(`Failed to unlock start lock on community (${community.address})`, e);
|
|
6624
6658
|
}
|
|
6625
6659
|
const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient();
|
|
6626
|
-
const pubsubClient = community._clientsManager.getDefaultKuboPubsubClient();
|
|
6627
6660
|
community._setStartedStateWithEmission("stopped");
|
|
6628
6661
|
untrackStartedCommunity(community._pkc, community);
|
|
6629
6662
|
processStartedCommunities.untrack(community);
|
|
@@ -6632,7 +6665,7 @@ async function stop(community) {
|
|
|
6632
6665
|
await community._dbHandler.unlockCommunityState();
|
|
6633
6666
|
await community._updateStartedValue();
|
|
6634
6667
|
community._clientsManager.updateKuboRpcState("stopped", kuboRpcClient.url);
|
|
6635
|
-
community._clientsManager.
|
|
6668
|
+
community._clientsManager.updateKuboRpcPubsubStateIfProviderExists("stopped");
|
|
6636
6669
|
if (community._dbHandler) community._dbHandler.destoryConnection();
|
|
6637
6670
|
log(`Stopped the running of local community (${community.address})`);
|
|
6638
6671
|
community._setState("stopped");
|
|
@@ -6691,6 +6724,8 @@ async function deleteCommunity(community) {
|
|
|
6691
6724
|
log.error("Failed to add old page cids from community.posts to be unpinned", e);
|
|
6692
6725
|
}
|
|
6693
6726
|
if (community.ipnsPubsubTopicRoutingCid) community._cidsToUnPin.add(community.ipnsPubsubTopicRoutingCid);
|
|
6727
|
+
const configuredChallengeTopic = communityChallengePubsubTopic(community);
|
|
6728
|
+
if (configuredChallengeTopic) community._cidsToUnPin.add(pubsubTopicToDhtKey(configuredChallengeTopic));
|
|
6694
6729
|
if (community.pubsubTopicRoutingCid) community._cidsToUnPin.add(community.pubsubTopicRoutingCid);
|
|
6695
6730
|
try {
|
|
6696
6731
|
await community.initDbHandlerIfNeeded();
|
|
@@ -6881,11 +6916,11 @@ async function edit(community, newCommunityOptions) {
|
|
|
6881
6916
|
const EXPORTS_KEY = STORAGE_KEYS[STORAGE_KEYS.EXPORTS];
|
|
6882
6917
|
function defaultExportPathFor(community, exportId) {
|
|
6883
6918
|
if (typeof community._pkc.dataPath !== "string") throw new PKCError("ERR_DATA_PATH_IS_NOT_DEFINED", { communityAddress: community.address });
|
|
6884
|
-
return
|
|
6919
|
+
return path.join(community._pkc.dataPath, "exports", `${exportId}.sqlite`);
|
|
6885
6920
|
}
|
|
6886
6921
|
function sourceDbPathFor(community) {
|
|
6887
6922
|
if (typeof community._pkc.dataPath !== "string") throw new PKCError("ERR_DATA_PATH_IS_NOT_DEFINED", { communityAddress: community.address });
|
|
6888
|
-
return
|
|
6923
|
+
return path.join(community._pkc.dataPath, "communities", community.address);
|
|
6889
6924
|
}
|
|
6890
6925
|
async function persistExports(community) {
|
|
6891
6926
|
if (!community._dbHandler) return;
|
|
@@ -6961,9 +6996,9 @@ async function runExportTask(community, exportId, opts) {
|
|
|
6961
6996
|
async function exportCommunityEmbedded(community, options = {}) {
|
|
6962
6997
|
if (options.signal?.aborted) throw options.signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
6963
6998
|
const exportId = v4();
|
|
6964
|
-
const destPath = options.exportPath ?
|
|
6999
|
+
const destPath = options.exportPath ? path.resolve(options.exportPath) : defaultExportPathFor(community, exportId);
|
|
6965
7000
|
const includePrivateKey = options.includePrivateKey === true;
|
|
6966
|
-
if (
|
|
7001
|
+
if (path.resolve(destPath) === path.resolve(sourceDbPathFor(community))) throw new PKCError("ERR_EXPORT_PATH_TARGETS_LIVE_DB", {
|
|
6967
7002
|
communityAddress: community.address,
|
|
6968
7003
|
exportPath: destPath
|
|
6969
7004
|
});
|
|
@@ -7089,6 +7124,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7089
7124
|
this._firstUpdateAfterStart = true;
|
|
7090
7125
|
this._internalStateUpdateId = "";
|
|
7091
7126
|
this._lastPubsubTopicRoutingProvideAt = void 0;
|
|
7127
|
+
this._subscribedChallengePubsubTopic = void 0;
|
|
7092
7128
|
this._lastProvidedBrowserDialableSelfAddrs = void 0;
|
|
7093
7129
|
this._lastAddressReprovideCheckAt = void 0;
|
|
7094
7130
|
this._mirroredStartedOrUpdatingCommunity = void 0;
|
|
@@ -7127,7 +7163,8 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7127
7163
|
_internalStateUpdateId: this._internalStateUpdateId,
|
|
7128
7164
|
_cidsToUnPin: [...this._cidsToUnPin],
|
|
7129
7165
|
_mfsPathsToRemove: [...this._mfsPathsToRemove],
|
|
7130
|
-
_pendingEditProps: this._pendingEditProps
|
|
7166
|
+
_pendingEditProps: this._pendingEditProps,
|
|
7167
|
+
_configuredPubsubTopic: this.pubsubTopic
|
|
7131
7168
|
};
|
|
7132
7169
|
}
|
|
7133
7170
|
toJSONInternalBeforeFirstUpdate() {
|
|
@@ -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-
|
|
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-
|
|
4
|
-
import { o as getHeliaDebugContext } from "./util-
|
|
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-wNdSno5O.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-O94vseOA.js";
|
|
4
|
+
import { o as getHeliaDebugContext } from "./util-iNnH2bP5.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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
603
|
-
const pubsubTopic = this._community?.pubsubTopic
|
|
604
|
-
if (typeof pubsubTopic !== "string") throw
|
|
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.
|
|
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.
|
|
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.
|
|
879
|
+
await this._clientsManager.pubsubSubscribeOnProvider(this._communityChallengePubsubExchangeTopic(), this._handleChallengeExchange, providerUrl);
|
|
872
880
|
this._updatePubsubState("publishing-challenge-request", providerUrl);
|
|
873
|
-
await this._clientsManager.pubsubPublishOnProvider(this.
|
|
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.
|
|
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.
|
|
1000
|
+
await this._clientsManager.pubsubSubscribeOnProvider(this._communityChallengePubsubExchangeTopic(), this._handleChallengeExchange, providerUrl);
|
|
975
1001
|
this._updatePubsubState("publishing-challenge-request", providerUrl);
|
|
976
|
-
await this._clientsManager.pubsubPublishOnProvider(this.
|
|
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.
|
|
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,11 +8901,12 @@ 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-
|
|
8904
|
+
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-BPj1zAUb.js");
|
|
8879
8905
|
for (const clientOptions of this.libp2pJsClientsOptions) {
|
|
8880
8906
|
const heliaNode = await createLibp2pJsClientOrUseExistingOne({
|
|
8881
8907
|
...clientOptions,
|
|
8882
|
-
httpRoutersOptions: this.httpRoutersOptions
|
|
8908
|
+
httpRoutersOptions: this.httpRoutersOptions,
|
|
8909
|
+
dataPath: this.dataPath
|
|
8883
8910
|
});
|
|
8884
8911
|
this.clients.libp2pJsClients[clientOptions.key] = heliaNode;
|
|
8885
8912
|
}
|
|
@@ -9123,7 +9150,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
9123
9150
|
const log = logger_default("pkc-js:pkc:createLocalCommunity");
|
|
9124
9151
|
log.trace("Received community options to create a local community instance:", options);
|
|
9125
9152
|
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-
|
|
9153
|
+
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-ChTkd8lH.js");
|
|
9127
9154
|
const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
|
|
9128
9155
|
const community = new LocalCommunity(this);
|
|
9129
9156
|
if (isLocalCommunity) {
|