@tronweb3/tronwallet-adapter-okxwallet
Version:
Wallet adapter for Okx Wallet extension and Okx Wallet app.
1 lines • 50.4 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self)["@tronweb3/tronwallet-adapter-okxwallet"]=e()}(this,(function(){"use strict";function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e,n={},o={},r={},i={},s={exports:{}};var a,c,l={},d={};function u(){if(a)return d;a=1,Object.defineProperty(d,"__esModule",{value:!0}),d.WalletSignTypedDataError=d.WalletGetNetworkError=d.WalletSwitchChainError=d.WalletWindowClosedError=d.WalletWalletLoadError=d.WalletSignTransactionError=d.WalletSignMessageError=d.WalletDisconnectionError=d.WalletConnectionError=d.WalletDisconnectedError=d.WalletNotSelectedError=d.WalletNotFoundError=d.WalletError=void 0;class t extends Error{constructor(t,e){super(t),this.error=e}}d.WalletError=t;d.WalletNotFoundError=class extends t{constructor(t,e){super(t||"The wallet is not found.",e),this.name="WalletNotFoundError"}};d.WalletNotSelectedError=class extends t{constructor(){super(...arguments),this.name="WalletNotSelectedError",this.message="No wallet is selected. Please select a wallet."}};d.WalletDisconnectedError=class extends t{constructor(){super(...arguments),this.name="WalletDisconnectedError",this.message="The wallet is disconnected. Please connect first."}};d.WalletConnectionError=class extends t{constructor(){super(...arguments),this.name="WalletConnectionError"}};d.WalletDisconnectionError=class extends t{constructor(){super(...arguments),this.name="WalletDisconnectionError"}};d.WalletSignMessageError=class extends t{constructor(){super(...arguments),this.name="WalletSignMessageError"}};d.WalletSignTransactionError=class extends t{constructor(){super(...arguments),this.name="WalletSignTransactionError"}};d.WalletWalletLoadError=class extends t{constructor(){super(...arguments),this.name="WalletWalletLoadError"}};d.WalletWindowClosedError=class extends t{constructor(t,e){super(t||"The QR window is closed.",e),this.name="WalletWindowClosedError"}};d.WalletSwitchChainError=class extends t{constructor(){super(...arguments),this.name="WalletSwitchChainError"}};d.WalletGetNetworkError=class extends t{constructor(){super(...arguments),this.name="WalletGetNetworkError"}};return d.WalletSignTypedDataError=class extends t{constructor(){super(...arguments),this.name="WalletSignTypedDataError"}},d}function h(){if(c)return l;c=1,Object.defineProperty(l,"__esModule",{value:!0}),l.normalizeAndValidateTypedData=function(n){if(!e(n))throw new t.WalletSignTypedDataError("typedData must be an object.");if(!e(n.domain))throw new t.WalletSignTypedDataError("typedData.domain must be an object.");if(!e(n.types))throw new t.WalletSignTypedDataError("typedData.types must be an object.");if(!e(n.message))throw new t.WalletSignTypedDataError("typedData.message must be an object.");const{chainId:o}=n.domain;if("string"==typeof o){const e=Number(o);if(!Number.isFinite(e))throw new t.WalletSignTypedDataError(`Invalid domain.chainId: ${o}.`);return Object.assign(Object.assign({},n),{domain:Object.assign(Object.assign({},n.domain),{chainId:e})})}return n};const t=u();function e(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}return l}var p,f,y={};function w(){return p||(p=1,Object.defineProperty(y,"__esModule",{value:!0}),y.TIP6963RequestProviderEventName=y.TIP6963AnnounceProviderEventName=y.ChainNetwork=y.NetworkType=y.AdapterState=y.WalletReadyState=void 0,function(t){t.Loading="Loading",t.NotFound="NotFound",t.Found="Found"}(t||(y.WalletReadyState=t={})),function(t){t.Loading="Loading",t.NotFound="NotFound",t.Disconnect="Disconnected",t.Connected="Connected"}(e||(y.AdapterState=e={})),function(t){t.Mainnet="Mainnet",t.Shasta="Shasta",t.Nile="Nile",t.Unknown="Unknown"}(n||(y.NetworkType=n={})),function(t){t.Mainnet="Mainnet",t.Shasta="Shasta",t.Nile="Nile"}(o||(y.ChainNetwork=o={})),y.TIP6963AnnounceProviderEventName="TIP6963:announceProvider",y.TIP6963RequestProviderEventName="TIP6963:requestProvider"),y;var t,e,n,o}function A(){if(f)return i;f=1;var t=i&&i.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(i,"__esModule",{value:!0}),i.Adapter=i.EventEmitter=void 0;const n=t((e||(e=1,function(t){var e=Object.prototype.hasOwnProperty,n="~";function o(){}function r(t,e,n){this.fn=t,this.context=e,this.once=n||!1}function i(t,e,o,i,s){if("function"!=typeof o)throw new TypeError("The listener must be a function");var a=new r(o,i||t,s),c=n?n+e:e;return t._events[c]?t._events[c].fn?t._events[c]=[t._events[c],a]:t._events[c].push(a):(t._events[c]=a,t._eventsCount++),t}function s(t,e){0==--t._eventsCount?t._events=new o:delete t._events[e]}function a(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(n=!1)),a.prototype.eventNames=function(){var t,o,r=[];if(0===this._eventsCount)return r;for(o in t=this._events)e.call(t,o)&&r.push(n?o.slice(1):o);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(t)):r},a.prototype.listeners=function(t){var e=n?n+t:t,o=this._events[e];if(!o)return[];if(o.fn)return[o.fn];for(var r=0,i=o.length,s=new Array(i);r<i;r++)s[r]=o[r].fn;return s},a.prototype.listenerCount=function(t){var e=n?n+t:t,o=this._events[e];return o?o.fn?1:o.length:0},a.prototype.emit=function(t,e,o,r,i,s){var a=n?n+t:t;if(!this._events[a])return!1;var c,l,d=this._events[a],u=arguments.length;if(d.fn){switch(d.once&&this.removeListener(t,d.fn,void 0,!0),u){case 1:return d.fn.call(d.context),!0;case 2:return d.fn.call(d.context,e),!0;case 3:return d.fn.call(d.context,e,o),!0;case 4:return d.fn.call(d.context,e,o,r),!0;case 5:return d.fn.call(d.context,e,o,r,i),!0;case 6:return d.fn.call(d.context,e,o,r,i,s),!0}for(l=1,c=new Array(u-1);l<u;l++)c[l-1]=arguments[l];d.fn.apply(d.context,c)}else{var h,p=d.length;for(l=0;l<p;l++)switch(d[l].once&&this.removeListener(t,d[l].fn,void 0,!0),u){case 1:d[l].fn.call(d[l].context);break;case 2:d[l].fn.call(d[l].context,e);break;case 3:d[l].fn.call(d[l].context,e,o);break;case 4:d[l].fn.call(d[l].context,e,o,r);break;default:if(!c)for(h=1,c=new Array(u-1);h<u;h++)c[h-1]=arguments[h];d[l].fn.apply(d[l].context,c)}}return!0},a.prototype.on=function(t,e,n){return i(this,t,e,n,!1)},a.prototype.once=function(t,e,n){return i(this,t,e,n,!0)},a.prototype.removeListener=function(t,e,o,r){var i=n?n+t:t;if(!this._events[i])return this;if(!e)return s(this,i),this;var a=this._events[i];if(a.fn)a.fn!==e||r&&!a.once||o&&a.context!==o||s(this,i);else{for(var c=0,l=[],d=a.length;c<d;c++)(a[c].fn!==e||r&&!a[c].once||o&&a[c].context!==o)&&l.push(a[c]);l.length?this._events[i]=1===l.length?l[0]:l:s(this,i)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=n?n+t:t,this._events[e]&&s(this,e)):(this._events=new o,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,t.exports=a}(s)),s.exports));i.EventEmitter=n.default;const o=h(),r=w();class a extends n.default{get connected(){return this.state===r.AdapterState.Connected}disconnect(){return console.info("The current adapter doesn't support disconnect by DApp."),Promise.resolve()}multiSign(t,e={}){return Promise.reject("The current wallet doesn't support multiSign.")}signTypedData(t){let e;try{e=(0,o.normalizeAndValidateTypedData)(t)}catch(t){return Promise.reject(t)}return this._signTypedData(e)}_signTypedData(t){return Promise.reject("The current wallet doesn't support signTypedData.")}switchChain(t){return Promise.reject("The current wallet doesn't support switch chain.")}}return i.Adapter=a,i}var g,M={};function v(){if(g)return M;function t(){return"undefined"!=typeof window&&"undefined"!=typeof document&&"undefined"!=typeof navigator}return g=1,Object.defineProperty(M,"__esModule",{value:!0}),M.isInBrowser=t,M.checkAdapterState=function(e){if(!t())return;const n=[];function o(){for(const t of n)t()}function r(){e()&&o()}const i=setInterval(r,500);n.push((()=>clearInterval(i))),"loading"===document.readyState&&(document.addEventListener("DOMContentLoaded",r,{once:!0}),n.push((()=>document.removeEventListener("DOMContentLoaded",r))));"complete"!==document.readyState&&(window.addEventListener("load",r,{once:!0}),n.push((()=>window.removeEventListener("load",r))));r(),setTimeout(o,6e4)},M.isInMobileBrowser=function(){return"undefined"!=typeof navigator&&navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i)},M}var N,I,T,m={},S={};function j(){return N||(N=1,function(t){var e=S&&S.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))};function n(t){return!!t&&"object"==typeof t&&"string"==typeof t.title&&t.title.length>0&&(1===t.noticeType||2===t.noticeType||3===t.noticeType)}function o(t){const e={title:t.title,noticeType:t.noticeType};return"string"==typeof t.ext&&(e.ext=t.ext),"string"==typeof t.ios&&(e.ios=t.ios),"string"==typeof t.and&&(e.and=t.and),e}function r(t){const e=t&&"object"==typeof t?t:{},r={};if(e.wallets&&"object"==typeof e.wallets)for(const[t,i]of Object.entries(e.wallets)){if(!Array.isArray(i)){console.warn(`[WalletAdapter] Ignoring malformed risks for "${t}": expected an array, got ${typeof i}.`);continue}const e=[];for(const r of i)n(r)?e.push(o(r)):console.warn(`[WalletAdapter] Dropping malformed risk entry for "${t}":`,r);e.length>0&&(r[t]=e)}return{v:"string"==typeof e.v?e.v:"",ts:"number"==typeof e.ts?e.ts:0,wallets:r}}Object.defineProperty(t,"__esModule",{value:!0}),t.defaultSecurityOptions=void 0,t.clearCache=function(){Object.keys(i).forEach((t=>{Reflect.deleteProperty(i,t)}))},t.fetchJsonWithCache=function(n){return e(this,void 0,void 0,(function*(){const{configUrls:o=t.defaultSecurityOptions.configUrls,timeout:s=t.defaultSecurityOptions.timeout,retries:a=t.defaultSecurityOptions.retries,onConfigFallback:c,cacheTTL:l=t.defaultSecurityOptions.cacheTTL}=n,d=Date.now();const u=(yield Promise.all(o.map((function(t){return e(this,void 0,void 0,(function*(){const n=i[t];if(n&&d-n.timestamp<l)return n.data;function o(){return e(this,void 0,void 0,(function*(){return new Promise(((e,n)=>{const o=new AbortController,i=setTimeout((()=>o.abort()),s);fetch(t,{signal:o.signal}).then((t=>{clearTimeout(i),t.ok?t.json().then((t=>e(r(t))),n):n(new Error("Fetch failed with code: "+t.status))})).catch((t=>{clearTimeout(i),n(t)}))}))}))}for(let e=0;e<=a;e++)try{const e=yield o();return i[t]={data:e,timestamp:Date.now()},e}catch(n){console.warn(`[WalletAdapter] Fetch attempt ${e+1} for ${t} failed:`,n)}return null}))})))).filter((t=>null!==t));return u.length>0?u.reduce(((t,e)=>{var n;e.ts>t.ts&&(t.v=e.v,t.ts=e.ts);for(const[o,r]of Object.entries(e.wallets))t.wallets[o]=[...null!==(n=t.wallets[o])&&void 0!==n?n:[],...r];return t}),{v:"",ts:0,wallets:{}}):c?r(yield c()):{v:"",ts:0,wallets:{}}}))},t.defaultSecurityOptions={onRiskDetected:t=>e(void 0,void 0,void 0,(function*(){console.log("[WalletAdapter] Risk detected:",t)})),configUrls:[],enabled:!1,timeout:2e3,retries:0,cacheTTL:6e5};const i={}}(S)),S}function D(){if(I)return m;I=1;var t=m&&m.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))};Object.defineProperty(m,"__esModule",{value:!0}),m.AddonAdapter=void 0;const e=A(),n=u(),o=j(),r=w(),i=v();class s extends e.Adapter{constructor(t){if(super(),this.commonConfig={checkTimeout:2e3,openAppWithDeeplink:!0,openUrlWhenWalletNotFound:!0,securityOptions:o.defaultSecurityOptions},this._securityCheckCache=null,this.commonConfig=Object.assign(Object.assign({},this.commonConfig),t),"number"!=typeof this.commonConfig.checkTimeout)throw new Error("[WalletAdapter] config.checkTimeout should be a number");s._validateSecurityOptions(this.commonConfig.securityOptions)}static _validateSecurityOptions(t){const{enabled:e,configUrls:n}=t;if(e&&(!n||0===n.length))throw new Error("[WalletAdapter] config.securityOptions.configUrls is required when securityOptions.enabled is true")}updateSecurityOptions(t){const e=Object.assign(Object.assign({},this.commonConfig.securityOptions),t);s._validateSecurityOptions(e),this.commonConfig.securityOptions=e,this._securityCheckCache=null}_beforeConnect(){return t(this,void 0,void 0,(function*(){if(this.connected||this.connecting)return!1;if(yield this._checkWallet(),this.readyState===r.WalletReadyState.NotFound)throw(0,i.isInBrowser)()&&!this._openAppByDeepLinkIfNeed()&&!1!==this.commonConfig.openUrlWhenWalletNotFound&&window.open(this.url,"_blank"),new n.WalletNotFoundError;return yield this.checkSecurity(),!0}))}checkSecurity(){return t(this,void 0,void 0,(function*(){if(!this.commonConfig.securityOptions.enabled)return;const e=this._securityCheckCache;if(e&&(null===e.settledAt||Date.now()-e.settledAt<s.SECURITY_CHECK_CACHE_TTL))return e.promise;const n=(()=>t(this,void 0,void 0,(function*(){const t=(yield(0,o.fetchJsonWithCache)(this.commonConfig.securityOptions)).wallets[this.name];if(t&&t.length>0){const e=this.commonConfig.securityOptions.onRiskDetected||o.defaultSecurityOptions.onRiskDetected;yield e({risks:t})}})))(),r={promise:n,settledAt:null};return this._securityCheckCache=r,n.finally((()=>{this._securityCheckCache===r&&(r.settledAt=Date.now())})).catch((()=>{})),n}))}}return m.AddonAdapter=s,s.SECURITY_CHECK_CACHE_TTL=5e3,m}function k(){return T||(T=1,t=r,e=r&&r.__createBinding||(Object.create?function(t,e,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(e,n);r&&!("get"in r?!e.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,o,r)}:function(t,e,n,o){void 0===o&&(o=n),t[o]=e[n]}),n=r&&r.__exportStar||function(t,n){for(var o in t)"default"===o||Object.prototype.hasOwnProperty.call(n,o)||e(n,t,o)},Object.defineProperty(t,"__esModule",{value:!0}),n(A(),t),n(u(),t),n(w(),t),n(h(),t),n(v(),t),n(D(),t),n(j(),t)),r;var t,e,n}var W,E,C={},O={},b={};function L(){if(W)return b;W=1;var t=b&&b.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))};Object.defineProperty(b,"__esModule",{value:!0}),b.supportTron=n,b.supportTronLink=o,b.isInTronLinkApp=r,b.openTronLink=function({dappIcon:t,dappName:n}={dappIcon:"",dappName:""}){if(!o()&&(0,e.isInMobileBrowser)()&&!r()){let e="",o="";try{e=document.title;const t=document.querySelector('link[rel*="icon"]');t&&(o=new URL(t.getAttribute("href")||"",location.href).toString())}catch(t){}const{origin:r,pathname:i,search:s,hash:a}=window.location,c=r+i+s+(a.includes("?")?a:`${a}?_=1`),l={action:"open",actionId:Date.now()+"",callbackUrl:"http://someurl.com",dappIcon:t||o,dappName:n||e,url:c,protocol:"TronLink",version:"1.0",chainId:"0x2b6653dc"};return window.location.href=`tronlinkoutside://pull.activity?param=${encodeURIComponent(JSON.stringify(l))}`,!0}return!1},b.waitTronwebReady=function(e){return t(this,void 0,void 0,(function*(){return new Promise(((t,n)=>{const o=setInterval((()=>{e.tronWeb&&(clearInterval(o),clearTimeout(r),t())}),50),r=setTimeout((()=>{clearInterval(o),n("`window.tron.tronweb` is not ready.")}),2e3)}))}))};const e=k();function n(){return(0,e.isInBrowser)()&&!(!window.tron||!window.tron.isTronLink)}function o(){return(0,e.isInBrowser)()&&!!(n()||window.tronLink||window.tronWeb)}function r(){return(0,e.isInBrowser)()&&void 0!==window.iTron}return b}function z(){return E||(E=1,function(t){var e=O&&O.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.TronLinkAdapter=t.TronLinkAdapterName=t.chainIdNetworkMap=void 0,t.getNetworkInfoByTronWeb=r;const n=k(),o=L();function r(o){return e(this,void 0,void 0,(function*(){var e,r,i;const{blockID:s=""}=yield o.trx.getBlockByNumber(0),a=`0x${s.slice(-8)}`;return{networkType:t.chainIdNetworkMap[a]||n.NetworkType.Unknown,chainId:a,fullNode:(null===(e=o.fullNode)||void 0===e?void 0:e.host)||"",solidityNode:(null===(r=o.solidityNode)||void 0===r?void 0:r.host)||"",eventServer:(null===(i=o.eventServer)||void 0===i?void 0:i.host)||""}}))}t.chainIdNetworkMap={"0x2b6653dc":n.NetworkType.Mainnet,"0x94a9059e":n.NetworkType.Shasta,"0xcd8690dc":n.NetworkType.Nile},t.TronLinkAdapterName="TronLink";class i extends n.AddonAdapter{constructor(r={}){super(r),this.name=t.TronLinkAdapterName,this.url="https://www.tronlink.org/",this.icon="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAF0AAABdCAYAAADHcWrDAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAUGVYSWZNTQAqAAAACAACARIAAwAAAAEAAQAAh2kABAAAAAEAAAAmAAAAAAADoAEAAwAAAAEAAQAAoAIABAAAAAEAAABdoAMABAAAAAEAAABdAAAAAMkTBfIAAAFZaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJYTVAgQ29yZSA2LjAuMCI+CiAgIDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53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2M5CT8oGmmw3IMjURZsWh3h/3pGbas3OKXE5hJy4lMs8s1WESwbAMOejwdUoaIVaR/nt6JKK1GoVAQDEF61lG4+Ks2GPRgQbId3InZl7cxQBeWLJ70ZYzHUYdigs4WHPX4txA9L8qfs34UfM7J2B6NFVmDxLB6i92q0KkLtfcPhX0vSqq3H6geC/98RHg/VwL0MW8e/hjvVy/Xim34CVG+21h+ePawjAk4HDG1byFN4q+r/dQH74aaDGOtFvnw4wC+2BJzo8db/XnJc1Njr7EMua7DuJAdXXXTrq8fI2lpUyPvz8LSjjXLjCEXHIw8Ft8eu65sqmTkjok4K+AvNnyZH0Xsb+eO/wWrg46Do/7gYAAAAABJRU5ErkJggg==",this._readyState=(0,n.isInBrowser)()?n.WalletReadyState.Loading:n.WalletReadyState.NotFound,this._state=(0,n.isInBrowser)()?n.AdapterState.Loading:n.AdapterState.NotFound,this._supportNewTronProtocol=!1,this._onChainChanged=t=>{this.emit("chainChanged",t)},this._onAccountsChanged=()=>{var t,e,o;const r=this.address||"",i=(null===(t=this._wallet)||void 0===t?void 0:t.tronWeb)&&(null===(o=null===(e=this._wallet)||void 0===e?void 0:e.tronWeb.defaultAddress)||void 0===o?void 0:o.base58)||"";this.setAddress(i||null),this.setState(this.address?n.AdapterState.Connected:n.AdapterState.Disconnect),this.emit("accountsChanged",this.address||"",r),!r&&this.address?this.emit("connect",this.address):r&&!this.address&&this.emit("disconnect")},this._checkPromise=null,this._updateWallet=()=>e(this,void 0,void 0,(function*(){var t,e,o,r,i,s,a,c;this._supportNewTronProtocol=!1;let l=this.state,d=this.address;if((0,n.isInMobileBrowser)())if(window.tronLink?this._wallet=window.tronLink:this._wallet={ready:!!(null===(t=window.tronWeb)||void 0===t?void 0:t.defaultAddress),tronWeb:window.tronWeb,request:()=>Promise.resolve(!0)},d=(null===(o=null===(e=this._wallet.tronWeb)||void 0===e?void 0:e.defaultAddress)||void 0===o?void 0:o.base58)||null,d){try{yield this.checkSecurity()}catch(t){return this.setAddress(null),void this.setState(n.AdapterState.Disconnect)}l=n.AdapterState.Connected}else l=n.AdapterState.Disconnect;else if(this.isLegacyTronLinkProvider(window.tron)){this._supportNewTronProtocol=!0,this._wallet=window.tron,this._listenTronEvent();try{d=(null===(r=this._wallet)||void 0===r?void 0:r.tronWeb)&&(null===(s=null===(i=this._wallet.tronWeb)||void 0===i?void 0:i.defaultAddress)||void 0===s?void 0:s.base58)||null,l=d?n.AdapterState.Connected:n.AdapterState.Disconnect}catch(t){return console.error("Unknown error: "+t," Please install TronLink extension wallet."),d=null,l=n.AdapterState.Disconnect,this._readyState=n.WalletReadyState.NotFound,void this.emit("readyStateChanged",this.readyState)}}else window.tronLink?(this._wallet=window.tronLink,d=(null===(c=null===(a=this._wallet.tronWeb)||void 0===a?void 0:a.defaultAddress)||void 0===c?void 0:c.base58)||null,l=this._wallet.ready?n.AdapterState.Connected:n.AdapterState.Disconnect):(this._wallet=null,d=null,l=n.AdapterState.NotFound);(0,n.isInMobileBrowser)()&&l===n.AdapterState.Disconnect&&this.checkForWalletReadyForApp(),this.setAddress(d),this.setState(l)})),this.checkReadyInterval=null;const{checkTimeout:i=5e3,dappIcon:s="",dappName:a="",openUrlWhenWalletNotFound:c=!0,openTronLinkAppOnMobile:l=!0,openAppWithDeeplink:d=!0}=r;if("number"!=typeof i)throw new Error("[TronLinkAdapter] config.checkTimeout should be a number");if(this.config=Object.assign(Object.assign({},this.commonConfig),{checkTimeout:i,openTronLinkAppOnMobile:l,openAppWithDeeplink:d,openUrlWhenWalletNotFound:c,dappIcon:s,dappName:a}),this._connecting=!1,this._wallet=null,this._address=null,!(0,n.isInBrowser)())return this._readyState=n.WalletReadyState.NotFound,void this.setState(n.AdapterState.NotFound);(0,n.isInMobileBrowser)()&&((0,o.supportTron)()||(0,n.isInMobileBrowser)()&&(window.tronLink||window.tronWeb))?(this._readyState=n.WalletReadyState.Found,this._updateWallet().then((()=>{this.connected&&this.emit("connect",this.address||"")}))):this._checkWallet().then((()=>{this.connected&&this.emit("connect",this.address||"")}))}get address(){return this._address}get state(){return this._state}get readyState(){return this._readyState}get connecting(){return this._connecting}network(){return e(this,void 0,void 0,(function*(){var t;try{if(yield this._checkWallet(),this.state!==n.AdapterState.Connected)throw new n.WalletDisconnectedError;const e=(null===(t=this._wallet)||void 0===t?void 0:t.tronWeb)||window.tronWeb;if(!e)throw new n.WalletDisconnectedError;try{return yield r(e)}catch(t){throw new n.WalletGetNetworkError(null==t?void 0:t.message,t)}}catch(t){throw this.emit("error",t),t}}))}connect(){return e(this,void 0,void 0,(function*(){var t,e;try{if(!(yield this._beforeConnect()))return;if(!this._wallet)return;if(this._connecting=!0,this._supportNewTronProtocol){const t=this._wallet;try{const e=(yield t.request({method:"eth_requestAccounts"}))[0];this.setAddress(e),this.setState(n.AdapterState.Connected),this._listenTronEvent(),this._wallet.tronWeb||(yield(0,o.waitTronwebReady)(this._wallet))}catch(t){let e=(null==t?void 0:t.message)||t||"Connect TronLink wallet failed.";throw-32002===t.code&&(e="The same DApp has already initiated a request to connect to TronLink wallet, and the pop-up window has not been closed."),4001===t.code&&(e="The user rejected connection."),new n.WalletConnectionError(e,t)}}else if(window.tronLink){const e=this._wallet,o=yield e.request({method:"tron_requestAccounts"});if(!o)throw new n.WalletConnectionError("TronLink wallet is locked or no wallet account is avaliable.");if(4e3===o.code)throw new n.WalletConnectionError("The same DApp has already initiated a request to connect to TronLink wallet, and the pop-up window has not been closed.");if(4001===o.code)throw new n.WalletConnectionError("The user rejected connection.");const r=(null===(t=e.tronWeb.defaultAddress)||void 0===t?void 0:t.base58)||"";this.setAddress(r),this.setState(n.AdapterState.Connected)}else{if(!window.tronWeb)throw new n.WalletConnectionError("Cannot connect wallet.");{const t=(null===(e=this._wallet.tronWeb.defaultAddress)||void 0===e?void 0:e.base58)||"";this.setAddress(t),this.setState(n.AdapterState.Connected)}}this.connected&&this.emit("connect",this.address||"")}catch(t){const e=t instanceof n.WalletError?t:new n.WalletConnectionError(null==t?void 0:t.message,t);throw this.emit("error",e),e}finally{this._connecting=!1}}))}disconnect(){return e(this,void 0,void 0,(function*(){this._supportNewTronProtocol&&this._stopListenTronEvent(),this.state===n.AdapterState.Connected&&(this.setAddress(null),this.setState(n.AdapterState.Disconnect),this.emit("disconnect"))}))}_checkAndSign(t,n){return e(this,void 0,void 0,(function*(){try{const e=yield this.checkAndGetWallet();try{return yield t(e)}catch(t){throw t instanceof Error||"object"==typeof t&&t.message?new n(t.message,t):"string"==typeof t?new n(t,new Error(t)):new n("Unknown error",t)}}catch(t){throw this.emit("error",t),t}}))}signTransaction(t){return e(this,void 0,void 0,(function*(){return this._checkAndSign((e=>e.tronWeb.trx.sign(t)),n.WalletSignTransactionError)}))}multiSign(t){return e(this,arguments,void 0,(function*(t,e={}){return this._checkAndSign((n=>n.tronWeb.trx.multiSign(t,void 0,e.permissionId)),n.WalletSignTransactionError)}))}signMessage(t){return e(this,void 0,void 0,(function*(){return this._checkAndSign((n=>e(this,void 0,void 0,(function*(){return n.tronWeb.trx.signMessageV2(t)}))),n.WalletSignMessageError)}))}_signTypedData(t){return e(this,void 0,void 0,(function*(){return this._checkAndSign((n=>e(this,void 0,void 0,(function*(){return n.tronWeb.trx._signTypedData(t.domain,t.types,t.message)}))),n.WalletSignTypedDataError)}))}switchChain(t){return e(this,void 0,void 0,(function*(){try{if(yield this._checkWallet(),this.state===n.AdapterState.NotFound)throw!1!==this.config.openUrlWhenWalletNotFound&&(0,n.isInBrowser)()&&window.open(this.url,"_blank"),new n.WalletNotFoundError;if(!this._supportNewTronProtocol)throw new n.WalletSwitchChainError("Current version of TronLink doesn't support switch chain operation.");const e=this._wallet;try{yield e.request({method:"wallet_switchEthereumChain",params:[{chainId:t}]})}catch(t){throw new n.WalletSwitchChainError((null==t?void 0:t.message)||t,t instanceof Error?t:new Error(t))}}catch(t){throw this.emit("error",t),t}}))}checkAndGetWallet(){return e(this,void 0,void 0,(function*(){if(this._openAppByDeepLinkIfNeed())throw new n.WalletNotFoundError;if(yield this._checkWallet(),this.state!==n.AdapterState.Connected)throw new n.WalletDisconnectedError;const t=this._wallet;if(!t||!t.tronWeb)throw new n.WalletDisconnectedError;return t}))}_openAppByDeepLinkIfNeed(){if(!1===this.config.openAppWithDeeplink||!1===this.config.openTronLinkAppOnMobile)return!1;const{dappName:t="",dappIcon:e=""}=this.config;return(0,o.openTronLink)({dappIcon:e,dappName:t})}_listenTronEvent(){var t,e;this._stopListenTronEvent();const n=this._wallet;null===(t=n.on)||void 0===t||t.call(n,"chainChanged",this._onChainChanged),null===(e=n.on)||void 0===e||e.call(n,"accountsChanged",this._onAccountsChanged)}_stopListenTronEvent(){var t,e;const n=this._wallet;null===(t=n.removeListener)||void 0===t||t.call(n,"chainChanged",this._onChainChanged),null===(e=n.removeListener)||void 0===e||e.call(n,"accountsChanged",this._onAccountsChanged)}isLegacyTronLinkProvider(t){return!!(null==t?void 0:t.isTronLink)}hasDesktopLegacyTronLinkProvider(){return this.isLegacyTronLinkProvider(window.tron)||!!window.tronLink}_checkWallet(){if(this.readyState===n.WalletReadyState.Found)return Promise.resolve(!0);if(this._checkPromise)return this._checkPromise;if((0,n.isInBrowser)()&&!(0,n.isInMobileBrowser)())return this._checkPromise=new Promise((t=>{let o=!1,r=null,i=null;const s=()=>{r&&(clearTimeout(r),r=null),"undefined"!=typeof window&&i&&window.removeEventListener(n.TIP6963AnnounceProviderEventName,i)};r=setTimeout((()=>{if(o)return;if(o=!0,s(),"undefined"==typeof window)return void t(!1);this._updateWallet();const e=this.state!==n.AdapterState.NotFound;this._readyState=e?n.WalletReadyState.Found:n.WalletReadyState.NotFound,this.emit("readyStateChanged",this._readyState),t(e)}),this.config.checkTimeout),i=r=>e(this,void 0,void 0,(function*(){var e,i;if(o)return;const{info:a,provider:c}=r.detail;if("TronLink"===a.name){o=!0,this._supportNewTronProtocol=!0,this._wallet=c;try{yield this.checkSecurity()}catch(e){return this.setAddress(null),this.setState(n.AdapterState.Disconnect),this._readyState=n.WalletReadyState.Found,this.emit("readyStateChanged",this.readyState),void t(!0)}this._listenTronEvent(),this._readyState=n.WalletReadyState.Found;const r=(null===(e=this._wallet)||void 0===e?void 0:e.tronWeb)&&(null===(i=this._wallet.tronWeb.defaultAddress)||void 0===i?void 0:i.base58)||null,a=r?n.AdapterState.Connected:n.AdapterState.Disconnect;this.setAddress(r),this.setState(a),this.emit("readyStateChanged",this.readyState),s(),t(!0)}})),window.addEventListener(n.TIP6963AnnounceProviderEventName,i),window.dispatchEvent(new Event(n.TIP6963RequestProviderEventName))})),this._checkPromise;const t=Math.floor(this.config.checkTimeout/100);let o,r=0;return this._checkPromise=new Promise((e=>{const i=()=>{r++,this._updateWallet();const i=!(!(0,n.isInMobileBrowser)()||!window.tronLink&&!window.tronWeb);(i||r>t)&&(o&&clearInterval(o),this._readyState=i?n.WalletReadyState.Found:n.WalletReadyState.NotFound,this.emit("readyStateChanged",this.readyState),e(i))};o=setInterval(i,100),i()})),this._checkPromise}checkForWalletReadyForApp(){if(this.checkReadyInterval)return;let t=0;const e=Math.floor(this.config.checkTimeout/200);this.checkReadyInterval=setInterval((()=>{var n,o;(window.tronLink?null===(n=window.tronLink.tronWeb)||void 0===n?void 0:n.defaultAddress:null===(o=window.tronWeb)||void 0===o?void 0:o.defaultAddress)?(this.checkReadyInterval&&clearInterval(this.checkReadyInterval),this.checkReadyInterval=null,this._updateWallet(),this.emit("connect",this.address||"")):t>e?(this.checkReadyInterval&&clearInterval(this.checkReadyInterval),this.checkReadyInterval=null):t++}),200)}setAddress(t){this._address=t}setState(t){t!==this.state&&(this._state=t,this.emit("stateChanged",t))}}t.TronLinkAdapter=i}(O)),O}var x,_,P={};function Q(){return _||(_=1,t=C,e=C&&C.__createBinding||(Object.create?function(t,e,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(e,n);r&&!("get"in r?!e.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,o,r)}:function(t,e,n,o){void 0===o&&(o=n),t[o]=e[n]}),n=C&&C.__exportStar||function(t,n){for(var o in t)"default"===o||Object.prototype.hasOwnProperty.call(n,o)||e(n,t,o)},Object.defineProperty(t,"__esModule",{value:!0}),n(z(),t),n((x||(x=1,Object.defineProperty(P,"__esModule",{value:!0})),P),t),n(L(),t)),C;var t,e,n}var U,R,Y,F,B,G,H={};function q(){if(U)return H;U=1,Object.defineProperty(H,"__esModule",{value:!0}),H.isOKApp=void 0,H.supportOkxWallet=function(){return!(!window.okxwallet||!window.okxwallet.tronLink)},H.isInOKApp=e,H.openOkxWallet=function(){if(!e()&&(0,t.isInMobileBrowser)())return window.location.href="okx://wallet/dapp/url?dappUrl="+encodeURIComponent(window.location.href),!0;return!1};const t=k();function e(){return"undefined"!=typeof window&&void 0!==window.navigator&&/OKApp/i.test(window.navigator.userAgent)}return H.isOKApp="undefined"!=typeof navigator&&/OKApp/i.test(navigator.userAgent),H}function Z(){return R||(R=1,function(t){var e=o&&o.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.OkxWalletAdapter=t.OkxWalletAdapterName=void 0;const n=k(),r=Q(),i=q();t.OkxWalletAdapterName="OKX Wallet";class s extends n.AddonAdapter{constructor(o={}){if(super(o),this.name=t.OkxWalletAdapterName,this.url="https://okx.com",this.icon="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAiIGhlaWdodD0iNDAiIHZpZXdCb3g9IjAgMCA0MCA0MCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjQwIiBoZWlnaHQ9IjQwIiByeD0iOCIgZmlsbD0iYmxhY2siLz4KPHBhdGggZD0iTTIzLjU1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VIMzEuNzYwNEMzMi4wNjI1IDMyLjMwNDUgMzIuMzA3NCAzMi4wNTk2IDMyLjMwNzQgMzEuNzU3NVYyNC42NDY2QzMyLjMwNzQgMjQuMzQ0NSAzMi4wNjI1IDI0LjA5OTYgMzEuNzYwNCAyNC4wOTk2WiIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTI0LjY0OTUgMjQuNTk5NkgzMS43NjA0QzMxLjc4NjQgMjQuNTk5NiAzMS44MDc0IDI0LjYyMDYgMzEuODA3NCAyNC42NDY2VjMxLjc1NzVDMzEuODA3NCAzMS43ODM0IDMxLjc4NjQgMzEuODA0NSAzMS43NjA0IDMxLjgwNDVIMjQuNjQ5NUMyNC42MjM2IDMxLjgwNDUgMjQuNjAyNSAzMS43ODM0IDI0LjYwMjUgMzEuNzU3NVYyNC42NDY2QzI0LjYwMjUgMjQuNjIwNiAyNC42MjM2IDI0LjU5OTYgMjQuNjQ5NSAyNC41OTk2WiIgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLW9wYWNpdHk9IjAuMTUiLz4KPC9zdmc+Cg==",this._readyState=(0,n.isInBrowser)()?n.WalletReadyState.Loading:n.WalletReadyState.NotFound,this._state=n.AdapterState.Loading,this.messageHandler=t=>e(this,void 0,void 0,(function*(){var o,r,i;const s=null===(o=t.data)||void 0===o?void 0:o.message;if(s)if("accountsChanged"===s.action)setTimeout((()=>e(this,void 0,void 0,(function*(){var t;const e=this.address||"";if(null===(t=this._wallet)||void 0===t?void 0:t.ready){try{yield this.checkSecurity()}catch(t){return this.setAddress(null),void this.setState(n.AdapterState.Disconnect)}const t=s.data.address;this.setAddress(t),this.setState(n.AdapterState.Connected)}else this.setAddress(null),this.setState(n.AdapterState.Disconnect);(this.address||"")!==e&&this.emit("accountsChanged",this.address||"",e),!e&&this.address?this.emit("connect",this.address):e&&!this.address&&this.emit("disconnect")}))),200);else if("connect"===s.action){const t=this.connected,e=this.address||"";try{yield this.checkSecurity()}catch(t){return this.setAddress(null),void this.setState(n.AdapterState.Disconnect)}const o=(null===(i=null===(r=this._wallet.tronWeb)||void 0===r?void 0:r.defaultAddress)||void 0===i?void 0:i.base58)||"";this.setAddress(o),this.setState(n.AdapterState.Connected),t?o!==e&&this.emit("accountsChanged",this.address||"",e):this.emit("connect",o)}else"disconnect"===s.action&&(this.setAddress(null),this.setState(n.AdapterState.Disconnect),this.emit("disconnect"))})),this._checkPromise=null,this._updateWallet=()=>e(this,void 0,void 0,(function*(){var t,e;let o=this.state,r=this.address;if((0,i.supportOkxWallet)())if(this._wallet=window.okxwallet.tronLink,this._listenEvent(),r=(null===(e=null===(t=this._wallet.tronWeb)||void 0===t?void 0:t.defaultAddress)||void 0===e?void 0:e.base58)||null,r){try{yield this.checkSecurity()}catch(t){return this.setAddress(null),void this.setState(n.AdapterState.Disconnect)}o=n.AdapterState.Connected}else o=n.AdapterState.Disconnect;else this._wallet=null,r=null,o=n.AdapterState.NotFound;this.setAddress(r),this.setState(o)})),this.config=Object.assign({},this.commonConfig),this._connecting=!1,this._wallet=null,this._address=null,!(0,n.isInBrowser)())return this._readyState=n.WalletReadyState.NotFound,void this.setState(n.AdapterState.NotFound);(0,i.supportOkxWallet)()?(this._readyState=n.WalletReadyState.Found,this._updateWallet().then((()=>{this.connected&&this.emit("connect",this.address||"")}))):this._checkWallet().then((()=>{this.connected&&this.emit("connect",this.address||"")}))}get address(){return this._address}get state(){return this._state}get readyState(){return this._readyState}get connecting(){return this._connecting}network(){return e(this,void 0,void 0,(function*(){try{if(yield this._checkWallet(),this.state!==n.AdapterState.Connected)throw new n.WalletDisconnectedError;const t=this._wallet;if(!t||!t.tronWeb)throw new n.WalletDisconnectedError;try{return yield(0,r.getNetworkInfoByTronWeb)(t.tronWeb)}catch(t){throw new n.WalletGetNetworkError(null==t?void 0:t.message,t)}}catch(t){throw this.emit("error",t),t}}))}connect(){return e(this,void 0,void 0,(function*(){var t;try{if(!(yield this._beforeConnect()))return;if(!this._wallet)return;this._connecting=!0;const e=this._wallet,o=yield e.request({method:"tron_requestAccounts"});if(!o)throw new n.WalletConnectionError("Request connect error.");if(4e3===o.code)throw new n.WalletConnectionError("The same DApp has already initiated a request to connect to OkxWallet, and the pop-up window has not been closed.");if(4001===o.code)throw new n.WalletConnectionError("The user rejected connection.");const r=(null===(t=e.tronWeb.defaultAddress)||void 0===t?void 0:t.base58)||"";this.setAddress(r),this.setState(n.AdapterState.Connected),this._listenEvent(),this.connected&&this.emit("connect",this.address||"")}catch(t){const e=t instanceof n.WalletError?t:new n.WalletConnectionError(null==t?void 0:t.message,t);throw this.emit("error",e),e}finally{this._connecting=!1}}))}disconnect(){return e(this,void 0,void 0,(function*(){this._stopListenEvent(),this.state===n.AdapterState.Connected&&(this.setAddress(null),this.setState(n.AdapterState.Disconnect),this.emit("disconnect"))}))}signTransaction(t){return e(this,void 0,void 0,(function*(){try{const e=yield this.checkAndGetWallet();try{return yield e.tronWeb.trx.sign(t)}catch(t){throw t instanceof Error||"object"==typeof t&&t.message?new n.WalletSignTransactionError(t.message,t):"string"==typeof t?new n.WalletSignTransactionError(t,new Error(t)):new n.WalletSignTransactionError("Unknown error",t)}}catch(t){throw this.emit("error",t),t}}))}multiSign(t){return e(this,arguments,void 0,(function*(t,e={}){try{const o=yield this.checkAndGetWallet();try{return yield o.tronWeb.trx.multiSign(t,void 0,e.permissionId)}catch(t){throw t instanceof Error||"object"==typeof t&&t.message?new n.WalletSignTransactionError(t.message,t):"string"==typeof t?new n.WalletSignTransactionError(t,new Error(t)):new n.WalletSignTransactionError("Unknown error",t)}}catch(t){throw this.emit("error",t),t}}))}signMessage(t){return e(this,void 0,void 0,(function*(){try{const e=yield this.checkAndGetWallet();try{return yield e.tronWeb.trx.signMessageV2(t)}catch(t){throw t instanceof Error||"object"==typeof t&&t.message?new n.WalletSignMessageError(t.message,t):"string"==typeof t?new n.WalletSignMessageError(t,new Error(t)):new n.WalletSignMessageError("Unknown error",t)}}catch(t){throw this.emit("error",t),t}}))}checkAndGetWallet(){return e(this,void 0,void 0,(function*(){if(this.checkIfOpenOkxWallet(),yield this._checkWallet(),this.state!==n.AdapterState.Connected)throw new n.WalletDisconnectedError;const t=this._wallet;if(!t||!t.tronWeb)throw new n.WalletDisconnectedError;return t}))}_listenEvent(){this._stopListenEvent(),window.addEventListener("message",this.messageHandler)}_stopListenEvent(){window.removeEventListener("message",this.messageHandler)}checkIfOpenOkxWallet(){if(!1!==this.config.openAppWithDeeplink&&(0,i.openOkxWallet)())throw new n.WalletNotFoundError}_openAppByDeepLinkIfNeed(){return!1!==this.config.openAppWithDeeplink&&(0,i.openOkxWallet)()}_checkWallet(){if(this.readyState===n.WalletReadyState.Found)return Promise.resolve(!0);if(this._checkPromise)return this._checkPromise;const t=Math.floor(this.config.checkTimeout/100);let o,r=0;return this._checkPromise=new Promise((s=>{const a=()=>e(this,void 0,void 0,(function*(){r++;const e=(0,i.supportOkxWallet)();(e||r>t)&&(o&&clearInterval(o),this._readyState=e?n.WalletReadyState.Found:n.WalletReadyState.NotFound,yield this._updateWallet(),this.emit("readyStateChanged",this.readyState),s(e))}));o=setInterval(a,100),a()})),this._checkPromise}setAddress(t){this._address=t}setState(t){t!==this.state&&(this._state=t,this.emit("stateChanged",t))}}t.OkxWalletAdapter=s}(o)),o}return t((Y||(Y=1,F=n,B=n&&n.__createBinding||(Object.create?function(t,e,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(e,n);r&&!(