@supanovaapp/sdk 0.2.15 → 0.2.17

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 CHANGED
@@ -9,6 +9,7 @@ For a quick overview of the code, check out the demo application in the `/demo`
9
9
  ## Key Features
10
10
 
11
11
  - **Privy.io Authentication** - Email, wallet, and social login methods
12
+ - **Wallet Export** - Export private keys for Solana wallets (with `withExport: true`)
12
13
  - **EVM Smart Wallets** - Support for Privy Smart Wallets with gas sponsorship
13
14
  - **Built-in Confirmation Modals** - User-friendly signing confirmations
14
15
  - **Theme Support** - Light/dark mode with customizable appearance
@@ -24,11 +25,11 @@ For a quick overview of the code, check out the demo application in the `/demo`
24
25
  ### From npm (when published)
25
26
 
26
27
  ```bash
27
- npm install @supa/sdk
28
+ npm install @supanovaapp/sdk
28
29
  # or
29
- yarn add @supa/sdk
30
+ yarn add @supanovaapp/sdk
30
31
  # or
31
- pnpm add @supa/sdk
32
+ pnpm add @supanovaapp/sdk
32
33
  ```
33
34
 
34
35
  #### Optional: For Smart Wallets support
@@ -66,7 +67,7 @@ npm link
66
67
 
67
68
  In your project directory:
68
69
  ```bash
69
- npm link @supa/sdk
70
+ npm link @supanovaapp/sdk
70
71
  ```
71
72
 
72
73
  **Option B: Using local path**
@@ -75,7 +76,7 @@ In your project's `package.json`, add:
75
76
  ```json
76
77
  {
77
78
  "dependencies": {
78
- "@supa/sdk": "file:../path/to/supa-sdk"
79
+ "@supanovaapp/sdk": "file:../path/to/supa-sdk"
79
80
  }
80
81
  }
81
82
  ```
@@ -100,7 +101,7 @@ npm install ../path/to/supa-sdk/supa-sdk-0.1.0.tgz
100
101
  ## Quick Start
101
102
 
102
103
  ```tsx
103
- import { SupaProvider, useAuth, useCanton } from '@supa/sdk';
104
+ import { SupaProvider, useAuth, useCanton } from '@supanovaapp/sdk';
104
105
 
105
106
  function App() {
106
107
  return (
@@ -137,7 +138,7 @@ function MyApp() {
137
138
  Wrap your application with `SupaProvider`:
138
139
 
139
140
  ```tsx
140
- import { SupaProvider } from '@supa/sdk';
141
+ import { SupaProvider } from '@supanovaapp/sdk';
141
142
 
142
143
  function App() {
143
144
  return (
@@ -254,7 +255,7 @@ function InviteOnlyApp() {
254
255
  Use the `useAuth` hook to manage authentication:
255
256
 
256
257
  ```tsx
257
- import { useAuth } from '@supa/sdk';
258
+ import { useAuth } from '@supanovaapp/sdk';
258
259
 
259
260
  function LoginButton() {
260
261
  const { login, logout, authenticated, user } = useAuth();
@@ -274,6 +275,78 @@ function LoginButton() {
274
275
 
275
276
  After successful authentication, `authenticated` becomes `true` and `user` object contains user data.
276
277
 
278
+ #### Export Wallet Private Key
279
+
280
+ **Note:** Wallet export is only available when `withExport: true` is set in SupaProvider config (Solana wallets).
281
+
282
+ Export your wallet's private key to use it with other wallet clients like Phantom:
283
+
284
+ ```tsx
285
+ import { useAuth, useCantonWallet } from '@supanovaapp/sdk';
286
+
287
+ function ExportWalletButton() {
288
+ const { exportWallet, authenticated } = useAuth();
289
+ const { cantonWallet } = useCantonWallet();
290
+
291
+ const handleExport = async () => {
292
+ if (!cantonWallet) return;
293
+
294
+ try {
295
+ // Export the primary Canton wallet
296
+ await exportWallet({ address: cantonWallet.address });
297
+
298
+ // Or export without specifying address (exports first wallet)
299
+ await exportWallet();
300
+ } catch (error) {
301
+ console.error('Export failed:', error);
302
+ }
303
+ };
304
+
305
+ return (
306
+ <button onClick={handleExport} disabled={!authenticated || !cantonWallet}>
307
+ Export Private Key
308
+ </button>
309
+ );
310
+ }
311
+ ```
312
+
313
+ **What happens:**
314
+ - Privy modal opens showing your private key
315
+ - You can copy the key to use with MetaMask, Phantom, or other wallet clients
316
+ - The key is assembled securely on a different origin - neither you nor Privy can access it during transmission
317
+
318
+ **Security Warning:** Never share your private key! Anyone with your private key has full control over your wallet.
319
+
320
+ #### Complete Logout with State Cleanup
321
+
322
+ For a complete logout that clears all SDK state (Canton balances, registration, etc.), use the `useSupa` hook:
323
+
324
+ ```tsx
325
+ import { useSupa } from '@supanovaapp/sdk';
326
+
327
+ function App() {
328
+ const { auth, canton, logout } = useSupa();
329
+
330
+ if (!auth.authenticated) {
331
+ return <button onClick={auth.login}>Login</button>;
332
+ }
333
+
334
+ return (
335
+ <div>
336
+ <p>Welcome! Canton registered: {canton.isRegistered ? 'Yes' : 'No'}</p>
337
+ <button onClick={logout}>Complete Logout</button>
338
+ </div>
339
+ );
340
+ }
341
+ ```
342
+
343
+ **What `useSupa().logout()` does:**
344
+ 1. Clears all Canton state (balances, user info, registration flags)
345
+ 2. Terminates Privy session
346
+ 3. Resets all internal SDK state
347
+
348
+ **Note:** Using `auth.logout()` directly only logs out from Privy but doesn't clear Canton state. For complete cleanup, always use `useSupa().logout()`.
349
+
277
350
  ---
278
351
 
279
352
  ### 3. Canton Network Operations
@@ -283,7 +356,7 @@ After successful authentication, `authenticated` becomes `true` and `user` objec
283
356
  Register your Canton wallet with optional invite code support:
284
357
 
285
358
  ```tsx
286
- import { useCanton } from '@supa/sdk';
359
+ import { useCanton } from '@supanovaapp/sdk';
287
360
 
288
361
  function CantonWallet() {
289
362
  const { registerCanton, isRegistered, cantonUser, loading } = useCanton();
@@ -623,7 +696,7 @@ try {
623
696
  #### Custom Modal Options
624
697
 
625
698
  ```tsx
626
- import { useSignMessage } from '@supa/sdk';
699
+ import { useSignMessage } from '@supanovaapp/sdk';
627
700
 
628
701
  const { signMessage } = useSignMessage();
629
702
 
@@ -640,7 +713,7 @@ await signMessage('Hello', {
640
713
  #### Custom Transaction Modals
641
714
 
642
715
  ```tsx
643
- import { useSendTransaction } from '@supa/sdk';
716
+ import { useSendTransaction } from '@supanovaapp/sdk';
644
717
 
645
718
  const { sendTransaction } = useSendTransaction();
646
719
 
@@ -658,8 +731,9 @@ await sendTransaction(command, contracts, {
658
731
 
659
732
  | Hook | Purpose | Key Methods |
660
733
  |------|---------|-------------|
734
+ | `useSupa` | Main SDK hook | `auth`, `canton`, `api`, `onboard`, `logout` (recommended for complete cleanup) |
661
735
  | `useAuth` | Authentication | `login`, `logout`, `authenticated`, `user` |
662
- | `useCanton` | Canton Network | `registerCanton`, `getBalances`, `sendCantonCoin`, `signMessage`, `sendTransaction`, `getActiveContracts`, `tapDevnet`, `getPendingIncomingTransfers`, `respondToIncomingTransfer` |
736
+ | `useCanton` | Canton Network | `registerCanton`, `getBalances`, `sendCantonCoin`, `signMessage`, `sendTransaction`, `getActiveContracts`, `tapDevnet`, `getPendingIncomingTransfers`, `respondToIncomingTransfer`, `resetState` |
663
737
  | `useSignMessage` | Enhanced message signing | `signMessage` with custom modals |
664
738
  | `useSendTransaction` | Enhanced transactions | `sendTransaction` with custom modals |
665
739
  | `useConfirmModal` | Generic modals | `confirm`, `signMessageConfirm`, `signTransactionConfirm` |
@@ -696,7 +770,7 @@ import type {
696
770
  SendTransactionOptions,
697
771
  ConfirmModalOptions,
698
772
  CantonSubmitPreparedOptions,
699
- } from '@supa/sdk';
773
+ } from '@supanovaapp/sdk';
700
774
  ```
701
775
 
702
776
  ## How to run demo
@@ -758,7 +832,7 @@ npm run build
758
832
 
759
833
  ### Development Workflow
760
834
 
761
- The demo application in `/demo` folder is already configured to use the local SDK version via `"@supa/sdk": "file:.."` dependency.
835
+ The demo application in `/demo` folder is already configured to use the local SDK version via `"@supanovaapp/sdk": "file:.."` dependency.
762
836
 
763
837
  #### Recommended Workflow
764
838
 
@@ -2,14 +2,15 @@ import { AxiosRequestConfig } from 'axios';
2
2
  export interface ClientConfig {
3
3
  baseURL?: string;
4
4
  nodeIdentifier: string;
5
+ /** Optional app identifier for app-specific backend rules */
6
+ supaAppId?: string;
5
7
  getAccessToken?: () => Promise<string | null>;
6
8
  }
7
9
  export declare class ApiClient {
8
10
  private client;
9
11
  private getAccessToken?;
10
12
  private nodeIdentifier;
11
- private cache;
12
- private cacheTTL;
13
+ private supaAppId?;
13
14
  constructor(config?: ClientConfig);
14
15
  get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
15
16
  post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
@@ -38,6 +38,16 @@ export interface CantonSubmitTransactionResponseDto {
38
38
  /** Submission ID for tracking completion */
39
39
  submissionId: string;
40
40
  }
41
+ export interface CantonSubmitMultipleResultDto {
42
+ /** Hash of the transaction that was submitted */
43
+ hash: string;
44
+ /** Whether the submission succeeded */
45
+ success: boolean;
46
+ /** Submission ID if successful */
47
+ submissionId?: string;
48
+ /** Error message if failed */
49
+ error?: string;
50
+ }
41
51
  export type CantonQueryCompletionStatus = 'completed' | 'unknown';
42
52
  export interface CantonQueryCompletionResponseDto {
43
53
  /** Status of the completion query */
@@ -5,7 +5,7 @@ import { User as PrivyUser } from '@privy-io/react-auth';
5
5
  export interface UseAuthReturn {
6
6
  /** Opens Privy login modal */
7
7
  login: () => void;
8
- /** Logs out the current user */
8
+ /** Logs out the current user and clears all SDK state */
9
9
  logout: () => Promise<void>;
10
10
  /** Whether user is authenticated */
11
11
  authenticated: boolean;
@@ -17,6 +17,10 @@ export interface UseAuthReturn {
17
17
  getAccessToken: () => Promise<string | null>;
18
18
  /** Whether SDK is ready (not loading) */
19
19
  ready: boolean;
20
+ /** Export wallet private key (opens Privy modal). Address is optional - defaults to first wallet */
21
+ exportWallet: (options?: {
22
+ address?: string;
23
+ }) => Promise<void>;
20
24
  }
21
25
  /**
22
26
  * Hook for managing user authentication via Privy
@@ -0,0 +1,10 @@
1
+ import { CantonWallet } from '../utils/wallet';
2
+ export interface UseCantonWalletReturn {
3
+ cantonWallets: CantonWallet[];
4
+ cantonWallet: CantonWallet | null;
5
+ }
6
+ /** @deprecated Use useCantonWallet instead */
7
+ export type UseStellarWalletReturn = UseCantonWalletReturn;
8
+ export declare function useCantonWallet(): UseCantonWalletReturn;
9
+ /** @deprecated Use useCantonWallet instead */
10
+ export declare const useStellarWallet: typeof useCantonWallet;
@@ -0,0 +1,10 @@
1
+ import { CantonSubmitMultipleResultDto } from '../core/types';
2
+ export interface UseInitializationTransactionsReturn {
3
+ runInitializationTransactions: () => Promise<CantonSubmitMultipleResultDto[]>;
4
+ /** Внутренний лоадер хука; приложения могут его игнорировать, чтобы не блокировать UI */
5
+ loading: boolean;
6
+ /** Последняя ошибка хука; приложения могут игнорировать и обрабатывать ошибку на уровне вызова */
7
+ error: Error | null;
8
+ clearError: () => void;
9
+ }
10
+ export declare function useInitializationTransactions(): UseInitializationTransactionsReturn;
@@ -1,4 +1,4 @@
1
- import { StellarWallet } from '../utils/stellar';
1
+ import { CantonWallet } from '../utils/wallet';
2
2
  import { CantonQueryCompletionResponseDto, CantonSubmitPreparedOptions } from '../services/cantonService';
3
3
  export interface SendTransactionOptions {
4
4
  onSuccess?: (result: CantonQueryCompletionResponseDto) => void;
@@ -21,7 +21,7 @@ export interface UseSendTransactionReturn {
21
21
  loading: boolean;
22
22
  error: Error | null;
23
23
  clearError: () => void;
24
- stellarWallets: StellarWallet[];
25
- stellarWallet: StellarWallet | null;
24
+ cantonWallets: CantonWallet[];
25
+ cantonWallet: CantonWallet | null;
26
26
  }
27
27
  export declare function useSendTransaction(): UseSendTransactionReturn;
@@ -1,4 +1,4 @@
1
- import { StellarWallet } from '../utils/stellar';
1
+ import { CantonWallet } from '../utils/wallet';
2
2
  export interface SignMessageOptions {
3
3
  onSuccess?: (signature: string) => void;
4
4
  onRejection?: () => void;
@@ -19,7 +19,7 @@ export interface UseSignMessageReturn {
19
19
  loading: boolean;
20
20
  error: Error | null;
21
21
  clearError: () => void;
22
- stellarWallets: StellarWallet[];
23
- stellarWallet: StellarWallet | null;
22
+ cantonWallets: CantonWallet[];
23
+ cantonWallet: CantonWallet | null;
24
24
  }
25
25
  export declare function useSignMessage(): UseSignMessageReturn;
@@ -1,4 +1,9 @@
1
- import { useSignRawHash } from '@privy-io/react-auth/extended-chains';
1
+ /**
2
+ * Wrapper over Privy's signing with automatic confirmation modals
3
+ *
4
+ * Shows a confirmation modal before every signing operation
5
+ * Supports both Stellar (rawSign) and Solana (signMessage) based on withExport config
6
+ */
2
7
  export interface SignRawHashModalOptions {
3
8
  skipModal?: boolean;
4
9
  title?: string;
@@ -11,7 +16,11 @@ export interface SignRawHashModalOptions {
11
16
  /** Show technical details (address, chainType, hash) as JSON. Default: false */
12
17
  showTechnicalDetails?: boolean;
13
18
  }
14
- type SignRawHashParams = Parameters<ReturnType<typeof useSignRawHash>['signRawHash']>[0];
19
+ export interface SignRawHashParams {
20
+ address: string;
21
+ chainType: string;
22
+ hash: `0x${string}`;
23
+ }
15
24
  export interface UseSignRawHashWithModalReturn {
16
25
  /** Sign a raw hash with confirmation modal */
17
26
  signRawHashWithModal: (params: SignRawHashParams, modalOptions?: SignRawHashModalOptions) => Promise<{
@@ -19,4 +28,3 @@ export interface UseSignRawHashWithModalReturn {
19
28
  } | null>;
20
29
  }
21
30
  export declare function useSignRawHashWithModal(): UseSignRawHashWithModalReturn;
22
- export {};
@@ -13,6 +13,8 @@ export interface UseSupaReturn {
13
13
  api: UseAPIReturn;
14
14
  /** Automated onboarding flow (login → create wallet → register Canton) */
15
15
  onboard: () => Promise<void>;
16
+ /** Complete logout (Privy + clear all SDK state) */
17
+ logout: () => Promise<void>;
16
18
  }
17
19
  /**
18
20
  * Main hook for accessing all Supa SDK features
@@ -27,7 +29,7 @@ export interface UseSupaReturn {
27
29
  * Basic usage
28
30
  * ```tsx
29
31
  * function Dashboard() {
30
- * const { auth, canton, api } = useSupa();
32
+ * const { auth, canton, api, logout } = useSupa();
31
33
  *
32
34
  * if (!auth.authenticated) {
33
35
  * return <button onClick={auth.login}>Login</button>;
@@ -39,6 +41,7 @@ export interface UseSupaReturn {
39
41
  * <button onClick={() => canton.registerCanton()}>
40
42
  * Register Canton
41
43
  * </button>
44
+ * <button onClick={logout}>Logout</button>
42
45
  * </div>
43
46
  * );
44
47
  * }