LavaPack.loadBundle([[998,{"@firebase/util":1003},function(){with(this.scopeTerminator)with(this.globalThis)return function(){"use strict";return function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.Provider=n.ComponentContainer=n.Component=void 0;var a=e("@firebase/util");
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
n.Component=class{constructor(e,t,n){this.name=e,this.instanceFactory=t,this.type=n,this.multipleInstances=!1,this.serviceProps={},this.instantiationMode="LAZY",this.onInstanceCreated=null}setInstantiationMode(e){return this.instantiationMode=e,this}setMultipleInstances(e){return this.multipleInstances=e,this}setServiceProps(e){return this.serviceProps=e,this}setInstanceCreatedCallback(e){return this.onInstanceCreated=e,this}};const r="[DEFAULT]";
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */class i{constructor(e,t){this.name=e,this.container=t,this.component=null,this.instances=new Map,this.instancesDeferred=new Map,this.instancesOptions=new Map,this.onInitCallbacks=new Map}get(e){const t=this.normalizeInstanceIdentifier(e);if(!this.instancesDeferred.has(t)){const e=new a.Deferred;if(this.instancesDeferred.set(t,e),this.isInitialized(t)||this.shouldAutoInitialize())try{const n=this.getOrInitializeService({instanceIdentifier:t});n&&e.resolve(n)}catch(e){}}return this.instancesDeferred.get(t).promise}getImmediate(e){var t;const n=this.normalizeInstanceIdentifier(null==e?void 0:e.identifier),a=null!==(t=null==e?void 0:e.optional)&&void 0!==t&&t;if(!this.isInitialized(n)&&!this.shouldAutoInitialize()){if(a)return null;throw Error(`Service ${this.name} is not available`)}try{return this.getOrInitializeService({instanceIdentifier:n})}catch(e){if(a)return null;throw e}}getComponent(){return this.component}setComponent(e){if(e.name!==this.name)throw Error(`Mismatching Component ${e.name} for Provider ${this.name}.`);if(this.component)throw Error(`Component for ${this.name} has already been provided`);if(this.component=e,this.shouldAutoInitialize()){if(function(e){return"EAGER"===e.instantiationMode}
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */(e))try{this.getOrInitializeService({instanceIdentifier:r})}catch(e){}for(const[e,t]of this.instancesDeferred.entries()){const n=this.normalizeInstanceIdentifier(e);try{const e=this.getOrInitializeService({instanceIdentifier:n});t.resolve(e)}catch(e){}}}}clearInstance(e=r){this.instancesDeferred.delete(e),this.instancesOptions.delete(e),this.instances.delete(e)}async delete(){const e=Array.from(this.instances.values());await Promise.all([...e.filter(e=>"INTERNAL"in e).map(e=>e.INTERNAL.delete()),...e.filter(e=>"_delete"in e).map(e=>e._delete())])}isComponentSet(){return null!=this.component}isInitialized(e=r){return this.instances.has(e)}getOptions(e=r){return this.instancesOptions.get(e)||{}}initialize(e={}){const{options:t={}}=e,n=this.normalizeInstanceIdentifier(e.instanceIdentifier);if(this.isInitialized(n))throw Error(`${this.name}(${n}) has already been initialized`);if(!this.isComponentSet())throw Error(`Component ${this.name} has not been registered yet`);const a=this.getOrInitializeService({instanceIdentifier:n,options:t});for(const[e,t]of this.instancesDeferred.entries()){n===this.normalizeInstanceIdentifier(e)&&t.resolve(a)}return a}onInit(e,t){var n;const a=this.normalizeInstanceIdentifier(t),r=null!==(n=this.onInitCallbacks.get(a))&&void 0!==n?n:new Set;r.add(e),this.onInitCallbacks.set(a,r);const i=this.instances.get(a);return i&&e(i,a),()=>{r.delete(e)}}invokeOnInitCallbacks(e,t){const n=this.onInitCallbacks.get(t);if(n)for(const a of n)try{a(e,t)}catch(e){}}getOrInitializeService({instanceIdentifier:e,options:t={}}){let n=this.instances.get(e);if(!n&&this.component&&(n=this.component.instanceFactory(this.container,{instanceIdentifier:(a=e,a===r?undefined:a),options:t}),this.instances.set(e,n),this.instancesOptions.set(e,t),this.invokeOnInitCallbacks(n,e),this.component.onInstanceCreated))try{this.component.onInstanceCreated(this.container,e,n)}catch(e){}var a;return n||null}normalizeInstanceIdentifier(e=r){return this.component?this.component.multipleInstances?e:r:e}shouldAutoInitialize(){return!!this.component&&"EXPLICIT"!==this.component.instantiationMode}}n.Provider=i;n.ComponentContainer=class{constructor(e){this.name=e,this.providers=new Map}addComponent(e){const t=this.getProvider(e.name);if(t.isComponentSet())throw new Error(`Component ${e.name} has already been registered with ${this.name}`);t.setComponent(e)}addOrOverwriteComponent(e){this.getProvider(e.name).isComponentSet()&&this.providers.delete(e.name),this.addComponent(e)}getProvider(e){if(this.providers.has(e))return this.providers.get(e);const t=new i(e,this);return this.providers.set(e,t),t}getProviders(){return Array.from(this.providers.values())}}}}},{package:"@metamask/notification-services-controller>firebase>@firebase/app>@firebase/component",file:"node_modules/@firebase/component/dist/esm/index.esm2017.js"}],[999,{"@firebase/app":997,"@firebase/component":998,"@firebase/util":1003,idb:6831},function(){with(this.scopeTerminator)with(this.globalThis)return function(){"use strict";return function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.deleteInstallations=
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
async function(e){const{appConfig:t}=e,n=await K(t,e=>e&&0===e.registrationStatus?undefined:e);if(n){if(1===n.registrationStatus)throw h.create("delete-pending-registration");if(2===n.registrationStatus){if(!navigator.onLine)throw h.create("app-offline");
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
await async function(e,t){const n=function(e,{fid:t}){return`${b(e)}/${t}`}(e,t),a=C(e,t),r={method:"DELETE",headers:a},i=await v(()=>fetch(n,r));if(!i.ok)throw await w("Delete Installation",i)}(t,n),await x(t)}}}
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */,n.getId=J,n.getInstallations=
/**
 * @license
 * Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
function(e=(0,a.getApp)()){return(0,a._getProvider)(e,"installations").getImmediate()}
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */,n.getToken=X,n.onIdChange=function(e,t){const{appConfig:n}=e;return function(e,t){N();const n=A(e);let a=P.get(n);a||(a=new Set,P.set(n,a));a.add(t)}(n,t),()=>{!function(e,t){const n=A(e),a=P.get(n);if(!a)return;a.delete(t),0===a.size&&P.delete(n);R()}(n,t)}};var a=e("@firebase/app"),r=e("@firebase/component"),i=e("@firebase/util"),s=e("idb");const o="@firebase/installations",l="0.6.12",c=1e4,d=`w:${l}`,u="FIS_v2",p="https://firebaseinstallations.googleapis.com/v1",f=36e5,g={"missing-app-config-values":'Missing App configuration value: "{$valueName}"',"not-registered":"Firebase Installation is not registered.","installation-not-found":"Firebase Installation not found.","request-failed":'{$requestName} request failed with error "{$serverCode} {$serverStatus}: {$serverMessage}"',"app-offline":"Could not process request. Application offline.","delete-pending-registration":"Can't delete installation while there is a pending registration request."},h=new i.ErrorFactory("installations","Installations",g);function m(e){return e instanceof i.FirebaseError&&e.code.includes("request-failed")}
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function b({projectId:e}){return`${p}/projects/${e}/installations`}function E(e){return{token:e.token,requestStatus:2,expiresIn:(t=e.expiresIn,Number(t.replace("s","000"))),creationTime:Date.now()};var t}async function w(e,t){const n=(await t.json()).error;return h.create("request-failed",{requestName:e,serverCode:n.code,serverMessage:n.message,serverStatus:n.status})}function S({apiKey:e}){return new Headers({"Content-Type":"application/json",Accept:"application/json","x-goog-api-key":e})}function C(e,{refreshToken:t}){const n=S(e);return n.append("Authorization",function(e){return`${u} ${e}`}
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */(t)),n}async function v(e){const t=await e();return t.status>=500&&t.status<600?e():t}
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
function M(e){return new Promise(t=>{setTimeout(t,e)})}
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
const I=/^[cdef][\w-]{21}$/,T="";function y(){try{const e=new Uint8Array(17);(self.crypto||self.msCrypto).getRandomValues(e),e[0]=112+e[0]%16;const t=function(e){const t=(n=e,btoa(String.fromCharCode(...n)).replace(/\+/g,"-").replace(/\//g,"_"));var n;return t.substr(0,22)}
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */(e);return I.test(t)?t:T}catch(e){return T}}function A(e){return`${e.appName}!${e.appId}`}
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const P=new Map;function O(e,t){const n=A(e);k(n,t),function(e,t){const n=N();n&&n.postMessage({key:e,fid:t});R()}(n,t)}function k(e,t){const n=P.get(e);if(n)for(const e of n)e(t)}let _=null;function N(){return!_&&"BroadcastChannel"in self&&(_=new BroadcastChannel("[Firebase] FID Change"),_.onmessage=e=>{k(e.data.key,e.data.fid)}),_}function R(){0===P.size&&_&&(_.close(),_=null)}
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const L="firebase-installations-database",D=1,U="firebase-installations-store";let j=null;function F(){return j||(j=(0,s.openDB)(L,D,{upgrade:(e,t)=>{if(0===t)e.createObjectStore(U)}})),j}async function V(e,t){const n=A(e),a=(await F()).transaction(U,"readwrite"),r=a.objectStore(U),i=await r.get(n);return await r.put(t,n),await a.done,i&&i.fid===t.fid||O(e,t.fid),t}async function x(e){const t=A(e),n=(await F()).transaction(U,"readwrite");await n.objectStore(U).delete(t),await n.done}async function K(e,t){const n=A(e),a=(await F()).transaction(U,"readwrite"),r=a.objectStore(U),i=await r.get(n),s=t(i);return s===undefined?await r.delete(n):await r.put(s,n),await a.done,!s||i&&i.fid===s.fid||O(e,s.fid),s}
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */async function B(e){let t;const n=await K(e.appConfig,n=>{const a=function(e){const t=e||{fid:y(),registrationStatus:0};return q(t)}(n),r=function(e,t){if(0===t.registrationStatus){if(!navigator.onLine){return{installationEntry:t,registrationPromise:Promise.reject(h.create("app-offline"))}}const n={fid:t.fid,registrationStatus:1,registrationTime:Date.now()},a=async function(e,t){try{const n=await async function({appConfig:e,heartbeatServiceProvider:t},{fid:n}){const a=b(e),r=S(e),i=t.getImmediate({optional:!0});if(i){const e=await i.getHeartbeatsHeader();e&&r.append("x-firebase-client",e)}const s={fid:n,authVersion:u,appId:e.appId,sdkVersion:d},o={method:"POST",headers:r,body:JSON.stringify(s)},l=await v(()=>fetch(a,o));if(l.ok){const e=await l.json();return{fid:e.fid||n,registrationStatus:2,refreshToken:e.refreshToken,authToken:E(e.authToken)}}throw await w("Create Installation",l)}(e,t);return V(e.appConfig,n)}catch(n){throw m(n)&&409===n.customData.serverCode?await x(e.appConfig):await V(e.appConfig,{fid:t.fid,registrationStatus:0}),n}}(e,n);return{installationEntry:n,registrationPromise:a}}return 1===t.registrationStatus?{installationEntry:t,registrationPromise:z(e)}:{installationEntry:t}}(e,a);return t=r.registrationPromise,r.installationEntry});return n.fid===T?{installationEntry:await t}:{installationEntry:n,registrationPromise:t}}async function z(e){let t=await $(e.appConfig);for(;1===t.registrationStatus;)await M(100),t=await $(e.appConfig);if(0===t.registrationStatus){const{installationEntry:t,registrationPromise:n}=await B(e);return n||t}return t}function $(e){return K(e,e=>{if(!e)throw h.create("installation-not-found");return q(e)})}function q(e){return 1===(t=e).registrationStatus&&t.registrationTime+c<Date.now()?{fid:e.fid,registrationStatus:0}:e;var t;
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */}async function Y({appConfig:e,heartbeatServiceProvider:t},n){const a=function(e,{fid:t}){return`${b(e)}/${t}/authTokens:generate`}
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */(e,n),r=C(e,n),i=t.getImmediate({optional:!0});if(i){const e=await i.getHeartbeatsHeader();e&&r.append("x-firebase-client",e)}const s={installation:{sdkVersion:d,appId:e.appId}},o={method:"POST",headers:r,body:JSON.stringify(s)},l=await v(()=>fetch(a,o));if(l.ok){return E(await l.json())}throw await w("Generate Auth Token",l)}async function G(e,t=!1){let n;const a=await K(e.appConfig,a=>{if(!W(a))throw h.create("not-registered");const r=a.authToken;if(!t&&function(e){return 2===e.requestStatus&&!function(e){const t=Date.now();return t<e.creationTime||e.creationTime+e.expiresIn<t+f}(e)}(r))return a;if(1===r.requestStatus)return n=async function(e,t){let n=await H(e.appConfig);for(;1===n.authToken.requestStatus;)await M(100),n=await H(e.appConfig);const a=n.authToken;return 0===a.requestStatus?G(e,t):a}(e,t),a;{if(!navigator.onLine)throw h.create("app-offline");const t=function(e){const t={requestStatus:1,requestTime:Date.now()};return Object.assign(Object.assign({},e),{authToken:t})}(a);return n=async function(e,t){try{const n=await Y(e,t),a=Object.assign(Object.assign({},t),{authToken:n});return await V(e.appConfig,a),n}catch(n){if(!m(n)||401!==n.customData.serverCode&&404!==n.customData.serverCode){const n=Object.assign(Object.assign({},t),{authToken:{requestStatus:0}});await V(e.appConfig,n)}else await x(e.appConfig);throw n}}(e,t),t}});return n?await n:a.authToken}function H(e){return K(e,e=>{if(!W(e))throw h.create("not-registered");const t=e.authToken;return 1===(n=t).requestStatus&&n.requestTime+c<Date.now()?Object.assign(Object.assign({},e),{authToken:{requestStatus:0}}):e;var n;
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */})}function W(e){return e!==undefined&&2===e.registrationStatus}async function J(e){const t=e,{installationEntry:n,registrationPromise:a}=await B(t);return a?a.catch(console.error):G(t).catch(console.error),n.fid}
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */async function X(e,t=!1){const n=e;await async function(e){const{registrationPromise:t}=await B(e);t&&await t}(n);return(await G(n,t)).token}function Z(e){return h.create("missing-app-config-values",{valueName:e})}
/**
 * @license
 * Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const Q="installations",ee=e=>{const t=e.getProvider("app").getImmediate(),n=function(e){if(!e||!e.options)throw Z("App Configuration");if(!e.name)throw Z("App Name");const t=["projectId","apiKey","appId"];for(const n of t)if(!e.options[n])throw Z(n);return{appName:e.name,projectId:e.options.projectId,apiKey:e.options.apiKey,appId:e.options.appId}}(t);return{app:t,appConfig:n,heartbeatServiceProvider:(0,a._getProvider)(t,"heartbeat"),_delete:()=>Promise.resolve()}},te=e=>{const t=e.getProvider("app").getImmediate(),n=(0,a._getProvider)(t,Q).getImmediate();return{getId:()=>J(n),getToken:e=>X(n,e)}};(0,a._registerComponent)(new r.Component(Q,ee,"PUBLIC")),(0,a._registerComponent)(new r.Component("installations-internal",te,"PRIVATE")),(0,a.registerVersion)(o,l),(0,a.registerVersion)(o,l,"esm2017")}}},{package:"@metamask/notification-services-controller>firebase>@firebase/installations",file:"node_modules/@firebase/installations/dist/esm/index.esm2017.js"}],[12,{"../../shared/constants/app":8457,"../../shared/constants/app-state":8456,"../../shared/constants/defi-referrals":8467,"../../shared/constants/errors":8468,"../../shared/constants/infura-project-id":8473,"../../shared/constants/messages":8478,"../../shared/constants/metametrics":8479,"../../shared/constants/offscreen-communication":8485,"../../shared/constants/onboarding":8486,"../../shared/constants/start-up-errors":8499,"../../shared/constants/ui-initialization":8507,"../../shared/lib/active-tab-domain-metrics":8524,"../../shared/lib/browser-runtime.utils":8541,"../../shared/lib/caip-stream":8544,"../../shared/lib/fetch-with-timeout":8596,"../../shared/lib/get-first-preferred-lang-code":8616,"../../shared/lib/install-attribution":8620,"../../shared/lib/manifestFlags":8622,"../../shared/lib/mv3.utils":8634,"../../shared/lib/object.utils":8637,"../../shared/lib/promise-with-resolvers":8647,"../../shared/lib/selectors/networks":8657,"../../shared/lib/sentry":8663,"../../shared/lib/stores/persistence-manager":8677,"./constants/background":13,"./constants/marketing-site-whitelist":14,"./constants/sentry-state":15,"./constants/snaps":16,"./constants/stream":17,"./controllers/analytics":22,"./first-time-state":66,"./lib/CronjobControllerStorageManager":70,"./lib/approval/utils":77,"./lib/critical-error/critical-error-recovery":92,"./lib/critical-error/critical-error-tab-handoff":93,"./lib/deep-links/deep-link-router":97,"./lib/deep-links/metrics":98,"./lib/defi-referrals/createDefiReferralMiddleware":99,"./lib/ens-ipfs/setup":107,"./lib/extension-lazy-listener/extension-lazy-listener":108,"./lib/getIframeProperties":110,"./lib/getObjStructure":111,"./lib/migrator":117,"./lib/notification-manager":120,"./lib/repair":134,"./lib/safe-reload":151,"./lib/setup-initial-state-hooks":155,"./lib/start-up-errors/start-up-errors":168,"./lib/state-corruption/state-corruption-recovery":169,"./lib/stream-utils":172,"./lib/update-remote-feature-flags":209,"./lib/use-split-state-storage":210,"./lib/util":211,"./metamask-controller":436,"./migrations":684,"./offscreen":685,"./on-update":686,"./platforms/extension":687,"@metamask/base-controller":1451,"@metamask/design-tokens":2120,"@metamask/utils":3991,"extension-port-stream":6550,loglevel:7151,"readable-stream":7628,"webextension-polyfill":8444},function(){with(this.scopeTerminator)with(this.globalThis)return function(){"use strict";return function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.loadStateFromPersistence=it,n.setupController=ut;var a=e("./lib/setup-initial-state-hooks");e("../../shared/constants/infura-project-id");var r=e("@metamask/design-tokens"),i=e("readable-stream"),s=pe(e("loglevel")),o=pe(e("webextension-polyfill")),l=e("@metamask/utils"),c=e("@metamask/base-controller"),d=e("extension-port-stream"),u=e("../../shared/lib/promise-with-resolvers"),p=e("../../shared/constants/onboarding"),f=e("../../shared/constants/app"),g=e("../../shared/constants/app-state"),h=e("../../shared/constants/messages"),m=e("../../shared/constants/ui-initialization"),b=e("../../shared/constants/metametrics"),E=e("../../shared/lib/active-tab-domain-metrics"),w=e("../../shared/lib/browser-runtime.utils"),S=e("../../shared/lib/mv3.utils"),C=e("../../shared/lib/object.utils"),v=(e("../../shared/constants/offscreen-communication"),e("../../shared/lib/sentry")),M=e("../../shared/lib/selectors/networks"),I=e("../../shared/lib/caip-stream"),T=pe(e("../../shared/lib/fetch-with-timeout")),y=e("../../shared/constants/errors"),A=pe(e("../../shared/lib/get-first-preferred-lang-code")),P=(e("../../shared/lib/manifestFlags"),e("../../shared/constants/start-up-errors")),O=e("../../shared/constants/defi-referrals"),k=e("../../shared/lib/install-attribution"),_=e("../../shared/lib/stores/persistence-manager"),N=e("./lib/critical-error/critical-error-recovery"),R=e("./lib/state-corruption/state-corruption-recovery"),L=e("./lib/approval/utils"),D=e("./lib/use-split-state-storage"),U=pe(e("./migrations")),j=pe(e("./lib/migrator")),F=e("./lib/update-remote-feature-flags"),V=pe(e("./platforms/extension")),x=e("./constants/sentry-state"),K=ue(e("./lib/notification-manager")),B=ue(e("./metamask-controller")),z=e("./controllers/analytics"),$=pe(e("./lib/getObjStructure")),q=pe(e("./lib/ens-ipfs/setup")),Y=e("./lib/util"),G=e("./offscreen"),H=e("./lib/stream-utils"),W=pe(e("./first-time-state")),J=e("./on-update"),X=e("./constants/marketing-site-whitelist"),Z=e("./constants/stream"),Q=e("./constants/snaps"),ee=e("./lib/extension-lazy-listener/extension-lazy-listener"),te=e("./lib/deep-links/deep-link-router"),ne=e("./lib/deep-links/metrics"),ae=e("./lib/safe-reload"),re=e("./lib/critical-error/critical-error-tab-handoff"),ie=e("./lib/repair"),se=e("./lib/start-up-errors/start-up-errors"),oe=e("./lib/CronjobControllerStorageManager"),le=e("./lib/defi-referrals/createDefiReferralMiddleware"),ce=e("./lib/getIframeProperties"),de=e("./constants/background");function ue(e,t){if("function"==typeof WeakMap)var n=new WeakMap,a=new WeakMap;return(ue=function(e,t){if(!t&&e&&e.__esModule)return e;var r,i,s={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return s;if(r=t?a:n){if(r.has(e))return r.get(e);r.set(e,s)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((i=(r=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(i.get||i.set)?r(s,t,i):s[t]=e[t]);return s})(e,t)}function pe(e){return e&&e.__esModule?e:{default:e}}const fe=globalThis.stateHooks.lazyListener??new ee.ExtensionLazyListener(o.default),ge="#0376C9",he=r.lightTheme.colors.error.default,me=9,be=99,Ee=!1;const we=null,{safePersist:Se,requestSafeReload:Ce,evacuate:ve}=(0,ae.getRequestSafeReload)(a.persistenceManager);global.stateHooks.getMostRecentPersistedState=()=>a.persistenceManager.mostRecentRetrievedState,global.stateHooks.getStorageKind=()=>a.persistenceManager.storageKind,global.logEncryptedVault=()=>{a.persistenceManager.logEncryptedVault()};const{sentry:Me}=global;let Ie={...W.default};const Te={[f.ENVIRONMENT_TYPE_POPUP]:!0,[f.ENVIRONMENT_TYPE_NOTIFICATION]:!0,[f.ENVIRONMENT_TYPE_FULLSCREEN]:!0};s.default.setLevel("info",!1);const ye=new V.default,Ae=new K.default,Pe=(0,Y.getPlatform)()===f.PLATFORM_FIREFOX;function Oe(e){const t=e.name,n=e.sender?.url?new URL(e.sender.url):null;let a;return a=Pe?Boolean(Te[t]):n?.origin===`chrome-extension://${o.default.runtime.id}`,{processName:t,senderUrl:n,isMetaMaskUIPort:a}}let ke=0,_e=!1,Ne=!1,Re=0,Le=0;const De=new Set,Ue={},je={};let Fe;const Ve={},xe={},Ke={};const Be=new URL("https://metamask.github.io/phishing-warning/v5.1.0/"),ze=Be.toString();let $e,qe,Ye;function Ge(){const e=(0,u.withResolvers)();$e=e.promise,qe=e.resolve,Ye=e.reject}fe.once("runtime","onInstalled").then(e=>{!async function([e]){if("install"===e.reason)await async function(){s.default.debug("First install detected");const e=(0,k.getInstallAttribution)();ye.openExtensionInBrowser();await $e,await ft(e)}();else if("update"===e.reason){const{previousVersion:t}=e;if(!t||t===ye.getVersion())return;await $e,(0,J.onUpdate)(Fe,ye,t,Ce)}}(e)}),Ge(),o.default?.sidePanel?.setPanelBehavior&&o.default.sidePanel.setPanelBehavior({openPanelOnActionClick:!0}).catch(()=>{});let He,We,Je,Xe;const Ze=new R.CorruptionHandler,Qe=new N.CriticalErrorHandler,et=async e=>{const{isMetaMaskUIPort:t}=Oe(e);try{e.postMessage({data:{method:m.BACKGROUND_LIVENESS_METHOD},name:"background-liveness"})}catch(e){return void s.default.error("MetaMask - background-liveness check: Failed to message to port",e)}let n;t&&(Qe.registerPortForCriticalError({port:e,repairCallback:()=>(0,ie.requestRepair)(()=>(0,re.openRestoringTabAndReload)(Ce))}),n=()=>Qe.removeListenersForPort(e));try{if(await $e,t&&!(0,se.tryPostMessage)(e,m.BACKGROUND_INITIALIZED_METHOD))return;Ee,He(e,n)}catch(r){try{if(Me?.captureException(r),t)if((0,y.isStateCorruptionError)(r))await Ze.handleStateCorruptionError({port:e,error:r,database:a.persistenceManager,repairCallback:async e=>{Ge(),(0,_.hasVault)(e)?(await gt(e),Fe.onboardingController.setFirstTimeFlowType(p.FirstTimeFlowType.restore)):(await a.persistenceManager.reset(),await gt(null))}});else{const t=(0,l.isObject)(r)?{message:r.message??"Unknown error",name:r.name??"UnknownError",stack:r.stack,...r.sentryTags&&{sentryTags:r.sentryTags}}:{message:String(r),name:"UnknownError",stack:""};(0,se.tryPostMessage)(e,P.DISPLAY_GENERAL_STARTUP_ERROR,{error:t,currentLocale:Fe?.preferencesController?.state?.currentLocale})}}finally{n?.()}}},tt=()=>{fe.addListener("runtime","onConnect",et)};function nt(){const e=(new Date).toISOString();o.default.storage.session.set({timestamp:e})}async function at(e){(0,Y.initInstallType)();const t=S.isManifestV3?(0,G.createOffscreen)():null;let n=null,r=!1;S.isManifestV3&&(0,G.addOffscreenConnectivityListener)(e=>{if(r&&Fe.connectivityAdapter){const t=e?"online":"offline";Fe.connectivityAdapter.setStatus(t)}else n=e});const i=await it(e),s=i.data,l=await(0,A.default)();let c;if(S.isManifestV3){if(!1!==s.PreferencesController?.enableMV3TimestampSave){const e=2e3;nt(),setInterval(nt,e)}const e=await o.default.storage.session.get(["isFirstMetaMaskControllerSetup"]);c=e?.isFirstMetaMaskControllerSetup===undefined,await o.default.storage.session.set({isFirstMetaMaskControllerSetup:c})}const d=await async function(){const e=(0,T.default)(),t=Q.PREINSTALLED_SNAPS_URLS.map(async t=>{const n=await e(t);if(t.pathname.endsWith(".json.gz")){const e=new DecompressionStream("gzip"),t=n.body.pipeThrough(e);return await new Response(t).json()}return await n.json()});return Promise.all(t)}(),u=new oe.CronjobControllerStorageManager;if(await u.init(),ut(s,l,c,i.meta,t,d,u),Fe.metaMetricsController.updateTraits({[b.MetaMetricsUserTrait.StorageKind]:a.persistenceManager.storageKind}),function(e){async function t(e,t){try{const n=await o.default.tabs.get(e);return!(n.url&&n.url.startsWith("https://www.google.com/search")||(await o.default.tabs.update(e,{url:t}),0))}catch(e){return Me?.captureException(e),!1}}const n=!S.isManifestV3;o.default.webRequest.onBeforeRequest.addListener(a=>{if(a.tabId===o.default.tabs.TAB_ID_NONE)return{};const{completedOnboarding:r}=e.onboardingController.state;if(!r)return{};if(!e.preferencesController.state.usePhishDetect)return{};if(a.initiator&&"null"!==a.initiator&&new URL(a.initiator).host===Be.host)return{};const{hostname:i,href:s,searchParams:l}=new URL(a.url);e.phishingController.maybeUpdateState();const c=e.phishingController.isBlockedRequest(a.url);let d,u;if("main_frame"!==a.type&&"sub_frame"!==a.type||(d=e.phishingController.test(a.url)),!d?.result&&!c.result)return{};let p,f=s;d?.result&&c.result?u=`${d.type} and ${c.type}`:d?.result?u=d.type:(u=c.type,f=a.initiator);try{p=new URL(f).hostname}catch{p=i,f=s}const g=new URLSearchParams({hostname:p,href:f}),h=new URL(ze);h.hash=g.toString();const m=h.toString(),E=()=>{Pe||(0,z.trackEvent)((0,z.createEventBuilder)(b.MetaMetricsEventName.PhishingPageDisplayed).addCategory(b.MetaMetricsEventCategory.Phishing).addProperties({url:f,referrer:{url:f},reason:u,requestDomain:c.result?i:undefined}).build({excludeMetaMetricsId:!0}))};return n?"main_frame"===a.type?(E(),{redirectUrl:m}):(t(a.tabId,m).then(e=>{e&&E()}),{cancel:!0}):(t(a.tabId,m).then(e=>{e&&E()}),{})},{urls:["http://*/*","https://*/*","ws://*/*","wss://*/*"]},n?["blocking"]:[])}(Fe),S.isManifestV3){if(r=!0,null!==n){const e=n?"online":"offline";Fe.connectivityAdapter.setStatus(e)}}else{const e=e=>{const t=e?"online":"offline";Fe.connectivityAdapter.setStatus(t)};e(globalThis.navigator.onLine),globalThis.addEventListener("online",()=>e(!0)),globalThis.addEventListener("offline",()=>e(!1))}S.isManifestV3||await async function(){let e;try{const t=new URL(ze);let n,a;t.hash="#extensionStartup",e=window.document.createElement("iframe"),e.setAttribute("src",t.href),e.setAttribute("sandbox","allow-scripts allow-same-origin");const r=new Promise((e,t)=>{n=e,a=t});e.addEventListener("load",n),window.document.body.appendChild(e),setTimeout(()=>a(new rt),1e3),await r}catch(e){e instanceof rt?console.warn("Phishing warning page timeout; page not guaranteed to work offline."):console.error("Failed to initialize phishing warning page",e)}finally{e&&e.remove()}}(),await(async()=>{const e=await o.default.tabs.query({url:"<all_urls>",windowType:"normal"}).then(e=>((0,w.checkForLastErrorAndLog)(),e)).catch(()=>{(0,w.checkForLastErrorAndLog)()});for(const t of e)o.default.tabs.sendMessage(t.id,{name:h.EXTENSION_MESSAGES.READY}).then(()=>{(0,w.checkForLastErrorAndLog)()}).catch(()=>{(0,w.checkForLastErrorAndLog)()})})(),new te.DeepLinkRouter({getExtensionURL:ye.getExtensionURL,getState:Fe.getState.bind(Fe)}).on("navigate",async({url:e,parsed:t})=>{"redirectTo"in t||(0,z.trackEvent)((0,ne.createEvent)({signature:t.signature,url:e}))}).on("error",e=>Me?.captureException(e)).install()}tt(),o.default.runtime.onConnectExternal.addListener(async(...e)=>{await $e,We(...e)});class rt extends Error{constructor(){super("Timeout failed")}}async function it(e){let t;if(e){t={data:{},meta:{}};for(const n of _.backedUpStateKeys)(0,l.hasProperty)(e,n)&&(t.data[n]=e[n]);(0,l.hasProperty)(e,"meta")&&(0,l.isObject)(e.meta)&&(t.meta=e.meta,"split"===e.meta.storageKind||"data"===e.meta.storageKind?a.persistenceManager.storageKind=e.meta.storageKind:a.persistenceManager.storageKind="data"),"number"!=typeof t.meta.version&&(s.default.error("The `backup`'s `meta.version` property was missing during backup restore."),t.meta.version=155)}else{const e=!0;t=await a.persistenceManager.get({validateVault:e})}const n=new j.default({migrations:U.default,defaultVersion:null});n.on("error",e=>{console.warn(e);const n=(0,$.default)(t);Me?.captureException(e,{extra:{vaultStructure:n}})});let r=!1;t?.data||t?.meta||(r=!0,t=n.generateInitialState(Ie));const{state:i,changedKeys:o}=await n.migrateData(t),c=async n=>{const r=t?.meta?.version,s="number"==typeof r&&r>=157;let o=e?.AppMetadataController?.firstTimeInfo??i?.data?.AppMetadataController?.firstTimeInfo??i?.data?.firstTimeInfo??t?.data?.AppMetadataController?.firstTimeInfo??t?.data?.firstTimeInfo;if(!o)try{const e=await a.persistenceManager.getBackup();o=e?.AppMetadataController?.firstTimeInfo}catch{}const l=new Error(n);return l.sentryTags={"corruption.preMigrationVersion":String(r??"unknown"),"corruption.backupShouldExist":String(s),"corruption.installVersion":String(o?.version??"unknown"),"corruption.installDate":String(o?.date??"unknown")},l};if(!i)throw await c("MetaMask - migrator returned undefined");if(!(0,l.isObject)(i.meta))throw await c(`MetaMask - migrator metadata has invalid type '${typeof i.meta}'`);if("number"!=typeof i.meta.version)throw await c(`MetaMask - migrator metadata version has invalid type '${typeof i.meta.version}'`);if(!["data","split",undefined].includes(i.meta.storageKind))throw await c(`MetaMask - migrator metadata storageKind has invalid value '${i.meta.storageKind}'`);if(!(0,l.isObject)(i.data))throw await c(`MetaMask - migrator data has invalid type '${typeof i.data}'`);if(a.persistenceManager.setMetadata(i.meta),s.default.debug("[Split State]: Loaded data from persistence with storageKind '%s'",a.persistenceManager.storageKind),"data"===a.persistenceManager.storageKind){const e=!0===i.meta.platformSplitStateGradualRolloutAttempted,t=!e&&await(0,D.useSplitStateStorage)(i.data);s.default.debug("[Split State]: shouldUseSplitStateStorage: %s (alreadyTried: %s)",t,e),t&&(i.meta.platformSplitStateGradualRolloutAttempted=!0,a.persistenceManager.setMetadata(i.meta)),s.default.debug("[Split State]: Writing data to persistence with storageKind 'data'"),await a.persistenceManager.set(i.data),t&&(await a.persistenceManager.migrateToSplitState(i.data),i.meta=a.persistenceManager.getMetaData(),i.meta!==undefined&&(delete i.meta.platformSplitStateGradualRolloutAttempted,a.persistenceManager.setMetadata(i.meta)),await a.persistenceManager.persist())}else{if("split"!==a.persistenceManager.storageKind)throw new Error(`MetaMask - persistenceManager has invalid storageKind '${a.persistenceManager.storageKind}'`);if(r)for(const[e,t]of Object.entries(i.data))a.persistenceManager.update(e,t);else for(const e of o)a.persistenceManager.update(e,i.data[e]);await a.persistenceManager.persist()}return s.default.debug("[Split State]: Load complete."),i}function st(e,t,n){const{analyticsId:a}=Fe.getState();if(!(0,Y.shouldEmitDappViewedEvent)(a))return;const r=Fe.getPermittedAccounts(e).length;if(0===r)return;const i=Fe.controllerMessenger.call("AccountsController:getState"),s=Object.keys(i.internalAccounts.accounts).length,o=(0,ce.getIframeProperties)({frameId:n,origin:e,mainFrameOrigin:t});(0,z.trackEvent)((0,z.createEventBuilder)(b.MetaMetricsEventName.DappViewed).addCategory(b.MetaMetricsEventCategory.InpageProvider).addProperties({is_first_visit:!1,number_of_accounts:s,number_of_accounts_connected:r,...o}).build({referrer:{url:e},excludeMetaMetricsId:!0}))}function ot(e){if(!e.sender?.tab||!e.sender?.url||!e.sender?.tab?.url)return;const t=e.sender.tab.id,n=new URL(e.sender.url),{origin:a}=n,r=new URL(e.sender.tab.url),{origin:i}=r,{frameId:s}=e.sender;Object.keys(Ve).includes(t)||(Ve[t]=a),t in xe||(xe[t]=i),t in Ke||(Ke[t]=s);const o=Fe.controllerMessenger.call("PermissionController:hasPermissions",a),l="New Tab"!==e.sender.tab.title;o&&l&&st(a,i,s)}function lt(e){const{completedMetaMetricsOnboarding:t,optedIn:n}=Fe.getState();if(!t||!n)return;const a=Fe.appStateController.state.appActiveTab?.origin,r=(0,E.getActiveTabDomainAllowlist)(Fe.remoteFeatureFlagController.state),i=(0,E.getActiveTabDomainForMetrics)(a,r);(0,z.trackEvent)((0,z.createEventBuilder)(b.MetaMetricsEventName.AppOpened).addCategory(b.MetaMetricsEventCategory.App).addProperties(i?{active_tab_domain:i}:{}).build({environmentType:e}))}function ct(e){const t=[f.ENVIRONMENT_TYPE_POPUP,f.ENVIRONMENT_TYPE_NOTIFICATION,f.ENVIRONMENT_TYPE_FULLSCREEN,f.ENVIRONMENT_TYPE_SIDEPANEL];return!(Object.values(Ue).some(Boolean)||_e||ke>0||Re>0)&&t.includes(e)}const dt=async e=>{if(await $e,Fe)try{const t=e?{active:!0,windowId:e}:{active:!0,currentWindow:!0},n=await o.default.tabs.query(t);if(!n||0===n.length)return;const a=n[0],{id:r,title:i,url:s,favIconUrl:l}=a;if(!s)return void Fe.appStateController.clearAppActiveTab();const{origin:c,protocol:d,host:u,href:p}=new URL(s);if(!(0,Y.isWebOrigin)(c))return void Fe.appStateController.clearAppActiveTab();Fe.appStateController.setAppActiveTab({id:r,title:i,origin:c,protocol:d,url:s,host:u,href:p,favIconUrl:l}),Fe.subjectMetadataController.addSubjectMetadata({origin:c,name:i||u||c,iconUrl:l||null,subjectType:"website"})}catch(e){console.log("Error refreshing appActiveTab:",e.message)}};function ut(e,t,n,r,l,u,p){Fe=new B.default({infuraProjectId:globalThis.INFURA_PROJECT_ID,showUserConfirmation:pt,initState:e,initLangCode:t,platform:ye,notificationManager:Ae,browser:o.default,getRequestAccountTabIds:()=>je,getOpenMetamaskTabsIds:()=>Ue,isFirstMetaMaskControllerSetup:n,currentMigrationVersion:r.version,featureFlags:{},offscreenPromise:l,preinstalledSnaps:u,requestSafeReload:Ce,cronjobControllerStorageManager:p}),a.persistenceManager.setOnSetFailed(e=>{Fe.appStateController.setStorageWriteErrorType(e)});const h=[],m=Fe.store.getState();for(const t of Object.keys(m)){const n=e[t]||{},a=m[t];if(null===a||"object"!=typeof a){(0,v.captureException)(new Error(`Invalid controller state for '${t}' of type '${null===a?"null":typeof a}'`));continue}const r=Object.keys(a);if(r.length===Object.keys(n).length){for(const e of r)if(a[e]!==n[e]){h.push(t);break}}else h.push(t)}var E;"split"===a.persistenceManager.storageKind?(h.length>0&&(s.default.info(`MetaMaskController state changed during configuration for controllers: ${h.join(", ")}. Persisting updated state.`),h.forEach(e=>{a.persistenceManager.update(e,m[e])}),Se().catch(e=>{s.default.error("Error persisting updated state:",e),Me?.captureException(e)})),Fe.store.on("stateChange",async({controllerKey:e,newState:t,_oldState:n,_patches:r})=>{a.persistenceManager.update(e,t),_.backedUpStateKeys.includes(e)&&_.backedUpStateKeys.forEach(t=>{if(t===e)return;const n=Fe.store.config[t];if(!n?.metadata)throw new Error(`Cannot backup ${t}: controller metadata is required but not found. All controllers in backedUpStateKeys must extend BaseController and define metadata.`);const r=Fe.controllerMessenger.call(`${t}:getState`),i=(0,c.deriveStateFromMetadata)(r,n.metadata,"persist");a.persistenceManager.update(t,i)});try{await Se()}catch(e){s.default.error("Error persisting state change:",e),Me?.captureException(e)}})):(h.length>0&&(s.default.info(`MetaMaskController state changed during configuration for controllers: ${h.join(", ")}. Persisting updated state.`),Se(m).catch(e=>{s.default.error("Error persisting updated controller state:",e),Me?.captureException(e)})),Fe.store.on("update",Se)),Fe.store.on("error",e=>{s.default.error("MetaMask controller.store error:",e),Me?.captureException(e)}),(0,q.default)({getCurrentChainId:()=>(0,M.getCurrentChainId)({metamask:Fe.networkController.state}),getIpfsGateway:Fe.preferencesController.getIpfsGateway.bind(Fe.preferencesController),getUseAddressBarEnsResolution:()=>Fe.preferencesController.state.useAddressBarEnsResolution,provider:Fe.provider}),E=Fe,global.stateHooks.getSentryAppState=function(){const e=E.memStore.getState();return(0,C.maskObject)(e,x.SENTRY_BACKGROUND_STATE)};const w=()=>ke>0||Boolean(Object.keys(Ue).length)||_e||Re>0||!1,T=()=>ke>0||Re>0,y=()=>_e&&!T(),A=(e,t)=>{if(!1===e)Fe.onClientClosed();else{if(t===f.ENVIRONMENT_TYPE_FULLSCREEN&&Boolean(Object.keys(Ue).length)||t===f.ENVIRONMENT_TYPE_SIDEPANEL&&Re>0)return;Fe.onEnvironmentTypeClosed(t)}};function P(e){try{Fe.appStateController.setDefaultHomeActiveTabName(e??null)}catch(e){console.error("Error setting landing tab:",e)}}function O(){De.clear(),Le=0,N()}function k(e,t){return e>t?`${t}+`:String(e)}function N(){const e=R();let t="",n=ge;Le>0&&!y()?(t=k(Le,me),n=he):e>0&&(t=k(e,me));try{const e={text:t},a={color:n};S.isManifestV3?(o.default.action.setBadgeText(e),o.default.action.setBadgeBackgroundColor(a)):(o.default.browserAction.setBadgeText(e),o.default.browserAction.setBadgeBackgroundColor(a))}catch(e){console.error("Error updating browser badge:",e)}}function R(){try{return(0,L.getAttentionRequiredApprovalCount)({approvalController:Fe.approvalController})}catch(e){return console.error("Failed to get pending approval count:",e),0}}He=(e,t)=>{if(de.BLOCKED_PORTS.includes(e.name))return;const{processName:n,senderUrl:a,isMetaMaskUIPort:r}=Oe(e);if(r){const a=new d.ExtensionPortStream(e),r=function({chunkSize:e}){(0,z.trackEvent)((0,z.createEventBuilder)(b.MetaMetricsEventName.PortStreamChunked).addCategory(b.MetaMetricsEventCategory.PortStream).addProperties({chunkSize:e}).build())};e.onDisconnect.addListener(()=>a.off("message-too-large",r)),a.on("message-too-large",r),Fe.isClientOpen=!0,Fe.setupTrustedCommunication(a,e.sender).finally(()=>{t?.()});const o=n===f.ENVIRONMENT_TYPE_SIDEPANEL&&ct(f.ENVIRONMENT_TYPE_SIDEPANEL);if(n!==f.ENVIRONMENT_TYPE_SIDEPANEL&&ct(s=n)&&lt(s),(0,F.updateRemoteFeatureFlags)(Fe),n===f.ENVIRONMENT_TYPE_POPUP&&(O(),ke+=1,(0,i.finished)(a,()=>{ke-=1;const e=w();Fe.isClientOpen=e,A(e,f.ENVIRONMENT_TYPE_POPUP)})),n===f.ENVIRONMENT_TYPE_SIDEPANEL&&(O(),Re+=1,dt().then(()=>{o&&lt(f.ENVIRONMENT_TYPE_SIDEPANEL)}),(0,i.finished)(a,()=>{Re=Math.max(Re-1,0);const e=w();Fe.isClientOpen=e,A(e,f.ENVIRONMENT_TYPE_SIDEPANEL)})),n===f.ENVIRONMENT_TYPE_NOTIFICATION&&(_e=!0,(0,i.finished)(a,()=>{_e=!1,Le>0&&P(g.AccountOverviewTabKey.Activity),N();const e=w();Fe.isClientOpen=e,A(e,f.ENVIRONMENT_TYPE_NOTIFICATION)})),n===f.ENVIRONMENT_TYPE_FULLSCREEN){O();const t=e.sender.tab.id;Ue[t]=!0,(0,i.finished)(a,()=>{delete Ue[t];const e=w();Fe.isClientOpen=e,A(e,f.ENVIRONMENT_TYPE_FULLSCREEN)})}}else if(a&&a.origin===Be.origin&&a.pathname===Be.pathname){const t=new d.ExtensionPortStream(e,{chunkSize:0});Fe.setupPhishingCommunication({connectionStream:t})}else{if(e.sender&&e.sender.tab&&e.sender.url){const t=e.sender.tab.id,n=new URL(e.sender.url),{origin:a}=n;ot(e),e.onMessage.addListener(e=>{e.data&&e.data.method===f.MESSAGE_TYPE.ETH_REQUEST_ACCOUNTS&&(je[a]=t)})}if(a&&X.COOKIE_ID_MARKETING_WHITELIST_ORIGINS.some(e=>e===a.origin)){const t=new d.ExtensionPortStream(e,{chunkSize:0});Fe.setUpCookieHandlerCommunication({connectionStream:t})}const t=new d.ExtensionPortStream(e,{chunkSize:0});if(Je(t,e.sender),Pe||!S.isManifestV3){const n=(0,H.setupMultiplex)(t);n.ignoreStream(Z.METAMASK_EIP_1193_PROVIDER),Xe(n.createStream(Z.METAMASK_CAIP_MULTICHAIN_PROVIDER),e.sender)}}var s},We=e=>{const t=e.sender?.url;if(t){const{hostname:n}=new URL(t);if(de.BLOCKED_HOSTNAMES.includes(n))return void e.disconnect()}const n=new d.ExtensionPortStream(e,{chunkSize:0});if(!e.sender.id){if(de.BLOCKED_PORTS.includes(e.name))return;ot(e),Xe((0,I.createCaipStream)(n),e.sender)}else Je(n,e.sender)},Je=(e,t)=>{Fe.setupUntrustedCommunicationEip1193({connectionStream:e,sender:t})},Xe=(e,t)=>{Fe.setupUntrustedCommunicationCaip({connectionStream:e,sender:t})},N(),Fe.controllerMessenger.subscribe(B.METAMASK_CONTROLLER_EVENTS.DECRYPT_MESSAGE_MANAGER_UPDATE_BADGE,N),Fe.controllerMessenger.subscribe(B.METAMASK_CONTROLLER_EVENTS.ENCRYPTION_PUBLIC_KEY_MANAGER_UPDATE_BADGE,N),Fe.signatureController.hub.on(B.METAMASK_CONTROLLER_EVENTS.UPDATE_BADGE,N),Fe.controllerMessenger.subscribe(B.METAMASK_CONTROLLER_EVENTS.APP_STATE_UNLOCK_CHANGE,N),Fe.controllerMessenger.subscribe(B.METAMASK_CONTROLLER_EVENTS.APPROVAL_STATE_CHANGE,N),Fe.controllerMessenger.subscribe(B.METAMASK_CONTROLLER_EVENTS.METAMASK_NOTIFICATIONS_LIST_UPDATED,N),Fe.controllerMessenger.subscribe(B.METAMASK_CONTROLLER_EVENTS.METAMASK_NOTIFICATIONS_MARK_AS_READ,N),Fe.controllerMessenger.subscribe("TransactionController:transactionStatusUpdated",function({transactionMeta:e}){const{status:t,txParams:n,chainId:a}=e??{};if("failed"!==t&&"dropped"!==t)return;const{from:r,nonce:i}=n??{},s=r&&i!==undefined&&a?`${a}:${r.toLowerCase()}:${i}`:undefined;if(s&&De.has(s))return;if(T())return;s&&(De.size>=be&&De.clear(),De.add(s));Le+=1,y()||P(g.AccountOverviewTabKey.Activity);N()}),Ae.on(K.NOTIFICATION_MANAGER_EVENTS.POPUP_CLOSED,({automaticallyClosed:e})=>{e?R()>0&&pt():(Fe.signatureController.rejectUnapproved(b.REJECT_NOTIFICATION_CLOSE_SIG),Fe.decryptMessageController.rejectUnapproved(b.REJECT_NOTIFICATION_CLOSE),Fe.encryptionPublicKeyController.rejectUnapproved(b.REJECT_NOTIFICATION_CLOSE),Fe.legacyBackgroundApiService.rejectAllPendingApprovals()),N()})}async function pt(){const e=await ye.getActiveTabs(),t=Boolean(e.find(e=>Ue[e.id])),n=e.length>0&&e[0].extData&&e[0].extData.indexOf("vivaldi_tab")>-1;if(!Ne&&(n||0===ke)&&!t&&0===Re){Ne=!0;try{const e=Fe.appStateController.getCurrentPopupId();await Ae.showPopup(e=>Fe.appStateController.setCurrentPopupId(e),e)}finally{Ne=!1}}}const ft=async e=>{const{deferredDeepLink:t,traits:n}=await e;Fe.metaMetricsController.updateTraits({[b.MetaMetricsUserTrait.InstallDateExt]:(new Date).toISOString().split("T")[0],...n});const a={};t&&(Fe.appStateController.setDeferredDeepLink(t),a.install_source="deeplink",a.deeplink_path=t.referringLink);const r={category:b.MetaMetricsEventCategory.App,event:b.MetaMetricsEventName.AppInstalled,properties:a},{completedMetaMetricsOnboarding:i,optedIn:s,analyticsId:o}=Fe.getState();!0===i&&!1===s||(!0===i&&!0===s&&o?(0,z.trackEvent)((0,z.createEventBuilder)(b.MetaMetricsEventName.AppInstalled).addCategory(b.MetaMetricsEventCategory.App).addProperties(a).build()):Fe.metaMetricsController.addEventBeforeMetricsOptIn(r))};o.default.runtime.onUpdateAvailable.addListener(async function(e){await $e,s.default.info("An update is available",e?.version),Fe.appStateController.setPendingExtensionVersion(e?.version??null)});(async()=>{if(o.default?.sidePanel)try{await $e,await async function(){if(!o.default?.sidePanel?.setPanelBehavior)return;const e=Fe?.preferencesController?.state?.preferences?.useSidePanelAsDefault??!0;await o.default.sidePanel.setPanelBehavior({openPanelOnActionClick:e})}(),Fe?.controllerMessenger?.subscribe("PreferencesController:stateChange",e=>{o.default?.sidePanel?.setPanelBehavior&&o.default.sidePanel.setPanelBehavior({openPanelOnActionClick:e}).catch(e=>console.error("Error updating panel behavior:",e))},e=>e?.preferences?.useSidePanelAsDefault??!0)}catch(e){console.error("Error setting side panel toolbar behavior:",e)}})();async function gt(e){o.default.tabs.onActivated.addListener(e=>{if(Fe){const{tabId:t}=e,n=Ve[t],a=xe[t];n&&Fe.permissionController.state.subjects[n]!==undefined&&st(n,a,Ke[t]);const r=(0,O.getPartnerByOrigin)(a);r&&Fe.permissionController.state.subjects[a]!==undefined&&Fe.handleDefiReferral(r,t,le.ReferralTriggerType.OnNavigateConnectedTab).catch(e=>{s.default.error(`Failed to handle ${r.name} referral after navigation to connected tab: `,e)})}});try{await at(e),a.persistenceManager.cleanUpMostRecentRetrievedState(),s.default.info("MetaMask initialization complete."),qe()}catch(e){s.default.error(e),Ye(e)}}(async()=>{await dt()})(),o.default.tabs.onActivated.addListener(async({tabId:e})=>{if(await $e,!Fe)return{};try{const t=await o.default.tabs.get(e),{id:n,title:a,url:r,favIconUrl:i}=t;if(!r)return Fe.appStateController.clearAppActiveTab(),{};const{origin:s,protocol:l,host:c,href:d}=new URL(r);if(!(0,Y.isWebOrigin)(s))return Fe.appStateController.clearAppActiveTab(),{};Fe.appStateController.setAppActiveTab({id:n,title:a,origin:s,protocol:l,url:r,host:c,href:d,favIconUrl:i}),Fe.subjectMetadataController.addSubjectMetadata({origin:s,name:a||c||s,iconUrl:i||null,subjectType:"website"})}catch(e){console.log("Error in tabs.onActivated listener:",e.message)}return{}}),o.default.tabs.onUpdated.addListener(async(e,t,n)=>{if(await $e,!Fe)return{};const a=t.url!==undefined,r="complete"===t.status;if(!a&&!r)return{};try{const t=n||await o.default.tabs.get(e),{id:i,title:s,url:l,favIconUrl:c}=t,d=Fe.appStateController.state.appActiveTab,u=d?.id===i;if(!l)return u&&Fe.appStateController.clearAppActiveTab(),{};const{origin:p,protocol:f,host:g,href:h}=new URL(l);if(!p||"null"===p||p.startsWith("chrome-extension://")||p.startsWith("moz-extension://"))return u&&Fe.appStateController.clearAppActiveTab(),{};let m=!1;try{m=(await o.default.tabs.query({active:!0,currentWindow:!0})).some(e=>e.id===i)}catch(e){m=u}(a||r)&&m&&(Fe.appStateController.setAppActiveTab({id:i,title:s,origin:p,protocol:f,url:l,host:g,href:h,favIconUrl:c}),Fe.subjectMetadataController.addSubjectMetadata({origin:p,name:s||g||p,iconUrl:c||null,subjectType:"website"}))}catch(e){console.log("Error in tabs.onUpdated listener:",e.message)}return{}}),o.default.windows.onFocusChanged.addListener(async e=>{e!==o.default.windows.WINDOW_ID_NONE&&await dt(e)}),async function(){const e=await(0,re.readCriticalErrorRestoreSession)(o.default),t=undefined;let n=null;(e||t?.simulateBackgroundStateSyncHang||t?.simulateBackgroundInitializationHang)&&(n=await a.persistenceManager.getBackup().catch(()=>null));const r=(0,_.hasVault)(n);if((t?.simulateBackgroundStateSyncHang||t?.simulateBackgroundInitializationHang)&&we&&(we.hasVaultAtStartup=r?Date.now():null),e&&(await(0,re.clearCriticalErrorRestoreSession)(o.default),r)){we&&(we.restoreInProgress=!0);const t={tabId:e.tabId,tabUrl:e.tabUrl};gt(n);try{await $e}catch(e){return void s.default.error("critical-error-restore: initialization failed",e)}return Fe.onboardingController.setFirstTimeFlowType(p.FirstTimeFlowType.restore),void await(0,re.handoffRestoringTabToExtension)(ye,t)}gt(null)}().catch(e=>{s.default.error("initOrRestoreBackground failed",e)})}}},{package:"$root$",file:"app/scripts/background.js"}]],[12],{});