@tuwaio/quasar-sdk 1.0.0-fix-docs-alpha.3.56f32d0 → 1.0.0-fix-docs-alpha.4.494fbc9
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.d.mts +139 -60
- package/dist/index.d.ts +139 -60
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +6 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { FetchOptions } from 'ofetch';
|
|
2
2
|
import { Transaction } from '@tuwaio/pulsar-core';
|
|
3
3
|
export { Transaction, UpdatableTransactionFields } from '@tuwaio/pulsar-core';
|
|
4
|
+
import * as zustand_middleware from 'zustand/middleware';
|
|
5
|
+
import * as zustand from 'zustand';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* @module types
|
|
@@ -137,6 +139,81 @@ interface PaginatedResult<T> {
|
|
|
137
139
|
hasPrevPage: boolean;
|
|
138
140
|
}
|
|
139
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Supported blockchain ecosystems for authentication.
|
|
144
|
+
* @public
|
|
145
|
+
*/
|
|
146
|
+
declare enum ChainType {
|
|
147
|
+
EVM = "EVM",
|
|
148
|
+
SOLANA = "SOLANA"
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Result of the Mini-Session signing process.
|
|
152
|
+
* Used for both frontend-side caching and backend-side verification.
|
|
153
|
+
* @public
|
|
154
|
+
*/
|
|
155
|
+
interface MiniSessionAuth {
|
|
156
|
+
/** The cryptographic signature (hex for EVM, base58 for Solana). */
|
|
157
|
+
signature: string;
|
|
158
|
+
/** ISO string timestamp used in the signed message. */
|
|
159
|
+
timestamp: string;
|
|
160
|
+
/** The blockchain ecosystem type. */
|
|
161
|
+
chainType: ChainType;
|
|
162
|
+
/** The wallet address that signed the message. */
|
|
163
|
+
walletAddress: string;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Parameters for verifying a mini-session signature.
|
|
167
|
+
* @public
|
|
168
|
+
*/
|
|
169
|
+
interface VerifySessionParams extends Omit<MiniSessionAuth, 'walletAddress'> {
|
|
170
|
+
/** The wallet address that allegedly signed the message. */
|
|
171
|
+
walletAddress: string;
|
|
172
|
+
/**
|
|
173
|
+
* Maximum allowed age for the signature in milliseconds.
|
|
174
|
+
* Default: 5 minutes (300,000ms).
|
|
175
|
+
*/
|
|
176
|
+
maxAge?: number;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Parameters for signing a mini-session message.
|
|
180
|
+
* @public
|
|
181
|
+
*/
|
|
182
|
+
interface SignSessionParams {
|
|
183
|
+
/** The signer object. For EVM, a `WalletClient`. For Solana, a `KeyPairSigner` or `TransactionSendingSigner`. */
|
|
184
|
+
signer: any;
|
|
185
|
+
/** The wallet address to sign with (required for EVM). */
|
|
186
|
+
walletAddress?: string;
|
|
187
|
+
/** The blockchain ecosystem type. */
|
|
188
|
+
chainType: ChainType;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Zustand store interface for managing Mini-Sessions.
|
|
192
|
+
* @public
|
|
193
|
+
*/
|
|
194
|
+
interface MiniSessionStore {
|
|
195
|
+
/** Current active session or null. */
|
|
196
|
+
miniSession: MiniSessionAuth | null;
|
|
197
|
+
/** Sets the active session. */
|
|
198
|
+
setMiniSession: (session: MiniSessionAuth | null) => void;
|
|
199
|
+
/** Clears the current session. */
|
|
200
|
+
clearSession: () => void;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Minimum connection data required for Mini-Session signing.
|
|
204
|
+
* @public
|
|
205
|
+
*/
|
|
206
|
+
interface ConnectionData {
|
|
207
|
+
/** Whether a wallet is currently connected. */
|
|
208
|
+
isConnected: boolean;
|
|
209
|
+
/** The active wallet address. */
|
|
210
|
+
address: string;
|
|
211
|
+
/** The blockchain ecosystem type. */
|
|
212
|
+
chainType: ChainType;
|
|
213
|
+
/** The wallet signer object (WalletClient for EVM, TransactionSendingSigner for Solana). */
|
|
214
|
+
signer: any;
|
|
215
|
+
}
|
|
216
|
+
|
|
140
217
|
/**
|
|
141
218
|
* @module core/client
|
|
142
219
|
* @description Core HTTP client for the Quasar SDK.
|
|
@@ -331,26 +408,9 @@ declare class PulsarModule {
|
|
|
331
408
|
* @module utils/auth
|
|
332
409
|
* @description Security utilities for Mini-Session signature verification.
|
|
333
410
|
*/
|
|
411
|
+
|
|
334
412
|
/**
|
|
335
|
-
*
|
|
336
|
-
*/
|
|
337
|
-
interface VerifySessionParams {
|
|
338
|
-
/** The wallet address that allegedly signed the message. */
|
|
339
|
-
walletAddress: string;
|
|
340
|
-
/** ISO string timestamp matching the one used in the message. */
|
|
341
|
-
timestamp: string;
|
|
342
|
-
/** The cryptographic signature (hex for EVM, base58 for Solana). */
|
|
343
|
-
signature: string;
|
|
344
|
-
/** The blockchain ecosystem type. */
|
|
345
|
-
chainType: 'evm' | 'solana';
|
|
346
|
-
/**
|
|
347
|
-
* Maximum allowed age for the signature in milliseconds.
|
|
348
|
-
* Default: 5 minutes (300,000ms).
|
|
349
|
-
*/
|
|
350
|
-
maxAge?: number;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Standardizes the message format for Quasar Mini-Session login.
|
|
413
|
+
* Standardizes the message format for Mini-Session login.
|
|
354
414
|
* Both frontend and backend must use this exact template.
|
|
355
415
|
*
|
|
356
416
|
* @param timestamp - ISO string timestamp (e.g., `new Date().toISOString()`).
|
|
@@ -359,21 +419,10 @@ interface VerifySessionParams {
|
|
|
359
419
|
* @example
|
|
360
420
|
* ```typescript
|
|
361
421
|
* const msg = createMiniSessionMessage(new Date().toISOString());
|
|
362
|
-
* // msg -> "
|
|
422
|
+
* // msg -> "Mini-Session Login: 2026-05-13T10:00:00.000Z"
|
|
363
423
|
* ```
|
|
364
424
|
*/
|
|
365
425
|
declare function createMiniSessionMessage(timestamp: string): string;
|
|
366
|
-
/**
|
|
367
|
-
* Parameters for signing a mini-session message.
|
|
368
|
-
*/
|
|
369
|
-
interface SignSessionParams {
|
|
370
|
-
/** The signer object. For EVM, a `WalletClient`. For Solana, a `KeyPairSigner` or `TransactionSendingSigner`. */
|
|
371
|
-
signer: any;
|
|
372
|
-
/** The wallet address to sign with (required for EVM). */
|
|
373
|
-
walletAddress?: string;
|
|
374
|
-
/** The blockchain ecosystem type. */
|
|
375
|
-
chainType: 'evm' | 'solana';
|
|
376
|
-
}
|
|
377
426
|
/**
|
|
378
427
|
* Result of a mini-session signing operation.
|
|
379
428
|
*/
|
|
@@ -388,29 +437,13 @@ interface SignSessionResult {
|
|
|
388
437
|
*
|
|
389
438
|
* This is a frontend-friendly helper that:
|
|
390
439
|
* 1. Generates a fresh ISO timestamp.
|
|
391
|
-
* 2. Formats the standard
|
|
440
|
+
* 2. Formats the standard login message.
|
|
392
441
|
* 3. Triggers the wallet's signMessage method.
|
|
393
442
|
* 4. Returns the signature and timestamp for verification on the backend.
|
|
394
443
|
*
|
|
395
444
|
* @param params - The signing parameters including the signer and ecosystem type.
|
|
396
445
|
* @returns A promise that resolves to the signature and timestamp.
|
|
397
446
|
* @throws {Error} If the required peer dependencies are missing or signing fails.
|
|
398
|
-
*
|
|
399
|
-
* @example
|
|
400
|
-
* ```typescript
|
|
401
|
-
* // EVM (viem)
|
|
402
|
-
* const { signature, timestamp } = await signMiniSession({
|
|
403
|
-
* signer: walletClient,
|
|
404
|
-
* walletAddress: '0x...',
|
|
405
|
-
* chainType: 'evm',
|
|
406
|
-
* });
|
|
407
|
-
*
|
|
408
|
-
* // Solana (gill)
|
|
409
|
-
* const { signature, timestamp } = await signMiniSession({
|
|
410
|
-
* signer: keypairSigner,
|
|
411
|
-
* chainType: 'solana',
|
|
412
|
-
* });
|
|
413
|
-
* ```
|
|
414
447
|
*/
|
|
415
448
|
declare function signMiniSession(params: SignSessionParams): Promise<SignSessionResult>;
|
|
416
449
|
/**
|
|
@@ -419,25 +452,51 @@ declare function signMiniSession(params: SignSessionParams): Promise<SignSession
|
|
|
419
452
|
* This utility performs three checks:
|
|
420
453
|
* 1. Timestamp freshness (rejects if older than 5 minutes or in the future).
|
|
421
454
|
* 2. Cryptographic validity (checks if the signature matches the wallet address and message).
|
|
422
|
-
* 3.
|
|
455
|
+
* 3. Ecosystem-specific logic (EVM via `viem`, Solana via `gill`).
|
|
423
456
|
*
|
|
424
457
|
* @param params - The verification parameters including address, signature, and timestamp.
|
|
425
458
|
* @returns A promise that resolves to `true` if the signature is valid and fresh.
|
|
426
459
|
* @throws {Error} If the required peer dependencies (`viem` or `gill`) are missing.
|
|
427
460
|
* @throws {Error} If the timestamp is invalid or expired.
|
|
428
|
-
*
|
|
429
|
-
* @example
|
|
430
|
-
* ```typescript
|
|
431
|
-
* const isValid = await verifyMiniSession({
|
|
432
|
-
* walletAddress: '0x...',
|
|
433
|
-
* timestamp: '2026-05-13T10:00:00.000Z',
|
|
434
|
-
* signature: '0x...',
|
|
435
|
-
* chainType: 'evm',
|
|
436
|
-
* });
|
|
437
|
-
* ```
|
|
438
461
|
*/
|
|
439
462
|
declare function verifyMiniSession(params: VerifySessionParams): Promise<boolean>;
|
|
440
463
|
|
|
464
|
+
/**
|
|
465
|
+
* Creates a persistent Zustand store to cache Mini-Session signatures.
|
|
466
|
+
* Requires `zustand` to be installed as a peer dependency.
|
|
467
|
+
*
|
|
468
|
+
* @param storageName - Key name for localStorage persistence.
|
|
469
|
+
* @returns A Zustand store instance.
|
|
470
|
+
*/
|
|
471
|
+
declare function createMiniSessionStore(storageName?: string): zustand.UseBoundStore<Omit<zustand.StoreApi<MiniSessionStore>, "setState" | "persist"> & {
|
|
472
|
+
setState(partial: MiniSessionStore | Partial<MiniSessionStore> | ((state: MiniSessionStore) => MiniSessionStore | Partial<MiniSessionStore>), replace?: false | undefined): unknown;
|
|
473
|
+
setState(state: MiniSessionStore | ((state: MiniSessionStore) => MiniSessionStore), replace: true): unknown;
|
|
474
|
+
persist: {
|
|
475
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<MiniSessionStore, MiniSessionStore, unknown>>) => void;
|
|
476
|
+
clearStorage: () => void;
|
|
477
|
+
rehydrate: () => Promise<void> | void;
|
|
478
|
+
hasHydrated: () => boolean;
|
|
479
|
+
onHydrate: (fn: (state: MiniSessionStore) => void) => () => void;
|
|
480
|
+
onFinishHydration: (fn: (state: MiniSessionStore) => void) => () => void;
|
|
481
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<MiniSessionStore, MiniSessionStore, unknown>>;
|
|
482
|
+
};
|
|
483
|
+
}>;
|
|
484
|
+
/**
|
|
485
|
+
* Generic helper to manage Mini-Session signing and caching.
|
|
486
|
+
*
|
|
487
|
+
* Checks the provided store for an existing session matching the current connection.
|
|
488
|
+
* If no session is found, it triggers a signature request using the provided signer.
|
|
489
|
+
*
|
|
490
|
+
* @param connection - Current active connection state.
|
|
491
|
+
* @param store - An object compatible with MiniSessionStore to read/write the session.
|
|
492
|
+
* @returns A promise resolving to the authenticated session.
|
|
493
|
+
* @throws {Error} If no wallet is connected or signing fails.
|
|
494
|
+
*/
|
|
495
|
+
declare function getMiniSessionAuth(connection: ConnectionData, store: {
|
|
496
|
+
miniSession: MiniSessionAuth | null;
|
|
497
|
+
setMiniSession: (s: MiniSessionAuth) => void;
|
|
498
|
+
}): Promise<MiniSessionAuth>;
|
|
499
|
+
|
|
441
500
|
declare const BASE_API_URL = "https://api.tuwa.io";
|
|
442
501
|
declare const PULSAR_SYNC_ENDPOINT = "/v1/engine/pulsar/sync";
|
|
443
502
|
declare const PULSAR_HISTORY_ENDPOINT = "/v1/engine/pulsar/history";
|
|
@@ -485,6 +544,16 @@ declare const utils: {
|
|
|
485
544
|
* @see {@link signMiniSession}
|
|
486
545
|
*/
|
|
487
546
|
signMiniSession: typeof signMiniSession;
|
|
547
|
+
/**
|
|
548
|
+
* Creates a persistent Zustand store for session management.
|
|
549
|
+
* @see {@link createMiniSessionStore}
|
|
550
|
+
*/
|
|
551
|
+
createMiniSessionStore: typeof createMiniSessionStore;
|
|
552
|
+
/**
|
|
553
|
+
* Reusable helper to manage signing and session caching.
|
|
554
|
+
* @see {@link getMiniSessionAuth}
|
|
555
|
+
*/
|
|
556
|
+
getMiniSessionAuth: typeof getMiniSessionAuth;
|
|
488
557
|
};
|
|
489
558
|
/**
|
|
490
559
|
* Main entry point for the Quasar SDK.
|
|
@@ -531,6 +600,16 @@ declare class Quasar {
|
|
|
531
600
|
* @see {@link signMiniSession}
|
|
532
601
|
*/
|
|
533
602
|
signMiniSession: typeof signMiniSession;
|
|
603
|
+
/**
|
|
604
|
+
* Creates a persistent Zustand store for session management.
|
|
605
|
+
* @see {@link createMiniSessionStore}
|
|
606
|
+
*/
|
|
607
|
+
createMiniSessionStore: typeof createMiniSessionStore;
|
|
608
|
+
/**
|
|
609
|
+
* Reusable helper to manage signing and session caching.
|
|
610
|
+
* @see {@link getMiniSessionAuth}
|
|
611
|
+
*/
|
|
612
|
+
getMiniSessionAuth: typeof getMiniSessionAuth;
|
|
534
613
|
};
|
|
535
614
|
/**
|
|
536
615
|
* The internal HTTP client used for authenticated requests.
|
|
@@ -560,4 +639,4 @@ declare class Quasar {
|
|
|
560
639
|
constructor(config: QuasarConfig);
|
|
561
640
|
}
|
|
562
641
|
|
|
563
|
-
export { BASE_API_URL, type HistoryQuery, PULSAR_HISTORY_ENDPOINT, PULSAR_SYNC_ENDPOINT, type PaginatedResult, PulsarModule, Quasar, type QuasarConfig, QuasarSDKError, type SignSessionParams, type SignSessionResult, type VerifySessionParams, createMiniSessionMessage, signMiniSession, utils, verifyMiniSession };
|
|
642
|
+
export { BASE_API_URL, ChainType, type ConnectionData, type HistoryQuery, type MiniSessionAuth, type MiniSessionStore, PULSAR_HISTORY_ENDPOINT, PULSAR_SYNC_ENDPOINT, type PaginatedResult, PulsarModule, Quasar, type QuasarConfig, QuasarSDKError, type SignSessionParams, type SignSessionResult, type VerifySessionParams, createMiniSessionMessage, createMiniSessionStore, getMiniSessionAuth, signMiniSession, utils, verifyMiniSession };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { FetchOptions } from 'ofetch';
|
|
2
2
|
import { Transaction } from '@tuwaio/pulsar-core';
|
|
3
3
|
export { Transaction, UpdatableTransactionFields } from '@tuwaio/pulsar-core';
|
|
4
|
+
import * as zustand_middleware from 'zustand/middleware';
|
|
5
|
+
import * as zustand from 'zustand';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* @module types
|
|
@@ -137,6 +139,81 @@ interface PaginatedResult<T> {
|
|
|
137
139
|
hasPrevPage: boolean;
|
|
138
140
|
}
|
|
139
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Supported blockchain ecosystems for authentication.
|
|
144
|
+
* @public
|
|
145
|
+
*/
|
|
146
|
+
declare enum ChainType {
|
|
147
|
+
EVM = "EVM",
|
|
148
|
+
SOLANA = "SOLANA"
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Result of the Mini-Session signing process.
|
|
152
|
+
* Used for both frontend-side caching and backend-side verification.
|
|
153
|
+
* @public
|
|
154
|
+
*/
|
|
155
|
+
interface MiniSessionAuth {
|
|
156
|
+
/** The cryptographic signature (hex for EVM, base58 for Solana). */
|
|
157
|
+
signature: string;
|
|
158
|
+
/** ISO string timestamp used in the signed message. */
|
|
159
|
+
timestamp: string;
|
|
160
|
+
/** The blockchain ecosystem type. */
|
|
161
|
+
chainType: ChainType;
|
|
162
|
+
/** The wallet address that signed the message. */
|
|
163
|
+
walletAddress: string;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Parameters for verifying a mini-session signature.
|
|
167
|
+
* @public
|
|
168
|
+
*/
|
|
169
|
+
interface VerifySessionParams extends Omit<MiniSessionAuth, 'walletAddress'> {
|
|
170
|
+
/** The wallet address that allegedly signed the message. */
|
|
171
|
+
walletAddress: string;
|
|
172
|
+
/**
|
|
173
|
+
* Maximum allowed age for the signature in milliseconds.
|
|
174
|
+
* Default: 5 minutes (300,000ms).
|
|
175
|
+
*/
|
|
176
|
+
maxAge?: number;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Parameters for signing a mini-session message.
|
|
180
|
+
* @public
|
|
181
|
+
*/
|
|
182
|
+
interface SignSessionParams {
|
|
183
|
+
/** The signer object. For EVM, a `WalletClient`. For Solana, a `KeyPairSigner` or `TransactionSendingSigner`. */
|
|
184
|
+
signer: any;
|
|
185
|
+
/** The wallet address to sign with (required for EVM). */
|
|
186
|
+
walletAddress?: string;
|
|
187
|
+
/** The blockchain ecosystem type. */
|
|
188
|
+
chainType: ChainType;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Zustand store interface for managing Mini-Sessions.
|
|
192
|
+
* @public
|
|
193
|
+
*/
|
|
194
|
+
interface MiniSessionStore {
|
|
195
|
+
/** Current active session or null. */
|
|
196
|
+
miniSession: MiniSessionAuth | null;
|
|
197
|
+
/** Sets the active session. */
|
|
198
|
+
setMiniSession: (session: MiniSessionAuth | null) => void;
|
|
199
|
+
/** Clears the current session. */
|
|
200
|
+
clearSession: () => void;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Minimum connection data required for Mini-Session signing.
|
|
204
|
+
* @public
|
|
205
|
+
*/
|
|
206
|
+
interface ConnectionData {
|
|
207
|
+
/** Whether a wallet is currently connected. */
|
|
208
|
+
isConnected: boolean;
|
|
209
|
+
/** The active wallet address. */
|
|
210
|
+
address: string;
|
|
211
|
+
/** The blockchain ecosystem type. */
|
|
212
|
+
chainType: ChainType;
|
|
213
|
+
/** The wallet signer object (WalletClient for EVM, TransactionSendingSigner for Solana). */
|
|
214
|
+
signer: any;
|
|
215
|
+
}
|
|
216
|
+
|
|
140
217
|
/**
|
|
141
218
|
* @module core/client
|
|
142
219
|
* @description Core HTTP client for the Quasar SDK.
|
|
@@ -331,26 +408,9 @@ declare class PulsarModule {
|
|
|
331
408
|
* @module utils/auth
|
|
332
409
|
* @description Security utilities for Mini-Session signature verification.
|
|
333
410
|
*/
|
|
411
|
+
|
|
334
412
|
/**
|
|
335
|
-
*
|
|
336
|
-
*/
|
|
337
|
-
interface VerifySessionParams {
|
|
338
|
-
/** The wallet address that allegedly signed the message. */
|
|
339
|
-
walletAddress: string;
|
|
340
|
-
/** ISO string timestamp matching the one used in the message. */
|
|
341
|
-
timestamp: string;
|
|
342
|
-
/** The cryptographic signature (hex for EVM, base58 for Solana). */
|
|
343
|
-
signature: string;
|
|
344
|
-
/** The blockchain ecosystem type. */
|
|
345
|
-
chainType: 'evm' | 'solana';
|
|
346
|
-
/**
|
|
347
|
-
* Maximum allowed age for the signature in milliseconds.
|
|
348
|
-
* Default: 5 minutes (300,000ms).
|
|
349
|
-
*/
|
|
350
|
-
maxAge?: number;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Standardizes the message format for Quasar Mini-Session login.
|
|
413
|
+
* Standardizes the message format for Mini-Session login.
|
|
354
414
|
* Both frontend and backend must use this exact template.
|
|
355
415
|
*
|
|
356
416
|
* @param timestamp - ISO string timestamp (e.g., `new Date().toISOString()`).
|
|
@@ -359,21 +419,10 @@ interface VerifySessionParams {
|
|
|
359
419
|
* @example
|
|
360
420
|
* ```typescript
|
|
361
421
|
* const msg = createMiniSessionMessage(new Date().toISOString());
|
|
362
|
-
* // msg -> "
|
|
422
|
+
* // msg -> "Mini-Session Login: 2026-05-13T10:00:00.000Z"
|
|
363
423
|
* ```
|
|
364
424
|
*/
|
|
365
425
|
declare function createMiniSessionMessage(timestamp: string): string;
|
|
366
|
-
/**
|
|
367
|
-
* Parameters for signing a mini-session message.
|
|
368
|
-
*/
|
|
369
|
-
interface SignSessionParams {
|
|
370
|
-
/** The signer object. For EVM, a `WalletClient`. For Solana, a `KeyPairSigner` or `TransactionSendingSigner`. */
|
|
371
|
-
signer: any;
|
|
372
|
-
/** The wallet address to sign with (required for EVM). */
|
|
373
|
-
walletAddress?: string;
|
|
374
|
-
/** The blockchain ecosystem type. */
|
|
375
|
-
chainType: 'evm' | 'solana';
|
|
376
|
-
}
|
|
377
426
|
/**
|
|
378
427
|
* Result of a mini-session signing operation.
|
|
379
428
|
*/
|
|
@@ -388,29 +437,13 @@ interface SignSessionResult {
|
|
|
388
437
|
*
|
|
389
438
|
* This is a frontend-friendly helper that:
|
|
390
439
|
* 1. Generates a fresh ISO timestamp.
|
|
391
|
-
* 2. Formats the standard
|
|
440
|
+
* 2. Formats the standard login message.
|
|
392
441
|
* 3. Triggers the wallet's signMessage method.
|
|
393
442
|
* 4. Returns the signature and timestamp for verification on the backend.
|
|
394
443
|
*
|
|
395
444
|
* @param params - The signing parameters including the signer and ecosystem type.
|
|
396
445
|
* @returns A promise that resolves to the signature and timestamp.
|
|
397
446
|
* @throws {Error} If the required peer dependencies are missing or signing fails.
|
|
398
|
-
*
|
|
399
|
-
* @example
|
|
400
|
-
* ```typescript
|
|
401
|
-
* // EVM (viem)
|
|
402
|
-
* const { signature, timestamp } = await signMiniSession({
|
|
403
|
-
* signer: walletClient,
|
|
404
|
-
* walletAddress: '0x...',
|
|
405
|
-
* chainType: 'evm',
|
|
406
|
-
* });
|
|
407
|
-
*
|
|
408
|
-
* // Solana (gill)
|
|
409
|
-
* const { signature, timestamp } = await signMiniSession({
|
|
410
|
-
* signer: keypairSigner,
|
|
411
|
-
* chainType: 'solana',
|
|
412
|
-
* });
|
|
413
|
-
* ```
|
|
414
447
|
*/
|
|
415
448
|
declare function signMiniSession(params: SignSessionParams): Promise<SignSessionResult>;
|
|
416
449
|
/**
|
|
@@ -419,25 +452,51 @@ declare function signMiniSession(params: SignSessionParams): Promise<SignSession
|
|
|
419
452
|
* This utility performs three checks:
|
|
420
453
|
* 1. Timestamp freshness (rejects if older than 5 minutes or in the future).
|
|
421
454
|
* 2. Cryptographic validity (checks if the signature matches the wallet address and message).
|
|
422
|
-
* 3.
|
|
455
|
+
* 3. Ecosystem-specific logic (EVM via `viem`, Solana via `gill`).
|
|
423
456
|
*
|
|
424
457
|
* @param params - The verification parameters including address, signature, and timestamp.
|
|
425
458
|
* @returns A promise that resolves to `true` if the signature is valid and fresh.
|
|
426
459
|
* @throws {Error} If the required peer dependencies (`viem` or `gill`) are missing.
|
|
427
460
|
* @throws {Error} If the timestamp is invalid or expired.
|
|
428
|
-
*
|
|
429
|
-
* @example
|
|
430
|
-
* ```typescript
|
|
431
|
-
* const isValid = await verifyMiniSession({
|
|
432
|
-
* walletAddress: '0x...',
|
|
433
|
-
* timestamp: '2026-05-13T10:00:00.000Z',
|
|
434
|
-
* signature: '0x...',
|
|
435
|
-
* chainType: 'evm',
|
|
436
|
-
* });
|
|
437
|
-
* ```
|
|
438
461
|
*/
|
|
439
462
|
declare function verifyMiniSession(params: VerifySessionParams): Promise<boolean>;
|
|
440
463
|
|
|
464
|
+
/**
|
|
465
|
+
* Creates a persistent Zustand store to cache Mini-Session signatures.
|
|
466
|
+
* Requires `zustand` to be installed as a peer dependency.
|
|
467
|
+
*
|
|
468
|
+
* @param storageName - Key name for localStorage persistence.
|
|
469
|
+
* @returns A Zustand store instance.
|
|
470
|
+
*/
|
|
471
|
+
declare function createMiniSessionStore(storageName?: string): zustand.UseBoundStore<Omit<zustand.StoreApi<MiniSessionStore>, "setState" | "persist"> & {
|
|
472
|
+
setState(partial: MiniSessionStore | Partial<MiniSessionStore> | ((state: MiniSessionStore) => MiniSessionStore | Partial<MiniSessionStore>), replace?: false | undefined): unknown;
|
|
473
|
+
setState(state: MiniSessionStore | ((state: MiniSessionStore) => MiniSessionStore), replace: true): unknown;
|
|
474
|
+
persist: {
|
|
475
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<MiniSessionStore, MiniSessionStore, unknown>>) => void;
|
|
476
|
+
clearStorage: () => void;
|
|
477
|
+
rehydrate: () => Promise<void> | void;
|
|
478
|
+
hasHydrated: () => boolean;
|
|
479
|
+
onHydrate: (fn: (state: MiniSessionStore) => void) => () => void;
|
|
480
|
+
onFinishHydration: (fn: (state: MiniSessionStore) => void) => () => void;
|
|
481
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<MiniSessionStore, MiniSessionStore, unknown>>;
|
|
482
|
+
};
|
|
483
|
+
}>;
|
|
484
|
+
/**
|
|
485
|
+
* Generic helper to manage Mini-Session signing and caching.
|
|
486
|
+
*
|
|
487
|
+
* Checks the provided store for an existing session matching the current connection.
|
|
488
|
+
* If no session is found, it triggers a signature request using the provided signer.
|
|
489
|
+
*
|
|
490
|
+
* @param connection - Current active connection state.
|
|
491
|
+
* @param store - An object compatible with MiniSessionStore to read/write the session.
|
|
492
|
+
* @returns A promise resolving to the authenticated session.
|
|
493
|
+
* @throws {Error} If no wallet is connected or signing fails.
|
|
494
|
+
*/
|
|
495
|
+
declare function getMiniSessionAuth(connection: ConnectionData, store: {
|
|
496
|
+
miniSession: MiniSessionAuth | null;
|
|
497
|
+
setMiniSession: (s: MiniSessionAuth) => void;
|
|
498
|
+
}): Promise<MiniSessionAuth>;
|
|
499
|
+
|
|
441
500
|
declare const BASE_API_URL = "https://api.tuwa.io";
|
|
442
501
|
declare const PULSAR_SYNC_ENDPOINT = "/v1/engine/pulsar/sync";
|
|
443
502
|
declare const PULSAR_HISTORY_ENDPOINT = "/v1/engine/pulsar/history";
|
|
@@ -485,6 +544,16 @@ declare const utils: {
|
|
|
485
544
|
* @see {@link signMiniSession}
|
|
486
545
|
*/
|
|
487
546
|
signMiniSession: typeof signMiniSession;
|
|
547
|
+
/**
|
|
548
|
+
* Creates a persistent Zustand store for session management.
|
|
549
|
+
* @see {@link createMiniSessionStore}
|
|
550
|
+
*/
|
|
551
|
+
createMiniSessionStore: typeof createMiniSessionStore;
|
|
552
|
+
/**
|
|
553
|
+
* Reusable helper to manage signing and session caching.
|
|
554
|
+
* @see {@link getMiniSessionAuth}
|
|
555
|
+
*/
|
|
556
|
+
getMiniSessionAuth: typeof getMiniSessionAuth;
|
|
488
557
|
};
|
|
489
558
|
/**
|
|
490
559
|
* Main entry point for the Quasar SDK.
|
|
@@ -531,6 +600,16 @@ declare class Quasar {
|
|
|
531
600
|
* @see {@link signMiniSession}
|
|
532
601
|
*/
|
|
533
602
|
signMiniSession: typeof signMiniSession;
|
|
603
|
+
/**
|
|
604
|
+
* Creates a persistent Zustand store for session management.
|
|
605
|
+
* @see {@link createMiniSessionStore}
|
|
606
|
+
*/
|
|
607
|
+
createMiniSessionStore: typeof createMiniSessionStore;
|
|
608
|
+
/**
|
|
609
|
+
* Reusable helper to manage signing and session caching.
|
|
610
|
+
* @see {@link getMiniSessionAuth}
|
|
611
|
+
*/
|
|
612
|
+
getMiniSessionAuth: typeof getMiniSessionAuth;
|
|
534
613
|
};
|
|
535
614
|
/**
|
|
536
615
|
* The internal HTTP client used for authenticated requests.
|
|
@@ -560,4 +639,4 @@ declare class Quasar {
|
|
|
560
639
|
constructor(config: QuasarConfig);
|
|
561
640
|
}
|
|
562
641
|
|
|
563
|
-
export { BASE_API_URL, type HistoryQuery, PULSAR_HISTORY_ENDPOINT, PULSAR_SYNC_ENDPOINT, type PaginatedResult, PulsarModule, Quasar, type QuasarConfig, QuasarSDKError, type SignSessionParams, type SignSessionResult, type VerifySessionParams, createMiniSessionMessage, signMiniSession, utils, verifyMiniSession };
|
|
642
|
+
export { BASE_API_URL, ChainType, type ConnectionData, type HistoryQuery, type MiniSessionAuth, type MiniSessionStore, PULSAR_HISTORY_ENDPOINT, PULSAR_SYNC_ENDPOINT, type PaginatedResult, PulsarModule, Quasar, type QuasarConfig, QuasarSDKError, type SignSessionParams, type SignSessionResult, type VerifySessionParams, createMiniSessionMessage, createMiniSessionStore, getMiniSessionAuth, signMiniSession, utils, verifyMiniSession };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var ofetch=require('ofetch');var
|
|
2
|
-
exports.BASE_API_URL=
|
|
1
|
+
'use strict';var ofetch=require('ofetch'),zustand=require('zustand'),middleware=require('zustand/middleware');var d="https://api.tuwa.io",p="/v1/engine/pulsar/sync",m="/v1/engine/pulsar/history";var c=class extends Error{status;originalError;constructor(e,r,s){super(e),this.name="QuasarSDKError",this.status=r,this.originalError=s;}},l=class{secretKey;internalSecret;baseUrl;timeout;constructor(e){if(!e.secretKey)throw new Error("[Quasar SDK] Missing API Key. Provide a secretKey starting with sk_live_.");this.secretKey=e.secretKey,this.internalSecret=e.internalSecret,this.baseUrl=e.baseUrl||d,this.timeout=e.timeout||1e4;}async request(e,r={}){try{return await ofetch.ofetch(e,{baseURL:this.baseUrl,timeout:this.timeout,...r,headers:{"Content-Type":"application/json","x-tuwa-secret-key":this.secretKey,...this.internalSecret?{"x-internal-secret":this.internalSecret}:{},...r.headers}})}catch(s){throw this.buildError(s)}}buildError(e){let r=e,s=r.statusCode??r.response?.status,n=(r.data??r.response?._data)?.error??r.message??"Unknown Error";return (s===401||s===403)&&console.error("\u{1F6A8} [Quasar SDK] Auth Error. Check your Secret Key and scopes."),new c(`[Quasar SDK] Request Failed (${s}): ${n}`,s,r)}};var a=class{constructor(e){this.client=e;}async syncCreate(e,r){return this.client.request(p,{method:"POST",body:{...e,appName:r}})}async getHistory(e={}){return this.client.request(m,{method:"GET",query:{page:e.page??1,limit:e.limit??10,chainId:e.chainId,status:e.status,txKey:e.txKey,appName:e.appName,walletAddress:e.walletAddress}})}};var S=(r=>(r.EVM="EVM",r.SOLANA="SOLANA",r))(S||{});var M=300*1e3,x=60*1e3;function u(t){return `Mini-Session Login: ${t}`}async function g(t){let e=new Date().toISOString(),r=u(e);if(t.chainType==="EVM"){if(!t.walletAddress)throw new Error("[SDK] walletAddress is required for EVM signing.");try{return {signature:await t.signer.signMessage({account:t.walletAddress,message:r}),timestamp:e}}catch(s){throw new Error(`[SDK] EVM signing failed: ${s.message}`,{cause:s})}}if(t.chainType==="SOLANA"){let s;try{s=await import('gill');}catch(i){throw new Error('[SDK] Peer dependency "gill" is required for Solana signing.',{cause:i})}try{let n=s.getUtf8Encoder().encode(r),[o]=await t.signer.signMessages([n]);return {signature:s.getSignatureFromBytes(o),timestamp:e}}catch(i){throw new Error(`[SDK] Solana signing failed: ${i.message}`,{cause:i})}}throw new Error(`[SDK] Unsupported chain type: ${t.chainType}`)}async function h(t){let e=new Date(t.timestamp).getTime(),r=Date.now();if(isNaN(e))throw new Error("[SDK] Invalid timestamp format. Use ISO string.");let s=t.maxAge??M;if(r-e>s)throw new Error("[SDK] Signature expired. Please sign a fresh message.");if(e>r+x)throw new Error("[SDK] Timestamp is in the future. Check your system clock.");let i=u(t.timestamp);if(t.chainType==="EVM"){let n;try{n=await import('viem');}catch(o){throw new Error('[SDK] Peer dependency "viem" is required for EVM verification.',{cause:o})}return await n.verifyMessage({address:t.walletAddress,message:i,signature:t.signature})}if(t.chainType==="SOLANA"){let n;try{n=await import('gill');}catch(o){throw new Error('[SDK] Peer dependency "gill" is required for Solana verification.',{cause:o})}try{return await n.verifySignatureForAddress(n.address(t.walletAddress),t.signature,i)}catch{return false}}return false}function y(t="mini-session-storage"){return zustand.create()(middleware.persist(e=>({miniSession:null,setMiniSession:r=>e({miniSession:r}),clearSession:()=>e({miniSession:null})}),{name:t}))}async function f(t,e){if(!t.isConnected||!t.address)throw new Error("Wallet not connected. Please connect your wallet first.");let{address:r,chainType:s,signer:i}=t;if(e.miniSession&&e.miniSession.walletAddress===r&&e.miniSession.chainType===s)return e.miniSession;let o={...await g({signer:i,walletAddress:r,chainType:s}),chainType:s,walletAddress:r};return e.setMiniSession(o),o}var b={createMiniSessionMessage:u,verifyMiniSession:h,signMiniSession:g,createMiniSessionStore:y,getMiniSessionAuth:f},w=class{static utils=b;client;pulsar;constructor(e){this.client=new l(e),this.pulsar=new a(this.client);}};
|
|
2
|
+
exports.BASE_API_URL=d;exports.ChainType=S;exports.PULSAR_HISTORY_ENDPOINT=m;exports.PULSAR_SYNC_ENDPOINT=p;exports.PulsarModule=a;exports.Quasar=w;exports.QuasarSDKError=c;exports.createMiniSessionMessage=u;exports.createMiniSessionStore=y;exports.getMiniSessionAuth=f;exports.signMiniSession=g;exports.utils=b;exports.verifyMiniSession=h;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {ofetch}from'ofetch';var
|
|
2
|
-
export{
|
|
1
|
+
import {ofetch}from'ofetch';import {create}from'zustand';import {persist}from'zustand/middleware';var d="https://api.tuwa.io",p="/v1/engine/pulsar/sync",m="/v1/engine/pulsar/history";var c=class extends Error{status;originalError;constructor(e,r,s){super(e),this.name="QuasarSDKError",this.status=r,this.originalError=s;}},l=class{secretKey;internalSecret;baseUrl;timeout;constructor(e){if(!e.secretKey)throw new Error("[Quasar SDK] Missing API Key. Provide a secretKey starting with sk_live_.");this.secretKey=e.secretKey,this.internalSecret=e.internalSecret,this.baseUrl=e.baseUrl||d,this.timeout=e.timeout||1e4;}async request(e,r={}){try{return await ofetch(e,{baseURL:this.baseUrl,timeout:this.timeout,...r,headers:{"Content-Type":"application/json","x-tuwa-secret-key":this.secretKey,...this.internalSecret?{"x-internal-secret":this.internalSecret}:{},...r.headers}})}catch(s){throw this.buildError(s)}}buildError(e){let r=e,s=r.statusCode??r.response?.status,n=(r.data??r.response?._data)?.error??r.message??"Unknown Error";return (s===401||s===403)&&console.error("\u{1F6A8} [Quasar SDK] Auth Error. Check your Secret Key and scopes."),new c(`[Quasar SDK] Request Failed (${s}): ${n}`,s,r)}};var a=class{constructor(e){this.client=e;}async syncCreate(e,r){return this.client.request(p,{method:"POST",body:{...e,appName:r}})}async getHistory(e={}){return this.client.request(m,{method:"GET",query:{page:e.page??1,limit:e.limit??10,chainId:e.chainId,status:e.status,txKey:e.txKey,appName:e.appName,walletAddress:e.walletAddress}})}};var S=(r=>(r.EVM="EVM",r.SOLANA="SOLANA",r))(S||{});var M=300*1e3,x=60*1e3;function u(t){return `Mini-Session Login: ${t}`}async function g(t){let e=new Date().toISOString(),r=u(e);if(t.chainType==="EVM"){if(!t.walletAddress)throw new Error("[SDK] walletAddress is required for EVM signing.");try{return {signature:await t.signer.signMessage({account:t.walletAddress,message:r}),timestamp:e}}catch(s){throw new Error(`[SDK] EVM signing failed: ${s.message}`,{cause:s})}}if(t.chainType==="SOLANA"){let s;try{s=await import('gill');}catch(i){throw new Error('[SDK] Peer dependency "gill" is required for Solana signing.',{cause:i})}try{let n=s.getUtf8Encoder().encode(r),[o]=await t.signer.signMessages([n]);return {signature:s.getSignatureFromBytes(o),timestamp:e}}catch(i){throw new Error(`[SDK] Solana signing failed: ${i.message}`,{cause:i})}}throw new Error(`[SDK] Unsupported chain type: ${t.chainType}`)}async function h(t){let e=new Date(t.timestamp).getTime(),r=Date.now();if(isNaN(e))throw new Error("[SDK] Invalid timestamp format. Use ISO string.");let s=t.maxAge??M;if(r-e>s)throw new Error("[SDK] Signature expired. Please sign a fresh message.");if(e>r+x)throw new Error("[SDK] Timestamp is in the future. Check your system clock.");let i=u(t.timestamp);if(t.chainType==="EVM"){let n;try{n=await import('viem');}catch(o){throw new Error('[SDK] Peer dependency "viem" is required for EVM verification.',{cause:o})}return await n.verifyMessage({address:t.walletAddress,message:i,signature:t.signature})}if(t.chainType==="SOLANA"){let n;try{n=await import('gill');}catch(o){throw new Error('[SDK] Peer dependency "gill" is required for Solana verification.',{cause:o})}try{return await n.verifySignatureForAddress(n.address(t.walletAddress),t.signature,i)}catch{return false}}return false}function y(t="mini-session-storage"){return create()(persist(e=>({miniSession:null,setMiniSession:r=>e({miniSession:r}),clearSession:()=>e({miniSession:null})}),{name:t}))}async function f(t,e){if(!t.isConnected||!t.address)throw new Error("Wallet not connected. Please connect your wallet first.");let{address:r,chainType:s,signer:i}=t;if(e.miniSession&&e.miniSession.walletAddress===r&&e.miniSession.chainType===s)return e.miniSession;let o={...await g({signer:i,walletAddress:r,chainType:s}),chainType:s,walletAddress:r};return e.setMiniSession(o),o}var b={createMiniSessionMessage:u,verifyMiniSession:h,signMiniSession:g,createMiniSessionStore:y,getMiniSessionAuth:f},w=class{static utils=b;client;pulsar;constructor(e){this.client=new l(e),this.pulsar=new a(this.client);}};
|
|
2
|
+
export{d as BASE_API_URL,S as ChainType,m as PULSAR_HISTORY_ENDPOINT,p as PULSAR_SYNC_ENDPOINT,a as PulsarModule,w as Quasar,c as QuasarSDKError,u as createMiniSessionMessage,y as createMiniSessionStore,f as getMiniSessionAuth,g as signMiniSession,b as utils,h as verifyMiniSession};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/quasar-sdk",
|
|
3
|
-
"version": "1.0.0-fix-docs-alpha.
|
|
3
|
+
"version": "1.0.0-fix-docs-alpha.4.494fbc9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"@tuwaio/pulsar-core": ">=0.6.0",
|
|
40
40
|
"ofetch": ">=1.5.1",
|
|
41
41
|
"viem": "^2.0.0",
|
|
42
|
-
"gill": "^0.14.0"
|
|
42
|
+
"gill": "^0.14.0",
|
|
43
|
+
"zustand": "^5.0.0"
|
|
43
44
|
},
|
|
44
45
|
"peerDependenciesMeta": {
|
|
45
46
|
"viem": {
|
|
@@ -47,6 +48,9 @@
|
|
|
47
48
|
},
|
|
48
49
|
"gill": {
|
|
49
50
|
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"zustand": {
|
|
53
|
+
"optional": true
|
|
50
54
|
}
|
|
51
55
|
},
|
|
52
56
|
"devDependencies": {
|