@swype-org/react-sdk 0.1.2 → 0.1.4
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.cjs +682 -446
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -20
- package/dist/index.d.ts +37 -20
- package/dist/index.js +684 -448
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.d.cts
CHANGED
|
@@ -27,11 +27,6 @@ interface WalletSource {
|
|
|
27
27
|
token: WalletToken;
|
|
28
28
|
balance: TokenBalance;
|
|
29
29
|
}
|
|
30
|
-
/** Token + chain most recently authorized via Permit2 for a wallet */
|
|
31
|
-
interface LastAuthorizedToken {
|
|
32
|
-
symbol: string;
|
|
33
|
-
chainName: string;
|
|
34
|
-
}
|
|
35
30
|
/** Full wallet with chain, balance, and token sources */
|
|
36
31
|
interface Wallet {
|
|
37
32
|
id: string;
|
|
@@ -43,8 +38,8 @@ interface Wallet {
|
|
|
43
38
|
id: string;
|
|
44
39
|
name: string;
|
|
45
40
|
};
|
|
46
|
-
/** The
|
|
47
|
-
|
|
41
|
+
/** The smart account type (e.g. 'metamask'), if a smart account has been created. */
|
|
42
|
+
smartAccountType?: string | null;
|
|
48
43
|
createDate: string;
|
|
49
44
|
updateDate: string;
|
|
50
45
|
authorizationSessions?: AuthorizationSession[];
|
|
@@ -94,6 +89,17 @@ interface TransferDestination {
|
|
|
94
89
|
};
|
|
95
90
|
amount: Amount;
|
|
96
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
|
+
}
|
|
97
103
|
/** Transfer object returned by the API */
|
|
98
104
|
interface Transfer {
|
|
99
105
|
id: string;
|
|
@@ -109,6 +115,7 @@ interface Transfer {
|
|
|
109
115
|
createDate: string;
|
|
110
116
|
updateDate: string;
|
|
111
117
|
authorizationSessions: AuthorizationSession[];
|
|
118
|
+
signPayload?: TransferSignPayload | null;
|
|
112
119
|
}
|
|
113
120
|
/** Standard API error shape */
|
|
114
121
|
interface ErrorResponse {
|
|
@@ -162,11 +169,6 @@ interface AdvancedSettings {
|
|
|
162
169
|
/** Override chain name (e.g. 'Base', 'Ethereum'). Null = let backend decide. */
|
|
163
170
|
chain: string | null;
|
|
164
171
|
}
|
|
165
|
-
/** User's top-up allowance selection for the SIGN_PERMIT2 action. */
|
|
166
|
-
interface AllowanceSelection {
|
|
167
|
-
/** Extra amount (in human-readable units, e.g. 100 = $100) to add on top of the transfer amount. */
|
|
168
|
-
topUpAmount: number;
|
|
169
|
-
}
|
|
170
172
|
|
|
171
173
|
interface ThemeTokens {
|
|
172
174
|
bg: string;
|
|
@@ -281,21 +283,30 @@ interface UseAuthorizationExecutorResult {
|
|
|
281
283
|
executing: boolean;
|
|
282
284
|
results: ActionExecutionResult[];
|
|
283
285
|
error: string | null;
|
|
286
|
+
/** The current action being executed (for UI display). */
|
|
287
|
+
currentAction: AuthorizationAction | null;
|
|
284
288
|
/** The SELECT_SOURCE action when paused for user selection, null otherwise. */
|
|
285
289
|
pendingSelectSource: AuthorizationAction | null;
|
|
286
290
|
/** Call this from the UI to provide the user's chain+token choice. */
|
|
287
291
|
resolveSelectSource: (selection: SourceSelection) => void;
|
|
288
|
-
/** The SIGN_PERMIT2 action when paused for allowance selection, null otherwise. */
|
|
289
|
-
pendingAllowanceSelection: AuthorizationAction | null;
|
|
290
|
-
/** Call this from the UI to provide the user's top-up allowance choice. */
|
|
291
|
-
resolveAllowanceSelection: (selection: AllowanceSelection) => void;
|
|
292
292
|
executeSession: (transfer: Transfer) => Promise<void>;
|
|
293
293
|
}
|
|
294
294
|
/**
|
|
295
295
|
* Executes the full authorization flow for a transfer's first session:
|
|
296
|
-
* fetches the session, walks through PENDING actions
|
|
297
|
-
*
|
|
298
|
-
*
|
|
296
|
+
* fetches the session, walks through PENDING actions, reports each
|
|
297
|
+
* completion to the server, and chains new actions that appear.
|
|
298
|
+
*
|
|
299
|
+
* Supported action types:
|
|
300
|
+
* - OPEN_PROVIDER — connect the user's wallet
|
|
301
|
+
* - SELECT_SOURCE — pause for user chain+token selection
|
|
302
|
+
* - SWITCH_CHAIN — switch the wallet to the required chain
|
|
303
|
+
* - REGISTER_PASSKEY — create a WebAuthn passkey credential
|
|
304
|
+
* - CREATE_SMART_ACCOUNT — server-side smart account deployment
|
|
305
|
+
* - APPROVE_PERMIT2 — ERC-20 approve(permit2, maxUint256) from EOA
|
|
306
|
+
* - SIGN_PERMIT2 — EIP-712 Permit2 allowance signature from EOA
|
|
307
|
+
*
|
|
308
|
+
* Transfer signing (passkey) is handled separately via
|
|
309
|
+
* `useTransferSigning()` after the authorization flow completes.
|
|
299
310
|
*
|
|
300
311
|
* When a SELECT_SOURCE action is encountered, the executor pauses and
|
|
301
312
|
* exposes the action via `pendingSelectSource`. The UI should display
|
|
@@ -316,6 +327,11 @@ interface CreateTransferParams {
|
|
|
316
327
|
}
|
|
317
328
|
declare function createTransfer(apiBaseUrl: string, token: string, params: CreateTransferParams): Promise<Transfer>;
|
|
318
329
|
declare function fetchTransfer(apiBaseUrl: string, token: string, transferId: string): Promise<Transfer>;
|
|
330
|
+
/**
|
|
331
|
+
* Submit a passkey-signed UserOperation for a transfer.
|
|
332
|
+
* PATCH /v1/transfers/{transferId}
|
|
333
|
+
*/
|
|
334
|
+
declare function signTransfer(apiBaseUrl: string, token: string, transferId: string, signedUserOp: Record<string, unknown>): Promise<Transfer>;
|
|
319
335
|
declare function fetchAuthorizationSession(apiBaseUrl: string, sessionId: string): Promise<AuthorizationSessionDetail>;
|
|
320
336
|
declare function updateUserConfig(apiBaseUrl: string, token: string, config: {
|
|
321
337
|
defaultAllowance: number;
|
|
@@ -340,10 +356,11 @@ declare const api_fetchChains: typeof fetchChains;
|
|
|
340
356
|
declare const api_fetchProviders: typeof fetchProviders;
|
|
341
357
|
declare const api_fetchTransfer: typeof fetchTransfer;
|
|
342
358
|
declare const api_reportActionCompletion: typeof reportActionCompletion;
|
|
359
|
+
declare const api_signTransfer: typeof signTransfer;
|
|
343
360
|
declare const api_updateUserConfig: typeof updateUserConfig;
|
|
344
361
|
declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
|
|
345
362
|
declare namespace api {
|
|
346
|
-
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, api_updateUserConfigBySession as updateUserConfigBySession };
|
|
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 };
|
|
347
364
|
}
|
|
348
365
|
|
|
349
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -27,11 +27,6 @@ interface WalletSource {
|
|
|
27
27
|
token: WalletToken;
|
|
28
28
|
balance: TokenBalance;
|
|
29
29
|
}
|
|
30
|
-
/** Token + chain most recently authorized via Permit2 for a wallet */
|
|
31
|
-
interface LastAuthorizedToken {
|
|
32
|
-
symbol: string;
|
|
33
|
-
chainName: string;
|
|
34
|
-
}
|
|
35
30
|
/** Full wallet with chain, balance, and token sources */
|
|
36
31
|
interface Wallet {
|
|
37
32
|
id: string;
|
|
@@ -43,8 +38,8 @@ interface Wallet {
|
|
|
43
38
|
id: string;
|
|
44
39
|
name: string;
|
|
45
40
|
};
|
|
46
|
-
/** The
|
|
47
|
-
|
|
41
|
+
/** The smart account type (e.g. 'metamask'), if a smart account has been created. */
|
|
42
|
+
smartAccountType?: string | null;
|
|
48
43
|
createDate: string;
|
|
49
44
|
updateDate: string;
|
|
50
45
|
authorizationSessions?: AuthorizationSession[];
|
|
@@ -94,6 +89,17 @@ interface TransferDestination {
|
|
|
94
89
|
};
|
|
95
90
|
amount: Amount;
|
|
96
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
|
+
}
|
|
97
103
|
/** Transfer object returned by the API */
|
|
98
104
|
interface Transfer {
|
|
99
105
|
id: string;
|
|
@@ -109,6 +115,7 @@ interface Transfer {
|
|
|
109
115
|
createDate: string;
|
|
110
116
|
updateDate: string;
|
|
111
117
|
authorizationSessions: AuthorizationSession[];
|
|
118
|
+
signPayload?: TransferSignPayload | null;
|
|
112
119
|
}
|
|
113
120
|
/** Standard API error shape */
|
|
114
121
|
interface ErrorResponse {
|
|
@@ -162,11 +169,6 @@ interface AdvancedSettings {
|
|
|
162
169
|
/** Override chain name (e.g. 'Base', 'Ethereum'). Null = let backend decide. */
|
|
163
170
|
chain: string | null;
|
|
164
171
|
}
|
|
165
|
-
/** User's top-up allowance selection for the SIGN_PERMIT2 action. */
|
|
166
|
-
interface AllowanceSelection {
|
|
167
|
-
/** Extra amount (in human-readable units, e.g. 100 = $100) to add on top of the transfer amount. */
|
|
168
|
-
topUpAmount: number;
|
|
169
|
-
}
|
|
170
172
|
|
|
171
173
|
interface ThemeTokens {
|
|
172
174
|
bg: string;
|
|
@@ -281,21 +283,30 @@ interface UseAuthorizationExecutorResult {
|
|
|
281
283
|
executing: boolean;
|
|
282
284
|
results: ActionExecutionResult[];
|
|
283
285
|
error: string | null;
|
|
286
|
+
/** The current action being executed (for UI display). */
|
|
287
|
+
currentAction: AuthorizationAction | null;
|
|
284
288
|
/** The SELECT_SOURCE action when paused for user selection, null otherwise. */
|
|
285
289
|
pendingSelectSource: AuthorizationAction | null;
|
|
286
290
|
/** Call this from the UI to provide the user's chain+token choice. */
|
|
287
291
|
resolveSelectSource: (selection: SourceSelection) => void;
|
|
288
|
-
/** The SIGN_PERMIT2 action when paused for allowance selection, null otherwise. */
|
|
289
|
-
pendingAllowanceSelection: AuthorizationAction | null;
|
|
290
|
-
/** Call this from the UI to provide the user's top-up allowance choice. */
|
|
291
|
-
resolveAllowanceSelection: (selection: AllowanceSelection) => void;
|
|
292
292
|
executeSession: (transfer: Transfer) => Promise<void>;
|
|
293
293
|
}
|
|
294
294
|
/**
|
|
295
295
|
* Executes the full authorization flow for a transfer's first session:
|
|
296
|
-
* fetches the session, walks through PENDING actions
|
|
297
|
-
*
|
|
298
|
-
*
|
|
296
|
+
* fetches the session, walks through PENDING actions, reports each
|
|
297
|
+
* completion to the server, and chains new actions that appear.
|
|
298
|
+
*
|
|
299
|
+
* Supported action types:
|
|
300
|
+
* - OPEN_PROVIDER — connect the user's wallet
|
|
301
|
+
* - SELECT_SOURCE — pause for user chain+token selection
|
|
302
|
+
* - SWITCH_CHAIN — switch the wallet to the required chain
|
|
303
|
+
* - REGISTER_PASSKEY — create a WebAuthn passkey credential
|
|
304
|
+
* - CREATE_SMART_ACCOUNT — server-side smart account deployment
|
|
305
|
+
* - APPROVE_PERMIT2 — ERC-20 approve(permit2, maxUint256) from EOA
|
|
306
|
+
* - SIGN_PERMIT2 — EIP-712 Permit2 allowance signature from EOA
|
|
307
|
+
*
|
|
308
|
+
* Transfer signing (passkey) is handled separately via
|
|
309
|
+
* `useTransferSigning()` after the authorization flow completes.
|
|
299
310
|
*
|
|
300
311
|
* When a SELECT_SOURCE action is encountered, the executor pauses and
|
|
301
312
|
* exposes the action via `pendingSelectSource`. The UI should display
|
|
@@ -316,6 +327,11 @@ interface CreateTransferParams {
|
|
|
316
327
|
}
|
|
317
328
|
declare function createTransfer(apiBaseUrl: string, token: string, params: CreateTransferParams): Promise<Transfer>;
|
|
318
329
|
declare function fetchTransfer(apiBaseUrl: string, token: string, transferId: string): Promise<Transfer>;
|
|
330
|
+
/**
|
|
331
|
+
* Submit a passkey-signed UserOperation for a transfer.
|
|
332
|
+
* PATCH /v1/transfers/{transferId}
|
|
333
|
+
*/
|
|
334
|
+
declare function signTransfer(apiBaseUrl: string, token: string, transferId: string, signedUserOp: Record<string, unknown>): Promise<Transfer>;
|
|
319
335
|
declare function fetchAuthorizationSession(apiBaseUrl: string, sessionId: string): Promise<AuthorizationSessionDetail>;
|
|
320
336
|
declare function updateUserConfig(apiBaseUrl: string, token: string, config: {
|
|
321
337
|
defaultAllowance: number;
|
|
@@ -340,10 +356,11 @@ declare const api_fetchChains: typeof fetchChains;
|
|
|
340
356
|
declare const api_fetchProviders: typeof fetchProviders;
|
|
341
357
|
declare const api_fetchTransfer: typeof fetchTransfer;
|
|
342
358
|
declare const api_reportActionCompletion: typeof reportActionCompletion;
|
|
359
|
+
declare const api_signTransfer: typeof signTransfer;
|
|
343
360
|
declare const api_updateUserConfig: typeof updateUserConfig;
|
|
344
361
|
declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
|
|
345
362
|
declare namespace api {
|
|
346
|
-
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, api_updateUserConfigBySession as updateUserConfigBySession };
|
|
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 };
|
|
347
364
|
}
|
|
348
365
|
|
|
349
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 };
|