@fangorn-network/sdk 2026.9.22-dev → 2026.10.19-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.
- package/README.md +177 -192
- package/lib/cli/cli.d.ts +0 -0
- package/lib/cli/cli.js +165 -194
- package/lib/config.d.ts +32 -27
- package/lib/config.js +17 -7
- package/lib/contracts/app-registry/abi.d.ts +1033 -277
- package/lib/contracts/app-registry/abi.js +1214 -335
- package/lib/contracts/app-registry/index.d.ts +105 -65
- package/lib/contracts/app-registry/index.js +182 -175
- package/lib/contracts/data-registry/abi.d.ts +166 -187
- package/lib/contracts/data-registry/abi.js +207 -237
- package/lib/contracts/data-registry/index.d.ts +4 -151
- package/lib/contracts/data-registry/index.js +5 -279
- package/lib/contracts/index.d.ts +6 -7
- package/lib/contracts/index.js +6 -8
- package/lib/contracts/logs.d.ts +4 -1
- package/lib/contracts/logs.js +9 -2
- package/lib/contracts/membership-registry/abi.d.ts +1145 -0
- package/lib/contracts/membership-registry/abi.js +1333 -0
- package/lib/contracts/membership-registry/index.d.ts +79 -0
- package/lib/contracts/membership-registry/index.js +104 -0
- package/lib/contracts/types.d.ts +3 -1
- package/lib/contracts/types.js +3 -1
- package/lib/contracts/write.d.ts +34 -2
- package/lib/contracts/write.js +48 -1
- package/lib/crypto/encryption.js +4 -4
- package/lib/engine/car.d.ts +2 -2
- package/lib/engine/car.js +10 -5
- package/lib/engine/index.d.ts +99 -143
- package/lib/engine/index.js +156 -295
- package/lib/engine/records.d.ts +110 -0
- package/lib/engine/records.js +165 -0
- package/lib/engine/test-helpers.d.ts +7 -14
- package/lib/engine/test-helpers.js +7 -18
- package/lib/fangorn.d.ts +129 -156
- package/lib/fangorn.js +250 -250
- package/lib/feed.d.ts +7 -4
- package/lib/feed.js +4 -1
- package/lib/index.d.ts +9 -9
- package/lib/index.js +8 -9
- package/lib/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js +77 -0
- package/lib/node_modules/@vitest/expect/dist/index.js +1414 -0
- package/lib/node_modules/@vitest/pretty-format/dist/index.js +858 -0
- package/lib/node_modules/@vitest/runner/dist/chunk-tasks.js +51 -0
- package/lib/node_modules/@vitest/runner/dist/index.js +1199 -0
- package/lib/node_modules/@vitest/runner/dist/utils.js +3 -0
- package/lib/node_modules/@vitest/snapshot/dist/index.js +1075 -0
- package/lib/node_modules/@vitest/spy/dist/index.js +353 -0
- package/lib/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +7 -0
- package/lib/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js +81 -0
- package/lib/node_modules/@vitest/utils/dist/diff.js +1345 -0
- package/lib/node_modules/@vitest/utils/dist/display.js +534 -0
- package/lib/node_modules/@vitest/utils/dist/error.js +30 -0
- package/lib/node_modules/@vitest/utils/dist/helpers.js +118 -0
- package/lib/node_modules/@vitest/utils/dist/serialize.js +76 -0
- package/lib/node_modules/@vitest/utils/dist/source-map.js +93 -0
- package/lib/node_modules/@vitest/utils/dist/timers.js +36 -0
- package/lib/node_modules/chai/index.js +2874 -0
- package/lib/node_modules/magic-string/dist/magic-string.es.js +939 -0
- package/lib/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +81 -0
- package/lib/node_modules/tinyrainbow/dist/index.js +85 -0
- package/lib/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js +5 -0
- package/lib/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js +50 -0
- package/lib/node_modules/vitest/dist/chunks/utils.DvEY5TfP.js +44 -0
- package/lib/node_modules/vitest/dist/chunks/vi.2VT5v0um.js +2578 -0
- package/lib/providers/storage/signed-url.d.ts +16 -6
- package/lib/providers/storage/signed-url.js +20 -8
- package/lib/registry.d.ts +116 -0
- package/lib/registry.js +182 -0
- package/lib/test/mem-registry.d.ts +51 -0
- package/lib/test/mem-registry.js +107 -0
- package/lib/test/sdk-suite.d.ts +13 -0
- package/lib/test/sdk-suite.js +226 -0
- package/lib/test/testbed.d.ts +16411 -61
- package/lib/test/testbed.js +190 -84
- package/lib/types/index.d.ts +13 -11
- package/package.json +89 -73
- package/lib/contracts/data-registry/test.d.ts +0 -1
- package/lib/contracts/data-registry/test.js +0 -1
- package/lib/contracts/settlement-registry/abi.d.ts +0 -466
- package/lib/contracts/settlement-registry/abi.js +0 -535
- package/lib/contracts/settlement-registry/index.d.ts +0 -163
- package/lib/contracts/settlement-registry/index.js +0 -264
- package/lib/contracts/subscription-registry/abi.d.ts +0 -179
- package/lib/contracts/subscription-registry/abi.js +0 -195
- package/lib/contracts/subscription-registry/index.d.ts +0 -59
- package/lib/contracts/subscription-registry/index.js +0 -116
- package/lib/engine/graph.d.ts +0 -70
- package/lib/engine/graph.js +0 -73
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { ZERO_HEAD } from "../registry.js";
|
|
2
|
+
import { GADGET_SELF_HKDF_V1, sealSelf, unsealSelf } from "../crypto/encryption.js";
|
|
3
|
+
import { afterAll, beforeAll, describe, it } from "../node_modules/@vitest/runner/dist/index.js";
|
|
4
|
+
import { globalExpect } from "../node_modules/vitest/dist/chunks/vi.2VT5v0um.js";
|
|
5
|
+
import { TEST_APP } from "./testbed.js";
|
|
6
|
+
import { bytesToHex, hexToBytes, keccak256, stringToBytes } from "viem";
|
|
7
|
+
import { generatePrivateKey } from "viem/accounts";
|
|
8
|
+
|
|
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
|
+
const head = (f, repo) => f.getRegistry().head({
|
|
17
|
+
publisher: f.getAddress(),
|
|
18
|
+
repo
|
|
19
|
+
});
|
|
20
|
+
/** Take the first n entries of the stream and then stop. */
|
|
21
|
+
async function take(stream, n) {
|
|
22
|
+
const out = [];
|
|
23
|
+
for await (const c of stream) {
|
|
24
|
+
out.push(c);
|
|
25
|
+
if (out.length === n) break;
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
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
|
+
function sdkSuite(makeNetwork, timeout = 5e3) {
|
|
32
|
+
let net;
|
|
33
|
+
beforeAll(async () => {
|
|
34
|
+
net = await makeNetwork();
|
|
35
|
+
}, 12e4);
|
|
36
|
+
afterAll(() => {
|
|
37
|
+
net.stop();
|
|
38
|
+
});
|
|
39
|
+
describe("publishing", () => {
|
|
40
|
+
it("a publisher uploads records and reads them back", async () => {
|
|
41
|
+
const f = await net.client();
|
|
42
|
+
await f.initRepo("r");
|
|
43
|
+
const a = await f.upload("r", { event: "one" }, "event", "a");
|
|
44
|
+
const b = await f.upload("r", { event: "two" }, "event", "b");
|
|
45
|
+
globalExpect((await f.engine.readRecord(f.getAddress(), "r", "a"))?.payload).toEqual({ event: "one" });
|
|
46
|
+
const { records } = await f.inspectRepo("r");
|
|
47
|
+
globalExpect(records.map((r) => r.cid).sort()).toEqual([a.payloadCid, b.payloadCid].sort());
|
|
48
|
+
}, timeout);
|
|
49
|
+
it("can't upload to a repo that was never initialized", async () => {
|
|
50
|
+
await globalExpect((await net.client()).upload("nope", { x: 1 }, "t")).rejects.toThrow(/initRepo/);
|
|
51
|
+
}, timeout);
|
|
52
|
+
it("keeps each repo's head and records to itself", async () => {
|
|
53
|
+
const f = await net.client();
|
|
54
|
+
await f.initRepo("a");
|
|
55
|
+
const headA = await head(f, "a");
|
|
56
|
+
await f.initRepo("b");
|
|
57
|
+
const headB = await head(f, "b");
|
|
58
|
+
globalExpect(headA).not.toBe(ZERO_HEAD);
|
|
59
|
+
globalExpect(headB).not.toBe(headA);
|
|
60
|
+
globalExpect(await head(f, "untouched")).toBe(ZERO_HEAD);
|
|
61
|
+
await f.upload("a", { n: 1 }, "t", "x");
|
|
62
|
+
globalExpect(await head(f, "a")).not.toBe(headA);
|
|
63
|
+
globalExpect(await head(f, "b")).toBe(headB);
|
|
64
|
+
globalExpect((await f.inspectRepo("b")).records).toEqual([]);
|
|
65
|
+
}, timeout);
|
|
66
|
+
it("publishes a batch as one entry of the ordering", async () => {
|
|
67
|
+
const f = await net.client();
|
|
68
|
+
await f.initRepo("batch");
|
|
69
|
+
const records = Array.from({ length: 25 }, (_, i) => ({
|
|
70
|
+
id: `v-${String(i)}`,
|
|
71
|
+
type: "t",
|
|
72
|
+
payload: { i }
|
|
73
|
+
}));
|
|
74
|
+
const before = await net.clock();
|
|
75
|
+
const res = await f.uploadBatch("batch", records);
|
|
76
|
+
globalExpect(await net.clock() - before).toBe(1n);
|
|
77
|
+
globalExpect(Object.keys(res.recordCids)).toHaveLength(25);
|
|
78
|
+
globalExpect((await f.inspectRepo("batch")).records).toHaveLength(25);
|
|
79
|
+
}, timeout);
|
|
80
|
+
it("stores a payload sealed to its publisher as opaque bytes", async () => {
|
|
81
|
+
const sk = generatePrivateKey();
|
|
82
|
+
const f = await net.client(TEST_APP, sk);
|
|
83
|
+
await f.initRepo("private");
|
|
84
|
+
const resourceId = keccak256(stringToBytes("private:secret"));
|
|
85
|
+
const ciphertext = sealSelf(new TextEncoder().encode("the eagles are coming"), hexToBytes(sk), resourceId);
|
|
86
|
+
const { id } = await f.upload("private", {
|
|
87
|
+
gadget: GADGET_SELF_HKDF_V1,
|
|
88
|
+
resourceId,
|
|
89
|
+
ciphertext: bytesToHex(ciphertext)
|
|
90
|
+
}, "sealed");
|
|
91
|
+
const stored = (await f.engine.readRecord(f.getAddress(), "private", id))?.payload;
|
|
92
|
+
globalExpect(new TextDecoder().decode(unsealSelf(hexToBytes(stored.ciphertext), hexToBytes(sk), resourceId))).toBe("the eagles are coming");
|
|
93
|
+
globalExpect(() => unsealSelf(hexToBytes(stored.ciphertext), new Uint8Array(32).fill(171), resourceId)).toThrow();
|
|
94
|
+
}, timeout);
|
|
95
|
+
it("reset empties a repo with a new commit, without zeroing its head", async () => {
|
|
96
|
+
const f = await net.client();
|
|
97
|
+
await f.initRepo("r");
|
|
98
|
+
await f.upload("r", { n: 1 }, "t", "x");
|
|
99
|
+
const before = await head(f, "r");
|
|
100
|
+
await f.reset("r");
|
|
101
|
+
globalExpect(await head(f, "r")).not.toBe(before);
|
|
102
|
+
globalExpect(await head(f, "r")).not.toBe(ZERO_HEAD);
|
|
103
|
+
globalExpect((await f.inspectRepo("r")).records).toEqual([]);
|
|
104
|
+
}, timeout);
|
|
105
|
+
it("refuses to push a commit whose parent is no longer the head", async () => {
|
|
106
|
+
const f = await net.client();
|
|
107
|
+
await f.initRepo("r");
|
|
108
|
+
const stale = await f.commit({
|
|
109
|
+
repo: "r",
|
|
110
|
+
records: [{
|
|
111
|
+
id: "x",
|
|
112
|
+
type: "t",
|
|
113
|
+
payload: {}
|
|
114
|
+
}],
|
|
115
|
+
message: "m"
|
|
116
|
+
});
|
|
117
|
+
await globalExpect(f.push("r", stale.commitCid)).rejects.toThrow(/stale parent/);
|
|
118
|
+
}, timeout);
|
|
119
|
+
});
|
|
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");
|
|
129
|
+
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);
|
|
191
|
+
}, timeout);
|
|
192
|
+
});
|
|
193
|
+
describe("subscriptions", () => {
|
|
194
|
+
it("replays from a block, then follows live", async () => {
|
|
195
|
+
const app = freshApp();
|
|
196
|
+
const pub = await net.client(app);
|
|
197
|
+
const from = await net.clock();
|
|
198
|
+
await pub.initRepo("feed");
|
|
199
|
+
await pub.upload("feed", { n: 1 }, "t", "a");
|
|
200
|
+
const ctl = new AbortController();
|
|
201
|
+
const stream = (await net.client(app)).subscribeApp({
|
|
202
|
+
fromBlock: from,
|
|
203
|
+
signal: ctl.signal,
|
|
204
|
+
pollingInterval: 100
|
|
205
|
+
});
|
|
206
|
+
globalExpect((await stream.next()).value.puts.map((r) => r.id)).toEqual(["a"]);
|
|
207
|
+
const second = stream.next();
|
|
208
|
+
await pub.upload("feed", { n: 2 }, "t", "b");
|
|
209
|
+
const live = (await second).value;
|
|
210
|
+
globalExpect([
|
|
211
|
+
live.repo,
|
|
212
|
+
live.owner,
|
|
213
|
+
live.puts.map((r) => r.id)
|
|
214
|
+
]).toEqual([
|
|
215
|
+
"feed",
|
|
216
|
+
pub.getAddress(),
|
|
217
|
+
["b"]
|
|
218
|
+
]);
|
|
219
|
+
ctl.abort();
|
|
220
|
+
await stream.return(void 0);
|
|
221
|
+
}, timeout);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
//#endregion
|
|
226
|
+
export { appOf, head, sdkSuite, take };
|