@clawdvault/sdk 0.1.2 → 0.2.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/dist/index.js CHANGED
@@ -148,8 +148,17 @@ async function signAndSerialize(transaction, signer) {
148
148
  return Buffer.from(signedTx.serialize()).toString("base64");
149
149
  }
150
150
  }
151
- async function createAuthSignature(signer, payload) {
152
- const message = JSON.stringify(payload);
151
+ async function createAuthSignature(signer, payload, action) {
152
+ const authAction = action || payload.action || "session";
153
+ const timestamp = Math.floor(Date.now() / 1e3);
154
+ const window2 = Math.floor(timestamp / 300) * 300;
155
+ let signData;
156
+ if (authAction === "session") {
157
+ signData = { action: "create_session" };
158
+ } else {
159
+ signData = { ...payload };
160
+ }
161
+ const message = `ClawdVault:${authAction}:${window2}:${JSON.stringify(signData)}`;
153
162
  const messageBytes = new TextEncoder().encode(message);
154
163
  const signatureBytes = await signer.signMessage(messageBytes);
155
164
  return {
@@ -196,7 +205,7 @@ var ClawdVaultClient = class {
196
205
  return this.signer?.publicKey.toBase58() ?? null;
197
206
  }
198
207
  async request(method, path, options = {}) {
199
- const { params, body, auth, formData } = options;
208
+ const { params, body, auth, formData, action } = options;
200
209
  let url = `${this.baseUrl}${path}`;
201
210
  if (params) {
202
211
  const searchParams = new URLSearchParams();
@@ -213,9 +222,12 @@ var ClawdVaultClient = class {
213
222
  if (this.sessionToken) {
214
223
  headers["Authorization"] = `Bearer ${this.sessionToken}`;
215
224
  } else if (this.signer && body) {
216
- const { signature, wallet } = await createAuthSignature(this.signer, body);
225
+ const { signature, wallet } = await createAuthSignature(this.signer, body, action);
217
226
  headers["X-Wallet"] = wallet;
218
227
  headers["X-Signature"] = signature;
228
+ if (action) {
229
+ headers["X-Action"] = action;
230
+ }
219
231
  }
220
232
  }
221
233
  let requestBody;
@@ -373,7 +385,8 @@ var ClawdVaultClient = class {
373
385
  throw new Error("Signer required for sellPercent");
374
386
  }
375
387
  const wallet = this.signer.publicKey.toBase58();
376
- const { balance } = await this.getBalance(wallet, mint);
388
+ const balanceResponse = await this.getBalance(wallet, mint);
389
+ const balance = balanceResponse.balance ?? 0;
377
390
  if (balance <= 0) {
378
391
  throw new Error("No tokens to sell");
379
392
  }
@@ -530,7 +543,7 @@ var ClawdVaultClient = class {
530
543
  * Send chat message
531
544
  */
532
545
  async sendChat(params) {
533
- return this.request("POST", "/chat", { body: params, auth: true });
546
+ return this.request("POST", "/chat", { body: params, auth: true, action: "chat" });
534
547
  }
535
548
  /**
536
549
  * Add reaction
@@ -538,7 +551,8 @@ var ClawdVaultClient = class {
538
551
  async addReaction(messageId, emoji) {
539
552
  await this.request("POST", "/reactions", {
540
553
  body: { messageId, emoji },
541
- auth: true
554
+ auth: true,
555
+ action: "react"
542
556
  });
543
557
  }
544
558
  /**
@@ -547,7 +561,8 @@ var ClawdVaultClient = class {
547
561
  async removeReaction(messageId, emoji) {
548
562
  await this.request("DELETE", "/reactions", {
549
563
  params: { messageId, emoji },
550
- auth: true
564
+ auth: true,
565
+ action: "unreact"
551
566
  });
552
567
  }
553
568
  // ============ User / Auth ============
@@ -561,13 +576,13 @@ var ClawdVaultClient = class {
561
576
  * Update profile
562
577
  */
563
578
  async updateProfile(params) {
564
- await this.request("POST", "/profile", { body: params, auth: true });
579
+ await this.request("POST", "/profile", { body: params, auth: true, action: "profile" });
565
580
  }
566
581
  /**
567
582
  * Create session token
568
583
  */
569
584
  async createSession() {
570
- return this.request("POST", "/auth/session", { body: {}, auth: true });
585
+ return this.request("POST", "/auth/session", { body: {}, auth: true, action: "session" });
571
586
  }
572
587
  /**
573
588
  * Validate session token
package/dist/index.mjs CHANGED
@@ -114,8 +114,17 @@ async function signAndSerialize(transaction, signer) {
114
114
  return Buffer.from(signedTx.serialize()).toString("base64");
115
115
  }
116
116
  }
117
- async function createAuthSignature(signer, payload) {
118
- const message = JSON.stringify(payload);
117
+ async function createAuthSignature(signer, payload, action) {
118
+ const authAction = action || payload.action || "session";
119
+ const timestamp = Math.floor(Date.now() / 1e3);
120
+ const window2 = Math.floor(timestamp / 300) * 300;
121
+ let signData;
122
+ if (authAction === "session") {
123
+ signData = { action: "create_session" };
124
+ } else {
125
+ signData = { ...payload };
126
+ }
127
+ const message = `ClawdVault:${authAction}:${window2}:${JSON.stringify(signData)}`;
119
128
  const messageBytes = new TextEncoder().encode(message);
120
129
  const signatureBytes = await signer.signMessage(messageBytes);
121
130
  return {
@@ -162,7 +171,7 @@ var ClawdVaultClient = class {
162
171
  return this.signer?.publicKey.toBase58() ?? null;
163
172
  }
164
173
  async request(method, path, options = {}) {
165
- const { params, body, auth, formData } = options;
174
+ const { params, body, auth, formData, action } = options;
166
175
  let url = `${this.baseUrl}${path}`;
167
176
  if (params) {
168
177
  const searchParams = new URLSearchParams();
@@ -179,9 +188,12 @@ var ClawdVaultClient = class {
179
188
  if (this.sessionToken) {
180
189
  headers["Authorization"] = `Bearer ${this.sessionToken}`;
181
190
  } else if (this.signer && body) {
182
- const { signature, wallet } = await createAuthSignature(this.signer, body);
191
+ const { signature, wallet } = await createAuthSignature(this.signer, body, action);
183
192
  headers["X-Wallet"] = wallet;
184
193
  headers["X-Signature"] = signature;
194
+ if (action) {
195
+ headers["X-Action"] = action;
196
+ }
185
197
  }
186
198
  }
187
199
  let requestBody;
@@ -339,7 +351,8 @@ var ClawdVaultClient = class {
339
351
  throw new Error("Signer required for sellPercent");
340
352
  }
341
353
  const wallet = this.signer.publicKey.toBase58();
342
- const { balance } = await this.getBalance(wallet, mint);
354
+ const balanceResponse = await this.getBalance(wallet, mint);
355
+ const balance = balanceResponse.balance ?? 0;
343
356
  if (balance <= 0) {
344
357
  throw new Error("No tokens to sell");
345
358
  }
@@ -496,7 +509,7 @@ var ClawdVaultClient = class {
496
509
  * Send chat message
497
510
  */
498
511
  async sendChat(params) {
499
- return this.request("POST", "/chat", { body: params, auth: true });
512
+ return this.request("POST", "/chat", { body: params, auth: true, action: "chat" });
500
513
  }
501
514
  /**
502
515
  * Add reaction
@@ -504,7 +517,8 @@ var ClawdVaultClient = class {
504
517
  async addReaction(messageId, emoji) {
505
518
  await this.request("POST", "/reactions", {
506
519
  body: { messageId, emoji },
507
- auth: true
520
+ auth: true,
521
+ action: "react"
508
522
  });
509
523
  }
510
524
  /**
@@ -513,7 +527,8 @@ var ClawdVaultClient = class {
513
527
  async removeReaction(messageId, emoji) {
514
528
  await this.request("DELETE", "/reactions", {
515
529
  params: { messageId, emoji },
516
- auth: true
530
+ auth: true,
531
+ action: "unreact"
517
532
  });
518
533
  }
519
534
  // ============ User / Auth ============
@@ -527,13 +542,13 @@ var ClawdVaultClient = class {
527
542
  * Update profile
528
543
  */
529
544
  async updateProfile(params) {
530
- await this.request("POST", "/profile", { body: params, auth: true });
545
+ await this.request("POST", "/profile", { body: params, auth: true, action: "profile" });
531
546
  }
532
547
  /**
533
548
  * Create session token
534
549
  */
535
550
  async createSession() {
536
- return this.request("POST", "/auth/session", { body: {}, auth: true });
551
+ return this.request("POST", "/auth/session", { body: {}, auth: true, action: "session" });
537
552
  }
538
553
  /**
539
554
  * Validate session token
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawdvault/sdk",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "TypeScript SDK for ClawdVault - Solana token launchpad",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -19,15 +19,19 @@
19
19
  "build": "tsup src/index.ts --format cjs,esm --dts --clean",
20
20
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
21
21
  "test": "vitest run",
22
- "clean": "rm -rf dist"
22
+ "clean": "rm -rf dist",
23
+ "generate-types": "openapi-typescript https://clawdvault.com/api/openapi -o src/generated/api.ts",
24
+ "generate-types:local": "openapi-typescript ../../clawdvault/app/public/openapi.yaml -o src/generated/api.ts"
23
25
  },
24
26
  "dependencies": {
25
- "@solana/web3.js": "^1.91.0",
26
27
  "@solana/spl-token": "^0.4.0",
28
+ "@solana/web3.js": "^1.91.0",
27
29
  "bs58": "^5.0.0",
30
+ "eventsource": "^2.0.2",
28
31
  "tweetnacl": "^1.0.3"
29
32
  },
30
33
  "devDependencies": {
34
+ "openapi-typescript": "^7.10.1",
31
35
  "tsup": "^8.0.1",
32
36
  "typescript": "^5.3.3",
33
37
  "vitest": "^1.2.0"