UNPKG

@perawallet/connect

Version:

JavaScript SDK for integrating Pera Wallet to web applications.

2 lines (1 loc) 44.4 kB
import e from"@walletconnect/client";import t from"algosdk";import{sign_detached_verify as n}from"tweetnacl-ts";import r from"bowser";var i="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},o=[],s=[],a="undefined"!=typeof Uint8Array?Uint8Array:Array,c=!1;function l(){c=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)o[t]=e[t],s[e.charCodeAt(t)]=t;s["-".charCodeAt(0)]=62,s["_".charCodeAt(0)]=63}function u(e,t,n){for(var r,i,s=[],a=t;a<n;a+=3)r=(e[a]<<16)+(e[a+1]<<8)+e[a+2],s.push(o[(i=r)>>18&63]+o[i>>12&63]+o[i>>6&63]+o[63&i]);return s.join("")}function h(e){var t;c||l();for(var n=e.length,r=n%3,i="",s=[],a=16383,h=0,d=n-r;h<d;h+=a)s.push(u(e,h,h+a>d?d:h+a));return 1===r?(t=e[n-1],i+=o[t>>2],i+=o[t<<4&63],i+="=="):2===r&&(t=(e[n-2]<<8)+e[n-1],i+=o[t>>10],i+=o[t>>4&63],i+=o[t<<2&63],i+="="),s.push(i),s.join("")}function d(e,t,n,r,i){var o,s,a=8*i-r-1,c=(1<<a)-1,l=c>>1,u=-7,h=n?i-1:0,d=n?-1:1,f=e[t+h];for(h+=d,o=f&(1<<-u)-1,f>>=-u,u+=a;u>0;o=256*o+e[t+h],h+=d,u-=8);for(s=o&(1<<-u)-1,o>>=-u,u+=r;u>0;s=256*s+e[t+h],h+=d,u-=8);if(0===o)o=1-l;else{if(o===c)return s?NaN:1/0*(f?-1:1);s+=Math.pow(2,r),o-=l}return(f?-1:1)*s*Math.pow(2,o-r)}function f(e,t,n,r,i,o){var s,a,c,l=8*o-i-1,u=(1<<l)-1,h=u>>1,d=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,f=r?0:o-1,p=r?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=u):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=s+h>=1?d/c:d*Math.pow(2,1-h))*c>=2&&(s++,c/=2),s+h>=u?(a=0,s=u):s+h>=1?(a=(t*c-1)*Math.pow(2,i),s+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;e[n+f]=255&a,f+=p,a/=256,i-=8);for(s=s<<i|a,l+=i;l>0;e[n+f]=255&s,f+=p,s/=256,l-=8);e[n+f-p]|=128*g}var p={}.toString,g=Array.isArray||function(e){return"[object Array]"==p.call(e)};function w(){return y.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function v(e,t){if(w()<t)throw new RangeError("Invalid typed array length");return y.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=y.prototype:(null===e&&(e=new y(t)),e.length=t),e}function y(e,t,n){if(!(y.TYPED_ARRAY_SUPPORT||this instanceof y))return new y(e,t,n);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return A(this,e)}return m(this,e,t,n)}function m(e,t,n,r){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,n,r){if(t.byteLength,n<0||t.byteLength<n)throw new RangeError("'offset' is out of bounds");if(t.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");t=void 0===n&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,n):new Uint8Array(t,n,r);y.TYPED_ARRAY_SUPPORT?(e=t).__proto__=y.prototype:e=E(e,t);return e}(e,t,n,r):"string"==typeof t?function(e,t,n){"string"==typeof n&&""!==n||(n="utf8");if(!y.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|I(t,n);e=v(e,r);var i=e.write(t,n);i!==r&&(e=e.slice(0,i));return e}(e,t,n):function(e,t){if(R(t)){var n=0|T(t.length);return 0===(e=v(e,n)).length||t.copy(e,0,0,n),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(r=t.length)!=r?v(e,0):E(e,t);if("Buffer"===t.type&&g(t.data))return E(e,t.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function b(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function A(e,t){if(b(t),e=v(e,t<0?0:0|T(t)),!y.TYPED_ARRAY_SUPPORT)for(var n=0;n<t;++n)e[n]=0;return e}function E(e,t){var n=t.length<0?0:0|T(t.length);e=v(e,n);for(var r=0;r<n;r+=1)e[r]=255&t[r];return e}function T(e){if(e>=w())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+w().toString(16)+" bytes");return 0|e}function R(e){return!(null==e||!e._isBuffer)}function I(e,t){if(R(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var n=e.length;if(0===n)return 0;for(var r=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return Q(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return Z(e).length;default:if(r)return Q(e).length;t=(""+t).toLowerCase(),r=!0}}function S(e,t,n){var r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return Y(this,t,n);case"utf8":case"utf-8":return x(this,t,n);case"ascii":return k(this,t,n);case"latin1":case"binary":return j(this,t,n);case"base64":return B(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return $(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function _(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function N(e,t,n,r,i){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof t&&(t=y.from(t,r)),R(t))return 0===t.length?-1:P(e,t,n,r,i);if("number"==typeof t)return t&=255,y.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):P(e,[t],n,r,i);throw new TypeError("val must be string, number or Buffer")}function P(e,t,n,r,i){var o,s=1,a=e.length,c=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;s=2,a/=2,c/=2,n/=2}function l(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var u=-1;for(o=n;o<a;o++)if(l(e,o)===l(t,-1===u?0:o-u)){if(-1===u&&(u=o),o-u+1===c)return u*s}else-1!==u&&(o-=o-u),u=-1}else for(n+c>a&&(n=a-c),o=n;o>=0;o--){for(var h=!0,d=0;d<c;d++)if(l(e,o+d)!==l(t,d)){h=!1;break}if(h)return o}return-1}function C(e,t,n,r){n=Number(n)||0;var i=e.length-n;r?(r=Number(r))>i&&(r=i):r=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");r>o/2&&(r=o/2);for(var s=0;s<r;++s){var a=parseInt(t.substr(2*s,2),16);if(isNaN(a))return s;e[n+s]=a}return s}function O(e,t,n,r){return ee(Q(t,e.length-n),e,n,r)}function L(e,t,n,r){return ee(function(e){for(var t=[],n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function M(e,t,n,r){return L(e,t,n,r)}function U(e,t,n,r){return ee(Z(t),e,n,r)}function W(e,t,n,r){return ee(function(e,t){for(var n,r,i,o=[],s=0;s<e.length&&!((t-=2)<0);++s)r=(n=e.charCodeAt(s))>>8,i=n%256,o.push(i),o.push(r);return o}(t,e.length-n),e,n,r)}function B(e,t,n){return 0===t&&n===e.length?h(e):h(e.slice(t,n))}function x(e,t,n){n=Math.min(e.length,n);for(var r=[],i=t;i<n;){var o,s,a,c,l=e[i],u=null,h=l>239?4:l>223?3:l>191?2:1;if(i+h<=n)switch(h){case 1:l<128&&(u=l);break;case 2:128==(192&(o=e[i+1]))&&(c=(31&l)<<6|63&o)>127&&(u=c);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(c=(15&l)<<12|(63&o)<<6|63&s)>2047&&(c<55296||c>57343)&&(u=c);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(c=(15&l)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&c<1114112&&(u=c)}null===u?(u=65533,h=1):u>65535&&(u-=65536,r.push(u>>>10&1023|55296),u=56320|1023&u),r.push(u),i+=h}return function(e){var t=e.length;if(t<=D)return String.fromCharCode.apply(String,e);var n="",r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=D));return n}(r)}y.TYPED_ARRAY_SUPPORT=void 0===i.TYPED_ARRAY_SUPPORT||i.TYPED_ARRAY_SUPPORT,w(),y.poolSize=8192,y._augment=function(e){return e.__proto__=y.prototype,e},y.from=function(e,t,n){return m(null,e,t,n)},y.TYPED_ARRAY_SUPPORT&&(y.prototype.__proto__=Uint8Array.prototype,y.__proto__=Uint8Array),y.alloc=function(e,t,n){return function(e,t,n,r){return b(t),t<=0?v(e,t):void 0!==n?"string"==typeof r?v(e,t).fill(n,r):v(e,t).fill(n):v(e,t)}(null,e,t,n)},y.allocUnsafe=function(e){return A(null,e)},y.allocUnsafeSlow=function(e){return A(null,e)},y.isBuffer=function(e){return null!=e&&(!!e._isBuffer||te(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&te(e.slice(0,0))}(e))},y.compare=function(e,t){if(!R(e)||!R(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,i=0,o=Math.min(n,r);i<o;++i)if(e[i]!==t[i]){n=e[i],r=t[i];break}return n<r?-1:r<n?1:0},y.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},y.concat=function(e,t){if(!g(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return y.alloc(0);var n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var r=y.allocUnsafe(t),i=0;for(n=0;n<e.length;++n){var o=e[n];if(!R(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(r,i),i+=o.length}return r},y.byteLength=I,y.prototype._isBuffer=!0,y.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)_(this,t,t+1);return this},y.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)_(this,t,t+3),_(this,t+1,t+2);return this},y.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)_(this,t,t+7),_(this,t+1,t+6),_(this,t+2,t+5),_(this,t+3,t+4);return this},y.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?x(this,0,e):S.apply(this,arguments)},y.prototype.equals=function(e){if(!R(e))throw new TypeError("Argument must be a Buffer");return this===e||0===y.compare(this,e)},y.prototype.inspect=function(){var e="";return this.length>0&&(e=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(e+=" ... ")),"<Buffer "+e+">"},y.prototype.compare=function(e,t,n,r,i){if(!R(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(this===e)return 0;for(var o=(i>>>=0)-(r>>>=0),s=(n>>>=0)-(t>>>=0),a=Math.min(o,s),c=this.slice(r,i),l=e.slice(t,n),u=0;u<a;++u)if(c[u]!==l[u]){o=c[u],s=l[u];break}return o<s?-1:s<o?1:0},y.prototype.includes=function(e,t,n){return-1!==this.indexOf(e,t,n)},y.prototype.indexOf=function(e,t,n){return N(this,e,t,n,!0)},y.prototype.lastIndexOf=function(e,t,n){return N(this,e,t,n,!1)},y.prototype.write=function(e,t,n,r){if(void 0===t)r="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)r=t,n=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var i=this.length-t;if((void 0===n||n>i)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var o=!1;;)switch(r){case"hex":return C(this,e,t,n);case"utf8":case"utf-8":return O(this,e,t,n);case"ascii":return L(this,e,t,n);case"latin1":case"binary":return M(this,e,t,n);case"base64":return U(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return W(this,e,t,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},y.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var D=4096;function k(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;i<n;++i)r+=String.fromCharCode(127&e[i]);return r}function j(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;i<n;++i)r+=String.fromCharCode(e[i]);return r}function Y(e,t,n){var r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);for(var i="",o=t;o<n;++o)i+=V(e[o]);return i}function $(e,t,n){for(var r=e.slice(t,n),i="",o=0;o<r.length;o+=2)i+=String.fromCharCode(r[o]+256*r[o+1]);return i}function q(e,t,n){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function F(e,t,n,r,i,o){if(!R(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(n+r>e.length)throw new RangeError("Index out of range")}function G(e,t,n,r){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-n,2);i<o;++i)e[n+i]=(t&255<<8*(r?i:1-i))>>>8*(r?i:1-i)}function H(e,t,n,r){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-n,4);i<o;++i)e[n+i]=t>>>8*(r?i:3-i)&255}function J(e,t,n,r,i,o){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function z(e,t,n,r,i){return i||J(e,0,n,4),f(e,t,n,r,23,4),n+4}function K(e,t,n,r,i){return i||J(e,0,n,8),f(e,t,n,r,52,8),n+8}y.prototype.slice=function(e,t){var n,r=this.length;if((e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e),y.TYPED_ARRAY_SUPPORT)(n=this.subarray(e,t)).__proto__=y.prototype;else{var i=t-e;n=new y(i,void 0);for(var o=0;o<i;++o)n[o]=this[o+e]}return n},y.prototype.readUIntLE=function(e,t,n){e|=0,t|=0,n||q(e,t,this.length);for(var r=this[e],i=1,o=0;++o<t&&(i*=256);)r+=this[e+o]*i;return r},y.prototype.readUIntBE=function(e,t,n){e|=0,t|=0,n||q(e,t,this.length);for(var r=this[e+--t],i=1;t>0&&(i*=256);)r+=this[e+--t]*i;return r},y.prototype.readUInt8=function(e,t){return t||q(e,1,this.length),this[e]},y.prototype.readUInt16LE=function(e,t){return t||q(e,2,this.length),this[e]|this[e+1]<<8},y.prototype.readUInt16BE=function(e,t){return t||q(e,2,this.length),this[e]<<8|this[e+1]},y.prototype.readUInt32LE=function(e,t){return t||q(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},y.prototype.readUInt32BE=function(e,t){return t||q(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},y.prototype.readIntLE=function(e,t,n){e|=0,t|=0,n||q(e,t,this.length);for(var r=this[e],i=1,o=0;++o<t&&(i*=256);)r+=this[e+o]*i;return r>=(i*=128)&&(r-=Math.pow(2,8*t)),r},y.prototype.readIntBE=function(e,t,n){e|=0,t|=0,n||q(e,t,this.length);for(var r=t,i=1,o=this[e+--r];r>0&&(i*=256);)o+=this[e+--r]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*t)),o},y.prototype.readInt8=function(e,t){return t||q(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},y.prototype.readInt16LE=function(e,t){t||q(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},y.prototype.readInt16BE=function(e,t){t||q(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},y.prototype.readInt32LE=function(e,t){return t||q(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},y.prototype.readInt32BE=function(e,t){return t||q(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},y.prototype.readFloatLE=function(e,t){return t||q(e,4,this.length),d(this,e,!0,23,4)},y.prototype.readFloatBE=function(e,t){return t||q(e,4,this.length),d(this,e,!1,23,4)},y.prototype.readDoubleLE=function(e,t){return t||q(e,8,this.length),d(this,e,!0,52,8)},y.prototype.readDoubleBE=function(e,t){return t||q(e,8,this.length),d(this,e,!1,52,8)},y.prototype.writeUIntLE=function(e,t,n,r){(e=+e,t|=0,n|=0,r)||F(this,e,t,n,Math.pow(2,8*n)-1,0);var i=1,o=0;for(this[t]=255&e;++o<n&&(i*=256);)this[t+o]=e/i&255;return t+n},y.prototype.writeUIntBE=function(e,t,n,r){(e=+e,t|=0,n|=0,r)||F(this,e,t,n,Math.pow(2,8*n)-1,0);var i=n-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+n},y.prototype.writeUInt8=function(e,t,n){return e=+e,t|=0,n||F(this,e,t,1,255,0),y.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},y.prototype.writeUInt16LE=function(e,t,n){return e=+e,t|=0,n||F(this,e,t,2,65535,0),y.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):G(this,e,t,!0),t+2},y.prototype.writeUInt16BE=function(e,t,n){return e=+e,t|=0,n||F(this,e,t,2,65535,0),y.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):G(this,e,t,!1),t+2},y.prototype.writeUInt32LE=function(e,t,n){return e=+e,t|=0,n||F(this,e,t,4,4294967295,0),y.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):H(this,e,t,!0),t+4},y.prototype.writeUInt32BE=function(e,t,n){return e=+e,t|=0,n||F(this,e,t,4,4294967295,0),y.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):H(this,e,t,!1),t+4},y.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);F(this,e,t,n,i-1,-i)}var o=0,s=1,a=0;for(this[t]=255&e;++o<n&&(s*=256);)e<0&&0===a&&0!==this[t+o-1]&&(a=1),this[t+o]=(e/s|0)-a&255;return t+n},y.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);F(this,e,t,n,i-1,-i)}var o=n-1,s=1,a=0;for(this[t+o]=255&e;--o>=0&&(s*=256);)e<0&&0===a&&0!==this[t+o+1]&&(a=1),this[t+o]=(e/s|0)-a&255;return t+n},y.prototype.writeInt8=function(e,t,n){return e=+e,t|=0,n||F(this,e,t,1,127,-128),y.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},y.prototype.writeInt16LE=function(e,t,n){return e=+e,t|=0,n||F(this,e,t,2,32767,-32768),y.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):G(this,e,t,!0),t+2},y.prototype.writeInt16BE=function(e,t,n){return e=+e,t|=0,n||F(this,e,t,2,32767,-32768),y.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):G(this,e,t,!1),t+2},y.prototype.writeInt32LE=function(e,t,n){return e=+e,t|=0,n||F(this,e,t,4,2147483647,-2147483648),y.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):H(this,e,t,!0),t+4},y.prototype.writeInt32BE=function(e,t,n){return e=+e,t|=0,n||F(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),y.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):H(this,e,t,!1),t+4},y.prototype.writeFloatLE=function(e,t,n){return z(this,e,t,!0,n)},y.prototype.writeFloatBE=function(e,t,n){return z(this,e,t,!1,n)},y.prototype.writeDoubleLE=function(e,t,n){return K(this,e,t,!0,n)},y.prototype.writeDoubleBE=function(e,t,n){return K(this,e,t,!1,n)},y.prototype.copy=function(e,t,n,r){if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);var i,o=r-n;if(this===e&&n<t&&t<r)for(i=o-1;i>=0;--i)e[i+t]=this[i+n];else if(o<1e3||!y.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)e[i+t]=this[i+n];else Uint8Array.prototype.set.call(e,this.subarray(n,n+o),t);return o},y.prototype.fill=function(e,t,n,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===e.length){var i=e.charCodeAt(0);i<256&&(e=i)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!y.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;var o;if(t>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(o=t;o<n;++o)this[o]=e;else{var s=R(e)?e:Q(new y(e,r).toString()),a=s.length;for(o=0;o<n-t;++o)this[o+t]=s[o%a]}return this};var X=/[^+\/0-9A-Za-z-_]/g;function V(e){return e<16?"0"+e.toString(16):e.toString(16)}function Q(e,t){var n;t=t||1/0;for(var r=e.length,i=null,o=[],s=0;s<r;++s){if((n=e.charCodeAt(s))>55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===r){(t-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&o.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((t-=1)<0)break;o.push(n)}else if(n<2048){if((t-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;o.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function Z(e){return function(e){var t,n,r,i,o,u;c||l();var h=e.length;if(h%4>0)throw new Error("Invalid string. Length must be a multiple of 4");o="="===e[h-2]?2:"="===e[h-1]?1:0,u=new a(3*h/4-o),r=o>0?h-4:h;var d=0;for(t=0,n=0;t<r;t+=4,n+=3)i=s[e.charCodeAt(t)]<<18|s[e.charCodeAt(t+1)]<<12|s[e.charCodeAt(t+2)]<<6|s[e.charCodeAt(t+3)],u[d++]=i>>16&255,u[d++]=i>>8&255,u[d++]=255&i;return 2===o?(i=s[e.charCodeAt(t)]<<2|s[e.charCodeAt(t+1)]>>4,u[d++]=255&i):1===o&&(i=s[e.charCodeAt(t)]<<10|s[e.charCodeAt(t+1)]<<4|s[e.charCodeAt(t+2)]>>2,u[d++]=i>>8&255,u[d++]=255&i),u}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(X,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function ee(e,t,n,r){for(var i=0;i<r&&!(i+n>=t.length||i>=e.length);++i)t[i+n]=e[i];return i}function te(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function ne(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class re extends Error{constructor(e,t,...n){super(...n),Error.captureStackTrace&&Error.captureStackTrace(this,re),this.name="PeraWalletConnectError",this.data=e,this.message=t}}const ie=new class{constructor(e){this.listener=void 0,this.channel=e.channel}setupListener({onReceiveMessage:e}){this.close(),this.listener=t=>{if("object"==typeof t.data)try{t.data.channel===this.channel&&e(t)}catch(e){console.error(e)}},window.addEventListener("message",this.listener)}sendMessage({message:e,targetWindow:t,origin:n,timeout:r=1e3}){setTimeout((()=>{const r={channel:this.channel,message:e};t.postMessage(r,{targetOrigin:n||"*"})}),r)}close(){this.listener&&(window.removeEventListener("message",this.listener),this.listener=void 0)}}({channel:"pera-web-wallet"}),oe=700,se=50;function ae(){const e=document.querySelector('meta[name="name"]'),t=document.querySelector('meta[name="description"]');let{title:n}=document,r="";return e instanceof HTMLMetaElement&&(n=e.content),t instanceof HTMLMetaElement&&(r=t.content),{title:n,description:r,url:window.location.origin,favicon:ce()[0]}}function ce(){const e=document.getElementsByTagName("link"),t=[];for(let n=0;n<e.length;n++){const r=e[n],i=r.getAttribute("rel");if(i&&i.toLowerCase().indexOf("icon")>-1){const e=r.getAttribute("href");if(e&&-1===e.toLowerCase().indexOf("https:")&&-1===e.toLowerCase().indexOf("http:")&&0!==e.indexOf("//")){let n=`${window.location.protocol}//${window.location.host}`;if(0===e.indexOf("/"))n+=e;else{const t=window.location.pathname.split("/");t.pop();n+=`${t.join("/")}/${e}`}t.push(n)}else if(0===(null==e?void 0:e.indexOf("//"))){const n=window.location.protocol+e;t.push(n)}else e&&t.push(e)}}return t}function le(e){return new Promise(((t,n)=>{try{const r=window.open(e,"_blank");let i=0;const o=setInterval((()=>{if(i+=1,i===se)return clearInterval(o),void n(new re({type:"MESSAGE_NOT_RECEIVED"},"Couldn't open Pera Wallet, please try again."));r&&(!0===r.closed&&(clearInterval(o),n(new re({type:"OPERATION_CANCELLED"},"Operation cancelled by user"))),ie.sendMessage({message:{type:"TAB_OPEN"},origin:e,targetWindow:r}))}),oe);ie.setupListener({onReceiveMessage:e=>{"TAB_OPEN_RECEIVED"===e.data.message.type&&(clearInterval(o),t(r))}})}catch(e){n(e)}}))}function ue(){return"undefined"!=typeof navigator}function he(){return ue()&&/iPhone|iPad|iPod/i.test(navigator.userAgent)}function de(){return ue()&&/iPhone|iPod|Android/i.test(navigator.userAgent)}function fe(){if(!ue())return null;const{userAgent:e}=navigator;let t;return t=e.match(/DuckDuckGo/i)?"DuckDuckGo":e.match(/OPX/i)?"Opera GX":navigator.brave?"Brave":r.getParser(navigator.userAgent).getBrowserName(),t}const pe="perawallet-wc://",ge="https://perawallet.app/download/",we=[77,88];function ve(e){return{ROOT:`https://${e}`,CONNECT:`https://${e}/connect`,TRANSACTION_SIGN:`https://${e}/transaction/sign`}}function ye(e=!0){let t=pe;const n=fe();return e&&n&&(t=`${t}?browser=${encodeURIComponent(n)}`),t}function me(e,t){let n=ye(!1);he()&&!n.includes("-wc")&&(n=n.replace("://","-wc://"));let r=`${n}wc?uri=${encodeURIComponent(e)}`;const i=fe();return ue()&&/Android/i.test(navigator.userAgent)&&(r=e),i&&(r=`${r}&browser=${encodeURIComponent(i)}`),(null==t?void 0:t.singleAccount)&&(r=`${r}&singleAccount=true`),(null==t?void 0:t.selectedAccount)&&(r=`${r}&selectedAccount=${t.selectedAccount}`),r}const be="pera-wallet-connect-modal-wrapper",Ae="pera-wallet-redirect-modal-wrapper",Ee="pera-wallet-sign-txn-toast-wrapper",Te="pera-wallet-sign-txn-modal-wrapper",Re="pera-wallet-modal";function Ie(e){const t=document.createElement("div");return t.setAttribute("id",e),document.body.appendChild(t),t}function Se(){Ie(Ae).innerHTML="<pera-wallet-redirect-modal></pera-wallet-redirect-modal>"}function _e(){Ie(Ee).innerHTML="<pera-wallet-sign-txn-toast></pera-wallet-sign-txn-toast>"}function Ne(){Pe(Ee)}function Pe(e){const t=document.getElementById(e);t&&t.remove()}const Ce={WALLET:"PeraWallet.Wallet",WALLETCONNECT:"walletconnect"};function Oe(){return"undefined"==typeof localStorage?void 0:localStorage}function Le(e,t){var n;null===(n=Oe())||void 0===n||n.setItem(Ce.WALLET,JSON.stringify({type:t||"pera-wallet",accounts:e,selectedAccount:e[0]}))}function Me(){var e;const t=null===(e=Oe())||void 0===e?void 0:e.getItem(Ce.WALLET);return t?JSON.parse(t):null}function Ue(){return new Promise(((e,t)=>{var n,r;try{null===(n=Oe())||void 0===n||n.removeItem(Ce.WALLETCONNECT),null===(r=Oe())||void 0===r||r.removeItem(Ce.WALLET),e(void 0)}catch(e){t(e)}}))}function We(e){const t=e.slice();for(let e=t.length-1;e>0;e--){const n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t}const Be="https://wc.perawallet.app/config.json";function xe(){return function(e,t={}){return fetch(e,t).then((e=>e.json())).then((e=>e))}(Be,{cache:"no-store"})}function De(){return ne(this,void 0,void 0,(function*(){let e={bridgeURL:"",webWalletURL:"",isWebWalletAvailable:!1,shouldDisplayNewBadge:!1,shouldUseSound:!0,silent:!1,promoteMobile:!1};try{const t=yield xe();void 0!==t.web_wallet&&t.web_wallet_url&&(e.isWebWalletAvailable=t.web_wallet),void 0!==t.display_new_badge&&(e.shouldDisplayNewBadge=t.display_new_badge),void 0!==t.use_sound&&(e.shouldUseSound=t.use_sound),void 0!==t.silent&&(e.silent=t.silent),void 0!==t.promote_mobile&&(e.promoteMobile=t.promote_mobile),e=Object.assign(Object.assign({},e),{bridgeURL:We(t.servers||[])[0]||"",webWalletURL:t.web_wallet_url||""})}catch(e){console.log(e)}return e}))}function ke(e){return Uint8Array.from(window.atob(e),(e=>e.charCodeAt(0)))}function je(e,t){return{id:Date.now()*Math.pow(10,3)+Math.floor(Math.random()*Math.pow(10,3)),jsonrpc:"2.0",method:e,params:t}}function Ye({method:e,signTxnRequestParams:t,signer:n,chainId:r,webWalletURL:i,resolve:o,reject:s}){const a=ve(i);!function(){ne(this,void 0,void 0,(function*(){try{const i=yield le(a.TRANSACTION_SIGN);if(i){let o;"SIGN_TXN"===e?o={type:"SIGN_TXN",txn:t}:"SIGN_DATA"===e&&n&&r&&(o={type:"SIGN_DATA",data:t,signer:n,chainId:r}),o&&ie.sendMessage({message:o,origin:a.TRANSACTION_SIGN,targetWindow:i})}const c=setInterval((()=>{!0===(null==i?void 0:i.closed)&&(s(new re({type:`${e}_CANCELLED`},"Transaction signing is cancelled by user.")),clearInterval(c))}),2e3);ie.setupListener({onReceiveMessage:t=>function({event:e,newPeraWalletTab:t,method:n,resolve:r,reject:i}){switch(e.data.message.type){case"SIGN_TXN_CALLBACK":null==t||t.close(),r(e.data.message.signedTxns.map((e=>ke(e.signedTxn))));break;case"SIGN_DATA_CALLBACK":null==t||t.close(),r(e.data.message.signedData.map((e=>ke(e.signedData))));break;case"SIGN_TXN_NETWORK_MISMATCH":i(new re({type:`${n}_NETWORK_MISMATCH`,detail:e.data.message.error},e.data.message.error||"Network mismatch"));break;case"SIGN_TXN_CALLBACK_ERROR":null==t||t.close(),i(new re({type:`${n}_CANCELLED`},e.data.message.error));break;case"SESSION_DISCONNECTED":null==t||t.close(),Ue(),i(new re({type:"SESSION_DISCONNECTED",detail:e.data.message.error},e.data.message.error))}}({event:t,newPeraWalletTab:i,method:e,resolve:o,reject:s})})}catch(e){s(e)}}))}()}function $e({webWalletURL:e,chainId:t,resolve:n,reject:r}){const i=ve(e);return function(){return ne(this,void 0,void 0,(function*(){try{const e=yield le(i.CONNECT);e&&ie.sendMessage({message:{type:"CONNECT",data:Object.assign(Object.assign({},ae()),{chainId:t})},origin:i.CONNECT,targetWindow:e});const s=setInterval((()=>{!0===(null==e?void 0:e.closed)&&(r(new re({type:"CONNECT_CANCELLED"},"Connect is cancelled by user")),clearInterval(s),o())}),2e3);ie.setupListener({onReceiveMessage:t=>function({event:e,newPeraWalletTab:t,resolve:n,reject:r}){if(n&&"CONNECT_CALLBACK"===e.data.message.type){const r=e.data.message.data.addresses;Le(r,"pera-wallet-web"),n(r),Pe(be),null==t||t.close()}else"CONNECT_NETWORK_MISMATCH"===e.data.message.type&&(r(new re({type:"CONNECT_NETWORK_MISMATCH",detail:e.data.message.error},e.data.message.error||"Your wallet is connected to a different network to this dApp. Update your wallet to the correct network (MainNet or TestNet) to continue.")),Pe(be),null==t||t.close())}({event:t,newPeraWalletTab:e,resolve:n,reject:r})})}catch(e){o(),r(e)}}))};function o(){Pe(be)}}const qe=416001,Fe=416002,Ge={clientToken:"0dw4Qu6ckPJTQY540Z0sEokH910KUWKjsf312fxNtTcVjw5UUhhlK4s4odcXIoEz",indexerToken:"KegWFLYQnBNVeP4oHCX64dObBk8VemzYdNqsnAOIxYQ8aqJLQTYeVDQyZNnx1PZA",port:443},He={mainnet:{algodev:Object.assign(Object.assign({},Ge),{clientServer:"https://node-mainnet.chain.perawallet.app/",indexerServer:"https://indexer-mainnet.chain.perawallet.app/",chainId:qe})},testnet:{algodev:Object.assign(Object.assign({},Ge),{clientServer:"https://node-testnet.chain.perawallet.app/",indexerServer:"https://indexer-testnet.chain.perawallet.app/",chainId:Fe})}};function Je(e,t){const{mainnet:n,testnet:r}=He,i="mainnet"===e?n:r;return{tokens:{client:i[t].clientToken,indexer:i[t].indexerToken},server:{client:i[t].clientServer,indexer:i[t].indexerServer},port:i[t].port}}class ze{constructor({network:e,providerType:n}){const r=Je(e,n);this.providerType=n,this.client=new t.Algodv2(r.tokens.client,r.server.client,r.port),this.indexer=new t.Indexer(r.tokens.indexer,r.server.indexer,r.port)}updateClient(e,n){const r=Je(e,n);this.providerType=n,this.client=new t.Algodv2(r.tokens.client,r.server.client,r.port),this.indexer=new t.Indexer(r.tokens.indexer,r.server.indexer,r.port)}}var Ke;!function(e){e[e.ParseError=-32700]="ParseError",e[e.InvalidRequest=-32600]="InvalidRequest",e[e.MethodNotFound=-32601]="MethodNotFound",e[e.InvalidParams=-32602]="InvalidParams",e[e.InternalError=-32603]="InternalError",e[e.ServerErrorStart=-32e3]="ServerErrorStart",e[e.ServerErrorEnd=-32099]="ServerErrorEnd"}(Ke||(Ke={}));let Xe=0;function Ve(){const e=Date.now(),t=Xe++,n=e.toString().slice(-8),r=t.toString().padStart(4,"0");return parseInt(`${n}${r}`,10)}function Qe(e){if(!e||"object"!=typeof e)return!1;const t=e;return"2.0"===t.jsonrpc&&("result"in t||"error"in t)&&(null===t.id||"string"==typeof t.id||"number"==typeof t.id)}class Ze extends Error{constructor(e){super(e.message),this.name="JsonRpcError",this.code=e.code,this.data=e.data,Error.captureStackTrace&&Error.captureStackTrace(this,Ze)}getMessage(){return`[${this.code}] ${this.message}`}}const et=new class{constructor(){this.listeners=new Map,this.pendingRequests=new Map,this.isListening=!1}startListening(){this.isListening||(window.addEventListener("message",this.handleMessage.bind(this)),this.isListening=!0)}handleMessage(e){try{const n="string"==typeof e.data?JSON.parse(e.data):e.data;if(!n||"object"!=typeof n)return;if(t=n,Array.isArray(t)&&t.every((e=>Qe(e))))return void this.handleBatchResponse(n);if(Qe(n))return void this.handleJsonRpcResponse(n);(function(e){if(!e||"object"!=typeof e)return!1;const t=e;return"2.0"===t.jsonrpc&&"string"==typeof t.method&&!("id"in t)})(n)&&this.handleJsonRpcNotification(n)}catch(e){}var t}handleBatchResponse(e){e.forEach((e=>{this.handleJsonRpcResponse(e)}))}handleJsonRpcResponse(e){const{id:t}=e;if(null===t)return;const n=this.pendingRequests.get(t);if(n)if(clearTimeout(n.timeoutHandle),this.pendingRequests.delete(t),"error"in e){const t=function(e){switch(e.code){case Ke.ParseError:return new Ze({code:Ke.ParseError,message:"Parse error",data:e.data});case Ke.InvalidRequest:return new Ze({code:Ke.InvalidRequest,message:"Invalid Request",data:e.data});case Ke.MethodNotFound:return new Ze({code:Ke.MethodNotFound,message:e.message||"Method not found",data:e.data});case Ke.InvalidParams:return new Ze({code:Ke.InvalidParams,message:"Invalid params",data:e.data});case Ke.InternalError:return new Ze({code:Ke.InternalError,message:"Internal error",data:e.data});default:return e.code>=Ke.ServerErrorStart&&(e.code,Ke.ServerErrorEnd),new Ze(e)}}(e.error);n.reject(t)}else if("result"in e)try{const t=this.parsePayload(e.result);n.resolve(t)}catch(e){n.reject(e instanceof Error?e:new Error(`Failed to parse result for method ${n.method}`))}}handleJsonRpcNotification(e){const{method:t,params:n}=e,r=this.listeners.get(t);if(r){const e=this.parsePayload(n);r.forEach((n=>{try{n(e)}catch(e){console.error(`Error in handler for method ${t}:`,e)}}))}}parsePayload(e){if("string"==typeof e)try{const t=window.atob(e);return JSON.parse(t)}catch(t){try{return JSON.parse(e)}catch(t){return e}}return e}waitForResponse(e,t,n=5e3){return this.startListening(),new Promise(((r,i)=>{const o=this.pendingRequests.get(e);o&&(clearTimeout(o.timeoutHandle),o.reject(new Error(`New request for ${t} (id: ${e}) cancelled previous request`)));const s=setTimeout((()=>{this.pendingRequests.delete(e),i(new Error(`Timeout waiting for response from ${t} (id: ${e})`))}),n);this.pendingRequests.set(e,{resolve:r,reject:i,timeoutHandle:s,method:t})}))}onAction(e,t){this.startListening(),this.listeners.has(e)||this.listeners.set(e,new Set);const n=this.listeners.get(e);return n.add(t),()=>{n.delete(t),0===n.size&&this.listeners.delete(e)}}cleanup(){this.pendingRequests.forEach((e=>{clearTimeout(e.timeoutHandle),e.reject(new Error("Message listener cleaned up"))})),this.pendingRequests.clear(),this.listeners.clear(),this.isListening&&(window.removeEventListener("message",this.handleMessage.bind(this)),this.isListening=!1)}};function tt(e){var t;const n=window.peraMobileInterface,r=function(){var e;return null===(e=window.webkit)||void 0===e?void 0:e.messageHandlers}(),i=JSON.stringify(e);(null==n?void 0:n.handleRequest)&&n.handleRequest(i),(null===(t=null==r?void 0:r.handleRequest)||void 0===t?void 0:t.postMessage)&&r.handleRequest.postMessage(i)}function nt(e,t=5e3,n){const r=Ve(),i=et.waitForResponse(r,e,t),o=function(e,t,n){const r=null!=n?n:Ve();return Object.assign(Object.assign({jsonrpc:"2.0",method:e},void 0!==t&&{params:t}),{id:r})}(e,n,r);return tt(o),i}function rt({isWebWalletAvailable:e,shouldDisplayNewBadge:t,shouldUseSound:n,compactMode:r,promoteMobile:i,singleAccount:o,selectedAccount:s,isInWebview:a}){return{open:(c={isWebWalletAvailable:e,shouldDisplayNewBadge:t,shouldUseSound:n,compactMode:r,promoteMobile:i,singleAccount:o,selectedAccount:s,isInWebview:a},e=>{const{isWebWalletAvailable:t,shouldDisplayNewBadge:n,shouldUseSound:r,compactMode:i,promoteMobile:o,singleAccount:s,selectedAccount:a,isInWebview:l}=c;if(l){const t=me(e,{singleAccount:s,selectedAccount:a});window.open(t,"_blank")}else if(!document.getElementById(be)){const c=`${e}&algorand=true`;Ie(be).innerHTML=`<pera-wallet-connect-modal uri="${c}" is-web-wallet-avaliable="${t}" should-display-new-badge="${n}" should-use-sound="${r}" compact-mode="${i}" promote-mobile="${o}" single-account="${s}" selected-account="${a||""}" is-in-webview="${l||!1}"></pera-wallet-connect-modal>`}}),close:()=>Pe(be)};var c}class it{constructor(e){this.bridge=(null==e?void 0:e.bridge)||"",this.connector=null,this.shouldShowSignTxnToast=void 0===(null==e?void 0:e.shouldShowSignTxnToast)||e.shouldShowSignTxnToast,this.chainId=null==e?void 0:e.chainId,this.isInWebview=!1,this.compactMode=(null==e?void 0:e.compactMode)||!1,this.singleAccount=(null==e?void 0:e.singleAccount)||!1,this.algodClients=new Map}get platform(){return function(){const e=Me();let t=null;return"pera-wallet"===(null==e?void 0:e.type)?t="mobile":"pera-wallet-web"===(null==e?void 0:e.type)&&(t="web"),t}()}get isConnected(){var e;return"mobile"===this.platform?!!this.connector:"web"===this.platform&&!!(null===(e=Me())||void 0===e?void 0:e.accounts.length)}get isPeraDiscoverBrowser(){return this.checkIsPeraDiscoverBrowser()}checkIsInWebview(){return ne(this,void 0,void 0,(function*(){if(de())try{return null!==(yield function(e=2e3){return nt("getPublicSettings",e)}())}catch(e){return!1}return!1}))}connect(t){return new Promise(((n,r)=>ne(this,void 0,void 0,(function*(){var i;try{if(null===(i=this.connector)||void 0===i?void 0:i.connected)try{yield this.connector.killSession()}catch(e){}const{isWebWalletAvailable:o,bridgeURL:s,webWalletURL:a,shouldDisplayNewBadge:c,shouldUseSound:l,promoteMobile:u}=yield De();this.isInWebview=yield this.checkIsInWebview();const h=$e({resolve:n,reject:r,webWalletURL:a,chainId:this.chainId,isCompactMode:this.compactMode});o&&(window.onWebWalletConnect=h),this.connector=new e({bridge:this.bridge||s||"https://bridge.walletconnect.org",qrcodeModal:rt({isWebWalletAvailable:o,shouldDisplayNewBadge:c,shouldUseSound:l,compactMode:this.compactMode,promoteMobile:u,singleAccount:this.singleAccount,selectedAccount:null==t?void 0:t.selectedAccount,isInWebview:this.isInWebview})}),yield this.connector.createSession({chainId:this.chainId||4160}),function(e,t){var n,r,i,o;const s=document.getElementById(e),a=null===(r=null===(n=null==s?void 0:s.querySelector(e.replace("-wrapper","")))||void 0===n?void 0:n.shadowRoot)||void 0===r?void 0:r.querySelector(`.${Re}`),c=null===(o=null===(i=null==a?void 0:a.querySelector("pera-wallet-modal-header"))||void 0===i?void 0:i.shadowRoot)||void 0===o?void 0:o.getElementById("pera-wallet-modal-header-close-button");null==c||c.addEventListener("click",(()=>{t(),Pe(e)}))}(be,(()=>r(new re({type:"CONNECT_MODAL_CLOSED"},"Connect modal is closed by user")))),this.connector.on("connect",((e,t)=>{var i,o;e&&r(e),n((null===(i=this.connector)||void 0===i?void 0:i.accounts)||[]),Le((null===(o=this.connector)||void 0===o?void 0:o.accounts)||[])}))}catch(e){console.log(e),r(new re({type:"SESSION_CONNECT",detail:e},e.message||"There was an error while connecting to Pera Wallet"))}}))))}reconnectSession(){return new Promise(((t,n)=>ne(this,void 0,void 0,(function*(){var r,i;try{const o=Me();if(!o)return void t([]);if("pera-wallet-web"===(null==o?void 0:o.type)){const{isWebWalletAvailable:e}=yield De();e?t(o.accounts||[]):n(new re({type:"SESSION_RECONNECT",detail:"Pera Web is not available"},"Pera Web is not available"))}this.isInWebview=yield this.checkIsInWebview(),this.connector&&t(this.connector.accounts||[]),this.bridge=(null===(r=function(){var e;const t=null===(e=Oe())||void 0===e?void 0:e.getItem(Ce.WALLETCONNECT);return t?JSON.parse(t):null}())||void 0===r?void 0:r.bridge)||"",this.bridge&&(this.connector=new e({bridge:this.bridge}),t((null===(i=this.connector)||void 0===i?void 0:i.accounts)||[])),this.isConnected||t([])}catch(e){yield this.disconnect(),n(new re({type:"SESSION_RECONNECT",detail:e},e.message||"There was an error while reconnecting to Pera Wallet"))}}))))}disconnect(){var e;return ne(this,void 0,void 0,(function*(){let t;this.isConnected&&"mobile"===this.platform&&(t=null===(e=this.connector)||void 0===e?void 0:e.killSession(),null==t||t.then((()=>{this.connector=null}))),yield Ue()}))}verifySignature(e,r,i){try{const{publicKey:o}=t.decodeAddress(i),s=function(...e){const t=e.reduce(((e,t)=>e+t.length),0),n=new Uint8Array(t);let r=0;for(let t=0;t<e.length;t++)n.set(e[t],r),r+=e[t].length;return n}(we,e);return n(s,r,o)}catch(e){return!1}}signTransactionWithMobile(e){return ne(this,void 0,void 0,(function*(){const t=je("algo_signTxn",[e]);try{try{const{silent:e}=yield De(),n=(yield this.connector.sendCustomRequest(t,{forcePushNotification:!e})).filter(Boolean);return"string"==typeof n[0]?n.map(ke):n.map((e=>Uint8Array.from(e)))}catch(e){return yield Promise.reject(new re({type:"SIGN_TRANSACTIONS",detail:e},e.message||"Failed to sign transaction"))}}finally{Pe(Ae),Pe(Ee)}}))}signTransactionWithWeb(e,t){return new Promise(((n,r)=>Ye({signTxnRequestParams:e,webWalletURL:t,method:"SIGN_TXN",resolve:n,reject:r})))}signDataWithMobile({data:e,signer:t,chainId:n}){return ne(this,void 0,void 0,(function*(){const r=je("algo_signData",e.map((e=>Object.assign(Object.assign({},e),{signer:t,chainId:n}))));try{try{const{silent:e}=yield De(),t=yield this.connector.sendCustomRequest(r,{forcePushNotification:!e});return"string"==typeof t[0]?t.map(ke):t.map((e=>Uint8Array.from(e)))}catch(e){return yield Promise.reject(new re({type:"SIGN_TRANSACTIONS",detail:e},e.message||"Failed to sign transaction"))}}finally{Pe(Ae),Pe(Ee)}}))}signDataWithWeb({data:e,signer:t,chainId:n,webWalletURL:r}){return new Promise(((i,o)=>Ye({method:"SIGN_DATA",signTxnRequestParams:e,signer:t,chainId:n,webWalletURL:r,resolve:i,reject:o})))}checkIsPeraDiscoverBrowser(){return window.navigator.userAgent.includes("pera")}getAlgodClient(e){if(!this.algodClients.has(e)){const t=new ze({network:e,providerType:"algodev"});this.algodClients.set(e,t)}return this.algodClients.get(e)}getAccountAuthAddr(e,t){return ne(this,void 0,void 0,(function*(){try{const n=function(e){return e===qe||4160===e?"mainnet":e===Fe?"testnet":"mainnet"}(t),r=this.getAlgodClient(n),i=yield r.client.accountInformation(e).do();return i.authAddr?String(i.authAddr):null}catch(e){return null}}))}signTransaction(e,n){return ne(this,void 0,void 0,(function*(){if("mobile"===this.platform&&(de()&&!this.isInWebview?Se():!de()&&this.shouldShowSignTxnToast&&_e(),!this.connector))throw new Error("PeraWalletConnect was not initialized correctly.");const r=e.flatMap((e=>e.map((e=>function(e,n){let r;n&&!(e.signers||[]).includes(n)&&(r=[]);const i={txn:(o=e.txn,Buffer.from(t.encodeUnsignedTransaction(o)).toString("base64"))};var o;return Array.isArray(r)&&(i.signers=r),e.authAddr&&(i.authAddr=e.authAddr),e.message&&(i.message=e.message),e.msig&&(i.msig=e.msig),i}(e,n)))));if("web"===this.platform){const{webWalletURL:e}=yield De();return this.signTransactionWithWeb(r,e)}return this.signTransactionWithMobile(r)}))}signData(e,t,n){return ne(this,void 0,void 0,(function*(){const r=this.chainId||4160;if("mobile"===this.platform&&(de()&&!this.isInWebview?Se():!de()&&this.shouldShowSignTxnToast&&_e(),!this.connector))throw new Error("PeraWalletConnect was not initialized correctly.");let i;if("web"===this.platform){const{webWalletURL:n}=yield De();i=yield this.signDataWithWeb({data:e,signer:t,chainId:r,webWalletURL:n})}else{const n=e.map((e=>Object.assign(Object.assign({},e),{data:Buffer.from(e.data).toString("base64")})));i=yield this.signDataWithMobile({data:n,signer:t,chainId:r})}if(n){const n=(yield this.getAccountAuthAddr(t,r))||t;for(let t=0;t<i.length;t++){const r=i[t],o=e[t].data;if(!this.verifySignature(o,r,n))throw new re({type:"SIGN_DATA_VERIFICATION_FAILED"},`Signature verification failed for data item at index ${t}`)}}return i}))}}"undefined"!=typeof window&&(window.global=window,window.Buffer=window.Buffer||y,import("./App-8f865981.js"));export{Ae as P,ge as a,Re as b,be as c,ye as d,he as e,Ee as f,me as g,Te as h,de as i,it as j,Ne as k,Pe as r};