waku-lab/buddybook/assets/index-DyOq0GRj.js
status-im-auto 83618ef98b Updates
2024-11-14 14:05:57 +00:00

4 lines
81 KiB
JavaScript

import{g as rt,m as at,a as ot,o as ct,p as dt,E as lt}from"./index-D-Yr2Iya.js";import{B as Y,_ as h,h as ae,y as ht}from"./hooks.module-D0gf0yJl.js";const ut=(t,e)=>{let s;switch(t){case"standard":return s=e,`data:image/svg+xml,%3Csvg width='${e}' height='${s}' viewBox='0 0 1024 1024' fill='none' xmlns='http://www.w3.org/2000/svg'%3E %3Crect width='1024' height='1024' fill='%230052FF'/%3E %3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M152 512C152 710.823 313.177 872 512 872C710.823 872 872 710.823 872 512C872 313.177 710.823 152 512 152C313.177 152 152 313.177 152 512ZM420 396C406.745 396 396 406.745 396 420V604C396 617.255 406.745 628 420 628H604C617.255 628 628 617.255 628 604V420C628 406.745 617.255 396 604 396H420Z' fill='white'/%3E %3C/svg%3E `;case"circle":return s=e,`data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='${e}' height='${s}' viewBox='0 0 999.81 999.81'%3E%3Cdefs%3E%3Cstyle%3E.cls-1%7Bfill:%230052fe;%7D.cls-2%7Bfill:%23fefefe;%7D.cls-3%7Bfill:%230152fe;%7D%3C/style%3E%3C/defs%3E%3Cpath class='cls-1' d='M655-115.9h56c.83,1.59,2.36.88,3.56,1a478,478,0,0,1,75.06,10.42C891.4-81.76,978.33-32.58,1049.19,44q116.7,126,131.94,297.61c.38,4.14-.34,8.53,1.78,12.45v59c-1.58.84-.91,2.35-1,3.56a482.05,482.05,0,0,1-10.38,74.05c-24,106.72-76.64,196.76-158.83,268.93s-178.18,112.82-287.2,122.6c-4.83.43-9.86-.25-14.51,1.77H654c-1-1.68-2.69-.91-4.06-1a496.89,496.89,0,0,1-105.9-18.59c-93.54-27.42-172.78-77.59-236.91-150.94Q199.34,590.1,184.87,426.58c-.47-5.19.25-10.56-1.77-15.59V355c1.68-1,.91-2.7,1-4.06a498.12,498.12,0,0,1,18.58-105.9c26-88.75,72.64-164.9,140.6-227.57q126-116.27,297.21-131.61C645.32-114.57,650.35-113.88,655-115.9Zm377.92,500c0-192.44-156.31-349.49-347.56-350.15-194.13-.68-350.94,155.13-352.29,347.42-1.37,194.55,155.51,352.1,348.56,352.47C876.15,734.23,1032.93,577.84,1032.93,384.11Z' transform='translate(-183.1 115.9)'/%3E%3Cpath class='cls-2' d='M1032.93,384.11c0,193.73-156.78,350.12-351.29,349.74-193-.37-349.93-157.92-348.56-352.47C334.43,189.09,491.24,33.28,685.37,34,876.62,34.62,1032.94,191.67,1032.93,384.11ZM683,496.81q43.74,0,87.48,0c15.55,0,25.32-9.72,25.33-25.21q0-87.48,0-175c0-15.83-9.68-25.46-25.59-25.46H595.77c-15.88,0-25.57,9.64-25.58,25.46q0,87.23,0,174.45c0,16.18,9.59,25.7,25.84,25.71Z' transform='translate(-183.1 115.9)'/%3E%3Cpath class='cls-3' d='M683,496.81H596c-16.25,0-25.84-9.53-25.84-25.71q0-87.23,0-174.45c0-15.82,9.7-25.46,25.58-25.46H770.22c15.91,0,25.59,9.63,25.59,25.46q0,87.47,0,175c0,15.49-9.78,25.2-25.33,25.21Q726.74,496.84,683,496.81Z' transform='translate(-183.1 115.9)'/%3E%3C/svg%3E`;case"text":return s=(.1*e).toFixed(2),`data:image/svg+xml,%3Csvg width='${e}' height='${s}' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 528.15 53.64'%3E%3Cdefs%3E%3Cstyle%3E.cls-1%7Bfill:%230052ff;%7D%3C/style%3E%3C/defs%3E%3Ctitle%3ECoinbase_Wordmark_SubBrands_ALL%3C/title%3E%3Cpath class='cls-1' d='M164.45,15a15,15,0,0,0-11.74,5.4V0h-8.64V52.92h8.5V48a15,15,0,0,0,11.88,5.62c10.37,0,18.21-8.21,18.21-19.3S174.67,15,164.45,15Zm-1.3,30.67c-6.19,0-10.73-4.83-10.73-11.31S157,23,163.22,23s10.66,4.82,10.66,11.37S169.34,45.65,163.15,45.65Zm83.31-14.91-6.34-.93c-3-.43-5.18-1.44-5.18-3.82,0-2.59,2.8-3.89,6.62-3.89,4.18,0,6.84,1.8,7.42,4.76h8.35c-.94-7.49-6.7-11.88-15.55-11.88-9.15,0-15.2,4.68-15.2,11.3,0,6.34,4,10,12,11.16l6.33.94c3.1.43,4.83,1.65,4.83,4,0,2.95-3,4.17-7.2,4.17-5.12,0-8-2.09-8.43-5.25h-8.49c.79,7.27,6.48,12.38,16.84,12.38,9.44,0,15.7-4.32,15.7-11.74C258.12,35.28,253.58,31.82,246.46,30.74Zm-27.65-2.3c0-8.06-4.9-13.46-15.27-13.46-9.79,0-15.26,5-16.34,12.6h8.57c.43-3,2.73-5.4,7.63-5.4,4.39,0,6.55,1.94,6.55,4.32,0,3.09-4,3.88-8.85,4.39-6.63.72-14.84,3-14.84,11.66,0,6.7,5,11,12.89,11,6.19,0,10.08-2.59,12-6.7.28,3.67,3,6.05,6.84,6.05h5v-7.7h-4.25Zm-8.5,9.36c0,5-4.32,8.64-9.57,8.64-3.24,0-6-1.37-6-4.25,0-3.67,4.39-4.68,8.42-5.11s6-1.22,7.13-2.88ZM281.09,15c-11.09,0-19.23,8.35-19.23,19.36,0,11.6,8.72,19.3,19.37,19.3,9,0,16.06-5.33,17.86-12.89h-9c-1.3,3.31-4.47,5.19-8.71,5.19-5.55,0-9.72-3.46-10.66-9.51H299.3V33.12C299.3,22.46,291.53,15,281.09,15Zm-9.87,15.26c1.37-5.18,5.26-7.7,9.72-7.7,4.9,0,8.64,2.8,9.51,7.7ZM19.3,23a9.84,9.84,0,0,1,9.5,7h9.14c-1.65-8.93-9-15-18.57-15A19,19,0,0,0,0,34.34c0,11.09,8.28,19.3,19.37,19.3,9.36,0,16.85-6,18.5-15H28.8a9.75,9.75,0,0,1-9.43,7.06c-6.27,0-10.66-4.83-10.66-11.31S13,23,19.3,23Zm41.11-8A19,19,0,0,0,41,34.34c0,11.09,8.28,19.3,19.37,19.3A19,19,0,0,0,79.92,34.27C79.92,23.33,71.64,15,60.41,15Zm.07,30.67c-6.19,0-10.73-4.83-10.73-11.31S54.22,23,60.41,23s10.8,4.89,10.8,11.37S66.67,45.65,60.48,45.65ZM123.41,15c-5.62,0-9.29,2.3-11.45,5.54V15.7h-8.57V52.92H112V32.69C112,27,115.63,23,121,23c5,0,8.06,3.53,8.06,8.64V52.92h8.64V31C137.66,21.6,132.84,15,123.41,15ZM92,.36a5.36,5.36,0,0,0-5.55,5.47,5.55,5.55,0,0,0,11.09,0A5.35,5.35,0,0,0,92,.36Zm-9.72,23h5.4V52.92h8.64V15.7h-14Zm298.17-7.7L366.2,52.92H372L375.29,44H392l3.33,8.88h6L386.87,15.7ZM377,39.23l6.45-17.56h.1l6.56,17.56ZM362.66,15.7l-7.88,29h-.11l-8.14-29H341l-8,28.93h-.1l-8-28.87H319L329.82,53h5.45l8.19-29.24h.11L352,53h5.66L368.1,15.7Zm135.25,0v4.86h12.32V52.92h5.6V20.56h12.32V15.7ZM467.82,52.92h25.54V48.06H473.43v-12h18.35V31.35H473.43V20.56h19.93V15.7H467.82ZM443,15.7h-5.6V52.92h24.32V48.06H443Zm-30.45,0h-5.61V52.92h24.32V48.06H412.52Z'/%3E%3C/svg%3E`;case"textWithLogo":return s=(.25*e).toFixed(2),`data:image/svg+xml,%3Csvg width='${e}' height='${s}' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 308.44 77.61'%3E%3Cdefs%3E%3Cstyle%3E.cls-1%7Bfill:%230052ff;%7D%3C/style%3E%3C/defs%3E%3Cpath class='cls-1' d='M142.94,20.2l-7.88,29H135l-8.15-29h-5.55l-8,28.93h-.11l-8-28.87H99.27l10.84,37.27h5.44l8.2-29.24h.1l8.41,29.24h5.66L148.39,20.2Zm17.82,0L146.48,57.42h5.82l3.28-8.88h16.65l3.34,8.88h6L167.16,20.2Zm-3.44,23.52,6.45-17.55h.11l6.56,17.55ZM278.2,20.2v4.86h12.32V57.42h5.6V25.06h12.32V20.2ZM248.11,57.42h25.54V52.55H253.71V40.61h18.35V35.85H253.71V25.06h19.94V20.2H248.11ZM223.26,20.2h-5.61V57.42H242V52.55H223.26Zm-30.46,0h-5.6V57.42h24.32V52.55H192.8Zm-154,38A19.41,19.41,0,1,1,57.92,35.57H77.47a38.81,38.81,0,1,0,0,6.47H57.92A19.39,19.39,0,0,1,38.81,58.21Z'/%3E%3C/svg%3E`;case"textLight":return s=(.1*e).toFixed(2),`data:image/svg+xml,%3Csvg width='${e}' height='${s}' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 528.15 53.64'%3E%3Cdefs%3E%3Cstyle%3E.cls-1%7Bfill:%23fefefe;%7D%3C/style%3E%3C/defs%3E%3Ctitle%3ECoinbase_Wordmark_SubBrands_ALL%3C/title%3E%3Cpath class='cls-1' d='M164.45,15a15,15,0,0,0-11.74,5.4V0h-8.64V52.92h8.5V48a15,15,0,0,0,11.88,5.62c10.37,0,18.21-8.21,18.21-19.3S174.67,15,164.45,15Zm-1.3,30.67c-6.19,0-10.73-4.83-10.73-11.31S157,23,163.22,23s10.66,4.82,10.66,11.37S169.34,45.65,163.15,45.65Zm83.31-14.91-6.34-.93c-3-.43-5.18-1.44-5.18-3.82,0-2.59,2.8-3.89,6.62-3.89,4.18,0,6.84,1.8,7.42,4.76h8.35c-.94-7.49-6.7-11.88-15.55-11.88-9.15,0-15.2,4.68-15.2,11.3,0,6.34,4,10,12,11.16l6.33.94c3.1.43,4.83,1.65,4.83,4,0,2.95-3,4.17-7.2,4.17-5.12,0-8-2.09-8.43-5.25h-8.49c.79,7.27,6.48,12.38,16.84,12.38,9.44,0,15.7-4.32,15.7-11.74C258.12,35.28,253.58,31.82,246.46,30.74Zm-27.65-2.3c0-8.06-4.9-13.46-15.27-13.46-9.79,0-15.26,5-16.34,12.6h8.57c.43-3,2.73-5.4,7.63-5.4,4.39,0,6.55,1.94,6.55,4.32,0,3.09-4,3.88-8.85,4.39-6.63.72-14.84,3-14.84,11.66,0,6.7,5,11,12.89,11,6.19,0,10.08-2.59,12-6.7.28,3.67,3,6.05,6.84,6.05h5v-7.7h-4.25Zm-8.5,9.36c0,5-4.32,8.64-9.57,8.64-3.24,0-6-1.37-6-4.25,0-3.67,4.39-4.68,8.42-5.11s6-1.22,7.13-2.88ZM281.09,15c-11.09,0-19.23,8.35-19.23,19.36,0,11.6,8.72,19.3,19.37,19.3,9,0,16.06-5.33,17.86-12.89h-9c-1.3,3.31-4.47,5.19-8.71,5.19-5.55,0-9.72-3.46-10.66-9.51H299.3V33.12C299.3,22.46,291.53,15,281.09,15Zm-9.87,15.26c1.37-5.18,5.26-7.7,9.72-7.7,4.9,0,8.64,2.8,9.51,7.7ZM19.3,23a9.84,9.84,0,0,1,9.5,7h9.14c-1.65-8.93-9-15-18.57-15A19,19,0,0,0,0,34.34c0,11.09,8.28,19.3,19.37,19.3,9.36,0,16.85-6,18.5-15H28.8a9.75,9.75,0,0,1-9.43,7.06c-6.27,0-10.66-4.83-10.66-11.31S13,23,19.3,23Zm41.11-8A19,19,0,0,0,41,34.34c0,11.09,8.28,19.3,19.37,19.3A19,19,0,0,0,79.92,34.27C79.92,23.33,71.64,15,60.41,15Zm.07,30.67c-6.19,0-10.73-4.83-10.73-11.31S54.22,23,60.41,23s10.8,4.89,10.8,11.37S66.67,45.65,60.48,45.65ZM123.41,15c-5.62,0-9.29,2.3-11.45,5.54V15.7h-8.57V52.92H112V32.69C112,27,115.63,23,121,23c5,0,8.06,3.53,8.06,8.64V52.92h8.64V31C137.66,21.6,132.84,15,123.41,15ZM92,.36a5.36,5.36,0,0,0-5.55,5.47,5.55,5.55,0,0,0,11.09,0A5.35,5.35,0,0,0,92,.36Zm-9.72,23h5.4V52.92h8.64V15.7h-14Zm298.17-7.7L366.2,52.92H372L375.29,44H392l3.33,8.88h6L386.87,15.7ZM377,39.23l6.45-17.56h.1l6.56,17.56ZM362.66,15.7l-7.88,29h-.11l-8.14-29H341l-8,28.93h-.1l-8-28.87H319L329.82,53h5.45l8.19-29.24h.11L352,53h5.66L368.1,15.7Zm135.25,0v4.86h12.32V52.92h5.6V20.56h12.32V15.7ZM467.82,52.92h25.54V48.06H473.43v-12h18.35V31.35H473.43V20.56h19.93V15.7H467.82ZM443,15.7h-5.6V52.92h24.32V48.06H443Zm-30.45,0h-5.61V52.92h24.32V48.06H412.52Z'/%3E%3C/svg%3E`;case"textWithLogoLight":return s=(.25*e).toFixed(2),`data:image/svg+xml,%3Csvg width='${e}' height='${s}' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 308.44 77.61'%3E%3Cdefs%3E%3Cstyle%3E.cls-1%7Bfill:%23fefefe;%7D%3C/style%3E%3C/defs%3E%3Cpath class='cls-1' d='M142.94,20.2l-7.88,29H135l-8.15-29h-5.55l-8,28.93h-.11l-8-28.87H99.27l10.84,37.27h5.44l8.2-29.24h.1l8.41,29.24h5.66L148.39,20.2Zm17.82,0L146.48,57.42h5.82l3.28-8.88h16.65l3.34,8.88h6L167.16,20.2Zm-3.44,23.52,6.45-17.55h.11l6.56,17.55ZM278.2,20.2v4.86h12.32V57.42h5.6V25.06h12.32V20.2ZM248.11,57.42h25.54V52.55H253.71V40.61h18.35V35.85H253.71V25.06h19.94V20.2H248.11ZM223.26,20.2h-5.61V57.42H242V52.55H223.26Zm-30.46,0h-5.6V57.42h24.32V52.55H192.8Zm-154,38A19.41,19.41,0,1,1,57.92,35.57H77.47a38.81,38.81,0,1,0,0,6.47H57.92A19.39,19.39,0,0,1,38.81,58.21Z'/%3E%3C/svg%3E`;default:return s=e,`data:image/svg+xml,%3Csvg width='${e}' height='${s}' viewBox='0 0 1024 1024' fill='none' xmlns='http://www.w3.org/2000/svg'%3E %3Crect width='1024' height='1024' fill='%230052FF'/%3E %3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M152 512C152 710.823 313.177 872 512 872C710.823 872 872 710.823 872 512C872 313.177 710.823 152 512 152C313.177 152 152 313.177 152 512ZM420 396C406.745 396 396 406.745 396 420V604C396 617.255 406.745 628 420 628H604C617.255 628 628 617.255 628 604V420C628 406.745 617.255 396 604 396H420Z' fill='white'/%3E %3C/svg%3E `}};class v{constructor(e,s){this.scope=e,this.module=s}storeObject(e,s){this.setItem(e,JSON.stringify(s))}loadObject(e){const s=this.getItem(e);return s?JSON.parse(s):void 0}setItem(e,s){localStorage.setItem(this.scopedKey(e),s)}getItem(e){return localStorage.getItem(this.scopedKey(e))}removeItem(e){localStorage.removeItem(this.scopedKey(e))}clear(){const e=this.scopedKey(""),s=[];for(let n=0;n<localStorage.length;n++){const i=localStorage.key(n);typeof i=="string"&&i.startsWith(e)&&s.push(i)}s.forEach(n=>localStorage.removeItem(n))}scopedKey(e){return`-${this.scope}${this.module?`:${this.module}`:""}:${e}`}static clearAll(){new v("CBWSDK").clear(),new v("walletlink").clear()}}const u={rpc:{invalidInput:-32e3,resourceNotFound:-32001,resourceUnavailable:-32002,transactionRejected:-32003,methodNotSupported:-32004,limitExceeded:-32005,parse:-32700,invalidRequest:-32600,methodNotFound:-32601,invalidParams:-32602,internal:-32603},provider:{userRejectedRequest:4001,unauthorized:4100,unsupportedMethod:4200,disconnected:4900,chainDisconnected:4901,unsupportedChain:4902}},J={"-32700":{standard:"JSON RPC 2.0",message:"Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."},"-32600":{standard:"JSON RPC 2.0",message:"The JSON sent is not a valid Request object."},"-32601":{standard:"JSON RPC 2.0",message:"The method does not exist / is not available."},"-32602":{standard:"JSON RPC 2.0",message:"Invalid method parameter(s)."},"-32603":{standard:"JSON RPC 2.0",message:"Internal JSON-RPC error."},"-32000":{standard:"EIP-1474",message:"Invalid input."},"-32001":{standard:"EIP-1474",message:"Resource not found."},"-32002":{standard:"EIP-1474",message:"Resource unavailable."},"-32003":{standard:"EIP-1474",message:"Transaction rejected."},"-32004":{standard:"EIP-1474",message:"Method not supported."},"-32005":{standard:"EIP-1474",message:"Request limit exceeded."},4001:{standard:"EIP-1193",message:"User rejected the request."},4100:{standard:"EIP-1193",message:"The requested account and/or method has not been authorized by the user."},4200:{standard:"EIP-1193",message:"The requested method is not supported by this Ethereum provider."},4900:{standard:"EIP-1193",message:"The provider is disconnected from all chains."},4901:{standard:"EIP-1193",message:"The provider is disconnected from the specified chain."},4902:{standard:"EIP-3085",message:"Unrecognized chain ID."}},Ie="Unspecified error message.",pt="Unspecified server error.";function te(t,e=Ie){if(t&&Number.isInteger(t)){const s=t.toString();if(Q(J,s))return J[s].message;if(Se(t))return pt}return e}function ft(t){if(!Number.isInteger(t))return!1;const e=t.toString();return!!(J[e]||Se(t))}function gt(t,{shouldIncludeStack:e=!1}={}){const s={};if(t&&typeof t=="object"&&!Array.isArray(t)&&Q(t,"code")&&ft(t.code)){const n=t;s.code=n.code,n.message&&typeof n.message=="string"?(s.message=n.message,Q(n,"data")&&(s.data=n.data)):(s.message=te(s.code),s.data={originalError:oe(t)})}else s.code=u.rpc.internal,s.message=ce(t,"message")?t.message:Ie,s.data={originalError:oe(t)};return e&&(s.stack=ce(t,"stack")?t.stack:void 0),s}function Se(t){return t>=-32099&&t<=-32e3}function oe(t){return t&&typeof t=="object"&&!Array.isArray(t)?Object.assign({},t):t}function Q(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function ce(t,e){return typeof t=="object"&&t!==null&&e in t&&typeof t[e]=="string"}const l={rpc:{parse:t=>b(u.rpc.parse,t),invalidRequest:t=>b(u.rpc.invalidRequest,t),invalidParams:t=>b(u.rpc.invalidParams,t),methodNotFound:t=>b(u.rpc.methodNotFound,t),internal:t=>b(u.rpc.internal,t),server:t=>{if(!t||typeof t!="object"||Array.isArray(t))throw new Error("Ethereum RPC Server errors must provide single object argument.");const{code:e}=t;if(!Number.isInteger(e)||e>-32005||e<-32099)throw new Error('"code" must be an integer such that: -32099 <= code <= -32005');return b(e,t)},invalidInput:t=>b(u.rpc.invalidInput,t),resourceNotFound:t=>b(u.rpc.resourceNotFound,t),resourceUnavailable:t=>b(u.rpc.resourceUnavailable,t),transactionRejected:t=>b(u.rpc.transactionRejected,t),methodNotSupported:t=>b(u.rpc.methodNotSupported,t),limitExceeded:t=>b(u.rpc.limitExceeded,t)},provider:{userRejectedRequest:t=>P(u.provider.userRejectedRequest,t),unauthorized:t=>P(u.provider.unauthorized,t),unsupportedMethod:t=>P(u.provider.unsupportedMethod,t),disconnected:t=>P(u.provider.disconnected,t),chainDisconnected:t=>P(u.provider.chainDisconnected,t),unsupportedChain:t=>P(u.provider.unsupportedChain,t),custom:t=>{if(!t||typeof t!="object"||Array.isArray(t))throw new Error("Ethereum Provider custom errors must provide single object argument.");const{code:e,message:s,data:n}=t;if(!s||typeof s!="string")throw new Error('"message" must be a nonempty string');return new Ae(e,s,n)}}};function b(t,e){const[s,n]=Me(e);return new xe(t,s||te(t),n)}function P(t,e){const[s,n]=Me(e);return new Ae(t,s||te(t),n)}function Me(t){if(t){if(typeof t=="string")return[t];if(typeof t=="object"&&!Array.isArray(t)){const{message:e,data:s}=t;if(e&&typeof e!="string")throw new Error("Must specify string message.");return[e||void 0,s]}}return[]}class xe extends Error{constructor(e,s,n){if(!Number.isInteger(e))throw new Error('"code" must be an integer.');if(!s||typeof s!="string")throw new Error('"message" must be a nonempty string.');super(s),this.code=e,n!==void 0&&(this.data=n)}}class Ae extends xe{constructor(e,s,n){if(!mt(e))throw new Error('"code" must be an integer such that: 1000 <= code <= 4999');super(e,s,n)}}function mt(t){return Number.isInteger(t)&&t>=1e3&&t<=4999}function se(){return t=>t}const B=se(),wt=se(),bt=se();function I(t){return Math.floor(t)}const _e=/^[0-9]*$/,Le=/^[a-f0-9]*$/;function _(t){return ne(crypto.getRandomValues(new Uint8Array(t)))}function ne(t){return[...t].map(e=>e.toString(16).padStart(2,"0")).join("")}function H(t){return new Uint8Array(t.match(/.{1,2}/g).map(e=>Number.parseInt(e,16)))}function O(t,e=!1){const s=t.toString("hex");return B(e?`0x${s}`:s)}function z(t){return O(X(t),!0)}function k(t){return bt(t.toString(10))}function A(t){return B(`0x${BigInt(t).toString(16)}`)}function Pe(t){return t.startsWith("0x")||t.startsWith("0X")}function ie(t){return Pe(t)?t.slice(2):t}function Re(t){return Pe(t)?`0x${t.slice(2)}`:`0x${t}`}function K(t){if(typeof t!="string")return!1;const e=ie(t).toLowerCase();return Le.test(e)}function yt(t,e=!1){if(typeof t=="string"){const s=ie(t).toLowerCase();if(Le.test(s))return B(e?`0x${s}`:s)}throw l.rpc.invalidParams(`"${String(t)}" is not a hexadecimal string`)}function re(t,e=!1){let s=yt(t,!1);return s.length%2===1&&(s=B(`0${s}`)),e?B(`0x${s}`):s}function x(t){if(typeof t=="string"){const e=ie(t).toLowerCase();if(K(e)&&e.length===40)return wt(Re(e))}throw l.rpc.invalidParams(`Invalid Ethereum address: ${String(t)}`)}function X(t){if(Buffer.isBuffer(t))return t;if(typeof t=="string"){if(K(t)){const e=re(t,!1);return Buffer.from(e,"hex")}return Buffer.from(t,"utf8")}throw l.rpc.invalidParams(`Not binary data: ${String(t)}`)}function j(t){if(typeof t=="number"&&Number.isInteger(t))return I(t);if(typeof t=="string"){if(_e.test(t))return I(Number(t));if(K(t))return I(Number(BigInt(re(t,!0))))}throw l.rpc.invalidParams(`Not an integer: ${String(t)}`)}function D(t){if(t!==null&&(typeof t=="bigint"||kt(t)))return BigInt(t.toString(10));if(typeof t=="number")return BigInt(j(t));if(typeof t=="string"){if(_e.test(t))return BigInt(t);if(K(t))return BigInt(re(t,!0))}throw l.rpc.invalidParams(`Not an integer: ${String(t)}`)}function vt(t){if(typeof t=="string")return JSON.parse(t);if(typeof t=="object")return t;throw l.rpc.invalidParams(`Not a JSON string or an object: ${String(t)}`)}function kt(t){if(t==null||typeof t.constructor!="function")return!1;const{constructor:e}=t;return typeof e.config=="function"&&typeof e.EUCLID=="number"}function Et(){const t=document.querySelector('link[sizes="192x192"]')||document.querySelector('link[sizes="180x180"]')||document.querySelector('link[rel="icon"]')||document.querySelector('link[rel="shortcut icon"]'),{protocol:e,host:s}=document.location,n=t?t.getAttribute("href"):null;return!n||n.startsWith("javascript:")||n.startsWith("vbscript:")?`${e}//${s}/favicon.ico`:n.startsWith("http://")||n.startsWith("https://")||n.startsWith("data:")?n:n.startsWith("//")?e+n:`${e}//${s}${n}`}async function Ct(){return crypto.subtle.generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveKey"])}async function It(t,e){return crypto.subtle.deriveKey({name:"ECDH",public:e},t,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function St(t,e){const s=crypto.getRandomValues(new Uint8Array(12)),n=await crypto.subtle.encrypt({name:"AES-GCM",iv:s},t,new TextEncoder().encode(e));return{iv:s,cipherText:n}}async function Mt(t,{iv:e,cipherText:s}){const n=await crypto.subtle.decrypt({name:"AES-GCM",iv:e},t,s);return new TextDecoder().decode(n)}function Ne(t){switch(t){case"public":return"spki";case"private":return"pkcs8"}}async function Te(t,e){const s=Ne(t),n=await crypto.subtle.exportKey(s,e);return ne(new Uint8Array(n))}async function De(t,e){const s=Ne(t),n=H(e).buffer;return await crypto.subtle.importKey(s,new Uint8Array(n),{name:"ECDH",namedCurve:"P-256"},!0,t==="private"?["deriveKey"]:[])}async function xt(t,e){const s=JSON.stringify(t,(n,i)=>{if(!(i instanceof Error))return i;const r=i;return Object.assign(Object.assign({},r.code?{code:r.code}:{}),{message:r.message})});return St(e,s)}async function At(t,e){return JSON.parse(await Mt(e,t))}const Z={storageKey:"ownPrivateKey",keyType:"private"},F={storageKey:"ownPublicKey",keyType:"public"},$={storageKey:"peerPublicKey",keyType:"public"};class _t{constructor(){this.storage=new v("CBWSDK","SCWKeyManager"),this.ownPrivateKey=null,this.ownPublicKey=null,this.peerPublicKey=null,this.sharedSecret=null}async getOwnPublicKey(){return await this.loadKeysIfNeeded(),this.ownPublicKey}async getSharedSecret(){return await this.loadKeysIfNeeded(),this.sharedSecret}async setPeerPublicKey(e){this.sharedSecret=null,this.peerPublicKey=e,await this.storeKey($,e),await this.loadKeysIfNeeded()}async clear(){this.ownPrivateKey=null,this.ownPublicKey=null,this.peerPublicKey=null,this.sharedSecret=null,this.storage.removeItem(F.storageKey),this.storage.removeItem(Z.storageKey),this.storage.removeItem($.storageKey)}async generateKeyPair(){const e=await Ct();this.ownPrivateKey=e.privateKey,this.ownPublicKey=e.publicKey,await this.storeKey(Z,e.privateKey),await this.storeKey(F,e.publicKey)}async loadKeysIfNeeded(){if(this.ownPrivateKey===null&&(this.ownPrivateKey=await this.loadKey(Z)),this.ownPublicKey===null&&(this.ownPublicKey=await this.loadKey(F)),(this.ownPrivateKey===null||this.ownPublicKey===null)&&await this.generateKeyPair(),this.peerPublicKey===null&&(this.peerPublicKey=await this.loadKey($)),this.sharedSecret===null){if(this.ownPrivateKey===null||this.peerPublicKey===null)return;this.sharedSecret=await It(this.ownPrivateKey,this.peerPublicKey)}}async loadKey(e){const s=this.storage.getItem(e.storageKey);return s?De(e.keyType,s):null}async storeKey(e,s){const n=await Te(e.keyType,s);this.storage.setItem(e.storageKey,n)}}const T="4.2.3",Oe="@coinbase/wallet-sdk";async function je(t,e){const s=Object.assign(Object.assign({},t),{jsonrpc:"2.0",id:crypto.randomUUID()}),n=await window.fetch(e,{method:"POST",body:JSON.stringify(s),mode:"cors",headers:{"Content-Type":"application/json","X-Cbw-Sdk-Version":T,"X-Cbw-Sdk-Platform":Oe}}),{result:i,error:r}=await n.json();if(r)throw r;return i}function Lt(){return globalThis.coinbaseWalletExtension}function Pt(){var t,e;try{const s=globalThis;return(t=s.ethereum)!==null&&t!==void 0?t:(e=s.top)===null||e===void 0?void 0:e.ethereum}catch{return}}function Ue({metadata:t,preference:e}){var s,n;const{appName:i,appLogoUrl:r,appChainIds:a}=t;if(e.options!=="smartWalletOnly"){const c=Lt();if(c)return(s=c.setAppInfo)===null||s===void 0||s.call(c,i,r,a,e),c}const o=Pt();if(o!=null&&o.isCoinbaseBrowser)return(n=o.setAppInfo)===null||n===void 0||n.call(o,i,r,a,e),o}function Rt(t){if(!t||typeof t!="object"||Array.isArray(t))throw l.rpc.invalidParams({message:"Expected a single, non-array, object argument.",data:t});const{method:e,params:s}=t;if(typeof e!="string"||e.length===0)throw l.rpc.invalidParams({message:"'args.method' must be a non-empty string.",data:t});if(s!==void 0&&!Array.isArray(s)&&(typeof s!="object"||s===null))throw l.rpc.invalidParams({message:"'args.params' must be an object or array if provided.",data:t});switch(e){case"eth_sign":case"eth_signTypedData_v2":case"eth_subscribe":case"eth_unsubscribe":throw l.provider.unsupportedMethod()}}const de="accounts",le="activeChain",he="availableChains",ue="walletCapabilities";class Nt{constructor(e){var s,n,i;this.metadata=e.metadata,this.communicator=e.communicator,this.callback=e.callback,this.keyManager=new _t,this.storage=new v("CBWSDK","SCWStateManager"),this.accounts=(s=this.storage.loadObject(de))!==null&&s!==void 0?s:[],this.chain=this.storage.loadObject(le)||{id:(i=(n=e.metadata.appChainIds)===null||n===void 0?void 0:n[0])!==null&&i!==void 0?i:1},this.handshake=this.handshake.bind(this),this.request=this.request.bind(this),this.createRequestMessage=this.createRequestMessage.bind(this),this.decryptResponseMessage=this.decryptResponseMessage.bind(this)}async handshake(e){var s,n;const i=await this.createRequestMessage({handshake:{method:e.method,params:Object.assign({},this.metadata,(s=e.params)!==null&&s!==void 0?s:{})}}),r=await this.communicator.postRequestAndWaitForResponse(i);if("failure"in r.content)throw r.content.failure;const a=await De("public",r.sender);await this.keyManager.setPeerPublicKey(a);const c=(await this.decryptResponseMessage(r)).result;if("error"in c)throw c.error;const d=c.value;this.accounts=d,this.storage.storeObject(de,d),(n=this.callback)===null||n===void 0||n.call(this,"accountsChanged",d)}async request(e){var s;if(this.accounts.length===0)throw l.provider.unauthorized();switch(e.method){case"eth_requestAccounts":return(s=this.callback)===null||s===void 0||s.call(this,"connect",{chainId:A(this.chain.id)}),this.accounts;case"eth_accounts":return this.accounts;case"eth_coinbase":return this.accounts[0];case"net_version":return this.chain.id;case"eth_chainId":return A(this.chain.id);case"wallet_getCapabilities":return this.storage.loadObject(ue);case"wallet_switchEthereumChain":return this.handleSwitchChainRequest(e);case"eth_ecRecover":case"personal_sign":case"personal_ecRecover":case"eth_signTransaction":case"eth_sendTransaction":case"eth_signTypedData_v1":case"eth_signTypedData_v3":case"eth_signTypedData_v4":case"eth_signTypedData":case"wallet_addEthereumChain":case"wallet_watchAsset":case"wallet_sendCalls":case"wallet_showCallsStatus":case"wallet_grantPermissions":return this.sendRequestToPopup(e);default:if(!this.chain.rpcUrl)throw l.rpc.internal("No RPC URL set for chain");return je(e,this.chain.rpcUrl)}}async sendRequestToPopup(e){var s,n;await((n=(s=this.communicator).waitForPopupLoaded)===null||n===void 0?void 0:n.call(s));const i=await this.sendEncryptedRequest(e),a=(await this.decryptResponseMessage(i)).result;if("error"in a)throw a.error;return a.value}async cleanup(){var e,s;this.storage.clear(),await this.keyManager.clear(),this.accounts=[],this.chain={id:(s=(e=this.metadata.appChainIds)===null||e===void 0?void 0:e[0])!==null&&s!==void 0?s:1}}async handleSwitchChainRequest(e){var s;const n=e.params;if(!n||!(!((s=n[0])===null||s===void 0)&&s.chainId))throw l.rpc.invalidParams();const i=j(n[0].chainId);if(this.updateChain(i))return null;const a=await this.sendRequestToPopup(e);return a===null&&this.updateChain(i),a}async sendEncryptedRequest(e){const s=await this.keyManager.getSharedSecret();if(!s)throw l.provider.unauthorized("No valid session found, try requestAccounts before other methods");const n=await xt({action:e,chainId:this.chain.id},s),i=await this.createRequestMessage({encrypted:n});return this.communicator.postRequestAndWaitForResponse(i)}async createRequestMessage(e){const s=await Te("public",await this.keyManager.getOwnPublicKey());return{id:crypto.randomUUID(),sender:s,content:e,timestamp:new Date}}async decryptResponseMessage(e){var s,n;const i=e.content;if("failure"in i)throw i.failure;const r=await this.keyManager.getSharedSecret();if(!r)throw l.provider.unauthorized("Invalid session");const a=await At(i.encrypted,r),o=(s=a.data)===null||s===void 0?void 0:s.chains;if(o){const d=Object.entries(o).map(([g,p])=>({id:Number(g),rpcUrl:p}));this.storage.storeObject(he,d),this.updateChain(this.chain.id,d)}const c=(n=a.data)===null||n===void 0?void 0:n.capabilities;return c&&this.storage.storeObject(ue,c),a}updateChain(e,s){var n;const i=s??this.storage.loadObject(he),r=i==null?void 0:i.find(a=>a.id===e);return r?(r!==this.chain&&(this.chain=r,this.storage.storeObject(le,r),(n=this.callback)===null||n===void 0||n.call(this,"chainChanged",A(r.id))),!0):!1}}const Tt=rt(at),{keccak_256:Dt}=Tt;function We(t){return Buffer.allocUnsafe(t).fill(0)}function Ot(t){return t.toString(2).length}function Be(t,e){let s=t.toString(16);s.length%2!==0&&(s="0"+s);const n=s.match(/.{1,2}/g).map(i=>parseInt(i,16));for(;n.length<e;)n.unshift(0);return Buffer.from(n)}function jt(t,e){const s=t<0n;let n;if(s){const i=(1n<<BigInt(e))-1n;n=(~t&i)+1n}else n=t;return n&=(1n<<BigInt(e))-1n,n}function qe(t,e,s){const n=We(e);return t=V(t),s?t.length<e?(t.copy(n),n):t.slice(0,e):t.length<e?(t.copy(n,e-t.length),n):t.slice(-e)}function Ut(t,e){return qe(t,e,!0)}function V(t){if(!Buffer.isBuffer(t))if(Array.isArray(t))t=Buffer.from(t);else if(typeof t=="string")He(t)?t=Buffer.from(qt(Ke(t)),"hex"):t=Buffer.from(t);else if(typeof t=="number")t=intToBuffer(t);else if(t==null)t=Buffer.allocUnsafe(0);else if(typeof t=="bigint")t=Be(t);else if(t.toArray)t=Buffer.from(t.toArray());else throw new Error("invalid type");return t}function Wt(t){return t=V(t),"0x"+t.toString("hex")}function Bt(t,e){if(t=V(t),e||(e=256),e!==256)throw new Error("unsupported");return Buffer.from(Dt(new Uint8Array(t)))}function qt(t){return t.length%2?"0"+t:t}function He(t){return typeof t=="string"&&t.match(/^0x[0-9A-Fa-f]*$/)}function Ke(t){return typeof t=="string"&&t.startsWith("0x")?t.slice(2):t}var Ve={zeros:We,setLength:qe,setLengthRight:Ut,isHexString:He,stripHexPrefix:Ke,toBuffer:V,bufferToHex:Wt,keccak:Bt,bitLengthFromBigInt:Ot,bufferBEFromBigInt:Be,twosFromBigInt:jt};const w=Ve;function ze(t){return t.startsWith("int[")?"int256"+t.slice(3):t==="int"?"int256":t.startsWith("uint[")?"uint256"+t.slice(4):t==="uint"?"uint256":t.startsWith("fixed[")?"fixed128x128"+t.slice(5):t==="fixed"?"fixed128x128":t.startsWith("ufixed[")?"ufixed128x128"+t.slice(6):t==="ufixed"?"ufixed128x128":t}function R(t){return Number.parseInt(/^\D+(\d+)$/.exec(t)[1],10)}function pe(t){var e=/^\D+(\d+)x(\d+)$/.exec(t);return[Number.parseInt(e[1],10),Number.parseInt(e[2],10)]}function Ze(t){var e=t.match(/(.*)\[(.*?)\]$/);return e?e[2]===""?"dynamic":Number.parseInt(e[2],10):null}function L(t){var e=typeof t;if(e==="string"||e==="number")return BigInt(t);if(e==="bigint")return t;throw new Error("Argument is not a number")}function E(t,e){var s,n,i,r;if(t==="address")return E("uint160",L(e));if(t==="bool")return E("uint8",e?1:0);if(t==="string")return E("bytes",new Buffer(e,"utf8"));if(Kt(t)){if(typeof e.length>"u")throw new Error("Not an array?");if(s=Ze(t),s!=="dynamic"&&s!==0&&e.length>s)throw new Error("Elements exceed array size: "+s);i=[],t=t.slice(0,t.lastIndexOf("[")),typeof e=="string"&&(e=JSON.parse(e));for(r in e)i.push(E(t,e[r]));if(s==="dynamic"){var a=E("uint256",e.length);i.unshift(a)}return Buffer.concat(i)}else{if(t==="bytes")return e=new Buffer(e),i=Buffer.concat([E("uint256",e.length),e]),e.length%32!==0&&(i=Buffer.concat([i,w.zeros(32-e.length%32)])),i;if(t.startsWith("bytes")){if(s=R(t),s<1||s>32)throw new Error("Invalid bytes<N> width: "+s);return w.setLengthRight(e,32)}else if(t.startsWith("uint")){if(s=R(t),s%8||s<8||s>256)throw new Error("Invalid uint<N> width: "+s);n=L(e);const o=w.bitLengthFromBigInt(n);if(o>s)throw new Error("Supplied uint exceeds width: "+s+" vs "+o);if(n<0)throw new Error("Supplied uint is negative");return w.bufferBEFromBigInt(n,32)}else if(t.startsWith("int")){if(s=R(t),s%8||s<8||s>256)throw new Error("Invalid int<N> width: "+s);n=L(e);const o=w.bitLengthFromBigInt(n);if(o>s)throw new Error("Supplied int exceeds width: "+s+" vs "+o);const c=w.twosFromBigInt(n,256);return w.bufferBEFromBigInt(c,32)}else if(t.startsWith("ufixed")){if(s=pe(t),n=L(e),n<0)throw new Error("Supplied ufixed is negative");return E("uint256",n*BigInt(2)**BigInt(s[1]))}else if(t.startsWith("fixed"))return s=pe(t),E("int256",L(e)*BigInt(2)**BigInt(s[1]))}throw new Error("Unsupported or invalid type: "+t)}function Ht(t){return t==="string"||t==="bytes"||Ze(t)==="dynamic"}function Kt(t){return t.lastIndexOf("]")===t.length-1}function Vt(t,e){var s=[],n=[],i=32*t.length;for(var r in t){var a=ze(t[r]),o=e[r],c=E(a,o);Ht(a)?(s.push(E("uint256",i)),n.push(c),i+=c.length):s.push(c)}return Buffer.concat(s.concat(n))}function Fe(t,e){if(t.length!==e.length)throw new Error("Number of types are not matching the values");for(var s,n,i=[],r=0;r<t.length;r++){var a=ze(t[r]),o=e[r];if(a==="bytes")i.push(o);else if(a==="string")i.push(new Buffer(o,"utf8"));else if(a==="bool")i.push(new Buffer(o?"01":"00","hex"));else if(a==="address")i.push(w.setLength(o,20));else if(a.startsWith("bytes")){if(s=R(a),s<1||s>32)throw new Error("Invalid bytes<N> width: "+s);i.push(w.setLengthRight(o,s))}else if(a.startsWith("uint")){if(s=R(a),s%8||s<8||s>256)throw new Error("Invalid uint<N> width: "+s);n=L(o);const c=w.bitLengthFromBigInt(n);if(c>s)throw new Error("Supplied uint exceeds width: "+s+" vs "+c);i.push(w.bufferBEFromBigInt(n,s/8))}else if(a.startsWith("int")){if(s=R(a),s%8||s<8||s>256)throw new Error("Invalid int<N> width: "+s);n=L(o);const c=w.bitLengthFromBigInt(n);if(c>s)throw new Error("Supplied int exceeds width: "+s+" vs "+c);const d=w.twosFromBigInt(n,s);i.push(w.bufferBEFromBigInt(d,s/8))}else throw new Error("Unsupported or invalid type: "+a)}return Buffer.concat(i)}function zt(t,e){return w.keccak(Fe(t,e))}var Zt={rawEncode:Vt,solidityPack:Fe,soliditySHA3:zt};const y=Ve,U=Zt,$e={type:"object",properties:{types:{type:"object",additionalProperties:{type:"array",items:{type:"object",properties:{name:{type:"string"},type:{type:"string"}},required:["name","type"]}}},primaryType:{type:"string"},domain:{type:"object"},message:{type:"object"}},required:["types","primaryType","domain","message"]},G={encodeData(t,e,s,n=!0){const i=["bytes32"],r=[this.hashType(t,s)];if(n){const a=(o,c,d)=>{if(s[c]!==void 0)return["bytes32",d==null?"0x0000000000000000000000000000000000000000000000000000000000000000":y.keccak(this.encodeData(c,d,s,n))];if(d===void 0)throw new Error(`missing value for field ${o} of type ${c}`);if(c==="bytes")return["bytes32",y.keccak(d)];if(c==="string")return typeof d=="string"&&(d=Buffer.from(d,"utf8")),["bytes32",y.keccak(d)];if(c.lastIndexOf("]")===c.length-1){const g=c.slice(0,c.lastIndexOf("[")),p=d.map(f=>a(o,g,f));return["bytes32",y.keccak(U.rawEncode(p.map(([f])=>f),p.map(([,f])=>f)))]}return[c,d]};for(const o of s[t]){const[c,d]=a(o.name,o.type,e[o.name]);i.push(c),r.push(d)}}else for(const a of s[t]){let o=e[a.name];if(o!==void 0)if(a.type==="bytes")i.push("bytes32"),o=y.keccak(o),r.push(o);else if(a.type==="string")i.push("bytes32"),typeof o=="string"&&(o=Buffer.from(o,"utf8")),o=y.keccak(o),r.push(o);else if(s[a.type]!==void 0)i.push("bytes32"),o=y.keccak(this.encodeData(a.type,o,s,n)),r.push(o);else{if(a.type.lastIndexOf("]")===a.type.length-1)throw new Error("Arrays currently unimplemented in encodeData");i.push(a.type),r.push(o)}}return U.rawEncode(i,r)},encodeType(t,e){let s="",n=this.findTypeDependencies(t,e).filter(i=>i!==t);n=[t].concat(n.sort());for(const i of n){if(!e[i])throw new Error("No type definition specified: "+i);s+=i+"("+e[i].map(({name:a,type:o})=>o+" "+a).join(",")+")"}return s},findTypeDependencies(t,e,s=[]){if(t=t.match(/^\w*/)[0],s.includes(t)||e[t]===void 0)return s;s.push(t);for(const n of e[t])for(const i of this.findTypeDependencies(n.type,e,s))!s.includes(i)&&s.push(i);return s},hashStruct(t,e,s,n=!0){return y.keccak(this.encodeData(t,e,s,n))},hashType(t,e){return y.keccak(this.encodeType(t,e))},sanitizeData(t){const e={};for(const s in $e.properties)t[s]&&(e[s]=t[s]);return e.types&&(e.types=Object.assign({EIP712Domain:[]},e.types)),e},hash(t,e=!0){const s=this.sanitizeData(t),n=[Buffer.from("1901","hex")];return n.push(this.hashStruct("EIP712Domain",s.domain,s.types,e)),s.primaryType!=="EIP712Domain"&&n.push(this.hashStruct(s.primaryType,s.message,s.types,e)),y.keccak(Buffer.concat(n))}};var Ft={TYPED_MESSAGE_SCHEMA:$e,TypedDataUtils:G,hashForSignTypedDataLegacy:function(t){return $t(t.data)},hashForSignTypedData_v3:function(t){return G.hash(t.data,!1)},hashForSignTypedData_v4:function(t){return G.hash(t.data)}};function $t(t){const e=new Error("Expect argument to be non-empty array");if(typeof t!="object"||!t.length)throw e;const s=t.map(function(r){return r.type==="bytes"?y.toBuffer(r.value):r.value}),n=t.map(function(r){return r.type}),i=t.map(function(r){if(!r.name)throw e;return r.type+" "+r.name});return U.soliditySHA3(["bytes32","bytes32"],[U.soliditySHA3(new Array(t.length).fill("string"),i),U.soliditySHA3(n,s)])}const q=ot(Ft),Gt="walletUsername",ee="Addresses",Yt="AppVersion";function m(t){return t.errorMessage!==void 0}class Jt{constructor(e){this.secret=e}async encrypt(e){const s=this.secret;if(s.length!==64)throw Error("secret must be 256 bits");const n=crypto.getRandomValues(new Uint8Array(12)),i=await crypto.subtle.importKey("raw",H(s),{name:"aes-gcm"},!1,["encrypt","decrypt"]),r=new TextEncoder,a=await window.crypto.subtle.encrypt({name:"AES-GCM",iv:n},i,r.encode(e)),o=16,c=a.slice(a.byteLength-o),d=a.slice(0,a.byteLength-o),g=new Uint8Array(c),p=new Uint8Array(d),f=new Uint8Array([...n,...g,...p]);return ne(f)}async decrypt(e){const s=this.secret;if(s.length!==64)throw Error("secret must be 256 bits");return new Promise((n,i)=>{(async function(){const r=await crypto.subtle.importKey("raw",H(s),{name:"aes-gcm"},!1,["encrypt","decrypt"]),a=H(e),o=a.slice(0,12),c=a.slice(12,28),d=a.slice(28),g=new Uint8Array([...d,...c]),p={name:"AES-GCM",iv:new Uint8Array(o)};try{const f=await window.crypto.subtle.decrypt(p,r,g),C=new TextDecoder;n(C.decode(f))}catch(f){i(f)}})()})}}class Qt{constructor(e,s,n){this.linkAPIUrl=e,this.sessionId=s;const i=`${s}:${n}`;this.auth=`Basic ${btoa(i)}`}async markUnseenEventsAsSeen(e){return Promise.all(e.map(s=>fetch(`${this.linkAPIUrl}/events/${s.eventId}/seen`,{method:"POST",headers:{Authorization:this.auth}}))).catch(s=>console.error("Unabled to mark event as failed:",s))}async fetchUnseenEvents(){var e;const s=await fetch(`${this.linkAPIUrl}/events?unseen=true`,{headers:{Authorization:this.auth}});if(s.ok){const{events:n,error:i}=await s.json();if(i)throw new Error(`Check unseen events failed: ${i}`);const r=(e=n==null?void 0:n.filter(a=>a.event==="Web3Response").map(a=>({type:"Event",sessionId:this.sessionId,eventId:a.id,event:a.event,data:a.data})))!==null&&e!==void 0?e:[];return this.markUnseenEventsAsSeen(r),r}throw new Error(`Check unseen events failed: ${s.status}`)}}var M;(function(t){t[t.DISCONNECTED=0]="DISCONNECTED",t[t.CONNECTING=1]="CONNECTING",t[t.CONNECTED=2]="CONNECTED"})(M||(M={}));class Xt{setConnectionStateListener(e){this.connectionStateListener=e}setIncomingDataListener(e){this.incomingDataListener=e}constructor(e,s=WebSocket){this.WebSocketClass=s,this.webSocket=null,this.pendingData=[],this.url=e.replace(/^http/,"ws")}async connect(){if(this.webSocket)throw new Error("webSocket object is not null");return new Promise((e,s)=>{var n;let i;try{this.webSocket=i=new this.WebSocketClass(this.url)}catch(r){s(r);return}(n=this.connectionStateListener)===null||n===void 0||n.call(this,M.CONNECTING),i.onclose=r=>{var a;this.clearWebSocket(),s(new Error(`websocket error ${r.code}: ${r.reason}`)),(a=this.connectionStateListener)===null||a===void 0||a.call(this,M.DISCONNECTED)},i.onopen=r=>{var a;e(),(a=this.connectionStateListener)===null||a===void 0||a.call(this,M.CONNECTED),this.pendingData.length>0&&([...this.pendingData].forEach(c=>this.sendData(c)),this.pendingData=[])},i.onmessage=r=>{var a,o;if(r.data==="h")(a=this.incomingDataListener)===null||a===void 0||a.call(this,{type:"Heartbeat"});else try{const c=JSON.parse(r.data);(o=this.incomingDataListener)===null||o===void 0||o.call(this,c)}catch{}}})}disconnect(){var e;const{webSocket:s}=this;if(s){this.clearWebSocket(),(e=this.connectionStateListener)===null||e===void 0||e.call(this,M.DISCONNECTED),this.connectionStateListener=void 0,this.incomingDataListener=void 0;try{s.close()}catch{}}}sendData(e){const{webSocket:s}=this;if(!s){this.pendingData.push(e),this.connect();return}s.send(e)}clearWebSocket(){const{webSocket:e}=this;e&&(this.webSocket=null,e.onclose=null,e.onerror=null,e.onmessage=null,e.onopen=null)}}const fe=1e4,es=6e4;class ts{constructor({session:e,linkAPIUrl:s,listener:n}){this.destroyed=!1,this.lastHeartbeatResponse=0,this.nextReqId=I(1),this._connected=!1,this._linked=!1,this.shouldFetchUnseenEventsOnConnect=!1,this.requestResolutions=new Map,this.handleSessionMetadataUpdated=r=>{if(!r)return;new Map([["__destroyed",this.handleDestroyed],["EthereumAddress",this.handleAccountUpdated],["WalletUsername",this.handleWalletUsernameUpdated],["AppVersion",this.handleAppVersionUpdated],["ChainId",o=>r.JsonRpcUrl&&this.handleChainUpdated(o,r.JsonRpcUrl)]]).forEach((o,c)=>{const d=r[c];d!==void 0&&o(d)})},this.handleDestroyed=r=>{var a;r==="1"&&((a=this.listener)===null||a===void 0||a.resetAndReload())},this.handleAccountUpdated=async r=>{var a;const o=await this.cipher.decrypt(r);(a=this.listener)===null||a===void 0||a.accountUpdated(o)},this.handleMetadataUpdated=async(r,a)=>{var o;const c=await this.cipher.decrypt(a);(o=this.listener)===null||o===void 0||o.metadataUpdated(r,c)},this.handleWalletUsernameUpdated=async r=>{this.handleMetadataUpdated(Gt,r)},this.handleAppVersionUpdated=async r=>{this.handleMetadataUpdated(Yt,r)},this.handleChainUpdated=async(r,a)=>{var o;const c=await this.cipher.decrypt(r),d=await this.cipher.decrypt(a);(o=this.listener)===null||o===void 0||o.chainUpdated(c,d)},this.session=e,this.cipher=new Jt(e.secret),this.listener=n;const i=new Xt(`${s}/rpc`,WebSocket);i.setConnectionStateListener(async r=>{let a=!1;switch(r){case M.DISCONNECTED:if(!this.destroyed){const o=async()=>{await new Promise(c=>setTimeout(c,5e3)),this.destroyed||i.connect().catch(()=>{o()})};o()}break;case M.CONNECTED:a=await this.handleConnected(),this.updateLastHeartbeat(),setInterval(()=>{this.heartbeat()},fe),this.shouldFetchUnseenEventsOnConnect&&this.fetchUnseenEventsAPI();break;case M.CONNECTING:break}this.connected!==a&&(this.connected=a)}),i.setIncomingDataListener(r=>{var a;switch(r.type){case"Heartbeat":this.updateLastHeartbeat();return;case"IsLinkedOK":case"Linked":{const o=r.type==="IsLinkedOK"?r.linked:void 0;this.linked=o||r.onlineGuests>0;break}case"GetSessionConfigOK":case"SessionConfigUpdated":{this.handleSessionMetadataUpdated(r.metadata);break}case"Event":{this.handleIncomingEvent(r);break}}r.id!==void 0&&((a=this.requestResolutions.get(r.id))===null||a===void 0||a(r))}),this.ws=i,this.http=new Qt(s,e.id,e.key)}connect(){if(this.destroyed)throw new Error("instance is destroyed");this.ws.connect()}async destroy(){this.destroyed||(await this.makeRequest({type:"SetSessionConfig",id:I(this.nextReqId++),sessionId:this.session.id,metadata:{__destroyed:"1"}},{timeout:1e3}),this.destroyed=!0,this.ws.disconnect(),this.listener=void 0)}get connected(){return this._connected}set connected(e){this._connected=e}get linked(){return this._linked}set linked(e){var s,n;this._linked=e,e&&((s=this.onceLinked)===null||s===void 0||s.call(this)),(n=this.listener)===null||n===void 0||n.linkedUpdated(e)}setOnceLinked(e){return new Promise(s=>{this.linked?e().then(s):this.onceLinked=()=>{e().then(s),this.onceLinked=void 0}})}async handleIncomingEvent(e){var s;if(e.type!=="Event"||e.event!=="Web3Response")return;const n=await this.cipher.decrypt(e.data),i=JSON.parse(n);if(i.type!=="WEB3_RESPONSE")return;const{id:r,response:a}=i;(s=this.listener)===null||s===void 0||s.handleWeb3ResponseMessage(r,a)}async checkUnseenEvents(){if(!this.connected){this.shouldFetchUnseenEventsOnConnect=!0;return}await new Promise(e=>setTimeout(e,250));try{await this.fetchUnseenEventsAPI()}catch(e){console.error("Unable to check for unseen events",e)}}async fetchUnseenEventsAPI(){this.shouldFetchUnseenEventsOnConnect=!1,(await this.http.fetchUnseenEvents()).forEach(s=>this.handleIncomingEvent(s))}async publishEvent(e,s,n=!1){const i=await this.cipher.encrypt(JSON.stringify(Object.assign(Object.assign({},s),{origin:location.origin,relaySource:"coinbaseWalletExtension"in window&&window.coinbaseWalletExtension?"injected_sdk":"sdk"}))),r={type:"PublishEvent",id:I(this.nextReqId++),sessionId:this.session.id,event:e,data:i,callWebhook:n};return this.setOnceLinked(async()=>{const a=await this.makeRequest(r);if(a.type==="Fail")throw new Error(a.error||"failed to publish event");return a.eventId})}sendData(e){this.ws.sendData(JSON.stringify(e))}updateLastHeartbeat(){this.lastHeartbeatResponse=Date.now()}heartbeat(){if(Date.now()-this.lastHeartbeatResponse>fe*2){this.ws.disconnect();return}try{this.ws.sendData("h")}catch{}}async makeRequest(e,s={timeout:es}){const n=e.id;this.sendData(e);let i;return Promise.race([new Promise((r,a)=>{i=window.setTimeout(()=>{a(new Error(`request ${n} timed out`))},s.timeout)}),new Promise(r=>{this.requestResolutions.set(n,a=>{clearTimeout(i),r(a),this.requestResolutions.delete(n)})})])}async handleConnected(){return(await this.makeRequest({type:"HostSession",id:I(this.nextReqId++),sessionId:this.session.id,sessionKey:this.session.key})).type==="Fail"?!1:(this.sendData({type:"IsLinked",id:I(this.nextReqId++),sessionId:this.session.id}),this.sendData({type:"GetSessionConfig",id:I(this.nextReqId++),sessionId:this.session.id}),!0)}}class ss{constructor(){this._nextRequestId=0,this.callbacks=new Map}makeRequestId(){this._nextRequestId=(this._nextRequestId+1)%2147483647;const e=this._nextRequestId,s=Re(e.toString(16));return this.callbacks.get(s)&&this.callbacks.delete(s),e}}const ge="session:id",me="session:secret",we="session:linked";class N{constructor(e,s,n,i=!1){this.storage=e,this.id=s,this.secret=n,this.key=ct(dt(`${s}, ${n} WalletLink`)),this._linked=!!i}static create(e){const s=_(16),n=_(32);return new N(e,s,n).save()}static load(e){const s=e.getItem(ge),n=e.getItem(we),i=e.getItem(me);return s&&i?new N(e,s,i,n==="1"):null}get linked(){return this._linked}set linked(e){this._linked=e,this.persistLinked()}save(){return this.storage.setItem(ge,this.id),this.storage.setItem(me,this.secret),this.persistLinked(),this}persistLinked(){this.storage.setItem(we,this._linked?"1":"0")}}function ns(){try{return window.frameElement!==null}catch{return!1}}function is(){try{return ns()&&window.top?window.top.location:window.location}catch{return window.location}}function rs(){var t;return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test((t=window==null?void 0:window.navigator)===null||t===void 0?void 0:t.userAgent)}function Ge(){var t,e;return(e=(t=window==null?void 0:window.matchMedia)===null||t===void 0?void 0:t.call(window,"(prefers-color-scheme: dark)").matches)!==null&&e!==void 0?e:!1}const as='@namespace svg "http://www.w3.org/2000/svg";.-cbwsdk-css-reset,.-cbwsdk-css-reset *{animation:none;animation-delay:0;animation-direction:normal;animation-duration:0;animation-fill-mode:none;animation-iteration-count:1;animation-name:none;animation-play-state:running;animation-timing-function:ease;backface-visibility:visible;background:0;background-attachment:scroll;background-clip:border-box;background-color:rgba(0,0,0,0);background-image:none;background-origin:padding-box;background-position:0 0;background-position-x:0;background-position-y:0;background-repeat:repeat;background-size:auto auto;border:0;border-style:none;border-width:medium;border-color:inherit;border-bottom:0;border-bottom-color:inherit;border-bottom-left-radius:0;border-bottom-right-radius:0;border-bottom-style:none;border-bottom-width:medium;border-collapse:separate;border-image:none;border-left:0;border-left-color:inherit;border-left-style:none;border-left-width:medium;border-radius:0;border-right:0;border-right-color:inherit;border-right-style:none;border-right-width:medium;border-spacing:0;border-top:0;border-top-color:inherit;border-top-left-radius:0;border-top-right-radius:0;border-top-style:none;border-top-width:medium;box-shadow:none;box-sizing:border-box;caption-side:top;clear:none;clip:auto;color:inherit;columns:auto;column-count:auto;column-fill:balance;column-gap:normal;column-rule:medium none currentColor;column-rule-color:currentColor;column-rule-style:none;column-rule-width:none;column-span:1;column-width:auto;counter-increment:none;counter-reset:none;direction:ltr;empty-cells:show;float:none;font:normal;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Helvetica Neue",Arial,sans-serif;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;height:auto;hyphens:none;letter-spacing:normal;line-height:normal;list-style:none;list-style-image:none;list-style-position:outside;list-style-type:disc;margin:0;margin-bottom:0;margin-left:0;margin-right:0;margin-top:0;opacity:1;orphans:0;outline:0;outline-color:invert;outline-style:none;outline-width:medium;overflow:visible;overflow-x:visible;overflow-y:visible;padding:0;padding-bottom:0;padding-left:0;padding-right:0;padding-top:0;page-break-after:auto;page-break-before:auto;page-break-inside:auto;perspective:none;perspective-origin:50% 50%;pointer-events:auto;position:static;quotes:"\\201C" "\\201D" "\\2018" "\\2019";tab-size:8;table-layout:auto;text-align:inherit;text-align-last:auto;text-decoration:none;text-decoration-color:inherit;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-shadow:none;text-transform:none;transform:none;transform-style:flat;transition:none;transition-delay:0s;transition-duration:0s;transition-property:none;transition-timing-function:ease;unicode-bidi:normal;vertical-align:baseline;visibility:visible;white-space:normal;widows:0;word-spacing:normal;z-index:auto}.-cbwsdk-css-reset strong{font-weight:bold}.-cbwsdk-css-reset *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Helvetica Neue",Arial,sans-serif;line-height:1}.-cbwsdk-css-reset [class*=container]{margin:0;padding:0}.-cbwsdk-css-reset style{display:none}';function Ye(){const t=document.createElement("style");t.type="text/css",t.appendChild(document.createTextNode(as)),document.documentElement.appendChild(t)}function Je(t){var e,s,n="";if(typeof t=="string"||typeof t=="number")n+=t;else if(typeof t=="object")if(Array.isArray(t))for(e=0;e<t.length;e++)t[e]&&(s=Je(t[e]))&&(n&&(n+=" "),n+=s);else for(e in t)t[e]&&(n&&(n+=" "),n+=e);return n}function W(){for(var t,e,s=0,n="";s<arguments.length;)(t=arguments[s++])&&(e=Je(t))&&(n&&(n+=" "),n+=e);return n}const os=".-cbwsdk-css-reset .-gear-container{margin-left:16px !important;margin-right:9px !important;display:flex;align-items:center;justify-content:center;width:24px;height:24px;transition:opacity .25s}.-cbwsdk-css-reset .-gear-container *{user-select:none}.-cbwsdk-css-reset .-gear-container svg{opacity:0;position:absolute}.-cbwsdk-css-reset .-gear-icon{height:12px;width:12px;z-index:10000}.-cbwsdk-css-reset .-cbwsdk-snackbar{align-items:flex-end;display:flex;flex-direction:column;position:fixed;right:0;top:0;z-index:2147483647}.-cbwsdk-css-reset .-cbwsdk-snackbar *{user-select:none}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance{display:flex;flex-direction:column;margin:8px 16px 0 16px;overflow:visible;text-align:left;transform:translateX(0);transition:opacity .25s,transform .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header:hover .-gear-container svg{opacity:1}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header{display:flex;align-items:center;background:#fff;overflow:hidden;border:1px solid #e7ebee;box-sizing:border-box;border-radius:8px;cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header-cblogo{margin:8px 8px 8px 8px}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header *{cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header-message{color:#000;font-size:13px;line-height:1.5;user-select:none}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu{background:#fff;transition:opacity .25s ease-in-out,transform .25s linear,visibility 0s;visibility:hidden;border:1px solid #e7ebee;box-sizing:border-box;border-radius:8px;opacity:0;flex-direction:column;padding-left:8px;padding-right:8px}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:last-child{margin-bottom:8px !important}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:hover{background:#f5f7f8;border-radius:6px;transition:background .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:hover span{color:#050f19;transition:color .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:hover svg path{fill:#000;transition:fill .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item{visibility:inherit;height:35px;margin-top:8px;margin-bottom:0;display:flex;flex-direction:row;align-items:center;padding:8px;cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item *{visibility:inherit;cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover{background:rgba(223,95,103,.2);transition:background .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover *{cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover svg path{fill:#df5f67;transition:fill .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover span{color:#df5f67;transition:color .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-info{color:#aaa;font-size:13px;margin:0 8px 0 32px;position:absolute}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-hidden{opacity:0;text-align:left;transform:translateX(25%);transition:opacity .5s linear}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-expanded .-cbwsdk-snackbar-instance-menu{opacity:1;display:flex;transform:translateY(8px);visibility:visible}",cs="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEuNDkyIDEwLjQxOWE4LjkzIDguOTMgMCAwMTguOTMtOC45M2gxMS4xNjNhOC45MyA4LjkzIDAgMDE4LjkzIDguOTN2MTEuMTYzYTguOTMgOC45MyAwIDAxLTguOTMgOC45M0gxMC40MjJhOC45MyA4LjkzIDAgMDEtOC45My04LjkzVjEwLjQxOXoiIGZpbGw9IiMxNjUyRjAiLz48cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTEwLjQxOSAwSDIxLjU4QzI3LjMzNSAwIDMyIDQuNjY1IDMyIDEwLjQxOVYyMS41OEMzMiAyNy4zMzUgMjcuMzM1IDMyIDIxLjU4MSAzMkgxMC40MkM0LjY2NSAzMiAwIDI3LjMzNSAwIDIxLjU4MVYxMC40MkMwIDQuNjY1IDQuNjY1IDAgMTAuNDE5IDB6bTAgMS40ODhhOC45MyA4LjkzIDAgMDAtOC45MyA4LjkzdjExLjE2M2E4LjkzIDguOTMgMCAwMDguOTMgOC45M0gyMS41OGE4LjkzIDguOTMgMCAwMDguOTMtOC45M1YxMC40MmE4LjkzIDguOTMgMCAwMC04LjkzLTguOTNIMTAuNDJ6IiBmaWxsPSIjZmZmIi8+PHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xNS45OTggMjYuMDQ5Yy01LjU0OSAwLTEwLjA0Ny00LjQ5OC0xMC4wNDctMTAuMDQ3IDAtNS41NDggNC40OTgtMTAuMDQ2IDEwLjA0Ny0xMC4wNDYgNS41NDggMCAxMC4wNDYgNC40OTggMTAuMDQ2IDEwLjA0NiAwIDUuNTQ5LTQuNDk4IDEwLjA0Ny0xMC4wNDYgMTAuMDQ3eiIgZmlsbD0iI2ZmZiIvPjxwYXRoIGQ9Ik0xMi43NjIgMTQuMjU0YzAtLjgyMi42NjctMS40ODkgMS40ODktMS40ODloMy40OTdjLjgyMiAwIDEuNDg4LjY2NiAxLjQ4OCAxLjQ4OXYzLjQ5N2MwIC44MjItLjY2NiAxLjQ4OC0xLjQ4OCAxLjQ4OGgtMy40OTdhMS40ODggMS40ODggMCAwMS0xLjQ4OS0xLjQ4OHYtMy40OTh6IiBmaWxsPSIjMTY1MkYwIi8+PC9zdmc+",ds="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iMTIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDYuNzV2LTEuNWwtMS43Mi0uNTdjLS4wOC0uMjctLjE5LS41Mi0uMzItLjc3bC44MS0xLjYyLTEuMDYtMS4wNi0xLjYyLjgxYy0uMjQtLjEzLS41LS4yNC0uNzctLjMyTDYuNzUgMGgtMS41bC0uNTcgMS43MmMtLjI3LjA4LS41My4xOS0uNzcuMzJsLTEuNjItLjgxLTEuMDYgMS4wNi44MSAxLjYyYy0uMTMuMjQtLjI0LjUtLjMyLjc3TDAgNS4yNXYxLjVsMS43Mi41N2MuMDguMjcuMTkuNTMuMzIuNzdsLS44MSAxLjYyIDEuMDYgMS4wNiAxLjYyLS44MWMuMjQuMTMuNS4yMy43Ny4zMkw1LjI1IDEyaDEuNWwuNTctMS43MmMuMjctLjA4LjUyLS4xOS43Ny0uMzJsMS42Mi44MSAxLjA2LTEuMDYtLjgxLTEuNjJjLjEzLS4yNC4yMy0uNS4zMi0uNzdMMTIgNi43NXpNNiA4LjVhMi41IDIuNSAwIDAxMC01IDIuNSAyLjUgMCAwMTAgNXoiIGZpbGw9IiMwNTBGMTkiLz48L3N2Zz4=";class ls{constructor(){this.items=new Map,this.nextItemKey=0,this.root=null,this.darkMode=Ge()}attach(e){this.root=document.createElement("div"),this.root.className="-cbwsdk-snackbar-root",e.appendChild(this.root),this.render()}presentItem(e){const s=this.nextItemKey++;return this.items.set(s,e),this.render(),()=>{this.items.delete(s),this.render()}}clear(){this.items.clear(),this.render()}render(){this.root&&Y(h("div",null,h(Qe,{darkMode:this.darkMode},Array.from(this.items.entries()).map(([e,s])=>h(hs,Object.assign({},s,{key:e}))))),this.root)}}const Qe=t=>h("div",{class:W("-cbwsdk-snackbar-container")},h("style",null,os),h("div",{class:"-cbwsdk-snackbar"},t.children)),hs=({autoExpand:t,message:e,menuItems:s})=>{const[n,i]=ae(!0),[r,a]=ae(t??!1);ht(()=>{const c=[window.setTimeout(()=>{i(!1)},1),window.setTimeout(()=>{a(!0)},1e4)];return()=>{c.forEach(window.clearTimeout)}});const o=()=>{a(!r)};return h("div",{class:W("-cbwsdk-snackbar-instance",n&&"-cbwsdk-snackbar-instance-hidden",r&&"-cbwsdk-snackbar-instance-expanded")},h("div",{class:"-cbwsdk-snackbar-instance-header",onClick:o},h("img",{src:cs,class:"-cbwsdk-snackbar-instance-header-cblogo"})," ",h("div",{class:"-cbwsdk-snackbar-instance-header-message"},e),h("div",{class:"-gear-container"},!r&&h("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},h("circle",{cx:"12",cy:"12",r:"12",fill:"#F5F7F8"})),h("img",{src:ds,class:"-gear-icon",title:"Expand"}))),s&&s.length>0&&h("div",{class:"-cbwsdk-snackbar-instance-menu"},s.map((c,d)=>h("div",{class:W("-cbwsdk-snackbar-instance-menu-item",c.isRed&&"-cbwsdk-snackbar-instance-menu-item-is-red"),onClick:c.onClick,key:d},h("svg",{width:c.svgWidth,height:c.svgHeight,viewBox:"0 0 10 11",fill:"none",xmlns:"http://www.w3.org/2000/svg"},h("path",{"fill-rule":c.defaultFillRule,"clip-rule":c.defaultClipRule,d:c.path,fill:"#AAAAAA"})),h("span",{class:W("-cbwsdk-snackbar-instance-menu-item-info",c.isRed&&"-cbwsdk-snackbar-instance-menu-item-info-is-red")},c.info)))))};class us{constructor(){this.attached=!1,this.snackbar=new ls}attach(){if(this.attached)throw new Error("Coinbase Wallet SDK UI is already attached");const e=document.documentElement,s=document.createElement("div");s.className="-cbwsdk-css-reset",e.appendChild(s),this.snackbar.attach(s),this.attached=!0,Ye()}showConnecting(e){let s;return e.isUnlinkedErrorState?s={autoExpand:!0,message:"Connection lost",menuItems:[{isRed:!1,info:"Reset connection",svgWidth:"10",svgHeight:"11",path:"M5.00008 0.96875C6.73133 0.96875 8.23758 1.94375 9.00008 3.375L10.0001 2.375V5.5H9.53133H7.96883H6.87508L7.80633 4.56875C7.41258 3.3875 6.31258 2.53125 5.00008 2.53125C3.76258 2.53125 2.70633 3.2875 2.25633 4.36875L0.812576 3.76875C1.50008 2.125 3.11258 0.96875 5.00008 0.96875ZM2.19375 6.43125C2.5875 7.6125 3.6875 8.46875 5 8.46875C6.2375 8.46875 7.29375 7.7125 7.74375 6.63125L9.1875 7.23125C8.5 8.875 6.8875 10.0312 5 10.0312C3.26875 10.0312 1.7625 9.05625 1 7.625L0 8.625V5.5H0.46875H2.03125H3.125L2.19375 6.43125Z",defaultFillRule:"evenodd",defaultClipRule:"evenodd",onClick:e.onResetConnection}]}:s={message:"Confirm on phone",menuItems:[{isRed:!0,info:"Cancel transaction",svgWidth:"11",svgHeight:"11",path:"M10.3711 1.52346L9.21775 0.370117L5.37109 4.21022L1.52444 0.370117L0.371094 1.52346L4.2112 5.37012L0.371094 9.21677L1.52444 10.3701L5.37109 6.53001L9.21775 10.3701L10.3711 9.21677L6.53099 5.37012L10.3711 1.52346Z",defaultFillRule:"inherit",defaultClipRule:"inherit",onClick:e.onCancel},{isRed:!1,info:"Reset connection",svgWidth:"10",svgHeight:"11",path:"M5.00008 0.96875C6.73133 0.96875 8.23758 1.94375 9.00008 3.375L10.0001 2.375V5.5H9.53133H7.96883H6.87508L7.80633 4.56875C7.41258 3.3875 6.31258 2.53125 5.00008 2.53125C3.76258 2.53125 2.70633 3.2875 2.25633 4.36875L0.812576 3.76875C1.50008 2.125 3.11258 0.96875 5.00008 0.96875ZM2.19375 6.43125C2.5875 7.6125 3.6875 8.46875 5 8.46875C6.2375 8.46875 7.29375 7.7125 7.74375 6.63125L9.1875 7.23125C8.5 8.875 6.8875 10.0312 5 10.0312C3.26875 10.0312 1.7625 9.05625 1 7.625L0 8.625V5.5H0.46875H2.03125H3.125L2.19375 6.43125Z",defaultFillRule:"evenodd",defaultClipRule:"evenodd",onClick:e.onResetConnection}]},this.snackbar.presentItem(s)}}const ps=".-cbwsdk-css-reset .-cbwsdk-redirect-dialog-backdrop{position:fixed;top:0;left:0;right:0;bottom:0;transition:opacity .25s;background-color:rgba(10,11,13,.5)}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-backdrop-hidden{opacity:0}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box{display:block;position:fixed;top:50%;left:50%;transform:translate(-50%, -50%);padding:20px;border-radius:8px;background-color:#fff;color:#0a0b0d}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box p{display:block;font-weight:400;font-size:14px;line-height:20px;padding-bottom:12px;color:#5b636e}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box button{appearance:none;border:none;background:none;color:#0052ff;padding:0;text-decoration:none;display:block;font-weight:600;font-size:16px;line-height:24px}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.dark{background-color:#0a0b0d;color:#fff}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.dark button{color:#0052ff}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.light{background-color:#fff;color:#0a0b0d}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.light button{color:#0052ff}";class fs{constructor(){this.root=null,this.darkMode=Ge()}attach(){const e=document.documentElement;this.root=document.createElement("div"),this.root.className="-cbwsdk-css-reset",e.appendChild(this.root),Ye()}present(e){this.render(e)}clear(){this.render(null)}render(e){this.root&&(Y(null,this.root),e&&Y(h(gs,Object.assign({},e,{onDismiss:()=>{this.clear()},darkMode:this.darkMode})),this.root))}}const gs=({title:t,buttonText:e,darkMode:s,onButtonClick:n,onDismiss:i})=>{const r=s?"dark":"light";return h(Qe,{darkMode:s},h("div",{class:"-cbwsdk-redirect-dialog"},h("style",null,ps),h("div",{class:"-cbwsdk-redirect-dialog-backdrop",onClick:i}),h("div",{class:W("-cbwsdk-redirect-dialog-box",r)},h("p",null,t),h("button",{onClick:n},e))))},ms="https://keys.coinbase.com/connect",be="https://www.walletlink.org",ws="https://go.cb-w.com/walletlink";class ye{constructor(){this.attached=!1,this.redirectDialog=new fs}attach(){if(this.attached)throw new Error("Coinbase Wallet SDK UI is already attached");this.redirectDialog.attach(),this.attached=!0}redirectToCoinbaseWallet(e){const s=new URL(ws);s.searchParams.append("redirect_url",is().href),e&&s.searchParams.append("wl_url",e);const n=document.createElement("a");n.target="cbw-opener",n.href=s.href,n.rel="noreferrer noopener",n.click()}openCoinbaseWalletDeeplink(e){this.redirectDialog.present({title:"Redirecting to Coinbase Wallet...",buttonText:"Open",onButtonClick:()=>{this.redirectToCoinbaseWallet(e)}}),setTimeout(()=>{this.redirectToCoinbaseWallet(e)},99)}showConnecting(e){return()=>{this.redirectDialog.clear()}}}class S{constructor(e){this.chainCallbackParams={chainId:"",jsonRpcUrl:""},this.isMobileWeb=rs(),this.linkedUpdated=r=>{this.isLinked=r;const a=this.storage.getItem(ee);if(r&&(this._session.linked=r),this.isUnlinkedErrorState=!1,a){const o=a.split(" "),c=this.storage.getItem("IsStandaloneSigning")==="true";o[0]!==""&&!r&&this._session.linked&&!c&&(this.isUnlinkedErrorState=!0)}},this.metadataUpdated=(r,a)=>{this.storage.setItem(r,a)},this.chainUpdated=(r,a)=>{this.chainCallbackParams.chainId===r&&this.chainCallbackParams.jsonRpcUrl===a||(this.chainCallbackParams={chainId:r,jsonRpcUrl:a},this.chainCallback&&this.chainCallback(a,Number.parseInt(r,10)))},this.accountUpdated=r=>{this.accountsCallback&&this.accountsCallback([r]),S.accountRequestCallbackIds.size>0&&(Array.from(S.accountRequestCallbackIds.values()).forEach(a=>{this.invokeCallback(a,{method:"requestEthereumAccounts",result:[r]})}),S.accountRequestCallbackIds.clear())},this.resetAndReload=this.resetAndReload.bind(this),this.linkAPIUrl=e.linkAPIUrl,this.storage=e.storage,this.metadata=e.metadata,this.accountsCallback=e.accountsCallback,this.chainCallback=e.chainCallback;const{session:s,ui:n,connection:i}=this.subscribe();this._session=s,this.connection=i,this.relayEventManager=new ss,this.ui=n,this.ui.attach()}subscribe(){const e=N.load(this.storage)||N.create(this.storage),{linkAPIUrl:s}=this,n=new ts({session:e,linkAPIUrl:s,listener:this}),i=this.isMobileWeb?new ye:new us;return n.connect(),{session:e,ui:i,connection:n}}resetAndReload(){this.connection.destroy().then(()=>{const e=N.load(this.storage);(e==null?void 0:e.id)===this._session.id&&v.clearAll(),document.location.reload()}).catch(e=>{})}signEthereumTransaction(e){return this.sendRequest({method:"signEthereumTransaction",params:{fromAddress:e.fromAddress,toAddress:e.toAddress,weiValue:k(e.weiValue),data:O(e.data,!0),nonce:e.nonce,gasPriceInWei:e.gasPriceInWei?k(e.gasPriceInWei):null,maxFeePerGas:e.gasPriceInWei?k(e.gasPriceInWei):null,maxPriorityFeePerGas:e.gasPriceInWei?k(e.gasPriceInWei):null,gasLimit:e.gasLimit?k(e.gasLimit):null,chainId:e.chainId,shouldSubmit:!1}})}signAndSubmitEthereumTransaction(e){return this.sendRequest({method:"signEthereumTransaction",params:{fromAddress:e.fromAddress,toAddress:e.toAddress,weiValue:k(e.weiValue),data:O(e.data,!0),nonce:e.nonce,gasPriceInWei:e.gasPriceInWei?k(e.gasPriceInWei):null,maxFeePerGas:e.maxFeePerGas?k(e.maxFeePerGas):null,maxPriorityFeePerGas:e.maxPriorityFeePerGas?k(e.maxPriorityFeePerGas):null,gasLimit:e.gasLimit?k(e.gasLimit):null,chainId:e.chainId,shouldSubmit:!0}})}submitEthereumTransaction(e,s){return this.sendRequest({method:"submitEthereumTransaction",params:{signedTransaction:O(e,!0),chainId:s}})}getWalletLinkSession(){return this._session}sendRequest(e){let s=null;const n=_(8),i=r=>{this.publishWeb3RequestCanceledEvent(n),this.handleErrorResponse(n,e.method,r),s==null||s()};return new Promise((r,a)=>{s=this.ui.showConnecting({isUnlinkedErrorState:this.isUnlinkedErrorState,onCancel:i,onResetConnection:this.resetAndReload}),this.relayEventManager.callbacks.set(n,o=>{if(s==null||s(),m(o))return a(new Error(o.errorMessage));r(o)}),this.publishWeb3RequestEvent(n,e)})}publishWeb3RequestEvent(e,s){const n={type:"WEB3_REQUEST",id:e,request:s};this.publishEvent("Web3Request",n,!0).then(i=>{}).catch(i=>{this.handleWeb3ResponseMessage(n.id,{method:s.method,errorMessage:i.message})}),this.isMobileWeb&&this.openCoinbaseWalletDeeplink(s.method)}openCoinbaseWalletDeeplink(e){if(this.ui instanceof ye)switch(e){case"requestEthereumAccounts":case"switchEthereumChain":return;default:window.addEventListener("blur",()=>{window.addEventListener("focus",()=>{this.connection.checkUnseenEvents()},{once:!0})},{once:!0}),this.ui.openCoinbaseWalletDeeplink();break}}publishWeb3RequestCanceledEvent(e){const s={type:"WEB3_REQUEST_CANCELED",id:e};this.publishEvent("Web3RequestCanceled",s,!1).then()}publishEvent(e,s,n){return this.connection.publishEvent(e,s,n)}handleWeb3ResponseMessage(e,s){if(s.method==="requestEthereumAccounts"){S.accountRequestCallbackIds.forEach(n=>this.invokeCallback(n,s)),S.accountRequestCallbackIds.clear();return}this.invokeCallback(e,s)}handleErrorResponse(e,s,n){var i;const r=(i=n==null?void 0:n.message)!==null&&i!==void 0?i:"Unspecified error message.";this.handleWeb3ResponseMessage(e,{method:s,errorMessage:r})}invokeCallback(e,s){const n=this.relayEventManager.callbacks.get(e);n&&(n(s),this.relayEventManager.callbacks.delete(e))}requestEthereumAccounts(){const{appName:e,appLogoUrl:s}=this.metadata,n={method:"requestEthereumAccounts",params:{appName:e,appLogoUrl:s}},i=_(8);return new Promise((r,a)=>{this.relayEventManager.callbacks.set(i,o=>{if(m(o))return a(new Error(o.errorMessage));r(o)}),S.accountRequestCallbackIds.add(i),this.publishWeb3RequestEvent(i,n)})}watchAsset(e,s,n,i,r,a){const o={method:"watchAsset",params:{type:e,options:{address:s,symbol:n,decimals:i,image:r},chainId:a}};let c=null;const d=_(8),g=p=>{this.publishWeb3RequestCanceledEvent(d),this.handleErrorResponse(d,o.method,p),c==null||c()};return c=this.ui.showConnecting({isUnlinkedErrorState:this.isUnlinkedErrorState,onCancel:g,onResetConnection:this.resetAndReload}),new Promise((p,f)=>{this.relayEventManager.callbacks.set(d,C=>{if(c==null||c(),m(C))return f(new Error(C.errorMessage));p(C)}),this.publishWeb3RequestEvent(d,o)})}addEthereumChain(e,s,n,i,r,a){const o={method:"addEthereumChain",params:{chainId:e,rpcUrls:s,blockExplorerUrls:i,chainName:r,iconUrls:n,nativeCurrency:a}};let c=null;const d=_(8),g=p=>{this.publishWeb3RequestCanceledEvent(d),this.handleErrorResponse(d,o.method,p),c==null||c()};return c=this.ui.showConnecting({isUnlinkedErrorState:this.isUnlinkedErrorState,onCancel:g,onResetConnection:this.resetAndReload}),new Promise((p,f)=>{this.relayEventManager.callbacks.set(d,C=>{if(c==null||c(),m(C))return f(new Error(C.errorMessage));p(C)}),this.publishWeb3RequestEvent(d,o)})}switchEthereumChain(e,s){const n={method:"switchEthereumChain",params:Object.assign({chainId:e},{address:s})};let i=null;const r=_(8),a=o=>{this.publishWeb3RequestCanceledEvent(r),this.handleErrorResponse(r,n.method,o),i==null||i()};return i=this.ui.showConnecting({isUnlinkedErrorState:this.isUnlinkedErrorState,onCancel:a,onResetConnection:this.resetAndReload}),new Promise((o,c)=>{this.relayEventManager.callbacks.set(r,d=>{if(i==null||i(),m(d)&&d.errorCode)return c(l.provider.custom({code:d.errorCode,message:"Unrecognized chain ID. Try adding the chain using addEthereumChain first."}));if(m(d))return c(new Error(d.errorMessage));o(d)}),this.publishWeb3RequestEvent(r,n)})}}S.accountRequestCallbackIds=new Set;const ve="DefaultChainId",ke="DefaultJsonRpcUrl";class Xe{constructor(e){this._relay=null,this._addresses=[],this.metadata=e.metadata,this._storage=new v("walletlink",be),this.callback=e.callback||null;const s=this._storage.getItem(ee);if(s){const n=s.split(" ");n[0]!==""&&(this._addresses=n.map(i=>x(i)))}this.initializeRelay()}getSession(){const e=this.initializeRelay(),{id:s,secret:n}=e.getWalletLinkSession();return{id:s,secret:n}}async handshake(){await this._eth_requestAccounts()}get selectedAddress(){return this._addresses[0]||void 0}get jsonRpcUrl(){var e;return(e=this._storage.getItem(ke))!==null&&e!==void 0?e:void 0}set jsonRpcUrl(e){this._storage.setItem(ke,e)}updateProviderInfo(e,s){var n;this.jsonRpcUrl=e;const i=this.getChainId();this._storage.setItem(ve,s.toString(10)),j(s)!==i&&((n=this.callback)===null||n===void 0||n.call(this,"chainChanged",A(s)))}async watchAsset(e){const s=Array.isArray(e)?e[0]:e;if(!s.type)throw l.rpc.invalidParams("Type is required");if((s==null?void 0:s.type)!=="ERC20")throw l.rpc.invalidParams(`Asset of type '${s.type}' is not supported`);if(!(s!=null&&s.options))throw l.rpc.invalidParams("Options are required");if(!(s!=null&&s.options.address))throw l.rpc.invalidParams("Address is required");const n=this.getChainId(),{address:i,symbol:r,image:a,decimals:o}=s.options,d=await this.initializeRelay().watchAsset(s.type,i,r,o,a,n==null?void 0:n.toString());return m(d)?!1:!!d.result}async addEthereumChain(e){var s,n;const i=e[0];if(((s=i.rpcUrls)===null||s===void 0?void 0:s.length)===0)throw l.rpc.invalidParams("please pass in at least 1 rpcUrl");if(!i.chainName||i.chainName.trim()==="")throw l.rpc.invalidParams("chainName is a required field");if(!i.nativeCurrency)throw l.rpc.invalidParams("nativeCurrency is a required field");const r=Number.parseInt(i.chainId,16);if(r===this.getChainId())return!1;const a=this.initializeRelay(),{rpcUrls:o=[],blockExplorerUrls:c=[],chainName:d,iconUrls:g=[],nativeCurrency:p}=i,f=await a.addEthereumChain(r.toString(),o,g,c,d,p);if(m(f))return!1;if(((n=f.result)===null||n===void 0?void 0:n.isApproved)===!0)return this.updateProviderInfo(o[0],r),null;throw l.rpc.internal("unable to add ethereum chain")}async switchEthereumChain(e){const s=e[0],n=Number.parseInt(s.chainId,16),r=await this.initializeRelay().switchEthereumChain(n.toString(10),this.selectedAddress||void 0);if(m(r))throw r;const a=r.result;return a.isApproved&&a.rpcUrl.length>0&&this.updateProviderInfo(a.rpcUrl,n),null}async cleanup(){this.callback=null,this._relay&&this._relay.resetAndReload(),this._storage.clear()}_setAddresses(e,s){var n;if(!Array.isArray(e))throw new Error("addresses is not an array");const i=e.map(r=>x(r));JSON.stringify(i)!==JSON.stringify(this._addresses)&&(this._addresses=i,(n=this.callback)===null||n===void 0||n.call(this,"accountsChanged",i),this._storage.setItem(ee,i.join(" ")))}async request(e){const s=e.params||[];switch(e.method){case"eth_accounts":return[...this._addresses];case"eth_coinbase":return this.selectedAddress||null;case"net_version":return this.getChainId().toString(10);case"eth_chainId":return A(this.getChainId());case"eth_requestAccounts":return this._eth_requestAccounts();case"eth_ecRecover":case"personal_ecRecover":return this.ecRecover(e);case"personal_sign":return this.personalSign(e);case"eth_signTransaction":return this._eth_signTransaction(s);case"eth_sendRawTransaction":return this._eth_sendRawTransaction(s);case"eth_sendTransaction":return this._eth_sendTransaction(s);case"eth_signTypedData_v1":case"eth_signTypedData_v3":case"eth_signTypedData_v4":case"eth_signTypedData":return this.signTypedData(e);case"wallet_addEthereumChain":return this.addEthereumChain(s);case"wallet_switchEthereumChain":return this.switchEthereumChain(s);case"wallet_watchAsset":return this.watchAsset(s);default:if(!this.jsonRpcUrl)throw l.rpc.internal("No RPC URL set for chain");return je(e,this.jsonRpcUrl)}}_ensureKnownAddress(e){const s=x(e);if(!this._addresses.map(i=>x(i)).includes(s))throw new Error("Unknown Ethereum address")}_prepareTransactionParams(e){const s=e.from?x(e.from):this.selectedAddress;if(!s)throw new Error("Ethereum address is unavailable");this._ensureKnownAddress(s);const n=e.to?x(e.to):null,i=e.value!=null?D(e.value):BigInt(0),r=e.data?X(e.data):Buffer.alloc(0),a=e.nonce!=null?j(e.nonce):null,o=e.gasPrice!=null?D(e.gasPrice):null,c=e.maxFeePerGas!=null?D(e.maxFeePerGas):null,d=e.maxPriorityFeePerGas!=null?D(e.maxPriorityFeePerGas):null,g=e.gas!=null?D(e.gas):null,p=e.chainId?j(e.chainId):this.getChainId();return{fromAddress:s,toAddress:n,weiValue:i,data:r,nonce:a,gasPriceInWei:o,maxFeePerGas:c,maxPriorityFeePerGas:d,gasLimit:g,chainId:p}}async ecRecover(e){const{method:s,params:n}=e;if(!Array.isArray(n))throw l.rpc.invalidParams();const r=await this.initializeRelay().sendRequest({method:"ethereumAddressFromSignedMessage",params:{message:z(n[0]),signature:z(n[1]),addPrefix:s==="personal_ecRecover"}});if(m(r))throw r;return r.result}getChainId(){var e;return Number.parseInt((e=this._storage.getItem(ve))!==null&&e!==void 0?e:"1",10)}async _eth_requestAccounts(){var e,s;if(this._addresses.length>0)return(e=this.callback)===null||e===void 0||e.call(this,"connect",{chainId:A(this.getChainId())}),this._addresses;const i=await this.initializeRelay().requestEthereumAccounts();if(m(i))throw i;if(!i.result)throw new Error("accounts received is empty");return this._setAddresses(i.result),(s=this.callback)===null||s===void 0||s.call(this,"connect",{chainId:A(this.getChainId())}),this._addresses}async personalSign({params:e}){if(!Array.isArray(e))throw l.rpc.invalidParams();const s=e[1],n=e[0];this._ensureKnownAddress(s);const r=await this.initializeRelay().sendRequest({method:"signEthereumMessage",params:{address:x(s),message:z(n),addPrefix:!0,typedDataJson:null}});if(m(r))throw r;return r.result}async _eth_signTransaction(e){const s=this._prepareTransactionParams(e[0]||{}),i=await this.initializeRelay().signEthereumTransaction(s);if(m(i))throw i;return i.result}async _eth_sendRawTransaction(e){const s=X(e[0]),i=await this.initializeRelay().submitEthereumTransaction(s,this.getChainId());if(m(i))throw i;return i.result}async _eth_sendTransaction(e){const s=this._prepareTransactionParams(e[0]||{}),i=await this.initializeRelay().signAndSubmitEthereumTransaction(s);if(m(i))throw i;return i.result}async signTypedData(e){const{method:s,params:n}=e;if(!Array.isArray(n))throw l.rpc.invalidParams();const i=d=>{const g={eth_signTypedData_v1:q.hashForSignTypedDataLegacy,eth_signTypedData_v3:q.hashForSignTypedData_v3,eth_signTypedData_v4:q.hashForSignTypedData_v4,eth_signTypedData:q.hashForSignTypedData_v4};return O(g[s]({data:vt(d)}),!0)},r=n[s==="eth_signTypedData_v1"?1:0],a=n[s==="eth_signTypedData_v1"?0:1];this._ensureKnownAddress(r);const c=await this.initializeRelay().sendRequest({method:"signEthereumMessage",params:{address:x(r),message:i(a),typedDataJson:JSON.stringify(a,null,2),addPrefix:!1}});if(m(c))throw c;return c.result}initializeRelay(){return this._relay||(this._relay=new S({linkAPIUrl:be,storage:this._storage,metadata:this.metadata,accountsCallback:this._setAddresses.bind(this),chainCallback:this.updateProviderInfo.bind(this)})),this._relay}}const et="SignerType",tt=new v("CBWSDK","SignerConfigurator");function bs(){return tt.getItem(et)}function ys(t){tt.setItem(et,t)}async function vs(t){const{communicator:e,metadata:s,handshakeRequest:n,callback:i}=t;Es(e,s,i).catch(()=>{});const r={id:crypto.randomUUID(),event:"selectSignerType",data:Object.assign(Object.assign({},t.preference),{handshakeRequest:n})},{data:a}=await e.postRequestAndWaitForResponse(r);return a}function ks(t){const{signerType:e,metadata:s,communicator:n,callback:i}=t;switch(e){case"scw":return new Nt({metadata:s,callback:i,communicator:n});case"walletlink":return new Xe({metadata:s,callback:i})}}async function Es(t,e,s){await t.onMessage(({event:i})=>i==="WalletLinkSessionRequest");const n=new Xe({metadata:e,callback:s});t.postMessage({event:"WalletLinkUpdate",data:{session:n.getSession()}}),await n.handshake(),t.postMessage({event:"WalletLinkUpdate",data:{connected:!0}})}const Cs=`Coinbase Wallet SDK requires the Cross-Origin-Opener-Policy header to not be set to 'same-origin'. This is to ensure that the SDK can communicate with the Coinbase Smart Wallet app.
Please see https://www.smartwallet.dev/guides/tips/popup-tips#cross-origin-opener-policy for more information.`,Is=()=>{let t;return{getCrossOriginOpenerPolicy:()=>t===void 0?"undefined":t,checkCrossOriginOpenerPolicy:async()=>{if(typeof window>"u"){t="non-browser-env";return}try{const e=`${window.location.origin}${window.location.pathname}`,s=await fetch(e,{method:"HEAD"});if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);const n=s.headers.get("Cross-Origin-Opener-Policy");t=n??"null",t==="same-origin"&&console.error(Cs)}catch(e){console.error("Error checking Cross-Origin-Opener-Policy:",e.message),t="error"}}}},{checkCrossOriginOpenerPolicy:st,getCrossOriginOpenerPolicy:Ss}=Is(),Ee=420,Ce=540;function Ms(t){const e=(window.innerWidth-Ee)/2+window.screenX,s=(window.innerHeight-Ce)/2+window.screenY;As(t);const n=window.open(t,"Smart Wallet",`width=${Ee}, height=${Ce}, left=${e}, top=${s}`);if(n==null||n.focus(),!n)throw l.rpc.internal("Pop up window failed to open");return n}function xs(t){t&&!t.closed&&t.close()}function As(t){const e={sdkName:Oe,sdkVersion:T,origin:window.location.origin,coop:Ss()};for(const[s,n]of Object.entries(e))t.searchParams.append(s,n.toString())}class _s{constructor({url:e=ms,metadata:s,preference:n}){this.popup=null,this.listeners=new Map,this.postMessage=async i=>{(await this.waitForPopupLoaded()).postMessage(i,this.url.origin)},this.postRequestAndWaitForResponse=async i=>{const r=this.onMessage(({requestId:a})=>a===i.id);return this.postMessage(i),await r},this.onMessage=async i=>new Promise((r,a)=>{const o=c=>{if(c.origin!==this.url.origin)return;const d=c.data;i(d)&&(r(d),window.removeEventListener("message",o),this.listeners.delete(o))};window.addEventListener("message",o),this.listeners.set(o,{reject:a})}),this.disconnect=()=>{xs(this.popup),this.popup=null,this.listeners.forEach(({reject:i},r)=>{i(l.provider.userRejectedRequest("Request rejected")),window.removeEventListener("message",r)}),this.listeners.clear()},this.waitForPopupLoaded=async()=>this.popup&&!this.popup.closed?(this.popup.focus(),this.popup):(this.popup=Ms(this.url),this.onMessage(({event:i})=>i==="PopupUnload").then(this.disconnect).catch(()=>{}),this.onMessage(({event:i})=>i==="PopupLoaded").then(i=>{this.postMessage({requestId:i.id,data:{version:T,metadata:this.metadata,preference:this.preference,location:window.location.toString()}})}).then(()=>{if(!this.popup)throw l.rpc.internal();return this.popup})),this.url=new URL(e),this.metadata=s,this.preference=n}}function Ls(t){const e=gt(Ps(t),{shouldIncludeStack:!0}),s=new URL("https://docs.cloud.coinbase.com/wallet-sdk/docs/errors");return s.searchParams.set("version",T),s.searchParams.set("code",e.code.toString()),s.searchParams.set("message",e.message),Object.assign(Object.assign({},e),{docUrl:s.href})}function Ps(t){var e;if(typeof t=="string")return{message:t,code:u.rpc.internal};if(m(t)){const s=t.errorMessage,n=(e=t.errorCode)!==null&&e!==void 0?e:s.match(/(denied|rejected)/i)?u.provider.userRejectedRequest:void 0;return Object.assign(Object.assign({},t),{message:s,code:n,data:{method:t.method}})}return t}class Rs extends lt{}var Ns=function(t,e){var s={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(s[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(s[n[i]]=t[n[i]]);return s};class nt extends Rs{constructor(e){var{metadata:s}=e,n=e.preference,{keysUrl:i}=n,r=Ns(n,["keysUrl"]);super(),this.signer=null,this.isCoinbaseWallet=!0,this.metadata=s,this.preference=r,this.communicator=new _s({url:i,metadata:s,preference:r});const a=bs();a&&(this.signer=this.initSigner(a))}async request(e){try{if(Rt(e),!this.signer)switch(e.method){case"eth_requestAccounts":{const s=await this.requestSignerSelection(e),n=this.initSigner(s);await n.handshake(e),this.signer=n,ys(s);break}case"net_version":return 1;case"eth_chainId":return A(1);default:throw l.provider.unauthorized("Must call 'eth_requestAccounts' before other methods")}return this.signer.request(e)}catch(s){const{code:n}=s;return n===u.provider.unauthorized&&this.disconnect(),Promise.reject(Ls(s))}}async enable(){return console.warn('.enable() has been deprecated. Please use .request({ method: "eth_requestAccounts" }) instead.'),await this.request({method:"eth_requestAccounts"})}async disconnect(){var e;await((e=this.signer)===null||e===void 0?void 0:e.cleanup()),this.signer=null,v.clearAll(),this.emit("disconnect",l.provider.disconnected("User initiated disconnection"))}requestSignerSelection(e){return vs({communicator:this.communicator,preference:this.preference,metadata:this.metadata,handshakeRequest:e,callback:this.emit.bind(this)})}initSigner(e){return ks({signerType:e,metadata:this.metadata,communicator:this.communicator,callback:this.emit.bind(this)})}}function it(t){if(t){if(!["all","smartWalletOnly","eoaOnly"].includes(t.options))throw new Error(`Invalid options: ${t.options}`);if(t.attribution&&t.attribution.auto!==void 0&&t.attribution.dataSuffix!==void 0)throw new Error("Attribution cannot contain both auto and dataSuffix properties")}}class Us{constructor(e){this.metadata={appName:e.appName||"Dapp",appLogoUrl:e.appLogoUrl||Et(),appChainIds:e.appChainIds||[]},this.storeLatestVersion(),st()}makeWeb3Provider(e={options:"all"}){var s;it(e);const n={metadata:this.metadata,preference:e};return(s=Ue(n))!==null&&s!==void 0?s:new nt(n)}getCoinbaseWalletLogo(e,s=240){return ut(e,s)}storeLatestVersion(){new v("CBWSDK").setItem("VERSION",T)}}function Ts(t){var e;const s={metadata:t.metadata,preference:t.preference};return(e=Ue(s))!==null&&e!==void 0?e:new nt(s)}const Ds={options:"all"};function Ws(t){var e;new v("CBWSDK").setItem("VERSION",T),st();const n={metadata:{appName:t.appName||"Dapp",appLogoUrl:t.appLogoUrl||"",appChainIds:t.appChainIds||[]},preference:Object.assign(Ds,(e=t.preference)!==null&&e!==void 0?e:{})};it(n.preference);let i=null;return{getProvider:()=>(i||(i=Ts(n)),i)}}export{Us as CoinbaseWalletSDK,Ws as createCoinbaseWalletSDK,Us as default};