@swype-org/react-sdk 0.1.19 → 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" },
@@ -2118,7 +2118,7 @@ function SwypePayment({
2118
2118
  useWalletConnector
2119
2119
  }) {
2120
2120
  const { apiBaseUrl, tokens, depositAmount } = useSwypeConfig();
2121
- const { ready, authenticated, login, logout, getAccessToken } = reactAuth.usePrivy();
2121
+ const { ready, authenticated, user, login, logout, getAccessToken } = reactAuth.usePrivy();
2122
2122
  const [step, setStep] = react.useState("login");
2123
2123
  const [error, setError] = react.useState(null);
2124
2124
  const [providers, setProviders] = react.useState([]);
@@ -2169,28 +2169,34 @@ function SwypePayment({
2169
2169
  if (!token || cancelled) return;
2170
2170
  const { config } = await fetchUserConfig(apiBaseUrl, token);
2171
2171
  if (cancelled) return;
2172
- if (config.passkey?.credentialId) {
2173
- 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) {
2174
2186
  if (cancelled) return;
2175
- if (hasKey) {
2176
- if (!activeCredentialId) {
2177
- setActiveCredentialId(config.passkey.credentialId);
2178
- window.localStorage.setItem(
2179
- ACTIVE_CREDENTIAL_STORAGE_KEY,
2180
- config.passkey.credentialId
2181
- );
2182
- }
2187
+ if (await deviceHasPasskey(pk.credentialId)) {
2188
+ setActiveCredentialId(pk.credentialId);
2189
+ window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, pk.credentialId);
2183
2190
  if (depositAmount != null && depositAmount > 0) {
2184
2191
  setStep("ready");
2185
2192
  } else {
2186
2193
  setStep("enter-amount");
2187
2194
  }
2188
- } else {
2189
- setStep("register-passkey");
2195
+ return;
2190
2196
  }
2191
- } else {
2192
- setStep("register-passkey");
2193
2197
  }
2198
+ if (cancelled) return;
2199
+ setStep("register-passkey");
2194
2200
  } catch {
2195
2201
  if (!cancelled) {
2196
2202
  if (depositAmount != null && depositAmount > 0) {
@@ -2705,7 +2711,11 @@ function SwypePayment({
2705
2711
  try {
2706
2712
  const token = await getAccessToken();
2707
2713
  if (!token) throw new Error("Not authenticated");
2708
- 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
+ });
2709
2719
  await registerPasskey(apiBaseUrl, token, credentialId, publicKey);
2710
2720
  setActiveCredentialId(credentialId);
2711
2721
  window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, credentialId);