@zkclaw/sdk 1.0.0 → 2.0.1

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