clutch-hub-sdk-js 1.2.0 → 1.3.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/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## [1.3.0](https://github.com/clutch-protocol/clutch-hub-sdk-js/compare/v1.2.0...v1.3.0) (2025-08-23)
2
+
3
+
4
+ ### Features
5
+
6
+ * **sdk:** add getPublicKey and isAuthenticated utility methods ([c0ac16e](https://github.com/clutch-protocol/clutch-hub-sdk-js/commit/c0ac16e1166cf9d6e4bcb5ae8cc37a17d6ae7028))
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **auth:** add buffer time to prevent token expiration race conditions ([29b3b53](https://github.com/clutch-protocol/clutch-hub-sdk-js/commit/29b3b538dc260c34d80814da4723a5d13a140a48))
12
+
13
+
14
+ ### Performance Improvements
15
+
16
+ * **sdk:** optimize float64ToUint64 conversion with cached buffers ([43a76b9](https://github.com/clutch-protocol/clutch-hub-sdk-js/commit/43a76b91cd05b737a5942a381653419816656fdd))
17
+
1
18
  ## [1.2.0](https://github.com/clutch-protocol/clutch-hub-sdk-js/compare/v1.1.0...v1.2.0) (2025-08-23)
2
19
 
3
20
 
package/dist/sdk.d.ts CHANGED
@@ -23,6 +23,16 @@ export declare class ClutchHubSdk {
23
23
  private token;
24
24
  private tokenExpireTime;
25
25
  constructor(apiUrl: string, publicKey: string);
26
+ /**
27
+ * Get the current public key associated with this SDK instance.
28
+ * @returns The public key string
29
+ */
30
+ getPublicKey(): string;
31
+ /**
32
+ * Check if the SDK is currently authenticated.
33
+ * @returns True if authenticated and token is not expired
34
+ */
35
+ isAuthenticated(): boolean;
26
36
  private get authHeaders();
27
37
  private executeGraphQL;
28
38
  private ensureAuth;
@@ -50,6 +60,9 @@ export declare class ClutchHubSdk {
50
60
  private encodeFunctionCall;
51
61
  /**
52
62
  * Converts a JavaScript number to uint64 bits as BigInt.
63
+ * Uses cached ArrayBuffer and DataView for better performance.
53
64
  */
65
+ private static readonly floatBuffer;
66
+ private static readonly floatView;
54
67
  private float64ToUint64;
55
68
  }
package/dist/sdk.js CHANGED
@@ -17,6 +17,22 @@ export class ClutchHubSdk {
17
17
  this.apiClient = axios.create({ baseURL: apiUrl });
18
18
  this.publicKey = publicKey;
19
19
  }
20
+ /**
21
+ * Get the current public key associated with this SDK instance.
22
+ * @returns The public key string
23
+ */
24
+ getPublicKey() {
25
+ return this.publicKey;
26
+ }
27
+ /**
28
+ * Check if the SDK is currently authenticated.
29
+ * @returns True if authenticated and token is not expired
30
+ */
31
+ isAuthenticated() {
32
+ const now = Date.now();
33
+ const bufferTime = 30000; // 30 seconds
34
+ return !!(this.token && now < (this.tokenExpireTime - bufferTime));
35
+ }
20
36
  get authHeaders() {
21
37
  return this.token ? { Authorization: `Bearer ${this.token}` } : {};
22
38
  }
@@ -32,7 +48,9 @@ export class ClutchHubSdk {
32
48
  }
33
49
  async ensureAuth() {
34
50
  const now = Date.now();
35
- if (!this.token || now >= this.tokenExpireTime) {
51
+ // Add buffer time to prevent race conditions near token expiration
52
+ const bufferTime = 30000; // 30 seconds
53
+ if (!this.token || now >= (this.tokenExpireTime - bufferTime)) {
36
54
  const query = `
37
55
  mutation GenerateToken($publicKey: String!) {
38
56
  generateToken(publicKey: $publicKey) {
@@ -168,15 +186,16 @@ export class ClutchHubSdk {
168
186
  throw new Error(`Unsupported FunctionCall type: ${type}`);
169
187
  }
170
188
  }
171
- /**
172
- * Converts a JavaScript number to uint64 bits as BigInt.
173
- */
174
189
  float64ToUint64(value) {
175
- const buffer = new ArrayBuffer(8);
176
- const view = new DataView(buffer);
177
- view.setFloat64(0, value, false);
178
- const high = BigInt(view.getUint32(0, false));
179
- const low = BigInt(view.getUint32(4, false));
190
+ ClutchHubSdk.floatView.setFloat64(0, value, false);
191
+ const high = BigInt(ClutchHubSdk.floatView.getUint32(0, false));
192
+ const low = BigInt(ClutchHubSdk.floatView.getUint32(4, false));
180
193
  return (high << BigInt(32)) | low;
181
194
  }
182
195
  }
196
+ /**
197
+ * Converts a JavaScript number to uint64 bits as BigInt.
198
+ * Uses cached ArrayBuffer and DataView for better performance.
199
+ */
200
+ ClutchHubSdk.floatBuffer = new ArrayBuffer(8);
201
+ ClutchHubSdk.floatView = new DataView(ClutchHubSdk.floatBuffer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clutch-hub-sdk-js",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "JavaScript SDK for interacting with the clutch-hub-api",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
package/src/sdk.ts CHANGED
@@ -37,6 +37,24 @@ export class ClutchHubSdk {
37
37
  this.publicKey = publicKey;
38
38
  }
39
39
 
40
+ /**
41
+ * Get the current public key associated with this SDK instance.
42
+ * @returns The public key string
43
+ */
44
+ public getPublicKey(): string {
45
+ return this.publicKey;
46
+ }
47
+
48
+ /**
49
+ * Check if the SDK is currently authenticated.
50
+ * @returns True if authenticated and token is not expired
51
+ */
52
+ public isAuthenticated(): boolean {
53
+ const now = Date.now();
54
+ const bufferTime = 30000; // 30 seconds
55
+ return !!(this.token && now < (this.tokenExpireTime - bufferTime));
56
+ }
57
+
40
58
  private get authHeaders(): Record<string, string> {
41
59
  return this.token ? { Authorization: `Bearer ${this.token}` } : {};
42
60
  }
@@ -58,7 +76,9 @@ export class ClutchHubSdk {
58
76
 
59
77
  private async ensureAuth(): Promise<void> {
60
78
  const now = Date.now();
61
- if (!this.token || now >= this.tokenExpireTime) {
79
+ // Add buffer time to prevent race conditions near token expiration
80
+ const bufferTime = 30000; // 30 seconds
81
+ if (!this.token || now >= (this.tokenExpireTime - bufferTime)) {
62
82
  const query = `
63
83
  mutation GenerateToken($publicKey: String!) {
64
84
  generateToken(publicKey: $publicKey) {
@@ -223,13 +243,15 @@ export class ClutchHubSdk {
223
243
 
224
244
  /**
225
245
  * Converts a JavaScript number to uint64 bits as BigInt.
246
+ * Uses cached ArrayBuffer and DataView for better performance.
226
247
  */
248
+ private static readonly floatBuffer = new ArrayBuffer(8);
249
+ private static readonly floatView = new DataView(ClutchHubSdk.floatBuffer);
250
+
227
251
  private float64ToUint64(value: number): bigint {
228
- const buffer = new ArrayBuffer(8);
229
- const view = new DataView(buffer);
230
- view.setFloat64(0, value, false);
231
- const high = BigInt(view.getUint32(0, false));
232
- const low = BigInt(view.getUint32(4, false));
252
+ ClutchHubSdk.floatView.setFloat64(0, value, false);
253
+ const high = BigInt(ClutchHubSdk.floatView.getUint32(0, false));
254
+ const low = BigInt(ClutchHubSdk.floatView.getUint32(4, false));
233
255
  return (high << BigInt(32)) | low;
234
256
  }
235
257
  }