@fangorn-network/sdk 2026.9.22-dev → 2026.10.19-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +177 -192
- package/lib/cli/cli.d.ts +0 -0
- package/lib/cli/cli.js +165 -194
- package/lib/config.d.ts +32 -27
- package/lib/config.js +17 -7
- package/lib/contracts/app-registry/abi.d.ts +1033 -277
- package/lib/contracts/app-registry/abi.js +1214 -335
- package/lib/contracts/app-registry/index.d.ts +105 -65
- package/lib/contracts/app-registry/index.js +182 -175
- package/lib/contracts/data-registry/abi.d.ts +166 -187
- package/lib/contracts/data-registry/abi.js +207 -237
- package/lib/contracts/data-registry/index.d.ts +4 -151
- package/lib/contracts/data-registry/index.js +5 -279
- package/lib/contracts/index.d.ts +6 -7
- package/lib/contracts/index.js +6 -8
- package/lib/contracts/logs.d.ts +4 -1
- package/lib/contracts/logs.js +9 -2
- package/lib/contracts/membership-registry/abi.d.ts +1145 -0
- package/lib/contracts/membership-registry/abi.js +1333 -0
- package/lib/contracts/membership-registry/index.d.ts +79 -0
- package/lib/contracts/membership-registry/index.js +104 -0
- package/lib/contracts/types.d.ts +3 -1
- package/lib/contracts/types.js +3 -1
- package/lib/contracts/write.d.ts +34 -2
- package/lib/contracts/write.js +48 -1
- package/lib/crypto/encryption.js +4 -4
- package/lib/engine/car.d.ts +2 -2
- package/lib/engine/car.js +10 -5
- package/lib/engine/index.d.ts +99 -143
- package/lib/engine/index.js +156 -295
- package/lib/engine/records.d.ts +110 -0
- package/lib/engine/records.js +165 -0
- package/lib/engine/test-helpers.d.ts +7 -14
- package/lib/engine/test-helpers.js +7 -18
- package/lib/fangorn.d.ts +129 -156
- package/lib/fangorn.js +250 -250
- package/lib/feed.d.ts +7 -4
- package/lib/feed.js +4 -1
- package/lib/index.d.ts +9 -9
- package/lib/index.js +8 -9
- package/lib/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js +77 -0
- package/lib/node_modules/@vitest/expect/dist/index.js +1414 -0
- package/lib/node_modules/@vitest/pretty-format/dist/index.js +858 -0
- package/lib/node_modules/@vitest/runner/dist/chunk-tasks.js +51 -0
- package/lib/node_modules/@vitest/runner/dist/index.js +1199 -0
- package/lib/node_modules/@vitest/runner/dist/utils.js +3 -0
- package/lib/node_modules/@vitest/snapshot/dist/index.js +1075 -0
- package/lib/node_modules/@vitest/spy/dist/index.js +353 -0
- package/lib/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +7 -0
- package/lib/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js +81 -0
- package/lib/node_modules/@vitest/utils/dist/diff.js +1345 -0
- package/lib/node_modules/@vitest/utils/dist/display.js +534 -0
- package/lib/node_modules/@vitest/utils/dist/error.js +30 -0
- package/lib/node_modules/@vitest/utils/dist/helpers.js +118 -0
- package/lib/node_modules/@vitest/utils/dist/serialize.js +76 -0
- package/lib/node_modules/@vitest/utils/dist/source-map.js +93 -0
- package/lib/node_modules/@vitest/utils/dist/timers.js +36 -0
- package/lib/node_modules/chai/index.js +2874 -0
- package/lib/node_modules/magic-string/dist/magic-string.es.js +939 -0
- package/lib/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +81 -0
- package/lib/node_modules/tinyrainbow/dist/index.js +85 -0
- package/lib/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js +5 -0
- package/lib/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js +50 -0
- package/lib/node_modules/vitest/dist/chunks/utils.DvEY5TfP.js +44 -0
- package/lib/node_modules/vitest/dist/chunks/vi.2VT5v0um.js +2578 -0
- package/lib/providers/storage/signed-url.d.ts +16 -6
- package/lib/providers/storage/signed-url.js +20 -8
- package/lib/registry.d.ts +116 -0
- package/lib/registry.js +182 -0
- package/lib/test/mem-registry.d.ts +51 -0
- package/lib/test/mem-registry.js +107 -0
- package/lib/test/sdk-suite.d.ts +13 -0
- package/lib/test/sdk-suite.js +226 -0
- package/lib/test/testbed.d.ts +16411 -61
- package/lib/test/testbed.js +190 -84
- package/lib/types/index.d.ts +13 -11
- package/package.json +89 -73
- package/lib/contracts/data-registry/test.d.ts +0 -1
- package/lib/contracts/data-registry/test.js +0 -1
- package/lib/contracts/settlement-registry/abi.d.ts +0 -466
- package/lib/contracts/settlement-registry/abi.js +0 -535
- package/lib/contracts/settlement-registry/index.d.ts +0 -163
- package/lib/contracts/settlement-registry/index.js +0 -264
- package/lib/contracts/subscription-registry/abi.d.ts +0 -179
- package/lib/contracts/subscription-registry/abi.js +0 -195
- package/lib/contracts/subscription-registry/index.d.ts +0 -59
- package/lib/contracts/subscription-registry/index.js +0 -116
- package/lib/engine/graph.d.ts +0 -70
- package/lib/engine/graph.js +0 -73
|
@@ -1,154 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
|
|
1
|
+
import { Hex } from "viem";
|
|
3
2
|
|
|
4
3
|
//#region src/contracts/data-registry/index.d.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* The onchain id of a namespace within an app is the sha256 hash of its hex representation
|
|
8
|
-
* i.e. ns = 'a' => ns_id = sha256(hex('a'))
|
|
9
|
-
*/
|
|
10
|
-
declare function subspaceId(namespace: string): Hex;
|
|
11
|
-
/**
|
|
12
|
-
* The composite storage key for a full path to a subspace: `app:publisher:subspace`.
|
|
13
|
-
*/
|
|
14
|
-
declare function namespaceKey(appId: Hex, publisher: Address, subspace: Hex): Hex;
|
|
15
|
-
/**
|
|
16
|
-
* A decoded `StateCommitted` log — the single on-chain signal that one
|
|
17
|
-
* hierarchical namespace's state root advanced. `logId` uniquely identifies the
|
|
18
|
-
* emitting log (tx + index) so consumers can dedupe across the catch-up
|
|
19
|
-
* (getLogs) and live (watch) paths.
|
|
20
|
-
*/
|
|
21
|
-
interface StateCommittedLog {
|
|
22
|
-
namespaceKey: Hex;
|
|
23
|
-
appId: Hex;
|
|
24
|
-
publisher: Address;
|
|
25
|
-
subspaceId: Hex;
|
|
26
|
-
oldRoot: Hex;
|
|
27
|
-
newRoot: Hex;
|
|
28
|
-
blockNumber: bigint;
|
|
29
|
-
logId: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Which slice of the app's commit stream to read. Every field is an indexed
|
|
33
|
-
* topic, so filtering happens on the RPC node — no indexer, no subgraph:
|
|
34
|
-
*
|
|
35
|
-
* {} — the whole app, every publisher and subspace
|
|
36
|
-
* { publisher } — one publisher's commits across the app
|
|
37
|
-
* { publisher, namespace } — one exact subspace (the tightest filter)
|
|
38
|
-
*
|
|
39
|
-
* `namespace` alone is not filterable: the key binds the publisher too, so a
|
|
40
|
-
* subspace name across all publishers means filtering the app stream in memory.
|
|
41
|
-
*/
|
|
42
|
-
interface CommitFilter {
|
|
43
|
-
publisher?: Address;
|
|
44
|
-
namespace?: string;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* An unsigned transaction, hex-encoded and ready to hand to a browser wallet's
|
|
48
|
-
* `eth_sendTransaction` — no `from`, since the signing wallet supplies it.
|
|
49
|
-
*/
|
|
50
|
-
interface PreparedTx {
|
|
51
|
-
to: Address;
|
|
52
|
-
data: Hex;
|
|
53
|
-
chainId: number | undefined;
|
|
54
|
-
gas: Hex;
|
|
55
|
-
maxFeePerGas: Hex;
|
|
56
|
-
maxPriorityFeePerGas: Hex;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Publisher registration, the state-root timeline, and nothing about apps.
|
|
60
|
-
*
|
|
61
|
-
* `registerApp` and `getAppOwner` used to live here. They are on
|
|
62
|
-
* {@link AppRegistryClient} now, together with the per-app terms and membership
|
|
63
|
-
* they belong with — and `commitStateRoot` cross-calls that contract, so a
|
|
64
|
-
* publisher must join an app before they can write under it. A commit for an app
|
|
65
|
-
* this wallet never joined reverts `NotRegisteredForApp`.
|
|
66
|
-
*/
|
|
67
|
-
declare class DataRegistryClient {
|
|
68
|
-
private contractAddress;
|
|
69
|
-
private appId;
|
|
70
|
-
private publicClient;
|
|
71
|
-
private walletClient;
|
|
72
|
-
constructor(contractAddress: Address, appId: Hex, publicClient: PublicClient, walletClient: WalletClient);
|
|
73
|
-
/** The app namespace every call on this client is scoped to. */
|
|
74
|
-
getAppId(): Hex;
|
|
75
|
-
/** Re-scope every subsequent call to a different app. See `Fangorn.setAppId`. */
|
|
76
|
-
setAppId(appId: Hex): void;
|
|
77
|
-
/** The deployed DataRegistry this client talks to. */
|
|
78
|
-
getAddress(): Address;
|
|
79
|
-
/**
|
|
80
|
-
* Internal helper to execute state-mutating transactions
|
|
81
|
-
* matching the exact gas buffer and aggressive fee styling of the protocol.
|
|
82
|
-
*/
|
|
83
|
-
private executeWrite;
|
|
84
|
-
/** The composite key for one of this app's namespaces. */
|
|
85
|
-
namespaceKey(publisher: Address, namespace: string): Hex;
|
|
86
|
-
/**
|
|
87
|
-
* Register as a new data publisher or reactivate a suspended account.
|
|
88
|
-
* Automatically reads the required on-chain fee and attaches it to the call.
|
|
89
|
-
*/
|
|
90
|
-
register(): Promise<Hash>;
|
|
91
|
-
/**
|
|
92
|
-
* The single mutating state gateway route. Enforces the sequential
|
|
93
|
-
* Compare-And-Swap (CAS) timeline rule — per namespace, so concurrent pushes
|
|
94
|
-
* to *different* namespaces never contend.
|
|
95
|
-
*/
|
|
96
|
-
commitStateRoot(namespace: string, oldRoot: Hex, newRoot: Hex): Promise<Hash>;
|
|
97
|
-
/**
|
|
98
|
-
* Build the `commitStateRoot` call as an UNSIGNED transaction for `publisher`
|
|
99
|
-
* to sign, instead of sending it from this client's wallet.
|
|
100
|
-
*
|
|
101
|
-
* This is the self-custodial publish path: a relay server builds and pins the
|
|
102
|
-
* commit with a keyless service wallet, then hands this back for the user's
|
|
103
|
-
* browser wallet to sign. The server never holds the key that moves the head,
|
|
104
|
-
* and the on-chain sender IS the publisher — which is what authenticates the
|
|
105
|
-
* publish, since the contract keys the namespace by `msg_sender`.
|
|
106
|
-
*/
|
|
107
|
-
prepareCommitStateRoot(publisher: Address, namespace: string, oldRoot: Hex, newRoot: Hex): Promise<PreparedTx>;
|
|
108
|
-
/**
|
|
109
|
-
* Obtains the authoritative timeline tracking anchor for one publisher's
|
|
110
|
-
* namespace within this app.
|
|
111
|
-
*/
|
|
112
|
-
getNamespaceHead(publisher: Address, namespace: string): Promise<Hex>;
|
|
113
|
-
/** The AppRegistry this contract defers to for apps and per-app membership. */
|
|
114
|
-
appRegistry(): Promise<Address>;
|
|
115
|
-
/**
|
|
116
|
-
* Reads the explicit enum lifecycle state from the registry status machine.
|
|
117
|
-
*/
|
|
118
|
-
getPublisherStatus(publisher: Address): Promise<PublisherStatus>;
|
|
119
|
-
/**
|
|
120
|
-
* Helper boolean view returning true if a publisher can currently commit data.
|
|
121
|
-
*/
|
|
122
|
-
isRegistered(publisher: Address): Promise<boolean>;
|
|
123
|
-
/** Current chain head block number — the default "start here" for a fresh subscription. */
|
|
124
|
-
currentBlock(): Promise<bigint>;
|
|
125
|
-
/** Translate a `CommitFilter` into indexed-topic args for this app. */
|
|
126
|
-
private topicsFor;
|
|
127
|
-
/**
|
|
128
|
-
* Historical `StateCommitted` logs for one slice of this app, oldest →
|
|
129
|
-
* newest — the catch-up path for a subscriber resuming from a saved block
|
|
130
|
-
* cursor. Node-side filtered by indexed topics, so no indexer is involved.
|
|
131
|
-
* Fetched in block windows (see `getLogsInWindows`).
|
|
132
|
-
*/
|
|
133
|
-
getStateCommittedLogs(filter: CommitFilter, fromBlock: bigint, toBlock?: bigint): Promise<StateCommittedLog[]>;
|
|
134
|
-
/**
|
|
135
|
-
* Live-watch `StateCommitted` for one slice of this app. Returns an
|
|
136
|
-
* unsubscribe function. Uses the client's transport (polling over HTTP, push
|
|
137
|
-
* over a WebSocket transport) — reads logs straight from the RPC node, no
|
|
138
|
-
* subgraph.
|
|
139
|
-
*/
|
|
140
|
-
watchStateCommitted(filter: CommitFilter, onCommit: (log: StateCommittedLog) => void, onError?: (err: Error) => void, pollingInterval?: number): () => void;
|
|
141
|
-
publisherCount(): Promise<bigint>;
|
|
142
|
-
registrationFee(): Promise<bigint>;
|
|
143
|
-
admin(): Promise<Address>;
|
|
144
|
-
/**
|
|
145
|
-
* Allows governance or protocol administrator to immediately freeze a publisher namespace.
|
|
146
|
-
*/
|
|
147
|
-
suspendPublisher(publisher: Address): Promise<Hash>;
|
|
148
|
-
/**
|
|
149
|
-
* Adjusts the current native/token onboarding collateral tier.
|
|
150
|
-
*/
|
|
151
|
-
setRegistrationFee(fee: bigint): Promise<Hash>;
|
|
152
|
-
}
|
|
4
|
+
/** A repo's on-chain id: keccak256 of its name's UTF-8 bytes, never of the name as hex. */
|
|
5
|
+
declare function repoId(repo: string): Hex;
|
|
153
6
|
//#endregion
|
|
154
|
-
export {
|
|
7
|
+
export { repoId };
|
|
@@ -1,284 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getLogsInWindows } from "../logs.js";
|
|
3
|
-
import { DATA_REGISTRY_ABI } from "./abi.js";
|
|
4
|
-
import { concatHex, encodeFunctionData, keccak256, toHex } from "viem";
|
|
1
|
+
import { keccak256, toHex } from "viem";
|
|
5
2
|
|
|
6
3
|
//#region src/contracts/data-registry/index.ts
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
function subspaceId(namespace) {
|
|
12
|
-
return keccak256(toHex(namespace));
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* The composite storage key for a full path to a subspace: `app:publisher:subspace`.
|
|
16
|
-
*/
|
|
17
|
-
function namespaceKey(appId, publisher, subspace) {
|
|
18
|
-
return keccak256(concatHex([
|
|
19
|
-
appId,
|
|
20
|
-
publisher,
|
|
21
|
-
subspace
|
|
22
|
-
]));
|
|
23
|
-
}
|
|
24
|
-
function decodeStateCommitted(log) {
|
|
25
|
-
const a = log.args;
|
|
26
|
-
if (a.namespace_key === void 0 || a.app_id === void 0 || a.publisher === void 0 || a.subspace_id === void 0 || a.old_root === void 0 || a.new_root === void 0) throw new Error("Malformed log event: incomplete StateCommitted args");
|
|
27
|
-
return {
|
|
28
|
-
namespaceKey: a.namespace_key,
|
|
29
|
-
appId: a.app_id,
|
|
30
|
-
publisher: a.publisher,
|
|
31
|
-
subspaceId: a.subspace_id,
|
|
32
|
-
oldRoot: a.old_root,
|
|
33
|
-
newRoot: a.new_root,
|
|
34
|
-
blockNumber: log.blockNumber,
|
|
35
|
-
logId: `${log.transactionHash}:${log.logIndex.toString()}`
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Publisher registration, the state-root timeline, and nothing about apps.
|
|
40
|
-
*
|
|
41
|
-
* `registerApp` and `getAppOwner` used to live here. They are on
|
|
42
|
-
* {@link AppRegistryClient} now, together with the per-app terms and membership
|
|
43
|
-
* they belong with — and `commitStateRoot` cross-calls that contract, so a
|
|
44
|
-
* publisher must join an app before they can write under it. A commit for an app
|
|
45
|
-
* this wallet never joined reverts `NotRegisteredForApp`.
|
|
46
|
-
*/
|
|
47
|
-
var DataRegistryClient = class {
|
|
48
|
-
constructor(contractAddress, appId, publicClient, walletClient) {
|
|
49
|
-
this.contractAddress = contractAddress;
|
|
50
|
-
this.appId = appId;
|
|
51
|
-
this.publicClient = publicClient;
|
|
52
|
-
this.walletClient = walletClient;
|
|
53
|
-
}
|
|
54
|
-
/** The app namespace every call on this client is scoped to. */
|
|
55
|
-
getAppId() {
|
|
56
|
-
return this.appId;
|
|
57
|
-
}
|
|
58
|
-
/** Re-scope every subsequent call to a different app. See `Fangorn.setAppId`. */
|
|
59
|
-
setAppId(appId) {
|
|
60
|
-
this.appId = appId;
|
|
61
|
-
}
|
|
62
|
-
/** The deployed DataRegistry this client talks to. */
|
|
63
|
-
getAddress() {
|
|
64
|
-
return this.contractAddress;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Internal helper to execute state-mutating transactions
|
|
68
|
-
* matching the exact gas buffer and aggressive fee styling of the protocol.
|
|
69
|
-
*/
|
|
70
|
-
executeWrite(functionName, args, value) {
|
|
71
|
-
return sendWrite(this.publicClient, requireWallet(this.walletClient, functionName), this.contractAddress, DATA_REGISTRY_ABI, functionName, args, value);
|
|
72
|
-
}
|
|
73
|
-
/** The composite key for one of this app's namespaces. */
|
|
74
|
-
namespaceKey(publisher, namespace) {
|
|
75
|
-
return namespaceKey(this.appId, publisher, subspaceId(namespace));
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Register as a new data publisher or reactivate a suspended account.
|
|
79
|
-
* Automatically reads the required on-chain fee and attaches it to the call.
|
|
80
|
-
*/
|
|
81
|
-
async register() {
|
|
82
|
-
const fee = await this.registrationFee();
|
|
83
|
-
return this.executeWrite("register", [], fee);
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* The single mutating state gateway route. Enforces the sequential
|
|
87
|
-
* Compare-And-Swap (CAS) timeline rule — per namespace, so concurrent pushes
|
|
88
|
-
* to *different* namespaces never contend.
|
|
89
|
-
*/
|
|
90
|
-
async commitStateRoot(namespace, oldRoot, newRoot) {
|
|
91
|
-
return this.executeWrite("commitStateRoot", [
|
|
92
|
-
this.appId,
|
|
93
|
-
subspaceId(namespace),
|
|
94
|
-
oldRoot,
|
|
95
|
-
newRoot
|
|
96
|
-
]);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Build the `commitStateRoot` call as an UNSIGNED transaction for `publisher`
|
|
100
|
-
* to sign, instead of sending it from this client's wallet.
|
|
101
|
-
*
|
|
102
|
-
* This is the self-custodial publish path: a relay server builds and pins the
|
|
103
|
-
* commit with a keyless service wallet, then hands this back for the user's
|
|
104
|
-
* browser wallet to sign. The server never holds the key that moves the head,
|
|
105
|
-
* and the on-chain sender IS the publisher — which is what authenticates the
|
|
106
|
-
* publish, since the contract keys the namespace by `msg_sender`.
|
|
107
|
-
*/
|
|
108
|
-
async prepareCommitStateRoot(publisher, namespace, oldRoot, newRoot) {
|
|
109
|
-
const data = encodeFunctionData({
|
|
110
|
-
abi: DATA_REGISTRY_ABI,
|
|
111
|
-
functionName: "commitStateRoot",
|
|
112
|
-
args: [
|
|
113
|
-
this.appId,
|
|
114
|
-
subspaceId(namespace),
|
|
115
|
-
oldRoot,
|
|
116
|
-
newRoot
|
|
117
|
-
]
|
|
118
|
-
});
|
|
119
|
-
const fees = await this.publicClient.estimateFeesPerGas();
|
|
120
|
-
let gas;
|
|
121
|
-
try {
|
|
122
|
-
gas = await this.publicClient.estimateGas({
|
|
123
|
-
account: publisher,
|
|
124
|
-
to: this.contractAddress,
|
|
125
|
-
data
|
|
126
|
-
}) * 3n / 2n;
|
|
127
|
-
} catch (err) {
|
|
128
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
129
|
-
if (/revert/i.test(message)) throw new Error(`settlement would revert — the head may have moved on-chain, or the app is unregistered: ${message}`);
|
|
130
|
-
gas = 5000000n;
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
to: this.contractAddress,
|
|
134
|
-
data,
|
|
135
|
-
chainId: this.publicClient.chain?.id,
|
|
136
|
-
gas: toHex(gas),
|
|
137
|
-
maxFeePerGas: toHex(fees.maxFeePerGas * 2n),
|
|
138
|
-
maxPriorityFeePerGas: toHex(fees.maxPriorityFeePerGas)
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Obtains the authoritative timeline tracking anchor for one publisher's
|
|
143
|
-
* namespace within this app.
|
|
144
|
-
*/
|
|
145
|
-
async getNamespaceHead(publisher, namespace) {
|
|
146
|
-
return this.publicClient.readContract({
|
|
147
|
-
address: this.contractAddress,
|
|
148
|
-
abi: DATA_REGISTRY_ABI,
|
|
149
|
-
functionName: "getNamespaceHead",
|
|
150
|
-
args: [
|
|
151
|
-
this.appId,
|
|
152
|
-
publisher,
|
|
153
|
-
subspaceId(namespace)
|
|
154
|
-
]
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
/** The AppRegistry this contract defers to for apps and per-app membership. */
|
|
158
|
-
async appRegistry() {
|
|
159
|
-
return this.publicClient.readContract({
|
|
160
|
-
address: this.contractAddress,
|
|
161
|
-
abi: DATA_REGISTRY_ABI,
|
|
162
|
-
functionName: "appRegistry"
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Reads the explicit enum lifecycle state from the registry status machine.
|
|
167
|
-
*/
|
|
168
|
-
async getPublisherStatus(publisher) {
|
|
169
|
-
return await this.publicClient.readContract({
|
|
170
|
-
address: this.contractAddress,
|
|
171
|
-
abi: DATA_REGISTRY_ABI,
|
|
172
|
-
functionName: "getPublisherStatus",
|
|
173
|
-
args: [publisher]
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Helper boolean view returning true if a publisher can currently commit data.
|
|
178
|
-
*/
|
|
179
|
-
async isRegistered(publisher) {
|
|
180
|
-
return this.publicClient.readContract({
|
|
181
|
-
address: this.contractAddress,
|
|
182
|
-
abi: DATA_REGISTRY_ABI,
|
|
183
|
-
functionName: "isRegistered",
|
|
184
|
-
args: [publisher]
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
/** Current chain head block number — the default "start here" for a fresh subscription. */
|
|
188
|
-
async currentBlock() {
|
|
189
|
-
return this.publicClient.getBlockNumber();
|
|
190
|
-
}
|
|
191
|
-
/** Translate a `CommitFilter` into indexed-topic args for this app. */
|
|
192
|
-
topicsFor(filter) {
|
|
193
|
-
const { publisher, namespace } = filter;
|
|
194
|
-
return {
|
|
195
|
-
app_id: this.appId,
|
|
196
|
-
...publisher ? { publisher } : {},
|
|
197
|
-
...publisher && namespace ? { namespace_key: this.namespaceKey(publisher, namespace) } : {}
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Historical `StateCommitted` logs for one slice of this app, oldest →
|
|
202
|
-
* newest — the catch-up path for a subscriber resuming from a saved block
|
|
203
|
-
* cursor. Node-side filtered by indexed topics, so no indexer is involved.
|
|
204
|
-
* Fetched in block windows (see `getLogsInWindows`).
|
|
205
|
-
*/
|
|
206
|
-
async getStateCommittedLogs(filter, fromBlock, toBlock) {
|
|
207
|
-
return (await getLogsInWindows(this.publicClient, fromBlock, toBlock, (from, to) => this.publicClient.getContractEvents({
|
|
208
|
-
address: this.contractAddress,
|
|
209
|
-
abi: DATA_REGISTRY_ABI,
|
|
210
|
-
eventName: "StateCommitted",
|
|
211
|
-
args: this.topicsFor(filter),
|
|
212
|
-
fromBlock: from,
|
|
213
|
-
toBlock: to
|
|
214
|
-
}))).map(decodeStateCommitted).filter((log) => matchesFilter(log, filter)).sort((a, b) => a.blockNumber === b.blockNumber ? a.logId.localeCompare(b.logId) : a.blockNumber < b.blockNumber ? -1 : 1);
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Live-watch `StateCommitted` for one slice of this app. Returns an
|
|
218
|
-
* unsubscribe function. Uses the client's transport (polling over HTTP, push
|
|
219
|
-
* over a WebSocket transport) — reads logs straight from the RPC node, no
|
|
220
|
-
* subgraph.
|
|
221
|
-
*/
|
|
222
|
-
watchStateCommitted(filter, onCommit, onError, pollingInterval) {
|
|
223
|
-
return this.publicClient.watchContractEvent({
|
|
224
|
-
address: this.contractAddress,
|
|
225
|
-
abi: DATA_REGISTRY_ABI,
|
|
226
|
-
eventName: "StateCommitted",
|
|
227
|
-
args: this.topicsFor(filter),
|
|
228
|
-
pollingInterval,
|
|
229
|
-
onLogs: (logs) => {
|
|
230
|
-
for (const raw of logs) {
|
|
231
|
-
const log = decodeStateCommitted(raw);
|
|
232
|
-
if (matchesFilter(log, filter)) onCommit(log);
|
|
233
|
-
}
|
|
234
|
-
},
|
|
235
|
-
onError
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
async publisherCount() {
|
|
239
|
-
return this.publicClient.readContract({
|
|
240
|
-
address: this.contractAddress,
|
|
241
|
-
abi: DATA_REGISTRY_ABI,
|
|
242
|
-
functionName: "publisherCount"
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
async registrationFee() {
|
|
246
|
-
return this.publicClient.readContract({
|
|
247
|
-
address: this.contractAddress,
|
|
248
|
-
abi: DATA_REGISTRY_ABI,
|
|
249
|
-
functionName: "registrationFee"
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
async admin() {
|
|
253
|
-
return this.publicClient.readContract({
|
|
254
|
-
address: this.contractAddress,
|
|
255
|
-
abi: DATA_REGISTRY_ABI,
|
|
256
|
-
functionName: "admin"
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Allows governance or protocol administrator to immediately freeze a publisher namespace.
|
|
261
|
-
*/
|
|
262
|
-
async suspendPublisher(publisher) {
|
|
263
|
-
return this.executeWrite("suspendPublisher", [publisher]);
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Adjusts the current native/token onboarding collateral tier.
|
|
267
|
-
*/
|
|
268
|
-
async setRegistrationFee(fee) {
|
|
269
|
-
return this.executeWrite("setRegistrationFee", [fee]);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
/**
|
|
273
|
-
* The in-memory half of a filter. `subspace_id` is not an indexed topic (the
|
|
274
|
-
* three slots go to namespace_key/app_id/publisher), so a namespace-without-
|
|
275
|
-
* publisher filter — "every publisher's `docs` namespace" — narrows here
|
|
276
|
-
* instead of on the node.
|
|
277
|
-
*/
|
|
278
|
-
function matchesFilter(log, filter) {
|
|
279
|
-
if (!filter.namespace || filter.publisher) return true;
|
|
280
|
-
return log.subspaceId === subspaceId(filter.namespace);
|
|
4
|
+
/** A repo's on-chain id: keccak256 of its name's UTF-8 bytes, never of the name as hex. */
|
|
5
|
+
function repoId(repo) {
|
|
6
|
+
return keccak256(toHex(repo));
|
|
281
7
|
}
|
|
282
8
|
|
|
283
9
|
//#endregion
|
|
284
|
-
export {
|
|
10
|
+
export { repoId };
|
package/lib/contracts/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { APP_REGISTRY_ABI } from "./app-registry/abi.js";
|
|
2
2
|
import { PublisherStatus } from "./types.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { PreparedTx } from "./write.js";
|
|
4
|
+
import { AppAccess, AppAgentLog, AppRegistryClient } from "./app-registry/index.js";
|
|
5
5
|
import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
export { APP_REGISTRY_ABI, AppAgentLog, AppJoinInfo, AppRegistryClient, CommitFilter, DATA_REGISTRY_ABI, DataRegistryClient, PreparedTx, PublisherStatus, Resource, SETTLEMENT_REGISTRY_ABI, SUBSCRIPTION_REGISTRY_ABI, SemaphoreProof, SettlementRegistryClient, StateCommittedLog, SubscriptionAccess, SubscriptionRegistryClient, TransferAuthorization, namespaceKey, needsReacceptance, packResourceUri, resourceIdOf, subspaceId };
|
|
6
|
+
import { repoId } from "./data-registry/index.js";
|
|
7
|
+
import { ClaimArgs, JoinArgs, MembershipPayment, MembershipRegistryClient, joinNonce, membershipScope, membershipTokenId } from "./membership-registry/index.js";
|
|
8
|
+
import { MEMBERSHIP_REGISTRY_ABI } from "./membership-registry/abi.js";
|
|
9
|
+
export { APP_REGISTRY_ABI, AppAccess, AppAgentLog, AppRegistryClient, ClaimArgs, DATA_REGISTRY_ABI, JoinArgs, MEMBERSHIP_REGISTRY_ABI, MembershipPayment, MembershipRegistryClient, PreparedTx, PublisherStatus, joinNonce, membershipScope, membershipTokenId, repoId };
|
package/lib/contracts/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { APP_REGISTRY_ABI } from "./app-registry/abi.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { AppRegistryClient } from "./app-registry/index.js";
|
|
3
|
+
import { repoId } from "./data-registry/index.js";
|
|
4
4
|
import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { SUBSCRIPTION_REGISTRY_ABI } from "./subscription-registry/abi.js";
|
|
9
|
-
import { SubscriptionRegistryClient } from "./subscription-registry/index.js";
|
|
5
|
+
import { MEMBERSHIP_REGISTRY_ABI } from "./membership-registry/abi.js";
|
|
6
|
+
import { MembershipRegistryClient, joinNonce, membershipScope, membershipTokenId } from "./membership-registry/index.js";
|
|
7
|
+
import { PublisherStatus } from "./types.js";
|
|
10
8
|
|
|
11
|
-
export { APP_REGISTRY_ABI, AppRegistryClient, DATA_REGISTRY_ABI,
|
|
9
|
+
export { APP_REGISTRY_ABI, AppRegistryClient, DATA_REGISTRY_ABI, MEMBERSHIP_REGISTRY_ABI, MembershipRegistryClient, PublisherStatus, joinNonce, membershipScope, membershipTokenId, repoId };
|
package/lib/contracts/logs.d.ts
CHANGED
|
@@ -12,7 +12,10 @@ import { PublicClient } from "viem";
|
|
|
12
12
|
* outright, and whatever depends on it (a catch-up, a directory listing) fails
|
|
13
13
|
* with it. Tune the window with `FANGORN_LOG_WINDOW`; a private RPC will take far
|
|
14
14
|
* more.
|
|
15
|
+
*
|
|
16
|
+
* `defaultWindow` is for a query the endpoint is known to serve over a wider
|
|
17
|
+
* range. `FANGORN_LOG_WINDOW` still overrides it.
|
|
15
18
|
*/
|
|
16
|
-
declare function getLogsInWindows<T>(publicClient: PublicClient, fromBlock: bigint, toBlock: bigint | undefined, fetch: (fromBlock: bigint, toBlock: bigint) => Promise<T[]
|
|
19
|
+
declare function getLogsInWindows<T>(publicClient: PublicClient, fromBlock: bigint, toBlock: bigint | undefined, fetch: (fromBlock: bigint, toBlock: bigint) => Promise<T[]>, defaultWindow?: bigint): Promise<T[]>;
|
|
17
20
|
//#endregion
|
|
18
21
|
export { getLogsInWindows };
|
package/lib/contracts/logs.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { nonBlank } from "../config.js";
|
|
2
|
+
|
|
1
3
|
//#region src/contracts/logs.ts
|
|
2
4
|
/**
|
|
3
5
|
* Run `fetch` over [fromBlock, toBlock] in consecutive block windows and
|
|
@@ -9,9 +11,14 @@
|
|
|
9
11
|
* outright, and whatever depends on it (a catch-up, a directory listing) fails
|
|
10
12
|
* with it. Tune the window with `FANGORN_LOG_WINDOW`; a private RPC will take far
|
|
11
13
|
* more.
|
|
14
|
+
*
|
|
15
|
+
* `defaultWindow` is for a query the endpoint is known to serve over a wider
|
|
16
|
+
* range. `FANGORN_LOG_WINDOW` still overrides it.
|
|
12
17
|
*/
|
|
13
|
-
async function getLogsInWindows(publicClient, fromBlock, toBlock, fetch) {
|
|
14
|
-
const
|
|
18
|
+
async function getLogsInWindows(publicClient, fromBlock, toBlock, fetch, defaultWindow = 1000n) {
|
|
19
|
+
const tuned = typeof process !== "undefined" ? nonBlank(process.env.FANGORN_LOG_WINDOW) : void 0;
|
|
20
|
+
const window = tuned === void 0 ? defaultWindow : BigInt(tuned);
|
|
21
|
+
if (window <= 0n) throw new Error(`FANGORN_LOG_WINDOW must be a positive number of blocks, not "${String(tuned)}"`);
|
|
15
22
|
const end = toBlock ?? await publicClient.getBlockNumber({ cacheTime: 0 });
|
|
16
23
|
const out = [];
|
|
17
24
|
for (let start = fromBlock; start <= end; start += window) {
|