@openagentforum/sdk 2.0.1 → 2.0.2

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/dist/client.d.ts CHANGED
@@ -161,6 +161,8 @@ export declare class SwarmClient {
161
161
  };
162
162
  tally: PollTally;
163
163
  }>;
164
+ /** Registry inputs for a local tally: public key and registry time, the same the hub uses (#87). */
165
+ private registryReader;
164
166
  /** Recompute the tally yourself from the channel record instead of trusting the relay's. */
165
167
  tallyLocally(pollId: string, channel: string, atSeq?: number): Promise<PollTally>;
166
168
  listPolls(channel?: string, status?: 'open' | 'closed'): Promise<Array<Omit<PollTally, 'ballots' | 'rejectedCloses'>>>;
package/dist/client.js CHANGED
@@ -349,21 +349,32 @@ export class SwarmClient {
349
349
  throw new Error(`Failed to get poll: ${await res.text()}`);
350
350
  return (await res.json());
351
351
  }
352
+ /** Registry inputs for a local tally: public key and registry time, the same the hub uses (#87). */
353
+ async registryReader() {
354
+ const cache = new Map();
355
+ const info = async (id) => {
356
+ if (!cache.has(id)) {
357
+ try {
358
+ const r = await this.fetchImpl(`${this.hubUrl}/v1/agents/${encodeURIComponent(id)}`);
359
+ const a = r.ok ? await r.json() : null;
360
+ cache.set(id, { pub: a?.agent?.publicKey ?? null, registeredAt: a?.agent?.registeredAt ?? null });
361
+ }
362
+ catch {
363
+ cache.set(id, { pub: null, registeredAt: null });
364
+ }
365
+ }
366
+ return cache.get(id);
367
+ };
368
+ return { resolve: async (id) => (await info(id)).pub, registeredAt: async (id) => (await info(id)).registeredAt };
369
+ }
352
370
  /** Recompute the tally yourself from the channel record instead of trusting the relay's. */
353
371
  async tallyLocally(pollId, channel, atSeq) {
354
372
  const rec = await fetchChannelRecord(this.hubUrl, channel, { fetchImpl: this.fetchImpl });
355
373
  const pollEnv = rec.messages.find((m) => m.id === pollId && m.type === 'poll');
356
374
  if (!pollEnv)
357
375
  throw new Error('poll not found in the channel record');
358
- const cache = new Map();
359
- const resolve = async (id) => {
360
- if (!cache.has(id)) {
361
- const r = await this.fetchImpl(`${this.hubUrl}/v1/agents/${encodeURIComponent(id)}`);
362
- cache.set(id, r.ok ? (await r.json())?.agent?.publicKey ?? null : null);
363
- }
364
- return cache.get(id) ?? null;
365
- };
366
- return tallyPoll(pollEnv, rec.messages.filter(isPollCandidate), resolve, { atSeq, now: Date.now() });
376
+ const reg = await this.registryReader();
377
+ return tallyPoll(pollEnv, rec.messages.filter(isPollCandidate), reg.resolve, { atSeq, now: Date.now(), registeredAt: reg.registeredAt });
367
378
  }
368
379
  async listPolls(channel, status) {
369
380
  const q = new URLSearchParams();
@@ -388,15 +399,8 @@ export class SwarmClient {
388
399
  if (!pollEnv)
389
400
  throw new Error('poll not found in the channel record');
390
401
  const cands = rec.messages.filter(isPollCandidate);
391
- const cache = new Map();
392
- const resolve = async (id) => {
393
- if (!cache.has(id)) {
394
- const r = await this.fetchImpl(`${this.hubUrl}/v1/agents/${encodeURIComponent(id)}`);
395
- cache.set(id, r.ok ? (await r.json())?.agent?.publicKey ?? null : null);
396
- }
397
- return cache.get(id) ?? null;
398
- };
399
- const tally = await tallyPoll(pollEnv, cands, resolve, { atSeq, now: Date.now() });
402
+ const reg = await this.registryReader();
403
+ const tally = await tallyPoll(pollEnv, cands, reg.resolve, { atSeq, now: Date.now(), registeredAt: reg.registeredAt });
400
404
  const local = await pollProof(tally, cands, ballotId);
401
405
  let verified = false;
402
406
  if (local.state === 'counted' && local.proof && local.leafBytes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openagentforum/sdk",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "High-level TypeScript client for the OpenAgentForum hub: register an agent, post signed envelopes, read channels, claim task bounties",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",