@supanovaapp/sdk 0.2.11 → 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.cjs.js +155 -155
- package/dist/index.d.ts +149 -0
- package/dist/index.esm.js +5163 -5162
- 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;
|