@chipi-stack/chipi-react 11.22.0 → 12.1.0
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/hooks.d.mts +471 -69
- package/dist/hooks.d.ts +471 -69
- package/dist/hooks.js +474 -4
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +469 -6
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +474 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +469 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/hooks.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CreateWalletParams, CreateWalletResponse, GetWalletParams, GetWalletResponse, TransferHookInput, ApproveHookInput, GetTransactionListQuery, PaginatedResponse, Transaction, CreateSkuTransactionParams, SkuTransaction, GetSkuListQuery, Sku, StakeVesuUsdcHookInputParams, WithdrawVesuUsdcHookInputParams, CallAnyContractParams, RecordSendTransactionParams, GetTokenBalanceParams,
|
|
1
|
+
import { CreateWalletParams, CreateWalletResponse, GetWalletParams, GetWalletResponse, ChainToken, GetTokenBalanceResponse, WalletType, WalletData, SessionKeyData, SessionDataResponse, CreateSessionKeyParams, SessionConfig, Call, TransferHookInput, ApproveHookInput, GetTransactionListQuery, PaginatedResponse, Transaction, CreateSkuTransactionParams, SkuTransaction, GetSkuListQuery, Sku, StakeVesuUsdcHookInputParams, WithdrawVesuUsdcHookInputParams, CallAnyContractParams, RecordSendTransactionParams, GetTokenBalanceParams, GetUserParams, User, CreateUserParams, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, ExecuteWithSessionParams } from '@chipi-stack/types';
|
|
2
2
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
3
|
-
import { UseQueryOptions } from '@tanstack/react-query';
|
|
3
|
+
import { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
4
4
|
|
|
5
5
|
type CreateWalletInput = {
|
|
6
6
|
params: CreateWalletParams;
|
|
@@ -23,17 +23,11 @@ declare function useCreateWallet(): {
|
|
|
23
23
|
type GetWalletInput = {
|
|
24
24
|
params?: GetWalletParams;
|
|
25
25
|
getBearerToken?: () => Promise<string | null | undefined>;
|
|
26
|
-
queryOptions?: Omit<UseQueryOptions<
|
|
27
|
-
normalizedPublicKey: string;
|
|
28
|
-
}) | null, Error>, "queryKey" | "queryFn">;
|
|
26
|
+
queryOptions?: Omit<UseQueryOptions<GetWalletResponse | null, Error>, "queryKey" | "queryFn">;
|
|
29
27
|
};
|
|
30
28
|
declare function useGetWallet(input?: GetWalletInput): {
|
|
31
|
-
fetchWallet: (newInput: GetWalletInput) => Promise<
|
|
32
|
-
|
|
33
|
-
}) | null>;
|
|
34
|
-
data: (GetWalletResponse & {
|
|
35
|
-
normalizedPublicKey: string;
|
|
36
|
-
}) | null;
|
|
29
|
+
fetchWallet: (newInput: GetWalletInput) => Promise<GetWalletResponse | null>;
|
|
30
|
+
data: GetWalletResponse | null;
|
|
37
31
|
error: Error;
|
|
38
32
|
isError: true;
|
|
39
33
|
isPending: false;
|
|
@@ -56,20 +50,12 @@ declare function useGetWallet(input?: GetWalletInput): {
|
|
|
56
50
|
isRefetching: boolean;
|
|
57
51
|
isStale: boolean;
|
|
58
52
|
isEnabled: boolean;
|
|
59
|
-
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<
|
|
60
|
-
normalizedPublicKey: string;
|
|
61
|
-
}) | null, Error>>;
|
|
53
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<GetWalletResponse | null, Error>>;
|
|
62
54
|
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
63
|
-
promise: Promise<
|
|
64
|
-
normalizedPublicKey: string;
|
|
65
|
-
}) | null>;
|
|
55
|
+
promise: Promise<GetWalletResponse | null>;
|
|
66
56
|
} | {
|
|
67
|
-
fetchWallet: (newInput: GetWalletInput) => Promise<
|
|
68
|
-
|
|
69
|
-
}) | null>;
|
|
70
|
-
data: (GetWalletResponse & {
|
|
71
|
-
normalizedPublicKey: string;
|
|
72
|
-
}) | null;
|
|
57
|
+
fetchWallet: (newInput: GetWalletInput) => Promise<GetWalletResponse | null>;
|
|
58
|
+
data: GetWalletResponse | null;
|
|
73
59
|
error: null;
|
|
74
60
|
isError: false;
|
|
75
61
|
isPending: false;
|
|
@@ -92,17 +78,11 @@ declare function useGetWallet(input?: GetWalletInput): {
|
|
|
92
78
|
isRefetching: boolean;
|
|
93
79
|
isStale: boolean;
|
|
94
80
|
isEnabled: boolean;
|
|
95
|
-
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<
|
|
96
|
-
normalizedPublicKey: string;
|
|
97
|
-
}) | null, Error>>;
|
|
81
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<GetWalletResponse | null, Error>>;
|
|
98
82
|
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
99
|
-
promise: Promise<
|
|
100
|
-
normalizedPublicKey: string;
|
|
101
|
-
}) | null>;
|
|
83
|
+
promise: Promise<GetWalletResponse | null>;
|
|
102
84
|
} | {
|
|
103
|
-
fetchWallet: (newInput: GetWalletInput) => Promise<
|
|
104
|
-
normalizedPublicKey: string;
|
|
105
|
-
}) | null>;
|
|
85
|
+
fetchWallet: (newInput: GetWalletInput) => Promise<GetWalletResponse | null>;
|
|
106
86
|
data: undefined;
|
|
107
87
|
error: Error;
|
|
108
88
|
isError: true;
|
|
@@ -126,17 +106,11 @@ declare function useGetWallet(input?: GetWalletInput): {
|
|
|
126
106
|
isRefetching: boolean;
|
|
127
107
|
isStale: boolean;
|
|
128
108
|
isEnabled: boolean;
|
|
129
|
-
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<
|
|
130
|
-
normalizedPublicKey: string;
|
|
131
|
-
}) | null, Error>>;
|
|
109
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<GetWalletResponse | null, Error>>;
|
|
132
110
|
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
133
|
-
promise: Promise<
|
|
134
|
-
normalizedPublicKey: string;
|
|
135
|
-
}) | null>;
|
|
111
|
+
promise: Promise<GetWalletResponse | null>;
|
|
136
112
|
} | {
|
|
137
|
-
fetchWallet: (newInput: GetWalletInput) => Promise<
|
|
138
|
-
normalizedPublicKey: string;
|
|
139
|
-
}) | null>;
|
|
113
|
+
fetchWallet: (newInput: GetWalletInput) => Promise<GetWalletResponse | null>;
|
|
140
114
|
data: undefined;
|
|
141
115
|
error: null;
|
|
142
116
|
isError: false;
|
|
@@ -160,17 +134,11 @@ declare function useGetWallet(input?: GetWalletInput): {
|
|
|
160
134
|
isRefetching: boolean;
|
|
161
135
|
isStale: boolean;
|
|
162
136
|
isEnabled: boolean;
|
|
163
|
-
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<
|
|
164
|
-
normalizedPublicKey: string;
|
|
165
|
-
}) | null, Error>>;
|
|
137
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<GetWalletResponse | null, Error>>;
|
|
166
138
|
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
167
|
-
promise: Promise<
|
|
168
|
-
normalizedPublicKey: string;
|
|
169
|
-
}) | null>;
|
|
139
|
+
promise: Promise<GetWalletResponse | null>;
|
|
170
140
|
} | {
|
|
171
|
-
fetchWallet: (newInput: GetWalletInput) => Promise<
|
|
172
|
-
normalizedPublicKey: string;
|
|
173
|
-
}) | null>;
|
|
141
|
+
fetchWallet: (newInput: GetWalletInput) => Promise<GetWalletResponse | null>;
|
|
174
142
|
data: undefined;
|
|
175
143
|
error: null;
|
|
176
144
|
isError: false;
|
|
@@ -194,20 +162,12 @@ declare function useGetWallet(input?: GetWalletInput): {
|
|
|
194
162
|
isRefetching: boolean;
|
|
195
163
|
isStale: boolean;
|
|
196
164
|
isEnabled: boolean;
|
|
197
|
-
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<
|
|
198
|
-
normalizedPublicKey: string;
|
|
199
|
-
}) | null, Error>>;
|
|
165
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<GetWalletResponse | null, Error>>;
|
|
200
166
|
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
201
|
-
promise: Promise<
|
|
202
|
-
normalizedPublicKey: string;
|
|
203
|
-
}) | null>;
|
|
167
|
+
promise: Promise<GetWalletResponse | null>;
|
|
204
168
|
} | {
|
|
205
|
-
fetchWallet: (newInput: GetWalletInput) => Promise<
|
|
206
|
-
|
|
207
|
-
}) | null>;
|
|
208
|
-
data: (GetWalletResponse & {
|
|
209
|
-
normalizedPublicKey: string;
|
|
210
|
-
}) | null;
|
|
169
|
+
fetchWallet: (newInput: GetWalletInput) => Promise<GetWalletResponse | null>;
|
|
170
|
+
data: GetWalletResponse | null;
|
|
211
171
|
isError: false;
|
|
212
172
|
error: null;
|
|
213
173
|
isPending: false;
|
|
@@ -230,15 +190,260 @@ declare function useGetWallet(input?: GetWalletInput): {
|
|
|
230
190
|
isRefetching: boolean;
|
|
231
191
|
isStale: boolean;
|
|
232
192
|
isEnabled: boolean;
|
|
233
|
-
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<
|
|
234
|
-
normalizedPublicKey: string;
|
|
235
|
-
}) | null, Error>>;
|
|
193
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<GetWalletResponse | null, Error>>;
|
|
236
194
|
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
237
|
-
promise: Promise<
|
|
238
|
-
normalizedPublicKey: string;
|
|
239
|
-
}) | null>;
|
|
195
|
+
promise: Promise<GetWalletResponse | null>;
|
|
240
196
|
};
|
|
241
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Configuration for useChipiWallet hook
|
|
200
|
+
*/
|
|
201
|
+
interface UseChipiWalletConfig {
|
|
202
|
+
/** External user ID (e.g., from Clerk, Firebase, etc.) */
|
|
203
|
+
externalUserId: string | null | undefined;
|
|
204
|
+
/** Function to get the bearer token for API calls */
|
|
205
|
+
getBearerToken: () => Promise<string | null | undefined>;
|
|
206
|
+
/** Default token for balance display (defaults to USDC) */
|
|
207
|
+
defaultToken?: ChainToken;
|
|
208
|
+
/** Whether to automatically fetch wallet on mount */
|
|
209
|
+
enabled?: boolean;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Extended wallet response with additional computed properties
|
|
213
|
+
*/
|
|
214
|
+
interface ChipiWalletData extends GetWalletResponse {
|
|
215
|
+
/** Whether this wallet supports session keys */
|
|
216
|
+
supportsSessionKeys: boolean;
|
|
217
|
+
/** Formatted short address for display */
|
|
218
|
+
shortAddress: string;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Return type for useChipiWallet hook
|
|
222
|
+
*/
|
|
223
|
+
interface UseChipiWalletReturn {
|
|
224
|
+
/** The user's wallet data, null if not found, undefined if loading */
|
|
225
|
+
wallet: ChipiWalletData | null | undefined;
|
|
226
|
+
/** Whether the user has a wallet */
|
|
227
|
+
hasWallet: boolean;
|
|
228
|
+
/** Whether the wallet is currently being fetched */
|
|
229
|
+
isLoadingWallet: boolean;
|
|
230
|
+
/** Error from fetching wallet */
|
|
231
|
+
walletError: Error | null;
|
|
232
|
+
/** The wallet's balance for the default token */
|
|
233
|
+
balance: GetTokenBalanceResponse | undefined;
|
|
234
|
+
/** Formatted balance string (e.g., "100.50") */
|
|
235
|
+
formattedBalance: string;
|
|
236
|
+
/** Whether balance is loading */
|
|
237
|
+
isLoadingBalance: boolean;
|
|
238
|
+
/** Create a new wallet */
|
|
239
|
+
createWallet: (params: {
|
|
240
|
+
encryptKey: string;
|
|
241
|
+
walletType?: WalletType;
|
|
242
|
+
}) => Promise<CreateWalletResponse>;
|
|
243
|
+
/** Whether wallet creation is in progress */
|
|
244
|
+
isCreating: boolean;
|
|
245
|
+
/** Data from the last wallet creation */
|
|
246
|
+
createdWallet: CreateWalletResponse | undefined;
|
|
247
|
+
/** Refetch the wallet data */
|
|
248
|
+
refetchWallet: () => Promise<void>;
|
|
249
|
+
/** Refetch the balance */
|
|
250
|
+
refetchBalance: () => Promise<void>;
|
|
251
|
+
/** Refetch both wallet and balance */
|
|
252
|
+
refetchAll: () => Promise<void>;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* All-in-one wallet hook for Chipi SDK.
|
|
256
|
+
*
|
|
257
|
+
* Combines wallet fetching, creation, and balance checking into a single hook
|
|
258
|
+
* for simplified wallet management.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```tsx
|
|
262
|
+
* import { useAuth } from "@clerk/nextjs";
|
|
263
|
+
* import { useChipiWallet } from "@chipi-stack/nextjs";
|
|
264
|
+
*
|
|
265
|
+
* function WalletComponent() {
|
|
266
|
+
* const { userId, getToken } = useAuth();
|
|
267
|
+
* const {
|
|
268
|
+
* wallet,
|
|
269
|
+
* hasWallet,
|
|
270
|
+
* balance,
|
|
271
|
+
* formattedBalance,
|
|
272
|
+
* createWallet,
|
|
273
|
+
* isCreating,
|
|
274
|
+
* isLoadingWallet,
|
|
275
|
+
* } = useChipiWallet({
|
|
276
|
+
* externalUserId: userId,
|
|
277
|
+
* getBearerToken: getToken,
|
|
278
|
+
* });
|
|
279
|
+
*
|
|
280
|
+
* if (isLoadingWallet) return <div>Loading...</div>;
|
|
281
|
+
*
|
|
282
|
+
* if (!hasWallet) {
|
|
283
|
+
* return (
|
|
284
|
+
* <button
|
|
285
|
+
* onClick={() => createWallet({ encryptKey: "1234" })}
|
|
286
|
+
* disabled={isCreating}
|
|
287
|
+
* >
|
|
288
|
+
* {isCreating ? "Creating..." : "Create Wallet"}
|
|
289
|
+
* </button>
|
|
290
|
+
* );
|
|
291
|
+
* }
|
|
292
|
+
*
|
|
293
|
+
* return (
|
|
294
|
+
* <div>
|
|
295
|
+
* <p>Address: {wallet?.shortAddress}</p>
|
|
296
|
+
* <p>Balance: ${formattedBalance} USDC</p>
|
|
297
|
+
* <p>Session Keys: {wallet?.supportsSessionKeys ? "Yes" : "No"}</p>
|
|
298
|
+
* </div>
|
|
299
|
+
* );
|
|
300
|
+
* }
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
declare function useChipiWallet(config: UseChipiWalletConfig): UseChipiWalletReturn;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Wallet data with optional wallet type for session operations
|
|
307
|
+
*/
|
|
308
|
+
interface SessionWallet extends WalletData {
|
|
309
|
+
walletType?: WalletType;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Configuration for useChipiSession hook
|
|
313
|
+
*/
|
|
314
|
+
interface UseChipiSessionConfig {
|
|
315
|
+
/** Wallet data (must be a CHIPI wallet for session support) */
|
|
316
|
+
wallet: SessionWallet | null | undefined;
|
|
317
|
+
/** Encryption key (user's PIN) for signing operations */
|
|
318
|
+
encryptKey: string;
|
|
319
|
+
/** Function to get the bearer token for API calls */
|
|
320
|
+
getBearerToken: () => Promise<string | null | undefined>;
|
|
321
|
+
/** Previously stored session data (from Clerk metadata, database, etc.) */
|
|
322
|
+
storedSession?: SessionKeyData | null;
|
|
323
|
+
/** Callback fired when a new session is created (for persistence) */
|
|
324
|
+
onSessionCreated?: (session: SessionKeyData) => void | Promise<void>;
|
|
325
|
+
/** Session duration in seconds (default: 6 hours) */
|
|
326
|
+
defaultDurationSeconds?: number;
|
|
327
|
+
/** Default max calls for session registration (default: 1000) */
|
|
328
|
+
defaultMaxCalls?: number;
|
|
329
|
+
/** Whether to auto-check session status on mount */
|
|
330
|
+
autoCheckStatus?: boolean;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Session lifecycle state
|
|
334
|
+
*/
|
|
335
|
+
type SessionState = "none" | "created" | "active" | "expired" | "revoked";
|
|
336
|
+
/**
|
|
337
|
+
* Return type for useChipiSession hook
|
|
338
|
+
*/
|
|
339
|
+
interface UseChipiSessionReturn {
|
|
340
|
+
/** Current session key data */
|
|
341
|
+
session: SessionKeyData | null;
|
|
342
|
+
/** On-chain session status (from contract query) */
|
|
343
|
+
sessionStatus: SessionDataResponse | undefined;
|
|
344
|
+
/** Current session lifecycle state */
|
|
345
|
+
sessionState: SessionState;
|
|
346
|
+
/** Whether there is an active, usable session */
|
|
347
|
+
hasActiveSession: boolean;
|
|
348
|
+
/** Whether the session has expired */
|
|
349
|
+
isSessionExpired: boolean;
|
|
350
|
+
/** Remaining calls available for the session */
|
|
351
|
+
remainingCalls: number | undefined;
|
|
352
|
+
/** Whether the wallet supports sessions (CHIPI wallet) */
|
|
353
|
+
supportsSession: boolean;
|
|
354
|
+
/** Create a new session keypair locally (does NOT register on-chain) */
|
|
355
|
+
createSession: (config?: Partial<CreateSessionKeyParams>) => Promise<SessionKeyData>;
|
|
356
|
+
/** Register the current session on the blockchain */
|
|
357
|
+
registerSession: (config?: Partial<SessionConfig>) => Promise<string>;
|
|
358
|
+
/** Revoke the current session from the blockchain */
|
|
359
|
+
revokeSession: () => Promise<string>;
|
|
360
|
+
/** Execute calls using the session key (no owner signature needed) */
|
|
361
|
+
executeWithSession: (calls: Call[]) => Promise<string>;
|
|
362
|
+
/** Clear the current session from local state */
|
|
363
|
+
clearSession: () => void;
|
|
364
|
+
/** Refresh the on-chain session status */
|
|
365
|
+
refetchStatus: () => Promise<void>;
|
|
366
|
+
isCreating: boolean;
|
|
367
|
+
isRegistering: boolean;
|
|
368
|
+
isRevoking: boolean;
|
|
369
|
+
isExecuting: boolean;
|
|
370
|
+
isLoadingStatus: boolean;
|
|
371
|
+
error: Error | null;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* All-in-one session management hook for Chipi SDK.
|
|
375
|
+
*
|
|
376
|
+
* Combines session creation, registration, execution, and revocation
|
|
377
|
+
* into a single unified API. Session keys enable gasless transactions
|
|
378
|
+
* without requiring the owner's private key for each operation.
|
|
379
|
+
*
|
|
380
|
+
* **Important:** Sessions only work with CHIPI wallets. ARGENT wallets
|
|
381
|
+
* do not support session keys.
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```tsx
|
|
385
|
+
* import { useAuth } from "@clerk/nextjs";
|
|
386
|
+
* import { useChipiWallet, useChipiSession } from "@chipi-stack/nextjs";
|
|
387
|
+
*
|
|
388
|
+
* function SessionComponent() {
|
|
389
|
+
* const { userId, getToken } = useAuth();
|
|
390
|
+
* const [pin, setPin] = useState("");
|
|
391
|
+
* const { wallet } = useChipiWallet({ externalUserId: userId, getBearerToken: getToken });
|
|
392
|
+
*
|
|
393
|
+
* const {
|
|
394
|
+
* session,
|
|
395
|
+
* hasActiveSession,
|
|
396
|
+
* sessionState,
|
|
397
|
+
* createSession,
|
|
398
|
+
* registerSession,
|
|
399
|
+
* executeWithSession,
|
|
400
|
+
* isCreating,
|
|
401
|
+
* isRegistering,
|
|
402
|
+
* } = useChipiSession({
|
|
403
|
+
* wallet,
|
|
404
|
+
* encryptKey: pin,
|
|
405
|
+
* getBearerToken: getToken,
|
|
406
|
+
* onSessionCreated: async (newSession) => {
|
|
407
|
+
* // Persist to Clerk metadata or database
|
|
408
|
+
* await saveSessionToClerk(newSession);
|
|
409
|
+
* },
|
|
410
|
+
* });
|
|
411
|
+
*
|
|
412
|
+
* const handleSetupSession = async () => {
|
|
413
|
+
* // Step 1: Create session locally
|
|
414
|
+
* await createSession();
|
|
415
|
+
* // Step 2: Register on-chain
|
|
416
|
+
* await registerSession();
|
|
417
|
+
* };
|
|
418
|
+
*
|
|
419
|
+
* const handleTransfer = async () => {
|
|
420
|
+
* // Execute transfer using session (no PIN needed after setup)
|
|
421
|
+
* await executeWithSession([{
|
|
422
|
+
* contractAddress: USDC_ADDRESS,
|
|
423
|
+
* entrypoint: "transfer",
|
|
424
|
+
* calldata: [recipient, amount, "0x0"],
|
|
425
|
+
* }]);
|
|
426
|
+
* };
|
|
427
|
+
*
|
|
428
|
+
* return (
|
|
429
|
+
* <div>
|
|
430
|
+
* <p>Session State: {sessionState}</p>
|
|
431
|
+
* {!hasActiveSession ? (
|
|
432
|
+
* <button onClick={handleSetupSession} disabled={isCreating || isRegistering}>
|
|
433
|
+
* Setup Session
|
|
434
|
+
* </button>
|
|
435
|
+
* ) : (
|
|
436
|
+
* <button onClick={handleTransfer}>
|
|
437
|
+
* Transfer (Gasless)
|
|
438
|
+
* </button>
|
|
439
|
+
* )}
|
|
440
|
+
* </div>
|
|
441
|
+
* );
|
|
442
|
+
* }
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
declare function useChipiSession(config: UseChipiSessionConfig): UseChipiSessionReturn;
|
|
446
|
+
|
|
242
447
|
type TransferInput = {
|
|
243
448
|
params: TransferHookInput;
|
|
244
449
|
bearerToken: string;
|
|
@@ -1472,4 +1677,201 @@ declare function useCreateUser(): {
|
|
|
1472
1677
|
reset: () => void;
|
|
1473
1678
|
};
|
|
1474
1679
|
|
|
1475
|
-
|
|
1680
|
+
/**
|
|
1681
|
+
* Hook for creating a session keypair locally.
|
|
1682
|
+
*
|
|
1683
|
+
* This generates session keys but does NOT register them on-chain.
|
|
1684
|
+
* The returned SessionKeyData should be stored by the developer externally
|
|
1685
|
+
* (e.g., in Clerk metadata, database, etc.) - the SDK does NOT persist this.
|
|
1686
|
+
*
|
|
1687
|
+
* After generating, call `useAddSessionKeyToContract` to register the session on-chain.
|
|
1688
|
+
*
|
|
1689
|
+
* @example
|
|
1690
|
+
* ```typescript
|
|
1691
|
+
* const { createSessionKey, data: session } = useCreateSessionKey();
|
|
1692
|
+
*
|
|
1693
|
+
* // Generate session keypair
|
|
1694
|
+
* createSessionKey({
|
|
1695
|
+
* encryptKey: userEncryptKey,
|
|
1696
|
+
* durationSeconds: 21600 // 6 hours (optional, default)
|
|
1697
|
+
* });
|
|
1698
|
+
*
|
|
1699
|
+
* // Store session externally after creation
|
|
1700
|
+
* if (session) {
|
|
1701
|
+
* await saveToClerk(session);
|
|
1702
|
+
* }
|
|
1703
|
+
* ```
|
|
1704
|
+
*/
|
|
1705
|
+
declare function useCreateSessionKey(): {
|
|
1706
|
+
createSessionKey: (params: CreateSessionKeyParams) => void;
|
|
1707
|
+
createSessionKeyAsync: (params: CreateSessionKeyParams) => Promise<SessionKeyData>;
|
|
1708
|
+
data: SessionKeyData | undefined;
|
|
1709
|
+
isLoading: boolean;
|
|
1710
|
+
isError: boolean;
|
|
1711
|
+
error: Error | null;
|
|
1712
|
+
isSuccess: boolean;
|
|
1713
|
+
reset: () => void;
|
|
1714
|
+
};
|
|
1715
|
+
|
|
1716
|
+
type AddSessionKeyInput = {
|
|
1717
|
+
params: AddSessionKeyParams;
|
|
1718
|
+
bearerToken: string;
|
|
1719
|
+
};
|
|
1720
|
+
/**
|
|
1721
|
+
* Hook for registering a session key on the smart contract.
|
|
1722
|
+
*
|
|
1723
|
+
* This executes a sponsored transaction (using owner signature) to call
|
|
1724
|
+
* `add_or_update_session_key` on the CHIPI wallet contract.
|
|
1725
|
+
*
|
|
1726
|
+
* The session must be registered before it can be used for transactions.
|
|
1727
|
+
* Only works with CHIPI wallets.
|
|
1728
|
+
*
|
|
1729
|
+
* @example
|
|
1730
|
+
* ```typescript
|
|
1731
|
+
* const { addSessionKeyToContract, isLoading } = useAddSessionKeyToContract();
|
|
1732
|
+
*
|
|
1733
|
+
* // Register session on-chain
|
|
1734
|
+
* addSessionKeyToContract({
|
|
1735
|
+
* params: {
|
|
1736
|
+
* encryptKey: userEncryptKey,
|
|
1737
|
+
* wallet: userWallet,
|
|
1738
|
+
* sessionConfig: {
|
|
1739
|
+
* sessionPublicKey: session.publicKey,
|
|
1740
|
+
* validUntil: session.validUntil,
|
|
1741
|
+
* maxCalls: 1000,
|
|
1742
|
+
* allowedEntrypoints: [] // empty = all allowed
|
|
1743
|
+
* }
|
|
1744
|
+
* },
|
|
1745
|
+
* bearerToken
|
|
1746
|
+
* });
|
|
1747
|
+
* ```
|
|
1748
|
+
*/
|
|
1749
|
+
declare function useAddSessionKeyToContract(): {
|
|
1750
|
+
addSessionKeyToContract: (input: AddSessionKeyInput) => void;
|
|
1751
|
+
addSessionKeyToContractAsync: (input: AddSessionKeyInput) => Promise<string>;
|
|
1752
|
+
data: string | undefined;
|
|
1753
|
+
isLoading: boolean;
|
|
1754
|
+
isError: boolean;
|
|
1755
|
+
error: Error | null;
|
|
1756
|
+
isSuccess: boolean;
|
|
1757
|
+
reset: () => void;
|
|
1758
|
+
};
|
|
1759
|
+
|
|
1760
|
+
type RevokeSessionKeyInput = {
|
|
1761
|
+
params: RevokeSessionKeyParams;
|
|
1762
|
+
bearerToken: string;
|
|
1763
|
+
};
|
|
1764
|
+
/**
|
|
1765
|
+
* Hook for revoking a session key from the smart contract.
|
|
1766
|
+
*
|
|
1767
|
+
* This executes a sponsored transaction (using owner signature) to call
|
|
1768
|
+
* `revoke_session_key` on the CHIPI wallet contract.
|
|
1769
|
+
*
|
|
1770
|
+
* After revocation, the session key can no longer be used for transactions.
|
|
1771
|
+
* Only works with CHIPI wallets.
|
|
1772
|
+
*
|
|
1773
|
+
* @example
|
|
1774
|
+
* ```typescript
|
|
1775
|
+
* const { revokeSessionKey, isLoading } = useRevokeSessionKey();
|
|
1776
|
+
*
|
|
1777
|
+
* // Revoke a session
|
|
1778
|
+
* revokeSessionKey({
|
|
1779
|
+
* params: {
|
|
1780
|
+
* encryptKey: userEncryptKey,
|
|
1781
|
+
* wallet: userWallet,
|
|
1782
|
+
* sessionPublicKey: session.publicKey
|
|
1783
|
+
* },
|
|
1784
|
+
* bearerToken
|
|
1785
|
+
* });
|
|
1786
|
+
* ```
|
|
1787
|
+
*/
|
|
1788
|
+
declare function useRevokeSessionKey(): {
|
|
1789
|
+
revokeSessionKey: (input: RevokeSessionKeyInput) => void;
|
|
1790
|
+
revokeSessionKeyAsync: (input: RevokeSessionKeyInput) => Promise<string>;
|
|
1791
|
+
data: string | undefined;
|
|
1792
|
+
isLoading: boolean;
|
|
1793
|
+
isError: boolean;
|
|
1794
|
+
error: Error | null;
|
|
1795
|
+
isSuccess: boolean;
|
|
1796
|
+
reset: () => void;
|
|
1797
|
+
};
|
|
1798
|
+
|
|
1799
|
+
/**
|
|
1800
|
+
* Hook for querying session data from the smart contract.
|
|
1801
|
+
*
|
|
1802
|
+
* This is a read-only call that does not require signing or gas.
|
|
1803
|
+
* Returns the on-chain state of a session key including:
|
|
1804
|
+
* - Whether it's active
|
|
1805
|
+
* - When it expires
|
|
1806
|
+
* - Remaining calls
|
|
1807
|
+
* - Allowed entrypoints
|
|
1808
|
+
*
|
|
1809
|
+
* @example
|
|
1810
|
+
* ```typescript
|
|
1811
|
+
* const { data: sessionData, isLoading } = useGetSessionData({
|
|
1812
|
+
* walletAddress: userWallet.publicKey,
|
|
1813
|
+
* sessionPublicKey: session.publicKey
|
|
1814
|
+
* });
|
|
1815
|
+
*
|
|
1816
|
+
* if (sessionData?.isActive) {
|
|
1817
|
+
* console.log(`Session has ${sessionData.remainingCalls} calls remaining`);
|
|
1818
|
+
* }
|
|
1819
|
+
* ```
|
|
1820
|
+
*/
|
|
1821
|
+
declare function useGetSessionData(params: GetSessionDataParams | null, options?: {
|
|
1822
|
+
enabled?: boolean;
|
|
1823
|
+
}): {
|
|
1824
|
+
data: SessionDataResponse | undefined;
|
|
1825
|
+
isLoading: boolean;
|
|
1826
|
+
isError: boolean;
|
|
1827
|
+
error: Error | null;
|
|
1828
|
+
isSuccess: boolean;
|
|
1829
|
+
refetch: UseQueryResult<SessionDataResponse, Error>["refetch"];
|
|
1830
|
+
};
|
|
1831
|
+
|
|
1832
|
+
type ExecuteWithSessionInput = {
|
|
1833
|
+
params: ExecuteWithSessionParams;
|
|
1834
|
+
bearerToken: string;
|
|
1835
|
+
};
|
|
1836
|
+
/**
|
|
1837
|
+
* Hook for executing a gasless transaction using a session key.
|
|
1838
|
+
*
|
|
1839
|
+
* This uses the 4-element session signature format instead of owner signature.
|
|
1840
|
+
* The session must be:
|
|
1841
|
+
* 1. Generated via `useCreateSessionKey`
|
|
1842
|
+
* 2. Registered on-chain via `useAddSessionKeyToContract`
|
|
1843
|
+
*
|
|
1844
|
+
* Only works with CHIPI wallets.
|
|
1845
|
+
*
|
|
1846
|
+
* @example
|
|
1847
|
+
* ```typescript
|
|
1848
|
+
* const { executeWithSession, isLoading } = useExecuteWithSession();
|
|
1849
|
+
*
|
|
1850
|
+
* // Execute a transfer using session key (no owner key needed)
|
|
1851
|
+
* executeWithSession({
|
|
1852
|
+
* params: {
|
|
1853
|
+
* encryptKey: userEncryptKey,
|
|
1854
|
+
* wallet: userWallet,
|
|
1855
|
+
* session: sessionKeyData,
|
|
1856
|
+
* calls: [{
|
|
1857
|
+
* contractAddress: USDC_ADDRESS,
|
|
1858
|
+
* entrypoint: 'transfer',
|
|
1859
|
+
* calldata: [recipient, amount, '0x0']
|
|
1860
|
+
* }]
|
|
1861
|
+
* },
|
|
1862
|
+
* bearerToken
|
|
1863
|
+
* });
|
|
1864
|
+
* ```
|
|
1865
|
+
*/
|
|
1866
|
+
declare function useExecuteWithSession(): {
|
|
1867
|
+
executeWithSession: (input: ExecuteWithSessionInput) => void;
|
|
1868
|
+
executeWithSessionAsync: (input: ExecuteWithSessionInput) => Promise<string>;
|
|
1869
|
+
data: string | undefined;
|
|
1870
|
+
isLoading: boolean;
|
|
1871
|
+
isError: boolean;
|
|
1872
|
+
error: Error | null;
|
|
1873
|
+
isSuccess: boolean;
|
|
1874
|
+
reset: () => void;
|
|
1875
|
+
};
|
|
1876
|
+
|
|
1877
|
+
export { type ChipiWalletData, type SessionState, type SessionWallet, type UseChipiSessionConfig, type UseChipiSessionReturn, type UseChipiWalletConfig, type UseChipiWalletReturn, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateSkuTransaction, useCreateUser, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuTransaction, useGetTokenBalance, useGetTransactionList, useGetUser, useGetWallet, useRecordSendTransaction, useRevokeSessionKey, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
|