@openkey/sdk 0.12.1-beta.1 → 0.12.2-beta.0

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.d.mts CHANGED
@@ -456,6 +456,7 @@ declare class OpenKey {
456
456
  authorizeTinyCloud(request: TinyCloudAuthorizationRequestV1, opts?: {
457
457
  mode?: OpenKeyMode;
458
458
  }): Promise<TinyCloudAuthorizationResultV1>;
459
+ private authorizeTinyCloudFlow;
459
460
  /**
460
461
  * Sol MAJOR-3 (continuation): authorizeTinyCloud path for external keys.
461
462
  * The wallet lives outside OpenKey, so the SDK opens the shared widget
@@ -549,6 +550,12 @@ declare class OpenKey {
549
550
  private isResponseForAction;
550
551
  private handleWalletLinkDelegation;
551
552
  private handleExternalWalletConnect;
553
+ /**
554
+ * Opens the popup window of a flow in the current tick, blank. `openPopup`
555
+ * navigates it to the widget later. `null` when the browser did not give a
556
+ * usable window: the flow then opens its own, as it always did.
557
+ */
558
+ private reservePopup;
552
559
  private openPopup;
553
560
  private cancelActiveFlows;
554
561
  /**
package/dist/index.d.ts CHANGED
@@ -456,6 +456,7 @@ declare class OpenKey {
456
456
  authorizeTinyCloud(request: TinyCloudAuthorizationRequestV1, opts?: {
457
457
  mode?: OpenKeyMode;
458
458
  }): Promise<TinyCloudAuthorizationResultV1>;
459
+ private authorizeTinyCloudFlow;
459
460
  /**
460
461
  * Sol MAJOR-3 (continuation): authorizeTinyCloud path for external keys.
461
462
  * The wallet lives outside OpenKey, so the SDK opens the shared widget
@@ -549,6 +550,12 @@ declare class OpenKey {
549
550
  private isResponseForAction;
550
551
  private handleWalletLinkDelegation;
551
552
  private handleExternalWalletConnect;
553
+ /**
554
+ * Opens the popup window of a flow in the current tick, blank. `openPopup`
555
+ * navigates it to the widget later. `null` when the browser did not give a
556
+ * usable window: the flow then opens its own, as it always did.
557
+ */
558
+ private reservePopup;
552
559
  private openPopup;
553
560
  private cancelActiveFlows;
554
561
  /**
package/dist/index.js CHANGED
@@ -864,6 +864,19 @@ var OpenKey = class {
864
864
  * remains preserved and OpenKey never rewrites their bytes.
865
865
  */
866
866
  async authorizeTinyCloud(request, opts) {
867
+ const reserved = request?.protocolVersion === 1 && typeof request.siwe === "string" && request.siwe !== "" && this.resolveMode(opts?.mode) === "popup" ? this.reservePopup("sign") : null;
868
+ try {
869
+ return await this.authorizeTinyCloudFlow(request, opts, reserved);
870
+ } finally {
871
+ if (reserved && !reserved.used) {
872
+ try {
873
+ reserved.window.close();
874
+ } catch {
875
+ }
876
+ }
877
+ }
878
+ }
879
+ async authorizeTinyCloudFlow(request, opts, reserved) {
867
880
  if (request.protocolVersion !== 1) {
868
881
  throw new Error(
869
882
  `authorizeTinyCloud only supports protocolVersion 1; got ${request.protocolVersion}`
@@ -911,7 +924,8 @@ var OpenKey = class {
911
924
  // verified unless the server actually origin-binds a manifest.
912
925
  presentation: request.presentation
913
926
  },
914
- opts?.mode
927
+ opts?.mode,
928
+ reserved
915
929
  );
916
930
  if (typeof raw.signedMessage !== "string" || !raw.signedMessage) {
917
931
  throw new Error(
@@ -1351,14 +1365,14 @@ var OpenKey = class {
1351
1365
  if (typeof window !== "undefined" && window.ethereum) return true;
1352
1366
  return false;
1353
1367
  }
1354
- async openFlow(action, message, modeOverride) {
1368
+ async openFlow(action, message, modeOverride, reserved) {
1355
1369
  const mode = this.resolveMode(modeOverride);
1356
1370
  const origin = encodeURIComponent(window.location.origin);
1357
1371
  const eoaFlag = action === "connect" && this.hasDetectedEoa() ? "&hasEoa=true" : "";
1358
1372
  const passkeysFlag = passkeysQueryFlag(this.passkeysSupported);
1359
1373
  if (mode === "popup") {
1360
1374
  const url2 = `${this.host}/widget/${action}?origin=${origin}${eoaFlag}${passkeysFlag}`;
1361
- return new Promise((resolve, reject) => this.openPopup(action, url2, message, resolve, reject));
1375
+ return new Promise((resolve, reject) => this.openPopup(action, url2, message, resolve, reject, reserved ?? null));
1362
1376
  }
1363
1377
  if (mode === "redirect") {
1364
1378
  const url2 = `${this.host}/widget/${action}?origin=${origin}${eoaFlag}${passkeysFlag}`;
@@ -1589,14 +1603,40 @@ var OpenKey = class {
1589
1603
  }
1590
1604
  });
1591
1605
  }
1592
- openPopup(action, url, message, resolve, reject) {
1606
+ /**
1607
+ * Opens the popup window of a flow in the current tick, blank. `openPopup`
1608
+ * navigates it to the widget later. `null` when the browser did not give a
1609
+ * usable window: the flow then opens its own, as it always did.
1610
+ */
1611
+ reservePopup(action) {
1593
1612
  const left = window.screenX + (window.outerWidth - POPUP_WIDTH) / 2;
1594
1613
  const top = window.screenY + (window.outerHeight - POPUP_HEIGHT) / 2;
1595
- const popup = window.open(
1596
- url,
1614
+ const win = window.open(
1615
+ "about:blank",
1597
1616
  `openkey-${action}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
1598
1617
  `width=${POPUP_WIDTH},height=${POPUP_HEIGHT},left=${left},top=${top},popup=true`
1599
1618
  );
1619
+ return isUsablePopup(win) ? { window: win, used: false } : null;
1620
+ }
1621
+ openPopup(action, url, message, resolve, reject, reserved = null) {
1622
+ const left = window.screenX + (window.outerWidth - POPUP_WIDTH) / 2;
1623
+ const top = window.screenY + (window.outerHeight - POPUP_HEIGHT) / 2;
1624
+ let popup;
1625
+ if (reserved && !reserved.window.closed) {
1626
+ try {
1627
+ reserved.window.location.href = url;
1628
+ reserved.used = true;
1629
+ popup = reserved.window;
1630
+ } catch {
1631
+ popup = null;
1632
+ }
1633
+ } else {
1634
+ popup = window.open(
1635
+ url,
1636
+ `openkey-${action}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
1637
+ `width=${POPUP_WIDTH},height=${POPUP_HEIGHT},left=${left},top=${top},popup=true`
1638
+ );
1639
+ }
1600
1640
  if (!isUsablePopup(popup)) {
1601
1641
  this.popup = null;
1602
1642
  const embedded = isEmbeddedAppWebView();