@swype-org/react-sdk 0.1.4 → 0.1.5

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
@@ -94,6 +94,8 @@ interface TransferSignPayload {
94
94
  userOp: Record<string, unknown>;
95
95
  /** ERC-4337 UserOp hash — used as the WebAuthn challenge for on-chain verification. */
96
96
  userOpHash: string;
97
+ /** WebAuthn credential ID bound to the smart account validator. */
98
+ passkeyCredentialId: string;
97
99
  bridgeRelayAddress: string;
98
100
  tokenSymbol: string;
99
101
  chainName: string;
@@ -137,6 +139,15 @@ interface ActionExecutionResult {
137
139
  }
138
140
  /** Source type discriminator for transfer creation */
139
141
  type SourceType = 'providerId' | 'accountId' | 'walletId' | 'tokenId';
142
+ /** A chain+token option from the SELECT_SOURCE action metadata. */
143
+ interface SourceOption {
144
+ chainName: string;
145
+ chainId: string;
146
+ tokenSymbol: string;
147
+ tokenAddress: string;
148
+ decimals: number;
149
+ rawBalance: string;
150
+ }
140
151
  /** User's chain+token selection for the SELECT_SOURCE action. */
141
152
  interface SourceSelection {
142
153
  chainName: string;
@@ -157,11 +168,16 @@ interface ListResponse<T> {
157
168
  /** User configuration preferences */
158
169
  interface UserConfig {
159
170
  defaultAllowance?: number;
171
+ /** Registered WebAuthn passkey credential, or null if none registered */
172
+ passkey?: {
173
+ credentialId: string;
174
+ publicKey: string;
175
+ } | null;
160
176
  }
161
177
  /** Theme mode */
162
178
  type ThemeMode = 'light' | 'dark';
163
179
  /** Steps in the payment flow */
164
- type PaymentStep = 'login' | 'enter-amount' | 'ready' | 'processing' | 'complete';
180
+ type PaymentStep = 'login' | 'register-passkey' | 'enter-amount' | 'ready' | 'processing' | 'complete';
165
181
  /** User-selected advanced settings for chain/asset override */
166
182
  interface AdvancedSettings {
167
183
  /** Override asset (e.g. 'USDC', 'USDT'). Null = let backend decide. */
@@ -267,6 +283,19 @@ interface SwypePaymentProps {
267
283
  }
268
284
  declare function SwypePayment({ destination, onComplete, onError, }: SwypePaymentProps): react_jsx_runtime.JSX.Element | null;
269
285
 
286
+ type AccessTokenGetter = () => Promise<string | null | undefined>;
287
+ /**
288
+ * Creates a WebAuthn passkey credential.
289
+ * Used for upfront passkey registration before the authorization flow.
290
+ *
291
+ * @param userIdentifier - A string used to identify the user in the
292
+ * WebAuthn ceremony (e.g. wallet address or Privy user ID).
293
+ * @returns The base64-encoded credentialId and publicKey.
294
+ */
295
+ declare function createPasskeyCredential(userIdentifier: string): Promise<{
296
+ credentialId: string;
297
+ publicKey: string;
298
+ }>;
270
299
  interface UseTransferPollingResult {
271
300
  transfer: Transfer | null;
272
301
  error: string | null;
@@ -289,8 +318,14 @@ interface UseAuthorizationExecutorResult {
289
318
  pendingSelectSource: AuthorizationAction | null;
290
319
  /** Call this from the UI to provide the user's chain+token choice. */
291
320
  resolveSelectSource: (selection: SourceSelection) => void;
321
+ /** Execute authorization by session id. */
322
+ executeSessionById: (sessionId: string) => Promise<void>;
292
323
  executeSession: (transfer: Transfer) => Promise<void>;
293
324
  }
325
+ interface UseAuthorizationExecutorOptions {
326
+ /** Optional API base URL override when used outside SwypeProvider. */
327
+ apiBaseUrl?: string;
328
+ }
294
329
  /**
295
330
  * Executes the full authorization flow for a transfer's first session:
296
331
  * fetches the session, walks through PENDING actions, reports each
@@ -300,20 +335,43 @@ interface UseAuthorizationExecutorResult {
300
335
  * - OPEN_PROVIDER — connect the user's wallet
301
336
  * - SELECT_SOURCE — pause for user chain+token selection
302
337
  * - SWITCH_CHAIN — switch the wallet to the required chain
303
- * - REGISTER_PASSKEY — create a WebAuthn passkey credential
304
338
  * - CREATE_SMART_ACCOUNT — server-side smart account deployment
305
339
  * - APPROVE_PERMIT2 — ERC-20 approve(permit2, maxUint256) from EOA
306
340
  * - SIGN_PERMIT2 — EIP-712 Permit2 allowance signature from EOA
307
341
  *
308
342
  * Transfer signing (passkey) is handled separately via
309
343
  * `useTransferSigning()` after the authorization flow completes.
344
+ */
345
+ declare function useAuthorizationExecutor(options?: UseAuthorizationExecutorOptions): UseAuthorizationExecutorResult;
346
+ interface UseTransferSigningResult {
347
+ signing: boolean;
348
+ signPayload: TransferSignPayload | null;
349
+ error: string | null;
350
+ /**
351
+ * Starts the signing flow:
352
+ * 1. Polls GET /v1/transfers/{id} until signPayload is present
353
+ * 2. Triggers WebAuthn passkey prompt
354
+ * 3. Submits signed UserOp via PATCH /v1/transfers/{id}
355
+ */
356
+ signTransfer: (transferId: string) => Promise<Transfer>;
357
+ }
358
+ interface UseTransferSigningOptions {
359
+ /** Optional API base URL override when used outside SwypeProvider. */
360
+ apiBaseUrl?: string;
361
+ /** Optional access-token getter override (e.g. deeplink query token). */
362
+ getAccessToken?: AccessTokenGetter;
363
+ /** Optional authorization-session token for session-authenticated transfer signing. */
364
+ authorizationSessionToken?: string;
365
+ }
366
+ /**
367
+ * Post-authorization transfer signing hook.
310
368
  *
311
- * When a SELECT_SOURCE action is encountered, the executor pauses and
312
- * exposes the action via `pendingSelectSource`. The UI should display
313
- * a chain+token selector and call `resolveSelectSource()` with the
314
- * user's choice. The executor then resumes automatically.
369
+ * After the auth session completes and the transfer reaches AUTHORIZED,
370
+ * the backend prepares a signPayload containing the unsigned UserOp.
371
+ * This hook polls for it, prompts the user's passkey via WebAuthn, and
372
+ * submits the signed UserOp back to the API.
315
373
  */
316
- declare function useAuthorizationExecutor(): UseAuthorizationExecutorResult;
374
+ declare function useTransferSigning(pollIntervalMs?: number, options?: UseTransferSigningOptions): UseTransferSigningResult;
317
375
 
318
376
  declare function fetchProviders(apiBaseUrl: string, token: string): Promise<Provider[]>;
319
377
  declare function fetchChains(apiBaseUrl: string, token: string): Promise<Chain[]>;
@@ -326,13 +384,26 @@ interface CreateTransferParams {
326
384
  currency?: string;
327
385
  }
328
386
  declare function createTransfer(apiBaseUrl: string, token: string, params: CreateTransferParams): Promise<Transfer>;
329
- declare function fetchTransfer(apiBaseUrl: string, token: string, transferId: string): Promise<Transfer>;
387
+ declare function fetchTransfer(apiBaseUrl: string, token: string, transferId: string, authorizationSessionToken?: string): Promise<Transfer>;
330
388
  /**
331
389
  * Submit a passkey-signed UserOperation for a transfer.
332
390
  * PATCH /v1/transfers/{transferId}
333
391
  */
334
- declare function signTransfer(apiBaseUrl: string, token: string, transferId: string, signedUserOp: Record<string, unknown>): Promise<Transfer>;
392
+ declare function signTransfer(apiBaseUrl: string, token: string, transferId: string, signedUserOp: Record<string, unknown>, authorizationSessionToken?: string): Promise<Transfer>;
335
393
  declare function fetchAuthorizationSession(apiBaseUrl: string, sessionId: string): Promise<AuthorizationSessionDetail>;
394
+ /**
395
+ * Registers a WebAuthn passkey for the authenticated user.
396
+ * POST /v1/users/config/passkey
397
+ */
398
+ declare function registerPasskey(apiBaseUrl: string, token: string, credentialId: string, publicKey: string): Promise<void>;
399
+ /**
400
+ * Fetches the authenticated user's config, including passkey status.
401
+ * GET /v1/users/config
402
+ */
403
+ declare function fetchUserConfig(apiBaseUrl: string, token: string): Promise<{
404
+ id: string;
405
+ config: UserConfig;
406
+ }>;
336
407
  declare function updateUserConfig(apiBaseUrl: string, token: string, config: {
337
408
  defaultAllowance: number;
338
409
  }): Promise<void>;
@@ -355,12 +426,14 @@ declare const api_fetchAuthorizationSession: typeof fetchAuthorizationSession;
355
426
  declare const api_fetchChains: typeof fetchChains;
356
427
  declare const api_fetchProviders: typeof fetchProviders;
357
428
  declare const api_fetchTransfer: typeof fetchTransfer;
429
+ declare const api_fetchUserConfig: typeof fetchUserConfig;
430
+ declare const api_registerPasskey: typeof registerPasskey;
358
431
  declare const api_reportActionCompletion: typeof reportActionCompletion;
359
432
  declare const api_signTransfer: typeof signTransfer;
360
433
  declare const api_updateUserConfig: typeof updateUserConfig;
361
434
  declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
362
435
  declare namespace api {
363
- 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 };
436
+ 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_fetchUserConfig as fetchUserConfig, api_registerPasskey as registerPasskey, api_reportActionCompletion as reportActionCompletion, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
364
437
  }
365
438
 
366
- 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 };
439
+ 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 SourceOption, type SourceSelection, 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, createPasskeyCredential, darkTheme, getTheme, lightTheme, api as swypeApi, useAuthorizationExecutor, useSwypeConfig, useSwypeDepositAmount, useTransferPolling, useTransferSigning };
package/dist/index.d.ts CHANGED
@@ -94,6 +94,8 @@ interface TransferSignPayload {
94
94
  userOp: Record<string, unknown>;
95
95
  /** ERC-4337 UserOp hash — used as the WebAuthn challenge for on-chain verification. */
96
96
  userOpHash: string;
97
+ /** WebAuthn credential ID bound to the smart account validator. */
98
+ passkeyCredentialId: string;
97
99
  bridgeRelayAddress: string;
98
100
  tokenSymbol: string;
99
101
  chainName: string;
@@ -137,6 +139,15 @@ interface ActionExecutionResult {
137
139
  }
138
140
  /** Source type discriminator for transfer creation */
139
141
  type SourceType = 'providerId' | 'accountId' | 'walletId' | 'tokenId';
142
+ /** A chain+token option from the SELECT_SOURCE action metadata. */
143
+ interface SourceOption {
144
+ chainName: string;
145
+ chainId: string;
146
+ tokenSymbol: string;
147
+ tokenAddress: string;
148
+ decimals: number;
149
+ rawBalance: string;
150
+ }
140
151
  /** User's chain+token selection for the SELECT_SOURCE action. */
141
152
  interface SourceSelection {
142
153
  chainName: string;
@@ -157,11 +168,16 @@ interface ListResponse<T> {
157
168
  /** User configuration preferences */
158
169
  interface UserConfig {
159
170
  defaultAllowance?: number;
171
+ /** Registered WebAuthn passkey credential, or null if none registered */
172
+ passkey?: {
173
+ credentialId: string;
174
+ publicKey: string;
175
+ } | null;
160
176
  }
161
177
  /** Theme mode */
162
178
  type ThemeMode = 'light' | 'dark';
163
179
  /** Steps in the payment flow */
164
- type PaymentStep = 'login' | 'enter-amount' | 'ready' | 'processing' | 'complete';
180
+ type PaymentStep = 'login' | 'register-passkey' | 'enter-amount' | 'ready' | 'processing' | 'complete';
165
181
  /** User-selected advanced settings for chain/asset override */
166
182
  interface AdvancedSettings {
167
183
  /** Override asset (e.g. 'USDC', 'USDT'). Null = let backend decide. */
@@ -267,6 +283,19 @@ interface SwypePaymentProps {
267
283
  }
268
284
  declare function SwypePayment({ destination, onComplete, onError, }: SwypePaymentProps): react_jsx_runtime.JSX.Element | null;
269
285
 
286
+ type AccessTokenGetter = () => Promise<string | null | undefined>;
287
+ /**
288
+ * Creates a WebAuthn passkey credential.
289
+ * Used for upfront passkey registration before the authorization flow.
290
+ *
291
+ * @param userIdentifier - A string used to identify the user in the
292
+ * WebAuthn ceremony (e.g. wallet address or Privy user ID).
293
+ * @returns The base64-encoded credentialId and publicKey.
294
+ */
295
+ declare function createPasskeyCredential(userIdentifier: string): Promise<{
296
+ credentialId: string;
297
+ publicKey: string;
298
+ }>;
270
299
  interface UseTransferPollingResult {
271
300
  transfer: Transfer | null;
272
301
  error: string | null;
@@ -289,8 +318,14 @@ interface UseAuthorizationExecutorResult {
289
318
  pendingSelectSource: AuthorizationAction | null;
290
319
  /** Call this from the UI to provide the user's chain+token choice. */
291
320
  resolveSelectSource: (selection: SourceSelection) => void;
321
+ /** Execute authorization by session id. */
322
+ executeSessionById: (sessionId: string) => Promise<void>;
292
323
  executeSession: (transfer: Transfer) => Promise<void>;
293
324
  }
325
+ interface UseAuthorizationExecutorOptions {
326
+ /** Optional API base URL override when used outside SwypeProvider. */
327
+ apiBaseUrl?: string;
328
+ }
294
329
  /**
295
330
  * Executes the full authorization flow for a transfer's first session:
296
331
  * fetches the session, walks through PENDING actions, reports each
@@ -300,20 +335,43 @@ interface UseAuthorizationExecutorResult {
300
335
  * - OPEN_PROVIDER — connect the user's wallet
301
336
  * - SELECT_SOURCE — pause for user chain+token selection
302
337
  * - SWITCH_CHAIN — switch the wallet to the required chain
303
- * - REGISTER_PASSKEY — create a WebAuthn passkey credential
304
338
  * - CREATE_SMART_ACCOUNT — server-side smart account deployment
305
339
  * - APPROVE_PERMIT2 — ERC-20 approve(permit2, maxUint256) from EOA
306
340
  * - SIGN_PERMIT2 — EIP-712 Permit2 allowance signature from EOA
307
341
  *
308
342
  * Transfer signing (passkey) is handled separately via
309
343
  * `useTransferSigning()` after the authorization flow completes.
344
+ */
345
+ declare function useAuthorizationExecutor(options?: UseAuthorizationExecutorOptions): UseAuthorizationExecutorResult;
346
+ interface UseTransferSigningResult {
347
+ signing: boolean;
348
+ signPayload: TransferSignPayload | null;
349
+ error: string | null;
350
+ /**
351
+ * Starts the signing flow:
352
+ * 1. Polls GET /v1/transfers/{id} until signPayload is present
353
+ * 2. Triggers WebAuthn passkey prompt
354
+ * 3. Submits signed UserOp via PATCH /v1/transfers/{id}
355
+ */
356
+ signTransfer: (transferId: string) => Promise<Transfer>;
357
+ }
358
+ interface UseTransferSigningOptions {
359
+ /** Optional API base URL override when used outside SwypeProvider. */
360
+ apiBaseUrl?: string;
361
+ /** Optional access-token getter override (e.g. deeplink query token). */
362
+ getAccessToken?: AccessTokenGetter;
363
+ /** Optional authorization-session token for session-authenticated transfer signing. */
364
+ authorizationSessionToken?: string;
365
+ }
366
+ /**
367
+ * Post-authorization transfer signing hook.
310
368
  *
311
- * When a SELECT_SOURCE action is encountered, the executor pauses and
312
- * exposes the action via `pendingSelectSource`. The UI should display
313
- * a chain+token selector and call `resolveSelectSource()` with the
314
- * user's choice. The executor then resumes automatically.
369
+ * After the auth session completes and the transfer reaches AUTHORIZED,
370
+ * the backend prepares a signPayload containing the unsigned UserOp.
371
+ * This hook polls for it, prompts the user's passkey via WebAuthn, and
372
+ * submits the signed UserOp back to the API.
315
373
  */
316
- declare function useAuthorizationExecutor(): UseAuthorizationExecutorResult;
374
+ declare function useTransferSigning(pollIntervalMs?: number, options?: UseTransferSigningOptions): UseTransferSigningResult;
317
375
 
318
376
  declare function fetchProviders(apiBaseUrl: string, token: string): Promise<Provider[]>;
319
377
  declare function fetchChains(apiBaseUrl: string, token: string): Promise<Chain[]>;
@@ -326,13 +384,26 @@ interface CreateTransferParams {
326
384
  currency?: string;
327
385
  }
328
386
  declare function createTransfer(apiBaseUrl: string, token: string, params: CreateTransferParams): Promise<Transfer>;
329
- declare function fetchTransfer(apiBaseUrl: string, token: string, transferId: string): Promise<Transfer>;
387
+ declare function fetchTransfer(apiBaseUrl: string, token: string, transferId: string, authorizationSessionToken?: string): Promise<Transfer>;
330
388
  /**
331
389
  * Submit a passkey-signed UserOperation for a transfer.
332
390
  * PATCH /v1/transfers/{transferId}
333
391
  */
334
- declare function signTransfer(apiBaseUrl: string, token: string, transferId: string, signedUserOp: Record<string, unknown>): Promise<Transfer>;
392
+ declare function signTransfer(apiBaseUrl: string, token: string, transferId: string, signedUserOp: Record<string, unknown>, authorizationSessionToken?: string): Promise<Transfer>;
335
393
  declare function fetchAuthorizationSession(apiBaseUrl: string, sessionId: string): Promise<AuthorizationSessionDetail>;
394
+ /**
395
+ * Registers a WebAuthn passkey for the authenticated user.
396
+ * POST /v1/users/config/passkey
397
+ */
398
+ declare function registerPasskey(apiBaseUrl: string, token: string, credentialId: string, publicKey: string): Promise<void>;
399
+ /**
400
+ * Fetches the authenticated user's config, including passkey status.
401
+ * GET /v1/users/config
402
+ */
403
+ declare function fetchUserConfig(apiBaseUrl: string, token: string): Promise<{
404
+ id: string;
405
+ config: UserConfig;
406
+ }>;
336
407
  declare function updateUserConfig(apiBaseUrl: string, token: string, config: {
337
408
  defaultAllowance: number;
338
409
  }): Promise<void>;
@@ -355,12 +426,14 @@ declare const api_fetchAuthorizationSession: typeof fetchAuthorizationSession;
355
426
  declare const api_fetchChains: typeof fetchChains;
356
427
  declare const api_fetchProviders: typeof fetchProviders;
357
428
  declare const api_fetchTransfer: typeof fetchTransfer;
429
+ declare const api_fetchUserConfig: typeof fetchUserConfig;
430
+ declare const api_registerPasskey: typeof registerPasskey;
358
431
  declare const api_reportActionCompletion: typeof reportActionCompletion;
359
432
  declare const api_signTransfer: typeof signTransfer;
360
433
  declare const api_updateUserConfig: typeof updateUserConfig;
361
434
  declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
362
435
  declare namespace api {
363
- 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 };
436
+ 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_fetchUserConfig as fetchUserConfig, api_registerPasskey as registerPasskey, api_reportActionCompletion as reportActionCompletion, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
364
437
  }
365
438
 
366
- 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 };
439
+ 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 SourceOption, type SourceSelection, 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, createPasskeyCredential, darkTheme, getTheme, lightTheme, api as swypeApi, useAuthorizationExecutor, useSwypeConfig, useSwypeDepositAmount, useTransferPolling, useTransferSigning };