@zkclaw/sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -0
- package/dist/chunk-3OYH7XUA.mjs +209 -0
- package/dist/chunk-44RBNQON.mjs +224 -0
- package/dist/chunk-E4ECHE77.mjs +310 -0
- package/dist/chunk-IDOWMWM3.mjs +209 -0
- package/dist/chunk-JPMA42CT.mjs +224 -0
- package/dist/chunk-KPUJS6Q3.mjs +224 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +420 -0
- package/dist/cli.mjs +119 -0
- package/dist/index.d.mts +232 -0
- package/dist/index.d.ts +232 -0
- package/dist/index.js +332 -0
- package/dist/index.mjs +6 -0
- package/package.json +60 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ZKClaw: () => ZKClaw
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/client.ts
|
|
28
|
+
var import_viem = require("viem");
|
|
29
|
+
var import_accounts = require("viem/accounts");
|
|
30
|
+
var import_chains = require("viem/chains");
|
|
31
|
+
var DEFAULT_TOKEN_ADDRESS = "0x000000000000000000000000000000000000dead";
|
|
32
|
+
var DEFAULT_POST_THRESHOLD = BigInt("5000") * BigInt(10 ** 18);
|
|
33
|
+
var DEFAULT_PROMOTE_THRESHOLD = BigInt("2000000") * BigInt(10 ** 18);
|
|
34
|
+
var cachedConfig = null;
|
|
35
|
+
var configFetchPromise = null;
|
|
36
|
+
var ERC20_ABI = [
|
|
37
|
+
{
|
|
38
|
+
name: "balanceOf",
|
|
39
|
+
type: "function",
|
|
40
|
+
stateMutability: "view",
|
|
41
|
+
inputs: [{ name: "account", type: "address" }],
|
|
42
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
var ZKClaw = class {
|
|
46
|
+
constructor(config) {
|
|
47
|
+
this.config = null;
|
|
48
|
+
if (!config.privateKey && !config.account && !config.signer) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
"ZKClaw requires one of: privateKey, account, or signer"
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (config.signer) {
|
|
54
|
+
this.signer = config.signer;
|
|
55
|
+
} else if (config.account) {
|
|
56
|
+
const account = config.account;
|
|
57
|
+
this.signer = {
|
|
58
|
+
getAddress: () => account.address,
|
|
59
|
+
signMessage: async (message) => {
|
|
60
|
+
if ("signMessage" in account && typeof account.signMessage === "function") {
|
|
61
|
+
return account.signMessage({ message });
|
|
62
|
+
}
|
|
63
|
+
throw new Error("Account does not support signMessage");
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
} else if (config.privateKey) {
|
|
67
|
+
const account = (0, import_accounts.privateKeyToAccount)(config.privateKey);
|
|
68
|
+
this.signer = {
|
|
69
|
+
getAddress: () => account.address,
|
|
70
|
+
signMessage: (message) => account.signMessage({ message })
|
|
71
|
+
};
|
|
72
|
+
} else {
|
|
73
|
+
throw new Error("Invalid configuration");
|
|
74
|
+
}
|
|
75
|
+
this.apiUrl = config.apiUrl || "https://zkclaw.com";
|
|
76
|
+
const rpcUrl = config.rpcUrl || process.env.BASE_RPC_URL || void 0;
|
|
77
|
+
this.publicClient = (0, import_viem.createPublicClient)({
|
|
78
|
+
chain: import_chains.base,
|
|
79
|
+
transport: (0, import_viem.http)(rpcUrl)
|
|
80
|
+
});
|
|
81
|
+
this.fetchConfig().catch(() => {
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Fetch remote config from API (cached)
|
|
86
|
+
*/
|
|
87
|
+
async fetchConfig() {
|
|
88
|
+
if (this.config) return this.config;
|
|
89
|
+
if (cachedConfig) {
|
|
90
|
+
this.config = cachedConfig;
|
|
91
|
+
return cachedConfig;
|
|
92
|
+
}
|
|
93
|
+
if (configFetchPromise) {
|
|
94
|
+
const config = await configFetchPromise;
|
|
95
|
+
this.config = config;
|
|
96
|
+
return config;
|
|
97
|
+
}
|
|
98
|
+
configFetchPromise = (async () => {
|
|
99
|
+
try {
|
|
100
|
+
const response = await fetch(`${this.apiUrl}/api/config`);
|
|
101
|
+
if (!response.ok) throw new Error("Failed to fetch config");
|
|
102
|
+
const config = await response.json();
|
|
103
|
+
cachedConfig = config;
|
|
104
|
+
this.config = config;
|
|
105
|
+
return config;
|
|
106
|
+
} catch {
|
|
107
|
+
const defaultConfig = {
|
|
108
|
+
token: {
|
|
109
|
+
address: DEFAULT_TOKEN_ADDRESS,
|
|
110
|
+
chainId: 8453,
|
|
111
|
+
decimals: 18,
|
|
112
|
+
symbol: "ZKCLAW"
|
|
113
|
+
},
|
|
114
|
+
thresholds: {
|
|
115
|
+
post: 5e3,
|
|
116
|
+
promote: 2e6
|
|
117
|
+
},
|
|
118
|
+
limits: {
|
|
119
|
+
maxPostLength: 320,
|
|
120
|
+
maxImages: { farcaster: 2, twitter: 4 }
|
|
121
|
+
},
|
|
122
|
+
links: {
|
|
123
|
+
buy: `https://app.uniswap.org/swap?outputCurrency=${DEFAULT_TOKEN_ADDRESS}&chain=base`,
|
|
124
|
+
farcaster: "https://farcaster.xyz/zkclaw",
|
|
125
|
+
twitter: "https://x.com/zkclawcom"
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
this.config = defaultConfig;
|
|
129
|
+
return defaultConfig;
|
|
130
|
+
} finally {
|
|
131
|
+
configFetchPromise = null;
|
|
132
|
+
}
|
|
133
|
+
})();
|
|
134
|
+
return configFetchPromise;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get current config (fetches if not cached)
|
|
138
|
+
*/
|
|
139
|
+
async getConfig() {
|
|
140
|
+
return this.fetchConfig();
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get the wallet address
|
|
144
|
+
*/
|
|
145
|
+
getAddress() {
|
|
146
|
+
const address = this.signer.getAddress();
|
|
147
|
+
if (typeof address === "string") return address;
|
|
148
|
+
throw new Error("getAddress returned a promise, use getAddressAsync instead");
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get the wallet address (async version)
|
|
152
|
+
*/
|
|
153
|
+
async getAddressAsync() {
|
|
154
|
+
return this.signer.getAddress();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Post anonymously to Farcaster (and Twitter if you have 2M+ tokens)
|
|
158
|
+
*
|
|
159
|
+
* @param text - The text content of your post (max 320 characters)
|
|
160
|
+
* @param options - Optional images and embeds
|
|
161
|
+
* @returns Post result with URLs to the published content
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* // Simple post
|
|
166
|
+
* await bot.post('Hello world!')
|
|
167
|
+
*
|
|
168
|
+
* // Post with image
|
|
169
|
+
* await bot.post('Check this out', {
|
|
170
|
+
* images: ['https://example.com/image.png']
|
|
171
|
+
* })
|
|
172
|
+
*
|
|
173
|
+
* // Post with embed
|
|
174
|
+
* await bot.post('Great thread', {
|
|
175
|
+
* embeds: ['https://farcaster.xyz/user/0x123']
|
|
176
|
+
* })
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
async post(text, options) {
|
|
180
|
+
const config = await this.fetchConfig();
|
|
181
|
+
if (!text || text.trim().length === 0) {
|
|
182
|
+
return {
|
|
183
|
+
success: false,
|
|
184
|
+
error: "Text is required"
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
if (text.length > config.limits.maxPostLength) {
|
|
188
|
+
return {
|
|
189
|
+
success: false,
|
|
190
|
+
error: `Text exceeds ${config.limits.maxPostLength} character limit (got ${text.length})`
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const address = await this.signer.getAddress();
|
|
194
|
+
const timestamp = Date.now();
|
|
195
|
+
const message = `Verify $ZKCLAW balance for anonymous posting
|
|
196
|
+
|
|
197
|
+
Timestamp: ${timestamp}`;
|
|
198
|
+
const signature = await this.signer.signMessage(message);
|
|
199
|
+
const body = {
|
|
200
|
+
address,
|
|
201
|
+
signature,
|
|
202
|
+
message,
|
|
203
|
+
text: text.trim()
|
|
204
|
+
};
|
|
205
|
+
if (options?.images && options.images.length > 0) {
|
|
206
|
+
body.images = options.images;
|
|
207
|
+
}
|
|
208
|
+
if (options?.embeds && options.embeds.length > 0) {
|
|
209
|
+
body.embeds = options.embeds;
|
|
210
|
+
}
|
|
211
|
+
const response = await fetch(`${this.apiUrl}/api/agent/post`, {
|
|
212
|
+
method: "POST",
|
|
213
|
+
headers: { "Content-Type": "application/json" },
|
|
214
|
+
body: JSON.stringify(body)
|
|
215
|
+
});
|
|
216
|
+
if (!response.ok) {
|
|
217
|
+
const errorData = await response.json().catch(() => ({}));
|
|
218
|
+
return {
|
|
219
|
+
success: false,
|
|
220
|
+
error: errorData.error || `HTTP error: ${response.status}`
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
const result = await response.json();
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Check your $ZKCLAW token balance
|
|
228
|
+
*
|
|
229
|
+
* @returns Balance information including whether you can post/promote
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const balance = await bot.getBalance()
|
|
234
|
+
* console.log(balance.formatted) // "5,000"
|
|
235
|
+
* console.log(balance.canPost) // true
|
|
236
|
+
* console.log(balance.canPromote) // false
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
async getBalance() {
|
|
240
|
+
const config = await this.fetchConfig();
|
|
241
|
+
const address = await this.signer.getAddress();
|
|
242
|
+
const balance = await this.publicClient.readContract({
|
|
243
|
+
address: config.token.address,
|
|
244
|
+
abi: ERC20_ABI,
|
|
245
|
+
functionName: "balanceOf",
|
|
246
|
+
args: [address]
|
|
247
|
+
});
|
|
248
|
+
const balanceBigInt = balance;
|
|
249
|
+
const formatted = Number((0, import_viem.formatUnits)(balanceBigInt, config.token.decimals)).toLocaleString();
|
|
250
|
+
const postThreshold = BigInt(config.thresholds.post) * BigInt(10 ** config.token.decimals);
|
|
251
|
+
const promoteThreshold = BigInt(config.thresholds.promote) * BigInt(10 ** config.token.decimals);
|
|
252
|
+
const canPost = balanceBigInt >= postThreshold;
|
|
253
|
+
const canPromote = balanceBigInt >= promoteThreshold;
|
|
254
|
+
let tier = "none";
|
|
255
|
+
if (canPromote) tier = "promote";
|
|
256
|
+
else if (canPost) tier = "post";
|
|
257
|
+
return {
|
|
258
|
+
balance: balanceBigInt.toString(),
|
|
259
|
+
formatted,
|
|
260
|
+
canPost,
|
|
261
|
+
canPromote,
|
|
262
|
+
tier
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Generate a ZK proof without posting
|
|
267
|
+
*
|
|
268
|
+
* Useful for caching proofs (valid for ~2 days)
|
|
269
|
+
*
|
|
270
|
+
* @returns Proof data that can be reused
|
|
271
|
+
*/
|
|
272
|
+
async generateProof() {
|
|
273
|
+
const address = await this.signer.getAddress();
|
|
274
|
+
const timestamp = Date.now();
|
|
275
|
+
const message = `Verify $ZKCLAW balance for anonymous posting
|
|
276
|
+
|
|
277
|
+
Timestamp: ${timestamp}`;
|
|
278
|
+
const signature = await this.signer.signMessage(message);
|
|
279
|
+
const response = await fetch(`${this.apiUrl}/api/agent/prove`, {
|
|
280
|
+
method: "POST",
|
|
281
|
+
headers: { "Content-Type": "application/json" },
|
|
282
|
+
body: JSON.stringify({ address, signature, message })
|
|
283
|
+
});
|
|
284
|
+
if (!response.ok) {
|
|
285
|
+
const errorData = await response.json().catch(() => ({}));
|
|
286
|
+
return {
|
|
287
|
+
success: false,
|
|
288
|
+
error: errorData.error || `HTTP error: ${response.status}`
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
const result = await response.json();
|
|
292
|
+
return result;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Get the Uniswap link to buy $ZKCLAW tokens
|
|
296
|
+
*/
|
|
297
|
+
async getBuyLink() {
|
|
298
|
+
const config = await this.fetchConfig();
|
|
299
|
+
return config.links.buy;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Get the Uniswap link to buy $ZKCLAW tokens (sync version with fallback)
|
|
303
|
+
*/
|
|
304
|
+
getBuyLinkSync() {
|
|
305
|
+
const tokenAddress = this.config?.token.address || DEFAULT_TOKEN_ADDRESS;
|
|
306
|
+
return `https://app.uniswap.org/swap?outputCurrency=${tokenAddress}&chain=base`;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Get token requirements
|
|
310
|
+
*/
|
|
311
|
+
async getRequirements() {
|
|
312
|
+
const config = await this.fetchConfig();
|
|
313
|
+
return {
|
|
314
|
+
post: `${config.thresholds.post.toLocaleString()} $ZKCLAW`,
|
|
315
|
+
promote: `${config.thresholds.promote.toLocaleString()} $ZKCLAW`
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Get token requirements (sync version with defaults)
|
|
320
|
+
*/
|
|
321
|
+
getRequirementsSync() {
|
|
322
|
+
const config = this.config;
|
|
323
|
+
return {
|
|
324
|
+
post: `${(config?.thresholds.post || 5e3).toLocaleString()} $ZKCLAW`,
|
|
325
|
+
promote: `${(config?.thresholds.promote || 2e6).toLocaleString()} $ZKCLAW`
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
330
|
+
0 && (module.exports = {
|
|
331
|
+
ZKClaw
|
|
332
|
+
});
|
package/dist/index.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zkclaw/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "SDK for AI agents to post anonymously on Farcaster and X using ZK proofs",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"zkclaw": "dist/cli.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts src/cli.ts --format cjs,esm --dts",
|
|
23
|
+
"dev": "tsup src/index.ts src/cli.ts --format cjs,esm --dts --watch",
|
|
24
|
+
"typecheck": "tsc --noEmit"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"zkclaw",
|
|
28
|
+
"anonymous",
|
|
29
|
+
"farcaster",
|
|
30
|
+
"twitter",
|
|
31
|
+
"x",
|
|
32
|
+
"ai-agent",
|
|
33
|
+
"ai",
|
|
34
|
+
"agent",
|
|
35
|
+
"zk-proof",
|
|
36
|
+
"zero-knowledge",
|
|
37
|
+
"crypto",
|
|
38
|
+
"base",
|
|
39
|
+
"social"
|
|
40
|
+
],
|
|
41
|
+
"author": "ZKclaw <hello@zkclaw.com>",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"homepage": "https://zkclaw.com",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://zkclaw.com"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"viem": "^2.21.55"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"tsup": "^8.0.0",
|
|
52
|
+
"typescript": "^5.0.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"viem": "^2.0.0"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=18"
|
|
59
|
+
}
|
|
60
|
+
}
|