@swype-org/react-sdk 0.1.1 → 0.1.3

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/dist/index.d.cts CHANGED
@@ -38,6 +38,8 @@ interface Wallet {
38
38
  id: string;
39
39
  name: string;
40
40
  };
41
+ /** The smart account type (e.g. 'metamask'), if the wallet has been upgraded. */
42
+ smartAccountType?: string | null;
41
43
  createDate: string;
42
44
  updateDate: string;
43
45
  authorizationSessions?: AuthorizationSession[];
@@ -87,6 +89,17 @@ interface TransferDestination {
87
89
  };
88
90
  amount: Amount;
89
91
  }
92
+ /** Sign payload containing the unsigned UserOp and bridge/relay metadata */
93
+ interface TransferSignPayload {
94
+ userOp: Record<string, unknown>;
95
+ /** ERC-4337 UserOp hash — used as the WebAuthn challenge for on-chain verification. */
96
+ userOpHash: string;
97
+ bridgeRelayAddress: string;
98
+ tokenSymbol: string;
99
+ chainName: string;
100
+ amount: string;
101
+ estimatedFeeUsd: string;
102
+ }
90
103
  /** Transfer object returned by the API */
91
104
  interface Transfer {
92
105
  id: string;
@@ -102,6 +115,7 @@ interface Transfer {
102
115
  createDate: string;
103
116
  updateDate: string;
104
117
  authorizationSessions: AuthorizationSession[];
118
+ signPayload?: TransferSignPayload | null;
105
119
  }
106
120
  /** Standard API error shape */
107
121
  interface ErrorResponse {
@@ -123,6 +137,11 @@ interface ActionExecutionResult {
123
137
  }
124
138
  /** Source type discriminator for transfer creation */
125
139
  type SourceType = 'providerId' | 'accountId' | 'walletId' | 'tokenId';
140
+ /** User's chain+token selection for the SELECT_SOURCE action. */
141
+ interface SourceSelection {
142
+ chainName: string;
143
+ tokenSymbol: string;
144
+ }
126
145
  /** Destination input provided by the host app */
127
146
  interface Destination {
128
147
  chainId: string;
@@ -142,7 +161,14 @@ interface UserConfig {
142
161
  /** Theme mode */
143
162
  type ThemeMode = 'light' | 'dark';
144
163
  /** Steps in the payment flow */
145
- type PaymentStep = 'login' | 'select-source' | 'enter-amount' | 'processing' | 'complete';
164
+ type PaymentStep = 'login' | 'enter-amount' | 'ready' | 'processing' | 'complete';
165
+ /** User-selected advanced settings for chain/asset override */
166
+ interface AdvancedSettings {
167
+ /** Override asset (e.g. 'USDC', 'USDT'). Null = let backend decide. */
168
+ asset: string | null;
169
+ /** Override chain name (e.g. 'Base', 'Ethereum'). Null = let backend decide. */
170
+ chain: string | null;
171
+ }
146
172
 
147
173
  interface ThemeTokens {
148
174
  bg: string;
@@ -176,6 +202,10 @@ interface SwypeConfig {
176
202
  apiBaseUrl: string;
177
203
  theme: ThemeMode;
178
204
  tokens: ThemeTokens;
205
+ /** Pre-set deposit amount (controlled by host app via useSwypeDepositAmount) */
206
+ depositAmount: number | null;
207
+ /** Update the deposit amount from a host-app component */
208
+ setDepositAmount: (amount: number | null) => void;
179
209
  }
180
210
  interface SwypeProviderProps {
181
211
  /** Base URL for the Swype API (e.g. "http://localhost:3000") */
@@ -201,6 +231,26 @@ interface SwypeProviderProps {
201
231
  declare function SwypeProvider({ apiBaseUrl, theme, children, }: SwypeProviderProps): react_jsx_runtime.JSX.Element;
202
232
  /** Access the Swype SDK configuration. Throws if used outside SwypeProvider. */
203
233
  declare function useSwypeConfig(): SwypeConfig;
234
+ /**
235
+ * Hook for host apps to pre-set the deposit amount before showing the
236
+ * payment widget. When set, the amount field in SwypePayment is
237
+ * auto-populated.
238
+ *
239
+ * @example
240
+ * ```tsx
241
+ * function ProductPage() {
242
+ * const { setAmount } = useSwypeDepositAmount();
243
+ * useEffect(() => { setAmount(25.00); }, []);
244
+ * return <SwypePayment destination={dest} />;
245
+ * }
246
+ * ```
247
+ */
248
+ declare function useSwypeDepositAmount(): {
249
+ /** Current deposit amount, or null if not set */
250
+ amount: number | null;
251
+ /** Set the deposit amount (pass null to clear) */
252
+ setAmount: (amount: number | null) => void;
253
+ };
204
254
 
205
255
  interface SwypePaymentProps {
206
256
  /**
@@ -233,13 +283,28 @@ interface UseAuthorizationExecutorResult {
233
283
  executing: boolean;
234
284
  results: ActionExecutionResult[];
235
285
  error: string | null;
286
+ /** The current action being executed (for UI display). */
287
+ currentAction: AuthorizationAction | null;
288
+ /** The SELECT_SOURCE action when paused for user selection, null otherwise. */
289
+ pendingSelectSource: AuthorizationAction | null;
290
+ /** Call this from the UI to provide the user's chain+token choice. */
291
+ resolveSelectSource: (selection: SourceSelection) => void;
236
292
  executeSession: (transfer: Transfer) => Promise<void>;
237
293
  }
238
294
  /**
239
295
  * Executes the full authorization flow for a transfer's first session:
240
296
  * fetches the session, walks through PENDING actions (OPEN_PROVIDER,
241
- * SWITCH_CHAIN, APPROVE_PERMIT_2, SIGN_PERMIT2), reports each completion
242
- * to the server, and chains new actions that appear.
297
+ * REGISTER_PASSKEY, UPGRADE_SMART_ACCOUNT, GRANT_PERMISSIONS,
298
+ * SELECT_SOURCE), reports each completion to the server, and chains
299
+ * new actions that appear.
300
+ *
301
+ * Transfer signing (passkey) is handled separately via
302
+ * `useTransferSigning()` after the authorization flow completes.
303
+ *
304
+ * When a SELECT_SOURCE action is encountered, the executor pauses and
305
+ * exposes the action via `pendingSelectSource`. The UI should display
306
+ * a chain+token selector and call `resolveSelectSource()` with the
307
+ * user's choice. The executor then resumes automatically.
243
308
  */
244
309
  declare function useAuthorizationExecutor(): UseAuthorizationExecutorResult;
245
310
 
@@ -255,10 +320,25 @@ interface CreateTransferParams {
255
320
  }
256
321
  declare function createTransfer(apiBaseUrl: string, token: string, params: CreateTransferParams): Promise<Transfer>;
257
322
  declare function fetchTransfer(apiBaseUrl: string, token: string, transferId: string): Promise<Transfer>;
323
+ /**
324
+ * Submit a passkey-signed UserOperation for a transfer.
325
+ * PATCH /v1/transfers/{transferId}
326
+ */
327
+ declare function signTransfer(apiBaseUrl: string, token: string, transferId: string, signedUserOp: Record<string, unknown>): Promise<Transfer>;
258
328
  declare function fetchAuthorizationSession(apiBaseUrl: string, sessionId: string): Promise<AuthorizationSessionDetail>;
259
329
  declare function updateUserConfig(apiBaseUrl: string, token: string, config: {
260
330
  defaultAllowance: number;
261
331
  }): Promise<void>;
332
+ /**
333
+ * Updates the user's default allowance, authenticated by session ID.
334
+ * PATCH /v1/authorization-sessions/{id}/user-config
335
+ *
336
+ * This does not require a bearer token — the session ID itself serves
337
+ * as proof of authorization.
338
+ */
339
+ declare function updateUserConfigBySession(apiBaseUrl: string, sessionId: string, config: {
340
+ defaultAllowance: number;
341
+ }): Promise<void>;
262
342
  declare function reportActionCompletion(apiBaseUrl: string, actionId: string, result: Record<string, unknown>): Promise<AuthorizationSessionDetail>;
263
343
 
264
344
  type api_CreateTransferParams = CreateTransferParams;
@@ -269,9 +349,11 @@ declare const api_fetchChains: typeof fetchChains;
269
349
  declare const api_fetchProviders: typeof fetchProviders;
270
350
  declare const api_fetchTransfer: typeof fetchTransfer;
271
351
  declare const api_reportActionCompletion: typeof reportActionCompletion;
352
+ declare const api_signTransfer: typeof signTransfer;
272
353
  declare const api_updateUserConfig: typeof updateUserConfig;
354
+ declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
273
355
  declare namespace api {
274
- export { type api_CreateTransferParams as CreateTransferParams, api_createTransfer as createTransfer, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_reportActionCompletion as reportActionCompletion, api_updateUserConfig as updateUserConfig };
356
+ export { type api_CreateTransferParams as CreateTransferParams, api_createTransfer as createTransfer, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_reportActionCompletion as reportActionCompletion, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
275
357
  }
276
358
 
277
- export { type Account, type ActionExecutionResult, type Amount, type AuthorizationAction, type AuthorizationSession, type AuthorizationSessionDetail, type Chain, type Destination, type ErrorResponse, type ListResponse, type PaymentStep, type Provider, type SourceType, SwypePayment, type SwypePaymentProps, SwypeProvider, type SwypeProviderProps, type ThemeMode, type ThemeTokens, type TokenBalance, type Transfer, type TransferDestination, type UserConfig, type Wallet, type WalletSource, type WalletToken, darkTheme, getTheme, lightTheme, api as swypeApi, useAuthorizationExecutor, useSwypeConfig, useTransferPolling };
359
+ export { type Account, type ActionExecutionResult, type AdvancedSettings, type Amount, type AuthorizationAction, type AuthorizationSession, type AuthorizationSessionDetail, type Chain, type Destination, type ErrorResponse, type ListResponse, type PaymentStep, type Provider, type SourceType, SwypePayment, type SwypePaymentProps, SwypeProvider, type SwypeProviderProps, type ThemeMode, type ThemeTokens, type TokenBalance, type Transfer, type TransferDestination, type UserConfig, type Wallet, type WalletSource, type WalletToken, darkTheme, getTheme, lightTheme, api as swypeApi, useAuthorizationExecutor, useSwypeConfig, useSwypeDepositAmount, useTransferPolling };
package/dist/index.d.ts CHANGED
@@ -38,6 +38,8 @@ interface Wallet {
38
38
  id: string;
39
39
  name: string;
40
40
  };
41
+ /** The smart account type (e.g. 'metamask'), if the wallet has been upgraded. */
42
+ smartAccountType?: string | null;
41
43
  createDate: string;
42
44
  updateDate: string;
43
45
  authorizationSessions?: AuthorizationSession[];
@@ -87,6 +89,17 @@ interface TransferDestination {
87
89
  };
88
90
  amount: Amount;
89
91
  }
92
+ /** Sign payload containing the unsigned UserOp and bridge/relay metadata */
93
+ interface TransferSignPayload {
94
+ userOp: Record<string, unknown>;
95
+ /** ERC-4337 UserOp hash — used as the WebAuthn challenge for on-chain verification. */
96
+ userOpHash: string;
97
+ bridgeRelayAddress: string;
98
+ tokenSymbol: string;
99
+ chainName: string;
100
+ amount: string;
101
+ estimatedFeeUsd: string;
102
+ }
90
103
  /** Transfer object returned by the API */
91
104
  interface Transfer {
92
105
  id: string;
@@ -102,6 +115,7 @@ interface Transfer {
102
115
  createDate: string;
103
116
  updateDate: string;
104
117
  authorizationSessions: AuthorizationSession[];
118
+ signPayload?: TransferSignPayload | null;
105
119
  }
106
120
  /** Standard API error shape */
107
121
  interface ErrorResponse {
@@ -123,6 +137,11 @@ interface ActionExecutionResult {
123
137
  }
124
138
  /** Source type discriminator for transfer creation */
125
139
  type SourceType = 'providerId' | 'accountId' | 'walletId' | 'tokenId';
140
+ /** User's chain+token selection for the SELECT_SOURCE action. */
141
+ interface SourceSelection {
142
+ chainName: string;
143
+ tokenSymbol: string;
144
+ }
126
145
  /** Destination input provided by the host app */
127
146
  interface Destination {
128
147
  chainId: string;
@@ -142,7 +161,14 @@ interface UserConfig {
142
161
  /** Theme mode */
143
162
  type ThemeMode = 'light' | 'dark';
144
163
  /** Steps in the payment flow */
145
- type PaymentStep = 'login' | 'select-source' | 'enter-amount' | 'processing' | 'complete';
164
+ type PaymentStep = 'login' | 'enter-amount' | 'ready' | 'processing' | 'complete';
165
+ /** User-selected advanced settings for chain/asset override */
166
+ interface AdvancedSettings {
167
+ /** Override asset (e.g. 'USDC', 'USDT'). Null = let backend decide. */
168
+ asset: string | null;
169
+ /** Override chain name (e.g. 'Base', 'Ethereum'). Null = let backend decide. */
170
+ chain: string | null;
171
+ }
146
172
 
147
173
  interface ThemeTokens {
148
174
  bg: string;
@@ -176,6 +202,10 @@ interface SwypeConfig {
176
202
  apiBaseUrl: string;
177
203
  theme: ThemeMode;
178
204
  tokens: ThemeTokens;
205
+ /** Pre-set deposit amount (controlled by host app via useSwypeDepositAmount) */
206
+ depositAmount: number | null;
207
+ /** Update the deposit amount from a host-app component */
208
+ setDepositAmount: (amount: number | null) => void;
179
209
  }
180
210
  interface SwypeProviderProps {
181
211
  /** Base URL for the Swype API (e.g. "http://localhost:3000") */
@@ -201,6 +231,26 @@ interface SwypeProviderProps {
201
231
  declare function SwypeProvider({ apiBaseUrl, theme, children, }: SwypeProviderProps): react_jsx_runtime.JSX.Element;
202
232
  /** Access the Swype SDK configuration. Throws if used outside SwypeProvider. */
203
233
  declare function useSwypeConfig(): SwypeConfig;
234
+ /**
235
+ * Hook for host apps to pre-set the deposit amount before showing the
236
+ * payment widget. When set, the amount field in SwypePayment is
237
+ * auto-populated.
238
+ *
239
+ * @example
240
+ * ```tsx
241
+ * function ProductPage() {
242
+ * const { setAmount } = useSwypeDepositAmount();
243
+ * useEffect(() => { setAmount(25.00); }, []);
244
+ * return <SwypePayment destination={dest} />;
245
+ * }
246
+ * ```
247
+ */
248
+ declare function useSwypeDepositAmount(): {
249
+ /** Current deposit amount, or null if not set */
250
+ amount: number | null;
251
+ /** Set the deposit amount (pass null to clear) */
252
+ setAmount: (amount: number | null) => void;
253
+ };
204
254
 
205
255
  interface SwypePaymentProps {
206
256
  /**
@@ -233,13 +283,28 @@ interface UseAuthorizationExecutorResult {
233
283
  executing: boolean;
234
284
  results: ActionExecutionResult[];
235
285
  error: string | null;
286
+ /** The current action being executed (for UI display). */
287
+ currentAction: AuthorizationAction | null;
288
+ /** The SELECT_SOURCE action when paused for user selection, null otherwise. */
289
+ pendingSelectSource: AuthorizationAction | null;
290
+ /** Call this from the UI to provide the user's chain+token choice. */
291
+ resolveSelectSource: (selection: SourceSelection) => void;
236
292
  executeSession: (transfer: Transfer) => Promise<void>;
237
293
  }
238
294
  /**
239
295
  * Executes the full authorization flow for a transfer's first session:
240
296
  * fetches the session, walks through PENDING actions (OPEN_PROVIDER,
241
- * SWITCH_CHAIN, APPROVE_PERMIT_2, SIGN_PERMIT2), reports each completion
242
- * to the server, and chains new actions that appear.
297
+ * REGISTER_PASSKEY, UPGRADE_SMART_ACCOUNT, GRANT_PERMISSIONS,
298
+ * SELECT_SOURCE), reports each completion to the server, and chains
299
+ * new actions that appear.
300
+ *
301
+ * Transfer signing (passkey) is handled separately via
302
+ * `useTransferSigning()` after the authorization flow completes.
303
+ *
304
+ * When a SELECT_SOURCE action is encountered, the executor pauses and
305
+ * exposes the action via `pendingSelectSource`. The UI should display
306
+ * a chain+token selector and call `resolveSelectSource()` with the
307
+ * user's choice. The executor then resumes automatically.
243
308
  */
244
309
  declare function useAuthorizationExecutor(): UseAuthorizationExecutorResult;
245
310
 
@@ -255,10 +320,25 @@ interface CreateTransferParams {
255
320
  }
256
321
  declare function createTransfer(apiBaseUrl: string, token: string, params: CreateTransferParams): Promise<Transfer>;
257
322
  declare function fetchTransfer(apiBaseUrl: string, token: string, transferId: string): Promise<Transfer>;
323
+ /**
324
+ * Submit a passkey-signed UserOperation for a transfer.
325
+ * PATCH /v1/transfers/{transferId}
326
+ */
327
+ declare function signTransfer(apiBaseUrl: string, token: string, transferId: string, signedUserOp: Record<string, unknown>): Promise<Transfer>;
258
328
  declare function fetchAuthorizationSession(apiBaseUrl: string, sessionId: string): Promise<AuthorizationSessionDetail>;
259
329
  declare function updateUserConfig(apiBaseUrl: string, token: string, config: {
260
330
  defaultAllowance: number;
261
331
  }): Promise<void>;
332
+ /**
333
+ * Updates the user's default allowance, authenticated by session ID.
334
+ * PATCH /v1/authorization-sessions/{id}/user-config
335
+ *
336
+ * This does not require a bearer token — the session ID itself serves
337
+ * as proof of authorization.
338
+ */
339
+ declare function updateUserConfigBySession(apiBaseUrl: string, sessionId: string, config: {
340
+ defaultAllowance: number;
341
+ }): Promise<void>;
262
342
  declare function reportActionCompletion(apiBaseUrl: string, actionId: string, result: Record<string, unknown>): Promise<AuthorizationSessionDetail>;
263
343
 
264
344
  type api_CreateTransferParams = CreateTransferParams;
@@ -269,9 +349,11 @@ declare const api_fetchChains: typeof fetchChains;
269
349
  declare const api_fetchProviders: typeof fetchProviders;
270
350
  declare const api_fetchTransfer: typeof fetchTransfer;
271
351
  declare const api_reportActionCompletion: typeof reportActionCompletion;
352
+ declare const api_signTransfer: typeof signTransfer;
272
353
  declare const api_updateUserConfig: typeof updateUserConfig;
354
+ declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
273
355
  declare namespace api {
274
- export { type api_CreateTransferParams as CreateTransferParams, api_createTransfer as createTransfer, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_reportActionCompletion as reportActionCompletion, api_updateUserConfig as updateUserConfig };
356
+ export { type api_CreateTransferParams as CreateTransferParams, api_createTransfer as createTransfer, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_reportActionCompletion as reportActionCompletion, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
275
357
  }
276
358
 
277
- export { type Account, type ActionExecutionResult, type Amount, type AuthorizationAction, type AuthorizationSession, type AuthorizationSessionDetail, type Chain, type Destination, type ErrorResponse, type ListResponse, type PaymentStep, type Provider, type SourceType, SwypePayment, type SwypePaymentProps, SwypeProvider, type SwypeProviderProps, type ThemeMode, type ThemeTokens, type TokenBalance, type Transfer, type TransferDestination, type UserConfig, type Wallet, type WalletSource, type WalletToken, darkTheme, getTheme, lightTheme, api as swypeApi, useAuthorizationExecutor, useSwypeConfig, useTransferPolling };
359
+ export { type Account, type ActionExecutionResult, type AdvancedSettings, type Amount, type AuthorizationAction, type AuthorizationSession, type AuthorizationSessionDetail, type Chain, type Destination, type ErrorResponse, type ListResponse, type PaymentStep, type Provider, type SourceType, SwypePayment, type SwypePaymentProps, SwypeProvider, type SwypeProviderProps, type ThemeMode, type ThemeTokens, type TokenBalance, type Transfer, type TransferDestination, type UserConfig, type Wallet, type WalletSource, type WalletToken, darkTheme, getTheme, lightTheme, api as swypeApi, useAuthorizationExecutor, useSwypeConfig, useSwypeDepositAmount, useTransferPolling };