@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.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 ?? "",
@@ -3911,7 +3857,7 @@ function OpenWalletScreen({
3911
3857
  const logoSrc = walletName ? KNOWN_LOGOS[walletName.toLowerCase()] : void 0;
3912
3858
  const handleOpen = useCallback(() => {
3913
3859
  const opened = window.open(deeplinkUri, "_blank");
3914
- if (!opened) {
3860
+ if (!opened && window === window.parent) {
3915
3861
  window.location.href = deeplinkUri;
3916
3862
  }
3917
3863
  }, [deeplinkUri]);