UNPKG

@tonconnect/ui

Version:

TonConnect UI is a UI kit for TonConnect SDK. Use it to connect your app to TON wallets via TonConnect protocol.

1 lines 423 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TON_CONNECT_UI={})}(this,function(e){"use strict";var t,n,r,o,i,a,s,l,c=Object.defineProperty,d=Object.defineProperties,u=Object.getOwnPropertyDescriptors,h=Object.getOwnPropertySymbols,p=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable,f=(e,t,n)=>t in e?c(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,m=(e,t)=>{for(var n in t||(t={}))p.call(t,n)&&f(e,n,t[n]);if(h)for(var n of h(t))g.call(t,n)&&f(e,n,t[n]);return e},w=(e,t)=>d(e,u(t)),v=(e,t)=>{var n={};for(var r in e)p.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&h)for(var r of h(e))t.indexOf(r)<0&&g.call(e,r)&&(n[r]=e[r]);return n},y=(e,t,n)=>new Promise((r,o)=>{var i=e=>{try{s(n.next(e))}catch(Gr){o(Gr)}},a=e=>{try{s(n.throw(e))}catch(Gr){o(Gr)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(i,a);s((n=n.apply(e,t)).next())});function b(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function C(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var n=function e(){var n=!1;try{n=this instanceof e}catch(r){}return n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}),n}var x,S,k,_,E={exports:{}};const R=b((x||(x=1,k=E.exports,_=function(){var e={};function t(e){if(!/^(?:[A-Za-z0-9+\/]{2}[A-Za-z0-9+\/]{2})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(e))throw new TypeError("invalid encoding")}return e.decodeUTF8=function(e){if("string"!=typeof e)throw new TypeError("expected string");var t,n=unescape(encodeURIComponent(e)),r=new Uint8Array(n.length);for(t=0;t<n.length;t++)r[t]=n.charCodeAt(t);return r},e.encodeUTF8=function(e){var t,n=[];for(t=0;t<e.length;t++)n.push(String.fromCharCode(e[t]));return decodeURIComponent(escape(n.join("")))},"undefined"==typeof atob?void 0!==Buffer.from?(e.encodeBase64=function(e){return Buffer.from(e).toString("base64")},e.decodeBase64=function(e){return t(e),new Uint8Array(Array.prototype.slice.call(Buffer.from(e,"base64"),0))}):(e.encodeBase64=function(e){return new Buffer(e).toString("base64")},e.decodeBase64=function(e){return t(e),new Uint8Array(Array.prototype.slice.call(new Buffer(e,"base64"),0))}):(e.encodeBase64=function(e){var t,n=[],r=e.length;for(t=0;t<r;t++)n.push(String.fromCharCode(e[t]));return btoa(n.join(""))},e.decodeBase64=function(e){t(e);var n,r=atob(e),o=new Uint8Array(r.length);for(n=0;n<r.length;n++)o[n]=r.charCodeAt(n);return o}),e},(S=E).exports?S.exports=_():(k.nacl||(k.nacl={}),k.nacl.util=_())),E.exports));function T(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var I={exports:{}};const O=C(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var M;var A=(M||(M=1,function(e){!function(e){var t=function(e){var t,n=new Float64Array(16);if(e)for(t=0;t<e.length;t++)n[t]=e[t];return n},n=function(){throw new Error("no PRNG")},r=new Uint8Array(16),o=new Uint8Array(32);o[0]=9;var i=t(),a=t([1]),s=t([56129,1]),l=t([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),c=t([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),d=t([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),u=t([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),h=t([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function p(e,t,n,r){e[t]=n>>24&255,e[t+1]=n>>16&255,e[t+2]=n>>8&255,e[t+3]=255&n,e[t+4]=r>>24&255,e[t+5]=r>>16&255,e[t+6]=r>>8&255,e[t+7]=255&r}function g(e,t,n,r,o){var i,a=0;for(i=0;i<o;i++)a|=e[t+i]^n[r+i];return(1&a-1>>>8)-1}function f(e,t,n,r){return g(e,t,n,r,16)}function m(e,t,n,r){return g(e,t,n,r,32)}function w(e,t,n,r){!function(e,t,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,a=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,s=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,l=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,c=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,d=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,u=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,h=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,p=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,g=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,f=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,m=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,w=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,v=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,y=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,b=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,C=i,x=a,S=s,k=l,_=c,E=d,R=u,T=h,I=p,O=g,M=f,A=m,L=w,N=v,W=y,P=b,U=0;U<20;U+=2)C^=(o=(L^=(o=(I^=(o=(_^=(o=C+L|0)<<7|o>>>25)+C|0)<<9|o>>>23)+_|0)<<13|o>>>19)+I|0)<<18|o>>>14,E^=(o=(x^=(o=(N^=(o=(O^=(o=E+x|0)<<7|o>>>25)+E|0)<<9|o>>>23)+O|0)<<13|o>>>19)+N|0)<<18|o>>>14,M^=(o=(R^=(o=(S^=(o=(W^=(o=M+R|0)<<7|o>>>25)+M|0)<<9|o>>>23)+W|0)<<13|o>>>19)+S|0)<<18|o>>>14,P^=(o=(A^=(o=(T^=(o=(k^=(o=P+A|0)<<7|o>>>25)+P|0)<<9|o>>>23)+k|0)<<13|o>>>19)+T|0)<<18|o>>>14,C^=(o=(k^=(o=(S^=(o=(x^=(o=C+k|0)<<7|o>>>25)+C|0)<<9|o>>>23)+x|0)<<13|o>>>19)+S|0)<<18|o>>>14,E^=(o=(_^=(o=(T^=(o=(R^=(o=E+_|0)<<7|o>>>25)+E|0)<<9|o>>>23)+R|0)<<13|o>>>19)+T|0)<<18|o>>>14,M^=(o=(O^=(o=(I^=(o=(A^=(o=M+O|0)<<7|o>>>25)+M|0)<<9|o>>>23)+A|0)<<13|o>>>19)+I|0)<<18|o>>>14,P^=(o=(W^=(o=(N^=(o=(L^=(o=P+W|0)<<7|o>>>25)+P|0)<<9|o>>>23)+L|0)<<13|o>>>19)+N|0)<<18|o>>>14;C=C+i|0,x=x+a|0,S=S+s|0,k=k+l|0,_=_+c|0,E=E+d|0,R=R+u|0,T=T+h|0,I=I+p|0,O=O+g|0,M=M+f|0,A=A+m|0,L=L+w|0,N=N+v|0,W=W+y|0,P=P+b|0,e[0]=C>>>0&255,e[1]=C>>>8&255,e[2]=C>>>16&255,e[3]=C>>>24&255,e[4]=x>>>0&255,e[5]=x>>>8&255,e[6]=x>>>16&255,e[7]=x>>>24&255,e[8]=S>>>0&255,e[9]=S>>>8&255,e[10]=S>>>16&255,e[11]=S>>>24&255,e[12]=k>>>0&255,e[13]=k>>>8&255,e[14]=k>>>16&255,e[15]=k>>>24&255,e[16]=_>>>0&255,e[17]=_>>>8&255,e[18]=_>>>16&255,e[19]=_>>>24&255,e[20]=E>>>0&255,e[21]=E>>>8&255,e[22]=E>>>16&255,e[23]=E>>>24&255,e[24]=R>>>0&255,e[25]=R>>>8&255,e[26]=R>>>16&255,e[27]=R>>>24&255,e[28]=T>>>0&255,e[29]=T>>>8&255,e[30]=T>>>16&255,e[31]=T>>>24&255,e[32]=I>>>0&255,e[33]=I>>>8&255,e[34]=I>>>16&255,e[35]=I>>>24&255,e[36]=O>>>0&255,e[37]=O>>>8&255,e[38]=O>>>16&255,e[39]=O>>>24&255,e[40]=M>>>0&255,e[41]=M>>>8&255,e[42]=M>>>16&255,e[43]=M>>>24&255,e[44]=A>>>0&255,e[45]=A>>>8&255,e[46]=A>>>16&255,e[47]=A>>>24&255,e[48]=L>>>0&255,e[49]=L>>>8&255,e[50]=L>>>16&255,e[51]=L>>>24&255,e[52]=N>>>0&255,e[53]=N>>>8&255,e[54]=N>>>16&255,e[55]=N>>>24&255,e[56]=W>>>0&255,e[57]=W>>>8&255,e[58]=W>>>16&255,e[59]=W>>>24&255,e[60]=P>>>0&255,e[61]=P>>>8&255,e[62]=P>>>16&255,e[63]=P>>>24&255}(e,t,n,r)}function v(e,t,n,r){!function(e,t,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,a=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,s=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,l=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,c=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,d=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,u=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,h=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,p=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,g=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,f=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,m=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,w=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,v=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,y=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,b=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,C=0;C<20;C+=2)i^=(o=(w^=(o=(p^=(o=(c^=(o=i+w|0)<<7|o>>>25)+i|0)<<9|o>>>23)+c|0)<<13|o>>>19)+p|0)<<18|o>>>14,d^=(o=(a^=(o=(v^=(o=(g^=(o=d+a|0)<<7|o>>>25)+d|0)<<9|o>>>23)+g|0)<<13|o>>>19)+v|0)<<18|o>>>14,f^=(o=(u^=(o=(s^=(o=(y^=(o=f+u|0)<<7|o>>>25)+f|0)<<9|o>>>23)+y|0)<<13|o>>>19)+s|0)<<18|o>>>14,b^=(o=(m^=(o=(h^=(o=(l^=(o=b+m|0)<<7|o>>>25)+b|0)<<9|o>>>23)+l|0)<<13|o>>>19)+h|0)<<18|o>>>14,i^=(o=(l^=(o=(s^=(o=(a^=(o=i+l|0)<<7|o>>>25)+i|0)<<9|o>>>23)+a|0)<<13|o>>>19)+s|0)<<18|o>>>14,d^=(o=(c^=(o=(h^=(o=(u^=(o=d+c|0)<<7|o>>>25)+d|0)<<9|o>>>23)+u|0)<<13|o>>>19)+h|0)<<18|o>>>14,f^=(o=(g^=(o=(p^=(o=(m^=(o=f+g|0)<<7|o>>>25)+f|0)<<9|o>>>23)+m|0)<<13|o>>>19)+p|0)<<18|o>>>14,b^=(o=(y^=(o=(v^=(o=(w^=(o=b+y|0)<<7|o>>>25)+b|0)<<9|o>>>23)+w|0)<<13|o>>>19)+v|0)<<18|o>>>14;e[0]=i>>>0&255,e[1]=i>>>8&255,e[2]=i>>>16&255,e[3]=i>>>24&255,e[4]=d>>>0&255,e[5]=d>>>8&255,e[6]=d>>>16&255,e[7]=d>>>24&255,e[8]=f>>>0&255,e[9]=f>>>8&255,e[10]=f>>>16&255,e[11]=f>>>24&255,e[12]=b>>>0&255,e[13]=b>>>8&255,e[14]=b>>>16&255,e[15]=b>>>24&255,e[16]=u>>>0&255,e[17]=u>>>8&255,e[18]=u>>>16&255,e[19]=u>>>24&255,e[20]=h>>>0&255,e[21]=h>>>8&255,e[22]=h>>>16&255,e[23]=h>>>24&255,e[24]=p>>>0&255,e[25]=p>>>8&255,e[26]=p>>>16&255,e[27]=p>>>24&255,e[28]=g>>>0&255,e[29]=g>>>8&255,e[30]=g>>>16&255,e[31]=g>>>24&255}(e,t,n,r)}var y=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function b(e,t,n,r,o,i,a){var s,l,c=new Uint8Array(16),d=new Uint8Array(64);for(l=0;l<16;l++)c[l]=0;for(l=0;l<8;l++)c[l]=i[l];for(;o>=64;){for(w(d,c,a,y),l=0;l<64;l++)e[t+l]=n[r+l]^d[l];for(s=1,l=8;l<16;l++)s=s+(255&c[l])|0,c[l]=255&s,s>>>=8;o-=64,t+=64,r+=64}if(o>0)for(w(d,c,a,y),l=0;l<o;l++)e[t+l]=n[r+l]^d[l];return 0}function C(e,t,n,r,o){var i,a,s=new Uint8Array(16),l=new Uint8Array(64);for(a=0;a<16;a++)s[a]=0;for(a=0;a<8;a++)s[a]=r[a];for(;n>=64;){for(w(l,s,o,y),a=0;a<64;a++)e[t+a]=l[a];for(i=1,a=8;a<16;a++)i=i+(255&s[a])|0,s[a]=255&i,i>>>=8;n-=64,t+=64}if(n>0)for(w(l,s,o,y),a=0;a<n;a++)e[t+a]=l[a];return 0}function x(e,t,n,r,o){var i=new Uint8Array(32);v(i,r,o,y);for(var a=new Uint8Array(8),s=0;s<8;s++)a[s]=r[s+16];return C(e,t,n,a,i)}function S(e,t,n,r,o,i,a){var s=new Uint8Array(32);v(s,i,a,y);for(var l=new Uint8Array(8),c=0;c<8;c++)l[c]=i[c+16];return b(e,t,n,r,o,l,s)}var k=function(e){var t,n,r,o,i,a,s,l;this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0,t=255&e[0]|(255&e[1])<<8,this.r[0]=8191&t,n=255&e[2]|(255&e[3])<<8,this.r[1]=8191&(t>>>13|n<<3),r=255&e[4]|(255&e[5])<<8,this.r[2]=7939&(n>>>10|r<<6),o=255&e[6]|(255&e[7])<<8,this.r[3]=8191&(r>>>7|o<<9),i=255&e[8]|(255&e[9])<<8,this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,a=255&e[10]|(255&e[11])<<8,this.r[6]=8191&(i>>>14|a<<2),s=255&e[12]|(255&e[13])<<8,this.r[7]=8065&(a>>>11|s<<5),l=255&e[14]|(255&e[15])<<8,this.r[8]=8191&(s>>>8|l<<8),this.r[9]=l>>>5&127,this.pad[0]=255&e[16]|(255&e[17])<<8,this.pad[1]=255&e[18]|(255&e[19])<<8,this.pad[2]=255&e[20]|(255&e[21])<<8,this.pad[3]=255&e[22]|(255&e[23])<<8,this.pad[4]=255&e[24]|(255&e[25])<<8,this.pad[5]=255&e[26]|(255&e[27])<<8,this.pad[6]=255&e[28]|(255&e[29])<<8,this.pad[7]=255&e[30]|(255&e[31])<<8};function _(e,t,n,r,o,i){var a=new k(i);return a.update(n,r,o),a.finish(e,t),0}function E(e,t,n,r,o,i){var a=new Uint8Array(16);return _(a,0,n,r,o,i),f(e,t,a,0)}function R(e,t,n,r,o){var i;if(n<32)return-1;for(S(e,0,t,0,n,r,o),_(e,16,e,32,n-32,e),i=0;i<16;i++)e[i]=0;return 0}function I(e,t,n,r,o){var i,a=new Uint8Array(32);if(n<32)return-1;if(x(a,0,32,r,o),0!==E(t,16,t,32,n-32,a))return-1;for(S(e,0,t,0,n,r,o),i=0;i<32;i++)e[i]=0;return 0}function M(e,t){var n;for(n=0;n<16;n++)e[n]=0|t[n]}function A(e){var t,n,r=1;for(t=0;t<16;t++)n=e[t]+r+65535,r=Math.floor(n/65536),e[t]=n-65536*r;e[0]+=r-1+37*(r-1)}function L(e,t,n){for(var r,o=~(n-1),i=0;i<16;i++)r=o&(e[i]^t[i]),e[i]^=r,t[i]^=r}function N(e,n){var r,o,i,a=t(),s=t();for(r=0;r<16;r++)s[r]=n[r];for(A(s),A(s),A(s),o=0;o<2;o++){for(a[0]=s[0]-65517,r=1;r<15;r++)a[r]=s[r]-65535-(a[r-1]>>16&1),a[r-1]&=65535;a[15]=s[15]-32767-(a[14]>>16&1),i=a[15]>>16&1,a[14]&=65535,L(s,a,1-i)}for(r=0;r<16;r++)e[2*r]=255&s[r],e[2*r+1]=s[r]>>8}function W(e,t){var n=new Uint8Array(32),r=new Uint8Array(32);return N(n,e),N(r,t),m(n,0,r,0)}function P(e){var t=new Uint8Array(32);return N(t,e),1&t[0]}function U(e,t){var n;for(n=0;n<16;n++)e[n]=t[2*n]+(t[2*n+1]<<8);e[15]&=32767}function D(e,t,n){for(var r=0;r<16;r++)e[r]=t[r]+n[r]}function j(e,t,n){for(var r=0;r<16;r++)e[r]=t[r]-n[r]}function B(e,t,n){var r,o,i=0,a=0,s=0,l=0,c=0,d=0,u=0,h=0,p=0,g=0,f=0,m=0,w=0,v=0,y=0,b=0,C=0,x=0,S=0,k=0,_=0,E=0,R=0,T=0,I=0,O=0,M=0,A=0,L=0,N=0,W=0,P=n[0],U=n[1],D=n[2],j=n[3],B=n[4],q=n[5],$=n[6],K=n[7],F=n[8],H=n[9],V=n[10],z=n[11],Z=n[12],G=n[13],Y=n[14],J=n[15];i+=(r=t[0])*P,a+=r*U,s+=r*D,l+=r*j,c+=r*B,d+=r*q,u+=r*$,h+=r*K,p+=r*F,g+=r*H,f+=r*V,m+=r*z,w+=r*Z,v+=r*G,y+=r*Y,b+=r*J,a+=(r=t[1])*P,s+=r*U,l+=r*D,c+=r*j,d+=r*B,u+=r*q,h+=r*$,p+=r*K,g+=r*F,f+=r*H,m+=r*V,w+=r*z,v+=r*Z,y+=r*G,b+=r*Y,C+=r*J,s+=(r=t[2])*P,l+=r*U,c+=r*D,d+=r*j,u+=r*B,h+=r*q,p+=r*$,g+=r*K,f+=r*F,m+=r*H,w+=r*V,v+=r*z,y+=r*Z,b+=r*G,C+=r*Y,x+=r*J,l+=(r=t[3])*P,c+=r*U,d+=r*D,u+=r*j,h+=r*B,p+=r*q,g+=r*$,f+=r*K,m+=r*F,w+=r*H,v+=r*V,y+=r*z,b+=r*Z,C+=r*G,x+=r*Y,S+=r*J,c+=(r=t[4])*P,d+=r*U,u+=r*D,h+=r*j,p+=r*B,g+=r*q,f+=r*$,m+=r*K,w+=r*F,v+=r*H,y+=r*V,b+=r*z,C+=r*Z,x+=r*G,S+=r*Y,k+=r*J,d+=(r=t[5])*P,u+=r*U,h+=r*D,p+=r*j,g+=r*B,f+=r*q,m+=r*$,w+=r*K,v+=r*F,y+=r*H,b+=r*V,C+=r*z,x+=r*Z,S+=r*G,k+=r*Y,_+=r*J,u+=(r=t[6])*P,h+=r*U,p+=r*D,g+=r*j,f+=r*B,m+=r*q,w+=r*$,v+=r*K,y+=r*F,b+=r*H,C+=r*V,x+=r*z,S+=r*Z,k+=r*G,_+=r*Y,E+=r*J,h+=(r=t[7])*P,p+=r*U,g+=r*D,f+=r*j,m+=r*B,w+=r*q,v+=r*$,y+=r*K,b+=r*F,C+=r*H,x+=r*V,S+=r*z,k+=r*Z,_+=r*G,E+=r*Y,R+=r*J,p+=(r=t[8])*P,g+=r*U,f+=r*D,m+=r*j,w+=r*B,v+=r*q,y+=r*$,b+=r*K,C+=r*F,x+=r*H,S+=r*V,k+=r*z,_+=r*Z,E+=r*G,R+=r*Y,T+=r*J,g+=(r=t[9])*P,f+=r*U,m+=r*D,w+=r*j,v+=r*B,y+=r*q,b+=r*$,C+=r*K,x+=r*F,S+=r*H,k+=r*V,_+=r*z,E+=r*Z,R+=r*G,T+=r*Y,I+=r*J,f+=(r=t[10])*P,m+=r*U,w+=r*D,v+=r*j,y+=r*B,b+=r*q,C+=r*$,x+=r*K,S+=r*F,k+=r*H,_+=r*V,E+=r*z,R+=r*Z,T+=r*G,I+=r*Y,O+=r*J,m+=(r=t[11])*P,w+=r*U,v+=r*D,y+=r*j,b+=r*B,C+=r*q,x+=r*$,S+=r*K,k+=r*F,_+=r*H,E+=r*V,R+=r*z,T+=r*Z,I+=r*G,O+=r*Y,M+=r*J,w+=(r=t[12])*P,v+=r*U,y+=r*D,b+=r*j,C+=r*B,x+=r*q,S+=r*$,k+=r*K,_+=r*F,E+=r*H,R+=r*V,T+=r*z,I+=r*Z,O+=r*G,M+=r*Y,A+=r*J,v+=(r=t[13])*P,y+=r*U,b+=r*D,C+=r*j,x+=r*B,S+=r*q,k+=r*$,_+=r*K,E+=r*F,R+=r*H,T+=r*V,I+=r*z,O+=r*Z,M+=r*G,A+=r*Y,L+=r*J,y+=(r=t[14])*P,b+=r*U,C+=r*D,x+=r*j,S+=r*B,k+=r*q,_+=r*$,E+=r*K,R+=r*F,T+=r*H,I+=r*V,O+=r*z,M+=r*Z,A+=r*G,L+=r*Y,N+=r*J,b+=(r=t[15])*P,a+=38*(x+=r*D),s+=38*(S+=r*j),l+=38*(k+=r*B),c+=38*(_+=r*q),d+=38*(E+=r*$),u+=38*(R+=r*K),h+=38*(T+=r*F),p+=38*(I+=r*H),g+=38*(O+=r*V),f+=38*(M+=r*z),m+=38*(A+=r*Z),w+=38*(L+=r*G),v+=38*(N+=r*Y),y+=38*(W+=r*J),i=(r=(i+=38*(C+=r*U))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),w=(r=w+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),i=(r=(i+=o-1+37*(o-1))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),w=(r=w+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),i+=o-1+37*(o-1),e[0]=i,e[1]=a,e[2]=s,e[3]=l,e[4]=c,e[5]=d,e[6]=u,e[7]=h,e[8]=p,e[9]=g,e[10]=f,e[11]=m,e[12]=w,e[13]=v,e[14]=y,e[15]=b}function q(e,t){B(e,t,t)}function $(e,n){var r,o=t();for(r=0;r<16;r++)o[r]=n[r];for(r=253;r>=0;r--)q(o,o),2!==r&&4!==r&&B(o,o,n);for(r=0;r<16;r++)e[r]=o[r]}function K(e,n){var r,o=t();for(r=0;r<16;r++)o[r]=n[r];for(r=250;r>=0;r--)q(o,o),1!==r&&B(o,o,n);for(r=0;r<16;r++)e[r]=o[r]}function F(e,n,r){var o,i,a=new Uint8Array(32),l=new Float64Array(80),c=t(),d=t(),u=t(),h=t(),p=t(),g=t();for(i=0;i<31;i++)a[i]=n[i];for(a[31]=127&n[31]|64,a[0]&=248,U(l,r),i=0;i<16;i++)d[i]=l[i],h[i]=c[i]=u[i]=0;for(c[0]=h[0]=1,i=254;i>=0;--i)L(c,d,o=a[i>>>3]>>>(7&i)&1),L(u,h,o),D(p,c,u),j(c,c,u),D(u,d,h),j(d,d,h),q(h,p),q(g,c),B(c,u,c),B(u,d,p),D(p,c,u),j(c,c,u),q(d,c),j(u,h,g),B(c,u,s),D(c,c,h),B(u,u,c),B(c,h,g),B(h,d,l),q(d,p),L(c,d,o),L(u,h,o);for(i=0;i<16;i++)l[i+16]=c[i],l[i+32]=u[i],l[i+48]=d[i],l[i+64]=h[i];var f=l.subarray(32),m=l.subarray(16);return $(f,f),B(m,m,f),N(e,m),0}function H(e,t){return F(e,t,o)}function V(e,t){return n(t,32),H(e,t)}function z(e,t,n){var o=new Uint8Array(32);return F(o,n,t),v(e,r,o,y)}k.prototype.blocks=function(e,t,n){for(var r,o,i,a,s,l,c,d,u,h,p,g,f,m,w,v,y,b,C,x=this.fin?0:2048,S=this.h[0],k=this.h[1],_=this.h[2],E=this.h[3],R=this.h[4],T=this.h[5],I=this.h[6],O=this.h[7],M=this.h[8],A=this.h[9],L=this.r[0],N=this.r[1],W=this.r[2],P=this.r[3],U=this.r[4],D=this.r[5],j=this.r[6],B=this.r[7],q=this.r[8],$=this.r[9];n>=16;)h=u=0,h+=(S+=8191&(r=255&e[t+0]|(255&e[t+1])<<8))*L,h+=(k+=8191&(r>>>13|(o=255&e[t+2]|(255&e[t+3])<<8)<<3))*(5*$),h+=(_+=8191&(o>>>10|(i=255&e[t+4]|(255&e[t+5])<<8)<<6))*(5*q),h+=(E+=8191&(i>>>7|(a=255&e[t+6]|(255&e[t+7])<<8)<<9))*(5*B),u=(h+=(R+=8191&(a>>>4|(s=255&e[t+8]|(255&e[t+9])<<8)<<12))*(5*j))>>>13,h&=8191,h+=(T+=s>>>1&8191)*(5*D),h+=(I+=8191&(s>>>14|(l=255&e[t+10]|(255&e[t+11])<<8)<<2))*(5*U),h+=(O+=8191&(l>>>11|(c=255&e[t+12]|(255&e[t+13])<<8)<<5))*(5*P),h+=(M+=8191&(c>>>8|(d=255&e[t+14]|(255&e[t+15])<<8)<<8))*(5*W),p=u+=(h+=(A+=d>>>5|x)*(5*N))>>>13,p+=S*N,p+=k*L,p+=_*(5*$),p+=E*(5*q),u=(p+=R*(5*B))>>>13,p&=8191,p+=T*(5*j),p+=I*(5*D),p+=O*(5*U),p+=M*(5*P),u+=(p+=A*(5*W))>>>13,p&=8191,g=u,g+=S*W,g+=k*N,g+=_*L,g+=E*(5*$),u=(g+=R*(5*q))>>>13,g&=8191,g+=T*(5*B),g+=I*(5*j),g+=O*(5*D),g+=M*(5*U),f=u+=(g+=A*(5*P))>>>13,f+=S*P,f+=k*W,f+=_*N,f+=E*L,u=(f+=R*(5*$))>>>13,f&=8191,f+=T*(5*q),f+=I*(5*B),f+=O*(5*j),f+=M*(5*D),m=u+=(f+=A*(5*U))>>>13,m+=S*U,m+=k*P,m+=_*W,m+=E*N,u=(m+=R*L)>>>13,m&=8191,m+=T*(5*$),m+=I*(5*q),m+=O*(5*B),m+=M*(5*j),w=u+=(m+=A*(5*D))>>>13,w+=S*D,w+=k*U,w+=_*P,w+=E*W,u=(w+=R*N)>>>13,w&=8191,w+=T*L,w+=I*(5*$),w+=O*(5*q),w+=M*(5*B),v=u+=(w+=A*(5*j))>>>13,v+=S*j,v+=k*D,v+=_*U,v+=E*P,u=(v+=R*W)>>>13,v&=8191,v+=T*N,v+=I*L,v+=O*(5*$),v+=M*(5*q),y=u+=(v+=A*(5*B))>>>13,y+=S*B,y+=k*j,y+=_*D,y+=E*U,u=(y+=R*P)>>>13,y&=8191,y+=T*W,y+=I*N,y+=O*L,y+=M*(5*$),b=u+=(y+=A*(5*q))>>>13,b+=S*q,b+=k*B,b+=_*j,b+=E*D,u=(b+=R*U)>>>13,b&=8191,b+=T*P,b+=I*W,b+=O*N,b+=M*L,C=u+=(b+=A*(5*$))>>>13,C+=S*$,C+=k*q,C+=_*B,C+=E*j,u=(C+=R*D)>>>13,C&=8191,C+=T*U,C+=I*P,C+=O*W,C+=M*N,S=h=8191&(u=(u=((u+=(C+=A*L)>>>13)<<2)+u|0)+(h&=8191)|0),k=p+=u>>>=13,_=g&=8191,E=f&=8191,R=m&=8191,T=w&=8191,I=v&=8191,O=y&=8191,M=b&=8191,A=C&=8191,t+=16,n-=16;this.h[0]=S,this.h[1]=k,this.h[2]=_,this.h[3]=E,this.h[4]=R,this.h[5]=T,this.h[6]=I,this.h[7]=O,this.h[8]=M,this.h[9]=A},k.prototype.finish=function(e,t){var n,r,o,i,a=new Uint16Array(10);if(this.leftover){for(i=this.leftover,this.buffer[i++]=1;i<16;i++)this.buffer[i]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,i=2;i<10;i++)this.h[i]+=n,n=this.h[i]>>>13,this.h[i]&=8191;for(this.h[0]+=5*n,n=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=n,n=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=n,a[0]=this.h[0]+5,n=a[0]>>>13,a[0]&=8191,i=1;i<10;i++)a[i]=this.h[i]+n,n=a[i]>>>13,a[i]&=8191;for(a[9]-=8192,r=(1^n)-1,i=0;i<10;i++)a[i]&=r;for(r=~r,i=0;i<10;i++)this.h[i]=this.h[i]&r|a[i];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),o=this.h[0]+this.pad[0],this.h[0]=65535&o,i=1;i<8;i++)o=(this.h[i]+this.pad[i]|0)+(o>>>16)|0,this.h[i]=65535&o;e[t+0]=this.h[0]>>>0&255,e[t+1]=this.h[0]>>>8&255,e[t+2]=this.h[1]>>>0&255,e[t+3]=this.h[1]>>>8&255,e[t+4]=this.h[2]>>>0&255,e[t+5]=this.h[2]>>>8&255,e[t+6]=this.h[3]>>>0&255,e[t+7]=this.h[3]>>>8&255,e[t+8]=this.h[4]>>>0&255,e[t+9]=this.h[4]>>>8&255,e[t+10]=this.h[5]>>>0&255,e[t+11]=this.h[5]>>>8&255,e[t+12]=this.h[6]>>>0&255,e[t+13]=this.h[6]>>>8&255,e[t+14]=this.h[7]>>>0&255,e[t+15]=this.h[7]>>>8&255},k.prototype.update=function(e,t,n){var r,o;if(this.leftover){for((o=16-this.leftover)>n&&(o=n),r=0;r<o;r++)this.buffer[this.leftover+r]=e[t+r];if(n-=o,t+=o,this.leftover+=o,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(n>=16&&(o=n-n%16,this.blocks(e,t,o),t+=o,n-=o),n){for(r=0;r<n;r++)this.buffer[this.leftover+r]=e[t+r];this.leftover+=n}};var Z=R,G=I,Y=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function J(e,t,n,r){for(var o,i,a,s,l,c,d,u,h,p,g,f,m,w,v,y,b,C,x,S,k,_,E,R,T,I,O=new Int32Array(16),M=new Int32Array(16),A=e[0],L=e[1],N=e[2],W=e[3],P=e[4],U=e[5],D=e[6],j=e[7],B=t[0],q=t[1],$=t[2],K=t[3],F=t[4],H=t[5],V=t[6],z=t[7],Z=0;r>=128;){for(x=0;x<16;x++)S=8*x+Z,O[x]=n[S+0]<<24|n[S+1]<<16|n[S+2]<<8|n[S+3],M[x]=n[S+4]<<24|n[S+5]<<16|n[S+6]<<8|n[S+7];for(x=0;x<80;x++)if(o=A,i=L,a=N,s=W,l=P,c=U,d=D,h=B,p=q,g=$,f=K,m=F,w=H,v=V,E=65535&(_=z),R=_>>>16,T=65535&(k=j),I=k>>>16,E+=65535&(_=(F>>>14|P<<18)^(F>>>18|P<<14)^(P>>>9|F<<23)),R+=_>>>16,T+=65535&(k=(P>>>14|F<<18)^(P>>>18|F<<14)^(F>>>9|P<<23)),I+=k>>>16,E+=65535&(_=F&H^~F&V),R+=_>>>16,T+=65535&(k=P&U^~P&D),I+=k>>>16,E+=65535&(_=Y[2*x+1]),R+=_>>>16,T+=65535&(k=Y[2*x]),I+=k>>>16,k=O[x%16],R+=(_=M[x%16])>>>16,T+=65535&k,I+=k>>>16,T+=(R+=(E+=65535&_)>>>16)>>>16,E=65535&(_=C=65535&E|R<<16),R=_>>>16,T=65535&(k=b=65535&T|(I+=T>>>16)<<16),I=k>>>16,E+=65535&(_=(B>>>28|A<<4)^(A>>>2|B<<30)^(A>>>7|B<<25)),R+=_>>>16,T+=65535&(k=(A>>>28|B<<4)^(B>>>2|A<<30)^(B>>>7|A<<25)),I+=k>>>16,R+=(_=B&q^B&$^q&$)>>>16,T+=65535&(k=A&L^A&N^L&N),I+=k>>>16,u=65535&(T+=(R+=(E+=65535&_)>>>16)>>>16)|(I+=T>>>16)<<16,y=65535&E|R<<16,E=65535&(_=f),R=_>>>16,T=65535&(k=s),I=k>>>16,R+=(_=C)>>>16,T+=65535&(k=b),I+=k>>>16,L=o,N=i,W=a,P=s=65535&(T+=(R+=(E+=65535&_)>>>16)>>>16)|(I+=T>>>16)<<16,U=l,D=c,j=d,A=u,q=h,$=p,K=g,F=f=65535&E|R<<16,H=m,V=w,z=v,B=y,x%16==15)for(S=0;S<16;S++)k=O[S],E=65535&(_=M[S]),R=_>>>16,T=65535&k,I=k>>>16,k=O[(S+9)%16],E+=65535&(_=M[(S+9)%16]),R+=_>>>16,T+=65535&k,I+=k>>>16,b=O[(S+1)%16],E+=65535&(_=((C=M[(S+1)%16])>>>1|b<<31)^(C>>>8|b<<24)^(C>>>7|b<<25)),R+=_>>>16,T+=65535&(k=(b>>>1|C<<31)^(b>>>8|C<<24)^b>>>7),I+=k>>>16,b=O[(S+14)%16],R+=(_=((C=M[(S+14)%16])>>>19|b<<13)^(b>>>29|C<<3)^(C>>>6|b<<26))>>>16,T+=65535&(k=(b>>>19|C<<13)^(C>>>29|b<<3)^b>>>6),I+=k>>>16,I+=(T+=(R+=(E+=65535&_)>>>16)>>>16)>>>16,O[S]=65535&T|I<<16,M[S]=65535&E|R<<16;E=65535&(_=B),R=_>>>16,T=65535&(k=A),I=k>>>16,k=e[0],R+=(_=t[0])>>>16,T+=65535&k,I+=k>>>16,I+=(T+=(R+=(E+=65535&_)>>>16)>>>16)>>>16,e[0]=A=65535&T|I<<16,t[0]=B=65535&E|R<<16,E=65535&(_=q),R=_>>>16,T=65535&(k=L),I=k>>>16,k=e[1],R+=(_=t[1])>>>16,T+=65535&k,I+=k>>>16,I+=(T+=(R+=(E+=65535&_)>>>16)>>>16)>>>16,e[1]=L=65535&T|I<<16,t[1]=q=65535&E|R<<16,E=65535&(_=$),R=_>>>16,T=65535&(k=N),I=k>>>16,k=e[2],R+=(_=t[2])>>>16,T+=65535&k,I+=k>>>16,I+=(T+=(R+=(E+=65535&_)>>>16)>>>16)>>>16,e[2]=N=65535&T|I<<16,t[2]=$=65535&E|R<<16,E=65535&(_=K),R=_>>>16,T=65535&(k=W),I=k>>>16,k=e[3],R+=(_=t[3])>>>16,T+=65535&k,I+=k>>>16,I+=(T+=(R+=(E+=65535&_)>>>16)>>>16)>>>16,e[3]=W=65535&T|I<<16,t[3]=K=65535&E|R<<16,E=65535&(_=F),R=_>>>16,T=65535&(k=P),I=k>>>16,k=e[4],R+=(_=t[4])>>>16,T+=65535&k,I+=k>>>16,I+=(T+=(R+=(E+=65535&_)>>>16)>>>16)>>>16,e[4]=P=65535&T|I<<16,t[4]=F=65535&E|R<<16,E=65535&(_=H),R=_>>>16,T=65535&(k=U),I=k>>>16,k=e[5],R+=(_=t[5])>>>16,T+=65535&k,I+=k>>>16,I+=(T+=(R+=(E+=65535&_)>>>16)>>>16)>>>16,e[5]=U=65535&T|I<<16,t[5]=H=65535&E|R<<16,E=65535&(_=V),R=_>>>16,T=65535&(k=D),I=k>>>16,k=e[6],R+=(_=t[6])>>>16,T+=65535&k,I+=k>>>16,I+=(T+=(R+=(E+=65535&_)>>>16)>>>16)>>>16,e[6]=D=65535&T|I<<16,t[6]=V=65535&E|R<<16,E=65535&(_=z),R=_>>>16,T=65535&(k=j),I=k>>>16,k=e[7],R+=(_=t[7])>>>16,T+=65535&k,I+=k>>>16,I+=(T+=(R+=(E+=65535&_)>>>16)>>>16)>>>16,e[7]=j=65535&T|I<<16,t[7]=z=65535&E|R<<16,Z+=128,r-=128}return r}function Q(e,t,n){var r,o=new Int32Array(8),i=new Int32Array(8),a=new Uint8Array(256),s=n;for(o[0]=1779033703,o[1]=3144134277,o[2]=1013904242,o[3]=2773480762,o[4]=1359893119,o[5]=2600822924,o[6]=528734635,o[7]=1541459225,i[0]=4089235720,i[1]=2227873595,i[2]=4271175723,i[3]=1595750129,i[4]=2917565137,i[5]=725511199,i[6]=4215389547,i[7]=327033209,J(o,i,t,n),n%=128,r=0;r<n;r++)a[r]=t[s-n+r];for(a[n]=128,a[(n=256-128*(n<112?1:0))-9]=0,p(a,n-8,s/536870912|0,s<<3),J(o,i,a,n),r=0;r<8;r++)p(e,8*r,o[r],i[r]);return 0}function X(e,n){var r=t(),o=t(),i=t(),a=t(),s=t(),l=t(),d=t(),u=t(),h=t();j(r,e[1],e[0]),j(h,n[1],n[0]),B(r,r,h),D(o,e[0],e[1]),D(h,n[0],n[1]),B(o,o,h),B(i,e[3],n[3]),B(i,i,c),B(a,e[2],n[2]),D(a,a,a),j(s,o,r),j(l,a,i),D(d,a,i),D(u,o,r),B(e[0],s,l),B(e[1],u,d),B(e[2],d,l),B(e[3],s,u)}function ee(e,t,n){var r;for(r=0;r<4;r++)L(e[r],t[r],n)}function te(e,n){var r=t(),o=t(),i=t();$(i,n[2]),B(r,n[0],i),B(o,n[1],i),N(e,o),e[31]^=P(r)<<7}function ne(e,t,n){var r,o;for(M(e[0],i),M(e[1],a),M(e[2],a),M(e[3],i),o=255;o>=0;--o)ee(e,t,r=n[o/8|0]>>(7&o)&1),X(t,e),X(e,e),ee(e,t,r)}function re(e,n){var r=[t(),t(),t(),t()];M(r[0],d),M(r[1],u),M(r[2],a),B(r[3],d,u),ne(e,r,n)}function oe(e,r,o){var i,a=new Uint8Array(64),s=[t(),t(),t(),t()];for(o||n(r,32),Q(a,r,32),a[0]&=248,a[31]&=127,a[31]|=64,re(s,a),te(e,s),i=0;i<32;i++)r[i+32]=e[i];return 0}var ie=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function ae(e,t){var n,r,o,i;for(r=63;r>=32;--r){for(n=0,o=r-32,i=r-12;o<i;++o)t[o]+=n-16*t[r]*ie[o-(r-32)],n=Math.floor((t[o]+128)/256),t[o]-=256*n;t[o]+=n,t[r]=0}for(n=0,o=0;o<32;o++)t[o]+=n-(t[31]>>4)*ie[o],n=t[o]>>8,t[o]&=255;for(o=0;o<32;o++)t[o]-=n*ie[o];for(r=0;r<32;r++)t[r+1]+=t[r]>>8,e[r]=255&t[r]}function se(e){var t,n=new Float64Array(64);for(t=0;t<64;t++)n[t]=e[t];for(t=0;t<64;t++)e[t]=0;ae(e,n)}function le(e,n,r,o){var i,a,s=new Uint8Array(64),l=new Uint8Array(64),c=new Uint8Array(64),d=new Float64Array(64),u=[t(),t(),t(),t()];Q(s,o,32),s[0]&=248,s[31]&=127,s[31]|=64;var h=r+64;for(i=0;i<r;i++)e[64+i]=n[i];for(i=0;i<32;i++)e[32+i]=s[32+i];for(Q(c,e.subarray(32),r+32),se(c),re(u,c),te(e,u),i=32;i<64;i++)e[i]=o[i];for(Q(l,e,r+64),se(l),i=0;i<64;i++)d[i]=0;for(i=0;i<32;i++)d[i]=c[i];for(i=0;i<32;i++)for(a=0;a<32;a++)d[i+a]+=l[i]*s[a];return ae(e.subarray(32),d),h}function ce(e,n,r,o){var s,c=new Uint8Array(32),d=new Uint8Array(64),u=[t(),t(),t(),t()],p=[t(),t(),t(),t()];if(r<64)return-1;if(function(e,n){var r=t(),o=t(),s=t(),c=t(),d=t(),u=t(),p=t();return M(e[2],a),U(e[1],n),q(s,e[1]),B(c,s,l),j(s,s,e[2]),D(c,e[2],c),q(d,c),q(u,d),B(p,u,d),B(r,p,s),B(r,r,c),K(r,r),B(r,r,s),B(r,r,c),B(r,r,c),B(e[0],r,c),q(o,e[0]),B(o,o,c),W(o,s)&&B(e[0],e[0],h),q(o,e[0]),B(o,o,c),W(o,s)?-1:(P(e[0])===n[31]>>7&&j(e[0],i,e[0]),B(e[3],e[0],e[1]),0)}(p,o))return-1;for(s=0;s<r;s++)e[s]=n[s];for(s=0;s<32;s++)e[s+32]=o[s];if(Q(d,e,r),se(d),ne(u,p,d),re(p,n.subarray(32)),X(u,p),te(c,u),r-=64,m(n,0,c,0)){for(s=0;s<r;s++)e[s]=0;return-1}for(s=0;s<r;s++)e[s]=n[s+64];return r}var de,ue=16,he=64,pe=32,ge=64;function fe(e,t){if(32!==e.length)throw new Error("bad key size");if(24!==t.length)throw new Error("bad nonce size")}function me(){for(var e=0;e<arguments.length;e++)if(!(arguments[e]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}function we(e){for(var t=0;t<e.length;t++)e[t]=0}e.lowlevel={crypto_core_hsalsa20:v,crypto_stream_xor:S,crypto_stream:x,crypto_stream_salsa20_xor:b,crypto_stream_salsa20:C,crypto_onetimeauth:_,crypto_onetimeauth_verify:E,crypto_verify_16:f,crypto_verify_32:m,crypto_secretbox:R,crypto_secretbox_open:I,crypto_scalarmult:F,crypto_scalarmult_base:H,crypto_box_beforenm:z,crypto_box_afternm:Z,crypto_box:function(e,t,n,r,o,i){var a=new Uint8Array(32);return z(a,o,i),Z(e,t,n,r,a)},crypto_box_open:function(e,t,n,r,o,i){var a=new Uint8Array(32);return z(a,o,i),G(e,t,n,r,a)},crypto_box_keypair:V,crypto_hash:Q,crypto_sign:le,crypto_sign_keypair:oe,crypto_sign_open:ce,crypto_secretbox_KEYBYTES:32,crypto_secretbox_NONCEBYTES:24,crypto_secretbox_ZEROBYTES:32,crypto_secretbox_BOXZEROBYTES:ue,crypto_scalarmult_BYTES:32,crypto_scalarmult_SCALARBYTES:32,crypto_box_PUBLICKEYBYTES:32,crypto_box_SECRETKEYBYTES:32,crypto_box_BEFORENMBYTES:32,crypto_box_NONCEBYTES:24,crypto_box_ZEROBYTES:32,crypto_box_BOXZEROBYTES:16,crypto_sign_BYTES:he,crypto_sign_PUBLICKEYBYTES:pe,crypto_sign_SECRETKEYBYTES:ge,crypto_sign_SEEDBYTES:32,crypto_hash_BYTES:64,gf:t,D:l,L:ie,pack25519:N,unpack25519:U,M:B,A:D,S:q,Z:j,pow2523:K,add:X,set25519:M,modL:ae,scalarmult:ne,scalarbase:re},e.randomBytes=function(e){var t=new Uint8Array(e);return n(t,e),t},e.secretbox=function(e,t,n){me(e,t,n),fe(n,t);for(var r=new Uint8Array(32+e.length),o=new Uint8Array(r.length),i=0;i<e.length;i++)r[i+32]=e[i];return R(o,r,r.length,t,n),o.subarray(ue)},e.secretbox.open=function(e,t,n){me(e,t,n),fe(n,t);for(var r=new Uint8Array(ue+e.length),o=new Uint8Array(r.length),i=0;i<e.length;i++)r[i+ue]=e[i];return r.length<32||0!==I(o,r,r.length,t,n)?null:o.subarray(32)},e.secretbox.keyLength=32,e.secretbox.nonceLength=24,e.secretbox.overheadLength=ue,e.scalarMult=function(e,t){if(me(e,t),32!==e.length)throw new Error("bad n size");if(32!==t.length)throw new Error("bad p size");var n=new Uint8Array(32);return F(n,e,t),n},e.scalarMult.base=function(e){if(me(e),32!==e.length)throw new Error("bad n size");var t=new Uint8Array(32);return H(t,e),t},e.scalarMult.scalarLength=32,e.scalarMult.groupElementLength=32,e.box=function(t,n,r,o){var i=e.box.before(r,o);return e.secretbox(t,n,i)},e.box.before=function(e,t){me(e,t),function(e,t){if(32!==e.length)throw new Error("bad public key size");if(32!==t.length)throw new Error("bad secret key size")}(e,t);var n=new Uint8Array(32);return z(n,e,t),n},e.box.after=e.secretbox,e.box.open=function(t,n,r,o){var i=e.box.before(r,o);return e.secretbox.open(t,n,i)},e.box.open.after=e.secretbox.open,e.box.keyPair=function(){var e=new Uint8Array(32),t=new Uint8Array(32);return V(e,t),{publicKey:e,secretKey:t}},e.box.keyPair.fromSecretKey=function(e){if(me(e),32!==e.length)throw new Error("bad secret key size");var t=new Uint8Array(32);return H(t,e),{publicKey:t,secretKey:new Uint8Array(e)}},e.box.publicKeyLength=32,e.box.secretKeyLength=32,e.box.sharedKeyLength=32,e.box.nonceLength=24,e.box.overheadLength=e.secretbox.overheadLength,e.sign=function(e,t){if(me(e,t),t.length!==ge)throw new Error("bad secret key size");var n=new Uint8Array(he+e.length);return le(n,e,e.length,t),n},e.sign.open=function(e,t){if(me(e,t),t.length!==pe)throw new Error("bad public key size");var n=new Uint8Array(e.length),r=ce(n,e,e.length,t);if(r<0)return null;for(var o=new Uint8Array(r),i=0;i<o.length;i++)o[i]=n[i];return o},e.sign.detached=function(t,n){for(var r=e.sign(t,n),o=new Uint8Array(he),i=0;i<o.length;i++)o[i]=r[i];return o},e.sign.detached.verify=function(e,t,n){if(me(e,t,n),t.length!==he)throw new Error("bad signature size");if(n.length!==pe)throw new Error("bad public key size");var r,o=new Uint8Array(he+e.length),i=new Uint8Array(he+e.length);for(r=0;r<he;r++)o[r]=t[r];for(r=0;r<e.length;r++)o[r+he]=e[r];return ce(i,o,o.length,n)>=0},e.sign.keyPair=function(){var e=new Uint8Array(pe),t=new Uint8Array(ge);return oe(e,t),{publicKey:e,secretKey:t}},e.sign.keyPair.fromSecretKey=function(e){if(me(e),e.length!==ge)throw new Error("bad secret key size");for(var t=new Uint8Array(pe),n=0;n<t.length;n++)t[n]=e[32+n];return{publicKey:t,secretKey:new Uint8Array(e)}},e.sign.keyPair.fromSeed=function(e){if(me(e),32!==e.length)throw new Error("bad seed size");for(var t=new Uint8Array(pe),n=new Uint8Array(ge),r=0;r<32;r++)n[r]=e[r];return oe(t,n,!0),{publicKey:t,secretKey:n}},e.sign.publicKeyLength=pe,e.sign.secretKeyLength=ge,e.sign.seedLength=32,e.sign.signatureLength=he,e.hash=function(e){me(e);var t=new Uint8Array(64);return Q(t,e,e.length),t},e.hash.hashLength=64,e.verify=function(e,t){return me(e,t),0!==e.length&&0!==t.length&&e.length===t.length&&0===g(e,0,t,0,e.length)},e.setPRNG=function(e){n=e},(de="undefined"!=typeof self?self.crypto||self.msCrypto:null)&&de.getRandomValues?e.setPRNG(function(e,t){var n,r=new Uint8Array(t);for(n=0;n<t;n+=65536)de.getRandomValues(r.subarray(n,n+Math.min(t-n,65536)));for(n=0;n<t;n++)e[n]=r[n];we(r)}):void 0!==T&&(de=O)&&de.randomBytes&&e.setPRNG(function(e,t){var n,r=de.randomBytes(t);for(n=0;n<t;n++)e[n]=r[n];we(r)})}(e.exports?e.exports:self.nacl=self.nacl||{})}(I)),I.exports);const L=b(A);var N,W,P,U,D,j,B;e.CONNECT_EVENT_ERROR_CODES=void 0,(N=e.CONNECT_EVENT_ERROR_CODES||(e.CONNECT_EVENT_ERROR_CODES={}))[N.UNKNOWN_ERROR=0]="UNKNOWN_ERROR",N[N.BAD_REQUEST_ERROR=1]="BAD_REQUEST_ERROR",N[N.MANIFEST_NOT_FOUND_ERROR=2]="MANIFEST_NOT_FOUND_ERROR",N[N.MANIFEST_CONTENT_ERROR=3]="MANIFEST_CONTENT_ERROR",N[N.UNKNOWN_APP_ERROR=100]="UNKNOWN_APP_ERROR",N[N.USER_REJECTS_ERROR=300]="USER_REJECTS_ERROR",N[N.METHOD_NOT_SUPPORTED=400]="METHOD_NOT_SUPPORTED",e.CONNECT_ITEM_ERROR_CODES=void 0,(W=e.CONNECT_ITEM_ERROR_CODES||(e.CONNECT_ITEM_ERROR_CODES={}))[W.UNKNOWN_ERROR=0]="UNKNOWN_ERROR",W[W.METHOD_NOT_SUPPORTED=400]="METHOD_NOT_SUPPORTED",e.SEND_TRANSACTION_ERROR_CODES=void 0,(P=e.SEND_TRANSACTION_ERROR_CODES||(e.SEND_TRANSACTION_ERROR_CODES={}))[P.UNKNOWN_ERROR=0]="UNKNOWN_ERROR",P[P.BAD_REQUEST_ERROR=1]="BAD_REQUEST_ERROR",P[P.UNKNOWN_APP_ERROR=100]="UNKNOWN_APP_ERROR",P[P.USER_REJECTS_ERROR=300]="USER_REJECTS_ERROR",P[P.METHOD_NOT_SUPPORTED=400]="METHOD_NOT_SUPPORTED",e.SIGN_DATA_ERROR_CODES=void 0,(U=e.SIGN_DATA_ERROR_CODES||(e.SIGN_DATA_ERROR_CODES={}))[U.UNKNOWN_ERROR=0]="UNKNOWN_ERROR",U[U.BAD_REQUEST_ERROR=1]="BAD_REQUEST_ERROR",U[U.UNKNOWN_APP_ERROR=100]="UNKNOWN_APP_ERROR",U[U.USER_REJECTS_ERROR=300]="USER_REJECTS_ERROR",U[U.METHOD_NOT_SUPPORTED=400]="METHOD_NOT_SUPPORTED",(j=D||(D={}))[j.UNKNOWN_ERROR=0]="UNKNOWN_ERROR",j[j.BAD_REQUEST_ERROR=1]="BAD_REQUEST_ERROR",j[j.UNKNOWN_APP_ERROR=100]="UNKNOWN_APP_ERROR",j[j.METHOD_NOT_SUPPORTED=400]="METHOD_NOT_SUPPORTED",e.CHAIN=void 0,(B=e.CHAIN||(e.CHAIN={})).MAINNET="-239",B.TESTNET="-3";const q={encode:function(e,t=!1){let n;return e instanceof Uint8Array?n=e:("string"!=typeof e&&(e=JSON.stringify(e)),n=R.decodeUTF8(e)),function(e,t){const n=R.encodeBase64(e);return t?encodeURIComponent(n):n}(n,t)},decode:function(e,t=!1){const n=function(e,t){return t&&(e=decodeURIComponent(e)),R.decodeBase64(e)}(e,t);return{toString:()=>R.encodeUTF8(n),toObject(){try{return JSON.parse(R.encodeUTF8(n))}catch(e){return null}},toUint8Array:()=>n}}};function $(e){let t="";return e.forEach(e=>{t+=("0"+(255&e).toString(16)).slice(-2)}),t}function K(e){if(e.length%2!=0)throw new Error(`Cannot convert ${e} to bytesArray`);const t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=parseInt(e.slice(n,n+2),16);return t}class F{constructor(e){this.nonceLength=24,this.keyPair=e?this.createKeypairFromString(e):this.createKeypair(),this.sessionId=$(this.keyPair.publicKey)}createKeypair(){return L.box.keyPair()}createKeypairFromString(e){return{publicKey:K(e.publicKey),secretKey:K(e.secretKey)}}createNonce(){return L.randomBytes(this.nonceLength)}encrypt(e,t){const n=(new TextEncoder).encode(e),r=this.createNonce();return function(e,t){const n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n}(r,L.box(n,r,t,this.keyPair.secretKey))}decrypt(e,t){const[n,r]=function(e,t){if(t>=e.length)throw new Error("Index is out of buffer");return[e.slice(0,t),e.slice(t)]}(e,this.nonceLength),o=L.box.open(r,n,t,this.keyPair.secretKey);if(!o)throw new Error(`Decryption error: \n message: ${e.toString()} \n sender pubkey: ${t.toString()} \n keypair pubkey: ${this.keyPair.publicKey.toString()} \n keypair secretkey: ${this.keyPair.secretKey.toString()}`);return(new TextDecoder).decode(o)}stringifyKeypair(){return{publicKey:$(this.keyPair.publicKey),secretKey:$(this.keyPair.secretKey)}}}function H(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function V(e,t,n,r){return new(n||(n=Promise))(function(t,o){function i(e){try{s(r.next(e))}catch(t){o(t)}}function a(e){try{s(r.throw(e))}catch(t){o(t)}}function s(e){var r;e.done?t(e.value):(r=e.value,r instanceof n?r:new n(function(e){e(r)})).then(i,a)}s((r=r.apply(e,[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class z extends Error{get info(){return""}constructor(e,t){super(e,t),this.message=`${z.prefix} ${this.constructor.name}${this.info?": "+this.info:""}${e?"\n"+e:""}`,Object.setPrototypeOf(this,z.prototype)}}z.prefix="[TON_CONNECT_SDK_ERROR]";class Z extends z{get info(){return"Passed DappMetadata is in incorrect format."}constructor(...e){super(...e),Object.setPrototypeOf(this,Z.prototype)}}class G extends z{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,G.prototype)}}class Y extends z{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,Y.prototype)}}class J extends z{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,J.prototype)}}class Q extends z{get info(){return"Send transaction or other protocol methods called while wallet is not connected."}constructor(...e){super(...e),Object.setPrototypeOf(this,Q.prototype)}}class X extends z{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,X.prototype)}}class ee extends z{get info(){return"Wallet doesn't support requested feature method."}constructor(e,t){super(e,t),Object.setPrototypeOf(this,ee.prototype)}}class te extends z{get info(){return"Missing required features. You need to update your wallet."}constructor(e,t){super(e,t),Object.setPrototypeOf(this,te.prototype)}}class ne extends z{constructor(e,t){super(e,t),this.name="WalletWrongNetworkError",Object.setPrototypeOf(this,ne.prototype)}}class re extends z{get info(){return"User rejects the action in the wallet."}constructor(...e){super(...e),Object.setPrototypeOf(this,re.prototype)}}class oe extends z{get info(){return"Request to the wallet contains errors."}constructor(...e){super(...e),Object.setPrototypeOf(this,oe.prototype)}}class ie extends z{get info(){return"App tries to send rpc request to the injected wallet while not connected."}constructor(...e){super(...e),Object.setPrototypeOf(this,ie.prototype)}}class ae extends z{get info(){return"Storage was not specified in the `DappMetadata` and default `localStorage` was not detected in the environment."}constructor(...e){super(...e),Object.setPrototypeOf(this,ae.prototype)}}class se extends z{get info(){return"An error occurred while fetching the wallets list."}constructor(...e){super(...e),Object.setPrototypeOf(this,se.prototype)}}class le extends z{get info(){return"Passed address is in incorrect format."}constructor(...e){super(...e),Object.setPrototypeOf(this,le.prototype)}}class ce extends z{get info(){return"Passed hex is in incorrect format."}constructor(...e){super(...e),Object.setPrototypeOf(this,ce.prototype)}}class de extends z{constructor(...e){super(...e),Object.setPrototypeOf(this,de.prototype)}}const ue={[e.CONNECT_EVENT_ERROR_CODES.UNKNOWN_ERROR]:de,[e.CONNECT_EVENT_ERROR_CODES.USER_REJECTS_ERROR]:re,[e.CONNECT_EVENT_ERROR_CODES.BAD_REQUEST_ERROR]:oe,[e.CONNECT_EVENT_ERROR_CODES.UNKNOWN_APP_ERROR]:ie,[e.CONNECT_EVENT_ERROR_CODES.MANIFEST_NOT_FOUND_ERROR]:Y,[e.CONNECT_EVENT_ERROR_CODES.MANIFEST_CONTENT_ERROR]:G};const he=new class{parseError(e){let t=de;return e.code in ue&&(t=ue[e.code]||de),new t(e.message)}};class pe{isError(e){return"error"in e}}const ge={[e.SEND_TRANSACTION_ERROR_CODES.UNKNOWN_ERROR]:de,[e.SEND_TRANSACTION_ERROR_CODES.USER_REJECTS_ERROR]:re,[e.SEND_TRANSACTION_ERROR_CODES.BAD_REQUEST_ERROR]:oe,[e.SEND_TRANSACTION_ERROR_CODES.UNKNOWN_APP_ERROR]:ie};const fe=new class extends pe{convertToRpcRequest(e){return{method:"sendTransaction",params:[JSON.stringify(e)]}}parseAndThrowError(e){let t=de;throw e.error.code in ge&&(t=ge[e.error.code]||de),new t(e.error.message)}convertFromRpcResponse(e){return{boc:e.result}}},me={[e.SIGN_DATA_ERROR_CODES.UNKNOWN_ERROR]:de,[e.SIGN_DATA_ERROR_CODES.USER_REJECTS_ERROR]:re,[e.SIGN_DATA_ERROR_CODES.BAD_REQUEST_ERROR]:oe,[e.SIGN_DATA_ERROR_CODES.UNKNOWN_APP_ERROR]:ie};const we=new class extends pe{convertToRpcRequest(e){return{method:"signData",params:[JSON.stringify(e)]}}parseAndThrowError(e){let t=de;throw e.error.code in me&&(t=me[e.error.code]||de),new t(e.error.message)}convertFromRpcResponse(e){return e.result}};class ve{constructor(e,t){this.storage=e,this.storeKey="ton-connect-storage_http-bridge-gateway::"+t}storeLastEventId(e){return V(this,0,void 0,function*(){return this.storage.setItem(this.storeKey,e)})}removeLastEventId(){return V(this,0,void 0,function*(){return this.storage.removeItem(this.storeKey)})}getLastEventId(){return V(this,0,void 0,function*(){const e=yield this.storage.getItem(this.storeKey);return e||null})}}function ye(e,t){return function(e){return"/"===e.slice(-1)?e.slice(0,-1):e}(e)+"/"+t}function be(e){if(!e)return!1;const t=new URL(e);return"tg:"===t.protocol||"t.me"===t.hostname}function Ce(e){return!!e&&(e.includes("ton_addr")||e.includes("ton--5Faddr"))}function xe(e){return e.replaceAll(".","%2E").replaceAll("-","%2D").replaceAll("_","%5F").replaceAll("&","-").replaceAll("=","__").replaceAll("%","--")}function Se(e){return e.replaceAll("--","%").replaceAll("__","=").replaceAll("-","&").replaceAll("%5F","_").replaceAll("%2D","-").replaceAll("%2E",".")}function ke(e,t){return V(this,0,void 0,function*(){return new Promise((t,n)=>{setTimeout(()=>t(),e)})})}function _e(e){const t=new AbortController;return(null==e?void 0:e.aborted)?t.abort():null==e||e.addEventListener("abort",()=>t.abort(),{once:!0}),t}function Ee(e,t){return V(this,0,void 0,function*(){var n,r;const o=null!==(n=null==t?void 0:t.attempts)&&void 0!==n?n:10,i=null!==(r=null==t?void 0:t.delayMs)&&void 0!==r?r:200,a=_e(null==t?void 0:t.signal);if("function"!=typeof e)throw new z("Expected a function, got "+typeof e);let s,l=0;for(;l<o;){if(a.signal.aborted)throw new z(`Aborted after attempts ${l}`);try{return yield e({signal:a.signal})}catch(c){s=c,l++,l<o&&(yield ke(i))}}throw s})}function Re(...e){try{console.debug("[TON_CONNECT_SDK]",...e)}catch(t){}}function Te(...e){try{console.error("[TON_CONNECT_SDK]",...e)}catch(t){}}class Ie{get isReady(){const e=this.eventSource.current();return(null==e?void 0:e.readyState)===EventSource.OPEN}get isClosed(){const e=this.eventSource.current();return(null==e?void 0:e.readyState)!==EventSource.OPEN}get isConnecting(){const e=this.eventSource.current();return(null==e?void 0:e.readyState)===EventSource.CONNECTING}constructor(e,t,n,r,o,i){this.bridgeUrl=t,this.sessionId=n,this.listener=r,this.errorsListener=o,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,r=null,o=null,i=null,a=null;const s=(s,...l)=>V(this,0,void 0,function*(){if(i=null!=s?s:null,null==a||a.abort(),a=_e(s),a.signal.aborted)throw new z("Resource creation was aborted");r=null!=l?l:null;const c=e(a.signal,...l);o=c;const d=yield c;if(o!==c&&d!==n)throw yield t(d),new z("Resource creation was aborted by a new resource creation");return n=d,n});return{create:s,current:()=>null!=n?n:null,dispose:()=>V(this,0,void 0,function*(){try{const r=n;n=null;const i=o;o=null;try{null==a||a.abort()}catch(e){}yield Promise.allSettled([r?t(r):Promise.resolve(),i?t(yield i):Promise.resolve()])}catch(e){}}),recreate:e=>V(this,0,void 0,function*(){const t=n,a=o,l=r,c=i;if(yield ke(e),t===n&&a===o&&l===r&&c===i)return yield s(i,...null!=l?l:[]);throw new z("Resource recreation was aborted by a new resource creation")})}}((e,t,n)=>V(this,0,void 0,function*(){const r={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,traceId:n};return yield function(e){return V(this,0,void 0,function*(){return yield function(e,t){const n=null==t?void 0:t.timeout,r=_e(null==t?void 0:t.signal);return new Promise((t,o)=>V(this,0,void 0,function*(){if(r.signal.aborted)return void o(new z("Operation aborted"));let i;void 0!==n&&(i=setTimeout(()=>{r.abort(),o(new z(`Timeout after ${n}ms`))},n)),r.signal.addEventListener("abort",()=>{clearTimeout(i),o(new z("Operation aborted"))},{once:!0});const a={timeout:n,abort:r.signal};yield e((...e)=>{clearTimeout(i),t(...e)},()=>{clearTimeout(i),o()},a)}))}((t,n,r)=>V(this,0,void 0,function*(){var o;const i=_e(r.signal).signal;if(i.aborted)return void n(new z("Bridge connection aborted"));const a=new URL(ye(e.bridgeUrl,e.ssePath));a.searchParams.append("client_id",e.sessionId);const s=yield e.bridgeGatewayStorage.getLastEventId();if(s&&a.searchParams.append("last_event_id",s),e.traceId&&a.searchParams.append("trace_id",e.traceId),i.aborted)return void n(new z("Bridge connection aborted"));const l=new EventSource(a.toString());l.onerror=r=>V(this,0,void 0,function*(){if(i.aborted)return l.close(),void n(new z("Bridge connection aborted"));try{const n=yield e.errorHandler(l,r);n!==l&&l.close(),n&&n!==l&&t(n)}catch(o){l.close(),n(o)}}),l.onopen=()=>{if(i.aborted)return l.close(),void n(new z("Bridge connection aborted"));t(l)},l.onmessage=t=>{if(i.aborted)return l.close(),void n(new z("Bridge connection aborted"));e.messageHandler(t)},null===(o=e.signal)||void 0===o||o.addEventListener("abort",()=>{l.close(),n(new z("Bridge connection aborted"))})}),{timeout:e.openingDeadlineMS,signal:e.signal})})}(r)}),e=>V(this,0,void 0,function*(){e.close()})),this.bridgeGatewayStorage=new ve(e,t),this.analytics=null==i?void 0:i.scoped({bridge_url:t,client_id:n})}registerSession(e){return V(this,0,void 0,function*(){var t,n,r;try{null===(t=this.analytics)||void 0===t||t.emitBridgeClientConnectStarted({trace_id:null==e?void 0:e.traceId});const r=Date.now();yield this.eventSource.create(null==e?void 0:e.signal,null==e?void 0:e.openingDeadlineMS,null==e?void 0:e.traceId);const o=Date.now()-r;null===(n=this.analytics)||void 0===n||n.emitBridgeClientConnectEstablished({bridge_c