@tuwaio/quasar-sdk 0.0.4 → 0.0.6

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/react.js ADDED
@@ -0,0 +1 @@
1
+ 'use strict';var chunkA52BVTJ6_js=require('./chunk-A52BVTJ6.js'),react$1=require('@solana/react'),core=require('@wagmi/core'),react=require('react'),jsxRuntime=require('react/jsx-runtime');var s=null;async function P(){for(let n=0;n<15;n++){if(s)return s();await new Promise(t=>setTimeout(t,200));}throw new Error("[QuasarSDK] Auth helper not initialized. Ensure QuasarAuthBridge is mounted and wallet is connected.")}function k({activeConnection:n,store:t,wagmiConfig:r,session:i,setSession:e,onAddressMismatch:a}){let o=typeof n?.chainId=="string"?"SOLANA":"EVM";return react.useEffect(()=>{i&&n?.address&&i.walletAddress!==n.address&&(console.log("[QuasarSDK] Address mismatch detected, clearing session..."),e(null),a?.());},[n?.address,i,e,a]),!n?.isConnected||!t?null:o==="SOLANA"?jsxRuntime.jsx(h,{connectedAccount:n.connectedAccount,store:t,session:i,setSession:e}):jsxRuntime.jsx(f,{wagmiConfig:r,store:t,session:i,setSession:e})}function h({connectedAccount:n,store:t,session:r,setSession:i}){let e=react$1.useWalletAccountMessageSigner(n),a=react.useCallback(async()=>{let o=t.getState().activeConnection;if(!o?.isConnected)throw new Error("[QuasarSDK] Wallet disconnected");if(!e)throw new Error("[QuasarSDK] Solana Message Signer not initialized.");return chunkA52BVTJ6_js.g({isConnected:o.isConnected,address:o.address,chainType:"SOLANA",signer:e},{miniSession:r,setMiniSession:i})},[t,e,r,i]);return react.useEffect(()=>(s=a,()=>{s===a&&(s=null);}),[a]),null}function f({wagmiConfig:n,store:t,session:r,setSession:i}){let e=react.useCallback(async()=>{let u=t.getState().activeConnection;if(!u?.isConnected)throw new Error("[QuasarSDK] Wallet disconnected");let o=await core.getWalletClient(n);if(!o)throw new Error("[QuasarSDK] EVM Signer not found");return chunkA52BVTJ6_js.g({isConnected:u.isConnected,address:u.address,chainType:"EVM",signer:o},{miniSession:r,setMiniSession:i})},[t,n,r,i]);return react.useEffect(()=>(s=e,()=>{s===e&&(s=null);}),[e]),null}exports.QuasarAuthBridge=k;exports.getMiniSessionAuth=P;
package/dist/react.mjs ADDED
@@ -0,0 +1 @@
1
+ import {g}from'./chunk-DK4D3PU5.mjs';import {useWalletAccountMessageSigner}from'@solana/react';import {getWalletClient}from'@wagmi/core';import {useEffect,useCallback}from'react';import {jsx}from'react/jsx-runtime';var s=null;async function P(){for(let n=0;n<15;n++){if(s)return s();await new Promise(t=>setTimeout(t,200));}throw new Error("[QuasarSDK] Auth helper not initialized. Ensure QuasarAuthBridge is mounted and wallet is connected.")}function k({activeConnection:n,store:t,wagmiConfig:r,session:i,setSession:e,onAddressMismatch:a}){let o=typeof n?.chainId=="string"?"SOLANA":"EVM";return useEffect(()=>{i&&n?.address&&i.walletAddress!==n.address&&(console.log("[QuasarSDK] Address mismatch detected, clearing session..."),e(null),a?.());},[n?.address,i,e,a]),!n?.isConnected||!t?null:o==="SOLANA"?jsx(h,{connectedAccount:n.connectedAccount,store:t,session:i,setSession:e}):jsx(f,{wagmiConfig:r,store:t,session:i,setSession:e})}function h({connectedAccount:n,store:t,session:r,setSession:i}){let e=useWalletAccountMessageSigner(n),a=useCallback(async()=>{let o=t.getState().activeConnection;if(!o?.isConnected)throw new Error("[QuasarSDK] Wallet disconnected");if(!e)throw new Error("[QuasarSDK] Solana Message Signer not initialized.");return g({isConnected:o.isConnected,address:o.address,chainType:"SOLANA",signer:e},{miniSession:r,setMiniSession:i})},[t,e,r,i]);return useEffect(()=>(s=a,()=>{s===a&&(s=null);}),[a]),null}function f({wagmiConfig:n,store:t,session:r,setSession:i}){let e=useCallback(async()=>{let u=t.getState().activeConnection;if(!u?.isConnected)throw new Error("[QuasarSDK] Wallet disconnected");let o=await getWalletClient(n);if(!o)throw new Error("[QuasarSDK] EVM Signer not found");return g({isConnected:u.isConnected,address:u.address,chainType:"EVM",signer:o},{miniSession:r,setMiniSession:i})},[t,n,r,i]);return useEffect(()=>(s=e,()=>{s===e&&(s=null);}),[e]),null}export{k as QuasarAuthBridge,P as getMiniSessionAuth};
@@ -0,0 +1,188 @@
1
+ /**
2
+ * @module types
3
+ * @description Shared type definitions for the Quasar SDK.
4
+ * Contains configuration interfaces, query parameters, and authentication structures.
5
+ */
6
+
7
+ /**
8
+ * Configuration options for initializing the {@link Quasar} SDK client.
9
+ *
10
+ * @public
11
+ */
12
+ interface QuasarConfig {
13
+ /** Your secret API key starting with `sk_live_`. */
14
+ secretKey: string;
15
+ /** Optional internal secret for system-to-system communication. */
16
+ internalSecret?: string;
17
+ /** The base URL of the Quasar Cloud API. Defaults to 'https://api.tuwa.io'. */
18
+ baseUrl?: string;
19
+ /** Request timeout in milliseconds. Defaults to 10000. */
20
+ timeout?: number;
21
+ }
22
+ /**
23
+ * Query parameters for filtering and paginating transaction history.
24
+ *
25
+ * @public
26
+ */
27
+ interface HistoryQuery {
28
+ /** Page number for pagination (1-indexed). */
29
+ page?: number;
30
+ /** Maximum number of results to return per page. */
31
+ limit?: number;
32
+ /** Filter by blockchain chain ID (e.g., 1, 'solana'). */
33
+ chainId?: string | number;
34
+ /** Filter by transaction status (e.g., 'Success', 'Failed'). */
35
+ status?: string;
36
+ /** Filter by a specific Quasar transaction key. */
37
+ txKey?: string;
38
+ /** Filter by the application name. */
39
+ appName?: string;
40
+ /** Filter by the sender's wallet address. */
41
+ walletAddress?: string;
42
+ }
43
+ /**
44
+ * Generic wrapper for paginated API responses.
45
+ *
46
+ * @typeParam T - The type of the documents contained in the result set.
47
+ * @public
48
+ */
49
+ interface PaginatedResult<T> {
50
+ /** Array of documents for the current page. */
51
+ docs: T[];
52
+ /** Total number of documents matching the query. */
53
+ totalDocs: number;
54
+ /** Total number of available pages. */
55
+ totalPages: number;
56
+ /** The current page number (1-indexed). */
57
+ page: number;
58
+ /** Indicates if a subsequent page is available. */
59
+ hasNextPage: boolean;
60
+ /** Indicates if a preceding page is available. */
61
+ hasPrevPage: boolean;
62
+ }
63
+
64
+ /**
65
+ * Supported blockchain ecosystems for authentication.
66
+ * @public
67
+ */
68
+ declare enum ChainType {
69
+ /** Ethereum and compatible L2s. */
70
+ EVM = "EVM",
71
+ /** Solana blockchain. */
72
+ SOLANA = "SOLANA"
73
+ }
74
+ /**
75
+ * Result structure for a signed message.
76
+ * @public
77
+ */
78
+ interface SignSessionResult {
79
+ /** The cryptographic signature string. */
80
+ signature: string;
81
+ /** The ISO timestamp used to generate the message. */
82
+ timestamp: string;
83
+ }
84
+ /**
85
+ * Result of the Mini-Session signing process.
86
+ * Used for both frontend-side caching and backend-side verification.
87
+ * @public
88
+ */
89
+ interface MiniSessionAuth extends SignSessionResult {
90
+ /** The blockchain ecosystem type. */
91
+ chainType: ChainType;
92
+ /** The wallet address that signed the message. */
93
+ walletAddress: string;
94
+ }
95
+ /**
96
+ * Parameters for verifying a mini-session signature.
97
+ * @public
98
+ */
99
+ interface VerifySessionParams extends Omit<MiniSessionAuth, 'walletAddress'> {
100
+ /** The wallet address that allegedly signed the message. */
101
+ walletAddress: string;
102
+ /** Maximum allowed age for the signature in milliseconds. Defaults to 5 minutes. */
103
+ maxAge?: number;
104
+ }
105
+ /**
106
+ * Interface for an EVM signer (compatible with Viem WalletClient).
107
+ * @public
108
+ */
109
+ interface EvmSigner {
110
+ /** Signs a message using the specified account. */
111
+ signMessage: (params: {
112
+ account: `0x${string}`;
113
+ message: string;
114
+ }) => Promise<`0x${string}`>;
115
+ }
116
+ /**
117
+ * Result structure for a signed Solana message in Web3 v2.
118
+ * @public
119
+ */
120
+ interface SolanaSignedMessage {
121
+ /** A map of public addresses to their corresponding signature bytes. */
122
+ readonly signatures: Readonly<Record<string, Uint8Array>>;
123
+ }
124
+ /**
125
+ * Interface for a Solana signer.
126
+ * Optimized to handle modern Web3 v2 (MessageModifyingSigner), Standard, and Legacy interfaces.
127
+ * @public
128
+ */
129
+ interface SolanaSigner {
130
+ /** The public address of the signer. */
131
+ readonly address: string;
132
+ /**
133
+ * Modern Web3 v2 method to modify and sign messages.
134
+ * Used by latest @solana/react hooks.
135
+ */
136
+ modifyAndSignMessages?: (messages: readonly unknown[]) => Promise<readonly SolanaSignedMessage[]>;
137
+ /**
138
+ * Plural signing method (Wallet Standard).
139
+ */
140
+ signMessages?: (messages: readonly Uint8Array[]) => Promise<readonly {
141
+ signature: Uint8Array;
142
+ }[]>;
143
+ /**
144
+ * Singular signing method (Legacy).
145
+ */
146
+ signMessage?: (message: Uint8Array) => Promise<Uint8Array>;
147
+ }
148
+ /**
149
+ * Parameters for signing a mini-session message.
150
+ * @public
151
+ */
152
+ interface SignSessionParams {
153
+ /** The signer object for the respective ecosystem. */
154
+ signer: EvmSigner | SolanaSigner;
155
+ /** The wallet address to sign with. */
156
+ walletAddress: string;
157
+ /** The blockchain ecosystem type. */
158
+ chainType: ChainType;
159
+ }
160
+ /**
161
+ * Interface for a store that manages Mini-Session persistence.
162
+ * Designed to be compatible with Zustand.
163
+ * @public
164
+ */
165
+ interface MiniSessionStore {
166
+ /** Current active session or null. */
167
+ miniSession: MiniSessionAuth | null;
168
+ /** Sets the active session. */
169
+ setMiniSession: (session: MiniSessionAuth | null) => void;
170
+ /** Clears the current session. */
171
+ clearSession: () => void;
172
+ }
173
+ /**
174
+ * Minimum connection data required for Mini-Session signing.
175
+ * @public
176
+ */
177
+ interface ConnectionData {
178
+ /** Whether a wallet is currently connected. */
179
+ isConnected: boolean;
180
+ /** The active wallet address. */
181
+ address: string;
182
+ /** The blockchain ecosystem type. */
183
+ chainType: ChainType;
184
+ /** The wallet signer object. */
185
+ signer: EvmSigner | SolanaSigner;
186
+ }
187
+
188
+ export { type ConnectionData as C, type EvmSigner as E, type HistoryQuery as H, type MiniSessionStore as M, type PaginatedResult as P, type QuasarConfig as Q, type SignSessionParams as S, type VerifySessionParams as V, type SignSessionResult as a, type MiniSessionAuth as b, ChainType as c, type SolanaSignedMessage as d, type SolanaSigner as e };
@@ -0,0 +1,188 @@
1
+ /**
2
+ * @module types
3
+ * @description Shared type definitions for the Quasar SDK.
4
+ * Contains configuration interfaces, query parameters, and authentication structures.
5
+ */
6
+
7
+ /**
8
+ * Configuration options for initializing the {@link Quasar} SDK client.
9
+ *
10
+ * @public
11
+ */
12
+ interface QuasarConfig {
13
+ /** Your secret API key starting with `sk_live_`. */
14
+ secretKey: string;
15
+ /** Optional internal secret for system-to-system communication. */
16
+ internalSecret?: string;
17
+ /** The base URL of the Quasar Cloud API. Defaults to 'https://api.tuwa.io'. */
18
+ baseUrl?: string;
19
+ /** Request timeout in milliseconds. Defaults to 10000. */
20
+ timeout?: number;
21
+ }
22
+ /**
23
+ * Query parameters for filtering and paginating transaction history.
24
+ *
25
+ * @public
26
+ */
27
+ interface HistoryQuery {
28
+ /** Page number for pagination (1-indexed). */
29
+ page?: number;
30
+ /** Maximum number of results to return per page. */
31
+ limit?: number;
32
+ /** Filter by blockchain chain ID (e.g., 1, 'solana'). */
33
+ chainId?: string | number;
34
+ /** Filter by transaction status (e.g., 'Success', 'Failed'). */
35
+ status?: string;
36
+ /** Filter by a specific Quasar transaction key. */
37
+ txKey?: string;
38
+ /** Filter by the application name. */
39
+ appName?: string;
40
+ /** Filter by the sender's wallet address. */
41
+ walletAddress?: string;
42
+ }
43
+ /**
44
+ * Generic wrapper for paginated API responses.
45
+ *
46
+ * @typeParam T - The type of the documents contained in the result set.
47
+ * @public
48
+ */
49
+ interface PaginatedResult<T> {
50
+ /** Array of documents for the current page. */
51
+ docs: T[];
52
+ /** Total number of documents matching the query. */
53
+ totalDocs: number;
54
+ /** Total number of available pages. */
55
+ totalPages: number;
56
+ /** The current page number (1-indexed). */
57
+ page: number;
58
+ /** Indicates if a subsequent page is available. */
59
+ hasNextPage: boolean;
60
+ /** Indicates if a preceding page is available. */
61
+ hasPrevPage: boolean;
62
+ }
63
+
64
+ /**
65
+ * Supported blockchain ecosystems for authentication.
66
+ * @public
67
+ */
68
+ declare enum ChainType {
69
+ /** Ethereum and compatible L2s. */
70
+ EVM = "EVM",
71
+ /** Solana blockchain. */
72
+ SOLANA = "SOLANA"
73
+ }
74
+ /**
75
+ * Result structure for a signed message.
76
+ * @public
77
+ */
78
+ interface SignSessionResult {
79
+ /** The cryptographic signature string. */
80
+ signature: string;
81
+ /** The ISO timestamp used to generate the message. */
82
+ timestamp: string;
83
+ }
84
+ /**
85
+ * Result of the Mini-Session signing process.
86
+ * Used for both frontend-side caching and backend-side verification.
87
+ * @public
88
+ */
89
+ interface MiniSessionAuth extends SignSessionResult {
90
+ /** The blockchain ecosystem type. */
91
+ chainType: ChainType;
92
+ /** The wallet address that signed the message. */
93
+ walletAddress: string;
94
+ }
95
+ /**
96
+ * Parameters for verifying a mini-session signature.
97
+ * @public
98
+ */
99
+ interface VerifySessionParams extends Omit<MiniSessionAuth, 'walletAddress'> {
100
+ /** The wallet address that allegedly signed the message. */
101
+ walletAddress: string;
102
+ /** Maximum allowed age for the signature in milliseconds. Defaults to 5 minutes. */
103
+ maxAge?: number;
104
+ }
105
+ /**
106
+ * Interface for an EVM signer (compatible with Viem WalletClient).
107
+ * @public
108
+ */
109
+ interface EvmSigner {
110
+ /** Signs a message using the specified account. */
111
+ signMessage: (params: {
112
+ account: `0x${string}`;
113
+ message: string;
114
+ }) => Promise<`0x${string}`>;
115
+ }
116
+ /**
117
+ * Result structure for a signed Solana message in Web3 v2.
118
+ * @public
119
+ */
120
+ interface SolanaSignedMessage {
121
+ /** A map of public addresses to their corresponding signature bytes. */
122
+ readonly signatures: Readonly<Record<string, Uint8Array>>;
123
+ }
124
+ /**
125
+ * Interface for a Solana signer.
126
+ * Optimized to handle modern Web3 v2 (MessageModifyingSigner), Standard, and Legacy interfaces.
127
+ * @public
128
+ */
129
+ interface SolanaSigner {
130
+ /** The public address of the signer. */
131
+ readonly address: string;
132
+ /**
133
+ * Modern Web3 v2 method to modify and sign messages.
134
+ * Used by latest @solana/react hooks.
135
+ */
136
+ modifyAndSignMessages?: (messages: readonly unknown[]) => Promise<readonly SolanaSignedMessage[]>;
137
+ /**
138
+ * Plural signing method (Wallet Standard).
139
+ */
140
+ signMessages?: (messages: readonly Uint8Array[]) => Promise<readonly {
141
+ signature: Uint8Array;
142
+ }[]>;
143
+ /**
144
+ * Singular signing method (Legacy).
145
+ */
146
+ signMessage?: (message: Uint8Array) => Promise<Uint8Array>;
147
+ }
148
+ /**
149
+ * Parameters for signing a mini-session message.
150
+ * @public
151
+ */
152
+ interface SignSessionParams {
153
+ /** The signer object for the respective ecosystem. */
154
+ signer: EvmSigner | SolanaSigner;
155
+ /** The wallet address to sign with. */
156
+ walletAddress: string;
157
+ /** The blockchain ecosystem type. */
158
+ chainType: ChainType;
159
+ }
160
+ /**
161
+ * Interface for a store that manages Mini-Session persistence.
162
+ * Designed to be compatible with Zustand.
163
+ * @public
164
+ */
165
+ interface MiniSessionStore {
166
+ /** Current active session or null. */
167
+ miniSession: MiniSessionAuth | null;
168
+ /** Sets the active session. */
169
+ setMiniSession: (session: MiniSessionAuth | null) => void;
170
+ /** Clears the current session. */
171
+ clearSession: () => void;
172
+ }
173
+ /**
174
+ * Minimum connection data required for Mini-Session signing.
175
+ * @public
176
+ */
177
+ interface ConnectionData {
178
+ /** Whether a wallet is currently connected. */
179
+ isConnected: boolean;
180
+ /** The active wallet address. */
181
+ address: string;
182
+ /** The blockchain ecosystem type. */
183
+ chainType: ChainType;
184
+ /** The wallet signer object. */
185
+ signer: EvmSigner | SolanaSigner;
186
+ }
187
+
188
+ export { type ConnectionData as C, type EvmSigner as E, type HistoryQuery as H, type MiniSessionStore as M, type PaginatedResult as P, type QuasarConfig as Q, type SignSessionParams as S, type VerifySessionParams as V, type SignSessionResult as a, type MiniSessionAuth as b, ChainType as c, type SolanaSignedMessage as d, type SolanaSigner as e };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/quasar-sdk",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",
@@ -8,6 +8,18 @@
8
8
  "main": "./dist/index.js",
9
9
  "module": "./dist/index.mjs",
10
10
  "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.mjs",
15
+ "require": "./dist/index.js"
16
+ },
17
+ "./react": {
18
+ "types": "./dist/react.d.ts",
19
+ "import": "./dist/react.mjs",
20
+ "require": "./dist/react.js"
21
+ }
22
+ },
11
23
  "publishConfig": {
12
24
  "access": "public"
13
25
  },
@@ -36,17 +48,53 @@
36
48
  }
37
49
  ],
38
50
  "peerDependencies": {
51
+ "@solana/react": ">=6.9.0",
39
52
  "@tuwaio/pulsar-core": ">=0.6.0",
40
- "ofetch": ">=1.5.1"
53
+ "@wagmi/core": "3.x.x",
54
+ "@wallet-standard/react": "1.x.x",
55
+ "ofetch": ">=1.5.1",
56
+ "react": ">=19.2.0",
57
+ "gill": ">=0.14",
58
+ "viem": "2.x.x",
59
+ "zustand": "5.x.x"
60
+ },
61
+ "peerDependenciesMeta": {
62
+ "viem": {
63
+ "optional": true
64
+ },
65
+ "gill": {
66
+ "optional": true
67
+ },
68
+ "zustand": {
69
+ "optional": true
70
+ },
71
+ "react": {
72
+ "optional": true
73
+ },
74
+ "@solana/react": {
75
+ "optional": true
76
+ },
77
+ "@wagmi/core": {
78
+ "optional": true
79
+ },
80
+ "@wallet-standard/react": {
81
+ "optional": true
82
+ }
41
83
  },
42
84
  "devDependencies": {
43
- "@tuwaio/pulsar-core": "^0.6.2",
85
+ "@solana/react": "^6.9.0",
86
+ "@tuwaio/pulsar-core": "^0.6.3",
87
+ "@types/react": "^19.2.14",
88
+ "@wagmi/core": "^3.4.11",
89
+ "@wallet-standard/react": "^1.0.2",
44
90
  "ofetch": "^1.5.1",
91
+ "react": "^19.2.6",
45
92
  "tsup": "^8.5.1",
46
- "typescript": "^6.0.3"
93
+ "typescript": "^6.0.3",
94
+ "zustand": "^5.0.13"
47
95
  },
48
96
  "scripts": {
49
- "start": "tsup src/index.ts --watch",
97
+ "start": "tsup --watch",
50
98
  "build": "tsup"
51
99
  }
52
100
  }