1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4084],{93270:(e,t,n)=>{n.d(t,{$e:()=>ed,BH:()=>eo,Dg:()=>eb,Ee:()=>Q,Es:()=>el,GE:()=>eB,Gz:()=>er,K3:()=>a,Mx:()=>eh,NQ:()=>ep,S5:()=>i.S5,Sq:()=>ek,TB:()=>ef,VA:()=>ey,Vb:()=>L,_0:()=>en,aV:()=>em,dQ:()=>eS,fB:()=>D,iA:()=>m,ip:()=>Y,iw:()=>Z,j9:()=>eu,kT:()=>g,lp:()=>ev,m5:()=>es,m_:()=>e_,o2:()=>i.o2,q:()=>ew,sQ:()=>ec});var i=n(32374),r=n(82402);function s(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&0>t.indexOf(i)&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,i=Object.getOwnPropertySymbols(e);r<i.length;r++)0>t.indexOf(i[r])&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]]);return n}function o(e,t,n,i){return new(n||(n=Promise))(function(r,s){function o(e){try{l(i.next(e))}catch(e){s(e)}}function a(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?r(e.value):((t=e.value)instanceof n?t:new n(function(e){e(t)})).then(o,a)}l((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class a extends Error{get info(){return""}constructor(e,t){super(e,t),this.message=`${a.prefix} ${this.constructor.name}${this.info?": "+this.info:""}${e?"\n"+e:""}`,Object.setPrototypeOf(this,a.prototype)}}a.prefix="[TON_CONNECT_SDK_ERROR]";class l extends a{get info(){return"Passed DappMetadata is in incorrect format."}constructor(...e){super(...e),Object.setPrototypeOf(this,l.prototype)}}class c extends a{get info(){return"Passed `tonconnect-manifest.json` contains errors. Check format of your manifest. See more https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest"}constructor(...e){super(...e),Object.setPrototypeOf(this,c.prototype)}}class d extends a{get info(){return"Manifest not found. Make sure you added `tonconnect-manifest.json` to the root of your app or passed correct manifestUrl. See more https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest"}constructor(...e){super(...e),Object.setPrototypeOf(this,d.prototype)}}class u extends a{get info(){return"Wallet connection called but wallet already connected. To avoid the error, disconnect the wallet before doing a new connection."}constructor(...e){super(...e),Object.setPrototypeOf(this,u.prototype)}}class p extends a{get info(){return"Send transaction or other protocol methods called while wallet is not connected."}constructor(...e){super(...e),Object.setPrototypeOf(this,p.prototype)}}class h extends a{get info(){return"There is an attempt to connect to the injected wallet while it is not exists in the webpage."}constructor(...e){super(...e),Object.setPrototypeOf(this,h.prototype)}}class g extends a{get info(){return"Wallet doesn't support requested feature method."}constructor(e,t){super(e,t),Object.setPrototypeOf(this,g.prototype)}}class m extends a{get info(){return"Missing required features. You need to update your wallet."}constructor(e,t){super(e,t),Object.setPrototypeOf(this,m.prototype)}}class f extends a{get info(){return"User rejects the action in the wallet."}constructor(...e){super(...e),Object.setPrototypeOf(this,f.prototype)}}class y extends a{get info(){return"Request to the wallet contains errors."}constructor(...e){super(...e),Object.setPrototypeOf(this,y.prototype)}}class w extends a{get info(){return"App tries to send rpc request to the injected wallet while not connected."}constructor(...e){super(...e),Object.setPrototypeOf(this,w.prototype)}}class v extends a{get info(){return"An error occurred while fetching the wallets list."}constructor(...e){super(...e),Object.setPrototypeOf(this,v.prototype)}}class b extends a{get info(){return"Passed address is in incorrect format."}constructor(...e){super(...e),Object.setPrototypeOf(this,b.prototype)}}class S extends a{get info(){return"Passed hex is in incorrect format."}constructor(...e){super(...e),Object.setPrototypeOf(this,S.prototype)}}class _ extends a{constructor(...e){super(...e),Object.setPrototypeOf(this,_.prototype)}}let C={[i.IS.UNKNOWN_ERROR]:_,[i.IS.USER_REJECTS_ERROR]:f,[i.IS.BAD_REQUEST_ERROR]:y,[i.IS.UNKNOWN_APP_ERROR]:w,[i.IS.MANIFEST_NOT_FOUND_ERROR]:d,[i.IS.MANIFEST_CONTENT_ERROR]:c};class k{parseError(e){let t=_;return e.code in C&&(t=C[e.code]||_),new t(e.message)}}let x=new k;class T{isError(e){return"error"in e}}let R={[i.K4.UNKNOWN_ERROR]:_,[i.K4.USER_REJECTS_ERROR]:f,[i.K4.BAD_REQUEST_ERROR]:y,[i.K4.UNKNOWN_APP_ERROR]:w};class E extends T{convertToRpcRequest(e){return{method:"sendTransaction",params:[JSON.stringify(e)]}}parseAndThrowError(e){let t=_;throw e.error.code in R&&(t=R[e.error.code]||_),new t(e.error.message)}convertFromRpcResponse(e){return{boc:e.result}}}let O=new E,j={[i.Dn.UNKNOWN_ERROR]:_,[i.Dn.USER_REJECTS_ERROR]:f,[i.Dn.BAD_REQUEST_ERROR]:y,[i.Dn.UNKNOWN_APP_ERROR]:w};class I extends T{convertToRpcRequest(e){return{method:"signData",params:[JSON.stringify(e)]}}parseAndThrowError(e){let t=_;
1throw e.error.code in j&&(t=j[e.error.code]||_),new t(e.error.message)}convertFromRpcResponse(e){return e.result}}let W=new I;class q{constructor(e,t){this.storage=e,this.storeKey="ton-connect-storage_http-bridge-gateway::"+t}storeLastEventId(e){return o(this,void 0,void 0,function*(){return this.storage.setItem(this.storeKey,e)})}removeLastEventId(){return o(this,void 0,void 0,function*(){return this.storage.removeItem(this.storeKey)})}getLastEventId(){return o(this,void 0,void 0,function*(){let e=yield this.storage.getItem(this.storeKey);return e||null})}}function P(e,t){return("/"===e.slice(-1)?e.slice(0,-1):e)+"/"+t}function L(e){if(!e)return!1;let t=new URL(e);return"tg:"===t.protocol||"t.me"===t.hostname}function D(e){return e.replaceAll(".","%2E").replaceAll("-","%2D").replaceAll("_","%5F").replaceAll("&","-").replaceAll("=","__").replaceAll("%","--")}function M(e,t){return o(this,void 0,void 0,function*(){return new Promise((t,n)=>{setTimeout(()=>t(),e)})})}function A(e){let t=new AbortController;return(null==e?void 0:e.aborted)?t.abort():null==e||e.addEventListener("abort",()=>t.abort(),{once:!0}),t}function U(e,t){return o(this,void 0,void 0,function*(){var n,i;let r,s=null!=(n=null==t?void 0:t.attempts)?n:10,o=null!=(i=null==t?void 0:t.delayMs)?i:200,l=A(null==t?void 0:t.signal);if("function"!=typeof e)throw new a(`Expected a function, got ${typeof e}`);let c=0;for(;c<s;){if(l.signal.aborted)throw new a(`Aborted after attempts ${c}`);try{return yield e({signal:l.signal})}catch(e){r=e,++c<s&&(yield M(o))}}throw r})}function N(...e){try{console.debug("[TON_CONNECT_SDK]",...e)}catch(e){}}function B(...e){try{console.error("[TON_CONNECT_SDK]",...e)}catch(e){}}class K{get isReady(){let e=this.eventSource.current();return(null==e?void 0:e.readyState)===EventSource.OPEN}get isClosed(){let e=this.eventSource.current();return(null==e?void 0:e.readyState)!==EventSource.OPEN}get isConnecting(){let e=this.eventSource.current();return(null==e?void 0:e.readyState)===EventSource.CONNECTING}constructor(e,t,n,i,r){this.bridgeUrl=t,this.sessionId=n,this.listener=i,this.errorsListener=r,this.ssePath="events",this.postPath="message",this.heartbeatMessage="heartbeat",this.defaultTtl=300,this.defaultReconnectDelay=2e3,this.defaultResendDelay=5e3,this.eventSource=function(e,t){let n=null,i=null,r=null,s=null,l=null,c=(c,...d)=>o(this,void 0,void 0,function*(){if(s=null!=c?c:null,null==l||l.abort(),(l=A(c)).signal.aborted)throw new a("Resource creation was aborted");i=null!=d?d:null;let o=e(l.signal,...d);r=o;let u=yield o;if(r!==o&&u!==n)throw yield t(u),new a("Resource creation was aborted by a new resource creation");return n=u}),d=e=>o(this,void 0,void 0,function*(){let t=n,o=r,l=i,d=s;if(yield M(e),t===n&&o===r&&l===i&&d===s)return yield c(s,...null!=l?l:[]);throw new a("Resource recreation was aborted by a new resource creation")});return{create:c,current:()=>null!=n?n:null,dispose:()=>o(this,void 0,void 0,function*(){try{let e=n;n=null;let i=r;r=null;try{null==l||l.abort()}catch(e){}yield Promise.allSettled([e?t(e):Promise.resolve(),i?t((yield i)):Promise.resolve()])}catch(e){}}),recreate:d}}((e,t)=>o(this,void 0,void 0,function*(){let n={bridgeUrl:this.bridgeUrl,ssePath:this.ssePath,sessionId:this.sessionId,bridgeGatewayStorage:this.bridgeGatewayStorage,errorHandler:this.errorsHandler.bind(this),messageHandler:this.messagesHandler.bind(this),signal:e,openingDeadlineMS:t};return yield function(e){return o(this,void 0,void 0,function*(){return yield function(e,t){let n=null==t?void 0:t.timeout,i=A(null==t?void 0:t.signal);return new Promise((t,r)=>o(this,void 0,void 0,function*(){let s;if(i.signal.aborted)return void r(new a("Operation aborted"));void 0!==n&&(s=setTimeout(()=>{i.abort(),r(new a(`Timeout after ${n}ms`))},n)),i.signal.addEventListener("abort",()=>{clearTimeout(s),r(new a("Operation aborted"))},{once:!0});let o={timeout:n,abort:i.signal};yield e((...e)=>{clearTimeout(s),t(...e)},()=>{clearTimeout(s),r()},o)}))}((t,n,i)=>o(this,void 0,void 0,function*(){var r;let s=A(i.signal).signal;if(s.aborted)return void n(new a("Bridge connection aborted"));let l=new URL(P(e.bridgeUrl,e.ssePath));
1l.searchParams.append("client_id",e.sessionId);let c=yield e.bridgeGatewayStorage.getLastEventId();if(c&&l.searchParams.append("last_event_id",c),s.aborted)return void n(new a("Bridge connection aborted"));let d=new EventSource(l.toString());d.onerror=i=>o(this,void 0,void 0,function*(){if(s.aborted){d.close(),n(new a("Bridge connection aborted"));return}try{let n=yield e.errorHandler(d,i);n!==d&&d.close(),n&&n!==d&&t(n)}catch(e){d.close(),n(e)}}),d.onopen=()=>{if(s.aborted){d.close(),n(new a("Bridge connection aborted"));return}t(d)},d.onmessage=t=>{if(s.aborted){d.close(),n(new a("Bridge connection aborted"));return}e.messageHandler(t)},null==(r=e.signal)||r.addEventListener("abort",()=>{d.close(),n(new a("Bridge connection aborted"))})}),{timeout:e.openingDeadlineMS,signal:e.signal})})}(n)}),e=>o(this,void 0,void 0,function*(){e.close()})),this.bridgeGatewayStorage=new q(e,t)}registerSession(e){return o(this,void 0,void 0,function*(){yield this.eventSource.create(null==e?void 0:e.signal,null==e?void 0:e.openingDeadlineMS)})}send(e,t,n,r){return o(this,void 0,void 0,function*(){var s;let l={};"number"==typeof r?l.ttl=r:(l.ttl=null==r?void 0:r.ttl,l.signal=null==r?void 0:r.signal,l.attempts=null==r?void 0:r.attempts);let c=new URL(P(this.bridgeUrl,this.postPath));c.searchParams.append("client_id",this.sessionId),c.searchParams.append("to",t),c.searchParams.append("ttl",((null==l?void 0:l.ttl)||this.defaultTtl).toString()),c.searchParams.append("topic",n);let d=i.o4.encode(e);yield U(e=>o(this,void 0,void 0,function*(){let t=yield this.post(c,d,e.signal);if(!t.ok)throw new a(`Bridge send failed, status ${t.status}`)}),{attempts:null!=(s=null==l?void 0:l.attempts)?s:Number.MAX_SAFE_INTEGER,delayMs:this.defaultResendDelay,signal:null==l?void 0:l.signal})})}pause(){this.eventSource.dispose().catch(e=>B(`Bridge pause failed, ${e}`))}unPause(){return o(this,void 0,void 0,function*(){yield this.eventSource.recreate(0)})}close(){return o(this,void 0,void 0,function*(){yield this.eventSource.dispose().catch(e=>B(`Bridge close failed, ${e}`))})}setListener(e){this.listener=e}setErrorsListener(e){this.errorsListener=e}post(e,t,n){return o(this,void 0,void 0,function*(){let i=yield fetch(e,{method:"post",body:t,signal:n});if(!i.ok)throw new a(`Bridge send failed, status ${i.status}`);return i})}errorsHandler(e,t){return o(this,void 0,void 0,function*(){if(this.isConnecting)throw e.close(),new a("Bridge error, failed to connect");if(this.isReady){try{this.errorsListener(t)}catch(e){}return}if(this.isClosed)return e.close(),N(`Bridge reconnecting, ${this.defaultReconnectDelay}ms delay`),yield this.eventSource.recreate(this.defaultReconnectDelay);throw new a("Bridge error, unknown state")})}messagesHandler(e){return o(this,void 0,void 0,function*(){let t;if(e.data!==this.heartbeatMessage&&(yield this.bridgeGatewayStorage.storeLastEventId(e.lastEventId),!this.isClosed)){try{t=JSON.parse(e.data)}catch(t){throw new a(`Bridge message parse failed, message ${e.data}`)}this.listener(t)}})}}function $(e){return!("connectEvent"in e)}class G{constructor(e){this.storage=e,this.storeKey="ton-connect-storage_bridge-connection"}storeConnection(e){return o(this,void 0,void 0,function*(){if("injected"===e.type)return this.storage.setItem(this.storeKey,JSON.stringify(e));if(!$(e)){let t={sessionKeyPair:e.session.sessionCrypto.stringifyKeypair(),walletPublicKey:e.session.walletPublicKey,bridgeUrl:e.session.bridgeUrl},n={type:"http",connectEvent:e.connectEvent,session:t,lastWalletEventId:e.lastWalletEventId,nextRpcRequestId:e.nextRpcRequestId};return this.storage.setItem(this.storeKey,JSON.stringify(n))}let t={type:"http",connectionSource:e.connectionSource,sessionCrypto:e.sessionCrypto.stringifyKeypair(),createdAt:Date.now()};return this.storage.setItem(this.storeKey,JSON.stringify(t))})}removeConnection(){return o(this,void 0,void 0,function*(){return this.storage.removeItem(this.storeKey)})}getConnection(){return o(this,void 0,void 0,function*(){var e;let t=yield this.storage.getItem(this.storeKey);if(!t)return null;let n=JSON.parse(t);if("injected"===n.type)return n;if("connectEvent"in n){let e=new i.o2(n.session.sessionKeyPair);return{type:"http",connectEvent:n.connectEvent,lastWalletEventId:n.lastWalletEventId,nextRpcRequestId:n.nextRpcRequestId,session:{sessionCrypto:e,bridgeUrl:n.session.bridgeUrl,walletPublicKey:n.session.walletPublicKey}}}return Date.now()-(null!=(e=n.createdAt)?e:0)>3e5?(yield this.removeConnection(),null):{type:"http",sessionCrypto:new i.o2(n.sessionCrypto),connectionSource:n.connectionSource}})}getHttpConnection(){return o(this,void 0,void 0,function*(){let e=yield this.getConnection();if(!e)throw new a("Trying to read HTTP connection source while nothing is stored");if("injected"===e.type)throw new a("Trying to read HTTP connection source while injected connection is stored");return e})}getHttpPendingConnection(){return o(this,void 0,void 0,function*(){let e=yield this.getConnection();if(!e)throw new a("Trying to read HTTP connection source while nothing is stored");if("injected"===e.type)throw new a("Trying to read HTTP connection source while injected connection is stored");if(!$(e))throw new a("Trying to read HTTP-pending connection while http connection is stored");return e})}getInjectedConnection(){return o(this,void 0,void 0,function*(){let e=yield this.getConnection();if(!e)throw new a("Trying to read Injected bridge connection source while nothing is stored");if((null==e?void 0:e.type)==="http")throw new a("Trying to read Injected bridge connection source while HTTP connection is stored");return e})}storedConnectionType(){return o(this,void 0,void 0,function*(){let e=yield this.storage.getItem(this.storeKey);return e?JSON.parse(e).type:null})}storeLastWalletEventId(e){return o(this,void 0,void 0,function*(){let t=yield this.getConnection();if(t&&"http"===t.type&&!$(t))return t.lastWalletEventId=e,this.storeConnection(t)})}getLastWalletEventId(){return o(this,void 0,void 0,function*(){let e=yield this.getConnection();if(e&&"lastWalletEventId"in e)return e.lastWalletEventId})}increaseNextRpcRequestId(){return o(this,void 0,void 0,function*(){let e=yield this.getConnection();if(e&&"nextRpcRequestId"in e){let t=e.nextRpcRequestId||0;return e.nextRpcRequestId=t+1,this.storeConnection(e)}})}getNextRpcRequestId(){return o(this,void 0,void 0,function*(){let e=yield this.getConnection();return e&&"nextRpcRequestId"in e&&e.nextRpcRequestId||0})}}class F{static fromStorage(e){return o(this,void 0,void 0,function*(){let t=new G(e),n=yield t.getHttpConnection();return $(n)?new F(e,n.connectionSource):new F(e,{bridgeUrl:n.session.bridgeUrl})})}constructor(e,t){this.storage=e,this.walletConnectionSource=t,this.type="http",this.standardUniversalLink="tc://",this.pendingRequests=new Map,this.session=null,this.gateway=null,this.pendingGateways=[],this.listeners=[],this.defaultOpeningDeadlineMS=12e3,this.defaultRetryTimeoutMS=2e3,this.connectionStorage=new G(e)}connect(e,t){var n;let r=A(null==t?void 0:t.signal);null==(n=this.abortController)||n.abort(),this.abortController=r,this.closeGateways();let s=new i.o2;this.session={sessionCrypto:s,bridgeUrl:"bridgeUrl"in this.walletConnectionSource?this.walletConnectionSource.bridgeUrl:""},this.connectionStorage.storeConnection({type:"http",connectionSource:this.walletConnectionSource,sessionCrypto:s}).then(()=>o(this,void 0,void 0,function*(){r.signal.aborted||(yield U(e=>{var n;return this.openGateways(s,{openingDeadlineMS:null!=(n=null==t?void 0:t.openingDeadlineMS)?n:this.defaultOpeningDeadlineMS,signal:null==e?void 0:e.signal})},{attempts:Number.MAX_SAFE_INTEGER,delayMs:this.defaultRetryTimeoutMS,signal:r.signal}))}));let a="universalLink"in this.walletConnectionSource&&this.walletConnectionSource.universalLink?this.walletConnectionSource.universalLink:this.standardUniversalLink;return this.generateUniversalLink(a,e)}restoreConnection(e){return o(this,void 0,void 0,function*(){var t,n;let i=A(null==e?void 0:e.signal);if(null==(t=this.abortController)||t.abort(),this.abortController=i,i.signal.aborted)return;this.closeGateways();let r=yield this.connectionStorage.getHttpConnection();if(!r||i.signal.aborted)return;let s=null!=(n=null==e?void 0:e.openingDeadlineMS)?n:this.defaultOpeningDeadlineMS;
1if($(r))return this.session={sessionCrypto:r.sessionCrypto,bridgeUrl:"bridgeUrl"in this.walletConnectionSource?this.walletConnectionSource.bridgeUrl:""},yield this.openGateways(r.sessionCrypto,{openingDeadlineMS:s,signal:null==i?void 0:i.signal});if(Array.isArray(this.walletConnectionSource))throw new a("Internal error. Connection source is array while WalletConnectionSourceHTTP was expected.");if(this.session=r.session,this.gateway&&(N("Gateway is already opened, closing previous gateway"),yield this.gateway.close()),this.gateway=new K(this.storage,this.walletConnectionSource.bridgeUrl,r.session.sessionCrypto.sessionId,this.gatewayListener.bind(this),this.gatewayErrorsListener.bind(this)),!i.signal.aborted){this.listeners.forEach(e=>e(r.connectEvent));try{yield U(e=>this.gateway.registerSession({openingDeadlineMS:s,signal:e.signal}),{attempts:Number.MAX_SAFE_INTEGER,delayMs:this.defaultRetryTimeoutMS,signal:i.signal})}catch(e){yield this.disconnect({signal:i.signal});return}}})}sendRequest(e,t){let n={};return"function"==typeof t?n.onRequestSent=t:(n.onRequestSent=null==t?void 0:t.onRequestSent,n.signal=null==t?void 0:t.signal,n.attempts=null==t?void 0:t.attempts),new Promise((t,r)=>o(this,void 0,void 0,function*(){var s;if(!this.gateway||!this.session||!("walletPublicKey"in this.session))throw new a("Trying to send bridge request without session");let o=(yield this.connectionStorage.getNextRpcRequestId()).toString();yield this.connectionStorage.increaseNextRpcRequestId(),N("Send http-bridge request:",Object.assign(Object.assign({},e),{id:o}));let l=this.session.sessionCrypto.encrypt(JSON.stringify(Object.assign(Object.assign({},e),{id:o})),(0,i.Aq)(this.session.walletPublicKey));try{yield this.gateway.send(l,this.session.walletPublicKey,e.method,{attempts:null==n?void 0:n.attempts,signal:null==n?void 0:n.signal}),null==(s=null==n?void 0:n.onRequestSent)||s.call(n),this.pendingRequests.set(o.toString(),t)}catch(e){r(e)}}))}closeConnection(){this.closeGateways(),this.listeners=[],this.session=null,this.gateway=null}disconnect(e){return o(this,void 0,void 0,function*(){return new Promise(t=>o(this,void 0,void 0,function*(){let n=!1,i=null,r=()=>{n||(n=!0,this.removeBridgeAndSession().then(t))};try{this.closeGateways();let t=A(null==e?void 0:e.signal);i=setTimeout(()=>{t.abort()},this.defaultOpeningDeadlineMS),yield this.sendRequest({method:"disconnect",params:[]},{onRequestSent:r,signal:t.signal,attempts:1})}catch(e){N("Disconnect error:",e),n||this.removeBridgeAndSession().then(t)}finally{i&&clearTimeout(i),r()}}))})}listen(e){return this.listeners.push(e),()=>this.listeners=this.listeners.filter(t=>t!==e)}pause(){var e;null==(e=this.gateway)||e.pause(),this.pendingGateways.forEach(e=>e.pause())}unPause(){return o(this,void 0,void 0,function*(){let e=this.pendingGateways.map(e=>e.unPause());this.gateway&&e.push(this.gateway.unPause()),yield Promise.all(e)})}pendingGatewaysListener(e,t,n){return o(this,void 0,void 0,function*(){return this.pendingGateways.includes(e)?(this.closeGateways({except:e}),this.gateway&&(N("Gateway is already opened, closing previous gateway"),yield this.gateway.close()),this.session.bridgeUrl=t,this.gateway=e,this.gateway.setErrorsListener(this.gatewayErrorsListener.bind(this)),this.gateway.setListener(this.gatewayListener.bind(this)),this.gatewayListener(n)):void(yield e.close())})}gatewayListener(e){return o(this,void 0,void 0,function*(){let t=JSON.parse(this.session.sessionCrypto.decrypt(i.o4.decode(e.message).toUint8Array(),(0,i.Aq)(e.from)));if(N("Wallet message received:",t),!("event"in t)){let e=t.id.toString(),n=this.pendingRequests.get(e);return n?(n(t),void this.pendingRequests.delete(e)):void N(`Response id ${e} doesn't match any request's id`)}if(void 0!==t.id){let e=yield this.connectionStorage.getLastWalletEventId();if(void 0!==e&&t.id<=e)return void B(`Received event id (=${t.id}) must be greater than stored last wallet event id (=${e}) `);"connect"!==t.event&&(yield this.connectionStorage.storeLastWalletEventId(t.id))}let n=this.listeners;"connect"===t.event&&(yield this.updateSession(t,e.from)),"disconnect"===t.event&&(N("Removing bridge and session: received disconnect event"),yield this.removeBridgeAndSession()),n.forEac
1h(e=>e(t))})}gatewayErrorsListener(e){return o(this,void 0,void 0,function*(){throw new a(`Bridge error ${JSON.stringify(e)}`)})}updateSession(e,t){return o(this,void 0,void 0,function*(){this.session=Object.assign(Object.assign({},this.session),{walletPublicKey:t});let n=e.payload.items.find(e=>"ton_addr"===e.name),i=Object.assign(Object.assign({},e),{payload:Object.assign(Object.assign({},e.payload),{items:[n]})});yield this.connectionStorage.storeConnection({type:"http",session:this.session,lastWalletEventId:e.id,connectEvent:i,nextRpcRequestId:0})})}removeBridgeAndSession(){return o(this,void 0,void 0,function*(){this.closeConnection(),yield this.connectionStorage.removeConnection()})}generateUniversalLink(e,t){return L(e)?this.generateTGUniversalLink(e,t):this.generateRegularUniversalLink(e,t)}generateRegularUniversalLink(e,t){let n=new URL(e);return n.searchParams.append("v","2"),n.searchParams.append("id",this.session.sessionCrypto.sessionId),n.searchParams.append("r",JSON.stringify(t)),n.toString()}generateTGUniversalLink(e,t){let n="tonconnect-"+D(this.generateRegularUniversalLink("about:blank",t).split("?")[1]),i=new URL(this.convertToDirectLink(e));return i.searchParams.append("startapp",n),i.toString()}convertToDirectLink(e){let t=new URL(e);return t.searchParams.has("attach")&&(t.searchParams.delete("attach"),t.pathname+="/start"),t.toString()}openGateways(e,t){return o(this,void 0,void 0,function*(){if(!Array.isArray(this.walletConnectionSource))return this.gateway&&(N("Gateway is already opened, closing previous gateway"),yield this.gateway.close()),this.gateway=new K(this.storage,this.walletConnectionSource.bridgeUrl,e.sessionId,this.gatewayListener.bind(this),this.gatewayErrorsListener.bind(this)),yield this.gateway.registerSession({openingDeadlineMS:null==t?void 0:t.openingDeadlineMS,signal:null==t?void 0:t.signal});this.pendingGateways.map(e=>e.close().catch()),this.pendingGateways=this.walletConnectionSource.map(t=>{let n=new K(this.storage,t.bridgeUrl,e.sessionId,()=>{},()=>{});return n.setListener(e=>this.pendingGatewaysListener(n,t.bridgeUrl,e)),n}),yield Promise.allSettled(this.pendingGateways.map(e=>U(n=>{var i;return this.pendingGateways.some(t=>t===e)?e.registerSession({openingDeadlineMS:null!=(i=null==t?void 0:t.openingDeadlineMS)?i:this.defaultOpeningDeadlineMS,signal:n.signal}):e.close()},{attempts:Number.MAX_SAFE_INTEGER,delayMs:this.defaultRetryTimeoutMS,signal:null==t?void 0:t.signal})))})}closeGateways(e){var t;null==(t=this.gateway)||t.close(),this.pendingGateways.filter(t=>t!==(null==e?void 0:e.except)).forEach(e=>e.close()),this.pendingGateways=[]}}function H(e,t){return!!e&&"object"==typeof e&&t.every(t=>t in e)}class V{static getInstance(){return V.instance||(V.instance=new V),V.instance}constructor(){this.storage={}}get length(){return Object.keys(this.storage).length}clear(){this.storage={}}getItem(e){var t;return null!=(t=this.storage[e])?t:null}key(e){var t;let n=Object.keys(this.storage);return e<0||e>=n.length?null:null!=(t=n[e])?t:null}removeItem(e){delete this.storage[e]}setItem(e,t){this.storage[e]=t}}function J(){if("undefined"!=typeof window)return window}class z{static fromStorage(e){return o(this,void 0,void 0,function*(){let t=new G(e);return new z(e,(yield t.getInjectedConnection()).jsBridgeKey)})}static isWalletInjected(e){return z.isWindowContainsWallet(this.window,e)}static isInsideWalletBrowser(e){return!!z.isWindowContainsWallet(this.window,e)&&this.window[e].tonconnect.isWalletBrowser}static getCurrentlyInjectedWallets(){return this.window?(function(){let e=J();if(!e)return[];try{return Object.entries(e)}catch(e){return[]}})().filter(([e,t])=>(function(e){try{var t;if(!H(e,["tonconnect"])||(t=e.tonconnect,!H(t,["walletInfo"])))return!1;return H(e.tonconnect.walletInfo,["name","app_name","image","about_url","platforms"])}catch(e){return!1}})(t)).map(([e,t])=>({name:t.tonconnect.walletInfo.name,appName:t.tonconnect.walletInfo.app_name,aboutUrl:t.tonconnect.walletInfo.about_url,imageUrl:t.tonconnect.walletInfo.image,tondns:t.tonconnect.walletInfo.tondns,jsBridgeKey:e,injected:!0,embedded:t.tonconnect.isWalletBrowser,platforms:t.tonconnect.walletInfo.platforms,features:t.tonconnect.walletInfo.features})):[]}static isWindowContainsWallet(e,t){return!!e&&t in e&&"object"==typeof e[t]&&"tonconnect"in e[t]}constructor(e,t){this.injectedWalletKey=t,this.type="injected",this.unsubscribeCallback=null,this.listenSubscriptions=!1,this.listeners=[];const n=z.window;if(!z.isWindowContainsWallet(n,t))throw new h;this.connectionStorage=new G(e),this.injectedWallet=n[t].tonconnect}connect(e){this._connect(2,e)}restoreConnection(){return o(this,void 0,void 0,function*(){try{N("Injected Provider restoring connection...");let e=yield this.injectedWallet.restoreConnection();N("Injected Provider restoring connection response",e),"connect"===e.event?(this.makeSubscriptions(),this.listeners.forEac
1h(t=>t(e))):yield this.connectionStorage.removeConnection()}catch(e){yield this.connectionStorage.removeConnection(),console.error(e)}})}closeConnection(){this.listenSubscriptions&&this.injectedWallet.disconnect(),this.closeAllListeners()}disconnect(){return o(this,void 0,void 0,function*(){return new Promise(e=>{let t=()=>{this.closeAllListeners(),this.connectionStorage.removeConnection().then(e)};try{this.injectedWallet.disconnect(),t()}catch(e){N(e),this.sendRequest({method:"disconnect",params:[]},t)}})})}closeAllListeners(){var e;this.listenSubscriptions=!1,this.listeners=[],null==(e=this.unsubscribeCallback)||e.call(this)}listen(e){return this.listeners.push(e),()=>this.listeners=this.listeners.filter(t=>t!==e)}sendRequest(e,t){return o(this,void 0,void 0,function*(){var n;let i={};"function"==typeof t?i.onRequestSent=t:(i.onRequestSent=null==t?void 0:t.onRequestSent,i.signal=null==t?void 0:t.signal);let r=(yield this.connectionStorage.getNextRpcRequestId()).toString();yield this.connectionStorage.increaseNextRpcRequestId(),N("Send injected-bridge request:",Object.assign(Object.assign({},e),{id:r}));let s=this.injectedWallet.send(Object.assign(Object.assign({},e),{id:r}));return s.then(e=>N("Wallet message received:",e)),null==(n=null==i?void 0:i.onRequestSent)||n.call(i),s})}_connect(e,t){return o(this,void 0,void 0,function*(){try{N(`Injected Provider connect request: protocolVersion: ${e}, message:`,t);let n=yield this.injectedWallet.connect(e,t);N("Injected Provider connect response:",n),"connect"===n.event&&(yield this.updateSession(),this.makeSubscriptions()),this.listeners.forEach(e=>e(n))}catch(t){N("Injected Provider connect error:",t);let e={event:"connect_error",payload:{code:0,message:null==t?void 0:t.toString()}};this.listeners.forEach(t=>t(e))}})}makeSubscriptions(){this.listenSubscriptions=!0,this.unsubscribeCallback=this.injectedWallet.listen(e=>{N("Wallet message received:",e),this.listenSubscriptions&&this.listeners.forEach(t=>t(e)),"disconnect"===e.event&&this.disconnect()})}updateSession(){return this.connectionStorage.storeConnection({type:"injected",jsBridgeKey:this.injectedWalletKey,nextRpcRequestId:0})}}z.window=J();class X{constructor(){this.localStorage=function(){if(function(){try{return"undefined"!=typeof localStorage}catch(e){return!1}}())return localStorage;if(void 0!==r&&null!=r.versions&&null!=r.versions.node)throw new a("`localStorage` is unavailable, but it is required for TonConnect. For more details, see https://github.com/ton-connect/sdk/tree/main/packages/sdk#init-connector");return V.getInstance()}()}getItem(e){return o(this,void 0,void 0,function*(){return this.localStorage.getItem(e)})}removeItem(e){return o(this,void 0,void 0,function*(){this.localStorage.removeItem(e)})}setItem(e,t){return o(this,void 0,void 0,function*(){this.localStorage.setItem(e,t)})}}function Q(e){return"jsBridgeKey"in e&&e.injected}function Z(e){return Q(e)&&e.embedded}function Y(e){return"bridgeUrl"in e}let ee=[{app_name:"telegram-wallet",name:"Wallet",image:"https://wallet.tg/images/logo-288.png",about_url:"https://wallet.tg/",universal_url:"https://t.me/wallet?attach=wallet",bridge:[{type:"sse",url:"https://walletbot.me/tonconnect-bridge/bridge"}],platforms:["ios","android","macos","windows","linux"],features:[{name:"SendTransaction",maxMessages:255,extraCurrencySupported:!0},{name:"SignData",types:["text","binary","cell"]}]},{app_name:"tonkeeper",name:"Tonkeeper",image:"https://tonkeeper.com/assets/tonconnect-icon.png",tondns:"tonkeeper.ton",about_url:"https://tonkeeper.com",universal_url:"https://app.tonkeeper.com/ton-connect",deepLink:"tonkeeper-tc://",bridge:[{type:"sse",url:"https://bridge.tonapi.io/bridge"},{type:"js",key:"tonkeeper"}],platforms:["ios","android","chrome","firefox","macos"],features:[{name:"SendTransaction",maxMessages:255,extraCurrencySupported:!0},{name:"SignData",types:["text","binary","cell"]}]},{app_name:"mytonwallet",name:"MyTonWallet",image:"https://static.mytonwallet.io/icon-256.png",about_url:"https://mytonwallet.io",universal_url:"https://connect.mytonwallet.org",deepLink:"mytonwallet-tc://",bridge:[{type:"js",key:"mytonwallet"},{type:"sse",url:"https://tonconnectbridge.mytonwallet.org/bridge/"}],platforms:["chrome","windows","macos","linux","ios","android","firefox"],features:[{name:"SendTransaction",maxMessages:255,extraCurrencySupported:!1},{name:"SignData",types:["text","binary","cell"]}]},{app_name:"tonhub",name:"Tonhub",image:"https://tonhub.com/tonconnect_logo.png",about_url:"https://tonhub.com",universal_url:"https://tonhub.com/ton-connect",bridge:[{type:"js",key:"tonhub"},{type:"sse",url:"https://connect.tonhubapi.com/tonconnect"}],platforms:["ios","android"],features:[{name:"SendTransaction",maxMessages:255,extraCurrencySupported:!0}
1,{name:"SignData",types:["text","binary","cell"]}]},{app_name:"bitgetTonWallet",name:"Bitget Wallet",image:"https://raw.githubusercontent.com/bitgetwallet/download/refs/heads/main/logo/png/bitget_wallet_logo_288_mini.png",about_url:"https://web3.bitget.com",deepLink:"bitkeep://",bridge:[{type:"js",key:"bitgetTonWallet"},{type:"sse",url:"https://ton-connect-bridge.bgwapi.io/bridge"}],platforms:["ios","android","chrome"],universal_url:"https://bkcode.vip/ton-connect",features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"okxMiniWallet",name:"OKX Mini Wallet",image:"https://static.okx.com/cdn/assets/imgs/2411/8BE1A4A434D8F58A.png",about_url:"https://www.okx.com/web3",universal_url:"https://t.me/OKX_WALLET_BOT?attach=wallet",bridge:[{type:"sse",url:"https://www.okx.com/tonbridge/discover/rpc/bridge"}],platforms:["ios","android","macos","windows","linux"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"binanceWeb3TonWallet",name:"Binance Wallet",image:"https://public.bnbstatic.com/static/binance-w3w/ton-provider/binancew3w.png",about_url:"https://www.binance.com/en/web3wallet",deepLink:"bnc://app.binance.com/cedefi/ton-connect",bridge:[{type:"js",key:"binancew3w"},{type:"sse",url:"https://wallet.binance.com/tonbridge/bridge"}],platforms:["ios","android","macos","windows","linux"],universal_url:"https://app.binance.com/cedefi/ton-connect",features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"fintopio-tg",name:"Fintopio",image:"https://raw.githubusercontent.com/fintopio/ton-pub/refs/heads/main/logos/tonconnect-icon.png",about_url:"https://fintopio.com",universal_url:"https://t.me/fintopio?attach=wallet",bridge:[{type:"sse",url:"https://wallet-bridge.fintopio.com/bridge"}],platforms:["ios","android","macos","windows","linux"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"okxTonWallet",name:"OKX Wallet",image:"https://static.okx.com/cdn/assets/imgs/247/58E63FEA47A2B7D7.png",about_url:"https://www.okx.com/web3",universal_url:"https://www.okx.com/download?appendQuery=true&deeplink=okx://web3/wallet/tonconnect",bridge:[{type:"js",key:"okxTonWallet"},{type:"sse",url:"https://www.okx.com/tonbridge/discover/rpc/bridge"}],platforms:["chrome","safari","firefox","ios","android"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"hot",name:"HOT",image:"https://raw.githubusercontent.com/hot-dao/media/main/logo.png",about_url:"https://hot-labs.org/",universal_url:"https://t.me/herewalletbot?attach=wallet",bridge:[{type:"sse",url:"https://sse-bridge.hot-labs.org"},{type:"js",key:"hotWallet"}],platforms:["ios","android","macos","windows","linux"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"bybitTonWallet",name:"Bybit Wallet",image:"https://raw.githubusercontent.com/bybit-web3/bybit-web3.github.io/main/docs/images/bybit-logo.png",about_url:"https://www.bybit.com/web3",universal_url:"https://app.bybit.com/ton-connect",deepLink:"bybitapp://",bridge:[{type:"js",key:"bybitTonWallet"},{type:"sse",url:"https://api-node.bybit.com/spot/api/web3/bridge/ton/bridge"}],platforms:["ios","android","chrome"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"dewallet",name:"DeWallet",image:"https://raw.githubusercontent.com/delab-team/manifests-images/main/WalletAvatar.png",about_url:"https://delabwallet.com",universal_url:"https://t.me/dewallet?attach=wallet",bridge:[{type:"sse",url:"https://bridge.dewallet.pro/bridge"}],platforms:["ios","android","macos","windows","linux"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"safepalwallet",name:"SafePal",image:"https://s.pvcliping.com/web/public_image/SafePal_x288.png",tondns:"",about_url:"https://www.safepal.com",universal_url:"https://link.safepal.io/ton-connect",deepLink:"safepal-tc://",bridge:[{type:"sse",url:"https://ton-bridge.safepal.com/tonbridge/v1/bridge"},{type:"js",key:"safepalwallet"}],platforms:["ios","android","chrome","firefox"],features:[{name:"SendTransaction",maxMessages:1,extraCurrencySupported:!1}]},{app_name:"GateWallet",name:"GateWallet",image:"https://img.gatedataimg.com/prd-ordinal-imgs/036f07bb8730716e/gateio-0925.png",about_url:"https://www.gate.io/",bridge:[{type:"js",key:"gatetonwallet"},{type:"sse",url:"https://dapp.gateio.services/tonbridge_api/bridge/v1"}],platforms:["ios","android"],universal_url:"https://gate.onelink.me/Hls0/web3?gate_web3_wallet_universal_type=ton_connect",features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"openmask",name:"OpenMask",image:"https://raw.githubusercontent.com/OpenProduct/openmask-extension/main/public/openmask-logo-288.png",about_url:"https://www.openmask.app/",bridge:[{type:"js",key:"openmask"}],platforms:["chrome"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"BitgetWeb3",name:"BitgetWeb3",image:"https://img.bitgetimg.com/image/third/1731638059795.png",about_url:"âhttps://www.bitget.com",universal_url:"https://t.me/BitgetOfficialBot?attach=wallet",bridge:[{type:"sse",url:"https://ton-connect-bridge.bgwapi.io/bridge"}],platforms:["ios","android","windows","macos","linux"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"xtonwallet",name:"XTONWallet",image:"https://xtonwallet.com/assets/img/icon-256-back.png",about_url:"https://xtonwallet.com",bridge:[{type:"js",key:"xtonwallet"}],platforms:["chrome","firefox"],features:[{name:"SendTransaction",maxMessages:1,extraCurrencySupported:!1}]},{app_name:"tonwallet",name:"TON Wallet",image:"https://wallet.ton.org/assets/ui/qr-logo.png",about_url:"https://chrome.google.com/webstore/detail/ton-wallet/nphplpgoakhhjchkkhmiggakijnkhfnd",bridge:[{type:"js",key:"tonwallet"}],platforms:["chrome"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"bitgetWalletLite",name:"Bitget Wallet Lite",image:"https://raw.githubusercontent.com/bitgetwallet/download/refs/heads/main/logo/png/bitget_wallet_lite_logo_288.png",about_url:"https://web3.bitget.com",universal_url:"https://t.me/BitgetWallet_TGBot?attach=wallet",bridge:[{type:"sse",url:"https://ton-connect-bridge.bgwapi.io/bridge"}],platforms:["ios","android","macos","windows","linux"],features:[{name:"SendTransaction",maxMessages:255,extraCurrencySupported:!1}]},{app_name:"tomoWallet",name:"Tomo Wallet",image:"https://pub.tomo.inc/logo.png",about_url:"https://www.tomo.inc/",universal_url:"https://t.me/tomowalletbot?attach=wallet",bridge:[{type:"sse",url:"https://go-bridge.tomo.inc/bridge"}],platforms:["ios","android","macos","windows","linux"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"miraiapp-tg",name:"Mirai Mini App",image:"https://cdn.mirailabs.co/miraihub/miraiapp-tg-icon-288.png",about_url:"https://mirai.app",universal_url:"https://t.me/MiraiAppBot?attach=wallet",bridge:[{type:"sse",url:"https://bridge.mirai.app"}],platforms:["ios","android","macos","windows","linux"],features:[{name:"SendTransaction",maxMessages:255,extraCurrencySupported:!1},{name:"SignData",types:["text","binary","cell"]}]},{app_name:"Architec.ton",name:"Architec.ton",image:"https://raw.githubusercontent.com/Architec-Ton/wallet-tma/refs/heads/dev/public/images/arcwallet_logo.png",about_url:"https://architecton.tech",universal_url:"https://t.me/architec_ton_bot?attach=wallet",bridge:[{type:"sse",url:"https://tc.architecton.su/bridge"}],platforms:["ios","android","macos","windows","linux"],features:[{name:"SendTransaction",maxMessages:255,extraCurrencySupported:!1}]},{app_name:"tokenpocket",name:"TokenPocket",image:"https://hk.tpstatic.net/logo/tokenpocket.png",about_url:"https://www.tokenpocket.pro",universal_url:"https://tp-lab.tptool.pro/ton-connect/",bridge:[{type:"js",key:"tokenpocket"},{type:"sse",url:"https://ton-connect.mytokenpocket.vip/bridge"}],platforms:["ios","android"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"uxuyWallet",name:"UXUY Wallet",image:"https://chain-cdn.uxuy.com/logo/square_288.png",about_url:"https://docs.uxuy.com",universal_url:"https://t.me/UXUYbot?attach=wallet",bridge:[{type:"sse",url:"https://bridge.uxuy.me/bridge"}],platforms:["ios","android","macos","windows","linux"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"tonkeeper-pro",name:"Tonkeeper Pro",image:"https://tonkeeper.com/assets/tonconnect-icon-pro.png",tondns:"tonkeeper.ton",about_url:"https://tonkeeper.com/pro",universal_url:"https://app.tonkeeper.com/pro/ton-connect",deepLink:"tonkeeper-pro-tc://",bridge:[{type:"sse",url:"https://bridge.tonapi.io/bridge"}],platforms:["ios","macos","windows","linux"],features:[{name:"SendTransaction",maxMessages:255,extraCurrencySupported:!0}
1,{name:"SignData",types:["text","binary","cell"]}]},{app_name:"nicegramWallet",name:"Nicegram Wallet",image:"https://static.nicegram.app/icon.png",about_url:"https://nicegram.app",universal_url:"https://nicegram.app/tc",deepLink:"nicegram-tc://",bridge:[{type:"sse",url:"https://tc.nicegram.app/bridge"},{type:"js",key:"nicegramWallet"}],platforms:["ios","android"],features:[{name:"SendTransaction",maxMessages:255,extraCurrencySupported:!1}]},{app_name:"echoooTonWallet",name:"EchoooWallet",image:"https://cdn.echooo.xyz/front-end/source/images/logo/echooo-ton.png",about_url:"https://www.echooo.xyz",universal_url:"https://www.echooo.xyz/ton-connect",deepLink:"echooo://",bridge:[{type:"js",key:"echoooTonWallet"},{type:"sse",url:"https://ton-connect-bridge.echooo.link/bridge"}],platforms:["ios","android"],features:[{name:"SendTransaction",maxMessages:255,extraCurrencySupported:!1}]},{app_name:"blitzwallet",name:"BLITZ wallet",image:"https://blitzwallet.cfd/wallet/public/logo.png",about_url:"https://blitzwallet.cfd",universal_url:"https://t.me/blitz_wallet_bot?attach=wallet",bridge:[{type:"sse",url:"https://blitzwallet.cfd/bridge/"}],platforms:["ios","android","macos","windows","linux"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]},{app_name:"koloWeb3Wallet",name:"Kolo",image:"https://raw.githubusercontent.com/onidev1/tc-assets/refs/heads/main/kolo_logo_288.png",about_url:"https://kolo.xyz",universal_url:"https://t.me/kolo?attach=wallet",bridge:[{type:"sse",url:"https://web3-bridge.kolo.in/bridge"}],platforms:["ios","android","macos","windows","linux"],features:[{name:"SendTransaction",maxMessages:255,extraCurrencySupported:!1}]},{app_name:"imToken",name:"imToken",image:"https://aws-v2-cdn.token.im/orbit/token-v2/icons/logo-ton-connect.png",about_url:"https://token.im",universal_url:"https://connect.token.im/link/ton-connect",deepLink:"imtokenv2://link/ton-connect",bridge:[{type:"sse",url:"https://connect.token.im/tonbridge"},{type:"js",key:"imToken"}],platforms:["ios","android"],features:[{name:"SendTransaction",maxMessages:255,extraCurrencySupported:!1}]},{app_name:"cactuslink",name:"Cactus Link",image:"https://downloads.mycactus.com/288_cactus_link.png",about_url:"https://www.mycactus.com/defi-connector",bridge:[{type:"js",key:"cactuslink_ton"}],platforms:["chrome"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1},{name:"SignData",types:["text","binary"]}]},{app_name:"onekey",name:"OneKey",image:"https://uni.onekey-asset.com/static/logo/onekey-x288.png",about_url:"https://onekey.so",bridge:[{type:"js",key:"onekeyTonWallet"}],platforms:["chrome"],features:[{name:"SendTransaction",maxMessages:4,extraCurrencySupported:!1}]}];class et{constructor(e){var t;this.walletsListDTOCache=null,this.walletsListDTOCacheCreationTimestamp=null,this.walletsListSource=null!=(t=null==e?void 0:e.walletsListSource)?t:"https://config.ton.org/wallets-v2.json",this.cacheTTLMs=null==e?void 0:e.cacheTTLMs}getWallets(){return o(this,void 0,void 0,function*(){let[e,t]=yield Promise.all([this.fetchWalletsListDTO(),this.getCurrentlyInjectedWallets()]);return this.mergeWalletsLists(this.walletConfigDTOListToWalletConfigList(e),t)})}getEmbeddedWallet(){return o(this,void 0,void 0,function*(){let e=(yield this.getWallets()).filter(Z);return 1===e.length?e[0]:null})}fetchWalletsListDTO(){return o(this,void 0,void 0,function*(){return this.cacheTTLMs&&this.walletsListDTOCacheCreationTimestamp&&Date.now()>this.walletsListDTOCacheCreationTimestamp+this.cacheTTLMs&&(this.walletsListDTOCache=null),this.walletsListDTOCache||(this.walletsListDTOCache=this.fetchWalletsListFromSource(),this.walletsListDTOCache.then(()=>{this.walletsListDTOCacheCreationTimestamp=Date.now()}).catch(()=>{this.walletsListDTOCache=null,this.walletsListDTOCacheCreationTimestamp=null})),this.walletsListDTOCache})}fetchWalletsListFromSource(){return o(this,void 0,void 0,function*(){let e=[];try{let t=yield fetch(this.walletsListSource);if(e=yield t.json(),!Array.isArray(e))throw new v("Wrong wallets list format, wallets list must be an array.");let n=e.filter(e=>!this.isCorrectWalletConfigDTO(e));n.length&&(B(`Wallet(s) ${n.map(e=>(null==e?void 0:e.name)||"unknown").join(", ")} config format is wrong. They were removed from the wallets list.`),e=e.filter(e=>this.isCorrectWalletConfigDTO(e)))}catch(t){B(t),e=ee}return e})}getCurrentlyInjectedWallets(){return[]}walletConfigDTOListToWalletConfigList(e){return e.map(e=>{let t={name:e.name,appName:e.app_name,imageUrl:e.image,aboutUrl:e.about_url,tondns:e.tondns,platforms:e.platforms,features:e.features};return e.bridge.forEach(n=>{if("sse"===n.type&&(t.bridgeUrl=n.url,t.universalLink=e.universal_url,t.deepLink=e.deepLink),"js"===n.type){let e=n.key;
1t.jsBridgeKey=e,t.injected=z.isWalletInjected(e),t.embedded=z.isInsideWalletBrowser(e)}}),t})}mergeWalletsLists(e,t){return[...new Set(e.concat(t).map(e=>e.name)).values()].map(n=>{let i=e.find(e=>e.name===n),r=t.find(e=>e.name===n);return Object.assign(Object.assign({},i&&Object.assign({},i)),r&&Object.assign({},r))})}isCorrectWalletConfigDTO(e){if(!e||"object"!=typeof e)return!1;let t="name"in e,n="app_name"in e,i="image"in e,r="about_url"in e,s="platforms"in e;if(!t||!i||!r||!s||!n||!e.platforms||!Array.isArray(e.platforms)||!e.platforms.length||!("bridge"in e)||!Array.isArray(e.bridge)||!e.bridge.length)return!1;let o=e.bridge;if(o.some(e=>!e||"object"!=typeof e||!("type"in e)))return!1;let a=o.find(e=>"sse"===e.type);if(a&&(!("object"==typeof a&&"url"in a)||!a.url||!e.universal_url))return!1;let l=o.find(e=>"js"===e.type);return!l||"object"==typeof l&&"key"in l&&!!l.key}}function en(e,t){var n,i,r;if("object"!=typeof t)return!0;let{sendTransaction:s,signData:o}=t;if(s){let t,r,o=ei(e,"SendTransaction");if(!o||(n=o,t=void 0===(i=s).minMessages||i.minMessages<=n.maxMessages,r=!i.extraCurrencyRequired||n.extraCurrencySupported,!t||!r))return!1}if(o){let t=ei(e,"SignData");if(!t||(r=t,!o.types.every(e=>r.types.includes(e))))return!1}return!0}function ei(e,t){return e.find(e=>e&&"object"==typeof e&&e.name===t)}function er(){return{type:"request-version"}}function es(e){return{type:"response-version",version:e}}function eo(e){return{ton_connect_sdk_lib:e.ton_connect_sdk_lib,ton_connect_ui_lib:e.ton_connect_ui_lib}}function ea(e,t){var n,i,r,s,o,a,l,c;let d=(null==(n=null==t?void 0:t.connectItems)?void 0:n.tonProof)&&"proof"in t.connectItems.tonProof;return{wallet_address:null!=(r=null==(i=null==t?void 0:t.account)?void 0:i.address)?r:null,wallet_type:null!=(s=null==t?void 0:t.device.appName)?s:null,wallet_version:null!=(o=null==t?void 0:t.device.appVersion)?o:null,auth_type:d?"ton_proof":"ton_addr",custom_data:Object.assign({chain_id:null!=(l=null==(a=null==t?void 0:t.account)?void 0:a.chain)?l:null,provider:null!=(c=null==t?void 0:t.provider)?c:null},eo(e))}}function el(e){return{type:"connection-started",custom_data:eo(e)}}function ec(e,t){return Object.assign({type:"connection-completed",is_success:!0},ea(e,t))}function ed(e,t,n){return{type:"connection-error",is_success:!1,error_message:t,error_code:null!=n?n:null,custom_data:eo(e)}}function eu(e){return{type:"connection-restoring-started",custom_data:eo(e)}}function ep(e,t){return Object.assign({type:"connection-restoring-completed",is_success:!0},ea(e,t))}function eh(e,t){return{type:"connection-restoring-error",is_success:!1,error_message:t,custom_data:eo(e)}}function eg(e,t){var n,i,r,s;return{valid_until:null!=(n=String(t.validUntil))?n:null,from:null!=(s=null!=(i=t.from)?i:null==(r=null==e?void 0:e.account)?void 0:r.address)?s:null,messages:t.messages.map(e=>{var t,n;return{address:null!=(t=e.address)?t:null,amount:null!=(n=e.amount)?n:null}})}}function em(e,t,n){return Object.assign(Object.assign({type:"transaction-sent-for-signature"},ea(e,t)),eg(t,n))}function ef(e,t,n,i){return Object.assign(Object.assign({type:"transaction-signed",is_success:!0,signed_transaction:i.boc},ea(e,t)),eg(t,n))}function ey(e,t,n,i,r){return Object.assign(Object.assign({type:"transaction-signing-failed",is_success:!1,error_message:i,error_code:null!=r?r:null},ea(e,t)),eg(t,n))}function ew(e,t,n){return Object.assign({type:"sign-data-request-initiated",data:n},ea(e,t))}function ev(e,t,n,i){return Object.assign({type:"sign-data-request-completed",is_success:!0,data:n,signed_data:i},ea(e,t))}function eb(e,t,n,i,r){return Object.assign({type:"sign-data-request-failed",is_success:!1,data:n,error_message:i,error_code:null!=r?r:null},ea(e,t))}function eS(e,t,n){return Object.assign({type:"disconnection",scope:n},ea(e,t))}class e_{constructor(){this.window=J()}dispatchEvent(e,t){return o(this,void 0,void 0,function*(){var n;let i=new CustomEvent(e,{detail:t});null==(n=this.window)||n.dispatchEvent(i)})}addEventListener(e,t,n){return o(this,void 0,void 0,function*(){var i;return null==(i=this.window)||i.addEventListener(e,t,n),()=>{var n;return null==(n=this.window)?void 0:n.removeEventListener(e,t)}})}}class eC{get version(){return eo({ton_connect_sdk_lib:this.tonConnectSdkVersion,ton_connect_ui_lib:this.tonConnectUiVersion})}constructor(e){var t;this.eventPrefix="ton-connect-",this.tonConnectUiVersion=null,this.eventDispatcher=null!=(t=null==e?void 0:e.eventDispatcher)?t:new e_,this.tonConnectSdkVersion=e.tonConnectSdkVersion,this.init().catch()}init(){return o(this,void 0,void 0,function*(){try{yield this.setRequestVersionHandler(),this.tonConnectUiVersion=yield this.requestTonConnectUiVersion()}catch(e){}})}setRequestVersionHandler(){return o(this,void 0,void 0,function*(){yield this.eventDispatcher.addEventListener("ton-connect-request-version",()=>o(this,void 0,void 0,function*(){yield this.eventDispatcher.dispatchEvent("ton-connect-response-version",es(this.tonConnectSdkVersion))}))})}requestTonConnectUiVersion(){return o(this,void 0,void 0,function*(){return new Promise((e,t)=>
1o(this,void 0,void 0,function*(){try{yield this.eventDispatcher.addEventListener("ton-connect-ui-response-version",t=>{e(t.detail.version)},{once:!0}),yield this.eventDispatcher.dispatchEvent("ton-connect-ui-request-version",er())}catch(e){t(e)}}))})}dispatchUserActionEvent(e){try{this.eventDispatcher.dispatchEvent(`${this.eventPrefix}${e.type}`,e).catch()}catch(e){}}trackConnectionStarted(...e){try{let t=el(this.version,...e);this.dispatchUserActionEvent(t)}catch(e){}}trackConnectionCompleted(...e){try{let t=ec(this.version,...e);this.dispatchUserActionEvent(t)}catch(e){}}trackConnectionError(...e){try{let t=ed(this.version,...e);this.dispatchUserActionEvent(t)}catch(e){}}trackConnectionRestoringStarted(...e){try{let t=eu(this.version,...e);this.dispatchUserActionEvent(t)}catch(e){}}trackConnectionRestoringCompleted(...e){try{let t=ep(this.version,...e);this.dispatchUserActionEvent(t)}catch(e){}}trackConnectionRestoringError(...e){try{let t=eh(this.version,...e);this.dispatchUserActionEvent(t)}catch(e){}}trackDisconnection(...e){try{let t=eS(this.version,...e);this.dispatchUserActionEvent(t)}catch(e){}}trackTransactionSentForSignature(...e){try{let t=em(this.version,...e);this.dispatchUserActionEvent(t)}catch(e){}}trackTransactionSigned(...e){try{let t=ef(this.version,...e);this.dispatchUserActionEvent(t)}catch(e){}}trackTransactionSigningFailed(...e){try{let t=ey(this.version,...e);this.dispatchUserActionEvent(t)}catch(e){}}trackDataSentForSignature(...e){try{let t=ew(this.version,...e);this.dispatchUserActionEvent(t)}catch(e){}}trackDataSigned(...e){try{let t=ev(this.version,...e);this.dispatchUserActionEvent(t)}catch(e){}}trackDataSigningFailed(...e){try{let t=eb(this.version,...e);this.dispatchUserActionEvent(t)}catch(e){}}}function ek(e,t=!1){let{wc:n,hex:r}=eT(e),s=81;t&&(s|=128);let o=new Int8Array(34);o[0]=s,o[1]=n,o.set(r,2);let a=new Uint8Array(36);return a.set(o),a.set(eR(o),34),i.o4.encode(a).replace(/\+/g,"-").replace(/\//g,"_")}function ex(e){try{return function(e){let t,n=e.replace(/-/g,"+").replace(/_/g,"/");try{t=i.o4.decode(n).toUint8Array()}catch(t){throw new b(`Invalid base64 encoding in address: ${e}`)}if(36!==t.length)throw new b(`Invalid address length: ${e}`);let r=t.slice(0,34),s=t.slice(34,36),o=eR(r);if(!s.every((e,t)=>e===o[t]))throw new b(`Invalid checksum in address: ${e}`);let a=r[0];if(128&a&&(a^=128),17!==a&&81!==a)throw new b(`Unknown address tag: ${a}`);let l=null;l=255===r[1]?-1:r[1];let c=r.slice(2);if(0!==l&&-1!==l)throw new b(`Invalid workchain: ${l}`);Array.from(c).map(e=>e.toString(16).padStart(2,"0")).join("")}(e),!0}catch(e){return!1}}function eT(e){if(!e.includes(":"))throw new b(`Wrong address ${e}. Address must include ":".`);let t=e.split(":");if(2!==t.length)throw new b(`Wrong address ${e}. Address must include ":" only once.`);let n=parseInt(t[0]);if(0!==n&&-1!==n)throw new b(`Wrong address ${e}. WC must be eq 0 or -1, but ${n} received.`);let i=t[1];if((null==i?void 0:i.length)!==64)throw new b(`Wrong address ${e}. Hex part must be 64bytes length, but ${null==i?void 0:i.length} received.`);return{wc:n,hex:function(e){let t=(e=e.toLowerCase()).length;if(t%2!=0)throw new S("Hex string must have length a multiple of 2: "+e);let n=t/2,i=new Uint8Array(n);for(let t=0;t<n;t++){let n=2*t,r=e.substring(n,n+2);if(!eE.hasOwnProperty(r))throw new S("Invalid hex character: "+r);i[t]=eE[r]}return i}(i)}}function eR(e){let t=0,n=new Uint8Array(e.length+2);for(let i of(n.set(e),n)){let e=128;for(;e>0;)t<<=1,i&e&&(t+=1),e>>=1,t>65535&&(t&=65535,t^=4129)}return new Uint8Array([Math.floor(t/256),t%256])}let eE={};for(let e=0;e<=255;e++){let t=e.toString(16);t.length<2&&(t="0"+t),eE[t]=e}let eO=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,ej=/^[A-Za-z0-9\-_]+$/,eI=/^-?\d+$/,eW=/^\d+$/;function eq(e){return"number"==typeof e&&!isNaN(e)}function eP(e){return"string"==typeof e&&e.length>0}function eL(e){return eP(e)&&(function(e){try{return eT(e),!0}catch(e){return!1}}(e)||ex(e))}function eD(e){return eP(e)&&/^-?\d+$/.test(e)}function eM(e){return"string"==typeof e&&(eO.test(e)||ej.test(e))&&e.startsWith("te6cc")}function eA(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function eU(e,t){return Object.keys(e).some(e=>!t.includes(e))}function eN(e){if("string"!=typeof e)return;let t=e.length+(4-e.length%4)%4;return e.replace(/-/g,"+").replace(/_/g,"/").padEnd(t,"=")}class eB{static getWallets(){return this.walletsList.getWallets()}get connected(){return null!==this._wallet}get account(){var e;return(null==(e=this._wallet)?void 0:e.account)||null}get wallet(){return this._wallet}set wallet(e){this._wallet=e,this.statusChangeSubscriptions.forEach(e
1=>e(this._wallet))}constructor(e){if(this.walletsList=new et,this._wallet=null,this.provider=null,this.statusChangeSubscriptions=[],this.statusChangeErrorSubscriptions=[],this.dappSettings={manifestUrl:(null==e?void 0:e.manifestUrl)||function(){var e;let t=null==(e=J())?void 0:e.location.origin;return t?t+"/tonconnect-manifest.json":""}(),storage:(null==e?void 0:e.storage)||new X},this.walletsRequiredFeatures=null==e?void 0:e.walletsRequiredFeatures,this.walletsList=new et({walletsListSource:null==e?void 0:e.walletsListSource,cacheTTLMs:null==e?void 0:e.walletsListCacheTTLMs}),this.tracker=new eC({eventDispatcher:null==e?void 0:e.eventDispatcher,tonConnectSdkVersion:"3.3.1"}),!this.dappSettings.manifestUrl)throw new l("Dapp tonconnect-manifest.json must be specified if window.location.origin is undefined. See more https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest");this.bridgeConnectionStorage=new G(this.dappSettings.storage),(null==e?void 0:e.disableAutoPauseConnection)||this.addWindowFocusAndBlurSubscriptions()}getWallets(){return this.walletsList.getWallets()}onStatusChange(e,t){return this.statusChangeSubscriptions.push(e),t&&this.statusChangeErrorSubscriptions.push(t),()=>{this.statusChangeSubscriptions=this.statusChangeSubscriptions.filter(t=>t!==e),t&&(this.statusChangeErrorSubscriptions=this.statusChangeErrorSubscriptions.filter(e=>e!==t))}}connect(e,t){var n,i;let r={};if("object"==typeof t&&"tonProof"in t&&(r.request=t),"object"==typeof t&&("openingDeadlineMS"in t||"signal"in t||"request"in t)&&(r.request=null==t?void 0:t.request,r.openingDeadlineMS=null==t?void 0:t.openingDeadlineMS,r.signal=null==t?void 0:t.signal),r.request){let e=function(e){if(!eA(e))return"Request must be an object";if(eU(e,["tonProof"]))return"Request contains extra properties";if(void 0!==e.tonProof){if("string"!=typeof e.tonProof)return"Invalid 'tonProof'";let t=e.tonProof;if(0===t.length)return"Empty 'tonProof' payload";let n=function(){try{if("undefined"!=typeof window&&window.location)return window.location.hostname;return null}catch(e){return null}}();if(!n)return null;let i=new TextEncoder().encode(n).length;if(i>128)return"Current domain exceeds 128 bytes limit";let r=new TextEncoder().encode(t).length;if(r>128)return"'tonProof' payload exceeds 128 bytes limit";if(i+r>222)return"'tonProof' domain + payload exceeds 222 bytes limit"}return null}(r.request);if(e)if(1)throw new a("ConnectAdditionalRequest validation failed: "+e);else console.error("ConnectAdditionalRequest validation failed: "+e)}if(this.connected)throw new u;let s=A(null==r?void 0:r.signal);if(null==(n=this.abortController)||n.abort(),this.abortController=s,s.signal.aborted)throw new a("Connection was aborted");return null==(i=this.provider)||i.closeConnection(),this.provider=this.createProvider(e),s.signal.addEventListener("abort",()=>{var e;null==(e=this.provider)||e.closeConnection(),this.provider=null}),this.tracker.trackConnectionStarted(),this.provider.connect(this.createConnectRequest(null==r?void 0:r.request),{openingDeadlineMS:null==r?void 0:r.openingDeadlineMS,signal:s.signal})}restoreConnection(e){return o(this,void 0,void 0,function*(){var t,n;this.tracker.trackConnectionRestoringStarted();let i=A(null==e?void 0:e.signal);if(null==(t=this.abortController)||t.abort(),this.abortController=i,i.signal.aborted)return void this.tracker.trackConnectionRestoringError("Connection restoring was aborted");let[r,s]=yield Promise.all([this.bridgeConnectionStorage.storedConnectionType(),this.walletsList.getEmbeddedWallet()]);if(i.signal.aborted)return void this.tracker.trackConnectionRestoringError("Connection restoring was aborted");let a=null;try{switch(r){case"http":a=yield F.fromStorage(this.dappSettings.storage);break;case"injected":a=yield z.fromStorage(this.dappSettings.storage);break;default:if(!s)return;a=this.createProvider(s)}}catch(e){this.tracker.trackConnectionRestoringError("Provider is not restored"),yield this.bridgeConnectionStorage.removeConnection(),null==a||a.closeConnection(),a=null;return}if(i.signal.aborted){null==a||a.closeConnection(),this.tracker.trackConnectionRestoringError("Connection restoring was aborted");return}if(!a){B("Provider is not restored"),this.tracker.trackConnectionRestoringError("Provider is not restored");return}null==(n=this.provider)||n.closeConnection(),this.provider=a,a.listen(this.walletEventsListener.bind(this));let l=()=>{this.tracker.trackConnectionRestoringError("Connection restoring was aborted"),null==a||a.closeConnection(),a=null};return i.signal.addEventListener("abort",l),Promise.race([U(t=>o(this,void 0,void 0,function*(){yield null==a?void 0:a.restoreConnection({openingDeadlineMS:null==e?void 0:e.openingDeadlineMS,signal:t.signal}),i.signal.removeEventListener("abort",l),this.connected?this.tracker.trackConnectionRestoringCompleted(this.wallet):this.tracker.trackConnectionRestoringError("Connection restoring failed")}),{attempts:Number.MAX_SAFE_INTEGER,delayMs:2e3,signal:null==e?void 0:e.signal}),new Promise(e=>setTimeout(()=>e(),12e3))])})}sendTransaction(e,t){return o(this,void 0,void 0,function*(){let n={};"function"==typeof t?n.onRequestSent=t:(n.onRequestSent=null==t?void 0:t.onRequestSent,n.signal=null==t?void 0:t.signal);let i=function(e){if(!eA(e))return"Request must be an object";if(eU(e,["validUntil","network","from","messages"]))return"Request contains extra properties";if(e.validUntil){if(!eq(e.validUntil))return"Incorrect 'validUntil'";let t=Math.floor(Date.now()/1e3);e.validUntil>t+300&&console.warn(`validUntil (${e.validUntil}) is more than 5 minutes from now (${t})`)}if(void 0!==e.network&&!eD(e.network))return"Invalid 'network' format";if(void 0!==e.from&&!eL(e.from))return"Invalid 'from' address format";if(!Array.isArray(e.messages)||0===e.messages.length)return"'messages' is required";for(let t=0;t<e.messages.length;t++){let n=function(e,t){if(!eA(e))return`Message at index ${t} must be an object`;if(eU(e,["address","amount","stateInit","payload","extraCurrency"]))return`Message at index ${t} contains extra properties`;if(!eP(e.address))return`'address' is required in message at index ${t}`;if(!ex(e.address))return`Wrong 'address' format in message at index ${t}`;if(!eP(e.amount))return`'amount' is required in message at index ${t}`;if(!/^[0-9]+$/.test(e.amount))return`Incorrect 'amount' in message at index ${t}`;if(void 0!==e.stateInit&&(!eP(e.stateInit)||!eM(e.stateInit)))return`Invalid 'stateInit' in message at index ${t}`;if(void 0!==e.payload&&(!eP(e.payload)||!eM(e.payload)))return`Invalid 'payload' in message at index ${t}`;if(void 0!==e.extraCurrency){if(!eA(e.extraCurrency))return`Invalid 'extraCurrency' in message at index ${t}`;for(let[n,i]of Object.entries(e.extraCurrency))if(!eI.test(n)||"string"!=typeof i||!eW.test(i))return`Invalid 'extraCurrency' format in message at index ${t}`}return null}(e.messages[t],t);if(n)return n}return null}(e);if(i)if(1)throw new a("SendTransactionRequest validation failed: "+i);else console.error("SendTransactionRequest validation failed: "+i);let r=A(null==n?void 0:n.signal);if(r.signal.aborted)throw new a("Transaction sending was aborted");this.checkConnection();let o=e.messages.length,l=e.messages.some(e=>e.extraCurrency&&Object.keys(e.extraCurrency).length>0);!function(e,t){let n=e.includes("SendTransaction"),i=ei(e,"SendTransaction"),r={minMessages:t.requiredMessagesNumber,extraCurrencyRequired:t.requireExtraCurrencies};if(!n&&!i)throw new g("Wallet doesn't support SendTransaction feature.",{cause:{requiredFeature:{featureName:"SendTransaction",value:r}}});if(t.requireExtraCurrencies&&(!i||!i.extraCurrencySupported))throw new g("Wallet is not able to handle such SendTransaction request. Extra currencies support is required.",{cause:{requiredFeature:{featureName:"SendTransaction",value:r}}});if(i&&void 0!==i.maxMessages){if(i.maxMessages<t.requiredMessagesNumber)throw new g(`Wallet is not able to handle such SendTransaction request. Max support messages number is ${i.maxMessages}, but ${t.requiredMessagesNumber} is required.`,{cause:{requiredFeature:{featureName:"SendTransaction",value:r}}});return}!function(...e){try{console.warn("[TON_CONNECT_SDK]",...e)}catch(e){}}("Connected wallet didn't provide information about max allowed messages in the SendTransaction request. Request may be rejected by the wallet.")}(this.wallet.device.features,{requiredMessagesNumber:o,requireExtraCurrencies:l}),this.tracker.trackTransactionSentForSignature(this.wallet,e);let{validUntil:c,messages:d}=e,u=s(e,["validUntil","messages"]),p=e.from||this.account.address,h=e.network||this.account.chain,m=yield this.provider.sendRequest(O.convertToRpcRequest(Object.assign(Object.assign({},u),{from:p,network:h,valid_until:c,messages:d.map(e=>{var{extraCurrency:t,payload:n,stateInit:i}=e;return Object.assign(Object.assign({},s(e,["extraCurrency","payload","stateInit"])),{payload:eN(n),stateInit:eN(i),extra_currency:t})})})),{onRequestSent:n.onRequestSent,signal:r.signal});if(O.isError(m))return this.tracker.trackTransactionSigningFailed(this.wallet,e,m.error.message,m.error.code),O.parseAndThrowError(m);let f=O.convertFromRpcResponse(m);return this.tracker.trackTransactionSigned(this.wallet,e,f),f})}signData(e,t){return o(this,void 0,void 0,function*(){let n=A(null==t?void 0:t.signal);if(n.signal.aborted)throw new a("data sending was aborted");let i=function(e){var t,n,i;if(!eA(e))return"Payload must be an object";if(!eP(e.type))return"'type' is required";switch(e.type){case"text":return eU(t=e,["type","text","network","from"])?"Text payload contains extra properties":eP(t.text)?void 0===t.network||eD(t.network)?void 0===t.from||eL(t.from)?null:"Invalid 'from'":"Invalid 'network' format":"'text' is required";case"binary":return eU(n=e,["type","bytes","network","from"])?"Binary payload contains extra properties":eP(n.bytes)?void 0===n.network||eD(n.network)?void 0===n.from||eL(n.from)?null:"Invalid 'from'":"Invalid 'network' format":"'bytes' is required";case"cell":return eU(i=e,["type","schema","cell","network","from"])?"Cell payload contains extra properties":eP(i.schema)?eP(i.cell)?eM(i.cell)?void 0===i.network||eD(i.network)?void 0===i.from||eL(i.from)?null:"Invalid 'from'":"Invalid 'network' format":"Invalid 'cell' format (must be valid base64)":"'cell' is required":"'schema' is required";default:return"Invalid 'type' value"}}(e);if(i)if(1)throw new a("SignDataPayload validation failed: "+i);else console.error("SignDataPayload validation failed: "+i);this.checkConnection(),function(e,t){let n=e.find(e=>e&&"object"==typeof e&&"SignData"===e.name);if(!n)throw new g("Wallet doesn't support SignData feature.",{cause:{requiredFeature:{featureName:"SignData",value:{types:t.requiredTypes}}}});let i=t.requiredTypes.filter(e=>!n.types.includes(e));if(i.length)throw new g(`Wallet doesn't support required SignData types: ${i.join(", ")}.`,{cause:{requiredFeature:{featureName:"SignData",value:{types:i}}}})}(this.wallet.device.features,{requiredTypes:[e.type]}),this.tracker.trackDataSentForSignature(this.wallet,e);let r=e.from||this.account.address,s=e.network||this.account.chain,o=yield this.provider.sendRequest(W.convertToRpcRequest(Object.assign(Object.assign(Object.assign({},e),"cell"===e.type?{cell:eN(e.cell)}:{}),{from:r,network:s})),{onRequestSent:null==t?void 0:t.onRequestSent,signal:n.signal});if(W.isError(o))return this.tracker.trackDataSigningFailed(this.wallet,e,o.error.message,o.error.code),W.parseAndThrowError(o);let l=W.convertFromRpcResponse(o);return this.tracker.trackDataSigned(this.wallet,e,l),l})}disconnect(e){return o(this,void 0,void 0,function*(){var t;if(!this.connected)throw new p;let n=A(null==e?void 0:e.signal),i=this.abortController;if(this.abortController=n,n.signal.aborted)throw new a("Disconnect was aborted");this.onWalletDisconnected("dapp"),yield null==(t=this.provider)?void 0:t.disconnect({signal:n.signal}),null==i||i.abort()})}getSessionId(){return o(this,void 0,void 0,function*(){if(!this.provider||!this.connected)return null;try{let e=yield this.bridgeConnectionStorage.getConnection();if(!e||"injected"===e.type)return null;if("sessionCrypto"in e)return e.sessionCrypto.sessionId;return e.session.sessionCrypto.sessionId}catch(e){return null}})}pauseConnection(){var e;(null==(e=this.provider)?void 0:e.type)==="http"&&this.provider.pause()}unPauseConnection(){var e;return(null==(e=this.provider)?void 0:e.type)!=="http"?Promise.resolve():this.provider.unPause()}addWindowFocusAndBlurSubscriptions(){let e=function(){if("undefined"!=typeof document)return document}();if(e)try{e.addEventListener("visibilitychange",()=>{e.hidden?this.pauseConnection():this.unPauseConnection().catch(()=>{})})}catch(e){B("Cannot subscribe to the document.visibilitychange: ",e)}}createProvider(e){let t;return(t=!Array.isArray(e)&&"jsBridgeKey"in e?new z(this.dappSettings.storage,e.
1jsBridgeKey):new F(this.dappSettings.storage,e)).listen(this.walletEventsListener.bind(this)),t}walletEventsListener(e){switch(e.event){case"connect":this.onWalletConnected(e.payload);break;case"connect_error":this.tracker.trackConnectionError(e.payload.message,e.payload.code);let t=x.parseError(e.payload);this.onWalletConnectError(t);break;case"disconnect":this.onWalletDisconnected("wallet")}}onWalletConnected(e){var t;let n=e.items.find(e=>"ton_addr"===e.name),r=e.items.find(e=>"ton_proof"===e.name);if(!n)throw new a("ton_addr connection item was not found");if(!en(e.device.features,this.walletsRequiredFeatures)){null==(t=this.provider)||t.disconnect(),this.onWalletConnectError(new m("Wallet does not support required features",{cause:{connectEvent:e}}));return}let s={device:e.device,provider:this.provider.type,account:{address:n.address,chain:n.network,walletStateInit:n.walletStateInit,publicKey:n.publicKey}};if(r){let e,t=function(e){if(!eA(e))return"ton_proof item must be an object";if(eU(e,["error","proof","name"]))return"ton_proof item contains extra properties";let t=Object.prototype.hasOwnProperty.call(e,"proof"),n=Object.prototype.hasOwnProperty.call(e,"error");if(!t&&!n)return"'ton_proof' item must contain either 'proof' or 'error'";if(t&&n)return"'ton_proof' item must contain either 'proof' or 'error', not both";if(t){let t=e.proof;if(!eA(t))return"Invalid 'proof' object";if(eU(t,["timestamp","domain","payload","signature"]))return"ton_proof item contains extra properties";if(!eq(t.timestamp))return"Invalid 'proof.timestamp'";let n=t.domain;if(!eA(n))return"Invalid 'proof.domain'";if(!eq(n.lengthBytes))return"Invalid 'proof.domain.lengthBytes'";if(!eP(n.value))return"Invalid 'proof.domain.value'";try{if(("undefined"!=typeof TextEncoder?new TextEncoder().encode(n.value).length:n.value.length)!==n.lengthBytes)return"'proof.domain.lengthBytes' does not match 'proof.domain.value'"}catch(e){}if(!eP(t.payload))return"Invalid 'proof.payload'";if(!eP(t.signature)||!eO.test(t.signature))return"Invalid 'proof.signature' format"}if(n){let t=e.error;if(!eA(t))return"Invalid 'error' object";if(eU(t,["code","message"]))return"ton_proof error contains extra properties";if(!eq(t.code))return"Invalid 'error.code'";if(!eP(t.message))return"Invalid 'error.message'"}return null}(r);if(t)e={name:"ton_proof",error:{code:i.F2.UNKNOWN_ERROR,message:t}};else try{if("proof"in r)e={name:"ton_proof",proof:{timestamp:r.proof.timestamp,domain:{lengthBytes:r.proof.domain.lengthBytes,value:r.proof.domain.value},payload:r.proof.payload,signature:r.proof.signature}};else if("error"in r)e={name:"ton_proof",error:{code:r.error.code,message:r.error.message}};else throw new a("Invalid data format")}catch(t){e={name:"ton_proof",error:{code:i.F2.UNKNOWN_ERROR,message:"Invalid data format"}}}s.connectItems={tonProof:e}}this.wallet=s,this.tracker.trackConnectionCompleted(s)}onWalletConnectError(e){if(this.statusChangeErrorSubscriptions.forEach(t=>t(e)),N(e),e instanceof d||e instanceof c)throw B(e),e}onWalletDisconnected(e){this.tracker.trackDisconnection(this.wallet,e),this.wallet=null}checkConnection(){if(!this.connected)throw new p}createConnectRequest(e){let t=[{name:"ton_addr"}];return(null==e?void 0:e.tonProof)&&t.push({name:"ton_proof",payload:e.tonProof}),{manifestUrl:this.dappSettings.manifestUrl,items:t}}}eB.walletsList=new et,eB.isWalletInjected=e=>z.isWalletInjected(e),eB.isInsideWalletBrowser=e=>z.isInsideWalletBrowser(e)}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.