@fibo-crypto/react-sdk 0.3.0

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.
@@ -0,0 +1,284 @@
1
+ interface EvmBalanceResponse {
2
+ address: string;
3
+ chain: 'base';
4
+ eth: {
5
+ wei: string;
6
+ formatted: string;
7
+ };
8
+ usdc: {
9
+ raw: string;
10
+ formatted: string;
11
+ };
12
+ }
13
+ interface QuoteFee {
14
+ label: string;
15
+ amount: string;
16
+ currency: string;
17
+ usd?: string;
18
+ }
19
+ interface SwapBreakdown {
20
+ source: {
21
+ token: string;
22
+ chain_id: number;
23
+ amount: string;
24
+ symbol: string;
25
+ decimals: number;
26
+ };
27
+ destination: {
28
+ token: string;
29
+ chain_id: number;
30
+ amount: string;
31
+ amount_min: string;
32
+ symbol: string;
33
+ decimals: number;
34
+ };
35
+ fees: QuoteFee[];
36
+ source_usd: string;
37
+ slippage_bps: number;
38
+ estimated_completion_seconds: number;
39
+ }
40
+ interface BuyEureBreakdown {
41
+ source: {
42
+ amount: string;
43
+ currency: 'EUR';
44
+ };
45
+ destination: {
46
+ amount: string;
47
+ currency: 'EURe';
48
+ chain: string;
49
+ };
50
+ fees: QuoteFee[];
51
+ ramping_provider: 'monerium';
52
+ estimated_completion_seconds: number;
53
+ }
54
+ type QuoteResponse = {
55
+ quote_id: string;
56
+ ttl_seconds: number;
57
+ expires_at: string;
58
+ kind: 'swap';
59
+ breakdown: SwapBreakdown;
60
+ } | {
61
+ quote_id: string;
62
+ ttl_seconds: number;
63
+ expires_at: string;
64
+ kind: 'buy_eure';
65
+ breakdown: BuyEureBreakdown;
66
+ };
67
+ interface SignEip7702Payload {
68
+ contractAddress: `0x${string}`;
69
+ }
70
+ type PrepareStep = {
71
+ step_index: number;
72
+ kind: 'sign_eip7702';
73
+ chain_id: number;
74
+ payload: SignEip7702Payload;
75
+ } | {
76
+ step_index: number;
77
+ kind: 'sign_evm_tx';
78
+ chain_id: number;
79
+ payload: unknown;
80
+ } | {
81
+ step_index: number;
82
+ kind: 'redirect_ramping';
83
+ provider: string;
84
+ widget_url: string;
85
+ };
86
+ interface PrepareTxResponse {
87
+ transaction_id: string;
88
+ steps: PrepareStep[];
89
+ }
90
+ interface Eip7702Signature {
91
+ r: `0x${string}`;
92
+ s: `0x${string}`;
93
+ yParity: number;
94
+ /** Stringified bigint when the legacy-signature variant comes back from
95
+ * viem's signedAuthorization. Never transport raw bigint over JSON. */
96
+ v?: string;
97
+ address: `0x${string}`;
98
+ chainId: number;
99
+ nonce: number;
100
+ }
101
+ interface SignMessageStep {
102
+ kind: 'sign_message';
103
+ chain_id: number;
104
+ payload: {
105
+ hash: `0x${string}`;
106
+ };
107
+ }
108
+ interface SubmitResponse {
109
+ transaction_id: string;
110
+ status: string;
111
+ /** D5: present when /submit successfully fetched a MEE quote and needs the
112
+ * user to sign quote.hash before /execute-signed-quote can run. */
113
+ next_step?: SignMessageStep;
114
+ payment_info?: unknown;
115
+ tx_hash: string | null;
116
+ super_hash: string | null;
117
+ tracker_url: string | null;
118
+ note?: string;
119
+ }
120
+ interface ExecuteResponse {
121
+ transaction_id: string;
122
+ status: string;
123
+ super_hash: `0x${string}`;
124
+ tracker_url: string;
125
+ }
126
+ interface TransactionState {
127
+ id: string;
128
+ quoteId: string;
129
+ status: string;
130
+ txHash?: string;
131
+ superHash?: string;
132
+ failureReason?: string;
133
+ }
134
+ /**
135
+ * Full transaction row returned by GET /v1/transactions (list endpoint).
136
+ * Wider shape than `TransactionState` which is just the per-id lookup.
137
+ */
138
+ type TransactionStatus = 'quoted' | 'preparing' | 'pending_signature' | 'submitted' | 'confirmed' | 'failed' | 'expired';
139
+ interface Transaction {
140
+ id: string;
141
+ tenant_id: string;
142
+ user_id: string;
143
+ kind: string;
144
+ status: TransactionStatus;
145
+ user_address: string | null;
146
+ source_amount: string | null;
147
+ source_currency: string | null;
148
+ source_chain_id: number | null;
149
+ dest_amount: string | null;
150
+ dest_currency: string | null;
151
+ dest_chain_id: number | null;
152
+ usd_volume: string | null;
153
+ tx_hash: string | null;
154
+ super_hash: string | null;
155
+ tracker_url: string | null;
156
+ failure_reason: string | null;
157
+ created_at: string;
158
+ updated_at: string;
159
+ completed_at: string | null;
160
+ }
161
+ interface TransactionListResponse {
162
+ data: Transaction[];
163
+ has_more: boolean;
164
+ next_before?: string;
165
+ }
166
+ interface TransactionListParams {
167
+ /** Maximum rows (1..200, default 50). */
168
+ limit?: number;
169
+ /** Filter by status. */
170
+ status?: TransactionStatus;
171
+ /** ISO 8601 cursor — return only rows created before this timestamp. */
172
+ before?: string;
173
+ }
174
+ interface MoneriumOrderResponse {
175
+ order_id: string;
176
+ status: string;
177
+ iban: string;
178
+ reference: string;
179
+ widget_url?: string;
180
+ }
181
+
182
+ /** Default API base URL — exported so callers and FiboProvider stay in sync. */
183
+ declare const DEFAULT_BASE_URL = "https://api.fibo-crypto.fr";
184
+ interface FiboClientConfig {
185
+ /** API base URL — defaults to https://api.fibo-crypto.fr if omitted. */
186
+ baseUrl?: string;
187
+ /**
188
+ * Bearer token used on every request. MUST be a publishable key
189
+ * (`pk_test_*` / `pk_live_*`) when used from browser contexts —
190
+ * secret keys (`sk_*`) are rejected to prevent accidentally embedding
191
+ * them in client bundles where any visitor could extract them.
192
+ *
193
+ * For trusted server-side contexts (Node scripts, CLI tools, backend-
194
+ * to-backend integrations) where an `sk_*` is intentional, set
195
+ * `allowSecretKey: true` to bypass the guard.
196
+ */
197
+ apiKey: string;
198
+ /**
199
+ * Opt-out of the `pk_*`-only check. Use only in trusted server-side
200
+ * contexts. Defaults to false. The `@fibo-crypto/cli` admin tool passes true.
201
+ */
202
+ allowSecretKey?: boolean;
203
+ }
204
+ interface FiboApiErrorInfo {
205
+ status: number;
206
+ code: string;
207
+ message: string;
208
+ details?: unknown;
209
+ request_id?: string;
210
+ }
211
+ declare class FiboApiError extends Error {
212
+ readonly status: number;
213
+ readonly code: string;
214
+ readonly details?: unknown;
215
+ readonly request_id?: string;
216
+ constructor(info: FiboApiErrorInfo);
217
+ }
218
+ interface RequestArgs {
219
+ method: 'GET' | 'POST' | 'DELETE' | 'PUT';
220
+ path: string;
221
+ body?: unknown;
222
+ /** Pass to cancel the fetch — e.g., on component unmount or address change. */
223
+ signal?: AbortSignal;
224
+ }
225
+ interface FiboClient {
226
+ request<T>(args: RequestArgs): Promise<T>;
227
+ health(): Promise<{
228
+ ok: boolean;
229
+ ts: number;
230
+ }>;
231
+ quoteSwap(params: {
232
+ source: {
233
+ token: string;
234
+ chain_id: number;
235
+ amount: string;
236
+ };
237
+ destination: {
238
+ token: string;
239
+ chain_id: number;
240
+ };
241
+ user_address: string;
242
+ }): Promise<Extract<QuoteResponse, {
243
+ kind: 'swap';
244
+ }>>;
245
+ quoteBuyEure(params: {
246
+ fiat_amount: string;
247
+ user_address: string;
248
+ }): Promise<Extract<QuoteResponse, {
249
+ kind: 'buy_eure';
250
+ }>>;
251
+ prepareTx(params: {
252
+ quote_id: string;
253
+ user_address: string;
254
+ }): Promise<PrepareTxResponse>;
255
+ submit(params: {
256
+ quote_id: string;
257
+ transaction_id: string;
258
+ signatures: {
259
+ step_index: number;
260
+ signature: Eip7702Signature;
261
+ }[];
262
+ }): Promise<SubmitResponse>;
263
+ executeSignedQuote(params: {
264
+ transaction_id: string;
265
+ quote_signature: `0x${string}`;
266
+ }): Promise<ExecuteResponse>;
267
+ getTransaction(id: string, opts?: {
268
+ signal?: AbortSignal;
269
+ }): Promise<TransactionState>;
270
+ listTransactions(params?: TransactionListParams, opts?: {
271
+ signal?: AbortSignal;
272
+ }): Promise<TransactionListResponse>;
273
+ moneriumCreateOrder(params: {
274
+ user_address: string;
275
+ amount: string;
276
+ chain?: string;
277
+ }): Promise<MoneriumOrderResponse>;
278
+ getEvmBalance(address: string, opts?: {
279
+ signal?: AbortSignal;
280
+ }): Promise<EvmBalanceResponse>;
281
+ }
282
+ declare function createFiboClient(config: FiboClientConfig): FiboClient;
283
+
284
+ export { type BuyEureBreakdown, DEFAULT_BASE_URL, type Eip7702Signature, type EvmBalanceResponse, type ExecuteResponse, FiboApiError, type FiboApiErrorInfo, type FiboClient, type FiboClientConfig, type MoneriumOrderResponse, type PrepareStep, type PrepareTxResponse, type QuoteFee, type QuoteResponse, type SignEip7702Payload, type SignMessageStep, type SubmitResponse, type SwapBreakdown, type Transaction, type TransactionListParams, type TransactionListResponse, type TransactionState, type TransactionStatus, createFiboClient };
package/dist/client.js ADDED
@@ -0,0 +1,3 @@
1
+ export { DEFAULT_BASE_URL, FiboApiError, createFiboClient } from './chunk-FRD4NVYJ.js';
2
+ //# sourceMappingURL=client.js.map
3
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"client.js"}
@@ -0,0 +1,189 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { FiboClient, EvmBalanceResponse, Transaction, TransactionStatus, QuoteResponse, ExecuteResponse } from './client.js';
4
+ export { BuyEureBreakdown, DEFAULT_BASE_URL, Eip7702Signature, FiboApiError, FiboApiErrorInfo, FiboClientConfig, MoneriumOrderResponse, PrepareStep, PrepareTxResponse, QuoteFee, SignEip7702Payload, SignMessageStep, SubmitResponse, SwapBreakdown, TransactionListParams, TransactionListResponse, TransactionState, createFiboClient } from './client.js';
5
+
6
+ interface FiboTheme {
7
+ /** Accent color — must be a hex string starting with `#` (e.g. `#5B44F9`). */
8
+ accent?: `#${string}`;
9
+ }
10
+ type FiboLoginMethod = 'email' | 'google' | 'apple' | 'github' | 'discord' | 'twitter' | 'sms' | 'passkey';
11
+ interface FiboProviderProps {
12
+ /** Publishable Fibo API key — `pk_test_*` or `pk_live_*`. */
13
+ publishableKey: string;
14
+ /** API base URL. Defaults to https://api.fibo-crypto.fr. */
15
+ baseUrl?: string;
16
+ /**
17
+ * Your own user identifier for this user. Echoed back on `wallet.created` /
18
+ * `tx.confirmed` webhooks so your backend can join Fibo's records with yours.
19
+ */
20
+ externalUserId?: string;
21
+ /**
22
+ * Privy login methods shown in the UI. Defaults to email + Google + Apple.
23
+ */
24
+ loginMethods?: FiboLoginMethod[];
25
+ /** UI theming applied to Privy modals. */
26
+ theme?: FiboTheme;
27
+ /**
28
+ * Override Fibo's shared Privy app id. Rarely needed — default covers all
29
+ * integrators per ADR 0002. Use only if your tenant has been provisioned
30
+ * with a dedicated Privy app (custom contractual setup).
31
+ */
32
+ privyAppIdOverride?: string;
33
+ children: ReactNode;
34
+ }
35
+ declare function FiboProvider({ publishableKey, baseUrl, externalUserId, loginMethods, theme, privyAppIdOverride, children, }: FiboProviderProps): react_jsx_runtime.JSX.Element;
36
+
37
+ declare function useFiboApi(): FiboClient;
38
+
39
+ interface FiboUser {
40
+ /** Privy user DID. Use as a stable identifier across sessions / devices. */
41
+ id: string;
42
+ email?: string;
43
+ /** ISO string when the user was first created on Privy. */
44
+ createdAt?: string;
45
+ }
46
+ interface FiboAuthState {
47
+ /** True once Privy has finished bootstrapping (cookies / local storage read). */
48
+ isReady: boolean;
49
+ /** True once the user has completed login. */
50
+ isAuthenticated: boolean;
51
+ /** The current user, or null when not authenticated / not ready yet. */
52
+ user: FiboUser | null;
53
+ /** Open the Privy login modal. */
54
+ login: () => void;
55
+ /** Log the user out — clears cookies and disconnects embedded wallets. */
56
+ logout: () => Promise<void>;
57
+ }
58
+ declare function useFiboAuth(): FiboAuthState;
59
+
60
+ interface FiboBalanceState {
61
+ /** Latest balance, or null while loading / on error / no address. */
62
+ balance: EvmBalanceResponse | null;
63
+ isLoading: boolean;
64
+ error: Error | null;
65
+ /** Manually re-fetch (e.g., after a swap completed). */
66
+ refetch: () => Promise<void>;
67
+ }
68
+ interface UseFiboBalanceOptions {
69
+ /**
70
+ * Auto-refresh every N milliseconds. Defaults to no polling.
71
+ * Set to ~10000 for a "live" balance display.
72
+ */
73
+ refreshIntervalMs?: number;
74
+ }
75
+ /**
76
+ * Fetches the on-chain balance for an EVM address. Returns `{ balance, isLoading, error, refetch }`.
77
+ * Pass `null` for `address` to skip the fetch (useful while waiting for a wallet to be ready).
78
+ *
79
+ * In-flight fetches are cancelled when `address` changes or the component unmounts —
80
+ * stale results never overwrite the current state.
81
+ */
82
+ declare function useFiboBalance(address: string | null, opts?: UseFiboBalanceOptions): FiboBalanceState;
83
+
84
+ interface FiboTransactionsState {
85
+ transactions: Transaction[];
86
+ /** True if more pages exist beyond the current view (use `nextBefore` cursor). */
87
+ hasMore: boolean;
88
+ /** Cursor to pass as `before` for the next page. */
89
+ nextBefore: string | undefined;
90
+ isLoading: boolean;
91
+ error: Error | null;
92
+ refetch: () => Promise<void>;
93
+ }
94
+ interface UseFiboTransactionsOptions {
95
+ /** Filter by status. */
96
+ status?: TransactionStatus;
97
+ /** Max rows per fetch (1..200, default 50). */
98
+ limit?: number;
99
+ /** ISO 8601 cursor for pagination. Pass `state.nextBefore` to get the next page. */
100
+ before?: string;
101
+ /** Auto-refresh interval in ms. Defaults to no polling. */
102
+ refreshIntervalMs?: number;
103
+ }
104
+ declare function useFiboTransactions(opts?: UseFiboTransactionsOptions): FiboTransactionsState;
105
+
106
+ type BitcoinChain = 'bitcoin-taproot' | 'bitcoin-segwit';
107
+ interface FiboBitcoinWallet {
108
+ address: string;
109
+ chainType: BitcoinChain;
110
+ publicKey?: string;
111
+ walletIndex?: number;
112
+ }
113
+ interface FiboWalletState {
114
+ /** Privy ready flag — true once the SDK has bootstrapped. Wait on this before signing. */
115
+ isReady: boolean;
116
+ /** Convenience flattened addresses for common single-wallet flows. */
117
+ addresses: {
118
+ evm: string | null;
119
+ solana: string | null;
120
+ /** First taproot BTC address, if any. */
121
+ bitcoin: string | null;
122
+ };
123
+ /** All Bitcoin wallets (the user may own multiple BTC addresses). */
124
+ bitcoinWallets: FiboBitcoinWallet[];
125
+ /**
126
+ * Provision a new BTC taproot wallet for the user. Resolves with the new wallet.
127
+ * BTC isn't auto-created on login by Privy — call this when the user wants to receive BTC.
128
+ */
129
+ createBitcoinWallet: () => Promise<FiboBitcoinWallet>;
130
+ }
131
+ declare function useFiboWallet(): FiboWalletState;
132
+
133
+ type FiboSwapPhase = 'idle' | 'quoting' | 'preparing' | 'signing_authorization' | 'submitting' | 'signing_mee_quote' | 'executing' | 'done' | 'error';
134
+ interface FiboSwapQuoteParams {
135
+ source: {
136
+ token: string;
137
+ chainId: number;
138
+ amount: string;
139
+ };
140
+ destination: {
141
+ token: string;
142
+ chainId: number;
143
+ };
144
+ /**
145
+ * The user's EVM address. If omitted, the hook auto-resolves it from
146
+ * Privy's first embedded EVM wallet. Pass explicitly if your app uses
147
+ * a different wallet (multi-account scenarios).
148
+ */
149
+ userAddress?: string;
150
+ }
151
+ interface FiboSwapState {
152
+ /** Latest quote returned by quote(). null until the first quote() call. */
153
+ currentQuote: Extract<QuoteResponse, {
154
+ kind: 'swap';
155
+ }> | null;
156
+ /** ExecuteResponse on success: { super_hash, tracker_url, ... }. */
157
+ result: ExecuteResponse | null;
158
+ /** Latest error from any phase. Cleared by the next quote() / executeSwap() call. */
159
+ error: Error | null;
160
+ /** High-level state machine — useful for "Loading..." vs "Awaiting signature..." UI. */
161
+ phase: FiboSwapPhase;
162
+ /** True if quote has expired (auto-tick). False if no quote yet. */
163
+ isExpired: boolean;
164
+ /** Seconds until current quote expires. 0 if no quote / expired. */
165
+ expiresInSeconds: number;
166
+ /** Convenience boolean: phase is not 'idle' / 'done' / 'error'. */
167
+ isLoading: boolean;
168
+ /**
169
+ * Fetch a swap quote. Resolves with the QuoteResponse (also exposed via
170
+ * state.currentQuote). Auto-resolves user_address from Privy if not passed.
171
+ */
172
+ quote: (params: FiboSwapQuoteParams) => Promise<Extract<QuoteResponse, {
173
+ kind: 'swap';
174
+ }>>;
175
+ /**
176
+ * Execute the current quote (the last one returned by quote()).
177
+ * Runs the full prepare → sign → submit → sign MEE → execute ceremony.
178
+ * Resolves with the ExecuteResponse on success.
179
+ *
180
+ * Throws if no quote is pending or if the quote has expired (caller
181
+ * should call quote() again first).
182
+ */
183
+ executeSwap: () => Promise<ExecuteResponse>;
184
+ /** Clear the current quote + result + error. Returns the hook to 'idle'. */
185
+ reset: () => void;
186
+ }
187
+ declare function useFiboSwap(): FiboSwapState;
188
+
189
+ export { type BitcoinChain, EvmBalanceResponse, ExecuteResponse, type FiboAuthState, type FiboBalanceState, type FiboBitcoinWallet, FiboClient, type FiboLoginMethod, FiboProvider, type FiboProviderProps, type FiboSwapPhase, type FiboSwapQuoteParams, type FiboSwapState, type FiboTheme, type FiboTransactionsState, type FiboUser, type FiboWalletState, QuoteResponse, Transaction, TransactionStatus, type UseFiboBalanceOptions, type UseFiboTransactionsOptions, useFiboApi, useFiboAuth, useFiboBalance, useFiboSwap, useFiboTransactions, useFiboWallet };