@fangorn-network/sdk 2026.10.28 → 2026.11.3
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 +37 -653
- package/lib/cli/cli.js +46 -357
- package/lib/cli/index.d.ts +1 -4
- package/lib/cli/index.js +2 -20
- package/lib/cli/sell.d.ts +28 -0
- package/lib/cli/sell.js +95 -0
- package/lib/config.d.ts +163 -226
- package/lib/config.js +8 -35
- package/lib/contracts/data-registry/abi.d.ts +206 -6
- package/lib/contracts/data-registry/abi.js +415 -186
- package/lib/contracts/data-registry/index.d.ts +126 -2
- package/lib/contracts/data-registry/index.js +174 -1
- package/lib/contracts/index.d.ts +4 -7
- package/lib/contracts/index.js +4 -7
- package/lib/contracts/logs.d.ts +1 -1
- package/lib/contracts/logs.js +1 -1
- package/lib/contracts/{membership-registry → settlement-registry}/abi.d.ts +288 -637
- package/lib/contracts/settlement-registry/abi.js +947 -0
- package/lib/contracts/settlement-registry/index.d.ts +141 -0
- package/lib/contracts/settlement-registry/index.js +209 -0
- package/lib/crypto/aes.d.ts +2 -2
- package/lib/crypto/aes.js +4 -4
- package/lib/crypto/encryption.d.ts +8 -109
- package/lib/crypto/encryption.js +16 -114
- package/lib/crypto/paid.d.ts +104 -0
- package/lib/crypto/paid.js +147 -0
- package/lib/engine/index.d.ts +23 -12
- package/lib/engine/index.js +68 -29
- package/lib/engine/records.d.ts +4 -7
- package/lib/engine/records.js +6 -6
- package/lib/engine/test-helpers.d.ts +2 -3
- package/lib/engine/test-helpers.js +7 -5
- package/lib/erc8004.js +7 -10
- package/lib/fangorn.d.ts +65 -96
- package/lib/fangorn.js +110 -168
- package/lib/feed.d.ts +7 -8
- package/lib/feed.js +7 -8
- package/lib/index.d.ts +10 -13
- package/lib/index.js +10 -13
- package/lib/providers/storage/signed-url.d.ts +2 -10
- package/lib/providers/storage/signed-url.js +5 -15
- package/lib/providers/storage/types.d.ts +1 -1
- package/lib/providers/storage/utils.js +5 -3
- package/lib/test/key-server.d.ts +12 -0
- package/lib/test/key-server.js +30 -0
- package/lib/test/mem-registry.d.ts +14 -19
- package/lib/test/mem-registry.js +44 -37
- package/lib/test/sdk-suite.d.ts +1 -4
- package/lib/test/sdk-suite.js +16 -87
- package/lib/test/testbed.d.ts +35 -45
- package/lib/test/testbed.js +29 -56
- package/lib/types/index.d.ts +6 -11
- package/package.json +2 -5
- package/lib/contracts/app-registry/abi.d.ts +0 -1306
- package/lib/contracts/app-registry/abi.js +0 -1493
- package/lib/contracts/app-registry/index.d.ts +0 -200
- package/lib/contracts/app-registry/index.js +0 -325
- package/lib/contracts/membership-registry/abi.js +0 -1333
- package/lib/contracts/membership-registry/index.d.ts +0 -79
- package/lib/contracts/membership-registry/index.js +0 -104
- package/lib/contracts/types.d.ts +0 -8
- package/lib/contracts/types.js +0 -10
- package/lib/harness/examples/hackmd/build-markdown-graph.d.ts +0 -1
- package/lib/harness/examples/hackmd/build-markdown-graph.js +0 -17
- package/lib/harness/index.d.ts +0 -58
- package/lib/harness/index.js +0 -73
- package/lib/registry.d.ts +0 -118
- package/lib/registry.js +0 -184
package/lib/engine/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { assertBlockMatches, assertValidRecordId, buildMst, decodeBlock, diffMst, encodeBlock, lookupMst, readMst } from "./records.js";
|
|
2
2
|
import { packCar, readCar } from "./car.js";
|
|
3
|
-
import { ZERO_HEAD } from "../registry.js";
|
|
3
|
+
import { ZERO_HEAD } from "../contracts/data-registry/index.js";
|
|
4
|
+
import "../contracts/index.js";
|
|
5
|
+
import { bytesToHex, hexToBytes } from "viem";
|
|
4
6
|
import { CID } from "multiformats/cid";
|
|
5
|
-
import
|
|
7
|
+
import * as dagCbor from "@ipld/dag-cbor";
|
|
6
8
|
import { sha256 } from "multiformats/hashes/sha2";
|
|
7
9
|
import * as Digest from "multiformats/hashes/digest";
|
|
8
10
|
|
|
@@ -18,7 +20,36 @@ const MAX_REPO_NAME_LENGTH = 256;
|
|
|
18
20
|
* The root of the graph, committed to IPFS, as hex
|
|
19
21
|
*/
|
|
20
22
|
function rootHexFromCid(commitCid) {
|
|
21
|
-
return
|
|
23
|
+
return bytesToHex(commitCid.multihash.digest);
|
|
24
|
+
}
|
|
25
|
+
/** The update that settles `commit`. */
|
|
26
|
+
function commitUpdate(commit) {
|
|
27
|
+
return {
|
|
28
|
+
repo: commit.repo,
|
|
29
|
+
epoch: commit.epoch,
|
|
30
|
+
parent: commit.parent ? rootHexFromCid(commit.parent) : ZERO_HEAD,
|
|
31
|
+
root: rootHexFromCid(commit.root),
|
|
32
|
+
car: bytesToHex(commit.car.bytes)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** The head the registry computes for `u`. */
|
|
36
|
+
async function commitHead(u) {
|
|
37
|
+
const link = (digest) => CID.createV1(dagCbor.code, Digest.create(sha256.code, hexToBytes(digest)));
|
|
38
|
+
return rootHexFromCid((await encodeBlock({
|
|
39
|
+
epoch: u.epoch,
|
|
40
|
+
parent: u.parent === ZERO_HEAD ? null : link(u.parent),
|
|
41
|
+
root: link(u.root),
|
|
42
|
+
repo: u.repo,
|
|
43
|
+
car: CID.decode(hexToBytes(u.car))
|
|
44
|
+
})).cid);
|
|
45
|
+
}
|
|
46
|
+
/** The CID a storage backend returned for a file, with or without an `ipfs://` prefix. */
|
|
47
|
+
function fileCid(uri) {
|
|
48
|
+
try {
|
|
49
|
+
return CID.parse(uri.replace(/^ipfs:\/\//, ""));
|
|
50
|
+
} catch {
|
|
51
|
+
throw new Error(`storage returned ${JSON.stringify(uri)} for a CAR file; expected its CID`);
|
|
52
|
+
}
|
|
22
53
|
}
|
|
23
54
|
/** Repos must be non-empty strings whose length does not exceed MAX_REPO_NAME_LENGTH */
|
|
24
55
|
function assertValidRepoName(repo) {
|
|
@@ -55,8 +86,7 @@ var FangornEngine = class {
|
|
|
55
86
|
* with sha256.digest() would produce an unrelated CID pointing at nothing.
|
|
56
87
|
*/
|
|
57
88
|
hexToRootCid(hex) {
|
|
58
|
-
const
|
|
59
|
-
const rawDigestBytes = Uint8Array.from(Buffer.from(cleanHex, "hex"));
|
|
89
|
+
const rawDigestBytes = hexToBytes(`0x${hex.startsWith("0x") ? hex.slice(2) : hex}`);
|
|
60
90
|
const multihash = Digest.create(sha256.code, rawDigestBytes);
|
|
61
91
|
return CID.createV1(113, multihash);
|
|
62
92
|
}
|
|
@@ -76,13 +106,12 @@ var FangornEngine = class {
|
|
|
76
106
|
parent: decoded.parent ? CID.parse(String(decoded.parent)) : null,
|
|
77
107
|
root: CID.parse(String(decoded.root)),
|
|
78
108
|
repo: decoded.repo,
|
|
79
|
-
|
|
80
|
-
car: decoded.car ?? ""
|
|
109
|
+
car: CID.parse(String(decoded.car))
|
|
81
110
|
};
|
|
82
111
|
}
|
|
83
112
|
/** Pull every block of `commit`'s CAR into the local cache. */
|
|
84
113
|
async loadCar(commitCid, commit) {
|
|
85
|
-
const bytes = await this.storage.getFile(commit.car);
|
|
114
|
+
const bytes = await this.storage.getFile(commit.car.toString());
|
|
86
115
|
for (const block of await readCar(bytes, { verify: false })) {
|
|
87
116
|
const key = block.cid.toString();
|
|
88
117
|
if (!this.cache.has(key)) this.unverified.set(key, block.bytes);
|
|
@@ -137,7 +166,7 @@ var FangornEngine = class {
|
|
|
137
166
|
}
|
|
138
167
|
/**
|
|
139
168
|
* Which repo a commit belongs to. Events carry only `keccak256(name)`, so
|
|
140
|
-
* this is how
|
|
169
|
+
* this is how a subscriber to every repo recovers the name.
|
|
141
170
|
*/
|
|
142
171
|
async repoOf(rootHex) {
|
|
143
172
|
return (await this.getCommit(this.hexToRootCid(rootHex))).repo;
|
|
@@ -166,7 +195,7 @@ var FangornEngine = class {
|
|
|
166
195
|
const carBlocks = [];
|
|
167
196
|
const recordCids = {};
|
|
168
197
|
for (const r of opts.records) {
|
|
169
|
-
const id = r.id ?? randomUUID();
|
|
198
|
+
const id = r.id ?? globalThis.crypto.randomUUID();
|
|
170
199
|
assertValidRecordId(id);
|
|
171
200
|
if (id in recordCids) throw new Error(`record id ${id} staged twice`);
|
|
172
201
|
const block = await encodeBlock({
|
|
@@ -182,14 +211,13 @@ var FangornEngine = class {
|
|
|
182
211
|
for (const node of mst.nodes) if (!old.nodeCids.has(node.cid.toString())) carBlocks.push(node);
|
|
183
212
|
for (const block of carBlocks) this.putLocal(block);
|
|
184
213
|
const carBytes = await packCar(mst.root, carBlocks);
|
|
185
|
-
const
|
|
214
|
+
const car = fileCid(await this.storage.putFile(carBytes, `${mst.root.toString()}.car`));
|
|
186
215
|
const commitBlock = await encodeBlock({
|
|
187
216
|
epoch: await this.registry.epoch(),
|
|
188
217
|
parent: base,
|
|
189
218
|
root: mst.root,
|
|
190
219
|
repo,
|
|
191
|
-
|
|
192
|
-
car: carUri
|
|
220
|
+
car
|
|
193
221
|
});
|
|
194
222
|
await this.storage.putBlock(commitBlock);
|
|
195
223
|
this.putLocal(commitBlock);
|
|
@@ -204,26 +232,38 @@ var FangornEngine = class {
|
|
|
204
232
|
* Settle a local commit as the on-chain head of one repo — the `update` of
|
|
205
233
|
* WHITEPAPER_1 §3.2. The commit and its CAR are already durable in storage
|
|
206
234
|
* (createCommit uploads them), so this is just the compare-and-swap.
|
|
207
|
-
*
|
|
208
|
-
* The commit's parent must BE the current head, not merely an ancestor of
|
|
209
|
-
* it: then the parent chain and the registry's log are one history
|
|
210
|
-
* (Theorem 3). Today's contract only checks the old root, so the parent is
|
|
211
|
-
* checked here.
|
|
212
235
|
*/
|
|
213
236
|
async pushCommit(publisher, repo, commitCid) {
|
|
214
|
-
const
|
|
215
|
-
publisher,
|
|
216
|
-
repo
|
|
217
|
-
});
|
|
218
|
-
const commit = await this.getCommit(commitCid);
|
|
219
|
-
const parentHex = commit.parent ? rootHexFromCid(commit.parent) : ZERO_BYTES32;
|
|
220
|
-
if (commit.repo !== repo) throw new Error(`commit ${commitCid.toString()} is a commit of ${commit.repo}, not ${repo}`);
|
|
221
|
-
if (parentHex !== head) throw new Error("stale parent: this commit's parent is not the on-chain head — rebuild it onto the current head.");
|
|
237
|
+
const update = await this.settleable(publisher, repo, commitCid);
|
|
222
238
|
return {
|
|
223
|
-
txHash: await this.registry.update(
|
|
239
|
+
txHash: await this.registry.update(update),
|
|
224
240
|
onChainTip: commitCid
|
|
225
241
|
};
|
|
226
242
|
}
|
|
243
|
+
/** `pushCommit`, signed by this registry's wallet for anyone to submit with `relayCommit`. */
|
|
244
|
+
async signCommit(publisher, repo, commitCid) {
|
|
245
|
+
const update = await this.settleable(publisher, repo, commitCid);
|
|
246
|
+
return {
|
|
247
|
+
publisher,
|
|
248
|
+
update,
|
|
249
|
+
signature: await this.registry.signUpdate(update)
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
relayCommit(s) {
|
|
253
|
+
return this.registry.updateBySig(s.publisher, s.update, s.signature);
|
|
254
|
+
}
|
|
255
|
+
/** The update for `commitCid`, once it is one the registry will take as the next head. */
|
|
256
|
+
async settleable(publisher, repo, commitCid) {
|
|
257
|
+
const commit = await this.getCommit(commitCid);
|
|
258
|
+
if (commit.repo !== repo) throw new Error(`commit ${commitCid.toString()} is a commit of ${commit.repo}, not ${repo}`);
|
|
259
|
+
const update = commitUpdate(commit);
|
|
260
|
+
if (update.parent !== await this.registry.head({
|
|
261
|
+
publisher,
|
|
262
|
+
repo
|
|
263
|
+
})) throw new Error("stale parent: this commit's parent is not the on-chain head — rebuild it onto the current head.");
|
|
264
|
+
if (await commitHead(update) !== rootHexFromCid(commitCid)) throw new Error(`commit ${commitCid.toString()} is not in the current commit format — rebuild it`);
|
|
265
|
+
return update;
|
|
266
|
+
}
|
|
227
267
|
/** Walk the parent chain from `tip` toward the root, newest first. */
|
|
228
268
|
async *walkParents(tip, max) {
|
|
229
269
|
let cursor = tip;
|
|
@@ -295,7 +335,6 @@ var FangornEngine = class {
|
|
|
295
335
|
}
|
|
296
336
|
for (const id of par.keys()) if (!child.has(id)) removed.push(`${ns}/${id}`);
|
|
297
337
|
return {
|
|
298
|
-
message: commit.message,
|
|
299
338
|
parent: commit.parent?.toString() ?? null,
|
|
300
339
|
epoch: commit.epoch,
|
|
301
340
|
repo: ns,
|
|
@@ -335,4 +374,4 @@ var FangornEngine = class {
|
|
|
335
374
|
};
|
|
336
375
|
|
|
337
376
|
//#endregion
|
|
338
|
-
export { FangornEngine, MAX_REPO_NAME_LENGTH, assertValidRepoName, rootHexFromCid };
|
|
377
|
+
export { FangornEngine, MAX_REPO_NAME_LENGTH, assertValidRepoName, commitHead, commitUpdate, fileCid, rootHexFromCid };
|
package/lib/engine/records.d.ts
CHANGED
|
@@ -37,12 +37,10 @@ type Ref = {
|
|
|
37
37
|
* Commit block: γ = (e, parent, root) of WHITEPAPER_1 §3.1, whose name is the
|
|
38
38
|
* on-chain head. `root` is the repo's MST root.
|
|
39
39
|
*
|
|
40
|
-
*
|
|
41
|
-
* itself (docs/REGISTRY_SPEC.md):
|
|
40
|
+
* Two more fields:
|
|
42
41
|
* • `repo`: the repo's name, which events carry only as keccak256(name);
|
|
43
|
-
* • `
|
|
44
|
-
*
|
|
45
|
-
* commit introduced. The commit block itself is stored OUTSIDE that CAR
|
|
42
|
+
* • `car`: the CID of the CAR file holding every block this commit
|
|
43
|
+
* introduced. The commit block itself is stored OUTSIDE that CAR
|
|
46
44
|
* (individually addressable), so a reader goes digest → commit → CAR with
|
|
47
45
|
* no index lookups.
|
|
48
46
|
*/
|
|
@@ -51,8 +49,7 @@ interface CommitBlock {
|
|
|
51
49
|
parent: CID | null;
|
|
52
50
|
root: CID;
|
|
53
51
|
repo: string;
|
|
54
|
-
|
|
55
|
-
car: string;
|
|
52
|
+
car: CID;
|
|
56
53
|
}
|
|
57
54
|
/** Upper bound on a record id's length. */
|
|
58
55
|
declare const MAX_RECORD_ID_LENGTH = 256;
|
package/lib/engine/records.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { CID } from "multiformats/cid";
|
|
2
2
|
import * as dagCbor from "@ipld/dag-cbor";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
4
|
+
import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils.js";
|
|
5
|
+
import { sha256 as sha256$1 } from "multiformats/hashes/sha2";
|
|
5
6
|
|
|
6
7
|
//#region src/engine/records.ts
|
|
7
8
|
/** Encode any value as canonical dag-cbor and derive its CIDv1 (sha256). */
|
|
8
9
|
async function encodeBlock(obj) {
|
|
9
10
|
const bytes = dagCbor.encode(obj);
|
|
10
|
-
const hash = await sha256.digest(bytes);
|
|
11
|
+
const hash = await sha256$1.digest(bytes);
|
|
11
12
|
return {
|
|
12
13
|
cid: CID.createV1(dagCbor.code, hash),
|
|
13
14
|
bytes
|
|
@@ -22,8 +23,7 @@ function decodeBlock(bytes) {
|
|
|
22
23
|
}
|
|
23
24
|
/** Throw unless `bytes` hash to `cid`. Hosts are untrusted; every fetched block goes through this. */
|
|
24
25
|
function assertBlockMatches(cid, bytes) {
|
|
25
|
-
|
|
26
|
-
if (!Buffer.from(cid.multihash.digest).equals(digest)) throw new Error(`block ${cid.toString()} does not match its content hash`);
|
|
26
|
+
if (bytesToHex(cid.multihash.digest) !== bytesToHex(sha256(bytes))) throw new Error(`block ${cid.toString()} does not match its content hash`);
|
|
27
27
|
}
|
|
28
28
|
/** Upper bound on a record id's length. */
|
|
29
29
|
const MAX_RECORD_ID_LENGTH = 256;
|
|
@@ -41,7 +41,7 @@ const MST_BITS = 4;
|
|
|
41
41
|
const MAX_DEPTH = 256 / MST_BITS + 1;
|
|
42
42
|
/** level(k) = ⌊leading zero bits of sha256(k) / b⌋ */
|
|
43
43
|
function keyLevel(key) {
|
|
44
|
-
const digest =
|
|
44
|
+
const digest = sha256(utf8ToBytes(key));
|
|
45
45
|
let zeros = 0;
|
|
46
46
|
for (const byte of digest) {
|
|
47
47
|
if (byte !== 0) {
|
|
@@ -20,7 +20,7 @@ declare class MemStorage implements MetadataStorage {
|
|
|
20
20
|
/** Remote fetches performed (getRawBlock + getFile). */
|
|
21
21
|
reads: number;
|
|
22
22
|
putBlock(block: RawBlock): Promise<void>;
|
|
23
|
-
putFile(bytes: Uint8Array
|
|
23
|
+
putFile(bytes: Uint8Array): Promise<string>;
|
|
24
24
|
getFile(uri: string): Promise<Uint8Array>;
|
|
25
25
|
getRawBlock(uri: string): Promise<Uint8Array>;
|
|
26
26
|
put(_data: unknown, _meta?: StorageMeta): Promise<string>;
|
|
@@ -33,7 +33,6 @@ declare class MemStorage implements MetadataStorage {
|
|
|
33
33
|
}
|
|
34
34
|
/** The paper's registry in memory, signing as PUBLISHER. */
|
|
35
35
|
declare const PUBLISHER: Hex;
|
|
36
|
-
declare const APP: Hex;
|
|
37
36
|
declare const newRegistry: () => MemRegistry;
|
|
38
37
|
//#endregion
|
|
39
|
-
export {
|
|
38
|
+
export { MemStorage, PUBLISHER, ZERO_BYTES32, newRegistry, rootHex };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { MemRegistry } from "../test/mem-registry.js";
|
|
2
|
+
import { CID } from "multiformats/cid";
|
|
3
|
+
import { sha256 } from "multiformats/hashes/sha2";
|
|
4
|
+
import * as raw from "multiformats/codecs/raw";
|
|
2
5
|
|
|
3
6
|
//#region src/engine/test-helpers.ts
|
|
4
7
|
const ZERO_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
@@ -21,11 +24,11 @@ var MemStorage = class {
|
|
|
21
24
|
this.blocks.set(block.cid.toString(), block.bytes);
|
|
22
25
|
return Promise.resolve();
|
|
23
26
|
}
|
|
24
|
-
putFile(bytes
|
|
27
|
+
async putFile(bytes) {
|
|
25
28
|
this.writes++;
|
|
26
|
-
const uri =
|
|
29
|
+
const uri = CID.createV1(raw.code, await sha256.digest(bytes)).toString();
|
|
27
30
|
this.files.set(uri, bytes);
|
|
28
|
-
return
|
|
31
|
+
return uri;
|
|
29
32
|
}
|
|
30
33
|
getFile(uri) {
|
|
31
34
|
const bytes = this.files.get(uri);
|
|
@@ -54,8 +57,7 @@ var MemStorage = class {
|
|
|
54
57
|
};
|
|
55
58
|
/** The paper's registry in memory, signing as PUBLISHER. */
|
|
56
59
|
const PUBLISHER = "0x0000000000000000000000000000000000000001";
|
|
57
|
-
const APP = `0x${"a".repeat(64)}`;
|
|
58
60
|
const newRegistry = () => new MemRegistry(PUBLISHER);
|
|
59
61
|
|
|
60
62
|
//#endregion
|
|
61
|
-
export {
|
|
63
|
+
export { MemStorage, PUBLISHER, ZERO_BYTES32, newRegistry, rootHex };
|
package/lib/erc8004.js
CHANGED
|
@@ -2,10 +2,7 @@ import { parseAbi, parseEventLogs } from "viem";
|
|
|
2
2
|
|
|
3
3
|
//#region src/erc8004.ts
|
|
4
4
|
/** The ERC-8004 identity registry by chain id */
|
|
5
|
-
const IDENTITY_REGISTRY = {
|
|
6
|
-
84532: "0x8004A818BFB912233c491871b3d84c89A494BD9e",
|
|
7
|
-
421614: "0x8004A818BFB912233c491871b3d84c89A494BD9e"
|
|
8
|
-
};
|
|
5
|
+
const IDENTITY_REGISTRY = { 84532: "0x8004A818BFB912233c491871b3d84c89A494BD9e" };
|
|
9
6
|
const ABI = parseAbi([
|
|
10
7
|
"function register(string agentURI, (string metadataKey, bytes metadataValue)[] metadata) returns (uint256 agentId)",
|
|
11
8
|
"function setAgentURI(uint256 agentId, string newURI)",
|
|
@@ -14,12 +11,12 @@ const ABI = parseAbi([
|
|
|
14
11
|
/**
|
|
15
12
|
* Get the agent card URL based on the access worker if defined, else return the carUrl
|
|
16
13
|
* Both params are optional, but at least one must be defined.
|
|
17
|
-
*
|
|
14
|
+
*
|
|
18
15
|
* Agent cards must live at accessWorker/.well-known/agent-card.json
|
|
19
|
-
*
|
|
16
|
+
*
|
|
20
17
|
* @param cardUrl The cardUrl (passthrough when defined)
|
|
21
|
-
* @param accessWorker The (optional) access worker url
|
|
22
|
-
* @returns
|
|
18
|
+
* @param accessWorker The (optional) access worker url
|
|
19
|
+
* @returns
|
|
23
20
|
*/
|
|
24
21
|
function agentCardUrl(cardUrl, accessWorker) {
|
|
25
22
|
if (cardUrl) return cardUrl;
|
|
@@ -51,8 +48,8 @@ async function mcpTools(endpoint) {
|
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
50
|
/**
|
|
54
|
-
* Build a registration file
|
|
55
|
-
* Since it desfines its own agent id,
|
|
51
|
+
* Build a registration file
|
|
52
|
+
* Since it desfines its own agent id,
|
|
56
53
|
* first registration mints without an agent URI and must be set retroactively.
|
|
57
54
|
*/
|
|
58
55
|
function registrationFile(opts) {
|
package/lib/fangorn.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { AppConfig } from "./config.js";
|
|
2
1
|
import { PreparedTx } from "./contracts/write.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { Registry } from "./contracts/data-registry/index.js";
|
|
3
|
+
import { SettlementRegistryClient } from "./contracts/settlement-registry/index.js";
|
|
5
4
|
import "./contracts/index.js";
|
|
6
|
-
import { Registry } from "./registry.js";
|
|
7
5
|
import { MetadataStorage } from "./providers/storage/types.js";
|
|
8
|
-
import { CommitDiff, FangornEngine, RecordInput, RepoContents, RepoDiff } from "./engine/index.js";
|
|
9
|
-
import {
|
|
6
|
+
import { CommitDiff, FangornEngine, RecordInput, RepoContents, RepoDiff, SignedUpdate } from "./engine/index.js";
|
|
7
|
+
import { NetworkConfig } from "./config.js";
|
|
10
8
|
import { FangornCreateOptions, StorageConfig } from "./types/index.js";
|
|
11
|
-
import {
|
|
9
|
+
import { AgentCard as AgentCard$1 } from "./erc8004.js";
|
|
10
|
+
import { CommitFeed } from "./feed.js";
|
|
12
11
|
import { Hash, Hex, WalletClient } from "viem";
|
|
13
12
|
import { CID } from "multiformats/cid";
|
|
14
13
|
|
|
@@ -23,10 +22,6 @@ interface RepoChange extends RepoDiff {
|
|
|
23
22
|
}
|
|
24
23
|
interface SubscribeOptions {
|
|
25
24
|
repo: string;
|
|
26
|
-
/**
|
|
27
|
-
* Under an app, the stream follows what the app presents (its members' updates,
|
|
28
|
-
* less exclusions); with no app, every update the publisher commits.
|
|
29
|
-
*/
|
|
30
25
|
/** Publisher whose repo to watch (defaults to this wallet's address). */
|
|
31
26
|
owner?: Hex;
|
|
32
27
|
/**
|
|
@@ -40,10 +35,19 @@ interface SubscribeOptions {
|
|
|
40
35
|
/** Abort to stop the subscription and release the watch. */
|
|
41
36
|
signal?: AbortSignal;
|
|
42
37
|
}
|
|
43
|
-
/** The A2A extension a Fangorn app's agent card carries: it names the app the card speaks for. */
|
|
44
|
-
declare const FANGORN_APP_EXTENSION = "https://fangorn.network/a2a/app/v1";
|
|
45
38
|
/**
|
|
46
|
-
* The
|
|
39
|
+
* The A2A extension a repo's agent card carries. Its params name the repo the
|
|
40
|
+
* card speaks for: `{ chainId, dataRegistry, publisher, repo }`.
|
|
41
|
+
*/
|
|
42
|
+
declare const FANGORN_REPO_EXTENSION = "https://fangorn.network/a2a/repo/v1";
|
|
43
|
+
/**
|
|
44
|
+
* The record that binds a repo to its agent card: `{ url }`, at this id in the
|
|
45
|
+
* repo. Only the publisher can commit it, so it plays the part an on-chain
|
|
46
|
+
* pointer would.
|
|
47
|
+
*/
|
|
48
|
+
declare const CARD_RECORD = "@card";
|
|
49
|
+
/**
|
|
50
|
+
* The part of an A2A agent card `discoverCard` reads. A card's other fields
|
|
47
51
|
* (skills, endpoints and so on) pass through untouched.
|
|
48
52
|
*/
|
|
49
53
|
interface AgentCard {
|
|
@@ -62,8 +66,7 @@ declare class Fangorn {
|
|
|
62
66
|
private readonly ctx;
|
|
63
67
|
private _engine;
|
|
64
68
|
private _feed;
|
|
65
|
-
private
|
|
66
|
-
private _membership;
|
|
69
|
+
private _settlement;
|
|
67
70
|
/**
|
|
68
71
|
* The repo cache
|
|
69
72
|
* Insertion order = LRU order
|
|
@@ -136,7 +139,6 @@ declare class Fangorn {
|
|
|
136
139
|
records?: RecordInput[];
|
|
137
140
|
deletes?: string[];
|
|
138
141
|
parent?: string;
|
|
139
|
-
message: string;
|
|
140
142
|
/** Snapshot semantics: the staged records replace the repo's previous contents. */
|
|
141
143
|
replace?: boolean;
|
|
142
144
|
}): Promise<{
|
|
@@ -164,7 +166,6 @@ declare class Fangorn {
|
|
|
164
166
|
repo: string;
|
|
165
167
|
records?: RecordInput[];
|
|
166
168
|
deletes?: string[];
|
|
167
|
-
message: string;
|
|
168
169
|
/** Snapshot semantics: the staged records replace the repo's contents. */
|
|
169
170
|
replace?: boolean;
|
|
170
171
|
}): Promise<{
|
|
@@ -187,13 +188,16 @@ declare class Fangorn {
|
|
|
187
188
|
txHash: string;
|
|
188
189
|
onChainTip: string;
|
|
189
190
|
}>;
|
|
191
|
+
/**
|
|
192
|
+
* `push`, signed instead of sent: anyone holding the result can settle it with
|
|
193
|
+
* `relayPush`, paying the gas.
|
|
194
|
+
*/
|
|
195
|
+
signPush(repo: string, commitCid: string): Promise<SignedUpdate>;
|
|
196
|
+
relayPush(signed: SignedUpdate): Promise<Hash>;
|
|
190
197
|
/** The owner's current on-chain tip for a repo, or null if they have none. */
|
|
191
198
|
onChainTip(owner: Hex, repo: string): Promise<string | null>;
|
|
192
199
|
/**
|
|
193
|
-
* A publisher's repo
|
|
194
|
-
* the publisher's latest head, or, under an app, nothing unless the app
|
|
195
|
-
* presents the publisher (provides its storage) and excludes neither it nor
|
|
196
|
-
* the repo.
|
|
200
|
+
* A publisher's repo at its latest head, cached against that head.
|
|
197
201
|
*
|
|
198
202
|
* Reading a repo walks its whole record tree from the root. The tip is one
|
|
199
203
|
* cheap contract read and only moves on publish, so it doubles as the cache
|
|
@@ -209,21 +213,16 @@ declare class Fangorn {
|
|
|
209
213
|
tip: string | null;
|
|
210
214
|
contents: RepoContents;
|
|
211
215
|
}>;
|
|
212
|
-
/** The commit
|
|
213
|
-
private
|
|
214
|
-
/** Does `app` present `ref`: it presents the publisher, and excludes neither it nor the repo? */
|
|
215
|
-
private presentsRepo;
|
|
216
|
+
/** The commit at a repo's head, or null for a repo never written. */
|
|
217
|
+
private headCommit;
|
|
216
218
|
/**
|
|
217
|
-
* Every (publisher, repo)
|
|
218
|
-
* what it excludes — the app's directory, from ONE `getLogs` over the update
|
|
219
|
-
* log, kept to the publishers the app presents.
|
|
220
|
-
*
|
|
221
|
-
* ponytail: reads every publisher's updates and drops non-members, so it costs
|
|
222
|
-
* what the network writes, not what the app holds. Filter on-chain by the
|
|
223
|
-
* app's members (a `publisher` topic list) once that is too slow.
|
|
219
|
+
* Every (publisher, repo) at its latest head, from one scan of the update log.
|
|
224
220
|
* Narrow it with `repo` (every publisher's `docs`) or `owner`, filtered on-chain.
|
|
221
|
+
*
|
|
222
|
+
* ponytail: scans the whole log from `fromBlock`; an indexer's sub-log once
|
|
223
|
+
* that is too slow.
|
|
225
224
|
*/
|
|
226
|
-
|
|
225
|
+
repos(opts?: {
|
|
227
226
|
repo?: string;
|
|
228
227
|
owner?: Hex;
|
|
229
228
|
fromBlock?: bigint;
|
|
@@ -234,36 +233,38 @@ declare class Fangorn {
|
|
|
234
233
|
blockNumber: bigint;
|
|
235
234
|
}[]>;
|
|
236
235
|
/**
|
|
237
|
-
* Resolve
|
|
236
|
+
* Resolve a repo from its agent card URL alone, and prove the card speaks for it.
|
|
238
237
|
*
|
|
239
|
-
* The card names its
|
|
240
|
-
* anyone can serve a card that names any
|
|
241
|
-
* the
|
|
238
|
+
* The card names its repo in the `FANGORN_REPO_EXTENSION` A2A extension, but
|
|
239
|
+
* anyone can serve a card that names any repo. So the card is trusted only if
|
|
240
|
+
* the repo's `@card` record, which only its publisher can commit, points
|
|
242
241
|
* back at this exact URL. The comparison is exact string equality, so a
|
|
243
242
|
* trailing slash or a different host counts as a different card.
|
|
244
|
-
*
|
|
245
|
-
* Doesn't touch this client's app. Pass `appId` to `setAppId` to read under it.
|
|
246
243
|
*/
|
|
247
|
-
|
|
244
|
+
discoverCard(cardUrl: string): Promise<{
|
|
248
245
|
card: AgentCard;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
repos: string[];
|
|
246
|
+
publisher: Hex;
|
|
247
|
+
repo: string;
|
|
252
248
|
}>;
|
|
249
|
+
/** The card URL a repo's `@card` record points at, or undefined for none. */
|
|
250
|
+
cardOf(publisher: Hex, repo: string): Promise<string | undefined>;
|
|
251
|
+
/**
|
|
252
|
+
* Point one of your repos at its agent card, by committing its `@card` record.
|
|
253
|
+
* Returns the transaction, or undefined if it already points there.
|
|
254
|
+
*/
|
|
255
|
+
setCard(repo: string, cardUrl: string): Promise<Hash | undefined>;
|
|
253
256
|
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
* wants the same feed — a server fanning out to connections, say.
|
|
257
|
+
* `subscribeAll` as ONE shared, ref-counted subscription (see `CommitFeed`), for
|
|
258
|
+
* anywhere more than one consumer wants the same stream.
|
|
257
259
|
*/
|
|
258
|
-
|
|
260
|
+
feed(opts?: {
|
|
259
261
|
pollingInterval?: number;
|
|
260
|
-
}):
|
|
262
|
+
}): CommitFeed;
|
|
261
263
|
/** Walk commit history from `head` (newest first). */
|
|
262
264
|
log(head: string, max?: number): AsyncGenerator<{
|
|
263
265
|
cid: string;
|
|
264
266
|
parent: string | null;
|
|
265
267
|
epoch: number;
|
|
266
|
-
message: string;
|
|
267
268
|
root: string;
|
|
268
269
|
}>;
|
|
269
270
|
/** Show a commit and what it changed vs. its parent. */
|
|
@@ -282,19 +283,17 @@ declare class Fangorn {
|
|
|
282
283
|
*/
|
|
283
284
|
subscribe(opts: SubscribeOptions): AsyncGenerator<RepoChange>;
|
|
284
285
|
/**
|
|
285
|
-
* Stream changes
|
|
286
|
-
*
|
|
287
|
-
* `owner` (one publisher's whole app footprint). With no app, every update by
|
|
288
|
-
* anyone: a firehose.
|
|
286
|
+
* Stream changes to every repo of every publisher. Narrow it with `repo`
|
|
287
|
+
* (every publisher's `docs`) or `owner` (one publisher's repos).
|
|
289
288
|
*/
|
|
290
|
-
|
|
289
|
+
subscribeAll(opts?: Omit<SubscribeOptions, "repo"> & {
|
|
291
290
|
repo?: string;
|
|
292
291
|
}): AsyncGenerator<RepoChange>;
|
|
293
|
-
/** Shared catch-up-then-live loop behind `subscribe` and `
|
|
292
|
+
/** Shared catch-up-then-live loop behind `subscribe` and `subscribeAll`. */
|
|
294
293
|
private streamCommits;
|
|
295
294
|
/**
|
|
296
|
-
* Resolve a log entry into a repo change, or null if
|
|
297
|
-
*
|
|
295
|
+
* Resolve a log entry into a repo change, or null if the repo's records did
|
|
296
|
+
* not change.
|
|
298
297
|
*
|
|
299
298
|
* The commit itself names its repo, which must be the one the entry was
|
|
300
299
|
* logged under, or the publisher settled a commit for one repo against
|
|
@@ -306,27 +305,21 @@ declare class Fangorn {
|
|
|
306
305
|
* dropped entry changed.
|
|
307
306
|
*/
|
|
308
307
|
private toRepoChange;
|
|
309
|
-
getConfig():
|
|
310
|
-
/** Heads
|
|
308
|
+
getConfig(): NetworkConfig;
|
|
309
|
+
/** Heads and the update log: the registry of WHITEPAPER_1 §3.2. */
|
|
311
310
|
getRegistry(): Registry;
|
|
311
|
+
getSettlementRegistry(): SettlementRegistryClient;
|
|
312
312
|
/**
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
* The owner accepts a publisher (`acceptPublisher()`); from then its uploads
|
|
316
|
-
* bill the app's subscription, and the app presents its repos.
|
|
317
|
-
*/
|
|
318
|
-
getAppRegistry(): AppRegistryClient;
|
|
319
|
-
getMembershipRegistry(): MembershipRegistryClient;
|
|
320
|
-
/**
|
|
321
|
-
* Register the app as an ERC-8004 agent from its card, and point the app at the card
|
|
322
|
-
* (owner only). The registration file is pinned with this client's storage, so a
|
|
313
|
+
* Register a repo as an ERC-8004 agent from its card, and point the repo at
|
|
314
|
+
* the card (`setCard`). The registration file is pinned with this client's storage, so a
|
|
323
315
|
* browser wallet on signed-URL storage needs no Pinata JWT.
|
|
324
316
|
*
|
|
325
317
|
* `update` re-files an agent already minted (its token id) from the card as it is
|
|
326
318
|
* now, minting nothing. `skipRegister` only binds the card. A binding that already
|
|
327
319
|
* points at `cardUrl` is left alone.
|
|
328
320
|
*/
|
|
329
|
-
registerAgent(cardUrl: string, opts
|
|
321
|
+
registerAgent(cardUrl: string, opts: {
|
|
322
|
+
repo: string;
|
|
330
323
|
mcp?: string;
|
|
331
324
|
update?: bigint;
|
|
332
325
|
skipRegister?: boolean;
|
|
@@ -335,30 +328,6 @@ declare class Fangorn {
|
|
|
335
328
|
agentId?: bigint;
|
|
336
329
|
txHash?: Hash;
|
|
337
330
|
}>;
|
|
338
|
-
/** The app this client reads and publishes under, or undefined for none. */
|
|
339
|
-
getAppId(): Hex | undefined;
|
|
340
|
-
private requireApp;
|
|
341
|
-
/**
|
|
342
|
-
* Point this client at a different app — by name (`"my-app"`) or by app id —
|
|
343
|
-
* or at none, without rebuilding it. Every read, publish and subscription
|
|
344
|
-
* after this call is in the new context.
|
|
345
|
-
*
|
|
346
|
-
* Repo reads are dropped from the cache (its keys are app-agnostic) and
|
|
347
|
-
* the shared `appFeed` is released: a feed watches one app's commit stream, so
|
|
348
|
-
* the next `appFeed()` opens a fresh subscription. Generators already running
|
|
349
|
-
* from `subscribe`/`subscribeApp` keep their original filter until aborted.
|
|
350
|
-
*/
|
|
351
|
-
setAppId(nameOrId: string | undefined): void;
|
|
352
|
-
/**
|
|
353
|
-
* Rename this client's app (owner only) — to a name (`"my-app"`) or an app id —
|
|
354
|
-
* and point this client at the new id.
|
|
355
|
-
*
|
|
356
|
-
* Nothing moves on chain: the new id is an alias of the id the app was claimed
|
|
357
|
-
* under, so its publishers, exclusions, subscription and token carry on, and
|
|
358
|
-
* clients still on an old id keep working. The new id must be unclaimed, or one
|
|
359
|
-
* this app already went by (renaming back).
|
|
360
|
-
*/
|
|
361
|
-
renameApp(nameOrId: string): Promise<Hash>;
|
|
362
331
|
getStorage(): MetadataStorage;
|
|
363
332
|
/**
|
|
364
333
|
* Swap the storage backend at runtime — e.g. move from access-worker signed
|
|
@@ -370,4 +339,4 @@ declare class Fangorn {
|
|
|
370
339
|
getAddress(): Hex;
|
|
371
340
|
}
|
|
372
341
|
//#endregion
|
|
373
|
-
export { AgentCard,
|
|
342
|
+
export { AgentCard, CARD_RECORD, FANGORN_REPO_EXTENSION, Fangorn, RepoChange, SubscribeOptions };
|