@bitsocial/pubsub-voting 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,7 +18,7 @@ The same engine generalizes to the original use case in [pkc-js issue #25](https
18
18
  - The engine is reusable across clients and contests.
19
19
  - The core (`schema/`, `verify/`, `crdt/`, `tally/`) is transport-agnostic and unit-testable without a network. libp2p only appears in `transport/`.
20
20
 
21
- This library does not start its own node. It consumes the host's running Helia node directly — no adapter — and drives that node's gossipsub service and blockstore itself. The node must carry a pubsub service at `libp2p.services.pubsub` (a plain Helia node does not — register e.g. `@libp2p/gossipsub`), a usable `blockstore`, and a libp2p fetch service at `libp2p.services.fetch` (register `@libp2p/fetch` — the checkpoint root-record pull rides it); construction throws `MissingPubsubError` / `MissingBlockstoreError` / `MissingFetchError` otherwise. With pkc-js today that node is reached at `pkc.clients.libp2pJsClients[key]._helia`; a version-stable accessor on pkc-js is a planned follow-up (see [DESIGN.md, Deferred pkc-js work](./DESIGN.md#deferred-pkc-js-work)).
21
+ This library does not start its own node. It consumes the host's running Helia node directly — no adapter — and drives that node's gossipsub service and blockstore itself. The node must carry a pubsub service at `libp2p.services.pubsub` (a plain Helia node does not — register e.g. `@libp2p/gossipsub`), a usable `blockstore`, and a libp2p fetch service at `libp2p.services.fetch` (register `@libp2p/fetch` — the checkpoint root-record pull rides it); construction throws `MissingPubsubError` / `MissingBlockstoreError` / `MissingFetchError` otherwise. With pkc-js that node is reached at `pkc.clients.libp2pJsClients[key].heliaNode` the documented, semver-covered accessor since pkc-js `0.0.72` (see [DESIGN.md, Deferred pkc-js work](./DESIGN.md#deferred-pkc-js-work)).
22
22
 
23
23
  ## Design at a glance
24
24
 
@@ -182,7 +182,7 @@ export interface VoteClient {
182
182
  export interface PubsubVoterOptions {
183
183
  /**
184
184
  * The host's running Helia node (the value `createHelia` returns; for pkc-js it is
185
- * `pkc.clients.libp2pJsClients[key]._helia`). The only host-node seam, passed
185
+ * `pkc.clients.libp2pJsClients[key].heliaNode`). The only host-node seam, passed
186
186
  * directly with no adapter. It MUST carry a gossipsub service at
187
187
  * `libp2p.services.pubsub`, a usable `blockstore`, and a libp2p fetch service at
188
188
  * `libp2p.services.fetch`; the constructor throws `MissingPubsubError` /
@@ -54,6 +54,24 @@ export interface VoteNode {
54
54
  admitBundle(bundle: VotesBundle): Promise<void>;
55
55
  stop(): Promise<void>;
56
56
  }
57
+ /**
58
+ * One real loopback libp2p + Helia node carrying gossipsub (topic-scoped score params) and
59
+ * `@libp2p/fetch` — the raw host node with nothing else wired. {@link makeVoteNode} builds the
60
+ * harness transport on top of it; the three-node relay test instead hands it straight to the
61
+ * REAL `PubsubVoter` as the injected host node (the `PubsubVoterOptions.helia` seam).
62
+ */
63
+ export declare function makeBareNode(topic: string): Promise<{
64
+ libp2p: Libp2p<{
65
+ identify: import("@libp2p/identify").Identify;
66
+ fetch: import("@libp2p/fetch").Fetch;
67
+ pubsub: import("@libp2p/gossipsub").GossipSub;
68
+ }>;
69
+ helia: Helia<Libp2p<{
70
+ identify: import("@libp2p/identify").Identify;
71
+ fetch: import("@libp2p/fetch").Fetch;
72
+ pubsub: import("@libp2p/gossipsub").GossipSub;
73
+ }>>;
74
+ }>;
57
75
  /** Build one real node with the full forward-gate wired to real gossipsub. */
58
76
  export declare function makeVoteNode(topic: string, options?: VoteNodeOptions): Promise<VoteNode>;
59
77
  /**
@@ -38,9 +38,13 @@ const BLOCKS_PER_BUCKET = 43_200;
38
38
  const VOTE_EXPIRY_BUCKETS = 30;
39
39
  /** A permissive default verifier; individual tests swap it via {@link VoteNode.setVerifier}. */
40
40
  const okVerifier = () => ({ valid: true, ruleScore: 1n, resolvedNames: {} });
41
- /** Build one real node with the full forward-gate wired to real gossipsub. */
42
- export async function makeVoteNode(topic, options = {}) {
43
- const timeoutMs = options.timeoutMs ?? 10_000;
41
+ /**
42
+ * One real loopback libp2p + Helia node carrying gossipsub (topic-scoped score params) and
43
+ * `@libp2p/fetch` — the raw host node with nothing else wired. {@link makeVoteNode} builds the
44
+ * harness transport on top of it; the three-node relay test instead hands it straight to the
45
+ * REAL `PubsubVoter` as the injected host node (the `PubsubVoterOptions.helia` seam).
46
+ */
47
+ export async function makeBareNode(topic) {
44
48
  const libp2p = await createLibp2p({
45
49
  addresses: { listen: ["/ip4/127.0.0.1/tcp/0"] },
46
50
  transports: [tcp()],
@@ -87,6 +91,12 @@ export async function makeVoteNode(topic, options = {}) {
87
91
  }
88
92
  });
89
93
  const helia = await createHelia({ libp2p });
94
+ return { libp2p, helia };
95
+ }
96
+ /** Build one real node with the full forward-gate wired to real gossipsub. */
97
+ export async function makeVoteNode(topic, options = {}) {
98
+ const timeoutMs = options.timeoutMs ?? 10_000;
99
+ const { libp2p, helia } = await makeBareNode(topic);
90
100
  const pubsub = libp2p.services.pubsub;
91
101
  // Adapt Helia's async-generator `get` to the library's Promise-returning BlockstoreLike, the
92
102
  // same bridge `requireHeliaServices` applies to an injected host node.
@@ -18,7 +18,7 @@ import type { RootRecord } from "./messages.js";
18
18
  *
19
19
  * The library does not start a node and does not take a host SDK. It receives the
20
20
  * host's already-running **Helia node** directly (e.g. the value `createHelia` returns,
21
- * which for a pkc-js host is `pkc.clients.libp2pJsClients[key]._helia`) and drives its
21
+ * which for a pkc-js host is `pkc.clients.libp2pJsClients[key].heliaNode`) and drives its
22
22
  * libp2p pubsub + blockstore itself — there is no host-written adapter. The node must
23
23
  * carry a gossipsub service at `libp2p.services.pubsub` and a usable `blockstore`;
24
24
  * construction enforces both (see `requireHeliaServices` / `MissingPubsubError` /
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitsocial/pubsub-voting",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Trustless pubsub voting over a shared libp2p/Helia node.",
5
5
  "type": "module",
6
6
  "license": "GPL-3.0-or-later",
@@ -26,6 +26,7 @@
26
26
  "typecheck": "tsc -p tsconfig.json --noEmit",
27
27
  "typecheck:examples": "tsc -p tsconfig.examples.json --noEmit",
28
28
  "test": "vitest run",
29
+ "test:coverage": "vitest run --coverage",
29
30
  "test:watch": "vitest",
30
31
  "test:integration": "vitest run -c vitest.integration.config.ts",
31
32
  "build:bench": "tsc -p benchmark/tsconfig.json",
@@ -64,9 +65,10 @@
64
65
  "@libp2p/identify": "4.1.8",
65
66
  "@libp2p/tcp": "11.0.22",
66
67
  "@multiformats/multiaddr": "13.0.3",
67
- "@pkcprotocol/pkc-js": "0.0.63",
68
+ "@pkcprotocol/pkc-js": "0.0.72",
68
69
  "@release-it/conventional-changelog": "10.0.6",
69
70
  "@types/better-sqlite3": "7.6.13",
71
+ "@vitest/coverage-v8": "4.1.9",
70
72
  "commitizen": "4.3.1",
71
73
  "cz-conventional-changelog": "3.3.0",
72
74
  "husky": "9.1.7",