@fangorn-network/sdk 2026.5.11 → 2026.7.1-2.0
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 +219 -225
- package/lib/ crypto/constants.d.ts +4 -0
- package/lib/ crypto/constants.js +5 -0
- package/lib/ crypto/merkle.d.ts +10 -0
- package/lib/ crypto/merkle.js +34 -0
- package/lib/cli/cli.d.ts +0 -0
- package/lib/cli/cli.js +234 -235
- package/lib/cli/index.d.ts +13 -650
- package/lib/config.d.ts +45 -699
- package/lib/config.js +6 -22
- package/lib/contracts/data-registry/abi.d.ts +38 -0
- package/lib/contracts/data-registry/abi.js +237 -0
- package/lib/contracts/data-registry/index.d.ts +81 -0
- package/lib/contracts/data-registry/index.js +184 -0
- package/lib/contracts/data-registry/test.d.ts +1 -0
- package/lib/contracts/index.d.ts +3 -0
- package/lib/contracts/index.js +4 -0
- package/lib/crypto/aes.d.ts +26 -0
- package/lib/crypto/aes.js +58 -0
- package/lib/crypto/encryption.d.ts +53 -0
- package/lib/crypto/encryption.js +82 -0
- package/lib/crypto/rand.d.ts +5 -0
- package/lib/{modules/encryption → crypto}/rand.js +1 -1
- package/lib/{modules/encryption → crypto}/types.d.ts +1 -1
- package/lib/engine/blockstore.d.ts +24 -0
- package/lib/engine/blockstore.js +85 -0
- package/lib/engine/index.d.ts +180 -0
- package/lib/engine/index.js +367 -0
- package/lib/fangorn.d.ts +149 -16
- package/lib/fangorn.js +256 -37
- package/lib/harness/examples/hackmd/build-markdown-graph.d.ts +1 -0
- package/lib/harness/examples/hackmd/build-markdown-graph.js +17 -0
- package/lib/harness/index.d.ts +57 -0
- package/lib/harness/index.js +67 -0
- package/lib/index.d.ts +2 -4
- package/lib/index.js +1 -3
- package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/_polyval.js +218 -0
- package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/aes.js +261 -0
- package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/utils.js +156 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/curve.js +299 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/edwards.js +532 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/modular.js +344 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/montgomery.js +137 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/ed25519.js +262 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/utils.js +150 -0
- package/lib/providers/storage/car.d.ts +36 -0
- package/lib/providers/storage/car.js +80 -0
- package/lib/providers/storage/pinata.d.ts +34 -2
- package/lib/providers/storage/pinata.js +141 -5
- package/lib/providers/storage/types.d.ts +31 -16
- package/lib/providers/storage/utils.js +2 -1
- package/lib/roles/repo/index.d.ts +56 -0
- package/lib/roles/repo/index.js +73 -0
- package/lib/test/car_smoke.d.ts +1 -0
- package/lib/test/car_smoke.js +81 -0
- package/lib/test/cleanup-embeddings-testdata.d.ts +1 -0
- package/lib/test/cleanup-embeddings-testdata.js +75 -0
- package/lib/test/setup-embeddings-testdata.d.ts +11 -0
- package/lib/test/setup-embeddings-testdata.js +155 -0
- package/lib/test/testbed.d.ts +39 -30
- package/lib/test/testbed.js +43 -129
- package/lib/types/index.d.ts +3 -19
- package/lib/utils/manifest.d.ts +23 -0
- package/lib/utils/manifest.js +77 -0
- package/package.json +99 -67
- package/lib/modules/encryption/actions.d.ts +0 -4
- package/lib/modules/encryption/actions.js +0 -18
- package/lib/modules/encryption/aes.d.ts +0 -10
- package/lib/modules/encryption/aes.js +0 -51
- package/lib/modules/encryption/rand.d.ts +0 -5
- package/lib/registries/datasource-registry/abi.d.ts +0 -156
- package/lib/registries/datasource-registry/abi.js +0 -194
- package/lib/registries/datasource-registry/index.d.ts +0 -30
- package/lib/registries/datasource-registry/index.js +0 -158
- package/lib/registries/index.d.ts +0 -3
- package/lib/registries/index.js +0 -4
- package/lib/registries/schema-registry/abi.d.ts +0 -218
- package/lib/registries/schema-registry/abi.js +0 -246
- package/lib/registries/schema-registry/index.d.ts +0 -34
- package/lib/registries/schema-registry/index.js +0 -179
- package/lib/registries/settlement-registry/abi.d.ts +0 -218
- package/lib/registries/settlement-registry/abi.js +0 -259
- package/lib/registries/settlement-registry/index.d.ts +0 -63
- package/lib/registries/settlement-registry/index.js +0 -325
- package/lib/registries/settlement-registry/types.d.ts +0 -54
- package/lib/roles/consumer/index.d.ts +0 -39
- package/lib/roles/consumer/index.js +0 -143
- package/lib/roles/consumer/types.d.ts +0 -47
- package/lib/roles/consumer/types.js +0 -1
- package/lib/roles/publisher/index.d.ts +0 -50
- package/lib/roles/publisher/index.js +0 -224
- package/lib/roles/publisher/types.d.ts +0 -99
- package/lib/roles/publisher/types.js +0 -1
- package/lib/roles/schema/index.d.ts +0 -18
- package/lib/roles/schema/index.js +0 -93
- package/lib/roles/schema/types.d.ts +0 -91
- package/lib/roles/schema/types.js +0 -1
- /package/lib/{modules/encryption/index.d.ts → crypto/utils.d.ts} +0 -0
- /package/lib/{modules/encryption/index.js → crypto/utils.js} +0 -0
- /package/lib/{modules/encryption/types.js → contracts/data-registry/test.js} +0 -0
- /package/lib/{registries/settlement-registry → crypto}/types.js +0 -0
package/lib/cli/cli.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { FangornConfig
|
|
3
|
-
import { DataSourceRegistry } from "../registries/datasource-registry/index.js";
|
|
2
|
+
import { FangornConfig } from "../config.js";
|
|
4
3
|
import { Fangorn } from "../fangorn.js";
|
|
5
|
-
import {
|
|
6
|
-
import { createWalletClient, http } from "viem";
|
|
4
|
+
import { handleCancel } from "./index.js";
|
|
7
5
|
import { privateKeyToAccount } from "viem/accounts";
|
|
8
6
|
import { Command } from "commander";
|
|
9
|
-
import { confirm, intro,
|
|
7
|
+
import { confirm, intro, outro, spinner, text } from "@clack/prompts";
|
|
10
8
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
11
|
-
import {
|
|
9
|
+
import { join } from "path";
|
|
12
10
|
import { homedir } from "os";
|
|
13
|
-
import { Identity } from "@semaphore-protocol/identity";
|
|
14
11
|
import "dotenv/config";
|
|
15
12
|
|
|
16
13
|
//#region src/cli/cli.ts
|
|
@@ -19,45 +16,39 @@ const CONFIG_PATH = join(CONFIG_DIR, "config.json");
|
|
|
19
16
|
let _config = null;
|
|
20
17
|
let _account = null;
|
|
21
18
|
let _fangorn = null;
|
|
22
|
-
function resolveAppConfig(chainName) {
|
|
23
|
-
if (chainName === SupportedNetworks.ArbitrumSepolia.name) return FangornConfig.ArbitrumSepolia;
|
|
24
|
-
return FangornConfig.BaseSepolia;
|
|
25
|
-
}
|
|
26
19
|
function loadConfig() {
|
|
27
20
|
if (_config) return _config;
|
|
28
|
-
const privateKey = process.env.
|
|
21
|
+
const privateKey = process.env.ETH_PRIVATE_KEY;
|
|
29
22
|
const pinataJwt = process.env.PINATA_JWT;
|
|
30
23
|
const pinataGateway = process.env.PINATA_GATEWAY;
|
|
31
|
-
const chainName = process.env.CHAIN_NAME;
|
|
32
24
|
const workerUrl = process.env.WORKER_URL;
|
|
33
|
-
if (
|
|
25
|
+
if (existsSync(CONFIG_PATH)) {
|
|
26
|
+
const stored = JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
|
|
27
|
+
_config = {
|
|
28
|
+
privateKey: stored.privateKey,
|
|
29
|
+
cfg: FangornConfig,
|
|
30
|
+
pinataJwt: stored.pinataJwt,
|
|
31
|
+
pinataGateway: stored.pinataGateway,
|
|
32
|
+
workerUrl: stored.workerUrl
|
|
33
|
+
};
|
|
34
|
+
return _config;
|
|
35
|
+
}
|
|
36
|
+
{
|
|
34
37
|
const missing = [];
|
|
35
|
-
if (!privateKey) missing.push("
|
|
38
|
+
if (!privateKey) missing.push("ETH_PRIVATE_KEY");
|
|
36
39
|
if (!pinataJwt) missing.push("PINATA_JWT");
|
|
37
40
|
if (!pinataGateway) missing.push("PINATA_GATEWAY");
|
|
38
|
-
if (!chainName) missing.push("CHAIN_NAME");
|
|
39
41
|
if (missing.length > 0) throw new Error(`Incomplete environment configuration. Missing: ${missing.join(", ")}\nSet all required env vars or run \`fangorn init\` to use a config file.`);
|
|
40
42
|
_config = {
|
|
41
43
|
privateKey,
|
|
42
|
-
cfg:
|
|
44
|
+
cfg: FangornConfig,
|
|
43
45
|
pinataJwt: pinataJwt ?? "",
|
|
44
46
|
pinataGateway: pinataGateway ?? "",
|
|
45
47
|
workerUrl: workerUrl ?? ""
|
|
46
48
|
};
|
|
47
49
|
return _config;
|
|
48
50
|
}
|
|
49
|
-
|
|
50
|
-
const stored = JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
|
|
51
|
-
_config = {
|
|
52
|
-
privateKey: stored.privateKey,
|
|
53
|
-
cfg: resolveAppConfig(stored.chainName),
|
|
54
|
-
pinataJwt: stored.pinataJwt,
|
|
55
|
-
pinataGateway: stored.pinataGateway,
|
|
56
|
-
workerUrl: stored.workerUrl
|
|
57
|
-
};
|
|
58
|
-
return _config;
|
|
59
|
-
}
|
|
60
|
-
throw new Error("No configuration found. Run `fangorn init` or set the required env vars:\n DELEGATOR_ETH_PRIVATE_KEY, PINATA_JWT, PINATA_GATEWAY, CHAIN_NAME");
|
|
51
|
+
throw new Error("No configuration found. Run `fangorn init` or set the required env vars:\n ETH_PRIVATE_KEY, PINATA_JWT, PINATA_GATEWAY, CHAIN_NAME");
|
|
61
52
|
}
|
|
62
53
|
function getAccount() {
|
|
63
54
|
if (_account) return _account;
|
|
@@ -67,10 +58,6 @@ function getAccount() {
|
|
|
67
58
|
function getFangorn() {
|
|
68
59
|
if (_fangorn) return _fangorn;
|
|
69
60
|
const cfg = loadConfig();
|
|
70
|
-
const agentConfig = {
|
|
71
|
-
privateKey: cfg.privateKey,
|
|
72
|
-
pinataJwt: cfg.pinataJwt
|
|
73
|
-
};
|
|
74
61
|
_fangorn = Fangorn.create({
|
|
75
62
|
privateKey: cfg.privateKey,
|
|
76
63
|
storage: { pinata: {
|
|
@@ -78,20 +65,57 @@ function getFangorn() {
|
|
|
78
65
|
gateway: cfg.pinataGateway
|
|
79
66
|
} },
|
|
80
67
|
domain: "localhost",
|
|
81
|
-
config: cfg.cfg
|
|
82
|
-
agentConfig
|
|
68
|
+
config: cfg.cfg
|
|
83
69
|
});
|
|
84
70
|
return _fangorn;
|
|
85
71
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
throw new Error(`Schema "${schemaNameOrId}" not found on-chain. Register it with \`fangorn schema register\`.`);
|
|
72
|
+
var LocalRepo = class LocalRepo {
|
|
73
|
+
constructor(dir, state) {
|
|
74
|
+
this.dir = dir;
|
|
75
|
+
this.state = state;
|
|
91
76
|
}
|
|
92
|
-
|
|
77
|
+
static path(dir) {
|
|
78
|
+
return join(dir, ".fangorn", "repo.json");
|
|
79
|
+
}
|
|
80
|
+
/** Create (or overwrite) a repo pointer in `dir`. */
|
|
81
|
+
static init(state, dir = process.cwd()) {
|
|
82
|
+
const repoDir = join(dir, ".fangorn");
|
|
83
|
+
if (!existsSync(repoDir)) mkdirSync(repoDir, { recursive: true });
|
|
84
|
+
const repo = new LocalRepo(dir, state);
|
|
85
|
+
repo.save();
|
|
86
|
+
return repo;
|
|
87
|
+
}
|
|
88
|
+
/** Open the repo containing `dir` (searches upward like git). Throws if none. */
|
|
89
|
+
static open(dir = process.cwd()) {
|
|
90
|
+
let cur = dir;
|
|
91
|
+
while (true) {
|
|
92
|
+
const p = LocalRepo.path(cur);
|
|
93
|
+
if (existsSync(p)) return new LocalRepo(cur, JSON.parse(readFileSync(p, "utf-8")));
|
|
94
|
+
const parent = join(cur, "..");
|
|
95
|
+
if (parent === cur) break;
|
|
96
|
+
cur = parent;
|
|
97
|
+
}
|
|
98
|
+
throw new Error("not a fangorn repo (no .fangorn/repo.json here or above). Run `fangorn repo init <namespace>` or `fangorn clone`.");
|
|
99
|
+
}
|
|
100
|
+
save() {
|
|
101
|
+
writeFileSync(LocalRepo.path(this.dir), JSON.stringify(this.state, null, 2), "utf-8");
|
|
102
|
+
}
|
|
103
|
+
namespace() {
|
|
104
|
+
return this.state.namespace;
|
|
105
|
+
}
|
|
106
|
+
owner() {
|
|
107
|
+
return this.state.owner;
|
|
108
|
+
}
|
|
109
|
+
head() {
|
|
110
|
+
return this.state.head;
|
|
111
|
+
}
|
|
112
|
+
setHead(cid) {
|
|
113
|
+
this.state.head = cid;
|
|
114
|
+
this.save();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
93
117
|
const program = new Command();
|
|
94
|
-
program.name("fangorn").description("Fangorn Network CLI").version("0.
|
|
118
|
+
program.name("fangorn").description("Fangorn Network CLI").version("0.4.0");
|
|
95
119
|
program.command("init").description("Configure your Fangorn credentials").action(async () => {
|
|
96
120
|
intro("Fangorn Setup");
|
|
97
121
|
const privateKey = await text({
|
|
@@ -103,17 +127,6 @@ program.command("init").description("Configure your Fangorn credentials").action
|
|
|
103
127
|
}
|
|
104
128
|
});
|
|
105
129
|
handleCancel(privateKey);
|
|
106
|
-
const chainName = await select({
|
|
107
|
-
message: "Default chain:",
|
|
108
|
-
options: [{
|
|
109
|
-
value: SupportedNetworks.ArbitrumSepolia.name,
|
|
110
|
-
label: "Arbitrum Sepolia"
|
|
111
|
-
}, {
|
|
112
|
-
value: SupportedNetworks.BaseSepolia.name,
|
|
113
|
-
label: "Base Sepolia"
|
|
114
|
-
}]
|
|
115
|
-
});
|
|
116
|
-
handleCancel(chainName);
|
|
117
130
|
const pinataJwt = await text({
|
|
118
131
|
message: "Pinata JWT:",
|
|
119
132
|
validate: (v) => {
|
|
@@ -139,7 +152,7 @@ program.command("init").description("Configure your Fangorn credentials").action
|
|
|
139
152
|
handleCancel(workerUrl);
|
|
140
153
|
const stored = {
|
|
141
154
|
privateKey,
|
|
142
|
-
chainName,
|
|
155
|
+
chainName: "Arbitrum Sepolia",
|
|
143
156
|
pinataJwt,
|
|
144
157
|
pinataGateway,
|
|
145
158
|
workerUrl
|
|
@@ -149,254 +162,221 @@ program.command("init").description("Configure your Fangorn credentials").action
|
|
|
149
162
|
chmodSync(CONFIG_PATH, 384);
|
|
150
163
|
outro(`Config saved to ${CONFIG_PATH}`);
|
|
151
164
|
});
|
|
152
|
-
|
|
153
|
-
schemaCmd.command("register").description("Register a schema on-chain").argument("<name>", "Schema name").action(async (name) => {
|
|
165
|
+
program.command("register").description("Register your wallet as a data publisher on-chain").action(async () => {
|
|
154
166
|
try {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
message: "Path to your JSON schema file:",
|
|
161
|
-
placeholder: "./schema.json",
|
|
162
|
-
validate: (v) => {
|
|
163
|
-
if (!v) return "Required";
|
|
164
|
-
if (!existsSync(v)) return `File not found: ${v}`;
|
|
165
|
-
if (extname(v).toLowerCase() !== ".json") return "Must be a .json file";
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
handleCancel(schemaFilePath);
|
|
169
|
-
let definition;
|
|
170
|
-
try {
|
|
171
|
-
definition = JSON.parse(readFileSync(schemaFilePath, "utf-8"));
|
|
172
|
-
} catch {
|
|
173
|
-
throw new Error(`Failed to parse ${schemaFilePath} as JSON`);
|
|
174
|
-
}
|
|
175
|
-
note(JSON.stringify(definition, null, 2), "Schema definition:");
|
|
176
|
-
const ok = await confirm({ message: "Register this schema?" });
|
|
177
|
-
handleCancel(ok);
|
|
178
|
-
if (!ok) {
|
|
179
|
-
outro("Cancelled.");
|
|
167
|
+
const self = getAccount().address;
|
|
168
|
+
const registry = getFangorn().getDataRegistry();
|
|
169
|
+
const s = spinner();
|
|
170
|
+
if (await registry.isRegistered(self)) {
|
|
171
|
+
console.log(`Already registered: ${self}`);
|
|
180
172
|
process.exit(0);
|
|
181
173
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const { schemaId, schemaCid } = await fangorn.schema.register({
|
|
185
|
-
name,
|
|
186
|
-
definition,
|
|
187
|
-
agentId: ""
|
|
188
|
-
});
|
|
174
|
+
s.start("Registering publisher...");
|
|
175
|
+
const txHash = await registry.register();
|
|
189
176
|
s.stop();
|
|
190
|
-
|
|
177
|
+
console.log(`Publisher: ${self}`);
|
|
178
|
+
console.log(`Tx: ${txHash}`);
|
|
191
179
|
process.exit(0);
|
|
192
180
|
} catch (err) {
|
|
193
181
|
console.error("Failed:", err.message);
|
|
194
182
|
process.exit(1);
|
|
195
183
|
}
|
|
196
184
|
});
|
|
197
|
-
|
|
185
|
+
program.command("repo").description("Repository operations").command("init").description("Start tracking a namespace here (allocates it on-chain if new)").argument("<namespace>", "Namespace name").action(async (namespace) => {
|
|
198
186
|
try {
|
|
199
187
|
const fangorn = getFangorn();
|
|
188
|
+
const owner = fangorn.getAddress();
|
|
200
189
|
const s = spinner();
|
|
201
|
-
s.start(`
|
|
202
|
-
const
|
|
190
|
+
s.start(`Initializing namespace "${namespace}"...`);
|
|
191
|
+
const result = await fangorn.initRepo(namespace);
|
|
192
|
+
const head = result.alreadyInitialized ? await fangorn.onChainTip(owner) : result.commitCid ?? null;
|
|
193
|
+
const repo = LocalRepo.init({
|
|
194
|
+
namespace,
|
|
195
|
+
owner,
|
|
196
|
+
head
|
|
197
|
+
});
|
|
203
198
|
s.stop();
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
|
|
199
|
+
if (result.alreadyInitialized) console.log(`Namespace "${namespace}" already exists for ${owner}. Tracking it here.`);
|
|
200
|
+
else {
|
|
201
|
+
console.log(`Namespace: ${namespace}`);
|
|
202
|
+
console.log(`Owner: ${owner}`);
|
|
203
|
+
console.log(`Tx: ${result.txHash}`);
|
|
207
204
|
}
|
|
208
|
-
|
|
205
|
+
console.log(`HEAD: ${repo.head() ?? "(none)"}`);
|
|
209
206
|
process.exit(0);
|
|
210
207
|
} catch (err) {
|
|
211
208
|
console.error("Failed:", err.message);
|
|
212
209
|
process.exit(1);
|
|
213
210
|
}
|
|
214
211
|
});
|
|
215
|
-
|
|
216
|
-
publishCmd.command("upload").description("Publish file handle(s) under a schema").argument("<files...>", "JSON file(s) containing PublishRecord(s)").requiredOption("-s, --schema <schemaName>", "Schema name or bytes32 ID").option("-p, --price <USDC>", "Resource price in USDC (smallest unit)", "0").option("-o, --overwrite", "Overwrite existing entries instead of merging", false).action(async (files, options) => {
|
|
212
|
+
program.command("commit").description("Snapshot a namespace's vertices/edges into a new local commit (does not push)").argument("<file>", "JSON file: {\"vertices\":[{\"id\",\"tag\",\"payload\"}],\"edges\":[{\"rel\",\"from\",\"to\"}]}").requiredOption("-m, --message <msg>", "Commit message").action(async (file, options) => {
|
|
217
213
|
try {
|
|
214
|
+
if (!existsSync(file)) throw new Error(`file not found: ${file}`);
|
|
215
|
+
const data = JSON.parse(readFileSync(file, "utf-8"));
|
|
216
|
+
if (!Array.isArray(data.vertices) || data.vertices.length === 0) throw new Error(`${file} must contain a non-empty "vertices" array`);
|
|
217
|
+
const repo = LocalRepo.open();
|
|
218
218
|
const fangorn = getFangorn();
|
|
219
|
-
const
|
|
219
|
+
const parent = repo.head() ?? void 0;
|
|
220
220
|
const s = spinner();
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
221
|
+
s.start(parent ? "Committing (building on local HEAD)..." : "Committing (initial)...");
|
|
222
|
+
const result = await fangorn.commit({
|
|
223
|
+
namespace: repo.namespace(),
|
|
224
|
+
vertices: data.vertices,
|
|
225
|
+
edges: data.edges ?? [],
|
|
226
|
+
parent,
|
|
227
|
+
message: options.message
|
|
225
228
|
});
|
|
226
|
-
s.start("Publishing...");
|
|
227
|
-
const result = await fangorn.publisher.upload({
|
|
228
|
-
records,
|
|
229
|
-
schemaName: options.schema,
|
|
230
|
-
options: { overwrite: options.overwrite }
|
|
231
|
-
}, price);
|
|
232
229
|
s.stop();
|
|
233
|
-
|
|
230
|
+
repo.setHead(result.commitCid);
|
|
231
|
+
console.log(`Commit: ${result.commitCid}`);
|
|
232
|
+
console.log(`Parent: ${result.parents[0] ?? "(root)"}`);
|
|
233
|
+
console.log(`Tree: ${result.pailRoot}`);
|
|
234
|
+
console.log(`Staged: ${data.vertices.length.toString()} vertice(s) / ${(data.edges ?? []).length.toString()} edge(s)`);
|
|
235
|
+
console.log(`Message: ${options.message}`);
|
|
236
|
+
console.log(`\nCommitted locally. Run \`fangorn push\` to settle it on-chain.`);
|
|
234
237
|
process.exit(0);
|
|
235
238
|
} catch (err) {
|
|
236
239
|
console.error("Failed:", err.message);
|
|
237
240
|
process.exit(1);
|
|
238
241
|
}
|
|
239
242
|
});
|
|
240
|
-
|
|
243
|
+
program.command("push").description("Settle the local tip commit as the on-chain state root (the permissioned step)").option("--force", "Push even if it does not fast-forward the on-chain tip").action(async (options) => {
|
|
241
244
|
try {
|
|
245
|
+
const head = LocalRepo.open().head();
|
|
246
|
+
if (!head) throw new Error("nothing to push — no commits yet");
|
|
242
247
|
const fangorn = getFangorn();
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
248
|
+
const s = spinner();
|
|
249
|
+
s.start("Pushing...");
|
|
250
|
+
const { txHash, onChainTip } = await fangorn.push(head, { force: options.force });
|
|
251
|
+
s.stop();
|
|
252
|
+
console.log(`Tx: ${txHash}`);
|
|
253
|
+
console.log(`Tip: ${onChainTip}`);
|
|
246
254
|
process.exit(0);
|
|
247
255
|
} catch (err) {
|
|
248
256
|
console.error("Failed:", err.message);
|
|
249
257
|
process.exit(1);
|
|
250
258
|
}
|
|
251
259
|
});
|
|
252
|
-
|
|
253
|
-
consumeCmd.command("list").description("List a publisher's manifest entries").requiredOption("-s, --schema <schemaName>", "Schema name or bytes32 ID").requiredOption("--owner <address>", "Publisher address").action(async (options) => {
|
|
260
|
+
program.command("status").description("Compare the local tip with the on-chain tip").action(async () => {
|
|
254
261
|
try {
|
|
262
|
+
const repo = LocalRepo.open();
|
|
255
263
|
const fangorn = getFangorn();
|
|
256
|
-
const
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
console.log(`
|
|
263
|
-
console.log(`
|
|
264
|
-
console.log(`Entries (${manifest.entries.length.toString()}):`);
|
|
265
|
-
for (const entry of manifest.entries) console.log(` - ${entry.name}`);
|
|
264
|
+
const localHead = repo.head();
|
|
265
|
+
const onChainTip = await fangorn.onChainTip(repo.owner());
|
|
266
|
+
const state = localHead === onChainTip ? "up to date" : localHead && !onChainTip ? "local commits not yet pushed" : localHead !== onChainTip ? "local tip differs from on-chain tip (push to fast-forward)" : "no local commits";
|
|
267
|
+
console.log(`Namespace: ${repo.namespace()}`);
|
|
268
|
+
console.log(`Owner: ${repo.owner()}`);
|
|
269
|
+
console.log(`Local HEAD: ${localHead ?? "(none)"}`);
|
|
270
|
+
console.log(`On-chain tip: ${onChainTip ?? "(none)"}`);
|
|
271
|
+
console.log(`Status: ${state}`);
|
|
266
272
|
process.exit(0);
|
|
267
273
|
} catch (err) {
|
|
268
274
|
console.error("Failed:", err.message);
|
|
269
275
|
process.exit(1);
|
|
270
276
|
}
|
|
271
277
|
});
|
|
272
|
-
|
|
278
|
+
program.command("log").description("Walk commit history from the local tip").option("-n, --max <n>", "Limit number of commits", (v) => parseInt(v, 10)).action(async (options) => {
|
|
273
279
|
try {
|
|
280
|
+
const head = LocalRepo.open().head();
|
|
281
|
+
if (!head) {
|
|
282
|
+
console.log("(no commits yet)");
|
|
283
|
+
process.exit(0);
|
|
284
|
+
}
|
|
274
285
|
const fangorn = getFangorn();
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
286
|
+
for await (const c of fangorn.log(head, options.max)) {
|
|
287
|
+
console.log(`commit ${c.cid}`);
|
|
288
|
+
console.log(`Date: ${new Date(c.timestamp).toISOString()}`);
|
|
289
|
+
console.log(`Tree: ${c.pailRoot}`);
|
|
290
|
+
console.log(`\n ${c.message}\n`);
|
|
291
|
+
}
|
|
278
292
|
process.exit(0);
|
|
279
293
|
} catch (err) {
|
|
280
294
|
console.error("Failed:", err.message);
|
|
281
295
|
process.exit(1);
|
|
282
296
|
}
|
|
283
297
|
});
|
|
284
|
-
|
|
298
|
+
program.command("show").description("Show a commit and what it changed vs. its parent").argument("[commit]", "Commit CID (default: local HEAD)").action(async (commitArg) => {
|
|
285
299
|
try {
|
|
286
|
-
const
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
});
|
|
298
|
-
s.start("Preparing ERC-3009 authorization...");
|
|
299
|
-
const preparedRegister = await fangorn.consumer.prepareRegister({
|
|
300
|
-
walletClient,
|
|
301
|
-
paymentRecipient: owner,
|
|
302
|
-
amount: BigInt(options.amount),
|
|
303
|
-
usdcAddress: options.usdc,
|
|
304
|
-
usdcDomainName: "USD Coin",
|
|
305
|
-
usdcDomainVersion: "2"
|
|
306
|
-
});
|
|
307
|
-
s.stop();
|
|
308
|
-
s.start("Submitting registration...");
|
|
309
|
-
const { txHash } = await fangorn.consumer.register({
|
|
310
|
-
owner,
|
|
311
|
-
schemaId,
|
|
312
|
-
name,
|
|
313
|
-
identityCommitment: identity.commitment,
|
|
314
|
-
relayerPrivateKey: relayerKey,
|
|
315
|
-
preparedRegister
|
|
316
|
-
});
|
|
317
|
-
s.stop();
|
|
318
|
-
const exported = identity.export();
|
|
319
|
-
note([
|
|
320
|
-
`Tx: ${txHash}`,
|
|
321
|
-
``,
|
|
322
|
-
`⚠️ Save this identity string — you will need it for \`claim\`:`,
|
|
323
|
-
``,
|
|
324
|
-
` ${exported}`,
|
|
325
|
-
``,
|
|
326
|
-
`Next:`,
|
|
327
|
-
` fangorn consume claim ${owner} ${name} \\`,
|
|
328
|
-
` -s ${options.schema} \\`,
|
|
329
|
-
` --identity '${exported}' \\`,
|
|
330
|
-
` --stealth <your-stealth-address>`
|
|
331
|
-
].join("\n"), "Purchase complete ✓");
|
|
300
|
+
const repo = LocalRepo.open();
|
|
301
|
+
const target = commitArg ?? repo.head();
|
|
302
|
+
if (!target) throw new Error("no commit to show — no commits yet");
|
|
303
|
+
const diff = await getFangorn().show(target);
|
|
304
|
+
console.log(`commit ${target}`);
|
|
305
|
+
console.log(`Date: ${new Date(diff.timestamp).toISOString()}`);
|
|
306
|
+
console.log(`Parents: ${diff.parents.length ? diff.parents.join(", ") : "(root)"}`);
|
|
307
|
+
console.log(`Tree: ${diff.pailRoot}`);
|
|
308
|
+
console.log(`\n ${diff.message}\n`);
|
|
309
|
+
console.log(`Changes vs. parent: +${diff.added.length.toString()} / -${diff.removed.length.toString()} key(s)`);
|
|
310
|
+
for (const k of diff.added) console.log(` + ${k}`);
|
|
311
|
+
for (const k of diff.removed) console.log(` - ${k}`);
|
|
332
312
|
process.exit(0);
|
|
333
313
|
} catch (err) {
|
|
334
314
|
console.error("Failed:", err.message);
|
|
335
315
|
process.exit(1);
|
|
336
316
|
}
|
|
337
317
|
});
|
|
338
|
-
|
|
318
|
+
program.command("clone").description("Track an existing on-chain namespace by reconstructing its tip locally").argument("<owner>", "Owner (publisher) address").argument("<namespace>", "Namespace name").option("--dir <path>", "Directory to create the repo in (default: current dir)").action(async (owner, namespace, options) => {
|
|
339
319
|
try {
|
|
340
320
|
const fangorn = getFangorn();
|
|
341
|
-
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
342
|
-
const relayerKey = loadConfig().privateKey;
|
|
343
|
-
const identity = new Identity(options.identity);
|
|
344
321
|
const s = spinner();
|
|
345
|
-
s.start(
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
stealthAddress: options.stealth
|
|
350
|
-
});
|
|
351
|
-
s.stop();
|
|
352
|
-
s.start("Submitting settlement...");
|
|
353
|
-
const { txHash, nullifier } = await fangorn.consumer.claim({
|
|
322
|
+
s.start(`Resolving on-chain tip for ${owner}...`);
|
|
323
|
+
const tip = await fangorn.onChainTip(owner);
|
|
324
|
+
const repo = LocalRepo.init({
|
|
325
|
+
namespace,
|
|
354
326
|
owner,
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
relayerPrivateKey: relayerKey,
|
|
358
|
-
preparedSettle
|
|
359
|
-
});
|
|
327
|
+
head: tip
|
|
328
|
+
}, options.dir ?? process.cwd());
|
|
360
329
|
s.stop();
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
``,
|
|
365
|
-
`Next:`,
|
|
366
|
-
` fangorn consume fetch ${owner} ${name} \\`,
|
|
367
|
-
` -s ${options.schema} \\`,
|
|
368
|
-
` -f <field> \\`,
|
|
369
|
-
` --nullifier ${nullifier.toString()} \\`,
|
|
370
|
-
` --stealth-key <stealth-private-key> \\`,
|
|
371
|
-
` -o out.mp3`
|
|
372
|
-
].join("\n"), "Claim complete ✓");
|
|
330
|
+
console.log(`Namespace: ${namespace}`);
|
|
331
|
+
console.log(`Owner: ${owner}`);
|
|
332
|
+
console.log(`HEAD: ${repo.head() ?? "(none — publisher has no commits yet)"}`);
|
|
373
333
|
process.exit(0);
|
|
374
334
|
} catch (err) {
|
|
375
335
|
console.error("Failed:", err.message);
|
|
376
336
|
process.exit(1);
|
|
377
337
|
}
|
|
378
338
|
});
|
|
379
|
-
|
|
339
|
+
program.command("subscribe").description("Watch on-chain pushes to a namespace and stream JSON diffs (light client — no indexer)").argument("[namespace]", "Namespace name (default: current repo)").option("--owner <address>", "Owner (publisher) address (default: current repo owner, else self)").option("--from-block <n>", "Replay from this block (overrides the saved cursor)", (v) => BigInt(v)).option("--from-start", "Replay this namespace's full history (ignore the saved cursor)").option("--pretty", "Pretty-print each change").action(async (namespaceArg, options) => {
|
|
380
340
|
try {
|
|
381
|
-
const cfg = loadConfig();
|
|
382
|
-
const chain = getChain(cfg.cfg.chainName);
|
|
383
341
|
const fangorn = getFangorn();
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
342
|
+
let namespace = namespaceArg;
|
|
343
|
+
let owner = options.owner;
|
|
344
|
+
if (!namespace || !owner) try {
|
|
345
|
+
const repo = LocalRepo.open();
|
|
346
|
+
namespace = namespace ?? repo.namespace();
|
|
347
|
+
owner = owner ?? repo.owner();
|
|
348
|
+
} catch {}
|
|
349
|
+
if (!namespace) throw new Error("namespace required (pass it as an argument or run inside a repo)");
|
|
350
|
+
owner = owner ?? fangorn.getAddress();
|
|
351
|
+
const repoDir = join(process.cwd(), ".fangorn");
|
|
352
|
+
const cursorPath = join(repoDir, `subscribe-${owner}-${namespace}.json`);
|
|
353
|
+
const readCursor = () => {
|
|
354
|
+
if (options.fromStart) return void 0;
|
|
355
|
+
if (options.fromBlock !== void 0) return options.fromBlock;
|
|
356
|
+
if (existsSync(cursorPath)) return BigInt(JSON.parse(readFileSync(cursorPath, "utf-8")).lastBlock) + 1n;
|
|
357
|
+
};
|
|
358
|
+
const writeCursor = (block) => {
|
|
359
|
+
if (!existsSync(repoDir)) mkdirSync(repoDir, { recursive: true });
|
|
360
|
+
writeFileSync(cursorPath, JSON.stringify({
|
|
361
|
+
owner,
|
|
362
|
+
namespace,
|
|
363
|
+
lastBlock: block.toString()
|
|
364
|
+
}, null, 2), "utf-8");
|
|
365
|
+
};
|
|
366
|
+
const bigintReplacer = (_k, v) => typeof v === "bigint" ? v.toString() : v;
|
|
367
|
+
const fromBlock = readCursor();
|
|
368
|
+
console.error(`Subscribing to "${namespace}" @ ${owner} ` + (fromBlock !== void 0 ? `from block ${fromBlock}` : "(live from current tip)") + ` — Ctrl-C to stop.`);
|
|
369
|
+
const controller = new AbortController();
|
|
370
|
+
process.on("SIGINT", () => controller.abort());
|
|
371
|
+
process.on("SIGTERM", () => controller.abort());
|
|
372
|
+
for await (const change of fangorn.subscribe({
|
|
373
|
+
namespace,
|
|
374
|
+
owner,
|
|
375
|
+
fromBlock,
|
|
376
|
+
signal: controller.signal
|
|
377
|
+
})) {
|
|
378
|
+
process.stdout.write(JSON.stringify(change, bigintReplacer, options.pretty ? 2 : 0) + "\n");
|
|
379
|
+
writeCursor(change.blockNumber);
|
|
400
380
|
}
|
|
401
381
|
process.exit(0);
|
|
402
382
|
} catch (err) {
|
|
@@ -404,23 +384,42 @@ consumeCmd.command("fetch").description("Fetch a field after purchase and claim"
|
|
|
404
384
|
process.exit(1);
|
|
405
385
|
}
|
|
406
386
|
});
|
|
407
|
-
program.command("
|
|
387
|
+
program.command("read").description("List every vertex and edge committed under a namespace, as JSON").argument("[namespace]", "Namespace name (default: current repo)").option("--owner <address>", "Owner (publisher) address (default: current repo owner)").option("--pretty", "Pretty-print the JSON output").action(async (namespaceArg, options) => {
|
|
408
388
|
try {
|
|
409
|
-
const self = getAccount().address;
|
|
410
|
-
const owner = options.owner ?? self;
|
|
411
389
|
const fangorn = getFangorn();
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
390
|
+
let namespace = namespaceArg;
|
|
391
|
+
let owner = options.owner;
|
|
392
|
+
if (!namespace || !owner) {
|
|
393
|
+
const repo = LocalRepo.open();
|
|
394
|
+
namespace = namespace ?? repo.namespace();
|
|
395
|
+
owner = owner ?? repo.owner();
|
|
396
|
+
}
|
|
397
|
+
const [head, contents] = await Promise.all([fangorn.onChainTip(owner), fangorn.engine.listNamespace(namespace, owner)]);
|
|
398
|
+
const out = {
|
|
399
|
+
owner,
|
|
400
|
+
namespace,
|
|
401
|
+
head,
|
|
402
|
+
vertices: contents.vertices,
|
|
403
|
+
edges: contents.edges
|
|
404
|
+
};
|
|
405
|
+
process.stdout.write(JSON.stringify(out, null, options.pretty ? 2 : 0) + "\n");
|
|
418
406
|
process.exit(0);
|
|
419
407
|
} catch (err) {
|
|
420
408
|
console.error("Failed:", err.message);
|
|
421
409
|
process.exit(1);
|
|
422
410
|
}
|
|
423
411
|
});
|
|
412
|
+
program.command("reset").description("DANGER!: reset your on-chain head to zero (abandons all prior commits)").action(async () => {
|
|
413
|
+
const confirmFirst = await confirm({ message: "Are you sure? Your onchain head will reset to 0x0000..." });
|
|
414
|
+
handleCancel(confirmFirst);
|
|
415
|
+
if (!confirmFirst) {
|
|
416
|
+
console.log("Reset aborted.");
|
|
417
|
+
process.exit(0);
|
|
418
|
+
}
|
|
419
|
+
await getFangorn().reset();
|
|
420
|
+
console.log("On-chain head reset to zero. `repo init` will now start fresh.");
|
|
421
|
+
process.exit(0);
|
|
422
|
+
});
|
|
424
423
|
program.parse();
|
|
425
424
|
|
|
426
425
|
//#endregion
|