@tronweb3/tronwallet-adapter-trust 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !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-trust"]=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,w={};function v(){return p||(p=1,Object.defineProperty(w,"__esModule",{value:!0}),w.TIP6963RequestProviderEventName=w.TIP6963AnnounceProviderEventName=w.ChainNetwork=w.NetworkType=w.AdapterState=w.WalletReadyState=void 0,function(t){t.Loading="Loading",t.NotFound="NotFound",t.Found="Found"}(t||(w.WalletReadyState=t={})),function(t){t.Loading="Loading",t.NotFound="NotFound",t.Disconnect="Disconnected",t.Connected="Connected"}(e||(w.AdapterState=e={})),function(t){t.Mainnet="Mainnet",t.Shasta="Shasta",t.Nile="Nile",t.Unknown="Unknown"}(n||(w.NetworkType=n={})),function(t){t.Mainnet="Mainnet",t.Shasta="Shasta",t.Nile="Nile"}(o||(w.ChainNetwork=o={})),w.TIP6963AnnounceProviderEventName="TIP6963:announceProvider",w.TIP6963RequestProviderEventName="TIP6963:requestProvider"),w;var t,e,n,o}function y(){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=v();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 A,g={};function m(){if(A)return g;function t(){return"undefined"!=typeof window&&"undefined"!=typeof document&&"undefined"!=typeof navigator}return A=1,Object.defineProperty(g,"__esModule",{value:!0}),g.isInBrowser=t,g.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)},g.isInMobileBrowser=function(){return"undefined"!=typeof navigator&&navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i)},g}var W,b,S,k={},I={};function T(){return W||(W=1,function(t){var e=I&&I.__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={}}(I)),I}function C(){if(b)return k;b=1;var t=k&&k.__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(k,"__esModule",{value:!0}),k.AddonAdapter=void 0;const e=y(),n=u(),o=T(),r=v(),i=m();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 k.AddonAdapter=s,s.SECURITY_CHECK_CACHE_TTL=5e3,k}function E(){return S||(S=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(y(),t),n(u(),t),n(v(),t),n(h(),t),n(m(),t),n(C(),t),n(T(),t)),r;var t,e,n}var N,O,_={},D={},j={};function P(){if(N)return j;N=1;var t=j&&j.__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(j,"__esModule",{value:!0}),j.supportTron=n,j.supportTronLink=o,j.isInTronLinkApp=r,j.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},j.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=E();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 j}function L(){return O||(O=1,function(t){var e=D&&D.__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=E(),o=P();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+CiAgI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QEJhW9uI5n2laql36zE5T6/IXJi7Nu3H1CsO0r4OmmY2M5CT8oGmmw3IMjURZsWh3h/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}(D)),D}var x,M,R={};function F(){return M||(M=1,t=_,e=_&&_.__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=_&&_.__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(L(),t),n((x||(x=1,Object.defineProperty(R,"__esModule",{value:!0})),R),t),n(P(),t)),_;var t,e,n}var B,G,q,z,U,H,Z={};function Q(){return B||(B=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.isTrustApp=void 0,t.supportTrust=function(){return"undefined"!=typeof window&&!(!window.trustwallet||!window.trustwallet.tronLink)},t.openTrustWallet=function(){if(!(0,t.isTrustApp)()&&(0,e.isInMobileBrowser)())return window.location.href="https://link.trustwallet.com/open_url?url="+encodeURIComponent(window.location.href),!0;return!1};const e=E();t.isTrustApp=function(){return"undefined"!=typeof window&&void 0!==window.navigator&&/Trust/i.test(window.navigator.userAgent)}}(Z)),Z}function Y(){return G||(G=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.TrustAdapter=t.TrustAdapterName=void 0;const n=E(),r=F(),i=Q();t.TrustAdapterName="Trust";class s extends n.AddonAdapter{constructor(o={}){if(super(o),this.name=t.TrustAdapterName,this.url="https://trustwallet.com",this.icon="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTgiIGhlaWdodD0iNjUiIHZpZXdCb3g9IjAgMCA1OCA2NSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTAgOS4zODk0OUwyOC44OTA3IDBWNjUuMDA0MkM4LjI1NDUgNTYuMzM2OSAwIDM5LjcyNDggMCAzMC4zMzUzVjkuMzg5NDlaIiBmaWxsPSIjMDUwMEZGIi8+CjxwYXRoIGQ9Ik01Ny43ODIyIDkuMzg5NDlMMjguODkxNSAwVjY1LjAwNDJDNDkuNTI3NyA1Ni4zMzY5IDU3Ljc4MjIgMzkuNzI0OCA1Ny43ODIyIDMwLjMzNTNWOS4zODk0OVoiIGZpbGw9InVybCgjcGFpbnQwX2xpbmVhcl8yMjAxXzY5NDIpIi8+CjxkZWZzPgo8bGluZWFyR3JhZGllbnQgaWQ9InBhaW50MF9saW5lYXJfMjIwMV82OTQyIiB4MT0iNTEuMzYxNSIgeTE9Ii00LjE1MjkzIiB4Mj0iMjkuNTM4NCIgeTI9IjY0LjUxNDciIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIj4KPHN0b3Agb2Zmc2V0PSIwLjAyMTEyIiBzdG9wLWNvbG9yPSIjMDAwMEZGIi8+CjxzdG9wIG9mZnNldD0iMC4wNzYyNDIzIiBzdG9wLWNvbG9yPSIjMDA5NEZGIi8+CjxzdG9wIG9mZnNldD0iMC4xNjMwODkiIHN0b3AtY29sb3I9IiM0OEZGOTEiLz4KPHN0b3Agb2Zmc2V0PSIwLjQyMDA0OSIgc3RvcC1jb2xvcj0iIzAwOTRGRiIvPgo8c3RvcCBvZmZzZXQ9IjAuNjgyODg2IiBzdG9wLWNvbG9yPSIjMDAzOEZGIi8+CjxzdG9wIG9mZnNldD0iMC45MDI0NjUiIHN0b3AtY29sb3I9IiMwNTAwRkYiLz4KPC9saW5lYXJHcmFkaWVudD4KPC9kZWZzPgo8L3N2Zz4K",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||"",o=(null===(i=null===(r=this._wallet.tronWeb)||void 0===r?void 0:r.defaultAddress)||void 0===i?void 0:i.base58)||"";if(!o)return;try{yield this.checkSecurity()}catch(t){return this.setAddress(null),void this.setState(n.AdapterState.Disconnect)}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.supportTrust)())if(this._wallet=window.trustwallet.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.supportTrust)()?(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 trustwallet, 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.checkIfopenTrustWallet(),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)}checkIfopenTrustWallet(){if(!1!==this.config.openAppWithDeeplink&&(0,i.openTrustWallet)())throw new n.WalletNotFoundError}_openAppByDeepLinkIfNeed(){return!1!==this.config.openAppWithDeeplink&&(0,i.openTrustWallet)()}_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 e,o=0;return this._checkPromise=new Promise((r=>{const s=()=>{o++;const s=(0,i.supportTrust)();(s||o>t)&&(e&&clearInterval(e),this._readyState=s?n.WalletReadyState.Found:n.WalletReadyState.NotFound,this._updateWallet(),this.emit("readyStateChanged",this.readyState),r(s))};e=setInterval(s,100),s()})),this._checkPromise}setAddress(t){this._address=t}setState(t){t!==this.state&&(this._state=t,this.emit("stateChanged",t))}}t.TrustAdapter=s}(o)),o}return t((q||(q=1,z=n,U=n&&n.__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]}),H=n&&n.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||U(e,t,n)},Object.defineProperty(z,"__esModule",{value:!0}),H(Y(),z),H(Q(),z)),n))}));
1
+ !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-trust"]=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(r){if(!e(r))throw new t.WalletSignTypedDataError("typedData must be an object.");if(!e(r.domain))throw new t.WalletSignTypedDataError("typedData.domain must be an object.");if(!e(r.types))throw new t.WalletSignTypedDataError("typedData.types must be an object.");if(!e(r.message))throw new t.WalletSignTypedDataError("typedData.message must be an object.");const{chainId:i}=r.domain;if("string"==typeof i||"number"==typeof i||"bigint"==typeof i){const e=function(e){if("string"==typeof e){const r=e.trim();if(!n.test(r)&&!o.test(r))throw new t.WalletSignTypedDataError(`Invalid domain.chainId: ${e}. Expected a non-negative decimal or 0x-prefixed hex integer.`)}const r=Number(e);if(!Number.isInteger(r))throw new t.WalletSignTypedDataError(`Invalid domain.chainId: ${e}. Expected a non-negative integer.`);if(r<0)throw new t.WalletSignTypedDataError(`Invalid domain.chainId: ${e}. Expected a non-negative integer.`);if(!Number.isSafeInteger(r))throw new t.WalletSignTypedDataError(`domain.chainId ${e} exceeds Number.MAX_SAFE_INTEGER (${Number.MAX_SAFE_INTEGER}) and cannot be represented as a number without losing precision.`);return r}(i);return e===i?r:Object.assign(Object.assign({},r),{domain:Object.assign(Object.assign({},r.domain),{chainId:e})})}return r};const t=u();function e(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}const n=/^[0-9]+$/,o=/^0[xX][0-9a-fA-F]+$/;return l}var f,p,w={};function v(){return f||(f=1,Object.defineProperty(w,"__esModule",{value:!0}),w.TIP6963RequestProviderEventName=w.TIP6963AnnounceProviderEventName=w.ChainNetwork=w.NetworkType=w.AdapterState=w.WalletReadyState=void 0,function(t){t.Loading="Loading",t.NotFound="NotFound",t.Found="Found"}(t||(w.WalletReadyState=t={})),function(t){t.Loading="Loading",t.NotFound="NotFound",t.Disconnect="Disconnected",t.Connected="Connected"}(e||(w.AdapterState=e={})),function(t){t.Mainnet="Mainnet",t.Shasta="Shasta",t.Nile="Nile",t.Unknown="Unknown"}(n||(w.NetworkType=n={})),function(t){t.Mainnet="Mainnet",t.Shasta="Shasta",t.Nile="Nile"}(o||(w.ChainNetwork=o={})),w.TIP6963AnnounceProviderEventName="TIP6963:announceProvider",w.TIP6963RequestProviderEventName="TIP6963:requestProvider"),w;var t,e,n,o}function y(){if(p)return i;p=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,f=d.length;for(l=0;l<f;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=v();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 A,g={};function m(){return A||(A=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.MAX_CHECK_TIMEOUT=void 0,t.validateCheckTimeout=function(e,n="[WalletAdapter]"){if("number"!=typeof e)throw new Error(`${n} config.checkTimeout should be a number`);if(!Number.isFinite(e)||e<0||e>t.MAX_CHECK_TIMEOUT)throw new Error(`${n} config.checkTimeout should be a finite number between 0 and ${t.MAX_CHECK_TIMEOUT}, but got ${e}`)},t.omitUndefined=function(t){return Object.fromEntries(Object.entries(null!=t?t:{}).filter((([,t])=>void 0!==t)))},t.assertConnectAddress=function(t){if(!t)throw new e.WalletConnectionError("Request connect error.");return t},t.isInBrowser=n,t.checkAdapterState=function(t){if(!n())return;const e=[];function o(){for(const t of e)t()}function r(){t()&&o()}const i=setInterval(r,500);e.push((()=>clearInterval(i))),"loading"===document.readyState&&(document.addEventListener("DOMContentLoaded",r,{once:!0}),e.push((()=>document.removeEventListener("DOMContentLoaded",r))));"complete"!==document.readyState&&(window.addEventListener("load",r,{once:!0}),e.push((()=>window.removeEventListener("load",r))));r(),setTimeout(o,6e4)},t.isInMobileBrowser=function(){return"undefined"!=typeof navigator&&navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i)};const e=u();function n(){return"undefined"!=typeof window&&"undefined"!=typeof document&&"undefined"!=typeof navigator}t.MAX_CHECK_TIMEOUT=6e5}(g)),g}var b,W,S,T={},k={};function I(){return b||(b=1,function(t){var e=k&&k.__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.defaultSecurityOptions=void 0,t.validateSecurityOptions=function(t){const{enabled:e,configUrls:s,timeout:a,retries:c,cacheTTL:l,onRiskDetected:d,onConfigFallback:u}=t;if(void 0!==e&&"boolean"!=typeof e)throw new Error("[WalletAdapter] config.securityOptions.enabled should be a boolean, but got "+typeof e);void 0!==s&&function(t){if(!Array.isArray(t))throw new Error("[WalletAdapter] config.securityOptions.configUrls should be an array of URLs, but got "+typeof t);for(const e of t){if("string"!=typeof e||""===e.trim())throw new Error(`[WalletAdapter] config.securityOptions.configUrls should only contain non-empty URL strings, but got ${String(e)}`);const t=i(e);if(t&&"http:"!==t.protocol&&"https:"!==t.protocol)throw new Error(`[WalletAdapter] config.securityOptions.configUrls only supports http(s) URLs, but got ${e}`)}}(s);if(e&&(!s||0===s.length))throw new Error("[WalletAdapter] config.securityOptions.configUrls is required when securityOptions.enabled is true");void 0!==a&&r(a,"timeout",1,n);void 0!==l&&r(l,"cacheTTL",0,Number.MAX_SAFE_INTEGER);if(void 0!==c&&(!Number.isInteger(c)||c<0||c>o))throw new Error(`[WalletAdapter] config.securityOptions.retries should be an integer between 0 and ${o}, but got ${String(c)}`);if(void 0!==d&&"function"!=typeof d)throw new Error("[WalletAdapter] config.securityOptions.onRiskDetected should be a function, but got "+typeof d);if(void 0!==u&&"function"!=typeof u)throw new Error("[WalletAdapter] config.securityOptions.onConfigFallback should be a function, but got "+typeof u)},t.clearCache=function(){Object.keys(l).forEach((t=>{Reflect.deleteProperty(l,t)}))},t.fetchJsonWithCache=function(n){return e(this,void 0,void 0,(function*(){const{configUrls:o=t.defaultSecurityOptions.configUrls,timeout:r=t.defaultSecurityOptions.timeout,retries:i=t.defaultSecurityOptions.retries,onConfigFallback:s,cacheTTL:a=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=l[t];if(n&&d-n.timestamp<a)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()),r);fetch(t,{signal:o.signal}).then((t=>{clearTimeout(i),t.ok?t.json().then((t=>e(c(t))),n):n(new Error("Fetch failed with code: "+t.status))})).catch((t=>{clearTimeout(i),n(t)}))}))}))}for(let e=0;e<=i;e++)try{const e=yield o();return l[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:{}}):s?c(yield s()):{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 n=6e4,o=10;function r(t,e,n,o){if("number"!=typeof t||!Number.isFinite(t)||t<n||t>o)throw new Error(`[WalletAdapter] config.securityOptions.${e} should be a finite number between ${n} and ${o}, but got ${String(t)}`)}function i(t){try{return new URL(t)}catch(t){return null}}function s(t){return!!t&&"object"==typeof t&&"string"==typeof t.title&&t.title.length>0&&(1===t.noticeType||2===t.noticeType||3===t.noticeType)}function a(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 c(t){const e=t&&"object"==typeof t?t:{},n={};if(e.wallets&&"object"==typeof e.wallets)for(const[t,o]of Object.entries(e.wallets)){if(!Array.isArray(o)){console.warn(`[WalletAdapter] Ignoring malformed risks for "${t}": expected an array, got ${typeof o}.`);continue}const e=[];for(const n of o)s(n)?e.push(a(n)):console.warn(`[WalletAdapter] Dropping malformed risk entry for "${t}":`,n);e.length>0&&(n[t]=e)}return{v:"string"==typeof e.v?e.v:"",ts:"number"==typeof e.ts?e.ts:0,wallets:n}}const l={}}(k)),k}function E(){if(W)return T;W=1;var t=T&&T.__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.AddonAdapter=void 0;const e=y(),n=u(),o=I(),r=v(),i=m();class s extends e.Adapter{constructor(t){super(),this.commonConfig={checkTimeout:2e3,openAppWithDeeplink:!0,openUrlWhenWalletNotFound:!0,securityOptions:o.defaultSecurityOptions},this._connectPromise=null,this._securityCheckCache=null,this.commonConfig=Object.assign(Object.assign({},this.commonConfig),(0,i.omitUndefined)(t)),(0,i.validateCheckTimeout)(this.commonConfig.checkTimeout),(0,o.validateSecurityOptions)(this.commonConfig.securityOptions)}updateSecurityOptions(t){const e=Object.assign(Object.assign({},this.commonConfig.securityOptions),t);(0,o.validateSecurityOptions)(e),this.commonConfig.securityOptions=e,this._securityCheckCache=null}connect(e){if(this._connectPromise)return this._connectPromise;const n=(()=>t(this,void 0,void 0,(function*(){return this._connect(e)})))().finally((()=>{this._connectPromise===n&&(this._connectPromise=null)}));return this._connectPromise=n,n}_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 T.AddonAdapter=s,s.SECURITY_CHECK_CACHE_TTL=5e3,T}function C(){return S||(S=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(y(),t),n(u(),t),n(v(),t),n(h(),t),n(m(),t),n(E(),t),n(I(),t)),r;var t,e,n}var _,N,O={},D={},P={};function L(){if(_)return P;_=1;var t=P&&P.__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(P,"__esModule",{value:!0}),P.supportTron=n,P.supportTronLink=o,P.isInTronLinkApp=r,P.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},P.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=C();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 P}function j(){return N||(N=1,function(t){var e=D&&D.__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=C(),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+CiAgIDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+CiAgICAgIDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiCiAgICAgICAgICAgIHhtbG5zOnRpZmY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vdGlmZi8xLjAvIj4KICAgICAgICAgPHRpZmY6T3JpZW50YXRpb24+MTwvdGlmZjpPcmllbnRhdGlvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Chle4QcAABZhSURBVHgB7V0JlBTVuf6runtWllkA2QeYQQRBZHNFxZjw4jFqMEFxCWIS1yOaTeJ76nk5Lyc5CUZNfCoa0BgUxRh3QD2CJs8lELaIgOCw78sszN4z0131vu/W1NDTfbtneqa7Zx5v/nN6prrq1q2q77//ev9bbUgcNHjm/sya7P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i2S4Dc/hL2n7r9LdQ86gqB6KJ1tFpAd6N0+aKpF/rk7Zk5xA8G4rzAKyWLJ3/kXrPZTJf8efJysRueMXyxK5XcE5P9n17MBqQFGIjoiNUCPTJQkJSgwa4CI2Q7+WJmHTEvE7dqwS/x2kH/Pgn65oX22Qw6d5p1mfPwc46r+MuxnU18QL5F4x0kwXQ0Fq+QmjAC1QIJUjHkXTaYyFdh6ehweUN8oKu3uliVhhW8uWzJ+AOhfbYA/firZ1Y3NFqzwJ0PDS+TTp2rahhKc/4xtBzCvXlOHnCymO/2SgTRXeQLf3RTdzx2HKnn0EXGMa9Jwyn2CSMYuKHkxSl/C2/bAnQerHp5cgl+6niGHax7Tsitpl8KDz8xFd8Z9fGF93x5so4un9Rb5Uno6nWU2AdfH5KVHjnSObdZjmBNBZWxLoQGSkvYwS3A8IqSF6GyNRQBOtuULTmvsnTxxB9YVuB6VG1sxW9O4zc1wb24lZrminHsopzRH482lTccc6eszEpEWoDLbmhEdbEPk1p8U5NTxqF5AAxORyUbVWI1PNbQEJhW9uI5n2laql36zE5T6/IXJi7Nu3H1CsO0r4OmmY2M5CT8oGmmw3IMjURZsWh3h/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;let l,d;if(this._supportNewTronProtocol=!1,(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."),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"}),r=(0,n.assertConnectAddress)(null==e?void 0:e[0]);this.setAddress(r),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=(0,n.assertConnectAddress)(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=this._wallet,o=(0,n.assertConnectAddress)(null===(e=t.tronWeb.defaultAddress)||void 0===e?void 0:e.base58);this.setAddress(o),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)()){const t=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))}));return this._checkPromise=t,t.then((e=>{e||this._checkPromise!==t||(this._checkPromise=null)})),t}const t=Math.floor(this.config.checkTimeout/100);let o,r=0;const i=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()}));return this._checkPromise=i,i.then((t=>{t||this._checkPromise!==i||(this._checkPromise=null)})),i}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}(D)),D}var x,M,R={};function G(){return M||(M=1,t=O,e=O&&O.__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=O&&O.__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(j(),t),n((x||(x=1,Object.defineProperty(R,"__esModule",{value:!0})),R),t),n(L(),t)),O;var t,e,n}var F,B,U,q,z,H,Z={};function Q(){return F||(F=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.isTrustApp=void 0,t.supportTrust=function(){return"undefined"!=typeof window&&!(!window.trustwallet||!window.trustwallet.tronLink)},t.openTrustWallet=function(){if(!(0,t.isTrustApp)()&&(0,e.isInMobileBrowser)())return window.location.href="https://link.trustwallet.com/open_url?url="+encodeURIComponent(window.location.href),!0;return!1};const e=C();t.isTrustApp=function(){return"undefined"!=typeof window&&void 0!==window.navigator&&/Trust/i.test(window.navigator.userAgent)}}(Z)),Z}function Y(){return B||(B=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.TrustAdapter=t.TrustAdapterName=void 0;const n=C(),r=G(),i=Q();t.TrustAdapterName="Trust";class s extends n.AddonAdapter{constructor(o={}){if(super(o),this.name=t.TrustAdapterName,this.url="https://trustwallet.com",this.icon="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTgiIGhlaWdodD0iNjUiIHZpZXdCb3g9IjAgMCA1OCA2NSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTAgOS4zODk0OUwyOC44OTA3IDBWNjUuMDA0MkM4LjI1NDUgNTYuMzM2OSAwIDM5LjcyNDggMCAzMC4zMzUzVjkuMzg5NDlaIiBmaWxsPSIjMDUwMEZGIi8+CjxwYXRoIGQ9Ik01Ny43ODIyIDkuMzg5NDlMMjguODkxNSAwVjY1LjAwNDJDNDkuNTI3NyA1Ni4zMzY5IDU3Ljc4MjIgMzkuNzI0OCA1Ny43ODIyIDMwLjMzNTNWOS4zODk0OVoiIGZpbGw9InVybCgjcGFpbnQwX2xpbmVhcl8yMjAxXzY5NDIpIi8+CjxkZWZzPgo8bGluZWFyR3JhZGllbnQgaWQ9InBhaW50MF9saW5lYXJfMjIwMV82OTQyIiB4MT0iNTEuMzYxNSIgeTE9Ii00LjE1MjkzIiB4Mj0iMjkuNTM4NCIgeTI9IjY0LjUxNDciIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIj4KPHN0b3Agb2Zmc2V0PSIwLjAyMTEyIiBzdG9wLWNvbG9yPSIjMDAwMEZGIi8+CjxzdG9wIG9mZnNldD0iMC4wNzYyNDIzIiBzdG9wLWNvbG9yPSIjMDA5NEZGIi8+CjxzdG9wIG9mZnNldD0iMC4xNjMwODkiIHN0b3AtY29sb3I9IiM0OEZGOTEiLz4KPHN0b3Agb2Zmc2V0PSIwLjQyMDA0OSIgc3RvcC1jb2xvcj0iIzAwOTRGRiIvPgo8c3RvcCBvZmZzZXQ9IjAuNjgyODg2IiBzdG9wLWNvbG9yPSIjMDAzOEZGIi8+CjxzdG9wIG9mZnNldD0iMC45MDI0NjUiIHN0b3AtY29sb3I9IiMwNTAwRkYiLz4KPC9saW5lYXJHcmFkaWVudD4KPC9kZWZzPgo8L3N2Zz4K",this._readyState=(0,n.isInBrowser)()?n.WalletReadyState.Loading:n.WalletReadyState.NotFound,this._state=n.AdapterState.Loading,this._accountsChangedTimer=null,this._eventGeneration=0,this.messageHandler=t=>e(this,void 0,void 0,(function*(){var o,r,i,s,a;if(t.origin!==window.location.origin)return;const c=null===(o=t.data)||void 0===o?void 0:o.message;if(c)if("accountsChanged"===c.action){this._accountsChangedTimer&&clearTimeout(this._accountsChangedTimer);const t=this._eventGeneration;this._accountsChangedTimer=setTimeout((()=>e(this,void 0,void 0,(function*(){var e;if(this._accountsChangedTimer=null,t!==this._eventGeneration)return;const o=this.address||"",r=c.data.address||"";if(r&&(null===(e=this._wallet)||void 0===e?void 0:e.ready)){try{yield this.checkSecurity()}catch(e){if(t!==this._eventGeneration)return;return this.setAddress(null),void this.setState(n.AdapterState.Disconnect)}if(t!==this._eventGeneration)return;this.setAddress(r),this.setState(n.AdapterState.Connected)}else this.setAddress(null),this.setState(n.AdapterState.Disconnect);(this.address||"")!==o&&this.emit("accountsChanged",this.address||"",o),!o&&this.address?this.emit("connect",this.address):o&&!this.address&&this.emit("disconnect")}))),200)}else if("connect"===c.action){const t=this._eventGeneration;if(!(null===(i=null===(r=this._wallet.tronWeb)||void 0===r?void 0:r.defaultAddress)||void 0===i?void 0:i.base58))return;try{yield this.checkSecurity()}catch(e){if(t!==this._eventGeneration)return;return this.setAddress(null),void this.setState(n.AdapterState.Disconnect)}if(t!==this._eventGeneration)return;const e=(null===(a=null===(s=this._wallet.tronWeb)||void 0===s?void 0:s.defaultAddress)||void 0===a?void 0:a.base58)||"";if(!e)return;const o=this.connected,c=this.address||"";this.setAddress(e),this.setState(n.AdapterState.Connected),o?e!==c&&this.emit("accountsChanged",this.address||"",c):this.emit("connect",e)}else"disconnect"===c.action&&(this.setAddress(null),this.setState(n.AdapterState.Disconnect),this.emit("disconnect"))})),this._checkPromise=null,this._hasRunInitialDetection=!1,this._updateWallet=()=>e(this,void 0,void 0,(function*(){var t,e;let o,r;if((0,i.supportTrust)())if(this._wallet=window.trustwallet.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.supportTrust)()?(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 trustwallet, and the pop-up window has not been closed.");if(4001===o.code)throw new n.WalletConnectionError("The user rejected connection.");const r=(0,n.assertConnectAddress)(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.checkIfopenTrustWallet(),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(){this._eventGeneration++,this._accountsChangedTimer&&(clearTimeout(this._accountsChangedTimer),this._accountsChangedTimer=null),window.removeEventListener("message",this.messageHandler)}checkIfopenTrustWallet(){if(!1!==this.config.openAppWithDeeplink&&(0,i.openTrustWallet)())throw new n.WalletNotFoundError}_openAppByDeepLinkIfNeed(){return!1!==this.config.openAppWithDeeplink&&(0,i.openTrustWallet)()}_checkWallet(){if(this.readyState===n.WalletReadyState.Found)return Promise.resolve(!0);if(this._checkPromise)return this._checkPromise;const t=this._hasRunInitialDetection?0:Math.floor(this.config.checkTimeout/100);this._hasRunInitialDetection=!0;let e,o=0;const r=new Promise((r=>{const s=()=>{o++;const s=(0,i.supportTrust)();(s||o>t)&&(e&&clearInterval(e),this._readyState=s?n.WalletReadyState.Found:n.WalletReadyState.NotFound,this._updateWallet(),this.emit("readyStateChanged",this.readyState),r(s))};e=setInterval(s,100),s()}));return this._checkPromise=r,r.then((t=>{t||this._checkPromise!==r||(this._checkPromise=null)})),r}setAddress(t){this._address=t}setState(t){t!==this.state&&(this._state=t,this.emit("stateChanged",t))}}t.TrustAdapter=s}(o)),o}return t((U||(U=1,q=n,z=n&&n.__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]}),H=n&&n.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||z(e,t,n)},Object.defineProperty(q,"__esModule",{value:!0}),H(Y(),q),H(Q(),q)),n))}));
package/package.json CHANGED
@@ -1,54 +1,54 @@
1
1
  {
2
- "name": "@tronweb3/tronwallet-adapter-trust",
3
- "version": "1.1.0",
4
- "description": "Wallet adapter for Trust Extension.",
5
- "keywords": [
6
- "TRON",
7
- "TronWeb",
8
- "Trust Wallet"
9
- ],
10
- "author": "tronweb3",
11
- "repository": {
12
- "type": "git",
13
- "url": "https://github.com/tronweb3/tronwallet-adapter"
14
- },
15
- "license": "MIT",
16
- "type": "module",
17
- "sideEffects": false,
18
- "engines": {
19
- "node": ">=16",
20
- "pnpm": ">=7"
21
- },
22
- "main": "./lib/cjs/index.js",
23
- "module": "./lib/esm/index.js",
24
- "types": "./lib/types/index.d.ts",
25
- "exports": {
2
+ "name": "@tronweb3/tronwallet-adapter-trust",
3
+ "version": "1.2.0",
4
+ "description": "Wallet adapter for Trust Extension.",
5
+ "keywords": [
6
+ "TRON",
7
+ "TronWeb",
8
+ "Trust Wallet"
9
+ ],
10
+ "author": "tronweb3",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/tronweb3/tronwallet-adapter"
14
+ },
15
+ "license": "MIT",
16
+ "type": "module",
17
+ "sideEffects": false,
18
+ "engines": {
19
+ "node": ">=16",
20
+ "pnpm": ">=7"
21
+ },
22
+ "main": "./lib/cjs/index.js",
23
+ "module": "./lib/esm/index.js",
26
24
  "types": "./lib/types/index.d.ts",
27
- "import": "./lib/esm/index.js",
28
- "require": "./lib/cjs/index.js"
29
- },
30
- "files": [
31
- "lib",
32
- "src",
33
- "LICENSE"
34
- ],
35
- "publishConfig": {
36
- "access": "public"
37
- },
38
- "dependencies": {
39
- "@tronweb3/tronwallet-abstract-adapter": "^1.2.0",
40
- "@tronweb3/tronwallet-adapter-tronlink": "^1.2.0"
41
- },
42
- "devDependencies": {
43
- "@testing-library/dom": "8.20.1",
44
- "shx": "0.3.4",
45
- "vitest": "3.2.4"
46
- },
47
- "scripts": {
48
- "clean": "shx mkdir -p lib && shx rm -rf lib",
49
- "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
50
- "test": "vitest run",
51
- "test:coverage": "vitest run --coverage",
52
- "build:umd": "node ../../../scripts/build-umd.js"
53
- }
54
- }
25
+ "exports": {
26
+ "types": "./lib/types/index.d.ts",
27
+ "import": "./lib/esm/index.js",
28
+ "require": "./lib/cjs/index.js"
29
+ },
30
+ "files": [
31
+ "lib",
32
+ "src",
33
+ "LICENSE"
34
+ ],
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "clean": "shx mkdir -p lib && shx rm -rf lib",
40
+ "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
41
+ "test": "vitest run",
42
+ "test:coverage": "vitest run --coverage",
43
+ "build:umd": "node ../../../scripts/build-umd.js"
44
+ },
45
+ "dependencies": {
46
+ "@tronweb3/tronwallet-abstract-adapter": "^1.3.0",
47
+ "@tronweb3/tronwallet-adapter-tronlink": "^1.3.0"
48
+ },
49
+ "devDependencies": {
50
+ "@testing-library/dom": "8.20.1",
51
+ "shx": "0.3.4",
52
+ "vitest": "3.2.4"
53
+ }
54
+ }
package/src/adapter.ts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  WalletGetNetworkError,
11
11
  AddonAdapter,
12
12
  WalletError,
13
+ assertConnectAddress,
13
14
  } from '@tronweb3/tronwallet-abstract-adapter';
14
15
  import type {
15
16
  Transaction,
@@ -120,7 +121,7 @@ export class TrustAdapter extends AddonAdapter {
120
121
  }
121
122
  }
122
123
 
123
- async connect(): Promise<void> {
124
+ protected async _connect(): Promise<void> {
124
125
  try {
125
126
  if (!(await this._beforeConnect())) return;
126
127
  if (!this._wallet) return;
@@ -139,7 +140,7 @@ export class TrustAdapter extends AddonAdapter {
139
140
  throw new WalletConnectionError('The user rejected connection.');
140
141
  }
141
142
 
142
- const address = wallet.tronWeb.defaultAddress?.base58 || '';
143
+ const address = assertConnectAddress(wallet.tronWeb.defaultAddress?.base58);
143
144
  this.setAddress(address);
144
145
  this.setState(AdapterState.Connected);
145
146
  this._listenEvent();
@@ -240,28 +241,59 @@ export class TrustAdapter extends AddonAdapter {
240
241
  }
241
242
 
242
243
  private _stopListenEvent() {
244
+ this._eventGeneration++;
245
+ if (this._accountsChangedTimer) {
246
+ clearTimeout(this._accountsChangedTimer);
247
+ this._accountsChangedTimer = null;
248
+ }
243
249
  window.removeEventListener('message', this.messageHandler);
244
250
  }
245
251
 
252
+ private _accountsChangedTimer: ReturnType<typeof setTimeout> | null = null;
253
+ /**
254
+ * Incremented whenever the listening session ends. Deferred `accountsChanged`
255
+ * work and the awaited `connect` handler capture the value before they yield and
256
+ * abandon themselves if it no longer matches, so an event that started before
257
+ * `disconnect()` cannot write state after it.
258
+ */
259
+ private _eventGeneration = 0;
260
+
246
261
  private messageHandler = async (e: TronLinkMessageEvent) => {
262
+ if (e.origin !== window.location.origin) {
263
+ return;
264
+ }
265
+
247
266
  const message = e.data?.message;
248
267
  if (!message) {
249
268
  return;
250
269
  }
251
270
  if (message.action === 'accountsChanged') {
252
- setTimeout(async () => {
271
+ if (this._accountsChangedTimer) {
272
+ clearTimeout(this._accountsChangedTimer);
273
+ }
274
+ const generation = this._eventGeneration;
275
+ this._accountsChangedTimer = setTimeout(async () => {
276
+ this._accountsChangedTimer = null;
277
+ if (generation !== this._eventGeneration) return;
253
278
  const preAddr = this.address || '';
254
- if ((this._wallet as TronLinkWallet)?.ready) {
255
- // Gate the connect transition with the security check.
279
+ const curAddr = (message.data as AccountsChangedEventData).address || '';
280
+ // An empty account is a disconnection, not a connection to the empty
281
+ // address. Going Connected here leaves `connected === true` with no
282
+ // address, and the block below then emits `disconnect` against a state
283
+ // that still says Connected.
284
+ if (curAddr && (this._wallet as TronLinkWallet)?.ready) {
256
285
  try {
257
286
  await this.checkSecurity();
258
287
  } catch {
288
+ if (generation !== this._eventGeneration) return;
259
289
  this.setAddress(null);
260
290
  this.setState(AdapterState.Disconnect);
261
291
  return;
262
292
  }
263
- const address = (message.data as AccountsChangedEventData).address;
264
- this.setAddress(address);
293
+ // `checkSecurity()` was awaited, so the session may have ended while it
294
+ // was pending — re-check before writing any state.
295
+ if (generation !== this._eventGeneration) return;
296
+ this.setAddress(curAddr);
265
297
  this.setState(AdapterState.Connected);
266
298
  } else {
267
299
  this.setAddress(null);
@@ -278,21 +310,31 @@ export class TrustAdapter extends AddonAdapter {
278
310
  }
279
311
  }, 200);
280
312
  } else if (message.action === 'connect') {
281
- const isCurConnected = this.connected;
282
- const preAddress = this.address || '';
283
- const address = (this._wallet as TronLinkWallet).tronWeb?.defaultAddress?.base58 || '';
313
+ const generation = this._eventGeneration;
284
314
  // Trust may post a `connect` message before the address is available;
285
315
  // ignore it so we don't report a connection (and emit connect) with no address.
286
- if (!address) {
316
+ if (!(this._wallet as TronLinkWallet).tronWeb?.defaultAddress?.base58) {
287
317
  return;
288
318
  }
289
319
  try {
290
320
  await this.checkSecurity();
291
321
  } catch {
322
+ // A stale rejection must not tear down a session that has since been
323
+ // re-established, so the generation is honoured on this path too.
324
+ if (generation !== this._eventGeneration) return;
292
325
  this.setAddress(null);
293
326
  this.setState(AdapterState.Disconnect);
294
327
  return;
295
328
  }
329
+ // `checkSecurity()` was awaited, so the session may have ended while it
330
+ // was pending — re-check before writing any state.
331
+ if (generation !== this._eventGeneration) return;
332
+ // Re-read after the await: the account may have changed or been cleared
333
+ // while the check was pending.
334
+ const address = (this._wallet as TronLinkWallet).tronWeb?.defaultAddress?.base58 || '';
335
+ if (!address) return;
336
+ const isCurConnected = this.connected;
337
+ const preAddress = this.address || '';
296
338
  this.setAddress(address);
297
339
  this.setState(AdapterState.Connected);
298
340
  if (!isCurConnected) {
@@ -324,6 +366,11 @@ export class TrustAdapter extends AddonAdapter {
324
366
  }
325
367
 
326
368
  private _checkPromise: Promise<boolean> | null = null;
369
+ /**
370
+ * Detection polls for the full `checkTimeout` only once. Later attempts re-check a
371
+ * single time, so retrying is free when the wallet is genuinely absent.
372
+ */
373
+ private _hasRunInitialDetection = false;
327
374
  /**
328
375
  * check if wallet exists by interval, the promise only resolve when wallet detected or timeout
329
376
  * @returns if trustwallet exists
@@ -336,10 +383,11 @@ export class TrustAdapter extends AddonAdapter {
336
383
  return this._checkPromise;
337
384
  }
338
385
  const interval = 100;
339
- const maxTimes = Math.floor(this.config.checkTimeout / interval);
386
+ const maxTimes = this._hasRunInitialDetection ? 0 : Math.floor(this.config.checkTimeout / interval);
387
+ this._hasRunInitialDetection = true;
340
388
  let times = 0,
341
389
  timer: ReturnType<typeof setInterval>;
342
- this._checkPromise = new Promise((resolve) => {
390
+ const detection = new Promise<boolean>((resolve) => {
343
391
  const check = () => {
344
392
  times++;
345
393
  const isSupport = supportTrust();
@@ -354,12 +402,21 @@ export class TrustAdapter extends AddonAdapter {
354
402
  timer = setInterval(check, interval);
355
403
  check();
356
404
  });
357
- return this._checkPromise;
405
+ this._checkPromise = detection;
406
+ // Never cache a failed detection. The extension may inject late, be switched on at
407
+ // runtime, or a mobile WebView may still be initialising — in all of those cases the
408
+ // next call has to look again instead of replaying the old negative answer.
409
+ void detection.then((found) => {
410
+ if (!found && this._checkPromise === detection) {
411
+ this._checkPromise = null;
412
+ }
413
+ });
414
+ return detection;
358
415
  }
359
416
 
360
417
  private _updateWallet = async () => {
361
- let state = this.state;
362
- let address = this.address;
418
+ let state;
419
+ let address;
363
420
  if (supportTrust()) {
364
421
  this._wallet = window.trustwallet!.tronLink;
365
422
  this._listenEvent();