@bitsocial/bitsocial-react-hooks 0.1.53 → 0.1.55
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/CHANGELOG.md +23 -0
- package/dist/hooks/accounts/accounts.js +2 -2
- package/dist/hooks/accounts/accounts.js.map +1 -1
- package/dist/hooks/accounts/utils.d.ts.map +1 -1
- package/dist/hooks/accounts/utils.js +3 -12
- package/dist/hooks/accounts/utils.js.map +1 -1
- package/dist/hooks/actions/actions.js +1 -1
- package/dist/hooks/actions/actions.js.map +1 -1
- package/dist/hooks/authors/author-avatars.js +1 -1
- package/dist/hooks/authors/author-avatars.js.map +1 -1
- package/dist/hooks/authors/authors.js +1 -1
- package/dist/hooks/authors/authors.js.map +1 -1
- package/dist/hooks/authors/utils.d.ts.map +1 -1
- package/dist/hooks/authors/utils.js +1 -13
- package/dist/hooks/authors/utils.js.map +1 -1
- package/dist/hooks/comments.d.ts +7 -1
- package/dist/hooks/comments.d.ts.map +1 -1
- package/dist/hooks/comments.js +31 -1
- package/dist/hooks/comments.js.map +1 -1
- package/dist/hooks/communities.js +1 -1
- package/dist/hooks/communities.js.map +1 -1
- package/dist/hooks/feeds/feeds.js +1 -1
- package/dist/hooks/feeds/feeds.js.map +1 -1
- package/dist/hooks/pkc-rpc.js +1 -1
- package/dist/hooks/pkc-rpc.js.map +1 -1
- package/dist/hooks/replies.js +1 -1
- package/dist/hooks/replies.js.map +1 -1
- package/dist/hooks/states.js +1 -1
- package/dist/hooks/states.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/assert.d.ts +6 -0
- package/dist/lib/assert.d.ts.map +1 -0
- package/dist/lib/assert.js +17 -0
- package/dist/lib/assert.js.map +1 -0
- package/dist/lib/chain/chain.js +1 -1
- package/dist/lib/chain/chain.js.map +1 -1
- package/dist/lib/community-ref.js +1 -1
- package/dist/lib/community-ref.js.map +1 -1
- package/dist/lib/crosspost.js +1 -1
- package/dist/lib/crosspost.js.map +1 -1
- package/dist/lib/is-equal.d.ts +6 -0
- package/dist/lib/is-equal.d.ts.map +1 -0
- package/dist/lib/is-equal.js +100 -0
- package/dist/lib/is-equal.js.map +1 -0
- package/dist/lib/memoize.d.ts +9 -0
- package/dist/lib/memoize.d.ts.map +1 -0
- package/dist/lib/memoize.js +24 -0
- package/dist/lib/memoize.js.map +1 -0
- package/dist/lib/pkc-address.d.ts +2 -0
- package/dist/lib/pkc-address.d.ts.map +1 -0
- package/dist/lib/pkc-address.js +16 -0
- package/dist/lib/pkc-address.js.map +1 -0
- package/dist/lib/pkc-compat.js +1 -1
- package/dist/lib/pkc-compat.js.map +1 -1
- package/dist/lib/pkc-js/index.d.ts.map +1 -1
- package/dist/lib/pkc-js/index.js +23 -12
- package/dist/lib/pkc-js/index.js.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock-content.js +1 -1
- package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -1
- package/dist/lib/protocol-compat.js +1 -1
- package/dist/lib/protocol-compat.js.map +1 -1
- package/dist/lib/utils/utils.js +1 -1
- package/dist/lib/utils/utils.js.map +1 -1
- package/dist/lib/validate-comment.d.ts +11 -0
- package/dist/lib/validate-comment.d.ts.map +1 -0
- package/dist/lib/validate-comment.js +133 -0
- package/dist/lib/validate-comment.js.map +1 -0
- package/dist/lib/validator.js +1 -1
- package/dist/lib/validator.js.map +1 -1
- package/dist/stores/accounts/accounts-actions-internal.js +2 -2
- package/dist/stores/accounts/accounts-actions-internal.js.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +2 -2
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/stores/accounts/accounts-database.js +2 -2
- package/dist/stores/accounts/accounts-database.js.map +1 -1
- package/dist/stores/accounts/accounts-store.js +1 -1
- package/dist/stores/accounts/accounts-store.js.map +1 -1
- package/dist/stores/accounts/utils.js +1 -1
- package/dist/stores/accounts/utils.js.map +1 -1
- package/dist/stores/authors-comments/authors-comments-store.js +1 -1
- package/dist/stores/authors-comments/authors-comments-store.js.map +1 -1
- package/dist/stores/authors-comments/utils.js.map +1 -1
- package/dist/stores/communities/communities-store.d.ts.map +1 -1
- package/dist/stores/communities/communities-store.js +53 -11
- package/dist/stores/communities/communities-store.js.map +1 -1
- package/dist/stores/communities-pages/communities-pages-store.js +1 -1
- package/dist/stores/communities-pages/communities-pages-store.js.map +1 -1
- package/dist/stores/feeds/feeds-store.js +1 -1
- package/dist/stores/feeds/feeds-store.js.map +1 -1
- package/dist/stores/feeds/utils.js.map +1 -1
- package/dist/stores/replies/replies-store.js +1 -1
- package/dist/stores/replies/replies-store.js.map +1 -1
- package/dist/stores/replies/utils.js.map +1 -1
- package/dist/stores/replies-pages/replies-pages-store.js +1 -1
- package/dist/stores/replies-pages/replies-pages-store.js.map +1 -1
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/utils/utils.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAG7C,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,mCAAmC,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,MAAM,GAAG,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC;AAElD,MAAM,KAAK,GAAG,CAAC,GAAG,IAAS,EAAE,EAAE;IAC7B,aAAa;IACb,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACl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,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;YACtF,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC3D,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;AACH,CAAC,CAAA,CAAC;AACF,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;AAEpC,eAAe,KAAK,CAAC","sourcesContent":["import assert from \"assert\";\nimport QuickLru from \"quick-lru\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nimport PkcJs from \"../pkc-js\";\nimport { Comment } from \"../../types\";\nimport { areEquivalentCommunityAddresses } from \"../community-address\";\nimport { getCommentCommunityAddress, normalizePublicationOptionsForStore } from \"../pkc-compat\";\nimport { getPageRpcClients } from \"../pkc-compat\";\nconst log = Logger(\"bitsocial-react-hooks:utils\");\n\nconst merge = (...args: any) => {\n // @ts-ignore\n const clonedArgs = args.map((arg) => {\n assert(arg && typeof arg === \"object\", `utils.merge argument '${arg}' not an object`);\n return clone(arg);\n });\n const mergedObj: any = {};\n while (clonedArgs.length) {\n const currentArg = clonedArgs.shift();\n for (const i in currentArg) {\n if (currentArg[i] === undefined || currentArg[i] === null) {\n continue;\n }\n mergedObj[i] = currentArg[i];\n }\n }\n return mergedObj;\n};\n\nconst clone = (obj: any) => {\n assert(obj && typeof obj === \"object\", `utils.clone argument '${obj}' not an object`);\n let clonedObj: any = {};\n\n // clean the object to be cloned\n for (const i in obj) {\n // remove functions\n if (typeof obj[i] === \"function\") {\n continue;\n }\n // remove internal props\n if (i.startsWith(\"_\")) {\n continue;\n }\n if (obj[i] === undefined || obj[i] === null) {\n continue;\n }\n // pkc-js has a bug where pkc instances have circular deps\n if (obj[i]?.constructor?.name === \"PKC\") {\n continue;\n }\n clonedObj[i] = obj[i];\n }\n\n // clone the object\n clonedObj = JSON.parse(JSON.stringify(clonedObj));\n return clonedObj;\n};\n\n// this function should not clone the comments to not waste memory\nexport const flattenCommentsPages = (pageInstanceOrPagesInstance: any) => {\n const flattenedComments = [];\n\n // if is a Page instance\n if (pageInstanceOrPagesInstance?.comments) {\n for (const comment of pageInstanceOrPagesInstance.comments) {\n flattenedComments.push(comment);\n if (comment.replies?.pages && Object.keys(comment.replies.pages).length) {\n flattenedComments.push(...flattenCommentsPages(comment.replies));\n }\n }\n }\n\n // if is a Pages instance\n else if (pageInstanceOrPagesInstance?.pages) {\n for (const sortType in pageInstanceOrPagesInstance.pages) {\n flattenedComments.push(...flattenCommentsPages(pageInstanceOrPagesInstance.pages[sortType]));\n }\n }\n\n // if is a Pages.pages instance\n else {\n for (const sortType in pageInstanceOrPagesInstance) {\n const page = pageInstanceOrPagesInstance[sortType];\n if (page?.comments?.length) {\n flattenedComments.push(...flattenCommentsPages(page));\n }\n }\n }\n\n // remove duplicate comments\n const flattenedCommentsObject = {};\n for (const comment of flattenedComments) {\n // @ts-ignore\n flattenedCommentsObject[comment.cid] = comment;\n }\n const uniqueFlattened = [];\n for (const cid in flattenedCommentsObject) {\n // @ts-ignore\n uniqueFlattened.push(flattenedCommentsObject[cid]);\n }\n\n return uniqueFlattened;\n};\n\nconst memo = (functionToMemo: Function, memoOptions: any) => {\n assert(typeof functionToMemo === \"function\", `memo first argument must be a function`);\n const pendingPromises: any = new Map();\n const cache = new QuickLru(memoOptions);\n\n // preserve function name\n const memoedFunctionName = functionToMemo.name || \"memoedFunction\";\n const obj = {\n [memoedFunctionName]: async (...args: any) => {\n let cacheKey = args[0];\n if (args.length > 1) {\n cacheKey = \"\";\n for (const arg of args) {\n if (\n typeof arg !== \"string\" &&\n typeof arg !== \"number\" &&\n arg !== undefined &&\n arg !== null\n ) {\n const argumentIndex = args.indexOf(arg);\n throw Error(\n `memoed function '${memoedFunctionName}' invalid argument number '${argumentIndex}' '${arg}', memoed function can only use multiple arguments if they are all of type string, number, undefined or null`,\n );\n }\n cacheKey += arg;\n }\n }\n\n // has cached result\n const cached = cache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n // don't request the same thing twice if fetching is pending\n let pendingPromise = pendingPromises.get(cacheKey);\n if (pendingPromise) {\n return pendingPromise;\n }\n\n // create the pending promise\n let resolve: any, reject: any;\n pendingPromise = new Promise((_resolve, _reject) => {\n resolve = _resolve;\n reject = _reject;\n });\n pendingPromises.set(cacheKey, pendingPromise);\n\n // execute the function\n try {\n const result = await functionToMemo(...args);\n cache.set(cacheKey, result);\n pendingPromises.delete(cacheKey);\n resolve?.(result);\n } catch (error) {\n pendingPromises.delete(cacheKey);\n reject?.(error);\n }\n\n return pendingPromise;\n },\n };\n return obj[memoedFunctionName];\n};\n\nconst memoSync = (functionToMemo: Function, memoOptions: any) => {\n assert(typeof functionToMemo === \"function\", `memo first argument must be a function`);\n const cache = new QuickLru(memoOptions);\n\n // preserve function name\n const memoedFunctionName = functionToMemo.name || \"memoedFunction\";\n const obj = {\n [memoedFunctionName]: (...args: any) => {\n let cacheKey = args[0];\n if (args.length > 1) {\n cacheKey = \"\";\n for (const arg of args) {\n if (\n typeof arg !== \"string\" &&\n typeof arg !== \"number\" &&\n arg !== undefined &&\n arg !== null\n ) {\n const argumentIndex = args.indexOf(arg);\n throw Error(\n `memoed function '${memoedFunctionName}' invalid argument number '${argumentIndex}' '${arg}', memoed function can only use multiple arguments if they are all of type string, number, undefined or null`,\n );\n }\n cacheKey += arg;\n }\n }\n\n // has cached result\n const cached = cache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n // execute the function\n const result = functionToMemo(...args);\n if (typeof result?.then === \"function\") {\n throw Error(\n `memoed function '${memoedFunctionName}' is an async function, cannot be used with memoSync, use memo instead`,\n );\n }\n cache.set(cacheKey, result);\n return result;\n },\n };\n return obj[memoedFunctionName];\n};\n\nconst clientsOnStateChange = (clients: any, onStateChange: Function) => {\n for (const clientUrl in clients?.ipfsGateways) {\n clients?.ipfsGateways?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"ipfsGateways\", clientUrl),\n );\n }\n for (const clientUrl in clients?.kuboRpcClients) {\n clients?.kuboRpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"kuboRpcClients\", clientUrl),\n );\n }\n for (const clientUrl in clients?.pubsubKuboRpcClients) {\n clients?.pubsubKuboRpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pubsubKuboRpcClients\", clientUrl),\n );\n }\n const rpcClients = getPageRpcClients(clients);\n for (const clientUrl in rpcClients) {\n rpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pkcRpcClients\", clientUrl),\n );\n }\n for (const clientUrl in clients?.libp2pJsClients) {\n clients?.libp2pJsClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"libp2pJsClients\", clientUrl),\n );\n }\n for (const chainTicker in clients?.chainProviders) {\n for (const clientUrl in clients?.chainProviders?.[chainTicker]) {\n clients?.chainProviders?.[chainTicker]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"chainProviders\", clientUrl, chainTicker),\n );\n }\n }\n for (const resolverKey in clients?.nameResolvers) {\n clients?.nameResolvers?.[resolverKey].on(\"statechange\", (state: string) =>\n onStateChange(state, \"nameResolvers\", resolverKey),\n );\n }\n};\n\nconst pageClientsOnStateChange = (clients: any, onStateChange: Function) => {\n for (const sortType in clients?.ipfsGateways) {\n for (const clientUrl in clients?.ipfsGateways?.[sortType]) {\n clients?.ipfsGateways?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"ipfsGateways\", sortType, clientUrl),\n );\n }\n }\n for (const sortType in clients?.kuboRpcClients) {\n for (const clientUrl in clients?.kuboRpcClients?.[sortType]) {\n clients?.kuboRpcClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"kuboRpcClients\", sortType, clientUrl),\n );\n }\n }\n const rpcPageClients = getPageRpcClients(clients);\n for (const sortType in rpcPageClients) {\n for (const clientUrl in rpcPageClients?.[sortType]) {\n rpcPageClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pkcRpcClients\", sortType, clientUrl),\n );\n }\n }\n for (const sortType in clients?.libp2pJsClients) {\n for (const clientUrl in clients?.libp2pJsClients?.[sortType]) {\n clients?.libp2pJsClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"libp2pJsClients\", sortType, clientUrl),\n );\n }\n }\n};\n\nexport const communityPostsCacheExpired = (community: any) => {\n // NOTE: fetchedAt is undefined on owner communities\n if (!community || community.fetchedAt == null) {\n return false;\n }\n // if community cache is older than 1 hour, its community.posts are considered expired\n const oneHourAgo = Date.now() / 1000 - 60 * 60;\n return oneHourAgo > community.fetchedAt;\n};\n\nexport const removeInvalidComments = async (\n comments: Comment[],\n { validateReplies, blockCommunity }: any,\n pkc: any,\n) => {\n if (!comments.length) {\n return [];\n }\n const isValid = await Promise.all(\n comments.map((comment) => commentIsValid(comment, { validateReplies, blockCommunity }, pkc)),\n );\n const validComments = comments.filter((_, i) => isValid[i]);\n return validComments;\n};\n\nconst communitiesWithInvalidComments: { [communityAddress: string]: boolean } = {};\nexport const commentIsValid = async (\n comment: Comment,\n { validateReplies, blockCommunity }: any = {},\n pkc: any,\n) => {\n validateReplies = Boolean(validateReplies);\n if (blockCommunity === undefined || blockCommunity === null) {\n blockCommunity = true;\n }\n if (!comment) {\n return false;\n }\n if (communitiesWithInvalidComments[comment.communityAddress]) {\n console.log(\n `community '${comment.communityAddress}' had an invalid comment, invalidate all its future comments to avoid wasting resources`,\n );\n return false;\n }\n try {\n await pkc.validateComment(comment, { validateReplies });\n } catch (e) {\n if (blockCommunity) {\n communitiesWithInvalidComments[comment.communityAddress] = true;\n }\n console.log(\"invalid comment\", { comment, error: e });\n return false;\n }\n return true;\n};\n\nconst repliesAreValid = async (\n comment: Comment,\n { validateReplies, blockCommunity }: any = {},\n pkc: any,\n) => {\n validateReplies = Boolean(validateReplies);\n if (blockCommunity === undefined || blockCommunity === null) {\n blockCommunity = true;\n }\n if (!comment) {\n return false;\n }\n const commentCommunityAddress = getCommentCommunityAddress(comment);\n if (commentCommunityAddress && communitiesWithInvalidComments[commentCommunityAddress]) {\n console.log(\n `community '${commentCommunityAddress}' had an invalid comment, invalidate all its future comments to avoid wasting resources`,\n );\n return false;\n }\n const replyPageArray: any[] = Object.values(comment.replies?.pages || {});\n const replies = replyPageArray.flatMap((replyPage: any) => replyPage?.comments || []);\n const normalizedReplies = replies.map((reply) => {\n const normalizedReply = normalizePublicationOptionsForStore(reply) as Comment;\n normalizedReply.communityAddress =\n getCommentCommunityAddress(normalizedReply) || commentCommunityAddress;\n return normalizedReply;\n });\n\n // manual validation\n for (const reply of normalizedReplies) {\n if (\n !areEquivalentCommunityAddresses(\n getCommentCommunityAddress(reply),\n commentCommunityAddress,\n ) ||\n reply.depth !== comment.depth + 1 ||\n reply.parentCid !== comment.cid\n ) {\n if (blockCommunity && commentCommunityAddress) {\n communitiesWithInvalidComments[commentCommunityAddress] = true;\n }\n console.log(\"invalid comment\", {\n comment: reply,\n error:\n \"!areEquivalentCommunityAddresses(reply.communityAddress, comment.communityAddress) || reply.depth !== comment.depth + 1 || reply.parentCid !== comment.cid\",\n });\n return false;\n }\n }\n\n // signature verification\n try {\n const promises = normalizedReplies.map((reply) =>\n commentIsValid(reply, { validateReplies: false, blockCommunity: true }, pkc),\n );\n await Promise.all(promises);\n } catch (e: any) {\n if (blockCommunity && commentCommunityAddress) {\n communitiesWithInvalidComments[commentCommunityAddress] = true;\n }\n console.log(\"invalid comment\", { comment, error: e });\n return false;\n }\n return true;\n};\n\nconst utils = {\n merge,\n clone,\n flattenCommentsPages,\n memo,\n memoSync,\n retryInfinity: (f: any, o?: any): any => {},\n // export timeout values to mock them in tests\n retryInfinityMinTimeout: 1000,\n retryInfinityMaxTimeout: 1000 * 60 * 60 * 24,\n clientsOnStateChange,\n pageClientsOnStateChange,\n communityPostsCacheExpired,\n commentIsValid,\n removeInvalidComments,\n repliesAreValid,\n};\n\nconst retryInfinity = async (functionToRetry: any, options?: any) => {\n const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));\n let attempt = 0;\n while (true) {\n try {\n const res = await functionToRetry();\n return res;\n } catch (e) {\n options?.onError(e || Error(`retryInfinity failed attempt ${attempt}`));\n const factor = 2;\n let timeout = Math.round(utils.retryInfinityMinTimeout * Math.pow(factor, attempt++));\n timeout = Math.min(timeout, utils.retryInfinityMaxTimeout);\n await sleep(timeout);\n }\n }\n};\nutils.retryInfinity = retryInfinity;\n\nexport default utils;\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/utils/utils.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAG7C,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,mCAAmC,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,MAAM,GAAG,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC;AAElD,MAAM,KAAK,GAAG,CAAC,GAAG,IAAS,EAAE,EAAE;IAC7B,aAAa;IACb,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAClC,MAAM,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,yBAAyB,GAAG,iBAAiB,CAAC,CAAC;QACtF,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;IACH,MAAM,SAAS,GAAQ,EAAE,CAAC;IAC1B,OAAO,UAAU,CAAC,MAAM,EAAE,CAAC;QACzB,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC;QACtC,KAAK,MA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";\nimport QuickLru from \"quick-lru\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nimport PkcJs from \"../pkc-js\";\nimport { Comment } from \"../../types\";\nimport { areEquivalentCommunityAddresses } from \"../community-address\";\nimport { getCommentCommunityAddress, normalizePublicationOptionsForStore } from \"../pkc-compat\";\nimport { getPageRpcClients } from \"../pkc-compat\";\nconst log = Logger(\"bitsocial-react-hooks:utils\");\n\nconst merge = (...args: any) => {\n // @ts-ignore\n const clonedArgs = args.map((arg) => {\n assert(arg && typeof arg === \"object\", `utils.merge argument '${arg}' not an object`);\n return clone(arg);\n });\n const mergedObj: any = {};\n while (clonedArgs.length) {\n const currentArg = clonedArgs.shift();\n for (const i in currentArg) {\n if (currentArg[i] === undefined || currentArg[i] === null) {\n continue;\n }\n mergedObj[i] = currentArg[i];\n }\n }\n return mergedObj;\n};\n\nconst clone = (obj: any) => {\n assert(obj && typeof obj === \"object\", `utils.clone argument '${obj}' not an object`);\n let clonedObj: any = {};\n\n // clean the object to be cloned\n for (const i in obj) {\n // remove functions\n if (typeof obj[i] === \"function\") {\n continue;\n }\n // remove internal props\n if (i.startsWith(\"_\")) {\n continue;\n }\n if (obj[i] === undefined || obj[i] === null) {\n continue;\n }\n // pkc-js has a bug where pkc instances have circular deps\n if (obj[i]?.constructor?.name === \"PKC\") {\n continue;\n }\n clonedObj[i] = obj[i];\n }\n\n // clone the object\n clonedObj = JSON.parse(JSON.stringify(clonedObj));\n return clonedObj;\n};\n\n// this function should not clone the comments to not waste memory\nexport const flattenCommentsPages = (pageInstanceOrPagesInstance: any) => {\n const flattenedComments = [];\n\n // if is a Page instance\n if (pageInstanceOrPagesInstance?.comments) {\n for (const comment of pageInstanceOrPagesInstance.comments) {\n flattenedComments.push(comment);\n if (comment.replies?.pages && Object.keys(comment.replies.pages).length) {\n flattenedComments.push(...flattenCommentsPages(comment.replies));\n }\n }\n }\n\n // if is a Pages instance\n else if (pageInstanceOrPagesInstance?.pages) {\n for (const sortType in pageInstanceOrPagesInstance.pages) {\n flattenedComments.push(...flattenCommentsPages(pageInstanceOrPagesInstance.pages[sortType]));\n }\n }\n\n // if is a Pages.pages instance\n else {\n for (const sortType in pageInstanceOrPagesInstance) {\n const page = pageInstanceOrPagesInstance[sortType];\n if (page?.comments?.length) {\n flattenedComments.push(...flattenCommentsPages(page));\n }\n }\n }\n\n // remove duplicate comments\n const flattenedCommentsObject = {};\n for (const comment of flattenedComments) {\n // @ts-ignore\n flattenedCommentsObject[comment.cid] = comment;\n }\n const uniqueFlattened = [];\n for (const cid in flattenedCommentsObject) {\n // @ts-ignore\n uniqueFlattened.push(flattenedCommentsObject[cid]);\n }\n\n return uniqueFlattened;\n};\n\nconst memo = (functionToMemo: Function, memoOptions: any) => {\n assert(typeof functionToMemo === \"function\", `memo first argument must be a function`);\n const pendingPromises: any = new Map();\n const cache = new QuickLru(memoOptions);\n\n // preserve function name\n const memoedFunctionName = functionToMemo.name || \"memoedFunction\";\n const obj = {\n [memoedFunctionName]: async (...args: any) => {\n let cacheKey = args[0];\n if (args.length > 1) {\n cacheKey = \"\";\n for (const arg of args) {\n if (\n typeof arg !== \"string\" &&\n typeof arg !== \"number\" &&\n arg !== undefined &&\n arg !== null\n ) {\n const argumentIndex = args.indexOf(arg);\n throw Error(\n `memoed function '${memoedFunctionName}' invalid argument number '${argumentIndex}' '${arg}', memoed function can only use multiple arguments if they are all of type string, number, undefined or null`,\n );\n }\n cacheKey += arg;\n }\n }\n\n // has cached result\n const cached = cache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n // don't request the same thing twice if fetching is pending\n let pendingPromise = pendingPromises.get(cacheKey);\n if (pendingPromise) {\n return pendingPromise;\n }\n\n // create the pending promise\n let resolve: any, reject: any;\n pendingPromise = new Promise((_resolve, _reject) => {\n resolve = _resolve;\n reject = _reject;\n });\n pendingPromises.set(cacheKey, pendingPromise);\n\n // execute the function\n try {\n const result = await functionToMemo(...args);\n cache.set(cacheKey, result);\n pendingPromises.delete(cacheKey);\n resolve?.(result);\n } catch (error) {\n pendingPromises.delete(cacheKey);\n reject?.(error);\n }\n\n return pendingPromise;\n },\n };\n return obj[memoedFunctionName];\n};\n\nconst memoSync = (functionToMemo: Function, memoOptions: any) => {\n assert(typeof functionToMemo === \"function\", `memo first argument must be a function`);\n const cache = new QuickLru(memoOptions);\n\n // preserve function name\n const memoedFunctionName = functionToMemo.name || \"memoedFunction\";\n const obj = {\n [memoedFunctionName]: (...args: any) => {\n let cacheKey = args[0];\n if (args.length > 1) {\n cacheKey = \"\";\n for (const arg of args) {\n if (\n typeof arg !== \"string\" &&\n typeof arg !== \"number\" &&\n arg !== undefined &&\n arg !== null\n ) {\n const argumentIndex = args.indexOf(arg);\n throw Error(\n `memoed function '${memoedFunctionName}' invalid argument number '${argumentIndex}' '${arg}', memoed function can only use multiple arguments if they are all of type string, number, undefined or null`,\n );\n }\n cacheKey += arg;\n }\n }\n\n // has cached result\n const cached = cache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n // execute the function\n const result = functionToMemo(...args);\n if (typeof result?.then === \"function\") {\n throw Error(\n `memoed function '${memoedFunctionName}' is an async function, cannot be used with memoSync, use memo instead`,\n );\n }\n cache.set(cacheKey, result);\n return result;\n },\n };\n return obj[memoedFunctionName];\n};\n\nconst clientsOnStateChange = (clients: any, onStateChange: Function) => {\n for (const clientUrl in clients?.ipfsGateways) {\n clients?.ipfsGateways?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"ipfsGateways\", clientUrl),\n );\n }\n for (const clientUrl in clients?.kuboRpcClients) {\n clients?.kuboRpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"kuboRpcClients\", clientUrl),\n );\n }\n for (const clientUrl in clients?.pubsubKuboRpcClients) {\n clients?.pubsubKuboRpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pubsubKuboRpcClients\", clientUrl),\n );\n }\n const rpcClients = getPageRpcClients(clients);\n for (const clientUrl in rpcClients) {\n rpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pkcRpcClients\", clientUrl),\n );\n }\n for (const clientUrl in clients?.libp2pJsClients) {\n clients?.libp2pJsClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"libp2pJsClients\", clientUrl),\n );\n }\n for (const chainTicker in clients?.chainProviders) {\n for (const clientUrl in clients?.chainProviders?.[chainTicker]) {\n clients?.chainProviders?.[chainTicker]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"chainProviders\", clientUrl, chainTicker),\n );\n }\n }\n for (const resolverKey in clients?.nameResolvers) {\n clients?.nameResolvers?.[resolverKey].on(\"statechange\", (state: string) =>\n onStateChange(state, \"nameResolvers\", resolverKey),\n );\n }\n};\n\nconst pageClientsOnStateChange = (clients: any, onStateChange: Function) => {\n for (const sortType in clients?.ipfsGateways) {\n for (const clientUrl in clients?.ipfsGateways?.[sortType]) {\n clients?.ipfsGateways?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"ipfsGateways\", sortType, clientUrl),\n );\n }\n }\n for (const sortType in clients?.kuboRpcClients) {\n for (const clientUrl in clients?.kuboRpcClients?.[sortType]) {\n clients?.kuboRpcClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"kuboRpcClients\", sortType, clientUrl),\n );\n }\n }\n const rpcPageClients = getPageRpcClients(clients);\n for (const sortType in rpcPageClients) {\n for (const clientUrl in rpcPageClients?.[sortType]) {\n rpcPageClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pkcRpcClients\", sortType, clientUrl),\n );\n }\n }\n for (const sortType in clients?.libp2pJsClients) {\n for (const clientUrl in clients?.libp2pJsClients?.[sortType]) {\n clients?.libp2pJsClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"libp2pJsClients\", sortType, clientUrl),\n );\n }\n }\n};\n\nexport const communityPostsCacheExpired = (community: any) => {\n // NOTE: fetchedAt is undefined on owner communities\n if (!community || community.fetchedAt == null) {\n return false;\n }\n // if community cache is older than 1 hour, its community.posts are considered expired\n const oneHourAgo = Date.now() / 1000 - 60 * 60;\n return oneHourAgo > community.fetchedAt;\n};\n\nexport const removeInvalidComments = async (\n comments: Comment[],\n { validateReplies, blockCommunity }: any,\n pkc: any,\n) => {\n if (!comments.length) {\n return [];\n }\n const isValid = await Promise.all(\n comments.map((comment) => commentIsValid(comment, { validateReplies, blockCommunity }, pkc)),\n );\n const validComments = comments.filter((_, i) => isValid[i]);\n return validComments;\n};\n\nconst communitiesWithInvalidComments: { [communityAddress: string]: boolean } = {};\nexport const commentIsValid = async (\n comment: Comment,\n { validateReplies, blockCommunity }: any = {},\n pkc: any,\n) => {\n validateReplies = Boolean(validateReplies);\n if (blockCommunity === undefined || blockCommunity === null) {\n blockCommunity = true;\n }\n if (!comment) {\n return false;\n }\n if (communitiesWithInvalidComments[comment.communityAddress]) {\n console.log(\n `community '${comment.communityAddress}' had an invalid comment, invalidate all its future comments to avoid wasting resources`,\n );\n return false;\n }\n try {\n await pkc.validateComment(comment, { validateReplies });\n } catch (e) {\n if (blockCommunity) {\n communitiesWithInvalidComments[comment.communityAddress] = true;\n }\n console.log(\"invalid comment\", { comment, error: e });\n return false;\n }\n return true;\n};\n\nconst repliesAreValid = async (\n comment: Comment,\n { validateReplies, blockCommunity }: any = {},\n pkc: any,\n) => {\n validateReplies = Boolean(validateReplies);\n if (blockCommunity === undefined || blockCommunity === null) {\n blockCommunity = true;\n }\n if (!comment) {\n return false;\n }\n const commentCommunityAddress = getCommentCommunityAddress(comment);\n if (commentCommunityAddress && communitiesWithInvalidComments[commentCommunityAddress]) {\n console.log(\n `community '${commentCommunityAddress}' had an invalid comment, invalidate all its future comments to avoid wasting resources`,\n );\n return false;\n }\n const replyPageArray: any[] = Object.values(comment.replies?.pages || {});\n const replies = replyPageArray.flatMap((replyPage: any) => replyPage?.comments || []);\n const normalizedReplies = replies.map((reply) => {\n const normalizedReply = normalizePublicationOptionsForStore(reply) as Comment;\n normalizedReply.communityAddress =\n getCommentCommunityAddress(normalizedReply) || commentCommunityAddress;\n return normalizedReply;\n });\n\n // manual validation\n for (const reply of normalizedReplies) {\n if (\n !areEquivalentCommunityAddresses(\n getCommentCommunityAddress(reply),\n commentCommunityAddress,\n ) ||\n reply.depth !== comment.depth + 1 ||\n reply.parentCid !== comment.cid\n ) {\n if (blockCommunity && commentCommunityAddress) {\n communitiesWithInvalidComments[commentCommunityAddress] = true;\n }\n console.log(\"invalid comment\", {\n comment: reply,\n error:\n \"!areEquivalentCommunityAddresses(reply.communityAddress, comment.communityAddress) || reply.depth !== comment.depth + 1 || reply.parentCid !== comment.cid\",\n });\n return false;\n }\n }\n\n // signature verification\n try {\n const promises = normalizedReplies.map((reply) =>\n commentIsValid(reply, { validateReplies: false, blockCommunity: true }, pkc),\n );\n await Promise.all(promises);\n } catch (e: any) {\n if (blockCommunity && commentCommunityAddress) {\n communitiesWithInvalidComments[commentCommunityAddress] = true;\n }\n console.log(\"invalid comment\", { comment, error: e });\n return false;\n }\n return true;\n};\n\nconst utils = {\n merge,\n clone,\n flattenCommentsPages,\n memo,\n memoSync,\n retryInfinity: (f: any, o?: any): any => {},\n // export timeout values to mock them in tests\n retryInfinityMinTimeout: 1000,\n retryInfinityMaxTimeout: 1000 * 60 * 60 * 24,\n clientsOnStateChange,\n pageClientsOnStateChange,\n communityPostsCacheExpired,\n commentIsValid,\n removeInvalidComments,\n repliesAreValid,\n};\n\nconst retryInfinity = async (functionToRetry: any, options?: any) => {\n const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));\n let attempt = 0;\n while (true) {\n try {\n const res = await functionToRetry();\n return res;\n } catch (e) {\n options?.onError(e || Error(`retryInfinity failed attempt ${attempt}`));\n const factor = 2;\n let timeout = Math.round(utils.retryInfinityMinTimeout * Math.pow(factor, attempt++));\n timeout = Math.min(timeout, utils.retryInfinityMaxTimeout);\n await sleep(timeout);\n }\n }\n};\nutils.retryInfinity = retryInfinity;\n\nexport default utils;\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Comment, ValidateCommentOptions, ValidateCommentResult } from "../types.js";
|
|
2
|
+
/** The CIDv0 of a CommentIpfs record, hashed the way pkc-js hashes page comments. */
|
|
3
|
+
export declare const calculateCommentCid: (commentIpfs: Record<string, any>) => Promise<string>;
|
|
4
|
+
/**
|
|
5
|
+
* Validate a comment received from an untrusted source, such as `{ cid, raw: { comment,
|
|
6
|
+
* commentUpdate } }`, the shape of a preloaded page comment. pkc.validateComment checks the
|
|
7
|
+
* signatures but trusts comment.cid, and only checks the commentUpdate signer when this pkc
|
|
8
|
+
* instance is updating the community, so both are checked here as well.
|
|
9
|
+
*/
|
|
10
|
+
export declare const validateCommentWithPkc: (comment: Comment, { validateReplies, community }: Omit<ValidateCommentOptions, "accountName"> | undefined, pkc: any) => Promise<ValidateCommentResult>;
|
|
11
|
+
//# sourceMappingURL=validate-comment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-comment.d.ts","sourceRoot":"","sources":["../../src/lib/validate-comment.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AA0BvF,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,GAAU,aAAa,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,OAAO,CAAC,MAAM,CAK1F,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAS,OAAO,EAChB,gCAAuC,IAAI,CAAC,sBAAsB,EAAE,aAAa,CAAC,YAAK,EACvF,KAAK,GAAG,KACP,OAAO,CAAC,qBAAqB,CAgG/B,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { stringify as deterministicStringify } from "safe-stable-stringify";
|
|
11
|
+
import { areEquivalentCommunityAddresses } from "./community-address.js";
|
|
12
|
+
import { getPkcAddressFromPublicKey } from "./pkc-address.js";
|
|
13
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
const getErrorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
15
|
+
const invalid = (reason) => ({ valid: false, reason });
|
|
16
|
+
// Same wire fallbacks as pkc-js getCommunityPublicKeyFromWire/getCommunityNameFromWire: old
|
|
17
|
+
// records carry a single subplebbitAddress that is either a domain or a key.
|
|
18
|
+
const isDomain = (value) => typeof value === "string" && value.includes(".");
|
|
19
|
+
const getCommunityPublicKeyFromWire = (record) => {
|
|
20
|
+
if (typeof record.communityPublicKey === "string")
|
|
21
|
+
return record.communityPublicKey;
|
|
22
|
+
if (typeof record.subplebbitAddress === "string" && !isDomain(record.subplebbitAddress))
|
|
23
|
+
return record.subplebbitAddress;
|
|
24
|
+
};
|
|
25
|
+
const getCommunityNameFromWire = (record) => {
|
|
26
|
+
if (typeof record.communityName === "string")
|
|
27
|
+
return record.communityName;
|
|
28
|
+
if (isDomain(record.subplebbitAddress))
|
|
29
|
+
return record.subplebbitAddress;
|
|
30
|
+
};
|
|
31
|
+
/** The CIDv0 of a CommentIpfs record, hashed the way pkc-js hashes page comments. */
|
|
32
|
+
export const calculateCommentCid = (commentIpfs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
// Imported on first use like pkc-js itself, so apps don't load this large library up front.
|
|
35
|
+
const ipfsOnlyHash = yield import("typestub-ipfs-only-hash");
|
|
36
|
+
const calculateIpfsHash = (_a = ipfsOnlyHash.of) !== null && _a !== void 0 ? _a : (_b = ipfsOnlyHash.default) === null || _b === void 0 ? void 0 : _b.of;
|
|
37
|
+
return calculateIpfsHash(deterministicStringify(commentIpfs));
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Validate a comment received from an untrusted source, such as `{ cid, raw: { comment,
|
|
41
|
+
* commentUpdate } }`, the shape of a preloaded page comment. pkc.validateComment checks the
|
|
42
|
+
* signatures but trusts comment.cid, and only checks the commentUpdate signer when this pkc
|
|
43
|
+
* instance is updating the community, so both are checked here as well.
|
|
44
|
+
*/
|
|
45
|
+
export const validateCommentWithPkc = (comment_1, ...args_1) => __awaiter(void 0, [comment_1, ...args_1], void 0, function* (comment, { validateReplies = true, community } = {}, pkc) {
|
|
46
|
+
var _a, _b, _c, _d, _e, _f;
|
|
47
|
+
const cid = comment === null || comment === void 0 ? void 0 : comment.cid;
|
|
48
|
+
const commentIpfs = (_a = comment === null || comment === void 0 ? void 0 : comment.raw) === null || _a === void 0 ? void 0 : _a.comment;
|
|
49
|
+
const commentUpdate = (_b = comment === null || comment === void 0 ? void 0 : comment.raw) === null || _b === void 0 ? void 0 : _b.commentUpdate;
|
|
50
|
+
if (typeof cid !== "string" || !cid) {
|
|
51
|
+
return invalid("comment.cid is not a string");
|
|
52
|
+
}
|
|
53
|
+
if (!isObject(commentIpfs)) {
|
|
54
|
+
return invalid("comment.raw.comment is not an object");
|
|
55
|
+
}
|
|
56
|
+
if (!isObject(commentUpdate)) {
|
|
57
|
+
return invalid("comment.raw.commentUpdate is not an object");
|
|
58
|
+
}
|
|
59
|
+
// Without this, a signed comment could be shown under another comment's cid together with that
|
|
60
|
+
// cid's genuine commentUpdate, and the fields a community adds unsigned (depth, postCid,
|
|
61
|
+
// thumbnailUrl, ...) could be altered.
|
|
62
|
+
let calculatedCid;
|
|
63
|
+
try {
|
|
64
|
+
calculatedCid = yield calculateCommentCid(commentIpfs);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return invalid(`failed to hash comment.raw.comment: ${getErrorMessage(error)}`);
|
|
68
|
+
}
|
|
69
|
+
if (calculatedCid !== cid) {
|
|
70
|
+
return invalid(`comment.raw.comment hashes to '${calculatedCid}', not comment.cid '${cid}'`);
|
|
71
|
+
}
|
|
72
|
+
// Preloaded replies, with their own nested updates, are trusted through this update's signature,
|
|
73
|
+
// whose signer is checked below, so they must be one of the fields it covers.
|
|
74
|
+
const signedPropertyNames = (_c = commentUpdate.signature) === null || _c === void 0 ? void 0 : _c.signedPropertyNames;
|
|
75
|
+
if (commentUpdate.replies !== undefined &&
|
|
76
|
+
!(Array.isArray(signedPropertyNames) && signedPropertyNames.includes("replies"))) {
|
|
77
|
+
return invalid("comment.raw.commentUpdate.replies is not covered by its signature");
|
|
78
|
+
}
|
|
79
|
+
// Derive what pkc.validateComment reads from the hash-verified record, never from the wrapper.
|
|
80
|
+
const communityPublicKey = getCommunityPublicKeyFromWire(commentIpfs);
|
|
81
|
+
const communityName = getCommunityNameFromWire(commentIpfs);
|
|
82
|
+
const postCid = commentIpfs.depth === 0 ? cid : commentIpfs.postCid;
|
|
83
|
+
try {
|
|
84
|
+
yield pkc.validateComment({
|
|
85
|
+
cid,
|
|
86
|
+
postCid,
|
|
87
|
+
communityPublicKey,
|
|
88
|
+
communityName,
|
|
89
|
+
raw: { comment: commentIpfs, commentUpdate },
|
|
90
|
+
}, { validateReplies });
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
return invalid(getErrorMessage(error));
|
|
94
|
+
}
|
|
95
|
+
// pkc.validateComment has already verified the commentUpdate signature, this checks who signed it.
|
|
96
|
+
const updateSignerPublicKey = (_d = commentUpdate.signature) === null || _d === void 0 ? void 0 : _d.publicKey;
|
|
97
|
+
if (community) {
|
|
98
|
+
// A loaded community record names its current signer, which also covers communities whose
|
|
99
|
+
// signing key differs from the comment's communityPublicKey (rotated or delegated keys).
|
|
100
|
+
const communitySignerPublicKey = (_e = community.signature) === null || _e === void 0 ? void 0 : _e.publicKey;
|
|
101
|
+
if (typeof communitySignerPublicKey !== "string") {
|
|
102
|
+
return invalid("options.community has no signature.publicKey");
|
|
103
|
+
}
|
|
104
|
+
if (updateSignerPublicKey !== communitySignerPublicKey) {
|
|
105
|
+
return invalid("comment.raw.commentUpdate is not signed by options.community");
|
|
106
|
+
}
|
|
107
|
+
// As pkc-js does for page comments, names win over keys, which can rotate. Without a name on
|
|
108
|
+
// both sides the keys must match, and a comment with no comparable identifier is rejected:
|
|
109
|
+
// another community can share this one's signing key (delegated or reused keys).
|
|
110
|
+
const namesMatch = communityName && community.name
|
|
111
|
+
? areEquivalentCommunityAddresses(communityName, community.name)
|
|
112
|
+
: undefined;
|
|
113
|
+
const keysMatch = communityPublicKey && community.publicKey
|
|
114
|
+
? communityPublicKey === community.publicKey
|
|
115
|
+
: undefined;
|
|
116
|
+
if (!((_f = namesMatch !== null && namesMatch !== void 0 ? namesMatch : keysMatch) !== null && _f !== void 0 ? _f : false)) {
|
|
117
|
+
return invalid("comment.raw.comment belongs to a different community than options.community");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
// Offline, the only community key the record proves is the communityPublicKey its author signed.
|
|
122
|
+
let updateSignerAddress;
|
|
123
|
+
try {
|
|
124
|
+
updateSignerAddress = getPkcAddressFromPublicKey(updateSignerPublicKey);
|
|
125
|
+
}
|
|
126
|
+
catch (_g) { }
|
|
127
|
+
if (!communityPublicKey || updateSignerAddress !== communityPublicKey) {
|
|
128
|
+
return invalid("comment.raw.commentUpdate is not signed by the comment's communityPublicKey, pass options.community to check it against the loaded community");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { valid: true };
|
|
132
|
+
});
|
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C;QAAC,WAAM,CAAC,CAAA,CAAC;QACV,IAAI,CAAC,kBAAkB,IAAI,mBAAmB,KAAK,kBAAkB,EAAE,CAAC;YACtE,OAAO,OAAO,CACZ,8IAA8I,CAC/I,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC,CAAA,CAAC","sourcesContent":["import { stringify as deterministicStringify } from \"safe-stable-stringify\";\nimport type { Comment, ValidateCommentOptions, ValidateCommentResult } from \"../types\";\nimport { areEquivalentCommunityAddresses } from \"./community-address\";\nimport { getPkcAddressFromPublicKey } from \"./pkc-address\";\n\nconst isObject = (value: unknown): value is Record<string, any> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst getErrorMessage = (error: unknown) =>\n error instanceof Error ? error.message : String(error);\n\nconst invalid = (reason: string): ValidateCommentResult => ({ valid: false, reason });\n\n// Same wire fallbacks as pkc-js getCommunityPublicKeyFromWire/getCommunityNameFromWire: old\n// records carry a single subplebbitAddress that is either a domain or a key.\nconst isDomain = (value: unknown): value is string =>\n typeof value === \"string\" && value.includes(\".\");\nconst getCommunityPublicKeyFromWire = (record: Record<string, any>): string | undefined => {\n if (typeof record.communityPublicKey === \"string\") return record.communityPublicKey;\n if (typeof record.subplebbitAddress === \"string\" && !isDomain(record.subplebbitAddress))\n return record.subplebbitAddress;\n};\nconst getCommunityNameFromWire = (record: Record<string, any>): string | undefined => {\n if (typeof record.communityName === \"string\") return record.communityName;\n if (isDomain(record.subplebbitAddress)) return record.subplebbitAddress;\n};\n\n/** The CIDv0 of a CommentIpfs record, hashed the way pkc-js hashes page comments. */\nexport const calculateCommentCid = async (commentIpfs: Record<string, any>): Promise<string> => {\n // Imported on first use like pkc-js itself, so apps don't load this large library up front.\n const ipfsOnlyHash: any = await import(\"typestub-ipfs-only-hash\");\n const calculateIpfsHash = ipfsOnlyHash.of ?? ipfsOnlyHash.default?.of;\n return calculateIpfsHash(deterministicStringify(commentIpfs));\n};\n\n/**\n * Validate a comment received from an untrusted source, such as `{ cid, raw: { comment,\n * commentUpdate } }`, the shape of a preloaded page comment. pkc.validateComment checks the\n * signatures but trusts comment.cid, and only checks the commentUpdate signer when this pkc\n * instance is updating the community, so both are checked here as well.\n */\nexport const validateCommentWithPkc = async (\n comment: Comment,\n { validateReplies = true, community }: Omit<ValidateCommentOptions, \"accountName\"> = {},\n pkc: any,\n): Promise<ValidateCommentResult> => {\n const cid = comment?.cid;\n const commentIpfs = comment?.raw?.comment;\n const commentUpdate = comment?.raw?.commentUpdate;\n if (typeof cid !== \"string\" || !cid) {\n return invalid(\"comment.cid is not a string\");\n }\n if (!isObject(commentIpfs)) {\n return invalid(\"comment.raw.comment is not an object\");\n }\n if (!isObject(commentUpdate)) {\n return invalid(\"comment.raw.commentUpdate is not an object\");\n }\n\n // Without this, a signed comment could be shown under another comment's cid together with that\n // cid's genuine commentUpdate, and the fields a community adds unsigned (depth, postCid,\n // thumbnailUrl, ...) could be altered.\n let calculatedCid: string;\n try {\n calculatedCid = await calculateCommentCid(commentIpfs);\n } catch (error) {\n return invalid(`failed to hash comment.raw.comment: ${getErrorMessage(error)}`);\n }\n if (calculatedCid !== cid) {\n return invalid(`comment.raw.comment hashes to '${calculatedCid}', not comment.cid '${cid}'`);\n }\n\n // Preloaded replies, with their own nested updates, are trusted through this update's signature,\n // whose signer is checked below, so they must be one of the fields it covers.\n const signedPropertyNames = commentUpdate.signature?.signedPropertyNames;\n if (\n commentUpdate.replies !== undefined &&\n !(Array.isArray(signedPropertyNames) && signedPropertyNames.includes(\"replies\"))\n ) {\n return invalid(\"comment.raw.commentUpdate.replies is not covered by its signature\");\n }\n\n // Derive what pkc.validateComment reads from the hash-verified record, never from the wrapper.\n const communityPublicKey = getCommunityPublicKeyFromWire(commentIpfs);\n const communityName = getCommunityNameFromWire(commentIpfs);\n const postCid = commentIpfs.depth === 0 ? cid : commentIpfs.postCid;\n try {\n await pkc.validateComment(\n {\n cid,\n postCid,\n communityPublicKey,\n communityName,\n raw: { comment: commentIpfs, commentUpdate },\n },\n { validateReplies },\n );\n } catch (error) {\n return invalid(getErrorMessage(error));\n }\n\n // pkc.validateComment has already verified the commentUpdate signature, this checks who signed it.\n const updateSignerPublicKey = commentUpdate.signature?.publicKey;\n if (community) {\n // A loaded community record names its current signer, which also covers communities whose\n // signing key differs from the comment's communityPublicKey (rotated or delegated keys).\n const communitySignerPublicKey = community.signature?.publicKey;\n if (typeof communitySignerPublicKey !== \"string\") {\n return invalid(\"options.community has no signature.publicKey\");\n }\n if (updateSignerPublicKey !== communitySignerPublicKey) {\n return invalid(\"comment.raw.commentUpdate is not signed by options.community\");\n }\n // As pkc-js does for page comments, names win over keys, which can rotate. Without a name on\n // both sides the keys must match, and a comment with no comparable identifier is rejected:\n // another community can share this one's signing key (delegated or reused keys).\n const namesMatch =\n communityName && community.name\n ? areEquivalentCommunityAddresses(communityName, community.name)\n : undefined;\n const keysMatch =\n communityPublicKey && community.publicKey\n ? communityPublicKey === community.publicKey\n : undefined;\n if (!(namesMatch ?? keysMatch ?? false)) {\n return invalid(\"comment.raw.comment belongs to a different community than options.community\");\n }\n } else {\n // Offline, the only community key the record proves is the communityPublicKey its author signed.\n let updateSignerAddress: string | undefined;\n try {\n updateSignerAddress = getPkcAddressFromPublicKey(updateSignerPublicKey);\n } catch {}\n if (!communityPublicKey || updateSignerAddress !== communityPublicKey) {\n return invalid(\n \"comment.raw.commentUpdate is not signed by the comment's communityPublicKey, pass options.community to check it against the loaded community\",\n );\n }\n }\n\n return { valid: true };\n};\n"]}
|
package/dist/lib/validator.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/lib/validator.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,QAAQ,GAAG,CAAC,KAAU,EAAE,EAAE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ClD,wDAAwD;IACxD,oDAAoD;IACpD,2CAA2C;IAC3C,6CAA6C;IAC7C,gDAAgD;IAChD,0CAA0C;IAC1C,gDAAgD;IAChD,2CAA2C;IAC3C,4CAA4C;IAC5C,oCAAoC;IACpC,2BAA2B;IAC3B,4BAA4B;IAC5B,6BAA6B;IAC7B,kCAAkC;IAClC,+BAA+B;IAC/B,qCAAqC;IACrC,oBAAoB;IACpB,wBAAwB;IACxB,iCAAiC;IACjC,uBAAuB;IACvB,2BAA2B;CAC5B,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import assert from \"assert\";\nimport { assertCommunityRef } from \"./community-ref\";\n\nconst toString = (value: any) => {\n if (typeof value === \"string\") {\n return value;\n }\n try {\n const string = JSON.stringify(value);\n return string;\n } catch {}\n return value;\n};\n\nconst getPublicationCommunityAddress = (options: any) =>\n options?.communityAddress || options?.communityAddress;\nconst getAccountProtocolClient = (account: any) => account?.pkc || account?.pkc;\n\nconst validateAccountsActionsPublishCommentArguments = ({\n publishCommentOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishComment accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishComment accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishComment no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentOptions && typeof publishCommentOptions === \"object\",\n \"publishComment publishCommentOptions not an object\",\n );\n assert(\n typeof publishCommentOptions.onChallenge === \"function\",\n \"publishComment publishCommentOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentOptions.onChallengeVerification === \"function\",\n \"publishComment publishCommentOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentOptions.onError || typeof publishCommentOptions.onError === \"function\",\n \"publishComment publishCommentOptions.onError not a function\",\n );\n assert(\n publishCommentOptions.onPendingComment == null ||\n typeof publishCommentOptions.onPendingComment === \"function\",\n \"publishComment publishCommentOptions.onPendingComment not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentOptions) === \"string\",\n \"publishComment publishCommentOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n !publishCommentOptions.parentCid || typeof publishCommentOptions.parentCid === \"string\",\n \"publishComment publishCommentOptions.parentCid not a string\",\n );\n assert(\n !publishCommentOptions.timestamp || typeof publishCommentOptions.timestamp === \"number\",\n \"publishComment publishCommentOptions.timestamp is not a number\",\n );\n\n // validate content\n assert(\n !publishCommentOptions.content || typeof publishCommentOptions.content === \"string\",\n \"publishComment publishCommentOptions.content not a string\",\n );\n assert(\n publishCommentOptions.content !== \"\",\n \"publishComment publishCommentOptions.content is an empty string\",\n );\n assert(\n !publishCommentOptions.link || typeof publishCommentOptions.link === \"string\",\n \"publishComment publishCommentOptions.link not a string\",\n );\n assert(\n publishCommentOptions.link !== \"\",\n \"publishComment publishCommentOptions.link is an empty string\",\n );\n assert(\n !publishCommentOptions.title || typeof publishCommentOptions.title === \"string\",\n \"publishComment publishCommentOptions.title not a string\",\n );\n assert(\n publishCommentOptions.title !== \"\",\n \"publishComment publishCommentOptions.title is an empty string\",\n );\n};\n\nconst validateAccountsActionsPublishVoteArguments = ({\n publishVoteOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishVote accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishVote accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishVote no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishVoteOptions && typeof publishVoteOptions === \"object\",\n \"publishVote publishVoteOptions not an object\",\n );\n assert(\n typeof publishVoteOptions.onChallenge === \"function\",\n \"publishVote publishVoteOptions.onChallenge not a function\",\n );\n assert(\n typeof publishVoteOptions.onChallengeVerification === \"function\",\n \"publishVote publishVoteOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishVoteOptions.onError || typeof publishVoteOptions.onError === \"function\",\n \"publishVote publishVoteOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishVoteOptions) === \"string\",\n \"publishVote publishVoteOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishVoteOptions.commentCid === \"string\",\n \"publishVote publishVoteOptions.commentCid not a string\",\n );\n assert(\n publishVoteOptions.vote === 1 ||\n publishVoteOptions.vote === 0 ||\n publishVoteOptions.vote === -1,\n \"publishVote publishVoteOptions.vote not 1, 0 or -1\",\n );\n assert(\n !publishVoteOptions.timestamp || typeof publishVoteOptions.timestamp === \"number\",\n \"publishVote publishVoteOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsPublishCommentEditArguments = ({\n publishCommentEditOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommentEdit accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommentEdit accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommentEdit no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentEditOptions && typeof publishCommentEditOptions === \"object\",\n \"publishCommentEdit publishCommentEditOptions not an object\",\n );\n assert(\n typeof publishCommentEditOptions.onChallenge === \"function\",\n \"publishCommentEdit publishCommentEditOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentEditOptions.onChallengeVerification === \"function\",\n \"publishCommentEdit publishCommentEditOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentEditOptions.onError || typeof publishCommentEditOptions.onError === \"function\",\n \"publishCommentEditOptions publishCommentEditOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentEditOptions) === \"string\",\n \"publishCommentEdit publishCommentEditOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishCommentEditOptions.commentCid === \"string\",\n \"publishCommentEdit publishCommentEditOptions.commentCid not a string\",\n );\n assert(\n !publishCommentEditOptions.timestamp || typeof publishCommentEditOptions.timestamp === \"number\",\n \"publishCommentEdit publishCommentEditOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsPublishCommentModerationArguments = ({\n publishCommentModerationOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommentModeration accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommentModeration accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommentModeration no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentModerationOptions && typeof publishCommentModerationOptions === \"object\",\n \"publishCommentModeration publishCommentModerationOptions not an object\",\n );\n assert(\n typeof publishCommentModerationOptions.onChallenge === \"function\",\n \"publishCommentModeration publishCommentModerationOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentModerationOptions.onChallengeVerification === \"function\",\n \"publishCommentModeration publishCommentModerationOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentModerationOptions.onError ||\n typeof publishCommentModerationOptions.onError === \"function\",\n \"publishCommentModerationOptions publishCommentModerationOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentModerationOptions) === \"string\",\n \"publishCommentModeration publishCommentModerationOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishCommentModerationOptions.commentCid === \"string\",\n \"publishCommentModeration publishCommentModerationOptions.commentCid not a string\",\n );\n assert(\n !publishCommentModerationOptions.timestamp ||\n typeof publishCommentModerationOptions.timestamp === \"number\",\n \"publishCommentModeration publishCommentModerationOptions.timestamp is not a number\",\n );\n assert(\n publishCommentModerationOptions.commentModeration &&\n typeof publishCommentModerationOptions.commentModeration === \"object\",\n \"publishCommentModeration publishCommentModerationOptions.commentModeration is not an object\",\n );\n};\n\nconst validateAccountsActionsPublishCommunityEditArguments = ({\n communityAddress,\n publishCommunityEditOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommunityEdit accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommunityEdit accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommunityEdit no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommunityEditOptions && typeof publishCommunityEditOptions === \"object\",\n \"publishCommunityEdit publishCommunityEditOptions not an object\",\n );\n assert(\n typeof publishCommunityEditOptions.onChallenge === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommunityEditOptions.onChallengeVerification === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommunityEditOptions.onError ||\n typeof publishCommunityEditOptions.onError === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onError not a function\",\n );\n assert(communityAddress !== \"\", `publishCommunityEdit communityAddress argument is empty string`);\n assert(\n typeof communityAddress === \"string\",\n \"publishCommunityEdit communityAddress not a string\",\n );\n assert(\n !publishCommunityEditOptions.timestamp ||\n typeof publishCommunityEditOptions.timestamp === \"number\",\n \"publishCommunityEdit publishCommunityEditOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsExportAccountArguments = (accountName: any) => {\n assert(\n typeof accountName === \"string\",\n `exportAccount accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `exportAccount accountName argument is empty string`);\n};\n\nconst validateAccountsActionsSetAccountsOrderArguments = (\n newOrderedAccountNames: any,\n accountNames: any,\n) => {\n assert(\n JSON.stringify([...accountNames].sort()) === JSON.stringify([...newOrderedAccountNames].sort()),\n `previous account names '${accountNames} contain different account names than argument newOrderedAccountNames '${newOrderedAccountNames}'`,\n );\n};\n\nconst validateAccountsActionsSetAccountArguments = (account: any) => {\n assert(account && typeof account === \"object\", `setAccount account '${account}' not an object`);\n assert(\n typeof account.name === \"string\",\n `setAccount account.name '${account.name}' not a string`,\n );\n assert(account.name !== \"\", `setAccount account.name is empty string`);\n assert(typeof account.id === \"string\", `setAccount account.id '${account.id}' not a string`);\n assert(account.id !== \"\", `setAccount account.id is empty string`);\n};\n\nconst validateAccountsActionsSetActiveAccountArguments = (accountName: any) => {\n assert(\n typeof accountName === \"string\",\n `setActiveAccountName accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `setActiveAccountName accountName argument is empty string`);\n};\n\nconst validateAccountsDatabaseGetAccountsArguments = (accountIds: any) => {\n assert(\n Array.isArray(accountIds),\n `accountsDatabase.getAccounts accountIds '${accountIds}' not an array`,\n );\n assert(accountIds.length > 0, `accountsDatabase.getAccounts accountIds array is empty`);\n for (const accountId of accountIds) {\n assert(\n typeof accountId === \"string\",\n `accountsDatabase.getAccountsaccountIds '${accountIds}' accountId '${accountId}' not a string`,\n );\n assert(\n accountId !== \"\",\n `accountsDatabase.getAccounts accountIds '${accountIds}' an accountId argument is empty string`,\n );\n }\n};\n\nconst validateAccountsDatabaseAccountNames = (accountNames: any) => {\n assert(\n Array.isArray(accountNames),\n `accountsDatabase accountNames '${accountNames}' not an array`,\n );\n for (const accountName of accountNames) {\n assert(\n typeof accountName === \"string\",\n `accountsDatabase accountNames '${accountNames}' accountName '${accountName}' not a string`,\n );\n }\n};\n\nconst validateAccountsDatabaseAddAccountArguments = (account: any) => {\n assert(\n account && typeof account === \"object\",\n `accountsDatabase.addAccount '${account}' not an object`,\n );\n assert(\n typeof account.name === \"string\",\n `accountsDatabase.addAccount account.name '${account.name}' not a string`,\n );\n assert(account.name !== \"\", `accountsDatabase.addAccount account.name is empty string`);\n assert(\n typeof account.id === \"string\",\n `accountsDatabase.addAccount account.id '${account.id}' not a string`,\n );\n assert(account.id !== \"\", `accountsDatabase.addAccount account.id is empty string`);\n};\n\nconst validateUseCommentArguments = (commentCid: any, account: any) => {\n assert(typeof commentCid === \"string\", `useComment commentCid '${commentCid}' not a string`);\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useComment account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n};\n\nconst validateUseCommentsArguments = (commentCids: any, account: any) => {\n assert(\n Array.isArray(commentCids),\n `useComment commentCids '${toString(commentCids)}' not an array`,\n );\n for (const commentCid of commentCids) {\n assert(\n typeof commentCid === \"string\",\n `useComments commentCids '${toString(commentCids)}' commentCid '${toString(commentCid)}' not a string`,\n );\n }\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useComments account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n};\n\nconst validateCommunityIdentifierArguments = (\n community: any,\n legacyCommunityAddress: any,\n scope: string,\n) => {\n assert(\n legacyCommunityAddress === undefined,\n `${scope} communityAddress has been removed, pass { community: { name, publicKey } }`,\n );\n if (community === undefined) {\n return;\n }\n assertCommunityRef(community, `${scope} community`);\n};\n\nconst validateUseCommunityArguments = ({ community, communityAddress, account }: any) => {\n validateCommunityIdentifierArguments(community, communityAddress, \"useCommunity\");\n if (account !== undefined && account !== null) {\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useCommunity account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n }\n};\n\nconst validateUseCommunityStatsArguments = ({ community, communityAddress }: any) => {\n validateCommunityIdentifierArguments(community, communityAddress, \"useCommunityStats\");\n};\n\nconst validateCommunitiesArguments = (\n communities: any,\n communityRefs: any,\n communityAddresses: any,\n scope: string,\n) => {\n assert(\n communityRefs === undefined,\n `${scope} communityRefs has been removed, pass communities instead`,\n );\n assert(\n communityAddresses === undefined,\n `${scope} communityAddresses has been removed, pass communities instead`,\n );\n if (communities !== undefined) {\n assert(\n Array.isArray(communities),\n `${scope} communities '${toString(communities)}' not an array`,\n );\n for (const community of communities) {\n assertCommunityRef(\n community,\n `${scope} communities '${toString(communities)}' community '${toString(community)}'`,\n );\n }\n }\n};\n\nconst validateUseCommunitiesArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n account,\n}: any) => {\n validateCommunitiesArguments(communities, communityRefs, communityAddresses, \"useCommunities\");\n if (account !== undefined && account !== null) {\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useCommunity account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n }\n};\n\nconst validateFeedSortType = (sortType: any) => {\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `invalid feed sort type '${sortType}'`,\n );\n};\nconst validateUseFeedArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n}: any) => {\n validateCommunitiesArguments(communities, communityRefs, communityAddresses, \"useFeed\");\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useFeed sortType argument '${sortType}' invalid`,\n );\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useFeed accountName argument '${accountName}' not a string`,\n );\n }\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useFeed postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useFeed filter.filter argument '${filter.filter}' not a function, useFeedOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useFeed filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n if (newerThan !== undefined && newerThan !== null) {\n assert(typeof newerThan === \"number\", `useFeed newerThan argument '${newerThan}' not a number`);\n }\n if (accountComments) {\n assert(\n typeof accountComments === \"object\",\n `useFeed accountComments argument '${accountComments}' not an object`,\n );\n assert(\n typeof accountComments.newerThan === \"number\",\n `useFeed accountComments.newerThan argument '${accountComments}' not a number`,\n );\n }\n};\nconst validateUseBufferedFeedsArguments = ({\n feedsOptions,\n accountName,\n}: {\n feedsOptions?: any;\n accountName?: any;\n}) => {\n assert(\n Array.isArray(feedsOptions),\n `useBufferedFeeds feedsOptions argument '${toString(feedsOptions)}' not an array`,\n );\n for (const {\n communities,\n communityRefs,\n communityAddresses,\n sortType,\n postsPerPage,\n filter,\n newerThan,\n } of feedsOptions) {\n validateCommunitiesArguments(\n communities,\n communityRefs,\n communityAddresses,\n \"useBufferedFeeds feedOptions\",\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useBufferedFeeds feedOptions.sortType argument '${sortType}' invalid`,\n );\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useBufferedFeeds feedOptions.postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useBufferedFeeds feedOptions.filter.filter argument '${filter.filter}' not a function, useFeedOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useBufferedFeeds feedOptions.filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n if (newerThan !== undefined && newerThan !== null) {\n assert(\n typeof newerThan === \"number\",\n `useBufferedFeeds feedOptions.newerThan argument '${newerThan}' not a number`,\n );\n }\n }\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useBufferedFeeds accountName argument '${accountName}' not a string`,\n );\n }\n};\n\nconst validateUseCommunitiesStatesArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n}: any) => {\n validateCommunitiesArguments(\n communities,\n communityRefs,\n communityAddresses,\n \"useCommunitiesStates\",\n );\n};\n\nconst validateRepliesSortType = (sortType: any) => {\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `invalid replies sort type '${sortType}'`,\n );\n};\nconst validateUseRepliesArguments = (\n comment?: any,\n sortType?: any,\n accountName?: any,\n onlyIfCached?: any,\n flat?: any,\n accountComments?: any,\n postsPerPage?: any,\n filter?: any,\n) => {\n assert(\n !comment || typeof comment === \"object\",\n `useReplies comment argument '${comment}' not an object`,\n );\n assert(\n !comment?.cid || typeof comment.cid === \"string\",\n `useReplies comment.cid argument '${comment?.cid}' not a string`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useReplies sortType argument '${sortType}' invalid`,\n );\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useReplies accountName argument '${accountName}' not a string`,\n );\n }\n if (onlyIfCached !== undefined && onlyIfCached !== null) {\n assert(\n typeof onlyIfCached === \"boolean\",\n `useReplies onlyIfCached argument '${onlyIfCached}' not a boolean`,\n );\n }\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useReplies postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (flat !== undefined && flat !== null) {\n assert(typeof flat === \"boolean\", `useReplies flat argument '${flat}' not a boolean`);\n }\n if (accountComments !== undefined && accountComments !== null) {\n assert(\n typeof accountComments.newerThan === \"number\",\n `useReplies accountComments.newerThan argument '${accountComments.newerThan}' not a number`,\n );\n assert(\n !accountComments.append || typeof accountComments.append === \"boolean\",\n `useReplies accountComments.append argument '${accountComments.append}' not a boolean`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useReplies filter.filter argument '${filter.filter}' not a function, useRepliesOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useReplies filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n};\n\nconst validator = {\n validateAccountsActionsPublishCommentArguments,\n validateAccountsActionsPublishCommentEditArguments,\n validateAccountsActionsPublishCommentModerationArguments,\n validateAccountsActionsPublishCommunityEditArguments,\n validateAccountsActionsPublishVoteArguments,\n validateAccountsActionsExportAccountArguments,\n validateAccountsActionsSetAccountsOrderArguments,\n validateAccountsActionsSetAccountArguments,\n validateAccountsActionsSetActiveAccountArguments,\n validateAccountsDatabaseAddAccountArguments,\n validateAccountsDatabaseGetAccountsArguments,\n validateAccountsDatabaseAccountNames,\n validateUseCommentArguments,\n validateUseCommentsArguments,\n validateUseCommunityArguments,\n validateUseCommunityStatsArguments,\n validateUseCommunitiesArguments,\n validateUseCommunitiesStatesArguments,\n validateFeedSortType,\n validateUseFeedArguments,\n validateUseBufferedFeedsArguments,\n validateRepliesSortType,\n validateUseRepliesArguments,\n};\n\nexport default validator;\n"]}
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/lib/validator.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,QAAQ,GAAG,CAAC,KAAU,EAAE,EAAE;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACrC,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,WAAM,CAAC,CAAA,CAAC;IACV,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,8BAA8B,GAAG,CAAC,OAAY,EAAE,EAAE,CACtD,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,CAAA,CAAC;AACzD,MAAM,wBAAwB,GAAG,CAAC,OAAY,EAAE,EAAE,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAA,CAAC;AAEhF,MAAM,8CAA8C,GAAG,CAAC,EACtD,qBAAqB,EACrB,WAAW,EACX,OAAO,GACH,EAAE,EAAE;IACR,MAAM,CACJ,CAAC,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,EAC/C,+BAA+B,WAAW,gBAAgB,CAC3D,CAAC;IACF,MAAM,CAAC,WAAW,KAAK,EAAE,EAAE,qDAAqD,CAAC,CAAC;IAClF,MAAM,CACJ,CAAC,WAAW,IAAI,OAAO,EACvB,wCAAwC,WAAW,oBAAoB,CACxE,CAAC;IACF,MAAM,CACJ,qBAAqB,IAAI,OA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EACnC,sCAAsC,MAAM,CAAC,MAAM,yHAAyH,CAC7K,CAAC;QACF,MAAM,CACJ,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,EAC9B,mCAAmC,MAAM,CAAC,GAAG,yEAAyE,CACvH,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG;IAChB,8CAA8C;IAC9C,kDAAkD;IAClD,wDAAwD;IACxD,oDAAoD;IACpD,2CAA2C;IAC3C,6CAA6C;IAC7C,gDAAgD;IAChD,0CAA0C;IAC1C,gDAAgD;IAChD,2CAA2C;IAC3C,4CAA4C;IAC5C,oCAAoC;IACpC,2BAA2B;IAC3B,4BAA4B;IAC5B,6BAA6B;IAC7B,kCAAkC;IAClC,+BAA+B;IAC/B,qCAAqC;IACrC,oBAAoB;IACpB,wBAAwB;IACxB,iCAAiC;IACjC,uBAAuB;IACvB,2BAA2B;CAC5B,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import assert from \"./assert\";\nimport { assertCommunityRef } from \"./community-ref\";\n\nconst toString = (value: any) => {\n if (typeof value === \"string\") {\n return value;\n }\n try {\n const string = JSON.stringify(value);\n return string;\n } catch {}\n return value;\n};\n\nconst getPublicationCommunityAddress = (options: any) =>\n options?.communityAddress || options?.communityAddress;\nconst getAccountProtocolClient = (account: any) => account?.pkc || account?.pkc;\n\nconst validateAccountsActionsPublishCommentArguments = ({\n publishCommentOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishComment accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishComment accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishComment no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentOptions && typeof publishCommentOptions === \"object\",\n \"publishComment publishCommentOptions not an object\",\n );\n assert(\n typeof publishCommentOptions.onChallenge === \"function\",\n \"publishComment publishCommentOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentOptions.onChallengeVerification === \"function\",\n \"publishComment publishCommentOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentOptions.onError || typeof publishCommentOptions.onError === \"function\",\n \"publishComment publishCommentOptions.onError not a function\",\n );\n assert(\n publishCommentOptions.onPendingComment == null ||\n typeof publishCommentOptions.onPendingComment === \"function\",\n \"publishComment publishCommentOptions.onPendingComment not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentOptions) === \"string\",\n \"publishComment publishCommentOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n !publishCommentOptions.parentCid || typeof publishCommentOptions.parentCid === \"string\",\n \"publishComment publishCommentOptions.parentCid not a string\",\n );\n assert(\n !publishCommentOptions.timestamp || typeof publishCommentOptions.timestamp === \"number\",\n \"publishComment publishCommentOptions.timestamp is not a number\",\n );\n\n // validate content\n assert(\n !publishCommentOptions.content || typeof publishCommentOptions.content === \"string\",\n \"publishComment publishCommentOptions.content not a string\",\n );\n assert(\n publishCommentOptions.content !== \"\",\n \"publishComment publishCommentOptions.content is an empty string\",\n );\n assert(\n !publishCommentOptions.link || typeof publishCommentOptions.link === \"string\",\n \"publishComment publishCommentOptions.link not a string\",\n );\n assert(\n publishCommentOptions.link !== \"\",\n \"publishComment publishCommentOptions.link is an empty string\",\n );\n assert(\n !publishCommentOptions.title || typeof publishCommentOptions.title === \"string\",\n \"publishComment publishCommentOptions.title not a string\",\n );\n assert(\n publishCommentOptions.title !== \"\",\n \"publishComment publishCommentOptions.title is an empty string\",\n );\n};\n\nconst validateAccountsActionsPublishVoteArguments = ({\n publishVoteOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishVote accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishVote accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishVote no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishVoteOptions && typeof publishVoteOptions === \"object\",\n \"publishVote publishVoteOptions not an object\",\n );\n assert(\n typeof publishVoteOptions.onChallenge === \"function\",\n \"publishVote publishVoteOptions.onChallenge not a function\",\n );\n assert(\n typeof publishVoteOptions.onChallengeVerification === \"function\",\n \"publishVote publishVoteOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishVoteOptions.onError || typeof publishVoteOptions.onError === \"function\",\n \"publishVote publishVoteOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishVoteOptions) === \"string\",\n \"publishVote publishVoteOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishVoteOptions.commentCid === \"string\",\n \"publishVote publishVoteOptions.commentCid not a string\",\n );\n assert(\n publishVoteOptions.vote === 1 ||\n publishVoteOptions.vote === 0 ||\n publishVoteOptions.vote === -1,\n \"publishVote publishVoteOptions.vote not 1, 0 or -1\",\n );\n assert(\n !publishVoteOptions.timestamp || typeof publishVoteOptions.timestamp === \"number\",\n \"publishVote publishVoteOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsPublishCommentEditArguments = ({\n publishCommentEditOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommentEdit accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommentEdit accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommentEdit no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentEditOptions && typeof publishCommentEditOptions === \"object\",\n \"publishCommentEdit publishCommentEditOptions not an object\",\n );\n assert(\n typeof publishCommentEditOptions.onChallenge === \"function\",\n \"publishCommentEdit publishCommentEditOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentEditOptions.onChallengeVerification === \"function\",\n \"publishCommentEdit publishCommentEditOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentEditOptions.onError || typeof publishCommentEditOptions.onError === \"function\",\n \"publishCommentEditOptions publishCommentEditOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentEditOptions) === \"string\",\n \"publishCommentEdit publishCommentEditOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishCommentEditOptions.commentCid === \"string\",\n \"publishCommentEdit publishCommentEditOptions.commentCid not a string\",\n );\n assert(\n !publishCommentEditOptions.timestamp || typeof publishCommentEditOptions.timestamp === \"number\",\n \"publishCommentEdit publishCommentEditOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsPublishCommentModerationArguments = ({\n publishCommentModerationOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommentModeration accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommentModeration accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommentModeration no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentModerationOptions && typeof publishCommentModerationOptions === \"object\",\n \"publishCommentModeration publishCommentModerationOptions not an object\",\n );\n assert(\n typeof publishCommentModerationOptions.onChallenge === \"function\",\n \"publishCommentModeration publishCommentModerationOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentModerationOptions.onChallengeVerification === \"function\",\n \"publishCommentModeration publishCommentModerationOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentModerationOptions.onError ||\n typeof publishCommentModerationOptions.onError === \"function\",\n \"publishCommentModerationOptions publishCommentModerationOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentModerationOptions) === \"string\",\n \"publishCommentModeration publishCommentModerationOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishCommentModerationOptions.commentCid === \"string\",\n \"publishCommentModeration publishCommentModerationOptions.commentCid not a string\",\n );\n assert(\n !publishCommentModerationOptions.timestamp ||\n typeof publishCommentModerationOptions.timestamp === \"number\",\n \"publishCommentModeration publishCommentModerationOptions.timestamp is not a number\",\n );\n assert(\n publishCommentModerationOptions.commentModeration &&\n typeof publishCommentModerationOptions.commentModeration === \"object\",\n \"publishCommentModeration publishCommentModerationOptions.commentModeration is not an object\",\n );\n};\n\nconst validateAccountsActionsPublishCommunityEditArguments = ({\n communityAddress,\n publishCommunityEditOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommunityEdit accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommunityEdit accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommunityEdit no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommunityEditOptions && typeof publishCommunityEditOptions === \"object\",\n \"publishCommunityEdit publishCommunityEditOptions not an object\",\n );\n assert(\n typeof publishCommunityEditOptions.onChallenge === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommunityEditOptions.onChallengeVerification === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommunityEditOptions.onError ||\n typeof publishCommunityEditOptions.onError === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onError not a function\",\n );\n assert(communityAddress !== \"\", `publishCommunityEdit communityAddress argument is empty string`);\n assert(\n typeof communityAddress === \"string\",\n \"publishCommunityEdit communityAddress not a string\",\n );\n assert(\n !publishCommunityEditOptions.timestamp ||\n typeof publishCommunityEditOptions.timestamp === \"number\",\n \"publishCommunityEdit publishCommunityEditOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsExportAccountArguments = (accountName: any) => {\n assert(\n typeof accountName === \"string\",\n `exportAccount accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `exportAccount accountName argument is empty string`);\n};\n\nconst validateAccountsActionsSetAccountsOrderArguments = (\n newOrderedAccountNames: any,\n accountNames: any,\n) => {\n assert(\n JSON.stringify([...accountNames].sort()) === JSON.stringify([...newOrderedAccountNames].sort()),\n `previous account names '${accountNames} contain different account names than argument newOrderedAccountNames '${newOrderedAccountNames}'`,\n );\n};\n\nconst validateAccountsActionsSetAccountArguments = (account: any) => {\n assert(account && typeof account === \"object\", `setAccount account '${account}' not an object`);\n assert(\n typeof account.name === \"string\",\n `setAccount account.name '${account.name}' not a string`,\n );\n assert(account.name !== \"\", `setAccount account.name is empty string`);\n assert(typeof account.id === \"string\", `setAccount account.id '${account.id}' not a string`);\n assert(account.id !== \"\", `setAccount account.id is empty string`);\n};\n\nconst validateAccountsActionsSetActiveAccountArguments = (accountName: any) => {\n assert(\n typeof accountName === \"string\",\n `setActiveAccountName accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `setActiveAccountName accountName argument is empty string`);\n};\n\nconst validateAccountsDatabaseGetAccountsArguments = (accountIds: any) => {\n assert(\n Array.isArray(accountIds),\n `accountsDatabase.getAccounts accountIds '${accountIds}' not an array`,\n );\n assert(accountIds.length > 0, `accountsDatabase.getAccounts accountIds array is empty`);\n for (const accountId of accountIds) {\n assert(\n typeof accountId === \"string\",\n `accountsDatabase.getAccountsaccountIds '${accountIds}' accountId '${accountId}' not a string`,\n );\n assert(\n accountId !== \"\",\n `accountsDatabase.getAccounts accountIds '${accountIds}' an accountId argument is empty string`,\n );\n }\n};\n\nconst validateAccountsDatabaseAccountNames = (accountNames: any) => {\n assert(\n Array.isArray(accountNames),\n `accountsDatabase accountNames '${accountNames}' not an array`,\n );\n for (const accountName of accountNames) {\n assert(\n typeof accountName === \"string\",\n `accountsDatabase accountNames '${accountNames}' accountName '${accountName}' not a string`,\n );\n }\n};\n\nconst validateAccountsDatabaseAddAccountArguments = (account: any) => {\n assert(\n account && typeof account === \"object\",\n `accountsDatabase.addAccount '${account}' not an object`,\n );\n assert(\n typeof account.name === \"string\",\n `accountsDatabase.addAccount account.name '${account.name}' not a string`,\n );\n assert(account.name !== \"\", `accountsDatabase.addAccount account.name is empty string`);\n assert(\n typeof account.id === \"string\",\n `accountsDatabase.addAccount account.id '${account.id}' not a string`,\n );\n assert(account.id !== \"\", `accountsDatabase.addAccount account.id is empty string`);\n};\n\nconst validateUseCommentArguments = (commentCid: any, account: any) => {\n assert(typeof commentCid === \"string\", `useComment commentCid '${commentCid}' not a string`);\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useComment account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n};\n\nconst validateUseCommentsArguments = (commentCids: any, account: any) => {\n assert(\n Array.isArray(commentCids),\n `useComment commentCids '${toString(commentCids)}' not an array`,\n );\n for (const commentCid of commentCids) {\n assert(\n typeof commentCid === \"string\",\n `useComments commentCids '${toString(commentCids)}' commentCid '${toString(commentCid)}' not a string`,\n );\n }\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useComments account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n};\n\nconst validateCommunityIdentifierArguments = (\n community: any,\n legacyCommunityAddress: any,\n scope: string,\n) => {\n assert(\n legacyCommunityAddress === undefined,\n `${scope} communityAddress has been removed, pass { community: { name, publicKey } }`,\n );\n if (community === undefined) {\n return;\n }\n assertCommunityRef(community, `${scope} community`);\n};\n\nconst validateUseCommunityArguments = ({ community, communityAddress, account }: any) => {\n validateCommunityIdentifierArguments(community, communityAddress, \"useCommunity\");\n if (account !== undefined && account !== null) {\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useCommunity account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n }\n};\n\nconst validateUseCommunityStatsArguments = ({ community, communityAddress }: any) => {\n validateCommunityIdentifierArguments(community, communityAddress, \"useCommunityStats\");\n};\n\nconst validateCommunitiesArguments = (\n communities: any,\n communityRefs: any,\n communityAddresses: any,\n scope: string,\n) => {\n assert(\n communityRefs === undefined,\n `${scope} communityRefs has been removed, pass communities instead`,\n );\n assert(\n communityAddresses === undefined,\n `${scope} communityAddresses has been removed, pass communities instead`,\n );\n if (communities !== undefined) {\n assert(\n Array.isArray(communities),\n `${scope} communities '${toString(communities)}' not an array`,\n );\n for (const community of communities) {\n assertCommunityRef(\n community,\n `${scope} communities '${toString(communities)}' community '${toString(community)}'`,\n );\n }\n }\n};\n\nconst validateUseCommunitiesArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n account,\n}: any) => {\n validateCommunitiesArguments(communities, communityRefs, communityAddresses, \"useCommunities\");\n if (account !== undefined && account !== null) {\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useCommunity account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n }\n};\n\nconst validateFeedSortType = (sortType: any) => {\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `invalid feed sort type '${sortType}'`,\n );\n};\nconst validateUseFeedArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n}: any) => {\n validateCommunitiesArguments(communities, communityRefs, communityAddresses, \"useFeed\");\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useFeed sortType argument '${sortType}' invalid`,\n );\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useFeed accountName argument '${accountName}' not a string`,\n );\n }\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useFeed postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useFeed filter.filter argument '${filter.filter}' not a function, useFeedOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useFeed filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n if (newerThan !== undefined && newerThan !== null) {\n assert(typeof newerThan === \"number\", `useFeed newerThan argument '${newerThan}' not a number`);\n }\n if (accountComments) {\n assert(\n typeof accountComments === \"object\",\n `useFeed accountComments argument '${accountComments}' not an object`,\n );\n assert(\n typeof accountComments.newerThan === \"number\",\n `useFeed accountComments.newerThan argument '${accountComments}' not a number`,\n );\n }\n};\nconst validateUseBufferedFeedsArguments = ({\n feedsOptions,\n accountName,\n}: {\n feedsOptions?: any;\n accountName?: any;\n}) => {\n assert(\n Array.isArray(feedsOptions),\n `useBufferedFeeds feedsOptions argument '${toString(feedsOptions)}' not an array`,\n );\n for (const {\n communities,\n communityRefs,\n communityAddresses,\n sortType,\n postsPerPage,\n filter,\n newerThan,\n } of feedsOptions) {\n validateCommunitiesArguments(\n communities,\n communityRefs,\n communityAddresses,\n \"useBufferedFeeds feedOptions\",\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useBufferedFeeds feedOptions.sortType argument '${sortType}' invalid`,\n );\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useBufferedFeeds feedOptions.postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useBufferedFeeds feedOptions.filter.filter argument '${filter.filter}' not a function, useFeedOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useBufferedFeeds feedOptions.filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n if (newerThan !== undefined && newerThan !== null) {\n assert(\n typeof newerThan === \"number\",\n `useBufferedFeeds feedOptions.newerThan argument '${newerThan}' not a number`,\n );\n }\n }\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useBufferedFeeds accountName argument '${accountName}' not a string`,\n );\n }\n};\n\nconst validateUseCommunitiesStatesArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n}: any) => {\n validateCommunitiesArguments(\n communities,\n communityRefs,\n communityAddresses,\n \"useCommunitiesStates\",\n );\n};\n\nconst validateRepliesSortType = (sortType: any) => {\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `invalid replies sort type '${sortType}'`,\n );\n};\nconst validateUseRepliesArguments = (\n comment?: any,\n sortType?: any,\n accountName?: any,\n onlyIfCached?: any,\n flat?: any,\n accountComments?: any,\n postsPerPage?: any,\n filter?: any,\n) => {\n assert(\n !comment || typeof comment === \"object\",\n `useReplies comment argument '${comment}' not an object`,\n );\n assert(\n !comment?.cid || typeof comment.cid === \"string\",\n `useReplies comment.cid argument '${comment?.cid}' not a string`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useReplies sortType argument '${sortType}' invalid`,\n );\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useReplies accountName argument '${accountName}' not a string`,\n );\n }\n if (onlyIfCached !== undefined && onlyIfCached !== null) {\n assert(\n typeof onlyIfCached === \"boolean\",\n `useReplies onlyIfCached argument '${onlyIfCached}' not a boolean`,\n );\n }\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useReplies postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (flat !== undefined && flat !== null) {\n assert(typeof flat === \"boolean\", `useReplies flat argument '${flat}' not a boolean`);\n }\n if (accountComments !== undefined && accountComments !== null) {\n assert(\n typeof accountComments.newerThan === \"number\",\n `useReplies accountComments.newerThan argument '${accountComments.newerThan}' not a number`,\n );\n assert(\n !accountComments.append || typeof accountComments.append === \"boolean\",\n `useReplies accountComments.append argument '${accountComments.append}' not a boolean`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useReplies filter.filter argument '${filter.filter}' not a function, useRepliesOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useReplies filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n};\n\nconst validator = {\n validateAccountsActionsPublishCommentArguments,\n validateAccountsActionsPublishCommentEditArguments,\n validateAccountsActionsPublishCommentModerationArguments,\n validateAccountsActionsPublishCommunityEditArguments,\n validateAccountsActionsPublishVoteArguments,\n validateAccountsActionsExportAccountArguments,\n validateAccountsActionsSetAccountsOrderArguments,\n validateAccountsActionsSetAccountArguments,\n validateAccountsActionsSetActiveAccountArguments,\n validateAccountsDatabaseAddAccountArguments,\n validateAccountsDatabaseGetAccountsArguments,\n validateAccountsDatabaseAccountNames,\n validateUseCommentArguments,\n validateUseCommentsArguments,\n validateUseCommunityArguments,\n validateUseCommunityStatsArguments,\n validateUseCommunitiesArguments,\n validateUseCommunitiesStatesArguments,\n validateFeedSortType,\n validateUseFeedArguments,\n validateUseBufferedFeedsArguments,\n validateRepliesSortType,\n validateUseRepliesArguments,\n};\n\nexport default validator;\n"]}
|
|
@@ -11,8 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
import accountsStore, { listeners } from "./accounts-store.js";
|
|
12
12
|
import accountsDatabase from "./accounts-database.js";
|
|
13
13
|
import Logger from "@pkcprotocol/pkc-logger";
|
|
14
|
-
import assert from "assert";
|
|
15
|
-
import isEqual from "
|
|
14
|
+
import assert from "../../lib/assert.js";
|
|
15
|
+
import isEqual from "../../lib/is-equal.js";
|
|
16
16
|
const log = Logger("bitsocial-react-hooks:accounts:stores");
|
|
17
17
|
import utils from "../../lib/utils/index.js";
|
|
18
18
|
import { backfillPublicationCommunityAddress, getCommentCommunityAddress, normalizePublicationOptionsForPkc, normalizePublicationOptionsForStore, } from "../../lib/pkc-compat.js";
|