@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,82 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ApiClient } from '../core/client';
|
|
3
|
+
import { CantonService } from '../services/cantonService';
|
|
4
|
+
import { ApiService } from '../services/apiService';
|
|
5
|
+
export interface SupaConfig {
|
|
6
|
+
privyAppId: string;
|
|
7
|
+
privyClientId?: string;
|
|
8
|
+
apiBaseUrl?: string;
|
|
9
|
+
nodeIdentifier: string;
|
|
10
|
+
appearance?: {
|
|
11
|
+
theme?: 'light' | 'dark';
|
|
12
|
+
accentColor?: string;
|
|
13
|
+
logo?: string;
|
|
14
|
+
};
|
|
15
|
+
loginMethods?: Array<'email' | 'wallet' | 'google' | 'twitter' | 'discord' | 'github' | 'linkedin' | 'telegram'>;
|
|
16
|
+
smartWallets?: {
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
paymasterContext?: {
|
|
19
|
+
mode?: string;
|
|
20
|
+
calculateGasLimits?: boolean;
|
|
21
|
+
expiryDuration?: number;
|
|
22
|
+
sponsorshipInfo?: {
|
|
23
|
+
webhookData?: Record<string, any>;
|
|
24
|
+
smartAccountInfo?: {
|
|
25
|
+
name?: string;
|
|
26
|
+
version?: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/** Default chain for smart wallets and transactions */
|
|
32
|
+
defaultChain?: any;
|
|
33
|
+
/** Supported chains for the app */
|
|
34
|
+
supportedChains?: any[];
|
|
35
|
+
/** Enable automatic onboarding (create wallet + register Canton on login). Default: true */
|
|
36
|
+
autoOnboarding?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface ConfirmModalOptions {
|
|
39
|
+
title?: string;
|
|
40
|
+
message: string;
|
|
41
|
+
confirmText?: string;
|
|
42
|
+
rejectText?: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
icon?: ReactNode;
|
|
45
|
+
}
|
|
46
|
+
export interface SignTransactionOptions {
|
|
47
|
+
transaction: string;
|
|
48
|
+
title?: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
confirmText?: string;
|
|
51
|
+
rejectText?: string;
|
|
52
|
+
infoText?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface ModalResult<T = void> {
|
|
55
|
+
confirmed: boolean;
|
|
56
|
+
data?: T;
|
|
57
|
+
}
|
|
58
|
+
export interface SignMessageModalOptions {
|
|
59
|
+
message: string;
|
|
60
|
+
title?: string;
|
|
61
|
+
description?: string;
|
|
62
|
+
confirmText?: string;
|
|
63
|
+
rejectText?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface SupaContextValue {
|
|
66
|
+
apiClient: ApiClient;
|
|
67
|
+
cantonService: CantonService;
|
|
68
|
+
apiService: ApiService;
|
|
69
|
+
config: SupaConfig;
|
|
70
|
+
theme: 'light' | 'dark';
|
|
71
|
+
confirm: (options: ConfirmModalOptions) => Promise<ModalResult>;
|
|
72
|
+
signMessageConfirm: (options: SignMessageModalOptions) => Promise<ModalResult>;
|
|
73
|
+
signTransactionConfirm: (options: SignTransactionOptions) => Promise<ModalResult>;
|
|
74
|
+
setModalLoading: (loading: boolean) => void;
|
|
75
|
+
closeModal: () => void;
|
|
76
|
+
}
|
|
77
|
+
export interface SupaProviderProps {
|
|
78
|
+
config: SupaConfig;
|
|
79
|
+
children: ReactNode;
|
|
80
|
+
}
|
|
81
|
+
export declare function SupaProvider({ config, children }: SupaProviderProps): import("react/jsx-runtime").JSX.Element | null;
|
|
82
|
+
export declare function useSupaContext(): SupaContextValue;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { ApiClient } from '../core/client';
|
|
2
|
+
import { UserResponseDto, UserBalanceResponseDto, DialogWithMessagesResponseDto, DialogListResponseDto, OffsetPaginatedDto, MessageResponseDto, PaginationParams, NetworkAddressAndPriceDto, TokenInfoWithPriceChangeDto, TokenInfo, TokenPriceHistoryParams, TokenPriceHistoryResponse, AccountTokensBalancesResponse, AlchemyNetwork, SupaPointsBalanceResponseDto, DailyLoginResponseDto, SupaPointsHistoryParams, TransactionQueryParams, PaymasterRequestDto, PaymasterResponseDto } from '../core/types';
|
|
3
|
+
export declare class ApiService {
|
|
4
|
+
private client;
|
|
5
|
+
private userMeCache;
|
|
6
|
+
private userMeCacheTimestamp;
|
|
7
|
+
private userMePendingPromise;
|
|
8
|
+
private supaPointsBalanceCache;
|
|
9
|
+
private supaPointsBalanceCacheTimestamp;
|
|
10
|
+
private supaPointsBalancePendingPromise;
|
|
11
|
+
private privyBalanceCache;
|
|
12
|
+
private privyBalanceCacheTimestamp;
|
|
13
|
+
private privyBalancePendingPromise;
|
|
14
|
+
private readonly USER_CACHE_TTL;
|
|
15
|
+
constructor(client: ApiClient);
|
|
16
|
+
/**
|
|
17
|
+
* Инвалидация кеша /user/me
|
|
18
|
+
* Вызывается после операций, изменяющих данные пользователя
|
|
19
|
+
*/
|
|
20
|
+
private invalidateUserCache;
|
|
21
|
+
/**
|
|
22
|
+
* Инвалидация кеша /supa_points/balance
|
|
23
|
+
*/
|
|
24
|
+
private invalidateSupaPointsCache;
|
|
25
|
+
/**
|
|
26
|
+
* Инвалидация кеша /privy/balance
|
|
27
|
+
*/
|
|
28
|
+
private invalidatePrivyBalanceCache;
|
|
29
|
+
/**
|
|
30
|
+
* Get current user information
|
|
31
|
+
* GET /user/me
|
|
32
|
+
* С мемоизацией на 5 минут и дедупликацией одновременных запросов
|
|
33
|
+
*/
|
|
34
|
+
getCurrentUser(force?: boolean): Promise<UserResponseDto>;
|
|
35
|
+
/**
|
|
36
|
+
* Get all users
|
|
37
|
+
* GET /user/all
|
|
38
|
+
*/
|
|
39
|
+
getAllUsers(): Promise<UserResponseDto[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Get user by Privy user ID
|
|
42
|
+
* GET /user/{privyUserId}
|
|
43
|
+
*/
|
|
44
|
+
getUserByPrivyId(privyUserId: string): Promise<UserResponseDto>;
|
|
45
|
+
/**
|
|
46
|
+
* Get current user's smart wallet token balances
|
|
47
|
+
* GET /user/smart_wallet_balances
|
|
48
|
+
*/
|
|
49
|
+
getSmartWalletBalances(force?: boolean): Promise<UserBalanceResponseDto>;
|
|
50
|
+
/**
|
|
51
|
+
* Create new dialog
|
|
52
|
+
* POST /dialogs
|
|
53
|
+
*/
|
|
54
|
+
createDialog(text: string): Promise<DialogWithMessagesResponseDto>;
|
|
55
|
+
/**
|
|
56
|
+
* Get all user dialogs
|
|
57
|
+
* GET /dialogs
|
|
58
|
+
*/
|
|
59
|
+
getAllDialogs(params?: PaginationParams): Promise<OffsetPaginatedDto<DialogListResponseDto>>;
|
|
60
|
+
/**
|
|
61
|
+
* Get specific dialog
|
|
62
|
+
* GET /dialogs/{id}
|
|
63
|
+
*/
|
|
64
|
+
getDialog(id: number): Promise<DialogListResponseDto>;
|
|
65
|
+
/**
|
|
66
|
+
* Delete dialog
|
|
67
|
+
* DELETE /dialogs/{id}
|
|
68
|
+
*/
|
|
69
|
+
deleteDialog(id: number): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Create new message in dialog
|
|
72
|
+
* POST /dialogs/{dialogId}/messages
|
|
73
|
+
*/
|
|
74
|
+
createMessage(dialogId: number, text: string): Promise<MessageResponseDto>;
|
|
75
|
+
/**
|
|
76
|
+
* Get all messages in dialog
|
|
77
|
+
* GET /dialogs/{dialogId}/messages
|
|
78
|
+
*/
|
|
79
|
+
getDialogMessages(dialogId: number, params?: PaginationParams): Promise<OffsetPaginatedDto<MessageResponseDto>>;
|
|
80
|
+
/**
|
|
81
|
+
* Get specific message
|
|
82
|
+
* GET /messages/{id}
|
|
83
|
+
*/
|
|
84
|
+
getMessage(id: number): Promise<MessageResponseDto>;
|
|
85
|
+
/**
|
|
86
|
+
* Get token prices by contract addresses
|
|
87
|
+
* POST /onchain/tokens_prices_by_addresses
|
|
88
|
+
*/
|
|
89
|
+
getTokenPricesByAddresses(addresses: Array<{
|
|
90
|
+
network: AlchemyNetwork;
|
|
91
|
+
contractAddress: string;
|
|
92
|
+
}>): Promise<NetworkAddressAndPriceDto[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Get token prices by symbols
|
|
95
|
+
* GET /onchain/tokens_prices
|
|
96
|
+
* @param symbols Array of token symbols (e.g., ['BTC', 'ETH', 'USDT'])
|
|
97
|
+
*/
|
|
98
|
+
getTokenPrices(symbols: string[]): Promise<Record<string, number>>;
|
|
99
|
+
/**
|
|
100
|
+
* Get token price history
|
|
101
|
+
* GET /onchain/token_price_history
|
|
102
|
+
*/
|
|
103
|
+
getTokenPriceHistory(params: TokenPriceHistoryParams): Promise<TokenPriceHistoryResponse>;
|
|
104
|
+
/**
|
|
105
|
+
* Get 24hr price changes for tokens
|
|
106
|
+
* POST /onchain/tokens_24hr_changes
|
|
107
|
+
*/
|
|
108
|
+
getTokens24hrPriceChanges(tokens: Array<{
|
|
109
|
+
network: AlchemyNetwork;
|
|
110
|
+
contractAddress: string;
|
|
111
|
+
}>): Promise<TokenInfoWithPriceChangeDto[]>;
|
|
112
|
+
/**
|
|
113
|
+
* Get token info by address(es)
|
|
114
|
+
* GET /onchain/token_info/{network}
|
|
115
|
+
* @param network Blockchain network
|
|
116
|
+
* @param addresses Single address or array of addresses
|
|
117
|
+
*/
|
|
118
|
+
getTokenInfo(network: string, addresses: string | string[]): Promise<Record<string, TokenInfo>>;
|
|
119
|
+
/**
|
|
120
|
+
* Get account token balances
|
|
121
|
+
* GET /onchain/account_tokens_balances/{network}
|
|
122
|
+
*/
|
|
123
|
+
getAccountTokenBalances(network: string, account: string, force?: boolean): Promise<AccountTokensBalancesResponse>;
|
|
124
|
+
/**
|
|
125
|
+
* Get user transactions
|
|
126
|
+
* GET /transactions
|
|
127
|
+
*/
|
|
128
|
+
getTransactions(params?: TransactionQueryParams): Promise<any>;
|
|
129
|
+
/**
|
|
130
|
+
* Force load user transactions
|
|
131
|
+
* POST /transactions/transactions_force
|
|
132
|
+
*/
|
|
133
|
+
forceLoadTransactions(params?: TransactionQueryParams): Promise<any>;
|
|
134
|
+
/**
|
|
135
|
+
* Get SupaPoints balance
|
|
136
|
+
* GET /supa_points/balance
|
|
137
|
+
* С мемоизацией на 5 минут и дедупликацией одновременных запросов
|
|
138
|
+
*/
|
|
139
|
+
getSupaPointsBalance(force?: boolean): Promise<SupaPointsBalanceResponseDto>;
|
|
140
|
+
/**
|
|
141
|
+
* Get SupaPoints history
|
|
142
|
+
* GET /supa_points/history
|
|
143
|
+
*/
|
|
144
|
+
getSupaPointsHistory(params?: SupaPointsHistoryParams): Promise<OffsetPaginatedDto<any>>;
|
|
145
|
+
/**
|
|
146
|
+
* Process daily login
|
|
147
|
+
* POST /supa_points/daily_login
|
|
148
|
+
*/
|
|
149
|
+
dailyLogin(): Promise<DailyLoginResponseDto>;
|
|
150
|
+
/**
|
|
151
|
+
* Check if paymaster can sponsor user operation
|
|
152
|
+
* POST /paymaster
|
|
153
|
+
*/
|
|
154
|
+
checkPaymasterSponsorship(request: PaymasterRequestDto): Promise<PaymasterResponseDto>;
|
|
155
|
+
/**
|
|
156
|
+
* Get Privy balance
|
|
157
|
+
* GET /privy/balance
|
|
158
|
+
* С мемоизацией на 5 минут и дедупликацией одновременных запросов
|
|
159
|
+
*/
|
|
160
|
+
getPrivyBalance(force?: boolean): Promise<any>;
|
|
161
|
+
}
|
|
162
|
+
export declare function createApiService(client: ApiClient): ApiService;
|
|
163
|
+
export declare function getApiService(): ApiService;
|
|
@@ -0,0 +1,156 @@
|
|
|
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, };
|
|
4
|
+
export interface CantonRegisterParams {
|
|
5
|
+
/** Base64 public key from Stellar wallet */
|
|
6
|
+
publicKey: string;
|
|
7
|
+
/** Function to sign hash (returns signature in hex) */
|
|
8
|
+
signFunction: (hashHex: string) => Promise<string>;
|
|
9
|
+
/** Optional invite code */
|
|
10
|
+
inviteCode?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CantonTapParams {
|
|
13
|
+
/** Amount of Canton coins to receive */
|
|
14
|
+
amount: string;
|
|
15
|
+
/** Function to sign hash (returns signature in hex) */
|
|
16
|
+
signFunction: (hashHex: string) => Promise<string>;
|
|
17
|
+
}
|
|
18
|
+
export interface CantonSubmitPreparedOptions {
|
|
19
|
+
/** Timeout in milliseconds to wait for completion (default: 30000) */
|
|
20
|
+
timeout?: number;
|
|
21
|
+
/** Polling interval in milliseconds (default: 1000) */
|
|
22
|
+
pollInterval?: number;
|
|
23
|
+
/** Callback to receive cost estimation before signing (optional) */
|
|
24
|
+
onCostEstimation?: (costEstimation: CantonCostEstimationDto | undefined) => void | Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export declare class CantonService {
|
|
27
|
+
private client;
|
|
28
|
+
private meCache;
|
|
29
|
+
private meCacheTimestamp;
|
|
30
|
+
private mePendingPromise;
|
|
31
|
+
private readonly CACHE_TTL;
|
|
32
|
+
constructor(client: ApiClient);
|
|
33
|
+
/**
|
|
34
|
+
* Инвалидация кеша /me
|
|
35
|
+
* Вызывается после операций регистрации/изменения пользователя
|
|
36
|
+
*/
|
|
37
|
+
private invalidateMeCache;
|
|
38
|
+
/**
|
|
39
|
+
* Register Canton wallet
|
|
40
|
+
* Flow:
|
|
41
|
+
* 1. Call /canton/register/prepare with publicKey -> get hash
|
|
42
|
+
* 2. Sign hash with Stellar wallet
|
|
43
|
+
* 3. Call /canton/register/submit with hash + signature
|
|
44
|
+
*
|
|
45
|
+
* @param params Registration parameters
|
|
46
|
+
*/
|
|
47
|
+
registerCanton(params: CantonRegisterParams, errCounter?: number): Promise<any>;
|
|
48
|
+
/**
|
|
49
|
+
* Tap devnet faucet to receive test Canton coins
|
|
50
|
+
* Flow:
|
|
51
|
+
* 1. Call /canton/devnet/tap with amount -> get hash
|
|
52
|
+
* 2. Sign hash with Stellar wallet
|
|
53
|
+
* 3. Call /canton/api/submit_prepared with hash + signature
|
|
54
|
+
* 4. Poll for completion
|
|
55
|
+
*
|
|
56
|
+
* @param params Tap parameters
|
|
57
|
+
* @param options Polling options
|
|
58
|
+
*/
|
|
59
|
+
tapDevnet(params: CantonTapParams, options?: CantonSubmitPreparedOptions): Promise<CantonQueryCompletionResponseDto>;
|
|
60
|
+
/**
|
|
61
|
+
* Submit signed Canton transaction
|
|
62
|
+
* @param hash Base64 hash
|
|
63
|
+
* @param signature Base64 signature
|
|
64
|
+
*/
|
|
65
|
+
submitPrepared(hash: string, signature: string): Promise<CantonSubmitTransactionResponseDto>;
|
|
66
|
+
/**
|
|
67
|
+
* Query completion status for a submission
|
|
68
|
+
* @param submissionId Submission ID from submitPrepared
|
|
69
|
+
*/
|
|
70
|
+
queryCompletion(submissionId: string): Promise<CantonQueryCompletionResponseDto>;
|
|
71
|
+
/**
|
|
72
|
+
* Submit signed Canton transaction and wait for completion
|
|
73
|
+
* Polls the ledger API until the transaction is completed or timeout is reached
|
|
74
|
+
* @param hash Base64 hash
|
|
75
|
+
* @param signature Base64 signature
|
|
76
|
+
* @param options Polling options (timeout, pollInterval)
|
|
77
|
+
* @returns Completion data when transaction is completed
|
|
78
|
+
* @throws Error if timeout is reached before completion
|
|
79
|
+
*/
|
|
80
|
+
submitPreparedAndWait(hash: string, signature: string, options?: CantonSubmitPreparedOptions): Promise<CantonQueryCompletionResponseDto>;
|
|
81
|
+
/**
|
|
82
|
+
* Get current Canton user info (partyId and email)
|
|
83
|
+
* Only works after registration
|
|
84
|
+
* С мемоизацией на 5 минут и дедупликацией одновременных запросов
|
|
85
|
+
*/
|
|
86
|
+
getMe(force?: boolean): Promise<CantonMeResponseDto>;
|
|
87
|
+
/**
|
|
88
|
+
* Get active contracts with optional template filtering
|
|
89
|
+
* Returns array of active contract items with full contract details
|
|
90
|
+
* @param templateIds Optional array of template IDs to filter by
|
|
91
|
+
*/
|
|
92
|
+
getActiveContracts(templateIds?: string[]): Promise<CantonActiveContractsResponseDto>;
|
|
93
|
+
/**
|
|
94
|
+
* Sign text message (client-side only, no backend call)
|
|
95
|
+
* Converts text to bytes and signs with Stellar wallet
|
|
96
|
+
* @param message Text message to sign
|
|
97
|
+
* @param signFunction Function to sign hash (returns signature in hex)
|
|
98
|
+
*/
|
|
99
|
+
signMessage(message: string, signFunction: (hashHex: string) => Promise<string>): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Prepare Canton transaction
|
|
102
|
+
* @param commands Command or array of commands
|
|
103
|
+
* @param disclosedContracts Optional disclosed contracts
|
|
104
|
+
*/
|
|
105
|
+
prepareTransaction(commands: unknown, disclosedContracts?: unknown): Promise<CantonPrepareTransactionResponseDto>;
|
|
106
|
+
/**
|
|
107
|
+
* Check if user has Canton wallet registered
|
|
108
|
+
* This is inferred - if /me succeeds, user has wallet
|
|
109
|
+
*/
|
|
110
|
+
checkRegistrationStatus(): Promise<boolean>;
|
|
111
|
+
/**
|
|
112
|
+
* Prepare transfer preapproval
|
|
113
|
+
* Flow: prepare -> sign -> submit
|
|
114
|
+
* No request body required
|
|
115
|
+
*/
|
|
116
|
+
prepareTransferPreapproval(): Promise<CantonPrepareTransactionResponseDto>;
|
|
117
|
+
/**
|
|
118
|
+
* Get Canton wallet balances
|
|
119
|
+
* Returns balances for all tokens grouped by instrument ID
|
|
120
|
+
* Includes unlocked and locked UTXOs
|
|
121
|
+
*/
|
|
122
|
+
getBalances(): Promise<CantonWalletBalancesResponseDto>;
|
|
123
|
+
/**
|
|
124
|
+
* Prepare Amulet (Canton Coin) transfer
|
|
125
|
+
* @param params Transfer parameters (receiverPartyId, amount, memo)
|
|
126
|
+
* @throws Error if amount has more than 10 decimal places
|
|
127
|
+
*/
|
|
128
|
+
prepareAmuletTransfer(params: CantonPrepareAmuletTransferRequestDto): Promise<CantonPrepareTransactionResponseDto>;
|
|
129
|
+
/**
|
|
130
|
+
* Get pending incoming transfers for the current user
|
|
131
|
+
* Returns a list of transfer offers that can be accepted or rejected
|
|
132
|
+
* @returns Array of incoming transfer DTOs
|
|
133
|
+
*/
|
|
134
|
+
getPendingIncomingTransfers(): Promise<CantonIncomingTransferDto[]>;
|
|
135
|
+
/**
|
|
136
|
+
* Prepare response to incoming transfer (accept or reject)
|
|
137
|
+
* Flow: prepare -> sign -> submit
|
|
138
|
+
* @param params Request with contractId and accept flag
|
|
139
|
+
* @returns Prepare response with hash to sign
|
|
140
|
+
*/
|
|
141
|
+
prepareResponseToIncomingTransfer(params: CantonPrepareResponseIncomingTransferRequestDto): Promise<CantonPrepareTransactionResponseDto>;
|
|
142
|
+
/**
|
|
143
|
+
* Get Canton transactions history with pagination
|
|
144
|
+
* @param params Pagination parameters (limit, beforeOffsetExclusive)
|
|
145
|
+
* @returns Array of transaction DTOs
|
|
146
|
+
*/
|
|
147
|
+
getTransactions(params?: CantonTransactionsParams): Promise<CantonTransactionDto[]>;
|
|
148
|
+
/**
|
|
149
|
+
* Get Canton price history (candles from Bybit)
|
|
150
|
+
* @param interval Time interval: '1h' (hour), '1d' (day), '1w' (week), '1M' (month)
|
|
151
|
+
* @returns Array of price candles
|
|
152
|
+
*/
|
|
153
|
+
getPriceHistory(interval: CantonPriceInterval): Promise<CantonPriceCandleDto[]>;
|
|
154
|
+
}
|
|
155
|
+
export declare function createCantonService(client: ApiClient): CantonService;
|
|
156
|
+
export declare function getCantonService(): CantonService;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for converting between hex and base64 formats
|
|
3
|
+
* Required for Canton Network integration (Canton uses base64, Privy uses hex)
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Converts hex string to base64 format
|
|
7
|
+
* @param hex - Hex string (with or without 0x prefix)
|
|
8
|
+
* @returns Base64 encoded string
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const base64 = hexToBase64('0x48656c6c6f');
|
|
12
|
+
* console.log(base64); // "SGVsbG8="
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const hexToBase64: (hex: string) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Converts base64 string to hex format
|
|
18
|
+
* @param base64 - Base64 encoded string
|
|
19
|
+
* @returns Hex string with 0x prefix
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const hex = base64ToHex('SGVsbG8=');
|
|
23
|
+
* console.log(hex); // "0x48656c6c6f"
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const base64ToHex: (base64: string) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Converts Uint8Array to base64 string
|
|
29
|
+
* @param bytes - Byte array to convert
|
|
30
|
+
* @returns Base64 encoded string
|
|
31
|
+
*/
|
|
32
|
+
export declare const bytesToBase64: (bytes: Uint8Array) => string;
|
|
33
|
+
/**
|
|
34
|
+
* Converts base64 string to Uint8Array
|
|
35
|
+
* @param base64 - Base64 encoded string
|
|
36
|
+
* @returns Byte array
|
|
37
|
+
*/
|
|
38
|
+
export declare const base64ToBytes: (base64: string) => Uint8Array;
|
|
39
|
+
/**
|
|
40
|
+
* Removes leading 00 byte from hex string if present
|
|
41
|
+
* Required for Stellar public keys from Privy which include a leading 00 byte
|
|
42
|
+
* @param hex - Hex string (with or without 0x prefix)
|
|
43
|
+
* @returns Clean hex string with 0x prefix
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const clean = stripLeadingZero('0x00e95cb2553361ed...');
|
|
47
|
+
* console.log(clean); // "0xe95cb2553361ed..."
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare const stripLeadingZero: (hex: string) => string;
|
|
51
|
+
/**
|
|
52
|
+
* Converts Privy public key (hex with leading 00) to Canton format (base64 without leading 00)
|
|
53
|
+
* This function handles the conversion from Privy's Stellar wallet public key format
|
|
54
|
+
* to Canton Network's expected base64 format.
|
|
55
|
+
*
|
|
56
|
+
* @param publicKeyHex - Public key in hex format from Privy (may include 0x prefix and leading 00)
|
|
57
|
+
* @returns Public key in base64 format for Canton Network
|
|
58
|
+
* @throws {Error} If conversion fails
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const wallet = { publicKey: '00e95cb2553361ed...' };
|
|
63
|
+
* const cantonKey = privyPublicKeyToCantonBase64(wallet.publicKey);
|
|
64
|
+
* // Use cantonKey for Canton Network API calls
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare const privyPublicKeyToCantonBase64: (publicKeyHex: string) => string;
|
|
@@ -0,0 +1,90 @@
|
|
|
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;
|
package/package.json
CHANGED