@fangorn-network/sdk 2026.8.18-dev → 2026.10.1-9.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/README.md +191 -195
- package/lib/cli/cli.d.ts +0 -0
- package/lib/cli/cli.js +198 -164
- package/lib/cli/index.d.ts +3 -91
- package/lib/cli/index.js +5 -2
- package/lib/config.d.ts +349 -433
- package/lib/config.js +41 -28
- package/lib/contracts/app-registry/abi.d.ts +1064 -265
- package/lib/contracts/app-registry/abi.js +1233 -308
- package/lib/contracts/app-registry/index.d.ts +123 -102
- package/lib/contracts/app-registry/index.js +200 -198
- 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 -160
- package/lib/contracts/data-registry/index.js +5 -294
- package/lib/contracts/index.d.ts +6 -7
- package/lib/contracts/index.js +6 -8
- package/lib/contracts/logs.d.ts +21 -0
- package/lib/contracts/logs.js +32 -0
- 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 +163 -155
- package/lib/fangorn.js +284 -248
- package/lib/feed.d.ts +7 -4
- package/lib/feed.js +4 -1
- package/lib/index.d.ts +9 -9
- package/lib/index.js +9 -10
- 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 -72
- 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,264 +0,0 @@
|
|
|
1
|
-
import { requireWallet, sendWrite } from "../write.js";
|
|
2
|
-
import { SETTLEMENT_REGISTRY_ABI } from "./abi.js";
|
|
3
|
-
import { concat, keccak256 } from "viem";
|
|
4
|
-
|
|
5
|
-
//#region src/contracts/settlement-registry/index.ts
|
|
6
|
-
/**
|
|
7
|
-
* `keccak256(publisher ++ uid)` — the same derivation the registry does in
|
|
8
|
-
* `resource_id_of`, and the same one `resourceIdOf` in `@fangorn-network/fetch`
|
|
9
|
-
* does on the buyer side. Pinned against the deployed contract by an e2e case.
|
|
10
|
-
*
|
|
11
|
-
* The id is derived rather than chosen, so a uid cannot be squatted or
|
|
12
|
-
* front-run. Deriving it locally means a publisher knows the id before
|
|
13
|
-
* `createResource` lands, and a buyer needs no RPC to name what they are buying;
|
|
14
|
-
* `resourceIdFor` asks the chain the same question and exists for parity checks.
|
|
15
|
-
*/
|
|
16
|
-
const resourceIdOf = (publisher, uid) => keccak256(concat([publisher, uid]));
|
|
17
|
-
/**
|
|
18
|
-
* The on-chain `uri` is not free-form: it packs the access worker to fetch from
|
|
19
|
-
* and the sha256 of the plaintext to verify against, as `${workerUrl}#${hash}`.
|
|
20
|
-
*
|
|
21
|
-
* The hash is what makes a read more than a download — without it a worker can
|
|
22
|
-
* serve any bytes that happen to decrypt. `unpackUri` in `@fangorn-network/fetch`
|
|
23
|
-
* is the other side of this, and a publisher who lists a bare URL produces a
|
|
24
|
-
* resource that buyer cannot verify.
|
|
25
|
-
*/
|
|
26
|
-
const packResourceUri = (workerUrl, plaintextHash) => `${workerUrl.replace(/\/$/, "")}#${plaintextHash}`;
|
|
27
|
-
/**
|
|
28
|
-
* Client for the SettlementRegistry — the pay-then-read rail.
|
|
29
|
-
*
|
|
30
|
-
* The two consumer calls are separate on purpose, and the separation is the whole
|
|
31
|
-
* privacy property:
|
|
32
|
-
*
|
|
33
|
-
* 1. `register` — pay for `resourceId` and join its Semaphore group with an
|
|
34
|
-
* identity commitment. This transaction is linked to the payer.
|
|
35
|
-
* 2. `settle` — prove group membership in zero knowledge from a *fresh stealth
|
|
36
|
-
* address*, which is then the address `isSettled` answers for.
|
|
37
|
-
*
|
|
38
|
-
* Nothing on-chain connects the payer to the reader beyond membership of the same
|
|
39
|
-
* group, so a publisher can verify a reader paid without learning who they are.
|
|
40
|
-
* Both are normally relayed by a facilitator, so the consumer needs no gas at all —
|
|
41
|
-
* which is why `register` takes a signed authorization rather than moving funds
|
|
42
|
-
* from `msg.sender`.
|
|
43
|
-
*
|
|
44
|
-
* Constructing without a wallet client gives a read-only client: that is the access
|
|
45
|
-
* worker's usage, which only ever asks `isSettled` and `getPrice`.
|
|
46
|
-
*
|
|
47
|
-
* The publisher half of the flow is here. The BUYER half — deriving a Semaphore
|
|
48
|
-
* identity, signing the EIP-3009 authorization, rebuilding the resource's group
|
|
49
|
-
* from `MemberRegistered` logs and proving membership — already lives in
|
|
50
|
-
* `@fangorn-network/fetch` (x402f), which relays both writes through a facilitator
|
|
51
|
-
* so the buyer never needs gas. Do not reimplement it here: this SDK deliberately
|
|
52
|
-
* carries no Semaphore proving dependency (see the note in the wiki's gotchas).
|
|
53
|
-
*/
|
|
54
|
-
var SettlementRegistryClient = class {
|
|
55
|
-
constructor(contractAddress, publicClient, walletClient) {
|
|
56
|
-
this.contractAddress = contractAddress;
|
|
57
|
-
this.publicClient = publicClient;
|
|
58
|
-
this.walletClient = walletClient;
|
|
59
|
-
}
|
|
60
|
-
getAddress() {
|
|
61
|
-
return this.contractAddress;
|
|
62
|
-
}
|
|
63
|
-
executeWrite(functionName, args) {
|
|
64
|
-
return sendWrite(this.publicClient, requireWallet(this.walletClient, functionName), this.contractAddress, SETTLEMENT_REGISTRY_ABI, functionName, args);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* List a resource for sale and mint its Semaphore group in one transaction.
|
|
68
|
-
*
|
|
69
|
-
* `uid` is the publisher's own identifier for the item; the on-chain
|
|
70
|
-
* `resourceId` is `resourceIdFor(owner, uid)`, so two publishers can use the
|
|
71
|
-
* same uid without collision and a publisher can compute the id before the
|
|
72
|
-
* transaction lands. Claiming the same uid twice reverts `AlreadyRegistered`.
|
|
73
|
-
*/
|
|
74
|
-
async createResource(uid, price, uri) {
|
|
75
|
-
return this.executeWrite("createResource", [
|
|
76
|
-
uid,
|
|
77
|
-
price,
|
|
78
|
-
uri
|
|
79
|
-
]);
|
|
80
|
-
}
|
|
81
|
-
/** Reprice a resource. Does not affect anyone who already settled. */
|
|
82
|
-
async updatePrice(resourceId, price) {
|
|
83
|
-
return this.executeWrite("updatePrice", [resourceId, price]);
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Take a resource off the market. Existing settlements still read — disabling
|
|
87
|
-
* blocks new registrations, it does not revoke access that was paid for.
|
|
88
|
-
*/
|
|
89
|
-
async setDisabled(resourceId, disabled) {
|
|
90
|
-
return this.executeWrite("setDisabled", [resourceId, disabled]);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Attach a contract called after each successful `settle`.
|
|
94
|
-
*
|
|
95
|
-
* No funds pass through it and it cannot change the payment: it fires after
|
|
96
|
-
* settlement is already recorded, and a revert inside it surfaces as
|
|
97
|
-
* `HookFailed`. It is a notification, not a fee lever.
|
|
98
|
-
*/
|
|
99
|
-
async registerHook(resourceId, hook) {
|
|
100
|
-
return this.executeWrite("registerHook", [resourceId, hook]);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Step 1: pay for `resourceId` and join its group.
|
|
104
|
-
*
|
|
105
|
-
* The USDC moves via the caller's EIP-3009 authorization, not from
|
|
106
|
-
* `msg.sender`, so this is safe (and intended) to relay. `amount` must equal
|
|
107
|
-
* the current price exactly, or it reverts `IncorrectPaymentAmount` — quote
|
|
108
|
-
* `getPrice` immediately before signing, since the owner can reprice.
|
|
109
|
-
*/
|
|
110
|
-
async register(resourceId, identityCommitment, auth) {
|
|
111
|
-
return this.executeWrite("register", [
|
|
112
|
-
resourceId,
|
|
113
|
-
identityCommitment,
|
|
114
|
-
auth.from,
|
|
115
|
-
auth.amount,
|
|
116
|
-
auth.validAfter,
|
|
117
|
-
auth.validBefore,
|
|
118
|
-
auth.nonce,
|
|
119
|
-
auth.v,
|
|
120
|
-
auth.r,
|
|
121
|
-
auth.s
|
|
122
|
-
]);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Step 2: prove membership from `stealthAddress`, which is the address
|
|
126
|
-
* `isSettled` will answer for afterwards.
|
|
127
|
-
*
|
|
128
|
-
* The proof's nullifier makes this once-per-identity: a second settle reverts
|
|
129
|
-
* `AlreadySettled`. Send it from an address with no history, or the
|
|
130
|
-
* unlinkability that `register`/`settle` exist to provide is spent for nothing.
|
|
131
|
-
*
|
|
132
|
-
* `hookData` is `uint8[]`, not `bytes` — the contract declares it `Vec<u8>`, and
|
|
133
|
-
* Stylus maps that to a dynamic array of words. Every byte costs a full 32-byte
|
|
134
|
-
* slot in calldata, so keep it empty unless a hook actually reads it.
|
|
135
|
-
*/
|
|
136
|
-
async settle(resourceId, stealthAddress, proof, hookData = []) {
|
|
137
|
-
return this.executeWrite("settle", [
|
|
138
|
-
resourceId,
|
|
139
|
-
stealthAddress,
|
|
140
|
-
proof.merkleTreeDepth,
|
|
141
|
-
proof.merkleTreeRoot,
|
|
142
|
-
proof.nullifier,
|
|
143
|
-
proof.message,
|
|
144
|
-
proof.points,
|
|
145
|
-
hookData
|
|
146
|
-
]);
|
|
147
|
-
}
|
|
148
|
-
/** True if `stealthAddress` has settled for `resourceId`. */
|
|
149
|
-
async isSettled(stealthAddress, resourceId) {
|
|
150
|
-
return this.publicClient.readContract({
|
|
151
|
-
address: this.contractAddress,
|
|
152
|
-
abi: SETTLEMENT_REGISTRY_ABI,
|
|
153
|
-
functionName: "isSettled",
|
|
154
|
-
args: [stealthAddress, resourceId]
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
/** Price of `resourceId` in the settlement token's smallest unit; 0 = free. */
|
|
158
|
-
async getPrice(resourceId) {
|
|
159
|
-
return this.publicClient.readContract({
|
|
160
|
-
address: this.contractAddress,
|
|
161
|
-
abi: SETTLEMENT_REGISTRY_ABI,
|
|
162
|
-
functionName: "getPrice",
|
|
163
|
-
args: [resourceId]
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
/** The id a `uid` will get under `publisher` — computable before listing. */
|
|
167
|
-
async resourceIdFor(publisher, uid) {
|
|
168
|
-
return this.publicClient.readContract({
|
|
169
|
-
address: this.contractAddress,
|
|
170
|
-
abi: SETTLEMENT_REGISTRY_ABI,
|
|
171
|
-
functionName: "resourceIdFor",
|
|
172
|
-
args: [publisher, uid]
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
/** Whether this identity commitment already joined the resource's group. */
|
|
176
|
-
async isRegistered(resourceId, identityCommitment) {
|
|
177
|
-
return this.publicClient.readContract({
|
|
178
|
-
address: this.contractAddress,
|
|
179
|
-
abi: SETTLEMENT_REGISTRY_ABI,
|
|
180
|
-
functionName: "isRegistered",
|
|
181
|
-
args: [resourceId, identityCommitment]
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
async getOwner(resourceId) {
|
|
185
|
-
return this.publicClient.readContract({
|
|
186
|
-
address: this.contractAddress,
|
|
187
|
-
abi: SETTLEMENT_REGISTRY_ABI,
|
|
188
|
-
functionName: "getOwner",
|
|
189
|
-
args: [resourceId]
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
async getGroupId(resourceId) {
|
|
193
|
-
return this.publicClient.readContract({
|
|
194
|
-
address: this.contractAddress,
|
|
195
|
-
abi: SETTLEMENT_REGISTRY_ABI,
|
|
196
|
-
functionName: "getGroupId",
|
|
197
|
-
args: [resourceId]
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
async getUri(resourceId) {
|
|
201
|
-
return this.publicClient.readContract({
|
|
202
|
-
address: this.contractAddress,
|
|
203
|
-
abi: SETTLEMENT_REGISTRY_ABI,
|
|
204
|
-
functionName: "getUri",
|
|
205
|
-
args: [resourceId]
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
async isDisabled(resourceId) {
|
|
209
|
-
return this.publicClient.readContract({
|
|
210
|
-
address: this.contractAddress,
|
|
211
|
-
abi: SETTLEMENT_REGISTRY_ABI,
|
|
212
|
-
functionName: "isDisabled",
|
|
213
|
-
args: [resourceId]
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Everything a listing page needs, in one round trip. An unlisted resource
|
|
218
|
-
* comes back with a zero owner rather than throwing — `getPrice` alone cannot
|
|
219
|
-
* tell "free" from "does not exist".
|
|
220
|
-
*/
|
|
221
|
-
async getResource(resourceId) {
|
|
222
|
-
const [owner, price, groupId, uri, disabled] = await Promise.all([
|
|
223
|
-
this.getOwner(resourceId),
|
|
224
|
-
this.getPrice(resourceId),
|
|
225
|
-
this.getGroupId(resourceId),
|
|
226
|
-
this.getUri(resourceId),
|
|
227
|
-
this.isDisabled(resourceId)
|
|
228
|
-
]);
|
|
229
|
-
return {
|
|
230
|
-
owner,
|
|
231
|
-
price,
|
|
232
|
-
groupId,
|
|
233
|
-
uri,
|
|
234
|
-
disabled
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
async getUsdc() {
|
|
238
|
-
return this.publicClient.readContract({
|
|
239
|
-
address: this.contractAddress,
|
|
240
|
-
abi: SETTLEMENT_REGISTRY_ABI,
|
|
241
|
-
functionName: "getUsdc"
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
async getSemaphore() {
|
|
245
|
-
return this.publicClient.readContract({
|
|
246
|
-
address: this.contractAddress,
|
|
247
|
-
abi: SETTLEMENT_REGISTRY_ABI,
|
|
248
|
-
functionName: "getSemaphore"
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
async getAdmin() {
|
|
252
|
-
return this.publicClient.readContract({
|
|
253
|
-
address: this.contractAddress,
|
|
254
|
-
abi: SETTLEMENT_REGISTRY_ABI,
|
|
255
|
-
functionName: "getAdmin"
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
async setAdmin(admin) {
|
|
259
|
-
return this.executeWrite("setAdmin", [admin]);
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
//#endregion
|
|
264
|
-
export { SettlementRegistryClient, packResourceUri, resourceIdOf };
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
//#region src/contracts/subscription-registry/abi.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* The SubscriptionRegistry: the publisher-side paywall for storage.
|
|
4
|
-
*
|
|
5
|
-
* A publisher pays a USDC fee to open or renew; the off-chain upload gate reads
|
|
6
|
-
* `access(publisher)` — `(registered, paidAt)` — and applies its own free-tier and
|
|
7
|
-
* active-window policy. The contract deliberately stores no expiry: the window is a
|
|
8
|
-
* policy decision the gate owns, so changing it does not need a migration.
|
|
9
|
-
*
|
|
10
|
-
* `registered` is a cross-call to the DataRegistry, so this contract never
|
|
11
|
-
* duplicates publisher registration; it only prices storage on top of it.
|
|
12
|
-
*
|
|
13
|
-
* Generated from `cargo stylus export-abi --json`; the events are appended by hand
|
|
14
|
-
* because export-abi does not emit `sol!` event definitions.
|
|
15
|
-
*/
|
|
16
|
-
declare const SUBSCRIPTION_REGISTRY_ABI: readonly [{
|
|
17
|
-
readonly inputs: readonly [{
|
|
18
|
-
readonly internalType: "address";
|
|
19
|
-
readonly name: "publisher";
|
|
20
|
-
readonly type: "address";
|
|
21
|
-
}];
|
|
22
|
-
readonly name: "access";
|
|
23
|
-
readonly outputs: readonly [{
|
|
24
|
-
readonly internalType: "bool";
|
|
25
|
-
readonly name: "";
|
|
26
|
-
readonly type: "bool";
|
|
27
|
-
}, {
|
|
28
|
-
readonly internalType: "uint64";
|
|
29
|
-
readonly name: "";
|
|
30
|
-
readonly type: "uint64";
|
|
31
|
-
}];
|
|
32
|
-
readonly stateMutability: "view";
|
|
33
|
-
readonly type: "function";
|
|
34
|
-
}, {
|
|
35
|
-
readonly inputs: readonly [];
|
|
36
|
-
readonly name: "admin";
|
|
37
|
-
readonly outputs: readonly [{
|
|
38
|
-
readonly internalType: "address";
|
|
39
|
-
readonly name: "";
|
|
40
|
-
readonly type: "address";
|
|
41
|
-
}];
|
|
42
|
-
readonly stateMutability: "view";
|
|
43
|
-
readonly type: "function";
|
|
44
|
-
}, {
|
|
45
|
-
readonly inputs: readonly [];
|
|
46
|
-
readonly name: "dataRegistry";
|
|
47
|
-
readonly outputs: readonly [{
|
|
48
|
-
readonly internalType: "address";
|
|
49
|
-
readonly name: "";
|
|
50
|
-
readonly type: "address";
|
|
51
|
-
}];
|
|
52
|
-
readonly stateMutability: "view";
|
|
53
|
-
readonly type: "function";
|
|
54
|
-
}, {
|
|
55
|
-
readonly inputs: readonly [{
|
|
56
|
-
readonly internalType: "address";
|
|
57
|
-
readonly name: "registry";
|
|
58
|
-
readonly type: "address";
|
|
59
|
-
}];
|
|
60
|
-
readonly name: "setDataRegistry";
|
|
61
|
-
readonly outputs: readonly [];
|
|
62
|
-
readonly stateMutability: "nonpayable";
|
|
63
|
-
readonly type: "function";
|
|
64
|
-
}, {
|
|
65
|
-
readonly inputs: readonly [{
|
|
66
|
-
readonly internalType: "uint256";
|
|
67
|
-
readonly name: "fee";
|
|
68
|
-
readonly type: "uint256";
|
|
69
|
-
}];
|
|
70
|
-
readonly name: "setSubscriptionFee";
|
|
71
|
-
readonly outputs: readonly [];
|
|
72
|
-
readonly stateMutability: "nonpayable";
|
|
73
|
-
readonly type: "function";
|
|
74
|
-
}, {
|
|
75
|
-
readonly inputs: readonly [{
|
|
76
|
-
readonly internalType: "address";
|
|
77
|
-
readonly name: "token";
|
|
78
|
-
readonly type: "address";
|
|
79
|
-
}];
|
|
80
|
-
readonly name: "setUsdc";
|
|
81
|
-
readonly outputs: readonly [];
|
|
82
|
-
readonly stateMutability: "nonpayable";
|
|
83
|
-
readonly type: "function";
|
|
84
|
-
}, {
|
|
85
|
-
readonly inputs: readonly [];
|
|
86
|
-
readonly name: "subscribe";
|
|
87
|
-
readonly outputs: readonly [];
|
|
88
|
-
readonly stateMutability: "nonpayable";
|
|
89
|
-
readonly type: "function";
|
|
90
|
-
}, {
|
|
91
|
-
readonly inputs: readonly [{
|
|
92
|
-
readonly internalType: "address";
|
|
93
|
-
readonly name: "publisher";
|
|
94
|
-
readonly type: "address";
|
|
95
|
-
}];
|
|
96
|
-
readonly name: "subscribedAt";
|
|
97
|
-
readonly outputs: readonly [{
|
|
98
|
-
readonly internalType: "uint64";
|
|
99
|
-
readonly name: "";
|
|
100
|
-
readonly type: "uint64";
|
|
101
|
-
}];
|
|
102
|
-
readonly stateMutability: "view";
|
|
103
|
-
readonly type: "function";
|
|
104
|
-
}, {
|
|
105
|
-
readonly inputs: readonly [];
|
|
106
|
-
readonly name: "subscriptionFee";
|
|
107
|
-
readonly outputs: readonly [{
|
|
108
|
-
readonly internalType: "uint256";
|
|
109
|
-
readonly name: "";
|
|
110
|
-
readonly type: "uint256";
|
|
111
|
-
}];
|
|
112
|
-
readonly stateMutability: "view";
|
|
113
|
-
readonly type: "function";
|
|
114
|
-
}, {
|
|
115
|
-
readonly inputs: readonly [];
|
|
116
|
-
readonly name: "usdc";
|
|
117
|
-
readonly outputs: readonly [{
|
|
118
|
-
readonly internalType: "address";
|
|
119
|
-
readonly name: "";
|
|
120
|
-
readonly type: "address";
|
|
121
|
-
}];
|
|
122
|
-
readonly stateMutability: "view";
|
|
123
|
-
readonly type: "function";
|
|
124
|
-
}, {
|
|
125
|
-
readonly inputs: readonly [{
|
|
126
|
-
readonly internalType: "address";
|
|
127
|
-
readonly name: "to";
|
|
128
|
-
readonly type: "address";
|
|
129
|
-
}, {
|
|
130
|
-
readonly internalType: "uint256";
|
|
131
|
-
readonly name: "amount";
|
|
132
|
-
readonly type: "uint256";
|
|
133
|
-
}];
|
|
134
|
-
readonly name: "withdrawEth";
|
|
135
|
-
readonly outputs: readonly [];
|
|
136
|
-
readonly stateMutability: "nonpayable";
|
|
137
|
-
readonly type: "function";
|
|
138
|
-
}, {
|
|
139
|
-
readonly inputs: readonly [{
|
|
140
|
-
readonly internalType: "address";
|
|
141
|
-
readonly name: "to";
|
|
142
|
-
readonly type: "address";
|
|
143
|
-
}, {
|
|
144
|
-
readonly internalType: "uint256";
|
|
145
|
-
readonly name: "amount";
|
|
146
|
-
readonly type: "uint256";
|
|
147
|
-
}];
|
|
148
|
-
readonly name: "withdrawUsdc";
|
|
149
|
-
readonly outputs: readonly [];
|
|
150
|
-
readonly stateMutability: "nonpayable";
|
|
151
|
-
readonly type: "function";
|
|
152
|
-
}, {
|
|
153
|
-
readonly type: "event";
|
|
154
|
-
readonly name: "Subscribed";
|
|
155
|
-
readonly anonymous: false;
|
|
156
|
-
readonly inputs: readonly [{
|
|
157
|
-
readonly type: "address";
|
|
158
|
-
readonly name: "publisher";
|
|
159
|
-
readonly internalType: "address";
|
|
160
|
-
readonly indexed: true;
|
|
161
|
-
}, {
|
|
162
|
-
readonly type: "uint64";
|
|
163
|
-
readonly name: "paidAt";
|
|
164
|
-
readonly internalType: "uint64";
|
|
165
|
-
readonly indexed: false;
|
|
166
|
-
}];
|
|
167
|
-
}, {
|
|
168
|
-
readonly type: "event";
|
|
169
|
-
readonly name: "SubscriptionFeeChanged";
|
|
170
|
-
readonly anonymous: false;
|
|
171
|
-
readonly inputs: readonly [{
|
|
172
|
-
readonly type: "uint256";
|
|
173
|
-
readonly name: "fee";
|
|
174
|
-
readonly internalType: "uint256";
|
|
175
|
-
readonly indexed: false;
|
|
176
|
-
}];
|
|
177
|
-
}];
|
|
178
|
-
//#endregion
|
|
179
|
-
export { SUBSCRIPTION_REGISTRY_ABI };
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
//#region src/contracts/subscription-registry/abi.ts
|
|
2
|
-
/**
|
|
3
|
-
* The SubscriptionRegistry: the publisher-side paywall for storage.
|
|
4
|
-
*
|
|
5
|
-
* A publisher pays a USDC fee to open or renew; the off-chain upload gate reads
|
|
6
|
-
* `access(publisher)` — `(registered, paidAt)` — and applies its own free-tier and
|
|
7
|
-
* active-window policy. The contract deliberately stores no expiry: the window is a
|
|
8
|
-
* policy decision the gate owns, so changing it does not need a migration.
|
|
9
|
-
*
|
|
10
|
-
* `registered` is a cross-call to the DataRegistry, so this contract never
|
|
11
|
-
* duplicates publisher registration; it only prices storage on top of it.
|
|
12
|
-
*
|
|
13
|
-
* Generated from `cargo stylus export-abi --json`; the events are appended by hand
|
|
14
|
-
* because export-abi does not emit `sol!` event definitions.
|
|
15
|
-
*/
|
|
16
|
-
const SUBSCRIPTION_REGISTRY_ABI = [
|
|
17
|
-
{
|
|
18
|
-
"inputs": [{
|
|
19
|
-
"internalType": "address",
|
|
20
|
-
"name": "publisher",
|
|
21
|
-
"type": "address"
|
|
22
|
-
}],
|
|
23
|
-
"name": "access",
|
|
24
|
-
"outputs": [{
|
|
25
|
-
"internalType": "bool",
|
|
26
|
-
"name": "",
|
|
27
|
-
"type": "bool"
|
|
28
|
-
}, {
|
|
29
|
-
"internalType": "uint64",
|
|
30
|
-
"name": "",
|
|
31
|
-
"type": "uint64"
|
|
32
|
-
}],
|
|
33
|
-
"stateMutability": "view",
|
|
34
|
-
"type": "function"
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"inputs": [],
|
|
38
|
-
"name": "admin",
|
|
39
|
-
"outputs": [{
|
|
40
|
-
"internalType": "address",
|
|
41
|
-
"name": "",
|
|
42
|
-
"type": "address"
|
|
43
|
-
}],
|
|
44
|
-
"stateMutability": "view",
|
|
45
|
-
"type": "function"
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
"inputs": [],
|
|
49
|
-
"name": "dataRegistry",
|
|
50
|
-
"outputs": [{
|
|
51
|
-
"internalType": "address",
|
|
52
|
-
"name": "",
|
|
53
|
-
"type": "address"
|
|
54
|
-
}],
|
|
55
|
-
"stateMutability": "view",
|
|
56
|
-
"type": "function"
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"inputs": [{
|
|
60
|
-
"internalType": "address",
|
|
61
|
-
"name": "registry",
|
|
62
|
-
"type": "address"
|
|
63
|
-
}],
|
|
64
|
-
"name": "setDataRegistry",
|
|
65
|
-
"outputs": [],
|
|
66
|
-
"stateMutability": "nonpayable",
|
|
67
|
-
"type": "function"
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
"inputs": [{
|
|
71
|
-
"internalType": "uint256",
|
|
72
|
-
"name": "fee",
|
|
73
|
-
"type": "uint256"
|
|
74
|
-
}],
|
|
75
|
-
"name": "setSubscriptionFee",
|
|
76
|
-
"outputs": [],
|
|
77
|
-
"stateMutability": "nonpayable",
|
|
78
|
-
"type": "function"
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
"inputs": [{
|
|
82
|
-
"internalType": "address",
|
|
83
|
-
"name": "token",
|
|
84
|
-
"type": "address"
|
|
85
|
-
}],
|
|
86
|
-
"name": "setUsdc",
|
|
87
|
-
"outputs": [],
|
|
88
|
-
"stateMutability": "nonpayable",
|
|
89
|
-
"type": "function"
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
"inputs": [],
|
|
93
|
-
"name": "subscribe",
|
|
94
|
-
"outputs": [],
|
|
95
|
-
"stateMutability": "nonpayable",
|
|
96
|
-
"type": "function"
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"inputs": [{
|
|
100
|
-
"internalType": "address",
|
|
101
|
-
"name": "publisher",
|
|
102
|
-
"type": "address"
|
|
103
|
-
}],
|
|
104
|
-
"name": "subscribedAt",
|
|
105
|
-
"outputs": [{
|
|
106
|
-
"internalType": "uint64",
|
|
107
|
-
"name": "",
|
|
108
|
-
"type": "uint64"
|
|
109
|
-
}],
|
|
110
|
-
"stateMutability": "view",
|
|
111
|
-
"type": "function"
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
"inputs": [],
|
|
115
|
-
"name": "subscriptionFee",
|
|
116
|
-
"outputs": [{
|
|
117
|
-
"internalType": "uint256",
|
|
118
|
-
"name": "",
|
|
119
|
-
"type": "uint256"
|
|
120
|
-
}],
|
|
121
|
-
"stateMutability": "view",
|
|
122
|
-
"type": "function"
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
"inputs": [],
|
|
126
|
-
"name": "usdc",
|
|
127
|
-
"outputs": [{
|
|
128
|
-
"internalType": "address",
|
|
129
|
-
"name": "",
|
|
130
|
-
"type": "address"
|
|
131
|
-
}],
|
|
132
|
-
"stateMutability": "view",
|
|
133
|
-
"type": "function"
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
"inputs": [{
|
|
137
|
-
"internalType": "address",
|
|
138
|
-
"name": "to",
|
|
139
|
-
"type": "address"
|
|
140
|
-
}, {
|
|
141
|
-
"internalType": "uint256",
|
|
142
|
-
"name": "amount",
|
|
143
|
-
"type": "uint256"
|
|
144
|
-
}],
|
|
145
|
-
"name": "withdrawEth",
|
|
146
|
-
"outputs": [],
|
|
147
|
-
"stateMutability": "nonpayable",
|
|
148
|
-
"type": "function"
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
"inputs": [{
|
|
152
|
-
"internalType": "address",
|
|
153
|
-
"name": "to",
|
|
154
|
-
"type": "address"
|
|
155
|
-
}, {
|
|
156
|
-
"internalType": "uint256",
|
|
157
|
-
"name": "amount",
|
|
158
|
-
"type": "uint256"
|
|
159
|
-
}],
|
|
160
|
-
"name": "withdrawUsdc",
|
|
161
|
-
"outputs": [],
|
|
162
|
-
"stateMutability": "nonpayable",
|
|
163
|
-
"type": "function"
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
"type": "event",
|
|
167
|
-
"name": "Subscribed",
|
|
168
|
-
"anonymous": false,
|
|
169
|
-
"inputs": [{
|
|
170
|
-
"type": "address",
|
|
171
|
-
"name": "publisher",
|
|
172
|
-
"internalType": "address",
|
|
173
|
-
"indexed": true
|
|
174
|
-
}, {
|
|
175
|
-
"type": "uint64",
|
|
176
|
-
"name": "paidAt",
|
|
177
|
-
"internalType": "uint64",
|
|
178
|
-
"indexed": false
|
|
179
|
-
}]
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
"type": "event",
|
|
183
|
-
"name": "SubscriptionFeeChanged",
|
|
184
|
-
"anonymous": false,
|
|
185
|
-
"inputs": [{
|
|
186
|
-
"type": "uint256",
|
|
187
|
-
"name": "fee",
|
|
188
|
-
"internalType": "uint256",
|
|
189
|
-
"indexed": false
|
|
190
|
-
}]
|
|
191
|
-
}
|
|
192
|
-
];
|
|
193
|
-
|
|
194
|
-
//#endregion
|
|
195
|
-
export { SUBSCRIPTION_REGISTRY_ABI };
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Address, Hash, PublicClient, WalletClient } from "viem";
|
|
2
|
-
|
|
3
|
-
//#region src/contracts/subscription-registry/index.d.ts
|
|
4
|
-
/** What the upload gate needs to decide whether to serve a publisher. */
|
|
5
|
-
interface SubscriptionAccess {
|
|
6
|
-
/** Registered in the DataRegistry. Read here via cross-call, so it is never stale. */
|
|
7
|
-
registered: boolean;
|
|
8
|
-
/** Unix seconds of the last payment, or 0 if they never subscribed. */
|
|
9
|
-
paidAt: bigint;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Client for the SubscriptionRegistry — the publisher-side storage paywall.
|
|
13
|
-
*
|
|
14
|
-
* Deliberately does NOT decide whether a subscription is currently valid. The
|
|
15
|
-
* contract stores only when it was last paid; the active window and any free tier
|
|
16
|
-
* are the gate's policy, and keeping them off-chain means changing them is a config
|
|
17
|
-
* edit rather than a redeploy. `isActiveAt` is offered as the obvious default, with
|
|
18
|
-
* the window passed in.
|
|
19
|
-
*/
|
|
20
|
-
declare class SubscriptionRegistryClient {
|
|
21
|
-
private contractAddress;
|
|
22
|
-
private publicClient;
|
|
23
|
-
private walletClient?;
|
|
24
|
-
constructor(contractAddress: Address, publicClient: PublicClient, walletClient?: WalletClient | undefined);
|
|
25
|
-
getAddress(): Address;
|
|
26
|
-
private executeWrite;
|
|
27
|
-
/**
|
|
28
|
-
* Open or renew this wallet's subscription.
|
|
29
|
-
*
|
|
30
|
-
* The fee is pulled in USDC, so the caller must have `approve`d this contract
|
|
31
|
-
* for at least `subscriptionFee()` first — otherwise the call reverts
|
|
32
|
-
* `SubscriptionFeeRequired`, which reads like a pricing error but is really an
|
|
33
|
-
* allowance one. Renewing while still active is allowed and simply re-stamps
|
|
34
|
-
* the timestamp, so there is no window to lose by renewing early.
|
|
35
|
-
*/
|
|
36
|
-
subscribe(): Promise<Hash>;
|
|
37
|
-
/** The single oracle the upload gate reads. */
|
|
38
|
-
access(publisher: Address): Promise<SubscriptionAccess>;
|
|
39
|
-
/**
|
|
40
|
-
* Registered, paid, and inside `windowSeconds` of that payment — the whole
|
|
41
|
-
* gate policy in one call. `now` is injectable so a caller can evaluate against
|
|
42
|
-
* block time rather than wall-clock skew.
|
|
43
|
-
*/
|
|
44
|
-
isActiveAt(publisher: Address, windowSeconds: bigint, now?: bigint): Promise<boolean>;
|
|
45
|
-
subscribedAt(publisher: Address): Promise<bigint>;
|
|
46
|
-
/** The fee in USDC's smallest unit (6 decimals), not wei. */
|
|
47
|
-
subscriptionFee(): Promise<bigint>;
|
|
48
|
-
usdc(): Promise<Address>;
|
|
49
|
-
/** The DataRegistry this contract cross-calls for `isRegistered`. */
|
|
50
|
-
dataRegistry(): Promise<Address>;
|
|
51
|
-
admin(): Promise<Address>;
|
|
52
|
-
setSubscriptionFee(fee: bigint): Promise<Hash>;
|
|
53
|
-
setUsdc(token: Address): Promise<Hash>;
|
|
54
|
-
setDataRegistry(registry: Address): Promise<Hash>;
|
|
55
|
-
withdrawUsdc(to: Address, amount: bigint): Promise<Hash>;
|
|
56
|
-
withdrawEth(to: Address, amount: bigint): Promise<Hash>;
|
|
57
|
-
}
|
|
58
|
-
//#endregion
|
|
59
|
-
export { SubscriptionAccess, SubscriptionRegistryClient };
|