@fangorn-network/sdk 2026.10.27-dev → 2026.11.3-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +36 -642
  2. package/lib/cli/cli.js +47 -322
  3. package/lib/cli/index.d.ts +1 -4
  4. package/lib/cli/index.js +2 -20
  5. package/lib/config.d.ts +15 -78
  6. package/lib/config.js +8 -35
  7. package/lib/contracts/data-registry/abi.d.ts +195 -19
  8. package/lib/contracts/data-registry/abi.js +223 -20
  9. package/lib/contracts/data-registry/index.d.ts +126 -2
  10. package/lib/contracts/data-registry/index.js +174 -1
  11. package/lib/contracts/index.d.ts +5 -8
  12. package/lib/contracts/index.js +4 -7
  13. package/lib/contracts/logs.d.ts +1 -1
  14. package/lib/contracts/logs.js +1 -1
  15. package/lib/contracts/{membership-registry → settlement-registry}/abi.d.ts +288 -637
  16. package/lib/contracts/{membership-registry → settlement-registry}/abi.js +326 -712
  17. package/lib/contracts/settlement-registry/index.d.ts +141 -0
  18. package/lib/contracts/settlement-registry/index.js +209 -0
  19. package/lib/crypto/aes.d.ts +2 -2
  20. package/lib/crypto/aes.js +4 -4
  21. package/lib/crypto/encryption.d.ts +8 -109
  22. package/lib/crypto/encryption.js +16 -114
  23. package/lib/crypto/paid.d.ts +104 -0
  24. package/lib/crypto/paid.js +147 -0
  25. package/lib/engine/index.d.ts +23 -12
  26. package/lib/engine/index.js +68 -29
  27. package/lib/engine/records.d.ts +4 -7
  28. package/lib/engine/records.js +6 -6
  29. package/lib/engine/test-helpers.d.ts +2 -3
  30. package/lib/engine/test-helpers.js +7 -5
  31. package/lib/erc8004.js +1 -4
  32. package/lib/fangorn.d.ts +64 -85
  33. package/lib/fangorn.js +106 -148
  34. package/lib/feed.d.ts +7 -8
  35. package/lib/feed.js +7 -8
  36. package/lib/index.d.ts +10 -14
  37. package/lib/index.js +9 -13
  38. package/lib/providers/storage/signed-url.d.ts +2 -10
  39. package/lib/providers/storage/signed-url.js +4 -14
  40. package/lib/providers/storage/types.d.ts +1 -1
  41. package/lib/providers/storage/utils.js +5 -3
  42. package/lib/test/key-server.d.ts +12 -0
  43. package/lib/test/key-server.js +30 -0
  44. package/lib/test/mem-registry.d.ts +14 -19
  45. package/lib/test/mem-registry.js +44 -37
  46. package/lib/test/sdk-suite.d.ts +1 -4
  47. package/lib/test/sdk-suite.js +16 -87
  48. package/lib/test/testbed.d.ts +5216 -5226
  49. package/lib/test/testbed.js +29 -56
  50. package/lib/types/index.d.ts +6 -11
  51. package/package.json +1 -4
  52. package/lib/contracts/app-registry/abi.d.ts +0 -1317
  53. package/lib/contracts/app-registry/abi.js +0 -1510
  54. package/lib/contracts/app-registry/index.d.ts +0 -173
  55. package/lib/contracts/app-registry/index.js +0 -294
  56. package/lib/contracts/membership-registry/index.d.ts +0 -79
  57. package/lib/contracts/membership-registry/index.js +0 -104
  58. package/lib/contracts/types.d.ts +0 -10
  59. package/lib/contracts/types.js +0 -12
  60. package/lib/harness/examples/hackmd/build-markdown-graph.d.ts +0 -1
  61. package/lib/harness/examples/hackmd/build-markdown-graph.js +0 -17
  62. package/lib/harness/index.d.ts +0 -58
  63. package/lib/harness/index.js +0 -73
  64. package/lib/registry.d.ts +0 -118
  65. package/lib/registry.js +0 -184
@@ -27,31 +27,22 @@ function workerError(r) {
27
27
  * JWT-only operations (server-side metadata queries / deletes) are unavailable
28
28
  * here. Switch to a PinataBackend they're needed.
29
29
  *
30
- * Apps provide storage: every upload is billed to the client's app, whose
31
- * subscription pays for it. Each request carries the app id, the signer must be
32
- * one of that app's publishers, and the pins are filed under the app's group.
33
- * There is no app-less upload: with no app this refuses before contacting the
34
- * worker. The id is read per request so a later `setAppId` takes effect
35
- * immediately.
30
+ * Every upload is charged to the signing publisher's storage quota.
36
31
  */
37
32
  var SignedUrlBackend = class {
38
33
  workerUrl;
39
- constructor(workerUrl, signer, gateway, appId) {
34
+ constructor(workerUrl, signer, gateway) {
40
35
  this.signer = signer;
41
36
  this.gateway = gateway;
42
- this.appId = appId;
43
37
  this.workerUrl = workerUrl?.trim() ? workerUrl : DEFAULT_SIGNED_URL_WORKER;
44
38
  }
45
39
  /** Run the worker challenge handshake → one-time presigned upload URL + network. */
46
40
  async requestUploadUrl(size, uploadId) {
47
41
  const address = this.signer.address;
48
- const appId = this.appId();
49
- if (!appId) throw new Error("signed-url uploads are billed to an app: pass `appId` to Fangorn.create() or call setAppId(), or bring your own storage ({ pinata } or { backend })");
50
42
  const challenge = await this.workerJson({
51
43
  address,
52
44
  size,
53
- uploadId,
54
- appId
45
+ uploadId
55
46
  });
56
47
  if (!challenge.challenge) throw new Error(`Presigned-URL worker did not issue a challenge: ${workerError(challenge)}`);
57
48
  const signature = await this.signer.signMessage(challenge.challenge);
@@ -60,8 +51,7 @@ var SignedUrlBackend = class {
60
51
  message: challenge.challenge,
61
52
  signature,
62
53
  size,
63
- uploadId,
64
- appId
54
+ uploadId
65
55
  });
66
56
  if (!grant.ok || !grant.uploadUrl) throw new Error(`Presigned-URL worker denied an upload URL: ${workerError(grant)}`);
67
57
  return {
@@ -36,7 +36,7 @@ interface MetadataStorage {
36
36
  */
37
37
  putBlock(block: RawBlock): Promise<void>;
38
38
  /**
39
- * Store an opaque byte payload (e.g. a CAR file) and return a URI handle.
39
+ * Store an opaque byte payload (e.g. a CAR file) and return its CID.
40
40
  * The backend is NOT expected to understand the contents.
41
41
  */
42
42
  putFile(bytes: Uint8Array, name: string): Promise<string>;
@@ -1,11 +1,12 @@
1
1
  import { DEFAULT_SIGNED_URL_WORKER, SignedUrlBackend } from "./signed-url.js";
2
2
  import { PinataBackend } from "./pinata.js";
3
3
  import { CID } from "multiformats/cid";
4
+ import { base64pad } from "multiformats/bases/base64";
4
5
 
5
6
  //#region src/providers/storage/utils.ts
6
7
  const RAW_CODE = 85;
7
8
  const REVIVERS = [(_key, value) => {
8
- if (value !== null && typeof value === "object" && "__type" in value && "data" in value && value.__type === "Uint8Array") return new Uint8Array(Buffer.from(value.data, "base64"));
9
+ if (value !== null && typeof value === "object" && "__type" in value && "data" in value && value.__type === "Uint8Array") return base64pad.baseDecode(value.data);
9
10
  return value;
10
11
  }];
11
12
  function serialize(data) {
@@ -13,7 +14,7 @@ function serialize(data) {
13
14
  return JSON.stringify(data, (_key, value) => {
14
15
  if (value instanceof Uint8Array) return {
15
16
  __type: "Uint8Array",
16
- data: Buffer.from(value).toString("base64")
17
+ data: base64pad.baseEncode(value)
17
18
  };
18
19
  return value;
19
20
  });
@@ -27,7 +28,8 @@ function deserialize(text) {
27
28
  return value;
28
29
  });
29
30
  }
30
- const MAX_UPLOAD_ATTEMPTS = Math.max(1, Number(process.env.PINATA_UPLOAD_RETRIES ?? 6));
31
+ const env = globalThis.process?.env;
32
+ const MAX_UPLOAD_ATTEMPTS = Math.max(1, Number(env?.PINATA_UPLOAD_RETRIES ?? 6));
31
33
  function isTransientUpload(err) {
32
34
  const e = err;
33
35
  const s = typeof e.statusCode === "number" ? e.statusCode : 0;
@@ -0,0 +1,12 @@
1
+ import { AccessRequest } from "../crypto/paid.js";
2
+ import { Address, Hex } from "viem";
3
+
4
+ //#region src/test/key-server.d.ts
5
+ declare function testKeyServer(body: AccessRequest, ks: {
6
+ secret: Uint8Array;
7
+ chainId: number;
8
+ registry: Address;
9
+ canRead(reader: Address, publisher: Address, repo: Hex, key: Hex): Promise<boolean>;
10
+ }): Promise<Response>;
11
+ //#endregion
12
+ export { testKeyServer };
@@ -0,0 +1,30 @@
1
+ import { WHOLE_REPO } from "../contracts/settlement-registry/index.js";
2
+ import { seal, unseal } from "../crypto/encryption.js";
3
+ import { accessMessage, deriveRecordKey, statement } from "../crypto/paid.js";
4
+ import { bytesToHex, hexToBytes, recoverMessageAddress } from "viem";
5
+
6
+ //#region src/test/key-server.ts
7
+ async function testKeyServer(body, ks) {
8
+ const stmt = statement({
9
+ ...ks,
10
+ publisher: body.publisher,
11
+ repo: body.repo,
12
+ generation: BigInt(body.generation)
13
+ });
14
+ const reader = await recoverMessageAddress({
15
+ message: { raw: accessMessage(stmt, body.key, body.readerKey, body.timestamp) },
16
+ signature: body.signature
17
+ });
18
+ if (!(reader.toLowerCase() === body.publisher.toLowerCase()) && !await ks.canRead(reader, body.publisher, body.repo, body.key)) return new Response("not settled", { status: 403 });
19
+ let kRepo;
20
+ try {
21
+ kRepo = unseal(hexToBytes(body.sealed), ks.secret, stmt);
22
+ } catch {
23
+ return new Response("deposit does not match", { status: 400 });
24
+ }
25
+ const out = body.key === WHOLE_REPO ? kRepo : deriveRecordKey(kRepo, stmt, body.key);
26
+ return Response.json({ sealed: bytesToHex(seal(out, hexToBytes(body.readerKey), stmt)) });
27
+ }
28
+
29
+ //#endregion
30
+ export { testKeyServer };
@@ -1,9 +1,12 @@
1
1
  import { PreparedTx } from "../contracts/write.js";
2
+ import { CommitUpdate, LogFilter, Registry, RepoRef, UpdateEntry } from "../contracts/data-registry/index.js";
2
3
  import "../contracts/index.js";
3
- import { Exclusion, LogFilter, Registry, RepoRef, UpdateEntry } from "../registry.js";
4
- import { Address, Hash, Hex } from "viem";
4
+ import { Address, Hash, Hex, LocalAccount } from "viem";
5
+ import * as abitype31 from "abitype";
5
6
 
6
7
  //#region src/test/mem-registry.d.ts
8
+ /** The EIP-712 domain a MemRegistry signs under. */
9
+ declare const MEM_DOMAIN: abitype31.TypedDataDomain;
7
10
  /** One ordering and the registry state over it, shared by every signer of a MemRegistry. */
8
11
  declare class MemLedger {
9
12
  /** H: position and head */
@@ -11,10 +14,6 @@ declare class MemLedger {
11
14
  pos: number;
12
15
  head: Hex;
13
16
  }>;
14
- /** `app/publisher` for each publisher an app presents (provides storage to) */
15
- members: Set<string>;
16
- /** C, per app */
17
- counts: Map<string, number>;
18
17
  /** U */
19
18
  entries: UpdateEntry[];
20
19
  /** The clock: one tick per entry of the ordering. */
@@ -23,29 +22,25 @@ declare class MemLedger {
23
22
  append(entry: Omit<UpdateEntry, "t" | "id">): void;
24
23
  }
25
24
  /**
26
- * The paper's Apply, signing as `signer`. Membership is whatever the ledger is
27
- * told (`members`): its rules (invites, terms, suspensions) are the contracts'
28
- * business. Signers that share a ledger see each other's writes, like wallets on
29
- * one chain.
25
+ * The paper's Apply, signing as `signer`. Signers that share a ledger see each
26
+ * other's writes, like wallets on one chain.
30
27
  */
31
28
  declare class MemRegistry implements Registry {
32
29
  signer: Address;
33
30
  ledger: MemLedger;
34
31
  now: () => number;
35
- constructor(signer: Address, ledger?: MemLedger, now?: () => number);
32
+ account?: LocalAccount | undefined;
33
+ constructor(signer: Address, ledger?: MemLedger, now?: () => number, account?: LocalAccount | undefined);
36
34
  epoch(): Promise<number>;
37
35
  head(ref: RepoRef): Promise<Hex>;
38
- presents(app: Hex, publisher: Address): Promise<boolean>;
39
- exclusionCount(app: Hex, x: Exclusion): Promise<number>;
40
- update(repo: string, parent: Hex, head: Hex): Promise<Hash>;
36
+ update(u: CommitUpdate): Promise<Hash>;
37
+ signUpdate(u: CommitUpdate): Promise<Hex>;
38
+ updateBySig(publisher: Address, u: CommitUpdate, signature: Hex): Promise<Hash>;
39
+ private apply;
41
40
  prepareUpdate(): Promise<PreparedTx>;
42
- exclude(app: Hex, x: Exclusion): Promise<Hash>;
43
- restore(app: Hex, x: Exclusion): Promise<Hash>;
44
- /** exclude needs an even count, restore an odd one; both add one. */
45
- private flip;
46
41
  log(filter: LogFilter, from: bigint, to?: bigint): Promise<UpdateEntry[]>;
47
42
  watch(filter: LogFilter, onEntry: (entry: UpdateEntry) => void): () => void;
48
43
  clock(): Promise<bigint>;
49
44
  }
50
45
  //#endregion
51
- export { MemLedger, MemRegistry };
46
+ export { MEM_DOMAIN, MemLedger, MemRegistry };
@@ -1,16 +1,16 @@
1
- import { ZERO_HEAD, epochOf } from "../registry.js";
1
+ import { UPDATE_TYPES, WINDOW, ZERO_HEAD, dataDomain, epochOf, updateMessage } from "../contracts/data-registry/index.js";
2
+ import "../contracts/index.js";
3
+ import { commitHead } from "../engine/index.js";
4
+ import { verifyTypedData } from "viem";
2
5
 
3
6
  //#region src/test/mem-registry.ts
7
+ /** The EIP-712 domain a MemRegistry signs under. */
8
+ const MEM_DOMAIN = dataDomain(31337, "0x000000000000000000000000000000000000da7a");
4
9
  const refKey = (r) => `${r.publisher.toLowerCase()}/${r.repo}`;
5
- const exclKey = (x) => `${x.publisher.toLowerCase()}/${x.repo ?? ""}/${x.key ?? ""}`;
6
10
  /** One ordering and the registry state over it, shared by every signer of a MemRegistry. */
7
11
  var MemLedger = class {
8
12
  /** H: position and head */
9
13
  heads = /* @__PURE__ */ new Map();
10
- /** `app/publisher` for each publisher an app presents (provides storage to) */
11
- members = /* @__PURE__ */ new Set();
12
- /** C, per app */
13
- counts = /* @__PURE__ */ new Map();
14
14
  /** U */
15
15
  entries = [];
16
16
  /** The clock: one tick per entry of the ordering. */
@@ -29,16 +29,15 @@ var MemLedger = class {
29
29
  };
30
30
  const matches = (filter, e) => (!filter.publisher || e.publisher.toLowerCase() === filter.publisher.toLowerCase()) && (!filter.repo || e.repo === filter.repo);
31
31
  /**
32
- * The paper's Apply, signing as `signer`. Membership is whatever the ledger is
33
- * told (`members`): its rules (invites, terms, suspensions) are the contracts'
34
- * business. Signers that share a ledger see each other's writes, like wallets on
35
- * one chain.
32
+ * The paper's Apply, signing as `signer`. Signers that share a ledger see each
33
+ * other's writes, like wallets on one chain.
36
34
  */
37
35
  var MemRegistry = class {
38
- constructor(signer, ledger = new MemLedger(), now = () => Math.floor(Date.now() / 1e3)) {
36
+ constructor(signer, ledger = new MemLedger(), now = () => Math.floor(Date.now() / 1e3), account) {
39
37
  this.signer = signer;
40
38
  this.ledger = ledger;
41
39
  this.now = now;
40
+ this.account = account;
42
41
  }
43
42
  epoch() {
44
43
  return Promise.resolve(epochOf(this.now()));
@@ -46,48 +45,56 @@ var MemRegistry = class {
46
45
  head(ref) {
47
46
  return Promise.resolve(this.ledger.heads.get(refKey(ref))?.head ?? ZERO_HEAD);
48
47
  }
49
- presents(app, publisher) {
50
- return Promise.resolve(this.ledger.members.has(`${app}/${publisher.toLowerCase()}`));
48
+ update(u) {
49
+ return this.apply(this.signer, u);
51
50
  }
52
- exclusionCount(app, x) {
53
- return Promise.resolve(this.ledger.counts.get(`${app}/${exclKey(x)}`) ?? 0);
51
+ signUpdate(u) {
52
+ if (!this.account) return Promise.reject(/* @__PURE__ */ new Error("MemRegistry has no account to sign with"));
53
+ return this.account.signTypedData({
54
+ domain: MEM_DOMAIN,
55
+ types: UPDATE_TYPES,
56
+ primaryType: "Update",
57
+ message: updateMessage(this.account.address, u)
58
+ });
59
+ }
60
+ async updateBySig(publisher, u, signature) {
61
+ if (!await verifyTypedData({
62
+ address: publisher,
63
+ domain: MEM_DOMAIN,
64
+ types: UPDATE_TYPES,
65
+ primaryType: "Update",
66
+ message: updateMessage(publisher, u),
67
+ signature
68
+ })) throw new Error("BadSignature");
69
+ return this.apply(publisher, u);
54
70
  }
55
- async update(repo, parent, head) {
71
+ async apply(publisher, u) {
72
+ const now = epochOf(this.now());
73
+ if (u.epoch > now || u.epoch + WINDOW < now) throw new Error("EpochOutOfWindow");
56
74
  const ref = {
57
- publisher: this.signer,
58
- repo
75
+ publisher,
76
+ repo: u.repo
59
77
  };
60
- if (await this.head(ref) !== parent) throw new Error("StaleStateRoot");
78
+ if (await this.head(ref) !== u.parent) throw new Error("StaleStateRoot");
79
+ const head = await commitHead(u);
61
80
  const pos = (this.ledger.heads.get(refKey(ref))?.pos ?? 0) + 1;
62
81
  this.ledger.heads.set(refKey(ref), {
63
82
  pos,
64
83
  head
65
84
  });
66
85
  this.ledger.append({
67
- publisher: this.signer,
68
- repo,
86
+ publisher,
87
+ repo: u.repo,
69
88
  pos,
70
- parent,
71
- head
89
+ parent: u.parent,
90
+ head,
91
+ timestamp: BigInt(this.now())
72
92
  });
73
93
  return "0x00";
74
94
  }
75
95
  prepareUpdate() {
76
96
  return Promise.reject(/* @__PURE__ */ new Error("MemRegistry has no transactions to prepare"));
77
97
  }
78
- exclude(app, x) {
79
- return this.flip(app, x, 0);
80
- }
81
- restore(app, x) {
82
- return this.flip(app, x, 1);
83
- }
84
- /** exclude needs an even count, restore an odd one; both add one. */
85
- async flip(app, x, parity) {
86
- const n = await this.exclusionCount(app, x);
87
- if (n % 2 !== parity) throw new Error(parity ? "NotExcluded" : "AlreadyExcluded");
88
- this.ledger.counts.set(`${app}/${exclKey(x)}`, n + 1);
89
- return "0x00";
90
- }
91
98
  log(filter, from, to) {
92
99
  return Promise.resolve(this.ledger.entries.filter((e) => e.t >= from && (to === void 0 || e.t <= to) && matches(filter, e)));
93
100
  }
@@ -104,4 +111,4 @@ var MemRegistry = class {
104
111
  };
105
112
 
106
113
  //#endregion
107
- export { MemLedger, MemRegistry };
114
+ export { MEM_DOMAIN, MemLedger, MemRegistry };
@@ -1,13 +1,10 @@
1
1
  import { Fangorn, RepoChange } from "../fangorn.js";
2
2
  import { Network } from "./testbed.js";
3
- import { Hex } from "viem";
4
3
 
5
4
  //#region src/test/sdk-suite.d.ts
6
- /** The app a test client was made under. */
7
- declare function appOf(f: Fangorn): Hex;
8
5
  declare const head: (f: Fangorn, repo: string) => Promise<`0x${string}`>;
9
6
  /** Take the first n entries of the stream and then stop. */
10
7
  declare function take(stream: AsyncGenerator<RepoChange>, n: number): Promise<RepoChange[]>;
11
8
  declare function sdkSuite(makeNetwork: () => Promise<Network>, timeout?: number): void;
12
9
  //#endregion
13
- export { appOf, head, sdkSuite, take };
10
+ export { head, sdkSuite, take };
@@ -1,18 +1,12 @@
1
- import { ZERO_HEAD } from "../registry.js";
1
+ import { ZERO_HEAD } from "../contracts/data-registry/index.js";
2
+ import "../contracts/index.js";
2
3
  import { GADGET_SELF_HKDF_V1, sealSelf, unsealSelf } from "../crypto/encryption.js";
3
4
  import { afterAll, beforeAll, describe, it } from "../node_modules/@vitest/runner/dist/index.js";
4
5
  import { globalExpect } from "../node_modules/vitest/dist/chunks/vi.2VT5v0um.js";
5
- import { TEST_APP } from "./testbed.js";
6
6
  import { bytesToHex, hexToBytes, keccak256, stringToBytes } from "viem";
7
7
  import { generatePrivateKey } from "viem/accounts";
8
8
 
9
9
  //#region src/test/sdk-suite.ts
10
- /** The app a test client was made under. */
11
- function appOf(f) {
12
- const app = f.getAppId();
13
- if (!app) throw new Error("this client has no app");
14
- return app;
15
- }
16
10
  const head = (f, repo) => f.getRegistry().head({
17
11
  publisher: f.getAddress(),
18
12
  repo
@@ -26,8 +20,6 @@ async function take(stream, n) {
26
20
  }
27
21
  return out;
28
22
  }
29
- /** A fresh app name, so a test's owner and exclusions are its own. */
30
- const freshApp = () => `app-${Math.random().toString(36).slice(2)}`;
31
23
  function sdkSuite(makeNetwork, timeout = 5e3) {
32
24
  let net;
33
25
  beforeAll(async () => {
@@ -79,7 +71,7 @@ function sdkSuite(makeNetwork, timeout = 5e3) {
79
71
  }, timeout);
80
72
  it("stores a payload sealed to its publisher as opaque bytes", async () => {
81
73
  const sk = generatePrivateKey();
82
- const f = await net.client(TEST_APP, sk);
74
+ const f = await net.client(sk);
83
75
  await f.initRepo("private");
84
76
  const resourceId = keccak256(stringToBytes("private:secret"));
85
77
  const ciphertext = sealSelf(new TextEncoder().encode("the eagles are coming"), hexToBytes(sk), resourceId);
@@ -111,94 +103,31 @@ function sdkSuite(makeNetwork, timeout = 5e3) {
111
103
  id: "x",
112
104
  type: "t",
113
105
  payload: {}
114
- }],
115
- message: "m"
106
+ }]
116
107
  });
117
108
  await globalExpect(f.push("r", stale.commitCid)).rejects.toThrow(/stale parent/);
118
109
  }, timeout);
119
110
  });
120
- describe("apps present what they accept", () => {
121
- it("one member reads another's repo, and the app lists both", async () => {
122
- const app = freshApp();
123
- const owner = await net.client(app);
124
- const guest = await net.client(app);
125
- await owner.initRepo("catalog");
126
- await guest.initRepo("catalog");
127
- const { payloadCid } = await guest.upload("catalog", { title: "from the guest" }, "entry", "g");
128
- const { contents } = await owner.readRepo(guest.getAddress(), "catalog");
111
+ describe("reading other publishers", () => {
112
+ it("any client reads any publisher's repo, and lists every repo", async () => {
113
+ const reader = await net.client();
114
+ const pub = await net.client();
115
+ await pub.initRepo("catalog");
116
+ const { payloadCid } = await pub.upload("catalog", { title: "t" }, "entry", "g");
117
+ const { contents } = await reader.readRepo(pub.getAddress(), "catalog");
129
118
  globalExpect(contents.records.map((r) => r.cid)).toEqual([payloadCid]);
130
- const listed = await owner.appRepos({ repo: "catalog" });
131
- globalExpect(listed.map((d) => d.owner).sort()).toEqual([owner.getAddress(), guest.getAddress()].sort());
132
- globalExpect(listed.every((d) => d.repo === "catalog")).toBe(true);
133
- }, timeout);
134
- it("an app presents its members' repos and nobody else's; an update names no app", async () => {
135
- const app = freshApp();
136
- const owner = await net.client(app);
137
- const loner = await net.client(null);
138
- await loner.initRepo("notes");
139
- await loner.upload("notes", { n: 1 }, "t", "x");
140
- globalExpect((await owner.readRepo(loner.getAddress(), "notes")).contents.records).toEqual([]);
141
- globalExpect(await owner.appRepos()).toEqual([]);
142
- globalExpect((await (await net.client(null)).readRepo(loner.getAddress(), "notes")).contents.records).toHaveLength(1);
143
- }, timeout);
144
- it("an excluded publisher disappears from the app's reads, and a restore brings it back", async () => {
145
- const app = freshApp();
146
- const owner = await net.client(app);
147
- const guest = await net.client(app);
148
- await guest.initRepo("catalog");
149
- await guest.upload("catalog", { title: "t" }, "entry", "g");
150
- const x = { publisher: guest.getAddress() };
151
- const appId = appOf(owner);
152
- await owner.getRegistry().exclude(appId, x);
153
- globalExpect(await owner.appRepos()).toEqual([]);
154
- globalExpect((await owner.readRepo(guest.getAddress(), "catalog")).contents.records).toEqual([]);
155
- await owner.getRegistry().restore(appId, x);
156
- globalExpect(await owner.appRepos()).toHaveLength(1);
157
- globalExpect((await owner.readRepo(guest.getAddress(), "catalog")).contents.records).toHaveLength(1);
158
- }, timeout);
159
- it("a repo exclusion hides that repo only", async () => {
160
- const app = freshApp();
161
- const owner = await net.client(app);
162
- const guest = await net.client(app);
163
- for (const repo of ["keep", "drop"]) {
164
- await guest.initRepo(repo);
165
- await guest.upload(repo, { repo }, "t", "x");
166
- }
167
- await owner.getRegistry().exclude(appOf(owner), {
168
- publisher: guest.getAddress(),
169
- repo: "drop"
170
- });
171
- globalExpect((await owner.appRepos()).map((d) => d.repo)).toEqual(["keep"]);
172
- globalExpect((await owner.readRepo(guest.getAddress(), "drop")).contents.records).toEqual([]);
173
- globalExpect((await owner.readRepo(guest.getAddress(), "keep")).contents.records).toHaveLength(1);
174
- }, timeout);
175
- it("an exclusion in one app hides nothing in another that presents the same publisher", async () => {
176
- const [appA, appB] = [freshApp(), freshApp()];
177
- const ownerA = await net.client(appA);
178
- const ownerB = await net.client(appB);
179
- const sk = generatePrivateKey();
180
- const guest = await net.client(appA, sk);
181
- await net.client(appB, sk);
182
- await guest.initRepo("catalog");
183
- await guest.upload("catalog", { title: "t" }, "entry", "g");
184
- const ref = {
185
- publisher: guest.getAddress(),
186
- repo: "catalog"
187
- };
188
- await ownerA.getRegistry().exclude(appOf(ownerA), { publisher: ref.publisher });
189
- globalExpect((await ownerA.readRepo(ref.publisher, "catalog")).contents.records).toEqual([]);
190
- globalExpect((await ownerB.readRepo(ref.publisher, "catalog")).contents.records).toHaveLength(1);
119
+ globalExpect((await reader.repos({ owner: pub.getAddress() })).map((d) => [d.owner, d.repo])).toEqual([[pub.getAddress(), "catalog"]]);
191
120
  }, timeout);
192
121
  });
193
122
  describe("subscriptions", () => {
194
123
  it("replays from a block, then follows live", async () => {
195
- const app = freshApp();
196
- const pub = await net.client(app);
124
+ const pub = await net.client();
197
125
  const from = await net.clock();
198
126
  await pub.initRepo("feed");
199
127
  await pub.upload("feed", { n: 1 }, "t", "a");
200
128
  const ctl = new AbortController();
201
- const stream = (await net.client(app)).subscribeApp({
129
+ const stream = (await net.client()).subscribeAll({
130
+ owner: pub.getAddress(),
202
131
  fromBlock: from,
203
132
  signal: ctl.signal,
204
133
  pollingInterval: 100
@@ -223,4 +152,4 @@ function sdkSuite(makeNetwork, timeout = 5e3) {
223
152
  }
224
153
 
225
154
  //#endregion
226
- export { appOf, head, sdkSuite, take };
155
+ export { head, sdkSuite, take };