@swype-org/react-sdk 0.1.15 → 0.1.16

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
@@ -308,6 +308,18 @@ declare function createPasskeyCredential(userIdentifier: string): Promise<{
308
308
  credentialId: string;
309
309
  publicKey: string;
310
310
  }>;
311
+ /**
312
+ * Checks whether the current device's platform authenticator holds a passkey
313
+ * matching the given credential ID.
314
+ *
315
+ * Uses `navigator.credentials.get()` with a throwaway challenge and a short
316
+ * timeout. If the authenticator responds, the device has the key. If it
317
+ * throws (NotAllowedError, timeout, etc.), the device does not.
318
+ *
319
+ * @param credentialId - Base64-encoded WebAuthn credential ID from the server.
320
+ * @returns `true` if the device can authenticate with this credential.
321
+ */
322
+ declare function deviceHasPasskey(credentialId: string): Promise<boolean>;
311
323
  interface UseTransferPollingResult {
312
324
  transfer: Transfer | null;
313
325
  error: string | null;
@@ -449,4 +461,4 @@ declare namespace api {
449
461
  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 };
450
462
  }
451
463
 
452
- 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 };
464
+ 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, deviceHasPasskey, getTheme, lightTheme, api as swypeApi, useAuthorizationExecutor, useSwypeConfig, useSwypeDepositAmount, useTransferPolling, useTransferSigning };
package/dist/index.d.ts CHANGED
@@ -308,6 +308,18 @@ declare function createPasskeyCredential(userIdentifier: string): Promise<{
308
308
  credentialId: string;
309
309
  publicKey: string;
310
310
  }>;
311
+ /**
312
+ * Checks whether the current device's platform authenticator holds a passkey
313
+ * matching the given credential ID.
314
+ *
315
+ * Uses `navigator.credentials.get()` with a throwaway challenge and a short
316
+ * timeout. If the authenticator responds, the device has the key. If it
317
+ * throws (NotAllowedError, timeout, etc.), the device does not.
318
+ *
319
+ * @param credentialId - Base64-encoded WebAuthn credential ID from the server.
320
+ * @returns `true` if the device can authenticate with this credential.
321
+ */
322
+ declare function deviceHasPasskey(credentialId: string): Promise<boolean>;
311
323
  interface UseTransferPollingResult {
312
324
  transfer: Transfer | null;
313
325
  error: string | null;
@@ -449,4 +461,4 @@ declare namespace api {
449
461
  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 };
450
462
  }
451
463
 
452
- 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 };
464
+ 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, deviceHasPasskey, getTheme, lightTheme, api as swypeApi, useAuthorizationExecutor, useSwypeConfig, useSwypeDepositAmount, useTransferPolling, useTransferSigning };
package/dist/index.js CHANGED
@@ -735,6 +735,28 @@ async function createPasskeyCredential(userIdentifier) {
735
735
  publicKey: publicKeyBytes ? toBase64(publicKeyBytes) : ""
736
736
  };
737
737
  }
738
+ async function deviceHasPasskey(credentialId) {
739
+ try {
740
+ const challenge = new Uint8Array(32);
741
+ crypto.getRandomValues(challenge);
742
+ await waitForDocumentFocus();
743
+ const assertion = await navigator.credentials.get({
744
+ publicKey: {
745
+ challenge,
746
+ rpId: resolvePasskeyRpId(),
747
+ allowCredentials: [{
748
+ type: "public-key",
749
+ id: base64ToBytes(credentialId)
750
+ }],
751
+ userVerification: "required",
752
+ timeout: 3e4
753
+ }
754
+ });
755
+ return assertion != null;
756
+ } catch {
757
+ return false;
758
+ }
759
+ }
738
760
  function useTransferPolling(intervalMs = 3e3) {
739
761
  const { apiBaseUrl } = useSwypeConfig();
740
762
  const { getAccessToken } = usePrivy();
@@ -2138,12 +2160,27 @@ function SwypePayment({
2138
2160
  if (!token || cancelled) return;
2139
2161
  const { config } = await fetchUserConfig(apiBaseUrl, token);
2140
2162
  if (cancelled) return;
2141
- if (!config.passkey || !activeCredentialId) {
2142
- setStep("register-passkey");
2143
- } else if (depositAmount != null && depositAmount > 0) {
2144
- setStep("ready");
2163
+ if (config.passkey?.credentialId) {
2164
+ const hasKey = activeCredentialId ? activeCredentialId === config.passkey.credentialId : await deviceHasPasskey(config.passkey.credentialId);
2165
+ if (cancelled) return;
2166
+ if (hasKey) {
2167
+ if (!activeCredentialId) {
2168
+ setActiveCredentialId(config.passkey.credentialId);
2169
+ window.localStorage.setItem(
2170
+ ACTIVE_CREDENTIAL_STORAGE_KEY,
2171
+ config.passkey.credentialId
2172
+ );
2173
+ }
2174
+ if (depositAmount != null && depositAmount > 0) {
2175
+ setStep("ready");
2176
+ } else {
2177
+ setStep("enter-amount");
2178
+ }
2179
+ } else {
2180
+ setStep("register-passkey");
2181
+ }
2145
2182
  } else {
2146
- setStep("enter-amount");
2183
+ setStep("register-passkey");
2147
2184
  }
2148
2185
  } catch {
2149
2186
  if (!cancelled) {
@@ -3455,6 +3492,6 @@ function SwypePayment({
3455
3492
  return null;
3456
3493
  }
3457
3494
 
3458
- export { SwypePayment, SwypeProvider, createPasskeyCredential, darkTheme, getTheme, lightTheme, api_exports as swypeApi, useAuthorizationExecutor, useSwypeConfig, useSwypeDepositAmount, useTransferPolling, useTransferSigning };
3495
+ export { SwypePayment, SwypeProvider, createPasskeyCredential, darkTheme, deviceHasPasskey, getTheme, lightTheme, api_exports as swypeApi, useAuthorizationExecutor, useSwypeConfig, useSwypeDepositAmount, useTransferPolling, useTransferSigning };
3459
3496
  //# sourceMappingURL=index.js.map
3460
3497
  //# sourceMappingURL=index.js.map