@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.
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- import { StellarWallet } from '../utils/stellar';
2
+ import { CantonWallet } from '../utils/wallet';
3
3
  import { CantonService, CantonSubmitPreparedOptions } from '../services/cantonService';
4
4
  import { CantonMeResponseDto, CantonActiveContractsResponseDto, CantonQueryCompletionResponseDto, CantonWalletBalancesResponseDto, CantonIncomingTransferDto, CantonTransactionDto, CantonTransactionsParams, CantonPriceInterval, CantonPriceCandleDto } from '../core/types';
5
5
  export interface CantonSendCoinOptions extends CantonSubmitPreparedOptions {
@@ -8,11 +8,11 @@ export interface CantonSendCoinOptions extends CantonSubmitPreparedOptions {
8
8
  }
9
9
  export interface CantonContextValue {
10
10
  /** First Stellar wallet (primary) */
11
- stellarWallet: StellarWallet | null;
11
+ cantonWallet: CantonWallet | null;
12
12
  /** All Stellar wallets */
13
- stellarWallets: StellarWallet[];
13
+ cantonWallets: CantonWallet[];
14
14
  /** Create new Stellar wallet */
15
- createStellarWallet: () => Promise<StellarWallet | null>;
15
+ createCantonWallet: () => Promise<CantonWallet | null>;
16
16
  /** Register Canton wallet on backend */
17
17
  registerCanton: (inviteCode?: string) => Promise<void>;
18
18
  /** Whether Canton wallet is registered */
@@ -47,6 +47,8 @@ export interface CantonContextValue {
47
47
  getTransactions: (params?: CantonTransactionsParams) => Promise<CantonTransactionDto[]>;
48
48
  /** Get Canton price history (candles from Bybit) */
49
49
  getPriceHistory: (interval: CantonPriceInterval) => Promise<CantonPriceCandleDto[]>;
50
+ /** Reset all Canton state (for logout) */
51
+ resetState: () => void;
50
52
  /** Loading state */
51
53
  loading: boolean;
52
54
  /** Error state */
@@ -57,8 +59,15 @@ export interface CantonContextValue {
57
59
  export interface CantonProviderProps {
58
60
  cantonService: CantonService;
59
61
  children: ReactNode;
62
+ /** Enable wallet export (uses Solana instead of Stellar). Default: false */
63
+ withExport?: boolean;
60
64
  /** Enable automatic onboarding (create wallet + register Canton on login). Default: true */
61
65
  autoOnboarding?: boolean;
66
+ /**
67
+ * Legacy onboarding stage: automatically setup transfer preapproval after registration.
68
+ * Default: false (new onboarding uses prepare_initialization_transactions).
69
+ */
70
+ autoTransferPreapproval?: boolean;
62
71
  }
63
- export declare function CantonProvider({ cantonService, children, autoOnboarding }: CantonProviderProps): import("react/jsx-runtime").JSX.Element;
72
+ export declare function CantonProvider({ cantonService, children, withExport, autoOnboarding, autoTransferPreapproval, }: CantonProviderProps): import("react/jsx-runtime").JSX.Element;
64
73
  export declare function useCantonContext(): CantonContextValue;
@@ -7,6 +7,8 @@ export interface SupaConfig {
7
7
  privyClientId?: string;
8
8
  apiBaseUrl?: string;
9
9
  nodeIdentifier: string;
10
+ /** Optional app identifier for special app-specific rules (sent as X-Supa-App-Id header) */
11
+ supaAppId?: string;
10
12
  appearance?: {
11
13
  theme?: 'light' | 'dark';
12
14
  accentColor?: string;
@@ -32,8 +34,23 @@ export interface SupaConfig {
32
34
  defaultChain?: any;
33
35
  /** Supported chains for the app */
34
36
  supportedChains?: any[];
37
+ /**
38
+ * Enable wallet export functionality (uses Solana wallets instead of Stellar)
39
+ * When false (default): Uses Stellar wallets, export will throw an error
40
+ * When true: Uses Solana wallets, export is available
41
+ * @default false
42
+ */
43
+ withExport?: boolean;
35
44
  /** Enable automatic onboarding (create wallet + register Canton on login). Default: true */
36
45
  autoOnboarding?: boolean;
46
+ /**
47
+ * Optional onboarding stages flags.
48
+ * By default transfer preapproval is NOT auto-executed.
49
+ */
50
+ onboardingStages?: {
51
+ /** Auto-run transfer preapproval stage (legacy). Default: false */
52
+ transferPreapproval?: boolean;
53
+ };
37
54
  }
38
55
  export interface ConfirmModalOptions {
39
56
  title?: string;
@@ -14,22 +14,13 @@ export declare class ApiService {
14
14
  private readonly USER_CACHE_TTL;
15
15
  constructor(client: ApiClient);
16
16
  /**
17
- * Инвалидация кеша /user/me
18
- * Вызывается после операций, изменяющих данные пользователя
19
- */
20
- private invalidateUserCache;
21
- /**
22
- * Инвалидация кеша /supa_points/balance
17
+ * Invalidate /supa_points/balance cache
23
18
  */
24
19
  private invalidateSupaPointsCache;
25
- /**
26
- * Инвалидация кеша /privy/balance
27
- */
28
- private invalidatePrivyBalanceCache;
29
20
  /**
30
21
  * Get current user information
31
22
  * GET /user/me
32
- * С мемоизацией на 5 минут и дедупликацией одновременных запросов
23
+ * With 5 minute caching and request deduplication
33
24
  */
34
25
  getCurrentUser(force?: boolean): Promise<UserResponseDto>;
35
26
  /**
@@ -134,7 +125,7 @@ export declare class ApiService {
134
125
  /**
135
126
  * Get SupaPoints balance
136
127
  * GET /supa_points/balance
137
- * С мемоизацией на 5 минут и дедупликацией одновременных запросов
128
+ * With 5 minute caching and request deduplication
138
129
  */
139
130
  getSupaPointsBalance(force?: boolean): Promise<SupaPointsBalanceResponseDto>;
140
131
  /**
@@ -155,7 +146,7 @@ export declare class ApiService {
155
146
  /**
156
147
  * Get Privy balance
157
148
  * GET /privy/balance
158
- * С мемоизацией на 5 минут и дедупликацией одновременных запросов
149
+ * With 5 minute caching and request deduplication
159
150
  */
160
151
  getPrivyBalance(force?: boolean): Promise<any>;
161
152
  }
@@ -1,6 +1,6 @@
1
1
  import { ApiClient } from '../core/client';
2
- import { CantonPrepareTransactionResponseDto, CantonSubmitTransactionResponseDto, CantonMeResponseDto, CantonActiveContractsResponseDto, CantonQueryCompletionResponseDto, CantonWalletBalancesResponseDto, CantonPrepareAmuletTransferRequestDto, CantonIncomingTransferDto, CantonPrepareResponseIncomingTransferRequestDto, CantonCostEstimationDto, CantonTransactionDto, CantonTransactionsParams, CantonPriceInterval, CantonPriceCandleDto } from '../core/types';
3
- export type { CantonMeResponseDto, CantonActiveContractsResponseDto, CantonPrepareTransactionResponseDto, CantonQueryCompletionResponseDto, CantonWalletBalancesResponseDto, CantonPrepareAmuletTransferRequestDto, CantonIncomingTransferDto, CantonPrepareResponseIncomingTransferRequestDto, CantonCostEstimationDto, CantonTransactionDto, CantonTransactionsParams, CantonPriceInterval, CantonPriceCandleDto, };
2
+ import { CantonPrepareTransactionResponseDto, CantonSubmitRegisterRequestDto, CantonSubmitTransactionResponseDto, CantonMeResponseDto, CantonActiveContractsResponseDto, CantonQueryCompletionResponseDto, CantonWalletBalancesResponseDto, CantonPrepareAmuletTransferRequestDto, CantonIncomingTransferDto, CantonPrepareResponseIncomingTransferRequestDto, CantonCostEstimationDto, CantonTransactionDto, CantonTransactionsParams, CantonPriceInterval, CantonPriceCandleDto, CantonSubmitMultipleResultDto } from '../core/types';
3
+ export type { CantonMeResponseDto, CantonActiveContractsResponseDto, CantonPrepareTransactionResponseDto, CantonQueryCompletionResponseDto, CantonWalletBalancesResponseDto, CantonPrepareAmuletTransferRequestDto, CantonIncomingTransferDto, CantonPrepareResponseIncomingTransferRequestDto, CantonCostEstimationDto, CantonTransactionDto, CantonTransactionsParams, CantonPriceInterval, CantonPriceCandleDto, CantonSubmitMultipleResultDto, };
4
4
  export interface CantonRegisterParams {
5
5
  /** Base64 public key from Stellar wallet */
6
6
  publicKey: string;
@@ -31,8 +31,8 @@ export declare class CantonService {
31
31
  private readonly CACHE_TTL;
32
32
  constructor(client: ApiClient);
33
33
  /**
34
- * Инвалидация кеша /me
35
- * Вызывается после операций регистрации/изменения пользователя
34
+ * Invalidate /me cache
35
+ * Called after registration/user modification operations
36
36
  */
37
37
  private invalidateMeCache;
38
38
  /**
@@ -63,6 +63,11 @@ export declare class CantonService {
63
63
  * @param signature Base64 signature
64
64
  */
65
65
  submitPrepared(hash: string, signature: string): Promise<CantonSubmitTransactionResponseDto>;
66
+ /**
67
+ * Submit multiple signed Canton transactions in a single request
68
+ * @param txs Array of { hash, signature } (base64)
69
+ */
70
+ submitMultiplePrepared(txs: CantonSubmitRegisterRequestDto[]): Promise<CantonSubmitMultipleResultDto[]>;
66
71
  /**
67
72
  * Query completion status for a submission
68
73
  * @param submissionId Submission ID from submitPrepared
@@ -81,7 +86,7 @@ export declare class CantonService {
81
86
  /**
82
87
  * Get current Canton user info (partyId and email)
83
88
  * Only works after registration
84
- * С мемоизацией на 5 минут и дедупликацией одновременных запросов
89
+ * With 5 minute caching and request deduplication
85
90
  */
86
91
  getMe(force?: boolean): Promise<CantonMeResponseDto>;
87
92
  /**
@@ -114,6 +119,11 @@ export declare class CantonService {
114
119
  * No request body required
115
120
  */
116
121
  prepareTransferPreapproval(): Promise<CantonPrepareTransactionResponseDto>;
122
+ /**
123
+ * Prepare initialization transactions for onboarding
124
+ * Backend may return 0..4 transactions depending on app rules.
125
+ */
126
+ prepareInitializationTransactions(): Promise<CantonPrepareTransactionResponseDto[]>;
117
127
  /**
118
128
  * Get Canton wallet balances
119
129
  * Returns balances for all tokens grouped by instrument ID
@@ -65,3 +65,16 @@ export declare const stripLeadingZero: (hex: string) => string;
65
65
  * ```
66
66
  */
67
67
  export declare const privyPublicKeyToCantonBase64: (publicKeyHex: string) => string;
68
+ /**
69
+ * Decodes a base58 string to bytes using BigInt for precision
70
+ * @param str - Base58 encoded string
71
+ * @returns Byte array
72
+ */
73
+ export declare const base58ToBytes: (str: string) => Uint8Array;
74
+ /**
75
+ * Converts a Solana address (base58) to base64 for Canton Network
76
+ * @param address - Solana address in base58 format
77
+ * @returns Public key in base64 format (32 bytes Ed25519 key)
78
+ * @throws {Error} If decoded key is not 32 bytes
79
+ */
80
+ export declare const solanaAddressToBase64: (address: string) => string;
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Stellar wallet utilities for Privy integration
3
+ * Stellar chain type is used for Ed25519 signing required by Canton Network
4
+ */
5
+ /**
6
+ * Stellar/Solana wallet interface representing a Privy Ed25519 wallet
7
+ */
8
+ export interface CantonWallet {
9
+ /** Wallet address (public key in Stellar/Solana format) */
10
+ address: string;
11
+ /** Raw public key in hex format (camelCase) - only for Stellar */
12
+ publicKey?: string;
13
+ /** Raw public key in hex format (snake_case from Privy API) - only for Stellar */
14
+ public_key?: string;
15
+ /** Chain type: 'stellar' (default) or 'solana' (with export) */
16
+ chainType: 'stellar' | 'solana';
17
+ /** Wallet client type (e.g., 'privy') */
18
+ walletClientType?: string;
19
+ /** Whether the wallet was imported or created */
20
+ imported?: boolean;
21
+ }
22
+ /**
23
+ * Extracts all Ed25519 wallets (Stellar or Solana) from Privy user and wallets array
24
+ * Combines wallets from both user.linkedAccounts and useWallets hook,
25
+ * removing duplicates by address.
26
+ *
27
+ * @param user - Privy user object
28
+ * @param wallets - Privy wallets array from useWallets hook
29
+ * @param chainType - Chain type to filter by: 'stellar' (default) or 'solana' (with export)
30
+ * @returns Array of unique wallets
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const { user } = usePrivy();
35
+ * const { wallets } = useWallets();
36
+ * const cantonWallets = getCantonWallets(user, wallets, 'stellar');
37
+ * console.log(`Found ${cantonWallets.length} wallets`);
38
+ * ```
39
+ */
40
+ export declare const getCantonWallets: (user: any, wallets: any[], chainType?: "stellar" | "solana") => CantonWallet[];
41
+ /**
42
+ * Converts Stellar wallet public key to Canton Network base64 format
43
+ * Handles removal of leading 00 byte and conversion from hex to base64
44
+ *
45
+ * @param wallet - Stellar wallet object containing publicKey
46
+ * @returns Public key in base64 format ready for Canton Network API
47
+ * @throws {Error} If wallet is invalid or publicKey is missing/malformed
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const publicKeyBase64 = getPublicKeyBase64(stellarWallet);
52
+ * // Use with Canton Network API
53
+ * await fetch('/canton/register/prepare', {
54
+ * body: JSON.stringify({ publicKey: publicKeyBase64 })
55
+ * });
56
+ * ```
57
+ */
58
+ export declare const getPublicKeyBase64: (wallet: CantonWallet | any) => string;
59
+ /**
60
+ * Type guard to check if a wallet is a Stellar/Solana Ed25519 wallet
61
+ * @param wallet - Wallet object to check
62
+ * @returns True if wallet is a valid Ed25519 wallet (Stellar or Solana)
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * if (isCantonWallet(wallet)) {
67
+ * console.log('Ed25519 wallet address:', wallet.address);
68
+ * }
69
+ * ```
70
+ */
71
+ export declare const isCantonWallet: (wallet: any) => wallet is CantonWallet;
72
+ /**
73
+ * Gets the first Ed25519 wallet from user and wallets array
74
+ * Convenience function that throws if no wallet is found
75
+ *
76
+ * @param user - Privy user object
77
+ * @param wallets - Privy wallets array from useWallets hook
78
+ * @param chainType - Chain type to filter by: 'stellar' (default) or 'solana' (with export)
79
+ * @returns First wallet found
80
+ * @throws {Error} If no wallet found
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * try {
85
+ * const wallet = getFirstCantonWallet(user, wallets, 'stellar');
86
+ * console.log('Using wallet:', wallet.address);
87
+ * } catch (err) {
88
+ * console.error('No wallet available');
89
+ * }
90
+ * ```
91
+ */
92
+ export declare const getFirstCantonWallet: (user: any, wallets: any[], chainType?: "stellar" | "solana") => CantonWallet;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supanovaapp/sdk",
3
- "version": "0.2.15",
3
+ "version": "0.2.17",
4
4
  "description": "React SDK for Supa Backend + Privy.io integration with Canton Network and EVM Smart Wallets support",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",
@@ -1,6 +0,0 @@
1
- import { StellarWallet } from '../utils/stellar';
2
- export interface UseStellarWalletReturn {
3
- stellarWallets: StellarWallet[];
4
- stellarWallet: StellarWallet | null;
5
- }
6
- export declare function useStellarWallet(): UseStellarWalletReturn;
@@ -1,90 +0,0 @@
1
- /**
2
- * Stellar wallet utilities for Privy integration
3
- * Stellar chain type is used for Ed25519 signing required by Canton Network
4
- */
5
- /**
6
- * Stellar wallet interface representing a Privy Stellar wallet
7
- */
8
- export interface StellarWallet {
9
- /** Stellar address (public key in Stellar format) */
10
- address: string;
11
- /** Raw public key in hex format (camelCase) */
12
- publicKey?: string;
13
- /** Raw public key in hex format (snake_case from Privy API) */
14
- public_key?: string;
15
- /** Chain type, always 'stellar' for Stellar wallets */
16
- chainType: 'stellar';
17
- /** Wallet client type (e.g., 'privy') */
18
- walletClientType?: string;
19
- /** Whether the wallet was imported or created */
20
- imported?: boolean;
21
- }
22
- /**
23
- * Extracts all Stellar wallets from Privy user and wallets array
24
- * Combines wallets from both user.linkedAccounts and useWallets hook,
25
- * removing duplicates by address.
26
- *
27
- * @param user - Privy user object
28
- * @param wallets - Privy wallets array from useWallets hook
29
- * @returns Array of unique Stellar wallets
30
- *
31
- * @example
32
- * ```ts
33
- * const { user } = usePrivy();
34
- * const { wallets } = useWallets();
35
- * const stellarWallets = getStellarWallets(user, wallets);
36
- * console.log(`Found ${stellarWallets.length} Stellar wallets`);
37
- * ```
38
- */
39
- export declare const getStellarWallets: (user: any, wallets: any[]) => StellarWallet[];
40
- /**
41
- * Converts Stellar wallet public key to Canton Network base64 format
42
- * Handles removal of leading 00 byte and conversion from hex to base64
43
- *
44
- * @param wallet - Stellar wallet object containing publicKey
45
- * @returns Public key in base64 format ready for Canton Network API
46
- * @throws {Error} If wallet is invalid or publicKey is missing/malformed
47
- *
48
- * @example
49
- * ```ts
50
- * const publicKeyBase64 = getPublicKeyBase64(stellarWallet);
51
- * // Use with Canton Network API
52
- * await fetch('/canton/register/prepare', {
53
- * body: JSON.stringify({ publicKey: publicKeyBase64 })
54
- * });
55
- * ```
56
- */
57
- export declare const getPublicKeyBase64: (wallet: StellarWallet | any) => string;
58
- /**
59
- * Type guard to check if a wallet is a Stellar wallet
60
- * @param wallet - Wallet object to check
61
- * @returns True if wallet is a valid Stellar wallet
62
- *
63
- * @example
64
- * ```ts
65
- * if (isStellarWallet(wallet)) {
66
- * console.log('Stellar wallet address:', wallet.address);
67
- * }
68
- * ```
69
- */
70
- export declare const isStellarWallet: (wallet: any) => wallet is StellarWallet;
71
- /**
72
- * Gets the first Stellar wallet from user and wallets array
73
- * Convenience function that throws if no Stellar wallet is found
74
- *
75
- * @param user - Privy user object
76
- * @param wallets - Privy wallets array from useWallets hook
77
- * @returns First Stellar wallet found
78
- * @throws {Error} If no Stellar wallet found
79
- *
80
- * @example
81
- * ```ts
82
- * try {
83
- * const wallet = getFirstStellarWallet(user, wallets);
84
- * console.log('Using wallet:', wallet.address);
85
- * } catch (err) {
86
- * console.error('No Stellar wallet available');
87
- * }
88
- * ```
89
- */
90
- export declare const getFirstStellarWallet: (user: any, wallets: any[]) => StellarWallet;