@pkcprotocol/pkc-js 0.0.75 → 0.0.77
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 +10 -0
- package/dist/browser/clients/rpc-client/pkc-rpc-client.d.ts +3 -1
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js +12 -1
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -1
- package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +18 -0
- package/dist/browser/clients/rpc-client/rpc-schema-util.js +5 -1
- package/dist/browser/clients/rpc-client/rpc-schema-util.js.map +1 -1
- package/dist/browser/clients/rpc-client/schema.d.ts +15 -0
- package/dist/browser/clients/rpc-client/schema.js +20 -0
- package/dist/browser/clients/rpc-client/schema.js.map +1 -1
- package/dist/browser/clients/rpc-client/types.d.ts +3 -2
- package/dist/browser/community/community-client-manager.js +9 -9
- package/dist/browser/community/community-client-manager.js.map +1 -1
- package/dist/browser/community/rpc-local-community.d.ts +6 -1
- package/dist/browser/community/rpc-local-community.js +32 -0
- package/dist/browser/community/rpc-local-community.js.map +1 -1
- package/dist/browser/community/schema.d.ts +15 -0
- package/dist/browser/community/schema.js +16 -1
- package/dist/browser/community/schema.js.map +1 -1
- package/dist/browser/community/types.d.ts +14 -1
- package/dist/browser/constants.d.ts +3 -1
- package/dist/browser/constants.js +9 -1
- package/dist/browser/constants.js.map +1 -1
- package/dist/browser/errors.d.ts +11 -1
- package/dist/browser/errors.js +11 -1
- 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/index-with-compile-cache.d.ts +2 -0
- package/dist/browser/index-with-compile-cache.js +1 -0
- package/dist/browser/index-with-compile-cache.js.map +1 -1
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.js +8 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/pkc/pkc.js +37 -3
- package/dist/browser/pkc/pkc.js.map +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/rpc/src/index.d.ts +4 -1
- package/dist/browser/rpc/src/index.js +29 -1
- package/dist/browser/rpc/src/index.js.map +1 -1
- package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +1 -0
- package/dist/browser/runtime/node/community/local-community/anchor-publishing.d.ts +9 -0
- package/dist/browser/runtime/node/community/local-community/anchor-publishing.js +197 -0
- package/dist/browser/runtime/node/community/local-community/anchor-publishing.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/cleanup.d.ts +2 -1
- package/dist/browser/runtime/node/community/local-community/cleanup.js +81 -30
- package/dist/browser/runtime/node/community/local-community/cleanup.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/comment-updates.js +5 -0
- 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 +22 -4
- package/dist/browser/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/identity.d.ts +2 -0
- package/dist/browser/runtime/node/community/local-community/identity.js +13 -0
- package/dist/browser/runtime/node/community/local-community/identity.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +11 -28
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +24 -0
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/publication-store.js +7 -3
- package/dist/browser/runtime/node/community/local-community/publication-store.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/publication-validation.js +6 -2
- package/dist/browser/runtime/node/community/local-community/publication-validation.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community.d.ts +5 -1
- package/dist/browser/runtime/node/community/local-community.js +47 -6
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.js +21 -3
- package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +1 -1
- package/dist/browser/schema/schema-util.d.ts +6 -0
- package/dist/browser/schema/schema.d.ts +1 -0
- package/dist/browser/schema/schema.js +11 -0
- package/dist/browser/schema/schema.js.map +1 -1
- package/dist/browser/signer/index.d.ts +1 -0
- package/dist/browser/signer/index.js +1 -0
- package/dist/browser/signer/index.js.map +1 -1
- package/dist/browser/signer/ipns-record.d.ts +7 -0
- package/dist/browser/signer/ipns-record.js +34 -0
- package/dist/browser/signer/ipns-record.js.map +1 -0
- package/dist/browser/signer/signatures.d.ts +2 -2
- package/dist/browser/signer/signatures.js +18 -6
- package/dist/browser/signer/signatures.js.map +1 -1
- package/dist/browser/test/test-util.d.ts +4 -0
- package/dist/browser/util.js +13 -4
- package/dist/browser/util.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +43 -38
- package/dist/bundled/chunks/{helia-for-pkc-BPj1zAUb.js → helia-for-pkc-HklWh03v.js} +3 -3
- package/dist/bundled/chunks/{local-community-D4efR9XJ.js → local-community-BIjlDWkC.js} +235 -50
- package/dist/bundled/chunks/{local-community-ChTkd8lH.js → local-community-CVm32rYh.js} +1 -1
- package/dist/bundled/chunks/{node-BK6GBM0d.js → node-tGwhcLcm.js} +48 -10
- package/dist/bundled/chunks/{rpc-local-community-O94vseOA.js → rpc-local-community-BmD9viua.js} +74 -16
- package/dist/bundled/chunks/{schema-wNdSno5O.js → schema-Bu4z3MGE.js} +32 -8
- package/dist/bundled/chunks/{util-iNnH2bP5.js → util-DIVqZjOO.js} +1 -1
- package/dist/bundled/index-with-compile-cache.js +2 -1
- package/dist/bundled/index.js +2 -2
- package/dist/bundled/rpc/src/index.js +27 -4
- package/dist/node/clients/rpc-client/pkc-rpc-client.d.ts +3 -1
- package/dist/node/clients/rpc-client/pkc-rpc-client.js +12 -1
- package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -1
- package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +18 -0
- package/dist/node/clients/rpc-client/rpc-schema-util.js +5 -1
- package/dist/node/clients/rpc-client/rpc-schema-util.js.map +1 -1
- package/dist/node/clients/rpc-client/schema.d.ts +15 -0
- package/dist/node/clients/rpc-client/schema.js +20 -0
- package/dist/node/clients/rpc-client/schema.js.map +1 -1
- package/dist/node/clients/rpc-client/types.d.ts +3 -2
- package/dist/node/community/community-client-manager.js +9 -9
- package/dist/node/community/community-client-manager.js.map +1 -1
- package/dist/node/community/rpc-local-community.d.ts +6 -1
- package/dist/node/community/rpc-local-community.js +32 -0
- package/dist/node/community/rpc-local-community.js.map +1 -1
- package/dist/node/community/schema.d.ts +15 -0
- package/dist/node/community/schema.js +16 -1
- package/dist/node/community/schema.js.map +1 -1
- package/dist/node/community/types.d.ts +14 -1
- package/dist/node/constants.d.ts +3 -1
- package/dist/node/constants.js +9 -1
- package/dist/node/constants.js.map +1 -1
- package/dist/node/errors.d.ts +11 -1
- package/dist/node/errors.js +11 -1
- 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/index-with-compile-cache.d.ts +2 -0
- package/dist/node/index-with-compile-cache.js +1 -0
- package/dist/node/index-with-compile-cache.js.map +1 -1
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.js +8 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/pkc/pkc.js +37 -3
- package/dist/node/pkc/pkc.js.map +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/rpc/src/index.d.ts +4 -1
- package/dist/node/rpc/src/index.js +29 -1
- package/dist/node/rpc/src/index.js.map +1 -1
- package/dist/node/rpc/src/lib/pkc-js/index.d.ts +1 -0
- package/dist/node/runtime/node/community/local-community/anchor-publishing.d.ts +9 -0
- package/dist/node/runtime/node/community/local-community/anchor-publishing.js +197 -0
- package/dist/node/runtime/node/community/local-community/anchor-publishing.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/cleanup.d.ts +2 -1
- package/dist/node/runtime/node/community/local-community/cleanup.js +81 -30
- package/dist/node/runtime/node/community/local-community/cleanup.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/comment-updates.js +5 -0
- 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 +22 -4
- package/dist/node/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/identity.d.ts +2 -0
- package/dist/node/runtime/node/community/local-community/identity.js +13 -0
- package/dist/node/runtime/node/community/local-community/identity.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js +11 -28
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.js +24 -0
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/publication-store.js +7 -3
- package/dist/node/runtime/node/community/local-community/publication-store.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/publication-validation.js +6 -2
- package/dist/node/runtime/node/community/local-community/publication-validation.js.map +1 -1
- package/dist/node/runtime/node/community/local-community.d.ts +5 -1
- package/dist/node/runtime/node/community/local-community.js +47 -6
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js +21 -3
- package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +1 -1
- package/dist/node/schema/schema-util.d.ts +6 -0
- package/dist/node/schema/schema.d.ts +1 -0
- package/dist/node/schema/schema.js +11 -0
- package/dist/node/schema/schema.js.map +1 -1
- package/dist/node/signer/index.d.ts +1 -0
- package/dist/node/signer/index.js +1 -0
- package/dist/node/signer/index.js.map +1 -1
- package/dist/node/signer/ipns-record.d.ts +7 -0
- package/dist/node/signer/ipns-record.js +34 -0
- package/dist/node/signer/ipns-record.js.map +1 -0
- package/dist/node/signer/signatures.d.ts +2 -2
- package/dist/node/signer/signatures.js +18 -6
- package/dist/node/signer/signatures.js.map +1 -1
- package/dist/node/test/test-util.d.ts +4 -0
- package/dist/node/util.js +13 -4
- package/dist/node/util.js.map +1 -1
- package/package.json +2 -2
- package/dist/bundled/chunks/{src-BKg5Lhod.js → src-BEjAH2gY.js} +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $ as pubsubTopicToDhtKey, $n as
|
|
3
|
-
import { $n as t$
|
|
2
|
+
import { $ as pubsubTopicToDhtKey, $n as n$3, An as CommentsTableRowSchema, At as trackStartedCommunity, Bn as CommentEditsTableRowSchema, Bt as CommunityEditPublicationPubsubReservedFields, C as contentContainsMarkdownAudio, Ct as findUpdatingCommunity, Dn as CommentUpdateSchema, F as getIpnsRecordInLocalKuboNode, Ft as untrackUpdatingCommunity, G as isLinkOfAudio, Gt as CommentModerationPubsubMessagePublicationSchema, In as CommentEditPubsubMessagePublicationSchema, It as require_sha256, J as isLinkOfVideo, Jt as CommentModerationsTableRowSchema, K as isLinkOfImage, Kt as CommentModerationReservedFields, L as hideClassPrivateProps, Ln as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, M as genToArray, Mt as trackUpdatingCommunity, N as getEquivalentCommunityAddresses, Nr as ZodError, Nt as untrackStartedCommunity, O as derivePublicationFromChallengeRequest, P as getErrorCodeFromMessage, Q as isStringDomain, Qn as t$8, R as ipnsNameToIpnsOverPubsubTopic, Rn as CommentEditReservedFields, S as calculateStringSizeSameAsIpfsAddCidV0, T as contentContainsMarkdownVideos, W as isLinkOfAnimatedImage, Wn as AuthorReservedFields, Y as isLinkValid, Zn as n$4, _t as timestamp, a as ChallengeRequestMessageSchema, ar as r$1, at as removeNullUndefinedValues, b as areEquivalentCommunityAddresses, bn as CommentPubsubMessageReservedFields, br as logger_default, bt as findCommunityInRegistry, d as DecryptedChallengeRequestSchema, dt as retryKuboIpfsAddAndProvide, er as t$7, fr as require_retry, gn as VoteTablesRowSchema, ht as statMfsPathSafely, in as CommunitySignedPropertyNames, k as doesDomainAddressHaveCapitalLetter, kn as CommentUpdateTableRowSchema, kt as syncCommunityRegistryEntry, lr as t$5, lt as retryKuboBlockPutPinAndProvidePubsubTopic, mn as VotePubsubReservedFields, mt as sleepUntilTimeoutOrAbort, nr as e, nt as removeBlocksFromKuboNode, or as t$4, pn as VotePubsubMessagePublicationSchema, q as isLinkOfMedia, r as ChallengeMessageSchema, rn as CommunityIpfsSchema, rr as e$1, rt as removeMfsFilesSafely, s as ChallengeVerificationMessageSchema, t as ChallengeAnswerMessageSchema, tr as t$6, u as DecryptedChallengeRequestPublicationSchema, ur as t$3, vr as PKCError, w as contentContainsMarkdownImages, x as calculateIpfsCidV0, xt as findStartedCommunity, y as version_default, yn as CommentIpfsSchema, yr as messages, yt as writeKuboFilesWithTimeout } from "./schema-Bu4z3MGE.js";
|
|
3
|
+
import { $n as t$11, A as deriveCommentIpfsFromCommentTableRow, At as verifyCommunity, B as resolveDbPostsCidRefs, Bt as getCommunityNameFromWire, C as encryptEd25519AesGcmPublicKeyBuffer, Ct as verifyChallengeRequest, D as calculateInlineRepliesBudget, Dt as verifyCommentModeration, E as calculateExpectedSignatureSize, Et as verifyCommentIpfs, F as getThumbnailPropsOfLink, G as POST_REPLIES_SORT_TYPES, I as importSignerIntoKuboNode, It as getAuthorNameFromWire, Jt as getPKCAddressFromPublicKeySync, K as REPLY_REPLIES_SORT_TYPES, Kt as getIpfsKeyFromPrivateKey, M as deriveDbReplies, Mt as verifyVote, N as getDefaultCommunityDbConfig, Nt as buildRuntimeAuthor, Ot as verifyCommentPubsubMessage, Pt as cleanWireAuthor, Q as iterateOverPageCidsToFindAllCids, Qn as r$2, Sn as parseJsonWithPKCErrorIfFails, T as backupCommunityDb, Tt as verifyCommentEdit, Ut as decode, Vt as getCommunityPublicKeyFromWire, W as POSTS_SORT_TYPES, Wt as encode, Xn as t$9, Xt as createSchemaRowParser, Yt as getPublicKeyFromPrivateKey, Zn as t$12, _ as SignerWithPublicKeyAddress, _t as signCommentUpdateForChallengeVerification, a as pkcJsChallenges, ar as STORAGE_KEYS, at as pLimit, ct as cleanUpBeforePublishing, d as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, er as n$6, f as KeyvBetterSqlite3, ft as signChallengeVerification, gt as signCommentUpdate, i as getCommunityChallengeFromCommunityChallengeSettings, ir as stringify, j as deriveDbPosts, jt as verifyCommunityEdit, k as deleteOldCommunityInWindows, kt as verifyCommentUpdate, l as normalizeSelfAddrsForProvider, ln as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, mt as signCommentEdit, o as TrackedInstanceRegistry, or as require_lodash_merge, pt as signComment, q as TIMEFRAMES_TO_SECONDS, qt as getPKCAddressFromPublicKey, r as getChallengeVerification, rr as t$10, s as LRUCache, sn as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, t as RpcLocalCommunity, tr as n$5, ut as signChallengeMessage, vt as signCommunity, w as BackupAbortError, x as decryptEd25519AesGcmPublicKeyBuffer, xt as verifyChallengeAnswer, yn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, z as moveCommunityDbToDeletedDirectory } from "./rpc-local-community-BmD9viua.js";
|
|
4
4
|
import { randomFillSync, randomUUID } from "node:crypto";
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
6
|
import path from "node:path";
|
|
@@ -11,6 +11,7 @@ import assert from "assert";
|
|
|
11
11
|
import fs from "fs";
|
|
12
12
|
import Database from "better-sqlite3";
|
|
13
13
|
import { CID } from "multiformats/cid";
|
|
14
|
+
import { peerIdFromString } from "@libp2p/peer-id";
|
|
14
15
|
import { of } from "typestub-ipfs-only-hash";
|
|
15
16
|
//#region node_modules/remeda/dist/entries.js
|
|
16
17
|
function t$2(...t) {
|
|
@@ -64,6 +65,138 @@ function r(t) {
|
|
|
64
65
|
};
|
|
65
66
|
}
|
|
66
67
|
//#endregion
|
|
68
|
+
//#region dist/node/runtime/node/community/local-community/identity.js
|
|
69
|
+
function communityIdentityPublicKey(community) {
|
|
70
|
+
return community.anchor?.publicKey ?? community.signer.address;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region dist/node/runtime/node/community/local-community/anchor-publishing.js
|
|
74
|
+
const ANCHOR_SEQUENCE_MARGIN = 5n;
|
|
75
|
+
const ANCHOR_LOOKUP_TIMEOUT_MS = 3e4;
|
|
76
|
+
function assertDelegated(community) {
|
|
77
|
+
if (!community.anchor) throw new PKCError("ERR_COMMUNITY_IS_NOT_DELEGATED", {
|
|
78
|
+
address: community.address,
|
|
79
|
+
signerAddress: community.signer?.address
|
|
80
|
+
});
|
|
81
|
+
return community.anchor;
|
|
82
|
+
}
|
|
83
|
+
function getPersistedAnchorRecordBytes(community) {
|
|
84
|
+
const stored = community._dbHandler.keyvGet(STORAGE_KEYS[STORAGE_KEYS.ANCHOR_IPNS_RECORD]);
|
|
85
|
+
if (!stored) return void 0;
|
|
86
|
+
return stored instanceof Uint8Array ? stored : new Uint8Array(Object.values(stored));
|
|
87
|
+
}
|
|
88
|
+
function getHighestAcceptedAnchorSequence(community) {
|
|
89
|
+
const stored = community._dbHandler.keyvGet(STORAGE_KEYS[STORAGE_KEYS.HIGHEST_ACCEPTED_ANCHOR_SEQUENCE]);
|
|
90
|
+
return typeof stored === "string" ? BigInt(stored) : void 0;
|
|
91
|
+
}
|
|
92
|
+
async function lookupAnchorRecordOnNetwork(community, anchorName) {
|
|
93
|
+
const log = logger_default("pkc-js:local-community:prepareAnchorPublish");
|
|
94
|
+
const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient();
|
|
95
|
+
try {
|
|
96
|
+
return await Promise.race([getIpnsRecordInLocalKuboNode(kuboRpcClient, anchorName), new Promise((resolve) => setTimeout(() => resolve(void 0), ANCHOR_LOOKUP_TIMEOUT_MS))]);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
log.trace(`Anchor (${anchorName}) did not resolve while preparing a publish`, e);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function prepareAnchorPublish(community) {
|
|
103
|
+
const log = logger_default("pkc-js:local-community:prepareAnchorPublish");
|
|
104
|
+
const anchor = assertDelegated(community);
|
|
105
|
+
await community._dbHandler.initDbIfNeeded();
|
|
106
|
+
const persistedSequence = getHighestAcceptedAnchorSequence(community);
|
|
107
|
+
const networkRecord = await lookupAnchorRecordOnNetwork(community, anchor.publicKey);
|
|
108
|
+
const networkSequence = networkRecord ? BigInt(networkRecord.sequence) : void 0;
|
|
109
|
+
if (persistedSequence === void 0 && networkSequence === void 0) throw new PKCError("ERR_UNABLE_TO_DETERMINE_ANCHOR_SEQUENCE", {
|
|
110
|
+
address: community.address,
|
|
111
|
+
anchorPublicKey: anchor.publicKey,
|
|
112
|
+
reason: "This node has never accepted an anchor record for this community and /ipns/<anchor> did not resolve. If this anchor has never been published, sign sequence 0 (the nextSequence createCommunity returned); otherwise retry once the anchor resolves."
|
|
113
|
+
});
|
|
114
|
+
const highestKnown = [persistedSequence, networkSequence].reduce((max, seq) => seq !== void 0 && seq > max ? seq : max, 0n);
|
|
115
|
+
const nextSequence = highestKnown + ANCHOR_SEQUENCE_MARGIN;
|
|
116
|
+
log(`Prepared anchor publish for community (${community.address}): persisted=${persistedSequence}, network=${networkSequence}, next=${nextSequence}`);
|
|
117
|
+
return {
|
|
118
|
+
nextSequence: nextSequence.toString(),
|
|
119
|
+
currentAnchorRecordSequence: highestKnown.toString(),
|
|
120
|
+
hasPersistedAnchorRecord: persistedSequence !== void 0
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
async function putAnchorRecordThroughKubo(community, anchorName, recordBytes) {
|
|
124
|
+
const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient();
|
|
125
|
+
for await (const _event of kuboRpcClient._client.routing.put(`/ipns/${anchorName}`, recordBytes, { allowOffline: true }));
|
|
126
|
+
}
|
|
127
|
+
const anchorPublishQueues = /* @__PURE__ */ new Map();
|
|
128
|
+
function serializePerCommunityAddress(address, task) {
|
|
129
|
+
const run = (anchorPublishQueues.get(address) ?? Promise.resolve()).then(task);
|
|
130
|
+
const settled = run.then(() => {}, () => {});
|
|
131
|
+
anchorPublishQueues.set(address, settled);
|
|
132
|
+
settled.then(() => {
|
|
133
|
+
if (anchorPublishQueues.get(address) === settled) anchorPublishQueues.delete(address);
|
|
134
|
+
});
|
|
135
|
+
return run;
|
|
136
|
+
}
|
|
137
|
+
async function publishAnchorRecord(community, recordBytes) {
|
|
138
|
+
return serializePerCommunityAddress(community.address, () => publishAnchorRecordSerialized(community, recordBytes));
|
|
139
|
+
}
|
|
140
|
+
async function publishAnchorRecordSerialized(community, recordBytes) {
|
|
141
|
+
const log = logger_default("pkc-js:local-community:publishAnchorRecord");
|
|
142
|
+
const anchor = assertDelegated(community);
|
|
143
|
+
await community._dbHandler.initDbIfNeeded();
|
|
144
|
+
const { multihashToIPNSRoutingKey, unmarshalIPNSRecord } = await import("ipns");
|
|
145
|
+
const { ipnsValidator } = await import("ipns/validator");
|
|
146
|
+
const bytes = recordBytes instanceof Uint8Array ? recordBytes : new Uint8Array(Object.values(recordBytes));
|
|
147
|
+
try {
|
|
148
|
+
await ipnsValidator(multihashToIPNSRoutingKey(peerIdFromString(anchor.publicKey).toMultihash()), bytes);
|
|
149
|
+
} catch (e) {
|
|
150
|
+
throw new PKCError("ERR_ANCHOR_IPNS_RECORD_IS_INVALID", {
|
|
151
|
+
address: community.address,
|
|
152
|
+
anchorPublicKey: anchor.publicKey,
|
|
153
|
+
validationError: e
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const record = unmarshalIPNSRecord(bytes);
|
|
157
|
+
const expectedValue = `/ipns/${community.signer.address}`;
|
|
158
|
+
if (record.value !== expectedValue) throw new PKCError("ERR_ANCHOR_IPNS_RECORD_POINTS_TO_DIFFERENT_MINTER", {
|
|
159
|
+
address: community.address,
|
|
160
|
+
anchorPublicKey: anchor.publicKey,
|
|
161
|
+
expectedValue,
|
|
162
|
+
recordValue: record.value
|
|
163
|
+
});
|
|
164
|
+
const sequence = BigInt(record.sequence);
|
|
165
|
+
const highestAccepted = getHighestAcceptedAnchorSequence(community);
|
|
166
|
+
if (highestAccepted !== void 0 && sequence <= highestAccepted) throw new PKCError("ERR_ANCHOR_IPNS_RECORD_SEQUENCE_IS_NOT_GREATER", {
|
|
167
|
+
address: community.address,
|
|
168
|
+
anchorPublicKey: anchor.publicKey,
|
|
169
|
+
recordSequence: sequence.toString(),
|
|
170
|
+
highestAcceptedSequence: highestAccepted.toString()
|
|
171
|
+
});
|
|
172
|
+
await putAnchorRecordThroughKubo(community, anchor.publicKey, bytes);
|
|
173
|
+
await community._dbHandler.keyvSet(STORAGE_KEYS[STORAGE_KEYS.ANCHOR_IPNS_RECORD], bytes);
|
|
174
|
+
await community._dbHandler.keyvSet(STORAGE_KEYS[STORAGE_KEYS.HIGHEST_ACCEPTED_ANCHOR_SEQUENCE], sequence.toString());
|
|
175
|
+
community.anchorRecordSequence = sequence.toString();
|
|
176
|
+
log(`Published anchor record for community (${community.address}) at sequence ${sequence}, pointing at ${record.value}`);
|
|
177
|
+
return {
|
|
178
|
+
sequence: sequence.toString(),
|
|
179
|
+
value: record.value,
|
|
180
|
+
anchorPublicKey: anchor.publicKey
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
async function reprovideAnchorRecordIfNeeded(community) {
|
|
184
|
+
const log = logger_default("pkc-js:local-community:reprovideAnchorRecord");
|
|
185
|
+
if (!community.anchor) return false;
|
|
186
|
+
const bytes = getPersistedAnchorRecordBytes(community);
|
|
187
|
+
if (!bytes) return false;
|
|
188
|
+
await putAnchorRecordThroughKubo(community, community.anchor.publicKey, bytes);
|
|
189
|
+
community._lastAnchorRecordReprovideAt = Date.now();
|
|
190
|
+
log.trace(`Re-provided anchor record of community (${community.address})`);
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
async function reprovideAnchorRecordIfDue(community) {
|
|
194
|
+
if (!community.anchor) return;
|
|
195
|
+
const lastAt = community._lastAnchorRecordReprovideAt;
|
|
196
|
+
if (typeof lastAt === "number" && Date.now() - lastAt < 36e5) return;
|
|
197
|
+
await reprovideAnchorRecordIfNeeded(community);
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
67
200
|
//#region dist/node/runtime/node/community/local-community/comment-updates.js
|
|
68
201
|
function communityChallengePubsubTopic(community) {
|
|
69
202
|
return community.pubsubTopic || community.signer?.address;
|
|
@@ -335,28 +468,64 @@ async function repinCommentUpdateIfNeeded(community) {
|
|
|
335
468
|
log(`CommentUpdate directory`, community.address, "will republish all comment updates");
|
|
336
469
|
community._dbHandler.forceUpdateOnAllComments();
|
|
337
470
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
471
|
+
const GC_HIGH_WATERMARK = .9;
|
|
472
|
+
const MIN_MS_BETWEEN_GC = 3600 * 1e3;
|
|
473
|
+
const lastGcFinishedAtByKuboUrl = /* @__PURE__ */ new Map();
|
|
474
|
+
const inFlightGcByKuboUrl = /* @__PURE__ */ new Map();
|
|
475
|
+
async function cleanUpIpfsRepoIfDue(community, force = false) {
|
|
476
|
+
const log = logger_default("pkc-js:local-community:syncIpnsWithDb:_cleanUpIpfsRepoIfDue");
|
|
477
|
+
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
478
|
+
const kuboUrl = String(kuboRpc.url);
|
|
479
|
+
const inFlight = inFlightGcByKuboUrl.get(kuboUrl);
|
|
480
|
+
if (inFlight) return inFlight;
|
|
481
|
+
const gcRun = _runRepoGcIfDue({
|
|
482
|
+
community,
|
|
483
|
+
kuboUrl,
|
|
484
|
+
force,
|
|
485
|
+
log
|
|
486
|
+
}).finally(() => inFlightGcByKuboUrl.delete(kuboUrl));
|
|
487
|
+
inFlightGcByKuboUrl.set(kuboUrl, gcRun);
|
|
488
|
+
return gcRun;
|
|
489
|
+
}
|
|
490
|
+
async function _runRepoGcIfDue({ community, kuboUrl, force, log }) {
|
|
491
|
+
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
492
|
+
let repoSizeBefore;
|
|
493
|
+
if (!force) {
|
|
494
|
+
const lastGcFinishedAt = lastGcFinishedAtByKuboUrl.get(kuboUrl);
|
|
495
|
+
if (typeof lastGcFinishedAt === "number" && Date.now() - lastGcFinishedAt < MIN_MS_BETWEEN_GC) return;
|
|
496
|
+
let repoStat;
|
|
343
497
|
try {
|
|
344
|
-
await
|
|
345
|
-
milliseconds: 15e3,
|
|
346
|
-
message: "Timed out flushing MFS root before repo.gc"
|
|
347
|
-
});
|
|
498
|
+
repoStat = await kuboRpc._client.repo.stat({ searchParams: new URLSearchParams({ "size-only": "true" }) });
|
|
348
499
|
} catch (e) {
|
|
349
|
-
log.error("Skipping repo.gc: failed to
|
|
500
|
+
log.error("Skipping repo.gc: failed to read repo.stat from the kubo node", kuboUrl, e);
|
|
350
501
|
return;
|
|
351
502
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
503
|
+
repoSizeBefore = repoStat.repoSize;
|
|
504
|
+
if (repoStat.storageMax > 0n) {
|
|
505
|
+
const gcThreshold = repoStat.storageMax * BigInt(Math.round(GC_HIGH_WATERMARK * 100)) / 100n;
|
|
506
|
+
if (repoStat.repoSize < gcThreshold) {
|
|
507
|
+
log.trace("Skipping repo.gc on", kuboUrl, "- repo size", repoStat.repoSize, "is below the", `${GC_HIGH_WATERMARK * 100}%`, "watermark", gcThreshold, "of StorageMax", repoStat.storageMax);
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
357
510
|
}
|
|
358
|
-
log("GC cleaned", gcCids, "cids out of the IPFS node");
|
|
359
511
|
}
|
|
512
|
+
let gcCids = 0;
|
|
513
|
+
try {
|
|
514
|
+
for await (const res of kuboRpc._client.repo.gc({ quiet: true })) if (res.cid) gcCids++;
|
|
515
|
+
else log.error("Failed to GC ipfs repo due to error", res.err);
|
|
516
|
+
} catch (e) {
|
|
517
|
+
log.error("Failed to GC ipfs repo due to error", e);
|
|
518
|
+
return;
|
|
519
|
+
} finally {
|
|
520
|
+
lastGcFinishedAtByKuboUrl.set(kuboUrl, Date.now());
|
|
521
|
+
}
|
|
522
|
+
let repoSizeAfter;
|
|
523
|
+
try {
|
|
524
|
+
repoSizeAfter = (await kuboRpc._client.repo.stat({ searchParams: new URLSearchParams({ "size-only": "true" }) })).repoSize;
|
|
525
|
+
} catch (e) {
|
|
526
|
+
log.trace("repo.gc finished but the follow-up repo.stat failed", e);
|
|
527
|
+
}
|
|
528
|
+
log("GC cleaned", gcCids, "cids out of the IPFS node", kuboUrl, "- repo size", repoSizeBefore ?? "unknown", "->", repoSizeAfter ?? "unknown");
|
|
360
529
|
}
|
|
361
530
|
async function addAllCidsUnderPurgedCommentToBeRemoved(community, purgedCommentAndCommentUpdate) {
|
|
362
531
|
community._cidsToUnPin.add(purgedCommentAndCommentUpdate.commentTableRow.cid);
|
|
@@ -1008,7 +1177,7 @@ async function checkWireFormatAndCommunityAuthor(community, publication, authorC
|
|
|
1008
1177
|
if ("subplebbitAddress" in publication) return messages.ERR_PUBLICATION_USES_DEPRECATED_SUBPLEBBIT_ADDRESS;
|
|
1009
1178
|
if ("communityAddress" in publication) return messages.ERR_PUBLICATION_USES_DEPRECATED_COMMUNITY_ADDRESS;
|
|
1010
1179
|
const pubCommunityPublicKey = getCommunityPublicKeyFromWire(publication);
|
|
1011
|
-
if (!pubCommunityPublicKey || pubCommunityPublicKey !== community
|
|
1180
|
+
if (!pubCommunityPublicKey || pubCommunityPublicKey !== communityIdentityPublicKey(community)) return messages.ERR_PUBLICATION_INVALID_COMMUNITY_PUBLIC_KEY;
|
|
1012
1181
|
const pubCommunityName = getCommunityNameFromWire(publication);
|
|
1013
1182
|
if (pubCommunityName && pubCommunityName !== community.address) return messages.ERR_PUBLICATION_INVALID_COMMUNITY_NAME;
|
|
1014
1183
|
if (publication.timestamp <= timestamp() - 300 || publication.timestamp >= timestamp() + 300) return messages.ERR_PUBLICATION_TIMESTAMP_IS_NOT_IN_PROPER_RANGE;
|
|
@@ -1324,7 +1493,7 @@ async function storeCommentEdit(community, commentEditRaw, challengeRequestId) {
|
|
|
1324
1493
|
const log = logger_default("pkc-js:local-community:storeCommentEdit");
|
|
1325
1494
|
const strippedOutEditPublication = CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema.strip().parse(commentEditRaw);
|
|
1326
1495
|
strippedOutEditPublication.author = cleanWireAuthor(strippedOutEditPublication.author);
|
|
1327
|
-
if (!strippedOutEditPublication.communityPublicKey) strippedOutEditPublication.communityPublicKey = community
|
|
1496
|
+
if (!strippedOutEditPublication.communityPublicKey) strippedOutEditPublication.communityPublicKey = communityIdentityPublicKey(community);
|
|
1328
1497
|
if (!strippedOutEditPublication.communityName && isStringDomain(community.address)) strippedOutEditPublication.communityName = community.address;
|
|
1329
1498
|
const commentToBeEdited = community._dbHandler.queryComment(commentEditRaw.commentCid);
|
|
1330
1499
|
if (!commentToBeEdited) throw Error("The comment to edit doesn't exist");
|
|
@@ -1358,7 +1527,7 @@ async function storeCommentModeration(community, commentModRaw, challengeRequest
|
|
|
1358
1527
|
const log = logger_default("pkc-js:local-community:storeCommentModeration");
|
|
1359
1528
|
const strippedOutModPublication = CommentModerationPubsubMessagePublicationSchema.strip().parse(commentModRaw);
|
|
1360
1529
|
strippedOutModPublication.author = cleanWireAuthor(strippedOutModPublication.author);
|
|
1361
|
-
if (!strippedOutModPublication.communityPublicKey) strippedOutModPublication.communityPublicKey = community
|
|
1530
|
+
if (!strippedOutModPublication.communityPublicKey) strippedOutModPublication.communityPublicKey = communityIdentityPublicKey(community);
|
|
1362
1531
|
if (!strippedOutModPublication.communityName && isStringDomain(community.address)) strippedOutModPublication.communityName = community.address;
|
|
1363
1532
|
const commentToBeEdited = community._dbHandler.queryComment(commentModRaw.commentCid);
|
|
1364
1533
|
if (!commentToBeEdited) throw Error("The comment to edit doesn't exist");
|
|
@@ -1456,7 +1625,7 @@ async function storeComment(community, opts) {
|
|
|
1456
1625
|
...pseudonymityMode ? { pseudonymityMode } : {},
|
|
1457
1626
|
...challengeAggregate?.aggregatedComment ?? {}
|
|
1458
1627
|
};
|
|
1459
|
-
commentIpfs.communityPublicKey = community
|
|
1628
|
+
commentIpfs.communityPublicKey = communityIdentityPublicKey(community);
|
|
1460
1629
|
if (isStringDomain(community.address)) commentIpfs.communityName = community.address;
|
|
1461
1630
|
delete commentIpfs.communityAddress;
|
|
1462
1631
|
commentIpfs.author = cleanWireAuthor(commentIpfs.author);
|
|
@@ -5798,6 +5967,7 @@ async function updateInstanceStateWithDbState(community) {
|
|
|
5798
5967
|
}
|
|
5799
5968
|
await community.initInternalCommunityAfterFirstUpdateNoMerge(currentDbState);
|
|
5800
5969
|
} else await community.initInternalCommunityBeforeFirstUpdateNoMerge(currentDbState);
|
|
5970
|
+
community.anchorRecordSequence = getHighestAcceptedAnchorSequence(community)?.toString();
|
|
5801
5971
|
}
|
|
5802
5972
|
async function updateInstancePropsWithStartedCommunityOrDb(community) {
|
|
5803
5973
|
const log = logger_default("pkc-js:local-community:_updateInstancePropsWithStartedCommunityOrDb");
|
|
@@ -5814,6 +5984,7 @@ async function updateInstancePropsWithStartedCommunityOrDb(community) {
|
|
|
5814
5984
|
else await community.initInternalCommunityBeforeFirstUpdateNoMerge(startedCommunity.toJSONInternalBeforeFirstUpdate());
|
|
5815
5985
|
community.started = true;
|
|
5816
5986
|
community._exports = startedCommunity.exports;
|
|
5987
|
+
community.anchorRecordSequence = startedCommunity.anchorRecordSequence;
|
|
5817
5988
|
} else {
|
|
5818
5989
|
await community.initDbHandlerIfNeeded();
|
|
5819
5990
|
try {
|
|
@@ -5899,6 +6070,8 @@ async function createNewLocalCommunityDb(community) {
|
|
|
5899
6070
|
}
|
|
5900
6071
|
async function initNewLocalCommunityPropsNoMerge(community, newProps) {
|
|
5901
6072
|
await initSignerProps(community, newProps.signer);
|
|
6073
|
+
community.anchor = newProps.anchor;
|
|
6074
|
+
if (newProps.anchor) community.ipnsHops = [newProps.anchor.publicKey, community.signer.address];
|
|
5902
6075
|
community.title = newProps.title;
|
|
5903
6076
|
community.description = newProps.description;
|
|
5904
6077
|
community.setAddress(newProps.address);
|
|
@@ -5936,6 +6109,7 @@ async function initInternalCommunityAfterFirstUpdateNoMerge(community, newProps)
|
|
|
5936
6109
|
"shortAddress",
|
|
5937
6110
|
"type"
|
|
5938
6111
|
]),
|
|
6112
|
+
anchor: newProps.anchor,
|
|
5939
6113
|
settings: newProps.settings,
|
|
5940
6114
|
_usingDefaultChallenge: newProps._usingDefaultChallenge,
|
|
5941
6115
|
address: newProps.address,
|
|
@@ -5972,9 +6146,6 @@ async function initInternalCommunityBeforeFirstUpdateNoMerge(community, newProps
|
|
|
5972
6146
|
await initSignerProps(community, newProps.signer);
|
|
5973
6147
|
community._internalStateUpdateId = newProps._internalStateUpdateId;
|
|
5974
6148
|
community._updateIpnsPubsubPropsIfNeeded(newProps);
|
|
5975
|
-
community.ipnsName = newProps.signer.address;
|
|
5976
|
-
community.ipnsPubsubTopic = ipnsNameToIpnsOverPubsubTopic(community.ipnsName);
|
|
5977
|
-
community.ipnsPubsubTopicRoutingCid = pubsubTopicToDhtKey(community.ipnsPubsubTopic);
|
|
5978
6149
|
if (processStartedCommunities.has(community)) syncCommunityRegistryEntry(processStartedCommunities, community);
|
|
5979
6150
|
community.raw.localCommunity = community.toJSONInternalRpcBeforeFirstUpdate();
|
|
5980
6151
|
}
|
|
@@ -6111,25 +6282,7 @@ async function calculateNextCommunityRecord(community, commentUpdateRowsToPublis
|
|
|
6111
6282
|
const latestComment = community._dbHandler.queryLatestCommentCid();
|
|
6112
6283
|
community._dbHandler.commitTransaction();
|
|
6113
6284
|
const stats = community._dbHandler.queryCommunityStats();
|
|
6114
|
-
if (commentUpdateRowsToPublishToIpfs.length > 0)
|
|
6115
|
-
await syncPostUpdatesWithIpfs(community, commentUpdateRowsToPublishToIpfs);
|
|
6116
|
-
} catch (e) {
|
|
6117
|
-
const err = e;
|
|
6118
|
-
if (err.message.includes("Timed out writing to MFS path") || err.message.includes("Timed out removing MFS paths")) {
|
|
6119
|
-
log.error(`MFS sync stuck for community ${community.address} - auto-nuking /${community.address} and forcing a full republish. See https://github.com/ipfs/kubo/issues/10842 for upstream context.`);
|
|
6120
|
-
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
6121
|
-
try {
|
|
6122
|
-
await kuboRpc._client.files.rm("/" + community.address, {
|
|
6123
|
-
recursive: true,
|
|
6124
|
-
force: true
|
|
6125
|
-
});
|
|
6126
|
-
} catch (rmErr) {
|
|
6127
|
-
log.error(`Auto-nuke files.rm of /${community.address} failed:`, rmErr);
|
|
6128
|
-
}
|
|
6129
|
-
community._dbHandler.forceUpdateOnAllComments();
|
|
6130
|
-
}
|
|
6131
|
-
throw e;
|
|
6132
|
-
}
|
|
6285
|
+
if (commentUpdateRowsToPublishToIpfs.length > 0) await syncPostUpdatesWithIpfs(community, commentUpdateRowsToPublishToIpfs);
|
|
6133
6286
|
const newPostUpdates = await community._calculateNewPostUpdates();
|
|
6134
6287
|
const newModQueue = await community._pageGenerator.generateModQueuePages();
|
|
6135
6288
|
const statsCid = (await retryKuboIpfsAddAndProvide({
|
|
@@ -6300,7 +6453,7 @@ async function syncIpnsWithDb(community) {
|
|
|
6300
6453
|
const commentUpdateRows = await updateCommentsThatNeedToBeUpdated(community);
|
|
6301
6454
|
requireCommunityUpdateIfModQueueChanged(community);
|
|
6302
6455
|
await updateCommunityIpnsIfNeeded(community, commentUpdateRows);
|
|
6303
|
-
await
|
|
6456
|
+
await cleanUpIpfsRepoIfDue(community);
|
|
6304
6457
|
} catch (e) {
|
|
6305
6458
|
e.details = {
|
|
6306
6459
|
...e.details,
|
|
@@ -6411,6 +6564,7 @@ async function publishLoop(community, syncIntervalMs) {
|
|
|
6411
6564
|
while (!shouldStopPublishLoop()) try {
|
|
6412
6565
|
await syncIpnsWithDb(community);
|
|
6413
6566
|
await reprovideOnAddressChangeIfDue(community).catch((e) => log.error("Failed to re-provide connection CIDs on address change", e));
|
|
6567
|
+
await reprovideAnchorRecordIfDue(community).catch((e) => log.error("Failed to re-provide the anchor record", e));
|
|
6414
6568
|
} catch (e) {
|
|
6415
6569
|
community.emit("error", e);
|
|
6416
6570
|
} finally {
|
|
@@ -6458,6 +6612,11 @@ async function start(community) {
|
|
|
6458
6612
|
})) throw new PKCError("ERR_COMMUNITY_ALREADY_STARTED", { address: community.address });
|
|
6459
6613
|
try {
|
|
6460
6614
|
await initBeforeStarting(community);
|
|
6615
|
+
if (community.anchor && !getPersistedAnchorRecordBytes(community)) throw new PKCError("ERR_DELEGATED_COMMUNITY_HAS_NO_ANCHOR_RECORD", {
|
|
6616
|
+
address: community.address,
|
|
6617
|
+
anchorPublicKey: community.anchor.publicKey,
|
|
6618
|
+
minterAddress: community.signer.address
|
|
6619
|
+
});
|
|
6461
6620
|
community._setState("started");
|
|
6462
6621
|
await community._updateStartedValue();
|
|
6463
6622
|
await community._dbHandler.lockCommunityStart();
|
|
@@ -6471,6 +6630,7 @@ async function start(community) {
|
|
|
6471
6630
|
await setChallengesToDefaultIfNotDefined(community, log);
|
|
6472
6631
|
await importCommunitySignerIntoIpfsIfNeeded(community);
|
|
6473
6632
|
await providePubsubTopicRoutingCidsIfNeeded(community, true);
|
|
6633
|
+
await reprovideAnchorRecordIfNeeded(community).catch((e) => log.error("Failed to re-provide the anchor record on start", e));
|
|
6474
6634
|
community._communityUpdateTrigger = true;
|
|
6475
6635
|
community._setStartedStateWithEmission("publishing-ipns");
|
|
6476
6636
|
await community._repinCommentsIPFSIfNeeded();
|
|
@@ -6506,6 +6666,7 @@ async function initMirroringStartedOrUpdatingCommunity(community, startedCommuni
|
|
|
6506
6666
|
if (startedCommunity.updateCid) await community.initInternalCommunityAfterFirstUpdateNoMerge(startedCommunity.toJSONInternalAfterFirstUpdate());
|
|
6507
6667
|
else await community.initInternalCommunityBeforeFirstUpdateNoMerge(startedCommunity.toJSONInternalBeforeFirstUpdate());
|
|
6508
6668
|
community.started = startedCommunity.started;
|
|
6669
|
+
community.anchorRecordSequence = startedCommunity.anchorRecordSequence;
|
|
6509
6670
|
community.emit("update", community);
|
|
6510
6671
|
};
|
|
6511
6672
|
const stateChangeListener = async (newState) => {
|
|
@@ -6538,6 +6699,7 @@ async function initMirroringStartedOrUpdatingCommunity(community, startedCommuni
|
|
|
6538
6699
|
}
|
|
6539
6700
|
if (startedCommunity.updateCid) await community.initInternalCommunityAfterFirstUpdateNoMerge(startedCommunity.toJSONInternalAfterFirstUpdate());
|
|
6540
6701
|
else await community.initInternalCommunityBeforeFirstUpdateNoMerge(startedCommunity.toJSONInternalBeforeFirstUpdate());
|
|
6702
|
+
community.anchorRecordSequence = startedCommunity.anchorRecordSequence;
|
|
6541
6703
|
community.emit("update", community);
|
|
6542
6704
|
}
|
|
6543
6705
|
async function cleanUpMirroredStartedOrUpdatingCommunity(community) {
|
|
@@ -7127,6 +7289,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7127
7289
|
this._subscribedChallengePubsubTopic = void 0;
|
|
7128
7290
|
this._lastProvidedBrowserDialableSelfAddrs = void 0;
|
|
7129
7291
|
this._lastAddressReprovideCheckAt = void 0;
|
|
7292
|
+
this._lastAnchorRecordReprovideAt = void 0;
|
|
7130
7293
|
this._mirroredStartedOrUpdatingCommunity = void 0;
|
|
7131
7294
|
this._pendingEditProps = [];
|
|
7132
7295
|
this._blocksToRm = [];
|
|
@@ -7151,7 +7314,11 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7151
7314
|
const rpcJson = this.toJSONInternalRpcAfterFirstUpdate();
|
|
7152
7315
|
return {
|
|
7153
7316
|
...rpcJson.community,
|
|
7154
|
-
...n$3(rpcJson.localCommunity, [
|
|
7317
|
+
...n$3(rpcJson.localCommunity, [
|
|
7318
|
+
"started",
|
|
7319
|
+
"startedState",
|
|
7320
|
+
"anchorRecordSequence"
|
|
7321
|
+
]),
|
|
7155
7322
|
updateCid: rpcJson.runtimeFields.updateCid,
|
|
7156
7323
|
signer: t$9(this.signer, [
|
|
7157
7324
|
"privateKey",
|
|
@@ -7169,7 +7336,11 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7169
7336
|
}
|
|
7170
7337
|
toJSONInternalBeforeFirstUpdate() {
|
|
7171
7338
|
return {
|
|
7172
|
-
...n$3(this.toJSONInternalRpcBeforeFirstUpdate().localCommunity, [
|
|
7339
|
+
...n$3(this.toJSONInternalRpcBeforeFirstUpdate().localCommunity, [
|
|
7340
|
+
"started",
|
|
7341
|
+
"startedState",
|
|
7342
|
+
"anchorRecordSequence"
|
|
7343
|
+
]),
|
|
7173
7344
|
signer: t$9(this.signer, [
|
|
7174
7345
|
"privateKey",
|
|
7175
7346
|
"type",
|
|
@@ -7207,6 +7378,12 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7207
7378
|
])
|
|
7208
7379
|
} };
|
|
7209
7380
|
}
|
|
7381
|
+
_updateIpnsPubsubPropsIfNeeded(_newProps) {
|
|
7382
|
+
if (!this.signer?.address) return;
|
|
7383
|
+
this.ipnsName = this.signer.address;
|
|
7384
|
+
this.ipnsPubsubTopic = ipnsNameToIpnsOverPubsubTopic(this.ipnsName);
|
|
7385
|
+
this.ipnsPubsubTopicRoutingCid = pubsubTopicToDhtKey(this.ipnsPubsubTopic);
|
|
7386
|
+
}
|
|
7210
7387
|
async _updateStartedValue() {
|
|
7211
7388
|
this.started = await this._dbHandler.isCommunityStartLocked(this.address);
|
|
7212
7389
|
}
|
|
@@ -7247,7 +7424,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7247
7424
|
}
|
|
7248
7425
|
const verificationOpts = {
|
|
7249
7426
|
community: recordToPublishRaw,
|
|
7250
|
-
|
|
7427
|
+
communityIpnsHops: this.ipnsHops ?? [this.signer.address],
|
|
7251
7428
|
resolveAuthorNames: false,
|
|
7252
7429
|
clientsManager: this._clientsManager,
|
|
7253
7430
|
validatePages: true,
|
|
@@ -7275,7 +7452,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7275
7452
|
throw e;
|
|
7276
7453
|
}
|
|
7277
7454
|
if (this.shouldResolveDomainForVerification()) try {
|
|
7278
|
-
log(`Resolving domain ${this.address} to make sure it's the same as
|
|
7455
|
+
log(`Resolving domain ${this.address} to make sure it's the same as ${communityIdentityPublicKey(this)}`);
|
|
7279
7456
|
await this._assertDomainResolvesCorrectly(this.address);
|
|
7280
7457
|
} catch (e) {
|
|
7281
7458
|
log.error(e);
|
|
@@ -7311,15 +7488,23 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7311
7488
|
communityName: newAddressAsDomain,
|
|
7312
7489
|
cache: { maxAge: 600 }
|
|
7313
7490
|
});
|
|
7314
|
-
|
|
7491
|
+
const identityPublicKey = communityIdentityPublicKey(this);
|
|
7492
|
+
if (resolvedIpnsFromNewDomain !== identityPublicKey) throw new PKCError("ERR_DOMAIN_COMMUNITY_ADDRESS_TXT_RECORD_POINT_TO_DIFFERENT_ADDRESS", {
|
|
7315
7493
|
currentCommunityAddress: this.address,
|
|
7316
7494
|
newAddressAsDomain,
|
|
7317
7495
|
resolvedIpnsFromNewDomain,
|
|
7496
|
+
identityPublicKey,
|
|
7318
7497
|
signerAddress: this.signer.address,
|
|
7319
7498
|
started: this.started
|
|
7320
7499
|
});
|
|
7321
7500
|
}
|
|
7322
7501
|
}
|
|
7502
|
+
async prepareAnchorPublish() {
|
|
7503
|
+
return prepareAnchorPublish(this);
|
|
7504
|
+
}
|
|
7505
|
+
async publishAnchorRecord(recordBytes) {
|
|
7506
|
+
return publishAnchorRecord(this, recordBytes);
|
|
7507
|
+
}
|
|
7323
7508
|
async start() {
|
|
7324
7509
|
return start(this);
|
|
7325
7510
|
}
|
|
@@ -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-BIjlDWkC.js";
|
|
2
2
|
export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };
|