@pkcprotocol/pkc-js 0.0.75 → 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.
Files changed (156) hide show
  1. package/README.md +10 -0
  2. package/dist/browser/clients/rpc-client/pkc-rpc-client.d.ts +3 -1
  3. package/dist/browser/clients/rpc-client/pkc-rpc-client.js +12 -1
  4. package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -1
  5. package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +18 -0
  6. package/dist/browser/clients/rpc-client/rpc-schema-util.js +5 -1
  7. package/dist/browser/clients/rpc-client/rpc-schema-util.js.map +1 -1
  8. package/dist/browser/clients/rpc-client/schema.d.ts +15 -0
  9. package/dist/browser/clients/rpc-client/schema.js +20 -0
  10. package/dist/browser/clients/rpc-client/schema.js.map +1 -1
  11. package/dist/browser/clients/rpc-client/types.d.ts +3 -2
  12. package/dist/browser/community/community-client-manager.js +9 -9
  13. package/dist/browser/community/community-client-manager.js.map +1 -1
  14. package/dist/browser/community/rpc-local-community.d.ts +6 -1
  15. package/dist/browser/community/rpc-local-community.js +32 -0
  16. package/dist/browser/community/rpc-local-community.js.map +1 -1
  17. package/dist/browser/community/schema.d.ts +15 -0
  18. package/dist/browser/community/schema.js +16 -1
  19. package/dist/browser/community/schema.js.map +1 -1
  20. package/dist/browser/community/types.d.ts +14 -1
  21. package/dist/browser/constants.d.ts +3 -1
  22. package/dist/browser/constants.js +9 -1
  23. package/dist/browser/constants.js.map +1 -1
  24. package/dist/browser/errors.d.ts +10 -0
  25. package/dist/browser/errors.js +10 -0
  26. package/dist/browser/errors.js.map +1 -1
  27. package/dist/browser/generated-version.d.ts +1 -1
  28. package/dist/browser/generated-version.js +1 -1
  29. package/dist/browser/index-with-compile-cache.d.ts +2 -0
  30. package/dist/browser/index-with-compile-cache.js +1 -0
  31. package/dist/browser/index-with-compile-cache.js.map +1 -1
  32. package/dist/browser/index.d.ts +3 -0
  33. package/dist/browser/index.js +8 -0
  34. package/dist/browser/index.js.map +1 -1
  35. package/dist/browser/pkc/pkc.js +37 -3
  36. package/dist/browser/pkc/pkc.js.map +1 -1
  37. package/dist/browser/pkc-error.d.ts +1 -1
  38. package/dist/browser/rpc/src/index.d.ts +4 -1
  39. package/dist/browser/rpc/src/index.js +29 -1
  40. package/dist/browser/rpc/src/index.js.map +1 -1
  41. package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +1 -0
  42. package/dist/browser/runtime/node/community/local-community/anchor-publishing.d.ts +9 -0
  43. package/dist/browser/runtime/node/community/local-community/anchor-publishing.js +197 -0
  44. package/dist/browser/runtime/node/community/local-community/anchor-publishing.js.map +1 -0
  45. package/dist/browser/runtime/node/community/local-community/db-state.js +22 -4
  46. package/dist/browser/runtime/node/community/local-community/db-state.js.map +1 -1
  47. package/dist/browser/runtime/node/community/local-community/identity.d.ts +2 -0
  48. package/dist/browser/runtime/node/community/local-community/identity.js +13 -0
  49. package/dist/browser/runtime/node/community/local-community/identity.js.map +1 -0
  50. package/dist/browser/runtime/node/community/local-community/lifecycle.js +24 -0
  51. package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
  52. package/dist/browser/runtime/node/community/local-community/publication-store.js +7 -3
  53. package/dist/browser/runtime/node/community/local-community/publication-store.js.map +1 -1
  54. package/dist/browser/runtime/node/community/local-community/publication-validation.js +6 -2
  55. package/dist/browser/runtime/node/community/local-community/publication-validation.js.map +1 -1
  56. package/dist/browser/runtime/node/community/local-community.d.ts +5 -1
  57. package/dist/browser/runtime/node/community/local-community.js +47 -6
  58. package/dist/browser/runtime/node/community/local-community.js.map +1 -1
  59. package/dist/browser/schema/schema-util.d.ts +6 -0
  60. package/dist/browser/schema/schema.d.ts +1 -0
  61. package/dist/browser/schema/schema.js +11 -0
  62. package/dist/browser/schema/schema.js.map +1 -1
  63. package/dist/browser/signer/index.d.ts +1 -0
  64. package/dist/browser/signer/index.js +1 -0
  65. package/dist/browser/signer/index.js.map +1 -1
  66. package/dist/browser/signer/ipns-record.d.ts +7 -0
  67. package/dist/browser/signer/ipns-record.js +34 -0
  68. package/dist/browser/signer/ipns-record.js.map +1 -0
  69. package/dist/browser/signer/signatures.d.ts +2 -2
  70. package/dist/browser/signer/signatures.js +18 -6
  71. package/dist/browser/signer/signatures.js.map +1 -1
  72. package/dist/browser/test/test-util.d.ts +4 -0
  73. package/dist/bundled/bundle-manifest.json +43 -38
  74. package/dist/bundled/chunks/{helia-for-pkc-BPj1zAUb.js → helia-for-pkc-cKp6JSwA.js} +34 -34
  75. package/dist/bundled/chunks/{local-community-D4efR9XJ.js → local-community-B3Fhrtiy.js} +205 -38
  76. package/dist/bundled/chunks/{local-community-ChTkd8lH.js → local-community-DerKPzJm.js} +1 -1
  77. package/dist/bundled/chunks/{node-BK6GBM0d.js → node-DffqRPit.js} +41 -8
  78. package/dist/bundled/chunks/{rpc-local-community-O94vseOA.js → rpc-local-community-BdNiruAf.js} +90 -32
  79. package/dist/bundled/chunks/{schema-wNdSno5O.js → schema-BvBJX6m7.js} +23 -3
  80. package/dist/bundled/chunks/{util-iNnH2bP5.js → util-BRxHPb9G.js} +1 -1
  81. package/dist/bundled/index-with-compile-cache.js +2 -1
  82. package/dist/bundled/index.js +2 -2
  83. package/dist/bundled/rpc/src/index.js +27 -4
  84. package/dist/node/clients/rpc-client/pkc-rpc-client.d.ts +3 -1
  85. package/dist/node/clients/rpc-client/pkc-rpc-client.js +12 -1
  86. package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -1
  87. package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +18 -0
  88. package/dist/node/clients/rpc-client/rpc-schema-util.js +5 -1
  89. package/dist/node/clients/rpc-client/rpc-schema-util.js.map +1 -1
  90. package/dist/node/clients/rpc-client/schema.d.ts +15 -0
  91. package/dist/node/clients/rpc-client/schema.js +20 -0
  92. package/dist/node/clients/rpc-client/schema.js.map +1 -1
  93. package/dist/node/clients/rpc-client/types.d.ts +3 -2
  94. package/dist/node/community/community-client-manager.js +9 -9
  95. package/dist/node/community/community-client-manager.js.map +1 -1
  96. package/dist/node/community/rpc-local-community.d.ts +6 -1
  97. package/dist/node/community/rpc-local-community.js +32 -0
  98. package/dist/node/community/rpc-local-community.js.map +1 -1
  99. package/dist/node/community/schema.d.ts +15 -0
  100. package/dist/node/community/schema.js +16 -1
  101. package/dist/node/community/schema.js.map +1 -1
  102. package/dist/node/community/types.d.ts +14 -1
  103. package/dist/node/constants.d.ts +3 -1
  104. package/dist/node/constants.js +9 -1
  105. package/dist/node/constants.js.map +1 -1
  106. package/dist/node/errors.d.ts +10 -0
  107. package/dist/node/errors.js +10 -0
  108. package/dist/node/errors.js.map +1 -1
  109. package/dist/node/generated-version.d.ts +1 -1
  110. package/dist/node/generated-version.js +1 -1
  111. package/dist/node/index-with-compile-cache.d.ts +2 -0
  112. package/dist/node/index-with-compile-cache.js +1 -0
  113. package/dist/node/index-with-compile-cache.js.map +1 -1
  114. package/dist/node/index.d.ts +3 -0
  115. package/dist/node/index.js +8 -0
  116. package/dist/node/index.js.map +1 -1
  117. package/dist/node/pkc/pkc.js +37 -3
  118. package/dist/node/pkc/pkc.js.map +1 -1
  119. package/dist/node/pkc-error.d.ts +1 -1
  120. package/dist/node/rpc/src/index.d.ts +4 -1
  121. package/dist/node/rpc/src/index.js +29 -1
  122. package/dist/node/rpc/src/index.js.map +1 -1
  123. package/dist/node/rpc/src/lib/pkc-js/index.d.ts +1 -0
  124. package/dist/node/runtime/node/community/local-community/anchor-publishing.d.ts +9 -0
  125. package/dist/node/runtime/node/community/local-community/anchor-publishing.js +197 -0
  126. package/dist/node/runtime/node/community/local-community/anchor-publishing.js.map +1 -0
  127. package/dist/node/runtime/node/community/local-community/db-state.js +22 -4
  128. package/dist/node/runtime/node/community/local-community/db-state.js.map +1 -1
  129. package/dist/node/runtime/node/community/local-community/identity.d.ts +2 -0
  130. package/dist/node/runtime/node/community/local-community/identity.js +13 -0
  131. package/dist/node/runtime/node/community/local-community/identity.js.map +1 -0
  132. package/dist/node/runtime/node/community/local-community/lifecycle.js +24 -0
  133. package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
  134. package/dist/node/runtime/node/community/local-community/publication-store.js +7 -3
  135. package/dist/node/runtime/node/community/local-community/publication-store.js.map +1 -1
  136. package/dist/node/runtime/node/community/local-community/publication-validation.js +6 -2
  137. package/dist/node/runtime/node/community/local-community/publication-validation.js.map +1 -1
  138. package/dist/node/runtime/node/community/local-community.d.ts +5 -1
  139. package/dist/node/runtime/node/community/local-community.js +47 -6
  140. package/dist/node/runtime/node/community/local-community.js.map +1 -1
  141. package/dist/node/schema/schema-util.d.ts +6 -0
  142. package/dist/node/schema/schema.d.ts +1 -0
  143. package/dist/node/schema/schema.js +11 -0
  144. package/dist/node/schema/schema.js.map +1 -1
  145. package/dist/node/signer/index.d.ts +1 -0
  146. package/dist/node/signer/index.js +1 -0
  147. package/dist/node/signer/index.js.map +1 -1
  148. package/dist/node/signer/ipns-record.d.ts +7 -0
  149. package/dist/node/signer/ipns-record.js +34 -0
  150. package/dist/node/signer/ipns-record.js.map +1 -0
  151. package/dist/node/signer/signatures.d.ts +2 -2
  152. package/dist/node/signer/signatures.js +18 -6
  153. package/dist/node/signer/signatures.js.map +1 -1
  154. package/dist/node/test/test-util.d.ts +4 -0
  155. package/package.json +1 -1
  156. package/dist/bundled/chunks/{src-BKg5Lhod.js → src-BEjAH2gY.js} +1 -1
@@ -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 t$7, At as trackStartedCommunity, Bt as CommunityEditPublicationPubsubReservedFields, C as contentContainsMarkdownAudio, Ct as findUpdatingCommunity, En as CommentUpdateSchema, F as getIpnsRecordInLocalKuboNode, Fn as CommentEditPubsubMessagePublicationSchema, Ft as untrackUpdatingCommunity, G as isLinkOfAudio, Gt as CommentModerationPubsubMessagePublicationSchema, In as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, It as require_sha256, J as isLinkOfVideo, Jt as CommentModerationsTableRowSchema, K as isLinkOfImage, Kt as CommentModerationReservedFields, L as hideClassPrivateProps, Ln as CommentEditReservedFields, M as genToArray, Mr as ZodError, Mt as trackUpdatingCommunity, N as getEquivalentCommunityAddresses, Nt as untrackStartedCommunity, O as derivePublicationFromChallengeRequest, On as CommentUpdateTableRowSchema, P as getErrorCodeFromMessage, Q as isStringDomain, Qn as n$3, R as ipnsNameToIpnsOverPubsubTopic, Rt as pTimeout, S as calculateStringSizeSameAsIpfsAddCidV0, T as contentContainsMarkdownVideos, Un as AuthorReservedFields, W as isLinkOfAnimatedImage, Xn as n$4, Y as isLinkValid, Zn as t$8, _r as PKCError, _t as timestamp, a as ChallengeRequestMessageSchema, ar as t$4, at as removeNullUndefinedValues, b as areEquivalentCommunityAddresses, bt as findCommunityInRegistry, cr as t$5, d as DecryptedChallengeRequestSchema, dr as require_retry, dt as retryKuboIpfsAddAndProvide, er as t$6, fn as VotePubsubMessagePublicationSchema, hn as VoteTablesRowSchema, ht as statMfsPathSafely, ir as r$1, k as doesDomainAddressHaveCapitalLetter, kn as CommentsTableRowSchema, kt as syncCommunityRegistryEntry, lr as t$3, lt as retryKuboBlockPutPinAndProvidePubsubTopic, mt as sleepUntilTimeoutOrAbort, nn as CommunityIpfsSchema, nr as e$1, nt as removeBlocksFromKuboNode, pn as VotePubsubReservedFields, q as isLinkOfMedia, r as ChallengeMessageSchema, rn as CommunitySignedPropertyNames, rt as removeMfsFilesSafely, s as ChallengeVerificationMessageSchema, t as ChallengeAnswerMessageSchema, tr as e, u as DecryptedChallengeRequestPublicationSchema, vn as CommentIpfsSchema, vr as messages, w as contentContainsMarkdownImages, x as calculateIpfsCidV0, xt as findStartedCommunity, y as version_default, yn as CommentPubsubMessageReservedFields, yr as logger_default, yt as writeKuboFilesWithTimeout, zn as CommentEditsTableRowSchema } from "./schema-wNdSno5O.js";
3
- import { $n as t$10, A as deriveDbPosts, At as verifyCommunityEdit, Bt as getCommunityPublicKeyFromWire, C as BackupAbortError, Dt as verifyCommentPubsubMessage, E as calculateInlineRepliesBudget, Et as verifyCommentModeration, F as importSignerIntoKuboNode, Ft as getAuthorNameFromWire, G as REPLY_REPLIES_SORT_TYPES, Gt as getIpfsKeyFromPrivateKey, Ht as decode, Jn as r$2, Jt as getPublicKeyFromPrivateKey, K as TIMEFRAMES_TO_SECONDS, Kn as t$9, Kt as getPKCAddressFromPublicKey, M as getDefaultCommunityDbConfig, Mt as buildRuntimeAuthor, Nt as cleanWireAuthor, O as deleteOldCommunityInWindows, Ot as verifyCommentUpdate, P as getThumbnailPropsOfLink, R as moveCommunityDbToDeletedDirectory, S as encryptEd25519AesGcmPublicKeyBuffer, St as verifyChallengeRequest, T as calculateExpectedSignatureSize, Tt as verifyCommentIpfs, U as POSTS_SORT_TYPES, Ut as encode, W as POST_REPLIES_SORT_TYPES, Xn as n$6, Yn as t$11, Yt as createSchemaRowParser, Z as iterateOverPageCidsToFindAllCids, Zn as n$5, _ as SignerWithPublicKeyAddress, _t as signCommunity, a as pkcJsChallenges, b as decryptEd25519AesGcmPublicKeyBuffer, bt as verifyChallengeAnswer, cn as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, d as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, dt as signChallengeVerification, er as stringify, f as KeyvBetterSqlite3, ft as signComment, gt as signCommentUpdateForChallengeVerification, ht as signCommentUpdate, i as getCommunityChallengeFromCommunityChallengeSettings, it as pLimit, j as deriveDbReplies, jt as verifyVote, k as deriveCommentIpfsFromCommentTableRow, kt as verifyCommunity, l as normalizeSelfAddrsForProvider, lt as signChallengeMessage, nr as require_lodash_merge, o as TrackedInstanceRegistry, on as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, pt as signCommentEdit, qn as t$12, qt as getPKCAddressFromPublicKeySync, r as getChallengeVerification, s as LRUCache, st as cleanUpBeforePublishing, t as RpcLocalCommunity, tr as STORAGE_KEYS, vn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, w as backupCommunityDb, wt as verifyCommentEdit, xn as parseJsonWithPKCErrorIfFails, z as resolveDbPostsCidRefs, zt as getCommunityNameFromWire } from "./rpc-local-community-O94vseOA.js";
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 path from "node:path";
6
+ import Path from "node:path";
7
7
  import os from "os";
8
8
  import { existsSync, promises } from "node:fs";
9
- import path$1 from "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.signer.address) return messages.ERR_PUBLICATION_INVALID_COMMUNITY_PUBLIC_KEY;
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.signer.address;
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.signer.address;
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.signer.address;
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$1.join(path$1.dirname(dbPath), ".backup_before_migration", `${path$1.basename(dbPath)}.${currentDbVersion}.${timestamp()}`);
3287
- log(`Copying db ${path$1.basename(dbPath)} to ${backupDbPath} before migration`);
3288
- if (!fs.existsSync(path$1.dirname(backupDbPath))) await fs.promises.mkdir(path$1.dirname(backupDbPath), { recursive: true });
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$1.join(dataPath, "communities", oldDbName);
5100
- const newPathString = path$1.join(dataPath, "communities", newDbName);
5101
- await fs.promises.mkdir(path$1.dirname(oldPathString), { recursive: true });
5102
- await fs.promises.mkdir(path$1.dirname(newPathString), { recursive: true });
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$1.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
5125
- const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", communityAddress);
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$1.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
5147
- const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", communityAddress);
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$1.join(this._community._pkc.dataPath, "communities", `${communityAddress}.start.lock`);
5159
- const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", communityAddress);
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$1.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
5169
- const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", this._community.address);
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$1.join(this._community._pkc.dataPath, "communities", `${this._community.address}.state.lock`);
5187
- const communityDbPath = path$1.join(this._community._pkc.dataPath, "communities", this._community.address);
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$1.join(this._community._pkc.dataPath, "communities", this._community.address);
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 path.join(community._pkc.dataPath, "exports", `${exportId}.sqlite`);
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 path.join(community._pkc.dataPath, "communities", community.address);
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 ? path.resolve(options.exportPath) : defaultExportPathFor(community, exportId);
7143
+ const destPath = options.exportPath ? Path.resolve(options.exportPath) : defaultExportPathFor(community, exportId);
7000
7144
  const includePrivateKey = options.includePrivateKey === true;
7001
- if (path.resolve(destPath) === path.resolve(sourceDbPathFor(community))) throw new PKCError("ERR_EXPORT_PATH_TARGETS_LIVE_DB", {
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, ["started", "startedState"]),
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, ["started", "startedState"]),
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
- communityIpnsName: this.signer.address,
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 signer.address ${this.signer.address}`);
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
- if (resolvedIpnsFromNewDomain !== this.signer.address) throw new PKCError("ERR_DOMAIN_COMMUNITY_ADDRESS_TXT_RECORD_POINT_TO_DIFFERENT_ADDRESS", {
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-D4efR9XJ.js";
1
+ import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-B3Fhrtiy.js";
2
2
  export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };