@swype-org/react-sdk 0.1.18 → 0.1.20

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 CHANGED
@@ -701,7 +701,7 @@ function parseSignTypedDataPayload(typedData) {
701
701
  function getPendingActions(session, completedIds) {
702
702
  return session.actions.filter((a) => a.status === "PENDING" && !completedIds.has(a.id)).sort((a, b) => a.orderIndex - b.orderIndex);
703
703
  }
704
- async function createPasskeyCredential(userIdentifier) {
704
+ async function createPasskeyCredential(params) {
705
705
  const challenge = new Uint8Array(32);
706
706
  crypto.getRandomValues(challenge);
707
707
  const rpId = resolvePasskeyRpId();
@@ -711,9 +711,9 @@ async function createPasskeyCredential(userIdentifier) {
711
711
  challenge,
712
712
  rp: { name: "Swype", id: rpId },
713
713
  user: {
714
- id: new TextEncoder().encode(userIdentifier),
715
- name: userIdentifier,
716
- displayName: "Swype User"
714
+ id: new TextEncoder().encode(params.userId),
715
+ name: params.displayName,
716
+ displayName: params.displayName
717
717
  },
718
718
  pubKeyCredParams: [
719
719
  { alg: -7, type: "public-key" },
@@ -1087,6 +1087,8 @@ function useAuthorizationExecutor(options) {
1087
1087
  return executeSwitchChain(action, wagmiConfig2, switchChainAsync);
1088
1088
  case "APPROVE_PERMIT2":
1089
1089
  return executeApprovePermit2(action, wagmiConfig2);
1090
+ case "DEPLOY_SMART_ACCOUNT":
1091
+ return actionSuccess(action, "Smart account deployment acknowledged.");
1090
1092
  case "SIGN_PERMIT2":
1091
1093
  return executeSignPermit2(action, wagmiConfig2, apiBaseUrl ?? "", sessionIdRef.current);
1092
1094
  default:
@@ -2116,7 +2118,7 @@ function SwypePayment({
2116
2118
  useWalletConnector
2117
2119
  }) {
2118
2120
  const { apiBaseUrl, tokens, depositAmount } = useSwypeConfig();
2119
- const { ready, authenticated, login, logout, getAccessToken } = reactAuth.usePrivy();
2121
+ const { ready, authenticated, user, login, logout, getAccessToken } = reactAuth.usePrivy();
2120
2122
  const [step, setStep] = react.useState("login");
2121
2123
  const [error, setError] = react.useState(null);
2122
2124
  const [providers, setProviders] = react.useState([]);
@@ -2167,28 +2169,34 @@ function SwypePayment({
2167
2169
  if (!token || cancelled) return;
2168
2170
  const { config } = await fetchUserConfig(apiBaseUrl, token);
2169
2171
  if (cancelled) return;
2170
- if (config.passkey?.credentialId) {
2171
- const hasKey = activeCredentialId ? activeCredentialId === config.passkey.credentialId : await deviceHasPasskey(config.passkey.credentialId);
2172
+ const allPasskeys = config.passkeys ?? (config.passkey ? [config.passkey] : []);
2173
+ if (allPasskeys.length === 0) {
2174
+ setStep("register-passkey");
2175
+ return;
2176
+ }
2177
+ if (activeCredentialId && allPasskeys.some((p) => p.credentialId === activeCredentialId)) {
2178
+ if (depositAmount != null && depositAmount > 0) {
2179
+ setStep("ready");
2180
+ } else {
2181
+ setStep("enter-amount");
2182
+ }
2183
+ return;
2184
+ }
2185
+ for (const pk of allPasskeys) {
2172
2186
  if (cancelled) return;
2173
- if (hasKey) {
2174
- if (!activeCredentialId) {
2175
- setActiveCredentialId(config.passkey.credentialId);
2176
- window.localStorage.setItem(
2177
- ACTIVE_CREDENTIAL_STORAGE_KEY,
2178
- config.passkey.credentialId
2179
- );
2180
- }
2187
+ if (await deviceHasPasskey(pk.credentialId)) {
2188
+ setActiveCredentialId(pk.credentialId);
2189
+ window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, pk.credentialId);
2181
2190
  if (depositAmount != null && depositAmount > 0) {
2182
2191
  setStep("ready");
2183
2192
  } else {
2184
2193
  setStep("enter-amount");
2185
2194
  }
2186
- } else {
2187
- setStep("register-passkey");
2195
+ return;
2188
2196
  }
2189
- } else {
2190
- setStep("register-passkey");
2191
2197
  }
2198
+ if (cancelled) return;
2199
+ setStep("register-passkey");
2192
2200
  } catch {
2193
2201
  if (!cancelled) {
2194
2202
  if (depositAmount != null && depositAmount > 0) {
@@ -2703,7 +2711,11 @@ function SwypePayment({
2703
2711
  try {
2704
2712
  const token = await getAccessToken();
2705
2713
  if (!token) throw new Error("Not authenticated");
2706
- const { credentialId, publicKey } = await createPasskeyCredential("Swype User");
2714
+ const passkeyDisplayName = user?.email?.address ?? user?.google?.name ?? user?.id ?? "Swype User";
2715
+ const { credentialId, publicKey } = await createPasskeyCredential({
2716
+ userId: user?.id ?? "unknown",
2717
+ displayName: passkeyDisplayName
2718
+ });
2707
2719
  await registerPasskey(apiBaseUrl, token, credentialId, publicKey);
2708
2720
  setActiveCredentialId(credentialId);
2709
2721
  window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, credentialId);