@supanovaapp/sdk 0.2.12 → 0.2.13
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 +81 -0
- package/dist/components/ConfirmationModal.d.ts +43 -0
- package/dist/core/client.d.ts +23 -0
- package/dist/core/types.d.ts +533 -0
- package/dist/hooks/useAPI.d.ts +142 -0
- package/dist/hooks/useAuth.d.ts +45 -0
- package/dist/hooks/useCanton.d.ts +19 -0
- package/dist/hooks/useConfirmModal.d.ts +15 -0
- package/dist/hooks/useSendTransaction.d.ts +27 -0
- package/dist/hooks/useSignMessage.d.ts +25 -0
- package/dist/hooks/useSignRawHashWithModal.d.ts +22 -0
- package/dist/hooks/useSmartWallets.d.ts +16 -0
- package/dist/hooks/useStellarWallet.d.ts +6 -0
- package/dist/hooks/useSupa.d.ts +61 -0
- package/dist/index.d.ts +149 -0
- package/dist/providers/CantonProvider.d.ts +64 -0
- package/dist/providers/SupaProvider.d.ts +82 -0
- package/dist/services/apiService.d.ts +163 -0
- package/dist/services/cantonService.d.ts +156 -0
- package/dist/utils/converters.d.ts +67 -0
- package/dist/utils/stellar.d.ts +90 -0
- package/package.json +1 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { UserResponseDto, UserBalanceResponseDto, DialogWithMessagesResponseDto, DialogListResponseDto, OffsetPaginatedDto, MessageResponseDto, PaginationParams, NetworkAddressAndPriceDto, TokenInfoWithPriceChangeDto, TokenInfo, TokenPriceHistoryParams, TokenPriceHistoryResponse, AccountTokensBalancesResponse, AlchemyNetwork, SupaPointsBalanceResponseDto, DailyLoginResponseDto, SupaPointsHistoryParams, TransactionQueryParams, PaymasterRequestDto, PaymasterResponseDto } from '../core/types';
|
|
2
|
+
/**
|
|
3
|
+
* Return type for useAPI hook
|
|
4
|
+
* Provides organized access to all backend API methods
|
|
5
|
+
*/
|
|
6
|
+
export interface UseAPIReturn {
|
|
7
|
+
/** User management and profile methods */
|
|
8
|
+
user: {
|
|
9
|
+
/** Fetches current authenticated user profile */
|
|
10
|
+
getCurrent: () => Promise<UserResponseDto>;
|
|
11
|
+
/** Fetches all users (admin only) */
|
|
12
|
+
getAll: () => Promise<UserResponseDto[]>;
|
|
13
|
+
/** Fetches user by Privy ID */
|
|
14
|
+
getByPrivyId: (privyUserId: string) => Promise<UserResponseDto>;
|
|
15
|
+
/** Fetches user's smart wallet token balances */
|
|
16
|
+
getBalance: (force?: boolean) => Promise<UserBalanceResponseDto>;
|
|
17
|
+
};
|
|
18
|
+
/** AI dialog management methods */
|
|
19
|
+
dialogs: {
|
|
20
|
+
/** Creates a new AI dialog with initial message */
|
|
21
|
+
create: (text: string) => Promise<DialogWithMessagesResponseDto>;
|
|
22
|
+
/** Fetches all user dialogs with pagination */
|
|
23
|
+
findAll: (params?: PaginationParams) => Promise<OffsetPaginatedDto<DialogListResponseDto>>;
|
|
24
|
+
/** Fetches a specific dialog by ID */
|
|
25
|
+
findOne: (id: number) => Promise<DialogListResponseDto>;
|
|
26
|
+
/** Deletes a dialog and all its messages */
|
|
27
|
+
delete: (id: number) => Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
/** AI message methods within dialogs */
|
|
30
|
+
messages: {
|
|
31
|
+
/** Creates a new message in a dialog */
|
|
32
|
+
create: (dialogId: number, text: string) => Promise<MessageResponseDto>;
|
|
33
|
+
/** Fetches all messages in a dialog with pagination */
|
|
34
|
+
findAll: (dialogId: number, params?: PaginationParams) => Promise<OffsetPaginatedDto<MessageResponseDto>>;
|
|
35
|
+
/** Fetches a specific message by ID */
|
|
36
|
+
findOne: (id: number) => Promise<MessageResponseDto>;
|
|
37
|
+
};
|
|
38
|
+
/** On-chain data and token price methods */
|
|
39
|
+
onchain: {
|
|
40
|
+
/** Fetches token prices by contract addresses */
|
|
41
|
+
getPricesByAddresses: (addresses: Array<{
|
|
42
|
+
network: AlchemyNetwork;
|
|
43
|
+
contractAddress: string;
|
|
44
|
+
}>) => Promise<NetworkAddressAndPriceDto[]>;
|
|
45
|
+
/** Fetches token prices by symbols (BTC, ETH, etc.) */
|
|
46
|
+
getTokenPrices: (symbols: string[]) => Promise<Record<string, number>>;
|
|
47
|
+
/** Fetches historical price data for a token */
|
|
48
|
+
getPriceHistory: (params: TokenPriceHistoryParams) => Promise<TokenPriceHistoryResponse>;
|
|
49
|
+
/** Fetches 24-hour price changes for tokens */
|
|
50
|
+
get24hrPriceChanges: (tokens: Array<{
|
|
51
|
+
network: AlchemyNetwork;
|
|
52
|
+
contractAddress: string;
|
|
53
|
+
}>) => Promise<TokenInfoWithPriceChangeDto[]>;
|
|
54
|
+
/** Fetches detailed token information */
|
|
55
|
+
getTokenInfo: (network: string, addresses: string | string[]) => Promise<Record<string, TokenInfo>>;
|
|
56
|
+
/** Fetches token balances for an account */
|
|
57
|
+
getAccountBalances: (network: string, account: string, force?: boolean) => Promise<AccountTokensBalancesResponse>;
|
|
58
|
+
};
|
|
59
|
+
/** Transaction history methods */
|
|
60
|
+
transactions: {
|
|
61
|
+
/** Fetches user transaction history */
|
|
62
|
+
get: (params?: TransactionQueryParams) => Promise<any>;
|
|
63
|
+
/** Forces reload of transaction history from blockchain */
|
|
64
|
+
forceLoad: (params?: TransactionQueryParams) => Promise<any>;
|
|
65
|
+
};
|
|
66
|
+
/** SupaPoints reward system methods */
|
|
67
|
+
supaPoints: {
|
|
68
|
+
/** Fetches current SupaPoints balance */
|
|
69
|
+
getBalance: () => Promise<SupaPointsBalanceResponseDto>;
|
|
70
|
+
/** Fetches SupaPoints transaction history */
|
|
71
|
+
getHistory: (params?: SupaPointsHistoryParams) => Promise<OffsetPaginatedDto<any>>;
|
|
72
|
+
/** Processes daily login bonus */
|
|
73
|
+
dailyLogin: () => Promise<DailyLoginResponseDto>;
|
|
74
|
+
};
|
|
75
|
+
/** Paymaster sponsorship methods */
|
|
76
|
+
paymaster: {
|
|
77
|
+
/** Checks if transaction qualifies for gas sponsorship */
|
|
78
|
+
checkSponsorship: (request: PaymasterRequestDto) => Promise<PaymasterResponseDto>;
|
|
79
|
+
};
|
|
80
|
+
/** Privy wallet methods */
|
|
81
|
+
privy: {
|
|
82
|
+
/** Fetches Privy embedded wallet balance */
|
|
83
|
+
getBalance: () => Promise<any>;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Hook for accessing Supa Backend API
|
|
88
|
+
* Provides organized, type-safe access to all backend endpoints
|
|
89
|
+
* All methods automatically include authentication token from Privy
|
|
90
|
+
*
|
|
91
|
+
* @returns Organized API methods grouped by functionality
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* Basic usage
|
|
95
|
+
* ```tsx
|
|
96
|
+
* function UserBalance() {
|
|
97
|
+
* const api = useAPI();
|
|
98
|
+
* const [balance, setBalance] = useState(null);
|
|
99
|
+
*
|
|
100
|
+
* useEffect(() => {
|
|
101
|
+
* api.user.getBalance().then(setBalance);
|
|
102
|
+
* }, []);
|
|
103
|
+
*
|
|
104
|
+
* return <div>Balance: ${balance?.totalUsdBalance}</div>;
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* Creating an AI dialog
|
|
110
|
+
* ```tsx
|
|
111
|
+
* function CreateDialog() {
|
|
112
|
+
* const api = useAPI();
|
|
113
|
+
*
|
|
114
|
+
* const handleCreate = async () => {
|
|
115
|
+
* const dialog = await api.dialogs.create('Hello AI!');
|
|
116
|
+
* console.log('Dialog created:', dialog.id);
|
|
117
|
+
* console.log('AI response:', dialog.messages[1].message);
|
|
118
|
+
* };
|
|
119
|
+
*
|
|
120
|
+
* return <button onClick={handleCreate}>Start Chat</button>;
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* Fetching crypto prices
|
|
126
|
+
* ```tsx
|
|
127
|
+
* function TokenPrices() {
|
|
128
|
+
* const api = useAPI();
|
|
129
|
+
*
|
|
130
|
+
* useEffect(() => {
|
|
131
|
+
* api.onchain.getTokenPrices(['BTC', 'ETH', 'SOL'])
|
|
132
|
+
* .then(prices => {
|
|
133
|
+
* console.log('BTC:', prices.BTC);
|
|
134
|
+
* console.log('ETH:', prices.ETH);
|
|
135
|
+
* });
|
|
136
|
+
* }, []);
|
|
137
|
+
*
|
|
138
|
+
* return <div>Check console for prices</div>;
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export declare const useAPI: () => UseAPIReturn;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { User as PrivyUser } from '@privy-io/react-auth';
|
|
2
|
+
/**
|
|
3
|
+
* Return type for useAuth hook
|
|
4
|
+
*/
|
|
5
|
+
export interface UseAuthReturn {
|
|
6
|
+
/** Opens Privy login modal */
|
|
7
|
+
login: () => void;
|
|
8
|
+
/** Logs out the current user */
|
|
9
|
+
logout: () => Promise<void>;
|
|
10
|
+
/** Whether user is authenticated */
|
|
11
|
+
authenticated: boolean;
|
|
12
|
+
/** Whether authentication is in progress */
|
|
13
|
+
loading: boolean;
|
|
14
|
+
/** Privy user object containing linked accounts and profile data */
|
|
15
|
+
user: PrivyUser | null;
|
|
16
|
+
/** Gets Privy JWT access token for authenticated API calls */
|
|
17
|
+
getAccessToken: () => Promise<string | null>;
|
|
18
|
+
/** Whether SDK is ready (not loading) */
|
|
19
|
+
ready: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Hook for managing user authentication via Privy
|
|
23
|
+
* Automatically configures API client with access token when user authenticates
|
|
24
|
+
*
|
|
25
|
+
* @returns Authentication methods and user state
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* function LoginButton() {
|
|
30
|
+
* const { login, logout, authenticated, user } = useAuth();
|
|
31
|
+
*
|
|
32
|
+
* if (!authenticated) {
|
|
33
|
+
* return <button onClick={login}>Login</button>;
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* return (
|
|
37
|
+
* <div>
|
|
38
|
+
* <p>Welcome, {user?.email?.address}!</p>
|
|
39
|
+
* <button onClick={logout}>Logout</button>
|
|
40
|
+
* </div>
|
|
41
|
+
* );
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const useAuth: () => UseAuthReturn;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CantonContextValue } from '../providers/CantonProvider';
|
|
2
|
+
export type { CantonContextValue as UseCantonReturn };
|
|
3
|
+
/**
|
|
4
|
+
* Hook for Canton Network operations
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* function MyComponent() {
|
|
9
|
+
* const { isRegistered, registerCanton, sendCantonCoin } = useCanton();
|
|
10
|
+
*
|
|
11
|
+
* if (!isRegistered) {
|
|
12
|
+
* return <button onClick={registerCanton}>Register</button>;
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* return <button onClick={() => sendCantonCoin(partyId, "10")}>Send</button>;
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function useCanton(): CantonContextValue;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConfirmModalOptions, SignMessageModalOptions, SignTransactionOptions, ModalResult } from '../providers/SupaProvider';
|
|
2
|
+
export interface UseConfirmModalReturn {
|
|
3
|
+
/** Show a generic confirmation modal */
|
|
4
|
+
confirm: (options: ConfirmModalOptions) => Promise<ModalResult>;
|
|
5
|
+
/** Show a message signing confirmation modal */
|
|
6
|
+
signMessageConfirm: (options: SignMessageModalOptions) => Promise<ModalResult>;
|
|
7
|
+
/** Show a transaction signing confirmation modal */
|
|
8
|
+
signTransactionConfirm: (options: SignTransactionOptions) => Promise<ModalResult>;
|
|
9
|
+
/** Set loading state for current modal */
|
|
10
|
+
setModalLoading: (loading: boolean) => void;
|
|
11
|
+
/** Close current modal */
|
|
12
|
+
closeModal: () => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function useConfirmModal(): UseConfirmModalReturn;
|
|
15
|
+
export type { ConfirmModalOptions, SignMessageModalOptions, SignTransactionOptions, ModalResult };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { StellarWallet } from '../utils/stellar';
|
|
2
|
+
import { CantonQueryCompletionResponseDto, CantonSubmitPreparedOptions } from '../services/cantonService';
|
|
3
|
+
export interface SendTransactionOptions {
|
|
4
|
+
onSuccess?: (result: CantonQueryCompletionResponseDto) => void;
|
|
5
|
+
onRejection?: () => void;
|
|
6
|
+
onError?: (error: Error) => void;
|
|
7
|
+
skipModal?: boolean;
|
|
8
|
+
modalTitle?: string;
|
|
9
|
+
modalDescription?: string;
|
|
10
|
+
modalConfirmText?: string;
|
|
11
|
+
modalRejectText?: string;
|
|
12
|
+
/** Custom content to display in modal instead of transaction hash */
|
|
13
|
+
modalDisplayContent?: string;
|
|
14
|
+
/** Show technical transaction details (command, contracts, hash) as JSON. Default: false */
|
|
15
|
+
showTechnicalDetails?: boolean;
|
|
16
|
+
submitOptions?: CantonSubmitPreparedOptions;
|
|
17
|
+
}
|
|
18
|
+
export interface UseSendTransactionReturn {
|
|
19
|
+
/** Sign and send a Canton transaction with confirmation modal */
|
|
20
|
+
sendTransaction: (commands: unknown, disclosedContracts?: unknown, options?: SendTransactionOptions) => Promise<CantonQueryCompletionResponseDto | null>;
|
|
21
|
+
loading: boolean;
|
|
22
|
+
error: Error | null;
|
|
23
|
+
clearError: () => void;
|
|
24
|
+
stellarWallets: StellarWallet[];
|
|
25
|
+
stellarWallet: StellarWallet | null;
|
|
26
|
+
}
|
|
27
|
+
export declare function useSendTransaction(): UseSendTransactionReturn;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { StellarWallet } from '../utils/stellar';
|
|
2
|
+
export interface SignMessageOptions {
|
|
3
|
+
onSuccess?: (signature: string) => void;
|
|
4
|
+
onRejection?: () => void;
|
|
5
|
+
onError?: (error: Error) => void;
|
|
6
|
+
skipModal?: boolean;
|
|
7
|
+
title?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
confirmText?: string;
|
|
10
|
+
rejectText?: string;
|
|
11
|
+
/** Custom content to display in modal instead of message */
|
|
12
|
+
displayContent?: string;
|
|
13
|
+
/** Show technical details (address, chainType, hash) as JSON. Default: false */
|
|
14
|
+
showTechnicalDetails?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface UseSignMessageReturn {
|
|
17
|
+
/** Sign a text message with confirmation modal */
|
|
18
|
+
signMessage: (message: string, options?: SignMessageOptions) => Promise<string | null>;
|
|
19
|
+
loading: boolean;
|
|
20
|
+
error: Error | null;
|
|
21
|
+
clearError: () => void;
|
|
22
|
+
stellarWallets: StellarWallet[];
|
|
23
|
+
stellarWallet: StellarWallet | null;
|
|
24
|
+
}
|
|
25
|
+
export declare function useSignMessage(): UseSignMessageReturn;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useSignRawHash } from '@privy-io/react-auth/extended-chains';
|
|
2
|
+
export interface SignRawHashModalOptions {
|
|
3
|
+
skipModal?: boolean;
|
|
4
|
+
title?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
confirmText?: string;
|
|
7
|
+
rejectText?: string;
|
|
8
|
+
infoText?: string;
|
|
9
|
+
/** Custom content to display instead of auto-generated JSON */
|
|
10
|
+
displayHash?: string;
|
|
11
|
+
/** Show technical details (address, chainType, hash) as JSON. Default: false */
|
|
12
|
+
showTechnicalDetails?: boolean;
|
|
13
|
+
}
|
|
14
|
+
type SignRawHashParams = Parameters<ReturnType<typeof useSignRawHash>['signRawHash']>[0];
|
|
15
|
+
export interface UseSignRawHashWithModalReturn {
|
|
16
|
+
/** Sign a raw hash with confirmation modal */
|
|
17
|
+
signRawHashWithModal: (params: SignRawHashParams, modalOptions?: SignRawHashModalOptions) => Promise<{
|
|
18
|
+
signature: string;
|
|
19
|
+
} | null>;
|
|
20
|
+
}
|
|
21
|
+
export declare function useSignRawHashWithModal(): UseSignRawHashWithModalReturn;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useSmartWallets as usePrivySmartWallets } from '@privy-io/react-auth/smart-wallets';
|
|
2
|
+
export interface UseSmartWalletsReturn {
|
|
3
|
+
/** Client for interacting with smart wallets */
|
|
4
|
+
client: ReturnType<typeof usePrivySmartWallets>['client'];
|
|
5
|
+
/** Get client for specific chain */
|
|
6
|
+
getClientForChain: ReturnType<typeof usePrivySmartWallets>['getClientForChain'];
|
|
7
|
+
/** Get user's smart wallet address */
|
|
8
|
+
address: string | undefined;
|
|
9
|
+
/** Whether smart wallets are ready to use */
|
|
10
|
+
ready: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Hook for using Privy Smart Wallets
|
|
14
|
+
* Must be used within SmartWalletsProvider (automatically enabled in SupaProvider when smartWallets.enabled = true)
|
|
15
|
+
*/
|
|
16
|
+
export declare function useSmartWallets(): UseSmartWalletsReturn;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { UseAuthReturn } from './useAuth';
|
|
2
|
+
import { UseCantonReturn } from './useCanton';
|
|
3
|
+
import { UseAPIReturn } from './useAPI';
|
|
4
|
+
/**
|
|
5
|
+
* Return type for useSupa hook
|
|
6
|
+
*/
|
|
7
|
+
export interface UseSupaReturn {
|
|
8
|
+
/** Authentication methods and user state */
|
|
9
|
+
auth: UseAuthReturn;
|
|
10
|
+
/** Canton Network operations and wallet management */
|
|
11
|
+
canton: UseCantonReturn;
|
|
12
|
+
/** Backend API methods for data access */
|
|
13
|
+
api: UseAPIReturn;
|
|
14
|
+
/** Automated onboarding flow (login → create wallet → register Canton) */
|
|
15
|
+
onboard: () => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Main hook for accessing all Supa SDK features
|
|
19
|
+
* Combines authentication, Canton Network, and API functionality
|
|
20
|
+
*
|
|
21
|
+
* Note: Canton state (isRegistered, cantonUser, etc.) is shared across
|
|
22
|
+
* all components via CantonProvider. No duplicate registration will occur.
|
|
23
|
+
*
|
|
24
|
+
* @returns Combined SDK functionality with convenience methods
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* Basic usage
|
|
28
|
+
* ```tsx
|
|
29
|
+
* function Dashboard() {
|
|
30
|
+
* const { auth, canton, api } = useSupa();
|
|
31
|
+
*
|
|
32
|
+
* if (!auth.authenticated) {
|
|
33
|
+
* return <button onClick={auth.login}>Login</button>;
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* return (
|
|
37
|
+
* <div>
|
|
38
|
+
* <p>User: {auth.user?.email?.address}</p>
|
|
39
|
+
* <button onClick={() => canton.registerCanton()}>
|
|
40
|
+
* Register Canton
|
|
41
|
+
* </button>
|
|
42
|
+
* </div>
|
|
43
|
+
* );
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* Using automated onboarding
|
|
49
|
+
* ```tsx
|
|
50
|
+
* function OnboardButton() {
|
|
51
|
+
* const { onboard, canton } = useSupa();
|
|
52
|
+
*
|
|
53
|
+
* return (
|
|
54
|
+
* <button onClick={onboard}>
|
|
55
|
+
* {canton.isRegistered ? 'Already registered' : 'Get Started'}
|
|
56
|
+
* </button>
|
|
57
|
+
* );
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const useSupa: () => UseSupaReturn;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supa SDK
|
|
3
|
+
*
|
|
4
|
+
* React SDK for seamless integration with Supa Backend API and Privy.io authentication,
|
|
5
|
+
* featuring full Canton Network support with Ed25519 signing via Stellar wallets.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* Basic setup
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { SupaProvider, useAuth, useCanton } from '@supa/sdk';
|
|
13
|
+
*
|
|
14
|
+
* function App() {
|
|
15
|
+
* return (
|
|
16
|
+
* <SupaProvider config={{ privyAppId: 'your_app_id' }}>
|
|
17
|
+
* <Dashboard />
|
|
18
|
+
* </SupaProvider>
|
|
19
|
+
* );
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* function Dashboard() {
|
|
23
|
+
* const { login, authenticated } = useAuth();
|
|
24
|
+
* const { registerCanton, isRegistered } = useCanton();
|
|
25
|
+
*
|
|
26
|
+
* if (!authenticated) {
|
|
27
|
+
* return <button onClick={login}>Login</button>;
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* if (!isRegistered) {
|
|
31
|
+
* return <button onClick={registerCanton}>Register Canton</button>;
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* return <div>Ready to use Canton Network!</div>;
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @see {@link https://github.com/your-repo/supa-sdk | GitHub Repository}
|
|
39
|
+
* @see {@link https://docs.privy.io | Privy Documentation}
|
|
40
|
+
* @see {@link https://canton.network | Canton Network}
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* Main provider component that wraps your application
|
|
44
|
+
* Includes built-in confirmation modals for signing operations
|
|
45
|
+
* @see {@link SupaProvider}
|
|
46
|
+
*/
|
|
47
|
+
export { SupaProvider, useSupaContext } from './providers/SupaProvider';
|
|
48
|
+
export type { SupaConfig, SupaContextValue, SupaProviderProps, ConfirmModalOptions, SignMessageModalOptions, SignTransactionOptions as SignTransactionModalOptions, ModalResult, } from './providers/SupaProvider';
|
|
49
|
+
/**
|
|
50
|
+
* Canton Provider for shared state (automatically included in SupaProvider)
|
|
51
|
+
* @see {@link CantonProvider}
|
|
52
|
+
*/
|
|
53
|
+
export { CantonProvider, useCantonContext } from './providers/CantonProvider';
|
|
54
|
+
export type { CantonContextValue, CantonProviderProps, CantonSendCoinOptions } from './providers/CantonProvider';
|
|
55
|
+
/**
|
|
56
|
+
* Primary hook combining all SDK functionality
|
|
57
|
+
* @see {@link useSupa}
|
|
58
|
+
*/
|
|
59
|
+
export { useSupa } from './hooks/useSupa';
|
|
60
|
+
export type { UseSupaReturn } from './hooks/useSupa';
|
|
61
|
+
export { useSupa as useWalletino } from './hooks/useSupa';
|
|
62
|
+
export type { UseSupaReturn as UseWalletinoReturn } from './hooks/useSupa';
|
|
63
|
+
/**
|
|
64
|
+
* Authentication hook for Privy integration
|
|
65
|
+
* @see {@link useAuth}
|
|
66
|
+
*/
|
|
67
|
+
export { useAuth } from './hooks/useAuth';
|
|
68
|
+
export type { UseAuthReturn } from './hooks/useAuth';
|
|
69
|
+
/**
|
|
70
|
+
* Canton Network operations hook
|
|
71
|
+
* @see {@link useCanton}
|
|
72
|
+
*/
|
|
73
|
+
export { useCanton } from './hooks/useCanton';
|
|
74
|
+
export type { UseCantonReturn } from './hooks/useCanton';
|
|
75
|
+
/**
|
|
76
|
+
* Sign message hook with confirmation modal
|
|
77
|
+
* @see {@link useSignMessage}
|
|
78
|
+
*/
|
|
79
|
+
export { useSignMessage } from './hooks/useSignMessage';
|
|
80
|
+
export type { UseSignMessageReturn, SignMessageOptions } from './hooks/useSignMessage';
|
|
81
|
+
/**
|
|
82
|
+
* Send transaction hook with confirmation modal
|
|
83
|
+
* @see {@link useSendTransaction}
|
|
84
|
+
*/
|
|
85
|
+
export { useSendTransaction } from './hooks/useSendTransaction';
|
|
86
|
+
export type { UseSendTransactionReturn, SendTransactionOptions } from './hooks/useSendTransaction';
|
|
87
|
+
/**
|
|
88
|
+
* Sign raw hash with automatic confirmation modal
|
|
89
|
+
* @see {@link useSignRawHashWithModal}
|
|
90
|
+
*/
|
|
91
|
+
export { useSignRawHashWithModal } from './hooks/useSignRawHashWithModal';
|
|
92
|
+
export type { UseSignRawHashWithModalReturn, SignRawHashModalOptions } from './hooks/useSignRawHashWithModal';
|
|
93
|
+
/**
|
|
94
|
+
* Confirmation modal hook
|
|
95
|
+
* @see {@link useConfirmModal}
|
|
96
|
+
*/
|
|
97
|
+
export { useConfirmModal } from './hooks/useConfirmModal';
|
|
98
|
+
export type { UseConfirmModalReturn } from './hooks/useConfirmModal';
|
|
99
|
+
/**
|
|
100
|
+
* Stellar wallet hook
|
|
101
|
+
* @see {@link useStellarWallet}
|
|
102
|
+
*/
|
|
103
|
+
export { useStellarWallet } from './hooks/useStellarWallet';
|
|
104
|
+
export type { UseStellarWalletReturn } from './hooks/useStellarWallet';
|
|
105
|
+
/**
|
|
106
|
+
* Smart Wallets hook (EVM)
|
|
107
|
+
* @see {@link useSmartWallets}
|
|
108
|
+
*/
|
|
109
|
+
export { useSmartWallets } from './hooks/useSmartWallets';
|
|
110
|
+
export type { UseSmartWalletsReturn } from './hooks/useSmartWallets';
|
|
111
|
+
/**
|
|
112
|
+
* Confirmation modal components (for custom usage)
|
|
113
|
+
* @see {@link ConfirmationModal}, {@link SignMessageModal}, {@link SignTransactionModal}
|
|
114
|
+
*/
|
|
115
|
+
export { ConfirmationModal, SignMessageModal, SignTransactionModal } from './components/ConfirmationModal';
|
|
116
|
+
export type { ConfirmationModalProps, SignMessageModalProps, SignTransactionModalProps } from './components/ConfirmationModal';
|
|
117
|
+
/**
|
|
118
|
+
* All DTO types generated from Swagger specification
|
|
119
|
+
* Includes types for User, Dialog, Message, Canton, Token, etc.
|
|
120
|
+
*/
|
|
121
|
+
export * from './core/types';
|
|
122
|
+
/**
|
|
123
|
+
* Format conversion utilities (hex ↔ base64)
|
|
124
|
+
* Required for Canton Network integration
|
|
125
|
+
* @see {@link hexToBase64}, {@link base64ToHex}, {@link privyPublicKeyToCantonBase64}
|
|
126
|
+
*/
|
|
127
|
+
export * from './utils/converters';
|
|
128
|
+
/**
|
|
129
|
+
* Stellar wallet utilities for Canton Network
|
|
130
|
+
* @see {@link getStellarWallets}, {@link getPublicKeyBase64}, {@link isStellarWallet}
|
|
131
|
+
*/
|
|
132
|
+
export * from './utils/stellar';
|
|
133
|
+
/**
|
|
134
|
+
* Canton Network service for direct API access (advanced usage)
|
|
135
|
+
* @see {@link CantonService}
|
|
136
|
+
*/
|
|
137
|
+
export { CantonService, getCantonService } from './services/cantonService';
|
|
138
|
+
export type { CantonRegisterParams, CantonTapParams, CantonSubmitPreparedOptions } from './services/cantonService';
|
|
139
|
+
/**
|
|
140
|
+
* Backend API service for direct access (advanced usage)
|
|
141
|
+
* @see {@link ApiService}
|
|
142
|
+
*/
|
|
143
|
+
export { ApiService, getApiService } from './services/apiService';
|
|
144
|
+
/**
|
|
145
|
+
* HTTP client for custom API calls (advanced usage)
|
|
146
|
+
* @see {@link ApiClient}, {@link createApiClient}
|
|
147
|
+
*/
|
|
148
|
+
export { ApiClient, createApiClient, getApiClient } from './core/client';
|
|
149
|
+
export type { ClientConfig } from './core/client';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { StellarWallet } from '../utils/stellar';
|
|
3
|
+
import { CantonService, CantonSubmitPreparedOptions } from '../services/cantonService';
|
|
4
|
+
import { CantonMeResponseDto, CantonActiveContractsResponseDto, CantonQueryCompletionResponseDto, CantonWalletBalancesResponseDto, CantonIncomingTransferDto, CantonTransactionDto, CantonTransactionsParams, CantonPriceInterval, CantonPriceCandleDto } from '../core/types';
|
|
5
|
+
export interface CantonSendCoinOptions extends CantonSubmitPreparedOptions {
|
|
6
|
+
/** Skip confirmation modal. Default: false */
|
|
7
|
+
skipModal?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface CantonContextValue {
|
|
10
|
+
/** First Stellar wallet (primary) */
|
|
11
|
+
stellarWallet: StellarWallet | null;
|
|
12
|
+
/** All Stellar wallets */
|
|
13
|
+
stellarWallets: StellarWallet[];
|
|
14
|
+
/** Create new Stellar wallet */
|
|
15
|
+
createStellarWallet: () => Promise<StellarWallet | null>;
|
|
16
|
+
/** Register Canton wallet on backend */
|
|
17
|
+
registerCanton: (inviteCode?: string) => Promise<void>;
|
|
18
|
+
/** Whether Canton wallet is registered */
|
|
19
|
+
isRegistered: boolean;
|
|
20
|
+
/** Canton user info (partyId, email, transferPreapprovalSet) */
|
|
21
|
+
cantonUser: CantonMeResponseDto | null;
|
|
22
|
+
/** Get Canton user info */
|
|
23
|
+
getMe: () => Promise<CantonMeResponseDto>;
|
|
24
|
+
/** Get active contracts with optional filtering */
|
|
25
|
+
getActiveContracts: (templateIds?: string[]) => Promise<CantonActiveContractsResponseDto>;
|
|
26
|
+
/** Canton wallet balances */
|
|
27
|
+
cantonBalances: CantonWalletBalancesResponseDto | null;
|
|
28
|
+
/** Get Canton wallet balances */
|
|
29
|
+
getBalances: () => Promise<CantonWalletBalancesResponseDto>;
|
|
30
|
+
/** Tap devnet faucet */
|
|
31
|
+
tapDevnet: (amount: string, options?: CantonSubmitPreparedOptions) => Promise<CantonQueryCompletionResponseDto>;
|
|
32
|
+
/** Sign hash with Stellar wallet */
|
|
33
|
+
signHash: (hashBase64: string) => Promise<string>;
|
|
34
|
+
/** Sign text message */
|
|
35
|
+
signMessage: (message: string) => Promise<string>;
|
|
36
|
+
/** Prepare and submit transaction with polling for completion */
|
|
37
|
+
sendTransaction: (commands: unknown, disclosedContracts?: unknown, options?: CantonSubmitPreparedOptions) => Promise<CantonQueryCompletionResponseDto>;
|
|
38
|
+
/** Send Canton Coin (Amulet) to another party */
|
|
39
|
+
sendCantonCoin: (receiverPartyId: string, amount: string, memo?: string, options?: CantonSendCoinOptions) => Promise<CantonQueryCompletionResponseDto>;
|
|
40
|
+
/** Setup transfer preapproval (internal, called automatically) */
|
|
41
|
+
setupTransferPreapproval: () => Promise<void>;
|
|
42
|
+
/** Get pending incoming transfers */
|
|
43
|
+
getPendingIncomingTransfers: () => Promise<CantonIncomingTransferDto[]>;
|
|
44
|
+
/** Respond to incoming transfer (accept or reject) */
|
|
45
|
+
respondToIncomingTransfer: (contractId: string, accept: boolean, options?: CantonSubmitPreparedOptions) => Promise<CantonQueryCompletionResponseDto>;
|
|
46
|
+
/** Get Canton transactions history with pagination */
|
|
47
|
+
getTransactions: (params?: CantonTransactionsParams) => Promise<CantonTransactionDto[]>;
|
|
48
|
+
/** Get Canton price history (candles from Bybit) */
|
|
49
|
+
getPriceHistory: (interval: CantonPriceInterval) => Promise<CantonPriceCandleDto[]>;
|
|
50
|
+
/** Loading state */
|
|
51
|
+
loading: boolean;
|
|
52
|
+
/** Error state */
|
|
53
|
+
error: Error | null;
|
|
54
|
+
/** Clear error */
|
|
55
|
+
clearError: () => void;
|
|
56
|
+
}
|
|
57
|
+
export interface CantonProviderProps {
|
|
58
|
+
cantonService: CantonService;
|
|
59
|
+
children: ReactNode;
|
|
60
|
+
/** Enable automatic onboarding (create wallet + register Canton on login). Default: true */
|
|
61
|
+
autoOnboarding?: boolean;
|
|
62
|
+
}
|
|
63
|
+
export declare function CantonProvider({ cantonService, children, autoOnboarding }: CantonProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
64
|
+
export declare function useCantonContext(): CantonContextValue;
|