@tuwaio/quasar-sdk 0.0.3 → 0.0.5
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 +64 -18
- package/dist/chunk-A52BVTJ6.js +1 -0
- package/dist/chunk-DK4D3PU5.mjs +1 -0
- package/dist/index.d.mts +219 -170
- package/dist/index.d.ts +219 -170
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/react.d.mts +78 -0
- package/dist/react.d.ts +78 -0
- package/dist/react.js +1 -0
- package/dist/react.mjs +1 -0
- package/dist/types-Ctaain6g.d.mts +188 -0
- package/dist/types-Ctaain6g.d.ts +188 -0
- package/package.json +53 -5
package/README.md
CHANGED
|
@@ -4,21 +4,28 @@
|
|
|
4
4
|
[](./LICENSE)
|
|
5
5
|
[](https://github.com/TuwaIO/sdk/actions)
|
|
6
6
|
|
|
7
|
-
> The official server-side Node.js & Edge SDK for the **TUWA Quasar Cloud
|
|
7
|
+
> The official server-side Node.js & Edge SDK for the **TUWA Quasar Cloud**, featuring built-in React authentication bridges.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
# Using pnpm (recommended)
|
|
12
|
+
# Using pnpm (recommended)
|
|
13
13
|
pnpm add @tuwaio/quasar-sdk ofetch
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
### Peer Dependencies
|
|
17
17
|
|
|
18
|
-
| Package
|
|
19
|
-
|
|
|
20
|
-
| `@tuwaio/pulsar-core`
|
|
21
|
-
| `ofetch`
|
|
18
|
+
| Package | Version | Requirement |
|
|
19
|
+
| -------------------------- | ---------- | ------------------------------------------ |
|
|
20
|
+
| `@tuwaio/pulsar-core` | `>=0.6.0` | **Required** (Core types) |
|
|
21
|
+
| `ofetch` | `>=1.5.1` | **Required** (Transport) |
|
|
22
|
+
| `react` | `>=18.0.0` | Optional (React Bridge support) |
|
|
23
|
+
| `@solana/react` | `>=6.9.0` | Optional (Solana signing) |
|
|
24
|
+
| `@wallet-standard/react` | `>=1.0.2` | Optional (Wallet Standard) |
|
|
25
|
+
| `@wagmi/core` | `>=3.0.0` | Optional (EVM signing) |
|
|
26
|
+
| `viem` | `^2.0.0` | Optional (EVM Auth primitives) |
|
|
27
|
+
| `gill` | `^0.14.0` | Optional (Solana Auth primitives) |
|
|
28
|
+
| `zustand` | `^5.0.0` | Optional (Session state management) |
|
|
22
29
|
|
|
23
30
|
## Quick Start
|
|
24
31
|
|
|
@@ -27,25 +34,65 @@ import { Quasar } from '@tuwaio/quasar-sdk';
|
|
|
27
34
|
|
|
28
35
|
const quasar = new Quasar({ secretKey: 'sk_live_your_secret_key' });
|
|
29
36
|
|
|
30
|
-
// Sync a pending transaction
|
|
31
|
-
const { txKey } = await quasar.pulsar.syncCreate(
|
|
37
|
+
// Sync a pending transaction to the cloud
|
|
38
|
+
const { txKey } = await quasar.pulsar.syncCreate(transaction, 'My Application');
|
|
32
39
|
|
|
33
|
-
//
|
|
34
|
-
await quasar.pulsar.syncUpdate(txKey, { status: 'confirmed' });
|
|
35
|
-
|
|
36
|
-
// Query history
|
|
40
|
+
// Query transaction history
|
|
37
41
|
const history = await quasar.pulsar.getHistory({ chainId: 1 });
|
|
38
42
|
```
|
|
39
43
|
|
|
44
|
+
## React Authentication Bridge
|
|
45
|
+
|
|
46
|
+
The SDK provides a unified component to handle multi-chain authentication (EVM & Solana) with zero boilerplate.
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import { QuasarAuthBridge } from '@tuwaio/quasar-sdk/react';
|
|
50
|
+
|
|
51
|
+
function MyApp() {
|
|
52
|
+
return (
|
|
53
|
+
<QuasarAuthBridge
|
|
54
|
+
activeConnection={activeConnection} // Structural interface for wallet state
|
|
55
|
+
store={store} // Zustand store API
|
|
56
|
+
wagmiConfig={config} // Wagmi config
|
|
57
|
+
session={miniSession} // Current session state
|
|
58
|
+
setSession={setMiniSession} // Session setter
|
|
59
|
+
/>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
40
64
|
## Modules
|
|
41
65
|
|
|
42
66
|
### Pulsar — `quasar.pulsar`
|
|
43
67
|
|
|
44
|
-
| Method
|
|
45
|
-
|
|
|
46
|
-
| `syncCreate(tx, appName?)`
|
|
47
|
-
| `
|
|
48
|
-
|
|
68
|
+
| Method | Description |
|
|
69
|
+
| -------------------------- | --------------------------------------------------- |
|
|
70
|
+
| `syncCreate(tx, appName?)` | Sync a new pending transaction to the cloud |
|
|
71
|
+
| `getHistory(query?)` | Retrieve paginated transaction history with filters |
|
|
72
|
+
|
|
73
|
+
### Utils — `utils`
|
|
74
|
+
|
|
75
|
+
Security and authentication utilities for signature verification and session management.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { utils, ChainType } from '@tuwaio/quasar-sdk';
|
|
79
|
+
|
|
80
|
+
// Verify a Mini-Session signature on the server
|
|
81
|
+
const isValid = await utils.verifyMiniSession({
|
|
82
|
+
walletAddress: '0x...',
|
|
83
|
+
signature,
|
|
84
|
+
timestamp,
|
|
85
|
+
chainType: ChainType.EVM
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
| Method | Description |
|
|
90
|
+
| ------------------------------ | ------------------------------------------------------ |
|
|
91
|
+
| `createMiniSessionMessage(ts)` | Format a standard login message for signing |
|
|
92
|
+
| `signMiniSession(params)` | Trigger signature request in the connected wallet |
|
|
93
|
+
| `verifyMiniSession(params)` | Verify an EVM or Solana signature with expiration check |
|
|
94
|
+
| `createMiniSessionStore(name)` | Create a persistent Zustand store for session caching |
|
|
95
|
+
| `getMiniSessionAuth(conn, st)` | Core logic for signing and caching a mini-session |
|
|
49
96
|
|
|
50
97
|
## Error Handling
|
|
51
98
|
|
|
@@ -58,7 +105,6 @@ try {
|
|
|
58
105
|
if (err instanceof QuasarSDKError) {
|
|
59
106
|
console.error(err.status); // HTTP status code
|
|
60
107
|
console.error(err.message); // Formatted error message
|
|
61
|
-
console.error(err.originalError); // Raw fetch error
|
|
62
108
|
}
|
|
63
109
|
}
|
|
64
110
|
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var zustand=require('zustand'),middleware=require('zustand/middleware');var d=(a=>(a.EVM="EVM",a.SOLANA="SOLANA",a))(d||{});var S=300*1e3,f=60*1e3;function m(e){return `Mini-Session Login: ${e}`}async function y(e){let t=new Date().toISOString(),a=m(t);if(e.chainType==="EVM"){let n=e.signer;try{return {signature:await n.signMessage({account:e.walletAddress,message:a}),timestamp:t}}catch(s){throw new Error(`[SDK] EVM signing failed: ${s.message}`,{cause:s})}}if(e.chainType==="SOLANA"){let n=e.signer,s;try{s=await import('gill');}catch(r){throw new Error('[SDK] Peer dependency "gill" is required for Solana signing.',{cause:r})}try{let i=s.getUtf8Encoder().encode(a),g;if(n.modifyAndSignMessages){let o=s.createSignableMessage(i),[l]=await n.modifyAndSignMessages([o]),u=l.signatures[n.address];if(!u)throw new Error(`[SDK] Signature missing for address: ${n.address}`);g=u;}else if(n.signMessages){let[o]=await n.signMessages([i]);if(!o?.signature)throw new Error("[SDK] Wallet returned invalid signMessages output.");g=o.signature;}else if(n.signMessage)g=await n.signMessage(i);else throw new Error("[SDK] Signer lacks message signing capabilities.");return {signature:s.getSignatureFromBytes(g),timestamp:t}}catch(r){throw new Error(`[SDK] Solana signing failed: ${r.message}`,{cause:r})}}throw new Error(`[SDK] Unsupported chain type: ${e.chainType}`)}async function P(e){let t=new Date(e.timestamp).getTime(),a=Date.now();if(isNaN(t))throw new Error("[SDK] Invalid timestamp format. Use ISO string.");let n=e.maxAge??S;if(a-t>n)throw new Error("[SDK] Signature expired. Please sign a fresh message.");if(t>a+f)throw new Error("[SDK] Timestamp is in the future. Check your system clock.");let s=m(e.timestamp);if(e.chainType==="EVM"){let r;try{r=await import('viem');}catch(i){throw new Error('[SDK] Peer dependency "viem" is required for EVM verification.',{cause:i})}return await r.verifyMessage({address:e.walletAddress,message:s,signature:e.signature})}if(e.chainType==="SOLANA"){let r;try{r=await import('gill');}catch(i){throw new Error('[SDK] Peer dependency "gill" is required for Solana verification.',{cause:i})}try{let i=r.address(e.walletAddress);return await r.verifySignatureForAddress(i,e.signature,s)}catch{return false}}return false}function k(e="mini-session-storage"){return zustand.create()(middleware.persist(t=>({miniSession:null,setMiniSession:a=>t({miniSession:a}),clearSession:()=>t({miniSession:null})}),{name:e}))}async function C(e,t){let{isConnected:a,address:n,chainType:s,signer:r}=e;if(!a||!n)throw new Error("[SDK] Wallet not connected. Please connect your wallet first.");let i=t.miniSession;if(i&&i.walletAddress===n&&i.chainType===s){let o=Date.now(),l=new Date(i.timestamp).getTime();if(o-l<S)return i}let c={...await y({signer:r,walletAddress:n,chainType:s}),chainType:s,walletAddress:n};return t.setMiniSession(c),c}exports.a=d;exports.b=S;exports.c=m;exports.d=y;exports.e=P;exports.f=k;exports.g=C;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {create}from'zustand';import {persist}from'zustand/middleware';var d=(a=>(a.EVM="EVM",a.SOLANA="SOLANA",a))(d||{});var S=300*1e3,f=60*1e3;function m(e){return `Mini-Session Login: ${e}`}async function y(e){let t=new Date().toISOString(),a=m(t);if(e.chainType==="EVM"){let n=e.signer;try{return {signature:await n.signMessage({account:e.walletAddress,message:a}),timestamp:t}}catch(s){throw new Error(`[SDK] EVM signing failed: ${s.message}`,{cause:s})}}if(e.chainType==="SOLANA"){let n=e.signer,s;try{s=await import('gill');}catch(r){throw new Error('[SDK] Peer dependency "gill" is required for Solana signing.',{cause:r})}try{let i=s.getUtf8Encoder().encode(a),g;if(n.modifyAndSignMessages){let o=s.createSignableMessage(i),[l]=await n.modifyAndSignMessages([o]),u=l.signatures[n.address];if(!u)throw new Error(`[SDK] Signature missing for address: ${n.address}`);g=u;}else if(n.signMessages){let[o]=await n.signMessages([i]);if(!o?.signature)throw new Error("[SDK] Wallet returned invalid signMessages output.");g=o.signature;}else if(n.signMessage)g=await n.signMessage(i);else throw new Error("[SDK] Signer lacks message signing capabilities.");return {signature:s.getSignatureFromBytes(g),timestamp:t}}catch(r){throw new Error(`[SDK] Solana signing failed: ${r.message}`,{cause:r})}}throw new Error(`[SDK] Unsupported chain type: ${e.chainType}`)}async function P(e){let t=new Date(e.timestamp).getTime(),a=Date.now();if(isNaN(t))throw new Error("[SDK] Invalid timestamp format. Use ISO string.");let n=e.maxAge??S;if(a-t>n)throw new Error("[SDK] Signature expired. Please sign a fresh message.");if(t>a+f)throw new Error("[SDK] Timestamp is in the future. Check your system clock.");let s=m(e.timestamp);if(e.chainType==="EVM"){let r;try{r=await import('viem');}catch(i){throw new Error('[SDK] Peer dependency "viem" is required for EVM verification.',{cause:i})}return await r.verifyMessage({address:e.walletAddress,message:s,signature:e.signature})}if(e.chainType==="SOLANA"){let r;try{r=await import('gill');}catch(i){throw new Error('[SDK] Peer dependency "gill" is required for Solana verification.',{cause:i})}try{let i=r.address(e.walletAddress);return await r.verifySignatureForAddress(i,e.signature,s)}catch{return false}}return false}function k(e="mini-session-storage"){return create()(persist(t=>({miniSession:null,setMiniSession:a=>t({miniSession:a}),clearSession:()=>t({miniSession:null})}),{name:e}))}async function C(e,t){let{isConnected:a,address:n,chainType:s,signer:r}=e;if(!a||!n)throw new Error("[SDK] Wallet not connected. Please connect your wallet first.");let i=t.miniSession;if(i&&i.walletAddress===n&&i.chainType===s){let o=Date.now(),l=new Date(i.timestamp).getTime();if(o-l<S)return i}let c={...await y({signer:r,walletAddress:n,chainType:s}),chainType:s,walletAddress:n};return t.setMiniSession(c),c}export{d as a,S as b,m as c,y as d,P as e,k as f,C as g};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,133 +1,10 @@
|
|
|
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-Ctaain6g.mjs';
|
|
3
|
+
export { c as ChainType, E as EvmSigner, d as SolanaSignedMessage, e as SolanaSigner } from './types-Ctaain6g.mjs';
|
|
2
4
|
import { Transaction } from '@tuwaio/pulsar-core';
|
|
3
5
|
export { Transaction, UpdatableTransactionFields } from '@tuwaio/pulsar-core';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @module types
|
|
7
|
-
* @description Shared type definitions for the Quasar SDK.
|
|
8
|
-
* Contains configuration interfaces, query parameters, paginated result structure,
|
|
9
|
-
* and re-exports from `@tuwaio/pulsar-core`.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Configuration options for initializing the {@link Quasar} SDK client.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* const config: QuasarConfig = {
|
|
18
|
-
* secretKey: 'sk_live_abc123...',
|
|
19
|
-
* internalSecret: 'int_secret_abc123...',
|
|
20
|
-
* baseUrl: 'https://api.tuwa.io',
|
|
21
|
-
* timeout: 15000,
|
|
22
|
-
* };
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
interface QuasarConfig {
|
|
26
|
-
/**
|
|
27
|
-
* Your secret API key starting with `sk_live_`.
|
|
28
|
-
*
|
|
29
|
-
* @remarks
|
|
30
|
-
* This key authenticates every request through the Iron Dome security perimeter.
|
|
31
|
-
* It **MUST** be kept secure on the server side — never expose it in client bundles.
|
|
32
|
-
*/
|
|
33
|
-
secretKey: string;
|
|
34
|
-
/**
|
|
35
|
-
* Optional internal secret sent as `x-internal-secret` header on every request.
|
|
36
|
-
*
|
|
37
|
-
* @remarks
|
|
38
|
-
* If provided, the SDK automatically includes it in outgoing requests.
|
|
39
|
-
* If omitted, the header is not added.
|
|
40
|
-
*/
|
|
41
|
-
internalSecret?: string;
|
|
42
|
-
/**
|
|
43
|
-
* The base URL of the Quasar Cloud API.
|
|
44
|
-
*
|
|
45
|
-
* @defaultValue `'https://api.tuwa.io'`
|
|
46
|
-
*/
|
|
47
|
-
baseUrl?: string;
|
|
48
|
-
/**
|
|
49
|
-
* Request timeout in milliseconds.
|
|
50
|
-
*
|
|
51
|
-
* @defaultValue `10000`
|
|
52
|
-
*/
|
|
53
|
-
timeout?: number;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Query parameters for filtering transaction history.
|
|
57
|
-
*
|
|
58
|
-
* All fields are optional — omitted fields apply no filter.
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```typescript
|
|
62
|
-
* const query: HistoryQuery = {
|
|
63
|
-
* page: 2,
|
|
64
|
-
* limit: 25,
|
|
65
|
-
* chainId: 1,
|
|
66
|
-
* status: 'confirmed',
|
|
67
|
-
* };
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
interface HistoryQuery {
|
|
71
|
-
/**
|
|
72
|
-
* Page number for pagination (1-indexed).
|
|
73
|
-
*
|
|
74
|
-
* @defaultValue `1`
|
|
75
|
-
*/
|
|
76
|
-
page?: number;
|
|
77
|
-
/**
|
|
78
|
-
* Maximum number of results per page.
|
|
79
|
-
*
|
|
80
|
-
* @defaultValue `10`
|
|
81
|
-
*/
|
|
82
|
-
limit?: number;
|
|
83
|
-
/**
|
|
84
|
-
* Filter by blockchain chain ID (e.g. `1` for Ethereum Mainnet, `'solana'` for Solana).
|
|
85
|
-
*/
|
|
86
|
-
chainId?: string | number;
|
|
87
|
-
/**
|
|
88
|
-
* Filter by transaction status (e.g. `'pending'`, `'confirmed'`, `'failed'`).
|
|
89
|
-
*/
|
|
90
|
-
status?: string;
|
|
91
|
-
/**
|
|
92
|
-
* Filter by a specific transaction key (unique identifier assigned by Quasar).
|
|
93
|
-
*/
|
|
94
|
-
txKey?: string;
|
|
95
|
-
/**
|
|
96
|
-
* Filter by a specific app name.
|
|
97
|
-
*/
|
|
98
|
-
appName?: string;
|
|
99
|
-
/**
|
|
100
|
-
* Filter by a specific wallet address.
|
|
101
|
-
*/
|
|
102
|
-
walletAddress?: string;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Generic wrapper for paginated API responses.
|
|
106
|
-
*
|
|
107
|
-
* @typeParam T - The type of each document in the result set.
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```typescript
|
|
111
|
-
* const result: PaginatedResult<Transaction> = await quasar.pulsar.getHistory();
|
|
112
|
-
* console.log(result.docs); // Transaction[]
|
|
113
|
-
* console.log(result.totalPages); // number
|
|
114
|
-
* console.log(result.hasNextPage); // boolean
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
interface PaginatedResult<T> {
|
|
118
|
-
/** Array of documents for the current page. */
|
|
119
|
-
docs: T[];
|
|
120
|
-
/** Total number of documents matching the query across all pages. */
|
|
121
|
-
totalDocs: number;
|
|
122
|
-
/** Total number of available pages. */
|
|
123
|
-
totalPages: number;
|
|
124
|
-
/** Current page number (1-indexed). */
|
|
125
|
-
page: number;
|
|
126
|
-
/** Whether a subsequent page exists. */
|
|
127
|
-
hasNextPage: boolean;
|
|
128
|
-
/** Whether a previous page exists. */
|
|
129
|
-
hasPrevPage: boolean;
|
|
130
|
-
}
|
|
6
|
+
import * as zustand_middleware from 'zustand/middleware';
|
|
7
|
+
import * as zustand from 'zustand';
|
|
131
8
|
|
|
132
9
|
/**
|
|
133
10
|
* @module core/client
|
|
@@ -235,25 +112,26 @@ declare class QuasarClient {
|
|
|
235
112
|
/**
|
|
236
113
|
* Pulsar module — the transaction engine interface for Quasar Cloud.
|
|
237
114
|
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
115
|
+
* The `PulsarModule` handles the lifecycle of blockchain transactions within the Quasar ecosystem.
|
|
116
|
+
* It allows developers to sync transaction states (EVM, Solana, Starknet) to the cloud for
|
|
117
|
+
* persistent tracking and to retrieve comprehensive transaction histories.
|
|
240
118
|
*
|
|
241
119
|
* @remarks
|
|
242
|
-
* Access this module via `quasar.pulsar` after initializing the SDK.
|
|
243
|
-
* All methods
|
|
120
|
+
* Access this module via `quasar.pulsar` after initializing the {@link Quasar} SDK.
|
|
121
|
+
* All methods are authenticated automatically using the configured secret key.
|
|
244
122
|
*
|
|
245
123
|
* @example
|
|
246
124
|
* ```typescript
|
|
247
125
|
* const quasar = new Quasar({ secretKey: 'sk_live_...' });
|
|
248
126
|
*
|
|
249
|
-
* //
|
|
127
|
+
* // Sync a new transaction to start tracking
|
|
250
128
|
* const { txKey } = await quasar.pulsar.syncCreate(transaction);
|
|
251
129
|
*
|
|
252
|
-
* //
|
|
253
|
-
* await quasar.pulsar.
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
130
|
+
* // Retrieve transaction history with filters
|
|
131
|
+
* const history = await quasar.pulsar.getHistory({
|
|
132
|
+
* chainId: 1,
|
|
133
|
+
* status: 'Success',
|
|
134
|
+
* });
|
|
257
135
|
* ```
|
|
258
136
|
*/
|
|
259
137
|
declare class PulsarModule {
|
|
@@ -266,25 +144,28 @@ declare class PulsarModule {
|
|
|
266
144
|
*/
|
|
267
145
|
constructor(client: QuasarClient);
|
|
268
146
|
/**
|
|
269
|
-
* Syncs a newly created pending transaction to the Quasar Cloud.
|
|
147
|
+
* Syncs a newly created or pending transaction to the Quasar Cloud.
|
|
270
148
|
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
149
|
+
* This method sends the full transaction object to the Pulsar sync engine.
|
|
150
|
+
* Once synced, the transaction is indexed and tracked through the Iron Dome infrastructure.
|
|
273
151
|
*
|
|
274
|
-
* @param tx - The complete transaction object to sync.
|
|
275
|
-
* @param appName -
|
|
276
|
-
* @returns
|
|
277
|
-
* @throws {QuasarSDKError}
|
|
152
|
+
* @param tx - The complete transaction object to sync. Must conform to the {@link Transaction} type.
|
|
153
|
+
* @param appName - Optional application name to associate with this transaction for filtering purposes.
|
|
154
|
+
* @returns A promise that resolves to an object containing the assigned `txKey`.
|
|
155
|
+
* @throws {QuasarSDKError} If the request fails due to authentication, validation, or network issues.
|
|
278
156
|
*
|
|
279
157
|
* @example
|
|
280
158
|
* ```typescript
|
|
281
|
-
* const
|
|
159
|
+
* const result = await quasar.pulsar.syncCreate({
|
|
282
160
|
* hash: '0xabc...',
|
|
283
161
|
* chainId: 1,
|
|
284
162
|
* status: 'pending',
|
|
285
163
|
* from: '0x123...',
|
|
286
164
|
* to: '0x456...',
|
|
287
|
-
*
|
|
165
|
+
* // ... other transaction fields
|
|
166
|
+
* }, 'My Dashboard');
|
|
167
|
+
*
|
|
168
|
+
* console.log(result.txKey); // The unique key for this transaction
|
|
288
169
|
* ```
|
|
289
170
|
*/
|
|
290
171
|
syncCreate(tx: Transaction, appName?: string): Promise<{
|
|
@@ -292,32 +173,122 @@ declare class PulsarModule {
|
|
|
292
173
|
txKey: string;
|
|
293
174
|
}>;
|
|
294
175
|
/**
|
|
295
|
-
* Retrieves paginated
|
|
176
|
+
* Retrieves a paginated list of transactions from the Quasar Cloud.
|
|
296
177
|
*
|
|
297
|
-
* Supports filtering by chain
|
|
298
|
-
*
|
|
178
|
+
* Supports advanced filtering by chain, status, wallet address, and more.
|
|
179
|
+
* Results are returned in a typed {@link PaginatedResult} wrapper.
|
|
299
180
|
*
|
|
300
|
-
* @param query - Optional query parameters for filtering and pagination.
|
|
301
|
-
* @returns A
|
|
302
|
-
* @throws {QuasarSDKError}
|
|
181
|
+
* @param query - Optional query parameters for filtering and pagination. See {@link HistoryQuery}.
|
|
182
|
+
* @returns A promise that resolves to a {@link PaginatedResult} containing an array of {@link Transaction} documents.
|
|
183
|
+
* @throws {QuasarSDKError} If the request fails (e.g., 401 Unauthorized, 404 Not Found).
|
|
303
184
|
*
|
|
304
185
|
* @example
|
|
305
186
|
* ```typescript
|
|
306
187
|
* const result = await quasar.pulsar.getHistory({
|
|
307
188
|
* page: 1,
|
|
308
189
|
* limit: 20,
|
|
309
|
-
*
|
|
310
|
-
* status: 'confirmed',
|
|
190
|
+
* walletAddress: '6x...',
|
|
311
191
|
* });
|
|
312
192
|
*
|
|
313
|
-
*
|
|
314
|
-
* console.log(tx.hash, tx.status);
|
|
315
|
-
* }
|
|
193
|
+
* result.docs.forEach(tx => console.log(tx.txKey, tx.status));
|
|
316
194
|
* ```
|
|
317
195
|
*/
|
|
318
196
|
getHistory(query?: HistoryQuery): Promise<PaginatedResult<Transaction>>;
|
|
319
197
|
}
|
|
320
198
|
|
|
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
|
+
* Standardizes the message format for Mini-Session authentication.
|
|
213
|
+
* Both frontend and backend MUST use this exact template for verification to pass.
|
|
214
|
+
*
|
|
215
|
+
* @param timestamp - ISO string timestamp (e.g., `new Date().toISOString()`).
|
|
216
|
+
* @returns The formatted message string to be signed.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const msg = createMiniSessionMessage(new Date().toISOString());
|
|
221
|
+
* // msg -> "Mini-Session Login: 2026-05-13T10:00:00.000Z"
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
declare function createMiniSessionMessage(timestamp: string): string;
|
|
225
|
+
/**
|
|
226
|
+
* Triggers a signature request in the connected wallet to create a Mini-Session.
|
|
227
|
+
*
|
|
228
|
+
* This function detects the signer's capabilities and uses the most appropriate
|
|
229
|
+
* signing method available (e.g., Web3 v2, Standard, or Legacy).
|
|
230
|
+
*
|
|
231
|
+
* @param params - Parameters containing the signer and target ecosystem.
|
|
232
|
+
* @returns A promise resolving to the signature and timestamp.
|
|
233
|
+
* @throws {Error} If signing fails or the signer lacks required methods.
|
|
234
|
+
*
|
|
235
|
+
* @public
|
|
236
|
+
*/
|
|
237
|
+
declare function signMiniSession(params: SignSessionParams): Promise<SignSessionResult>;
|
|
238
|
+
/**
|
|
239
|
+
* Verifies a Mini-Session signature for authenticity and freshness.
|
|
240
|
+
*
|
|
241
|
+
* Performs cryptographic verification against the provided wallet address and
|
|
242
|
+
* ensures the signature hasn't expired according to the `maxAge` parameter.
|
|
243
|
+
*
|
|
244
|
+
* @param params - Verification data including signature and timestamp.
|
|
245
|
+
* @returns A promise resolving to true if the session is valid.
|
|
246
|
+
*
|
|
247
|
+
* @public
|
|
248
|
+
*/
|
|
249
|
+
declare function verifyMiniSession(params: VerifySessionParams): Promise<boolean>;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Creates a persistent Zustand store to cache Mini-Session signatures.
|
|
253
|
+
* This is the recommended way to manage sessions in React applications.
|
|
254
|
+
*
|
|
255
|
+
* @param storageName - The localStorage key for persistence. Defaults to 'mini-session-storage'.
|
|
256
|
+
* @returns A Zustand store instance initialized with MiniSessionStore interface.
|
|
257
|
+
*
|
|
258
|
+
* @public
|
|
259
|
+
*/
|
|
260
|
+
declare function createMiniSessionStore(storageName?: string): zustand.UseBoundStore<Omit<zustand.StoreApi<MiniSessionStore>, "setState" | "persist"> & {
|
|
261
|
+
setState(partial: MiniSessionStore | Partial<MiniSessionStore> | ((state: MiniSessionStore) => MiniSessionStore | Partial<MiniSessionStore>), replace?: false | undefined): unknown;
|
|
262
|
+
setState(state: MiniSessionStore | ((state: MiniSessionStore) => MiniSessionStore), replace: true): unknown;
|
|
263
|
+
persist: {
|
|
264
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<MiniSessionStore, MiniSessionStore, unknown>>) => void;
|
|
265
|
+
clearStorage: () => void;
|
|
266
|
+
rehydrate: () => Promise<void> | void;
|
|
267
|
+
hasHydrated: () => boolean;
|
|
268
|
+
onHydrate: (fn: (state: MiniSessionStore) => void) => () => void;
|
|
269
|
+
onFinishHydration: (fn: (state: MiniSessionStore) => void) => () => void;
|
|
270
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<MiniSessionStore, MiniSessionStore, unknown>>;
|
|
271
|
+
};
|
|
272
|
+
}>;
|
|
273
|
+
/**
|
|
274
|
+
* High-level orchestrator to retrieve an existing Mini-Session or trigger a new signature.
|
|
275
|
+
*
|
|
276
|
+
* This function checks the provided store for a valid, non-expired session matching
|
|
277
|
+
* the current wallet connection. If no session is found or it has expired, it
|
|
278
|
+
* triggers a signature request through the wallet.
|
|
279
|
+
*
|
|
280
|
+
* @param connection - The current active wallet connection data (address, signer, etc).
|
|
281
|
+
* @param store - A store implementation (Zustand or compatible) for session persistence.
|
|
282
|
+
* @returns A promise resolving to a valid MiniSessionAuth object.
|
|
283
|
+
* @throws {Error} If the wallet is disconnected or signing fails.
|
|
284
|
+
*
|
|
285
|
+
* @public
|
|
286
|
+
*/
|
|
287
|
+
declare function getMiniSessionAuth(connection: ConnectionData, store: {
|
|
288
|
+
miniSession: MiniSessionAuth | null;
|
|
289
|
+
setMiniSession: (session: MiniSessionAuth | null) => void;
|
|
290
|
+
}): Promise<MiniSessionAuth>;
|
|
291
|
+
|
|
321
292
|
declare const BASE_API_URL = "https://api.tuwa.io";
|
|
322
293
|
declare const PULSAR_SYNC_ENDPOINT = "/v1/engine/pulsar/sync";
|
|
323
294
|
declare const PULSAR_HISTORY_ENDPOINT = "/v1/engine/pulsar/history";
|
|
@@ -341,45 +312,123 @@ declare const PULSAR_HISTORY_ENDPOINT = "/v1/engine/pulsar/history";
|
|
|
341
312
|
* @packageDocumentation
|
|
342
313
|
*/
|
|
343
314
|
|
|
315
|
+
/**
|
|
316
|
+
* Security and authentication utilities.
|
|
317
|
+
*
|
|
318
|
+
* Includes methods for creating, signing, and verifying Mini-Session signatures
|
|
319
|
+
* to protect your API quota. These can be used without initializing the Quasar class.
|
|
320
|
+
*
|
|
321
|
+
* @public
|
|
322
|
+
*/
|
|
323
|
+
declare const utils: {
|
|
324
|
+
/**
|
|
325
|
+
* Standardizes the message format for Quasar Mini-Session login.
|
|
326
|
+
* @see {@link createMiniSessionMessage}
|
|
327
|
+
*/
|
|
328
|
+
createMiniSessionMessage: typeof createMiniSessionMessage;
|
|
329
|
+
/**
|
|
330
|
+
* Verifies a Mini-Session signature (EVM or Solana).
|
|
331
|
+
* @see {@link verifyMiniSession}
|
|
332
|
+
*/
|
|
333
|
+
verifyMiniSession: typeof verifyMiniSession;
|
|
334
|
+
/**
|
|
335
|
+
* Triggers a signature request in the connected wallet.
|
|
336
|
+
* @see {@link signMiniSession}
|
|
337
|
+
*/
|
|
338
|
+
signMiniSession: typeof signMiniSession;
|
|
339
|
+
/**
|
|
340
|
+
* Creates a persistent Zustand store for session management.
|
|
341
|
+
* @see {@link createMiniSessionStore}
|
|
342
|
+
*/
|
|
343
|
+
createMiniSessionStore: typeof createMiniSessionStore;
|
|
344
|
+
/**
|
|
345
|
+
* Reusable helper to manage signing and session caching.
|
|
346
|
+
* @see {@link getMiniSessionAuth}
|
|
347
|
+
*/
|
|
348
|
+
getMiniSessionAuth: typeof getMiniSessionAuth;
|
|
349
|
+
};
|
|
344
350
|
/**
|
|
345
351
|
* Main entry point for the Quasar SDK.
|
|
346
352
|
*
|
|
347
|
-
*
|
|
348
|
-
* and exposes domain-specific modules
|
|
353
|
+
* The `Quasar` class provides a unified interface for interacting with the Quasar Cloud API.
|
|
354
|
+
* It handles authentication, base URL configuration, and exposes domain-specific modules
|
|
355
|
+
* like {@link PulsarModule} for transaction management.
|
|
349
356
|
*
|
|
350
357
|
* @example
|
|
351
358
|
* ```typescript
|
|
352
359
|
* import { Quasar } from '@tuwaio/quasar-sdk';
|
|
353
360
|
*
|
|
361
|
+
* // Initialize with your secret API key
|
|
354
362
|
* const quasar = new Quasar({
|
|
355
363
|
* secretKey: 'sk_live_your_secret_key',
|
|
356
|
-
* baseUrl: 'https://api.tuwa.io',
|
|
357
|
-
* timeout:
|
|
364
|
+
* baseUrl: 'https://api.tuwa.io', // Optional
|
|
365
|
+
* timeout: 10000, // Optional, default is 10s
|
|
358
366
|
* });
|
|
359
367
|
*
|
|
360
|
-
* // Access
|
|
361
|
-
* const
|
|
368
|
+
* // Access domain-specific modules
|
|
369
|
+
* const history = await quasar.pulsar.getHistory({ chainId: 1 });
|
|
362
370
|
* ```
|
|
371
|
+
*
|
|
372
|
+
* @public
|
|
363
373
|
*/
|
|
364
374
|
declare class Quasar {
|
|
365
|
-
/**
|
|
375
|
+
/**
|
|
376
|
+
* Security and authentication utilities.
|
|
377
|
+
* Shared across all instances and available statically.
|
|
378
|
+
*/
|
|
379
|
+
static readonly utils: {
|
|
380
|
+
/**
|
|
381
|
+
* Standardizes the message format for Quasar Mini-Session login.
|
|
382
|
+
* @see {@link createMiniSessionMessage}
|
|
383
|
+
*/
|
|
384
|
+
createMiniSessionMessage: typeof createMiniSessionMessage;
|
|
385
|
+
/**
|
|
386
|
+
* Verifies a Mini-Session signature (EVM or Solana).
|
|
387
|
+
* @see {@link verifyMiniSession}
|
|
388
|
+
*/
|
|
389
|
+
verifyMiniSession: typeof verifyMiniSession;
|
|
390
|
+
/**
|
|
391
|
+
* Triggers a signature request in the connected wallet.
|
|
392
|
+
* @see {@link signMiniSession}
|
|
393
|
+
*/
|
|
394
|
+
signMiniSession: typeof signMiniSession;
|
|
395
|
+
/**
|
|
396
|
+
* Creates a persistent Zustand store for session management.
|
|
397
|
+
* @see {@link createMiniSessionStore}
|
|
398
|
+
*/
|
|
399
|
+
createMiniSessionStore: typeof createMiniSessionStore;
|
|
400
|
+
/**
|
|
401
|
+
* Reusable helper to manage signing and session caching.
|
|
402
|
+
* @see {@link getMiniSessionAuth}
|
|
403
|
+
*/
|
|
404
|
+
getMiniSessionAuth: typeof getMiniSessionAuth;
|
|
405
|
+
};
|
|
406
|
+
/**
|
|
407
|
+
* The internal HTTP client used for authenticated requests.
|
|
408
|
+
* @internal
|
|
409
|
+
*/
|
|
366
410
|
private readonly client;
|
|
367
411
|
/**
|
|
368
412
|
* The Pulsar Transaction Engine module.
|
|
369
413
|
*
|
|
370
|
-
*
|
|
371
|
-
* and retrieve
|
|
414
|
+
* This module provides methods to sync transaction states to the Quasar Cloud
|
|
415
|
+
* and retrieve indexed transaction history across multiple blockchain networks.
|
|
372
416
|
*
|
|
373
417
|
* @see {@link PulsarModule}
|
|
374
418
|
*/
|
|
375
419
|
readonly pulsar: PulsarModule;
|
|
376
420
|
/**
|
|
377
|
-
* Creates a new Quasar SDK
|
|
421
|
+
* Creates a new instance of the Quasar SDK.
|
|
422
|
+
*
|
|
423
|
+
* @param config - Configuration options for the SDK.
|
|
424
|
+
* @throws {Error} If the `secretKey` is missing or invalid.
|
|
378
425
|
*
|
|
379
|
-
* @
|
|
380
|
-
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```typescript
|
|
428
|
+
* const quasar = new Quasar({ secretKey: process.env.QUASAR_SECRET_KEY! });
|
|
429
|
+
* ```
|
|
381
430
|
*/
|
|
382
431
|
constructor(config: QuasarConfig);
|
|
383
432
|
}
|
|
384
433
|
|
|
385
|
-
export { BASE_API_URL,
|
|
434
|
+
export { BASE_API_URL, ConnectionData, DEFAULT_MAX_AGE, HistoryQuery, MiniSessionAuth, MiniSessionStore, PULSAR_HISTORY_ENDPOINT, PULSAR_SYNC_ENDPOINT, PaginatedResult, PulsarModule, Quasar, QuasarConfig, QuasarSDKError, SignSessionParams, SignSessionResult, VerifySessionParams, createMiniSessionMessage, createMiniSessionStore, getMiniSessionAuth, signMiniSession, utils, verifyMiniSession };
|