@swype-org/react-sdk 0.1.50 → 0.1.52

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
@@ -674,33 +674,6 @@ function isInCrossOriginIframe() {
674
674
  return true;
675
675
  }
676
676
  }
677
- var delegationCounter = 0;
678
- var DELEGATION_GET_TIMEOUT_MS = 3e4;
679
- function delegatePasskeyGet(options) {
680
- return new Promise((resolve, reject) => {
681
- const id = `pg-${++delegationCounter}-${Date.now()}`;
682
- const timer = setTimeout(() => {
683
- window.removeEventListener("message", handler);
684
- reject(new Error("Passkey verification timed out. Please try again."));
685
- }, DELEGATION_GET_TIMEOUT_MS);
686
- const handler = (event) => {
687
- const data = event.data;
688
- if (!data || typeof data !== "object") return;
689
- if (data.type !== "swype:passkey-get-response" || data.id !== id) return;
690
- clearTimeout(timer);
691
- window.removeEventListener("message", handler);
692
- if (data.error) {
693
- reject(new Error(data.error));
694
- } else if (data.result) {
695
- resolve(data.result);
696
- } else {
697
- reject(new Error("Invalid passkey get response."));
698
- }
699
- };
700
- window.addEventListener("message", handler);
701
- window.parent.postMessage({ type: "swype:passkey-get-request", id, options }, "*");
702
- });
703
- }
704
677
  var POPUP_RESULT_TIMEOUT_MS = 12e4;
705
678
  var POPUP_CLOSED_POLL_MS = 500;
706
679
  function createPasskeyViaPopup(options) {
@@ -950,16 +923,6 @@ async function findDevicePasskey(credentialIds) {
950
923
  try {
951
924
  const challenge = new Uint8Array(32);
952
925
  crypto.getRandomValues(challenge);
953
- if (isInCrossOriginIframe()) {
954
- const result = await delegatePasskeyGet({
955
- challenge: toBase64(challenge),
956
- rpId: resolvePasskeyRpId(),
957
- allowCredentials: credentialIds.map((id) => ({ type: "public-key", id })),
958
- userVerification: "discouraged",
959
- timeout: 3e4
960
- });
961
- return result.credentialId;
962
- }
963
926
  await waitForDocumentFocus();
964
927
  const assertion = await navigator.credentials.get({
965
928
  publicKey: {
@@ -1458,48 +1421,31 @@ function useTransferSigning(pollIntervalMs = 2e3, options) {
1458
1421
  }
1459
1422
  const hashBytes = hexToBytes(payload.userOpHash);
1460
1423
  let signedUserOp;
1461
- if (isInCrossOriginIframe()) {
1462
- const delegatedResult = await delegatePasskeyGet({
1463
- challenge: toBase64(hashBytes),
1424
+ const allowCredentials = payload.passkeyCredentialId ? [{
1425
+ type: "public-key",
1426
+ id: base64ToBytes(payload.passkeyCredentialId)
1427
+ }] : void 0;
1428
+ await waitForDocumentFocus();
1429
+ const assertion = await navigator.credentials.get({
1430
+ publicKey: {
1431
+ challenge: hashBytes,
1464
1432
  rpId: resolvePasskeyRpId(),
1465
- allowCredentials: payload.passkeyCredentialId ? [{ type: "public-key", id: payload.passkeyCredentialId }] : void 0,
1433
+ allowCredentials,
1466
1434
  userVerification: "required",
1467
1435
  timeout: 6e4
1468
- });
1469
- signedUserOp = {
1470
- ...payload.userOp,
1471
- credentialId: delegatedResult.credentialId,
1472
- signature: delegatedResult.signature,
1473
- authenticatorData: delegatedResult.authenticatorData,
1474
- clientDataJSON: delegatedResult.clientDataJSON
1475
- };
1476
- } else {
1477
- const allowCredentials = payload.passkeyCredentialId ? [{
1478
- type: "public-key",
1479
- id: base64ToBytes(payload.passkeyCredentialId)
1480
- }] : void 0;
1481
- await waitForDocumentFocus();
1482
- const assertion = await navigator.credentials.get({
1483
- publicKey: {
1484
- challenge: hashBytes,
1485
- rpId: resolvePasskeyRpId(),
1486
- allowCredentials,
1487
- userVerification: "required",
1488
- timeout: 6e4
1489
- }
1490
- });
1491
- if (!assertion) {
1492
- throw new Error("Passkey authentication was cancelled.");
1493
1436
  }
1494
- const response = assertion.response;
1495
- signedUserOp = {
1496
- ...payload.userOp,
1497
- credentialId: toBase64(assertion.rawId),
1498
- signature: toBase64(response.signature),
1499
- authenticatorData: toBase64(response.authenticatorData),
1500
- clientDataJSON: toBase64(response.clientDataJSON)
1501
- };
1437
+ });
1438
+ if (!assertion) {
1439
+ throw new Error("Passkey authentication was cancelled.");
1502
1440
  }
1441
+ const response = assertion.response;
1442
+ signedUserOp = {
1443
+ ...payload.userOp,
1444
+ credentialId: toBase64(assertion.rawId),
1445
+ signature: toBase64(response.signature),
1446
+ authenticatorData: toBase64(response.authenticatorData),
1447
+ clientDataJSON: toBase64(response.clientDataJSON)
1448
+ };
1503
1449
  return await signTransfer(
1504
1450
  apiBaseUrl,
1505
1451
  token ?? "",
@@ -3914,7 +3860,7 @@ function OpenWalletScreen({
3914
3860
  const logoSrc = walletName ? KNOWN_LOGOS[walletName.toLowerCase()] : void 0;
3915
3861
  const handleOpen = react.useCallback(() => {
3916
3862
  const opened = window.open(deeplinkUri, "_blank");
3917
- if (!opened) {
3863
+ if (!opened && window === window.parent) {
3918
3864
  window.location.href = deeplinkUri;
3919
3865
  }
3920
3866
  }, [deeplinkUri]);