@swype-org/react-sdk 0.1.50 → 0.1.53

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.js CHANGED
@@ -671,33 +671,6 @@ function isInCrossOriginIframe() {
671
671
  return true;
672
672
  }
673
673
  }
674
- var delegationCounter = 0;
675
- var DELEGATION_GET_TIMEOUT_MS = 3e4;
676
- function delegatePasskeyGet(options) {
677
- return new Promise((resolve, reject) => {
678
- const id = `pg-${++delegationCounter}-${Date.now()}`;
679
- const timer = setTimeout(() => {
680
- window.removeEventListener("message", handler);
681
- reject(new Error("Passkey verification timed out. Please try again."));
682
- }, DELEGATION_GET_TIMEOUT_MS);
683
- const handler = (event) => {
684
- const data = event.data;
685
- if (!data || typeof data !== "object") return;
686
- if (data.type !== "swype:passkey-get-response" || data.id !== id) return;
687
- clearTimeout(timer);
688
- window.removeEventListener("message", handler);
689
- if (data.error) {
690
- reject(new Error(data.error));
691
- } else if (data.result) {
692
- resolve(data.result);
693
- } else {
694
- reject(new Error("Invalid passkey get response."));
695
- }
696
- };
697
- window.addEventListener("message", handler);
698
- window.parent.postMessage({ type: "swype:passkey-get-request", id, options }, "*");
699
- });
700
- }
701
674
  var POPUP_RESULT_TIMEOUT_MS = 12e4;
702
675
  var POPUP_CLOSED_POLL_MS = 500;
703
676
  function createPasskeyViaPopup(options) {
@@ -947,16 +920,6 @@ async function findDevicePasskey(credentialIds) {
947
920
  try {
948
921
  const challenge = new Uint8Array(32);
949
922
  crypto.getRandomValues(challenge);
950
- if (isInCrossOriginIframe()) {
951
- const result = await delegatePasskeyGet({
952
- challenge: toBase64(challenge),
953
- rpId: resolvePasskeyRpId(),
954
- allowCredentials: credentialIds.map((id) => ({ type: "public-key", id })),
955
- userVerification: "discouraged",
956
- timeout: 3e4
957
- });
958
- return result.credentialId;
959
- }
960
923
  await waitForDocumentFocus();
961
924
  const assertion = await navigator.credentials.get({
962
925
  publicKey: {
@@ -1455,48 +1418,31 @@ function useTransferSigning(pollIntervalMs = 2e3, options) {
1455
1418
  }
1456
1419
  const hashBytes = hexToBytes(payload.userOpHash);
1457
1420
  let signedUserOp;
1458
- if (isInCrossOriginIframe()) {
1459
- const delegatedResult = await delegatePasskeyGet({
1460
- challenge: toBase64(hashBytes),
1421
+ const allowCredentials = payload.passkeyCredentialId ? [{
1422
+ type: "public-key",
1423
+ id: base64ToBytes(payload.passkeyCredentialId)
1424
+ }] : void 0;
1425
+ await waitForDocumentFocus();
1426
+ const assertion = await navigator.credentials.get({
1427
+ publicKey: {
1428
+ challenge: hashBytes,
1461
1429
  rpId: resolvePasskeyRpId(),
1462
- allowCredentials: payload.passkeyCredentialId ? [{ type: "public-key", id: payload.passkeyCredentialId }] : void 0,
1430
+ allowCredentials,
1463
1431
  userVerification: "required",
1464
1432
  timeout: 6e4
1465
- });
1466
- signedUserOp = {
1467
- ...payload.userOp,
1468
- credentialId: delegatedResult.credentialId,
1469
- signature: delegatedResult.signature,
1470
- authenticatorData: delegatedResult.authenticatorData,
1471
- clientDataJSON: delegatedResult.clientDataJSON
1472
- };
1473
- } else {
1474
- const allowCredentials = payload.passkeyCredentialId ? [{
1475
- type: "public-key",
1476
- id: base64ToBytes(payload.passkeyCredentialId)
1477
- }] : void 0;
1478
- await waitForDocumentFocus();
1479
- const assertion = await navigator.credentials.get({
1480
- publicKey: {
1481
- challenge: hashBytes,
1482
- rpId: resolvePasskeyRpId(),
1483
- allowCredentials,
1484
- userVerification: "required",
1485
- timeout: 6e4
1486
- }
1487
- });
1488
- if (!assertion) {
1489
- throw new Error("Passkey authentication was cancelled.");
1490
1433
  }
1491
- const response = assertion.response;
1492
- signedUserOp = {
1493
- ...payload.userOp,
1494
- credentialId: toBase64(assertion.rawId),
1495
- signature: toBase64(response.signature),
1496
- authenticatorData: toBase64(response.authenticatorData),
1497
- clientDataJSON: toBase64(response.clientDataJSON)
1498
- };
1434
+ });
1435
+ if (!assertion) {
1436
+ throw new Error("Passkey authentication was cancelled.");
1499
1437
  }
1438
+ const response = assertion.response;
1439
+ signedUserOp = {
1440
+ ...payload.userOp,
1441
+ credentialId: toBase64(assertion.rawId),
1442
+ signature: toBase64(response.signature),
1443
+ authenticatorData: toBase64(response.authenticatorData),
1444
+ clientDataJSON: toBase64(response.clientDataJSON)
1445
+ };
1500
1446
  return await signTransfer(
1501
1447
  apiBaseUrl,
1502
1448
  token ?? "",
@@ -1959,8 +1905,7 @@ var inputStyle = (tokens, filled) => ({
1959
1905
  textAlign: "center",
1960
1906
  outline: "none",
1961
1907
  caretColor: tokens.borderFocus,
1962
- transition: "border-color 0.15s ease",
1963
- flexShrink: 0
1908
+ transition: "border-color 0.15s ease"
1964
1909
  });
1965
1910
  function LimitSlider({
1966
1911
  value,
@@ -3911,7 +3856,7 @@ function OpenWalletScreen({
3911
3856
  const logoSrc = walletName ? KNOWN_LOGOS[walletName.toLowerCase()] : void 0;
3912
3857
  const handleOpen = useCallback(() => {
3913
3858
  const opened = window.open(deeplinkUri, "_blank");
3914
- if (!opened) {
3859
+ if (!opened && window === window.parent) {
3915
3860
  window.location.href = deeplinkUri;
3916
3861
  }
3917
3862
  }, [deeplinkUri]);
@@ -4281,6 +4226,11 @@ function SwypePaymentInner({
4281
4226
  setError(err instanceof Error ? err.message : "Failed to verify code");
4282
4227
  }
4283
4228
  }, [verificationTarget, otpCode, loginWithEmailCode, loginWithSmsCode]);
4229
+ useEffect(() => {
4230
+ if (step === "otp-verify" && /^\d{6}$/.test(otpCode.trim()) && activeOtpStatus !== "submitting-code") {
4231
+ handleVerifyLoginCode();
4232
+ }
4233
+ }, [otpCode, step, activeOtpStatus, handleVerifyLoginCode]);
4284
4234
  const handleResendLoginCode = useCallback(async () => {
4285
4235
  if (!verificationTarget) return;
4286
4236
  setError(null);