@tuwaio/quasar-sdk 1.0.0-fix-docs-alpha.2.908b7c0 → 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 -55
- package/dist/index.d.ts +139 -55
- 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,21 +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
|
-
/**
|
|
348
|
-
* Standardizes the message format for Quasar Mini-Session login.
|
|
413
|
+
* Standardizes the message format for Mini-Session login.
|
|
349
414
|
* Both frontend and backend must use this exact template.
|
|
350
415
|
*
|
|
351
416
|
* @param timestamp - ISO string timestamp (e.g., `new Date().toISOString()`).
|
|
@@ -354,21 +419,10 @@ interface VerifySessionParams {
|
|
|
354
419
|
* @example
|
|
355
420
|
* ```typescript
|
|
356
421
|
* const msg = createMiniSessionMessage(new Date().toISOString());
|
|
357
|
-
* // msg -> "
|
|
422
|
+
* // msg -> "Mini-Session Login: 2026-05-13T10:00:00.000Z"
|
|
358
423
|
* ```
|
|
359
424
|
*/
|
|
360
425
|
declare function createMiniSessionMessage(timestamp: string): string;
|
|
361
|
-
/**
|
|
362
|
-
* Parameters for signing a mini-session message.
|
|
363
|
-
*/
|
|
364
|
-
interface SignSessionParams {
|
|
365
|
-
/** The signer object. For EVM, a `WalletClient`. For Solana, a `KeyPairSigner` or `TransactionSendingSigner`. */
|
|
366
|
-
signer: any;
|
|
367
|
-
/** The wallet address to sign with (required for EVM). */
|
|
368
|
-
walletAddress?: string;
|
|
369
|
-
/** The blockchain ecosystem type. */
|
|
370
|
-
chainType: 'evm' | 'solana';
|
|
371
|
-
}
|
|
372
426
|
/**
|
|
373
427
|
* Result of a mini-session signing operation.
|
|
374
428
|
*/
|
|
@@ -383,29 +437,13 @@ interface SignSessionResult {
|
|
|
383
437
|
*
|
|
384
438
|
* This is a frontend-friendly helper that:
|
|
385
439
|
* 1. Generates a fresh ISO timestamp.
|
|
386
|
-
* 2. Formats the standard
|
|
440
|
+
* 2. Formats the standard login message.
|
|
387
441
|
* 3. Triggers the wallet's signMessage method.
|
|
388
442
|
* 4. Returns the signature and timestamp for verification on the backend.
|
|
389
443
|
*
|
|
390
444
|
* @param params - The signing parameters including the signer and ecosystem type.
|
|
391
445
|
* @returns A promise that resolves to the signature and timestamp.
|
|
392
446
|
* @throws {Error} If the required peer dependencies are missing or signing fails.
|
|
393
|
-
*
|
|
394
|
-
* @example
|
|
395
|
-
* ```typescript
|
|
396
|
-
* // EVM (viem)
|
|
397
|
-
* const { signature, timestamp } = await signMiniSession({
|
|
398
|
-
* signer: walletClient,
|
|
399
|
-
* walletAddress: '0x...',
|
|
400
|
-
* chainType: 'evm',
|
|
401
|
-
* });
|
|
402
|
-
*
|
|
403
|
-
* // Solana (gill)
|
|
404
|
-
* const { signature, timestamp } = await signMiniSession({
|
|
405
|
-
* signer: keypairSigner,
|
|
406
|
-
* chainType: 'solana',
|
|
407
|
-
* });
|
|
408
|
-
* ```
|
|
409
447
|
*/
|
|
410
448
|
declare function signMiniSession(params: SignSessionParams): Promise<SignSessionResult>;
|
|
411
449
|
/**
|
|
@@ -414,25 +452,51 @@ declare function signMiniSession(params: SignSessionParams): Promise<SignSession
|
|
|
414
452
|
* This utility performs three checks:
|
|
415
453
|
* 1. Timestamp freshness (rejects if older than 5 minutes or in the future).
|
|
416
454
|
* 2. Cryptographic validity (checks if the signature matches the wallet address and message).
|
|
417
|
-
* 3.
|
|
455
|
+
* 3. Ecosystem-specific logic (EVM via `viem`, Solana via `gill`).
|
|
418
456
|
*
|
|
419
457
|
* @param params - The verification parameters including address, signature, and timestamp.
|
|
420
458
|
* @returns A promise that resolves to `true` if the signature is valid and fresh.
|
|
421
459
|
* @throws {Error} If the required peer dependencies (`viem` or `gill`) are missing.
|
|
422
460
|
* @throws {Error} If the timestamp is invalid or expired.
|
|
423
|
-
*
|
|
424
|
-
* @example
|
|
425
|
-
* ```typescript
|
|
426
|
-
* const isValid = await verifyMiniSession({
|
|
427
|
-
* walletAddress: '0x...',
|
|
428
|
-
* timestamp: '2026-05-13T10:00:00.000Z',
|
|
429
|
-
* signature: '0x...',
|
|
430
|
-
* chainType: 'evm',
|
|
431
|
-
* });
|
|
432
|
-
* ```
|
|
433
461
|
*/
|
|
434
462
|
declare function verifyMiniSession(params: VerifySessionParams): Promise<boolean>;
|
|
435
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
|
+
|
|
436
500
|
declare const BASE_API_URL = "https://api.tuwa.io";
|
|
437
501
|
declare const PULSAR_SYNC_ENDPOINT = "/v1/engine/pulsar/sync";
|
|
438
502
|
declare const PULSAR_HISTORY_ENDPOINT = "/v1/engine/pulsar/history";
|
|
@@ -480,6 +544,16 @@ declare const utils: {
|
|
|
480
544
|
* @see {@link signMiniSession}
|
|
481
545
|
*/
|
|
482
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;
|
|
483
557
|
};
|
|
484
558
|
/**
|
|
485
559
|
* Main entry point for the Quasar SDK.
|
|
@@ -526,6 +600,16 @@ declare class Quasar {
|
|
|
526
600
|
* @see {@link signMiniSession}
|
|
527
601
|
*/
|
|
528
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;
|
|
529
613
|
};
|
|
530
614
|
/**
|
|
531
615
|
* The internal HTTP client used for authenticated requests.
|
|
@@ -555,4 +639,4 @@ declare class Quasar {
|
|
|
555
639
|
constructor(config: QuasarConfig);
|
|
556
640
|
}
|
|
557
641
|
|
|
558
|
-
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,21 +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
|
-
/**
|
|
348
|
-
* Standardizes the message format for Quasar Mini-Session login.
|
|
413
|
+
* Standardizes the message format for Mini-Session login.
|
|
349
414
|
* Both frontend and backend must use this exact template.
|
|
350
415
|
*
|
|
351
416
|
* @param timestamp - ISO string timestamp (e.g., `new Date().toISOString()`).
|
|
@@ -354,21 +419,10 @@ interface VerifySessionParams {
|
|
|
354
419
|
* @example
|
|
355
420
|
* ```typescript
|
|
356
421
|
* const msg = createMiniSessionMessage(new Date().toISOString());
|
|
357
|
-
* // msg -> "
|
|
422
|
+
* // msg -> "Mini-Session Login: 2026-05-13T10:00:00.000Z"
|
|
358
423
|
* ```
|
|
359
424
|
*/
|
|
360
425
|
declare function createMiniSessionMessage(timestamp: string): string;
|
|
361
|
-
/**
|
|
362
|
-
* Parameters for signing a mini-session message.
|
|
363
|
-
*/
|
|
364
|
-
interface SignSessionParams {
|
|
365
|
-
/** The signer object. For EVM, a `WalletClient`. For Solana, a `KeyPairSigner` or `TransactionSendingSigner`. */
|
|
366
|
-
signer: any;
|
|
367
|
-
/** The wallet address to sign with (required for EVM). */
|
|
368
|
-
walletAddress?: string;
|
|
369
|
-
/** The blockchain ecosystem type. */
|
|
370
|
-
chainType: 'evm' | 'solana';
|
|
371
|
-
}
|
|
372
426
|
/**
|
|
373
427
|
* Result of a mini-session signing operation.
|
|
374
428
|
*/
|
|
@@ -383,29 +437,13 @@ interface SignSessionResult {
|
|
|
383
437
|
*
|
|
384
438
|
* This is a frontend-friendly helper that:
|
|
385
439
|
* 1. Generates a fresh ISO timestamp.
|
|
386
|
-
* 2. Formats the standard
|
|
440
|
+
* 2. Formats the standard login message.
|
|
387
441
|
* 3. Triggers the wallet's signMessage method.
|
|
388
442
|
* 4. Returns the signature and timestamp for verification on the backend.
|
|
389
443
|
*
|
|
390
444
|
* @param params - The signing parameters including the signer and ecosystem type.
|
|
391
445
|
* @returns A promise that resolves to the signature and timestamp.
|
|
392
446
|
* @throws {Error} If the required peer dependencies are missing or signing fails.
|
|
393
|
-
*
|
|
394
|
-
* @example
|
|
395
|
-
* ```typescript
|
|
396
|
-
* // EVM (viem)
|
|
397
|
-
* const { signature, timestamp } = await signMiniSession({
|
|
398
|
-
* signer: walletClient,
|
|
399
|
-
* walletAddress: '0x...',
|
|
400
|
-
* chainType: 'evm',
|
|
401
|
-
* });
|
|
402
|
-
*
|
|
403
|
-
* // Solana (gill)
|
|
404
|
-
* const { signature, timestamp } = await signMiniSession({
|
|
405
|
-
* signer: keypairSigner,
|
|
406
|
-
* chainType: 'solana',
|
|
407
|
-
* });
|
|
408
|
-
* ```
|
|
409
447
|
*/
|
|
410
448
|
declare function signMiniSession(params: SignSessionParams): Promise<SignSessionResult>;
|
|
411
449
|
/**
|
|
@@ -414,25 +452,51 @@ declare function signMiniSession(params: SignSessionParams): Promise<SignSession
|
|
|
414
452
|
* This utility performs three checks:
|
|
415
453
|
* 1. Timestamp freshness (rejects if older than 5 minutes or in the future).
|
|
416
454
|
* 2. Cryptographic validity (checks if the signature matches the wallet address and message).
|
|
417
|
-
* 3.
|
|
455
|
+
* 3. Ecosystem-specific logic (EVM via `viem`, Solana via `gill`).
|
|
418
456
|
*
|
|
419
457
|
* @param params - The verification parameters including address, signature, and timestamp.
|
|
420
458
|
* @returns A promise that resolves to `true` if the signature is valid and fresh.
|
|
421
459
|
* @throws {Error} If the required peer dependencies (`viem` or `gill`) are missing.
|
|
422
460
|
* @throws {Error} If the timestamp is invalid or expired.
|
|
423
|
-
*
|
|
424
|
-
* @example
|
|
425
|
-
* ```typescript
|
|
426
|
-
* const isValid = await verifyMiniSession({
|
|
427
|
-
* walletAddress: '0x...',
|
|
428
|
-
* timestamp: '2026-05-13T10:00:00.000Z',
|
|
429
|
-
* signature: '0x...',
|
|
430
|
-
* chainType: 'evm',
|
|
431
|
-
* });
|
|
432
|
-
* ```
|
|
433
461
|
*/
|
|
434
462
|
declare function verifyMiniSession(params: VerifySessionParams): Promise<boolean>;
|
|
435
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
|
+
|
|
436
500
|
declare const BASE_API_URL = "https://api.tuwa.io";
|
|
437
501
|
declare const PULSAR_SYNC_ENDPOINT = "/v1/engine/pulsar/sync";
|
|
438
502
|
declare const PULSAR_HISTORY_ENDPOINT = "/v1/engine/pulsar/history";
|
|
@@ -480,6 +544,16 @@ declare const utils: {
|
|
|
480
544
|
* @see {@link signMiniSession}
|
|
481
545
|
*/
|
|
482
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;
|
|
483
557
|
};
|
|
484
558
|
/**
|
|
485
559
|
* Main entry point for the Quasar SDK.
|
|
@@ -526,6 +600,16 @@ declare class Quasar {
|
|
|
526
600
|
* @see {@link signMiniSession}
|
|
527
601
|
*/
|
|
528
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;
|
|
529
613
|
};
|
|
530
614
|
/**
|
|
531
615
|
* The internal HTTP client used for authenticated requests.
|
|
@@ -555,4 +639,4 @@ declare class Quasar {
|
|
|
555
639
|
constructor(config: QuasarConfig);
|
|
556
640
|
}
|
|
557
641
|
|
|
558
|
-
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": {
|