@pkcprotocol/pkc-js 0.0.74 → 0.0.76
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 +34 -1
- 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 +10 -0
- package/dist/browser/errors.js +10 -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/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 +41 -4
- 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/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/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/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/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/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/schema.d.ts +20 -0
- package/dist/browser/schema.js +11 -1
- package/dist/browser/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/bundled/bundle-manifest.json +204 -92
- package/dist/bundled/chunks/helia-for-pkc-cKp6JSwA.js +6915 -0
- package/dist/bundled/chunks/{local-community-Br1ipu1Z.js → local-community-B3Fhrtiy.js} +205 -38
- package/dist/bundled/chunks/{local-community-CIVs_iuS.js → local-community-DerKPzJm.js} +1 -1
- package/dist/bundled/chunks/{node-Cn7VaPDJ.js → node-DffqRPit.js} +43 -9
- package/dist/bundled/chunks/{rpc-local-community-DtdeJBOq.js → rpc-local-community-BdNiruAf.js} +96 -38
- package/dist/bundled/chunks/{schema-B1Ot-kux.js → schema-BvBJX6m7.js} +29 -5
- package/dist/bundled/chunks/{src-o_MYSn-E.js → src-B2CwDTfy.js} +2 -142
- package/dist/bundled/chunks/{src-4u0f92eE.js → src-BEjAH2gY.js} +3 -128
- package/dist/bundled/chunks/src-Cpx2Sts8.js +127 -0
- package/dist/bundled/chunks/src-DKntVmyX.js +142 -0
- package/dist/bundled/chunks/{util-B6v5HAdy.js → util-BRxHPb9G.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 +10 -0
- package/dist/node/errors.js +10 -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/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 +41 -4
- 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/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/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/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/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/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/schema.d.ts +20 -0
- package/dist/node/schema.js +11 -1
- package/dist/node/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/package.json +8 -5
- package/dist/bundled/chunks/helia-for-pkc-B-75U9z9.js +0 -495
|
@@ -1,16 +1,17 @@
|
|
|
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, Rt as pTimeout, 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-BvBJX6m7.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-BdNiruAf.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
|
|
9
|
+
import path from "path";
|
|
10
10
|
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;
|
|
@@ -1008,7 +1141,7 @@ async function checkWireFormatAndCommunityAuthor(community, publication, authorC
|
|
|
1008
1141
|
if ("subplebbitAddress" in publication) return messages.ERR_PUBLICATION_USES_DEPRECATED_SUBPLEBBIT_ADDRESS;
|
|
1009
1142
|
if ("communityAddress" in publication) return messages.ERR_PUBLICATION_USES_DEPRECATED_COMMUNITY_ADDRESS;
|
|
1010
1143
|
const pubCommunityPublicKey = getCommunityPublicKeyFromWire(publication);
|
|
1011
|
-
if (!pubCommunityPublicKey || pubCommunityPublicKey !== community
|
|
1144
|
+
if (!pubCommunityPublicKey || pubCommunityPublicKey !== communityIdentityPublicKey(community)) return messages.ERR_PUBLICATION_INVALID_COMMUNITY_PUBLIC_KEY;
|
|
1012
1145
|
const pubCommunityName = getCommunityNameFromWire(publication);
|
|
1013
1146
|
if (pubCommunityName && pubCommunityName !== community.address) return messages.ERR_PUBLICATION_INVALID_COMMUNITY_NAME;
|
|
1014
1147
|
if (publication.timestamp <= timestamp() - 300 || publication.timestamp >= timestamp() + 300) return messages.ERR_PUBLICATION_TIMESTAMP_IS_NOT_IN_PROPER_RANGE;
|
|
@@ -1324,7 +1457,7 @@ async function storeCommentEdit(community, commentEditRaw, challengeRequestId) {
|
|
|
1324
1457
|
const log = logger_default("pkc-js:local-community:storeCommentEdit");
|
|
1325
1458
|
const strippedOutEditPublication = CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema.strip().parse(commentEditRaw);
|
|
1326
1459
|
strippedOutEditPublication.author = cleanWireAuthor(strippedOutEditPublication.author);
|
|
1327
|
-
if (!strippedOutEditPublication.communityPublicKey) strippedOutEditPublication.communityPublicKey = community
|
|
1460
|
+
if (!strippedOutEditPublication.communityPublicKey) strippedOutEditPublication.communityPublicKey = communityIdentityPublicKey(community);
|
|
1328
1461
|
if (!strippedOutEditPublication.communityName && isStringDomain(community.address)) strippedOutEditPublication.communityName = community.address;
|
|
1329
1462
|
const commentToBeEdited = community._dbHandler.queryComment(commentEditRaw.commentCid);
|
|
1330
1463
|
if (!commentToBeEdited) throw Error("The comment to edit doesn't exist");
|
|
@@ -1358,7 +1491,7 @@ async function storeCommentModeration(community, commentModRaw, challengeRequest
|
|
|
1358
1491
|
const log = logger_default("pkc-js:local-community:storeCommentModeration");
|
|
1359
1492
|
const strippedOutModPublication = CommentModerationPubsubMessagePublicationSchema.strip().parse(commentModRaw);
|
|
1360
1493
|
strippedOutModPublication.author = cleanWireAuthor(strippedOutModPublication.author);
|
|
1361
|
-
if (!strippedOutModPublication.communityPublicKey) strippedOutModPublication.communityPublicKey = community
|
|
1494
|
+
if (!strippedOutModPublication.communityPublicKey) strippedOutModPublication.communityPublicKey = communityIdentityPublicKey(community);
|
|
1362
1495
|
if (!strippedOutModPublication.communityName && isStringDomain(community.address)) strippedOutModPublication.communityName = community.address;
|
|
1363
1496
|
const commentToBeEdited = community._dbHandler.queryComment(commentModRaw.commentCid);
|
|
1364
1497
|
if (!commentToBeEdited) throw Error("The comment to edit doesn't exist");
|
|
@@ -1456,7 +1589,7 @@ async function storeComment(community, opts) {
|
|
|
1456
1589
|
...pseudonymityMode ? { pseudonymityMode } : {},
|
|
1457
1590
|
...challengeAggregate?.aggregatedComment ?? {}
|
|
1458
1591
|
};
|
|
1459
|
-
commentIpfs.communityPublicKey = community
|
|
1592
|
+
commentIpfs.communityPublicKey = communityIdentityPublicKey(community);
|
|
1460
1593
|
if (isStringDomain(community.address)) commentIpfs.communityName = community.address;
|
|
1461
1594
|
delete commentIpfs.communityAddress;
|
|
1462
1595
|
commentIpfs.author = cleanWireAuthor(commentIpfs.author);
|
|
@@ -3283,9 +3416,9 @@ var DbHandler = class {
|
|
|
3283
3416
|
if (needToMigrate) {
|
|
3284
3417
|
if (dbExistsAlready && currentDbVersion > 0) {
|
|
3285
3418
|
this.destoryConnection();
|
|
3286
|
-
backupDbPath = path
|
|
3287
|
-
log(`Copying db ${path
|
|
3288
|
-
if (!fs.existsSync(path
|
|
3419
|
+
backupDbPath = path.join(path.dirname(dbPath), ".backup_before_migration", `${path.basename(dbPath)}.${currentDbVersion}.${timestamp()}`);
|
|
3420
|
+
log(`Copying db ${path.basename(dbPath)} to ${backupDbPath} before migration`);
|
|
3421
|
+
if (!fs.existsSync(path.dirname(backupDbPath))) await fs.promises.mkdir(path.dirname(backupDbPath), { recursive: true });
|
|
3289
3422
|
const sourceDb = new Database(dbPath, { fileMustExist: true });
|
|
3290
3423
|
await sourceDb.backup(backupDbPath);
|
|
3291
3424
|
sourceDb.close();
|
|
@@ -5096,10 +5229,10 @@ var DbHandler = class {
|
|
|
5096
5229
|
if (this._db || this._keyv) await this.destoryConnection();
|
|
5097
5230
|
this._transactionDepth = 0;
|
|
5098
5231
|
const dataPath = this._community._pkc.dataPath;
|
|
5099
|
-
const oldPathString = path
|
|
5100
|
-
const newPathString = path
|
|
5101
|
-
await fs.promises.mkdir(path
|
|
5102
|
-
await fs.promises.mkdir(path
|
|
5232
|
+
const oldPathString = path.join(dataPath, "communities", oldDbName);
|
|
5233
|
+
const newPathString = path.join(dataPath, "communities", newDbName);
|
|
5234
|
+
await fs.promises.mkdir(path.dirname(oldPathString), { recursive: true });
|
|
5235
|
+
await fs.promises.mkdir(path.dirname(newPathString), { recursive: true });
|
|
5103
5236
|
try {
|
|
5104
5237
|
if (!fs.existsSync(oldPathString)) log(`Old DB file ${oldPathString} does not exist. Cannot backup/rename.`);
|
|
5105
5238
|
else {
|
|
@@ -5121,8 +5254,8 @@ var DbHandler = class {
|
|
|
5121
5254
|
}
|
|
5122
5255
|
async lockCommunityStart(communityAddress = this._community.address) {
|
|
5123
5256
|
const log = logger_default("pkc-js:local-community:db-handler:lock:start");
|
|
5124
|
-
const lockfilePath = path
|
|
5125
|
-
const communityDbPath = path
|
|
5257
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
5258
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
5126
5259
|
try {
|
|
5127
5260
|
await import_src.default.lock(communityDbPath, {
|
|
5128
5261
|
lockfilePath,
|
|
@@ -5143,8 +5276,8 @@ var DbHandler = class {
|
|
|
5143
5276
|
async unlockCommunityStart(communityAddress = this._community.address) {
|
|
5144
5277
|
const log = logger_default("pkc-js:local-community:db-handler:unlock:start");
|
|
5145
5278
|
log.trace(`Attempting to unlock the start of community (${communityAddress})`);
|
|
5146
|
-
const lockfilePath = path
|
|
5147
|
-
const communityDbPath = path
|
|
5279
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
5280
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
5148
5281
|
if (!fs.existsSync(lockfilePath) || !fs.existsSync(communityDbPath)) return;
|
|
5149
5282
|
try {
|
|
5150
5283
|
await import_src.default.unlock(communityDbPath, { lockfilePath });
|
|
@@ -5155,8 +5288,8 @@ var DbHandler = class {
|
|
|
5155
5288
|
}
|
|
5156
5289
|
}
|
|
5157
5290
|
async isCommunityStartLocked(communityAddress = this._community.address) {
|
|
5158
|
-
const lockfilePath = path
|
|
5159
|
-
const communityDbPath = path
|
|
5291
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
|
|
5292
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", communityAddress);
|
|
5160
5293
|
return await import_src.default.check(communityDbPath, {
|
|
5161
5294
|
lockfilePath,
|
|
5162
5295
|
realpath: false,
|
|
@@ -5165,8 +5298,8 @@ var DbHandler = class {
|
|
|
5165
5298
|
}
|
|
5166
5299
|
async lockCommunityState() {
|
|
5167
5300
|
const log = logger_default("pkc-js:local-community:db-handler:lock:lockCommunityState");
|
|
5168
|
-
const lockfilePath = path
|
|
5169
|
-
const communityDbPath = path
|
|
5301
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
|
|
5302
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
5170
5303
|
try {
|
|
5171
5304
|
await import_src.default.lock(communityDbPath, {
|
|
5172
5305
|
lockfilePath,
|
|
@@ -5183,8 +5316,8 @@ var DbHandler = class {
|
|
|
5183
5316
|
}
|
|
5184
5317
|
async unlockCommunityState() {
|
|
5185
5318
|
const log = logger_default("pkc-js:local-community:db-handler:lock:unlockCommunityState");
|
|
5186
|
-
const lockfilePath = path
|
|
5187
|
-
const communityDbPath = path
|
|
5319
|
+
const lockfilePath = path.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
|
|
5320
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
5188
5321
|
if (!fs.existsSync(lockfilePath)) return;
|
|
5189
5322
|
try {
|
|
5190
5323
|
await import_src.default.unlock(communityDbPath, { lockfilePath });
|
|
@@ -5194,7 +5327,7 @@ var DbHandler = class {
|
|
|
5194
5327
|
}
|
|
5195
5328
|
}
|
|
5196
5329
|
communityDbExists() {
|
|
5197
|
-
const communityDbPath = path
|
|
5330
|
+
const communityDbPath = path.join(this._community._pkc.dataPath, "communities", this._community.address);
|
|
5198
5331
|
return fs.existsSync(communityDbPath);
|
|
5199
5332
|
}
|
|
5200
5333
|
markCommentsAsPublishedToPostUpdates(commentCids) {
|
|
@@ -5798,6 +5931,7 @@ async function updateInstanceStateWithDbState(community) {
|
|
|
5798
5931
|
}
|
|
5799
5932
|
await community.initInternalCommunityAfterFirstUpdateNoMerge(currentDbState);
|
|
5800
5933
|
} else await community.initInternalCommunityBeforeFirstUpdateNoMerge(currentDbState);
|
|
5934
|
+
community.anchorRecordSequence = getHighestAcceptedAnchorSequence(community)?.toString();
|
|
5801
5935
|
}
|
|
5802
5936
|
async function updateInstancePropsWithStartedCommunityOrDb(community) {
|
|
5803
5937
|
const log = logger_default("pkc-js:local-community:_updateInstancePropsWithStartedCommunityOrDb");
|
|
@@ -5814,6 +5948,7 @@ async function updateInstancePropsWithStartedCommunityOrDb(community) {
|
|
|
5814
5948
|
else await community.initInternalCommunityBeforeFirstUpdateNoMerge(startedCommunity.toJSONInternalBeforeFirstUpdate());
|
|
5815
5949
|
community.started = true;
|
|
5816
5950
|
community._exports = startedCommunity.exports;
|
|
5951
|
+
community.anchorRecordSequence = startedCommunity.anchorRecordSequence;
|
|
5817
5952
|
} else {
|
|
5818
5953
|
await community.initDbHandlerIfNeeded();
|
|
5819
5954
|
try {
|
|
@@ -5899,6 +6034,8 @@ async function createNewLocalCommunityDb(community) {
|
|
|
5899
6034
|
}
|
|
5900
6035
|
async function initNewLocalCommunityPropsNoMerge(community, newProps) {
|
|
5901
6036
|
await initSignerProps(community, newProps.signer);
|
|
6037
|
+
community.anchor = newProps.anchor;
|
|
6038
|
+
if (newProps.anchor) community.ipnsHops = [newProps.anchor.publicKey, community.signer.address];
|
|
5902
6039
|
community.title = newProps.title;
|
|
5903
6040
|
community.description = newProps.description;
|
|
5904
6041
|
community.setAddress(newProps.address);
|
|
@@ -5936,6 +6073,7 @@ async function initInternalCommunityAfterFirstUpdateNoMerge(community, newProps)
|
|
|
5936
6073
|
"shortAddress",
|
|
5937
6074
|
"type"
|
|
5938
6075
|
]),
|
|
6076
|
+
anchor: newProps.anchor,
|
|
5939
6077
|
settings: newProps.settings,
|
|
5940
6078
|
_usingDefaultChallenge: newProps._usingDefaultChallenge,
|
|
5941
6079
|
address: newProps.address,
|
|
@@ -5972,9 +6110,6 @@ async function initInternalCommunityBeforeFirstUpdateNoMerge(community, newProps
|
|
|
5972
6110
|
await initSignerProps(community, newProps.signer);
|
|
5973
6111
|
community._internalStateUpdateId = newProps._internalStateUpdateId;
|
|
5974
6112
|
community._updateIpnsPubsubPropsIfNeeded(newProps);
|
|
5975
|
-
community.ipnsName = newProps.signer.address;
|
|
5976
|
-
community.ipnsPubsubTopic = ipnsNameToIpnsOverPubsubTopic(community.ipnsName);
|
|
5977
|
-
community.ipnsPubsubTopicRoutingCid = pubsubTopicToDhtKey(community.ipnsPubsubTopic);
|
|
5978
6113
|
if (processStartedCommunities.has(community)) syncCommunityRegistryEntry(processStartedCommunities, community);
|
|
5979
6114
|
community.raw.localCommunity = community.toJSONInternalRpcBeforeFirstUpdate();
|
|
5980
6115
|
}
|
|
@@ -6411,6 +6546,7 @@ async function publishLoop(community, syncIntervalMs) {
|
|
|
6411
6546
|
while (!shouldStopPublishLoop()) try {
|
|
6412
6547
|
await syncIpnsWithDb(community);
|
|
6413
6548
|
await reprovideOnAddressChangeIfDue(community).catch((e) => log.error("Failed to re-provide connection CIDs on address change", e));
|
|
6549
|
+
await reprovideAnchorRecordIfDue(community).catch((e) => log.error("Failed to re-provide the anchor record", e));
|
|
6414
6550
|
} catch (e) {
|
|
6415
6551
|
community.emit("error", e);
|
|
6416
6552
|
} finally {
|
|
@@ -6458,6 +6594,11 @@ async function start(community) {
|
|
|
6458
6594
|
})) throw new PKCError("ERR_COMMUNITY_ALREADY_STARTED", { address: community.address });
|
|
6459
6595
|
try {
|
|
6460
6596
|
await initBeforeStarting(community);
|
|
6597
|
+
if (community.anchor && !getPersistedAnchorRecordBytes(community)) throw new PKCError("ERR_DELEGATED_COMMUNITY_HAS_NO_ANCHOR_RECORD", {
|
|
6598
|
+
address: community.address,
|
|
6599
|
+
anchorPublicKey: community.anchor.publicKey,
|
|
6600
|
+
minterAddress: community.signer.address
|
|
6601
|
+
});
|
|
6461
6602
|
community._setState("started");
|
|
6462
6603
|
await community._updateStartedValue();
|
|
6463
6604
|
await community._dbHandler.lockCommunityStart();
|
|
@@ -6471,6 +6612,7 @@ async function start(community) {
|
|
|
6471
6612
|
await setChallengesToDefaultIfNotDefined(community, log);
|
|
6472
6613
|
await importCommunitySignerIntoIpfsIfNeeded(community);
|
|
6473
6614
|
await providePubsubTopicRoutingCidsIfNeeded(community, true);
|
|
6615
|
+
await reprovideAnchorRecordIfNeeded(community).catch((e) => log.error("Failed to re-provide the anchor record on start", e));
|
|
6474
6616
|
community._communityUpdateTrigger = true;
|
|
6475
6617
|
community._setStartedStateWithEmission("publishing-ipns");
|
|
6476
6618
|
await community._repinCommentsIPFSIfNeeded();
|
|
@@ -6506,6 +6648,7 @@ async function initMirroringStartedOrUpdatingCommunity(community, startedCommuni
|
|
|
6506
6648
|
if (startedCommunity.updateCid) await community.initInternalCommunityAfterFirstUpdateNoMerge(startedCommunity.toJSONInternalAfterFirstUpdate());
|
|
6507
6649
|
else await community.initInternalCommunityBeforeFirstUpdateNoMerge(startedCommunity.toJSONInternalBeforeFirstUpdate());
|
|
6508
6650
|
community.started = startedCommunity.started;
|
|
6651
|
+
community.anchorRecordSequence = startedCommunity.anchorRecordSequence;
|
|
6509
6652
|
community.emit("update", community);
|
|
6510
6653
|
};
|
|
6511
6654
|
const stateChangeListener = async (newState) => {
|
|
@@ -6538,6 +6681,7 @@ async function initMirroringStartedOrUpdatingCommunity(community, startedCommuni
|
|
|
6538
6681
|
}
|
|
6539
6682
|
if (startedCommunity.updateCid) await community.initInternalCommunityAfterFirstUpdateNoMerge(startedCommunity.toJSONInternalAfterFirstUpdate());
|
|
6540
6683
|
else await community.initInternalCommunityBeforeFirstUpdateNoMerge(startedCommunity.toJSONInternalBeforeFirstUpdate());
|
|
6684
|
+
community.anchorRecordSequence = startedCommunity.anchorRecordSequence;
|
|
6541
6685
|
community.emit("update", community);
|
|
6542
6686
|
}
|
|
6543
6687
|
async function cleanUpMirroredStartedOrUpdatingCommunity(community) {
|
|
@@ -6916,11 +7060,11 @@ async function edit(community, newCommunityOptions) {
|
|
|
6916
7060
|
const EXPORTS_KEY = STORAGE_KEYS[STORAGE_KEYS.EXPORTS];
|
|
6917
7061
|
function defaultExportPathFor(community, exportId) {
|
|
6918
7062
|
if (typeof community._pkc.dataPath !== "string") throw new PKCError("ERR_DATA_PATH_IS_NOT_DEFINED", { communityAddress: community.address });
|
|
6919
|
-
return
|
|
7063
|
+
return Path.join(community._pkc.dataPath, "exports", `${exportId}.sqlite`);
|
|
6920
7064
|
}
|
|
6921
7065
|
function sourceDbPathFor(community) {
|
|
6922
7066
|
if (typeof community._pkc.dataPath !== "string") throw new PKCError("ERR_DATA_PATH_IS_NOT_DEFINED", { communityAddress: community.address });
|
|
6923
|
-
return
|
|
7067
|
+
return Path.join(community._pkc.dataPath, "communities", community.address);
|
|
6924
7068
|
}
|
|
6925
7069
|
async function persistExports(community) {
|
|
6926
7070
|
if (!community._dbHandler) return;
|
|
@@ -6996,9 +7140,9 @@ async function runExportTask(community, exportId, opts) {
|
|
|
6996
7140
|
async function exportCommunityEmbedded(community, options = {}) {
|
|
6997
7141
|
if (options.signal?.aborted) throw options.signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
6998
7142
|
const exportId = v4();
|
|
6999
|
-
const destPath = options.exportPath ?
|
|
7143
|
+
const destPath = options.exportPath ? Path.resolve(options.exportPath) : defaultExportPathFor(community, exportId);
|
|
7000
7144
|
const includePrivateKey = options.includePrivateKey === true;
|
|
7001
|
-
if (
|
|
7145
|
+
if (Path.resolve(destPath) === Path.resolve(sourceDbPathFor(community))) throw new PKCError("ERR_EXPORT_PATH_TARGETS_LIVE_DB", {
|
|
7002
7146
|
communityAddress: community.address,
|
|
7003
7147
|
exportPath: destPath
|
|
7004
7148
|
});
|
|
@@ -7127,6 +7271,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7127
7271
|
this._subscribedChallengePubsubTopic = void 0;
|
|
7128
7272
|
this._lastProvidedBrowserDialableSelfAddrs = void 0;
|
|
7129
7273
|
this._lastAddressReprovideCheckAt = void 0;
|
|
7274
|
+
this._lastAnchorRecordReprovideAt = void 0;
|
|
7130
7275
|
this._mirroredStartedOrUpdatingCommunity = void 0;
|
|
7131
7276
|
this._pendingEditProps = [];
|
|
7132
7277
|
this._blocksToRm = [];
|
|
@@ -7151,7 +7296,11 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7151
7296
|
const rpcJson = this.toJSONInternalRpcAfterFirstUpdate();
|
|
7152
7297
|
return {
|
|
7153
7298
|
...rpcJson.community,
|
|
7154
|
-
...n$3(rpcJson.localCommunity, [
|
|
7299
|
+
...n$3(rpcJson.localCommunity, [
|
|
7300
|
+
"started",
|
|
7301
|
+
"startedState",
|
|
7302
|
+
"anchorRecordSequence"
|
|
7303
|
+
]),
|
|
7155
7304
|
updateCid: rpcJson.runtimeFields.updateCid,
|
|
7156
7305
|
signer: t$9(this.signer, [
|
|
7157
7306
|
"privateKey",
|
|
@@ -7169,7 +7318,11 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7169
7318
|
}
|
|
7170
7319
|
toJSONInternalBeforeFirstUpdate() {
|
|
7171
7320
|
return {
|
|
7172
|
-
...n$3(this.toJSONInternalRpcBeforeFirstUpdate().localCommunity, [
|
|
7321
|
+
...n$3(this.toJSONInternalRpcBeforeFirstUpdate().localCommunity, [
|
|
7322
|
+
"started",
|
|
7323
|
+
"startedState",
|
|
7324
|
+
"anchorRecordSequence"
|
|
7325
|
+
]),
|
|
7173
7326
|
signer: t$9(this.signer, [
|
|
7174
7327
|
"privateKey",
|
|
7175
7328
|
"type",
|
|
@@ -7207,6 +7360,12 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7207
7360
|
])
|
|
7208
7361
|
} };
|
|
7209
7362
|
}
|
|
7363
|
+
_updateIpnsPubsubPropsIfNeeded(_newProps) {
|
|
7364
|
+
if (!this.signer?.address) return;
|
|
7365
|
+
this.ipnsName = this.signer.address;
|
|
7366
|
+
this.ipnsPubsubTopic = ipnsNameToIpnsOverPubsubTopic(this.ipnsName);
|
|
7367
|
+
this.ipnsPubsubTopicRoutingCid = pubsubTopicToDhtKey(this.ipnsPubsubTopic);
|
|
7368
|
+
}
|
|
7210
7369
|
async _updateStartedValue() {
|
|
7211
7370
|
this.started = await this._dbHandler.isCommunityStartLocked(this.address);
|
|
7212
7371
|
}
|
|
@@ -7247,7 +7406,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7247
7406
|
}
|
|
7248
7407
|
const verificationOpts = {
|
|
7249
7408
|
community: recordToPublishRaw,
|
|
7250
|
-
|
|
7409
|
+
communityIpnsHops: this.ipnsHops ?? [this.signer.address],
|
|
7251
7410
|
resolveAuthorNames: false,
|
|
7252
7411
|
clientsManager: this._clientsManager,
|
|
7253
7412
|
validatePages: true,
|
|
@@ -7275,7 +7434,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7275
7434
|
throw e;
|
|
7276
7435
|
}
|
|
7277
7436
|
if (this.shouldResolveDomainForVerification()) try {
|
|
7278
|
-
log(`Resolving domain ${this.address} to make sure it's the same as
|
|
7437
|
+
log(`Resolving domain ${this.address} to make sure it's the same as ${communityIdentityPublicKey(this)}`);
|
|
7279
7438
|
await this._assertDomainResolvesCorrectly(this.address);
|
|
7280
7439
|
} catch (e) {
|
|
7281
7440
|
log.error(e);
|
|
@@ -7311,15 +7470,23 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
7311
7470
|
communityName: newAddressAsDomain,
|
|
7312
7471
|
cache: { maxAge: 600 }
|
|
7313
7472
|
});
|
|
7314
|
-
|
|
7473
|
+
const identityPublicKey = communityIdentityPublicKey(this);
|
|
7474
|
+
if (resolvedIpnsFromNewDomain !== identityPublicKey) throw new PKCError("ERR_DOMAIN_COMMUNITY_ADDRESS_TXT_RECORD_POINT_TO_DIFFERENT_ADDRESS", {
|
|
7315
7475
|
currentCommunityAddress: this.address,
|
|
7316
7476
|
newAddressAsDomain,
|
|
7317
7477
|
resolvedIpnsFromNewDomain,
|
|
7478
|
+
identityPublicKey,
|
|
7318
7479
|
signerAddress: this.signer.address,
|
|
7319
7480
|
started: this.started
|
|
7320
7481
|
});
|
|
7321
7482
|
}
|
|
7322
7483
|
}
|
|
7484
|
+
async prepareAnchorPublish() {
|
|
7485
|
+
return prepareAnchorPublish(this);
|
|
7486
|
+
}
|
|
7487
|
+
async publishAnchorRecord(recordBytes) {
|
|
7488
|
+
return publishAnchorRecord(this, recordBytes);
|
|
7489
|
+
}
|
|
7323
7490
|
async start() {
|
|
7324
7491
|
return start(this);
|
|
7325
7492
|
}
|
|
@@ -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-B3Fhrtiy.js";
|
|
2
2
|
export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };
|