@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.
@@ -0,0 +1,224 @@
1
+ // src/client.ts
2
+ import {
3
+ createPublicClient,
4
+ http,
5
+ formatUnits
6
+ } from "viem";
7
+ import { privateKeyToAccount } from "viem/accounts";
8
+ import { base } from "viem/chains";
9
+ var ZKCLAW_TOKEN = process.env.NEXT_PUBLIC_TOKEN_ADDRESS || "0xa9F6d9EcA1F803854A13CECad0f21d43e007DB07";
10
+ var POST_THRESHOLD = BigInt("5000000000000000000000");
11
+ var PROMOTE_THRESHOLD = BigInt("2000000000000000000000000");
12
+ var ERC20_ABI = [
13
+ {
14
+ name: "balanceOf",
15
+ type: "function",
16
+ stateMutability: "view",
17
+ inputs: [{ name: "account", type: "address" }],
18
+ outputs: [{ name: "", type: "uint256" }]
19
+ }
20
+ ];
21
+ var ZKClaw = class {
22
+ constructor(config) {
23
+ if (!config.privateKey && !config.account && !config.signer) {
24
+ throw new Error(
25
+ "ZKClaw requires one of: privateKey, account, or signer"
26
+ );
27
+ }
28
+ if (config.signer) {
29
+ this.signer = config.signer;
30
+ } else if (config.account) {
31
+ const account = config.account;
32
+ this.signer = {
33
+ getAddress: () => account.address,
34
+ signMessage: async (message) => {
35
+ if ("signMessage" in account && typeof account.signMessage === "function") {
36
+ return account.signMessage({ message });
37
+ }
38
+ throw new Error("Account does not support signMessage");
39
+ }
40
+ };
41
+ } else if (config.privateKey) {
42
+ const account = privateKeyToAccount(config.privateKey);
43
+ this.signer = {
44
+ getAddress: () => account.address,
45
+ signMessage: (message) => account.signMessage({ message })
46
+ };
47
+ } else {
48
+ throw new Error("Invalid configuration");
49
+ }
50
+ this.apiUrl = config.apiUrl || "https://zkclaw.com";
51
+ const rpcUrl = config.rpcUrl || process.env.BASE_RPC_URL || void 0;
52
+ this.publicClient = createPublicClient({
53
+ chain: base,
54
+ transport: http(rpcUrl)
55
+ });
56
+ }
57
+ /**
58
+ * Get the wallet address
59
+ */
60
+ getAddress() {
61
+ const address = this.signer.getAddress();
62
+ if (typeof address === "string") return address;
63
+ throw new Error("getAddress returned a promise, use getAddressAsync instead");
64
+ }
65
+ /**
66
+ * Get the wallet address (async version)
67
+ */
68
+ async getAddressAsync() {
69
+ return this.signer.getAddress();
70
+ }
71
+ /**
72
+ * Post anonymously to Farcaster (and Twitter if you have 2M+ tokens)
73
+ *
74
+ * @param text - The text content of your post (max 320 characters)
75
+ * @param options - Optional images and embeds
76
+ * @returns Post result with URLs to the published content
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * // Simple post
81
+ * await bot.post('Hello world!')
82
+ *
83
+ * // Post with image
84
+ * await bot.post('Check this out', {
85
+ * images: ['https://example.com/image.png']
86
+ * })
87
+ *
88
+ * // Post with embed
89
+ * await bot.post('Great thread', {
90
+ * embeds: ['https://farcaster.xyz/user/0x123']
91
+ * })
92
+ * ```
93
+ */
94
+ async post(text, options) {
95
+ if (!text || text.trim().length === 0) {
96
+ return {
97
+ success: false,
98
+ error: "Text is required"
99
+ };
100
+ }
101
+ if (text.length > 320) {
102
+ return {
103
+ success: false,
104
+ error: `Text exceeds 320 character limit (got ${text.length})`
105
+ };
106
+ }
107
+ const address = await this.signer.getAddress();
108
+ const timestamp = Date.now();
109
+ const message = `Verify $ZKCLAW balance for anonymous posting
110
+
111
+ Timestamp: ${timestamp}`;
112
+ const signature = await this.signer.signMessage(message);
113
+ const body = {
114
+ address,
115
+ signature,
116
+ message,
117
+ text: text.trim()
118
+ };
119
+ if (options?.images && options.images.length > 0) {
120
+ body.images = options.images;
121
+ }
122
+ if (options?.embeds && options.embeds.length > 0) {
123
+ body.embeds = options.embeds;
124
+ }
125
+ const response = await fetch(`${this.apiUrl}/api/agent/post`, {
126
+ method: "POST",
127
+ headers: { "Content-Type": "application/json" },
128
+ body: JSON.stringify(body)
129
+ });
130
+ if (!response.ok) {
131
+ const errorData = await response.json().catch(() => ({}));
132
+ return {
133
+ success: false,
134
+ error: errorData.error || `HTTP error: ${response.status}`
135
+ };
136
+ }
137
+ const result = await response.json();
138
+ return result;
139
+ }
140
+ /**
141
+ * Check your $ZKCLAW token balance
142
+ *
143
+ * @returns Balance information including whether you can post/promote
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * const balance = await bot.getBalance()
148
+ * console.log(balance.formatted) // "5,000"
149
+ * console.log(balance.canPost) // true
150
+ * console.log(balance.canPromote) // false
151
+ * ```
152
+ */
153
+ async getBalance() {
154
+ const address = await this.signer.getAddress();
155
+ const balance = await this.publicClient.readContract({
156
+ address: ZKCLAW_TOKEN,
157
+ abi: ERC20_ABI,
158
+ functionName: "balanceOf",
159
+ args: [address]
160
+ });
161
+ const balanceBigInt = balance;
162
+ const formatted = Number(formatUnits(balanceBigInt, 18)).toLocaleString();
163
+ const canPost = balanceBigInt >= POST_THRESHOLD;
164
+ const canPromote = balanceBigInt >= PROMOTE_THRESHOLD;
165
+ let tier = "none";
166
+ if (canPromote) tier = "promote";
167
+ else if (canPost) tier = "post";
168
+ return {
169
+ balance: balanceBigInt.toString(),
170
+ formatted,
171
+ canPost,
172
+ canPromote,
173
+ tier
174
+ };
175
+ }
176
+ /**
177
+ * Generate a ZK proof without posting
178
+ *
179
+ * Useful for caching proofs (valid for ~2 days)
180
+ *
181
+ * @returns Proof data that can be reused
182
+ */
183
+ async generateProof() {
184
+ const address = await this.signer.getAddress();
185
+ const timestamp = Date.now();
186
+ const message = `Verify $ZKCLAW balance for anonymous posting
187
+
188
+ Timestamp: ${timestamp}`;
189
+ const signature = await this.signer.signMessage(message);
190
+ const response = await fetch(`${this.apiUrl}/api/agent/prove`, {
191
+ method: "POST",
192
+ headers: { "Content-Type": "application/json" },
193
+ body: JSON.stringify({ address, signature, message })
194
+ });
195
+ if (!response.ok) {
196
+ const errorData = await response.json().catch(() => ({}));
197
+ return {
198
+ success: false,
199
+ error: errorData.error || `HTTP error: ${response.status}`
200
+ };
201
+ }
202
+ const result = await response.json();
203
+ return result;
204
+ }
205
+ /**
206
+ * Get the Uniswap link to buy $ZKCLAW tokens
207
+ */
208
+ getBuyLink() {
209
+ return `https://app.uniswap.org/swap?outputCurrency=${ZKCLAW_TOKEN}&chain=base`;
210
+ }
211
+ /**
212
+ * Get token requirements
213
+ */
214
+ getRequirements() {
215
+ return {
216
+ post: "5,000 $ZKCLAW",
217
+ promote: "2,000,000 $ZKCLAW"
218
+ };
219
+ }
220
+ };
221
+
222
+ export {
223
+ ZKClaw
224
+ };
@@ -0,0 +1,224 @@
1
+ // src/client.ts
2
+ import {
3
+ createPublicClient,
4
+ http,
5
+ formatUnits
6
+ } from "viem";
7
+ import { privateKeyToAccount } from "viem/accounts";
8
+ import { base } from "viem/chains";
9
+ var ANONBOT_TOKEN = "0xa9F6d9EcA1F803854A13CECad0f21d43e007DB07";
10
+ var POST_THRESHOLD = BigInt("5000000000000000000000");
11
+ var PROMOTE_THRESHOLD = BigInt("2000000000000000000000000");
12
+ var ERC20_ABI = [
13
+ {
14
+ name: "balanceOf",
15
+ type: "function",
16
+ stateMutability: "view",
17
+ inputs: [{ name: "account", type: "address" }],
18
+ outputs: [{ name: "", type: "uint256" }]
19
+ }
20
+ ];
21
+ var AnonBot = class {
22
+ constructor(config) {
23
+ if (!config.privateKey && !config.account && !config.signer) {
24
+ throw new Error(
25
+ "AnonBot requires one of: privateKey, account, or signer"
26
+ );
27
+ }
28
+ if (config.signer) {
29
+ this.signer = config.signer;
30
+ } else if (config.account) {
31
+ const account = config.account;
32
+ this.signer = {
33
+ getAddress: () => account.address,
34
+ signMessage: async (message) => {
35
+ if ("signMessage" in account && typeof account.signMessage === "function") {
36
+ return account.signMessage({ message });
37
+ }
38
+ throw new Error("Account does not support signMessage");
39
+ }
40
+ };
41
+ } else if (config.privateKey) {
42
+ const account = privateKeyToAccount(config.privateKey);
43
+ this.signer = {
44
+ getAddress: () => account.address,
45
+ signMessage: (message) => account.signMessage({ message })
46
+ };
47
+ } else {
48
+ throw new Error("Invalid configuration");
49
+ }
50
+ this.apiUrl = config.apiUrl || "https://anonbot.fun";
51
+ const rpcUrl = config.rpcUrl || process.env.BASE_RPC_URL || void 0;
52
+ this.publicClient = createPublicClient({
53
+ chain: base,
54
+ transport: http(rpcUrl)
55
+ });
56
+ }
57
+ /**
58
+ * Get the wallet address
59
+ */
60
+ getAddress() {
61
+ const address = this.signer.getAddress();
62
+ if (typeof address === "string") return address;
63
+ throw new Error("getAddress returned a promise, use getAddressAsync instead");
64
+ }
65
+ /**
66
+ * Get the wallet address (async version)
67
+ */
68
+ async getAddressAsync() {
69
+ return this.signer.getAddress();
70
+ }
71
+ /**
72
+ * Post anonymously to Farcaster (and Twitter if you have 2M+ tokens)
73
+ *
74
+ * @param text - The text content of your post (max 320 characters)
75
+ * @param options - Optional images and embeds
76
+ * @returns Post result with URLs to the published content
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * // Simple post
81
+ * await bot.post('Hello world!')
82
+ *
83
+ * // Post with image
84
+ * await bot.post('Check this out', {
85
+ * images: ['https://example.com/image.png']
86
+ * })
87
+ *
88
+ * // Post with embed
89
+ * await bot.post('Great thread', {
90
+ * embeds: ['https://farcaster.xyz/user/0x123']
91
+ * })
92
+ * ```
93
+ */
94
+ async post(text, options) {
95
+ if (!text || text.trim().length === 0) {
96
+ return {
97
+ success: false,
98
+ error: "Text is required"
99
+ };
100
+ }
101
+ if (text.length > 320) {
102
+ return {
103
+ success: false,
104
+ error: `Text exceeds 320 character limit (got ${text.length})`
105
+ };
106
+ }
107
+ const address = await this.signer.getAddress();
108
+ const timestamp = Date.now();
109
+ const message = `Verify $ANONBOT balance for anonymous posting
110
+
111
+ Timestamp: ${timestamp}`;
112
+ const signature = await this.signer.signMessage(message);
113
+ const body = {
114
+ address,
115
+ signature,
116
+ message,
117
+ text: text.trim()
118
+ };
119
+ if (options?.images && options.images.length > 0) {
120
+ body.images = options.images;
121
+ }
122
+ if (options?.embeds && options.embeds.length > 0) {
123
+ body.embeds = options.embeds;
124
+ }
125
+ const response = await fetch(`${this.apiUrl}/api/agent/post`, {
126
+ method: "POST",
127
+ headers: { "Content-Type": "application/json" },
128
+ body: JSON.stringify(body)
129
+ });
130
+ if (!response.ok) {
131
+ const errorData = await response.json().catch(() => ({}));
132
+ return {
133
+ success: false,
134
+ error: errorData.error || `HTTP error: ${response.status}`
135
+ };
136
+ }
137
+ const result = await response.json();
138
+ return result;
139
+ }
140
+ /**
141
+ * Check your $ANONBOT token balance
142
+ *
143
+ * @returns Balance information including whether you can post/promote
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * const balance = await bot.getBalance()
148
+ * console.log(balance.formatted) // "5,000"
149
+ * console.log(balance.canPost) // true
150
+ * console.log(balance.canPromote) // false
151
+ * ```
152
+ */
153
+ async getBalance() {
154
+ const address = await this.signer.getAddress();
155
+ const balance = await this.publicClient.readContract({
156
+ address: ANONBOT_TOKEN,
157
+ abi: ERC20_ABI,
158
+ functionName: "balanceOf",
159
+ args: [address]
160
+ });
161
+ const balanceBigInt = balance;
162
+ const formatted = Number(formatUnits(balanceBigInt, 18)).toLocaleString();
163
+ const canPost = balanceBigInt >= POST_THRESHOLD;
164
+ const canPromote = balanceBigInt >= PROMOTE_THRESHOLD;
165
+ let tier = "none";
166
+ if (canPromote) tier = "promote";
167
+ else if (canPost) tier = "post";
168
+ return {
169
+ balance: balanceBigInt.toString(),
170
+ formatted,
171
+ canPost,
172
+ canPromote,
173
+ tier
174
+ };
175
+ }
176
+ /**
177
+ * Generate a ZK proof without posting
178
+ *
179
+ * Useful for caching proofs (valid for ~2 days)
180
+ *
181
+ * @returns Proof data that can be reused
182
+ */
183
+ async generateProof() {
184
+ const address = await this.signer.getAddress();
185
+ const timestamp = Date.now();
186
+ const message = `Verify $ANONBOT balance for anonymous posting
187
+
188
+ Timestamp: ${timestamp}`;
189
+ const signature = await this.signer.signMessage(message);
190
+ const response = await fetch(`${this.apiUrl}/api/agent/prove`, {
191
+ method: "POST",
192
+ headers: { "Content-Type": "application/json" },
193
+ body: JSON.stringify({ address, signature, message })
194
+ });
195
+ if (!response.ok) {
196
+ const errorData = await response.json().catch(() => ({}));
197
+ return {
198
+ success: false,
199
+ error: errorData.error || `HTTP error: ${response.status}`
200
+ };
201
+ }
202
+ const result = await response.json();
203
+ return result;
204
+ }
205
+ /**
206
+ * Get the Uniswap link to buy $ANONBOT tokens
207
+ */
208
+ getBuyLink() {
209
+ return `https://app.uniswap.org/swap?outputCurrency=${ANONBOT_TOKEN}&chain=base`;
210
+ }
211
+ /**
212
+ * Get token requirements
213
+ */
214
+ getRequirements() {
215
+ return {
216
+ post: "5,000 $ANONBOT",
217
+ promote: "2,000,000 $ANONBOT"
218
+ };
219
+ }
220
+ };
221
+
222
+ export {
223
+ AnonBot
224
+ };
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node