@fangorn-network/sdk 2026.10.27-dev → 2026.11.3-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 +36 -642
- package/lib/cli/cli.js +47 -322
- package/lib/cli/index.d.ts +1 -4
- package/lib/cli/index.js +2 -20
- package/lib/config.d.ts +15 -78
- package/lib/config.js +8 -35
- package/lib/contracts/data-registry/abi.d.ts +195 -19
- package/lib/contracts/data-registry/abi.js +223 -20
- package/lib/contracts/data-registry/index.d.ts +126 -2
- package/lib/contracts/data-registry/index.js +174 -1
- package/lib/contracts/index.d.ts +5 -8
- package/lib/contracts/index.js +4 -7
- package/lib/contracts/logs.d.ts +1 -1
- package/lib/contracts/logs.js +1 -1
- package/lib/contracts/{membership-registry → settlement-registry}/abi.d.ts +288 -637
- package/lib/contracts/{membership-registry → settlement-registry}/abi.js +326 -712
- package/lib/contracts/settlement-registry/index.d.ts +141 -0
- package/lib/contracts/settlement-registry/index.js +209 -0
- package/lib/crypto/aes.d.ts +2 -2
- package/lib/crypto/aes.js +4 -4
- package/lib/crypto/encryption.d.ts +8 -109
- package/lib/crypto/encryption.js +16 -114
- package/lib/crypto/paid.d.ts +104 -0
- package/lib/crypto/paid.js +147 -0
- package/lib/engine/index.d.ts +23 -12
- package/lib/engine/index.js +68 -29
- package/lib/engine/records.d.ts +4 -7
- package/lib/engine/records.js +6 -6
- package/lib/engine/test-helpers.d.ts +2 -3
- package/lib/engine/test-helpers.js +7 -5
- package/lib/erc8004.js +1 -4
- package/lib/fangorn.d.ts +64 -85
- package/lib/fangorn.js +106 -148
- package/lib/feed.d.ts +7 -8
- package/lib/feed.js +7 -8
- package/lib/index.d.ts +10 -14
- package/lib/index.js +9 -13
- package/lib/providers/storage/signed-url.d.ts +2 -10
- package/lib/providers/storage/signed-url.js +4 -14
- package/lib/providers/storage/types.d.ts +1 -1
- package/lib/providers/storage/utils.js +5 -3
- package/lib/test/key-server.d.ts +12 -0
- package/lib/test/key-server.js +30 -0
- package/lib/test/mem-registry.d.ts +14 -19
- package/lib/test/mem-registry.js +44 -37
- package/lib/test/sdk-suite.d.ts +1 -4
- package/lib/test/sdk-suite.js +16 -87
- package/lib/test/testbed.d.ts +5216 -5226
- package/lib/test/testbed.js +29 -56
- package/lib/types/index.d.ts +6 -11
- package/package.json +1 -4
- package/lib/contracts/app-registry/abi.d.ts +0 -1317
- package/lib/contracts/app-registry/abi.js +0 -1510
- package/lib/contracts/app-registry/index.d.ts +0 -173
- package/lib/contracts/app-registry/index.js +0 -294
- package/lib/contracts/membership-registry/index.d.ts +0 -79
- package/lib/contracts/membership-registry/index.js +0 -104
- package/lib/contracts/types.d.ts +0 -10
- package/lib/contracts/types.js +0 -12
- package/lib/harness/examples/hackmd/build-markdown-graph.d.ts +0 -1
- package/lib/harness/examples/hackmd/build-markdown-graph.js +0 -17
- package/lib/harness/index.d.ts +0 -58
- package/lib/harness/index.js +0 -73
- package/lib/registry.d.ts +0 -118
- package/lib/registry.js +0 -184
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { PublisherStatus } from "../types.js";
|
|
2
|
-
import { PreparedTx } from "../write.js";
|
|
3
|
-
import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
|
|
4
|
-
|
|
5
|
-
//#region src/contracts/app-registry/index.d.ts
|
|
6
|
-
/** What the upload gate needs to decide whether to serve a publisher under an app. */
|
|
7
|
-
interface AppAccess {
|
|
8
|
-
/** May publish to the app now (see `canPublish`). */
|
|
9
|
-
canPublish: boolean;
|
|
10
|
-
/** The app's owner, or the zero address for an unclaimed app. */
|
|
11
|
-
owner: Address;
|
|
12
|
-
/** Unix seconds the app's subscription expires at; 0 if unclaimed or cancelled. */
|
|
13
|
-
expiresAt: bigint;
|
|
14
|
-
}
|
|
15
|
-
/** One `AppAgentChanged` event: an app owner pointed their app at a card. */
|
|
16
|
-
interface AppAgentLog {
|
|
17
|
-
appId: Hex;
|
|
18
|
-
agentUri: string;
|
|
19
|
-
blockNumber: bigint;
|
|
20
|
-
transactionHash: Hash;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Client for the AppRegistry's app management: apps and their ERC-5643
|
|
24
|
-
* subscriptions, the publishers each app accepts, the agent card, and the
|
|
25
|
-
* protocol admin's powers. What an app presents — its members, less exclusions — is
|
|
26
|
-
* read through the registry (`ChainRegistry`), not this client.
|
|
27
|
-
*
|
|
28
|
-
* Scoped to one app, which may be unset: then only the calls that take no app work.
|
|
29
|
-
*/
|
|
30
|
-
declare class AppRegistryClient {
|
|
31
|
-
private contractAddress;
|
|
32
|
-
private appId;
|
|
33
|
-
private publicClient;
|
|
34
|
-
private walletClient;
|
|
35
|
-
private logWindow?;
|
|
36
|
-
constructor(contractAddress: Address, appId: Hex | undefined, publicClient: PublicClient, walletClient: WalletClient, logWindow?: bigint | undefined);
|
|
37
|
-
getAppId(): Hex | undefined;
|
|
38
|
-
setAppId(appId: Hex | undefined): void;
|
|
39
|
-
getAddress(): Address;
|
|
40
|
-
/** This client's app, or a clear error for a call that needs one. */
|
|
41
|
-
private app;
|
|
42
|
-
/** The app's subscription token: an app's token id is its app id. */
|
|
43
|
-
tokenId(appId?: Hex): bigint;
|
|
44
|
-
private executeWrite;
|
|
45
|
-
private read;
|
|
46
|
-
/**
|
|
47
|
-
* Claim this app, if nobody has. Claiming IS subscribing: it pays one period
|
|
48
|
-
* of `subscriptionFee()` in USDC and mints the app's token to the caller,
|
|
49
|
-
* who becomes the app's first accepted publisher.
|
|
50
|
-
*
|
|
51
|
-
* The fee read now is approved and passed as the most the claim may cost,
|
|
52
|
-
* so a fee raised in the meantime makes the claim revert instead of charging
|
|
53
|
-
* more.
|
|
54
|
-
*/
|
|
55
|
-
registerApp(): Promise<Hash>;
|
|
56
|
-
/**
|
|
57
|
-
* Pay for one more period (the owner, or an address they approved for the
|
|
58
|
-
* app's token). Allowed once less than a period is left; the period is added
|
|
59
|
-
* to the current expiry, or to now if it has passed.
|
|
60
|
-
*
|
|
61
|
-
* The standard gives the contract no maximum-fee argument, so the allowance
|
|
62
|
-
* is the cap: exactly the fee read now is approved.
|
|
63
|
-
*/
|
|
64
|
-
renewSubscription(): Promise<Hash>;
|
|
65
|
-
/**
|
|
66
|
-
* End this app's subscription now (owner only): the expiry becomes zero and
|
|
67
|
-
* nothing is refunded. Until it is renewed the app provides no storage and includes nothing.
|
|
68
|
-
*/
|
|
69
|
-
cancelSubscription(): Promise<Hash>;
|
|
70
|
-
/** Unix seconds this app's subscription expires at; 0 once cancelled. Reverts for an unclaimed app. */
|
|
71
|
-
expiresAt(appId?: Hex): Promise<bigint>;
|
|
72
|
-
/** True while less than one period is left, or the subscription has expired. */
|
|
73
|
-
isRenewable(): Promise<boolean>;
|
|
74
|
-
/** How long one payment lasts, in seconds. */
|
|
75
|
-
subscriptionPeriod(): Promise<bigint>;
|
|
76
|
-
/** What claiming or renewing an app costs, in USDC base units (6 decimals), not wei. */
|
|
77
|
-
subscriptionFee(): Promise<bigint>;
|
|
78
|
-
/** The ERC-20 token (USDC) every fee is paid in. */
|
|
79
|
-
usdc(): Promise<Address>;
|
|
80
|
-
getAppOwner(appId?: Hex): Promise<Address>;
|
|
81
|
-
/** How many apps have been claimed. */
|
|
82
|
-
appCount(): Promise<bigint>;
|
|
83
|
-
/** Up to `limit` app ids from position `offset`, oldest first; fewer past the end. */
|
|
84
|
-
appsPage(offset: bigint, limit: bigint): Promise<readonly Hex[]>;
|
|
85
|
-
/**
|
|
86
|
-
* Every claimed app id, oldest first.
|
|
87
|
-
* ponytail: one eth_call for all of them; page with `appsPage` once the list
|
|
88
|
-
* outgrows the RPC's eth_call gas cap (tens of thousands of apps).
|
|
89
|
-
*/
|
|
90
|
-
allApps(): Promise<readonly Hex[]>;
|
|
91
|
-
/** The app ids `owner` claimed, oldest first. */
|
|
92
|
-
appsOf(owner: Address): Promise<readonly Hex[]>;
|
|
93
|
-
/**
|
|
94
|
-
* Point this app at its ERC-8004 agent card.
|
|
95
|
-
*
|
|
96
|
-
* Safe to call whenever the card moves: it leaves the app's publishers alone.
|
|
97
|
-
*/
|
|
98
|
-
setAppAgentUri(agentUri: string): Promise<Hash>;
|
|
99
|
-
/** Send the join fees the caller is still owed, from the old join flow, to `to`. */
|
|
100
|
-
withdrawJoinFees(to?: Address): Promise<Hash>;
|
|
101
|
-
/** Join fees still owed to `owner` from the old join flow, in USDC base units. Nothing adds to it. */
|
|
102
|
-
joinFeesOwed(owner?: Address): Promise<bigint>;
|
|
103
|
-
isAppSuspended(): Promise<boolean>;
|
|
104
|
-
/** The agent card URI of this app, or of `appId`. Empty if none is set. */
|
|
105
|
-
appAgentUri(appId?: Hex): Promise<string>;
|
|
106
|
-
/**
|
|
107
|
-
* Accept a publisher into this app (owner only). That is the whole
|
|
108
|
-
* membership: from here it uploads with storage the app provides, and the app
|
|
109
|
-
* includes its data, while `canPublish` holds. A suspended publisher comes
|
|
110
|
-
* back with `setPublisherSuspended(publisher, false)`.
|
|
111
|
-
*/
|
|
112
|
-
acceptPublisher(publisher: Address): Promise<Hash>;
|
|
113
|
-
/**
|
|
114
|
-
* Suspend an accepted publisher from this app, or reinstate them (owner
|
|
115
|
-
* only). An owner cannot suspend themselves.
|
|
116
|
-
*/
|
|
117
|
-
setPublisherSuspended(publisher: Address, suspended: boolean): Promise<Hash>;
|
|
118
|
-
/** `publisher`'s standing in this app. */
|
|
119
|
-
status(publisher: Address): Promise<PublisherStatus>;
|
|
120
|
-
/**
|
|
121
|
-
* May `publisher` publish to this app now: accepted and not suspended, not
|
|
122
|
-
* banned network-wide, and the app is live and paid up.
|
|
123
|
-
*/
|
|
124
|
-
canPublish(publisher: Address, appId?: Hex): Promise<boolean>;
|
|
125
|
-
/** The single oracle the upload gate reads for one publisher under this app. */
|
|
126
|
-
access(publisher: Address, appId?: Hex): Promise<AppAccess>;
|
|
127
|
-
/**
|
|
128
|
-
* `AppAgentChanged` events, oldest first. The last one for an app is its
|
|
129
|
-
* current card; an empty `agentUri` means the owner unset it.
|
|
130
|
-
*
|
|
131
|
-
* Leave `appId` out to list every app that has ever set a card. To list apps,
|
|
132
|
-
* use `allApps` or `appsOf`, which are one read each; this is a windowed log
|
|
133
|
-
* scan, for a card's history. `fromBlock` is required because scanning from genesis on an L2 costs
|
|
134
|
-
* hundreds of thousands of RPC calls. Pass the AppRegistry's deploy block, or
|
|
135
|
-
* a block you know to be before the app's registration.
|
|
136
|
-
*/
|
|
137
|
-
getAppAgentLogs(opts: {
|
|
138
|
-
appId?: Hex;
|
|
139
|
-
fromBlock: bigint;
|
|
140
|
-
toBlock?: bigint;
|
|
141
|
-
}): Promise<AppAgentLog[]>;
|
|
142
|
-
admin(): Promise<Address>;
|
|
143
|
-
/** The DataRegistry this contract names. */
|
|
144
|
-
dataRegistry(): Promise<Address>;
|
|
145
|
-
/** Whether the protocol admin has banned `wallet` network-wide. */
|
|
146
|
-
isGloballySuspended(wallet: Address): Promise<boolean>;
|
|
147
|
-
/**
|
|
148
|
-
* Ban `wallet` network-wide, or lift the ban. A banned wallet cannot claim an
|
|
149
|
-
* app or be accepted into one, and no app stores or includes it; a banned
|
|
150
|
-
* owner's app keeps running, but they cannot accept anyone or move its agent card.
|
|
151
|
-
*/
|
|
152
|
-
setGlobalSuspension(wallet: Address, suspended: boolean): Promise<Hash>;
|
|
153
|
-
/** Take this app down for every publisher at once, or restore it. */
|
|
154
|
-
setAppSuspended(suspended: boolean): Promise<Hash>;
|
|
155
|
-
setDataRegistry(registry: Address): Promise<Hash>;
|
|
156
|
-
setSubscriptionFee(fee: bigint): Promise<Hash>;
|
|
157
|
-
/** Applies from each app's next payment. */
|
|
158
|
-
setSubscriptionPeriod(period: bigint): Promise<Hash>;
|
|
159
|
-
/**
|
|
160
|
-
* Send `amount` of `token` to `to`. Of USDC, only the protocol's share: what
|
|
161
|
-
* app owners are owed in join fees stays (`ExceedsProtocolBalance`).
|
|
162
|
-
*/
|
|
163
|
-
withdrawToken(token: Address, to: Address, amount: bigint): Promise<Hash>;
|
|
164
|
-
/**
|
|
165
|
-
* Fees are pulled with `transferFrom`, so the registry needs an allowance.
|
|
166
|
-
* Without one the call reverts with a fee error that reads like a pricing
|
|
167
|
-
* problem but is really an allowance one. Approves exactly `amount`.
|
|
168
|
-
*/
|
|
169
|
-
private approveUsdc;
|
|
170
|
-
private senderAddress;
|
|
171
|
-
}
|
|
172
|
-
//#endregion
|
|
173
|
-
export { AppAccess, AppAgentLog, AppRegistryClient, type PreparedTx };
|
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
import { APP_REGISTRY_ABI } from "./abi.js";
|
|
2
|
-
import { requireWallet, sendWrite } from "../write.js";
|
|
3
|
-
import { getLogsInWindows } from "../logs.js";
|
|
4
|
-
import { erc20Abi, hexToBigInt } from "viem";
|
|
5
|
-
|
|
6
|
-
//#region src/contracts/app-registry/index.ts
|
|
7
|
-
/**
|
|
8
|
-
* Client for the AppRegistry's app management: apps and their ERC-5643
|
|
9
|
-
* subscriptions, the publishers each app accepts, the agent card, and the
|
|
10
|
-
* protocol admin's powers. What an app presents — its members, less exclusions — is
|
|
11
|
-
* read through the registry (`ChainRegistry`), not this client.
|
|
12
|
-
*
|
|
13
|
-
* Scoped to one app, which may be unset: then only the calls that take no app work.
|
|
14
|
-
*/
|
|
15
|
-
var AppRegistryClient = class {
|
|
16
|
-
constructor(contractAddress, appId, publicClient, walletClient, logWindow) {
|
|
17
|
-
this.contractAddress = contractAddress;
|
|
18
|
-
this.appId = appId;
|
|
19
|
-
this.publicClient = publicClient;
|
|
20
|
-
this.walletClient = walletClient;
|
|
21
|
-
this.logWindow = logWindow;
|
|
22
|
-
}
|
|
23
|
-
getAppId() {
|
|
24
|
-
return this.appId;
|
|
25
|
-
}
|
|
26
|
-
setAppId(appId) {
|
|
27
|
-
this.appId = appId;
|
|
28
|
-
}
|
|
29
|
-
getAddress() {
|
|
30
|
-
return this.contractAddress;
|
|
31
|
-
}
|
|
32
|
-
/** This client's app, or a clear error for a call that needs one. */
|
|
33
|
-
app() {
|
|
34
|
-
if (!this.appId) throw new Error("no app chosen: pass `appId` to Fangorn.create() or call setAppId()");
|
|
35
|
-
return this.appId;
|
|
36
|
-
}
|
|
37
|
-
/** The app's subscription token: an app's token id is its app id. */
|
|
38
|
-
tokenId(appId = this.app()) {
|
|
39
|
-
return hexToBigInt(appId);
|
|
40
|
-
}
|
|
41
|
-
executeWrite(functionName, args) {
|
|
42
|
-
return sendWrite(this.publicClient, requireWallet(this.walletClient, functionName), this.contractAddress, APP_REGISTRY_ABI, functionName, args);
|
|
43
|
-
}
|
|
44
|
-
read(functionName, args) {
|
|
45
|
-
return this.publicClient.readContract({
|
|
46
|
-
address: this.contractAddress,
|
|
47
|
-
abi: APP_REGISTRY_ABI,
|
|
48
|
-
functionName,
|
|
49
|
-
args
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Claim this app, if nobody has. Claiming IS subscribing: it pays one period
|
|
54
|
-
* of `subscriptionFee()` in USDC and mints the app's token to the caller,
|
|
55
|
-
* who becomes the app's first accepted publisher.
|
|
56
|
-
*
|
|
57
|
-
* The fee read now is approved and passed as the most the claim may cost,
|
|
58
|
-
* so a fee raised in the meantime makes the claim revert instead of charging
|
|
59
|
-
* more.
|
|
60
|
-
*/
|
|
61
|
-
async registerApp() {
|
|
62
|
-
const fee = await this.subscriptionFee();
|
|
63
|
-
await this.approveUsdc(fee);
|
|
64
|
-
return this.executeWrite("registerApp", [this.app(), fee]);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Pay for one more period (the owner, or an address they approved for the
|
|
68
|
-
* app's token). Allowed once less than a period is left; the period is added
|
|
69
|
-
* to the current expiry, or to now if it has passed.
|
|
70
|
-
*
|
|
71
|
-
* The standard gives the contract no maximum-fee argument, so the allowance
|
|
72
|
-
* is the cap: exactly the fee read now is approved.
|
|
73
|
-
*/
|
|
74
|
-
async renewSubscription() {
|
|
75
|
-
const [renewable, period, fee] = await Promise.all([
|
|
76
|
-
this.isRenewable(),
|
|
77
|
-
this.subscriptionPeriod(),
|
|
78
|
-
this.subscriptionFee()
|
|
79
|
-
]);
|
|
80
|
-
if (!renewable) {
|
|
81
|
-
const expiry = await this.expiresAt();
|
|
82
|
-
throw new Error(`app ${this.app()} cannot be renewed until less than one period is left — it expires ${(/* @__PURE__ */ new Date(Number(expiry) * 1e3)).toISOString()}`);
|
|
83
|
-
}
|
|
84
|
-
await this.approveUsdc(fee);
|
|
85
|
-
return this.executeWrite("renewSubscription", [this.tokenId(), period]);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* End this app's subscription now (owner only): the expiry becomes zero and
|
|
89
|
-
* nothing is refunded. Until it is renewed the app provides no storage and includes nothing.
|
|
90
|
-
*/
|
|
91
|
-
async cancelSubscription() {
|
|
92
|
-
return this.executeWrite("cancelSubscription", [this.tokenId()]);
|
|
93
|
-
}
|
|
94
|
-
/** Unix seconds this app's subscription expires at; 0 once cancelled. Reverts for an unclaimed app. */
|
|
95
|
-
async expiresAt(appId = this.app()) {
|
|
96
|
-
return this.read("expiresAt", [this.tokenId(appId)]);
|
|
97
|
-
}
|
|
98
|
-
/** True while less than one period is left, or the subscription has expired. */
|
|
99
|
-
async isRenewable() {
|
|
100
|
-
return this.read("isRenewable", [this.tokenId()]);
|
|
101
|
-
}
|
|
102
|
-
/** How long one payment lasts, in seconds. */
|
|
103
|
-
async subscriptionPeriod() {
|
|
104
|
-
return this.read("subscriptionPeriod", []);
|
|
105
|
-
}
|
|
106
|
-
/** What claiming or renewing an app costs, in USDC base units (6 decimals), not wei. */
|
|
107
|
-
async subscriptionFee() {
|
|
108
|
-
return this.read("subscriptionFee", []);
|
|
109
|
-
}
|
|
110
|
-
/** The ERC-20 token (USDC) every fee is paid in. */
|
|
111
|
-
async usdc() {
|
|
112
|
-
return this.read("usdc", []);
|
|
113
|
-
}
|
|
114
|
-
async getAppOwner(appId = this.app()) {
|
|
115
|
-
return this.read("getAppOwner", [appId]);
|
|
116
|
-
}
|
|
117
|
-
/** How many apps have been claimed. */
|
|
118
|
-
async appCount() {
|
|
119
|
-
return this.read("appCount", []);
|
|
120
|
-
}
|
|
121
|
-
/** Up to `limit` app ids from position `offset`, oldest first; fewer past the end. */
|
|
122
|
-
async appsPage(offset, limit) {
|
|
123
|
-
return this.read("appsPage", [offset, limit]);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Every claimed app id, oldest first.
|
|
127
|
-
* ponytail: one eth_call for all of them; page with `appsPage` once the list
|
|
128
|
-
* outgrows the RPC's eth_call gas cap (tens of thousands of apps).
|
|
129
|
-
*/
|
|
130
|
-
async allApps() {
|
|
131
|
-
return this.appsPage(0n, await this.appCount());
|
|
132
|
-
}
|
|
133
|
-
/** The app ids `owner` claimed, oldest first. */
|
|
134
|
-
async appsOf(owner) {
|
|
135
|
-
return this.read("appsOf", [owner]);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Point this app at its ERC-8004 agent card.
|
|
139
|
-
*
|
|
140
|
-
* Safe to call whenever the card moves: it leaves the app's publishers alone.
|
|
141
|
-
*/
|
|
142
|
-
async setAppAgentUri(agentUri) {
|
|
143
|
-
return this.executeWrite("setAppAgentUri", [this.app(), agentUri]);
|
|
144
|
-
}
|
|
145
|
-
/** Send the join fees the caller is still owed, from the old join flow, to `to`. */
|
|
146
|
-
async withdrawJoinFees(to = this.senderAddress()) {
|
|
147
|
-
return this.executeWrite("withdrawJoinFees", [to]);
|
|
148
|
-
}
|
|
149
|
-
/** Join fees still owed to `owner` from the old join flow, in USDC base units. Nothing adds to it. */
|
|
150
|
-
async joinFeesOwed(owner = this.senderAddress()) {
|
|
151
|
-
return this.read("joinFeesOwed", [owner]);
|
|
152
|
-
}
|
|
153
|
-
async isAppSuspended() {
|
|
154
|
-
return this.read("isAppSuspended", [this.app()]);
|
|
155
|
-
}
|
|
156
|
-
/** The agent card URI of this app, or of `appId`. Empty if none is set. */
|
|
157
|
-
async appAgentUri(appId = this.app()) {
|
|
158
|
-
return this.read("appAgentUri", [appId]);
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Accept a publisher into this app (owner only). That is the whole
|
|
162
|
-
* membership: from here it uploads with storage the app provides, and the app
|
|
163
|
-
* includes its data, while `canPublish` holds. A suspended publisher comes
|
|
164
|
-
* back with `setPublisherSuspended(publisher, false)`.
|
|
165
|
-
*/
|
|
166
|
-
async acceptPublisher(publisher) {
|
|
167
|
-
return this.executeWrite("acceptPublisher", [this.app(), publisher]);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Suspend an accepted publisher from this app, or reinstate them (owner
|
|
171
|
-
* only). An owner cannot suspend themselves.
|
|
172
|
-
*/
|
|
173
|
-
async setPublisherSuspended(publisher, suspended) {
|
|
174
|
-
return this.executeWrite("setPublisherSuspended", [
|
|
175
|
-
this.app(),
|
|
176
|
-
publisher,
|
|
177
|
-
suspended
|
|
178
|
-
]);
|
|
179
|
-
}
|
|
180
|
-
/** `publisher`'s standing in this app. */
|
|
181
|
-
async status(publisher) {
|
|
182
|
-
return await this.read("statusForApp", [this.app(), publisher]);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* May `publisher` publish to this app now: accepted and not suspended, not
|
|
186
|
-
* banned network-wide, and the app is live and paid up.
|
|
187
|
-
*/
|
|
188
|
-
async canPublish(publisher, appId = this.app()) {
|
|
189
|
-
return this.read("canPublish", [appId, publisher]);
|
|
190
|
-
}
|
|
191
|
-
/** The single oracle the upload gate reads for one publisher under this app. */
|
|
192
|
-
async access(publisher, appId = this.app()) {
|
|
193
|
-
const [canPublish, owner, expiresAt] = await this.read("access", [appId, publisher]);
|
|
194
|
-
return {
|
|
195
|
-
canPublish,
|
|
196
|
-
owner,
|
|
197
|
-
expiresAt
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* `AppAgentChanged` events, oldest first. The last one for an app is its
|
|
202
|
-
* current card; an empty `agentUri` means the owner unset it.
|
|
203
|
-
*
|
|
204
|
-
* Leave `appId` out to list every app that has ever set a card. To list apps,
|
|
205
|
-
* use `allApps` or `appsOf`, which are one read each; this is a windowed log
|
|
206
|
-
* scan, for a card's history. `fromBlock` is required because scanning from genesis on an L2 costs
|
|
207
|
-
* hundreds of thousands of RPC calls. Pass the AppRegistry's deploy block, or
|
|
208
|
-
* a block you know to be before the app's registration.
|
|
209
|
-
*/
|
|
210
|
-
async getAppAgentLogs(opts) {
|
|
211
|
-
return (await getLogsInWindows(this.publicClient, opts.fromBlock, opts.toBlock, (from, to) => this.publicClient.getContractEvents({
|
|
212
|
-
address: this.contractAddress,
|
|
213
|
-
abi: APP_REGISTRY_ABI,
|
|
214
|
-
eventName: "AppAgentChanged",
|
|
215
|
-
args: opts.appId ? { app_id: opts.appId } : {},
|
|
216
|
-
fromBlock: from,
|
|
217
|
-
toBlock: to,
|
|
218
|
-
strict: true
|
|
219
|
-
}), this.logWindow)).map((log) => ({
|
|
220
|
-
appId: log.args.app_id,
|
|
221
|
-
agentUri: log.args.agent_uri,
|
|
222
|
-
blockNumber: log.blockNumber,
|
|
223
|
-
transactionHash: log.transactionHash
|
|
224
|
-
}));
|
|
225
|
-
}
|
|
226
|
-
async admin() {
|
|
227
|
-
return this.read("admin", []);
|
|
228
|
-
}
|
|
229
|
-
/** The DataRegistry this contract names. */
|
|
230
|
-
async dataRegistry() {
|
|
231
|
-
return this.read("dataRegistry", []);
|
|
232
|
-
}
|
|
233
|
-
/** Whether the protocol admin has banned `wallet` network-wide. */
|
|
234
|
-
async isGloballySuspended(wallet) {
|
|
235
|
-
return this.read("globalSuspensions", [wallet]);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Ban `wallet` network-wide, or lift the ban. A banned wallet cannot claim an
|
|
239
|
-
* app or be accepted into one, and no app stores or includes it; a banned
|
|
240
|
-
* owner's app keeps running, but they cannot accept anyone or move its agent card.
|
|
241
|
-
*/
|
|
242
|
-
async setGlobalSuspension(wallet, suspended) {
|
|
243
|
-
return this.executeWrite("setGlobalSuspension", [wallet, suspended]);
|
|
244
|
-
}
|
|
245
|
-
/** Take this app down for every publisher at once, or restore it. */
|
|
246
|
-
async setAppSuspended(suspended) {
|
|
247
|
-
return this.executeWrite("setAppSuspended", [this.app(), suspended]);
|
|
248
|
-
}
|
|
249
|
-
async setDataRegistry(registry) {
|
|
250
|
-
return this.executeWrite("setDataRegistry", [registry]);
|
|
251
|
-
}
|
|
252
|
-
async setSubscriptionFee(fee) {
|
|
253
|
-
return this.executeWrite("setSubscriptionFee", [fee]);
|
|
254
|
-
}
|
|
255
|
-
/** Applies from each app's next payment. */
|
|
256
|
-
async setSubscriptionPeriod(period) {
|
|
257
|
-
return this.executeWrite("setSubscriptionPeriod", [period]);
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Send `amount` of `token` to `to`. Of USDC, only the protocol's share: what
|
|
261
|
-
* app owners are owed in join fees stays (`ExceedsProtocolBalance`).
|
|
262
|
-
*/
|
|
263
|
-
async withdrawToken(token, to, amount) {
|
|
264
|
-
return this.executeWrite("withdrawToken", [
|
|
265
|
-
token,
|
|
266
|
-
to,
|
|
267
|
-
amount
|
|
268
|
-
]);
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Fees are pulled with `transferFrom`, so the registry needs an allowance.
|
|
272
|
-
* Without one the call reverts with a fee error that reads like a pricing
|
|
273
|
-
* problem but is really an allowance one. Approves exactly `amount`.
|
|
274
|
-
*/
|
|
275
|
-
async approveUsdc(amount) {
|
|
276
|
-
if (amount === 0n) return;
|
|
277
|
-
const token = await this.usdc();
|
|
278
|
-
if (await this.publicClient.readContract({
|
|
279
|
-
address: token,
|
|
280
|
-
abi: erc20Abi,
|
|
281
|
-
functionName: "allowance",
|
|
282
|
-
args: [this.senderAddress(), this.contractAddress]
|
|
283
|
-
}) >= amount) return;
|
|
284
|
-
await sendWrite(this.publicClient, requireWallet(this.walletClient, "approve"), token, erc20Abi, "approve", [this.contractAddress, amount]);
|
|
285
|
-
}
|
|
286
|
-
senderAddress() {
|
|
287
|
-
const account = this.walletClient.account;
|
|
288
|
-
if (!account) throw new Error("Account required");
|
|
289
|
-
return account.address;
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
//#endregion
|
|
294
|
-
export { AppRegistryClient };
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
|
|
2
|
-
|
|
3
|
-
//#region src/contracts/membership-registry/index.d.ts
|
|
4
|
-
/** A signed ERC-3009 `receiveWithAuthorization` paying the registry, as `join` takes it. */
|
|
5
|
-
interface MembershipPayment {
|
|
6
|
-
from: Address;
|
|
7
|
-
value: bigint;
|
|
8
|
-
validAfter: bigint;
|
|
9
|
-
validBefore: bigint;
|
|
10
|
-
nonce: Hex;
|
|
11
|
-
v: number;
|
|
12
|
-
r: Hex;
|
|
13
|
-
s: Hex;
|
|
14
|
-
}
|
|
15
|
-
/** What `join` needs besides the payment: the app, the commitment, the salt in the nonce. */
|
|
16
|
-
interface JoinArgs {
|
|
17
|
-
appId: Hex;
|
|
18
|
-
commitment: bigint;
|
|
19
|
-
salt: Hex;
|
|
20
|
-
payment: MembershipPayment;
|
|
21
|
-
}
|
|
22
|
-
/** What `claim` needs: a Semaphore proof over the (app, epoch) group, message = holder. */
|
|
23
|
-
interface ClaimArgs {
|
|
24
|
-
appId: Hex;
|
|
25
|
-
epoch: bigint;
|
|
26
|
-
holder: Address;
|
|
27
|
-
merkleTreeDepth: bigint;
|
|
28
|
-
merkleTreeRoot: bigint;
|
|
29
|
-
nullifier: bigint;
|
|
30
|
-
points: readonly [bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint];
|
|
31
|
-
}
|
|
32
|
-
/** The nonce a payer signs for `join`, the same derivation as the contract's `joinNonce`. */
|
|
33
|
-
declare const joinNonce: (appId: Hex, epoch: bigint, commitment: bigint, salt: Hex) => Hex;
|
|
34
|
-
/** The Semaphore scope of (app, epoch), as the contract fixes it in `claim`. */
|
|
35
|
-
declare const membershipScope: (appId: Hex, epoch: bigint) => bigint;
|
|
36
|
-
/** A holder's membership token id in an app. */
|
|
37
|
-
declare const membershipTokenId: (appId: Hex, holder: Address) => bigint;
|
|
38
|
-
/**
|
|
39
|
-
* Client for the MembershipRegistry.
|
|
40
|
-
*
|
|
41
|
-
* The app owner's half is here (`setPlan`), with the reads every gate needs
|
|
42
|
-
* (`canRead`, `planOf`, `currentEpoch`) and the two relayed writes (`join`, `claim`),
|
|
43
|
-
* which take what a buyer signed and proved, so anyone may submit them.
|
|
44
|
-
*
|
|
45
|
-
* The buyer's half (Semaphore identity, stealth holder, the payment signature, the
|
|
46
|
-
* group from `Joined` logs, the proof) lives in `@fangorn-network/fetch`: this SDK
|
|
47
|
-
* carries no Semaphore proving dependency.
|
|
48
|
-
*/
|
|
49
|
-
declare class MembershipRegistryClient {
|
|
50
|
-
private contractAddress;
|
|
51
|
-
private publicClient;
|
|
52
|
-
private walletClient?;
|
|
53
|
-
constructor(contractAddress: Address, publicClient: PublicClient, walletClient?: WalletClient | undefined);
|
|
54
|
-
getAddress(): Address;
|
|
55
|
-
private write;
|
|
56
|
-
private read;
|
|
57
|
-
/** Price (USDC base units) and period (seconds) of a membership in `appId`. App owner only. */
|
|
58
|
-
setPlan(appId: Hex, price: bigint, period: bigint): Promise<Hash>;
|
|
59
|
-
join({
|
|
60
|
-
appId,
|
|
61
|
-
commitment,
|
|
62
|
-
salt,
|
|
63
|
-
payment
|
|
64
|
-
}: JoinArgs): Promise<Hash>;
|
|
65
|
-
claim(a: ClaimArgs): Promise<Hash>;
|
|
66
|
-
planOf(appId: Hex): Promise<{
|
|
67
|
-
price: bigint;
|
|
68
|
-
period: bigint;
|
|
69
|
-
}>;
|
|
70
|
-
currentEpoch(appId: Hex): Promise<bigint>;
|
|
71
|
-
/** What `who` may read with `tokenId`: the app, and until when (seconds; 0 = nothing). */
|
|
72
|
-
canRead(tokenId: bigint, who: Address): Promise<{
|
|
73
|
-
appId: Hex;
|
|
74
|
-
until: bigint;
|
|
75
|
-
}>;
|
|
76
|
-
expiresAt(tokenId: bigint): Promise<bigint>;
|
|
77
|
-
}
|
|
78
|
-
//#endregion
|
|
79
|
-
export { ClaimArgs, JoinArgs, MembershipPayment, MembershipRegistryClient, joinNonce, membershipScope, membershipTokenId };
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { requireWallet, sendWrite } from "../write.js";
|
|
2
|
-
import { MEMBERSHIP_REGISTRY_ABI } from "./abi.js";
|
|
3
|
-
import { encodeAbiParameters, keccak256 } from "viem";
|
|
4
|
-
|
|
5
|
-
//#region src/contracts/membership-registry/index.ts
|
|
6
|
-
/** The nonce a payer signs for `join`, the same derivation as the contract's `joinNonce`. */
|
|
7
|
-
const joinNonce = (appId, epoch, commitment, salt) => keccak256(encodeAbiParameters([
|
|
8
|
-
{ type: "bytes32" },
|
|
9
|
-
{ type: "uint256" },
|
|
10
|
-
{ type: "uint256" },
|
|
11
|
-
{ type: "bytes32" }
|
|
12
|
-
], [
|
|
13
|
-
appId,
|
|
14
|
-
epoch,
|
|
15
|
-
commitment,
|
|
16
|
-
salt
|
|
17
|
-
]));
|
|
18
|
-
/** The Semaphore scope of (app, epoch), as the contract fixes it in `claim`. */
|
|
19
|
-
const membershipScope = (appId, epoch) => BigInt(keccak256(encodeAbiParameters([{ type: "bytes32" }, { type: "uint256" }], [appId, epoch])));
|
|
20
|
-
/** A holder's membership token id in an app. */
|
|
21
|
-
const membershipTokenId = (appId, holder) => BigInt(keccak256(encodeAbiParameters([{ type: "bytes32" }, { type: "address" }], [appId, holder])));
|
|
22
|
-
/**
|
|
23
|
-
* Client for the MembershipRegistry.
|
|
24
|
-
*
|
|
25
|
-
* The app owner's half is here (`setPlan`), with the reads every gate needs
|
|
26
|
-
* (`canRead`, `planOf`, `currentEpoch`) and the two relayed writes (`join`, `claim`),
|
|
27
|
-
* which take what a buyer signed and proved, so anyone may submit them.
|
|
28
|
-
*
|
|
29
|
-
* The buyer's half (Semaphore identity, stealth holder, the payment signature, the
|
|
30
|
-
* group from `Joined` logs, the proof) lives in `@fangorn-network/fetch`: this SDK
|
|
31
|
-
* carries no Semaphore proving dependency.
|
|
32
|
-
*/
|
|
33
|
-
var MembershipRegistryClient = class {
|
|
34
|
-
constructor(contractAddress, publicClient, walletClient) {
|
|
35
|
-
this.contractAddress = contractAddress;
|
|
36
|
-
this.publicClient = publicClient;
|
|
37
|
-
this.walletClient = walletClient;
|
|
38
|
-
}
|
|
39
|
-
getAddress() {
|
|
40
|
-
return this.contractAddress;
|
|
41
|
-
}
|
|
42
|
-
write(functionName, args) {
|
|
43
|
-
return sendWrite(this.publicClient, requireWallet(this.walletClient, functionName), this.contractAddress, MEMBERSHIP_REGISTRY_ABI, functionName, args);
|
|
44
|
-
}
|
|
45
|
-
read(functionName, args = []) {
|
|
46
|
-
return this.publicClient.readContract({
|
|
47
|
-
address: this.contractAddress,
|
|
48
|
-
abi: MEMBERSHIP_REGISTRY_ABI,
|
|
49
|
-
functionName,
|
|
50
|
-
args
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/** Price (USDC base units) and period (seconds) of a membership in `appId`. App owner only. */
|
|
54
|
-
setPlan(appId, price, period) {
|
|
55
|
-
return this.write("setPlan", [
|
|
56
|
-
appId,
|
|
57
|
-
price,
|
|
58
|
-
period
|
|
59
|
-
]);
|
|
60
|
-
}
|
|
61
|
-
join({ appId, commitment, salt, payment }) {
|
|
62
|
-
return this.write("join", [
|
|
63
|
-
appId,
|
|
64
|
-
commitment,
|
|
65
|
-
salt,
|
|
66
|
-
payment
|
|
67
|
-
]);
|
|
68
|
-
}
|
|
69
|
-
claim(a) {
|
|
70
|
-
return this.write("claim", [
|
|
71
|
-
a.appId,
|
|
72
|
-
a.epoch,
|
|
73
|
-
a.holder,
|
|
74
|
-
a.merkleTreeDepth,
|
|
75
|
-
a.merkleTreeRoot,
|
|
76
|
-
a.nullifier,
|
|
77
|
-
a.points
|
|
78
|
-
]);
|
|
79
|
-
}
|
|
80
|
-
async planOf(appId) {
|
|
81
|
-
const [price, period] = await this.read("planOf", [appId]);
|
|
82
|
-
return {
|
|
83
|
-
price,
|
|
84
|
-
period
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
currentEpoch(appId) {
|
|
88
|
-
return this.read("currentEpoch", [appId]);
|
|
89
|
-
}
|
|
90
|
-
/** What `who` may read with `tokenId`: the app, and until when (seconds; 0 = nothing). */
|
|
91
|
-
async canRead(tokenId, who) {
|
|
92
|
-
const [appId, until] = await this.read("canRead", [tokenId, who]);
|
|
93
|
-
return {
|
|
94
|
-
appId,
|
|
95
|
-
until
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
expiresAt(tokenId) {
|
|
99
|
-
return this.read("expiresAt", [tokenId]);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
//#endregion
|
|
104
|
-
export { MembershipRegistryClient, joinNonce, membershipScope, membershipTokenId };
|
package/lib/contracts/types.d.ts
DELETED
package/lib/contracts/types.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
//#region src/contracts/types.ts
|
|
2
|
-
let PublisherStatus = /* @__PURE__ */ function(PublisherStatus$1) {
|
|
3
|
-
PublisherStatus$1[PublisherStatus$1["NONE"] = 0] = "NONE";
|
|
4
|
-
PublisherStatus$1[PublisherStatus$1["ACTIVE"] = 1] = "ACTIVE";
|
|
5
|
-
PublisherStatus$1[PublisherStatus$1["SUSPENDED"] = 2] = "SUSPENDED";
|
|
6
|
-
/** Retired: invited under the old join flow and never joined. Not a member. */
|
|
7
|
-
PublisherStatus$1[PublisherStatus$1["INVITED"] = 3] = "INVITED";
|
|
8
|
-
return PublisherStatus$1;
|
|
9
|
-
}({});
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
export { PublisherStatus };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|