@tuwaio/quasar-sdk 0.0.18 → 0.1.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.
- package/README.md +56 -166
- package/dist/index.cjs +2 -1
- package/dist/index.d.cts +69 -170
- package/dist/index.d.ts +69 -170
- package/dist/index.js +2 -1
- package/package.json +9 -55
- package/dist/chunk-C3D4A4ZL.cjs +0 -1
- package/dist/chunk-C6JAMIC3.js +0 -1
- package/dist/chunk-GZ7OST4D.js +0 -1
- package/dist/chunk-NJH5FYLU.cjs +0 -2
- package/dist/chunk-RSHZA2NR.js +0 -1
- package/dist/chunk-UIDJZGQ7.cjs +0 -1
- package/dist/chunk-VABKD4LZ.js +0 -1
- package/dist/chunk-VLHVLJGE.cjs +0 -1
- package/dist/chunk-YPUBFZPR.js +0 -2
- package/dist/chunk-YUZXHNP6.cjs +0 -1
- package/dist/react/evm.cjs +0 -1
- package/dist/react/evm.d.cts +0 -56
- package/dist/react/evm.d.ts +0 -56
- package/dist/react/evm.js +0 -1
- package/dist/react/shared.cjs +0 -1
- package/dist/react/shared.d.cts +0 -59
- package/dist/react/shared.d.ts +0 -59
- package/dist/react/shared.js +0 -1
- package/dist/react/solana.cjs +0 -1
- package/dist/react/solana.d.cts +0 -52
- package/dist/react/solana.d.ts +0 -52
- package/dist/react/solana.js +0 -1
- package/dist/react.cjs +0 -1
- package/dist/react.d.cts +0 -60
- package/dist/react.d.ts +0 -60
- package/dist/react.js +0 -1
- package/dist/types-C4cwIvHT.d.cts +0 -190
- package/dist/types-C4cwIvHT.d.ts +0 -190
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,69 @@
|
|
|
1
1
|
import { FetchOptions } from 'ofetch';
|
|
2
|
-
import { Q as QuasarConfig, H as HistoryQuery, P as PaginatedResult, V as VerifySessionParams, S as SignSessionParams, a as SignSessionResult, M as MiniSessionStore, C as ConnectionData, b as MiniSessionAuth } from './types-C4cwIvHT.cjs';
|
|
3
|
-
export { c as ChainType, E as EvmSigner, d as SolanaSignableMessage, e as SolanaSigner } from './types-C4cwIvHT.cjs';
|
|
4
2
|
import { Transaction } from '@tuwaio/pulsar-core';
|
|
5
3
|
export { Transaction, UpdatableTransactionFields } from '@tuwaio/pulsar-core';
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @module types
|
|
7
|
+
* @description Shared type definitions for the Quasar SDK.
|
|
8
|
+
* Contains configuration interfaces, query parameters, and authentication structures.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Configuration options for initializing the {@link Quasar} SDK client.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
interface QuasarConfig {
|
|
17
|
+
/** Your secret API key starting with `sk_live_`. */
|
|
18
|
+
secretKey: string;
|
|
19
|
+
/** Optional internal secret for system-to-system communication. */
|
|
20
|
+
internalSecret?: string;
|
|
21
|
+
/** The base URL of the Quasar Cloud API. Defaults to 'https://api.tuwa.io'. */
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
/** Request timeout in milliseconds. Defaults to 10000. */
|
|
24
|
+
timeout?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Query parameters for filtering and paginating transaction history.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
interface HistoryQuery {
|
|
32
|
+
/** Page number for pagination (1-indexed). */
|
|
33
|
+
page?: number;
|
|
34
|
+
/** Maximum number of results to return per page. */
|
|
35
|
+
limit?: number;
|
|
36
|
+
/** Filter by blockchain chain ID (e.g., 1, 'solana'). */
|
|
37
|
+
chainId?: string | number;
|
|
38
|
+
/** Filter by transaction status (e.g., 'Success', 'Failed'). */
|
|
39
|
+
status?: string;
|
|
40
|
+
/** Filter by a specific Quasar transaction key. */
|
|
41
|
+
txKey?: string;
|
|
42
|
+
/** Filter by the application name. */
|
|
43
|
+
appName?: string;
|
|
44
|
+
/** Filter by the sender's wallet address. */
|
|
45
|
+
walletAddress?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Generic wrapper for paginated API responses.
|
|
49
|
+
*
|
|
50
|
+
* @typeParam T - The type of the documents contained in the result set.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
interface PaginatedResult<T> {
|
|
54
|
+
/** Array of documents for the current page. */
|
|
55
|
+
docs: T[];
|
|
56
|
+
/** Total number of documents matching the query. */
|
|
57
|
+
totalDocs: number;
|
|
58
|
+
/** Total number of available pages. */
|
|
59
|
+
totalPages: number;
|
|
60
|
+
/** The current page number (1-indexed). */
|
|
61
|
+
page: number;
|
|
62
|
+
/** Indicates if a subsequent page is available. */
|
|
63
|
+
hasNextPage: boolean;
|
|
64
|
+
/** Indicates if a preceding page is available. */
|
|
65
|
+
hasPrevPage: boolean;
|
|
66
|
+
}
|
|
8
67
|
|
|
9
68
|
/**
|
|
10
69
|
* @module core/client
|
|
@@ -196,110 +255,6 @@ declare class PulsarModule {
|
|
|
196
255
|
getHistory(query?: HistoryQuery): Promise<PaginatedResult<Transaction>>;
|
|
197
256
|
}
|
|
198
257
|
|
|
199
|
-
/**
|
|
200
|
-
* @module utils/auth
|
|
201
|
-
* @description Security utilities for Mini-Session signature creation and verification.
|
|
202
|
-
* Supports dual-ecosystem (EVM & Solana) authentication flows with strict type safety.
|
|
203
|
-
*/
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Default maximum allowed age for a signature (5 minutes).
|
|
207
|
-
* Prevents replay attacks using stale signatures.
|
|
208
|
-
* @internal
|
|
209
|
-
*/
|
|
210
|
-
declare const DEFAULT_MAX_AGE: number;
|
|
211
|
-
/**
|
|
212
|
-
* Safety buffer subtracted from DEFAULT_MAX_AGE during cache validation.
|
|
213
|
-
* Ensures the session is refreshed before it expires on the server,
|
|
214
|
-
* accounting for network round-trip latency between client cache check
|
|
215
|
-
* and server-side verifyMiniSession call.
|
|
216
|
-
* @public
|
|
217
|
-
*/
|
|
218
|
-
declare const NETWORK_SAFETY_BUFFER: number;
|
|
219
|
-
/**
|
|
220
|
-
* Standardizes the message format for Mini-Session authentication.
|
|
221
|
-
* Both frontend and backend MUST use this exact template for verification to pass.
|
|
222
|
-
*
|
|
223
|
-
* @param timestamp - ISO string timestamp (e.g., `new Date().toISOString()`).
|
|
224
|
-
* @returns The formatted message string to be signed.
|
|
225
|
-
*
|
|
226
|
-
* @example
|
|
227
|
-
* ```typescript
|
|
228
|
-
* const msg = createMiniSessionMessage(new Date().toISOString());
|
|
229
|
-
* // msg -> "Mini-Session Login: 2026-05-13T10:00:00.000Z"
|
|
230
|
-
* ```
|
|
231
|
-
*/
|
|
232
|
-
declare function createMiniSessionMessage(timestamp: string): string;
|
|
233
|
-
/**
|
|
234
|
-
* Triggers a signature request in the connected wallet to create a Mini-Session.
|
|
235
|
-
*
|
|
236
|
-
* This function detects the signer's capabilities and uses the most appropriate
|
|
237
|
-
* signing method available (e.g., Web3 v2, Standard, or Legacy).
|
|
238
|
-
*
|
|
239
|
-
* @param params - Parameters containing the signer and target ecosystem.
|
|
240
|
-
* @returns A promise resolving to the signature and timestamp.
|
|
241
|
-
* @throws {Error} If signing fails or the signer lacks required methods.
|
|
242
|
-
*
|
|
243
|
-
* @public
|
|
244
|
-
*/
|
|
245
|
-
declare function signMiniSession(params: SignSessionParams): Promise<SignSessionResult>;
|
|
246
|
-
/**
|
|
247
|
-
* Verifies a Mini-Session signature for authenticity and freshness.
|
|
248
|
-
*
|
|
249
|
-
* Performs cryptographic verification against the provided wallet address and
|
|
250
|
-
* ensures the signature hasn't expired according to the `maxAge` parameter.
|
|
251
|
-
*
|
|
252
|
-
* @param params - Verification data including signature and timestamp.
|
|
253
|
-
* @returns A promise resolving to true if the session is valid.
|
|
254
|
-
*
|
|
255
|
-
* @public
|
|
256
|
-
*/
|
|
257
|
-
declare function verifyMiniSession(params: VerifySessionParams): Promise<boolean>;
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Creates a persistent Zustand store to cache Mini-Session signatures.
|
|
261
|
-
* This is the recommended way to manage sessions in React applications.
|
|
262
|
-
*
|
|
263
|
-
* @param storageName - The localStorage key for persistence. Defaults to 'mini-session-storage'.
|
|
264
|
-
* @returns A Zustand store instance initialized with MiniSessionStore interface.
|
|
265
|
-
*
|
|
266
|
-
* @public
|
|
267
|
-
*/
|
|
268
|
-
declare function createMiniSessionStore(storageName?: string): zustand.UseBoundStore<Omit<zustand.StoreApi<MiniSessionStore>, "setState" | "persist"> & {
|
|
269
|
-
setState(partial: MiniSessionStore | Partial<MiniSessionStore> | ((state: MiniSessionStore) => MiniSessionStore | Partial<MiniSessionStore>), replace?: false | undefined): unknown;
|
|
270
|
-
setState(state: MiniSessionStore | ((state: MiniSessionStore) => MiniSessionStore), replace: true): unknown;
|
|
271
|
-
persist: {
|
|
272
|
-
setOptions: (options: Partial<zustand_middleware.PersistOptions<MiniSessionStore, MiniSessionStore, unknown>>) => void;
|
|
273
|
-
clearStorage: () => void;
|
|
274
|
-
rehydrate: () => Promise<void> | void;
|
|
275
|
-
hasHydrated: () => boolean;
|
|
276
|
-
onHydrate: (fn: (state: MiniSessionStore) => void) => () => void;
|
|
277
|
-
onFinishHydration: (fn: (state: MiniSessionStore) => void) => () => void;
|
|
278
|
-
getOptions: () => Partial<zustand_middleware.PersistOptions<MiniSessionStore, MiniSessionStore, unknown>>;
|
|
279
|
-
};
|
|
280
|
-
}>;
|
|
281
|
-
/**
|
|
282
|
-
* High-level orchestrator to retrieve an existing Mini-Session or trigger a new signature.
|
|
283
|
-
*
|
|
284
|
-
* This function checks the provided store for a valid, non-expired session matching
|
|
285
|
-
* the current wallet connection. If no session is found or it has expired, it
|
|
286
|
-
* triggers a signature request through the wallet.
|
|
287
|
-
*
|
|
288
|
-
* @param connection - The current active wallet connection data (address, signer, etc).
|
|
289
|
-
* @param store - A store implementation (Zustand or compatible) for session persistence.
|
|
290
|
-
* @param maxAge - Maximum allowed session age in milliseconds. Must match the value
|
|
291
|
-
* passed to `verifyMiniSession` to keep cache and verification in sync.
|
|
292
|
-
* Defaults to `DEFAULT_MAX_AGE` (5 minutes).
|
|
293
|
-
* @returns A promise resolving to a valid MiniSessionAuth object.
|
|
294
|
-
* @throws {Error} If the wallet is disconnected or signing fails.
|
|
295
|
-
*
|
|
296
|
-
* @public
|
|
297
|
-
*/
|
|
298
|
-
declare function getMiniSessionAuth(connection: ConnectionData, store: {
|
|
299
|
-
miniSession: MiniSessionAuth | null;
|
|
300
|
-
setMiniSession: (session: MiniSessionAuth | null) => void;
|
|
301
|
-
}, maxAge?: number): Promise<MiniSessionAuth>;
|
|
302
|
-
|
|
303
258
|
declare const BASE_API_URL = "https://api.tuwa.io";
|
|
304
259
|
declare const PULSAR_SYNC_ENDPOINT = "/v1/engine/pulsar/sync";
|
|
305
260
|
declare const PULSAR_HISTORY_ENDPOINT = "/v1/engine/pulsar/history";
|
|
@@ -324,40 +279,15 @@ declare const PULSAR_HISTORY_ENDPOINT = "/v1/engine/pulsar/history";
|
|
|
324
279
|
*/
|
|
325
280
|
|
|
326
281
|
/**
|
|
327
|
-
*
|
|
282
|
+
* Pre-flight check before initiating a transaction.
|
|
283
|
+
* Ensures the local SIWX Session is valid and verifies Quasar Engine health.
|
|
328
284
|
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
285
|
+
* @param customApiUrl - Optional custom API URL to override the default.
|
|
286
|
+
* @throws {Error} If the session check fails or Quasar is unreachable.
|
|
331
287
|
*
|
|
332
288
|
* @public
|
|
333
289
|
*/
|
|
334
|
-
declare
|
|
335
|
-
/**
|
|
336
|
-
* Standardizes the message format for Quasar Mini-Session login.
|
|
337
|
-
* @see {@link createMiniSessionMessage}
|
|
338
|
-
*/
|
|
339
|
-
createMiniSessionMessage: typeof createMiniSessionMessage;
|
|
340
|
-
/**
|
|
341
|
-
* Verifies a Mini-Session signature (EVM or Solana).
|
|
342
|
-
* @see {@link verifyMiniSession}
|
|
343
|
-
*/
|
|
344
|
-
verifyMiniSession: typeof verifyMiniSession;
|
|
345
|
-
/**
|
|
346
|
-
* Triggers a signature request in the connected wallet.
|
|
347
|
-
* @see {@link signMiniSession}
|
|
348
|
-
*/
|
|
349
|
-
signMiniSession: typeof signMiniSession;
|
|
350
|
-
/**
|
|
351
|
-
* Creates a persistent Zustand store for session management.
|
|
352
|
-
* @see {@link createMiniSessionStore}
|
|
353
|
-
*/
|
|
354
|
-
createMiniSessionStore: typeof createMiniSessionStore;
|
|
355
|
-
/**
|
|
356
|
-
* Reusable helper to manage signing and session caching.
|
|
357
|
-
* @see {@link getMiniSessionAuth}
|
|
358
|
-
*/
|
|
359
|
-
getMiniSessionAuth: typeof getMiniSessionAuth;
|
|
360
|
-
};
|
|
290
|
+
declare function preFlightTxCheck(customApiUrl?: string): Promise<void>;
|
|
361
291
|
/**
|
|
362
292
|
* Main entry point for the Quasar SDK.
|
|
363
293
|
*
|
|
@@ -383,37 +313,6 @@ declare const utils: {
|
|
|
383
313
|
* @public
|
|
384
314
|
*/
|
|
385
315
|
declare class Quasar {
|
|
386
|
-
/**
|
|
387
|
-
* Security and authentication utilities.
|
|
388
|
-
* Shared across all instances and available statically.
|
|
389
|
-
*/
|
|
390
|
-
static readonly utils: {
|
|
391
|
-
/**
|
|
392
|
-
* Standardizes the message format for Quasar Mini-Session login.
|
|
393
|
-
* @see {@link createMiniSessionMessage}
|
|
394
|
-
*/
|
|
395
|
-
createMiniSessionMessage: typeof createMiniSessionMessage;
|
|
396
|
-
/**
|
|
397
|
-
* Verifies a Mini-Session signature (EVM or Solana).
|
|
398
|
-
* @see {@link verifyMiniSession}
|
|
399
|
-
*/
|
|
400
|
-
verifyMiniSession: typeof verifyMiniSession;
|
|
401
|
-
/**
|
|
402
|
-
* Triggers a signature request in the connected wallet.
|
|
403
|
-
* @see {@link signMiniSession}
|
|
404
|
-
*/
|
|
405
|
-
signMiniSession: typeof signMiniSession;
|
|
406
|
-
/**
|
|
407
|
-
* Creates a persistent Zustand store for session management.
|
|
408
|
-
* @see {@link createMiniSessionStore}
|
|
409
|
-
*/
|
|
410
|
-
createMiniSessionStore: typeof createMiniSessionStore;
|
|
411
|
-
/**
|
|
412
|
-
* Reusable helper to manage signing and session caching.
|
|
413
|
-
* @see {@link getMiniSessionAuth}
|
|
414
|
-
*/
|
|
415
|
-
getMiniSessionAuth: typeof getMiniSessionAuth;
|
|
416
|
-
};
|
|
417
316
|
/**
|
|
418
317
|
* The internal HTTP client used for authenticated requests.
|
|
419
318
|
* @internal
|
|
@@ -442,4 +341,4 @@ declare class Quasar {
|
|
|
442
341
|
constructor(config: QuasarConfig);
|
|
443
342
|
}
|
|
444
343
|
|
|
445
|
-
export { BASE_API_URL,
|
|
344
|
+
export { BASE_API_URL, type HistoryQuery, PULSAR_HISTORY_ENDPOINT, PULSAR_SYNC_ENDPOINT, type PaginatedResult, PulsarModule, Quasar, type QuasarConfig, QuasarSDKError, preFlightTxCheck };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,69 @@
|
|
|
1
1
|
import { FetchOptions } from 'ofetch';
|
|
2
|
-
import { Q as QuasarConfig, H as HistoryQuery, P as PaginatedResult, V as VerifySessionParams, S as SignSessionParams, a as SignSessionResult, M as MiniSessionStore, C as ConnectionData, b as MiniSessionAuth } from './types-C4cwIvHT.js';
|
|
3
|
-
export { c as ChainType, E as EvmSigner, d as SolanaSignableMessage, e as SolanaSigner } from './types-C4cwIvHT.js';
|
|
4
2
|
import { Transaction } from '@tuwaio/pulsar-core';
|
|
5
3
|
export { Transaction, UpdatableTransactionFields } from '@tuwaio/pulsar-core';
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @module types
|
|
7
|
+
* @description Shared type definitions for the Quasar SDK.
|
|
8
|
+
* Contains configuration interfaces, query parameters, and authentication structures.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Configuration options for initializing the {@link Quasar} SDK client.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
interface QuasarConfig {
|
|
17
|
+
/** Your secret API key starting with `sk_live_`. */
|
|
18
|
+
secretKey: string;
|
|
19
|
+
/** Optional internal secret for system-to-system communication. */
|
|
20
|
+
internalSecret?: string;
|
|
21
|
+
/** The base URL of the Quasar Cloud API. Defaults to 'https://api.tuwa.io'. */
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
/** Request timeout in milliseconds. Defaults to 10000. */
|
|
24
|
+
timeout?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Query parameters for filtering and paginating transaction history.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
interface HistoryQuery {
|
|
32
|
+
/** Page number for pagination (1-indexed). */
|
|
33
|
+
page?: number;
|
|
34
|
+
/** Maximum number of results to return per page. */
|
|
35
|
+
limit?: number;
|
|
36
|
+
/** Filter by blockchain chain ID (e.g., 1, 'solana'). */
|
|
37
|
+
chainId?: string | number;
|
|
38
|
+
/** Filter by transaction status (e.g., 'Success', 'Failed'). */
|
|
39
|
+
status?: string;
|
|
40
|
+
/** Filter by a specific Quasar transaction key. */
|
|
41
|
+
txKey?: string;
|
|
42
|
+
/** Filter by the application name. */
|
|
43
|
+
appName?: string;
|
|
44
|
+
/** Filter by the sender's wallet address. */
|
|
45
|
+
walletAddress?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Generic wrapper for paginated API responses.
|
|
49
|
+
*
|
|
50
|
+
* @typeParam T - The type of the documents contained in the result set.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
interface PaginatedResult<T> {
|
|
54
|
+
/** Array of documents for the current page. */
|
|
55
|
+
docs: T[];
|
|
56
|
+
/** Total number of documents matching the query. */
|
|
57
|
+
totalDocs: number;
|
|
58
|
+
/** Total number of available pages. */
|
|
59
|
+
totalPages: number;
|
|
60
|
+
/** The current page number (1-indexed). */
|
|
61
|
+
page: number;
|
|
62
|
+
/** Indicates if a subsequent page is available. */
|
|
63
|
+
hasNextPage: boolean;
|
|
64
|
+
/** Indicates if a preceding page is available. */
|
|
65
|
+
hasPrevPage: boolean;
|
|
66
|
+
}
|
|
8
67
|
|
|
9
68
|
/**
|
|
10
69
|
* @module core/client
|
|
@@ -196,110 +255,6 @@ declare class PulsarModule {
|
|
|
196
255
|
getHistory(query?: HistoryQuery): Promise<PaginatedResult<Transaction>>;
|
|
197
256
|
}
|
|
198
257
|
|
|
199
|
-
/**
|
|
200
|
-
* @module utils/auth
|
|
201
|
-
* @description Security utilities for Mini-Session signature creation and verification.
|
|
202
|
-
* Supports dual-ecosystem (EVM & Solana) authentication flows with strict type safety.
|
|
203
|
-
*/
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Default maximum allowed age for a signature (5 minutes).
|
|
207
|
-
* Prevents replay attacks using stale signatures.
|
|
208
|
-
* @internal
|
|
209
|
-
*/
|
|
210
|
-
declare const DEFAULT_MAX_AGE: number;
|
|
211
|
-
/**
|
|
212
|
-
* Safety buffer subtracted from DEFAULT_MAX_AGE during cache validation.
|
|
213
|
-
* Ensures the session is refreshed before it expires on the server,
|
|
214
|
-
* accounting for network round-trip latency between client cache check
|
|
215
|
-
* and server-side verifyMiniSession call.
|
|
216
|
-
* @public
|
|
217
|
-
*/
|
|
218
|
-
declare const NETWORK_SAFETY_BUFFER: number;
|
|
219
|
-
/**
|
|
220
|
-
* Standardizes the message format for Mini-Session authentication.
|
|
221
|
-
* Both frontend and backend MUST use this exact template for verification to pass.
|
|
222
|
-
*
|
|
223
|
-
* @param timestamp - ISO string timestamp (e.g., `new Date().toISOString()`).
|
|
224
|
-
* @returns The formatted message string to be signed.
|
|
225
|
-
*
|
|
226
|
-
* @example
|
|
227
|
-
* ```typescript
|
|
228
|
-
* const msg = createMiniSessionMessage(new Date().toISOString());
|
|
229
|
-
* // msg -> "Mini-Session Login: 2026-05-13T10:00:00.000Z"
|
|
230
|
-
* ```
|
|
231
|
-
*/
|
|
232
|
-
declare function createMiniSessionMessage(timestamp: string): string;
|
|
233
|
-
/**
|
|
234
|
-
* Triggers a signature request in the connected wallet to create a Mini-Session.
|
|
235
|
-
*
|
|
236
|
-
* This function detects the signer's capabilities and uses the most appropriate
|
|
237
|
-
* signing method available (e.g., Web3 v2, Standard, or Legacy).
|
|
238
|
-
*
|
|
239
|
-
* @param params - Parameters containing the signer and target ecosystem.
|
|
240
|
-
* @returns A promise resolving to the signature and timestamp.
|
|
241
|
-
* @throws {Error} If signing fails or the signer lacks required methods.
|
|
242
|
-
*
|
|
243
|
-
* @public
|
|
244
|
-
*/
|
|
245
|
-
declare function signMiniSession(params: SignSessionParams): Promise<SignSessionResult>;
|
|
246
|
-
/**
|
|
247
|
-
* Verifies a Mini-Session signature for authenticity and freshness.
|
|
248
|
-
*
|
|
249
|
-
* Performs cryptographic verification against the provided wallet address and
|
|
250
|
-
* ensures the signature hasn't expired according to the `maxAge` parameter.
|
|
251
|
-
*
|
|
252
|
-
* @param params - Verification data including signature and timestamp.
|
|
253
|
-
* @returns A promise resolving to true if the session is valid.
|
|
254
|
-
*
|
|
255
|
-
* @public
|
|
256
|
-
*/
|
|
257
|
-
declare function verifyMiniSession(params: VerifySessionParams): Promise<boolean>;
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Creates a persistent Zustand store to cache Mini-Session signatures.
|
|
261
|
-
* This is the recommended way to manage sessions in React applications.
|
|
262
|
-
*
|
|
263
|
-
* @param storageName - The localStorage key for persistence. Defaults to 'mini-session-storage'.
|
|
264
|
-
* @returns A Zustand store instance initialized with MiniSessionStore interface.
|
|
265
|
-
*
|
|
266
|
-
* @public
|
|
267
|
-
*/
|
|
268
|
-
declare function createMiniSessionStore(storageName?: string): zustand.UseBoundStore<Omit<zustand.StoreApi<MiniSessionStore>, "setState" | "persist"> & {
|
|
269
|
-
setState(partial: MiniSessionStore | Partial<MiniSessionStore> | ((state: MiniSessionStore) => MiniSessionStore | Partial<MiniSessionStore>), replace?: false | undefined): unknown;
|
|
270
|
-
setState(state: MiniSessionStore | ((state: MiniSessionStore) => MiniSessionStore), replace: true): unknown;
|
|
271
|
-
persist: {
|
|
272
|
-
setOptions: (options: Partial<zustand_middleware.PersistOptions<MiniSessionStore, MiniSessionStore, unknown>>) => void;
|
|
273
|
-
clearStorage: () => void;
|
|
274
|
-
rehydrate: () => Promise<void> | void;
|
|
275
|
-
hasHydrated: () => boolean;
|
|
276
|
-
onHydrate: (fn: (state: MiniSessionStore) => void) => () => void;
|
|
277
|
-
onFinishHydration: (fn: (state: MiniSessionStore) => void) => () => void;
|
|
278
|
-
getOptions: () => Partial<zustand_middleware.PersistOptions<MiniSessionStore, MiniSessionStore, unknown>>;
|
|
279
|
-
};
|
|
280
|
-
}>;
|
|
281
|
-
/**
|
|
282
|
-
* High-level orchestrator to retrieve an existing Mini-Session or trigger a new signature.
|
|
283
|
-
*
|
|
284
|
-
* This function checks the provided store for a valid, non-expired session matching
|
|
285
|
-
* the current wallet connection. If no session is found or it has expired, it
|
|
286
|
-
* triggers a signature request through the wallet.
|
|
287
|
-
*
|
|
288
|
-
* @param connection - The current active wallet connection data (address, signer, etc).
|
|
289
|
-
* @param store - A store implementation (Zustand or compatible) for session persistence.
|
|
290
|
-
* @param maxAge - Maximum allowed session age in milliseconds. Must match the value
|
|
291
|
-
* passed to `verifyMiniSession` to keep cache and verification in sync.
|
|
292
|
-
* Defaults to `DEFAULT_MAX_AGE` (5 minutes).
|
|
293
|
-
* @returns A promise resolving to a valid MiniSessionAuth object.
|
|
294
|
-
* @throws {Error} If the wallet is disconnected or signing fails.
|
|
295
|
-
*
|
|
296
|
-
* @public
|
|
297
|
-
*/
|
|
298
|
-
declare function getMiniSessionAuth(connection: ConnectionData, store: {
|
|
299
|
-
miniSession: MiniSessionAuth | null;
|
|
300
|
-
setMiniSession: (session: MiniSessionAuth | null) => void;
|
|
301
|
-
}, maxAge?: number): Promise<MiniSessionAuth>;
|
|
302
|
-
|
|
303
258
|
declare const BASE_API_URL = "https://api.tuwa.io";
|
|
304
259
|
declare const PULSAR_SYNC_ENDPOINT = "/v1/engine/pulsar/sync";
|
|
305
260
|
declare const PULSAR_HISTORY_ENDPOINT = "/v1/engine/pulsar/history";
|
|
@@ -324,40 +279,15 @@ declare const PULSAR_HISTORY_ENDPOINT = "/v1/engine/pulsar/history";
|
|
|
324
279
|
*/
|
|
325
280
|
|
|
326
281
|
/**
|
|
327
|
-
*
|
|
282
|
+
* Pre-flight check before initiating a transaction.
|
|
283
|
+
* Ensures the local SIWX Session is valid and verifies Quasar Engine health.
|
|
328
284
|
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
285
|
+
* @param customApiUrl - Optional custom API URL to override the default.
|
|
286
|
+
* @throws {Error} If the session check fails or Quasar is unreachable.
|
|
331
287
|
*
|
|
332
288
|
* @public
|
|
333
289
|
*/
|
|
334
|
-
declare
|
|
335
|
-
/**
|
|
336
|
-
* Standardizes the message format for Quasar Mini-Session login.
|
|
337
|
-
* @see {@link createMiniSessionMessage}
|
|
338
|
-
*/
|
|
339
|
-
createMiniSessionMessage: typeof createMiniSessionMessage;
|
|
340
|
-
/**
|
|
341
|
-
* Verifies a Mini-Session signature (EVM or Solana).
|
|
342
|
-
* @see {@link verifyMiniSession}
|
|
343
|
-
*/
|
|
344
|
-
verifyMiniSession: typeof verifyMiniSession;
|
|
345
|
-
/**
|
|
346
|
-
* Triggers a signature request in the connected wallet.
|
|
347
|
-
* @see {@link signMiniSession}
|
|
348
|
-
*/
|
|
349
|
-
signMiniSession: typeof signMiniSession;
|
|
350
|
-
/**
|
|
351
|
-
* Creates a persistent Zustand store for session management.
|
|
352
|
-
* @see {@link createMiniSessionStore}
|
|
353
|
-
*/
|
|
354
|
-
createMiniSessionStore: typeof createMiniSessionStore;
|
|
355
|
-
/**
|
|
356
|
-
* Reusable helper to manage signing and session caching.
|
|
357
|
-
* @see {@link getMiniSessionAuth}
|
|
358
|
-
*/
|
|
359
|
-
getMiniSessionAuth: typeof getMiniSessionAuth;
|
|
360
|
-
};
|
|
290
|
+
declare function preFlightTxCheck(customApiUrl?: string): Promise<void>;
|
|
361
291
|
/**
|
|
362
292
|
* Main entry point for the Quasar SDK.
|
|
363
293
|
*
|
|
@@ -383,37 +313,6 @@ declare const utils: {
|
|
|
383
313
|
* @public
|
|
384
314
|
*/
|
|
385
315
|
declare class Quasar {
|
|
386
|
-
/**
|
|
387
|
-
* Security and authentication utilities.
|
|
388
|
-
* Shared across all instances and available statically.
|
|
389
|
-
*/
|
|
390
|
-
static readonly utils: {
|
|
391
|
-
/**
|
|
392
|
-
* Standardizes the message format for Quasar Mini-Session login.
|
|
393
|
-
* @see {@link createMiniSessionMessage}
|
|
394
|
-
*/
|
|
395
|
-
createMiniSessionMessage: typeof createMiniSessionMessage;
|
|
396
|
-
/**
|
|
397
|
-
* Verifies a Mini-Session signature (EVM or Solana).
|
|
398
|
-
* @see {@link verifyMiniSession}
|
|
399
|
-
*/
|
|
400
|
-
verifyMiniSession: typeof verifyMiniSession;
|
|
401
|
-
/**
|
|
402
|
-
* Triggers a signature request in the connected wallet.
|
|
403
|
-
* @see {@link signMiniSession}
|
|
404
|
-
*/
|
|
405
|
-
signMiniSession: typeof signMiniSession;
|
|
406
|
-
/**
|
|
407
|
-
* Creates a persistent Zustand store for session management.
|
|
408
|
-
* @see {@link createMiniSessionStore}
|
|
409
|
-
*/
|
|
410
|
-
createMiniSessionStore: typeof createMiniSessionStore;
|
|
411
|
-
/**
|
|
412
|
-
* Reusable helper to manage signing and session caching.
|
|
413
|
-
* @see {@link getMiniSessionAuth}
|
|
414
|
-
*/
|
|
415
|
-
getMiniSessionAuth: typeof getMiniSessionAuth;
|
|
416
|
-
};
|
|
417
316
|
/**
|
|
418
317
|
* The internal HTTP client used for authenticated requests.
|
|
419
318
|
* @internal
|
|
@@ -442,4 +341,4 @@ declare class Quasar {
|
|
|
442
341
|
constructor(config: QuasarConfig);
|
|
443
342
|
}
|
|
444
343
|
|
|
445
|
-
export { BASE_API_URL,
|
|
344
|
+
export { BASE_API_URL, type HistoryQuery, PULSAR_HISTORY_ENDPOINT, PULSAR_SYNC_ENDPOINT, type PaginatedResult, PulsarModule, Quasar, type QuasarConfig, QuasarSDKError, preFlightTxCheck };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {useSiwxSessionStore}from'@tuwaio/siwx-react';import {ofetch}from'ofetch';var a="https://api.tuwa.io",c="/v1/engine/pulsar/sync",u="/v1/engine/pulsar/history";var i=class extends Error{status;originalError;constructor(r,e,t){super(r),this.name="QuasarSDKError",this.status=e,this.originalError=t;}},n=class{secretKey;internalSecret;baseUrl;timeout;constructor(r){if(!r.secretKey)throw new Error("[Quasar SDK] Missing API Key. Provide a secretKey starting with sk_live_.");this.secretKey=r.secretKey,this.internalSecret=r.internalSecret,this.baseUrl=r.baseUrl||a,this.timeout=r.timeout||1e4;}async request(r,e={}){try{return await ofetch(r,{baseURL:this.baseUrl,timeout:this.timeout,...e,headers:{"Content-Type":"application/json","x-tuwa-secret-key":this.secretKey,...this.internalSecret?{"x-internal-secret":this.internalSecret}:{},...e.headers}})}catch(t){throw this.buildError(t)}}buildError(r){let e=r,t=e.statusCode??e.response?.status,p=(e.data??e.response?._data)?.error??e.message??"Unknown Error";return (t===401||t===403)&&console.error("\u{1F6A8} [Quasar SDK] Auth Error. Check your Secret Key and scopes."),new i(`[Quasar SDK] Request Failed (${t}): ${p}`,t,e)}};var o=class{constructor(r){this.client=r;}async syncCreate(r,e){return this.client.request(c,{method:"POST",body:{...r,appName:e}})}async getHistory(r={}){return this.client.request(u,{method:"GET",query:{page:r.page??1,limit:r.limit??10,chainId:r.chainId,status:r.status,txKey:r.txKey,appName:r.appName,walletAddress:r.walletAddress}})}};async function Q(s){if(!useSiwxSessionStore.getState().session)throw new Error("[QuasarSDK] No SIWX Session found. User must be signed in.");let e=s||a;try{let t=await fetch(`${e}/v1/engine/monitoring/health`,{method:"GET",cache:"no-store"});if(!t.ok)throw new Error(`[QuasarSDK] API Health check failed with status: ${t.status}`)}catch(t){throw new Error("[QuasarSDK] Quasar Cloud Engine is currently unreachable.",{cause:t})}}var l=class{client;pulsar;constructor(r){this.client=new n(r),this.pulsar=new o(this.client);}};
|
|
2
|
+
export{a as BASE_API_URL,u as PULSAR_HISTORY_ENDPOINT,c as PULSAR_SYNC_ENDPOINT,o as PulsarModule,l as Quasar,i as QuasarSDKError,Q as preFlightTxCheck};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/quasar-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -14,26 +14,6 @@
|
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"import": "./dist/index.js",
|
|
16
16
|
"require": "./dist/index.cjs"
|
|
17
|
-
},
|
|
18
|
-
"./react": {
|
|
19
|
-
"types": "./dist/react.d.ts",
|
|
20
|
-
"import": "./dist/react.js",
|
|
21
|
-
"require": "./dist/react.cjs"
|
|
22
|
-
},
|
|
23
|
-
"./react/evm": {
|
|
24
|
-
"types": "./dist/react/evm.d.ts",
|
|
25
|
-
"import": "./dist/react/evm.js",
|
|
26
|
-
"require": "./dist/react/evm.cjs"
|
|
27
|
-
},
|
|
28
|
-
"./react/solana": {
|
|
29
|
-
"types": "./dist/react/solana.d.ts",
|
|
30
|
-
"import": "./dist/react/solana.js",
|
|
31
|
-
"require": "./dist/react/solana.cjs"
|
|
32
|
-
},
|
|
33
|
-
"./react/shared": {
|
|
34
|
-
"types": "./dist/react/shared.d.ts",
|
|
35
|
-
"import": "./dist/react/shared.js",
|
|
36
|
-
"require": "./dist/react/shared.cjs"
|
|
37
17
|
}
|
|
38
18
|
},
|
|
39
19
|
"publishConfig": {
|
|
@@ -79,7 +59,6 @@
|
|
|
79
59
|
"quasar",
|
|
80
60
|
"cloud",
|
|
81
61
|
"sdk",
|
|
82
|
-
"siwe",
|
|
83
62
|
"next-auth",
|
|
84
63
|
"cosmos",
|
|
85
64
|
"playground",
|
|
@@ -101,15 +80,9 @@
|
|
|
101
80
|
}
|
|
102
81
|
],
|
|
103
82
|
"peerDependencies": {
|
|
104
|
-
"@solana/react": "6.x.x",
|
|
105
83
|
"@tuwaio/pulsar-core": ">=0.6.0",
|
|
106
|
-
"@wagmi/core": "3.x.x",
|
|
107
|
-
"@wallet-standard/react": "1.x.x",
|
|
108
|
-
"gill": ">=0.14.0",
|
|
109
84
|
"ofetch": ">=1.5.1",
|
|
110
|
-
"react": ">=
|
|
111
|
-
"viem": "2.x.x",
|
|
112
|
-
"zustand": "5.x.x"
|
|
85
|
+
"@tuwaio/siwx-react": ">=0.1.0"
|
|
113
86
|
},
|
|
114
87
|
"peerDependenciesMeta": {
|
|
115
88
|
"@tuwaio/pulsar-core": {
|
|
@@ -118,39 +91,20 @@
|
|
|
118
91
|
"ofetch": {
|
|
119
92
|
"optional": false
|
|
120
93
|
},
|
|
121
|
-
"
|
|
122
|
-
"optional": true
|
|
123
|
-
},
|
|
124
|
-
"gill": {
|
|
125
|
-
"optional": true
|
|
126
|
-
},
|
|
127
|
-
"zustand": {
|
|
128
|
-
"optional": true
|
|
129
|
-
},
|
|
130
|
-
"react": {
|
|
131
|
-
"optional": true
|
|
132
|
-
},
|
|
133
|
-
"@solana/react": {
|
|
134
|
-
"optional": true
|
|
135
|
-
},
|
|
136
|
-
"@wagmi/core": {
|
|
137
|
-
"optional": true
|
|
138
|
-
},
|
|
139
|
-
"@wallet-standard/react": {
|
|
94
|
+
"@tuwaio/siwx-react": {
|
|
140
95
|
"optional": true
|
|
141
96
|
}
|
|
142
97
|
},
|
|
143
98
|
"devDependencies": {
|
|
144
|
-
"@
|
|
145
|
-
"@tuwaio/pulsar-core": "^0.6.10",
|
|
146
|
-
"@types/react": "^19.2.18",
|
|
147
|
-
"@wagmi/core": "^3.6.4",
|
|
148
|
-
"@wallet-standard/react": "^1.0.3",
|
|
99
|
+
"@tuwaio/pulsar-core": "^0.6.11",
|
|
149
100
|
"ofetch": "^1.5.1",
|
|
150
|
-
"react": "^19.2.8",
|
|
151
101
|
"tsup": "^8.5.1",
|
|
152
102
|
"typescript": "^6.0.3",
|
|
153
|
-
"
|
|
103
|
+
"@tuwaio/siwx-react": "^0.1.0"
|
|
104
|
+
},
|
|
105
|
+
"dependencies": {
|
|
106
|
+
"@tuwaio/siwx-core": "^0.1.0",
|
|
107
|
+
"@tuwaio/siwx-server": "^0.1.0"
|
|
154
108
|
},
|
|
155
109
|
"scripts": {
|
|
156
110
|
"start": "tsup src/index.ts --watch",
|
package/dist/chunk-C3D4A4ZL.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';var chunkNJH5FYLU_cjs=require('./chunk-NJH5FYLU.cjs');exports.a=null;function a(e){exports.a=e;}async function o(){for(let e=0;e<15;e++){if(exports.a)return exports.a();await new Promise(n=>setTimeout(n,200));}throw new Error("[QuasarSDK] Auth helper not initialized. Ensure QuasarAuthBridge is mounted and wallet is connected.")}async function u(e){await o();let n=e||chunkNJH5FYLU_cjs.a;try{let t=await fetch(`${n}/v1/engine/monitoring/health`,{method:"GET",cache:"no-store"});if(!t.ok)throw new Error(`[QuasarSDK] API Health check failed with status: ${t.status}`)}catch(t){throw new Error("[QuasarSDK] Quasar Cloud Engine is currently unreachable.",{cause:t})}}exports.b=a;exports.c=o;exports.d=u;
|
package/dist/chunk-C6JAMIC3.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import {create}from'zustand';import {persist}from'zustand/middleware';var m=(t=>(t.EVM="EVM",t.SOLANA="SOLANA",t))(m||{});var u=300*1e3,w=60*1e3,y=30*1e3;function f(e){return `Mini-Session Login: ${e}`}async function p(e){let r=new Date().toISOString(),t=f(r);if(e.chainType==="EVM"){let i=e.signer;try{return {signature:await i.signMessage({account:e.walletAddress,message:t}),timestamp:r}}catch(n){throw new Error(`[SDK] EVM signing failed: ${n.message}`,{cause:n})}}if(e.chainType==="SOLANA"){let i=e.signer,n;try{n=await import('gill');}catch(s){throw new Error('[SDK] Peer dependency "gill" is required for Solana signing.',{cause:s})}try{let a=n.getUtf8Encoder().encode(t),o;if(i.modifyAndSignMessages){let g=n.createSignableMessage(a),d=(await i.modifyAndSignMessages([g]))[0].signatures[i.address];if(!d)throw new Error(`[SDK] Signature missing for address: ${i.address}`);o=d;}else if(i.signMessages){let S=(await i.signMessages([a]))[0];if(!S?.signature)throw new Error("[SDK] Wallet returned invalid signMessages output.");o=S.signature;}else if(i.signMessage)o=await i.signMessage(a);else throw new Error("[SDK] Signer lacks message signing capabilities.");return {signature:n.getSignatureFromBytes(o),timestamp:r}}catch(s){throw new Error(`[SDK] Solana signing failed: ${s.message}`,{cause:s})}}throw new Error(`[SDK] Unsupported chain type: ${e.chainType}`)}async function v(e){let r=new Date(e.timestamp).getTime(),t=Date.now();if(isNaN(r))throw new Error("[SDK] Invalid timestamp format. Use ISO string.");let i=e.maxAge??u;if(t-r>i)throw new Error("[SDK] Signature expired. Please sign a fresh message.");if(r>t+w)throw new Error("[SDK] Timestamp is in the future. Check your system clock.");let n=f(e.timestamp);if(e.chainType==="EVM"){let s;try{s=await import('viem');}catch(a){throw new Error('[SDK] Peer dependency "viem" is required for EVM verification.',{cause:a})}return await s.verifyMessage({address:e.walletAddress,message:n,signature:e.signature})}if(e.chainType==="SOLANA"){let s;try{s=await import('gill');}catch(a){throw new Error('[SDK] Peer dependency "gill" is required for Solana verification.',{cause:a})}try{let a=s.address(e.walletAddress);return await s.verifySignatureForAddress(a,e.signature,n)}catch{return false}}return false}var c=null;function C(e="mini-session-storage"){return create()(persist(r=>({miniSession:null,setMiniSession:t=>r({miniSession:t}),clearSession:()=>r({miniSession:null})}),{name:e}))}async function N(e,r,t=u){let{isConnected:i,address:n,chainType:s,signer:a}=e;if(!i||!n)throw new Error("[SDK] Wallet not connected. Please connect your wallet first.");let o=r.miniSession;if(o&&o.walletAddress===n&&o.chainType===s){let l=Date.now(),g=new Date(o.timestamp).getTime();if(l-g<t-y)return o}return c||(c=p({signer:a,walletAddress:n,chainType:s}).then(l=>{let g={...l,chainType:s,walletAddress:n};return r.setMiniSession(g),g}).finally(()=>{c=null;})),c}export{m as a,u as b,y as c,f as d,p as e,v as f,C as g,N as h};
|