@swype-org/react-sdk 0.2.173 → 0.2.185

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
@@ -1,7 +1,8 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode, MouseEvent } from 'react';
2
+ import { ReactNode, MouseEvent, HTMLAttributeAnchorTarget } from 'react';
3
3
 
4
- /** Wallet provider (e.g. MetaMask) */
4
+ type ChainFamily = 'evm' | 'svm';
5
+ /** Wallet provider (e.g. MetaMask or Phantom) */
5
6
  interface Provider {
6
7
  id: string;
7
8
  name: string;
@@ -10,12 +11,15 @@ interface Provider {
10
11
  isDesktopCompatible: boolean;
11
12
  /** Whether this provider is available on mobile platforms. */
12
13
  isMobileCompatible: boolean;
14
+ /** Chain family this provider can connect to. */
15
+ chainFamily: ChainFamily;
13
16
  }
14
17
  /** Blockchain chain */
15
18
  interface Chain {
16
19
  id: string;
17
20
  name: string;
18
21
  commonId: number | null;
22
+ chainFamily: ChainFamily;
19
23
  }
20
24
  /** Token balance within a wallet source */
21
25
  interface TokenBalance {
@@ -30,7 +34,7 @@ interface WalletToken {
30
34
  /** A token source within a wallet (e.g. USDC on a specific chain) */
31
35
  interface WalletSource {
32
36
  id: string;
33
- /** On-chain ERC-20 contract address (e.g. 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913) */
37
+ /** On-chain token address: ERC-20 contract for EVM, mint address for SVM. */
34
38
  address: string;
35
39
  token: WalletToken;
36
40
  balance: TokenBalance;
@@ -126,8 +130,9 @@ interface TransferDestination {
126
130
  };
127
131
  amount: Amount;
128
132
  }
129
- /** Sign payload containing the unsigned UserOp and bridge/relay metadata */
130
- interface TransferSignPayload {
133
+ /** EVM sign payload containing the unsigned UserOp and bridge/relay metadata */
134
+ interface EvmTransferSignPayload {
135
+ chainFamily?: 'evm';
131
136
  userOp: Record<string, unknown>;
132
137
  /** ERC-4337 UserOp hash -- used as the WebAuthn challenge for on-chain verification. */
133
138
  userOpHash: string;
@@ -139,6 +144,23 @@ interface TransferSignPayload {
139
144
  amount: string;
140
145
  estimatedFeeUsd: string;
141
146
  }
147
+ /** SVM sign payload containing the raw Swig message to sign. */
148
+ interface SvmTransferSignPayload {
149
+ chainFamily: 'svm';
150
+ /** Base64-encoded Swig canonical message used directly as the WebAuthn challenge. */
151
+ message: string;
152
+ /** WebAuthn credential ID bound to the Swig root authority. */
153
+ passkeyCredentialId: string;
154
+ swigMetadataPda: string;
155
+ swigWalletPubkey: string;
156
+ bridgeRequestId: string;
157
+ bridgeProvider: string;
158
+ tokenSymbol: string;
159
+ chainName: string;
160
+ amount: string;
161
+ estimatedFeeUsd: string;
162
+ }
163
+ type TransferSignPayload = EvmTransferSignPayload | SvmTransferSignPayload;
142
164
  /** Transfer object returned by the API */
143
165
  interface Transfer {
144
166
  id: string;
@@ -445,7 +467,7 @@ declare function fetchTransfer(apiBaseUrl: string, token: string, transferId: st
445
467
  * Submit a passkey-signed UserOperation for a transfer.
446
468
  * PATCH /v1/transfers/{transferId}
447
469
  */
448
- declare function signTransfer(apiBaseUrl: string, token: string, transferId: string, signedUserOp: Record<string, unknown>, authorizationSessionToken?: string): Promise<Transfer>;
470
+ declare function signTransfer(apiBaseUrl: string, token: string, transferId: string, signedTransfer: Record<string, unknown>, authorizationSessionToken?: string): Promise<Transfer>;
449
471
  declare function fetchAuthorizationSession(apiBaseUrl: string, sessionId: string): Promise<AuthorizationSessionDetail>;
450
472
  declare function fetchAuthorizationSessionByToken(apiBaseUrl: string, token: string): Promise<AuthorizationSessionDetail>;
451
473
  /**
@@ -518,7 +540,8 @@ type ProbeActionCompletionResult = {
518
540
  * action as done.
519
541
  * - `detected: false, reason: 'not-found'` — scan completed with no match
520
542
  * (`DEPOSIT_TX_NOT_FOUND` for bridges, `APPROVE_NOT_DETECTED` for
521
- * approves); safe to prompt the wallet.
543
+ * EVM approves, `APPROVE_SPL_NOT_DETECTED` for Solana approves); safe to
544
+ * prompt the wallet.
522
545
  * - `detected: false, reason: 'invalid-state'` — transfer already advanced
523
546
  * past CREATED (race); the next orchestrator loop will observe it.
524
547
  * - `detected: false, reason: 'error'` — unexpected failure (network, 5xx);
@@ -588,7 +611,7 @@ interface SelectSourceChainChoice {
588
611
  }[];
589
612
  }
590
613
 
591
- type ScreenName = 'loading' | 'login' | 'success' | 'processing' | 'confirm-sign' | 'select-source' | 'setup' | 'open-wallet' | 'setup-deposit' | 'passkey-ready' | 'wallet-picker' | 'token-picker' | 'guest-source-picker' | 'deposit';
614
+ type ScreenName = 'loading' | 'login' | 'success' | 'processing' | 'confirm-sign' | 'select-source' | 'setup' | 'open-wallet' | 'setup-deposit' | 'passkey-ready' | 'wallet-picker' | 'token-picker' | 'guest-source-picker' | 'amount-too-low' | 'deposit';
592
615
  interface MobileFlowState {
593
616
  deeplinkUri: string;
594
617
  providerId: string | null;
@@ -634,6 +657,9 @@ type PaymentPhase = {
634
657
  step: 'failed';
635
658
  transfer: Transfer;
636
659
  error: string;
660
+ } | {
661
+ step: 'amount-too-low';
662
+ minAmountUsd: number;
637
663
  };
638
664
  declare function screenForPhase(phase: PaymentPhase): ScreenName;
639
665
 
@@ -701,6 +727,15 @@ declare function isUserDismissedAuthorizationError(err: unknown): boolean;
701
727
  /** True when the error represents any expected user-initiated cancellation of an authorization flow. */
702
728
  declare function isExpectedAuthorizationCancellation(err: unknown): boolean;
703
729
 
730
+ interface ExecuteSvmCombinedFirstTransferOptions {
731
+ /**
732
+ * Invoked once after Phantom's `signAllTransactions` returns and we
733
+ * begin polling Solana RPC for the SPL approval to confirm. UI uses
734
+ * this to swap "Confirm in Phantom" copy for a settlement spinner —
735
+ * mirroring `executeApproveSplSolana.onConfirming`.
736
+ */
737
+ onApproveSplConfirming?: (action: AuthorizationAction) => void;
738
+ }
704
739
  interface BatchedWalletCallsResult {
705
740
  txHash: string | undefined;
706
741
  actionResults: Array<{
@@ -719,12 +754,32 @@ type ExecutionResult = {
719
754
  status: 'cancelled';
720
755
  };
721
756
 
757
+ interface ExecuteActionOptions {
758
+ /** Forwarded to actions that may need server polling (e.g. SIGN_PERMIT2 typedData). */
759
+ sessionId?: string;
760
+ /**
761
+ * Forwarded to APPROVE_SPL: invoked once after the Phantom signature is
762
+ * returned and before client-side on-chain confirmation begins. The
763
+ * orchestrator can use this to render a "Confirming on Solana…" UI
764
+ * cue while the SDK polls for `confirmed`.
765
+ */
766
+ onApproveSplConfirming?: (action: AuthorizationAction) => void;
767
+ }
722
768
  interface UseAuthorizationExecutorResult {
723
769
  executing: boolean;
724
770
  results: ActionExecutionResult[];
725
771
  error: string | null;
726
772
  /** The current action being executed (for UI display). */
727
773
  currentAction: AuthorizationAction | null;
774
+ /**
775
+ * Set to the active APPROVE_SPL action while the SDK is awaiting
776
+ * client-side on-chain confirmation (after the Phantom signature has
777
+ * been returned but before `reportActionCompletion`). Cleared when
778
+ * the action settles or fails. UI surfaces use this to swap "confirm
779
+ * in Phantom" copy for "confirming on Solana…" — mirroring EVM's
780
+ * `waitForTransactionSettled` window.
781
+ */
782
+ approveSplConfirming: AuthorizationAction | null;
728
783
  /** The SELECT_SOURCE action when paused for user selection, null otherwise. */
729
784
  pendingSelectSource: AuthorizationAction | null;
730
785
  /** Call this from the UI to provide the user's chain+token choice. */
@@ -737,9 +792,7 @@ interface UseAuthorizationExecutorResult {
737
792
  * Execute a single authorization action. Sets `currentAction` for UI display.
738
793
  * Pass `sessionId` when the action may need server polling (e.g. SIGN_PERMIT2 typedData).
739
794
  */
740
- executeAction: (action: AuthorizationAction, options?: {
741
- sessionId?: string;
742
- }) => Promise<ActionExecutionResult>;
795
+ executeAction: (action: AuthorizationAction, options?: ExecuteActionOptions) => Promise<ActionExecutionResult>;
743
796
  /**
744
797
  * Execute batchable actions via EIP-5792 wallet_sendCalls.
745
798
  * Sets `batchTxHash` on success. The caller is responsible for reporting
@@ -751,6 +804,26 @@ interface UseAuthorizationExecutorResult {
751
804
  executeBatch: (actions: BatchedActionExecutionInput[], options?: {
752
805
  paymasterUrl?: string;
753
806
  }) => Promise<BatchedWalletCallsResult>;
807
+ /**
808
+ * SVM first-transfer combined path: signs the leading APPROVE_SPL +
809
+ * SVM EXECUTE_BRIDGE pair in a single Phantom prompt via
810
+ * `signAllTransactions`, submits the SPL approve via the configured
811
+ * client RPC, polls for confirmation, and returns the signed bridge
812
+ * tx for the orchestrator to forward to the server. The orchestrator
813
+ * iterates `actionResults` exactly as it does for `executeBatch`.
814
+ *
815
+ * Caller must pre-validate the pair via `isSvmCombinedFirstTransferPair`.
816
+ */
817
+ executeSvmCombinedFirstTransfer: (actions: BatchedActionExecutionInput[], options?: ExecuteSvmCombinedFirstTransferOptions) => Promise<BatchedWalletCallsResult>;
818
+ /**
819
+ * Probe whether the connected SVM wallet supports the
820
+ * `signAllTransactions` API used by `executeSvmCombinedFirstTransfer`.
821
+ * Pass the leading APPROVE_SPL action so we resolve the same
822
+ * `providerName` the combined path will use. Returns false on any
823
+ * connect/probe error so the orchestrator falls back to per-action
824
+ * SVM signing instead of throwing.
825
+ */
826
+ canSignAllSolanaTransactions: (action: AuthorizationAction) => Promise<boolean>;
754
827
  /** Refresh wallet capabilities and return whether atomicBatch is supported. */
755
828
  canBatch: () => Promise<boolean>;
756
829
  /** Check whether the connected wallet supports ERC-7677 paymasterService on the current chain. */
@@ -798,6 +871,7 @@ interface UseAuthorizationExecutorOptions {
798
871
  * - DEPLOY_SMART_ACCOUNT — server-side on-chain deployment via no-op UserOp
799
872
  * - APPROVE_PERMIT2 — ERC-20 approve(permit2, maxUint256) from EOA
800
873
  * - SIGN_PERMIT2 — EIP-712 Permit2 allowance signature from EOA
874
+ * - APPROVE_SPL — sign a server-built SPL delegate approval transaction
801
875
  * - EXECUTE_BRIDGE — on-chain bridge call(s)
802
876
  */
803
877
  declare function useAuthorizationExecutor(options?: UseAuthorizationExecutorOptions): UseAuthorizationExecutorResult;
@@ -809,8 +883,8 @@ type OrchestratorResult = {
809
883
  };
810
884
  interface OrchestratorRunOptions {
811
885
  /**
812
- * Called when the orchestrator encounters a SIGN_PERMIT2 action with
813
- * `awaitingLimit`. The callback should show the one-tap setup UI
886
+ * Called when the orchestrator encounters a SIGN_PERMIT2 or APPROVE_SPL
887
+ * action with `awaitingLimit`. The callback should show the one-tap setup UI
814
888
  * and return a Promise that resolves when the user completes (or
815
889
  * auto-resolves if the limit was already saved).
816
890
  *
@@ -835,7 +909,7 @@ interface OrchestratorRunOptions {
835
909
  alwaysPauseForOneTap?: boolean;
836
910
  /**
837
911
  * When true (default), before presenting the wallet for any of
838
- * APPROVE_PERMIT2 / SIGN_PERMIT2 / EXECUTE_BRIDGE on this run, probe
912
+ * APPROVE_PERMIT2 / SIGN_PERMIT2 / APPROVE_SPL / EXECUTE_BRIDGE on this run, probe
839
913
  * the server to see if the action is already satisfied on-chain (e.g.
840
914
  * user confirmed pre-reload but the PATCH never landed, signed in
841
915
  * another tab, or the wallet returned a stale error after broadcasting).
@@ -844,6 +918,7 @@ interface OrchestratorRunOptions {
844
918
  * - APPROVE_PERMIT2: backend re-checks ERC-20 allowance for Permit2.
845
919
  * - SIGN_PERMIT2: backend re-checks Permit2 allowance (single &
846
920
  * batched paths).
921
+ * - APPROVE_SPL: backend re-checks SPL delegate authority.
847
922
  * - EXECUTE_BRIDGE: backend scans for the deposit tx hash on-chain.
848
923
  *
849
924
  * Applied at most once per action.id within a run; on a not-detected
@@ -853,6 +928,19 @@ interface OrchestratorRunOptions {
853
928
  * run.
854
929
  */
855
930
  probeBeforePrompt?: boolean;
931
+ /**
932
+ * Fires once during APPROVE_SPL after Phantom returns the signed
933
+ * transaction, while the SDK polls a Solana RPC for on-chain
934
+ * confirmation. Mirrors EVM's "tx sent, awaiting settlement" window
935
+ * — useful for swapping wallet-prompt copy ("Confirm in Phantom") for
936
+ * a settlement spinner ("Confirming on Solana…") so the UI doesn't
937
+ * look frozen during the 5–30 second confirm phase.
938
+ *
939
+ * The `authExecutor.approveSplConfirming` state exposes the same
940
+ * signal for first-party SDK UI; this callback is the orchestrator
941
+ * surface for SDK consumers that drive their own UI.
942
+ */
943
+ onApproveSplConfirming?: (action: AuthorizationAction) => void;
856
944
  }
857
945
  interface UseAuthorizationOrchestratorResult {
858
946
  /**
@@ -893,7 +981,7 @@ interface UseAuthorizationOrchestratorResult {
893
981
  * the user completes one-tap setup.
894
982
  */
895
983
  resolveOneTapPause: () => void;
896
- /** The SIGN_PERMIT2 awaiting-limit action currently waiting on one-tap setup. */
984
+ /** The awaiting-limit action currently waiting on one-tap setup. */
897
985
  pendingOneTapAction: AuthorizationAction | null;
898
986
  /** Cancel any paused setup flow and reject the current orchestrator run. */
899
987
  cancelPendingFlow: () => void;
@@ -1006,6 +1094,14 @@ interface PaymentState {
1006
1094
  */
1007
1095
  guestWalletPrepared: PreparedSession | null;
1008
1096
  guestWalletDeeplinksPreparing: boolean;
1097
+ /**
1098
+ * When set, the host requested a transfer with `amount < minTransferAmountUsd`.
1099
+ * Routes the flow to a dedicated full-screen error via `resolveTerminalPhase`.
1100
+ * Cleared on `NEW_PAYMENT` (Try Again) and `LOGOUT`.
1101
+ */
1102
+ amountTooLow: {
1103
+ minAmountUsd: number;
1104
+ } | null;
1009
1105
  }
1010
1106
  interface InitialStateConfig {
1011
1107
  depositAmount: number | null;
@@ -1190,12 +1286,22 @@ interface UseTransferPollingResult {
1190
1286
  stopPolling: () => void;
1191
1287
  }
1192
1288
  /**
1193
- * Polls GET /v1/transfers/{id} every `intervalMs` until status is
1194
- * COMPLETED or FAILED.
1289
+ * Polls GET /v1/transfers/{id} until status is COMPLETED or FAILED. Uses an
1290
+ * adaptive interval (see FAST_POLL_COUNT/FAST_POLL_INTERVAL_MS) so the early
1291
+ * polls — when the bridge is most likely to settle — fire quickly while
1292
+ * later polls back off to `intervalMs` to limit API load.
1195
1293
  */
1196
1294
  declare function useTransferPolling(intervalMs?: number, overrideGetAccessToken?: () => Promise<string | null>): UseTransferPollingResult;
1197
1295
 
1198
1296
  type AccessTokenGetter = () => Promise<string | null | undefined>;
1297
+ interface SignTransferOptions {
1298
+ /**
1299
+ * Win 2 hint: when the caller already has a fresh `signPayload` (e.g. from
1300
+ * the POST /v1/transfers response), pass it here to skip the GET poll loop
1301
+ * and proceed directly to the WebAuthn ceremony.
1302
+ */
1303
+ knownSignPayload?: TransferSignPayload | null;
1304
+ }
1199
1305
  interface UseTransferSigningResult {
1200
1306
  signing: boolean;
1201
1307
  signPayload: TransferSignPayload | null;
@@ -1204,10 +1310,11 @@ interface UseTransferSigningResult {
1204
1310
  /**
1205
1311
  * Starts the signing flow:
1206
1312
  * 1. Polls GET /v1/transfers/{id} until signPayload is present
1313
+ * (skipped when `opts.knownSignPayload` is provided).
1207
1314
  * 2. Triggers WebAuthn passkey prompt
1208
1315
  * 3. Submits signed UserOp via PATCH /v1/transfers/{id}
1209
1316
  */
1210
- signTransfer: (transferId: string) => Promise<Transfer>;
1317
+ signTransfer: (transferId: string, opts?: SignTransferOptions) => Promise<Transfer>;
1211
1318
  }
1212
1319
  interface UseTransferSigningOptions {
1213
1320
  /** Optional API base URL override when used outside BlinkProvider. */
@@ -1271,6 +1378,8 @@ interface PrimaryButtonProps {
1271
1378
  children: ReactNode;
1272
1379
  onClick?: (event: MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => void;
1273
1380
  href?: string;
1381
+ target?: HTMLAttributeAnchorTarget;
1382
+ rel?: string;
1274
1383
  disabled?: boolean;
1275
1384
  loading?: boolean;
1276
1385
  /** Override the default "Please wait..." text shown while loading. */
@@ -1284,7 +1393,7 @@ interface PrimaryButtonProps {
1284
1393
  /** When true, the fill bar pulses to signal the user needs to take action (e.g. confirm in wallet). */
1285
1394
  progressPaused?: boolean;
1286
1395
  }
1287
- declare function PrimaryButton({ children, onClick, href, disabled, loading, loadingText, icon, progress, progressText, progressPaused, }: PrimaryButtonProps): react_jsx_runtime.JSX.Element;
1396
+ declare function PrimaryButton({ children, onClick, href, target, rel, disabled, loading, loadingText, icon, progress, progressText, progressPaused, }: PrimaryButtonProps): react_jsx_runtime.JSX.Element;
1288
1397
 
1289
1398
  interface OutlineButtonProps {
1290
1399
  children: ReactNode;
@@ -1775,6 +1884,7 @@ declare function OpenWalletScreen({ walletName, deeplinkUri, loading, useDeeplin
1775
1884
 
1776
1885
  interface ConfirmSignScreenProps {
1777
1886
  walletName: string | null;
1887
+ chainFamily?: 'evm' | 'svm' | null;
1778
1888
  signing: boolean;
1779
1889
  error: string | null;
1780
1890
  onSign: () => void;
@@ -1784,7 +1894,7 @@ interface ConfirmSignScreenProps {
1784
1894
  * Shown after the user returns from wallet authorization. Requires an explicit
1785
1895
  * button tap to initiate passkey signing (FaceID) rather than auto-triggering.
1786
1896
  */
1787
- declare function ConfirmSignScreen({ walletName, signing, error, onSign, onLogout, }: ConfirmSignScreenProps): react_jsx_runtime.JSX.Element;
1897
+ declare function ConfirmSignScreen({ walletName, chainFamily, signing, error, onSign, onLogout, }: ConfirmSignScreenProps): react_jsx_runtime.JSX.Element;
1788
1898
 
1789
1899
  interface TokenPickerScreenProps {
1790
1900
  /**