@pkcprotocol/pkc-js 0.0.11
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/LICENSE +339 -0
- package/README.md +1663 -0
- package/dist/browser/challenges.d.ts +1 -0
- package/dist/browser/challenges.js +2 -0
- package/dist/browser/challenges.js.map +1 -0
- package/dist/browser/clients/base-client-manager.d.ts +126 -0
- package/dist/browser/clients/base-client-manager.js +673 -0
- package/dist/browser/clients/base-client-manager.js.map +1 -0
- package/dist/browser/clients/name-resolver-client.d.ts +8 -0
- package/dist/browser/clients/name-resolver-client.js +10 -0
- package/dist/browser/clients/name-resolver-client.js.map +1 -0
- package/dist/browser/clients/pkc-typed-emitter.d.ts +9 -0
- package/dist/browser/clients/pkc-typed-emitter.js +52 -0
- package/dist/browser/clients/pkc-typed-emitter.js.map +1 -0
- package/dist/browser/clients/rpc-client/decode-rpc-response-util.d.ts +8 -0
- package/dist/browser/clients/rpc-client/decode-rpc-response-util.js +53 -0
- package/dist/browser/clients/rpc-client/decode-rpc-response-util.js.map +1 -0
- package/dist/browser/clients/rpc-client/pkc-rpc-client.d.ts +68 -0
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js +404 -0
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -0
- package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +147 -0
- package/dist/browser/clients/rpc-client/rpc-schema-util.js +11 -0
- package/dist/browser/clients/rpc-client/rpc-schema-util.js.map +1 -0
- package/dist/browser/clients/rpc-client/schema.d.ts +433 -0
- package/dist/browser/clients/rpc-client/schema.js +49 -0
- package/dist/browser/clients/rpc-client/schema.js.map +1 -0
- package/dist/browser/clients/rpc-client/types.d.ts +8 -0
- package/dist/browser/clients/rpc-client/types.js +2 -0
- package/dist/browser/clients/rpc-client/types.js.map +1 -0
- package/dist/browser/community/community-client-manager.d.ts +60 -0
- package/dist/browser/community/community-client-manager.js +717 -0
- package/dist/browser/community/community-client-manager.js.map +1 -0
- package/dist/browser/community/community-clients.d.ts +18 -0
- package/dist/browser/community/community-clients.js +12 -0
- package/dist/browser/community/community-clients.js.map +1 -0
- package/dist/browser/community/community-wire.d.ts +20 -0
- package/dist/browser/community/community-wire.js +38 -0
- package/dist/browser/community/community-wire.js.map +1 -0
- package/dist/browser/community/remote-community.d.ts +110 -0
- package/dist/browser/community/remote-community.js +555 -0
- package/dist/browser/community/remote-community.js.map +1 -0
- package/dist/browser/community/rpc-local-community.d.ts +41 -0
- package/dist/browser/community/rpc-local-community.js +289 -0
- package/dist/browser/community/rpc-local-community.js.map +1 -0
- package/dist/browser/community/rpc-remote-community.d.ts +18 -0
- package/dist/browser/community/rpc-remote-community.js +286 -0
- package/dist/browser/community/rpc-remote-community.js.map +1 -0
- package/dist/browser/community/schema.d.ts +4217 -0
- package/dist/browser/community/schema.js +289 -0
- package/dist/browser/community/schema.js.map +1 -0
- package/dist/browser/community/types.d.ts +135 -0
- package/dist/browser/community/types.js +2 -0
- package/dist/browser/community/types.js.map +1 -0
- package/dist/browser/constants.d.ts +6 -0
- package/dist/browser/constants.js +9 -0
- package/dist/browser/constants.js.map +1 -0
- package/dist/browser/decorator-util.d.ts +1 -0
- package/dist/browser/decorator-util.js +35 -0
- package/dist/browser/decorator-util.js.map +1 -0
- package/dist/browser/errors.d.ts +343 -0
- package/dist/browser/errors.js +358 -0
- package/dist/browser/errors.js.map +1 -0
- package/dist/browser/general-util/limited-set.d.ts +15 -0
- package/dist/browser/general-util/limited-set.js +66 -0
- package/dist/browser/general-util/limited-set.js.map +1 -0
- package/dist/browser/generated-version.d.ts +1 -0
- package/dist/browser/generated-version.js +3 -0
- package/dist/browser/generated-version.js.map +1 -0
- package/dist/browser/generic-state-client.d.ts +6 -0
- package/dist/browser/generic-state-client.js +11 -0
- package/dist/browser/generic-state-client.js.map +1 -0
- package/dist/browser/helia/helia-for-pkc.d.ts +3 -0
- package/dist/browser/helia/helia-for-pkc.js +255 -0
- package/dist/browser/helia/helia-for-pkc.js.map +1 -0
- package/dist/browser/helia/ipns-over-pubsub-with-fetch.d.ts +36 -0
- package/dist/browser/helia/ipns-over-pubsub-with-fetch.js +229 -0
- package/dist/browser/helia/ipns-over-pubsub-with-fetch.js.map +1 -0
- package/dist/browser/helia/libp2pjsClient.d.ts +27 -0
- package/dist/browser/helia/libp2pjsClient.js +15 -0
- package/dist/browser/helia/libp2pjsClient.js.map +1 -0
- package/dist/browser/helia/types.d.ts +19 -0
- package/dist/browser/helia/types.js +2 -0
- package/dist/browser/helia/types.js.map +1 -0
- package/dist/browser/helia/util.d.ts +13 -0
- package/dist/browser/helia/util.js +98 -0
- package/dist/browser/helia/util.js.map +1 -0
- package/dist/browser/index.d.ts +244 -0
- package/dist/browser/index.js +36 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/logger.d.ts +12 -0
- package/dist/browser/logger.js +11 -0
- package/dist/browser/logger.js.map +1 -0
- package/dist/browser/pages/pages-client-manager.d.ts +159 -0
- package/dist/browser/pages/pages-client-manager.js +334 -0
- package/dist/browser/pages/pages-client-manager.js.map +1 -0
- package/dist/browser/pages/pages-clients.d.ts +11 -0
- package/dist/browser/pages/pages-clients.js +10 -0
- package/dist/browser/pages/pages-clients.js.map +1 -0
- package/dist/browser/pages/pages.d.ts +107 -0
- package/dist/browser/pages/pages.js +262 -0
- package/dist/browser/pages/pages.js.map +1 -0
- package/dist/browser/pages/schema-util.d.ts +3 -0
- package/dist/browser/pages/schema-util.js +3 -0
- package/dist/browser/pages/schema-util.js.map +1 -0
- package/dist/browser/pages/schema.d.ts +719 -0
- package/dist/browser/pages/schema.js +32 -0
- package/dist/browser/pages/schema.js.map +1 -0
- package/dist/browser/pages/types.d.ts +44 -0
- package/dist/browser/pages/types.js +2 -0
- package/dist/browser/pages/types.js.map +1 -0
- package/dist/browser/pages/util.d.ts +56 -0
- package/dist/browser/pages/util.js +446 -0
- package/dist/browser/pages/util.js.map +1 -0
- package/dist/browser/pkc/pkc-client-manager.d.ts +44 -0
- package/dist/browser/pkc/pkc-client-manager.js +156 -0
- package/dist/browser/pkc/pkc-client-manager.js.map +1 -0
- package/dist/browser/pkc/pkc-clients.d.ts +11 -0
- package/dist/browser/pkc/pkc-clients.js +8 -0
- package/dist/browser/pkc/pkc-clients.js.map +1 -0
- package/dist/browser/pkc/pkc-with-rpc-client.d.ts +19 -0
- package/dist/browser/pkc/pkc-with-rpc-client.js +128 -0
- package/dist/browser/pkc/pkc-with-rpc-client.js.map +1 -0
- package/dist/browser/pkc/pkc.d.ts +137 -0
- package/dist/browser/pkc/pkc.js +888 -0
- package/dist/browser/pkc/pkc.js.map +1 -0
- package/dist/browser/pkc/tracked-instance-registry-util.d.ts +44 -0
- package/dist/browser/pkc/tracked-instance-registry-util.js +106 -0
- package/dist/browser/pkc/tracked-instance-registry-util.js.map +1 -0
- package/dist/browser/pkc/tracked-instance-registry.d.ts +18 -0
- package/dist/browser/pkc/tracked-instance-registry.js +134 -0
- package/dist/browser/pkc/tracked-instance-registry.js.map +1 -0
- package/dist/browser/pkc-error.d.ts +65 -0
- package/dist/browser/pkc-error.js +137 -0
- package/dist/browser/pkc-error.js.map +1 -0
- package/dist/browser/publications/comment/comment-client-manager.d.ts +86 -0
- package/dist/browser/publications/comment/comment-client-manager.js +908 -0
- package/dist/browser/publications/comment/comment-client-manager.js.map +1 -0
- package/dist/browser/publications/comment/comment-clients.d.ts +19 -0
- package/dist/browser/publications/comment/comment-clients.js +12 -0
- package/dist/browser/publications/comment/comment-clients.js.map +1 -0
- package/dist/browser/publications/comment/comment-util.d.ts +10 -0
- package/dist/browser/publications/comment/comment-util.js +202 -0
- package/dist/browser/publications/comment/comment-util.js.map +1 -0
- package/dist/browser/publications/comment/comment.d.ts +147 -0
- package/dist/browser/publications/comment/comment.js +1044 -0
- package/dist/browser/publications/comment/comment.js.map +1 -0
- package/dist/browser/publications/comment/schema.d.ts +1237 -0
- package/dist/browser/publications/comment/schema.js +184 -0
- package/dist/browser/publications/comment/schema.js.map +1 -0
- package/dist/browser/publications/comment/types.d.ts +100 -0
- package/dist/browser/publications/comment/types.js +2 -0
- package/dist/browser/publications/comment/types.js.map +1 -0
- package/dist/browser/publications/comment-edit/comment-edit.d.ts +41 -0
- package/dist/browser/publications/comment-edit/comment-edit.js +63 -0
- package/dist/browser/publications/comment-edit/comment-edit.js.map +1 -0
- package/dist/browser/publications/comment-edit/schema.d.ts +295 -0
- package/dist/browser/publications/comment-edit/schema.js +55 -0
- package/dist/browser/publications/comment-edit/schema.js.map +1 -0
- package/dist/browser/publications/comment-edit/types.d.ts +25 -0
- package/dist/browser/publications/comment-edit/types.js +2 -0
- package/dist/browser/publications/comment-edit/types.js.map +1 -0
- package/dist/browser/publications/comment-moderation/comment-moderation.d.ts +36 -0
- package/dist/browser/publications/comment-moderation/comment-moderation.js +53 -0
- package/dist/browser/publications/comment-moderation/comment-moderation.js.map +1 -0
- package/dist/browser/publications/comment-moderation/schema.d.ts +315 -0
- package/dist/browser/publications/comment-moderation/schema.js +62 -0
- package/dist/browser/publications/comment-moderation/schema.js.map +1 -0
- package/dist/browser/publications/comment-moderation/types.d.ts +22 -0
- package/dist/browser/publications/comment-moderation/types.js +2 -0
- package/dist/browser/publications/comment-moderation/types.js.map +1 -0
- package/dist/browser/publications/community-edit/community-edit.d.ts +35 -0
- package/dist/browser/publications/community-edit/community-edit.js +50 -0
- package/dist/browser/publications/community-edit/community-edit.js.map +1 -0
- package/dist/browser/publications/community-edit/schema.d.ts +467 -0
- package/dist/browser/publications/community-edit/schema.js +36 -0
- package/dist/browser/publications/community-edit/schema.js.map +1 -0
- package/dist/browser/publications/community-edit/types.d.ts +19 -0
- package/dist/browser/publications/community-edit/types.js +2 -0
- package/dist/browser/publications/community-edit/types.js.map +1 -0
- package/dist/browser/publications/publication-author.d.ts +22 -0
- package/dist/browser/publications/publication-author.js +66 -0
- package/dist/browser/publications/publication-author.js.map +1 -0
- package/dist/browser/publications/publication-client-manager.d.ts +62 -0
- package/dist/browser/publications/publication-client-manager.js +257 -0
- package/dist/browser/publications/publication-client-manager.js.map +1 -0
- package/dist/browser/publications/publication-clients.d.ts +19 -0
- package/dist/browser/publications/publication-clients.js +12 -0
- package/dist/browser/publications/publication-clients.js.map +1 -0
- package/dist/browser/publications/publication-community.d.ts +55 -0
- package/dist/browser/publications/publication-community.js +87 -0
- package/dist/browser/publications/publication-community.js.map +1 -0
- package/dist/browser/publications/publication.d.ts +120 -0
- package/dist/browser/publications/publication.js +950 -0
- package/dist/browser/publications/publication.js.map +1 -0
- package/dist/browser/publications/types.d.ts +26 -0
- package/dist/browser/publications/types.js +2 -0
- package/dist/browser/publications/types.js.map +1 -0
- package/dist/browser/publications/vote/schema.d.ts +150 -0
- package/dist/browser/publications/vote/schema.js +44 -0
- package/dist/browser/publications/vote/schema.js.map +1 -0
- package/dist/browser/publications/vote/types.d.ts +21 -0
- package/dist/browser/publications/vote/types.js +2 -0
- package/dist/browser/publications/vote/types.js.map +1 -0
- package/dist/browser/publications/vote/vote.d.ts +36 -0
- package/dist/browser/publications/vote/vote.js +49 -0
- package/dist/browser/publications/vote/vote.js.map +1 -0
- package/dist/browser/pubsub-messages/schema.d.ts +964 -0
- package/dist/browser/pubsub-messages/schema.js +98 -0
- package/dist/browser/pubsub-messages/schema.js.map +1 -0
- package/dist/browser/pubsub-messages/types.d.ts +81 -0
- package/dist/browser/pubsub-messages/types.js +2 -0
- package/dist/browser/pubsub-messages/types.js.map +1 -0
- package/dist/browser/rpc/src/index.d.ts +483 -0
- package/dist/browser/rpc/src/index.js +1267 -0
- package/dist/browser/rpc/src/index.js.map +1 -0
- package/dist/browser/rpc/src/json-rpc-util.d.ts +1 -0
- package/dist/browser/rpc/src/json-rpc-util.js +19 -0
- package/dist/browser/rpc/src/json-rpc-util.js.map +1 -0
- package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +132 -0
- package/dist/browser/rpc/src/lib/pkc-js/index.js +29 -0
- package/dist/browser/rpc/src/lib/pkc-js/index.js.map +1 -0
- package/dist/browser/rpc/src/lib/pkc-js/pkc-js-mock.d.ts +1 -0
- package/dist/browser/rpc/src/lib/pkc-js/pkc-js-mock.js +472 -0
- package/dist/browser/rpc/src/lib/pkc-js/pkc-js-mock.js.map +1 -0
- package/dist/browser/rpc/src/schema.d.ts +843 -0
- package/dist/browser/rpc/src/schema.js +28 -0
- package/dist/browser/rpc/src/schema.js.map +1 -0
- package/dist/browser/rpc/src/types.d.ts +24 -0
- package/dist/browser/rpc/src/types.js +2 -0
- package/dist/browser/rpc/src/types.js.map +1 -0
- package/dist/browser/rpc/src/utils.d.ts +7 -0
- package/dist/browser/rpc/src/utils.js +58 -0
- package/dist/browser/rpc/src/utils.js.map +1 -0
- package/dist/browser/runtime/browser/community/challenges/index.d.ts +6 -0
- package/dist/browser/runtime/browser/community/challenges/index.js +7 -0
- package/dist/browser/runtime/browser/community/challenges/index.js.map +1 -0
- package/dist/browser/runtime/browser/community/local-community.d.ts +3 -0
- package/dist/browser/runtime/browser/community/local-community.js +6 -0
- package/dist/browser/runtime/browser/community/local-community.js.map +1 -0
- package/dist/browser/runtime/browser/db-handler.d.ts +4 -0
- package/dist/browser/runtime/browser/db-handler.js +8 -0
- package/dist/browser/runtime/browser/db-handler.js.map +1 -0
- package/dist/browser/runtime/browser/localforage-lru.d.ts +15 -0
- package/dist/browser/runtime/browser/localforage-lru.js +140 -0
- package/dist/browser/runtime/browser/localforage-lru.js.map +1 -0
- package/dist/browser/runtime/browser/lru-storage.d.ts +14 -0
- package/dist/browser/runtime/browser/lru-storage.js +34 -0
- package/dist/browser/runtime/browser/lru-storage.js.map +1 -0
- package/dist/browser/runtime/browser/native-functions.d.ts +3 -0
- package/dist/browser/runtime/browser/native-functions.js +6 -0
- package/dist/browser/runtime/browser/native-functions.js.map +1 -0
- package/dist/browser/runtime/browser/polyfill.d.ts +3 -0
- package/dist/browser/runtime/browser/polyfill.js +37 -0
- package/dist/browser/runtime/browser/polyfill.js.map +1 -0
- package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +1 -0
- package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +4 -0
- package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
- package/dist/browser/runtime/browser/storage.d.ts +13 -0
- package/dist/browser/runtime/browser/storage.js +37 -0
- package/dist/browser/runtime/browser/storage.js.map +1 -0
- package/dist/browser/runtime/browser/util.d.ts +14 -0
- package/dist/browser/runtime/browser/util.js +61 -0
- package/dist/browser/runtime/browser/util.js.map +1 -0
- package/dist/browser/runtime/node/address-rewriter-db.d.ts +31 -0
- package/dist/browser/runtime/node/address-rewriter-db.js +156 -0
- package/dist/browser/runtime/node/address-rewriter-db.js.map +1 -0
- package/dist/browser/runtime/node/addresses-rewriter-proxy-server.d.ts +45 -0
- package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js +493 -0
- package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/exclude/exclude.d.ts +8 -0
- package/dist/browser/runtime/node/community/challenges/exclude/exclude.js +280 -0
- package/dist/browser/runtime/node/community/challenges/exclude/exclude.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/exclude/index.d.ts +3 -0
- package/dist/browser/runtime/node/community/challenges/exclude/index.js +4 -0
- package/dist/browser/runtime/node/community/challenges/exclude/index.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/exclude/rate-limiter.d.ts +5 -0
- package/dist/browser/runtime/node/community/challenges/exclude/rate-limiter.js +127 -0
- package/dist/browser/runtime/node/community/challenges/exclude/rate-limiter.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/exclude/utils.d.ts +13 -0
- package/dist/browser/runtime/node/community/challenges/exclude/utils.js +52 -0
- package/dist/browser/runtime/node/community/challenges/exclude/utils.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/index.d.ts +32 -0
- package/dist/browser/runtime/node/community/challenges/index.js +307 -0
- package/dist/browser/runtime/node/community/challenges/index.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/blacklist.d.ts +5 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/blacklist.js +118 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/blacklist.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/fail.d.ts +5 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/fail.js +26 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/fail.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/publication-match.d.ts +5 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/publication-match.js +135 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/publication-match.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/question.d.ts +5 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/question.js +66 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/question.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/text-math.d.ts +5 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/text-math.js +61 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/text-math.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/whitelist.d.ts +5 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/whitelist.js +118 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/whitelist.js.map +1 -0
- package/dist/browser/runtime/node/community/db-handler-types.d.ts +19 -0
- package/dist/browser/runtime/node/community/db-handler-types.js +2 -0
- package/dist/browser/runtime/node/community/db-handler-types.js.map +1 -0
- package/dist/browser/runtime/node/community/db-handler.d.ts +226 -0
- package/dist/browser/runtime/node/community/db-handler.js +2462 -0
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -0
- package/dist/browser/runtime/node/community/db-row-parser.d.ts +19 -0
- package/dist/browser/runtime/node/community/db-row-parser.js +40 -0
- package/dist/browser/runtime/node/community/db-row-parser.js.map +1 -0
- package/dist/browser/runtime/node/community/keyv-better-sqlite3.d.ts +68 -0
- package/dist/browser/runtime/node/community/keyv-better-sqlite3.js +251 -0
- package/dist/browser/runtime/node/community/keyv-better-sqlite3.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community.d.ts +129 -0
- package/dist/browser/runtime/node/community/local-community.js +2978 -0
- package/dist/browser/runtime/node/community/local-community.js.map +1 -0
- package/dist/browser/runtime/node/community/page-generator.d.ts +433 -0
- package/dist/browser/runtime/node/community/page-generator.js +441 -0
- package/dist/browser/runtime/node/community/page-generator.js.map +1 -0
- package/dist/browser/runtime/node/lru-storage.d.ts +14 -0
- package/dist/browser/runtime/node/lru-storage.js +40 -0
- package/dist/browser/runtime/node/lru-storage.js.map +1 -0
- package/dist/browser/runtime/node/native-functions.d.ts +3 -0
- package/dist/browser/runtime/node/native-functions.js +7 -0
- package/dist/browser/runtime/node/native-functions.js.map +1 -0
- package/dist/browser/runtime/node/polyfill.d.ts +3 -0
- package/dist/browser/runtime/node/polyfill.js +20 -0
- package/dist/browser/runtime/node/polyfill.js.map +1 -0
- package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +4 -0
- package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.js +240 -0
- package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
- package/dist/browser/runtime/node/sqlite-lru-cache.d.ts +52 -0
- package/dist/browser/runtime/node/sqlite-lru-cache.js +127 -0
- package/dist/browser/runtime/node/sqlite-lru-cache.js.map +1 -0
- package/dist/browser/runtime/node/storage.d.ts +14 -0
- package/dist/browser/runtime/node/storage.js +52 -0
- package/dist/browser/runtime/node/storage.js.map +1 -0
- package/dist/browser/runtime/node/test/helpers/hanging-runner.d.ts +1 -0
- package/dist/browser/runtime/node/test/helpers/hanging-runner.js +157 -0
- package/dist/browser/runtime/node/test/helpers/hanging-runner.js.map +1 -0
- package/dist/browser/runtime/node/test/helpers/run-hanging-node.d.ts +7 -0
- package/dist/browser/runtime/node/test/helpers/run-hanging-node.js +68 -0
- package/dist/browser/runtime/node/test/helpers/run-hanging-node.js.map +1 -0
- package/dist/browser/runtime/node/test/mock-http-router.d.ts +54 -0
- package/dist/browser/runtime/node/test/mock-http-router.js +397 -0
- package/dist/browser/runtime/node/test/mock-http-router.js.map +1 -0
- package/dist/browser/runtime/node/util.d.ts +43 -0
- package/dist/browser/runtime/node/util.js +384 -0
- package/dist/browser/runtime/node/util.js.map +1 -0
- package/dist/browser/schema/schema-util.d.ts +2751 -0
- package/dist/browser/schema/schema-util.js +562 -0
- package/dist/browser/schema/schema-util.js.map +1 -0
- package/dist/browser/schema/schema.d.ts +237 -0
- package/dist/browser/schema/schema.js +128 -0
- package/dist/browser/schema/schema.js.map +1 -0
- package/dist/browser/schema.d.ts +1142 -0
- package/dist/browser/schema.js +104 -0
- package/dist/browser/schema.js.map +1 -0
- package/dist/browser/signer/constants.d.ts +2 -0
- package/dist/browser/signer/constants.js +3 -0
- package/dist/browser/signer/constants.js.map +1 -0
- package/dist/browser/signer/encryption.d.ts +21 -0
- package/dist/browser/signer/encryption.js +122 -0
- package/dist/browser/signer/encryption.js.map +1 -0
- package/dist/browser/signer/index.d.ts +21 -0
- package/dist/browser/signer/index.js +49 -0
- package/dist/browser/signer/index.js.map +1 -0
- package/dist/browser/signer/signatures.d.ts +200 -0
- package/dist/browser/signer/signatures.js +594 -0
- package/dist/browser/signer/signatures.js.map +1 -0
- package/dist/browser/signer/types.d.ts +20 -0
- package/dist/browser/signer/types.js +2 -0
- package/dist/browser/signer/types.js.map +1 -0
- package/dist/browser/signer/util.d.ts +14 -0
- package/dist/browser/signer/util.js +156 -0
- package/dist/browser/signer/util.js.map +1 -0
- package/dist/browser/stats.d.ts +15 -0
- package/dist/browser/stats.js +64 -0
- package/dist/browser/stats.js.map +1 -0
- package/dist/browser/test/mock-ipfs-client.d.ts +34 -0
- package/dist/browser/test/mock-ipfs-client.js +208 -0
- package/dist/browser/test/mock-ipfs-client.js.map +1 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-publish-pending.scenario.d.ts +8 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js +21 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js.map +1 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-publish.scenario.d.ts +8 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-publish.scenario.js +19 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-publish.scenario.js.map +1 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-update.scenario.d.ts +8 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-update.scenario.js +22 -0
- package/dist/browser/test/node/hanging-test/scenarios/comment-update.scenario.js.map +1 -0
- package/dist/browser/test/node/hanging-test/scenarios/community-start.scenario.d.ts +8 -0
- package/dist/browser/test/node/hanging-test/scenarios/community-start.scenario.js +23 -0
- package/dist/browser/test/node/hanging-test/scenarios/community-start.scenario.js.map +1 -0
- package/dist/browser/test/node/hanging-test/scenarios/community-update.scenario.d.ts +8 -0
- package/dist/browser/test/node/hanging-test/scenarios/community-update.scenario.js +21 -0
- package/dist/browser/test/node/hanging-test/scenarios/community-update.scenario.js.map +1 -0
- package/dist/browser/test/node/hanging-test/scenarios/destroy-only.scenario.d.ts +7 -0
- package/dist/browser/test/node/hanging-test/scenarios/destroy-only.scenario.js +15 -0
- package/dist/browser/test/node/hanging-test/scenarios/destroy-only.scenario.js.map +1 -0
- package/dist/browser/test/node/hanging-test/scenarios/hanging-test-util.d.ts +30 -0
- package/dist/browser/test/node/hanging-test/scenarios/hanging-test-util.js +46 -0
- package/dist/browser/test/node/hanging-test/scenarios/hanging-test-util.js.map +1 -0
- package/dist/browser/test/test-util.d.ts +1019 -0
- package/dist/browser/test/test-util.js +1886 -0
- package/dist/browser/test/test-util.js.map +1 -0
- package/dist/browser/types.d.ts +165 -0
- package/dist/browser/types.js +2 -0
- package/dist/browser/types.js.map +1 -0
- package/dist/browser/util/inflight-fetch-manager.d.ts +11 -0
- package/dist/browser/util/inflight-fetch-manager.js +41 -0
- package/dist/browser/util/inflight-fetch-manager.js.map +1 -0
- package/dist/browser/util.d.ts +120 -0
- package/dist/browser/util.js +816 -0
- package/dist/browser/util.js.map +1 -0
- package/dist/browser/version.d.ts +7 -0
- package/dist/browser/version.js +12 -0
- package/dist/browser/version.js.map +1 -0
- package/dist/browser/zod-error-map.d.ts +1 -0
- package/dist/browser/zod-error-map.js +10 -0
- package/dist/browser/zod-error-map.js.map +1 -0
- package/dist/node/challenges.d.ts +1 -0
- package/dist/node/challenges.js +2 -0
- package/dist/node/challenges.js.map +1 -0
- package/dist/node/clients/base-client-manager.d.ts +126 -0
- package/dist/node/clients/base-client-manager.js +673 -0
- package/dist/node/clients/base-client-manager.js.map +1 -0
- package/dist/node/clients/name-resolver-client.d.ts +8 -0
- package/dist/node/clients/name-resolver-client.js +10 -0
- package/dist/node/clients/name-resolver-client.js.map +1 -0
- package/dist/node/clients/pkc-typed-emitter.d.ts +9 -0
- package/dist/node/clients/pkc-typed-emitter.js +52 -0
- package/dist/node/clients/pkc-typed-emitter.js.map +1 -0
- package/dist/node/clients/rpc-client/decode-rpc-response-util.d.ts +8 -0
- package/dist/node/clients/rpc-client/decode-rpc-response-util.js +53 -0
- package/dist/node/clients/rpc-client/decode-rpc-response-util.js.map +1 -0
- package/dist/node/clients/rpc-client/pkc-rpc-client.d.ts +68 -0
- package/dist/node/clients/rpc-client/pkc-rpc-client.js +404 -0
- package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -0
- package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +147 -0
- package/dist/node/clients/rpc-client/rpc-schema-util.js +11 -0
- package/dist/node/clients/rpc-client/rpc-schema-util.js.map +1 -0
- package/dist/node/clients/rpc-client/schema.d.ts +433 -0
- package/dist/node/clients/rpc-client/schema.js +49 -0
- package/dist/node/clients/rpc-client/schema.js.map +1 -0
- package/dist/node/clients/rpc-client/types.d.ts +8 -0
- package/dist/node/clients/rpc-client/types.js +2 -0
- package/dist/node/clients/rpc-client/types.js.map +1 -0
- package/dist/node/community/community-client-manager.d.ts +60 -0
- package/dist/node/community/community-client-manager.js +717 -0
- package/dist/node/community/community-client-manager.js.map +1 -0
- package/dist/node/community/community-clients.d.ts +18 -0
- package/dist/node/community/community-clients.js +12 -0
- package/dist/node/community/community-clients.js.map +1 -0
- package/dist/node/community/community-wire.d.ts +20 -0
- package/dist/node/community/community-wire.js +38 -0
- package/dist/node/community/community-wire.js.map +1 -0
- package/dist/node/community/remote-community.d.ts +110 -0
- package/dist/node/community/remote-community.js +555 -0
- package/dist/node/community/remote-community.js.map +1 -0
- package/dist/node/community/rpc-local-community.d.ts +41 -0
- package/dist/node/community/rpc-local-community.js +289 -0
- package/dist/node/community/rpc-local-community.js.map +1 -0
- package/dist/node/community/rpc-remote-community.d.ts +18 -0
- package/dist/node/community/rpc-remote-community.js +286 -0
- package/dist/node/community/rpc-remote-community.js.map +1 -0
- package/dist/node/community/schema.d.ts +4217 -0
- package/dist/node/community/schema.js +289 -0
- package/dist/node/community/schema.js.map +1 -0
- package/dist/node/community/types.d.ts +135 -0
- package/dist/node/community/types.js +2 -0
- package/dist/node/community/types.js.map +1 -0
- package/dist/node/constants.d.ts +6 -0
- package/dist/node/constants.js +9 -0
- package/dist/node/constants.js.map +1 -0
- package/dist/node/decorator-util.d.ts +1 -0
- package/dist/node/decorator-util.js +35 -0
- package/dist/node/decorator-util.js.map +1 -0
- package/dist/node/errors.d.ts +343 -0
- package/dist/node/errors.js +358 -0
- package/dist/node/errors.js.map +1 -0
- package/dist/node/general-util/limited-set.d.ts +15 -0
- package/dist/node/general-util/limited-set.js +66 -0
- package/dist/node/general-util/limited-set.js.map +1 -0
- package/dist/node/generated-version.d.ts +1 -0
- package/dist/node/generated-version.js +3 -0
- package/dist/node/generated-version.js.map +1 -0
- package/dist/node/generic-state-client.d.ts +6 -0
- package/dist/node/generic-state-client.js +11 -0
- package/dist/node/generic-state-client.js.map +1 -0
- package/dist/node/helia/helia-for-pkc.d.ts +3 -0
- package/dist/node/helia/helia-for-pkc.js +255 -0
- package/dist/node/helia/helia-for-pkc.js.map +1 -0
- package/dist/node/helia/ipns-over-pubsub-with-fetch.d.ts +36 -0
- package/dist/node/helia/ipns-over-pubsub-with-fetch.js +229 -0
- package/dist/node/helia/ipns-over-pubsub-with-fetch.js.map +1 -0
- package/dist/node/helia/libp2pjsClient.d.ts +27 -0
- package/dist/node/helia/libp2pjsClient.js +15 -0
- package/dist/node/helia/libp2pjsClient.js.map +1 -0
- package/dist/node/helia/types.d.ts +19 -0
- package/dist/node/helia/types.js +2 -0
- package/dist/node/helia/types.js.map +1 -0
- package/dist/node/helia/util.d.ts +13 -0
- package/dist/node/helia/util.js +98 -0
- package/dist/node/helia/util.js.map +1 -0
- package/dist/node/index.d.ts +244 -0
- package/dist/node/index.js +36 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/logger.d.ts +12 -0
- package/dist/node/logger.js +11 -0
- package/dist/node/logger.js.map +1 -0
- package/dist/node/pages/pages-client-manager.d.ts +159 -0
- package/dist/node/pages/pages-client-manager.js +334 -0
- package/dist/node/pages/pages-client-manager.js.map +1 -0
- package/dist/node/pages/pages-clients.d.ts +11 -0
- package/dist/node/pages/pages-clients.js +10 -0
- package/dist/node/pages/pages-clients.js.map +1 -0
- package/dist/node/pages/pages.d.ts +107 -0
- package/dist/node/pages/pages.js +262 -0
- package/dist/node/pages/pages.js.map +1 -0
- package/dist/node/pages/schema-util.d.ts +3 -0
- package/dist/node/pages/schema-util.js +3 -0
- package/dist/node/pages/schema-util.js.map +1 -0
- package/dist/node/pages/schema.d.ts +719 -0
- package/dist/node/pages/schema.js +32 -0
- package/dist/node/pages/schema.js.map +1 -0
- package/dist/node/pages/types.d.ts +44 -0
- package/dist/node/pages/types.js +2 -0
- package/dist/node/pages/types.js.map +1 -0
- package/dist/node/pages/util.d.ts +56 -0
- package/dist/node/pages/util.js +446 -0
- package/dist/node/pages/util.js.map +1 -0
- package/dist/node/pkc/pkc-client-manager.d.ts +44 -0
- package/dist/node/pkc/pkc-client-manager.js +156 -0
- package/dist/node/pkc/pkc-client-manager.js.map +1 -0
- package/dist/node/pkc/pkc-clients.d.ts +11 -0
- package/dist/node/pkc/pkc-clients.js +8 -0
- package/dist/node/pkc/pkc-clients.js.map +1 -0
- package/dist/node/pkc/pkc-with-rpc-client.d.ts +19 -0
- package/dist/node/pkc/pkc-with-rpc-client.js +128 -0
- package/dist/node/pkc/pkc-with-rpc-client.js.map +1 -0
- package/dist/node/pkc/pkc.d.ts +137 -0
- package/dist/node/pkc/pkc.js +888 -0
- package/dist/node/pkc/pkc.js.map +1 -0
- package/dist/node/pkc/tracked-instance-registry-util.d.ts +44 -0
- package/dist/node/pkc/tracked-instance-registry-util.js +106 -0
- package/dist/node/pkc/tracked-instance-registry-util.js.map +1 -0
- package/dist/node/pkc/tracked-instance-registry.d.ts +18 -0
- package/dist/node/pkc/tracked-instance-registry.js +134 -0
- package/dist/node/pkc/tracked-instance-registry.js.map +1 -0
- package/dist/node/pkc-error.d.ts +65 -0
- package/dist/node/pkc-error.js +137 -0
- package/dist/node/pkc-error.js.map +1 -0
- package/dist/node/publications/comment/comment-client-manager.d.ts +86 -0
- package/dist/node/publications/comment/comment-client-manager.js +908 -0
- package/dist/node/publications/comment/comment-client-manager.js.map +1 -0
- package/dist/node/publications/comment/comment-clients.d.ts +19 -0
- package/dist/node/publications/comment/comment-clients.js +12 -0
- package/dist/node/publications/comment/comment-clients.js.map +1 -0
- package/dist/node/publications/comment/comment-util.d.ts +10 -0
- package/dist/node/publications/comment/comment-util.js +202 -0
- package/dist/node/publications/comment/comment-util.js.map +1 -0
- package/dist/node/publications/comment/comment.d.ts +147 -0
- package/dist/node/publications/comment/comment.js +1044 -0
- package/dist/node/publications/comment/comment.js.map +1 -0
- package/dist/node/publications/comment/schema.d.ts +1237 -0
- package/dist/node/publications/comment/schema.js +184 -0
- package/dist/node/publications/comment/schema.js.map +1 -0
- package/dist/node/publications/comment/types.d.ts +100 -0
- package/dist/node/publications/comment/types.js +2 -0
- package/dist/node/publications/comment/types.js.map +1 -0
- package/dist/node/publications/comment-edit/comment-edit.d.ts +41 -0
- package/dist/node/publications/comment-edit/comment-edit.js +63 -0
- package/dist/node/publications/comment-edit/comment-edit.js.map +1 -0
- package/dist/node/publications/comment-edit/schema.d.ts +295 -0
- package/dist/node/publications/comment-edit/schema.js +55 -0
- package/dist/node/publications/comment-edit/schema.js.map +1 -0
- package/dist/node/publications/comment-edit/types.d.ts +25 -0
- package/dist/node/publications/comment-edit/types.js +2 -0
- package/dist/node/publications/comment-edit/types.js.map +1 -0
- package/dist/node/publications/comment-moderation/comment-moderation.d.ts +36 -0
- package/dist/node/publications/comment-moderation/comment-moderation.js +53 -0
- package/dist/node/publications/comment-moderation/comment-moderation.js.map +1 -0
- package/dist/node/publications/comment-moderation/schema.d.ts +315 -0
- package/dist/node/publications/comment-moderation/schema.js +62 -0
- package/dist/node/publications/comment-moderation/schema.js.map +1 -0
- package/dist/node/publications/comment-moderation/types.d.ts +22 -0
- package/dist/node/publications/comment-moderation/types.js +2 -0
- package/dist/node/publications/comment-moderation/types.js.map +1 -0
- package/dist/node/publications/community-edit/community-edit.d.ts +35 -0
- package/dist/node/publications/community-edit/community-edit.js +50 -0
- package/dist/node/publications/community-edit/community-edit.js.map +1 -0
- package/dist/node/publications/community-edit/schema.d.ts +467 -0
- package/dist/node/publications/community-edit/schema.js +36 -0
- package/dist/node/publications/community-edit/schema.js.map +1 -0
- package/dist/node/publications/community-edit/types.d.ts +19 -0
- package/dist/node/publications/community-edit/types.js +2 -0
- package/dist/node/publications/community-edit/types.js.map +1 -0
- package/dist/node/publications/publication-author.d.ts +22 -0
- package/dist/node/publications/publication-author.js +66 -0
- package/dist/node/publications/publication-author.js.map +1 -0
- package/dist/node/publications/publication-client-manager.d.ts +62 -0
- package/dist/node/publications/publication-client-manager.js +257 -0
- package/dist/node/publications/publication-client-manager.js.map +1 -0
- package/dist/node/publications/publication-clients.d.ts +19 -0
- package/dist/node/publications/publication-clients.js +12 -0
- package/dist/node/publications/publication-clients.js.map +1 -0
- package/dist/node/publications/publication-community.d.ts +55 -0
- package/dist/node/publications/publication-community.js +87 -0
- package/dist/node/publications/publication-community.js.map +1 -0
- package/dist/node/publications/publication.d.ts +120 -0
- package/dist/node/publications/publication.js +950 -0
- package/dist/node/publications/publication.js.map +1 -0
- package/dist/node/publications/types.d.ts +26 -0
- package/dist/node/publications/types.js +2 -0
- package/dist/node/publications/types.js.map +1 -0
- package/dist/node/publications/vote/schema.d.ts +150 -0
- package/dist/node/publications/vote/schema.js +44 -0
- package/dist/node/publications/vote/schema.js.map +1 -0
- package/dist/node/publications/vote/types.d.ts +21 -0
- package/dist/node/publications/vote/types.js +2 -0
- package/dist/node/publications/vote/types.js.map +1 -0
- package/dist/node/publications/vote/vote.d.ts +36 -0
- package/dist/node/publications/vote/vote.js +49 -0
- package/dist/node/publications/vote/vote.js.map +1 -0
- package/dist/node/pubsub-messages/schema.d.ts +964 -0
- package/dist/node/pubsub-messages/schema.js +98 -0
- package/dist/node/pubsub-messages/schema.js.map +1 -0
- package/dist/node/pubsub-messages/types.d.ts +81 -0
- package/dist/node/pubsub-messages/types.js +2 -0
- package/dist/node/pubsub-messages/types.js.map +1 -0
- package/dist/node/rpc/src/index.d.ts +483 -0
- package/dist/node/rpc/src/index.js +1267 -0
- package/dist/node/rpc/src/index.js.map +1 -0
- package/dist/node/rpc/src/json-rpc-util.d.ts +1 -0
- package/dist/node/rpc/src/json-rpc-util.js +19 -0
- package/dist/node/rpc/src/json-rpc-util.js.map +1 -0
- package/dist/node/rpc/src/lib/pkc-js/index.d.ts +132 -0
- package/dist/node/rpc/src/lib/pkc-js/index.js +29 -0
- package/dist/node/rpc/src/lib/pkc-js/index.js.map +1 -0
- package/dist/node/rpc/src/lib/pkc-js/pkc-js-mock.d.ts +1 -0
- package/dist/node/rpc/src/lib/pkc-js/pkc-js-mock.js +472 -0
- package/dist/node/rpc/src/lib/pkc-js/pkc-js-mock.js.map +1 -0
- package/dist/node/rpc/src/schema.d.ts +843 -0
- package/dist/node/rpc/src/schema.js +28 -0
- package/dist/node/rpc/src/schema.js.map +1 -0
- package/dist/node/rpc/src/types.d.ts +24 -0
- package/dist/node/rpc/src/types.js +2 -0
- package/dist/node/rpc/src/types.js.map +1 -0
- package/dist/node/rpc/src/utils.d.ts +7 -0
- package/dist/node/rpc/src/utils.js +58 -0
- package/dist/node/rpc/src/utils.js.map +1 -0
- package/dist/node/runtime/browser/community/challenges/index.d.ts +6 -0
- package/dist/node/runtime/browser/community/challenges/index.js +7 -0
- package/dist/node/runtime/browser/community/challenges/index.js.map +1 -0
- package/dist/node/runtime/browser/community/local-community.d.ts +3 -0
- package/dist/node/runtime/browser/community/local-community.js +6 -0
- package/dist/node/runtime/browser/community/local-community.js.map +1 -0
- package/dist/node/runtime/browser/db-handler.d.ts +4 -0
- package/dist/node/runtime/browser/db-handler.js +8 -0
- package/dist/node/runtime/browser/db-handler.js.map +1 -0
- package/dist/node/runtime/browser/localforage-lru.d.ts +15 -0
- package/dist/node/runtime/browser/localforage-lru.js +140 -0
- package/dist/node/runtime/browser/localforage-lru.js.map +1 -0
- package/dist/node/runtime/browser/lru-storage.d.ts +14 -0
- package/dist/node/runtime/browser/lru-storage.js +34 -0
- package/dist/node/runtime/browser/lru-storage.js.map +1 -0
- package/dist/node/runtime/browser/native-functions.d.ts +3 -0
- package/dist/node/runtime/browser/native-functions.js +6 -0
- package/dist/node/runtime/browser/native-functions.js.map +1 -0
- package/dist/node/runtime/browser/polyfill.d.ts +3 -0
- package/dist/node/runtime/browser/polyfill.js +37 -0
- package/dist/node/runtime/browser/polyfill.js.map +1 -0
- package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +1 -0
- package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +4 -0
- package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
- package/dist/node/runtime/browser/storage.d.ts +13 -0
- package/dist/node/runtime/browser/storage.js +37 -0
- package/dist/node/runtime/browser/storage.js.map +1 -0
- package/dist/node/runtime/browser/util.d.ts +14 -0
- package/dist/node/runtime/browser/util.js +61 -0
- package/dist/node/runtime/browser/util.js.map +1 -0
- package/dist/node/runtime/node/address-rewriter-db.d.ts +31 -0
- package/dist/node/runtime/node/address-rewriter-db.js +156 -0
- package/dist/node/runtime/node/address-rewriter-db.js.map +1 -0
- package/dist/node/runtime/node/addresses-rewriter-proxy-server.d.ts +45 -0
- package/dist/node/runtime/node/addresses-rewriter-proxy-server.js +493 -0
- package/dist/node/runtime/node/addresses-rewriter-proxy-server.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/exclude/exclude.d.ts +8 -0
- package/dist/node/runtime/node/community/challenges/exclude/exclude.js +280 -0
- package/dist/node/runtime/node/community/challenges/exclude/exclude.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/exclude/index.d.ts +3 -0
- package/dist/node/runtime/node/community/challenges/exclude/index.js +4 -0
- package/dist/node/runtime/node/community/challenges/exclude/index.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/exclude/rate-limiter.d.ts +5 -0
- package/dist/node/runtime/node/community/challenges/exclude/rate-limiter.js +127 -0
- package/dist/node/runtime/node/community/challenges/exclude/rate-limiter.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/exclude/utils.d.ts +13 -0
- package/dist/node/runtime/node/community/challenges/exclude/utils.js +52 -0
- package/dist/node/runtime/node/community/challenges/exclude/utils.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/index.d.ts +32 -0
- package/dist/node/runtime/node/community/challenges/index.js +307 -0
- package/dist/node/runtime/node/community/challenges/index.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/blacklist.d.ts +5 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/blacklist.js +118 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/blacklist.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/fail.d.ts +5 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/fail.js +26 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/fail.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/publication-match.d.ts +5 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/publication-match.js +135 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/publication-match.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/question.d.ts +5 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/question.js +66 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/question.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/text-math.d.ts +5 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/text-math.js +61 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/text-math.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/whitelist.d.ts +5 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/whitelist.js +118 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/whitelist.js.map +1 -0
- package/dist/node/runtime/node/community/db-handler-types.d.ts +19 -0
- package/dist/node/runtime/node/community/db-handler-types.js +2 -0
- package/dist/node/runtime/node/community/db-handler-types.js.map +1 -0
- package/dist/node/runtime/node/community/db-handler.d.ts +226 -0
- package/dist/node/runtime/node/community/db-handler.js +2462 -0
- package/dist/node/runtime/node/community/db-handler.js.map +1 -0
- package/dist/node/runtime/node/community/db-row-parser.d.ts +19 -0
- package/dist/node/runtime/node/community/db-row-parser.js +40 -0
- package/dist/node/runtime/node/community/db-row-parser.js.map +1 -0
- package/dist/node/runtime/node/community/keyv-better-sqlite3.d.ts +68 -0
- package/dist/node/runtime/node/community/keyv-better-sqlite3.js +251 -0
- package/dist/node/runtime/node/community/keyv-better-sqlite3.js.map +1 -0
- package/dist/node/runtime/node/community/local-community.d.ts +129 -0
- package/dist/node/runtime/node/community/local-community.js +2978 -0
- package/dist/node/runtime/node/community/local-community.js.map +1 -0
- package/dist/node/runtime/node/community/page-generator.d.ts +433 -0
- package/dist/node/runtime/node/community/page-generator.js +441 -0
- package/dist/node/runtime/node/community/page-generator.js.map +1 -0
- package/dist/node/runtime/node/lru-storage.d.ts +14 -0
- package/dist/node/runtime/node/lru-storage.js +40 -0
- package/dist/node/runtime/node/lru-storage.js.map +1 -0
- package/dist/node/runtime/node/native-functions.d.ts +3 -0
- package/dist/node/runtime/node/native-functions.js +7 -0
- package/dist/node/runtime/node/native-functions.js.map +1 -0
- package/dist/node/runtime/node/polyfill.d.ts +3 -0
- package/dist/node/runtime/node/polyfill.js +20 -0
- package/dist/node/runtime/node/polyfill.js.map +1 -0
- package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +4 -0
- package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js +240 -0
- package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
- package/dist/node/runtime/node/sqlite-lru-cache.d.ts +52 -0
- package/dist/node/runtime/node/sqlite-lru-cache.js +127 -0
- package/dist/node/runtime/node/sqlite-lru-cache.js.map +1 -0
- package/dist/node/runtime/node/storage.d.ts +14 -0
- package/dist/node/runtime/node/storage.js +52 -0
- package/dist/node/runtime/node/storage.js.map +1 -0
- package/dist/node/runtime/node/test/helpers/hanging-runner.d.ts +1 -0
- package/dist/node/runtime/node/test/helpers/hanging-runner.js +157 -0
- package/dist/node/runtime/node/test/helpers/hanging-runner.js.map +1 -0
- package/dist/node/runtime/node/test/helpers/run-hanging-node.d.ts +7 -0
- package/dist/node/runtime/node/test/helpers/run-hanging-node.js +68 -0
- package/dist/node/runtime/node/test/helpers/run-hanging-node.js.map +1 -0
- package/dist/node/runtime/node/test/mock-http-router.d.ts +54 -0
- package/dist/node/runtime/node/test/mock-http-router.js +397 -0
- package/dist/node/runtime/node/test/mock-http-router.js.map +1 -0
- package/dist/node/runtime/node/util.d.ts +43 -0
- package/dist/node/runtime/node/util.js +384 -0
- package/dist/node/runtime/node/util.js.map +1 -0
- package/dist/node/schema/schema-util.d.ts +2751 -0
- package/dist/node/schema/schema-util.js +562 -0
- package/dist/node/schema/schema-util.js.map +1 -0
- package/dist/node/schema/schema.d.ts +237 -0
- package/dist/node/schema/schema.js +128 -0
- package/dist/node/schema/schema.js.map +1 -0
- package/dist/node/schema.d.ts +1142 -0
- package/dist/node/schema.js +104 -0
- package/dist/node/schema.js.map +1 -0
- package/dist/node/signer/constants.d.ts +2 -0
- package/dist/node/signer/constants.js +3 -0
- package/dist/node/signer/constants.js.map +1 -0
- package/dist/node/signer/encryption.d.ts +21 -0
- package/dist/node/signer/encryption.js +122 -0
- package/dist/node/signer/encryption.js.map +1 -0
- package/dist/node/signer/index.d.ts +21 -0
- package/dist/node/signer/index.js +49 -0
- package/dist/node/signer/index.js.map +1 -0
- package/dist/node/signer/signatures.d.ts +200 -0
- package/dist/node/signer/signatures.js +594 -0
- package/dist/node/signer/signatures.js.map +1 -0
- package/dist/node/signer/types.d.ts +20 -0
- package/dist/node/signer/types.js +2 -0
- package/dist/node/signer/types.js.map +1 -0
- package/dist/node/signer/util.d.ts +14 -0
- package/dist/node/signer/util.js +156 -0
- package/dist/node/signer/util.js.map +1 -0
- package/dist/node/stats.d.ts +15 -0
- package/dist/node/stats.js +64 -0
- package/dist/node/stats.js.map +1 -0
- package/dist/node/test/mock-ipfs-client.d.ts +34 -0
- package/dist/node/test/mock-ipfs-client.js +208 -0
- package/dist/node/test/mock-ipfs-client.js.map +1 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-publish-pending.scenario.d.ts +8 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js +21 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js.map +1 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-publish.scenario.d.ts +8 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-publish.scenario.js +19 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-publish.scenario.js.map +1 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-update.scenario.d.ts +8 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-update.scenario.js +22 -0
- package/dist/node/test/node/hanging-test/scenarios/comment-update.scenario.js.map +1 -0
- package/dist/node/test/node/hanging-test/scenarios/community-start.scenario.d.ts +8 -0
- package/dist/node/test/node/hanging-test/scenarios/community-start.scenario.js +23 -0
- package/dist/node/test/node/hanging-test/scenarios/community-start.scenario.js.map +1 -0
- package/dist/node/test/node/hanging-test/scenarios/community-update.scenario.d.ts +8 -0
- package/dist/node/test/node/hanging-test/scenarios/community-update.scenario.js +21 -0
- package/dist/node/test/node/hanging-test/scenarios/community-update.scenario.js.map +1 -0
- package/dist/node/test/node/hanging-test/scenarios/destroy-only.scenario.d.ts +7 -0
- package/dist/node/test/node/hanging-test/scenarios/destroy-only.scenario.js +15 -0
- package/dist/node/test/node/hanging-test/scenarios/destroy-only.scenario.js.map +1 -0
- package/dist/node/test/node/hanging-test/scenarios/hanging-test-util.d.ts +30 -0
- package/dist/node/test/node/hanging-test/scenarios/hanging-test-util.js +46 -0
- package/dist/node/test/node/hanging-test/scenarios/hanging-test-util.js.map +1 -0
- package/dist/node/test/test-util.d.ts +1019 -0
- package/dist/node/test/test-util.js +1886 -0
- package/dist/node/test/test-util.js.map +1 -0
- package/dist/node/types.d.ts +165 -0
- package/dist/node/types.js +2 -0
- package/dist/node/types.js.map +1 -0
- package/dist/node/util/inflight-fetch-manager.d.ts +11 -0
- package/dist/node/util/inflight-fetch-manager.js +41 -0
- package/dist/node/util/inflight-fetch-manager.js.map +1 -0
- package/dist/node/util.d.ts +120 -0
- package/dist/node/util.js +816 -0
- package/dist/node/util.js.map +1 -0
- package/dist/node/version.d.ts +7 -0
- package/dist/node/version.js +12 -0
- package/dist/node/version.js.map +1 -0
- package/dist/node/zod-error-map.d.ts +1 -0
- package/dist/node/zod-error-map.js +10 -0
- package/dist/node/zod-error-map.js.map +1 -0
- package/package.json +212 -0
|
@@ -0,0 +1,950 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { decryptEd25519AesGcm, encryptEd25519AesGcm } from "../signer/index.js";
|
|
3
|
+
import Logger from "../logger.js";
|
|
4
|
+
import env from "../version.js";
|
|
5
|
+
import { cleanUpBeforePublishing, signChallengeAnswer, signChallengeRequest, verifyChallengeMessage, verifyChallengeVerification } from "../signer/signatures.js";
|
|
6
|
+
import { deepMergeRuntimeFields, hideClassPrivateProps, isStringDomain, shortifyAddress, timestamp } from "../util.js";
|
|
7
|
+
import { TypedEmitter } from "tiny-typed-emitter";
|
|
8
|
+
import { Comment } from "./comment/comment.js";
|
|
9
|
+
import { PKCError } from "../pkc-error.js";
|
|
10
|
+
import { getBufferedPKCAddressFromPublicKey } from "../signer/util.js";
|
|
11
|
+
import * as cborg from "cborg";
|
|
12
|
+
import * as remeda from "remeda";
|
|
13
|
+
import { findStartedCommunity, findUpdatingCommunity } from "../pkc/tracked-instance-registry-util.js";
|
|
14
|
+
import { parseDecryptedChallengeAnswerWithPKCErrorIfItFails, parseDecryptedChallengeVerification, parseDecryptedChallengeWithPKCErrorIfItFails, parseJsonWithPKCErrorIfFails } from "../schema/schema-util.js";
|
|
15
|
+
import { ChallengeRequestMessageSchema, ChallengeAnswerMessageSchema, ChallengeMessageSchema, ChallengeVerificationMessageSchema } from "../pubsub-messages/schema.js";
|
|
16
|
+
import { decodeRpcChallengeAnswerPubsubMsg, decodeRpcChallengePubsubMsg, decodeRpcChallengeRequestPubsubMsg, decodeRpcChallengeVerificationPubsubMsg } from "../clients/rpc-client/decode-rpc-response-util.js";
|
|
17
|
+
import { PublicationClientsManager } from "./publication-client-manager.js";
|
|
18
|
+
import { buildRuntimeAuthor } from "./publication-author.js";
|
|
19
|
+
import { buildRuntimeCommunityFields, normalizeCommunityInputFromCommunity } from "./publication-community.js";
|
|
20
|
+
class Publication extends TypedEmitter {
|
|
21
|
+
constructor(pkc) {
|
|
22
|
+
super();
|
|
23
|
+
this.raw = {};
|
|
24
|
+
// private
|
|
25
|
+
this._community = undefined; // will be used for publishing
|
|
26
|
+
this._challengeExchanges = {};
|
|
27
|
+
this._rpcPublishSubscriptionId = undefined;
|
|
28
|
+
this._pkc = pkc;
|
|
29
|
+
this._updatePublishingStateWithEmission("stopped");
|
|
30
|
+
this._setStateWithEmission("stopped");
|
|
31
|
+
this._initClients();
|
|
32
|
+
this._handleChallengeExchange = this._handleChallengeExchange.bind(this);
|
|
33
|
+
this.publish = this.publish.bind(this);
|
|
34
|
+
this.on("error", (...args) => this.listenerCount("error") === 1 && this._pkc.emit("error", ...args)); // only bubble up to pkc if no other listeners are attached
|
|
35
|
+
this._publishToDifferentProviderThresholdSeconds = 10;
|
|
36
|
+
this._setProviderFailureThresholdSeconds = 60 * 2; // Two minutes
|
|
37
|
+
// public method should be bound
|
|
38
|
+
this.publishChallengeAnswers = this.publishChallengeAnswers.bind(this);
|
|
39
|
+
hideClassPrivateProps(this);
|
|
40
|
+
}
|
|
41
|
+
_initClients() {
|
|
42
|
+
this._clientsManager = new PublicationClientsManager(this);
|
|
43
|
+
this.clients = this._clientsManager.clients;
|
|
44
|
+
}
|
|
45
|
+
setCommunityAddress(communityAddress) {
|
|
46
|
+
this.communityAddress = communityAddress;
|
|
47
|
+
this.shortCommunityAddress = shortifyAddress(communityAddress);
|
|
48
|
+
}
|
|
49
|
+
_initBaseRemoteProps(props) {
|
|
50
|
+
const communityFields = buildRuntimeCommunityFields({ publication: props });
|
|
51
|
+
this.setCommunityAddress(communityFields.communityAddress);
|
|
52
|
+
this.communityPublicKey = communityFields.communityPublicKey;
|
|
53
|
+
this.communityName = communityFields.communityName;
|
|
54
|
+
this.timestamp = props.timestamp;
|
|
55
|
+
this.signature = props.signature;
|
|
56
|
+
const runtimeAuthor = buildRuntimeAuthor({
|
|
57
|
+
author: props.author,
|
|
58
|
+
signaturePublicKey: props.signature.publicKey
|
|
59
|
+
});
|
|
60
|
+
this.author = { ...runtimeAuthor, shortAddress: shortifyAddress(runtimeAuthor.address) };
|
|
61
|
+
this.protocolVersion = props.protocolVersion;
|
|
62
|
+
}
|
|
63
|
+
_initUnsignedLocalProps(opts) {
|
|
64
|
+
this.raw.unsignedPublicationOptions = opts.unsignedOptions;
|
|
65
|
+
this.challengeRequest = opts.challengeRequest;
|
|
66
|
+
this.signer = opts.unsignedOptions.signer;
|
|
67
|
+
this.communityAddress = opts.unsignedOptions.communityAddress;
|
|
68
|
+
this.shortCommunityAddress = shortifyAddress(opts.unsignedOptions.communityAddress);
|
|
69
|
+
// Derive communityName/communityPublicKey from communityAddress if not explicitly provided
|
|
70
|
+
if (opts.unsignedOptions.communityPublicKey)
|
|
71
|
+
this.communityPublicKey = opts.unsignedOptions.communityPublicKey;
|
|
72
|
+
else if (!isStringDomain(opts.unsignedOptions.communityAddress))
|
|
73
|
+
this.communityPublicKey = opts.unsignedOptions.communityAddress;
|
|
74
|
+
if (opts.unsignedOptions.communityName)
|
|
75
|
+
this.communityName = opts.unsignedOptions.communityName;
|
|
76
|
+
else if (isStringDomain(opts.unsignedOptions.communityAddress))
|
|
77
|
+
this.communityName = opts.unsignedOptions.communityAddress;
|
|
78
|
+
this.timestamp = opts.unsignedOptions.timestamp;
|
|
79
|
+
this.protocolVersion = opts.unsignedOptions.protocolVersion;
|
|
80
|
+
const runtimeAuthor = buildRuntimeAuthor({
|
|
81
|
+
author: opts.unsignedOptions.author,
|
|
82
|
+
signaturePublicKey: opts.unsignedOptions.signer.publicKey
|
|
83
|
+
});
|
|
84
|
+
this.author = { ...runtimeAuthor, shortAddress: shortifyAddress(runtimeAuthor.address) };
|
|
85
|
+
}
|
|
86
|
+
async _signPublicationOptionsToPublish(_cleanedPublication) {
|
|
87
|
+
throw new Error(`Should be implemented by children of Publication`);
|
|
88
|
+
}
|
|
89
|
+
async _signPublication({ communityFields }) {
|
|
90
|
+
if (!this.raw.unsignedPublicationOptions)
|
|
91
|
+
throw Error("No unsigned publication options to sign");
|
|
92
|
+
const optionsWithCommunity = {
|
|
93
|
+
...this.raw.unsignedPublicationOptions,
|
|
94
|
+
...communityFields
|
|
95
|
+
};
|
|
96
|
+
const cleaned = cleanUpBeforePublishing(optionsWithCommunity);
|
|
97
|
+
const signature = await this._signPublicationOptionsToPublish(cleaned);
|
|
98
|
+
const signedPublicationFields = Object.fromEntries(signature.signedPropertyNames.map((propertyName) => [propertyName, cleaned[propertyName]]));
|
|
99
|
+
const signedPublication = {
|
|
100
|
+
...signedPublicationFields,
|
|
101
|
+
signature
|
|
102
|
+
};
|
|
103
|
+
this.raw.pubsubMessageToPublish = signedPublication;
|
|
104
|
+
delete this.raw.unsignedPublicationOptions;
|
|
105
|
+
this._initBaseRemoteProps(signedPublication);
|
|
106
|
+
}
|
|
107
|
+
async _signPublicationWithCommunityFields() {
|
|
108
|
+
if (!this._community)
|
|
109
|
+
throw Error("Community must be loaded before signing");
|
|
110
|
+
const communityFields = normalizeCommunityInputFromCommunity({ communityInstance: this._community });
|
|
111
|
+
await this._signPublication({ communityFields });
|
|
112
|
+
}
|
|
113
|
+
async _signPublicationWithKnownCommunityFieldsIfAvailable() {
|
|
114
|
+
if (!this.communityPublicKey || this.raw.pubsubMessageToPublish || !this.raw.unsignedPublicationOptions)
|
|
115
|
+
return;
|
|
116
|
+
await this._signPublication({
|
|
117
|
+
communityFields: {
|
|
118
|
+
communityPublicKey: this.communityPublicKey,
|
|
119
|
+
...(this.communityName ? { communityName: this.communityName } : {})
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
async _validateSignatureHook() {
|
|
124
|
+
// Subclasses override to validate signature after signing
|
|
125
|
+
}
|
|
126
|
+
async _verifyDecryptedChallengeVerificationAndUpdateCommentProps(decryptedVerification) {
|
|
127
|
+
throw Error("should be handled in comment, not publication");
|
|
128
|
+
}
|
|
129
|
+
getType() {
|
|
130
|
+
throw new Error(`Should be implemented by children of Publication`);
|
|
131
|
+
}
|
|
132
|
+
toJSONPubsubRequestToEncrypt() {
|
|
133
|
+
if (!this.raw.pubsubMessageToPublish)
|
|
134
|
+
throw Error("raw.pubsubMessageToPublish must be defined before calling toJSONPubsubRequestToEncrypt");
|
|
135
|
+
return {
|
|
136
|
+
[this.getType()]: this.raw.pubsubMessageToPublish,
|
|
137
|
+
...this.challengeRequest
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
async _handleRpcChallengeVerification(verification, runtimeFields) {
|
|
141
|
+
const log = Logger("pkc-js:publication:_handleRpcChallengeVerification");
|
|
142
|
+
if (verification.comment)
|
|
143
|
+
await this._verifyDecryptedChallengeVerificationAndUpdateCommentProps(verification);
|
|
144
|
+
if (this instanceof Comment && runtimeFields)
|
|
145
|
+
deepMergeRuntimeFields(this, runtimeFields);
|
|
146
|
+
this._setRpcClientState("stopped");
|
|
147
|
+
const newPublishingState = verification.challengeSuccess ? "succeeded" : "failed";
|
|
148
|
+
this._changePublicationStateEmitEventEmitStateChangeEvent({
|
|
149
|
+
newPublishingState,
|
|
150
|
+
newState: "stopped",
|
|
151
|
+
event: {
|
|
152
|
+
name: "challengeverification",
|
|
153
|
+
args: [verification, this instanceof Comment && verification.comment ? this : undefined]
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
if (this._rpcPublishSubscriptionId) {
|
|
157
|
+
try {
|
|
158
|
+
await this._pkc._pkcRpcClient.unsubscribe(this._rpcPublishSubscriptionId);
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
log.error("Failed to unsubscribe from publication publish", e);
|
|
162
|
+
}
|
|
163
|
+
this._rpcPublishSubscriptionId = undefined;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async _handleIncomingChallengePubsubMessage(msg) {
|
|
167
|
+
const log = Logger("pkc-js:publication:_handleIncomingChallengePubsubMessage");
|
|
168
|
+
if (Object.values(this._challengeExchanges).some((exchange) => exchange.challenge))
|
|
169
|
+
return; // We only process one challenge
|
|
170
|
+
const challengeMsgValidity = await verifyChallengeMessage({
|
|
171
|
+
challenge: msg,
|
|
172
|
+
pubsubTopic: this._communityPubsubTopicWithFallback(),
|
|
173
|
+
validateTimestampRange: true
|
|
174
|
+
});
|
|
175
|
+
if (!challengeMsgValidity.valid) {
|
|
176
|
+
const error = new PKCError("ERR_CHALLENGE_SIGNATURE_IS_INVALID", {
|
|
177
|
+
pubsubMsg: msg,
|
|
178
|
+
reason: challengeMsgValidity.reason
|
|
179
|
+
});
|
|
180
|
+
log.error("received challenge message with invalid signature", error.toString());
|
|
181
|
+
this._changePublicationStateEmitEventEmitStateChangeEvent({
|
|
182
|
+
newPublishingState: "failed",
|
|
183
|
+
event: { name: "error", args: [error] }
|
|
184
|
+
});
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
log(`Received encrypted challenges. Will decrypt and emit them on "challenge" event. User shoud publish solution by calling publishChallengeAnswers`);
|
|
188
|
+
const pubsubSigner = this._challengeExchanges[msg.challengeRequestId.toString()].signer;
|
|
189
|
+
if (!pubsubSigner)
|
|
190
|
+
throw Error("Signer is undefined for this challenge exchange");
|
|
191
|
+
let decryptedRawString;
|
|
192
|
+
try {
|
|
193
|
+
decryptedRawString = await decryptEd25519AesGcm(msg.encrypted, pubsubSigner.privateKey, this._community.encryption.publicKey);
|
|
194
|
+
}
|
|
195
|
+
catch (e) {
|
|
196
|
+
const pkcError = new PKCError("ERR_PUBLICATION_FAILED_TO_DECRYPT_CHALLENGE", { decryptErr: e });
|
|
197
|
+
log.error("could not decrypt challengemessage.encrypted", pkcError.toString());
|
|
198
|
+
this._changePublicationStateEmitEventEmitStateChangeEvent({
|
|
199
|
+
newPublishingState: "failed",
|
|
200
|
+
event: { name: "error", args: [pkcError] }
|
|
201
|
+
});
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
let decryptedJson;
|
|
205
|
+
try {
|
|
206
|
+
decryptedJson = await parseJsonWithPKCErrorIfFails(decryptedRawString);
|
|
207
|
+
}
|
|
208
|
+
catch (e) {
|
|
209
|
+
log.error("could not parse decrypted challengemessage.encrypted as a json", String(e));
|
|
210
|
+
this._changePublicationStateEmitEventEmitStateChangeEvent({
|
|
211
|
+
newPublishingState: "failed",
|
|
212
|
+
event: { name: "error", args: [e] }
|
|
213
|
+
});
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
let decryptedChallenge;
|
|
217
|
+
try {
|
|
218
|
+
decryptedChallenge = parseDecryptedChallengeWithPKCErrorIfItFails(decryptedJson);
|
|
219
|
+
}
|
|
220
|
+
catch (e) {
|
|
221
|
+
log.error("could not parse z challengemessage.encrypted as a json", String(e));
|
|
222
|
+
this._changePublicationStateEmitEventEmitStateChangeEvent({
|
|
223
|
+
newPublishingState: "failed",
|
|
224
|
+
event: { name: "error", args: [e] }
|
|
225
|
+
});
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const decryptedChallengeMsg = {
|
|
229
|
+
...msg,
|
|
230
|
+
...decryptedChallenge
|
|
231
|
+
};
|
|
232
|
+
this._challengeExchanges[msg.challengeRequestId.toString()].challenge = decryptedChallengeMsg;
|
|
233
|
+
this._updatePublishingStateWithEmission("waiting-challenge-answers");
|
|
234
|
+
const subscribedProviders = Object.entries(this._clientsManager.pubsubProviderSubscriptions)
|
|
235
|
+
.filter(([, pubsubTopics]) => pubsubTopics.includes(this._communityPubsubTopicWithFallback()))
|
|
236
|
+
.map(([provider]) => provider);
|
|
237
|
+
subscribedProviders.forEach((provider) => this._updatePubsubState("waiting-challenge-answers", provider));
|
|
238
|
+
this.emit("challenge", decryptedChallengeMsg);
|
|
239
|
+
}
|
|
240
|
+
async _handleIncomingChallengeVerificationPubsubMessage(msg) {
|
|
241
|
+
const log = Logger("pkc-js:publication:_handleIncomingChallengeVerificationPubsubMessage");
|
|
242
|
+
if (this._challengeExchanges[msg.challengeRequestId.toString()].challengeVerification)
|
|
243
|
+
return;
|
|
244
|
+
const signatureValidation = await verifyChallengeVerification({
|
|
245
|
+
verification: msg,
|
|
246
|
+
pubsubTopic: this._communityPubsubTopicWithFallback(),
|
|
247
|
+
validateTimestampRange: true
|
|
248
|
+
});
|
|
249
|
+
if (!signatureValidation.valid) {
|
|
250
|
+
const error = new PKCError("ERR_CHALLENGE_VERIFICATION_SIGNATURE_IS_INVALID", {
|
|
251
|
+
pubsubMsg: msg,
|
|
252
|
+
reason: signatureValidation.reason
|
|
253
|
+
});
|
|
254
|
+
log.error("Publication received a challenge verification with invalid signature", error);
|
|
255
|
+
this._changePublicationStateEmitEventEmitStateChangeEvent({
|
|
256
|
+
newPublishingState: "failed",
|
|
257
|
+
event: { name: "error", args: [error] }
|
|
258
|
+
});
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
let decryptedChallengeVerification;
|
|
262
|
+
let newPublishingState;
|
|
263
|
+
if (msg.challengeSuccess) {
|
|
264
|
+
newPublishingState = "succeeded";
|
|
265
|
+
log(`Received a challengeverification with challengeSuccess=true`, "for publication", this.getType());
|
|
266
|
+
if (msg.encrypted) {
|
|
267
|
+
let decryptedRawString;
|
|
268
|
+
const pubsubSigner = this._challengeExchanges[msg.challengeRequestId.toString()].signer;
|
|
269
|
+
if (!pubsubSigner)
|
|
270
|
+
throw Error("Signer is undefined for this challenge exchange");
|
|
271
|
+
try {
|
|
272
|
+
decryptedRawString = await decryptEd25519AesGcm(msg.encrypted, pubsubSigner.privateKey, this._community.encryption.publicKey);
|
|
273
|
+
}
|
|
274
|
+
catch (e) {
|
|
275
|
+
const pkcError = new PKCError("ERR_INVALID_CHALLENGE_VERIFICATION_DECRYPTED_SCHEMA", {
|
|
276
|
+
decryptErr: e,
|
|
277
|
+
challenegVerificationMsg: msg
|
|
278
|
+
});
|
|
279
|
+
log.error("could not decrypt challengeverification.encrypted", pkcError);
|
|
280
|
+
this.emit("error", pkcError);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
let decryptedJson;
|
|
284
|
+
try {
|
|
285
|
+
decryptedJson = await parseJsonWithPKCErrorIfFails(decryptedRawString);
|
|
286
|
+
}
|
|
287
|
+
catch (e) {
|
|
288
|
+
log.error("could not parse decrypted challengeverification.encrypted as a json", e);
|
|
289
|
+
this.emit("error", e);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
try {
|
|
293
|
+
decryptedChallengeVerification = parseDecryptedChallengeVerification(decryptedJson);
|
|
294
|
+
}
|
|
295
|
+
catch (e) {
|
|
296
|
+
log.error("could not parse challengeverification.encrypted due to invalid schema", e);
|
|
297
|
+
this.emit("error", e);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (decryptedChallengeVerification.comment) {
|
|
301
|
+
await this._verifyDecryptedChallengeVerificationAndUpdateCommentProps(decryptedChallengeVerification);
|
|
302
|
+
log("Updated the props of this instance with challengeverification.encrypted");
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
newPublishingState = "failed";
|
|
308
|
+
log.error(`Challenge exchange with publication`, this.getType(), `has failed to pass`, "Challenge errors", msg.challengeErrors, `reason`, msg.reason);
|
|
309
|
+
}
|
|
310
|
+
const challengeVerificationMsg = { ...msg, ...decryptedChallengeVerification };
|
|
311
|
+
this._challengeExchanges[msg.challengeRequestId.toString()].challengeVerification = challengeVerificationMsg;
|
|
312
|
+
Object.values(this._challengeExchanges).forEach((exchange) => this._updatePubsubState("stopped", exchange.providerUrl));
|
|
313
|
+
this._changePublicationStateEmitEventEmitStateChangeEvent({
|
|
314
|
+
newPublishingState,
|
|
315
|
+
newState: "stopped",
|
|
316
|
+
event: {
|
|
317
|
+
name: "challengeverification",
|
|
318
|
+
args: [challengeVerificationMsg, this instanceof Comment && decryptedChallengeVerification ? this : undefined]
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
await this._postSucessOrFailurePublishing();
|
|
322
|
+
}
|
|
323
|
+
async _handleChallengeExchange(pubsubMsg) {
|
|
324
|
+
const log = Logger("pkc-js:publication:handleChallengeExchange");
|
|
325
|
+
let decodedJson;
|
|
326
|
+
try {
|
|
327
|
+
decodedJson = cborg.decode(pubsubMsg.data);
|
|
328
|
+
}
|
|
329
|
+
catch (e) {
|
|
330
|
+
log.error("Failed to decode pubsub message", e);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const pubsubSchemas = [
|
|
334
|
+
ChallengeVerificationMessageSchema.loose(),
|
|
335
|
+
ChallengeMessageSchema.loose(),
|
|
336
|
+
ChallengeRequestMessageSchema.loose(),
|
|
337
|
+
ChallengeAnswerMessageSchema.loose()
|
|
338
|
+
];
|
|
339
|
+
let pubsubMsgParsed;
|
|
340
|
+
for (const pubsubSchema of pubsubSchemas) {
|
|
341
|
+
const parseRes = pubsubSchema.safeParse(decodedJson);
|
|
342
|
+
if (parseRes.success) {
|
|
343
|
+
pubsubMsgParsed = parseRes.data;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (!pubsubMsgParsed) {
|
|
348
|
+
log.error(`Failed to parse the schema of decoded pubsub message`, decodedJson);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (pubsubMsgParsed.type === "CHALLENGEREQUEST" || pubsubMsgParsed.type === "CHALLENGEANSWER") {
|
|
352
|
+
log.trace("Received unrelated pubsub message of type", pubsubMsgParsed.type);
|
|
353
|
+
}
|
|
354
|
+
else if (!Object.values(this._challengeExchanges).some((exchange) => remeda.isDeepEqual(pubsubMsgParsed.challengeRequestId, exchange.challengeRequest.challengeRequestId))) {
|
|
355
|
+
log.trace(`Received pubsub message with different challenge request id, ignoring it`);
|
|
356
|
+
}
|
|
357
|
+
else if (pubsubMsgParsed.type === "CHALLENGE")
|
|
358
|
+
return this._handleIncomingChallengePubsubMessage(pubsubMsgParsed);
|
|
359
|
+
else if (pubsubMsgParsed.type === "CHALLENGEVERIFICATION")
|
|
360
|
+
return this._handleIncomingChallengeVerificationPubsubMessage(pubsubMsgParsed);
|
|
361
|
+
}
|
|
362
|
+
_updatePubsubState(pubsubState, keyOrUrl) {
|
|
363
|
+
if (this._publishingToLocalCommunity)
|
|
364
|
+
return; // there's no pubsub for local community
|
|
365
|
+
const kuboOrHelia = this._clientsManager.getDefaultPubsubKuboRpcClientOrHelia();
|
|
366
|
+
if ("_helia" in kuboOrHelia)
|
|
367
|
+
this._clientsManager.updateLibp2pJsClientState(pubsubState, keyOrUrl);
|
|
368
|
+
else
|
|
369
|
+
this._clientsManager.updateKuboRpcPubsubState(pubsubState, keyOrUrl);
|
|
370
|
+
}
|
|
371
|
+
async publishChallengeAnswers(challengeAnswers) {
|
|
372
|
+
const log = Logger("pkc-js:publication:publishChallengeAnswers");
|
|
373
|
+
const toEncryptAnswers = parseDecryptedChallengeAnswerWithPKCErrorIfItFails({
|
|
374
|
+
challengeAnswers: challengeAnswers
|
|
375
|
+
});
|
|
376
|
+
if (this._pkc._pkcRpcClient && typeof this._rpcPublishSubscriptionId === "number") {
|
|
377
|
+
return this._pkc._pkcRpcClient.publishChallengeAnswers(this._rpcPublishSubscriptionId, toEncryptAnswers.challengeAnswers);
|
|
378
|
+
}
|
|
379
|
+
const challengeExchangesWithChallenge = Object.values(this._challengeExchanges).filter((exchange) => exchange.challenge);
|
|
380
|
+
if (challengeExchangesWithChallenge.length === 0)
|
|
381
|
+
throw Error("No challenge exchanges with challenge");
|
|
382
|
+
if (challengeExchangesWithChallenge.length > 1)
|
|
383
|
+
throw Error("We should only have one challenge exchange with challenge");
|
|
384
|
+
const challengeExchange = challengeExchangesWithChallenge[0];
|
|
385
|
+
assert(this._community, "Local pkc-js needs publication._community to be defined to publish challenge answer");
|
|
386
|
+
if (!challengeExchange.signer)
|
|
387
|
+
throw Error("Signer is undefined for this challenge exchange");
|
|
388
|
+
const encryptedChallengeAnswers = await encryptEd25519AesGcm(JSON.stringify(toEncryptAnswers), challengeExchange.signer.privateKey, this._community.encryption.publicKey);
|
|
389
|
+
const toSignAnswer = cleanUpBeforePublishing({
|
|
390
|
+
type: "CHALLENGEANSWER",
|
|
391
|
+
challengeRequestId: challengeExchange.challengeRequest.challengeRequestId,
|
|
392
|
+
encrypted: encryptedChallengeAnswers,
|
|
393
|
+
userAgent: this._pkc.userAgent,
|
|
394
|
+
protocolVersion: env.PROTOCOL_VERSION,
|
|
395
|
+
timestamp: timestamp()
|
|
396
|
+
});
|
|
397
|
+
const answerMsgToPublish = {
|
|
398
|
+
...toSignAnswer,
|
|
399
|
+
signature: await signChallengeAnswer({ challengeAnswer: toSignAnswer, signer: challengeExchange.signer })
|
|
400
|
+
};
|
|
401
|
+
// TODO should be handling multiple providers with publishing challenge answer?
|
|
402
|
+
// For now, let's just publish to the provider that got us the challenge and its request
|
|
403
|
+
this._updatePublishingStateWithEmission("publishing-challenge-answer");
|
|
404
|
+
this._updatePubsubState("publishing-challenge-answer", challengeExchange.providerUrl);
|
|
405
|
+
if (this._publishingToLocalCommunity) {
|
|
406
|
+
try {
|
|
407
|
+
await this._publishingToLocalCommunity.handleChallengeAnswer(answerMsgToPublish);
|
|
408
|
+
}
|
|
409
|
+
catch (e) {
|
|
410
|
+
this._challengeExchanges[challengeExchange.challengeRequest.challengeRequestId.toString()].challengeAnswerPublishError =
|
|
411
|
+
e;
|
|
412
|
+
this._updatePublishingStateWithEmission("failed");
|
|
413
|
+
this._updatePubsubState("stopped", challengeExchange.providerUrl);
|
|
414
|
+
throw e;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
try {
|
|
419
|
+
await this._clientsManager.pubsubPublishOnProvider(this._communityPubsubTopicWithFallback(), answerMsgToPublish, challengeExchange.providerUrl);
|
|
420
|
+
}
|
|
421
|
+
catch (e) {
|
|
422
|
+
this._challengeExchanges[challengeExchange.challengeRequest.challengeRequestId.toString()].challengeAnswerPublishError =
|
|
423
|
+
e;
|
|
424
|
+
this._updatePublishingStateWithEmission("failed");
|
|
425
|
+
this._updatePubsubState("stopped", challengeExchange.providerUrl);
|
|
426
|
+
throw e;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
const decryptedChallengeAnswer = {
|
|
430
|
+
...toEncryptAnswers,
|
|
431
|
+
...answerMsgToPublish
|
|
432
|
+
};
|
|
433
|
+
this._challengeExchanges[challengeExchange.challengeRequest.challengeRequestId.toString()].challengeAnswer =
|
|
434
|
+
decryptedChallengeAnswer;
|
|
435
|
+
this._challengeExchanges[challengeExchange.challengeRequest.challengeRequestId.toString()].challengeAnswerPublishTimestamp =
|
|
436
|
+
timestamp();
|
|
437
|
+
this._updatePublishingStateWithEmission("waiting-challenge-verification");
|
|
438
|
+
const providers = Object.entries(this._clientsManager.pubsubProviderSubscriptions)
|
|
439
|
+
.filter(([, pubsubTopics]) => pubsubTopics.includes(this._communityPubsubTopicWithFallback()))
|
|
440
|
+
.map(([provider]) => provider);
|
|
441
|
+
providers.forEach((provider) => this._updatePubsubState("waiting-challenge-verification", provider));
|
|
442
|
+
log(`Responded to challenge with answers`, challengeAnswers);
|
|
443
|
+
this.emit("challengeanswer", decryptedChallengeAnswer);
|
|
444
|
+
}
|
|
445
|
+
_validatePublicationFields() {
|
|
446
|
+
if (typeof this.timestamp !== "number" || this.timestamp < 0)
|
|
447
|
+
throw new PKCError("ERR_PUBLICATION_MISSING_FIELD", { type: this.getType, timestamp: this.timestamp });
|
|
448
|
+
if (typeof this.author?.address !== "string")
|
|
449
|
+
throw new PKCError("ERR_PUBLICATION_MISSING_FIELD", { type: this.getType(), authorAddress: this.author?.address });
|
|
450
|
+
if (typeof this.communityAddress !== "string")
|
|
451
|
+
throw new PKCError("ERR_PUBLICATION_MISSING_FIELD", { type: this.getType(), communityAddress: this.communityAddress });
|
|
452
|
+
}
|
|
453
|
+
_validateCommunityFields() {
|
|
454
|
+
if (typeof this._community?.encryption?.publicKey !== "string")
|
|
455
|
+
throw new PKCError("ERR_COMMUNITY_MISSING_FIELD", { communityPublicKey: this._community?.encryption?.publicKey });
|
|
456
|
+
if (typeof this._communityPubsubTopicWithFallback() !== "string")
|
|
457
|
+
throw new PKCError("ERR_COMMUNITY_MISSING_FIELD", {
|
|
458
|
+
pubsubTopic: this._community?.pubsubTopic,
|
|
459
|
+
address: this._community?.address
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
_updatePublishingStateNoEmission(newState) {
|
|
463
|
+
this.publishingState = newState;
|
|
464
|
+
}
|
|
465
|
+
_updatePublishingStateWithEmission(newState) {
|
|
466
|
+
if (this.publishingState === newState)
|
|
467
|
+
return;
|
|
468
|
+
this.publishingState = newState;
|
|
469
|
+
this.emit("publishingstatechange", this.publishingState);
|
|
470
|
+
}
|
|
471
|
+
_updateRpcClientStateFromPublishingState(publishingState) {
|
|
472
|
+
// We're deriving the the rpc state from publishing state
|
|
473
|
+
const mapper = {
|
|
474
|
+
failed: ["stopped"],
|
|
475
|
+
"fetching-community-ipfs": ["fetching-community-ipfs"],
|
|
476
|
+
"fetching-community-ipns": ["fetching-community-ipns"],
|
|
477
|
+
"publishing-challenge-answer": ["publishing-challenge-answer"],
|
|
478
|
+
"publishing-challenge-request": ["subscribing-pubsub", "publishing-challenge-request"],
|
|
479
|
+
"resolving-community-name": ["resolving-community-name"],
|
|
480
|
+
stopped: ["stopped"],
|
|
481
|
+
succeeded: ["stopped"],
|
|
482
|
+
"waiting-challenge": ["waiting-challenge"],
|
|
483
|
+
"waiting-challenge-answers": ["waiting-challenge-answers"],
|
|
484
|
+
"waiting-challenge-verification": ["waiting-challenge-verification"]
|
|
485
|
+
};
|
|
486
|
+
const newRpcClientState = mapper[publishingState] || [publishingState]; // In case RPC server transmitted a state we don't know about
|
|
487
|
+
newRpcClientState.forEach(this._setRpcClientState.bind(this));
|
|
488
|
+
}
|
|
489
|
+
_setStateNoEmission(newState) {
|
|
490
|
+
if (newState === this.state)
|
|
491
|
+
return;
|
|
492
|
+
this.state = newState;
|
|
493
|
+
}
|
|
494
|
+
_setStateWithEmission(newState) {
|
|
495
|
+
if (newState === this.state)
|
|
496
|
+
return;
|
|
497
|
+
this.state = newState;
|
|
498
|
+
this.emit("statechange", newState);
|
|
499
|
+
}
|
|
500
|
+
_setRpcClientState(newState) {
|
|
501
|
+
const currentRpcUrl = remeda.keys.strict(this.clients.pkcRpcClients)[0];
|
|
502
|
+
if (newState === this.clients.pkcRpcClients[currentRpcUrl].state)
|
|
503
|
+
return;
|
|
504
|
+
this.clients.pkcRpcClients[currentRpcUrl].state = newState;
|
|
505
|
+
this.clients.pkcRpcClients[currentRpcUrl].emit("statechange", newState);
|
|
506
|
+
}
|
|
507
|
+
_communityPubsubTopicWithFallback() {
|
|
508
|
+
const pubsubTopic = this._community?.pubsubTopic || this._community?.address;
|
|
509
|
+
if (typeof pubsubTopic !== "string")
|
|
510
|
+
throw Error("Failed to load the pubsub topic of community");
|
|
511
|
+
return pubsubTopic;
|
|
512
|
+
}
|
|
513
|
+
_getCommunityCache() {
|
|
514
|
+
const cached = this._pkc._memCaches.communityForPublishing.get(this.communityAddress, { allowStale: true });
|
|
515
|
+
if (cached)
|
|
516
|
+
return cached;
|
|
517
|
+
const subInstance = findUpdatingCommunity(this._pkc, { address: this.communityAddress }) ||
|
|
518
|
+
findStartedCommunity(this._pkc, { address: this.communityAddress });
|
|
519
|
+
const subIpfs = subInstance?.raw.communityIpfs;
|
|
520
|
+
if (subIpfs && subInstance.publicKey)
|
|
521
|
+
return {
|
|
522
|
+
address: subInstance.address,
|
|
523
|
+
publicKey: subInstance.publicKey,
|
|
524
|
+
name: subInstance.name,
|
|
525
|
+
encryption: subIpfs.encryption,
|
|
526
|
+
pubsubTopic: subIpfs.pubsubTopic
|
|
527
|
+
};
|
|
528
|
+
return undefined;
|
|
529
|
+
}
|
|
530
|
+
async _fetchCommunityForPublishing() {
|
|
531
|
+
const log = Logger("pkc-js:publish:_fetchCommunityForPublishing");
|
|
532
|
+
const cachedCommunity = this._getCommunityCache();
|
|
533
|
+
if (cachedCommunity) {
|
|
534
|
+
// We will use the cached community even though it's stale
|
|
535
|
+
// And in the background we will fetch a new one and update the cache
|
|
536
|
+
// cache.has will return false if the item is stale
|
|
537
|
+
if (!this._pkc._memCaches.communityForPublishing.has(this.communityAddress)) {
|
|
538
|
+
log("The cache of community is stale, we will use the cached and update in the background");
|
|
539
|
+
this._pkc
|
|
540
|
+
.getCommunity({ address: this.communityAddress })
|
|
541
|
+
.catch((e) => log.error("Failed to update cache of community", this.communityAddress, e));
|
|
542
|
+
}
|
|
543
|
+
return cachedCommunity;
|
|
544
|
+
}
|
|
545
|
+
else
|
|
546
|
+
return this._clientsManager.fetchCommunityForPublishingWithCacheGuard();
|
|
547
|
+
}
|
|
548
|
+
async stop() {
|
|
549
|
+
await this._postSucessOrFailurePublishing();
|
|
550
|
+
this._updatePublishingStateWithEmission("stopped");
|
|
551
|
+
}
|
|
552
|
+
_isAllAttemptsExhausted(maxNumOfChallengeExchanges) {
|
|
553
|
+
// When all providers failed to publish
|
|
554
|
+
// OR they're done with waiting
|
|
555
|
+
if (Object.keys(this._challengeExchanges).length !== maxNumOfChallengeExchanges)
|
|
556
|
+
return false;
|
|
557
|
+
return Object.values(this._challengeExchanges).every((exchange) => {
|
|
558
|
+
if (exchange.challengeRequestPublishError || exchange.challengeAnswerPublishError)
|
|
559
|
+
return true;
|
|
560
|
+
const doneWaitingForChallenge = typeof exchange.challengeRequestPublishTimestamp === "number" &&
|
|
561
|
+
exchange.challengeRequestPublishTimestamp + this._setProviderFailureThresholdSeconds <= timestamp();
|
|
562
|
+
return doneWaitingForChallenge;
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
async _postSucessOrFailurePublishing() {
|
|
566
|
+
const log = Logger("pkc-js:publication:_postSucessOrFailurePublishing");
|
|
567
|
+
this._setStateWithEmission("stopped");
|
|
568
|
+
if (this._rpcPublishSubscriptionId) {
|
|
569
|
+
try {
|
|
570
|
+
await this._pkc._pkcRpcClient.unsubscribe(this._rpcPublishSubscriptionId);
|
|
571
|
+
}
|
|
572
|
+
catch (e) {
|
|
573
|
+
log.error("Failed to unsubscribe from publication publish", e);
|
|
574
|
+
}
|
|
575
|
+
this._rpcPublishSubscriptionId = undefined;
|
|
576
|
+
this._setRpcClientState("stopped");
|
|
577
|
+
}
|
|
578
|
+
else if (this._community) {
|
|
579
|
+
// the client is publishing to pubsub without using PKC RPC
|
|
580
|
+
await this._clientsManager.pubsubUnsubscribe(this._communityPubsubTopicWithFallback(), this._handleChallengeExchange);
|
|
581
|
+
Object.values(this._challengeExchanges).forEach((exchange) => this._updatePubsubState("stopped", exchange.providerUrl));
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
_handleIncomingChallengeRequestFromRpc(args) {
|
|
585
|
+
const encodedRequest = args.params.result;
|
|
586
|
+
const request = decodeRpcChallengeRequestPubsubMsg(encodedRequest);
|
|
587
|
+
this._challengeExchanges[request.challengeRequestId.toString()] = {
|
|
588
|
+
...this._challengeExchanges[request.challengeRequestId.toString()],
|
|
589
|
+
challengeRequest: request,
|
|
590
|
+
challengeRequestPublishTimestamp: timestamp(),
|
|
591
|
+
providerUrl: Object.keys(this.clients.pkcRpcClients)[0]
|
|
592
|
+
};
|
|
593
|
+
this.emit("challengerequest", request);
|
|
594
|
+
}
|
|
595
|
+
_handleIncomingChallengeFromRpc(args) {
|
|
596
|
+
const encodedChallenge = args.params.result;
|
|
597
|
+
const challenge = decodeRpcChallengePubsubMsg(encodedChallenge);
|
|
598
|
+
this._challengeExchanges[challenge.challengeRequestId.toString()] = {
|
|
599
|
+
...this._challengeExchanges[challenge.challengeRequestId.toString()],
|
|
600
|
+
challenge,
|
|
601
|
+
challengeRequestPublishTimestamp: timestamp()
|
|
602
|
+
};
|
|
603
|
+
this.emit("challenge", challenge);
|
|
604
|
+
}
|
|
605
|
+
_handleIncomingChallengeAnswerFromRpc(args) {
|
|
606
|
+
const encodedChallengeAnswer = args.params.result;
|
|
607
|
+
const challengeAnswerMsg = decodeRpcChallengeAnswerPubsubMsg(encodedChallengeAnswer);
|
|
608
|
+
this._challengeExchanges[challengeAnswerMsg.challengeRequestId.toString()] = {
|
|
609
|
+
...this._challengeExchanges[challengeAnswerMsg.challengeRequestId.toString()],
|
|
610
|
+
challengeAnswer: challengeAnswerMsg,
|
|
611
|
+
challengeAnswerPublishTimestamp: timestamp()
|
|
612
|
+
};
|
|
613
|
+
this.emit("challengeanswer", challengeAnswerMsg);
|
|
614
|
+
}
|
|
615
|
+
async _handleIncomingChallengeVerificationFromRpc(args) {
|
|
616
|
+
const { challengeVerification: encoded, runtimeFields } = args.params.result;
|
|
617
|
+
const decoded = decodeRpcChallengeVerificationPubsubMsg(encoded);
|
|
618
|
+
this._challengeExchanges[decoded.challengeRequestId.toString()] = {
|
|
619
|
+
...this._challengeExchanges[decoded.challengeRequestId.toString()],
|
|
620
|
+
challengeVerification: decoded
|
|
621
|
+
};
|
|
622
|
+
await this._handleRpcChallengeVerification(decoded, runtimeFields);
|
|
623
|
+
}
|
|
624
|
+
_handleIncomingPublishingStateFromRpc(args) {
|
|
625
|
+
const publishState = args.params.result.state; // we're optimistic that RPC server transmitted a correct string
|
|
626
|
+
if (publishState === this.publishingState)
|
|
627
|
+
this.emit("publishingstatechange", publishState);
|
|
628
|
+
else
|
|
629
|
+
this._updatePublishingStateWithEmission(publishState);
|
|
630
|
+
this._updateRpcClientStateFromPublishingState(publishState);
|
|
631
|
+
}
|
|
632
|
+
_handleIncomingStateFromRpc(args) {
|
|
633
|
+
const state = args.params.result.state; // optimistic here, we're not validating it via schema
|
|
634
|
+
}
|
|
635
|
+
async _handleIncomingErrorFromRpc(args) {
|
|
636
|
+
const log = Logger("pkc-js:publication:publish:_publishWithRpc:_handleIncomingErrorFromRpc");
|
|
637
|
+
const error = args.params.result;
|
|
638
|
+
if (error.details?.newPublishingState)
|
|
639
|
+
this._updatePublishingStateNoEmission(error.details.newPublishingState);
|
|
640
|
+
if (error.details?.publishThrowError) {
|
|
641
|
+
log.error("RPC server threw an error on publish(), will stop publication", error);
|
|
642
|
+
await this._postSucessOrFailurePublishing();
|
|
643
|
+
}
|
|
644
|
+
this.emit("error", error);
|
|
645
|
+
}
|
|
646
|
+
async _publishWithRpc() {
|
|
647
|
+
if (!this._pkc._pkcRpcClient)
|
|
648
|
+
throw Error("Can't publish to RPC without publication.pkc.pkcRpcClient being defined");
|
|
649
|
+
this._setStateWithEmission("publishing");
|
|
650
|
+
const pubNameToPublishFunction = {
|
|
651
|
+
comment: this._pkc._pkcRpcClient.publishComment,
|
|
652
|
+
vote: this._pkc._pkcRpcClient.publishVote,
|
|
653
|
+
commentEdit: this._pkc._pkcRpcClient.publishCommentEdit,
|
|
654
|
+
commentModeration: this._pkc._pkcRpcClient.publishCommentModeration,
|
|
655
|
+
communityEdit: this._pkc._pkcRpcClient.publishCommunityEdit
|
|
656
|
+
};
|
|
657
|
+
// PKCRpcClient will take care of zod parsing for us
|
|
658
|
+
this._rpcPublishSubscriptionId = await pubNameToPublishFunction[this.getType()].bind(this._pkc._pkcRpcClient)(this.toJSONPubsubRequestToEncrypt());
|
|
659
|
+
if (typeof this._rpcPublishSubscriptionId !== "number") {
|
|
660
|
+
this._updatePublishingStateWithEmission("failed");
|
|
661
|
+
await this._postSucessOrFailurePublishing();
|
|
662
|
+
throw Error("Failed to find the type of publication");
|
|
663
|
+
}
|
|
664
|
+
this._pkc._pkcRpcClient
|
|
665
|
+
.getSubscription(this._rpcPublishSubscriptionId)
|
|
666
|
+
.on("challengerequest", this._handleIncomingChallengeRequestFromRpc.bind(this))
|
|
667
|
+
.on("challenge", this._handleIncomingChallengeFromRpc.bind(this))
|
|
668
|
+
.on("challengeanswer", this._handleIncomingChallengeAnswerFromRpc.bind(this))
|
|
669
|
+
.on("challengeverification", this._handleIncomingChallengeVerificationFromRpc.bind(this))
|
|
670
|
+
.on("publishingstatechange", this._handleIncomingPublishingStateFromRpc.bind(this))
|
|
671
|
+
.on("statechange", this._handleIncomingStateFromRpc.bind(this))
|
|
672
|
+
.on("error", this._handleIncomingErrorFromRpc.bind(this));
|
|
673
|
+
this._pkc._pkcRpcClient.emitAllPendingMessages(this._rpcPublishSubscriptionId);
|
|
674
|
+
}
|
|
675
|
+
_changePublicationStateEmitEventEmitStateChangeEvent(opts) {
|
|
676
|
+
// this code block is only called on a community whose update loop is already started
|
|
677
|
+
// never called in a community that is mirroring a community with an update loop
|
|
678
|
+
const shouldEmitStateChange = opts.newState && opts.newState !== this.state;
|
|
679
|
+
const shouldEmitPublishingstatechange = opts.newPublishingState && opts.newPublishingState !== this.publishingState;
|
|
680
|
+
if (opts.newState)
|
|
681
|
+
this._setStateNoEmission(opts.newState);
|
|
682
|
+
if (opts.newPublishingState)
|
|
683
|
+
this._updatePublishingStateNoEmission(opts.newPublishingState);
|
|
684
|
+
this.emit(opts.event.name, ...opts.event.args);
|
|
685
|
+
if (shouldEmitStateChange)
|
|
686
|
+
this.emit("statechange", this.state);
|
|
687
|
+
if (shouldEmitPublishingstatechange)
|
|
688
|
+
this.emit("publishingstatechange", this.publishingState);
|
|
689
|
+
}
|
|
690
|
+
async _signAndValidateChallengeRequestBeforePublishing(toSignMsg, pubsubSigner) {
|
|
691
|
+
// No validation for now, we might add in the future
|
|
692
|
+
return {
|
|
693
|
+
...toSignMsg,
|
|
694
|
+
signature: await signChallengeRequest({ request: toSignMsg, signer: pubsubSigner })
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
_didWeReceiveChallengeOrChallengeVerification() {
|
|
698
|
+
return Object.values(this._challengeExchanges).some((exchange) => exchange.challenge || exchange.challengeVerification);
|
|
699
|
+
}
|
|
700
|
+
async _generateChallengeRequestToPublish(providerUrl, acceptedChallengeTypes) {
|
|
701
|
+
const log = Logger("pkc-js:publication:publish:_generateChallengeRequestToPublish");
|
|
702
|
+
const pubsubMessageSigner = await this._pkc.createSigner();
|
|
703
|
+
const pubsubMsgToEncrypt = this.toJSONPubsubRequestToEncrypt();
|
|
704
|
+
const encrypted = await encryptEd25519AesGcm(JSON.stringify(pubsubMsgToEncrypt), pubsubMessageSigner.privateKey, this._community.encryption.publicKey);
|
|
705
|
+
const challengeRequestId = await getBufferedPKCAddressFromPublicKey(pubsubMessageSigner.publicKey);
|
|
706
|
+
const toSignMsg = cleanUpBeforePublishing({
|
|
707
|
+
type: "CHALLENGEREQUEST",
|
|
708
|
+
encrypted,
|
|
709
|
+
challengeRequestId,
|
|
710
|
+
acceptedChallengeTypes,
|
|
711
|
+
userAgent: this._pkc.userAgent,
|
|
712
|
+
protocolVersion: env.PROTOCOL_VERSION,
|
|
713
|
+
timestamp: timestamp()
|
|
714
|
+
});
|
|
715
|
+
const challengeRequest = await this._signAndValidateChallengeRequestBeforePublishing(toSignMsg, pubsubMessageSigner);
|
|
716
|
+
log("Attempting to publish", this.getType(), "to pubsub topic", this._communityPubsubTopicWithFallback(), "with provider", providerUrl, "request.encrypted=", pubsubMsgToEncrypt);
|
|
717
|
+
const decryptedChallengeRequest = { ...challengeRequest, ...pubsubMsgToEncrypt };
|
|
718
|
+
this._challengeExchanges[challengeRequestId.toString()] = {
|
|
719
|
+
challengeRequest: decryptedChallengeRequest,
|
|
720
|
+
signer: pubsubMessageSigner,
|
|
721
|
+
providerUrl
|
|
722
|
+
};
|
|
723
|
+
return challengeRequest;
|
|
724
|
+
}
|
|
725
|
+
async _initCommunity() {
|
|
726
|
+
if (this._community)
|
|
727
|
+
return;
|
|
728
|
+
try {
|
|
729
|
+
this._community = await this._fetchCommunityForPublishing();
|
|
730
|
+
this._validateCommunityFields();
|
|
731
|
+
}
|
|
732
|
+
catch (e) {
|
|
733
|
+
this._setStateWithEmission("stopped");
|
|
734
|
+
this._updatePublishingStateWithEmission("failed");
|
|
735
|
+
throw e;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
_challengeExchangesFormattedForErrors() {
|
|
739
|
+
return Object.values(this._challengeExchanges).map((exchange) => ({
|
|
740
|
+
...exchange,
|
|
741
|
+
timedoutWaitingForChallengeRequestResponse: !exchange.challengeVerification &&
|
|
742
|
+
!exchange.challenge &&
|
|
743
|
+
typeof exchange.challengeRequestPublishTimestamp === "number" &&
|
|
744
|
+
exchange.challengeRequestPublishTimestamp + this._setProviderFailureThresholdSeconds <= timestamp()
|
|
745
|
+
}));
|
|
746
|
+
}
|
|
747
|
+
async _handleNotReceivingResponseToChallengeRequest({ providers, currentPubsubProviderIndex, acceptedChallengeTypes }) {
|
|
748
|
+
await new Promise((resolve) => setTimeout(resolve, this._publishToDifferentProviderThresholdSeconds * 1000));
|
|
749
|
+
if (this._didWeReceiveChallengeOrChallengeVerification())
|
|
750
|
+
return;
|
|
751
|
+
// this provider did not get us a challenge or challenge verification
|
|
752
|
+
const currentPubsubProvider = providers[currentPubsubProviderIndex];
|
|
753
|
+
this._pkc._stats.recordGatewayFailure(currentPubsubProvider, "pubsub-publish");
|
|
754
|
+
this._pkc._stats.recordGatewayFailure(currentPubsubProvider, "pubsub-subscribe");
|
|
755
|
+
const log = Logger("pkc-js:publication:publish:_handleNotReceivingResponseToChallengeRequest");
|
|
756
|
+
if (this._isAllAttemptsExhausted(providers.length)) {
|
|
757
|
+
// pkc-js tried all providers and still no response is received
|
|
758
|
+
log.error(`Failed to receive any response for publication`, this.getType());
|
|
759
|
+
await this._postSucessOrFailurePublishing();
|
|
760
|
+
const error = new PKCError("ERR_PUBSUB_DID_NOT_RECEIVE_RESPONSE_AFTER_PUBLISHING_CHALLENGE_REQUEST", {
|
|
761
|
+
challengeExchanges: this._challengeExchangesFormattedForErrors(),
|
|
762
|
+
publishToDifferentProviderThresholdSeconds: this._publishToDifferentProviderThresholdSeconds
|
|
763
|
+
});
|
|
764
|
+
this._changePublicationStateEmitEventEmitStateChangeEvent({
|
|
765
|
+
newPublishingState: "failed",
|
|
766
|
+
event: { name: "error", args: [error] }
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
else if (this.state === "stopped") {
|
|
770
|
+
log.error(`Publication is stopped, will not re-publish`);
|
|
771
|
+
await this._postSucessOrFailurePublishing();
|
|
772
|
+
}
|
|
773
|
+
else {
|
|
774
|
+
if (currentPubsubProviderIndex + 1 === providers.length) {
|
|
775
|
+
log.error(`Failed to receive any response for publication`, this.getType(), "after publishing to all providers", providers);
|
|
776
|
+
await this._postSucessOrFailurePublishing();
|
|
777
|
+
}
|
|
778
|
+
else {
|
|
779
|
+
// let's publish to the next provider
|
|
780
|
+
log(`Re-publishing publication after ${this._publishToDifferentProviderThresholdSeconds}s of not receiving challenge from provider (${currentPubsubProvider})`);
|
|
781
|
+
currentPubsubProviderIndex += 1;
|
|
782
|
+
while (!this._didWeReceiveChallengeOrChallengeVerification() && currentPubsubProviderIndex < providers.length) {
|
|
783
|
+
const providerUrl = providers[currentPubsubProviderIndex];
|
|
784
|
+
const challengeRequest = await this._generateChallengeRequestToPublish(providerUrl, acceptedChallengeTypes);
|
|
785
|
+
this._updatePublishingStateWithEmission("publishing-challenge-request");
|
|
786
|
+
this._updatePubsubState("subscribing-pubsub", providerUrl);
|
|
787
|
+
try {
|
|
788
|
+
await this._clientsManager.pubsubSubscribeOnProvider(this._communityPubsubTopicWithFallback(), this._handleChallengeExchange, providerUrl);
|
|
789
|
+
this._updatePubsubState("publishing-challenge-request", providerUrl);
|
|
790
|
+
await this._clientsManager.pubsubPublishOnProvider(this._communityPubsubTopicWithFallback(), challengeRequest, providerUrl);
|
|
791
|
+
this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequestPublishTimestamp =
|
|
792
|
+
timestamp();
|
|
793
|
+
}
|
|
794
|
+
catch (e) {
|
|
795
|
+
log.error("Failed to publish challenge request using provider ", providerUrl, e);
|
|
796
|
+
this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequestPublishError = e;
|
|
797
|
+
continue;
|
|
798
|
+
}
|
|
799
|
+
finally {
|
|
800
|
+
currentPubsubProviderIndex += 1;
|
|
801
|
+
}
|
|
802
|
+
const decryptedRequest = this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequest;
|
|
803
|
+
this._updatePubsubState("waiting-challenge", providerUrl);
|
|
804
|
+
this._updatePublishingStateWithEmission("waiting-challenge");
|
|
805
|
+
log(`Published a challenge request of publication`, this.getType(), "with provider", providerUrl);
|
|
806
|
+
this.emit("challengerequest", decryptedRequest);
|
|
807
|
+
if (currentPubsubProviderIndex !== providers.length)
|
|
808
|
+
await new Promise((resolve) => setTimeout(resolve, this._publishToDifferentProviderThresholdSeconds * 1000));
|
|
809
|
+
}
|
|
810
|
+
await new Promise((resolve) => setTimeout(resolve, this._setProviderFailureThresholdSeconds * 1000));
|
|
811
|
+
if (this._isAllAttemptsExhausted(providers.length)) {
|
|
812
|
+
await this._postSucessOrFailurePublishing();
|
|
813
|
+
const allAttemptsFailedError = new PKCError("ERR_ALL_PUBSUB_PROVIDERS_THROW_ERRORS", {
|
|
814
|
+
challengeExchanges: this._challengeExchangesFormattedForErrors(),
|
|
815
|
+
pubsubTopic: this._communityPubsubTopicWithFallback()
|
|
816
|
+
});
|
|
817
|
+
log.error("All attempts to publish", this.getType(), "has failed", allAttemptsFailedError);
|
|
818
|
+
this._changePublicationStateEmitEventEmitStateChangeEvent({
|
|
819
|
+
newPublishingState: "failed",
|
|
820
|
+
event: { name: "error", args: [allAttemptsFailedError] }
|
|
821
|
+
});
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
_getPubsubProviders() {
|
|
828
|
+
const providers = this.clients.libp2pJsClients && remeda.keys.strict(this.clients.libp2pJsClients).length > 0
|
|
829
|
+
? remeda.keys.strict(this.clients.libp2pJsClients)
|
|
830
|
+
: remeda.keys.strict(this.clients.pubsubKuboRpcClients);
|
|
831
|
+
if (providers.length === 0)
|
|
832
|
+
throw new PKCError("ERR_NO_PUBSUB_PROVIDERS_AVAILABLE_TO_PUBLISH_OVER_PUBSUB", { providers });
|
|
833
|
+
if (providers.length === 1)
|
|
834
|
+
providers.push(providers[0]); // Same provider should be retried twice if publishing fails
|
|
835
|
+
return providers;
|
|
836
|
+
}
|
|
837
|
+
async _publishWithLocalCommunity(community, challengeRequest) {
|
|
838
|
+
this._publishingToLocalCommunity = community;
|
|
839
|
+
const log = Logger("pkc-js:publication:publish:_publishWithLocalCommunity");
|
|
840
|
+
log("Community is local, will not publish over pubsub, and instead will publish directly to the community by accessing pkc._startedCommunities");
|
|
841
|
+
const communityChallengeListener = async (challenge) => {
|
|
842
|
+
if (challenge.challengeRequestId.toString() === challengeRequest.challengeRequestId.toString()) {
|
|
843
|
+
// need to remove encrypted fields from challenge otherwise _handleIncomingChallengePubsubMessage will throw
|
|
844
|
+
const encryptedFields = ["challenges"];
|
|
845
|
+
log("Received a challenge from the local community", challenge);
|
|
846
|
+
await this._handleIncomingChallengePubsubMessage(remeda.omit(challenge, encryptedFields));
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
community.on("challenge", communityChallengeListener);
|
|
850
|
+
const communityChallengeVerificationListener = async (decryptedChallengeVerification) => {
|
|
851
|
+
if (decryptedChallengeVerification.challengeRequestId.toString() === challengeRequest.challengeRequestId.toString()) {
|
|
852
|
+
log("Received a challenge verification from the local community", decryptedChallengeVerification);
|
|
853
|
+
// need to remove publicatioon fields from challenge verification otherwise verifyChallengeVerification will throw
|
|
854
|
+
const publicationFieldsToRemove = ["comment", "commentUpdate"];
|
|
855
|
+
await this._handleIncomingChallengeVerificationPubsubMessage(remeda.omit(decryptedChallengeVerification, publicationFieldsToRemove));
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
community.on("challengeverification", communityChallengeVerificationListener);
|
|
859
|
+
this.emit("challengerequest", challengeRequest);
|
|
860
|
+
community
|
|
861
|
+
.handleChallengeRequest(challengeRequest, true)
|
|
862
|
+
.then(() => {
|
|
863
|
+
this._challengeExchanges[challengeRequest.challengeRequestId.toString()] = {
|
|
864
|
+
...this._challengeExchanges[challengeRequest.challengeRequestId.toString()],
|
|
865
|
+
challengeRequestPublishTimestamp: timestamp()
|
|
866
|
+
};
|
|
867
|
+
})
|
|
868
|
+
.catch((e) => {
|
|
869
|
+
log.error("Failed to handle challenge request with local community", e);
|
|
870
|
+
this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequestPublishError = e;
|
|
871
|
+
throw e;
|
|
872
|
+
})
|
|
873
|
+
.finally(() => {
|
|
874
|
+
community.removeListener("challenge", communityChallengeListener);
|
|
875
|
+
community.removeListener("challengeverification", communityChallengeVerificationListener);
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
async publish() {
|
|
879
|
+
const log = Logger("pkc-js:publication:publish");
|
|
880
|
+
this._validatePublicationFields();
|
|
881
|
+
this._setStateWithEmission("publishing");
|
|
882
|
+
// Fetch community for BOTH RPC and non-RPC paths (needed for signing)
|
|
883
|
+
await this._initCommunity();
|
|
884
|
+
// Sign the publication with community fields if not yet signed
|
|
885
|
+
if (this.raw.unsignedPublicationOptions && !this.raw.pubsubMessageToPublish) {
|
|
886
|
+
await this._signPublicationWithCommunityFields();
|
|
887
|
+
}
|
|
888
|
+
await this._validateSignatureHook();
|
|
889
|
+
if (this._pkc._pkcRpcClient)
|
|
890
|
+
return this._publishWithRpc();
|
|
891
|
+
const options = { acceptedChallengeTypes: [] };
|
|
892
|
+
const providers = this._getPubsubProviders();
|
|
893
|
+
const startedCommunity = findStartedCommunity(this._pkc, { address: this.communityAddress });
|
|
894
|
+
if (startedCommunity) {
|
|
895
|
+
return this._publishWithLocalCommunity(startedCommunity, await this._generateChallengeRequestToPublish("publishing directly to local community instance", options.acceptedChallengeTypes));
|
|
896
|
+
}
|
|
897
|
+
let currentPubsubProviderIndex = 0;
|
|
898
|
+
while (!this._didWeReceiveChallengeOrChallengeVerification() && currentPubsubProviderIndex < providers.length) {
|
|
899
|
+
const providerUrl = providers[currentPubsubProviderIndex];
|
|
900
|
+
const challengeRequest = await this._generateChallengeRequestToPublish(providerUrl, options.acceptedChallengeTypes);
|
|
901
|
+
this._updatePublishingStateWithEmission("publishing-challenge-request");
|
|
902
|
+
this._updatePubsubState("subscribing-pubsub", providerUrl);
|
|
903
|
+
try {
|
|
904
|
+
// this will throw if we succeed in subscribing first attempt, but then fail to publish
|
|
905
|
+
await this._clientsManager.pubsubSubscribeOnProvider(this._communityPubsubTopicWithFallback(), this._handleChallengeExchange, providerUrl);
|
|
906
|
+
this._updatePubsubState("publishing-challenge-request", providerUrl);
|
|
907
|
+
await this._clientsManager.pubsubPublishOnProvider(this._communityPubsubTopicWithFallback(), challengeRequest, providerUrl);
|
|
908
|
+
this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequestPublishTimestamp = timestamp();
|
|
909
|
+
}
|
|
910
|
+
catch (e) {
|
|
911
|
+
this._updatePubsubState("stopped", providerUrl);
|
|
912
|
+
log.error("Failed to publish challenge request using provider ", providerUrl, e);
|
|
913
|
+
currentPubsubProviderIndex += 1;
|
|
914
|
+
this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequestPublishError = e;
|
|
915
|
+
if (this._isAllAttemptsExhausted(providers.length)) {
|
|
916
|
+
await this._postSucessOrFailurePublishing();
|
|
917
|
+
const allAttemptsFailedError = new PKCError("ERR_ALL_PUBSUB_PROVIDERS_THROW_ERRORS", {
|
|
918
|
+
challengeExchanges: this._challengeExchangesFormattedForErrors(),
|
|
919
|
+
pubsubTopic: this._communityPubsubTopicWithFallback()
|
|
920
|
+
});
|
|
921
|
+
log.error("All attempts to publish", this.getType(), "has failed", allAttemptsFailedError);
|
|
922
|
+
this._changePublicationStateEmitEventEmitStateChangeEvent({
|
|
923
|
+
newPublishingState: "failed",
|
|
924
|
+
event: { name: "error", args: [allAttemptsFailedError] }
|
|
925
|
+
});
|
|
926
|
+
throw allAttemptsFailedError;
|
|
927
|
+
}
|
|
928
|
+
else
|
|
929
|
+
continue;
|
|
930
|
+
}
|
|
931
|
+
const decryptedRequest = this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequest;
|
|
932
|
+
this._updatePubsubState("waiting-challenge", providerUrl);
|
|
933
|
+
this._updatePublishingStateWithEmission("waiting-challenge");
|
|
934
|
+
log(`Published a challenge request of publication`, this.getType(), "with provider", providerUrl);
|
|
935
|
+
this.emit("challengerequest", decryptedRequest);
|
|
936
|
+
break;
|
|
937
|
+
}
|
|
938
|
+
// to handle cases where request is published but we didn't receive response within certain timeframe (20s for now)
|
|
939
|
+
// Maybe the community didn't receive the request, or the provider did not relay the challenge from community for some reason
|
|
940
|
+
this._handleNotReceivingResponseToChallengeRequest({
|
|
941
|
+
providers,
|
|
942
|
+
currentPubsubProviderIndex,
|
|
943
|
+
acceptedChallengeTypes: options.acceptedChallengeTypes
|
|
944
|
+
}).catch((err) => {
|
|
945
|
+
log.error("Failed to handle not receiving response to challenge request", err);
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
export default Publication;
|
|
950
|
+
//# sourceMappingURL=publication.js.map
|