@fangorn-network/sdk 0.1.0-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/LICENSE.md +20 -0
- package/README.md +80 -0
- package/lib/cli/cli.d.ts +2 -0
- package/lib/cli/cli.js +571 -0
- package/lib/cli/index.d.ts +10 -0
- package/lib/cli/index.js +18 -0
- package/lib/cli/sell.d.ts +28 -0
- package/lib/cli/sell.js +95 -0
- package/lib/cli/stage.d.ts +19 -0
- package/lib/cli/stage.js +94 -0
- package/lib/config.d.ts +697 -0
- package/lib/config.js +45 -0
- package/lib/contracts/data-registry/abi.d.ts +442 -0
- package/lib/contracts/data-registry/abi.js +508 -0
- package/lib/contracts/data-registry/index.d.ts +131 -0
- package/lib/contracts/data-registry/index.js +183 -0
- package/lib/contracts/index.d.ts +6 -0
- package/lib/contracts/index.js +6 -0
- package/lib/contracts/logs.d.ts +17 -0
- package/lib/contracts/logs.js +28 -0
- package/lib/contracts/settlement-registry/abi.d.ts +810 -0
- package/lib/contracts/settlement-registry/abi.js +962 -0
- package/lib/contracts/settlement-registry/index.d.ts +143 -0
- package/lib/contracts/settlement-registry/index.js +213 -0
- package/lib/contracts/write.d.ts +59 -0
- package/lib/contracts/write.js +102 -0
- package/lib/crypto/aes.d.ts +19 -0
- package/lib/crypto/aes.js +26 -0
- package/lib/crypto/encryption.d.ts +38 -0
- package/lib/crypto/encryption.js +68 -0
- package/lib/crypto/paid.d.ts +104 -0
- package/lib/crypto/paid.js +147 -0
- package/lib/crypto/rand.d.ts +5 -0
- package/lib/crypto/rand.js +16 -0
- package/lib/crypto/types.d.ts +23 -0
- package/lib/crypto/types.js +1 -0
- package/lib/engine/car.d.ts +14 -0
- package/lib/engine/car.js +42 -0
- package/lib/engine/index.d.ts +206 -0
- package/lib/engine/index.js +377 -0
- package/lib/engine/records.d.ts +121 -0
- package/lib/engine/records.js +239 -0
- package/lib/engine/test-helpers.d.ts +38 -0
- package/lib/engine/test-helpers.js +63 -0
- package/lib/erc8004.d.ts +56 -0
- package/lib/erc8004.js +140 -0
- package/lib/fangorn.d.ts +342 -0
- package/lib/fangorn.js +642 -0
- package/lib/feed.d.ts +34 -0
- package/lib/feed.js +67 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +16 -0
- 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/car.d.ts +36 -0
- package/lib/providers/storage/car.js +81 -0
- package/lib/providers/storage/index.d.ts +5 -0
- package/lib/providers/storage/index.js +5 -0
- package/lib/providers/storage/pinata.d.ts +53 -0
- package/lib/providers/storage/pinata.js +178 -0
- package/lib/providers/storage/signed-url.d.ts +54 -0
- package/lib/providers/storage/signed-url.js +122 -0
- package/lib/providers/storage/types.d.ts +62 -0
- package/lib/providers/storage/types.js +1 -0
- package/lib/providers/storage/utils.d.ts +30 -0
- package/lib/providers/storage/utils.js +107 -0
- package/lib/repo/index.d.ts +56 -0
- package/lib/repo/index.js +73 -0
- package/lib/test/key-server.d.ts +12 -0
- package/lib/test/key-server.js +30 -0
- package/lib/test/mem-registry.d.ts +46 -0
- package/lib/test/mem-registry.js +114 -0
- package/lib/test/sdk-suite.d.ts +10 -0
- package/lib/test/sdk-suite.js +155 -0
- package/lib/test/testbed.d.ts +16786 -0
- package/lib/test/testbed.js +175 -0
- package/lib/types/index.d.ts +37 -0
- package/lib/types/index.js +1 -0
- package/package.json +87 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Fangorn SDK
|
|
2
|
+
|
|
3
|
+
Fangorn is git for published data. You publish **repos** of records, and you can make any field paid. Each repo's head is anchored on chain and its history lives in IPFS. Anyone can read, verify, diff, subscribe to, or buy from your repos without asking you, an indexer, or a platform.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm i @fangorn-network/sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## The model
|
|
10
|
+
|
|
11
|
+
- **Publisher.** A wallet address. Publishers own their repos, and nobody admits or approves them.
|
|
12
|
+
- **Repo.** Keyed `publisher : repo`. Its state is a map of **records** `{ id, type, payload }`, stored as a content-addressed Merkle search tree.
|
|
13
|
+
- **Commit.** Each commit points at its parent and at one CAR file holding the blocks it introduced. History can be walked and diffed from the head alone.
|
|
14
|
+
- **Push.** Moves the on-chain head with a compare-and-swap on the parent, like a git ref update. The registry stores only heads.
|
|
15
|
+
- **Paid fields.** A publisher seals a field and signs a price for it in the record. Buyers pay through the SettlementRegistry, and a key server releases the key.
|
|
16
|
+
- **Apps are just repos.** An app is a publisher's repo of records that **cite** other publishers' records at named heads. It selects and arranges data, but it never holds or gates that data. When a citation leads to a sale, the app's publisher address receives the referral share.
|
|
17
|
+
|
|
18
|
+
What Fangorn is not: it is not a database. It has no query language and no indexer. You build those on top with `subscribe` (see [westmarch](https://github.com/fangorn-network/westmarch)).
|
|
19
|
+
|
|
20
|
+
## Quickstart (SDK)
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { Fangorn } from "@fangorn-network/sdk";
|
|
24
|
+
|
|
25
|
+
const fangorn = Fangorn.create({
|
|
26
|
+
privateKey: "0x...",
|
|
27
|
+
storage: { signedUrl: {} }, // hosted uploads on Base Sepolia; or { pinata: { jwt, gateway } }
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
await fangorn.initRepo("rusty-anchor");
|
|
31
|
+
await fangorn.uploadBatch("rusty-anchor", [
|
|
32
|
+
{ id: "t1", type: "track", payload: { title: "Locura", artist: "Alice" } },
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
// Anyone, from the head alone:
|
|
36
|
+
const { contents } = await fangorn.readRepo(
|
|
37
|
+
fangorn.getAddress(),
|
|
38
|
+
"rusty-anchor",
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
for await (const change of fangorn.subscribe({
|
|
42
|
+
repo: "rusty-anchor",
|
|
43
|
+
owner: fangorn.getAddress(),
|
|
44
|
+
})) {
|
|
45
|
+
console.log(change.puts, change.deletes);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quickstart (CLI)
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
npm i -g @fangorn-network/sdk
|
|
53
|
+
fangorn init # wallet key, storage → ~/.fangorn/config.json
|
|
54
|
+
fangorn repo init rusty-anchor # create on chain, track in ./.fangorn
|
|
55
|
+
fangorn add . # stage files: csv/json rows → records, text files → one record each
|
|
56
|
+
fangorn commit # local commit (IPFS only)
|
|
57
|
+
fangorn push # move the on-chain head
|
|
58
|
+
fangorn subscribe --owner 0x... rusty-anchor # stream diffs as JSON lines
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The [Guide](docs/GUIDE.md) covers the full flow: commit vs push, epochs, history, subscribing, agent cards, storage, and sealed and paid fields.
|
|
62
|
+
|
|
63
|
+
## Network
|
|
64
|
+
|
|
65
|
+
Fangorn runs on **Base Sepolia**. The DataRegistry, SettlementRegistry, and hosted upload worker are all deployed there. Addresses are in [`src/config.ts`](src/config.ts) (`BaseSepoliaConfig`). To use a local anvil or a private deployment, pass your own `NetworkConfig` to `Fangorn.create`, or set the `FANGORN_*` overrides for the CLI (see the [Guide](docs/GUIDE.md#configure)). Contract sources are in [fangorn-network/contracts](https://github.com/fangorn-network/contracts).
|
|
66
|
+
|
|
67
|
+
## Development
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
pnpm i
|
|
71
|
+
pnpm test # unit tests + the SDK suite in memory
|
|
72
|
+
pnpm test:e2e # the same suite against the contracts on a fresh anvil
|
|
73
|
+
pnpm abis # regenerate ABIs from the contracts repo
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The e2e tests need `anvil`, `forge`, and a sibling checkout of `fangorn-network/contracts` (set `FANGORN_CONTRACTS_DIR` to use another location). Without them, the tests are skipped locally and fail in CI. `E2E_STORAGE=pinata` runs the tests against Pinata (`PINATA_JWT`, `PINATA_GATEWAY`). `pnpm test:live` runs read-only checks against Base Sepolia.
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
package/lib/cli/cli.d.ts
ADDED
package/lib/cli/cli.js
ADDED
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import getNetwork, { nonBlank } from "../config.js";
|
|
3
|
+
import { agentCardUrl, parseAgentId } from "../erc8004.js";
|
|
4
|
+
import { Fangorn } from "../fangorn.js";
|
|
5
|
+
import { sealRecords } from "./sell.js";
|
|
6
|
+
import { fileToRecords, walk } from "./stage.js";
|
|
7
|
+
import { handleCancel } from "./index.js";
|
|
8
|
+
import { createPublicClient, formatEther, http, isAddress, parseUnits } from "viem";
|
|
9
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
10
|
+
import { Command } from "commander";
|
|
11
|
+
import { confirm, intro, outro, spinner, text } from "@clack/prompts";
|
|
12
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
13
|
+
import { dirname, join } from "path";
|
|
14
|
+
import { homedir } from "os";
|
|
15
|
+
import "dotenv/config";
|
|
16
|
+
|
|
17
|
+
//#region src/cli/cli.ts
|
|
18
|
+
const CONFIG_DIR = join(homedir(), ".fangorn");
|
|
19
|
+
const CONFIG_PATH = join(CONFIG_DIR, "config.json");
|
|
20
|
+
let _config = null;
|
|
21
|
+
let _account = null;
|
|
22
|
+
let _fangorn = null;
|
|
23
|
+
function readStoredConfig() {
|
|
24
|
+
return JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
|
|
25
|
+
}
|
|
26
|
+
function writeStoredConfig(stored) {
|
|
27
|
+
if (!existsSync(CONFIG_DIR)) mkdirSync(CONFIG_DIR, { recursive: true });
|
|
28
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(stored, null, 2), "utf-8");
|
|
29
|
+
chmodSync(CONFIG_PATH, 384);
|
|
30
|
+
}
|
|
31
|
+
function loadConfig() {
|
|
32
|
+
if (_config) return _config;
|
|
33
|
+
const privateKey = process.env.ETH_PRIVATE_KEY;
|
|
34
|
+
const pinataJwt = process.env.PINATA_JWT;
|
|
35
|
+
const pinataGateway = process.env.PINATA_GATEWAY;
|
|
36
|
+
const signedUrlWorkerUrl = process.env.SIGNED_URL_WORKER_URL;
|
|
37
|
+
const envChain = nonBlank(process.env.CHAIN_NAME);
|
|
38
|
+
if (existsSync(CONFIG_PATH)) {
|
|
39
|
+
const stored = readStoredConfig();
|
|
40
|
+
_config = {
|
|
41
|
+
privateKey: stored.privateKey,
|
|
42
|
+
cfg: network(envChain ?? stored.chainName),
|
|
43
|
+
pinataJwt: stored.pinataJwt,
|
|
44
|
+
pinataGateway: stored.pinataGateway,
|
|
45
|
+
signedUrlWorkerUrl: stored.signedUrlWorkerUrl ?? ""
|
|
46
|
+
};
|
|
47
|
+
return _config;
|
|
48
|
+
}
|
|
49
|
+
if (privateKey || pinataJwt || pinataGateway || signedUrlWorkerUrl) {
|
|
50
|
+
if (!privateKey) throw new Error("Incomplete environment configuration. Missing: ETH_PRIVATE_KEY\nSet it or run `fangorn init` to use a config file.");
|
|
51
|
+
_config = {
|
|
52
|
+
privateKey,
|
|
53
|
+
cfg: network(envChain ?? "baseSepolia"),
|
|
54
|
+
pinataJwt: pinataJwt ?? "",
|
|
55
|
+
pinataGateway: pinataGateway ?? "",
|
|
56
|
+
signedUrlWorkerUrl: signedUrlWorkerUrl ?? ""
|
|
57
|
+
};
|
|
58
|
+
return _config;
|
|
59
|
+
}
|
|
60
|
+
throw new Error("No configuration found. Run `fangorn init` or set ETH_PRIVATE_KEY\n(with no config, uploads go to Fangorn's shared Pinata account; files may be unpinned without notice. Set PINATA_JWT + PINATA_GATEWAY to use your own storage).");
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The named network, with its RPC and contracts overridable from the environment:
|
|
64
|
+
* FANGORN_RPC_URL, FANGORN_DATA_REGISTRY and FANGORN_SETTLEMENT_REGISTRY, for a local
|
|
65
|
+
* chain (an anvil with the contracts deployed) or a private RPC. Blank counts as unset.
|
|
66
|
+
*/
|
|
67
|
+
function network(name) {
|
|
68
|
+
const cfg = getNetwork(name);
|
|
69
|
+
const address = (variable) => {
|
|
70
|
+
const value = nonBlank(process.env[variable]);
|
|
71
|
+
if (value !== void 0 && !isAddress(value)) throw new Error(`${variable} is not an address: "${value}"`);
|
|
72
|
+
return value;
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
...cfg,
|
|
76
|
+
rpcUrl: nonBlank(process.env.FANGORN_RPC_URL) ?? cfg.rpcUrl,
|
|
77
|
+
dataRegistryContractAddress: address("FANGORN_DATA_REGISTRY") ?? cfg.dataRegistryContractAddress,
|
|
78
|
+
settlementRegistryContractAddress: address("FANGORN_SETTLEMENT_REGISTRY") ?? cfg.settlementRegistryContractAddress
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function getAccount() {
|
|
82
|
+
if (_account) return _account;
|
|
83
|
+
_account = privateKeyToAccount(loadConfig().privateKey);
|
|
84
|
+
return _account;
|
|
85
|
+
}
|
|
86
|
+
function getFangorn() {
|
|
87
|
+
if (_fangorn) return _fangorn;
|
|
88
|
+
const cfg = loadConfig();
|
|
89
|
+
const storage = cfg.pinataJwt ? { pinata: {
|
|
90
|
+
jwt: cfg.pinataJwt,
|
|
91
|
+
gateway: cfg.pinataGateway
|
|
92
|
+
} } : { signedUrl: {
|
|
93
|
+
workerUrl: cfg.signedUrlWorkerUrl,
|
|
94
|
+
gateway: cfg.pinataGateway
|
|
95
|
+
} };
|
|
96
|
+
_fangorn = Fangorn.create({
|
|
97
|
+
privateKey: cfg.privateKey,
|
|
98
|
+
storage,
|
|
99
|
+
config: cfg.cfg
|
|
100
|
+
});
|
|
101
|
+
return _fangorn;
|
|
102
|
+
}
|
|
103
|
+
var LocalRepo = class LocalRepo {
|
|
104
|
+
constructor(dir, state) {
|
|
105
|
+
this.dir = dir;
|
|
106
|
+
this.state = state;
|
|
107
|
+
}
|
|
108
|
+
static path(dir) {
|
|
109
|
+
return join(dir, ".fangorn", "repo.json");
|
|
110
|
+
}
|
|
111
|
+
/** Create (or overwrite) a repo pointer in `dir`. */
|
|
112
|
+
static init(state, dir = process.cwd()) {
|
|
113
|
+
const repoDir = join(dir, ".fangorn");
|
|
114
|
+
if (!existsSync(repoDir)) mkdirSync(repoDir, { recursive: true });
|
|
115
|
+
const repo = new LocalRepo(dir, state);
|
|
116
|
+
repo.save();
|
|
117
|
+
return repo;
|
|
118
|
+
}
|
|
119
|
+
/** Open the repo containing `dir` (searches upward like git). Throws if none. */
|
|
120
|
+
static open(dir = process.cwd()) {
|
|
121
|
+
let cur = dir;
|
|
122
|
+
let parent = "";
|
|
123
|
+
while (cur !== parent) {
|
|
124
|
+
const p = LocalRepo.path(cur);
|
|
125
|
+
if (existsSync(p)) return new LocalRepo(cur, JSON.parse(readFileSync(p, "utf-8")));
|
|
126
|
+
parent = cur;
|
|
127
|
+
cur = dirname(cur);
|
|
128
|
+
}
|
|
129
|
+
throw new Error("not a fangorn repo (no .fangorn/repo.json here or above). Run `fangorn repo init <namespace>` or `fangorn clone`.");
|
|
130
|
+
}
|
|
131
|
+
save() {
|
|
132
|
+
writeFileSync(LocalRepo.path(this.dir), JSON.stringify(this.state, null, 2), "utf-8");
|
|
133
|
+
}
|
|
134
|
+
namespace() {
|
|
135
|
+
return this.state.namespace;
|
|
136
|
+
}
|
|
137
|
+
owner() {
|
|
138
|
+
return this.state.owner;
|
|
139
|
+
}
|
|
140
|
+
head() {
|
|
141
|
+
return this.state.head;
|
|
142
|
+
}
|
|
143
|
+
setHead(cid) {
|
|
144
|
+
this.state.head = cid;
|
|
145
|
+
this.save();
|
|
146
|
+
}
|
|
147
|
+
root() {
|
|
148
|
+
return this.dir;
|
|
149
|
+
}
|
|
150
|
+
/** The staging area: what the next `fangorn commit` (no file) will commit. */
|
|
151
|
+
staged() {
|
|
152
|
+
const p = join(this.dir, ".fangorn", "index.json");
|
|
153
|
+
return existsSync(p) ? JSON.parse(readFileSync(p, "utf-8")) : {
|
|
154
|
+
records: [],
|
|
155
|
+
deletes: []
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
setStaged(s) {
|
|
159
|
+
writeFileSync(join(this.dir, ".fangorn", "index.json"), JSON.stringify(s, null, 2), "utf-8");
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const program = new Command();
|
|
163
|
+
program.name("fangorn").description("Fangorn Network CLI").version("0.4.0");
|
|
164
|
+
program.command("init").description("Configure your Fangorn credentials").action(async () => {
|
|
165
|
+
intro("Fangorn Setup");
|
|
166
|
+
const chainName = "baseSepolia";
|
|
167
|
+
const privateKey = await text({
|
|
168
|
+
message: "Wallet private key (stored locally, never transmitted):",
|
|
169
|
+
placeholder: "0x...",
|
|
170
|
+
validate: (v) => {
|
|
171
|
+
if (!v) return "Required";
|
|
172
|
+
if (!v.startsWith("0x") || v.length !== 66) return "Must be a valid 0x-prefixed 32-byte hex key";
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
handleCancel(privateKey);
|
|
176
|
+
const pinataJwt = await text({ message: "Pinata JWT — leave blank to use Fangorn's shared Pinata account (testnet convenience; files may be unpinned without notice):" });
|
|
177
|
+
handleCancel(pinataJwt);
|
|
178
|
+
const pinataGateway = await text({
|
|
179
|
+
message: "Pinata Gateway URL (optional; blank uses the network's gateway):",
|
|
180
|
+
placeholder: "https://your-gateway.mypinata.cloud"
|
|
181
|
+
});
|
|
182
|
+
handleCancel(pinataGateway);
|
|
183
|
+
const signedUrlWorkerUrl = await text({
|
|
184
|
+
message: "Presigned-URL worker URL (optional; blank uses the hosted default):",
|
|
185
|
+
placeholder: "https://pinata-url-provider.your-subdomain.workers.dev"
|
|
186
|
+
});
|
|
187
|
+
handleCancel(signedUrlWorkerUrl);
|
|
188
|
+
writeStoredConfig({
|
|
189
|
+
privateKey,
|
|
190
|
+
chainName,
|
|
191
|
+
pinataJwt,
|
|
192
|
+
pinataGateway,
|
|
193
|
+
signedUrlWorkerUrl
|
|
194
|
+
});
|
|
195
|
+
outro(`Config saved to ${CONFIG_PATH}`);
|
|
196
|
+
});
|
|
197
|
+
program.command("card").description("Point a repo at its agent card, and register the card as an ERC-8004 agent").argument("[cardUrl]", "The agent card URL; or pass --access-worker to use its /.well-known/agent-card.json").option("--repo <name>", "The repo the card speaks for (default: the repo tracked here)").option("--access-worker <url>", "The access worker serving the agent card").option("--mcp <url>", "An MCP endpoint to index alongside the card").option("--skip-register", "Only commit the @card record, for a card already registered with ERC-8004").option("--update <agentId>", "Update an agent already registered (e.g. 84532:10323) from the card as it is now: a new registration file, pointed to by setAgentURI; mints nothing").action(async (cardUrl, opts) => {
|
|
198
|
+
try {
|
|
199
|
+
const cfg = loadConfig();
|
|
200
|
+
const url = agentCardUrl(cardUrl, opts.accessWorker);
|
|
201
|
+
const local = opts.repo ? void 0 : LocalRepo.open();
|
|
202
|
+
const repo = opts.repo ?? local?.namespace() ?? "";
|
|
203
|
+
const s = spinner();
|
|
204
|
+
const chainId = cfg.cfg.caip2;
|
|
205
|
+
const update = opts.update ? parseAgentId(opts.update, chainId) : void 0;
|
|
206
|
+
s.start(opts.skipRegister ? `Pointing ${repo} at its card` : update !== void 0 ? `Updating ERC-8004 agent ${opts.update ?? ""}` : "Registering with the ERC-8004 identity registry");
|
|
207
|
+
const fangorn = getFangorn();
|
|
208
|
+
let result;
|
|
209
|
+
try {
|
|
210
|
+
result = await fangorn.registerAgent(url, {
|
|
211
|
+
repo,
|
|
212
|
+
mcp: opts.mcp,
|
|
213
|
+
update,
|
|
214
|
+
skipRegister: opts.skipRegister
|
|
215
|
+
});
|
|
216
|
+
} catch (e) {
|
|
217
|
+
s.stop();
|
|
218
|
+
const minted = e.agentId;
|
|
219
|
+
throw minted !== void 0 ? /* @__PURE__ */ new Error(`${e.message.replace(/; finish it with .*/, "")}. Finish it with: fangorn card ${url} --repo ${repo} --update ${String(chainId)}:${String(minted)}`) : e;
|
|
220
|
+
}
|
|
221
|
+
s.stop();
|
|
222
|
+
if (local && result.txHash) local.setHead(await fangorn.onChainTip(fangorn.getAddress(), repo));
|
|
223
|
+
const agentId = result.agentId !== void 0 ? `${String(chainId)}:${String(result.agentId)}` : void 0;
|
|
224
|
+
if (agentId) console.log(`Agent ID: ${agentId}`);
|
|
225
|
+
console.log(`Repo: ${repo}`);
|
|
226
|
+
console.log(`Card: ${url}`);
|
|
227
|
+
console.log(`Tx: ${result.txHash ?? "(already bound)"}`);
|
|
228
|
+
process.exit(0);
|
|
229
|
+
} catch (err) {
|
|
230
|
+
console.error("Failed:", err.message);
|
|
231
|
+
process.exit(1);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
program.command("wallet").description("Show the wallet this CLI signs with").argument("[action]", "show", "show").option("--reveal", "Also print the PRIVATE key — it grants full control of this wallet").action(async (_action, opts) => {
|
|
235
|
+
try {
|
|
236
|
+
const cfg = loadConfig();
|
|
237
|
+
const account = getAccount();
|
|
238
|
+
const s = spinner();
|
|
239
|
+
s.start("Reading balance...");
|
|
240
|
+
const balance = await createPublicClient({ transport: http(cfg.cfg.rpcUrl) }).getBalance({ address: account.address });
|
|
241
|
+
s.stop();
|
|
242
|
+
console.log(`Address: ${account.address}`);
|
|
243
|
+
console.log(`Public key: ${account.publicKey}`);
|
|
244
|
+
console.log(`Balance: ${formatEther(balance)} ETH`);
|
|
245
|
+
console.log(`Network: ${cfg.cfg.chain.name} (${cfg.cfg.caip2.toString()})`);
|
|
246
|
+
console.log(`Config: ${existsSync(CONFIG_PATH) ? CONFIG_PATH : "(from environment)"}`);
|
|
247
|
+
if (opts.reveal) {
|
|
248
|
+
console.log(`\nPrivate key: ${cfg.privateKey}`);
|
|
249
|
+
console.log(`Anyone with that key controls this wallet. Do not share it.`);
|
|
250
|
+
} else console.log(`\nPrivate key: hidden — pass --reveal to print it`);
|
|
251
|
+
process.exit(0);
|
|
252
|
+
} catch (err) {
|
|
253
|
+
console.error("Failed:", err.message);
|
|
254
|
+
process.exit(1);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
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) => {
|
|
258
|
+
try {
|
|
259
|
+
const fangorn = getFangorn();
|
|
260
|
+
const owner = fangorn.getAddress();
|
|
261
|
+
const s = spinner();
|
|
262
|
+
s.start(`Initializing namespace "${namespace}"...`);
|
|
263
|
+
const result = await fangorn.initRepo(namespace);
|
|
264
|
+
const head = result.alreadyInitialized ? await fangorn.onChainTip(owner, namespace) : result.commitCid;
|
|
265
|
+
const repo = LocalRepo.init({
|
|
266
|
+
namespace,
|
|
267
|
+
owner,
|
|
268
|
+
head
|
|
269
|
+
});
|
|
270
|
+
s.stop();
|
|
271
|
+
if (result.alreadyInitialized) console.log(`Namespace "${namespace}" already exists for ${owner}. Tracking it here.`);
|
|
272
|
+
else {
|
|
273
|
+
console.log(`Namespace: ${namespace}`);
|
|
274
|
+
console.log(`Owner: ${owner}`);
|
|
275
|
+
console.log(`Tx: ${result.txHash}`);
|
|
276
|
+
}
|
|
277
|
+
console.log(`HEAD: ${repo.head() ?? "(none)"}`);
|
|
278
|
+
process.exit(0);
|
|
279
|
+
} catch (err) {
|
|
280
|
+
console.error("Failed:", err.message);
|
|
281
|
+
process.exit(1);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
program.command("add").description("Stage files as records: csv/jsonl/json arrays → a record per row, other text → one record per file").argument("<paths...>", "Files or directories (dot entries skipped)").option("--type <type>", "Record type (default: file name, or \"file\" for text)").option("--id-column <col>", "Column/field holding the record id", "id").action((paths, options) => {
|
|
285
|
+
try {
|
|
286
|
+
const repo = LocalRepo.open();
|
|
287
|
+
const staged = repo.staged();
|
|
288
|
+
let n = 0;
|
|
289
|
+
for (const p of paths) for (const rel of walk(repo.root(), join(process.cwd(), p))) {
|
|
290
|
+
const got = fileToRecords(repo.root(), rel, options);
|
|
291
|
+
if (!got) {
|
|
292
|
+
console.warn(`skipped (binary): ${rel}`);
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
const ids = new Set(got.records.map((r) => r.id));
|
|
296
|
+
staged.records = staged.records.filter((r) => !r.id || !ids.has(r.id)).concat(got.records);
|
|
297
|
+
staged.deletes = staged.deletes.filter((d) => !ids.has(d)).concat(got.deletes);
|
|
298
|
+
n += got.records.length + got.deletes.length;
|
|
299
|
+
console.log(`added ${rel} (${got.records.length.toString()} record(s))`);
|
|
300
|
+
}
|
|
301
|
+
repo.setStaged(staged);
|
|
302
|
+
console.log(`${n.toString()} change(s) staged. Run \`fangorn commit\`.`);
|
|
303
|
+
process.exit(0);
|
|
304
|
+
} catch (err) {
|
|
305
|
+
console.error("Failed:", err.message);
|
|
306
|
+
process.exit(1);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
program.command("rm").description("Stage record deletes (and drop them from the staging area)").argument("<ids...>", "Record ids").action((ids) => {
|
|
310
|
+
try {
|
|
311
|
+
const repo = LocalRepo.open();
|
|
312
|
+
const staged = repo.staged();
|
|
313
|
+
staged.records = staged.records.filter((r) => !r.id || !ids.includes(r.id));
|
|
314
|
+
staged.deletes = [...new Set([...staged.deletes, ...ids])];
|
|
315
|
+
repo.setStaged(staged);
|
|
316
|
+
console.log(`${ids.length.toString()} delete(s) staged.`);
|
|
317
|
+
process.exit(0);
|
|
318
|
+
} catch (err) {
|
|
319
|
+
console.error("Failed:", err.message);
|
|
320
|
+
process.exit(1);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
program.command("commit").description("Put/delete a namespace's records in a new local commit (does not push)").argument("[file]", "JSON file: {\"records\":[{\"id\",\"type\",\"payload\"}],\"deletes\":[\"id\"]} (default: the staging area, see `fangorn add`)").option("--replace", "Snapshot semantics: the file replaces the namespace's previous contents (omitted entries are removed)").option("--paid <fields>", "Comma-separated payload fields to sell: sealed (field-v1) and priced with signed terms").option("--price <usdc>", "Price of each paid record, in USDC (e.g. 0.01)").option("--share <percent>", "Share of each sale paid to the referrer (Fangorn takes none by default)", "0").option("--deadline-days <days>", "Days the signed terms stay buyable", "365").option("--key-server <url>", "Key server a new deposit is sealed to (an existing deposit keeps its own)", "https://keys-test.fangorn.network").action(async (file, options) => {
|
|
324
|
+
try {
|
|
325
|
+
const repo = LocalRepo.open();
|
|
326
|
+
if (file && !existsSync(file)) throw new Error(`file not found: ${file}`);
|
|
327
|
+
const data = file ? JSON.parse(readFileSync(file, "utf-8")) : repo.staged();
|
|
328
|
+
let records = data.records ?? [];
|
|
329
|
+
const deletes = data.deletes ?? [];
|
|
330
|
+
if (!Array.isArray(records) || !Array.isArray(deletes) || records.length + deletes.length === 0) throw new Error(file ? `${file} must contain a non-empty "records" or "deletes" array` : "nothing staged — run `fangorn add <paths>` first");
|
|
331
|
+
const fangorn = getFangorn();
|
|
332
|
+
const parent = repo.head() ?? void 0;
|
|
333
|
+
if (options.paid) {
|
|
334
|
+
if (!options.price) throw new Error("--paid needs --price");
|
|
335
|
+
if (parent && parent !== await fangorn.onChainTip(fangorn.getAddress(), repo.namespace())) throw new Error("push your local commits before committing paid records");
|
|
336
|
+
const shareBps = Math.round(Number(options.share) * 100);
|
|
337
|
+
const days = Number(options.deadlineDays);
|
|
338
|
+
if (!Number.isFinite(days) || days <= 0) throw new Error(`--deadline-days must be a positive number, got ${options.deadlineDays}`);
|
|
339
|
+
records = await sealRecords(fangorn, repo.namespace(), records, {
|
|
340
|
+
fields: options.paid.split(",").map((f) => f.trim()).filter(Boolean),
|
|
341
|
+
price: parseUnits(options.price, 6),
|
|
342
|
+
shareBps,
|
|
343
|
+
deadline: BigInt(Math.floor(Date.now() / 1e3 + days * 86400)),
|
|
344
|
+
keyServer: options.keyServer
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
const s = spinner();
|
|
348
|
+
s.start(parent ? "Committing (building on local HEAD)..." : "Committing (initial)...");
|
|
349
|
+
const result = await fangorn.commit({
|
|
350
|
+
repo: repo.namespace(),
|
|
351
|
+
records,
|
|
352
|
+
deletes,
|
|
353
|
+
parent,
|
|
354
|
+
replace: options.replace
|
|
355
|
+
});
|
|
356
|
+
s.stop();
|
|
357
|
+
repo.setHead(result.commitCid);
|
|
358
|
+
if (!file) repo.setStaged({
|
|
359
|
+
records: [],
|
|
360
|
+
deletes: []
|
|
361
|
+
});
|
|
362
|
+
console.log(`Commit: ${result.commitCid}`);
|
|
363
|
+
console.log(`Parent: ${result.parent ?? "(root)"}`);
|
|
364
|
+
console.log(`Tree: ${result.root}`);
|
|
365
|
+
console.log(`Staged: ${records.length.toString()} put(s) / ${deletes.length.toString()} delete(s)`);
|
|
366
|
+
console.log(`\nCommitted locally. Run \`fangorn push\` to settle it on-chain.`);
|
|
367
|
+
process.exit(0);
|
|
368
|
+
} catch (err) {
|
|
369
|
+
console.error("Failed:", err.message);
|
|
370
|
+
process.exit(1);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
program.command("push").description("Settle the local tip commit as the on-chain state root (the permissioned step)").action(async () => {
|
|
374
|
+
try {
|
|
375
|
+
const repo = LocalRepo.open();
|
|
376
|
+
const head = repo.head();
|
|
377
|
+
if (!head) throw new Error("nothing to push — no commits yet");
|
|
378
|
+
const fangorn = getFangorn();
|
|
379
|
+
const s = spinner();
|
|
380
|
+
s.start("Pushing...");
|
|
381
|
+
const { txHash, onChainTip } = await fangorn.push(repo.namespace(), head);
|
|
382
|
+
s.stop();
|
|
383
|
+
console.log(`Tx: ${txHash}`);
|
|
384
|
+
console.log(`Tip: ${onChainTip}`);
|
|
385
|
+
process.exit(0);
|
|
386
|
+
} catch (err) {
|
|
387
|
+
console.error("Failed:", err.message);
|
|
388
|
+
process.exit(1);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
program.command("status").description("Compare the local tip with the on-chain tip").action(async () => {
|
|
392
|
+
try {
|
|
393
|
+
const repo = LocalRepo.open();
|
|
394
|
+
const fangorn = getFangorn();
|
|
395
|
+
const localHead = repo.head();
|
|
396
|
+
const onChainTip = await fangorn.onChainTip(repo.owner(), repo.namespace());
|
|
397
|
+
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";
|
|
398
|
+
console.log(`Namespace: ${repo.namespace()}`);
|
|
399
|
+
console.log(`Owner: ${repo.owner()}`);
|
|
400
|
+
console.log(`Local HEAD: ${localHead ?? "(none)"}`);
|
|
401
|
+
console.log(`On-chain tip: ${onChainTip ?? "(none)"}`);
|
|
402
|
+
console.log(`Status: ${state}`);
|
|
403
|
+
const staged = repo.staged();
|
|
404
|
+
console.log(`Staged: ${staged.records.length.toString()} put(s) / ${staged.deletes.length.toString()} delete(s)`);
|
|
405
|
+
process.exit(0);
|
|
406
|
+
} catch (err) {
|
|
407
|
+
console.error("Failed:", err.message);
|
|
408
|
+
process.exit(1);
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
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) => {
|
|
412
|
+
try {
|
|
413
|
+
const head = LocalRepo.open().head();
|
|
414
|
+
if (!head) {
|
|
415
|
+
console.log("(no commits yet)");
|
|
416
|
+
process.exit(0);
|
|
417
|
+
}
|
|
418
|
+
const fangorn = getFangorn();
|
|
419
|
+
for await (const c of fangorn.log(head, options.max)) {
|
|
420
|
+
console.log(`commit ${c.cid}`);
|
|
421
|
+
console.log(`Epoch: ${c.epoch.toString()}`);
|
|
422
|
+
console.log(`Tree: ${c.root}\n`);
|
|
423
|
+
}
|
|
424
|
+
process.exit(0);
|
|
425
|
+
} catch (err) {
|
|
426
|
+
console.error("Failed:", err.message);
|
|
427
|
+
process.exit(1);
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
program.command("show").description("Show a commit and what it changed vs. its parent").argument("[commit]", "Commit CID (default: local HEAD)").action(async (commitArg) => {
|
|
431
|
+
try {
|
|
432
|
+
const repo = LocalRepo.open();
|
|
433
|
+
const target = commitArg ?? repo.head();
|
|
434
|
+
if (!target) throw new Error("no commit to show — no commits yet");
|
|
435
|
+
const diff = await getFangorn().show(target);
|
|
436
|
+
console.log(`commit ${target}`);
|
|
437
|
+
console.log(`Epoch: ${diff.epoch.toString()}`);
|
|
438
|
+
console.log(`Parent: ${diff.parent ?? "(root)"}`);
|
|
439
|
+
console.log(`Tree: ${diff.root}\n`);
|
|
440
|
+
console.log(`Changes vs. parent: +${diff.added.length.toString()} / -${diff.removed.length.toString()} key(s)`);
|
|
441
|
+
for (const k of diff.added) console.log(` + ${k}`);
|
|
442
|
+
for (const k of diff.removed) console.log(` - ${k}`);
|
|
443
|
+
process.exit(0);
|
|
444
|
+
} catch (err) {
|
|
445
|
+
console.error("Failed:", err.message);
|
|
446
|
+
process.exit(1);
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
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) => {
|
|
450
|
+
try {
|
|
451
|
+
const fangorn = getFangorn();
|
|
452
|
+
const s = spinner();
|
|
453
|
+
s.start(`Resolving on-chain tip for ${owner}...`);
|
|
454
|
+
const tip = await fangorn.onChainTip(owner, namespace);
|
|
455
|
+
const repo = LocalRepo.init({
|
|
456
|
+
namespace,
|
|
457
|
+
owner,
|
|
458
|
+
head: tip
|
|
459
|
+
}, options.dir ?? process.cwd());
|
|
460
|
+
s.stop();
|
|
461
|
+
console.log(`Namespace: ${namespace}`);
|
|
462
|
+
console.log(`Owner: ${owner}`);
|
|
463
|
+
console.log(`HEAD: ${repo.head() ?? "(none — publisher has no commits yet)"}`);
|
|
464
|
+
process.exit(0);
|
|
465
|
+
} catch (err) {
|
|
466
|
+
console.error("Failed:", err.message);
|
|
467
|
+
process.exit(1);
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
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").option("--all", "Watch every publisher and namespace; --owner/namespace narrow it").action(async (namespaceArg, options) => {
|
|
471
|
+
try {
|
|
472
|
+
const fangorn = getFangorn();
|
|
473
|
+
let namespace = namespaceArg;
|
|
474
|
+
let owner = options.owner;
|
|
475
|
+
if (!options.all) {
|
|
476
|
+
if (!namespace || !owner) try {
|
|
477
|
+
const repo = LocalRepo.open();
|
|
478
|
+
namespace = namespace ?? repo.namespace();
|
|
479
|
+
owner = owner ?? repo.owner();
|
|
480
|
+
} catch {}
|
|
481
|
+
if (!namespace) throw new Error("namespace required (pass it as an argument, run inside a repo, or use --all)");
|
|
482
|
+
owner = owner ?? fangorn.getAddress();
|
|
483
|
+
}
|
|
484
|
+
const repoDir = join(process.cwd(), ".fangorn");
|
|
485
|
+
const cursorPath = join(repoDir, `subscribe-${owner ?? "all"}-${namespace ?? "all"}.json`);
|
|
486
|
+
const readCursor = () => {
|
|
487
|
+
if (options.fromStart) return 0n;
|
|
488
|
+
if (options.fromBlock !== void 0) return options.fromBlock;
|
|
489
|
+
if (existsSync(cursorPath)) {
|
|
490
|
+
const numInput = JSON.parse(readFileSync(cursorPath, "utf-8")).lastBlock ?? 0;
|
|
491
|
+
return BigInt(numInput) + 1n;
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
const writeCursor = (block) => {
|
|
495
|
+
if (!existsSync(repoDir)) mkdirSync(repoDir, { recursive: true });
|
|
496
|
+
writeFileSync(cursorPath, JSON.stringify({
|
|
497
|
+
owner,
|
|
498
|
+
namespace,
|
|
499
|
+
lastBlock: block.toString()
|
|
500
|
+
}, null, 2), "utf-8");
|
|
501
|
+
};
|
|
502
|
+
const bigintReplacer = (_k, v) => typeof v === "bigint" ? v.toString() : v;
|
|
503
|
+
const fromBlock = readCursor();
|
|
504
|
+
console.error(`Subscribing to "${namespace ?? "*"}" @ ${owner ?? "*"} ` + (fromBlock !== void 0 ? `from block ${fromBlock.toString()}` : "(live from current tip)") + ` — Ctrl-C to stop.`);
|
|
505
|
+
const controller = new AbortController();
|
|
506
|
+
process.on("SIGINT", () => {
|
|
507
|
+
controller.abort();
|
|
508
|
+
});
|
|
509
|
+
process.on("SIGTERM", () => {
|
|
510
|
+
controller.abort();
|
|
511
|
+
});
|
|
512
|
+
const stream = options.all ? fangorn.subscribeAll({
|
|
513
|
+
repo: namespace,
|
|
514
|
+
owner,
|
|
515
|
+
fromBlock,
|
|
516
|
+
signal: controller.signal
|
|
517
|
+
}) : fangorn.subscribe({
|
|
518
|
+
repo: namespace ?? "",
|
|
519
|
+
owner,
|
|
520
|
+
fromBlock,
|
|
521
|
+
signal: controller.signal
|
|
522
|
+
});
|
|
523
|
+
for await (const change of stream) {
|
|
524
|
+
process.stdout.write(JSON.stringify(change, bigintReplacer, options.pretty ? 2 : 0) + "\n");
|
|
525
|
+
writeCursor(change.blockNumber);
|
|
526
|
+
}
|
|
527
|
+
process.exit(0);
|
|
528
|
+
} catch (err) {
|
|
529
|
+
console.error("Failed:", err.message);
|
|
530
|
+
process.exit(1);
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
program.command("read").description("List every record 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) => {
|
|
534
|
+
try {
|
|
535
|
+
const fangorn = getFangorn();
|
|
536
|
+
let namespace = namespaceArg;
|
|
537
|
+
let owner = options.owner;
|
|
538
|
+
if (!namespace || !owner) {
|
|
539
|
+
const repo = LocalRepo.open();
|
|
540
|
+
namespace = namespace ?? repo.namespace();
|
|
541
|
+
owner = owner ?? repo.owner();
|
|
542
|
+
}
|
|
543
|
+
const [head, contents] = await Promise.all([fangorn.onChainTip(owner, namespace), fangorn.engine.listRepo(owner, namespace)]);
|
|
544
|
+
const out = {
|
|
545
|
+
owner,
|
|
546
|
+
namespace,
|
|
547
|
+
head,
|
|
548
|
+
records: contents.records
|
|
549
|
+
};
|
|
550
|
+
process.stdout.write(JSON.stringify(out, null, options.pretty ? 2 : 0) + "\n", () => process.exit(0));
|
|
551
|
+
} catch (err) {
|
|
552
|
+
console.error("Failed:", err.message);
|
|
553
|
+
process.exit(1);
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
program.command("reset").description("DANGER!: reset this namespace's on-chain head to zero (abandons all prior commits)").action(async () => {
|
|
557
|
+
const namespace = LocalRepo.open().namespace();
|
|
558
|
+
const confirmFirst = await confirm({ message: `Are you sure? The on-chain head for "${namespace}" will reset to 0x0000...` });
|
|
559
|
+
handleCancel(confirmFirst);
|
|
560
|
+
if (!confirmFirst) {
|
|
561
|
+
console.log("Reset aborted.");
|
|
562
|
+
process.exit(0);
|
|
563
|
+
}
|
|
564
|
+
await getFangorn().reset(namespace);
|
|
565
|
+
console.log(`On-chain head for "${namespace}" reset to zero. \`repo init\` will now start fresh.`);
|
|
566
|
+
process.exit(0);
|
|
567
|
+
});
|
|
568
|
+
program.parse();
|
|
569
|
+
|
|
570
|
+
//#endregion
|
|
571
|
+
export { };
|