@zkclaw/sdk 2.0.0 → 2.0.3

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/dist/cli.js CHANGED
@@ -1,369 +1,7 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
- // If the importer is in node compatibility mode or this is not an ESM
19
- // file that has been converted to a CommonJS file using a Babel-
20
- // compatible transform (i.e. "__esModule" has not been set), then set
21
- // "default" to the CommonJS "module.exports" for node compatibility.
22
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
- mod
24
- ));
25
-
26
- // src/client.ts
27
- var import_viem = require("viem");
28
- var import_accounts = require("viem/accounts");
29
- var import_chains = require("viem/chains");
30
- var DEFAULT_TOKEN_ADDRESS = "0x000000000000000000000000000000000000dead";
31
- var DEFAULT_POST_THRESHOLD = BigInt("5000") * BigInt(10 ** 18);
32
- var DEFAULT_PROMOTE_THRESHOLD = BigInt("2000000") * BigInt(10 ** 18);
33
- var cachedConfig = null;
34
- var configFetchPromise = null;
35
- var ERC20_ABI = [
36
- {
37
- name: "balanceOf",
38
- type: "function",
39
- stateMutability: "view",
40
- inputs: [{ name: "account", type: "address" }],
41
- outputs: [{ name: "", type: "uint256" }]
42
- }
43
- ];
44
- var ZKClaw = class {
45
- constructor(config) {
46
- this.config = null;
47
- if (!config.privateKey && !config.account && !config.signer) {
48
- throw new Error(
49
- "ZKClaw requires one of: privateKey, account, or signer"
50
- );
51
- }
52
- if (config.signer) {
53
- this.signer = config.signer;
54
- } else if (config.account) {
55
- const account = config.account;
56
- this.signer = {
57
- getAddress: () => account.address,
58
- signMessage: async (message) => {
59
- if ("signMessage" in account && typeof account.signMessage === "function") {
60
- return account.signMessage({ message });
61
- }
62
- throw new Error("Account does not support signMessage");
63
- }
64
- };
65
- } else if (config.privateKey) {
66
- const account = (0, import_accounts.privateKeyToAccount)(config.privateKey);
67
- this.signer = {
68
- getAddress: () => account.address,
69
- signMessage: (message) => account.signMessage({ message })
70
- };
71
- } else {
72
- throw new Error("Invalid configuration");
73
- }
74
- this.apiUrl = config.apiUrl || "https://zkclaw.com";
75
- const rpcUrl = config.rpcUrl || process.env.BASE_RPC_URL || "https://mainnet.base.org";
76
- this.publicClient = (0, import_viem.createPublicClient)({
77
- chain: import_chains.base,
78
- transport: (0, import_viem.http)(rpcUrl)
79
- });
80
- this.fetchConfig().catch(() => {
81
- });
82
- }
83
- /**
84
- * Fetch remote config from API (cached)
85
- */
86
- async fetchConfig() {
87
- if (this.config) return this.config;
88
- if (cachedConfig) {
89
- this.config = cachedConfig;
90
- return cachedConfig;
91
- }
92
- if (configFetchPromise) {
93
- const config = await configFetchPromise;
94
- this.config = config;
95
- return config;
96
- }
97
- configFetchPromise = (async () => {
98
- try {
99
- const response = await fetch(`${this.apiUrl}/api/config`);
100
- if (!response.ok) throw new Error("Failed to fetch config");
101
- const config = await response.json();
102
- cachedConfig = config;
103
- this.config = config;
104
- return config;
105
- } catch {
106
- const defaultConfig = {
107
- token: {
108
- address: DEFAULT_TOKEN_ADDRESS,
109
- chainId: 8453,
110
- decimals: 18,
111
- symbol: "ZKCLAW"
112
- },
113
- thresholds: {
114
- post: 5e3,
115
- promote: 2e6
116
- },
117
- limits: {
118
- maxPostLength: 320,
119
- maxImages: { farcaster: 2, twitter: 4 }
120
- },
121
- links: {
122
- buy: `https://app.uniswap.org/swap?outputCurrency=${DEFAULT_TOKEN_ADDRESS}&chain=base`,
123
- farcaster: "https://farcaster.xyz/zkclaw",
124
- twitter: "https://x.com/zkclawcom"
125
- }
126
- };
127
- this.config = defaultConfig;
128
- return defaultConfig;
129
- } finally {
130
- configFetchPromise = null;
131
- }
132
- })();
133
- return configFetchPromise;
134
- }
135
- /**
136
- * Get current config (fetches if not cached)
137
- */
138
- async getConfig() {
139
- return this.fetchConfig();
140
- }
141
- /**
142
- * Get the wallet address
143
- */
144
- getAddress() {
145
- const address = this.signer.getAddress();
146
- if (typeof address === "string") return address;
147
- throw new Error("getAddress returned a promise, use getAddressAsync instead");
148
- }
149
- /**
150
- * Get the wallet address (async version)
151
- */
152
- async getAddressAsync() {
153
- return this.signer.getAddress();
154
- }
155
- /**
156
- * Generate a ZK proof locally
157
- * Proof generation happens in your Node.js environment using WASM
158
- */
159
- async generateProofLocally() {
160
- const { AnonBalanceVerifier, BALANCE_THRESHOLDS } = await import("@anon/credentials");
161
- const address = await this.signer.getAddress();
162
- const message = `Verify $ZKCLAW balance for anonymous posting
163
-
164
- Timestamp: ${Date.now()}`;
165
- const signature = await this.signer.signMessage(message);
166
- const messageHash = (0, import_viem.hashMessage)(message);
167
- const verifier = new AnonBalanceVerifier();
168
- const { input } = await verifier.buildInput(address, BALANCE_THRESHOLDS.POST);
169
- const actualBalance = input.storageProof[0].value;
170
- if (actualBalance < BALANCE_THRESHOLDS.POST) {
171
- const config = await this.fetchConfig();
172
- throw new Error(
173
- `Insufficient $ZKCLAW balance. Required: ${config.thresholds.post.toLocaleString()}, got: ${Number((0, import_viem.formatUnits)(actualBalance, 18)).toLocaleString()}. Buy at: ${config.links.buy}`
174
- );
175
- }
176
- const threshold = actualBalance >= BALANCE_THRESHOLDS.PROMOTE ? BALANCE_THRESHOLDS.PROMOTE : BALANCE_THRESHOLDS.POST;
177
- const { input: finalInput } = await verifier.buildInput(address, threshold);
178
- const proofResult = await verifier.generateProof({
179
- ...finalInput,
180
- signature,
181
- messageHash
182
- });
183
- return {
184
- proof: {
185
- proof: Array.from(proofResult.proof),
186
- publicInputs: proofResult.publicInputs
187
- },
188
- balance: actualBalance
189
- };
190
- }
191
- /**
192
- * Post anonymously to Farcaster (and Twitter if you have 2M+ tokens)
193
- *
194
- * @param text - The text content of your post (max 320 characters)
195
- * @param options - Optional images and embeds
196
- * @returns Post result with URLs to the published content
197
- *
198
- * @example
199
- * ```typescript
200
- * // Simple post
201
- * await bot.post('Hello world!')
202
- *
203
- * // Post with image
204
- * await bot.post('Check this out', {
205
- * images: ['https://example.com/image.png']
206
- * })
207
- *
208
- * // Post with embed
209
- * await bot.post('Great thread', {
210
- * embeds: ['https://farcaster.xyz/user/0x123']
211
- * })
212
- * ```
213
- */
214
- async post(text, options) {
215
- const config = await this.fetchConfig();
216
- if (!text || text.trim().length === 0) {
217
- return {
218
- success: false,
219
- error: "Text is required"
220
- };
221
- }
222
- if (text.length > config.limits.maxPostLength) {
223
- return {
224
- success: false,
225
- error: `Text exceeds ${config.limits.maxPostLength} character limit (got ${text.length})`
226
- };
227
- }
228
- try {
229
- const { proof, balance } = await this.generateProofLocally();
230
- const promoteThreshold = BigInt(config.thresholds.promote) * BigInt(10 ** config.token.decimals);
231
- const canPromote = balance >= promoteThreshold;
232
- const body = {
233
- proof,
234
- text: text.trim(),
235
- platforms: {
236
- farcaster: true,
237
- twitter: canPromote
238
- // Auto-enable Twitter if user has enough balance
239
- }
240
- };
241
- if (options?.images && options.images.length > 0) {
242
- body.images = options.images;
243
- }
244
- if (options?.embeds && options.embeds.length > 0) {
245
- body.embeds = options.embeds;
246
- }
247
- const response = await fetch(`${this.apiUrl}/api/post`, {
248
- method: "POST",
249
- headers: { "Content-Type": "application/json" },
250
- body: JSON.stringify(body)
251
- });
252
- if (!response.ok) {
253
- const errorData = await response.json().catch(() => ({}));
254
- return {
255
- success: false,
256
- error: errorData.error || `HTTP error: ${response.status}`
257
- };
258
- }
259
- const result = await response.json();
260
- return result;
261
- } catch (err) {
262
- return {
263
- success: false,
264
- error: err instanceof Error ? err.message : "Failed to generate proof or post"
265
- };
266
- }
267
- }
268
- /**
269
- * Check your $ZKCLAW token balance
270
- *
271
- * @returns Balance information including whether you can post/promote
272
- *
273
- * @example
274
- * ```typescript
275
- * const balance = await bot.getBalance()
276
- * console.log(balance.formatted) // "5,000"
277
- * console.log(balance.canPost) // true
278
- * console.log(balance.canPromote) // false
279
- * ```
280
- */
281
- async getBalance() {
282
- const config = await this.fetchConfig();
283
- const address = await this.signer.getAddress();
284
- const balance = await this.publicClient.readContract({
285
- address: config.token.address,
286
- abi: ERC20_ABI,
287
- functionName: "balanceOf",
288
- args: [address]
289
- });
290
- const balanceBigInt = balance;
291
- const formatted = Number((0, import_viem.formatUnits)(balanceBigInt, config.token.decimals)).toLocaleString();
292
- const postThreshold = BigInt(config.thresholds.post) * BigInt(10 ** config.token.decimals);
293
- const promoteThreshold = BigInt(config.thresholds.promote) * BigInt(10 ** config.token.decimals);
294
- const canPost = balanceBigInt >= postThreshold;
295
- const canPromote = balanceBigInt >= promoteThreshold;
296
- let tier = "none";
297
- if (canPromote) tier = "promote";
298
- else if (canPost) tier = "post";
299
- return {
300
- balance: balanceBigInt.toString(),
301
- formatted,
302
- canPost,
303
- canPromote,
304
- tier
305
- };
306
- }
307
- /**
308
- * Generate a ZK proof without posting
309
- *
310
- * Useful for testing or caching proofs
311
- *
312
- * @returns Proof data that can be reused
313
- */
314
- async generateProof() {
315
- try {
316
- const { proof, balance } = await this.generateProofLocally();
317
- const config = await this.fetchConfig();
318
- const promoteThreshold = BigInt(config.thresholds.promote) * BigInt(10 ** config.token.decimals);
319
- return {
320
- success: true,
321
- proof,
322
- balance: balance.toString(),
323
- tier: balance >= promoteThreshold ? "promote" : "post"
324
- };
325
- } catch (err) {
326
- return {
327
- success: false,
328
- error: err instanceof Error ? err.message : "Failed to generate proof"
329
- };
330
- }
331
- }
332
- /**
333
- * Get the Uniswap link to buy $ZKCLAW tokens
334
- */
335
- async getBuyLink() {
336
- const config = await this.fetchConfig();
337
- return config.links.buy;
338
- }
339
- /**
340
- * Get the Uniswap link to buy $ZKCLAW tokens (sync version with fallback)
341
- */
342
- getBuyLinkSync() {
343
- const tokenAddress = this.config?.token.address || DEFAULT_TOKEN_ADDRESS;
344
- return `https://app.uniswap.org/swap?outputCurrency=${tokenAddress}&chain=base`;
345
- }
346
- /**
347
- * Get token requirements
348
- */
349
- async getRequirements() {
350
- const config = await this.fetchConfig();
351
- return {
352
- post: `${config.thresholds.post.toLocaleString()} $ZKCLAW`,
353
- promote: `${config.thresholds.promote.toLocaleString()} $ZKCLAW`
354
- };
355
- }
356
- /**
357
- * Get token requirements (sync version with defaults)
358
- */
359
- getRequirementsSync() {
360
- const config = this.config;
361
- return {
362
- post: `${(config?.thresholds.post || 5e3).toLocaleString()} $ZKCLAW`,
363
- promote: `${(config?.thresholds.promote || 2e6).toLocaleString()} $ZKCLAW`
364
- };
365
- }
366
- };
2
+ import {
3
+ ZKClaw
4
+ } from "./chunk-YPF5ZK5J.js";
367
5
 
368
6
  // src/cli.ts
369
7
  var HELP = `
package/dist/cli.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  ZKClaw
4
- } from "./chunk-L5QERYJQ.mjs";
4
+ } from "./chunk-UAQRGX32.mjs";
5
+ import "./chunk-XGB3TDIC.mjs";
5
6
 
6
7
  // src/cli.ts
7
8
  var HELP = `