@pkcprotocol/pkc-js 0.0.157 → 0.0.159
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 +58 -3
- package/dist/browser/clients/base-client-manager.js +24 -11
- package/dist/browser/clients/base-client-manager.js.map +1 -1
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js +17 -9
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -1
- package/dist/browser/clients/rpc-client/schema.d.ts +2 -0
- package/dist/browser/community/schema.d.ts +26 -0
- package/dist/browser/detached-guard.d.ts +5 -0
- package/dist/browser/detached-guard.js +50 -0
- package/dist/browser/detached-guard.js.map +1 -0
- package/dist/browser/errors.d.ts +2 -0
- package/dist/browser/errors.js +2 -0
- package/dist/browser/errors.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/helia/helia-for-pkc.js +6 -5
- package/dist/browser/helia/helia-for-pkc.js.map +1 -1
- package/dist/browser/index-with-compile-cache.d.ts +4 -0
- package/dist/browser/index.d.ts +8 -0
- package/dist/browser/pages/schema.d.ts +6 -0
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/comment/comment.d.ts +2 -0
- package/dist/browser/publications/comment/comment.js +2 -0
- package/dist/browser/publications/comment/comment.js.map +1 -1
- package/dist/browser/publications/comment/schema.d.ts +6 -2
- package/dist/browser/publications/comment/schema.js +13 -1
- package/dist/browser/publications/comment/schema.js.map +1 -1
- package/dist/browser/publications/comment-moderation/schema.js +2 -2
- package/dist/browser/publications/comment-moderation/schema.js.map +1 -1
- package/dist/browser/publications/publication.js +26 -32
- package/dist/browser/publications/publication.js.map +1 -1
- package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +4 -0
- package/dist/browser/rpc/src/schema.d.ts +24 -0
- package/dist/browser/runtime/node/community/db-handler.d.ts +1 -0
- package/dist/browser/runtime/node/community/db-handler.js +31 -7
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/cleanup.js +6 -0
- package/dist/browser/runtime/node/community/local-community/cleanup.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/comment-updates.js +36 -0
- package/dist/browser/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/db-fault.d.ts +3 -0
- package/dist/browser/runtime/node/community/local-community/db-fault.js +13 -0
- package/dist/browser/runtime/node/community/local-community/db-fault.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +36 -2
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +36 -2
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.d.ts +21 -0
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.js +141 -4
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community.d.ts +7 -0
- package/dist/browser/runtime/node/community/local-community.js +18 -0
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/test/helpers/hanging-runner.js +7 -3
- package/dist/browser/runtime/node/test/helpers/hanging-runner.js.map +1 -1
- package/dist/browser/runtime/node/test/helpers/run-hanging-node.js +6 -1
- package/dist/browser/runtime/node/test/helpers/run-hanging-node.js.map +1 -1
- package/dist/browser/schema/schema-util.d.ts +10 -0
- package/dist/browser/schema/schema.d.ts +9 -0
- package/dist/browser/schema/schema.js +9 -1
- package/dist/browser/schema/schema.js.map +1 -1
- package/dist/browser/schema.d.ts +32 -0
- package/dist/browser/signer/pseudonymity-author-tag.d.ts +8 -0
- package/dist/browser/signer/pseudonymity-author-tag.js +39 -0
- package/dist/browser/signer/pseudonymity-author-tag.js.map +1 -0
- package/dist/browser/signer/signatures.js +16 -0
- package/dist/browser/signer/signatures.js.map +1 -1
- package/dist/browser/test/test-util.d.ts +10 -0
- package/dist/browser/version.js +1 -1
- package/dist/bundled/bundle-manifest.json +58 -53
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-BT2UmDem.js → helia-for-pkc-CP5A7i4M.js} +5 -4
- package/dist/bundled/chunks/{local-community-oqjqTa9T.js → local-community-0xsjgulY.js} +373 -26
- package/dist/bundled/chunks/{local-community-BexngGU7.js → local-community-CUDfHfH_.js} +1 -1
- package/dist/bundled/chunks/{node-CvXtQ-4A.js → node-Bv7hIiW_.js} +40 -38
- package/dist/bundled/chunks/{page-sort-scoring-VN_GGInQ.js → page-sort-scoring-I02fuGkI.js} +1 -1
- package/dist/bundled/chunks/{rpc-local-community-BjIHRbYy.js → rpc-local-community-Bo4Z7ilA.js} +57 -13
- package/dist/bundled/chunks/{util-DDsWXOtP.js → util-BZuCmqxu.js} +12 -9
- package/dist/bundled/chunks/{util-Bu3ItQsN.js → util-xhgmI11L.js} +1 -1
- package/dist/bundled/chunks/{validate-package-factories-CmJt781W.js → validate-package-factories-BsSEIr__.js} +2 -2
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/page-sorts.js +1 -1
- package/dist/bundled/rpc/src/index.js +4 -4
- package/dist/node/clients/base-client-manager.js +24 -11
- package/dist/node/clients/base-client-manager.js.map +1 -1
- package/dist/node/clients/rpc-client/pkc-rpc-client.js +17 -9
- package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -1
- package/dist/node/clients/rpc-client/schema.d.ts +2 -0
- package/dist/node/community/schema.d.ts +26 -0
- package/dist/node/detached-guard.d.ts +5 -0
- package/dist/node/detached-guard.js +50 -0
- package/dist/node/detached-guard.js.map +1 -0
- package/dist/node/errors.d.ts +2 -0
- package/dist/node/errors.js +2 -0
- package/dist/node/errors.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/helia/helia-for-pkc.js +6 -5
- package/dist/node/helia/helia-for-pkc.js.map +1 -1
- package/dist/node/index-with-compile-cache.d.ts +4 -0
- package/dist/node/index.d.ts +8 -0
- package/dist/node/pages/schema.d.ts +6 -0
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/comment/comment.d.ts +2 -0
- package/dist/node/publications/comment/comment.js +2 -0
- package/dist/node/publications/comment/comment.js.map +1 -1
- package/dist/node/publications/comment/schema.d.ts +6 -2
- package/dist/node/publications/comment/schema.js +13 -1
- package/dist/node/publications/comment/schema.js.map +1 -1
- package/dist/node/publications/comment-moderation/schema.js +2 -2
- package/dist/node/publications/comment-moderation/schema.js.map +1 -1
- package/dist/node/publications/publication.js +26 -32
- package/dist/node/publications/publication.js.map +1 -1
- package/dist/node/rpc/src/lib/pkc-js/index.d.ts +4 -0
- package/dist/node/rpc/src/schema.d.ts +24 -0
- package/dist/node/runtime/node/community/db-handler.d.ts +1 -0
- package/dist/node/runtime/node/community/db-handler.js +31 -7
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/cleanup.js +6 -0
- package/dist/node/runtime/node/community/local-community/cleanup.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/comment-updates.js +36 -0
- package/dist/node/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/db-fault.d.ts +3 -0
- package/dist/node/runtime/node/community/local-community/db-fault.js +13 -0
- package/dist/node/runtime/node/community/local-community/db-fault.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js +36 -2
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.js +36 -2
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.d.ts +21 -0
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.js +141 -4
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.js.map +1 -1
- package/dist/node/runtime/node/community/local-community.d.ts +7 -0
- package/dist/node/runtime/node/community/local-community.js +18 -0
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/test/helpers/hanging-runner.js +7 -3
- package/dist/node/runtime/node/test/helpers/hanging-runner.js.map +1 -1
- package/dist/node/runtime/node/test/helpers/run-hanging-node.js +6 -1
- package/dist/node/runtime/node/test/helpers/run-hanging-node.js.map +1 -1
- package/dist/node/schema/schema-util.d.ts +10 -0
- package/dist/node/schema/schema.d.ts +9 -0
- package/dist/node/schema/schema.js +9 -1
- package/dist/node/schema/schema.js.map +1 -1
- package/dist/node/schema.d.ts +32 -0
- package/dist/node/signer/pseudonymity-author-tag.d.ts +8 -0
- package/dist/node/signer/pseudonymity-author-tag.js +39 -0
- package/dist/node/signer/pseudonymity-author-tag.js.map +1 -0
- package/dist/node/signer/signatures.js +16 -0
- package/dist/node/signer/signatures.js.map +1 -1
- package/dist/node/test/test-util.d.ts +10 -0
- package/dist/node/version.js +1 -1
- package/package.json +3 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as __toESM } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $n as CommentEditsTableRowSchema, Ar as t$4, At as ChallengeAnswerMessageSchema, B as pubsubTopicToDhtKey, Br as messages, Bt as DecryptedChallengeRequestSchema, C as hideClassPrivateProps, Cr as e$1, Ct as trackUpdatingCommunity, Dr as t$3, Dt as require_sha256, En as VotePubsubReservedFields, Er as r$1, Et as untrackUpdatingCommunity, F as isLinkOfVideo, G as removeBlocksFromKuboNode, Hn as CommentsTableRowSchema, I as isLinkValid, It as ChallengeVerificationMessageSchema, J as removeNullUndefinedValues, Jt as version_default, K as removeMfsFilesSafely, M as isLinkOfAudio, Mn as CommentPubsubMessageReservedFields, Mt as ChallengeMessageSchema, N as isLinkOfImage, Nr as require_retry, On as VoteTablesRowSchema, P as isLinkOfMedia, Pt as ChallengeRequestMessageSchema, Q as retryKuboBlockPutPinAndProvidePubsubTopic, Sr as t$6, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Vn as CommentUpdateTableRowSchema, Vr as logger_default, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xt as CommunityEditPublicationPubsubReservedFields, Yn as CommentEditPubsubMessagePublicationSchema, Zn as CommentEditReservedFields, _ as genToArray, b as getIpnsRecordInLocalKuboNode, br as n$2, bt as syncCommunityRegistryEntry, c as contentContainsMarkdownImages, ct as withSortedKeys, dt as findStartedCommunity, et as retryKuboIpfsAddAndProvide, f as derivePublicationFromChallengeRequest, g as findMalformedUnicodeString, gr as isStringDomain, i as calculateStringSizeSameAsIpfsAddCidV0, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, it as statMfsPathSafely, j as isLinkOfAnimatedImage, jn as CommentIpfsSchema, jr as t$2, kt as pTimeout, l as contentContainsMarkdownVideos, lt as withSortedKeysDeep, mn as CommunitySignedPropertyNames, nn as CommentModerationReservedFields, o as calculateUnixFsDagSizeCidV0, ot as timestamp, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, r as calculateIpfsCidV0, ri as ZodError, rt as sleepUntilTimeoutOrAbort, s as contentContainsMarkdownAudio, tn as CommentModerationPubsubMessagePublicationSchema, ut as findCommunityInRegistry, v as getEquivalentCommunityAddresses, vr as n$3, wr as e, wt as untrackStartedCommunity, xr as t$5, xt as trackStartedCommunity, y as getErrorCodeFromMessage, yr as t$7, zn as CommentUpdateSchema, zr as PKCError, zt as DecryptedChallengeRequestPublicationSchema } from "./util-
|
|
3
|
-
import { $ as coerceSchemaRowJson, $n as
|
|
4
|
-
import { a as scorePageCommentsWithFile, i as partitionPageCommentsForSort, n as filterRepliesForPageSort, o as stripRepliesFromPageComment, r as orderPageCommentsByScore, t as createDescendantsLookup } from "./page-sort-scoring-
|
|
2
|
+
import { $n as CommentEditsTableRowSchema, Ar as t$4, At as ChallengeAnswerMessageSchema, B as pubsubTopicToDhtKey, Br as messages, Bt as DecryptedChallengeRequestSchema, C as hideClassPrivateProps, Cr as e$1, Ct as trackUpdatingCommunity, Dr as t$3, Dt as require_sha256, En as VotePubsubReservedFields, Er as r$1, Et as untrackUpdatingCommunity, F as isLinkOfVideo, G as removeBlocksFromKuboNode, Hn as CommentsTableRowSchema, I as isLinkValid, It as ChallengeVerificationMessageSchema, J as removeNullUndefinedValues, Jt as version_default, K as removeMfsFilesSafely, M as isLinkOfAudio, Mn as CommentPubsubMessageReservedFields, Mt as ChallengeMessageSchema, N as isLinkOfImage, Nr as require_retry, On as VoteTablesRowSchema, P as isLinkOfMedia, Pt as ChallengeRequestMessageSchema, Q as retryKuboBlockPutPinAndProvidePubsubTopic, Sr as t$6, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Vn as CommentUpdateTableRowSchema, Vr as logger_default, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xt as CommunityEditPublicationPubsubReservedFields, Yn as CommentEditPubsubMessagePublicationSchema, Zn as CommentEditReservedFields, _ as genToArray, b as getIpnsRecordInLocalKuboNode, br as n$2, bt as syncCommunityRegistryEntry, c as contentContainsMarkdownImages, ct as withSortedKeys, dt as findStartedCommunity, et as retryKuboIpfsAddAndProvide, f as derivePublicationFromChallengeRequest, g as findMalformedUnicodeString, gr as isStringDomain, i as calculateStringSizeSameAsIpfsAddCidV0, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, it as statMfsPathSafely, j as isLinkOfAnimatedImage, jn as CommentIpfsSchema, jr as t$2, kt as pTimeout, l as contentContainsMarkdownVideos, lt as withSortedKeysDeep, mn as CommunitySignedPropertyNames, nn as CommentModerationReservedFields, o as calculateUnixFsDagSizeCidV0, ot as timestamp, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, r as calculateIpfsCidV0, ri as ZodError, rt as sleepUntilTimeoutOrAbort, s as contentContainsMarkdownAudio, tn as CommentModerationPubsubMessagePublicationSchema, ut as findCommunityInRegistry, v as getEquivalentCommunityAddresses, vr as n$3, wr as e, wt as untrackStartedCommunity, xr as t$5, xt as trackStartedCommunity, y as getErrorCodeFromMessage, yr as t$7, zn as CommentUpdateSchema, zr as PKCError, zt as DecryptedChallengeRequestPublicationSchema } from "./util-BZuCmqxu.js";
|
|
3
|
+
import { $ as coerceSchemaRowJson, $n as cleanWireAuthor, $r as getCommunitiesRegistry, An as signCommentUpdateForChallengeVerification, Ar as calculateExpectedSignatureSize, Bn as verifyCommentIpfs, Cn as signChallengeMessage, Cr as sha256$6, Dn as signCommentEdit, Dr as clean, En as signComment, Er as anumber, Et as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Fn as verifyChallengeAnswer, Fr as deriveDbPosts, Gn as verifyCommunityEdit, H as listSubscribedPubsubTopicsShared, Hn as verifyCommentPubsubMessage, Hr as importSignerIntoKuboNode, Ir as deriveDbReplies, Jr as removeFileRetryingWhileBusy, K as pLimit, Kr as moveCommunityDbToDeletedDirectory, Ln as verifyChallengeRequest, N as MAX_PAGE_SIZE_BYTES, Nr as deleteOldCommunityInWindows, Or as BackupAbortError, Pr as deriveCommentIpfsFromCommentTableRow, Q as coerceSchemaRowBoolean, Qn as buildRuntimeAuthor, Qr as unregisterLocalCommunity, Rr as forgetCommunityThatFailedToBeDeleted, S as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, Sr as x25519, Tn as signChallengeVerification, Tr as ahash, Un as verifyCommentUpdate, V as SHARED_KUBO_READ_TIMEOUT_MS, Vn as verifyCommentModeration, Vr as getThumbnailPropsOfLink, Wn as verifyCommunity, Yn as forbiddenKeysOf, Yr as resolveDbPostsCidRefs, _ as createAuthorIdentityMatcher, _i as require_lodash_merge, _n as decryptEd25519AesGcmPublicKeyBuffer, _r as getIpfsKeyFromPrivateKey, a as generatePagesReportingFailedSorts, ai as t$11, b as KeyvBetterSqlite3, bn as _validateSignatureOfPKCRecord, br as getPublicKeyFromPrivateKey, c as resolvePageSortsOrThrow, ci as n$5, cr as effectiveMaxCrosspostDepth, d as getChallengeVerification, di as t$9, dr as getCommunityNameFromWire, ei as markCommunityDbAsBeingWritten, et as collectSchemaRowCoercions, f as getCommunityChallengeFromCommunityChallengeSettings, fr as getCommunityPublicKeyFromWire, g as authorNameResolveFailureReason, gi as STORAGE_KEYS, h as authorIdentityMatcherForRequest, hr as encode, ht as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, i as derivePublicPageSorts, ii as t$10, j as iterateOverPageCidsToFindAllCids, jn as signCommunity, jr as calculateInlineRepliesBudget, kn as signCommentUpdate, kr as backupCommunityDb, kt as parseJsonWithPKCErrorIfFails, li as n$4, ln as verifyAuthorWalletEntry, m as pkcJsChallenges, mr as decode, o as loadPageSortsForStartedCommunity, oi as r$2, p as loadChallengeFileFromCommunityChallengeSettings, pn as SignerWithPublicKeyAddress, pt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, qn as verifyVote, r as computePageSortsFingerprint, rr as stringify, s as lookupPageSortFactories, si as t$8, sr as crosspostChainDepthUpTo, t as RpcLocalCommunity, ti as findCommunitiesEntry, tr as getAuthorNameFromWire, tt as createSchemaRowParser, u as deriveCommunityChallengesOrThrow, un as hmac, v as TrackedInstanceRegistry, vr as getPKCAddressFromPublicKey, w as TIMEFRAMES_TO_SECONDS, wr as abytes, xn as cleanUpBeforePublishing, xr as ed25519, y as LRUCache, yn as encryptEd25519AesGcmPublicKeyBuffer, yr as getPKCAddressFromPublicKeySync, zn as verifyCommentEdit, zr as getDefaultCommunityDbConfig } from "./rpc-local-community-Bo4Z7ilA.js";
|
|
4
|
+
import { a as scorePageCommentsWithFile, i as partitionPageCommentsForSort, n as filterRepliesForPageSort, o as stripRepliesFromPageComment, r as orderPageCommentsByScore, t as createDescendantsLookup } from "./page-sort-scoring-I02fuGkI.js";
|
|
5
5
|
import { c as prepare, n as decode$1, r as encode$1 } from "./src-BSYNGtIQ.js";
|
|
6
6
|
import { t as UnixFS } from "./src-CAvdjq_i.js";
|
|
7
7
|
import { monitorEventLoopDelay } from "node:perf_hooks";
|
|
@@ -17,6 +17,7 @@ import Database from "better-sqlite3";
|
|
|
17
17
|
import { CID } from "multiformats/cid";
|
|
18
18
|
import { peerIdFromString } from "@libp2p/peer-id";
|
|
19
19
|
import { of } from "typestub-ipfs-only-hash";
|
|
20
|
+
import { fromString, toString } from "uint8arrays";
|
|
20
21
|
import v8 from "node:v8";
|
|
21
22
|
import { sha256 } from "multiformats/hashes/sha2";
|
|
22
23
|
import { murmur3128 } from "@multiformats/murmur3";
|
|
@@ -188,6 +189,118 @@ async function reprovideAnchorRecordIfDue(community) {
|
|
|
188
189
|
await reprovideAnchorRecordIfNeeded(community);
|
|
189
190
|
}
|
|
190
191
|
//#endregion
|
|
192
|
+
//#region node_modules/@noble/hashes/hkdf.js
|
|
193
|
+
/**
|
|
194
|
+
* HKDF (RFC 5869): extract + expand in one step.
|
|
195
|
+
* See {@link https://soatok.blog/2021/11/17/understanding-hkdf/}.
|
|
196
|
+
* @module
|
|
197
|
+
*/
|
|
198
|
+
const HKDF_COUNTER = /* @__PURE__ */ Uint8Array.of(0);
|
|
199
|
+
const EMPTY_BUFFER = /* @__PURE__ */ Uint8Array.of();
|
|
200
|
+
/**
|
|
201
|
+
* HKDF-expand from the spec. The most important part. `HKDF-Expand(PRK, info, L) -> OKM`
|
|
202
|
+
* @param hash - hash function that would be used (e.g. sha256)
|
|
203
|
+
* @param prk - a pseudorandom key of at least HashLen octets
|
|
204
|
+
* (usually, the output from the extract step)
|
|
205
|
+
* @param info - optional context and application specific information (can be a zero-length string)
|
|
206
|
+
* @param length - length of output keying material in bytes.
|
|
207
|
+
* RFC 5869 §2.3 allows `0..255*HashLen`, so `0` returns an empty OKM.
|
|
208
|
+
* @param _recycled - Internal destroyed extract hashes owned by the combined `hkdf()` call.
|
|
209
|
+
* @returns Output keying material with the requested length.
|
|
210
|
+
* @throws If the requested output length exceeds the HKDF limit
|
|
211
|
+
* for the selected hash. {@link Error}
|
|
212
|
+
* @example
|
|
213
|
+
* Run the HKDF expand step.
|
|
214
|
+
* ```ts
|
|
215
|
+
* import { expand } from '@noble/hashes/hkdf.js';
|
|
216
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
217
|
+
* expand(sha256, new Uint8Array(32), new Uint8Array([1, 2, 3]), 16);
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
function expand(hash, prk, info, length = 32, _recycled) {
|
|
221
|
+
ahash(hash);
|
|
222
|
+
anumber(length, "length");
|
|
223
|
+
abytes(prk, void 0, "prk");
|
|
224
|
+
const olen = hash.outputLen;
|
|
225
|
+
if (prk.length < olen) throw new Error("\"prk\" must be at least HashLen octets");
|
|
226
|
+
if (length > 255 * olen) throw new Error("Length must be <= 255*HashLen");
|
|
227
|
+
const blocks = Math.ceil(length / olen);
|
|
228
|
+
if (info === void 0) info = EMPTY_BUFFER;
|
|
229
|
+
else abytes(info, void 0, "info");
|
|
230
|
+
if (!blocks) {
|
|
231
|
+
if (_recycled) clean(prk);
|
|
232
|
+
return new Uint8Array();
|
|
233
|
+
}
|
|
234
|
+
const okm = _recycled && blocks === 1 ? prk : new Uint8Array(blocks * olen);
|
|
235
|
+
const { iHash, oHash } = hmac.create(hash, prk);
|
|
236
|
+
const T = _recycled ? prk : new Uint8Array(olen);
|
|
237
|
+
const worker = blocks > 1 ? _recycled?.iHash || hash.create() : void 0;
|
|
238
|
+
for (let counter = 0; counter < blocks - 1; counter++) {
|
|
239
|
+
HKDF_COUNTER[0] = counter + 1;
|
|
240
|
+
const iWork = iHash._cloneInto(worker);
|
|
241
|
+
if (counter) iWork.update(T);
|
|
242
|
+
iWork.update(info).update(HKDF_COUNTER).digestInto(T);
|
|
243
|
+
oHash._cloneInto(worker).update(T).digestInto(T);
|
|
244
|
+
okm.set(T, olen * counter);
|
|
245
|
+
}
|
|
246
|
+
HKDF_COUNTER[0] = blocks;
|
|
247
|
+
if (blocks > 1) iHash.update(T);
|
|
248
|
+
iHash.update(info).update(HKDF_COUNTER).digestInto(T);
|
|
249
|
+
oHash.update(T).digestInto(T);
|
|
250
|
+
okm.set(T, olen * (blocks - 1));
|
|
251
|
+
iHash.destroy();
|
|
252
|
+
oHash.destroy();
|
|
253
|
+
worker?.destroy();
|
|
254
|
+
if (T !== okm) clean(T);
|
|
255
|
+
clean(HKDF_COUNTER);
|
|
256
|
+
if (length === okm.length) return okm;
|
|
257
|
+
const res = okm.slice(0, length);
|
|
258
|
+
clean(okm);
|
|
259
|
+
return res;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* HKDF (RFC 5869): derive keys from an initial input.
|
|
263
|
+
* Combines hkdf_extract + hkdf_expand in one step
|
|
264
|
+
* @param hash - hash function that would be used (e.g. sha256)
|
|
265
|
+
* @param ikm - input keying material, the initial key
|
|
266
|
+
* @param salt - optional salt value (a non-secret random value)
|
|
267
|
+
* @param info - optional context and application specific information bytes
|
|
268
|
+
* @param length - length of output keying material in bytes.
|
|
269
|
+
* RFC 5869 §2.3 allows `0..255*HashLen`, so `0` returns an empty OKM.
|
|
270
|
+
* @returns Output keying material derived from the input key.
|
|
271
|
+
* @throws If the requested output length exceeds the HKDF limit
|
|
272
|
+
* for the selected hash. {@link Error}
|
|
273
|
+
* @example
|
|
274
|
+
* HKDF (RFC 5869): derive keys from an initial input.
|
|
275
|
+
* ```ts
|
|
276
|
+
* import { hkdf } from '@noble/hashes/hkdf.js';
|
|
277
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
278
|
+
* import { randomBytes, utf8ToBytes } from '@noble/hashes/utils.js';
|
|
279
|
+
* const inputKey = randomBytes(32);
|
|
280
|
+
* const salt = randomBytes(32);
|
|
281
|
+
* const info = utf8ToBytes('application-key');
|
|
282
|
+
* const okm = hkdf(sha256, inputKey, salt, info, 32);
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
const hkdf = (hash, ikm, salt, info, length) => {
|
|
286
|
+
ahash(hash);
|
|
287
|
+
if (salt === void 0) salt = new Uint8Array(hash.outputLen);
|
|
288
|
+
const HMAC = hmac.create(hash, salt).update(ikm);
|
|
289
|
+
return expand(hash, HMAC.digest(), info, length, HMAC);
|
|
290
|
+
};
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region dist/node/signer/pseudonymity-author-tag.js
|
|
293
|
+
const HKDF_INFO = fromString("pkc-pseudonymity-author-tag-v1", "utf8");
|
|
294
|
+
const TAG_BYTE_LENGTH = 16;
|
|
295
|
+
function derivePseudonymityTagSharedKey(opts) {
|
|
296
|
+
const communityPrivateKey = fromString(opts.communityPrivateKeyBase64, "base64");
|
|
297
|
+
const authorPublicKey = fromString(opts.authorPublicKeyBase64, "base64");
|
|
298
|
+
return hkdf(sha256$6, x25519.getSharedSecret(ed25519.utils.toMontgomerySecret(communityPrivateKey), ed25519.utils.toMontgomery(authorPublicKey)), void 0, HKDF_INFO, 32);
|
|
299
|
+
}
|
|
300
|
+
function computePseudonymityAuthorTag(opts) {
|
|
301
|
+
return toString(hmac(sha256$6, opts.sharedKey, fromString(opts.commentCid, "utf8")).subarray(0, TAG_BYTE_LENGTH), "base64");
|
|
302
|
+
}
|
|
303
|
+
//#endregion
|
|
191
304
|
//#region dist/node/runtime/node/community/comment-update-row.js
|
|
192
305
|
const commentUpdateSchemaKeys = new Set(Object.keys(CommentUpdateSchema.shape));
|
|
193
306
|
function commentUpdateExtraKeys(update) {
|
|
@@ -1450,6 +1563,9 @@ const TABLES = Object.freeze({
|
|
|
1450
1563
|
COMMENT_EDITS: "commentEdits",
|
|
1451
1564
|
PSEUDONYMITY_ALIASES: "pseudonymityAliases"
|
|
1452
1565
|
});
|
|
1566
|
+
function isAuthorBanRow(modEdit) {
|
|
1567
|
+
return typeof modEdit?.banExpiresAt === "number" && modEdit.banExpiresAt > 0;
|
|
1568
|
+
}
|
|
1453
1569
|
function deriveAliasOriginalAuthorSignerAddress(originalAuthorPublicKey) {
|
|
1454
1570
|
try {
|
|
1455
1571
|
return getPKCAddressFromPublicKeySync(originalAuthorPublicKey);
|
|
@@ -1707,13 +1823,15 @@ var DbHandler = class {
|
|
|
1707
1823
|
removed INTEGER NULLABLE, -- BOOLEAN (0/1)
|
|
1708
1824
|
approved INTEGER NULLABLE, -- BOOLEAN (0/1)
|
|
1709
1825
|
reason TEXT NULLABLE,
|
|
1826
|
+
authorBanExpiresAt INTEGER NULLABLE, -- the ban a mod published on this comment (issue #363)
|
|
1710
1827
|
updatedAt INTEGER NOT NULL CHECK(updatedAt > 0),
|
|
1711
1828
|
protocolVersion TEXT NOT NULL,
|
|
1712
1829
|
signature TEXT NOT NULL, -- JSON
|
|
1713
1830
|
author TEXT NULLABLE, -- JSON
|
|
1714
1831
|
replies TEXT NULLABLE, -- JSON: CID refs per sort (DbRepliesSchema)
|
|
1715
1832
|
lastChildCid TEXT NULLABLE,
|
|
1716
|
-
lastReplyTimestamp INTEGER NULLABLE,
|
|
1833
|
+
lastReplyTimestamp INTEGER NULLABLE,
|
|
1834
|
+
pseudonymityAuthorTag TEXT NULLABLE, -- own-post recognition tag on aliased comments (issue #381); a signed CommentUpdate field
|
|
1717
1835
|
postUpdatesBucket INTEGER NULLABLE,
|
|
1718
1836
|
publishedToPostUpdatesMFS INTEGER NOT NULL, -- BOOLEAN (0/1)
|
|
1719
1837
|
insertedAt INTEGER NOT NULL,
|
|
@@ -2319,16 +2437,16 @@ var DbHandler = class {
|
|
|
2319
2437
|
const columnNames = this._getColumnNames(TABLES.COMMENT_UPDATES);
|
|
2320
2438
|
const stmt = this._prepareCached(`
|
|
2321
2439
|
INSERT INTO ${TABLES.COMMENT_UPDATES}
|
|
2322
|
-
(cid, edit, upvoteCount, downvoteCount, replyCount, childCount, number, postNumber, flairs, spoiler, nsfw, pinned, locked, archived, removed, approved, reason, updatedAt, protocolVersion, signature, author, replies, lastChildCid, lastReplyTimestamp, postUpdatesBucket, publishedToPostUpdatesMFS, insertedAt, extraProps)
|
|
2323
|
-
VALUES (@cid, @edit, @upvoteCount, @downvoteCount, @replyCount, @childCount, @number, @postNumber, @flairs, @spoiler, @nsfw, @pinned, @locked, @archived, @removed, @approved, @reason, @updatedAt, @protocolVersion, @signature, @author, @replies, @lastChildCid, @lastReplyTimestamp, @postUpdatesBucket, @publishedToPostUpdatesMFS, @insertedAt, @extraProps)
|
|
2440
|
+
(cid, edit, upvoteCount, downvoteCount, replyCount, childCount, number, postNumber, flairs, spoiler, nsfw, pinned, locked, archived, removed, approved, reason, authorBanExpiresAt, updatedAt, protocolVersion, signature, author, replies, lastChildCid, lastReplyTimestamp, pseudonymityAuthorTag, postUpdatesBucket, publishedToPostUpdatesMFS, insertedAt, extraProps)
|
|
2441
|
+
VALUES (@cid, @edit, @upvoteCount, @downvoteCount, @replyCount, @childCount, @number, @postNumber, @flairs, @spoiler, @nsfw, @pinned, @locked, @archived, @removed, @approved, @reason, @authorBanExpiresAt, @updatedAt, @protocolVersion, @signature, @author, @replies, @lastChildCid, @lastReplyTimestamp, @pseudonymityAuthorTag, @postUpdatesBucket, @publishedToPostUpdatesMFS, @insertedAt, @extraProps)
|
|
2324
2442
|
ON CONFLICT(cid) DO UPDATE SET
|
|
2325
2443
|
edit = excluded.edit, upvoteCount = excluded.upvoteCount, downvoteCount = excluded.downvoteCount, replyCount = excluded.replyCount, childCount = excluded.childCount,
|
|
2326
2444
|
number = COALESCE(excluded.number, ${TABLES.COMMENT_UPDATES}.number),
|
|
2327
2445
|
postNumber = COALESCE(excluded.postNumber, ${TABLES.COMMENT_UPDATES}.postNumber),
|
|
2328
2446
|
flairs = excluded.flairs, spoiler = excluded.spoiler, nsfw = excluded.nsfw, pinned = excluded.pinned, locked = excluded.locked, archived = excluded.archived,
|
|
2329
|
-
removed = excluded.removed, approved = excluded.approved, reason = excluded.reason, updatedAt = excluded.updatedAt, protocolVersion = excluded.protocolVersion,
|
|
2447
|
+
removed = excluded.removed, approved = excluded.approved, reason = excluded.reason, authorBanExpiresAt = excluded.authorBanExpiresAt, updatedAt = excluded.updatedAt, protocolVersion = excluded.protocolVersion,
|
|
2330
2448
|
signature = excluded.signature, author = excluded.author, replies = excluded.replies, lastChildCid = excluded.lastChildCid,
|
|
2331
|
-
lastReplyTimestamp = excluded.lastReplyTimestamp, postUpdatesBucket = excluded.postUpdatesBucket,
|
|
2449
|
+
lastReplyTimestamp = excluded.lastReplyTimestamp, pseudonymityAuthorTag = excluded.pseudonymityAuthorTag, postUpdatesBucket = excluded.postUpdatesBucket,
|
|
2332
2450
|
publishedToPostUpdatesMFS = excluded.publishedToPostUpdatesMFS,
|
|
2333
2451
|
insertedAt = excluded.insertedAt,
|
|
2334
2452
|
extraProps = excluded.extraProps
|
|
@@ -3362,6 +3480,7 @@ var DbHandler = class {
|
|
|
3362
3480
|
flairs: moderation?.flairs || authorEdit?.flairs || comment.challengeCommentUpdate?.flairs,
|
|
3363
3481
|
...moderation?.flags,
|
|
3364
3482
|
reason: moderation?.reason ?? comment.challengeCommentUpdate?.reason,
|
|
3483
|
+
authorBanExpiresAt: moderation?.authorBanExpiresAt || void 0,
|
|
3365
3484
|
author: { community: {
|
|
3366
3485
|
...challengeAuthorCommunity ?? {},
|
|
3367
3486
|
...authorCommunity
|
|
@@ -3497,6 +3616,8 @@ var DbHandler = class {
|
|
|
3497
3616
|
result.set(row.commentCid, summary);
|
|
3498
3617
|
}
|
|
3499
3618
|
if (summary.reason === void 0 && typeof moderation.reason === "string") summary.reason = moderation.reason;
|
|
3619
|
+
const banExpiresAt = moderation.author?.banExpiresAt;
|
|
3620
|
+
if (summary.authorBanExpiresAt === void 0 && typeof banExpiresAt === "number") summary.authorBanExpiresAt = banExpiresAt;
|
|
3500
3621
|
if (summary.flairs === void 0 && moderation.flairs !== null && moderation.flairs !== void 0) summary.flairs = moderation.flairs;
|
|
3501
3622
|
if (summary.approved === void 0 && moderation.approved !== null && moderation.approved !== void 0) summary.approved = Boolean(moderation.approved);
|
|
3502
3623
|
for (const flag of FLAG_NAMES) if (summary.flags[flag] === void 0 && moderation[flag] !== null && moderation[flag] !== void 0) summary.flags[flag] = Boolean(moderation[flag]);
|
|
@@ -3615,7 +3736,7 @@ var DbHandler = class {
|
|
|
3615
3736
|
for (const need of uncached.values()) {
|
|
3616
3737
|
const modEditSet = new Set(need.modEdit);
|
|
3617
3738
|
const modAuthorEdits = modEditRows.filter((row) => row.targetAuthorSignerAddress !== null && modEditSet.has(row.targetAuthorSignerAddress) || need.domain !== void 0 && row.targetAuthorDomain === need.domain).map((row) => row.author);
|
|
3618
|
-
const banAuthor = modAuthorEdits.find(
|
|
3739
|
+
const banAuthor = modAuthorEdits.find(isAuthorBanRow);
|
|
3619
3740
|
const authorFlairsByMod = modAuthorEdits.find((modEdit) => modEdit?.flairs);
|
|
3620
3741
|
const modEdits = {};
|
|
3621
3742
|
if (banAuthor?.banExpiresAt) modEdits.banExpiresAt = banAuthor.banExpiresAt;
|
|
@@ -3767,7 +3888,7 @@ var DbHandler = class {
|
|
|
3767
3888
|
SELECT json_extract(commentModeration, '$.author') AS commentAuthorJson FROM ${TABLES.COMMENT_MODERATIONS}
|
|
3768
3889
|
WHERE (${conditions.join(" OR ")}) AND json_extract(commentModeration, '$.author') IS NOT NULL ORDER BY rowid DESC
|
|
3769
3890
|
`).all(...params).map((r) => JSON.parse(r.commentAuthorJson));
|
|
3770
|
-
const banAuthor = modAuthorEdits.find(
|
|
3891
|
+
const banAuthor = modAuthorEdits.find(isAuthorBanRow);
|
|
3771
3892
|
const authorFlairsByMod = modAuthorEdits.find((modEdit) => modEdit?.flairs);
|
|
3772
3893
|
const aggregateAuthor = {};
|
|
3773
3894
|
if (banAuthor?.banExpiresAt) aggregateAuthor.banExpiresAt = banAuthor.banExpiresAt;
|
|
@@ -4038,6 +4159,9 @@ var DbHandler = class {
|
|
|
4038
4159
|
if (commentCids.length === 0) return;
|
|
4039
4160
|
this._runForEachCidBatch(commentCids, (placeholders) => `UPDATE ${TABLES.COMMENT_UPDATES} SET publishedToPostUpdatesMFS = 1 WHERE cid IN (${placeholders})`);
|
|
4040
4161
|
}
|
|
4162
|
+
queryPublishedPostCidsOfBucket(bucket) {
|
|
4163
|
+
return this._db.prepare(`SELECT cid FROM ${TABLES.COMMENT_UPDATES} WHERE postUpdatesBucket = ? AND publishedToPostUpdatesMFS = 1`).pluck().all(bucket);
|
|
4164
|
+
}
|
|
4041
4165
|
forceUpdateOnAllComments() {
|
|
4042
4166
|
this._db.prepare(`UPDATE ${TABLES.COMMENT_UPDATES} SET publishedToPostUpdatesMFS = 0`).run();
|
|
4043
4167
|
}
|
|
@@ -4456,6 +4580,58 @@ async function statMfsPathOrUndefined(kuboRpcClient, path, log) {
|
|
|
4456
4580
|
throw error;
|
|
4457
4581
|
}
|
|
4458
4582
|
}
|
|
4583
|
+
const bucketOfPath = (bucketPath) => Number(bucketPath.split("/").pop());
|
|
4584
|
+
async function markPostsMissingFromBucketForRewrite({ community, bucket, log }) {
|
|
4585
|
+
const published = community._dbHandler.queryPublishedPostCidsOfBucket(bucket);
|
|
4586
|
+
if (published.length === 0) return 0;
|
|
4587
|
+
const kubo = community._clientsManager.getDefaultKuboRpcClient()._client;
|
|
4588
|
+
const listed = /* @__PURE__ */ new Set();
|
|
4589
|
+
try {
|
|
4590
|
+
for await (const entry of kubo.files.ls(`/${community.address}/postUpdates/${bucket}`, { timeout: MFS_OP_TIMEOUT_MS })) listed.add(entry.name);
|
|
4591
|
+
} catch (error) {
|
|
4592
|
+
if (!isAbsentPathError(error)) throw error;
|
|
4593
|
+
}
|
|
4594
|
+
const missing = published.filter((cid) => !listed.has(cid));
|
|
4595
|
+
if (missing.length > 0) {
|
|
4596
|
+
community._dbHandler.forceUpdateOnAllCommentsWithCid(missing);
|
|
4597
|
+
log.error(`The postUpdates bucket ${bucket} of community ${community.address} holds ${listed.size} entries in MFS and ${missing.length} of its ${published.length} published posts are not in it. They will be written again by the next cycle`);
|
|
4598
|
+
}
|
|
4599
|
+
return missing.length;
|
|
4600
|
+
}
|
|
4601
|
+
const bucketsOfPaths = (community, mfsPaths) => {
|
|
4602
|
+
const prefix = `/${community.address}/postUpdates/`;
|
|
4603
|
+
const buckets = /* @__PURE__ */ new Set();
|
|
4604
|
+
for (const path of mfsPaths) if (path.startsWith(prefix)) {
|
|
4605
|
+
const bucket = Number(path.slice(prefix.length).split("/")[0]);
|
|
4606
|
+
if (Number.isFinite(bucket)) buckets.add(bucket);
|
|
4607
|
+
}
|
|
4608
|
+
return [...buckets];
|
|
4609
|
+
};
|
|
4610
|
+
async function statBucketsOfPaths({ community, mfsPaths }) {
|
|
4611
|
+
const log = logger_default("pkc-js:local-community:sync:statBucketsOfPaths");
|
|
4612
|
+
const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient();
|
|
4613
|
+
const stats = /* @__PURE__ */ new Map();
|
|
4614
|
+
for (const bucket of bucketsOfPaths(community, mfsPaths)) stats.set(bucket, await statMfsPathOrUndefined(kuboRpcClient, `/${community.address}/postUpdates/${bucket}`, log).then((stat) => stat?.cid.toString(), () => null));
|
|
4615
|
+
return stats;
|
|
4616
|
+
}
|
|
4617
|
+
function noteUnconfirmedRemovalsFromBuckets({ community, mfsPaths }) {
|
|
4618
|
+
for (const bucket of bucketsOfPaths(community, mfsPaths)) community._postUpdatesBucketsWithUnconfirmedRemovals.add(bucket);
|
|
4619
|
+
}
|
|
4620
|
+
async function rememberPostUpdatesBucketsOfPaths({ community, mfsPaths, before }) {
|
|
4621
|
+
const log = logger_default("pkc-js:local-community:sync:rememberPostUpdatesBuckets");
|
|
4622
|
+
const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient();
|
|
4623
|
+
for (const bucket of bucketsOfPaths(community, mfsPaths)) {
|
|
4624
|
+
const remembered = community._postUpdatesBucketCids.get(bucket);
|
|
4625
|
+
if (remembered !== void 0 && before.get(bucket) !== remembered) {
|
|
4626
|
+
community._postUpdatesBucketsWithUnconfirmedRemovals.add(bucket);
|
|
4627
|
+
continue;
|
|
4628
|
+
}
|
|
4629
|
+
community._postUpdatesBucketsWithUnconfirmedRemovals.delete(bucket);
|
|
4630
|
+
const stat = await statMfsPathOrUndefined(kuboRpcClient, `/${community.address}/postUpdates/${bucket}`, log).catch(() => void 0);
|
|
4631
|
+
if (stat) community._postUpdatesBucketCids.set(bucket, stat.cid.toString());
|
|
4632
|
+
else community._postUpdatesBucketCids.delete(bucket);
|
|
4633
|
+
}
|
|
4634
|
+
}
|
|
4459
4635
|
async function buildPostUpdateFiles(posts) {
|
|
4460
4636
|
const { importer } = await import("./src-DIOHVUq9.js");
|
|
4461
4637
|
const blocks = /* @__PURE__ */ new Map();
|
|
@@ -4570,22 +4746,68 @@ async function writePostUpdatesToBucket({ community, bucketPath, posts }) {
|
|
|
4570
4746
|
}
|
|
4571
4747
|
return bytes;
|
|
4572
4748
|
};
|
|
4749
|
+
const bucket = bucketOfPath(bucketPath);
|
|
4573
4750
|
let live = await recoverInterruptedBucketSwap(kuboRpcClient, bucketPath, log);
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4751
|
+
if (!live) {
|
|
4752
|
+
const bucketWasHere = community._postUpdatesBucketCids.delete(bucket);
|
|
4753
|
+
await markPostsMissingFromBucketForRewrite({
|
|
4754
|
+
community,
|
|
4755
|
+
bucket,
|
|
4756
|
+
log
|
|
4757
|
+
});
|
|
4758
|
+
if (bucketWasHere) throw new PKCError("ERR_POST_UPDATES_BUCKET_SWAP_WAS_LOST", {
|
|
4578
4759
|
communityAddress: community.address,
|
|
4579
4760
|
bucketPath,
|
|
4580
|
-
attempt
|
|
4761
|
+
attempt: 0
|
|
4762
|
+
});
|
|
4763
|
+
}
|
|
4764
|
+
const rememberedCid = community._postUpdatesBucketCids.get(bucket);
|
|
4765
|
+
const pendingCid = community._postUpdatesBucketPendingCids.get(bucket);
|
|
4766
|
+
if (live && pendingCid !== void 0 && live.cid.toString() === pendingCid) {
|
|
4767
|
+
community._postUpdatesBucketCids.set(bucket, pendingCid);
|
|
4768
|
+
community._postUpdatesBucketPendingCids.delete(bucket);
|
|
4769
|
+
} else if (live && rememberedCid !== void 0 && rememberedCid !== live.cid.toString()) {
|
|
4770
|
+
const missing = await markPostsMissingFromBucketForRewrite({
|
|
4771
|
+
community,
|
|
4772
|
+
bucket,
|
|
4773
|
+
log
|
|
4581
4774
|
});
|
|
4775
|
+
const removalsExplainIt = community._postUpdatesBucketsWithUnconfirmedRemovals.delete(bucket);
|
|
4776
|
+
community._postUpdatesBucketCids.set(bucket, live.cid.toString());
|
|
4777
|
+
if (!(removalsExplainIt && missing === 0)) throw new PKCError("ERR_POST_UPDATES_BUCKET_SWAP_WAS_LOST", {
|
|
4778
|
+
communityAddress: community.address,
|
|
4779
|
+
bucketPath,
|
|
4780
|
+
attempt: 0,
|
|
4781
|
+
bucketCidInMfs: live.cid.toString(),
|
|
4782
|
+
bucketCidRemembered: rememberedCid
|
|
4783
|
+
});
|
|
4784
|
+
}
|
|
4785
|
+
let bucketExisted = false;
|
|
4786
|
+
for (let attempt = 1;; attempt++) {
|
|
4787
|
+
if (live) bucketExisted = true;
|
|
4788
|
+
else if (bucketExisted) {
|
|
4789
|
+
community._postUpdatesBucketCids.delete(bucket);
|
|
4790
|
+
await markPostsMissingFromBucketForRewrite({
|
|
4791
|
+
community,
|
|
4792
|
+
bucket,
|
|
4793
|
+
log
|
|
4794
|
+
});
|
|
4795
|
+
throw new PKCError("ERR_POST_UPDATES_BUCKET_SWAP_WAS_LOST", {
|
|
4796
|
+
communityAddress: community.address,
|
|
4797
|
+
bucketPath,
|
|
4798
|
+
attempt
|
|
4799
|
+
});
|
|
4800
|
+
}
|
|
4582
4801
|
const { cid: root, newBlocks } = await patchUnixFsDirectory({
|
|
4583
4802
|
directoryCid: live?.cid,
|
|
4584
4803
|
entriesToPut: entries,
|
|
4585
4804
|
getBlock,
|
|
4586
4805
|
shardSplitThresholdBytes: MFS_SHARD_SPLIT_THRESHOLD_BYTES
|
|
4587
4806
|
});
|
|
4588
|
-
if (live && root.equals(live.cid))
|
|
4807
|
+
if (live && root.equals(live.cid)) {
|
|
4808
|
+
community._postUpdatesBucketCids.set(bucket, live.cid.toString());
|
|
4809
|
+
return;
|
|
4810
|
+
}
|
|
4589
4811
|
if (attempt > MAX_ATTEMPTS_TO_SWAP_POST_UPDATES_BUCKET) throw new PKCError("ERR_POST_UPDATES_BUCKET_SWAP_WAS_LOST", {
|
|
4590
4812
|
communityAddress: community.address,
|
|
4591
4813
|
bucketPath,
|
|
@@ -4609,6 +4831,7 @@ async function writePostUpdatesToBucket({ community, bucketPath, posts }) {
|
|
|
4609
4831
|
timeout: MFS_OP_TIMEOUT_MS
|
|
4610
4832
|
})) if (result.root.pinErrorMsg) throw Error(`Failed to pin the new blocks of bucket ${bucketPath} (${result.root.cid.toString()}): ${result.root.pinErrorMsg}`);
|
|
4611
4833
|
log(`Bucket ${bucketPath}: ${posts.length} posts written, ${newBlocks.length} of the bucket's nodes rebuilt (${car.length} bytes imported), root ${root.toString()}`);
|
|
4834
|
+
community._postUpdatesBucketPendingCids.set(bucket, root.toString());
|
|
4612
4835
|
await kubo.files.cp(`/ipfs/${root.toString()}`, nextPath, {
|
|
4613
4836
|
parents: true,
|
|
4614
4837
|
flush: true,
|
|
@@ -4628,9 +4851,30 @@ async function writePostUpdatesToBucket({ community, bucketPath, posts }) {
|
|
|
4628
4851
|
});
|
|
4629
4852
|
}
|
|
4630
4853
|
const swapped = await statMfsPathOrUndefined(kuboRpcClient, bucketPath, log);
|
|
4631
|
-
if (swapped?.cid.equals(root))
|
|
4854
|
+
if (swapped?.cid.equals(root)) {
|
|
4855
|
+
community._postUpdatesBucketCids.set(bucket, root.toString());
|
|
4856
|
+
community._postUpdatesBucketPendingCids.delete(bucket);
|
|
4857
|
+
return;
|
|
4858
|
+
}
|
|
4632
4859
|
log.error(`Bucket ${bucketPath} is ${swapped?.cid.toString()} in MFS after ${root.toString()} was swapped in (attempt ${attempt}), checking it for the posts' files`);
|
|
4633
4860
|
live = await recoverInterruptedBucketSwap(kuboRpcClient, bucketPath, log);
|
|
4861
|
+
if (live) {
|
|
4862
|
+
if (await markPostsMissingFromBucketForRewrite({
|
|
4863
|
+
community,
|
|
4864
|
+
bucket,
|
|
4865
|
+
log
|
|
4866
|
+
}) > 0) {
|
|
4867
|
+
community._postUpdatesBucketCids.set(bucket, live.cid.toString());
|
|
4868
|
+
community._postUpdatesBucketPendingCids.delete(bucket);
|
|
4869
|
+
throw new PKCError("ERR_POST_UPDATES_BUCKET_SWAP_WAS_LOST", {
|
|
4870
|
+
communityAddress: community.address,
|
|
4871
|
+
bucketPath,
|
|
4872
|
+
attempt,
|
|
4873
|
+
bucketCidInMfs: live.cid.toString(),
|
|
4874
|
+
bucketCidWithThePosts: root.toString()
|
|
4875
|
+
});
|
|
4876
|
+
}
|
|
4877
|
+
}
|
|
4634
4878
|
}
|
|
4635
4879
|
}
|
|
4636
4880
|
//#endregion
|
|
@@ -4658,6 +4902,32 @@ function calculateLocalMfsPathForCommentUpdate(community, postDbComment, timesta
|
|
|
4658
4902
|
"update"
|
|
4659
4903
|
].join("/");
|
|
4660
4904
|
}
|
|
4905
|
+
function computePseudonymityAuthorTagForComment(community, commentCid, log) {
|
|
4906
|
+
const aliasRow = community._dbHandler.queryPseudonymityAliasByCommentCid(commentCid);
|
|
4907
|
+
if (!aliasRow) return void 0;
|
|
4908
|
+
const authorPublicKeyBase64 = aliasRow.originalAuthorPublicKey;
|
|
4909
|
+
const signerPublicKey = community.signer.publicKey;
|
|
4910
|
+
try {
|
|
4911
|
+
let cached = community._pseudonymityTagKeyCache.get(authorPublicKeyBase64);
|
|
4912
|
+
if (!cached || cached.signerPublicKey !== signerPublicKey) {
|
|
4913
|
+
cached = {
|
|
4914
|
+
signerPublicKey,
|
|
4915
|
+
sharedKey: derivePseudonymityTagSharedKey({
|
|
4916
|
+
communityPrivateKeyBase64: community.signer.privateKey,
|
|
4917
|
+
authorPublicKeyBase64
|
|
4918
|
+
})
|
|
4919
|
+
};
|
|
4920
|
+
community._pseudonymityTagKeyCache.set(authorPublicKeyBase64, cached);
|
|
4921
|
+
}
|
|
4922
|
+
return computePseudonymityAuthorTag({
|
|
4923
|
+
sharedKey: cached.sharedKey,
|
|
4924
|
+
commentCid
|
|
4925
|
+
});
|
|
4926
|
+
} catch (e) {
|
|
4927
|
+
log.error(`Failed to derive pseudonymityAuthorTag for comment (${commentCid}) with author public key (${authorPublicKeyBase64}); publishing the CommentUpdate without a tag`, e);
|
|
4928
|
+
return;
|
|
4929
|
+
}
|
|
4930
|
+
}
|
|
4661
4931
|
async function calculateNewCommentUpdate(opts) {
|
|
4662
4932
|
const { community, comment, batchStartTimestamp, precomputed } = opts;
|
|
4663
4933
|
const log = logger_default("pkc-js:local-community:_calculateNewCommentUpdate");
|
|
@@ -4675,6 +4945,8 @@ async function calculateNewCommentUpdate(opts) {
|
|
|
4675
4945
|
updatedAt: newUpdatedAt,
|
|
4676
4946
|
protocolVersion: version_default.PROTOCOL_VERSION
|
|
4677
4947
|
}) };
|
|
4948
|
+
const pseudonymityAuthorTag = computePseudonymityAuthorTagForComment(community, comment.cid, log);
|
|
4949
|
+
if (pseudonymityAuthorTag) commentUpdatePriorToSigning.pseudonymityAuthorTag = pseudonymityAuthorTag;
|
|
4678
4950
|
const inlineRepliesBudget = calculateInlineRepliesBudget({
|
|
4679
4951
|
comment,
|
|
4680
4952
|
commentUpdateWithoutReplies: commentUpdatePriorToSigning
|
|
@@ -4940,6 +5212,10 @@ async function rmUnneededMfsPaths(community, opts) {
|
|
|
4940
5212
|
const toDeleteMfsPaths = Array.from(community._mfsPathsToRemove.values());
|
|
4941
5213
|
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
4942
5214
|
for (const watcher of community._mfsPathRemovalWatchers) for (const path of toDeleteMfsPaths) watcher.add(path);
|
|
5215
|
+
const bucketsBefore = await statBucketsOfPaths({
|
|
5216
|
+
community,
|
|
5217
|
+
mfsPaths: toDeleteMfsPaths
|
|
5218
|
+
});
|
|
4943
5219
|
try {
|
|
4944
5220
|
await removeMfsFilesSafely({
|
|
4945
5221
|
kuboRpcClient: kuboRpc,
|
|
@@ -4948,14 +5224,28 @@ async function rmUnneededMfsPaths(community, opts) {
|
|
|
4948
5224
|
inputNumOfRetries: opts?.numOfRetries
|
|
4949
5225
|
});
|
|
4950
5226
|
toDeleteMfsPaths.forEach((path) => community._mfsPathsToRemove.delete(path));
|
|
5227
|
+
await rememberPostUpdatesBucketsOfPaths({
|
|
5228
|
+
community,
|
|
5229
|
+
mfsPaths: toDeleteMfsPaths,
|
|
5230
|
+
before: bucketsBefore
|
|
5231
|
+
});
|
|
4951
5232
|
return toDeleteMfsPaths;
|
|
4952
5233
|
} catch (e) {
|
|
4953
5234
|
const error = e;
|
|
4954
5235
|
if (error.message.includes("file does not exist")) {
|
|
4955
5236
|
toDeleteMfsPaths.forEach((path) => community._mfsPathsToRemove.delete(path));
|
|
5237
|
+
await rememberPostUpdatesBucketsOfPaths({
|
|
5238
|
+
community,
|
|
5239
|
+
mfsPaths: toDeleteMfsPaths,
|
|
5240
|
+
before: bucketsBefore
|
|
5241
|
+
});
|
|
4956
5242
|
return toDeleteMfsPaths;
|
|
4957
5243
|
} else {
|
|
4958
5244
|
log.error("Failed to remove paths from MFS", toDeleteMfsPaths, e);
|
|
5245
|
+
noteUnconfirmedRemovalsFromBuckets({
|
|
5246
|
+
community,
|
|
5247
|
+
mfsPaths: toDeleteMfsPaths
|
|
5248
|
+
});
|
|
4959
5249
|
throw error;
|
|
4960
5250
|
}
|
|
4961
5251
|
}
|
|
@@ -6675,13 +6965,38 @@ async function syncWithRegistries(community) {
|
|
|
6675
6965
|
async function calculateNewPostUpdates(community) {
|
|
6676
6966
|
const postUpdates = {};
|
|
6677
6967
|
const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient();
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
6968
|
+
const log = logger_default("pkc-js:local-community:sync:calculateNewPostUpdates");
|
|
6969
|
+
for (const timeBucket of community._postUpdatesBuckets) {
|
|
6970
|
+
const rememberedCid = community._postUpdatesBucketCids.get(timeBucket);
|
|
6971
|
+
let cidInMfs;
|
|
6972
|
+
let absent = false;
|
|
6973
|
+
try {
|
|
6974
|
+
const statRes = await statMfsPathSafely({
|
|
6975
|
+
kuboRpcClient,
|
|
6976
|
+
path: `/${community.address}/postUpdates/${timeBucket}`
|
|
6977
|
+
});
|
|
6978
|
+
cidInMfs = String(statRes.cid);
|
|
6979
|
+
if (statRes.blocks !== 0) postUpdates[String(timeBucket)] = cidInMfs;
|
|
6980
|
+
} catch (error) {
|
|
6981
|
+
if (!isAbsentPathError(error)) continue;
|
|
6982
|
+
absent = true;
|
|
6983
|
+
}
|
|
6984
|
+
const lost = absent && (rememberedCid !== void 0 || community.postUpdates?.[String(timeBucket)] !== void 0);
|
|
6985
|
+
const changed = !absent && rememberedCid !== void 0 && rememberedCid !== cidInMfs;
|
|
6986
|
+
if (lost || changed) try {
|
|
6987
|
+
await markPostsMissingFromBucketForRewrite({
|
|
6988
|
+
community,
|
|
6989
|
+
bucket: timeBucket,
|
|
6990
|
+
log
|
|
6991
|
+
});
|
|
6992
|
+
} catch (error) {
|
|
6993
|
+
log.error(`Failed to check the postUpdates bucket ${timeBucket} of community ${community.address}`, error);
|
|
6994
|
+
continue;
|
|
6995
|
+
}
|
|
6996
|
+
if (lost || changed) community._postUpdatesBucketsWithUnconfirmedRemovals.delete(timeBucket);
|
|
6997
|
+
if (cidInMfs !== void 0) community._postUpdatesBucketCids.set(timeBucket, cidInMfs);
|
|
6998
|
+
else community._postUpdatesBucketCids.delete(timeBucket);
|
|
6999
|
+
}
|
|
6685
7000
|
if (e(postUpdates)) return void 0;
|
|
6686
7001
|
return postUpdates;
|
|
6687
7002
|
}
|
|
@@ -7039,6 +7354,16 @@ function holdEventLoopWatch() {
|
|
|
7039
7354
|
};
|
|
7040
7355
|
}
|
|
7041
7356
|
//#endregion
|
|
7357
|
+
//#region dist/node/runtime/node/community/local-community/db-fault.js
|
|
7358
|
+
function classifyDbFault(error) {
|
|
7359
|
+
const code = error?.code;
|
|
7360
|
+
const message = error?.message;
|
|
7361
|
+
const name = typeof code === "string" ? code : typeof message === "string" ? message.match(/^SQLITE_[A-Z_]+/)?.[0] ?? "" : "";
|
|
7362
|
+
if (name.startsWith("SQLITE_BUSY") || name.startsWith("SQLITE_LOCKED")) return "busy";
|
|
7363
|
+
if (name.startsWith("SQLITE_IOERR")) return "maybe-transient";
|
|
7364
|
+
return "final";
|
|
7365
|
+
}
|
|
7366
|
+
//#endregion
|
|
7042
7367
|
//#region dist/node/runtime/node/community/local-community/reprovide-on-address-change.js
|
|
7043
7368
|
const ADDRESS_REPROVIDE_POLL_INTERVAL_MS = 60 * 1e3;
|
|
7044
7369
|
function normalizeSelfAddrsForProvider(addrs, peerId) {
|
|
@@ -7155,14 +7480,28 @@ async function reprovideOnAddressChangeIfDue(community) {
|
|
|
7155
7480
|
//#endregion
|
|
7156
7481
|
//#region dist/node/runtime/node/community/local-community/lifecycle.js
|
|
7157
7482
|
const MIN_MS_BETWEEN_PUBLISH_CYCLES = 100;
|
|
7483
|
+
const MS_BETWEEN_DB_READ_RETRIES = 100;
|
|
7158
7484
|
async function publishLoop(community, syncIntervalMs) {
|
|
7159
7485
|
const log = logger_default("pkc-js:local-community:_publishLoop");
|
|
7160
7486
|
let syncFailedSinceStop = false;
|
|
7161
7487
|
const shouldStopPublishLoop = () => {
|
|
7162
7488
|
return community.state !== "started" || community._stopHasBeenCalled && (community._pendingEditProps.length === 0 || syncFailedSinceStop);
|
|
7163
7489
|
};
|
|
7490
|
+
const readUpdateTriggerRidingOutDbFaults = async () => {
|
|
7491
|
+
let consecutiveIoErrors = 0;
|
|
7492
|
+
while (true) try {
|
|
7493
|
+
calculateLatestUpdateTrigger(community);
|
|
7494
|
+
return;
|
|
7495
|
+
} catch (error) {
|
|
7496
|
+
const kind = classifyDbFault(error);
|
|
7497
|
+
if (!(kind === "busy" || kind === "maybe-transient" && ++consecutiveIoErrors <= 5)) throw error;
|
|
7498
|
+
if (shouldStopPublishLoop()) return;
|
|
7499
|
+
log(`The DB of community (${community.address}) could not be read (${kind}), reading again in ${MS_BETWEEN_DB_READ_RETRIES}ms`);
|
|
7500
|
+
await new Promise((resolve) => setTimeout(resolve, MS_BETWEEN_DB_READ_RETRIES));
|
|
7501
|
+
}
|
|
7502
|
+
};
|
|
7164
7503
|
const waitUntilNextSync = async ({ lastSyncFailed }) => {
|
|
7165
|
-
|
|
7504
|
+
await readUpdateTriggerRidingOutDbFaults();
|
|
7166
7505
|
if (shouldStopPublishLoop()) return;
|
|
7167
7506
|
const recordAlreadyRequested = !lastSyncFailed && community._communityUpdateTrigger;
|
|
7168
7507
|
const minPauseMs = Math.min(MIN_MS_BETWEEN_PUBLISH_CYCLES, syncIntervalMs);
|
|
@@ -7368,7 +7707,11 @@ async function startCommunity({ community, releaseMark }) {
|
|
|
7368
7707
|
}
|
|
7369
7708
|
community._publishLoopPromise = publishLoop(community, community._pkc.publishInterval).catch((err) => {
|
|
7370
7709
|
log.error(err);
|
|
7371
|
-
|
|
7710
|
+
try {
|
|
7711
|
+
community.emit("error", err);
|
|
7712
|
+
} finally {
|
|
7713
|
+
community.stop().catch((e) => log.error(`Failed to stop community (${community.address}) after its publish loop ended`, e));
|
|
7714
|
+
}
|
|
7372
7715
|
});
|
|
7373
7716
|
}
|
|
7374
7717
|
async function initMirroringStartedOrUpdatingCommunity(community, startedCommunity) {
|
|
@@ -8289,10 +8632,14 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
8289
8632
|
this._challengeExchangesFromLocalPublishers = {};
|
|
8290
8633
|
this._inFlightPublicationExchanges = /* @__PURE__ */ new Map();
|
|
8291
8634
|
this._pseudonymityAliasLocks = /* @__PURE__ */ new Map();
|
|
8635
|
+
this._pseudonymityTagKeyCache = /* @__PURE__ */ new Map();
|
|
8292
8636
|
this._challengeExchangeTtlMs = CHALLENGE_EXCHANGE_TTL_MS;
|
|
8293
8637
|
this._slowGetChallengeWarningMs = SLOW_GET_CHALLENGE_WARNING_MS;
|
|
8294
8638
|
this._cidsToUnPin = /* @__PURE__ */ new Set();
|
|
8295
8639
|
this._mfsPathsToRemove = /* @__PURE__ */ new Set();
|
|
8640
|
+
this._postUpdatesBucketCids = /* @__PURE__ */ new Map();
|
|
8641
|
+
this._postUpdatesBucketPendingCids = /* @__PURE__ */ new Map();
|
|
8642
|
+
this._postUpdatesBucketsWithUnconfirmedRemovals = /* @__PURE__ */ new Set();
|
|
8296
8643
|
this._mfsPathRemovalWatchers = /* @__PURE__ */ new Set();
|
|
8297
8644
|
this._communityUpdateTriggerValue = false;
|
|
8298
8645
|
this._updateTriggerGeneration = 0;
|
|
@@ -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-0xsjgulY.js";
|
|
2
2
|
export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };
|