@seams/wallet 0.15.4 → 0.15.6

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.
Files changed (49) hide show
  1. package/README.md +36 -16
  2. package/dist/.build-inputs.sha256 +1 -1
  3. package/dist/esm/SeamsWeb/walletIframe/host/auth-menu/domain.js +13 -1
  4. package/dist/esm/SeamsWeb/walletIframe/host/ui/auth-menu/AuthMenuSurface.js +8 -7
  5. package/dist/esm/sdk/{host-z-JJRWQe.js → host-DfWylEiw.js} +1 -1
  6. package/dist/esm/sdk/registration-yoF0o52H.js +1 -0
  7. package/dist/esm/sdk/runtime-auth--i_j8PP7.js +1 -0
  8. package/dist/{public/sdk/runtime-device-link-Dq8g_UNb.js → esm/sdk/runtime-device-link-fpvaxYyR.js} +1 -1
  9. package/dist/esm/sdk/{runtime-ecdsa-tempo-AGjT7Xpa.js → runtime-ecdsa-tempo-AE5QTaXu.js} +1 -1
  10. package/dist/esm/sdk/{runtime-email-otp-BpBOuSsT.js → runtime-email-otp-Dl03QI-O.js} +1 -1
  11. package/dist/esm/sdk/{runtime-export-CBsacCPY.js → runtime-export-F9s12UcT.js} +1 -1
  12. package/dist/esm/sdk/{runtime-near-J3hKjC7G.js → runtime-near-Bjrz1KYf.js} +1 -1
  13. package/dist/esm/sdk/{runtime-preferences-CVt5sLvm.js → runtime-preferences-oLRSEqmz.js} +1 -1
  14. package/dist/esm/sdk/{runtime-recovery-BzewdcoT.js → runtime-recovery-DBBKvIIg.js} +1 -1
  15. package/dist/esm/sdk/{shared-BywEqTsd.js → shared-D893jckQ.js} +1 -1
  16. package/dist/esm/sdk/wallet-iframe-host-ecdsa.js +1 -1
  17. package/dist/esm/sdk/wallet-iframe-host-full.js +1 -1
  18. package/dist/esm/sdk/wallet-iframe-host-near.js +1 -1
  19. package/dist/esm/sdk/wallet-iframe-host-runtime.js +1 -1
  20. package/dist/public/headers.manifest.json +1 -1
  21. package/dist/public/sdk/{host-z-JJRWQe.js → host-DfWylEiw.js} +1 -1
  22. package/dist/public/sdk/registration-yoF0o52H.js +1 -0
  23. package/dist/public/sdk/runtime-auth--i_j8PP7.js +1 -0
  24. package/dist/{esm/sdk/runtime-device-link-Dq8g_UNb.js → public/sdk/runtime-device-link-fpvaxYyR.js} +1 -1
  25. package/dist/public/sdk/{runtime-ecdsa-tempo-AGjT7Xpa.js → runtime-ecdsa-tempo-AE5QTaXu.js} +1 -1
  26. package/dist/public/sdk/{runtime-email-otp-BpBOuSsT.js → runtime-email-otp-Dl03QI-O.js} +1 -1
  27. package/dist/public/sdk/{runtime-export-CBsacCPY.js → runtime-export-F9s12UcT.js} +1 -1
  28. package/dist/public/sdk/{runtime-near-J3hKjC7G.js → runtime-near-Bjrz1KYf.js} +1 -1
  29. package/dist/public/sdk/{runtime-preferences-CVt5sLvm.js → runtime-preferences-oLRSEqmz.js} +1 -1
  30. package/dist/public/sdk/{runtime-recovery-BzewdcoT.js → runtime-recovery-DBBKvIIg.js} +1 -1
  31. package/dist/public/sdk/{shared-BywEqTsd.js → shared-D893jckQ.js} +1 -1
  32. package/dist/public/sdk/wallet-iframe-host-ecdsa.js +1 -1
  33. package/dist/public/sdk/wallet-iframe-host-full.js +1 -1
  34. package/dist/public/sdk/wallet-iframe-host-near.js +1 -1
  35. package/dist/public/sdk/wallet-iframe-host-runtime.js +1 -1
  36. package/dist/public/sdk/workers/email-otp.worker.js +7 -1
  37. package/dist/public/sdk/workers/passkey-mpc-export.worker.js +7 -1
  38. package/dist/public/sdk/workers/wallet-custody-ceremony.worker.js +2 -0
  39. package/dist/public/wallet-assets.manifest.json +26 -26
  40. package/dist/public/wallet-service/index.html +4 -4
  41. package/dist/types/wallet/src/SeamsWeb/walletIframe/host/auth-menu/domain.d.ts +15 -2
  42. package/dist/workers/email-otp.worker.js +7 -1
  43. package/dist/workers/passkey-mpc-export.worker.js +7 -1
  44. package/dist/workers/wallet-custody-ceremony.worker.js +2 -0
  45. package/package.json +1 -1
  46. package/dist/esm/sdk/registration-DEGZR8kA.js +0 -1
  47. package/dist/esm/sdk/runtime-auth-ZcxkQ-XF.js +0 -1
  48. package/dist/public/sdk/registration-DEGZR8kA.js +0 -1
  49. package/dist/public/sdk/runtime-auth-ZcxkQ-XF.js +0 -1
package/README.md CHANGED
@@ -1,24 +1,26 @@
1
1
  # Seams Wallet SDK
2
2
 
3
- `@seams/wallet` **0.14.0** provides browser wallet lifecycle, NEAR and EVM-family
3
+ `@seams/wallet` **0.15.4** provides browser wallet lifecycle, NEAR and EVM-family
4
4
  threshold signing, React components, and hosted wallet runtime assets.
5
5
 
6
6
  ## Install
7
7
 
8
8
  ```sh
9
- pnpm add @seams/wallet@0.14.0
9
+ pnpm add @seams/wallet@0.15.4
10
10
  ```
11
11
 
12
12
  React integrations support React 18 and 19. Import the provider and UI from
13
13
  `@seams/wallet/react` and its stylesheet from `@seams/wallet/react/styles`.
14
14
  Keep the application package, wallet-origin assets, and
15
- `@seams/wallet-server@0.14.0` on the matching release.
15
+ `@seams/wallet-server@0.15.4` on the matching release. The wallet iframe protocol
16
+ is `16.0.0`. A 0.13 application and a 0.14-or-later wallet host reject each other
17
+ with a protocol version mismatch.
16
18
 
17
- ## Next release migration (unreleased)
19
+ ## Current API
18
20
 
19
- The development API groups calls under `auth`, `connection`, `config`, `events`,
21
+ The public API groups calls under `auth`, `connection`, `config`, `events`,
20
22
  `registration`, and the chain namespaces. See the
21
- [complete migration map](../../docs/refactor-171.md#complete-operation-migration-map).
23
+ [browser reference](https://wallet.seams.sh/docs/reference/core).
22
24
  Use `auth.lock()` to end the session while retaining valid durable presignatures.
23
25
 
24
26
  Custom email unlock uses a host-owned challenge:
@@ -42,9 +44,8 @@ For an existing local email method, request with
42
44
  `cancel()`. Use the replacement challenge returned by a successful resend.
43
45
  The SDK selects signers and completes pending activation internally.
44
46
 
45
- Release 0.9.0 contains these changes. Its wallet iframe protocol is `15.0.0`
46
- and rejects older protocol versions, so keep the client and the wallet-host
47
- assets on the matching release. The 0.8.0 release does not contain them.
47
+ Request email codes only after a user chooses that method. The wallet host owns
48
+ the challenge and its expiry. The application receives the typed challenge handle.
48
49
 
49
50
  ## React quick start
50
51
 
@@ -95,7 +96,7 @@ recovery material out of app configuration and logs.
95
96
  `useSeams()` exposes the SDK client and authentication state. `useWallet()`
96
97
  provides `near`, `evm`, and `tempo` signers bound to the authenticated wallet.
97
98
  `near` is null until a NEAR account is ready. Check registration's pending
98
- branches and use `registration.awaitNearReady` before signing NEAR.
99
+ branches and use `registration.waitForNearAccount` before signing NEAR.
99
100
 
100
101
  The framework-neutral `SeamsWeb` client groups operations under `registration`,
101
102
  `auth`, `near`, `evm`, `tempo`, `recovery`, `devices`, and `keys`. Signing can
@@ -103,7 +104,7 @@ use fresh authorization for one operation; `unlock` provisions a bounded
103
104
  reusable Wallet Session. An EVM-family signing or export call requires a
104
105
  `chainTarget` naming a configured chain.
105
106
 
106
- `keys.exportKeypair` opens a wallet-origin viewer and returns an export outcome.
107
+ `keys.exportKey` opens a wallet-origin viewer and returns `{ kind: 'exported' }`.
107
108
  It does not return a private key to the application. `recovery.syncAccount`
108
109
  synchronizes a known wallet's account state; the hosted menu handles recovery
109
110
  codes and new-factor verification.
@@ -151,10 +152,29 @@ wallet use the same home. Travel does not change it. The owner can move a wallet
151
152
  to another region with the wallet region setting. Automatic region relocation is
152
153
  a future capability.
153
154
 
154
- When upgrading from 0.8.0, update application, wallet assets, and backend
155
- together. An older open client can receive an HTTP 409 upgrade-required message;
156
- show it and reload the current assets. See the
157
- [upgrade guide](https://wallet.seams.sh/docs/deploy-and-operate/hosted-integration#upgrading-to-0-9-0).
155
+ For APAC, registration and relocation request Southeast Asia placement through
156
+ `apac-se`. The hint does not guarantee a city or move existing objects. Operators
157
+ must verify the actual object locations and database primaries.
158
+
159
+ Follow the [upgrade guide](https://wallet.seams.sh/docs/deploy-and-operate/hosted-integration)
160
+ before changing the application, wallet assets, or backend. An incompatible open
161
+ client must reload matching assets before retrying.
162
+
163
+ ## Initial loading and registration
164
+
165
+ When the wallet origin stores no wallet, the host answers connection reads from
166
+ its boot code. It loads the runtime when an operation needs it. Call
167
+ `seams.authMenu.prepare()` on sign-in intent to download the sign-in code earlier.
168
+ Mounting `HostedSeamsAuthMenu` starts that download without an additional call.
169
+
170
+ Opening the hosted registration view prepares its wallet and passkey challenge.
171
+ `authMenu.prepare()` only downloads code. A direct `registerWallet()` call starts
172
+ registration setup within that call. See the
173
+ [compiled hosted-menu examples](https://wallet.seams.sh/docs/examples/wallet-setup-and-authentication).
174
+
175
+ Registration can sign before its completion appears in the Console directory.
176
+ The Gateway retries pending directory publications. Until acknowledgment, the
177
+ wallet can be absent from the Console list and unavailable for region moves.
158
178
 
159
179
  ## Public entrypoints
160
180
 
@@ -166,7 +186,7 @@ show it and reload the current assets. See the
166
186
  - `@seams/wallet/runtime` — explicit platform ports and custom signing runtime.
167
187
 
168
188
  Use the documented package exports. Agent-lane issuance and VoiceID
169
- authentication are planned and have no public 0.9.0 API.
189
+ authentication are planned and have no public API in this release.
170
190
 
171
191
  ## Develop from source
172
192
 
@@ -1 +1 @@
1
- 93b1ef116ecd8e93d9fe147324f06212aa3982133323ca33aa407d5e80a19d96
1
+ 90f4566ad3565bd0828de2eb38436e06b68bdee5db1618aaef8161d28694be5c
@@ -1,4 +1,16 @@
1
1
  //#region src/SeamsWeb/walletIframe/host/auth-menu/domain.ts
2
+ /** A wait on a prompt outside the menu shares one look: the ring, then the
3
+ * headline, then what to do in that prompt. */
4
+ const AUTH_MENU_WAITING_PROMPTS = {
5
+ passkey: {
6
+ label: "Passkey authentication",
7
+ instruction: "Complete the prompt on your device."
8
+ },
9
+ google: {
10
+ label: "Google sign-in",
11
+ instruction: "Choose your Google account."
12
+ }
13
+ };
2
14
  function resolveAuthMenuLoginAccount(accountOptions, selectedAccount) {
3
15
  const exactSelection = selectedAccount ? accountOptions.find((account) => account.walletId === selectedAccount.walletId && account.authMethod === selectedAccount.authMethod) : null;
4
16
  const sameWalletSelection = selectedAccount ? accountOptions.find((account) => account.walletId === selectedAccount.walletId) : null;
@@ -82,6 +94,6 @@ function isAuthMenuGoogleActionReady(viewModel) {
82
94
  return authMenuLoginAllowsEmailOtp(resolveAuthMenuLoginAccount(viewModel.accountOptions, viewModel.selectedAccount));
83
95
  }
84
96
  //#endregion
85
- export { isAuthMenuActionReady, isAuthMenuGoogleActionReady, isAuthMenuLoadingStatus, isAuthMenuReady, resolveAuthMenuLoginAccount };
97
+ export { AUTH_MENU_WAITING_PROMPTS, isAuthMenuActionReady, isAuthMenuGoogleActionReady, isAuthMenuLoadingStatus, isAuthMenuReady, resolveAuthMenuLoginAccount };
86
98
 
87
99
  //# sourceMappingURL=domain.js.map
@@ -2,7 +2,7 @@ import { isLinkedDeviceTargetEmailAddressV1 } from "../../../../../core/types/li
2
2
  import { EMAIL_OTP_RECOVERY_KEY_ALPHABET } from "../../../../../shared-ts/src/utils/emailOtpRecoveryKey.js";
3
3
  import "../../../../../shared-ts/src/wallet-recovery/recoveryCodes.js";
4
4
  import { demoEmailOtpCodeFromDelivery } from "../../../../../core/signingEngine/session/emailOtp/challengeDelivery.js";
5
- import { isAuthMenuActionReady, isAuthMenuGoogleActionReady, isAuthMenuLoadingStatus, isAuthMenuReady, resolveAuthMenuLoginAccount } from "../../auth-menu/domain.js";
5
+ import { AUTH_MENU_WAITING_PROMPTS, isAuthMenuActionReady, isAuthMenuGoogleActionReady, isAuthMenuLoadingStatus, isAuthMenuReady, resolveAuthMenuLoginAccount } from "../../auth-menu/domain.js";
6
6
  import { PadlockIcon } from "../../../../../core/signingEngine/uiConfirm/ui/preact/PadlockIcon.js";
7
7
  import { blinkMenuItem } from "../../../../../utils/menuItemBlink.js";
8
8
  import { accountDropdownIcon, backIcon, chevronIcon, fingerprintIcon, googleIcon, linkDeviceIcon, linkFailedIcon, mailIcon, passkeyRingIcon, recoveryIcon, rerollIcon } from "./icons.js";
@@ -1130,15 +1130,16 @@ var AuthMenuSurface = class extends Component {
1130
1130
  const status = viewModel.status;
1131
1131
  if (status.kind !== "busy") return /* @__PURE__ */ jsx(Fragment$1, {});
1132
1132
  const waitingText = status.headline;
1133
+ const prompt = status.illustration ? AUTH_MENU_WAITING_PROMPTS[status.illustration] : null;
1133
1134
  return /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsxs("div", {
1134
1135
  class: "seams-waiting",
1135
1136
  role: "status",
1136
1137
  "aria-live": "polite",
1137
1138
  children: [
1138
- status.illustration === "passkey" ? /* @__PURE__ */ jsx("span", {
1139
+ prompt ? /* @__PURE__ */ jsx("span", {
1139
1140
  class: "seams-passkey-prompt",
1140
1141
  role: "img",
1141
- "aria-label": "Passkey authentication",
1142
+ "aria-label": prompt.label,
1142
1143
  children: passkeyRingIcon()
1143
1144
  }) : null,
1144
1145
  /* @__PURE__ */ jsxs("div", {
@@ -1148,9 +1149,9 @@ var AuthMenuSurface = class extends Component {
1148
1149
  class: "seams-waiting-text",
1149
1150
  children: waitingText
1150
1151
  }),
1151
- status.illustration === "passkey" ? /* @__PURE__ */ jsx("span", {
1152
+ prompt ? /* @__PURE__ */ jsx("span", {
1152
1153
  class: "seams-passkey-instruction",
1153
- children: "Complete the prompt on your device."
1154
+ children: prompt.instruction
1154
1155
  }) : null,
1155
1156
  viewModel.showProgress && status.detail && status.detail !== waitingText ? /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx("span", {
1156
1157
  class: "seams-waiting-sdk-events",
@@ -1158,10 +1159,10 @@ var AuthMenuSurface = class extends Component {
1158
1159
  }) }) : null
1159
1160
  ]
1160
1161
  }),
1161
- status.illustration !== "passkey" ? /* @__PURE__ */ jsx("div", {
1162
+ prompt ? null : /* @__PURE__ */ jsx("div", {
1162
1163
  "aria-label": "Loading",
1163
1164
  class: "seams-spinner"
1164
- }) : null
1165
+ })
1165
1166
  ]
1166
1167
  }) });
1167
1168
  }
@@ -1 +1 @@
1
- import{C as e,S as t}from"./chains-C_X_fNuS.js";import{n}from"./walletRegistrationSetupPrewarm-B9kpnrbK.js";import{t as r}from"./walletDbName-DtRewci9.js";import{_ as i,b as a,c as o,d as s,g as c,i as l,m as u,n as d,r as f,t as p,u as m,v as ee,y as te}from"./sessionObservationRevision-CnEOLDbl.js";import{a as h,c as g,i as _,l as ne,n as v,o as re,s as y,t as ie,u as ae}from"./transactionReviewAdmission-CIvR4W5_.js";import{t as b}from"./events-1dzC4Ocx.js";import{t as x}from"./walletIframeIdentity-Cz82I_Uh.js";import{t as S}from"./errors-DIWY1KR9.js";import{t as C}from"./signer-worker-DlK58rEA.js";function w(){let e=globalThis;e.global===void 0&&(e.global=globalThis),!e.process||typeof e.process!=`object`?e.process={env:{}}:(!e.process.env||typeof e.process.env!=`object`)&&(e.process.env={})}function T(){w(),window.location.origin===`null`&&(window.parent?.postMessage({type:`SERVICE_HOST_DEBUG_ORIGIN`,origin:window.location.origin,href:window.location.href},`*`),console.warn(`[WalletHost] iframe is running with opaque (null) origin. Check COEP/CORP headers and ensure navigation succeeded.`)),oe(),window.parent?.postMessage({type:`SERVICE_HOST_BOOTED`},`*`),window.parent?.postMessage({type:`SERVICE_HOST_DEBUG_ORIGIN`,origin:window.location.origin,href:window.location.href},`*`);let e=new URL(import.meta.url),t=e.searchParams.get(`v`);t&&c(t);let n=new URL(`.`,e).toString(),r=n.endsWith(`/`)?n:n+`/`;u()||i(r)}function oe(){let e=()=>{let e=document;e.documentElement.classList.add(`seams-transparent`),e.body?.classList.add(`seams-transparent`),e.documentElement.classList.remove(`dark`),e.body?.classList.remove(`dark`)};document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>e(),{once:!0}):e(),window.addEventListener(`load`,()=>e(),{once:!0})}const E={};let D=null,O=null;function se(e){return e.type===`PM_ACKNOWLEDGE_WALLET_RECOVERY_CODE_BACKUP`?(D??=import(`./runtime-recovery-codes-GOytzExh.js`),D):k(e.kind)}function ce(){k(`auth`).catch(le)}function le(){}function k(e){let t=E[e];if(t)return t;let n=M(e);return E[e]=n,n.catch(A.bind(null,e,n)),n}function A(e,t){E[e]===t&&delete E[e]}async function j(){D??=import(`./runtime-recovery-codes-GOytzExh.js`),O??=Promise.all([D,import(`./mountRecoveryCodeBackupSurface-DlEb3uD7.js`)]).then(()=>void 0),await O}function M(e){switch(e){case`auth`:return import(`./runtime-auth-ZcxkQ-XF.js`);case`near`:return import(`./runtime-near-J3hKjC7G.js`);case`ecdsa`:return import(`./runtime-ecdsa-tempo-AGjT7Xpa.js`);case`email_otp`:return import(`./runtime-email-otp-BpBOuSsT.js`);case`recovery`:return import(`./runtime-recovery-BzewdcoT.js`);case`export`:return import(`./runtime-export-CBsacCPY.js`);case`device_link`:return import(`./runtime-device-link-Dq8g_UNb.js`);case`preferences`:return import(`./runtime-preferences-CVt5sLvm.js`)}return N(e)}function N(e){throw Error(`Unhandled wallet host runtime route: ${String(e)}`)}function P(e){switch(e.type){case`PM_GET_RECENT_UNLOCKS`:case`PM_GET_CONFIRMATION_CONFIG`:return!0;case`PM_GET_EXACT_WALLET_SESSION_STATE`:{let t=e.request.payload;if(!t||typeof t!=`object`)return!1;let n=Reflect.get(t,`authenticationRead`),r=Reflect.get(t,`wallet`);return(n===`restore`||n===`current`)&&!!r&&typeof r==`object`&&Reflect.get(r,`kind`)===`current`}default:return!1}}function F(e){switch(e.type){case`PM_GET_EXACT_WALLET_SESSION_STATE`:return{revision:p(),walletId:null,state:{kind:`wallet_locked`},session:d()};case`PM_GET_RECENT_UNLOCKS`:return{walletIds:[],accountIds:[],accounts:[],lastUsedAccount:null};case`PM_GET_CONFIRMATION_CONFIG`:return{walletId:null,confirmationConfig:C,revision:0}}}let I=null;function L(){return I??=z().finally(R),I}function R(){I=null}async function z(){try{return typeof indexedDB>`u`||typeof indexedDB.databases!=`function`?!1:(await indexedDB.databases()).some(B)?await V():!0}catch{return!1}}function B(e){return e.name===r}function V(){return new Promise(e=>{let t=indexedDB.open(r);t.onupgradeneeded=()=>t.transaction?.abort(),t.onerror=()=>e(!1),t.onsuccess=()=>{let n=t.result;n.onversionchange=()=>n.close(),H(n).then(t=>{n.close(),e(t===0)},()=>{n.close(),e(!1)})}})}function H(e){let t=Array.from(e.objectStoreNames);return t.length===0?Promise.resolve(0):new Promise((n,r)=>{let i=e.transaction(t,`readonly`),a=0;for(let e of t){let t=i.objectStore(e).count();t.onsuccess=()=>{a+=t.result}}i.oncomplete=()=>n(a),i.onerror=()=>r(i.error),i.onabort=()=>r(i.error)})}function U(e){throw Error(`Unhandled wallet host route: ${String(e)}`)}function W(e,t){if(e===null)throw Error(`Invalid ${t} payload`);return e}function G(e){try{return x(e)}catch{throw Error(`Hosted auth-menu request requires a non-empty requestId`)}}function ue(e){switch(e.type){case`PM_ACTIVATE_TRANSACTION_REVIEW`:case`PING`:case`PM_PREPARE_WALLET_RUNTIME`:case`PM_SET_CONFIG`:case`PM_CANCEL`:case`PM_SET_TRANSACTION_VIEW`:case`PM_TRANSACTION_BROADCAST_STARTED`:return{kind:`boot`,type:e.type,request:e};case`PM_REGISTER_WALLET`:case`PM_ADD_WALLET_SIGNER`:case`PM_ADD_PASSKEY`:case`PM_ADD_EMAIL_OTP`:case`PM_REVOKE_AUTH_METHOD`:case`PM_GET_NEAR_PROVISIONING_STATE`:case`PM_SIGN_TX_WITH_ACTIONS`:case`PM_SIGN_AND_SEND_TX`:case`PM_SEND_TRANSACTION`:case`PM_SIGN_DELEGATE_ACTION`:case`PM_SIGN_NEP413`:return{kind:`near`,type:e.type,request:e};case`PM_OPEN_AUTH_MENU`:{let t=G(e.requestId);return{kind:`auth`,type:e.type,request:{...e,requestId:t,payload:W(s(e.payload),`hosted auth-menu open`)}}}case`PM_CANCEL_AUTH_MENU`:{let t=G(e.requestId);return{kind:`auth`,type:e.type,request:{...e,requestId:t,payload:W(o(e.payload),`hosted auth-menu cancellation`)}}}case`PM_RESOLVE_AUTH_MENU_EXTERNAL_AUTH`:{let t=G(e.requestId);return{kind:`auth`,type:e.type,request:{...e,requestId:t,payload:W(m(e.payload),`hosted auth-menu external-auth resolution`)}}}case`PM_UNLOCK`:case`PM_LOCK`:case`PM_LOCK_EXACT_WALLET_SESSION`:case`PM_GET_LAST_WALLET_MOVE_REQUEST`:case`PM_MOVE_WALLET`:case`PM_GET_WALLET_MOVE`:case`PM_GET_WALLET_PLACEMENT`:case`PM_GET_WALLET_SESSION`:case`PM_GET_EXACT_WALLET_SESSION_STATE`:case`PM_GET_RECENT_UNLOCKS`:return{kind:`auth`,type:e.type,request:e};case`PM_SIGN_TEMPO`:case`PM_REPORT_TEMPO_BROADCAST_ACCEPTED`:case`PM_REPORT_TEMPO_BROADCAST_REJECTED`:case`PM_REPORT_TEMPO_FINALIZED`:case`PM_REPORT_TEMPO_DROPPED_OR_REPLACED`:case`PM_RECONCILE_TEMPO_NONCE_LANE`:return{kind:`ecdsa`,type:e.type,request:e};case`PM_REDEEM_HOSTED_WALLET_SEAMS_SESSION`:case`PM_REQUEST_EMAIL_OTP_CHALLENGE`:case`PM_BEGIN_GOOGLE_EMAIL_OTP_WALLET_AUTH`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_RESEND`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_REROLL_WALLET_ID`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_SUBMIT`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_COMPLETE_REGISTRATION`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_CANCEL`:case`PM_GET_WALLET_RECOVERY_CODE_STATUS`:case`PM_ACKNOWLEDGE_WALLET_RECOVERY_CODE_BACKUP`:case`PM_ROTATE_WALLET_RECOVERY_CODES`:case`PM_REQUEST_WALLET_CUSTODY_EMAIL_OTP_CHALLENGE`:return{kind:`email_otp`,type:e.type,request:e};case`PM_SYNC_ACCOUNT_FLOW`:return{kind:`recovery`,type:e.type,request:e};case`PM_RESOLVE_EXACT_KEY_EXPORT_LANE`:case`PM_EXPORT_KEYPAIR_UI`:return{kind:`export`,type:e.type,request:e};case`PM_HAS_PASSKEY`:case`PM_LIST_LINKED_DEVICES`:case`PM_REVOKE_LINKED_DEVICE`:case`PM_SCAN_AND_LINK_DEVICE`:case`PM_START_DEVICE2_LINKING_FLOW`:case`PM_DEVICE_LINK_TARGET_FACTOR_ACTION`:case`PM_DEVICE_LINK_EMAIL_OTP_BASE_FACTOR_ACTION`:case`PM_CANCEL_DEVICE_LINKING`:return{kind:`device_link`,type:e.type,request:e};case`PM_SET_CONFIRM_BEHAVIOR`:case`PM_SET_CONFIRMATION_CONFIG`:case`PM_GET_CONFIRMATION_CONFIG`:return{kind:`preferences`,type:e.type,request:e}}return U(e)}function de(e){return e.kind!==`boot`}let K=!1;const fe=[{selector:`.seams-auth-menu-surface`,cancellationKind:`native_cancel`},{selector:`.seams-confirmation-surface`,cancellationKind:`native_cancel`},{selector:`.seams-export-surface`,cancellationKind:`wallet_iframe_cancel`},{selector:`[data-seams-wallet-recovery-backup-dialog]`,cancellationKind:`native_cancel`}];function q(e,t){let n=new Set(t),r=Object.keys(e);return r.length===t.length&&r.every(e=>n.has(e))}function pe(t){return!e(t)||!q(t,[`type`,`payload`])||t.type!==`CONNECT`||!e(t.payload)||!q(t.payload,[`protocolVersion`])?null:typeof t.payload.protocolVersion==`string`?{type:`CONNECT`,payload:{protocolVersion:t.payload.protocolVersion}}:null}function J(e){if(e===`null`)return!0;try{let t=new URL(e);return(t.protocol===`https:`||t.protocol===`http:`)&&t.origin===e}catch{return!1}}function Y(e){try{e.close()}catch{}}function me(e,t){if(t===`16.0.0`)return!1;let n={expectedProtocolVersion:l,receivedProtocolVersion:t};try{e.postMessage({type:`ERROR`,payload:{code:f,message:`Wallet iframe protocol version mismatch: expected ${l}, received ${t??`missing`}`,details:n}})}catch{}return Y(e),!0}function X(e,t){return!t||t.has(e)}function Z(e,t,n,r){e.executionGeneration===t&&n(r)}function Q(e,t,n,r){return e.executionGeneration!==t||n(r)}function $(e={}){if(K)return;K=!0,T(),(!e.supportedRuntimeRouteKinds||e.supportedRuntimeRouteKinds.has(`email_otp`))&&j().catch(()=>void 0);let r=new Set,i=new Set,o=!1,s={parentOrigin:null,port:null,configuration:{kind:`unconfigured`},executionGeneration:0,onConfigurationChanged:null},c=e=>{try{s.port?.postMessage(e)}catch{}},u=e=>{e&&r.add(e)},d=e=>!!e&&(r.has(e)||_(e)?.cancelled===!0),f=e=>{e&&r.delete(e)},p=e=>{e&&c({type:`ERROR`,requestId:e,payload:{code:`cancelled`,message:`Request cancelled`}})},m=e=>!e||!d(e)?!1:_(e)?.cancelled?!0:(p(e),f(e),!0),x=()=>{for(let e of fe){let t=document.querySelectorAll(e.selector);for(let n of t)try{e.cancellationKind===`native_cancel`?n.dispatchEvent(new Event(`cancel`,{cancelable:!0})):n.dispatchEvent(new CustomEvent(b.TX_CONFIRMER_CANCEL,{bubbles:!0,composed:!0}))}catch{}}},C=async r=>{let l=r.data;if(!l||!t(l))return;let b=l.requestId,C=s.executionGeneration,w=Z.bind(null,s,C,c),T=null;try{if(`transactionReview`in l){if(l.type!==`PM_SIGN_AND_SEND_TX`&&l.type!==`PM_SIGN_TEMPO`)throw new h(`review_invalid_input`,`Review is unsupported for this request`);let e=g(l.transactionReview);if(e.requestId!==b)throw new h(`review_invalid_input`,`Review request identity mismatch`);let t=l.payload?.options?.confirmationConfig;if(t?.uiMode!==`modal`||t.behavior!==`requireClick`)throw new h(`review_unsupported_mode`,`Review requires modal presentation and explicit approval`);T=new ie(e,l.type===`PM_SIGN_TEMPO`&&l.payload?.request.senderSignatureAlgorithm!==`secp256k1`?`credential`:`mpc`,e=>w({type:`TRANSACTION_REVIEW_STATE`,requestId:b,payload:e}),e=>w({type:`ERROR`,requestId:b,payload:{code:e instanceof h?e.code:`cancelled`,message:e.message}}))}(l.type===`PM_LOCK`||l.type===`PM_LOCK_EXACT_WALLET_SESSION`)&&v(new h(`review_identity_changed`,`The wallet session changed`));let t=ue(l);if(!de(t))switch(t.type){case`PING`:c({type:`PONG`,requestId:b});return;case`PM_PREPARE_WALLET_RUNTIME`:X(`auth`,e.supportedRuntimeRouteKinds)&&ce(),c({type:`PONG`,requestId:b});return;case`PM_SET_CONFIG`:{let e=ee(s.configuration,te(t.request.payload)),r=a(s.configuration.kind===`configured`?s.configuration.config:null)!==a(e.config);if(s.configuration=e,r){s.executionGeneration+=1;let t=e.config;t.registration.publishableKey&&t.registration.projectEnvironmentId&&n(t.network.relayer.url);for(let e of i)c({type:`ERROR`,requestId:e,payload:{code:`wallet_configuration_changed`,message:`Wallet configuration changed during request`}});i.clear()}s.onConfigurationChanged?.(),r&&(v(new h(`review_identity_changed`,`Wallet execution configuration changed`)),x()),c({type:`PONG`,requestId:b});return}case`PM_ACTIVATE_TRANSACTION_REVIEW`:{let e=y(t.request.payload);e&&_(e.requestId)?.activate(e);return}case`PM_CANCEL`:{let e=t.request.payload?.requestId,n=t.request.payload,r=n&&typeof n==`object`?Reflect.get(n,`transactionReview`):void 0;if(r!==void 0){let t=g(r),i=_(t.requestId);if(t.requestId===e&&i&&ne(t,i.metadata)){let e=new h(ae(n&&typeof n==`object`?Reflect.get(n,`reviewErrorCode`):void 0),`Reviewed request cancelled`);try{re(i.metadata.validity)}catch(t){t instanceof Error&&(e=t)}i.cancel(e)}c({type:`PONG`,requestId:b});return}let i=e?_(e):void 0;if(i){i.cancel(new h(`cancelled`,`Request cancelled`)),c({type:`PONG`,requestId:b});return}u(e),x(),e&&p(e),c({type:`PONG`,requestId:b});return}case`PM_SET_TRANSACTION_VIEW`:{let e=t.request.payload,n=e&&typeof e==`object`?Reflect.get(e,`requestId`):null,r=e&&typeof e==`object`?Reflect.get(e,`view`):null;typeof n==`string`&&(r===`toast`||r===`closed`)&&(await import(`./transaction-activity-Cccvec2J.js`).then(e=>e.o)).setTransactionActivityView(n,r);return}case`PM_TRANSACTION_BROADCAST_STARTED`:{let e=t.request.payload,n=e&&typeof e==`object`?Reflect.get(e,`signedTransaction`):null;typeof n==`string`&&(await import(`./transaction-activity-Cccvec2J.js`).then(e=>e.o)).transactionBroadcastStarted(n);return}}if(!X(t.kind,e.supportedRuntimeRouteKinds)){c({type:`ERROR`,requestId:b,payload:{code:`unsupported_request`,message:`Unsupported wallet iframe request type: ${t.type}`}});return}if(b&&i.add(b),!o&&P(t)&&await L()&&!o){if(C!==s.executionGeneration||m(b))return;w({type:`PM_RESULT`,requestId:b,payload:{ok:!0,result:F(t)}});return}o=!0;let r=await se(t);if(C!==s.executionGeneration)return;await r.handleWalletHostRuntimeRequest({transactionReview:T,state:s,executionGeneration:C,req:t.request,post:Z.bind(null,s,C,c),isCancelled:Q.bind(null,s,C,d),respondIfCancelled:Q.bind(null,s,C,m)})}catch(e){if(C!==s.executionGeneration&&l.type!==`PM_SET_CONFIG`||T?.cancelled)return;let t=await import(`./canonicalSignerErrorCode-Cz48v4oy.js`);if(C!==s.executionGeneration&&l.type!==`PM_SET_CONFIG`)return;let n=e&&typeof e==`object`&&`code`in e?e.code:void 0,r=S(e),i=t.resolveWalletBoundaryErrorCode({requestType:l.type,rawCode:n,message:r,defaultCode:`HOST_ERROR`}),a=t.resolveWalletBoundaryErrorMessage({requestType:l.type,rawCode:n,code:i,message:r}),o=t.resolveWalletBoundarySignerKind(l.type);c({type:`ERROR`,requestId:b,payload:{code:i,message:a,...t.isWalletSignerBoundaryRequestType(l.type)&&t.isCanonicalSignerSessionBoundaryCode(i)&&o?{signerKind:o}:{}}})}finally{b&&(i.delete(b),f(b)),T?.finish()}};window.addEventListener(`message`,e=>{let t=pe(e.data),n=e.ports[0];if(!(!t||!n||s.port)){if(e.source!==window.parent||!J(e.origin)){Y(n);return}if(!me(n,t.payload.protocolVersion)){typeof e.origin==`string`&&e.origin.length&&e.origin!==`null`&&(s.parentOrigin=e.origin),s.port=n;try{s.port.onmessage=C,s.port.start?.()}catch{}c({type:`READY`,payload:{protocolVersion:l}})}}})}try{$()}catch(e){console.error(`[WalletHost] init failed`,e)}export{$ as t};
1
+ import{C as e,S as t}from"./chains-C_X_fNuS.js";import{n}from"./walletRegistrationSetupPrewarm-B9kpnrbK.js";import{t as r}from"./walletDbName-DtRewci9.js";import{_ as i,b as a,c as o,d as s,g as c,i as l,m as u,n as d,r as f,t as p,u as m,v as ee,y as te}from"./sessionObservationRevision-CnEOLDbl.js";import{a as h,c as g,i as _,l as ne,n as v,o as re,s as y,t as ie,u as ae}from"./transactionReviewAdmission-CIvR4W5_.js";import{t as b}from"./events-1dzC4Ocx.js";import{t as x}from"./walletIframeIdentity-Cz82I_Uh.js";import{t as S}from"./errors-DIWY1KR9.js";import{t as C}from"./signer-worker-DlK58rEA.js";function w(){let e=globalThis;e.global===void 0&&(e.global=globalThis),!e.process||typeof e.process!=`object`?e.process={env:{}}:(!e.process.env||typeof e.process.env!=`object`)&&(e.process.env={})}function T(){w(),window.location.origin===`null`&&(window.parent?.postMessage({type:`SERVICE_HOST_DEBUG_ORIGIN`,origin:window.location.origin,href:window.location.href},`*`),console.warn(`[WalletHost] iframe is running with opaque (null) origin. Check COEP/CORP headers and ensure navigation succeeded.`)),oe(),window.parent?.postMessage({type:`SERVICE_HOST_BOOTED`},`*`),window.parent?.postMessage({type:`SERVICE_HOST_DEBUG_ORIGIN`,origin:window.location.origin,href:window.location.href},`*`);let e=new URL(import.meta.url),t=e.searchParams.get(`v`);t&&c(t);let n=new URL(`.`,e).toString(),r=n.endsWith(`/`)?n:n+`/`;u()||i(r)}function oe(){let e=()=>{let e=document;e.documentElement.classList.add(`seams-transparent`),e.body?.classList.add(`seams-transparent`),e.documentElement.classList.remove(`dark`),e.body?.classList.remove(`dark`)};document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>e(),{once:!0}):e(),window.addEventListener(`load`,()=>e(),{once:!0})}const E={};let D=null,O=null;function se(e){return e.type===`PM_ACKNOWLEDGE_WALLET_RECOVERY_CODE_BACKUP`?(D??=import(`./runtime-recovery-codes-GOytzExh.js`),D):k(e.kind)}function ce(){k(`auth`).catch(le)}function le(){}function k(e){let t=E[e];if(t)return t;let n=M(e);return E[e]=n,n.catch(A.bind(null,e,n)),n}function A(e,t){E[e]===t&&delete E[e]}async function j(){D??=import(`./runtime-recovery-codes-GOytzExh.js`),O??=Promise.all([D,import(`./mountRecoveryCodeBackupSurface-DlEb3uD7.js`)]).then(()=>void 0),await O}function M(e){switch(e){case`auth`:return import(`./runtime-auth--i_j8PP7.js`);case`near`:return import(`./runtime-near-Bjrz1KYf.js`);case`ecdsa`:return import(`./runtime-ecdsa-tempo-AE5QTaXu.js`);case`email_otp`:return import(`./runtime-email-otp-Dl03QI-O.js`);case`recovery`:return import(`./runtime-recovery-DBBKvIIg.js`);case`export`:return import(`./runtime-export-F9s12UcT.js`);case`device_link`:return import(`./runtime-device-link-fpvaxYyR.js`);case`preferences`:return import(`./runtime-preferences-oLRSEqmz.js`)}return N(e)}function N(e){throw Error(`Unhandled wallet host runtime route: ${String(e)}`)}function P(e){switch(e.type){case`PM_GET_RECENT_UNLOCKS`:case`PM_GET_CONFIRMATION_CONFIG`:return!0;case`PM_GET_EXACT_WALLET_SESSION_STATE`:{let t=e.request.payload;if(!t||typeof t!=`object`)return!1;let n=Reflect.get(t,`authenticationRead`),r=Reflect.get(t,`wallet`);return(n===`restore`||n===`current`)&&!!r&&typeof r==`object`&&Reflect.get(r,`kind`)===`current`}default:return!1}}function F(e){switch(e.type){case`PM_GET_EXACT_WALLET_SESSION_STATE`:return{revision:p(),walletId:null,state:{kind:`wallet_locked`},session:d()};case`PM_GET_RECENT_UNLOCKS`:return{walletIds:[],accountIds:[],accounts:[],lastUsedAccount:null};case`PM_GET_CONFIRMATION_CONFIG`:return{walletId:null,confirmationConfig:C,revision:0}}}let I=null;function L(){return I??=z().finally(R),I}function R(){I=null}async function z(){try{return typeof indexedDB>`u`||typeof indexedDB.databases!=`function`?!1:(await indexedDB.databases()).some(B)?await V():!0}catch{return!1}}function B(e){return e.name===r}function V(){return new Promise(e=>{let t=indexedDB.open(r);t.onupgradeneeded=()=>t.transaction?.abort(),t.onerror=()=>e(!1),t.onsuccess=()=>{let n=t.result;n.onversionchange=()=>n.close(),H(n).then(t=>{n.close(),e(t===0)},()=>{n.close(),e(!1)})}})}function H(e){let t=Array.from(e.objectStoreNames);return t.length===0?Promise.resolve(0):new Promise((n,r)=>{let i=e.transaction(t,`readonly`),a=0;for(let e of t){let t=i.objectStore(e).count();t.onsuccess=()=>{a+=t.result}}i.oncomplete=()=>n(a),i.onerror=()=>r(i.error),i.onabort=()=>r(i.error)})}function U(e){throw Error(`Unhandled wallet host route: ${String(e)}`)}function W(e,t){if(e===null)throw Error(`Invalid ${t} payload`);return e}function G(e){try{return x(e)}catch{throw Error(`Hosted auth-menu request requires a non-empty requestId`)}}function ue(e){switch(e.type){case`PM_ACTIVATE_TRANSACTION_REVIEW`:case`PING`:case`PM_PREPARE_WALLET_RUNTIME`:case`PM_SET_CONFIG`:case`PM_CANCEL`:case`PM_SET_TRANSACTION_VIEW`:case`PM_TRANSACTION_BROADCAST_STARTED`:return{kind:`boot`,type:e.type,request:e};case`PM_REGISTER_WALLET`:case`PM_ADD_WALLET_SIGNER`:case`PM_ADD_PASSKEY`:case`PM_ADD_EMAIL_OTP`:case`PM_REVOKE_AUTH_METHOD`:case`PM_GET_NEAR_PROVISIONING_STATE`:case`PM_SIGN_TX_WITH_ACTIONS`:case`PM_SIGN_AND_SEND_TX`:case`PM_SEND_TRANSACTION`:case`PM_SIGN_DELEGATE_ACTION`:case`PM_SIGN_NEP413`:return{kind:`near`,type:e.type,request:e};case`PM_OPEN_AUTH_MENU`:{let t=G(e.requestId);return{kind:`auth`,type:e.type,request:{...e,requestId:t,payload:W(s(e.payload),`hosted auth-menu open`)}}}case`PM_CANCEL_AUTH_MENU`:{let t=G(e.requestId);return{kind:`auth`,type:e.type,request:{...e,requestId:t,payload:W(o(e.payload),`hosted auth-menu cancellation`)}}}case`PM_RESOLVE_AUTH_MENU_EXTERNAL_AUTH`:{let t=G(e.requestId);return{kind:`auth`,type:e.type,request:{...e,requestId:t,payload:W(m(e.payload),`hosted auth-menu external-auth resolution`)}}}case`PM_UNLOCK`:case`PM_LOCK`:case`PM_LOCK_EXACT_WALLET_SESSION`:case`PM_GET_LAST_WALLET_MOVE_REQUEST`:case`PM_MOVE_WALLET`:case`PM_GET_WALLET_MOVE`:case`PM_GET_WALLET_PLACEMENT`:case`PM_GET_WALLET_SESSION`:case`PM_GET_EXACT_WALLET_SESSION_STATE`:case`PM_GET_RECENT_UNLOCKS`:return{kind:`auth`,type:e.type,request:e};case`PM_SIGN_TEMPO`:case`PM_REPORT_TEMPO_BROADCAST_ACCEPTED`:case`PM_REPORT_TEMPO_BROADCAST_REJECTED`:case`PM_REPORT_TEMPO_FINALIZED`:case`PM_REPORT_TEMPO_DROPPED_OR_REPLACED`:case`PM_RECONCILE_TEMPO_NONCE_LANE`:return{kind:`ecdsa`,type:e.type,request:e};case`PM_REDEEM_HOSTED_WALLET_SEAMS_SESSION`:case`PM_REQUEST_EMAIL_OTP_CHALLENGE`:case`PM_BEGIN_GOOGLE_EMAIL_OTP_WALLET_AUTH`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_RESEND`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_REROLL_WALLET_ID`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_SUBMIT`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_COMPLETE_REGISTRATION`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_CANCEL`:case`PM_GET_WALLET_RECOVERY_CODE_STATUS`:case`PM_ACKNOWLEDGE_WALLET_RECOVERY_CODE_BACKUP`:case`PM_ROTATE_WALLET_RECOVERY_CODES`:case`PM_REQUEST_WALLET_CUSTODY_EMAIL_OTP_CHALLENGE`:return{kind:`email_otp`,type:e.type,request:e};case`PM_SYNC_ACCOUNT_FLOW`:return{kind:`recovery`,type:e.type,request:e};case`PM_RESOLVE_EXACT_KEY_EXPORT_LANE`:case`PM_EXPORT_KEYPAIR_UI`:return{kind:`export`,type:e.type,request:e};case`PM_HAS_PASSKEY`:case`PM_LIST_LINKED_DEVICES`:case`PM_REVOKE_LINKED_DEVICE`:case`PM_SCAN_AND_LINK_DEVICE`:case`PM_START_DEVICE2_LINKING_FLOW`:case`PM_DEVICE_LINK_TARGET_FACTOR_ACTION`:case`PM_DEVICE_LINK_EMAIL_OTP_BASE_FACTOR_ACTION`:case`PM_CANCEL_DEVICE_LINKING`:return{kind:`device_link`,type:e.type,request:e};case`PM_SET_CONFIRM_BEHAVIOR`:case`PM_SET_CONFIRMATION_CONFIG`:case`PM_GET_CONFIRMATION_CONFIG`:return{kind:`preferences`,type:e.type,request:e}}return U(e)}function de(e){return e.kind!==`boot`}let K=!1;const fe=[{selector:`.seams-auth-menu-surface`,cancellationKind:`native_cancel`},{selector:`.seams-confirmation-surface`,cancellationKind:`native_cancel`},{selector:`.seams-export-surface`,cancellationKind:`wallet_iframe_cancel`},{selector:`[data-seams-wallet-recovery-backup-dialog]`,cancellationKind:`native_cancel`}];function q(e,t){let n=new Set(t),r=Object.keys(e);return r.length===t.length&&r.every(e=>n.has(e))}function pe(t){return!e(t)||!q(t,[`type`,`payload`])||t.type!==`CONNECT`||!e(t.payload)||!q(t.payload,[`protocolVersion`])?null:typeof t.payload.protocolVersion==`string`?{type:`CONNECT`,payload:{protocolVersion:t.payload.protocolVersion}}:null}function J(e){if(e===`null`)return!0;try{let t=new URL(e);return(t.protocol===`https:`||t.protocol===`http:`)&&t.origin===e}catch{return!1}}function Y(e){try{e.close()}catch{}}function me(e,t){if(t===`16.0.0`)return!1;let n={expectedProtocolVersion:l,receivedProtocolVersion:t};try{e.postMessage({type:`ERROR`,payload:{code:f,message:`Wallet iframe protocol version mismatch: expected ${l}, received ${t??`missing`}`,details:n}})}catch{}return Y(e),!0}function X(e,t){return!t||t.has(e)}function Z(e,t,n,r){e.executionGeneration===t&&n(r)}function Q(e,t,n,r){return e.executionGeneration!==t||n(r)}function $(e={}){if(K)return;K=!0,T(),(!e.supportedRuntimeRouteKinds||e.supportedRuntimeRouteKinds.has(`email_otp`))&&j().catch(()=>void 0);let r=new Set,i=new Set,o=!1,s={parentOrigin:null,port:null,configuration:{kind:`unconfigured`},executionGeneration:0,onConfigurationChanged:null},c=e=>{try{s.port?.postMessage(e)}catch{}},u=e=>{e&&r.add(e)},d=e=>!!e&&(r.has(e)||_(e)?.cancelled===!0),f=e=>{e&&r.delete(e)},p=e=>{e&&c({type:`ERROR`,requestId:e,payload:{code:`cancelled`,message:`Request cancelled`}})},m=e=>!e||!d(e)?!1:_(e)?.cancelled?!0:(p(e),f(e),!0),x=()=>{for(let e of fe){let t=document.querySelectorAll(e.selector);for(let n of t)try{e.cancellationKind===`native_cancel`?n.dispatchEvent(new Event(`cancel`,{cancelable:!0})):n.dispatchEvent(new CustomEvent(b.TX_CONFIRMER_CANCEL,{bubbles:!0,composed:!0}))}catch{}}},C=async r=>{let l=r.data;if(!l||!t(l))return;let b=l.requestId,C=s.executionGeneration,w=Z.bind(null,s,C,c),T=null;try{if(`transactionReview`in l){if(l.type!==`PM_SIGN_AND_SEND_TX`&&l.type!==`PM_SIGN_TEMPO`)throw new h(`review_invalid_input`,`Review is unsupported for this request`);let e=g(l.transactionReview);if(e.requestId!==b)throw new h(`review_invalid_input`,`Review request identity mismatch`);let t=l.payload?.options?.confirmationConfig;if(t?.uiMode!==`modal`||t.behavior!==`requireClick`)throw new h(`review_unsupported_mode`,`Review requires modal presentation and explicit approval`);T=new ie(e,l.type===`PM_SIGN_TEMPO`&&l.payload?.request.senderSignatureAlgorithm!==`secp256k1`?`credential`:`mpc`,e=>w({type:`TRANSACTION_REVIEW_STATE`,requestId:b,payload:e}),e=>w({type:`ERROR`,requestId:b,payload:{code:e instanceof h?e.code:`cancelled`,message:e.message}}))}(l.type===`PM_LOCK`||l.type===`PM_LOCK_EXACT_WALLET_SESSION`)&&v(new h(`review_identity_changed`,`The wallet session changed`));let t=ue(l);if(!de(t))switch(t.type){case`PING`:c({type:`PONG`,requestId:b});return;case`PM_PREPARE_WALLET_RUNTIME`:X(`auth`,e.supportedRuntimeRouteKinds)&&ce(),c({type:`PONG`,requestId:b});return;case`PM_SET_CONFIG`:{let e=ee(s.configuration,te(t.request.payload)),r=a(s.configuration.kind===`configured`?s.configuration.config:null)!==a(e.config);if(s.configuration=e,r){s.executionGeneration+=1;let t=e.config;t.registration.publishableKey&&t.registration.projectEnvironmentId&&n(t.network.relayer.url);for(let e of i)c({type:`ERROR`,requestId:e,payload:{code:`wallet_configuration_changed`,message:`Wallet configuration changed during request`}});i.clear()}s.onConfigurationChanged?.(),r&&(v(new h(`review_identity_changed`,`Wallet execution configuration changed`)),x()),c({type:`PONG`,requestId:b});return}case`PM_ACTIVATE_TRANSACTION_REVIEW`:{let e=y(t.request.payload);e&&_(e.requestId)?.activate(e);return}case`PM_CANCEL`:{let e=t.request.payload?.requestId,n=t.request.payload,r=n&&typeof n==`object`?Reflect.get(n,`transactionReview`):void 0;if(r!==void 0){let t=g(r),i=_(t.requestId);if(t.requestId===e&&i&&ne(t,i.metadata)){let e=new h(ae(n&&typeof n==`object`?Reflect.get(n,`reviewErrorCode`):void 0),`Reviewed request cancelled`);try{re(i.metadata.validity)}catch(t){t instanceof Error&&(e=t)}i.cancel(e)}c({type:`PONG`,requestId:b});return}let i=e?_(e):void 0;if(i){i.cancel(new h(`cancelled`,`Request cancelled`)),c({type:`PONG`,requestId:b});return}u(e),x(),e&&p(e),c({type:`PONG`,requestId:b});return}case`PM_SET_TRANSACTION_VIEW`:{let e=t.request.payload,n=e&&typeof e==`object`?Reflect.get(e,`requestId`):null,r=e&&typeof e==`object`?Reflect.get(e,`view`):null;typeof n==`string`&&(r===`toast`||r===`closed`)&&(await import(`./transaction-activity-Cccvec2J.js`).then(e=>e.o)).setTransactionActivityView(n,r);return}case`PM_TRANSACTION_BROADCAST_STARTED`:{let e=t.request.payload,n=e&&typeof e==`object`?Reflect.get(e,`signedTransaction`):null;typeof n==`string`&&(await import(`./transaction-activity-Cccvec2J.js`).then(e=>e.o)).transactionBroadcastStarted(n);return}}if(!X(t.kind,e.supportedRuntimeRouteKinds)){c({type:`ERROR`,requestId:b,payload:{code:`unsupported_request`,message:`Unsupported wallet iframe request type: ${t.type}`}});return}if(b&&i.add(b),!o&&P(t)&&await L()&&!o){if(C!==s.executionGeneration||m(b))return;w({type:`PM_RESULT`,requestId:b,payload:{ok:!0,result:F(t)}});return}o=!0;let r=await se(t);if(C!==s.executionGeneration)return;await r.handleWalletHostRuntimeRequest({transactionReview:T,state:s,executionGeneration:C,req:t.request,post:Z.bind(null,s,C,c),isCancelled:Q.bind(null,s,C,d),respondIfCancelled:Q.bind(null,s,C,m)})}catch(e){if(C!==s.executionGeneration&&l.type!==`PM_SET_CONFIG`||T?.cancelled)return;let t=await import(`./canonicalSignerErrorCode-Cz48v4oy.js`);if(C!==s.executionGeneration&&l.type!==`PM_SET_CONFIG`)return;let n=e&&typeof e==`object`&&`code`in e?e.code:void 0,r=S(e),i=t.resolveWalletBoundaryErrorCode({requestType:l.type,rawCode:n,message:r,defaultCode:`HOST_ERROR`}),a=t.resolveWalletBoundaryErrorMessage({requestType:l.type,rawCode:n,code:i,message:r}),o=t.resolveWalletBoundarySignerKind(l.type);c({type:`ERROR`,requestId:b,payload:{code:i,message:a,...t.isWalletSignerBoundaryRequestType(l.type)&&t.isCanonicalSignerSessionBoundaryCode(i)&&o?{signerKind:o}:{}}})}finally{b&&(i.delete(b),f(b)),T?.finish()}};window.addEventListener(`message`,e=>{let t=pe(e.data),n=e.ports[0];if(!(!t||!n||s.port)){if(e.source!==window.parent||!J(e.origin)){Y(n);return}if(!me(n,t.payload.protocolVersion)){typeof e.origin==`string`&&e.origin.length&&e.origin!==`null`&&(s.parentOrigin=e.origin),s.port=n;try{s.port.onmessage=C,s.port.start?.()}catch{}c({type:`READY`,payload:{protocolVersion:l}})}}})}try{$()}catch(e){console.error(`[WalletHost] init failed`,e)}export{$ as t};